You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7026 lines
208 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /******/ (() => { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./resources/js/components/field-error.riot":
  4. /*!**************************************************!*\
  5. !*** ./resources/js/components/field-error.riot ***!
  6. \**************************************************/
  7. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  8. "use strict";
  9. __webpack_require__.r(__webpack_exports__);
  10. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  11. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  12. /* harmony export */ });
  13. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  14. 'css': null,
  15. 'exports': {
  16. state: {
  17. errors: [
  18. ],
  19. // css class for
  20. closest: '.field-group',
  21. },
  22. /**
  23. *
  24. *
  25. * @param {Object} props
  26. * @param {Object} state
  27. *
  28. */
  29. onBeforeMounted(props, state)
  30. {
  31. if (props.closest) {
  32. state.closest = props.closest
  33. }
  34. },
  35. /**
  36. *
  37. *
  38. * @param {Object} props
  39. * @param {Object} state
  40. *
  41. */
  42. onMounted(props, state)
  43. {
  44. // getting parent element for entire field
  45. const parent = this.root.closest(state.closest)
  46. // getting current element by name
  47. const element = parent.querySelector('[name="' + props.name + '"]')
  48. // getting form
  49. const form = element.closest('form')
  50. // element, form are exists and nofieldupdate is not set
  51. // each change of the element dispatch a event to form validation
  52. if (element && form && !props.nofieldupdate) {
  53. element.addEventListener('input', (event) => {
  54. this.dispatchCustomEvent(event, form, props.name)
  55. })
  56. }
  57. // add custom event to listen to form-validation
  58. this.root.addEventListener('form-validation', (event) => {
  59. this.onFormValidation(event, parent)
  60. })
  61. },
  62. /**
  63. * process form validation triggered by form
  64. *
  65. * @param {Event} event
  66. * @param {Element} parent
  67. *
  68. */
  69. onFormValidation(event, parent)
  70. {
  71. // if detail is a value, set to errors
  72. if (event.detail) {
  73. this.state.errors = event.detail
  74. parent.classList.add('field--error')
  75. parent.classList.remove('field--valid')
  76. } else {
  77. this.state.errors = []
  78. parent.classList.remove('field--error')
  79. parent.classList.add('field--valid')
  80. }
  81. this.update()
  82. },
  83. /**
  84. * create event to send to form validation
  85. *
  86. * @param {Event} event
  87. * @param {Element} form
  88. * @param {string} name
  89. *
  90. */
  91. dispatchCustomEvent(event, form, name)
  92. {
  93. const fieldUpdateEvent = new CustomEvent('field-update', {
  94. 'detail': {
  95. 'name': name,
  96. 'value': event.target.value
  97. }
  98. })
  99. form.dispatchEvent(fieldUpdateEvent)
  100. }
  101. },
  102. 'template': function(
  103. template,
  104. expressionTypes,
  105. bindingTypes,
  106. getComponent
  107. ) {
  108. return template(
  109. '<div expr0="expr0" class="field-error"></div>',
  110. [
  111. {
  112. 'type': bindingTypes.IF,
  113. 'evaluate': function(
  114. _scope
  115. ) {
  116. return _scope.state.errors.length > 0;
  117. },
  118. 'redundantAttribute': 'expr0',
  119. 'selector': '[expr0]',
  120. 'template': template(
  121. '<ul><li expr1="expr1"></li></ul>',
  122. [
  123. {
  124. 'type': bindingTypes.EACH,
  125. 'getKey': null,
  126. 'condition': null,
  127. 'template': template(
  128. ' ',
  129. [
  130. {
  131. 'expressions': [
  132. {
  133. 'type': expressionTypes.TEXT,
  134. 'childNodeIndex': 0,
  135. 'evaluate': function(
  136. _scope
  137. ) {
  138. return [
  139. _scope.error
  140. ].join(
  141. ''
  142. );
  143. }
  144. }
  145. ]
  146. }
  147. ]
  148. ),
  149. 'redundantAttribute': 'expr1',
  150. 'selector': '[expr1]',
  151. 'itemName': 'error',
  152. 'indexName': null,
  153. 'evaluate': function(
  154. _scope
  155. ) {
  156. return _scope.state.errors;
  157. }
  158. }
  159. ]
  160. )
  161. }
  162. ]
  163. );
  164. },
  165. 'name': 'field-error'
  166. });
  167. /***/ }),
  168. /***/ "./resources/js/components/note-form.riot":
  169. /*!************************************************!*\
  170. !*** ./resources/js/components/note-form.riot ***!
  171. \************************************************/
  172. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  173. "use strict";
  174. __webpack_require__.r(__webpack_exports__);
  175. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  176. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  177. /* harmony export */ });
  178. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  179. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);
  180. /* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js");
  181. /* harmony import */ var _FormValidator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../FormValidator */ "./resources/js/FormValidator.js");
  182. /* harmony import */ var _field_error_riot__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./field-error.riot */ "./resources/js/components/field-error.riot");
  183. riot__WEBPACK_IMPORTED_MODULE_3__.register('field-error', _field_error_riot__WEBPACK_IMPORTED_MODULE_2__["default"])
  184. riot__WEBPACK_IMPORTED_MODULE_3__.mount('field-error')
  185. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  186. 'css': null,
  187. 'exports': {
  188. state: {
  189. note: undefined
  190. },
  191. onBeforeMount() {
  192. // show error if props is missing
  193. if (!this.props.bucketId) {
  194. console.error('ID of Bucket is Missing!')
  195. }
  196. },
  197. /**
  198. *
  199. *
  200. */
  201. onMounted(props, state) {
  202. // create form validation
  203. const formValidation = new _FormValidator__WEBPACK_IMPORTED_MODULE_1__["default"]('form', {
  204. 'title': {
  205. 'length': {
  206. 'maximum': 255
  207. }
  208. },
  209. 'content': {
  210. 'length': {
  211. 'maximum': 10922
  212. }
  213. }
  214. }, (event, data) => {
  215. this.handleSubmit(event, data)
  216. })
  217. },
  218. /**
  219. *
  220. *
  221. */
  222. handleSubmit(event, data) {
  223. let method = 'post'
  224. if (this.state.note && this.state.note._id) {
  225. method = 'put'
  226. }
  227. axios__WEBPACK_IMPORTED_MODULE_0___default()({
  228. method: method,
  229. url: '/api/note/' + this.props.bucketId,
  230. data: data
  231. }).then((response) => {
  232. this.state.note = response.data.data
  233. this.update()
  234. })
  235. }
  236. },
  237. 'template': function(
  238. template,
  239. expressionTypes,
  240. bindingTypes,
  241. getComponent
  242. ) {
  243. return template(
  244. '<div class="note-form"><div class="panel"><div class="panel__body"><form id="form" novalidate><input expr20="expr20" type="hidden" name="_id"/><div class="field-group"><label class="field-label">\n title\n <input type="text" class="field-text" name="title"/></label></div><div class="field-group"><label class="field-label">\n content\n <textarea name="content" class="field-text"></textarea></label></div><div class><div class="tabs"></div></div><div><button expr21="expr21" class="button"></button><button expr22="expr22" class="button" type="submit"></button></div></form></div></div></div>',
  245. [
  246. {
  247. 'type': bindingTypes.IF,
  248. 'evaluate': function(
  249. _scope
  250. ) {
  251. return _scope.state.note && _scope.state.note._id;
  252. },
  253. 'redundantAttribute': 'expr20',
  254. 'selector': '[expr20]',
  255. 'template': template(
  256. null,
  257. [
  258. {
  259. 'expressions': [
  260. {
  261. 'type': expressionTypes.ATTRIBUTE,
  262. 'name': 'value',
  263. 'evaluate': function(
  264. _scope
  265. ) {
  266. return _scope.state.note._id;
  267. }
  268. }
  269. ]
  270. }
  271. ]
  272. )
  273. },
  274. {
  275. 'type': bindingTypes.IF,
  276. 'evaluate': function(
  277. _scope
  278. ) {
  279. return !_scope.state.note || (_scope.state.note && !_scope.state.note._id);
  280. },
  281. 'redundantAttribute': 'expr21',
  282. 'selector': '[expr21]',
  283. 'template': template(
  284. '\n Create\n ',
  285. []
  286. )
  287. },
  288. {
  289. 'type': bindingTypes.IF,
  290. 'evaluate': function(
  291. _scope
  292. ) {
  293. return _scope.state.note && _scope.state.note._id;
  294. },
  295. 'redundantAttribute': 'expr22',
  296. 'selector': '[expr22]',
  297. 'template': template(
  298. '\n Save\n ',
  299. []
  300. )
  301. }
  302. ]
  303. );
  304. },
  305. 'name': 'app-note-form'
  306. });
  307. /***/ }),
  308. /***/ "./node_modules/axios/index.js":
  309. /*!*************************************!*\
  310. !*** ./node_modules/axios/index.js ***!
  311. \*************************************/
  312. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  313. module.exports = __webpack_require__(/*! ./lib/axios */ "./node_modules/axios/lib/axios.js");
  314. /***/ }),
  315. /***/ "./node_modules/axios/lib/adapters/xhr.js":
  316. /*!************************************************!*\
  317. !*** ./node_modules/axios/lib/adapters/xhr.js ***!
  318. \************************************************/
  319. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  320. "use strict";
  321. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  322. var settle = __webpack_require__(/*! ./../core/settle */ "./node_modules/axios/lib/core/settle.js");
  323. var cookies = __webpack_require__(/*! ./../helpers/cookies */ "./node_modules/axios/lib/helpers/cookies.js");
  324. var buildURL = __webpack_require__(/*! ./../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  325. var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./node_modules/axios/lib/core/buildFullPath.js");
  326. var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./node_modules/axios/lib/helpers/parseHeaders.js");
  327. var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./node_modules/axios/lib/helpers/isURLSameOrigin.js");
  328. var createError = __webpack_require__(/*! ../core/createError */ "./node_modules/axios/lib/core/createError.js");
  329. module.exports = function xhrAdapter(config) {
  330. return new Promise(function dispatchXhrRequest(resolve, reject) {
  331. var requestData = config.data;
  332. var requestHeaders = config.headers;
  333. var responseType = config.responseType;
  334. if (utils.isFormData(requestData)) {
  335. delete requestHeaders['Content-Type']; // Let the browser set it
  336. }
  337. var request = new XMLHttpRequest();
  338. // HTTP basic authentication
  339. if (config.auth) {
  340. var username = config.auth.username || '';
  341. var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
  342. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  343. }
  344. var fullPath = buildFullPath(config.baseURL, config.url);
  345. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  346. // Set the request timeout in MS
  347. request.timeout = config.timeout;
  348. function onloadend() {
  349. if (!request) {
  350. return;
  351. }
  352. // Prepare the response
  353. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  354. var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
  355. request.responseText : request.response;
  356. var response = {
  357. data: responseData,
  358. status: request.status,
  359. statusText: request.statusText,
  360. headers: responseHeaders,
  361. config: config,
  362. request: request
  363. };
  364. settle(resolve, reject, response);
  365. // Clean up request
  366. request = null;
  367. }
  368. if ('onloadend' in request) {
  369. // Use onloadend if available
  370. request.onloadend = onloadend;
  371. } else {
  372. // Listen for ready state to emulate onloadend
  373. request.onreadystatechange = function handleLoad() {
  374. if (!request || request.readyState !== 4) {
  375. return;
  376. }
  377. // The request errored out and we didn't get a response, this will be
  378. // handled by onerror instead
  379. // With one exception: request that using file: protocol, most browsers
  380. // will return status as 0 even though it's a successful request
  381. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  382. return;
  383. }
  384. // readystate handler is calling before onerror or ontimeout handlers,
  385. // so we should call onloadend on the next 'tick'
  386. setTimeout(onloadend);
  387. };
  388. }
  389. // Handle browser request cancellation (as opposed to a manual cancellation)
  390. request.onabort = function handleAbort() {
  391. if (!request) {
  392. return;
  393. }
  394. reject(createError('Request aborted', config, 'ECONNABORTED', request));
  395. // Clean up request
  396. request = null;
  397. };
  398. // Handle low level network errors
  399. request.onerror = function handleError() {
  400. // Real errors are hidden from us by the browser
  401. // onerror should only fire if it's a network error
  402. reject(createError('Network Error', config, null, request));
  403. // Clean up request
  404. request = null;
  405. };
  406. // Handle timeout
  407. request.ontimeout = function handleTimeout() {
  408. var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
  409. if (config.timeoutErrorMessage) {
  410. timeoutErrorMessage = config.timeoutErrorMessage;
  411. }
  412. reject(createError(
  413. timeoutErrorMessage,
  414. config,
  415. config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
  416. request));
  417. // Clean up request
  418. request = null;
  419. };
  420. // Add xsrf header
  421. // This is only done if running in a standard browser environment.
  422. // Specifically not if we're in a web worker, or react-native.
  423. if (utils.isStandardBrowserEnv()) {
  424. // Add xsrf header
  425. var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
  426. cookies.read(config.xsrfCookieName) :
  427. undefined;
  428. if (xsrfValue) {
  429. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  430. }
  431. }
  432. // Add headers to the request
  433. if ('setRequestHeader' in request) {
  434. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  435. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  436. // Remove Content-Type if data is undefined
  437. delete requestHeaders[key];
  438. } else {
  439. // Otherwise add header to the request
  440. request.setRequestHeader(key, val);
  441. }
  442. });
  443. }
  444. // Add withCredentials to request if needed
  445. if (!utils.isUndefined(config.withCredentials)) {
  446. request.withCredentials = !!config.withCredentials;
  447. }
  448. // Add responseType to request if needed
  449. if (responseType && responseType !== 'json') {
  450. request.responseType = config.responseType;
  451. }
  452. // Handle progress if needed
  453. if (typeof config.onDownloadProgress === 'function') {
  454. request.addEventListener('progress', config.onDownloadProgress);
  455. }
  456. // Not all browsers support upload events
  457. if (typeof config.onUploadProgress === 'function' && request.upload) {
  458. request.upload.addEventListener('progress', config.onUploadProgress);
  459. }
  460. if (config.cancelToken) {
  461. // Handle cancellation
  462. config.cancelToken.promise.then(function onCanceled(cancel) {
  463. if (!request) {
  464. return;
  465. }
  466. request.abort();
  467. reject(cancel);
  468. // Clean up request
  469. request = null;
  470. });
  471. }
  472. if (!requestData) {
  473. requestData = null;
  474. }
  475. // Send the request
  476. request.send(requestData);
  477. });
  478. };
  479. /***/ }),
  480. /***/ "./node_modules/axios/lib/axios.js":
  481. /*!*****************************************!*\
  482. !*** ./node_modules/axios/lib/axios.js ***!
  483. \*****************************************/
  484. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  485. "use strict";
  486. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  487. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  488. var Axios = __webpack_require__(/*! ./core/Axios */ "./node_modules/axios/lib/core/Axios.js");
  489. var mergeConfig = __webpack_require__(/*! ./core/mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  490. var defaults = __webpack_require__(/*! ./defaults */ "./node_modules/axios/lib/defaults.js");
  491. /**
  492. * Create an instance of Axios
  493. *
  494. * @param {Object} defaultConfig The default config for the instance
  495. * @return {Axios} A new instance of Axios
  496. */
  497. function createInstance(defaultConfig) {
  498. var context = new Axios(defaultConfig);
  499. var instance = bind(Axios.prototype.request, context);
  500. // Copy axios.prototype to instance
  501. utils.extend(instance, Axios.prototype, context);
  502. // Copy context to instance
  503. utils.extend(instance, context);
  504. return instance;
  505. }
  506. // Create the default instance to be exported
  507. var axios = createInstance(defaults);
  508. // Expose Axios class to allow class inheritance
  509. axios.Axios = Axios;
  510. // Factory for creating new instances
  511. axios.create = function create(instanceConfig) {
  512. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  513. };
  514. // Expose Cancel & CancelToken
  515. axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  516. axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./node_modules/axios/lib/cancel/CancelToken.js");
  517. axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  518. // Expose all/spread
  519. axios.all = function all(promises) {
  520. return Promise.all(promises);
  521. };
  522. axios.spread = __webpack_require__(/*! ./helpers/spread */ "./node_modules/axios/lib/helpers/spread.js");
  523. // Expose isAxiosError
  524. axios.isAxiosError = __webpack_require__(/*! ./helpers/isAxiosError */ "./node_modules/axios/lib/helpers/isAxiosError.js");
  525. module.exports = axios;
  526. // Allow use of default import syntax in TypeScript
  527. module.exports["default"] = axios;
  528. /***/ }),
  529. /***/ "./node_modules/axios/lib/cancel/Cancel.js":
  530. /*!*************************************************!*\
  531. !*** ./node_modules/axios/lib/cancel/Cancel.js ***!
  532. \*************************************************/
  533. /***/ ((module) => {
  534. "use strict";
  535. /**
  536. * A `Cancel` is an object that is thrown when an operation is canceled.
  537. *
  538. * @class
  539. * @param {string=} message The message.
  540. */
  541. function Cancel(message) {
  542. this.message = message;
  543. }
  544. Cancel.prototype.toString = function toString() {
  545. return 'Cancel' + (this.message ? ': ' + this.message : '');
  546. };
  547. Cancel.prototype.__CANCEL__ = true;
  548. module.exports = Cancel;
  549. /***/ }),
  550. /***/ "./node_modules/axios/lib/cancel/CancelToken.js":
  551. /*!******************************************************!*\
  552. !*** ./node_modules/axios/lib/cancel/CancelToken.js ***!
  553. \******************************************************/
  554. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  555. "use strict";
  556. var Cancel = __webpack_require__(/*! ./Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  557. /**
  558. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  559. *
  560. * @class
  561. * @param {Function} executor The executor function.
  562. */
  563. function CancelToken(executor) {
  564. if (typeof executor !== 'function') {
  565. throw new TypeError('executor must be a function.');
  566. }
  567. var resolvePromise;
  568. this.promise = new Promise(function promiseExecutor(resolve) {
  569. resolvePromise = resolve;
  570. });
  571. var token = this;
  572. executor(function cancel(message) {
  573. if (token.reason) {
  574. // Cancellation has already been requested
  575. return;
  576. }
  577. token.reason = new Cancel(message);
  578. resolvePromise(token.reason);
  579. });
  580. }
  581. /**
  582. * Throws a `Cancel` if cancellation has been requested.
  583. */
  584. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  585. if (this.reason) {
  586. throw this.reason;
  587. }
  588. };
  589. /**
  590. * Returns an object that contains a new `CancelToken` and a function that, when called,
  591. * cancels the `CancelToken`.
  592. */
  593. CancelToken.source = function source() {
  594. var cancel;
  595. var token = new CancelToken(function executor(c) {
  596. cancel = c;
  597. });
  598. return {
  599. token: token,
  600. cancel: cancel
  601. };
  602. };
  603. module.exports = CancelToken;
  604. /***/ }),
  605. /***/ "./node_modules/axios/lib/cancel/isCancel.js":
  606. /*!***************************************************!*\
  607. !*** ./node_modules/axios/lib/cancel/isCancel.js ***!
  608. \***************************************************/
  609. /***/ ((module) => {
  610. "use strict";
  611. module.exports = function isCancel(value) {
  612. return !!(value && value.__CANCEL__);
  613. };
  614. /***/ }),
  615. /***/ "./node_modules/axios/lib/core/Axios.js":
  616. /*!**********************************************!*\
  617. !*** ./node_modules/axios/lib/core/Axios.js ***!
  618. \**********************************************/
  619. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  620. "use strict";
  621. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  622. var buildURL = __webpack_require__(/*! ../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  623. var InterceptorManager = __webpack_require__(/*! ./InterceptorManager */ "./node_modules/axios/lib/core/InterceptorManager.js");
  624. var dispatchRequest = __webpack_require__(/*! ./dispatchRequest */ "./node_modules/axios/lib/core/dispatchRequest.js");
  625. var mergeConfig = __webpack_require__(/*! ./mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  626. var validator = __webpack_require__(/*! ../helpers/validator */ "./node_modules/axios/lib/helpers/validator.js");
  627. var validators = validator.validators;
  628. /**
  629. * Create a new instance of Axios
  630. *
  631. * @param {Object} instanceConfig The default config for the instance
  632. */
  633. function Axios(instanceConfig) {
  634. this.defaults = instanceConfig;
  635. this.interceptors = {
  636. request: new InterceptorManager(),
  637. response: new InterceptorManager()
  638. };
  639. }
  640. /**
  641. * Dispatch a request
  642. *
  643. * @param {Object} config The config specific for this request (merged with this.defaults)
  644. */
  645. Axios.prototype.request = function request(config) {
  646. /*eslint no-param-reassign:0*/
  647. // Allow for axios('example/url'[, config]) a la fetch API
  648. if (typeof config === 'string') {
  649. config = arguments[1] || {};
  650. config.url = arguments[0];
  651. } else {
  652. config = config || {};
  653. }
  654. config = mergeConfig(this.defaults, config);
  655. // Set config.method
  656. if (config.method) {
  657. config.method = config.method.toLowerCase();
  658. } else if (this.defaults.method) {
  659. config.method = this.defaults.method.toLowerCase();
  660. } else {
  661. config.method = 'get';
  662. }
  663. var transitional = config.transitional;
  664. if (transitional !== undefined) {
  665. validator.assertOptions(transitional, {
  666. silentJSONParsing: validators.transitional(validators.boolean, '1.0.0'),
  667. forcedJSONParsing: validators.transitional(validators.boolean, '1.0.0'),
  668. clarifyTimeoutError: validators.transitional(validators.boolean, '1.0.0')
  669. }, false);
  670. }
  671. // filter out skipped interceptors
  672. var requestInterceptorChain = [];
  673. var synchronousRequestInterceptors = true;
  674. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  675. if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
  676. return;
  677. }
  678. synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
  679. requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
  680. });
  681. var responseInterceptorChain = [];
  682. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  683. responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
  684. });
  685. var promise;
  686. if (!synchronousRequestInterceptors) {
  687. var chain = [dispatchRequest, undefined];
  688. Array.prototype.unshift.apply(chain, requestInterceptorChain);
  689. chain = chain.concat(responseInterceptorChain);
  690. promise = Promise.resolve(config);
  691. while (chain.length) {
  692. promise = promise.then(chain.shift(), chain.shift());
  693. }
  694. return promise;
  695. }
  696. var newConfig = config;
  697. while (requestInterceptorChain.length) {
  698. var onFulfilled = requestInterceptorChain.shift();
  699. var onRejected = requestInterceptorChain.shift();
  700. try {
  701. newConfig = onFulfilled(newConfig);
  702. } catch (error) {
  703. onRejected(error);
  704. break;
  705. }
  706. }
  707. try {
  708. promise = dispatchRequest(newConfig);
  709. } catch (error) {
  710. return Promise.reject(error);
  711. }
  712. while (responseInterceptorChain.length) {
  713. promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
  714. }
  715. return promise;
  716. };
  717. Axios.prototype.getUri = function getUri(config) {
  718. config = mergeConfig(this.defaults, config);
  719. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  720. };
  721. // Provide aliases for supported request methods
  722. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  723. /*eslint func-names:0*/
  724. Axios.prototype[method] = function(url, config) {
  725. return this.request(mergeConfig(config || {}, {
  726. method: method,
  727. url: url,
  728. data: (config || {}).data
  729. }));
  730. };
  731. });
  732. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  733. /*eslint func-names:0*/
  734. Axios.prototype[method] = function(url, data, config) {
  735. return this.request(mergeConfig(config || {}, {
  736. method: method,
  737. url: url,
  738. data: data
  739. }));
  740. };
  741. });
  742. module.exports = Axios;
  743. /***/ }),
  744. /***/ "./node_modules/axios/lib/core/InterceptorManager.js":
  745. /*!***********************************************************!*\
  746. !*** ./node_modules/axios/lib/core/InterceptorManager.js ***!
  747. \***********************************************************/
  748. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  749. "use strict";
  750. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  751. function InterceptorManager() {
  752. this.handlers = [];
  753. }
  754. /**
  755. * Add a new interceptor to the stack
  756. *
  757. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  758. * @param {Function} rejected The function to handle `reject` for a `Promise`
  759. *
  760. * @return {Number} An ID used to remove interceptor later
  761. */
  762. InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
  763. this.handlers.push({
  764. fulfilled: fulfilled,
  765. rejected: rejected,
  766. synchronous: options ? options.synchronous : false,
  767. runWhen: options ? options.runWhen : null
  768. });
  769. return this.handlers.length - 1;
  770. };
  771. /**
  772. * Remove an interceptor from the stack
  773. *
  774. * @param {Number} id The ID that was returned by `use`
  775. */
  776. InterceptorManager.prototype.eject = function eject(id) {
  777. if (this.handlers[id]) {
  778. this.handlers[id] = null;
  779. }
  780. };
  781. /**
  782. * Iterate over all the registered interceptors
  783. *
  784. * This method is particularly useful for skipping over any
  785. * interceptors that may have become `null` calling `eject`.
  786. *
  787. * @param {Function} fn The function to call for each interceptor
  788. */
  789. InterceptorManager.prototype.forEach = function forEach(fn) {
  790. utils.forEach(this.handlers, function forEachHandler(h) {
  791. if (h !== null) {
  792. fn(h);
  793. }
  794. });
  795. };
  796. module.exports = InterceptorManager;
  797. /***/ }),
  798. /***/ "./node_modules/axios/lib/core/buildFullPath.js":
  799. /*!******************************************************!*\
  800. !*** ./node_modules/axios/lib/core/buildFullPath.js ***!
  801. \******************************************************/
  802. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  803. "use strict";
  804. var isAbsoluteURL = __webpack_require__(/*! ../helpers/isAbsoluteURL */ "./node_modules/axios/lib/helpers/isAbsoluteURL.js");
  805. var combineURLs = __webpack_require__(/*! ../helpers/combineURLs */ "./node_modules/axios/lib/helpers/combineURLs.js");
  806. /**
  807. * Creates a new URL by combining the baseURL with the requestedURL,
  808. * only when the requestedURL is not already an absolute URL.
  809. * If the requestURL is absolute, this function returns the requestedURL untouched.
  810. *
  811. * @param {string} baseURL The base URL
  812. * @param {string} requestedURL Absolute or relative URL to combine
  813. * @returns {string} The combined full path
  814. */
  815. module.exports = function buildFullPath(baseURL, requestedURL) {
  816. if (baseURL && !isAbsoluteURL(requestedURL)) {
  817. return combineURLs(baseURL, requestedURL);
  818. }
  819. return requestedURL;
  820. };
  821. /***/ }),
  822. /***/ "./node_modules/axios/lib/core/createError.js":
  823. /*!****************************************************!*\
  824. !*** ./node_modules/axios/lib/core/createError.js ***!
  825. \****************************************************/
  826. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  827. "use strict";
  828. var enhanceError = __webpack_require__(/*! ./enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  829. /**
  830. * Create an Error with the specified message, config, error code, request and response.
  831. *
  832. * @param {string} message The error message.
  833. * @param {Object} config The config.
  834. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  835. * @param {Object} [request] The request.
  836. * @param {Object} [response] The response.
  837. * @returns {Error} The created error.
  838. */
  839. module.exports = function createError(message, config, code, request, response) {
  840. var error = new Error(message);
  841. return enhanceError(error, config, code, request, response);
  842. };
  843. /***/ }),
  844. /***/ "./node_modules/axios/lib/core/dispatchRequest.js":
  845. /*!********************************************************!*\
  846. !*** ./node_modules/axios/lib/core/dispatchRequest.js ***!
  847. \********************************************************/
  848. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  849. "use strict";
  850. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  851. var transformData = __webpack_require__(/*! ./transformData */ "./node_modules/axios/lib/core/transformData.js");
  852. var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  853. var defaults = __webpack_require__(/*! ../defaults */ "./node_modules/axios/lib/defaults.js");
  854. /**
  855. * Throws a `Cancel` if cancellation has been requested.
  856. */
  857. function throwIfCancellationRequested(config) {
  858. if (config.cancelToken) {
  859. config.cancelToken.throwIfRequested();
  860. }
  861. }
  862. /**
  863. * Dispatch a request to the server using the configured adapter.
  864. *
  865. * @param {object} config The config that is to be used for the request
  866. * @returns {Promise} The Promise to be fulfilled
  867. */
  868. module.exports = function dispatchRequest(config) {
  869. throwIfCancellationRequested(config);
  870. // Ensure headers exist
  871. config.headers = config.headers || {};
  872. // Transform request data
  873. config.data = transformData.call(
  874. config,
  875. config.data,
  876. config.headers,
  877. config.transformRequest
  878. );
  879. // Flatten headers
  880. config.headers = utils.merge(
  881. config.headers.common || {},
  882. config.headers[config.method] || {},
  883. config.headers
  884. );
  885. utils.forEach(
  886. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  887. function cleanHeaderConfig(method) {
  888. delete config.headers[method];
  889. }
  890. );
  891. var adapter = config.adapter || defaults.adapter;
  892. return adapter(config).then(function onAdapterResolution(response) {
  893. throwIfCancellationRequested(config);
  894. // Transform response data
  895. response.data = transformData.call(
  896. config,
  897. response.data,
  898. response.headers,
  899. config.transformResponse
  900. );
  901. return response;
  902. }, function onAdapterRejection(reason) {
  903. if (!isCancel(reason)) {
  904. throwIfCancellationRequested(config);
  905. // Transform response data
  906. if (reason && reason.response) {
  907. reason.response.data = transformData.call(
  908. config,
  909. reason.response.data,
  910. reason.response.headers,
  911. config.transformResponse
  912. );
  913. }
  914. }
  915. return Promise.reject(reason);
  916. });
  917. };
  918. /***/ }),
  919. /***/ "./node_modules/axios/lib/core/enhanceError.js":
  920. /*!*****************************************************!*\
  921. !*** ./node_modules/axios/lib/core/enhanceError.js ***!
  922. \*****************************************************/
  923. /***/ ((module) => {
  924. "use strict";
  925. /**
  926. * Update an Error with the specified config, error code, and response.
  927. *
  928. * @param {Error} error The error to update.
  929. * @param {Object} config The config.
  930. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  931. * @param {Object} [request] The request.
  932. * @param {Object} [response] The response.
  933. * @returns {Error} The error.
  934. */
  935. module.exports = function enhanceError(error, config, code, request, response) {
  936. error.config = config;
  937. if (code) {
  938. error.code = code;
  939. }
  940. error.request = request;
  941. error.response = response;
  942. error.isAxiosError = true;
  943. error.toJSON = function toJSON() {
  944. return {
  945. // Standard
  946. message: this.message,
  947. name: this.name,
  948. // Microsoft
  949. description: this.description,
  950. number: this.number,
  951. // Mozilla
  952. fileName: this.fileName,
  953. lineNumber: this.lineNumber,
  954. columnNumber: this.columnNumber,
  955. stack: this.stack,
  956. // Axios
  957. config: this.config,
  958. code: this.code
  959. };
  960. };
  961. return error;
  962. };
  963. /***/ }),
  964. /***/ "./node_modules/axios/lib/core/mergeConfig.js":
  965. /*!****************************************************!*\
  966. !*** ./node_modules/axios/lib/core/mergeConfig.js ***!
  967. \****************************************************/
  968. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  969. "use strict";
  970. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  971. /**
  972. * Config-specific merge-function which creates a new config-object
  973. * by merging two configuration objects together.
  974. *
  975. * @param {Object} config1
  976. * @param {Object} config2
  977. * @returns {Object} New object resulting from merging config2 to config1
  978. */
  979. module.exports = function mergeConfig(config1, config2) {
  980. // eslint-disable-next-line no-param-reassign
  981. config2 = config2 || {};
  982. var config = {};
  983. var valueFromConfig2Keys = ['url', 'method', 'data'];
  984. var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
  985. var defaultToConfig2Keys = [
  986. 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
  987. 'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
  988. 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
  989. 'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
  990. 'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
  991. ];
  992. var directMergeKeys = ['validateStatus'];
  993. function getMergedValue(target, source) {
  994. if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
  995. return utils.merge(target, source);
  996. } else if (utils.isPlainObject(source)) {
  997. return utils.merge({}, source);
  998. } else if (utils.isArray(source)) {
  999. return source.slice();
  1000. }
  1001. return source;
  1002. }
  1003. function mergeDeepProperties(prop) {
  1004. if (!utils.isUndefined(config2[prop])) {
  1005. config[prop] = getMergedValue(config1[prop], config2[prop]);
  1006. } else if (!utils.isUndefined(config1[prop])) {
  1007. config[prop] = getMergedValue(undefined, config1[prop]);
  1008. }
  1009. }
  1010. utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
  1011. if (!utils.isUndefined(config2[prop])) {
  1012. config[prop] = getMergedValue(undefined, config2[prop]);
  1013. }
  1014. });
  1015. utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
  1016. utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
  1017. if (!utils.isUndefined(config2[prop])) {
  1018. config[prop] = getMergedValue(undefined, config2[prop]);
  1019. } else if (!utils.isUndefined(config1[prop])) {
  1020. config[prop] = getMergedValue(undefined, config1[prop]);
  1021. }
  1022. });
  1023. utils.forEach(directMergeKeys, function merge(prop) {
  1024. if (prop in config2) {
  1025. config[prop] = getMergedValue(config1[prop], config2[prop]);
  1026. } else if (prop in config1) {
  1027. config[prop] = getMergedValue(undefined, config1[prop]);
  1028. }
  1029. });
  1030. var axiosKeys = valueFromConfig2Keys
  1031. .concat(mergeDeepPropertiesKeys)
  1032. .concat(defaultToConfig2Keys)
  1033. .concat(directMergeKeys);
  1034. var otherKeys = Object
  1035. .keys(config1)
  1036. .concat(Object.keys(config2))
  1037. .filter(function filterAxiosKeys(key) {
  1038. return axiosKeys.indexOf(key) === -1;
  1039. });
  1040. utils.forEach(otherKeys, mergeDeepProperties);
  1041. return config;
  1042. };
  1043. /***/ }),
  1044. /***/ "./node_modules/axios/lib/core/settle.js":
  1045. /*!***********************************************!*\
  1046. !*** ./node_modules/axios/lib/core/settle.js ***!
  1047. \***********************************************/
  1048. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1049. "use strict";
  1050. var createError = __webpack_require__(/*! ./createError */ "./node_modules/axios/lib/core/createError.js");
  1051. /**
  1052. * Resolve or reject a Promise based on response status.
  1053. *
  1054. * @param {Function} resolve A function that resolves the promise.
  1055. * @param {Function} reject A function that rejects the promise.
  1056. * @param {object} response The response.
  1057. */
  1058. module.exports = function settle(resolve, reject, response) {
  1059. var validateStatus = response.config.validateStatus;
  1060. if (!response.status || !validateStatus || validateStatus(response.status)) {
  1061. resolve(response);
  1062. } else {
  1063. reject(createError(
  1064. 'Request failed with status code ' + response.status,
  1065. response.config,
  1066. null,
  1067. response.request,
  1068. response
  1069. ));
  1070. }
  1071. };
  1072. /***/ }),
  1073. /***/ "./node_modules/axios/lib/core/transformData.js":
  1074. /*!******************************************************!*\
  1075. !*** ./node_modules/axios/lib/core/transformData.js ***!
  1076. \******************************************************/
  1077. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1078. "use strict";
  1079. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1080. var defaults = __webpack_require__(/*! ./../defaults */ "./node_modules/axios/lib/defaults.js");
  1081. /**
  1082. * Transform the data for a request or a response
  1083. *
  1084. * @param {Object|String} data The data to be transformed
  1085. * @param {Array} headers The headers for the request or response
  1086. * @param {Array|Function} fns A single function or Array of functions
  1087. * @returns {*} The resulting transformed data
  1088. */
  1089. module.exports = function transformData(data, headers, fns) {
  1090. var context = this || defaults;
  1091. /*eslint no-param-reassign:0*/
  1092. utils.forEach(fns, function transform(fn) {
  1093. data = fn.call(context, data, headers);
  1094. });
  1095. return data;
  1096. };
  1097. /***/ }),
  1098. /***/ "./node_modules/axios/lib/defaults.js":
  1099. /*!********************************************!*\
  1100. !*** ./node_modules/axios/lib/defaults.js ***!
  1101. \********************************************/
  1102. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1103. "use strict";
  1104. /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
  1105. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  1106. var normalizeHeaderName = __webpack_require__(/*! ./helpers/normalizeHeaderName */ "./node_modules/axios/lib/helpers/normalizeHeaderName.js");
  1107. var enhanceError = __webpack_require__(/*! ./core/enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  1108. var DEFAULT_CONTENT_TYPE = {
  1109. 'Content-Type': 'application/x-www-form-urlencoded'
  1110. };
  1111. function setContentTypeIfUnset(headers, value) {
  1112. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  1113. headers['Content-Type'] = value;
  1114. }
  1115. }
  1116. function getDefaultAdapter() {
  1117. var adapter;
  1118. if (typeof XMLHttpRequest !== 'undefined') {
  1119. // For browsers use XHR adapter
  1120. adapter = __webpack_require__(/*! ./adapters/xhr */ "./node_modules/axios/lib/adapters/xhr.js");
  1121. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  1122. // For node use HTTP adapter
  1123. adapter = __webpack_require__(/*! ./adapters/http */ "./node_modules/axios/lib/adapters/xhr.js");
  1124. }
  1125. return adapter;
  1126. }
  1127. function stringifySafely(rawValue, parser, encoder) {
  1128. if (utils.isString(rawValue)) {
  1129. try {
  1130. (parser || JSON.parse)(rawValue);
  1131. return utils.trim(rawValue);
  1132. } catch (e) {
  1133. if (e.name !== 'SyntaxError') {
  1134. throw e;
  1135. }
  1136. }
  1137. }
  1138. return (encoder || JSON.stringify)(rawValue);
  1139. }
  1140. var defaults = {
  1141. transitional: {
  1142. silentJSONParsing: true,
  1143. forcedJSONParsing: true,
  1144. clarifyTimeoutError: false
  1145. },
  1146. adapter: getDefaultAdapter(),
  1147. transformRequest: [function transformRequest(data, headers) {
  1148. normalizeHeaderName(headers, 'Accept');
  1149. normalizeHeaderName(headers, 'Content-Type');
  1150. if (utils.isFormData(data) ||
  1151. utils.isArrayBuffer(data) ||
  1152. utils.isBuffer(data) ||
  1153. utils.isStream(data) ||
  1154. utils.isFile(data) ||
  1155. utils.isBlob(data)
  1156. ) {
  1157. return data;
  1158. }
  1159. if (utils.isArrayBufferView(data)) {
  1160. return data.buffer;
  1161. }
  1162. if (utils.isURLSearchParams(data)) {
  1163. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  1164. return data.toString();
  1165. }
  1166. if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
  1167. setContentTypeIfUnset(headers, 'application/json');
  1168. return stringifySafely(data);
  1169. }
  1170. return data;
  1171. }],
  1172. transformResponse: [function transformResponse(data) {
  1173. var transitional = this.transitional;
  1174. var silentJSONParsing = transitional && transitional.silentJSONParsing;
  1175. var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
  1176. var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
  1177. if (strictJSONParsing || (forcedJSONParsing && utils.isString(data) && data.length)) {
  1178. try {
  1179. return JSON.parse(data);
  1180. } catch (e) {
  1181. if (strictJSONParsing) {
  1182. if (e.name === 'SyntaxError') {
  1183. throw enhanceError(e, this, 'E_JSON_PARSE');
  1184. }
  1185. throw e;
  1186. }
  1187. }
  1188. }
  1189. return data;
  1190. }],
  1191. /**
  1192. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  1193. * timeout is not created.
  1194. */
  1195. timeout: 0,
  1196. xsrfCookieName: 'XSRF-TOKEN',
  1197. xsrfHeaderName: 'X-XSRF-TOKEN',
  1198. maxContentLength: -1,
  1199. maxBodyLength: -1,
  1200. validateStatus: function validateStatus(status) {
  1201. return status >= 200 && status < 300;
  1202. }
  1203. };
  1204. defaults.headers = {
  1205. common: {
  1206. 'Accept': 'application/json, text/plain, */*'
  1207. }
  1208. };
  1209. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  1210. defaults.headers[method] = {};
  1211. });
  1212. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  1213. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  1214. });
  1215. module.exports = defaults;
  1216. /***/ }),
  1217. /***/ "./node_modules/axios/lib/helpers/bind.js":
  1218. /*!************************************************!*\
  1219. !*** ./node_modules/axios/lib/helpers/bind.js ***!
  1220. \************************************************/
  1221. /***/ ((module) => {
  1222. "use strict";
  1223. module.exports = function bind(fn, thisArg) {
  1224. return function wrap() {
  1225. var args = new Array(arguments.length);
  1226. for (var i = 0; i < args.length; i++) {
  1227. args[i] = arguments[i];
  1228. }
  1229. return fn.apply(thisArg, args);
  1230. };
  1231. };
  1232. /***/ }),
  1233. /***/ "./node_modules/axios/lib/helpers/buildURL.js":
  1234. /*!****************************************************!*\
  1235. !*** ./node_modules/axios/lib/helpers/buildURL.js ***!
  1236. \****************************************************/
  1237. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1238. "use strict";
  1239. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1240. function encode(val) {
  1241. return encodeURIComponent(val).
  1242. replace(/%3A/gi, ':').
  1243. replace(/%24/g, '$').
  1244. replace(/%2C/gi, ',').
  1245. replace(/%20/g, '+').
  1246. replace(/%5B/gi, '[').
  1247. replace(/%5D/gi, ']');
  1248. }
  1249. /**
  1250. * Build a URL by appending params to the end
  1251. *
  1252. * @param {string} url The base of the url (e.g., http://www.google.com)
  1253. * @param {object} [params] The params to be appended
  1254. * @returns {string} The formatted url
  1255. */
  1256. module.exports = function buildURL(url, params, paramsSerializer) {
  1257. /*eslint no-param-reassign:0*/
  1258. if (!params) {
  1259. return url;
  1260. }
  1261. var serializedParams;
  1262. if (paramsSerializer) {
  1263. serializedParams = paramsSerializer(params);
  1264. } else if (utils.isURLSearchParams(params)) {
  1265. serializedParams = params.toString();
  1266. } else {
  1267. var parts = [];
  1268. utils.forEach(params, function serialize(val, key) {
  1269. if (val === null || typeof val === 'undefined') {
  1270. return;
  1271. }
  1272. if (utils.isArray(val)) {
  1273. key = key + '[]';
  1274. } else {
  1275. val = [val];
  1276. }
  1277. utils.forEach(val, function parseValue(v) {
  1278. if (utils.isDate(v)) {
  1279. v = v.toISOString();
  1280. } else if (utils.isObject(v)) {
  1281. v = JSON.stringify(v);
  1282. }
  1283. parts.push(encode(key) + '=' + encode(v));
  1284. });
  1285. });
  1286. serializedParams = parts.join('&');
  1287. }
  1288. if (serializedParams) {
  1289. var hashmarkIndex = url.indexOf('#');
  1290. if (hashmarkIndex !== -1) {
  1291. url = url.slice(0, hashmarkIndex);
  1292. }
  1293. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  1294. }
  1295. return url;
  1296. };
  1297. /***/ }),
  1298. /***/ "./node_modules/axios/lib/helpers/combineURLs.js":
  1299. /*!*******************************************************!*\
  1300. !*** ./node_modules/axios/lib/helpers/combineURLs.js ***!
  1301. \*******************************************************/
  1302. /***/ ((module) => {
  1303. "use strict";
  1304. /**
  1305. * Creates a new URL by combining the specified URLs
  1306. *
  1307. * @param {string} baseURL The base URL
  1308. * @param {string} relativeURL The relative URL
  1309. * @returns {string} The combined URL
  1310. */
  1311. module.exports = function combineURLs(baseURL, relativeURL) {
  1312. return relativeURL
  1313. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  1314. : baseURL;
  1315. };
  1316. /***/ }),
  1317. /***/ "./node_modules/axios/lib/helpers/cookies.js":
  1318. /*!***************************************************!*\
  1319. !*** ./node_modules/axios/lib/helpers/cookies.js ***!
  1320. \***************************************************/
  1321. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1322. "use strict";
  1323. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1324. module.exports = (
  1325. utils.isStandardBrowserEnv() ?
  1326. // Standard browser envs support document.cookie
  1327. (function standardBrowserEnv() {
  1328. return {
  1329. write: function write(name, value, expires, path, domain, secure) {
  1330. var cookie = [];
  1331. cookie.push(name + '=' + encodeURIComponent(value));
  1332. if (utils.isNumber(expires)) {
  1333. cookie.push('expires=' + new Date(expires).toGMTString());
  1334. }
  1335. if (utils.isString(path)) {
  1336. cookie.push('path=' + path);
  1337. }
  1338. if (utils.isString(domain)) {
  1339. cookie.push('domain=' + domain);
  1340. }
  1341. if (secure === true) {
  1342. cookie.push('secure');
  1343. }
  1344. document.cookie = cookie.join('; ');
  1345. },
  1346. read: function read(name) {
  1347. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  1348. return (match ? decodeURIComponent(match[3]) : null);
  1349. },
  1350. remove: function remove(name) {
  1351. this.write(name, '', Date.now() - 86400000);
  1352. }
  1353. };
  1354. })() :
  1355. // Non standard browser env (web workers, react-native) lack needed support.
  1356. (function nonStandardBrowserEnv() {
  1357. return {
  1358. write: function write() {},
  1359. read: function read() { return null; },
  1360. remove: function remove() {}
  1361. };
  1362. })()
  1363. );
  1364. /***/ }),
  1365. /***/ "./node_modules/axios/lib/helpers/isAbsoluteURL.js":
  1366. /*!*********************************************************!*\
  1367. !*** ./node_modules/axios/lib/helpers/isAbsoluteURL.js ***!
  1368. \*********************************************************/
  1369. /***/ ((module) => {
  1370. "use strict";
  1371. /**
  1372. * Determines whether the specified URL is absolute
  1373. *
  1374. * @param {string} url The URL to test
  1375. * @returns {boolean} True if the specified URL is absolute, otherwise false
  1376. */
  1377. module.exports = function isAbsoluteURL(url) {
  1378. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  1379. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  1380. // by any combination of letters, digits, plus, period, or hyphen.
  1381. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  1382. };
  1383. /***/ }),
  1384. /***/ "./node_modules/axios/lib/helpers/isAxiosError.js":
  1385. /*!********************************************************!*\
  1386. !*** ./node_modules/axios/lib/helpers/isAxiosError.js ***!
  1387. \********************************************************/
  1388. /***/ ((module) => {
  1389. "use strict";
  1390. /**
  1391. * Determines whether the payload is an error thrown by Axios
  1392. *
  1393. * @param {*} payload The value to test
  1394. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  1395. */
  1396. module.exports = function isAxiosError(payload) {
  1397. return (typeof payload === 'object') && (payload.isAxiosError === true);
  1398. };
  1399. /***/ }),
  1400. /***/ "./node_modules/axios/lib/helpers/isURLSameOrigin.js":
  1401. /*!***********************************************************!*\
  1402. !*** ./node_modules/axios/lib/helpers/isURLSameOrigin.js ***!
  1403. \***********************************************************/
  1404. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1405. "use strict";
  1406. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1407. module.exports = (
  1408. utils.isStandardBrowserEnv() ?
  1409. // Standard browser envs have full support of the APIs needed to test
  1410. // whether the request URL is of the same origin as current location.
  1411. (function standardBrowserEnv() {
  1412. var msie = /(msie|trident)/i.test(navigator.userAgent);
  1413. var urlParsingNode = document.createElement('a');
  1414. var originURL;
  1415. /**
  1416. * Parse a URL to discover it's components
  1417. *
  1418. * @param {String} url The URL to be parsed
  1419. * @returns {Object}
  1420. */
  1421. function resolveURL(url) {
  1422. var href = url;
  1423. if (msie) {
  1424. // IE needs attribute set twice to normalize properties
  1425. urlParsingNode.setAttribute('href', href);
  1426. href = urlParsingNode.href;
  1427. }
  1428. urlParsingNode.setAttribute('href', href);
  1429. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  1430. return {
  1431. href: urlParsingNode.href,
  1432. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  1433. host: urlParsingNode.host,
  1434. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  1435. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  1436. hostname: urlParsingNode.hostname,
  1437. port: urlParsingNode.port,
  1438. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  1439. urlParsingNode.pathname :
  1440. '/' + urlParsingNode.pathname
  1441. };
  1442. }
  1443. originURL = resolveURL(window.location.href);
  1444. /**
  1445. * Determine if a URL shares the same origin as the current location
  1446. *
  1447. * @param {String} requestURL The URL to test
  1448. * @returns {boolean} True if URL shares the same origin, otherwise false
  1449. */
  1450. return function isURLSameOrigin(requestURL) {
  1451. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  1452. return (parsed.protocol === originURL.protocol &&
  1453. parsed.host === originURL.host);
  1454. };
  1455. })() :
  1456. // Non standard browser envs (web workers, react-native) lack needed support.
  1457. (function nonStandardBrowserEnv() {
  1458. return function isURLSameOrigin() {
  1459. return true;
  1460. };
  1461. })()
  1462. );
  1463. /***/ }),
  1464. /***/ "./node_modules/axios/lib/helpers/normalizeHeaderName.js":
  1465. /*!***************************************************************!*\
  1466. !*** ./node_modules/axios/lib/helpers/normalizeHeaderName.js ***!
  1467. \***************************************************************/
  1468. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1469. "use strict";
  1470. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  1471. module.exports = function normalizeHeaderName(headers, normalizedName) {
  1472. utils.forEach(headers, function processHeader(value, name) {
  1473. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  1474. headers[normalizedName] = value;
  1475. delete headers[name];
  1476. }
  1477. });
  1478. };
  1479. /***/ }),
  1480. /***/ "./node_modules/axios/lib/helpers/parseHeaders.js":
  1481. /*!********************************************************!*\
  1482. !*** ./node_modules/axios/lib/helpers/parseHeaders.js ***!
  1483. \********************************************************/
  1484. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1485. "use strict";
  1486. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1487. // Headers whose duplicates are ignored by node
  1488. // c.f. https://nodejs.org/api/http.html#http_message_headers
  1489. var ignoreDuplicateOf = [
  1490. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  1491. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  1492. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  1493. 'referer', 'retry-after', 'user-agent'
  1494. ];
  1495. /**
  1496. * Parse headers into an object
  1497. *
  1498. * ```
  1499. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  1500. * Content-Type: application/json
  1501. * Connection: keep-alive
  1502. * Transfer-Encoding: chunked
  1503. * ```
  1504. *
  1505. * @param {String} headers Headers needing to be parsed
  1506. * @returns {Object} Headers parsed into an object
  1507. */
  1508. module.exports = function parseHeaders(headers) {
  1509. var parsed = {};
  1510. var key;
  1511. var val;
  1512. var i;
  1513. if (!headers) { return parsed; }
  1514. utils.forEach(headers.split('\n'), function parser(line) {
  1515. i = line.indexOf(':');
  1516. key = utils.trim(line.substr(0, i)).toLowerCase();
  1517. val = utils.trim(line.substr(i + 1));
  1518. if (key) {
  1519. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  1520. return;
  1521. }
  1522. if (key === 'set-cookie') {
  1523. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  1524. } else {
  1525. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  1526. }
  1527. }
  1528. });
  1529. return parsed;
  1530. };
  1531. /***/ }),
  1532. /***/ "./node_modules/axios/lib/helpers/spread.js":
  1533. /*!**************************************************!*\
  1534. !*** ./node_modules/axios/lib/helpers/spread.js ***!
  1535. \**************************************************/
  1536. /***/ ((module) => {
  1537. "use strict";
  1538. /**
  1539. * Syntactic sugar for invoking a function and expanding an array for arguments.
  1540. *
  1541. * Common use case would be to use `Function.prototype.apply`.
  1542. *
  1543. * ```js
  1544. * function f(x, y, z) {}
  1545. * var args = [1, 2, 3];
  1546. * f.apply(null, args);
  1547. * ```
  1548. *
  1549. * With `spread` this example can be re-written.
  1550. *
  1551. * ```js
  1552. * spread(function(x, y, z) {})([1, 2, 3]);
  1553. * ```
  1554. *
  1555. * @param {Function} callback
  1556. * @returns {Function}
  1557. */
  1558. module.exports = function spread(callback) {
  1559. return function wrap(arr) {
  1560. return callback.apply(null, arr);
  1561. };
  1562. };
  1563. /***/ }),
  1564. /***/ "./node_modules/axios/lib/helpers/validator.js":
  1565. /*!*****************************************************!*\
  1566. !*** ./node_modules/axios/lib/helpers/validator.js ***!
  1567. \*****************************************************/
  1568. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1569. "use strict";
  1570. var pkg = __webpack_require__(/*! ./../../package.json */ "./node_modules/axios/package.json");
  1571. var validators = {};
  1572. // eslint-disable-next-line func-names
  1573. ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
  1574. validators[type] = function validator(thing) {
  1575. return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
  1576. };
  1577. });
  1578. var deprecatedWarnings = {};
  1579. var currentVerArr = pkg.version.split('.');
  1580. /**
  1581. * Compare package versions
  1582. * @param {string} version
  1583. * @param {string?} thanVersion
  1584. * @returns {boolean}
  1585. */
  1586. function isOlderVersion(version, thanVersion) {
  1587. var pkgVersionArr = thanVersion ? thanVersion.split('.') : currentVerArr;
  1588. var destVer = version.split('.');
  1589. for (var i = 0; i < 3; i++) {
  1590. if (pkgVersionArr[i] > destVer[i]) {
  1591. return true;
  1592. } else if (pkgVersionArr[i] < destVer[i]) {
  1593. return false;
  1594. }
  1595. }
  1596. return false;
  1597. }
  1598. /**
  1599. * Transitional option validator
  1600. * @param {function|boolean?} validator
  1601. * @param {string?} version
  1602. * @param {string} message
  1603. * @returns {function}
  1604. */
  1605. validators.transitional = function transitional(validator, version, message) {
  1606. var isDeprecated = version && isOlderVersion(version);
  1607. function formatMessage(opt, desc) {
  1608. return '[Axios v' + pkg.version + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
  1609. }
  1610. // eslint-disable-next-line func-names
  1611. return function(value, opt, opts) {
  1612. if (validator === false) {
  1613. throw new Error(formatMessage(opt, ' has been removed in ' + version));
  1614. }
  1615. if (isDeprecated && !deprecatedWarnings[opt]) {
  1616. deprecatedWarnings[opt] = true;
  1617. // eslint-disable-next-line no-console
  1618. console.warn(
  1619. formatMessage(
  1620. opt,
  1621. ' has been deprecated since v' + version + ' and will be removed in the near future'
  1622. )
  1623. );
  1624. }
  1625. return validator ? validator(value, opt, opts) : true;
  1626. };
  1627. };
  1628. /**
  1629. * Assert object's properties type
  1630. * @param {object} options
  1631. * @param {object} schema
  1632. * @param {boolean?} allowUnknown
  1633. */
  1634. function assertOptions(options, schema, allowUnknown) {
  1635. if (typeof options !== 'object') {
  1636. throw new TypeError('options must be an object');
  1637. }
  1638. var keys = Object.keys(options);
  1639. var i = keys.length;
  1640. while (i-- > 0) {
  1641. var opt = keys[i];
  1642. var validator = schema[opt];
  1643. if (validator) {
  1644. var value = options[opt];
  1645. var result = value === undefined || validator(value, opt, options);
  1646. if (result !== true) {
  1647. throw new TypeError('option ' + opt + ' must be ' + result);
  1648. }
  1649. continue;
  1650. }
  1651. if (allowUnknown !== true) {
  1652. throw Error('Unknown option ' + opt);
  1653. }
  1654. }
  1655. }
  1656. module.exports = {
  1657. isOlderVersion: isOlderVersion,
  1658. assertOptions: assertOptions,
  1659. validators: validators
  1660. };
  1661. /***/ }),
  1662. /***/ "./node_modules/axios/lib/utils.js":
  1663. /*!*****************************************!*\
  1664. !*** ./node_modules/axios/lib/utils.js ***!
  1665. \*****************************************/
  1666. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1667. "use strict";
  1668. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  1669. // utils is a library of generic helper functions non-specific to axios
  1670. var toString = Object.prototype.toString;
  1671. /**
  1672. * Determine if a value is an Array
  1673. *
  1674. * @param {Object} val The value to test
  1675. * @returns {boolean} True if value is an Array, otherwise false
  1676. */
  1677. function isArray(val) {
  1678. return toString.call(val) === '[object Array]';
  1679. }
  1680. /**
  1681. * Determine if a value is undefined
  1682. *
  1683. * @param {Object} val The value to test
  1684. * @returns {boolean} True if the value is undefined, otherwise false
  1685. */
  1686. function isUndefined(val) {
  1687. return typeof val === 'undefined';
  1688. }
  1689. /**
  1690. * Determine if a value is a Buffer
  1691. *
  1692. * @param {Object} val The value to test
  1693. * @returns {boolean} True if value is a Buffer, otherwise false
  1694. */
  1695. function isBuffer(val) {
  1696. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  1697. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  1698. }
  1699. /**
  1700. * Determine if a value is an ArrayBuffer
  1701. *
  1702. * @param {Object} val The value to test
  1703. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  1704. */
  1705. function isArrayBuffer(val) {
  1706. return toString.call(val) === '[object ArrayBuffer]';
  1707. }
  1708. /**
  1709. * Determine if a value is a FormData
  1710. *
  1711. * @param {Object} val The value to test
  1712. * @returns {boolean} True if value is an FormData, otherwise false
  1713. */
  1714. function isFormData(val) {
  1715. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  1716. }
  1717. /**
  1718. * Determine if a value is a view on an ArrayBuffer
  1719. *
  1720. * @param {Object} val The value to test
  1721. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  1722. */
  1723. function isArrayBufferView(val) {
  1724. var result;
  1725. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  1726. result = ArrayBuffer.isView(val);
  1727. } else {
  1728. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  1729. }
  1730. return result;
  1731. }
  1732. /**
  1733. * Determine if a value is a String
  1734. *
  1735. * @param {Object} val The value to test
  1736. * @returns {boolean} True if value is a String, otherwise false
  1737. */
  1738. function isString(val) {
  1739. return typeof val === 'string';
  1740. }
  1741. /**
  1742. * Determine if a value is a Number
  1743. *
  1744. * @param {Object} val The value to test
  1745. * @returns {boolean} True if value is a Number, otherwise false
  1746. */
  1747. function isNumber(val) {
  1748. return typeof val === 'number';
  1749. }
  1750. /**
  1751. * Determine if a value is an Object
  1752. *
  1753. * @param {Object} val The value to test
  1754. * @returns {boolean} True if value is an Object, otherwise false
  1755. */
  1756. function isObject(val) {
  1757. return val !== null && typeof val === 'object';
  1758. }
  1759. /**
  1760. * Determine if a value is a plain Object
  1761. *
  1762. * @param {Object} val The value to test
  1763. * @return {boolean} True if value is a plain Object, otherwise false
  1764. */
  1765. function isPlainObject(val) {
  1766. if (toString.call(val) !== '[object Object]') {
  1767. return false;
  1768. }
  1769. var prototype = Object.getPrototypeOf(val);
  1770. return prototype === null || prototype === Object.prototype;
  1771. }
  1772. /**
  1773. * Determine if a value is a Date
  1774. *
  1775. * @param {Object} val The value to test
  1776. * @returns {boolean} True if value is a Date, otherwise false
  1777. */
  1778. function isDate(val) {
  1779. return toString.call(val) === '[object Date]';
  1780. }
  1781. /**
  1782. * Determine if a value is a File
  1783. *
  1784. * @param {Object} val The value to test
  1785. * @returns {boolean} True if value is a File, otherwise false
  1786. */
  1787. function isFile(val) {
  1788. return toString.call(val) === '[object File]';
  1789. }
  1790. /**
  1791. * Determine if a value is a Blob
  1792. *
  1793. * @param {Object} val The value to test
  1794. * @returns {boolean} True if value is a Blob, otherwise false
  1795. */
  1796. function isBlob(val) {
  1797. return toString.call(val) === '[object Blob]';
  1798. }
  1799. /**
  1800. * Determine if a value is a Function
  1801. *
  1802. * @param {Object} val The value to test
  1803. * @returns {boolean} True if value is a Function, otherwise false
  1804. */
  1805. function isFunction(val) {
  1806. return toString.call(val) === '[object Function]';
  1807. }
  1808. /**
  1809. * Determine if a value is a Stream
  1810. *
  1811. * @param {Object} val The value to test
  1812. * @returns {boolean} True if value is a Stream, otherwise false
  1813. */
  1814. function isStream(val) {
  1815. return isObject(val) && isFunction(val.pipe);
  1816. }
  1817. /**
  1818. * Determine if a value is a URLSearchParams object
  1819. *
  1820. * @param {Object} val The value to test
  1821. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  1822. */
  1823. function isURLSearchParams(val) {
  1824. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  1825. }
  1826. /**
  1827. * Trim excess whitespace off the beginning and end of a string
  1828. *
  1829. * @param {String} str The String to trim
  1830. * @returns {String} The String freed of excess whitespace
  1831. */
  1832. function trim(str) {
  1833. return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
  1834. }
  1835. /**
  1836. * Determine if we're running in a standard browser environment
  1837. *
  1838. * This allows axios to run in a web worker, and react-native.
  1839. * Both environments support XMLHttpRequest, but not fully standard globals.
  1840. *
  1841. * web workers:
  1842. * typeof window -> undefined
  1843. * typeof document -> undefined
  1844. *
  1845. * react-native:
  1846. * navigator.product -> 'ReactNative'
  1847. * nativescript
  1848. * navigator.product -> 'NativeScript' or 'NS'
  1849. */
  1850. function isStandardBrowserEnv() {
  1851. if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
  1852. navigator.product === 'NativeScript' ||
  1853. navigator.product === 'NS')) {
  1854. return false;
  1855. }
  1856. return (
  1857. typeof window !== 'undefined' &&
  1858. typeof document !== 'undefined'
  1859. );
  1860. }
  1861. /**
  1862. * Iterate over an Array or an Object invoking a function for each item.
  1863. *
  1864. * If `obj` is an Array callback will be called passing
  1865. * the value, index, and complete array for each item.
  1866. *
  1867. * If 'obj' is an Object callback will be called passing
  1868. * the value, key, and complete object for each property.
  1869. *
  1870. * @param {Object|Array} obj The object to iterate
  1871. * @param {Function} fn The callback to invoke for each item
  1872. */
  1873. function forEach(obj, fn) {
  1874. // Don't bother if no value provided
  1875. if (obj === null || typeof obj === 'undefined') {
  1876. return;
  1877. }
  1878. // Force an array if not already something iterable
  1879. if (typeof obj !== 'object') {
  1880. /*eslint no-param-reassign:0*/
  1881. obj = [obj];
  1882. }
  1883. if (isArray(obj)) {
  1884. // Iterate over array values
  1885. for (var i = 0, l = obj.length; i < l; i++) {
  1886. fn.call(null, obj[i], i, obj);
  1887. }
  1888. } else {
  1889. // Iterate over object keys
  1890. for (var key in obj) {
  1891. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  1892. fn.call(null, obj[key], key, obj);
  1893. }
  1894. }
  1895. }
  1896. }
  1897. /**
  1898. * Accepts varargs expecting each argument to be an object, then
  1899. * immutably merges the properties of each object and returns result.
  1900. *
  1901. * When multiple objects contain the same key the later object in
  1902. * the arguments list will take precedence.
  1903. *
  1904. * Example:
  1905. *
  1906. * ```js
  1907. * var result = merge({foo: 123}, {foo: 456});
  1908. * console.log(result.foo); // outputs 456
  1909. * ```
  1910. *
  1911. * @param {Object} obj1 Object to merge
  1912. * @returns {Object} Result of all merge properties
  1913. */
  1914. function merge(/* obj1, obj2, obj3, ... */) {
  1915. var result = {};
  1916. function assignValue(val, key) {
  1917. if (isPlainObject(result[key]) && isPlainObject(val)) {
  1918. result[key] = merge(result[key], val);
  1919. } else if (isPlainObject(val)) {
  1920. result[key] = merge({}, val);
  1921. } else if (isArray(val)) {
  1922. result[key] = val.slice();
  1923. } else {
  1924. result[key] = val;
  1925. }
  1926. }
  1927. for (var i = 0, l = arguments.length; i < l; i++) {
  1928. forEach(arguments[i], assignValue);
  1929. }
  1930. return result;
  1931. }
  1932. /**
  1933. * Extends object a by mutably adding to it the properties of object b.
  1934. *
  1935. * @param {Object} a The object to be extended
  1936. * @param {Object} b The object to copy properties from
  1937. * @param {Object} thisArg The object to bind function to
  1938. * @return {Object} The resulting value of object a
  1939. */
  1940. function extend(a, b, thisArg) {
  1941. forEach(b, function assignValue(val, key) {
  1942. if (thisArg && typeof val === 'function') {
  1943. a[key] = bind(val, thisArg);
  1944. } else {
  1945. a[key] = val;
  1946. }
  1947. });
  1948. return a;
  1949. }
  1950. /**
  1951. * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  1952. *
  1953. * @param {string} content with BOM
  1954. * @return {string} content value without BOM
  1955. */
  1956. function stripBOM(content) {
  1957. if (content.charCodeAt(0) === 0xFEFF) {
  1958. content = content.slice(1);
  1959. }
  1960. return content;
  1961. }
  1962. module.exports = {
  1963. isArray: isArray,
  1964. isArrayBuffer: isArrayBuffer,
  1965. isBuffer: isBuffer,
  1966. isFormData: isFormData,
  1967. isArrayBufferView: isArrayBufferView,
  1968. isString: isString,
  1969. isNumber: isNumber,
  1970. isObject: isObject,
  1971. isPlainObject: isPlainObject,
  1972. isUndefined: isUndefined,
  1973. isDate: isDate,
  1974. isFile: isFile,
  1975. isBlob: isBlob,
  1976. isFunction: isFunction,
  1977. isStream: isStream,
  1978. isURLSearchParams: isURLSearchParams,
  1979. isStandardBrowserEnv: isStandardBrowserEnv,
  1980. forEach: forEach,
  1981. merge: merge,
  1982. extend: extend,
  1983. trim: trim,
  1984. stripBOM: stripBOM
  1985. };
  1986. /***/ }),
  1987. /***/ "./resources/js/FormValidator.js":
  1988. /*!***************************************!*\
  1989. !*** ./resources/js/FormValidator.js ***!
  1990. \***************************************/
  1991. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  1992. "use strict";
  1993. __webpack_require__.r(__webpack_exports__);
  1994. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1995. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  1996. /* harmony export */ });
  1997. /* harmony import */ var validate_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! validate.js */ "./node_modules/validate.js/validate.js");
  1998. /* harmony import */ var validate_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(validate_js__WEBPACK_IMPORTED_MODULE_0__);
  1999. /* harmony import */ var form_serialize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! form-serialize */ "./node_modules/form-serialize/index.js");
  2000. /* harmony import */ var form_serialize__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(form_serialize__WEBPACK_IMPORTED_MODULE_1__);
  2001. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2002. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2003. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2004. /**
  2005. * Form Validator with RiotJS Components
  2006. *
  2007. *
  2008. *
  2009. *
  2010. */
  2011. var FormValidator = /*#__PURE__*/function () {
  2012. /**
  2013. *
  2014. * @param {[type]} formSelector [description]
  2015. * @param {[type]} constraits [description]
  2016. */
  2017. function FormValidator(formSelector, constraits, onSuccess) {
  2018. var _this = this;
  2019. _classCallCheck(this, FormValidator);
  2020. // getting selector to find form-element
  2021. this.formSelector = formSelector; // constraits for validate.js
  2022. this.constraits = constraits; // get form and elements
  2023. this.form = document.querySelector(this.formSelector);
  2024. if (!this.form) {
  2025. console.error('FormValidator: form not found, querySelector not found "' + this.formSelector + '"');
  2026. }
  2027. this.elements = this.form.querySelectorAll('field-error'); // adding submit event
  2028. this.form.addEventListener('submit', function (event) {
  2029. _this.onSubmit(event);
  2030. }); // adding event if a element is updated
  2031. this.form.addEventListener('field-update', function (event) {
  2032. _this.onFieldUpdate(event);
  2033. });
  2034. this.onSuccess = onSuccess;
  2035. }
  2036. /**
  2037. *
  2038. *
  2039. */
  2040. _createClass(FormValidator, [{
  2041. key: "setConstraits",
  2042. value: function setConstraits(constraits) {
  2043. this.constraits = constraits;
  2044. }
  2045. /**
  2046. *
  2047. *
  2048. */
  2049. }, {
  2050. key: "getConstraits",
  2051. value: function getConstraits(constraits) {
  2052. return this.constraits;
  2053. }
  2054. /**
  2055. *
  2056. * @param {[type]} event [description]
  2057. * @return {[type]} [description]
  2058. */
  2059. }, {
  2060. key: "onSubmit",
  2061. value: function onSubmit(event) {
  2062. var _this2 = this;
  2063. event.preventDefault();
  2064. console.log(this.constraits, event.target, form_serialize__WEBPACK_IMPORTED_MODULE_1___default()(event.target, {
  2065. hash: true
  2066. }));
  2067. var errors = validate_js__WEBPACK_IMPORTED_MODULE_0___default().async(form_serialize__WEBPACK_IMPORTED_MODULE_1___default()(event.target, {
  2068. hash: true
  2069. }), this.constraits, {
  2070. fullMessages: false
  2071. }).then(function () {
  2072. _this2.onSuccess(event, form_serialize__WEBPACK_IMPORTED_MODULE_1___default()(event.target, {
  2073. hash: true
  2074. }));
  2075. }, function (errors) {
  2076. // send each element a event
  2077. _this2.elements.forEach(function (element) {
  2078. var elementErrors = false; // check for errors by name
  2079. if (errors[element.attributes.name.nodeValue]) {
  2080. elementErrors = errors[element.attributes.name.nodeValue];
  2081. }
  2082. _this2.dispatchCustomEvent(elementErrors, element);
  2083. });
  2084. });
  2085. }
  2086. /**
  2087. *
  2088. *
  2089. * @param {Event} event
  2090. *
  2091. */
  2092. }, {
  2093. key: "onFieldUpdate",
  2094. value: function onFieldUpdate(event) {
  2095. var _this3 = this;
  2096. // workaround, make sure that value for single is undefined if it is empty
  2097. if (event.detail.value == '') {
  2098. event.detail.value = undefined;
  2099. }
  2100. var errors = validate_js__WEBPACK_IMPORTED_MODULE_0___default().single(event.detail.value, this.constraits[event.detail.name]); // search for element by name and dispatch event
  2101. this.elements.forEach(function (element) {
  2102. if (element.attributes.name.nodeValue == event.detail.name) {
  2103. _this3.dispatchCustomEvent(errors, element);
  2104. }
  2105. });
  2106. }
  2107. /**
  2108. * dispatch event to single element
  2109. *
  2110. * @param {Array} errors
  2111. * @param {Element} element
  2112. *
  2113. */
  2114. }, {
  2115. key: "dispatchCustomEvent",
  2116. value: function dispatchCustomEvent(errors, element) {
  2117. var detail = false;
  2118. if (errors) {
  2119. detail = errors;
  2120. }
  2121. var formValidationEvent = new CustomEvent('form-validation', {
  2122. 'detail': detail
  2123. });
  2124. element.dispatchEvent(formValidationEvent);
  2125. }
  2126. }]);
  2127. return FormValidator;
  2128. }();
  2129. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FormValidator);
  2130. /***/ }),
  2131. /***/ "./node_modules/form-serialize/index.js":
  2132. /*!**********************************************!*\
  2133. !*** ./node_modules/form-serialize/index.js ***!
  2134. \**********************************************/
  2135. /***/ ((module) => {
  2136. // get successful control from form and assemble into object
  2137. // http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2
  2138. // types which indicate a submit action and are not successful controls
  2139. // these will be ignored
  2140. var k_r_submitter = /^(?:submit|button|image|reset|file)$/i;
  2141. // node names which could be successful controls
  2142. var k_r_success_contrls = /^(?:input|select|textarea|keygen)/i;
  2143. // Matches bracket notation.
  2144. var brackets = /(\[[^\[\]]*\])/g;
  2145. // serializes form fields
  2146. // @param form MUST be an HTMLForm element
  2147. // @param options is an optional argument to configure the serialization. Default output
  2148. // with no options specified is a url encoded string
  2149. // - hash: [true | false] Configure the output type. If true, the output will
  2150. // be a js object.
  2151. // - serializer: [function] Optional serializer function to override the default one.
  2152. // The function takes 3 arguments (result, key, value) and should return new result
  2153. // hash and url encoded str serializers are provided with this module
  2154. // - disabled: [true | false]. If true serialize disabled fields.
  2155. // - empty: [true | false]. If true serialize empty fields
  2156. function serialize(form, options) {
  2157. if (typeof options != 'object') {
  2158. options = { hash: !!options };
  2159. }
  2160. else if (options.hash === undefined) {
  2161. options.hash = true;
  2162. }
  2163. var result = (options.hash) ? {} : '';
  2164. var serializer = options.serializer || ((options.hash) ? hash_serializer : str_serialize);
  2165. var elements = form && form.elements ? form.elements : [];
  2166. //Object store each radio and set if it's empty or not
  2167. var radio_store = Object.create(null);
  2168. for (var i=0 ; i<elements.length ; ++i) {
  2169. var element = elements[i];
  2170. // ingore disabled fields
  2171. if ((!options.disabled && element.disabled) || !element.name) {
  2172. continue;
  2173. }
  2174. // ignore anyhting that is not considered a success field
  2175. if (!k_r_success_contrls.test(element.nodeName) ||
  2176. k_r_submitter.test(element.type)) {
  2177. continue;
  2178. }
  2179. var key = element.name;
  2180. var val = element.value;
  2181. // we can't just use element.value for checkboxes cause some browsers lie to us
  2182. // they say "on" for value when the box isn't checked
  2183. if ((element.type === 'checkbox' || element.type === 'radio') && !element.checked) {
  2184. val = undefined;
  2185. }
  2186. // If we want empty elements
  2187. if (options.empty) {
  2188. // for checkbox
  2189. if (element.type === 'checkbox' && !element.checked) {
  2190. val = '';
  2191. }
  2192. // for radio
  2193. if (element.type === 'radio') {
  2194. if (!radio_store[element.name] && !element.checked) {
  2195. radio_store[element.name] = false;
  2196. }
  2197. else if (element.checked) {
  2198. radio_store[element.name] = true;
  2199. }
  2200. }
  2201. // if options empty is true, continue only if its radio
  2202. if (val == undefined && element.type == 'radio') {
  2203. continue;
  2204. }
  2205. }
  2206. else {
  2207. // value-less fields are ignored unless options.empty is true
  2208. if (!val) {
  2209. continue;
  2210. }
  2211. }
  2212. // multi select boxes
  2213. if (element.type === 'select-multiple') {
  2214. val = [];
  2215. var selectOptions = element.options;
  2216. var isSelectedOptions = false;
  2217. for (var j=0 ; j<selectOptions.length ; ++j) {
  2218. var option = selectOptions[j];
  2219. var allowedEmpty = options.empty && !option.value;
  2220. var hasValue = (option.value || allowedEmpty);
  2221. if (option.selected && hasValue) {
  2222. isSelectedOptions = true;
  2223. // If using a hash serializer be sure to add the
  2224. // correct notation for an array in the multi-select
  2225. // context. Here the name attribute on the select element
  2226. // might be missing the trailing bracket pair. Both names
  2227. // "foo" and "foo[]" should be arrays.
  2228. if (options.hash && key.slice(key.length - 2) !== '[]') {
  2229. result = serializer(result, key + '[]', option.value);
  2230. }
  2231. else {
  2232. result = serializer(result, key, option.value);
  2233. }
  2234. }
  2235. }
  2236. // Serialize if no selected options and options.empty is true
  2237. if (!isSelectedOptions && options.empty) {
  2238. result = serializer(result, key, '');
  2239. }
  2240. continue;
  2241. }
  2242. result = serializer(result, key, val);
  2243. }
  2244. // Check for all empty radio buttons and serialize them with key=""
  2245. if (options.empty) {
  2246. for (var key in radio_store) {
  2247. if (!radio_store[key]) {
  2248. result = serializer(result, key, '');
  2249. }
  2250. }
  2251. }
  2252. return result;
  2253. }
  2254. function parse_keys(string) {
  2255. var keys = [];
  2256. var prefix = /^([^\[\]]*)/;
  2257. var children = new RegExp(brackets);
  2258. var match = prefix.exec(string);
  2259. if (match[1]) {
  2260. keys.push(match[1]);
  2261. }
  2262. while ((match = children.exec(string)) !== null) {
  2263. keys.push(match[1]);
  2264. }
  2265. return keys;
  2266. }
  2267. function hash_assign(result, keys, value) {
  2268. if (keys.length === 0) {
  2269. result = value;
  2270. return result;
  2271. }
  2272. var key = keys.shift();
  2273. var between = key.match(/^\[(.+?)\]$/);
  2274. if (key === '[]') {
  2275. result = result || [];
  2276. if (Array.isArray(result)) {
  2277. result.push(hash_assign(null, keys, value));
  2278. }
  2279. else {
  2280. // This might be the result of bad name attributes like "[][foo]",
  2281. // in this case the original `result` object will already be
  2282. // assigned to an object literal. Rather than coerce the object to
  2283. // an array, or cause an exception the attribute "_values" is
  2284. // assigned as an array.
  2285. result._values = result._values || [];
  2286. result._values.push(hash_assign(null, keys, value));
  2287. }
  2288. return result;
  2289. }
  2290. // Key is an attribute name and can be assigned directly.
  2291. if (!between) {
  2292. result[key] = hash_assign(result[key], keys, value);
  2293. }
  2294. else {
  2295. var string = between[1];
  2296. // +var converts the variable into a number
  2297. // better than parseInt because it doesn't truncate away trailing
  2298. // letters and actually fails if whole thing is not a number
  2299. var index = +string;
  2300. // If the characters between the brackets is not a number it is an
  2301. // attribute name and can be assigned directly.
  2302. if (isNaN(index)) {
  2303. result = result || {};
  2304. result[string] = hash_assign(result[string], keys, value);
  2305. }
  2306. else {
  2307. result = result || [];
  2308. result[index] = hash_assign(result[index], keys, value);
  2309. }
  2310. }
  2311. return result;
  2312. }
  2313. // Object/hash encoding serializer.
  2314. function hash_serializer(result, key, value) {
  2315. var matches = key.match(brackets);
  2316. // Has brackets? Use the recursive assignment function to walk the keys,
  2317. // construct any missing objects in the result tree and make the assignment
  2318. // at the end of the chain.
  2319. if (matches) {
  2320. var keys = parse_keys(key);
  2321. hash_assign(result, keys, value);
  2322. }
  2323. else {
  2324. // Non bracket notation can make assignments directly.
  2325. var existing = result[key];
  2326. // If the value has been assigned already (for instance when a radio and
  2327. // a checkbox have the same name attribute) convert the previous value
  2328. // into an array before pushing into it.
  2329. //
  2330. // NOTE: If this requirement were removed all hash creation and
  2331. // assignment could go through `hash_assign`.
  2332. if (existing) {
  2333. if (!Array.isArray(existing)) {
  2334. result[key] = [ existing ];
  2335. }
  2336. result[key].push(value);
  2337. }
  2338. else {
  2339. result[key] = value;
  2340. }
  2341. }
  2342. return result;
  2343. }
  2344. // urlform encoding serializer
  2345. function str_serialize(result, key, value) {
  2346. // encode newlines as \r\n cause the html spec says so
  2347. value = value.replace(/(\r)?\n/g, '\r\n');
  2348. value = encodeURIComponent(value);
  2349. // spaces should be '+' rather than '%20'.
  2350. value = value.replace(/%20/g, '+');
  2351. return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value;
  2352. }
  2353. module.exports = serialize;
  2354. /***/ }),
  2355. /***/ "./node_modules/process/browser.js":
  2356. /*!*****************************************!*\
  2357. !*** ./node_modules/process/browser.js ***!
  2358. \*****************************************/
  2359. /***/ ((module) => {
  2360. // shim for using process in browser
  2361. var process = module.exports = {};
  2362. // cached from whatever global is present so that test runners that stub it
  2363. // don't break things. But we need to wrap it in a try catch in case it is
  2364. // wrapped in strict mode code which doesn't define any globals. It's inside a
  2365. // function because try/catches deoptimize in certain engines.
  2366. var cachedSetTimeout;
  2367. var cachedClearTimeout;
  2368. function defaultSetTimout() {
  2369. throw new Error('setTimeout has not been defined');
  2370. }
  2371. function defaultClearTimeout () {
  2372. throw new Error('clearTimeout has not been defined');
  2373. }
  2374. (function () {
  2375. try {
  2376. if (typeof setTimeout === 'function') {
  2377. cachedSetTimeout = setTimeout;
  2378. } else {
  2379. cachedSetTimeout = defaultSetTimout;
  2380. }
  2381. } catch (e) {
  2382. cachedSetTimeout = defaultSetTimout;
  2383. }
  2384. try {
  2385. if (typeof clearTimeout === 'function') {
  2386. cachedClearTimeout = clearTimeout;
  2387. } else {
  2388. cachedClearTimeout = defaultClearTimeout;
  2389. }
  2390. } catch (e) {
  2391. cachedClearTimeout = defaultClearTimeout;
  2392. }
  2393. } ())
  2394. function runTimeout(fun) {
  2395. if (cachedSetTimeout === setTimeout) {
  2396. //normal enviroments in sane situations
  2397. return setTimeout(fun, 0);
  2398. }
  2399. // if setTimeout wasn't available but was latter defined
  2400. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  2401. cachedSetTimeout = setTimeout;
  2402. return setTimeout(fun, 0);
  2403. }
  2404. try {
  2405. // when when somebody has screwed with setTimeout but no I.E. maddness
  2406. return cachedSetTimeout(fun, 0);
  2407. } catch(e){
  2408. try {
  2409. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2410. return cachedSetTimeout.call(null, fun, 0);
  2411. } catch(e){
  2412. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  2413. return cachedSetTimeout.call(this, fun, 0);
  2414. }
  2415. }
  2416. }
  2417. function runClearTimeout(marker) {
  2418. if (cachedClearTimeout === clearTimeout) {
  2419. //normal enviroments in sane situations
  2420. return clearTimeout(marker);
  2421. }
  2422. // if clearTimeout wasn't available but was latter defined
  2423. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  2424. cachedClearTimeout = clearTimeout;
  2425. return clearTimeout(marker);
  2426. }
  2427. try {
  2428. // when when somebody has screwed with setTimeout but no I.E. maddness
  2429. return cachedClearTimeout(marker);
  2430. } catch (e){
  2431. try {
  2432. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2433. return cachedClearTimeout.call(null, marker);
  2434. } catch (e){
  2435. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  2436. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  2437. return cachedClearTimeout.call(this, marker);
  2438. }
  2439. }
  2440. }
  2441. var queue = [];
  2442. var draining = false;
  2443. var currentQueue;
  2444. var queueIndex = -1;
  2445. function cleanUpNextTick() {
  2446. if (!draining || !currentQueue) {
  2447. return;
  2448. }
  2449. draining = false;
  2450. if (currentQueue.length) {
  2451. queue = currentQueue.concat(queue);
  2452. } else {
  2453. queueIndex = -1;
  2454. }
  2455. if (queue.length) {
  2456. drainQueue();
  2457. }
  2458. }
  2459. function drainQueue() {
  2460. if (draining) {
  2461. return;
  2462. }
  2463. var timeout = runTimeout(cleanUpNextTick);
  2464. draining = true;
  2465. var len = queue.length;
  2466. while(len) {
  2467. currentQueue = queue;
  2468. queue = [];
  2469. while (++queueIndex < len) {
  2470. if (currentQueue) {
  2471. currentQueue[queueIndex].run();
  2472. }
  2473. }
  2474. queueIndex = -1;
  2475. len = queue.length;
  2476. }
  2477. currentQueue = null;
  2478. draining = false;
  2479. runClearTimeout(timeout);
  2480. }
  2481. process.nextTick = function (fun) {
  2482. var args = new Array(arguments.length - 1);
  2483. if (arguments.length > 1) {
  2484. for (var i = 1; i < arguments.length; i++) {
  2485. args[i - 1] = arguments[i];
  2486. }
  2487. }
  2488. queue.push(new Item(fun, args));
  2489. if (queue.length === 1 && !draining) {
  2490. runTimeout(drainQueue);
  2491. }
  2492. };
  2493. // v8 likes predictible objects
  2494. function Item(fun, array) {
  2495. this.fun = fun;
  2496. this.array = array;
  2497. }
  2498. Item.prototype.run = function () {
  2499. this.fun.apply(null, this.array);
  2500. };
  2501. process.title = 'browser';
  2502. process.browser = true;
  2503. process.env = {};
  2504. process.argv = [];
  2505. process.version = ''; // empty string to avoid regexp issues
  2506. process.versions = {};
  2507. function noop() {}
  2508. process.on = noop;
  2509. process.addListener = noop;
  2510. process.once = noop;
  2511. process.off = noop;
  2512. process.removeListener = noop;
  2513. process.removeAllListeners = noop;
  2514. process.emit = noop;
  2515. process.prependListener = noop;
  2516. process.prependOnceListener = noop;
  2517. process.listeners = function (name) { return [] }
  2518. process.binding = function (name) {
  2519. throw new Error('process.binding is not supported');
  2520. };
  2521. process.cwd = function () { return '/' };
  2522. process.chdir = function (dir) {
  2523. throw new Error('process.chdir is not supported');
  2524. };
  2525. process.umask = function() { return 0; };
  2526. /***/ }),
  2527. /***/ "./node_modules/riot/riot.esm.js":
  2528. /*!***************************************!*\
  2529. !*** ./node_modules/riot/riot.esm.js ***!
  2530. \***************************************/
  2531. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  2532. "use strict";
  2533. __webpack_require__.r(__webpack_exports__);
  2534. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2535. /* harmony export */ "__": () => (/* binding */ __),
  2536. /* harmony export */ "component": () => (/* binding */ component),
  2537. /* harmony export */ "install": () => (/* binding */ install),
  2538. /* harmony export */ "mount": () => (/* binding */ mount),
  2539. /* harmony export */ "pure": () => (/* binding */ pure),
  2540. /* harmony export */ "register": () => (/* binding */ register),
  2541. /* harmony export */ "uninstall": () => (/* binding */ uninstall),
  2542. /* harmony export */ "unmount": () => (/* binding */ unmount),
  2543. /* harmony export */ "unregister": () => (/* binding */ unregister),
  2544. /* harmony export */ "version": () => (/* binding */ version),
  2545. /* harmony export */ "withTypes": () => (/* binding */ withTypes)
  2546. /* harmony export */ });
  2547. /* Riot v6.0.3, @license MIT */
  2548. /**
  2549. * Convert a string from camel case to dash-case
  2550. * @param {string} string - probably a component tag name
  2551. * @returns {string} component name normalized
  2552. */
  2553. function camelToDashCase(string) {
  2554. return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  2555. }
  2556. /**
  2557. * Convert a string containing dashes to camel case
  2558. * @param {string} string - input string
  2559. * @returns {string} my-string -> myString
  2560. */
  2561. function dashToCamelCase(string) {
  2562. return string.replace(/-(\w)/g, (_, c) => c.toUpperCase());
  2563. }
  2564. /**
  2565. * Get all the element attributes as object
  2566. * @param {HTMLElement} element - DOM node we want to parse
  2567. * @returns {Object} all the attributes found as a key value pairs
  2568. */
  2569. function DOMattributesToObject(element) {
  2570. return Array.from(element.attributes).reduce((acc, attribute) => {
  2571. acc[dashToCamelCase(attribute.name)] = attribute.value;
  2572. return acc;
  2573. }, {});
  2574. }
  2575. /**
  2576. * Move all the child nodes from a source tag to another
  2577. * @param {HTMLElement} source - source node
  2578. * @param {HTMLElement} target - target node
  2579. * @returns {undefined} it's a void method ¯\_()_/¯
  2580. */
  2581. // Ignore this helper because it's needed only for svg tags
  2582. function moveChildren(source, target) {
  2583. if (source.firstChild) {
  2584. target.appendChild(source.firstChild);
  2585. moveChildren(source, target);
  2586. }
  2587. }
  2588. /**
  2589. * Remove the child nodes from any DOM node
  2590. * @param {HTMLElement} node - target node
  2591. * @returns {undefined}
  2592. */
  2593. function cleanNode(node) {
  2594. clearChildren(node.childNodes);
  2595. }
  2596. /**
  2597. * Clear multiple children in a node
  2598. * @param {HTMLElement[]} children - direct children nodes
  2599. * @returns {undefined}
  2600. */
  2601. function clearChildren(children) {
  2602. Array.from(children).forEach(removeChild);
  2603. }
  2604. /**
  2605. * Remove a node
  2606. * @param {HTMLElement}node - node to remove
  2607. * @returns {undefined}
  2608. */
  2609. const removeChild = node => node && node.parentNode && node.parentNode.removeChild(node);
  2610. /**
  2611. * Insert before a node
  2612. * @param {HTMLElement} newNode - node to insert
  2613. * @param {HTMLElement} refNode - ref child
  2614. * @returns {undefined}
  2615. */
  2616. const insertBefore = (newNode, refNode) => refNode && refNode.parentNode && refNode.parentNode.insertBefore(newNode, refNode);
  2617. /**
  2618. * Replace a node
  2619. * @param {HTMLElement} newNode - new node to add to the DOM
  2620. * @param {HTMLElement} replaced - node to replace
  2621. * @returns {undefined}
  2622. */
  2623. const replaceChild = (newNode, replaced) => replaced && replaced.parentNode && replaced.parentNode.replaceChild(newNode, replaced);
  2624. // Riot.js constants that can be used accross more modules
  2625. const COMPONENTS_IMPLEMENTATION_MAP$1 = new Map(),
  2626. DOM_COMPONENT_INSTANCE_PROPERTY$1 = Symbol('riot-component'),
  2627. PLUGINS_SET$1 = new Set(),
  2628. IS_DIRECTIVE = 'is',
  2629. VALUE_ATTRIBUTE = 'value',
  2630. MOUNT_METHOD_KEY = 'mount',
  2631. UPDATE_METHOD_KEY = 'update',
  2632. UNMOUNT_METHOD_KEY = 'unmount',
  2633. SHOULD_UPDATE_KEY = 'shouldUpdate',
  2634. ON_BEFORE_MOUNT_KEY = 'onBeforeMount',
  2635. ON_MOUNTED_KEY = 'onMounted',
  2636. ON_BEFORE_UPDATE_KEY = 'onBeforeUpdate',
  2637. ON_UPDATED_KEY = 'onUpdated',
  2638. ON_BEFORE_UNMOUNT_KEY = 'onBeforeUnmount',
  2639. ON_UNMOUNTED_KEY = 'onUnmounted',
  2640. PROPS_KEY = 'props',
  2641. STATE_KEY = 'state',
  2642. SLOTS_KEY = 'slots',
  2643. ROOT_KEY = 'root',
  2644. IS_PURE_SYMBOL = Symbol('pure'),
  2645. IS_COMPONENT_UPDATING = Symbol('is_updating'),
  2646. PARENT_KEY_SYMBOL = Symbol('parent'),
  2647. ATTRIBUTES_KEY_SYMBOL = Symbol('attributes'),
  2648. TEMPLATE_KEY_SYMBOL = Symbol('template');
  2649. var globals = /*#__PURE__*/Object.freeze({
  2650. __proto__: null,
  2651. COMPONENTS_IMPLEMENTATION_MAP: COMPONENTS_IMPLEMENTATION_MAP$1,
  2652. DOM_COMPONENT_INSTANCE_PROPERTY: DOM_COMPONENT_INSTANCE_PROPERTY$1,
  2653. PLUGINS_SET: PLUGINS_SET$1,
  2654. IS_DIRECTIVE: IS_DIRECTIVE,
  2655. VALUE_ATTRIBUTE: VALUE_ATTRIBUTE,
  2656. MOUNT_METHOD_KEY: MOUNT_METHOD_KEY,
  2657. UPDATE_METHOD_KEY: UPDATE_METHOD_KEY,
  2658. UNMOUNT_METHOD_KEY: UNMOUNT_METHOD_KEY,
  2659. SHOULD_UPDATE_KEY: SHOULD_UPDATE_KEY,
  2660. ON_BEFORE_MOUNT_KEY: ON_BEFORE_MOUNT_KEY,
  2661. ON_MOUNTED_KEY: ON_MOUNTED_KEY,
  2662. ON_BEFORE_UPDATE_KEY: ON_BEFORE_UPDATE_KEY,
  2663. ON_UPDATED_KEY: ON_UPDATED_KEY,
  2664. ON_BEFORE_UNMOUNT_KEY: ON_BEFORE_UNMOUNT_KEY,
  2665. ON_UNMOUNTED_KEY: ON_UNMOUNTED_KEY,
  2666. PROPS_KEY: PROPS_KEY,
  2667. STATE_KEY: STATE_KEY,
  2668. SLOTS_KEY: SLOTS_KEY,
  2669. ROOT_KEY: ROOT_KEY,
  2670. IS_PURE_SYMBOL: IS_PURE_SYMBOL,
  2671. IS_COMPONENT_UPDATING: IS_COMPONENT_UPDATING,
  2672. PARENT_KEY_SYMBOL: PARENT_KEY_SYMBOL,
  2673. ATTRIBUTES_KEY_SYMBOL: ATTRIBUTES_KEY_SYMBOL,
  2674. TEMPLATE_KEY_SYMBOL: TEMPLATE_KEY_SYMBOL
  2675. });
  2676. const EACH = 0;
  2677. const IF = 1;
  2678. const SIMPLE = 2;
  2679. const TAG = 3;
  2680. const SLOT = 4;
  2681. var bindingTypes = {
  2682. EACH,
  2683. IF,
  2684. SIMPLE,
  2685. TAG,
  2686. SLOT
  2687. };
  2688. const ATTRIBUTE = 0;
  2689. const EVENT = 1;
  2690. const TEXT = 2;
  2691. const VALUE = 3;
  2692. var expressionTypes = {
  2693. ATTRIBUTE,
  2694. EVENT,
  2695. TEXT,
  2696. VALUE
  2697. };
  2698. const HEAD_SYMBOL = Symbol('head');
  2699. const TAIL_SYMBOL = Symbol('tail');
  2700. /**
  2701. * Create the <template> fragments text nodes
  2702. * @return {Object} {{head: Text, tail: Text}}
  2703. */
  2704. function createHeadTailPlaceholders() {
  2705. const head = document.createTextNode('');
  2706. const tail = document.createTextNode('');
  2707. head[HEAD_SYMBOL] = true;
  2708. tail[TAIL_SYMBOL] = true;
  2709. return {
  2710. head,
  2711. tail
  2712. };
  2713. }
  2714. /**
  2715. * Create the template meta object in case of <template> fragments
  2716. * @param {TemplateChunk} componentTemplate - template chunk object
  2717. * @returns {Object} the meta property that will be passed to the mount function of the TemplateChunk
  2718. */
  2719. function createTemplateMeta(componentTemplate) {
  2720. const fragment = componentTemplate.dom.cloneNode(true);
  2721. const {
  2722. head,
  2723. tail
  2724. } = createHeadTailPlaceholders();
  2725. return {
  2726. avoidDOMInjection: true,
  2727. fragment,
  2728. head,
  2729. tail,
  2730. children: [head, ...Array.from(fragment.childNodes), tail]
  2731. };
  2732. }
  2733. /**
  2734. * Helper function to set an immutable property
  2735. * @param {Object} source - object where the new property will be set
  2736. * @param {string} key - object key where the new property will be stored
  2737. * @param {*} value - value of the new property
  2738. * @param {Object} options - set the propery overriding the default options
  2739. * @returns {Object} - the original object modified
  2740. */
  2741. function defineProperty(source, key, value, options) {
  2742. if (options === void 0) {
  2743. options = {};
  2744. }
  2745. /* eslint-disable fp/no-mutating-methods */
  2746. Object.defineProperty(source, key, Object.assign({
  2747. value,
  2748. enumerable: false,
  2749. writable: false,
  2750. configurable: true
  2751. }, options));
  2752. /* eslint-enable fp/no-mutating-methods */
  2753. return source;
  2754. }
  2755. /**
  2756. * Define multiple properties on a target object
  2757. * @param {Object} source - object where the new properties will be set
  2758. * @param {Object} properties - object containing as key pair the key + value properties
  2759. * @param {Object} options - set the propery overriding the default options
  2760. * @returns {Object} the original object modified
  2761. */
  2762. function defineProperties(source, properties, options) {
  2763. Object.entries(properties).forEach(_ref => {
  2764. let [key, value] = _ref;
  2765. defineProperty(source, key, value, options);
  2766. });
  2767. return source;
  2768. }
  2769. /**
  2770. * Define default properties if they don't exist on the source object
  2771. * @param {Object} source - object that will receive the default properties
  2772. * @param {Object} defaults - object containing additional optional keys
  2773. * @returns {Object} the original object received enhanced
  2774. */
  2775. function defineDefaults(source, defaults) {
  2776. Object.entries(defaults).forEach(_ref2 => {
  2777. let [key, value] = _ref2;
  2778. if (!source[key]) source[key] = value;
  2779. });
  2780. return source;
  2781. }
  2782. /**
  2783. * Get the current <template> fragment children located in between the head and tail comments
  2784. * @param {Comment} head - head comment node
  2785. * @param {Comment} tail - tail comment node
  2786. * @return {Array[]} children list of the nodes found in this template fragment
  2787. */
  2788. function getFragmentChildren(_ref) {
  2789. let {
  2790. head,
  2791. tail
  2792. } = _ref;
  2793. const nodes = walkNodes([head], head.nextSibling, n => n === tail, false);
  2794. nodes.push(tail);
  2795. return nodes;
  2796. }
  2797. /**
  2798. * Recursive function to walk all the <template> children nodes
  2799. * @param {Array[]} children - children nodes collection
  2800. * @param {ChildNode} node - current node
  2801. * @param {Function} check - exit function check
  2802. * @param {boolean} isFilterActive - filter flag to skip nodes managed by other bindings
  2803. * @returns {Array[]} children list of the nodes found in this template fragment
  2804. */
  2805. function walkNodes(children, node, check, isFilterActive) {
  2806. const {
  2807. nextSibling
  2808. } = node; // filter tail and head nodes together with all the nodes in between
  2809. // this is needed only to fix a really ugly edge case https://github.com/riot/riot/issues/2892
  2810. if (!isFilterActive && !node[HEAD_SYMBOL] && !node[TAIL_SYMBOL]) {
  2811. children.push(node);
  2812. }
  2813. if (!nextSibling || check(node)) return children;
  2814. return walkNodes(children, nextSibling, check, // activate the filters to skip nodes between <template> fragments that will be managed by other bindings
  2815. isFilterActive && !node[TAIL_SYMBOL] || nextSibling[HEAD_SYMBOL]);
  2816. }
  2817. /**
  2818. * Quick type checking
  2819. * @param {*} element - anything
  2820. * @param {string} type - type definition
  2821. * @returns {boolean} true if the type corresponds
  2822. */
  2823. function checkType(element, type) {
  2824. return typeof element === type;
  2825. }
  2826. /**
  2827. * Check if an element is part of an svg
  2828. * @param {HTMLElement} el - element to check
  2829. * @returns {boolean} true if we are in an svg context
  2830. */
  2831. function isSvg(el) {
  2832. const owner = el.ownerSVGElement;
  2833. return !!owner || owner === null;
  2834. }
  2835. /**
  2836. * Check if an element is a template tag
  2837. * @param {HTMLElement} el - element to check
  2838. * @returns {boolean} true if it's a <template>
  2839. */
  2840. function isTemplate(el) {
  2841. return el.tagName.toLowerCase() === 'template';
  2842. }
  2843. /**
  2844. * Check that will be passed if its argument is a function
  2845. * @param {*} value - value to check
  2846. * @returns {boolean} - true if the value is a function
  2847. */
  2848. function isFunction(value) {
  2849. return checkType(value, 'function');
  2850. }
  2851. /**
  2852. * Check if a value is a Boolean
  2853. * @param {*} value - anything
  2854. * @returns {boolean} true only for the value is a boolean
  2855. */
  2856. function isBoolean(value) {
  2857. return checkType(value, 'boolean');
  2858. }
  2859. /**
  2860. * Check if a value is an Object
  2861. * @param {*} value - anything
  2862. * @returns {boolean} true only for the value is an object
  2863. */
  2864. function isObject(value) {
  2865. return !isNil(value) && value.constructor === Object;
  2866. }
  2867. /**
  2868. * Check if a value is null or undefined
  2869. * @param {*} value - anything
  2870. * @returns {boolean} true only for the 'undefined' and 'null' types
  2871. */
  2872. function isNil(value) {
  2873. return value === null || value === undefined;
  2874. }
  2875. /**
  2876. * ISC License
  2877. *
  2878. * Copyright (c) 2020, Andrea Giammarchi, @WebReflection
  2879. *
  2880. * Permission to use, copy, modify, and/or distribute this software for any
  2881. * purpose with or without fee is hereby granted, provided that the above
  2882. * copyright notice and this permission notice appear in all copies.
  2883. *
  2884. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  2885. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  2886. * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  2887. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2888. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2889. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2890. * PERFORMANCE OF THIS SOFTWARE.
  2891. */
  2892. // fork of https://github.com/WebReflection/udomdiff version 1.1.0
  2893. // due to https://github.com/WebReflection/udomdiff/pull/2
  2894. /* eslint-disable */
  2895. /**
  2896. * @param {Node[]} a The list of current/live children
  2897. * @param {Node[]} b The list of future children
  2898. * @param {(entry: Node, action: number) => Node} get
  2899. * The callback invoked per each entry related DOM operation.
  2900. * @param {Node} [before] The optional node used as anchor to insert before.
  2901. * @returns {Node[]} The same list of future children.
  2902. */
  2903. var udomdiff = ((a, b, get, before) => {
  2904. const bLength = b.length;
  2905. let aEnd = a.length;
  2906. let bEnd = bLength;
  2907. let aStart = 0;
  2908. let bStart = 0;
  2909. let map = null;
  2910. while (aStart < aEnd || bStart < bEnd) {
  2911. // append head, tail, or nodes in between: fast path
  2912. if (aEnd === aStart) {
  2913. // we could be in a situation where the rest of nodes that
  2914. // need to be added are not at the end, and in such case
  2915. // the node to `insertBefore`, if the index is more than 0
  2916. // must be retrieved, otherwise it's gonna be the first item.
  2917. const node = bEnd < bLength ? bStart ? get(b[bStart - 1], -0).nextSibling : get(b[bEnd - bStart], 0) : before;
  2918. while (bStart < bEnd) insertBefore(get(b[bStart++], 1), node);
  2919. } // remove head or tail: fast path
  2920. else if (bEnd === bStart) {
  2921. while (aStart < aEnd) {
  2922. // remove the node only if it's unknown or not live
  2923. if (!map || !map.has(a[aStart])) removeChild(get(a[aStart], -1));
  2924. aStart++;
  2925. }
  2926. } // same node: fast path
  2927. else if (a[aStart] === b[bStart]) {
  2928. aStart++;
  2929. bStart++;
  2930. } // same tail: fast path
  2931. else if (a[aEnd - 1] === b[bEnd - 1]) {
  2932. aEnd--;
  2933. bEnd--;
  2934. } // The once here single last swap "fast path" has been removed in v1.1.0
  2935. // https://github.com/WebReflection/udomdiff/blob/single-final-swap/esm/index.js#L69-L85
  2936. // reverse swap: also fast path
  2937. else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
  2938. // this is a "shrink" operation that could happen in these cases:
  2939. // [1, 2, 3, 4, 5]
  2940. // [1, 4, 3, 2, 5]
  2941. // or asymmetric too
  2942. // [1, 2, 3, 4, 5]
  2943. // [1, 2, 3, 5, 6, 4]
  2944. const node = get(a[--aEnd], -1).nextSibling;
  2945. insertBefore(get(b[bStart++], 1), get(a[aStart++], -1).nextSibling);
  2946. insertBefore(get(b[--bEnd], 1), node); // mark the future index as identical (yeah, it's dirty, but cheap 👍)
  2947. // The main reason to do this, is that when a[aEnd] will be reached,
  2948. // the loop will likely be on the fast path, as identical to b[bEnd].
  2949. // In the best case scenario, the next loop will skip the tail,
  2950. // but in the worst one, this node will be considered as already
  2951. // processed, bailing out pretty quickly from the map index check
  2952. a[aEnd] = b[bEnd];
  2953. } // map based fallback, "slow" path
  2954. else {
  2955. // the map requires an O(bEnd - bStart) operation once
  2956. // to store all future nodes indexes for later purposes.
  2957. // In the worst case scenario, this is a full O(N) cost,
  2958. // and such scenario happens at least when all nodes are different,
  2959. // but also if both first and last items of the lists are different
  2960. if (!map) {
  2961. map = new Map();
  2962. let i = bStart;
  2963. while (i < bEnd) map.set(b[i], i++);
  2964. } // if it's a future node, hence it needs some handling
  2965. if (map.has(a[aStart])) {
  2966. // grab the index of such node, 'cause it might have been processed
  2967. const index = map.get(a[aStart]); // if it's not already processed, look on demand for the next LCS
  2968. if (bStart < index && index < bEnd) {
  2969. let i = aStart; // counts the amount of nodes that are the same in the future
  2970. let sequence = 1;
  2971. while (++i < aEnd && i < bEnd && map.get(a[i]) === index + sequence) sequence++; // effort decision here: if the sequence is longer than replaces
  2972. // needed to reach such sequence, which would brings again this loop
  2973. // to the fast path, prepend the difference before a sequence,
  2974. // and move only the future list index forward, so that aStart
  2975. // and bStart will be aligned again, hence on the fast path.
  2976. // An example considering aStart and bStart are both 0:
  2977. // a: [1, 2, 3, 4]
  2978. // b: [7, 1, 2, 3, 6]
  2979. // this would place 7 before 1 and, from that time on, 1, 2, and 3
  2980. // will be processed at zero cost
  2981. if (sequence > index - bStart) {
  2982. const node = get(a[aStart], 0);
  2983. while (bStart < index) insertBefore(get(b[bStart++], 1), node);
  2984. } // if the effort wasn't good enough, fallback to a replace,
  2985. // moving both source and target indexes forward, hoping that some
  2986. // similar node will be found later on, to go back to the fast path
  2987. else {
  2988. replaceChild(get(b[bStart++], 1), get(a[aStart++], -1));
  2989. }
  2990. } // otherwise move the source forward, 'cause there's nothing to do
  2991. else aStart++;
  2992. } // this node has no meaning in the future list, so it's more than safe
  2993. // to remove it, and check the next live node out instead, meaning
  2994. // that only the live list index should be forwarded
  2995. else removeChild(get(a[aStart++], -1));
  2996. }
  2997. }
  2998. return b;
  2999. });
  3000. const UNMOUNT_SCOPE = Symbol('unmount');
  3001. const EachBinding = {
  3002. // dynamic binding properties
  3003. // childrenMap: null,
  3004. // node: null,
  3005. // root: null,
  3006. // condition: null,
  3007. // evaluate: null,
  3008. // template: null,
  3009. // isTemplateTag: false,
  3010. nodes: [],
  3011. // getKey: null,
  3012. // indexName: null,
  3013. // itemName: null,
  3014. // afterPlaceholder: null,
  3015. // placeholder: null,
  3016. // API methods
  3017. mount(scope, parentScope) {
  3018. return this.update(scope, parentScope);
  3019. },
  3020. update(scope, parentScope) {
  3021. const {
  3022. placeholder,
  3023. nodes,
  3024. childrenMap
  3025. } = this;
  3026. const collection = scope === UNMOUNT_SCOPE ? null : this.evaluate(scope);
  3027. const items = collection ? Array.from(collection) : []; // prepare the diffing
  3028. const {
  3029. newChildrenMap,
  3030. batches,
  3031. futureNodes
  3032. } = createPatch(items, scope, parentScope, this); // patch the DOM only if there are new nodes
  3033. udomdiff(nodes, futureNodes, patch(Array.from(childrenMap.values()), parentScope), placeholder); // trigger the mounts and the updates
  3034. batches.forEach(fn => fn()); // update the children map
  3035. this.childrenMap = newChildrenMap;
  3036. this.nodes = futureNodes; // make sure that the loop edge nodes are marked
  3037. markEdgeNodes(this.nodes);
  3038. return this;
  3039. },
  3040. unmount(scope, parentScope) {
  3041. this.update(UNMOUNT_SCOPE, parentScope);
  3042. return this;
  3043. }
  3044. };
  3045. /**
  3046. * Patch the DOM while diffing
  3047. * @param {any[]} redundant - list of all the children (template, nodes, context) added via each
  3048. * @param {*} parentScope - scope of the parent template
  3049. * @returns {Function} patch function used by domdiff
  3050. */
  3051. function patch(redundant, parentScope) {
  3052. return (item, info) => {
  3053. if (info < 0) {
  3054. // get the last element added to the childrenMap saved previously
  3055. const element = redundant[redundant.length - 1];
  3056. if (element) {
  3057. // get the nodes and the template in stored in the last child of the childrenMap
  3058. const {
  3059. template,
  3060. nodes,
  3061. context
  3062. } = element; // remove the last node (notice <template> tags might have more children nodes)
  3063. nodes.pop(); // notice that we pass null as last argument because
  3064. // the root node and its children will be removed by domdiff
  3065. if (!nodes.length) {
  3066. // we have cleared all the children nodes and we can unmount this template
  3067. redundant.pop();
  3068. template.unmount(context, parentScope, null);
  3069. }
  3070. }
  3071. }
  3072. return item;
  3073. };
  3074. }
  3075. /**
  3076. * Check whether a template must be filtered from a loop
  3077. * @param {Function} condition - filter function
  3078. * @param {Object} context - argument passed to the filter function
  3079. * @returns {boolean} true if this item should be skipped
  3080. */
  3081. function mustFilterItem(condition, context) {
  3082. return condition ? !condition(context) : false;
  3083. }
  3084. /**
  3085. * Extend the scope of the looped template
  3086. * @param {Object} scope - current template scope
  3087. * @param {Object} options - options
  3088. * @param {string} options.itemName - key to identify the looped item in the new context
  3089. * @param {string} options.indexName - key to identify the index of the looped item
  3090. * @param {number} options.index - current index
  3091. * @param {*} options.item - collection item looped
  3092. * @returns {Object} enhanced scope object
  3093. */
  3094. function extendScope(scope, _ref) {
  3095. let {
  3096. itemName,
  3097. indexName,
  3098. index,
  3099. item
  3100. } = _ref;
  3101. defineProperty(scope, itemName, item);
  3102. if (indexName) defineProperty(scope, indexName, index);
  3103. return scope;
  3104. }
  3105. /**
  3106. * Mark the first and last nodes in order to ignore them in case we need to retrieve the <template> fragment nodes
  3107. * @param {Array[]} nodes - each binding nodes list
  3108. * @returns {undefined} void function
  3109. */
  3110. function markEdgeNodes(nodes) {
  3111. const first = nodes[0];
  3112. const last = nodes[nodes.length - 1];
  3113. if (first) first[HEAD_SYMBOL] = true;
  3114. if (last) last[TAIL_SYMBOL] = true;
  3115. }
  3116. /**
  3117. * Loop the current template items
  3118. * @param {Array} items - expression collection value
  3119. * @param {*} scope - template scope
  3120. * @param {*} parentScope - scope of the parent template
  3121. * @param {EachBinding} binding - each binding object instance
  3122. * @returns {Object} data
  3123. * @returns {Map} data.newChildrenMap - a Map containing the new children template structure
  3124. * @returns {Array} data.batches - array containing the template lifecycle functions to trigger
  3125. * @returns {Array} data.futureNodes - array containing the nodes we need to diff
  3126. */
  3127. function createPatch(items, scope, parentScope, binding) {
  3128. const {
  3129. condition,
  3130. template,
  3131. childrenMap,
  3132. itemName,
  3133. getKey,
  3134. indexName,
  3135. root,
  3136. isTemplateTag
  3137. } = binding;
  3138. const newChildrenMap = new Map();
  3139. const batches = [];
  3140. const futureNodes = [];
  3141. items.forEach((item, index) => {
  3142. const context = extendScope(Object.create(scope), {
  3143. itemName,
  3144. indexName,
  3145. index,
  3146. item
  3147. });
  3148. const key = getKey ? getKey(context) : index;
  3149. const oldItem = childrenMap.get(key);
  3150. const nodes = [];
  3151. if (mustFilterItem(condition, context)) {
  3152. return;
  3153. }
  3154. const mustMount = !oldItem;
  3155. const componentTemplate = oldItem ? oldItem.template : template.clone();
  3156. const el = componentTemplate.el || root.cloneNode();
  3157. const meta = isTemplateTag && mustMount ? createTemplateMeta(componentTemplate) : componentTemplate.meta;
  3158. if (mustMount) {
  3159. batches.push(() => componentTemplate.mount(el, context, parentScope, meta));
  3160. } else {
  3161. batches.push(() => componentTemplate.update(context, parentScope));
  3162. } // create the collection of nodes to update or to add
  3163. // in case of template tags we need to add all its children nodes
  3164. if (isTemplateTag) {
  3165. nodes.push(...(mustMount ? meta.children : getFragmentChildren(meta)));
  3166. } else {
  3167. nodes.push(el);
  3168. } // delete the old item from the children map
  3169. childrenMap.delete(key);
  3170. futureNodes.push(...nodes); // update the children map
  3171. newChildrenMap.set(key, {
  3172. nodes,
  3173. template: componentTemplate,
  3174. context,
  3175. index
  3176. });
  3177. });
  3178. return {
  3179. newChildrenMap,
  3180. batches,
  3181. futureNodes
  3182. };
  3183. }
  3184. function create$6(node, _ref2) {
  3185. let {
  3186. evaluate,
  3187. condition,
  3188. itemName,
  3189. indexName,
  3190. getKey,
  3191. template
  3192. } = _ref2;
  3193. const placeholder = document.createTextNode('');
  3194. const root = node.cloneNode();
  3195. insertBefore(placeholder, node);
  3196. removeChild(node);
  3197. return Object.assign({}, EachBinding, {
  3198. childrenMap: new Map(),
  3199. node,
  3200. root,
  3201. condition,
  3202. evaluate,
  3203. isTemplateTag: isTemplate(root),
  3204. template: template.createDOM(node),
  3205. getKey,
  3206. indexName,
  3207. itemName,
  3208. placeholder
  3209. });
  3210. }
  3211. /**
  3212. * Binding responsible for the `if` directive
  3213. */
  3214. const IfBinding = {
  3215. // dynamic binding properties
  3216. // node: null,
  3217. // evaluate: null,
  3218. // isTemplateTag: false,
  3219. // placeholder: null,
  3220. // template: null,
  3221. // API methods
  3222. mount(scope, parentScope) {
  3223. return this.update(scope, parentScope);
  3224. },
  3225. update(scope, parentScope) {
  3226. const value = !!this.evaluate(scope);
  3227. const mustMount = !this.value && value;
  3228. const mustUnmount = this.value && !value;
  3229. const mount = () => {
  3230. const pristine = this.node.cloneNode();
  3231. insertBefore(pristine, this.placeholder);
  3232. this.template = this.template.clone();
  3233. this.template.mount(pristine, scope, parentScope);
  3234. };
  3235. switch (true) {
  3236. case mustMount:
  3237. mount();
  3238. break;
  3239. case mustUnmount:
  3240. this.unmount(scope);
  3241. break;
  3242. default:
  3243. if (value) this.template.update(scope, parentScope);
  3244. }
  3245. this.value = value;
  3246. return this;
  3247. },
  3248. unmount(scope, parentScope) {
  3249. this.template.unmount(scope, parentScope, true);
  3250. return this;
  3251. }
  3252. };
  3253. function create$5(node, _ref) {
  3254. let {
  3255. evaluate,
  3256. template
  3257. } = _ref;
  3258. const placeholder = document.createTextNode('');
  3259. insertBefore(placeholder, node);
  3260. removeChild(node);
  3261. return Object.assign({}, IfBinding, {
  3262. node,
  3263. evaluate,
  3264. placeholder,
  3265. template: template.createDOM(node)
  3266. });
  3267. }
  3268. /**
  3269. * Throw an error with a descriptive message
  3270. * @param { string } message - error message
  3271. * @returns { undefined } hoppla.. at this point the program should stop working
  3272. */
  3273. function panic(message) {
  3274. throw new Error(message);
  3275. }
  3276. /**
  3277. * Returns the memoized (cached) function.
  3278. * // borrowed from https://www.30secondsofcode.org/js/s/memoize
  3279. * @param {Function} fn - function to memoize
  3280. * @returns {Function} memoize function
  3281. */
  3282. function memoize(fn) {
  3283. const cache = new Map();
  3284. const cached = val => {
  3285. return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
  3286. };
  3287. cached.cache = cache;
  3288. return cached;
  3289. }
  3290. /**
  3291. * Evaluate a list of attribute expressions
  3292. * @param {Array} attributes - attribute expressions generated by the riot compiler
  3293. * @returns {Object} key value pairs with the result of the computation
  3294. */
  3295. function evaluateAttributeExpressions(attributes) {
  3296. return attributes.reduce((acc, attribute) => {
  3297. const {
  3298. value,
  3299. type
  3300. } = attribute;
  3301. switch (true) {
  3302. // spread attribute
  3303. case !attribute.name && type === ATTRIBUTE:
  3304. return Object.assign({}, acc, value);
  3305. // value attribute
  3306. case type === VALUE:
  3307. acc.value = attribute.value;
  3308. break;
  3309. // normal attributes
  3310. default:
  3311. acc[dashToCamelCase(attribute.name)] = attribute.value;
  3312. }
  3313. return acc;
  3314. }, {});
  3315. }
  3316. const ElementProto = typeof Element === 'undefined' ? {} : Element.prototype;
  3317. const isNativeHtmlProperty = memoize(name => ElementProto.hasOwnProperty(name)); // eslint-disable-line
  3318. /**
  3319. * Add all the attributes provided
  3320. * @param {HTMLElement} node - target node
  3321. * @param {Object} attributes - object containing the attributes names and values
  3322. * @returns {undefined} sorry it's a void function :(
  3323. */
  3324. function setAllAttributes(node, attributes) {
  3325. Object.entries(attributes).forEach(_ref => {
  3326. let [name, value] = _ref;
  3327. return attributeExpression(node, {
  3328. name
  3329. }, value);
  3330. });
  3331. }
  3332. /**
  3333. * Remove all the attributes provided
  3334. * @param {HTMLElement} node - target node
  3335. * @param {Object} newAttributes - object containing all the new attribute names
  3336. * @param {Object} oldAttributes - object containing all the old attribute names
  3337. * @returns {undefined} sorry it's a void function :(
  3338. */
  3339. function removeAllAttributes(node, newAttributes, oldAttributes) {
  3340. const newKeys = newAttributes ? Object.keys(newAttributes) : [];
  3341. Object.keys(oldAttributes).filter(name => !newKeys.includes(name)).forEach(attribute => node.removeAttribute(attribute));
  3342. }
  3343. /**
  3344. * Check whether the attribute value can be rendered
  3345. * @param {*} value - expression value
  3346. * @returns {boolean} true if we can render this attribute value
  3347. */
  3348. function canRenderAttribute(value) {
  3349. return value === true || ['string', 'number'].includes(typeof value);
  3350. }
  3351. /**
  3352. * Check whether the attribute should be removed
  3353. * @param {*} value - expression value
  3354. * @returns {boolean} boolean - true if the attribute can be removed}
  3355. */
  3356. function shouldRemoveAttribute(value) {
  3357. return !value && value !== 0;
  3358. }
  3359. /**
  3360. * This methods handles the DOM attributes updates
  3361. * @param {HTMLElement} node - target node
  3362. * @param {Object} expression - expression object
  3363. * @param {string} expression.name - attribute name
  3364. * @param {*} value - new expression value
  3365. * @param {*} oldValue - the old expression cached value
  3366. * @returns {undefined}
  3367. */
  3368. function attributeExpression(node, _ref2, value, oldValue) {
  3369. let {
  3370. name
  3371. } = _ref2;
  3372. // is it a spread operator? {...attributes}
  3373. if (!name) {
  3374. if (oldValue) {
  3375. // remove all the old attributes
  3376. removeAllAttributes(node, value, oldValue);
  3377. } // is the value still truthy?
  3378. if (value) {
  3379. setAllAttributes(node, value);
  3380. }
  3381. return;
  3382. } // handle boolean attributes
  3383. if (!isNativeHtmlProperty(name) && (isBoolean(value) || isObject(value) || isFunction(value))) {
  3384. node[name] = value;
  3385. }
  3386. if (shouldRemoveAttribute(value)) {
  3387. node.removeAttribute(name);
  3388. } else if (canRenderAttribute(value)) {
  3389. node.setAttribute(name, normalizeValue(name, value));
  3390. }
  3391. }
  3392. /**
  3393. * Get the value as string
  3394. * @param {string} name - attribute name
  3395. * @param {*} value - user input value
  3396. * @returns {string} input value as string
  3397. */
  3398. function normalizeValue(name, value) {
  3399. // be sure that expressions like selected={ true } will be always rendered as selected='selected'
  3400. return value === true ? name : value;
  3401. }
  3402. const RE_EVENTS_PREFIX = /^on/;
  3403. const getCallbackAndOptions = value => Array.isArray(value) ? value : [value, false]; // see also https://medium.com/@WebReflection/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38
  3404. const EventListener = {
  3405. handleEvent(event) {
  3406. this[event.type](event);
  3407. }
  3408. };
  3409. const ListenersWeakMap = new WeakMap();
  3410. const createListener = node => {
  3411. const listener = Object.create(EventListener);
  3412. ListenersWeakMap.set(node, listener);
  3413. return listener;
  3414. };
  3415. /**
  3416. * Set a new event listener
  3417. * @param {HTMLElement} node - target node
  3418. * @param {Object} expression - expression object
  3419. * @param {string} expression.name - event name
  3420. * @param {*} value - new expression value
  3421. * @returns {value} the callback just received
  3422. */
  3423. function eventExpression(node, _ref, value) {
  3424. let {
  3425. name
  3426. } = _ref;
  3427. const normalizedEventName = name.replace(RE_EVENTS_PREFIX, '');
  3428. const eventListener = ListenersWeakMap.get(node) || createListener(node);
  3429. const [callback, options] = getCallbackAndOptions(value);
  3430. const handler = eventListener[normalizedEventName];
  3431. const mustRemoveEvent = handler && !callback;
  3432. const mustAddEvent = callback && !handler;
  3433. if (mustRemoveEvent) {
  3434. node.removeEventListener(normalizedEventName, eventListener);
  3435. }
  3436. if (mustAddEvent) {
  3437. node.addEventListener(normalizedEventName, eventListener, options);
  3438. }
  3439. eventListener[normalizedEventName] = callback;
  3440. }
  3441. /**
  3442. * Normalize the user value in order to render a empty string in case of falsy values
  3443. * @param {*} value - user input value
  3444. * @returns {string} hopefully a string
  3445. */
  3446. function normalizeStringValue(value) {
  3447. return isNil(value) ? '' : value;
  3448. }
  3449. /**
  3450. * Get the the target text node to update or create one from of a comment node
  3451. * @param {HTMLElement} node - any html element containing childNodes
  3452. * @param {number} childNodeIndex - index of the text node in the childNodes list
  3453. * @returns {Text} the text node to update
  3454. */
  3455. const getTextNode = (node, childNodeIndex) => {
  3456. const target = node.childNodes[childNodeIndex];
  3457. if (target.nodeType === Node.COMMENT_NODE) {
  3458. const textNode = document.createTextNode('');
  3459. node.replaceChild(textNode, target);
  3460. return textNode;
  3461. }
  3462. return target;
  3463. };
  3464. /**
  3465. * This methods handles a simple text expression update
  3466. * @param {HTMLElement} node - target node
  3467. * @param {Object} data - expression object
  3468. * @param {*} value - new expression value
  3469. * @returns {undefined}
  3470. */
  3471. function textExpression(node, data, value) {
  3472. node.data = normalizeStringValue(value);
  3473. }
  3474. /**
  3475. * This methods handles the input fileds value updates
  3476. * @param {HTMLElement} node - target node
  3477. * @param {Object} expression - expression object
  3478. * @param {*} value - new expression value
  3479. * @returns {undefined}
  3480. */
  3481. function valueExpression(node, expression, value) {
  3482. node.value = normalizeStringValue(value);
  3483. }
  3484. var expressions = {
  3485. [ATTRIBUTE]: attributeExpression,
  3486. [EVENT]: eventExpression,
  3487. [TEXT]: textExpression,
  3488. [VALUE]: valueExpression
  3489. };
  3490. const Expression = {
  3491. // Static props
  3492. // node: null,
  3493. // value: null,
  3494. // API methods
  3495. /**
  3496. * Mount the expression evaluating its initial value
  3497. * @param {*} scope - argument passed to the expression to evaluate its current values
  3498. * @returns {Expression} self
  3499. */
  3500. mount(scope) {
  3501. // hopefully a pure function
  3502. this.value = this.evaluate(scope); // IO() DOM updates
  3503. apply(this, this.value);
  3504. return this;
  3505. },
  3506. /**
  3507. * Update the expression if its value changed
  3508. * @param {*} scope - argument passed to the expression to evaluate its current values
  3509. * @returns {Expression} self
  3510. */
  3511. update(scope) {
  3512. // pure function
  3513. const value = this.evaluate(scope);
  3514. if (this.value !== value) {
  3515. // IO() DOM updates
  3516. apply(this, value);
  3517. this.value = value;
  3518. }
  3519. return this;
  3520. },
  3521. /**
  3522. * Expression teardown method
  3523. * @returns {Expression} self
  3524. */
  3525. unmount() {
  3526. // unmount only the event handling expressions
  3527. if (this.type === EVENT) apply(this, null);
  3528. return this;
  3529. }
  3530. };
  3531. /**
  3532. * IO() function to handle the DOM updates
  3533. * @param {Expression} expression - expression object
  3534. * @param {*} value - current expression value
  3535. * @returns {undefined}
  3536. */
  3537. function apply(expression, value) {
  3538. return expressions[expression.type](expression.node, expression, value, expression.value);
  3539. }
  3540. function create$4(node, data) {
  3541. return Object.assign({}, Expression, data, {
  3542. node: data.type === TEXT ? getTextNode(node, data.childNodeIndex) : node
  3543. });
  3544. }
  3545. /**
  3546. * Create a flat object having as keys a list of methods that if dispatched will propagate
  3547. * on the whole collection
  3548. * @param {Array} collection - collection to iterate
  3549. * @param {Array<string>} methods - methods to execute on each item of the collection
  3550. * @param {*} context - context returned by the new methods created
  3551. * @returns {Object} a new object to simplify the the nested methods dispatching
  3552. */
  3553. function flattenCollectionMethods(collection, methods, context) {
  3554. return methods.reduce((acc, method) => {
  3555. return Object.assign({}, acc, {
  3556. [method]: scope => {
  3557. return collection.map(item => item[method](scope)) && context;
  3558. }
  3559. });
  3560. }, {});
  3561. }
  3562. function create$3(node, _ref) {
  3563. let {
  3564. expressions
  3565. } = _ref;
  3566. return Object.assign({}, flattenCollectionMethods(expressions.map(expression => create$4(node, expression)), ['mount', 'update', 'unmount']));
  3567. }
  3568. function extendParentScope(attributes, scope, parentScope) {
  3569. if (!attributes || !attributes.length) return parentScope;
  3570. const expressions = attributes.map(attr => Object.assign({}, attr, {
  3571. value: attr.evaluate(scope)
  3572. }));
  3573. return Object.assign(Object.create(parentScope || null), evaluateAttributeExpressions(expressions));
  3574. } // this function is only meant to fix an edge case
  3575. // https://github.com/riot/riot/issues/2842
  3576. const getRealParent = (scope, parentScope) => scope[PARENT_KEY_SYMBOL] || parentScope;
  3577. const SlotBinding = {
  3578. // dynamic binding properties
  3579. // node: null,
  3580. // name: null,
  3581. attributes: [],
  3582. // template: null,
  3583. getTemplateScope(scope, parentScope) {
  3584. return extendParentScope(this.attributes, scope, parentScope);
  3585. },
  3586. // API methods
  3587. mount(scope, parentScope) {
  3588. const templateData = scope.slots ? scope.slots.find(_ref => {
  3589. let {
  3590. id
  3591. } = _ref;
  3592. return id === this.name;
  3593. }) : false;
  3594. const {
  3595. parentNode
  3596. } = this.node;
  3597. const realParent = getRealParent(scope, parentScope);
  3598. this.template = templateData && create(templateData.html, templateData.bindings).createDOM(parentNode);
  3599. if (this.template) {
  3600. cleanNode(this.node);
  3601. this.template.mount(this.node, this.getTemplateScope(scope, realParent), realParent);
  3602. this.template.children = Array.from(this.node.childNodes);
  3603. }
  3604. moveSlotInnerContent(this.node);
  3605. removeChild(this.node);
  3606. return this;
  3607. },
  3608. update(scope, parentScope) {
  3609. if (this.template) {
  3610. const realParent = getRealParent(scope, parentScope);
  3611. this.template.update(this.getTemplateScope(scope, realParent), realParent);
  3612. }
  3613. return this;
  3614. },
  3615. unmount(scope, parentScope, mustRemoveRoot) {
  3616. if (this.template) {
  3617. this.template.unmount(this.getTemplateScope(scope, parentScope), null, mustRemoveRoot);
  3618. }
  3619. return this;
  3620. }
  3621. };
  3622. /**
  3623. * Move the inner content of the slots outside of them
  3624. * @param {HTMLElement} slot - slot node
  3625. * @returns {undefined} it's a void method ¯\_()_/¯
  3626. */
  3627. function moveSlotInnerContent(slot) {
  3628. const child = slot && slot.firstChild;
  3629. if (!child) return;
  3630. insertBefore(child, slot);
  3631. moveSlotInnerContent(slot);
  3632. }
  3633. /**
  3634. * Create a single slot binding
  3635. * @param {HTMLElement} node - slot node
  3636. * @param {string} name - slot id
  3637. * @param {AttributeExpressionData[]} attributes - slot attributes
  3638. * @returns {Object} Slot binding object
  3639. */
  3640. function createSlot(node, _ref2) {
  3641. let {
  3642. name,
  3643. attributes
  3644. } = _ref2;
  3645. return Object.assign({}, SlotBinding, {
  3646. attributes,
  3647. node,
  3648. name
  3649. });
  3650. }
  3651. /**
  3652. * Create a new tag object if it was registered before, otherwise fallback to the simple
  3653. * template chunk
  3654. * @param {Function} component - component factory function
  3655. * @param {Array<Object>} slots - array containing the slots markup
  3656. * @param {Array} attributes - dynamic attributes that will be received by the tag element
  3657. * @returns {TagImplementation|TemplateChunk} a tag implementation or a template chunk as fallback
  3658. */
  3659. function getTag(component, slots, attributes) {
  3660. if (slots === void 0) {
  3661. slots = [];
  3662. }
  3663. if (attributes === void 0) {
  3664. attributes = [];
  3665. }
  3666. // if this tag was registered before we will return its implementation
  3667. if (component) {
  3668. return component({
  3669. slots,
  3670. attributes
  3671. });
  3672. } // otherwise we return a template chunk
  3673. return create(slotsToMarkup(slots), [...slotBindings(slots), {
  3674. // the attributes should be registered as binding
  3675. // if we fallback to a normal template chunk
  3676. expressions: attributes.map(attr => {
  3677. return Object.assign({
  3678. type: ATTRIBUTE
  3679. }, attr);
  3680. })
  3681. }]);
  3682. }
  3683. /**
  3684. * Merge all the slots bindings into a single array
  3685. * @param {Array<Object>} slots - slots collection
  3686. * @returns {Array<Bindings>} flatten bindings array
  3687. */
  3688. function slotBindings(slots) {
  3689. return slots.reduce((acc, _ref) => {
  3690. let {
  3691. bindings
  3692. } = _ref;
  3693. return acc.concat(bindings);
  3694. }, []);
  3695. }
  3696. /**
  3697. * Merge all the slots together in a single markup string
  3698. * @param {Array<Object>} slots - slots collection
  3699. * @returns {string} markup of all the slots in a single string
  3700. */
  3701. function slotsToMarkup(slots) {
  3702. return slots.reduce((acc, slot) => {
  3703. return acc + slot.html;
  3704. }, '');
  3705. }
  3706. const TagBinding = {
  3707. // dynamic binding properties
  3708. // node: null,
  3709. // evaluate: null,
  3710. // name: null,
  3711. // slots: null,
  3712. // tag: null,
  3713. // attributes: null,
  3714. // getComponent: null,
  3715. mount(scope) {
  3716. return this.update(scope);
  3717. },
  3718. update(scope, parentScope) {
  3719. const name = this.evaluate(scope); // simple update
  3720. if (name && name === this.name) {
  3721. this.tag.update(scope);
  3722. } else {
  3723. // unmount the old tag if it exists
  3724. this.unmount(scope, parentScope, true); // mount the new tag
  3725. this.name = name;
  3726. this.tag = getTag(this.getComponent(name), this.slots, this.attributes);
  3727. this.tag.mount(this.node, scope);
  3728. }
  3729. return this;
  3730. },
  3731. unmount(scope, parentScope, keepRootTag) {
  3732. if (this.tag) {
  3733. // keep the root tag
  3734. this.tag.unmount(keepRootTag);
  3735. }
  3736. return this;
  3737. }
  3738. };
  3739. function create$2(node, _ref2) {
  3740. let {
  3741. evaluate,
  3742. getComponent,
  3743. slots,
  3744. attributes
  3745. } = _ref2;
  3746. return Object.assign({}, TagBinding, {
  3747. node,
  3748. evaluate,
  3749. slots,
  3750. attributes,
  3751. getComponent
  3752. });
  3753. }
  3754. var bindings = {
  3755. [IF]: create$5,
  3756. [SIMPLE]: create$3,
  3757. [EACH]: create$6,
  3758. [TAG]: create$2,
  3759. [SLOT]: createSlot
  3760. };
  3761. /**
  3762. * Text expressions in a template tag will get childNodeIndex value normalized
  3763. * depending on the position of the <template> tag offset
  3764. * @param {Expression[]} expressions - riot expressions array
  3765. * @param {number} textExpressionsOffset - offset of the <template> tag
  3766. * @returns {Expression[]} expressions containing the text expressions normalized
  3767. */
  3768. function fixTextExpressionsOffset(expressions, textExpressionsOffset) {
  3769. return expressions.map(e => e.type === TEXT ? Object.assign({}, e, {
  3770. childNodeIndex: e.childNodeIndex + textExpressionsOffset
  3771. }) : e);
  3772. }
  3773. /**
  3774. * Bind a new expression object to a DOM node
  3775. * @param {HTMLElement} root - DOM node where to bind the expression
  3776. * @param {TagBindingData} binding - binding data
  3777. * @param {number|null} templateTagOffset - if it's defined we need to fix the text expressions childNodeIndex offset
  3778. * @returns {Binding} Binding object
  3779. */
  3780. function create$1(root, binding, templateTagOffset) {
  3781. const {
  3782. selector,
  3783. type,
  3784. redundantAttribute,
  3785. expressions
  3786. } = binding; // find the node to apply the bindings
  3787. const node = selector ? root.querySelector(selector) : root; // remove eventually additional attributes created only to select this node
  3788. if (redundantAttribute) node.removeAttribute(redundantAttribute);
  3789. const bindingExpressions = expressions || []; // init the binding
  3790. return (bindings[type] || bindings[SIMPLE])(node, Object.assign({}, binding, {
  3791. expressions: templateTagOffset && !selector ? fixTextExpressionsOffset(bindingExpressions, templateTagOffset) : bindingExpressions
  3792. }));
  3793. }
  3794. function createHTMLTree(html, root) {
  3795. const template = isTemplate(root) ? root : document.createElement('template');
  3796. template.innerHTML = html;
  3797. return template.content;
  3798. } // for svg nodes we need a bit more work
  3799. function createSVGTree(html, container) {
  3800. // create the SVGNode
  3801. const svgNode = container.ownerDocument.importNode(new window.DOMParser().parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${html}</svg>`, 'application/xml').documentElement, true);
  3802. return svgNode;
  3803. }
  3804. /**
  3805. * Create the DOM that will be injected
  3806. * @param {Object} root - DOM node to find out the context where the fragment will be created
  3807. * @param {string} html - DOM to create as string
  3808. * @returns {HTMLDocumentFragment|HTMLElement} a new html fragment
  3809. */
  3810. function createDOMTree(root, html) {
  3811. if (isSvg(root)) return createSVGTree(html, root);
  3812. return createHTMLTree(html, root);
  3813. }
  3814. /**
  3815. * Inject the DOM tree into a target node
  3816. * @param {HTMLElement} el - target element
  3817. * @param {DocumentFragment|SVGElement} dom - dom tree to inject
  3818. * @returns {undefined}
  3819. */
  3820. function injectDOM(el, dom) {
  3821. switch (true) {
  3822. case isSvg(el):
  3823. moveChildren(dom, el);
  3824. break;
  3825. case isTemplate(el):
  3826. el.parentNode.replaceChild(dom, el);
  3827. break;
  3828. default:
  3829. el.appendChild(dom);
  3830. }
  3831. }
  3832. /**
  3833. * Create the Template DOM skeleton
  3834. * @param {HTMLElement} el - root node where the DOM will be injected
  3835. * @param {string|HTMLElement} html - HTML markup or HTMLElement that will be injected into the root node
  3836. * @returns {?DocumentFragment} fragment that will be injected into the root node
  3837. */
  3838. function createTemplateDOM(el, html) {
  3839. return html && (typeof html === 'string' ? createDOMTree(el, html) : html);
  3840. }
  3841. /**
  3842. * Get the offset of the <template> tag
  3843. * @param {HTMLElement} parentNode - template tag parent node
  3844. * @param {HTMLElement} el - the template tag we want to render
  3845. * @param {Object} meta - meta properties needed to handle the <template> tags in loops
  3846. * @returns {number} offset of the <template> tag calculated from its siblings DOM nodes
  3847. */
  3848. function getTemplateTagOffset(parentNode, el, meta) {
  3849. const siblings = Array.from(parentNode.childNodes);
  3850. return Math.max(siblings.indexOf(el), siblings.indexOf(meta.head) + 1, 0);
  3851. }
  3852. /**
  3853. * Template Chunk model
  3854. * @type {Object}
  3855. */
  3856. const TemplateChunk = Object.freeze({
  3857. // Static props
  3858. // bindings: null,
  3859. // bindingsData: null,
  3860. // html: null,
  3861. // isTemplateTag: false,
  3862. // fragment: null,
  3863. // children: null,
  3864. // dom: null,
  3865. // el: null,
  3866. /**
  3867. * Create the template DOM structure that will be cloned on each mount
  3868. * @param {HTMLElement} el - the root node
  3869. * @returns {TemplateChunk} self
  3870. */
  3871. createDOM(el) {
  3872. // make sure that the DOM gets created before cloning the template
  3873. this.dom = this.dom || createTemplateDOM(el, this.html) || document.createDocumentFragment();
  3874. return this;
  3875. },
  3876. // API methods
  3877. /**
  3878. * Attach the template to a DOM node
  3879. * @param {HTMLElement} el - target DOM node
  3880. * @param {*} scope - template data
  3881. * @param {*} parentScope - scope of the parent template tag
  3882. * @param {Object} meta - meta properties needed to handle the <template> tags in loops
  3883. * @returns {TemplateChunk} self
  3884. */
  3885. mount(el, scope, parentScope, meta) {
  3886. if (meta === void 0) {
  3887. meta = {};
  3888. }
  3889. if (!el) throw new Error('Please provide DOM node to mount properly your template');
  3890. if (this.el) this.unmount(scope); // <template> tags require a bit more work
  3891. // the template fragment might be already created via meta outside of this call
  3892. const {
  3893. fragment,
  3894. children,
  3895. avoidDOMInjection
  3896. } = meta; // <template> bindings of course can not have a root element
  3897. // so we check the parent node to set the query selector bindings
  3898. const {
  3899. parentNode
  3900. } = children ? children[0] : el;
  3901. const isTemplateTag = isTemplate(el);
  3902. const templateTagOffset = isTemplateTag ? getTemplateTagOffset(parentNode, el, meta) : null; // create the DOM if it wasn't created before
  3903. this.createDOM(el); // create the DOM of this template cloning the original DOM structure stored in this instance
  3904. // notice that if a documentFragment was passed (via meta) we will use it instead
  3905. const cloneNode = fragment || this.dom.cloneNode(true); // store root node
  3906. // notice that for template tags the root note will be the parent tag
  3907. this.el = isTemplateTag ? parentNode : el; // create the children array only for the <template> fragments
  3908. this.children = isTemplateTag ? children || Array.from(cloneNode.childNodes) : null; // inject the DOM into the el only if a fragment is available
  3909. if (!avoidDOMInjection && cloneNode) injectDOM(el, cloneNode); // create the bindings
  3910. this.bindings = this.bindingsData.map(binding => create$1(this.el, binding, templateTagOffset));
  3911. this.bindings.forEach(b => b.mount(scope, parentScope)); // store the template meta properties
  3912. this.meta = meta;
  3913. return this;
  3914. },
  3915. /**
  3916. * Update the template with fresh data
  3917. * @param {*} scope - template data
  3918. * @param {*} parentScope - scope of the parent template tag
  3919. * @returns {TemplateChunk} self
  3920. */
  3921. update(scope, parentScope) {
  3922. this.bindings.forEach(b => b.update(scope, parentScope));
  3923. return this;
  3924. },
  3925. /**
  3926. * Remove the template from the node where it was initially mounted
  3927. * @param {*} scope - template data
  3928. * @param {*} parentScope - scope of the parent template tag
  3929. * @param {boolean|null} mustRemoveRoot - if true remove the root element,
  3930. * if false or undefined clean the root tag content, if null don't touch the DOM
  3931. * @returns {TemplateChunk} self
  3932. */
  3933. unmount(scope, parentScope, mustRemoveRoot) {
  3934. if (mustRemoveRoot === void 0) {
  3935. mustRemoveRoot = false;
  3936. }
  3937. const el = this.el;
  3938. if (!el) {
  3939. return this;
  3940. }
  3941. this.bindings.forEach(b => b.unmount(scope, parentScope, mustRemoveRoot));
  3942. switch (true) {
  3943. // pure components should handle the DOM unmount updates by themselves
  3944. // for mustRemoveRoot === null don't touch the DOM
  3945. case el[IS_PURE_SYMBOL] || mustRemoveRoot === null:
  3946. break;
  3947. // if children are declared, clear them
  3948. // applicable for <template> and <slot/> bindings
  3949. case Array.isArray(this.children):
  3950. clearChildren(this.children);
  3951. break;
  3952. // clean the node children only
  3953. case !mustRemoveRoot:
  3954. cleanNode(el);
  3955. break;
  3956. // remove the root node only if the mustRemoveRoot is truly
  3957. case !!mustRemoveRoot:
  3958. removeChild(el);
  3959. break;
  3960. }
  3961. this.el = null;
  3962. return this;
  3963. },
  3964. /**
  3965. * Clone the template chunk
  3966. * @returns {TemplateChunk} a clone of this object resetting the this.el property
  3967. */
  3968. clone() {
  3969. return Object.assign({}, this, {
  3970. meta: {},
  3971. el: null
  3972. });
  3973. }
  3974. });
  3975. /**
  3976. * Create a template chunk wiring also the bindings
  3977. * @param {string|HTMLElement} html - template string
  3978. * @param {BindingData[]} bindings - bindings collection
  3979. * @returns {TemplateChunk} a new TemplateChunk copy
  3980. */
  3981. function create(html, bindings) {
  3982. if (bindings === void 0) {
  3983. bindings = [];
  3984. }
  3985. return Object.assign({}, TemplateChunk, {
  3986. html,
  3987. bindingsData: bindings
  3988. });
  3989. }
  3990. /**
  3991. * Method used to bind expressions to a DOM node
  3992. * @param {string|HTMLElement} html - your static template html structure
  3993. * @param {Array} bindings - list of the expressions to bind to update the markup
  3994. * @returns {TemplateChunk} a new TemplateChunk object having the `update`,`mount`, `unmount` and `clone` methods
  3995. *
  3996. * @example
  3997. *
  3998. * riotDOMBindings
  3999. * .template(
  4000. * `<div expr0><!----></div><div><p expr1><!----><section expr2></section></p>`,
  4001. * [
  4002. * {
  4003. * selector: '[expr0]',
  4004. * redundantAttribute: 'expr0',
  4005. * expressions: [
  4006. * {
  4007. * type: expressionTypes.TEXT,
  4008. * childNodeIndex: 0,
  4009. * evaluate(scope) {
  4010. * return scope.time;
  4011. * },
  4012. * },
  4013. * ],
  4014. * },
  4015. * {
  4016. * selector: '[expr1]',
  4017. * redundantAttribute: 'expr1',
  4018. * expressions: [
  4019. * {
  4020. * type: expressionTypes.TEXT,
  4021. * childNodeIndex: 0,
  4022. * evaluate(scope) {
  4023. * return scope.name;
  4024. * },
  4025. * },
  4026. * {
  4027. * type: 'attribute',
  4028. * name: 'style',
  4029. * evaluate(scope) {
  4030. * return scope.style;
  4031. * },
  4032. * },
  4033. * ],
  4034. * },
  4035. * {
  4036. * selector: '[expr2]',
  4037. * redundantAttribute: 'expr2',
  4038. * type: bindingTypes.IF,
  4039. * evaluate(scope) {
  4040. * return scope.isVisible;
  4041. * },
  4042. * template: riotDOMBindings.template('hello there'),
  4043. * },
  4044. * ]
  4045. * )
  4046. */
  4047. var DOMBindings = /*#__PURE__*/Object.freeze({
  4048. __proto__: null,
  4049. template: create,
  4050. createBinding: create$1,
  4051. createExpression: create$4,
  4052. bindingTypes: bindingTypes,
  4053. expressionTypes: expressionTypes
  4054. });
  4055. function noop() {
  4056. return this;
  4057. }
  4058. /**
  4059. * Autobind the methods of a source object to itself
  4060. * @param {Object} source - probably a riot tag instance
  4061. * @param {Array<string>} methods - list of the methods to autobind
  4062. * @returns {Object} the original object received
  4063. */
  4064. function autobindMethods(source, methods) {
  4065. methods.forEach(method => {
  4066. source[method] = source[method].bind(source);
  4067. });
  4068. return source;
  4069. }
  4070. /**
  4071. * Call the first argument received only if it's a function otherwise return it as it is
  4072. * @param {*} source - anything
  4073. * @returns {*} anything
  4074. */
  4075. function callOrAssign(source) {
  4076. return isFunction(source) ? source.prototype && source.prototype.constructor ? new source() : source() : source;
  4077. }
  4078. /**
  4079. * Converts any DOM node/s to a loopable array
  4080. * @param { HTMLElement|NodeList } els - single html element or a node list
  4081. * @returns { Array } always a loopable object
  4082. */
  4083. function domToArray(els) {
  4084. // can this object be already looped?
  4085. if (!Array.isArray(els)) {
  4086. // is it a node list?
  4087. if (/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(els)) && typeof els.length === 'number') return Array.from(els);else // if it's a single node
  4088. // it will be returned as "array" with one single entry
  4089. return [els];
  4090. } // this object could be looped out of the box
  4091. return els;
  4092. }
  4093. /**
  4094. * Simple helper to find DOM nodes returning them as array like loopable object
  4095. * @param { string|DOMNodeList } selector - either the query or the DOM nodes to arraify
  4096. * @param { HTMLElement } ctx - context defining where the query will search for the DOM nodes
  4097. * @returns { Array } DOM nodes found as array
  4098. */
  4099. function $(selector, ctx) {
  4100. return domToArray(typeof selector === 'string' ? (ctx || document).querySelectorAll(selector) : selector);
  4101. }
  4102. /**
  4103. * Normalize the return values, in case of a single value we avoid to return an array
  4104. * @param { Array } values - list of values we want to return
  4105. * @returns { Array|string|boolean } either the whole list of values or the single one found
  4106. * @private
  4107. */
  4108. const normalize = values => values.length === 1 ? values[0] : values;
  4109. /**
  4110. * Parse all the nodes received to get/remove/check their attributes
  4111. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  4112. * @param { string|Array } name - name or list of attributes
  4113. * @param { string } method - method that will be used to parse the attributes
  4114. * @returns { Array|string } result of the parsing in a list or a single value
  4115. * @private
  4116. */
  4117. function parseNodes(els, name, method) {
  4118. const names = typeof name === 'string' ? [name] : name;
  4119. return normalize(domToArray(els).map(el => {
  4120. return normalize(names.map(n => el[method](n)));
  4121. }));
  4122. }
  4123. /**
  4124. * Set any attribute on a single or a list of DOM nodes
  4125. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  4126. * @param { string|Object } name - either the name of the attribute to set
  4127. * or a list of properties as object key - value
  4128. * @param { string } value - the new value of the attribute (optional)
  4129. * @returns { HTMLElement|NodeList|Array } the original array of elements passed to this function
  4130. *
  4131. * @example
  4132. *
  4133. * import { set } from 'bianco.attr'
  4134. *
  4135. * const img = document.createElement('img')
  4136. *
  4137. * set(img, 'width', 100)
  4138. *
  4139. * // or also
  4140. * set(img, {
  4141. * width: 300,
  4142. * height: 300
  4143. * })
  4144. *
  4145. */
  4146. function set(els, name, value) {
  4147. const attrs = typeof name === 'object' ? name : {
  4148. [name]: value
  4149. };
  4150. const props = Object.keys(attrs);
  4151. domToArray(els).forEach(el => {
  4152. props.forEach(prop => el.setAttribute(prop, attrs[prop]));
  4153. });
  4154. return els;
  4155. }
  4156. /**
  4157. * Get any attribute from a single or a list of DOM nodes
  4158. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  4159. * @param { string|Array } name - name or list of attributes to get
  4160. * @returns { Array|string } list of the attributes found
  4161. *
  4162. * @example
  4163. *
  4164. * import { get } from 'bianco.attr'
  4165. *
  4166. * const img = document.createElement('img')
  4167. *
  4168. * get(img, 'width') // => '200'
  4169. *
  4170. * // or also
  4171. * get(img, ['width', 'height']) // => ['200', '300']
  4172. *
  4173. * // or also
  4174. * get([img1, img2], ['width', 'height']) // => [['200', '300'], ['500', '200']]
  4175. */
  4176. function get(els, name) {
  4177. return parseNodes(els, name, 'getAttribute');
  4178. }
  4179. const CSS_BY_NAME = new Map();
  4180. const STYLE_NODE_SELECTOR = 'style[riot]'; // memoized curried function
  4181. const getStyleNode = (style => {
  4182. return () => {
  4183. // lazy evaluation:
  4184. // if this function was already called before
  4185. // we return its cached result
  4186. if (style) return style; // create a new style element or use an existing one
  4187. // and cache it internally
  4188. style = $(STYLE_NODE_SELECTOR)[0] || document.createElement('style');
  4189. set(style, 'type', 'text/css');
  4190. /* istanbul ignore next */
  4191. if (!style.parentNode) document.head.appendChild(style);
  4192. return style;
  4193. };
  4194. })();
  4195. /**
  4196. * Object that will be used to inject and manage the css of every tag instance
  4197. */
  4198. var cssManager = {
  4199. CSS_BY_NAME,
  4200. /**
  4201. * Save a tag style to be later injected into DOM
  4202. * @param { string } name - if it's passed we will map the css to a tagname
  4203. * @param { string } css - css string
  4204. * @returns {Object} self
  4205. */
  4206. add(name, css) {
  4207. if (!CSS_BY_NAME.has(name)) {
  4208. CSS_BY_NAME.set(name, css);
  4209. this.inject();
  4210. }
  4211. return this;
  4212. },
  4213. /**
  4214. * Inject all previously saved tag styles into DOM
  4215. * innerHTML seems slow: http://jsperf.com/riot-insert-style
  4216. * @returns {Object} self
  4217. */
  4218. inject() {
  4219. getStyleNode().innerHTML = [...CSS_BY_NAME.values()].join('\n');
  4220. return this;
  4221. },
  4222. /**
  4223. * Remove a tag style from the DOM
  4224. * @param {string} name a registered tagname
  4225. * @returns {Object} self
  4226. */
  4227. remove(name) {
  4228. if (CSS_BY_NAME.has(name)) {
  4229. CSS_BY_NAME.delete(name);
  4230. this.inject();
  4231. }
  4232. return this;
  4233. }
  4234. };
  4235. /**
  4236. * Function to curry any javascript method
  4237. * @param {Function} fn - the target function we want to curry
  4238. * @param {...[args]} acc - initial arguments
  4239. * @returns {Function|*} it will return a function until the target function
  4240. * will receive all of its arguments
  4241. */
  4242. function curry(fn) {
  4243. for (var _len = arguments.length, acc = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  4244. acc[_key - 1] = arguments[_key];
  4245. }
  4246. return function () {
  4247. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  4248. args[_key2] = arguments[_key2];
  4249. }
  4250. args = [...acc, ...args];
  4251. return args.length < fn.length ? curry(fn, ...args) : fn(...args);
  4252. };
  4253. }
  4254. /**
  4255. * Get the tag name of any DOM node
  4256. * @param {HTMLElement} element - DOM node we want to inspect
  4257. * @returns {string} name to identify this dom node in riot
  4258. */
  4259. function getName(element) {
  4260. return get(element, IS_DIRECTIVE) || element.tagName.toLowerCase();
  4261. }
  4262. const COMPONENT_CORE_HELPERS = Object.freeze({
  4263. // component helpers
  4264. $(selector) {
  4265. return $(selector, this.root)[0];
  4266. },
  4267. $$(selector) {
  4268. return $(selector, this.root);
  4269. }
  4270. });
  4271. const PURE_COMPONENT_API = Object.freeze({
  4272. [MOUNT_METHOD_KEY]: noop,
  4273. [UPDATE_METHOD_KEY]: noop,
  4274. [UNMOUNT_METHOD_KEY]: noop
  4275. });
  4276. const COMPONENT_LIFECYCLE_METHODS = Object.freeze({
  4277. [SHOULD_UPDATE_KEY]: noop,
  4278. [ON_BEFORE_MOUNT_KEY]: noop,
  4279. [ON_MOUNTED_KEY]: noop,
  4280. [ON_BEFORE_UPDATE_KEY]: noop,
  4281. [ON_UPDATED_KEY]: noop,
  4282. [ON_BEFORE_UNMOUNT_KEY]: noop,
  4283. [ON_UNMOUNTED_KEY]: noop
  4284. });
  4285. const MOCKED_TEMPLATE_INTERFACE = Object.assign({}, PURE_COMPONENT_API, {
  4286. clone: noop,
  4287. createDOM: noop
  4288. });
  4289. /**
  4290. * Performance optimization for the recursive components
  4291. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  4292. * @returns {Object} component like interface
  4293. */
  4294. const memoizedCreateComponent = memoize(createComponent);
  4295. /**
  4296. * Evaluate the component properties either from its real attributes or from its initial user properties
  4297. * @param {HTMLElement} element - component root
  4298. * @param {Object} initialProps - initial props
  4299. * @returns {Object} component props key value pairs
  4300. */
  4301. function evaluateInitialProps(element, initialProps) {
  4302. if (initialProps === void 0) {
  4303. initialProps = {};
  4304. }
  4305. return Object.assign({}, DOMattributesToObject(element), callOrAssign(initialProps));
  4306. }
  4307. /**
  4308. * Bind a DOM node to its component object
  4309. * @param {HTMLElement} node - html node mounted
  4310. * @param {Object} component - Riot.js component object
  4311. * @returns {Object} the component object received as second argument
  4312. */
  4313. const bindDOMNodeToComponentObject = (node, component) => node[DOM_COMPONENT_INSTANCE_PROPERTY$1] = component;
  4314. /**
  4315. * Wrap the Riot.js core API methods using a mapping function
  4316. * @param {Function} mapFunction - lifting function
  4317. * @returns {Object} an object having the { mount, update, unmount } functions
  4318. */
  4319. function createCoreAPIMethods(mapFunction) {
  4320. return [MOUNT_METHOD_KEY, UPDATE_METHOD_KEY, UNMOUNT_METHOD_KEY].reduce((acc, method) => {
  4321. acc[method] = mapFunction(method);
  4322. return acc;
  4323. }, {});
  4324. }
  4325. /**
  4326. * Factory function to create the component templates only once
  4327. * @param {Function} template - component template creation function
  4328. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  4329. * @returns {TemplateChunk} template chunk object
  4330. */
  4331. function componentTemplateFactory(template, componentWrapper) {
  4332. const components = createSubcomponents(componentWrapper.exports ? componentWrapper.exports.components : {});
  4333. return template(create, expressionTypes, bindingTypes, name => {
  4334. // improve support for recursive components
  4335. if (name === componentWrapper.name) return memoizedCreateComponent(componentWrapper); // return the registered components
  4336. return components[name] || COMPONENTS_IMPLEMENTATION_MAP$1.get(name);
  4337. });
  4338. }
  4339. /**
  4340. * Create a pure component
  4341. * @param {Function} pureFactoryFunction - pure component factory function
  4342. * @param {Array} options.slots - component slots
  4343. * @param {Array} options.attributes - component attributes
  4344. * @param {Array} options.template - template factory function
  4345. * @param {Array} options.template - template factory function
  4346. * @param {any} options.props - initial component properties
  4347. * @returns {Object} pure component object
  4348. */
  4349. function createPureComponent(pureFactoryFunction, _ref) {
  4350. let {
  4351. slots,
  4352. attributes,
  4353. props,
  4354. css,
  4355. template
  4356. } = _ref;
  4357. if (template) panic('Pure components can not have html');
  4358. if (css) panic('Pure components do not have css');
  4359. const component = defineDefaults(pureFactoryFunction({
  4360. slots,
  4361. attributes,
  4362. props
  4363. }), PURE_COMPONENT_API);
  4364. return createCoreAPIMethods(method => function () {
  4365. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4366. args[_key] = arguments[_key];
  4367. }
  4368. // intercept the mount calls to bind the DOM node to the pure object created
  4369. // see also https://github.com/riot/riot/issues/2806
  4370. if (method === MOUNT_METHOD_KEY) {
  4371. const [element] = args; // mark this node as pure element
  4372. defineProperty(element, IS_PURE_SYMBOL, true);
  4373. bindDOMNodeToComponentObject(element, component);
  4374. }
  4375. component[method](...args);
  4376. return component;
  4377. });
  4378. }
  4379. /**
  4380. * Create the component interface needed for the @riotjs/dom-bindings tag bindings
  4381. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  4382. * @param {string} componentWrapper.css - component css
  4383. * @param {Function} componentWrapper.template - function that will return the dom-bindings template function
  4384. * @param {Object} componentWrapper.exports - component interface
  4385. * @param {string} componentWrapper.name - component name
  4386. * @returns {Object} component like interface
  4387. */
  4388. function createComponent(componentWrapper) {
  4389. const {
  4390. css,
  4391. template,
  4392. exports,
  4393. name
  4394. } = componentWrapper;
  4395. const templateFn = template ? componentTemplateFactory(template, componentWrapper) : MOCKED_TEMPLATE_INTERFACE;
  4396. return _ref2 => {
  4397. let {
  4398. slots,
  4399. attributes,
  4400. props
  4401. } = _ref2;
  4402. // pure components rendering will be managed by the end user
  4403. if (exports && exports[IS_PURE_SYMBOL]) return createPureComponent(exports, {
  4404. slots,
  4405. attributes,
  4406. props,
  4407. css,
  4408. template
  4409. });
  4410. const componentAPI = callOrAssign(exports) || {};
  4411. const component = defineComponent({
  4412. css,
  4413. template: templateFn,
  4414. componentAPI,
  4415. name
  4416. })({
  4417. slots,
  4418. attributes,
  4419. props
  4420. }); // notice that for the components create via tag binding
  4421. // we need to invert the mount (state/parentScope) arguments
  4422. // the template bindings will only forward the parentScope updates
  4423. // and never deal with the component state
  4424. return {
  4425. mount(element, parentScope, state) {
  4426. return component.mount(element, state, parentScope);
  4427. },
  4428. update(parentScope, state) {
  4429. return component.update(state, parentScope);
  4430. },
  4431. unmount(preserveRoot) {
  4432. return component.unmount(preserveRoot);
  4433. }
  4434. };
  4435. };
  4436. }
  4437. /**
  4438. * Component definition function
  4439. * @param {Object} implementation - the componen implementation will be generated via compiler
  4440. * @param {Object} component - the component initial properties
  4441. * @returns {Object} a new component implementation object
  4442. */
  4443. function defineComponent(_ref3) {
  4444. let {
  4445. css,
  4446. template,
  4447. componentAPI,
  4448. name
  4449. } = _ref3;
  4450. // add the component css into the DOM
  4451. if (css && name) cssManager.add(name, css);
  4452. return curry(enhanceComponentAPI)(defineProperties( // set the component defaults without overriding the original component API
  4453. defineDefaults(componentAPI, Object.assign({}, COMPONENT_LIFECYCLE_METHODS, {
  4454. [PROPS_KEY]: {},
  4455. [STATE_KEY]: {}
  4456. })), Object.assign({
  4457. // defined during the component creation
  4458. [SLOTS_KEY]: null,
  4459. [ROOT_KEY]: null
  4460. }, COMPONENT_CORE_HELPERS, {
  4461. name,
  4462. css,
  4463. template
  4464. })));
  4465. }
  4466. /**
  4467. * Create the bindings to update the component attributes
  4468. * @param {HTMLElement} node - node where we will bind the expressions
  4469. * @param {Array} attributes - list of attribute bindings
  4470. * @returns {TemplateChunk} - template bindings object
  4471. */
  4472. function createAttributeBindings(node, attributes) {
  4473. if (attributes === void 0) {
  4474. attributes = [];
  4475. }
  4476. const expressions = attributes.map(a => create$4(node, a));
  4477. const binding = {};
  4478. return Object.assign(binding, Object.assign({
  4479. expressions
  4480. }, createCoreAPIMethods(method => scope => {
  4481. expressions.forEach(e => e[method](scope));
  4482. return binding;
  4483. })));
  4484. }
  4485. /**
  4486. * Create the subcomponents that can be included inside a tag in runtime
  4487. * @param {Object} components - components imported in runtime
  4488. * @returns {Object} all the components transformed into Riot.Component factory functions
  4489. */
  4490. function createSubcomponents(components) {
  4491. if (components === void 0) {
  4492. components = {};
  4493. }
  4494. return Object.entries(callOrAssign(components)).reduce((acc, _ref4) => {
  4495. let [key, value] = _ref4;
  4496. acc[camelToDashCase(key)] = createComponent(value);
  4497. return acc;
  4498. }, {});
  4499. }
  4500. /**
  4501. * Run the component instance through all the plugins set by the user
  4502. * @param {Object} component - component instance
  4503. * @returns {Object} the component enhanced by the plugins
  4504. */
  4505. function runPlugins(component) {
  4506. return [...PLUGINS_SET$1].reduce((c, fn) => fn(c) || c, component);
  4507. }
  4508. /**
  4509. * Compute the component current state merging it with its previous state
  4510. * @param {Object} oldState - previous state object
  4511. * @param {Object} newState - new state givent to the `update` call
  4512. * @returns {Object} new object state
  4513. */
  4514. function computeState(oldState, newState) {
  4515. return Object.assign({}, oldState, callOrAssign(newState));
  4516. }
  4517. /**
  4518. * Add eventually the "is" attribute to link this DOM node to its css
  4519. * @param {HTMLElement} element - target root node
  4520. * @param {string} name - name of the component mounted
  4521. * @returns {undefined} it's a void function
  4522. */
  4523. function addCssHook(element, name) {
  4524. if (getName(element) !== name) {
  4525. set(element, IS_DIRECTIVE, name);
  4526. }
  4527. }
  4528. /**
  4529. * Component creation factory function that will enhance the user provided API
  4530. * @param {Object} component - a component implementation previously defined
  4531. * @param {Array} options.slots - component slots generated via riot compiler
  4532. * @param {Array} options.attributes - attribute expressions generated via riot compiler
  4533. * @returns {Riot.Component} a riot component instance
  4534. */
  4535. function enhanceComponentAPI(component, _ref5) {
  4536. let {
  4537. slots,
  4538. attributes,
  4539. props
  4540. } = _ref5;
  4541. return autobindMethods(runPlugins(defineProperties(isObject(component) ? Object.create(component) : component, {
  4542. mount(element, state, parentScope) {
  4543. if (state === void 0) {
  4544. state = {};
  4545. }
  4546. // any element mounted passing through this function can't be a pure component
  4547. defineProperty(element, IS_PURE_SYMBOL, false);
  4548. this[PARENT_KEY_SYMBOL] = parentScope;
  4549. this[ATTRIBUTES_KEY_SYMBOL] = createAttributeBindings(element, attributes).mount(parentScope);
  4550. defineProperty(this, PROPS_KEY, Object.freeze(Object.assign({}, evaluateInitialProps(element, props), evaluateAttributeExpressions(this[ATTRIBUTES_KEY_SYMBOL].expressions))));
  4551. this[STATE_KEY] = computeState(this[STATE_KEY], state);
  4552. this[TEMPLATE_KEY_SYMBOL] = this.template.createDOM(element).clone(); // link this object to the DOM node
  4553. bindDOMNodeToComponentObject(element, this); // add eventually the 'is' attribute
  4554. component.name && addCssHook(element, component.name); // define the root element
  4555. defineProperty(this, ROOT_KEY, element); // define the slots array
  4556. defineProperty(this, SLOTS_KEY, slots); // before mount lifecycle event
  4557. this[ON_BEFORE_MOUNT_KEY](this[PROPS_KEY], this[STATE_KEY]); // mount the template
  4558. this[TEMPLATE_KEY_SYMBOL].mount(element, this, parentScope);
  4559. this[ON_MOUNTED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  4560. return this;
  4561. },
  4562. update(state, parentScope) {
  4563. if (state === void 0) {
  4564. state = {};
  4565. }
  4566. if (parentScope) {
  4567. this[PARENT_KEY_SYMBOL] = parentScope;
  4568. this[ATTRIBUTES_KEY_SYMBOL].update(parentScope);
  4569. }
  4570. const newProps = evaluateAttributeExpressions(this[ATTRIBUTES_KEY_SYMBOL].expressions);
  4571. if (this[SHOULD_UPDATE_KEY](newProps, this[PROPS_KEY]) === false) return;
  4572. defineProperty(this, PROPS_KEY, Object.freeze(Object.assign({}, this[PROPS_KEY], newProps)));
  4573. this[STATE_KEY] = computeState(this[STATE_KEY], state);
  4574. this[ON_BEFORE_UPDATE_KEY](this[PROPS_KEY], this[STATE_KEY]); // avoiding recursive updates
  4575. // see also https://github.com/riot/riot/issues/2895
  4576. if (!this[IS_COMPONENT_UPDATING]) {
  4577. this[IS_COMPONENT_UPDATING] = true;
  4578. this[TEMPLATE_KEY_SYMBOL].update(this, this[PARENT_KEY_SYMBOL]);
  4579. }
  4580. this[ON_UPDATED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  4581. this[IS_COMPONENT_UPDATING] = false;
  4582. return this;
  4583. },
  4584. unmount(preserveRoot) {
  4585. this[ON_BEFORE_UNMOUNT_KEY](this[PROPS_KEY], this[STATE_KEY]);
  4586. this[ATTRIBUTES_KEY_SYMBOL].unmount(); // if the preserveRoot is null the template html will be left untouched
  4587. // in that case the DOM cleanup will happen differently from a parent node
  4588. this[TEMPLATE_KEY_SYMBOL].unmount(this, this[PARENT_KEY_SYMBOL], preserveRoot === null ? null : !preserveRoot);
  4589. this[ON_UNMOUNTED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  4590. return this;
  4591. }
  4592. })), Object.keys(component).filter(prop => isFunction(component[prop])));
  4593. }
  4594. /**
  4595. * Component initialization function starting from a DOM node
  4596. * @param {HTMLElement} element - element to upgrade
  4597. * @param {Object} initialProps - initial component properties
  4598. * @param {string} componentName - component id
  4599. * @returns {Object} a new component instance bound to a DOM node
  4600. */
  4601. function mountComponent(element, initialProps, componentName) {
  4602. const name = componentName || getName(element);
  4603. if (!COMPONENTS_IMPLEMENTATION_MAP$1.has(name)) panic(`The component named "${name}" was never registered`);
  4604. const component = COMPONENTS_IMPLEMENTATION_MAP$1.get(name)({
  4605. props: initialProps
  4606. });
  4607. return component.mount(element);
  4608. }
  4609. /**
  4610. * Similar to compose but performs from left-to-right function composition.<br/>
  4611. * {@link https://30secondsofcode.org/function#composeright see also}
  4612. * @param {...[function]} fns) - list of unary function
  4613. * @returns {*} result of the computation
  4614. */
  4615. /**
  4616. * Performs right-to-left function composition.<br/>
  4617. * Use Array.prototype.reduce() to perform right-to-left function composition.<br/>
  4618. * The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.<br/>
  4619. * {@link https://30secondsofcode.org/function#compose original source code}
  4620. * @param {...[function]} fns) - list of unary function
  4621. * @returns {*} result of the computation
  4622. */
  4623. function compose() {
  4624. for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  4625. fns[_key2] = arguments[_key2];
  4626. }
  4627. return fns.reduce((f, g) => function () {
  4628. return f(g(...arguments));
  4629. });
  4630. }
  4631. const {
  4632. DOM_COMPONENT_INSTANCE_PROPERTY,
  4633. COMPONENTS_IMPLEMENTATION_MAP,
  4634. PLUGINS_SET
  4635. } = globals;
  4636. /**
  4637. * Riot public api
  4638. */
  4639. /**
  4640. * Register a custom tag by name
  4641. * @param {string} name - component name
  4642. * @param {Object} implementation - tag implementation
  4643. * @returns {Map} map containing all the components implementations
  4644. */
  4645. function register(name, _ref) {
  4646. let {
  4647. css,
  4648. template,
  4649. exports
  4650. } = _ref;
  4651. if (COMPONENTS_IMPLEMENTATION_MAP.has(name)) panic(`The component "${name}" was already registered`);
  4652. COMPONENTS_IMPLEMENTATION_MAP.set(name, createComponent({
  4653. name,
  4654. css,
  4655. template,
  4656. exports
  4657. }));
  4658. return COMPONENTS_IMPLEMENTATION_MAP;
  4659. }
  4660. /**
  4661. * Unregister a riot web component
  4662. * @param {string} name - component name
  4663. * @returns {Map} map containing all the components implementations
  4664. */
  4665. function unregister(name) {
  4666. if (!COMPONENTS_IMPLEMENTATION_MAP.has(name)) panic(`The component "${name}" was never registered`);
  4667. COMPONENTS_IMPLEMENTATION_MAP.delete(name);
  4668. cssManager.remove(name);
  4669. return COMPONENTS_IMPLEMENTATION_MAP;
  4670. }
  4671. /**
  4672. * Mounting function that will work only for the components that were globally registered
  4673. * @param {string|HTMLElement} selector - query for the selection or a DOM element
  4674. * @param {Object} initialProps - the initial component properties
  4675. * @param {string} name - optional component name
  4676. * @returns {Array} list of riot components
  4677. */
  4678. function mount(selector, initialProps, name) {
  4679. return $(selector).map(element => mountComponent(element, initialProps, name));
  4680. }
  4681. /**
  4682. * Sweet unmounting helper function for the DOM node mounted manually by the user
  4683. * @param {string|HTMLElement} selector - query for the selection or a DOM element
  4684. * @param {boolean|null} keepRootElement - if true keep the root element
  4685. * @returns {Array} list of nodes unmounted
  4686. */
  4687. function unmount(selector, keepRootElement) {
  4688. return $(selector).map(element => {
  4689. if (element[DOM_COMPONENT_INSTANCE_PROPERTY]) {
  4690. element[DOM_COMPONENT_INSTANCE_PROPERTY].unmount(keepRootElement);
  4691. }
  4692. return element;
  4693. });
  4694. }
  4695. /**
  4696. * Define a riot plugin
  4697. * @param {Function} plugin - function that will receive all the components created
  4698. * @returns {Set} the set containing all the plugins installed
  4699. */
  4700. function install(plugin) {
  4701. if (!isFunction(plugin)) panic('Plugins must be of type function');
  4702. if (PLUGINS_SET.has(plugin)) panic('This plugin was already installed');
  4703. PLUGINS_SET.add(plugin);
  4704. return PLUGINS_SET;
  4705. }
  4706. /**
  4707. * Uninstall a riot plugin
  4708. * @param {Function} plugin - plugin previously installed
  4709. * @returns {Set} the set containing all the plugins installed
  4710. */
  4711. function uninstall(plugin) {
  4712. if (!PLUGINS_SET.has(plugin)) panic('This plugin was never installed');
  4713. PLUGINS_SET.delete(plugin);
  4714. return PLUGINS_SET;
  4715. }
  4716. /**
  4717. * Helper method to create component without relying on the registered ones
  4718. * @param {Object} implementation - component implementation
  4719. * @returns {Function} function that will allow you to mount a riot component on a DOM node
  4720. */
  4721. function component(implementation) {
  4722. return function (el, props, _temp) {
  4723. let {
  4724. slots,
  4725. attributes,
  4726. parentScope
  4727. } = _temp === void 0 ? {} : _temp;
  4728. return compose(c => c.mount(el, parentScope), c => c({
  4729. props,
  4730. slots,
  4731. attributes
  4732. }), createComponent)(implementation);
  4733. };
  4734. }
  4735. /**
  4736. * Lift a riot component Interface into a pure riot object
  4737. * @param {Function} func - RiotPureComponent factory function
  4738. * @returns {Function} the lifted original function received as argument
  4739. */
  4740. function pure(func) {
  4741. if (!isFunction(func)) panic('riot.pure accepts only arguments of type "function"');
  4742. func[IS_PURE_SYMBOL] = true;
  4743. return func;
  4744. }
  4745. /**
  4746. * no-op function needed to add the proper types to your component via typescript
  4747. * @param {Function|Object} component - component default export
  4748. * @returns {Function|Object} returns exactly what it has received
  4749. */
  4750. const withTypes = component => component;
  4751. /** @type {string} current riot version */
  4752. const version = 'v6.0.3'; // expose some internal stuff that might be used from external tools
  4753. const __ = {
  4754. cssManager,
  4755. DOMBindings,
  4756. createComponent,
  4757. defineComponent,
  4758. globals
  4759. };
  4760. /***/ }),
  4761. /***/ "./node_modules/validate.js/validate.js":
  4762. /*!**********************************************!*\
  4763. !*** ./node_modules/validate.js/validate.js ***!
  4764. \**********************************************/
  4765. /***/ (function(module, exports, __webpack_require__) {
  4766. /* module decorator */ module = __webpack_require__.nmd(module);
  4767. /*!
  4768. * validate.js 0.13.1
  4769. *
  4770. * (c) 2013-2019 Nicklas Ansman, 2013 Wrapp
  4771. * Validate.js may be freely distributed under the MIT license.
  4772. * For all details and documentation:
  4773. * http://validatejs.org/
  4774. */
  4775. (function(exports, module, define) {
  4776. "use strict";
  4777. // The main function that calls the validators specified by the constraints.
  4778. // The options are the following:
  4779. // - format (string) - An option that controls how the returned value is formatted
  4780. // * flat - Returns a flat array of just the error messages
  4781. // * grouped - Returns the messages grouped by attribute (default)
  4782. // * detailed - Returns an array of the raw validation data
  4783. // - fullMessages (boolean) - If `true` (default) the attribute name is prepended to the error.
  4784. //
  4785. // Please note that the options are also passed to each validator.
  4786. var validate = function(attributes, constraints, options) {
  4787. options = v.extend({}, v.options, options);
  4788. var results = v.runValidations(attributes, constraints, options)
  4789. , attr
  4790. , validator;
  4791. if (results.some(function(r) { return v.isPromise(r.error); })) {
  4792. throw new Error("Use validate.async if you want support for promises");
  4793. }
  4794. return validate.processValidationResults(results, options);
  4795. };
  4796. var v = validate;
  4797. // Copies over attributes from one or more sources to a single destination.
  4798. // Very much similar to underscore's extend.
  4799. // The first argument is the target object and the remaining arguments will be
  4800. // used as sources.
  4801. v.extend = function(obj) {
  4802. [].slice.call(arguments, 1).forEach(function(source) {
  4803. for (var attr in source) {
  4804. obj[attr] = source[attr];
  4805. }
  4806. });
  4807. return obj;
  4808. };
  4809. v.extend(validate, {
  4810. // This is the version of the library as a semver.
  4811. // The toString function will allow it to be coerced into a string
  4812. version: {
  4813. major: 0,
  4814. minor: 13,
  4815. patch: 1,
  4816. metadata: null,
  4817. toString: function() {
  4818. var version = v.format("%{major}.%{minor}.%{patch}", v.version);
  4819. if (!v.isEmpty(v.version.metadata)) {
  4820. version += "+" + v.version.metadata;
  4821. }
  4822. return version;
  4823. }
  4824. },
  4825. // Below is the dependencies that are used in validate.js
  4826. // The constructor of the Promise implementation.
  4827. // If you are using Q.js, RSVP or any other A+ compatible implementation
  4828. // override this attribute to be the constructor of that promise.
  4829. // Since jQuery promises aren't A+ compatible they won't work.
  4830. Promise: typeof Promise !== "undefined" ? Promise : /* istanbul ignore next */ null,
  4831. EMPTY_STRING_REGEXP: /^\s*$/,
  4832. // Runs the validators specified by the constraints object.
  4833. // Will return an array of the format:
  4834. // [{attribute: "<attribute name>", error: "<validation result>"}, ...]
  4835. runValidations: function(attributes, constraints, options) {
  4836. var results = []
  4837. , attr
  4838. , validatorName
  4839. , value
  4840. , validators
  4841. , validator
  4842. , validatorOptions
  4843. , error;
  4844. if (v.isDomElement(attributes) || v.isJqueryElement(attributes)) {
  4845. attributes = v.collectFormValues(attributes);
  4846. }
  4847. // Loops through each constraints, finds the correct validator and run it.
  4848. for (attr in constraints) {
  4849. value = v.getDeepObjectValue(attributes, attr);
  4850. // This allows the constraints for an attribute to be a function.
  4851. // The function will be called with the value, attribute name, the complete dict of
  4852. // attributes as well as the options and constraints passed in.
  4853. // This is useful when you want to have different
  4854. // validations depending on the attribute value.
  4855. validators = v.result(constraints[attr], value, attributes, attr, options, constraints);
  4856. for (validatorName in validators) {
  4857. validator = v.validators[validatorName];
  4858. if (!validator) {
  4859. error = v.format("Unknown validator %{name}", {name: validatorName});
  4860. throw new Error(error);
  4861. }
  4862. validatorOptions = validators[validatorName];
  4863. // This allows the options to be a function. The function will be
  4864. // called with the value, attribute name, the complete dict of
  4865. // attributes as well as the options and constraints passed in.
  4866. // This is useful when you want to have different
  4867. // validations depending on the attribute value.
  4868. validatorOptions = v.result(validatorOptions, value, attributes, attr, options, constraints);
  4869. if (!validatorOptions) {
  4870. continue;
  4871. }
  4872. results.push({
  4873. attribute: attr,
  4874. value: value,
  4875. validator: validatorName,
  4876. globalOptions: options,
  4877. attributes: attributes,
  4878. options: validatorOptions,
  4879. error: validator.call(validator,
  4880. value,
  4881. validatorOptions,
  4882. attr,
  4883. attributes,
  4884. options)
  4885. });
  4886. }
  4887. }
  4888. return results;
  4889. },
  4890. // Takes the output from runValidations and converts it to the correct
  4891. // output format.
  4892. processValidationResults: function(errors, options) {
  4893. errors = v.pruneEmptyErrors(errors, options);
  4894. errors = v.expandMultipleErrors(errors, options);
  4895. errors = v.convertErrorMessages(errors, options);
  4896. var format = options.format || "grouped";
  4897. if (typeof v.formatters[format] === 'function') {
  4898. errors = v.formatters[format](errors);
  4899. } else {
  4900. throw new Error(v.format("Unknown format %{format}", options));
  4901. }
  4902. return v.isEmpty(errors) ? undefined : errors;
  4903. },
  4904. // Runs the validations with support for promises.
  4905. // This function will return a promise that is settled when all the
  4906. // validation promises have been completed.
  4907. // It can be called even if no validations returned a promise.
  4908. async: function(attributes, constraints, options) {
  4909. options = v.extend({}, v.async.options, options);
  4910. var WrapErrors = options.wrapErrors || function(errors) {
  4911. return errors;
  4912. };
  4913. // Removes unknown attributes
  4914. if (options.cleanAttributes !== false) {
  4915. attributes = v.cleanAttributes(attributes, constraints);
  4916. }
  4917. var results = v.runValidations(attributes, constraints, options);
  4918. return new v.Promise(function(resolve, reject) {
  4919. v.waitForResults(results).then(function() {
  4920. var errors = v.processValidationResults(results, options);
  4921. if (errors) {
  4922. reject(new WrapErrors(errors, options, attributes, constraints));
  4923. } else {
  4924. resolve(attributes);
  4925. }
  4926. }, function(err) {
  4927. reject(err);
  4928. });
  4929. });
  4930. },
  4931. single: function(value, constraints, options) {
  4932. options = v.extend({}, v.single.options, options, {
  4933. format: "flat",
  4934. fullMessages: false
  4935. });
  4936. return v({single: value}, {single: constraints}, options);
  4937. },
  4938. // Returns a promise that is resolved when all promises in the results array
  4939. // are settled. The promise returned from this function is always resolved,
  4940. // never rejected.
  4941. // This function modifies the input argument, it replaces the promises
  4942. // with the value returned from the promise.
  4943. waitForResults: function(results) {
  4944. // Create a sequence of all the results starting with a resolved promise.
  4945. return results.reduce(function(memo, result) {
  4946. // If this result isn't a promise skip it in the sequence.
  4947. if (!v.isPromise(result.error)) {
  4948. return memo;
  4949. }
  4950. return memo.then(function() {
  4951. return result.error.then(function(error) {
  4952. result.error = error || null;
  4953. });
  4954. });
  4955. }, new v.Promise(function(r) { r(); })); // A resolved promise
  4956. },
  4957. // If the given argument is a call: function the and: function return the value
  4958. // otherwise just return the value. Additional arguments will be passed as
  4959. // arguments to the function.
  4960. // Example:
  4961. // ```
  4962. // result('foo') // 'foo'
  4963. // result(Math.max, 1, 2) // 2
  4964. // ```
  4965. result: function(value) {
  4966. var args = [].slice.call(arguments, 1);
  4967. if (typeof value === 'function') {
  4968. value = value.apply(null, args);
  4969. }
  4970. return value;
  4971. },
  4972. // Checks if the value is a number. This function does not consider NaN a
  4973. // number like many other `isNumber` functions do.
  4974. isNumber: function(value) {
  4975. return typeof value === 'number' && !isNaN(value);
  4976. },
  4977. // Returns false if the object is not a function
  4978. isFunction: function(value) {
  4979. return typeof value === 'function';
  4980. },
  4981. // A simple check to verify that the value is an integer. Uses `isNumber`
  4982. // and a simple modulo check.
  4983. isInteger: function(value) {
  4984. return v.isNumber(value) && value % 1 === 0;
  4985. },
  4986. // Checks if the value is a boolean
  4987. isBoolean: function(value) {
  4988. return typeof value === 'boolean';
  4989. },
  4990. // Uses the `Object` function to check if the given argument is an object.
  4991. isObject: function(obj) {
  4992. return obj === Object(obj);
  4993. },
  4994. // Simply checks if the object is an instance of a date
  4995. isDate: function(obj) {
  4996. return obj instanceof Date;
  4997. },
  4998. // Returns false if the object is `null` of `undefined`
  4999. isDefined: function(obj) {
  5000. return obj !== null && obj !== undefined;
  5001. },
  5002. // Checks if the given argument is a promise. Anything with a `then`
  5003. // function is considered a promise.
  5004. isPromise: function(p) {
  5005. return !!p && v.isFunction(p.then);
  5006. },
  5007. isJqueryElement: function(o) {
  5008. return o && v.isString(o.jquery);
  5009. },
  5010. isDomElement: function(o) {
  5011. if (!o) {
  5012. return false;
  5013. }
  5014. if (!o.querySelectorAll || !o.querySelector) {
  5015. return false;
  5016. }
  5017. if (v.isObject(document) && o === document) {
  5018. return true;
  5019. }
  5020. // http://stackoverflow.com/a/384380/699304
  5021. /* istanbul ignore else */
  5022. if (typeof HTMLElement === "object") {
  5023. return o instanceof HTMLElement;
  5024. } else {
  5025. return o &&
  5026. typeof o === "object" &&
  5027. o !== null &&
  5028. o.nodeType === 1 &&
  5029. typeof o.nodeName === "string";
  5030. }
  5031. },
  5032. isEmpty: function(value) {
  5033. var attr;
  5034. // Null and undefined are empty
  5035. if (!v.isDefined(value)) {
  5036. return true;
  5037. }
  5038. // functions are non empty
  5039. if (v.isFunction(value)) {
  5040. return false;
  5041. }
  5042. // Whitespace only strings are empty
  5043. if (v.isString(value)) {
  5044. return v.EMPTY_STRING_REGEXP.test(value);
  5045. }
  5046. // For arrays we use the length property
  5047. if (v.isArray(value)) {
  5048. return value.length === 0;
  5049. }
  5050. // Dates have no attributes but aren't empty
  5051. if (v.isDate(value)) {
  5052. return false;
  5053. }
  5054. // If we find at least one property we consider it non empty
  5055. if (v.isObject(value)) {
  5056. for (attr in value) {
  5057. return false;
  5058. }
  5059. return true;
  5060. }
  5061. return false;
  5062. },
  5063. // Formats the specified strings with the given values like so:
  5064. // ```
  5065. // format("Foo: %{foo}", {foo: "bar"}) // "Foo bar"
  5066. // ```
  5067. // If you want to write %{...} without having it replaced simply
  5068. // prefix it with % like this `Foo: %%{foo}` and it will be returned
  5069. // as `"Foo: %{foo}"`
  5070. format: v.extend(function(str, vals) {
  5071. if (!v.isString(str)) {
  5072. return str;
  5073. }
  5074. return str.replace(v.format.FORMAT_REGEXP, function(m0, m1, m2) {
  5075. if (m1 === '%') {
  5076. return "%{" + m2 + "}";
  5077. } else {
  5078. return String(vals[m2]);
  5079. }
  5080. });
  5081. }, {
  5082. // Finds %{key} style patterns in the given string
  5083. FORMAT_REGEXP: /(%?)%\{([^\}]+)\}/g
  5084. }),
  5085. // "Prettifies" the given string.
  5086. // Prettifying means replacing [.\_-] with spaces as well as splitting
  5087. // camel case words.
  5088. prettify: function(str) {
  5089. if (v.isNumber(str)) {
  5090. // If there are more than 2 decimals round it to two
  5091. if ((str * 100) % 1 === 0) {
  5092. return "" + str;
  5093. } else {
  5094. return parseFloat(Math.round(str * 100) / 100).toFixed(2);
  5095. }
  5096. }
  5097. if (v.isArray(str)) {
  5098. return str.map(function(s) { return v.prettify(s); }).join(", ");
  5099. }
  5100. if (v.isObject(str)) {
  5101. if (!v.isDefined(str.toString)) {
  5102. return JSON.stringify(str);
  5103. }
  5104. return str.toString();
  5105. }
  5106. // Ensure the string is actually a string
  5107. str = "" + str;
  5108. return str
  5109. // Splits keys separated by periods
  5110. .replace(/([^\s])\.([^\s])/g, '$1 $2')
  5111. // Removes backslashes
  5112. .replace(/\\+/g, '')
  5113. // Replaces - and - with space
  5114. .replace(/[_-]/g, ' ')
  5115. // Splits camel cased words
  5116. .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {
  5117. return "" + m1 + " " + m2.toLowerCase();
  5118. })
  5119. .toLowerCase();
  5120. },
  5121. stringifyValue: function(value, options) {
  5122. var prettify = options && options.prettify || v.prettify;
  5123. return prettify(value);
  5124. },
  5125. isString: function(value) {
  5126. return typeof value === 'string';
  5127. },
  5128. isArray: function(value) {
  5129. return {}.toString.call(value) === '[object Array]';
  5130. },
  5131. // Checks if the object is a hash, which is equivalent to an object that
  5132. // is neither an array nor a function.
  5133. isHash: function(value) {
  5134. return v.isObject(value) && !v.isArray(value) && !v.isFunction(value);
  5135. },
  5136. contains: function(obj, value) {
  5137. if (!v.isDefined(obj)) {
  5138. return false;
  5139. }
  5140. if (v.isArray(obj)) {
  5141. return obj.indexOf(value) !== -1;
  5142. }
  5143. return value in obj;
  5144. },
  5145. unique: function(array) {
  5146. if (!v.isArray(array)) {
  5147. return array;
  5148. }
  5149. return array.filter(function(el, index, array) {
  5150. return array.indexOf(el) == index;
  5151. });
  5152. },
  5153. forEachKeyInKeypath: function(object, keypath, callback) {
  5154. if (!v.isString(keypath)) {
  5155. return undefined;
  5156. }
  5157. var key = ""
  5158. , i
  5159. , escape = false;
  5160. for (i = 0; i < keypath.length; ++i) {
  5161. switch (keypath[i]) {
  5162. case '.':
  5163. if (escape) {
  5164. escape = false;
  5165. key += '.';
  5166. } else {
  5167. object = callback(object, key, false);
  5168. key = "";
  5169. }
  5170. break;
  5171. case '\\':
  5172. if (escape) {
  5173. escape = false;
  5174. key += '\\';
  5175. } else {
  5176. escape = true;
  5177. }
  5178. break;
  5179. default:
  5180. escape = false;
  5181. key += keypath[i];
  5182. break;
  5183. }
  5184. }
  5185. return callback(object, key, true);
  5186. },
  5187. getDeepObjectValue: function(obj, keypath) {
  5188. if (!v.isObject(obj)) {
  5189. return undefined;
  5190. }
  5191. return v.forEachKeyInKeypath(obj, keypath, function(obj, key) {
  5192. if (v.isObject(obj)) {
  5193. return obj[key];
  5194. }
  5195. });
  5196. },
  5197. // This returns an object with all the values of the form.
  5198. // It uses the input name as key and the value as value
  5199. // So for example this:
  5200. // <input type="text" name="email" value="foo@bar.com" />
  5201. // would return:
  5202. // {email: "foo@bar.com"}
  5203. collectFormValues: function(form, options) {
  5204. var values = {}
  5205. , i
  5206. , j
  5207. , input
  5208. , inputs
  5209. , option
  5210. , value;
  5211. if (v.isJqueryElement(form)) {
  5212. form = form[0];
  5213. }
  5214. if (!form) {
  5215. return values;
  5216. }
  5217. options = options || {};
  5218. inputs = form.querySelectorAll("input[name], textarea[name]");
  5219. for (i = 0; i < inputs.length; ++i) {
  5220. input = inputs.item(i);
  5221. if (v.isDefined(input.getAttribute("data-ignored"))) {
  5222. continue;
  5223. }
  5224. var name = input.name.replace(/\./g, "\\\\.");
  5225. value = v.sanitizeFormValue(input.value, options);
  5226. if (input.type === "number") {
  5227. value = value ? +value : null;
  5228. } else if (input.type === "checkbox") {
  5229. if (input.attributes.value) {
  5230. if (!input.checked) {
  5231. value = values[name] || null;
  5232. }
  5233. } else {
  5234. value = input.checked;
  5235. }
  5236. } else if (input.type === "radio") {
  5237. if (!input.checked) {
  5238. value = values[name] || null;
  5239. }
  5240. }
  5241. values[name] = value;
  5242. }
  5243. inputs = form.querySelectorAll("select[name]");
  5244. for (i = 0; i < inputs.length; ++i) {
  5245. input = inputs.item(i);
  5246. if (v.isDefined(input.getAttribute("data-ignored"))) {
  5247. continue;
  5248. }
  5249. if (input.multiple) {
  5250. value = [];
  5251. for (j in input.options) {
  5252. option = input.options[j];
  5253. if (option && option.selected) {
  5254. value.push(v.sanitizeFormValue(option.value, options));
  5255. }
  5256. }
  5257. } else {
  5258. var _val = typeof input.options[input.selectedIndex] !== 'undefined' ? input.options[input.selectedIndex].value : /* istanbul ignore next */ '';
  5259. value = v.sanitizeFormValue(_val, options);
  5260. }
  5261. values[input.name] = value;
  5262. }
  5263. return values;
  5264. },
  5265. sanitizeFormValue: function(value, options) {
  5266. if (options.trim && v.isString(value)) {
  5267. value = value.trim();
  5268. }
  5269. if (options.nullify !== false && value === "") {
  5270. return null;
  5271. }
  5272. return value;
  5273. },
  5274. capitalize: function(str) {
  5275. if (!v.isString(str)) {
  5276. return str;
  5277. }
  5278. return str[0].toUpperCase() + str.slice(1);
  5279. },
  5280. // Remove all errors who's error attribute is empty (null or undefined)
  5281. pruneEmptyErrors: function(errors) {
  5282. return errors.filter(function(error) {
  5283. return !v.isEmpty(error.error);
  5284. });
  5285. },
  5286. // In
  5287. // [{error: ["err1", "err2"], ...}]
  5288. // Out
  5289. // [{error: "err1", ...}, {error: "err2", ...}]
  5290. //
  5291. // All attributes in an error with multiple messages are duplicated
  5292. // when expanding the errors.
  5293. expandMultipleErrors: function(errors) {
  5294. var ret = [];
  5295. errors.forEach(function(error) {
  5296. // Removes errors without a message
  5297. if (v.isArray(error.error)) {
  5298. error.error.forEach(function(msg) {
  5299. ret.push(v.extend({}, error, {error: msg}));
  5300. });
  5301. } else {
  5302. ret.push(error);
  5303. }
  5304. });
  5305. return ret;
  5306. },
  5307. // Converts the error mesages by prepending the attribute name unless the
  5308. // message is prefixed by ^
  5309. convertErrorMessages: function(errors, options) {
  5310. options = options || {};
  5311. var ret = []
  5312. , prettify = options.prettify || v.prettify;
  5313. errors.forEach(function(errorInfo) {
  5314. var error = v.result(errorInfo.error,
  5315. errorInfo.value,
  5316. errorInfo.attribute,
  5317. errorInfo.options,
  5318. errorInfo.attributes,
  5319. errorInfo.globalOptions);
  5320. if (!v.isString(error)) {
  5321. ret.push(errorInfo);
  5322. return;
  5323. }
  5324. if (error[0] === '^') {
  5325. error = error.slice(1);
  5326. } else if (options.fullMessages !== false) {
  5327. error = v.capitalize(prettify(errorInfo.attribute)) + " " + error;
  5328. }
  5329. error = error.replace(/\\\^/g, "^");
  5330. error = v.format(error, {
  5331. value: v.stringifyValue(errorInfo.value, options)
  5332. });
  5333. ret.push(v.extend({}, errorInfo, {error: error}));
  5334. });
  5335. return ret;
  5336. },
  5337. // In:
  5338. // [{attribute: "<attributeName>", ...}]
  5339. // Out:
  5340. // {"<attributeName>": [{attribute: "<attributeName>", ...}]}
  5341. groupErrorsByAttribute: function(errors) {
  5342. var ret = {};
  5343. errors.forEach(function(error) {
  5344. var list = ret[error.attribute];
  5345. if (list) {
  5346. list.push(error);
  5347. } else {
  5348. ret[error.attribute] = [error];
  5349. }
  5350. });
  5351. return ret;
  5352. },
  5353. // In:
  5354. // [{error: "<message 1>", ...}, {error: "<message 2>", ...}]
  5355. // Out:
  5356. // ["<message 1>", "<message 2>"]
  5357. flattenErrorsToArray: function(errors) {
  5358. return errors
  5359. .map(function(error) { return error.error; })
  5360. .filter(function(value, index, self) {
  5361. return self.indexOf(value) === index;
  5362. });
  5363. },
  5364. cleanAttributes: function(attributes, whitelist) {
  5365. function whitelistCreator(obj, key, last) {
  5366. if (v.isObject(obj[key])) {
  5367. return obj[key];
  5368. }
  5369. return (obj[key] = last ? true : {});
  5370. }
  5371. function buildObjectWhitelist(whitelist) {
  5372. var ow = {}
  5373. , lastObject
  5374. , attr;
  5375. for (attr in whitelist) {
  5376. if (!whitelist[attr]) {
  5377. continue;
  5378. }
  5379. v.forEachKeyInKeypath(ow, attr, whitelistCreator);
  5380. }
  5381. return ow;
  5382. }
  5383. function cleanRecursive(attributes, whitelist) {
  5384. if (!v.isObject(attributes)) {
  5385. return attributes;
  5386. }
  5387. var ret = v.extend({}, attributes)
  5388. , w
  5389. , attribute;
  5390. for (attribute in attributes) {
  5391. w = whitelist[attribute];
  5392. if (v.isObject(w)) {
  5393. ret[attribute] = cleanRecursive(ret[attribute], w);
  5394. } else if (!w) {
  5395. delete ret[attribute];
  5396. }
  5397. }
  5398. return ret;
  5399. }
  5400. if (!v.isObject(whitelist) || !v.isObject(attributes)) {
  5401. return {};
  5402. }
  5403. whitelist = buildObjectWhitelist(whitelist);
  5404. return cleanRecursive(attributes, whitelist);
  5405. },
  5406. exposeModule: function(validate, root, exports, module, define) {
  5407. if (exports) {
  5408. if (module && module.exports) {
  5409. exports = module.exports = validate;
  5410. }
  5411. exports.validate = validate;
  5412. } else {
  5413. root.validate = validate;
  5414. if (validate.isFunction(define) && define.amd) {
  5415. define([], function () { return validate; });
  5416. }
  5417. }
  5418. },
  5419. warn: function(msg) {
  5420. if (typeof console !== "undefined" && console.warn) {
  5421. console.warn("[validate.js] " + msg);
  5422. }
  5423. },
  5424. error: function(msg) {
  5425. if (typeof console !== "undefined" && console.error) {
  5426. console.error("[validate.js] " + msg);
  5427. }
  5428. }
  5429. });
  5430. validate.validators = {
  5431. // Presence validates that the value isn't empty
  5432. presence: function(value, options) {
  5433. options = v.extend({}, this.options, options);
  5434. if (options.allowEmpty !== false ? !v.isDefined(value) : v.isEmpty(value)) {
  5435. return options.message || this.message || "can't be blank";
  5436. }
  5437. },
  5438. length: function(value, options, attribute) {
  5439. // Empty values are allowed
  5440. if (!v.isDefined(value)) {
  5441. return;
  5442. }
  5443. options = v.extend({}, this.options, options);
  5444. var is = options.is
  5445. , maximum = options.maximum
  5446. , minimum = options.minimum
  5447. , tokenizer = options.tokenizer || function(val) { return val; }
  5448. , err
  5449. , errors = [];
  5450. value = tokenizer(value);
  5451. var length = value.length;
  5452. if(!v.isNumber(length)) {
  5453. return options.message || this.notValid || "has an incorrect length";
  5454. }
  5455. // Is checks
  5456. if (v.isNumber(is) && length !== is) {
  5457. err = options.wrongLength ||
  5458. this.wrongLength ||
  5459. "is the wrong length (should be %{count} characters)";
  5460. errors.push(v.format(err, {count: is}));
  5461. }
  5462. if (v.isNumber(minimum) && length < minimum) {
  5463. err = options.tooShort ||
  5464. this.tooShort ||
  5465. "is too short (minimum is %{count} characters)";
  5466. errors.push(v.format(err, {count: minimum}));
  5467. }
  5468. if (v.isNumber(maximum) && length > maximum) {
  5469. err = options.tooLong ||
  5470. this.tooLong ||
  5471. "is too long (maximum is %{count} characters)";
  5472. errors.push(v.format(err, {count: maximum}));
  5473. }
  5474. if (errors.length > 0) {
  5475. return options.message || errors;
  5476. }
  5477. },
  5478. numericality: function(value, options, attribute, attributes, globalOptions) {
  5479. // Empty values are fine
  5480. if (!v.isDefined(value)) {
  5481. return;
  5482. }
  5483. options = v.extend({}, this.options, options);
  5484. var errors = []
  5485. , name
  5486. , count
  5487. , checks = {
  5488. greaterThan: function(v, c) { return v > c; },
  5489. greaterThanOrEqualTo: function(v, c) { return v >= c; },
  5490. equalTo: function(v, c) { return v === c; },
  5491. lessThan: function(v, c) { return v < c; },
  5492. lessThanOrEqualTo: function(v, c) { return v <= c; },
  5493. divisibleBy: function(v, c) { return v % c === 0; }
  5494. }
  5495. , prettify = options.prettify ||
  5496. (globalOptions && globalOptions.prettify) ||
  5497. v.prettify;
  5498. // Strict will check that it is a valid looking number
  5499. if (v.isString(value) && options.strict) {
  5500. var pattern = "^-?(0|[1-9]\\d*)";
  5501. if (!options.onlyInteger) {
  5502. pattern += "(\\.\\d+)?";
  5503. }
  5504. pattern += "$";
  5505. if (!(new RegExp(pattern).test(value))) {
  5506. return options.message ||
  5507. options.notValid ||
  5508. this.notValid ||
  5509. this.message ||
  5510. "must be a valid number";
  5511. }
  5512. }
  5513. // Coerce the value to a number unless we're being strict.
  5514. if (options.noStrings !== true && v.isString(value) && !v.isEmpty(value)) {
  5515. value = +value;
  5516. }
  5517. // If it's not a number we shouldn't continue since it will compare it.
  5518. if (!v.isNumber(value)) {
  5519. return options.message ||
  5520. options.notValid ||
  5521. this.notValid ||
  5522. this.message ||
  5523. "is not a number";
  5524. }
  5525. // Same logic as above, sort of. Don't bother with comparisons if this
  5526. // doesn't pass.
  5527. if (options.onlyInteger && !v.isInteger(value)) {
  5528. return options.message ||
  5529. options.notInteger ||
  5530. this.notInteger ||
  5531. this.message ||
  5532. "must be an integer";
  5533. }
  5534. for (name in checks) {
  5535. count = options[name];
  5536. if (v.isNumber(count) && !checks[name](value, count)) {
  5537. // This picks the default message if specified
  5538. // For example the greaterThan check uses the message from
  5539. // this.notGreaterThan so we capitalize the name and prepend "not"
  5540. var key = "not" + v.capitalize(name);
  5541. var msg = options[key] ||
  5542. this[key] ||
  5543. this.message ||
  5544. "must be %{type} %{count}";
  5545. errors.push(v.format(msg, {
  5546. count: count,
  5547. type: prettify(name)
  5548. }));
  5549. }
  5550. }
  5551. if (options.odd && value % 2 !== 1) {
  5552. errors.push(options.notOdd ||
  5553. this.notOdd ||
  5554. this.message ||
  5555. "must be odd");
  5556. }
  5557. if (options.even && value % 2 !== 0) {
  5558. errors.push(options.notEven ||
  5559. this.notEven ||
  5560. this.message ||
  5561. "must be even");
  5562. }
  5563. if (errors.length) {
  5564. return options.message || errors;
  5565. }
  5566. },
  5567. datetime: v.extend(function(value, options) {
  5568. if (!v.isFunction(this.parse) || !v.isFunction(this.format)) {
  5569. throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");
  5570. }
  5571. // Empty values are fine
  5572. if (!v.isDefined(value)) {
  5573. return;
  5574. }
  5575. options = v.extend({}, this.options, options);
  5576. var err
  5577. , errors = []
  5578. , earliest = options.earliest ? this.parse(options.earliest, options) : NaN
  5579. , latest = options.latest ? this.parse(options.latest, options) : NaN;
  5580. value = this.parse(value, options);
  5581. // 86400000 is the number of milliseconds in a day, this is used to remove
  5582. // the time from the date
  5583. if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
  5584. err = options.notValid ||
  5585. options.message ||
  5586. this.notValid ||
  5587. "must be a valid date";
  5588. return v.format(err, {value: arguments[0]});
  5589. }
  5590. if (!isNaN(earliest) && value < earliest) {
  5591. err = options.tooEarly ||
  5592. options.message ||
  5593. this.tooEarly ||
  5594. "must be no earlier than %{date}";
  5595. err = v.format(err, {
  5596. value: this.format(value, options),
  5597. date: this.format(earliest, options)
  5598. });
  5599. errors.push(err);
  5600. }
  5601. if (!isNaN(latest) && value > latest) {
  5602. err = options.tooLate ||
  5603. options.message ||
  5604. this.tooLate ||
  5605. "must be no later than %{date}";
  5606. err = v.format(err, {
  5607. date: this.format(latest, options),
  5608. value: this.format(value, options)
  5609. });
  5610. errors.push(err);
  5611. }
  5612. if (errors.length) {
  5613. return v.unique(errors);
  5614. }
  5615. }, {
  5616. parse: null,
  5617. format: null
  5618. }),
  5619. date: function(value, options) {
  5620. options = v.extend({}, options, {dateOnly: true});
  5621. return v.validators.datetime.call(v.validators.datetime, value, options);
  5622. },
  5623. format: function(value, options) {
  5624. if (v.isString(options) || (options instanceof RegExp)) {
  5625. options = {pattern: options};
  5626. }
  5627. options = v.extend({}, this.options, options);
  5628. var message = options.message || this.message || "is invalid"
  5629. , pattern = options.pattern
  5630. , match;
  5631. // Empty values are allowed
  5632. if (!v.isDefined(value)) {
  5633. return;
  5634. }
  5635. if (!v.isString(value)) {
  5636. return message;
  5637. }
  5638. if (v.isString(pattern)) {
  5639. pattern = new RegExp(options.pattern, options.flags);
  5640. }
  5641. match = pattern.exec(value);
  5642. if (!match || match[0].length != value.length) {
  5643. return message;
  5644. }
  5645. },
  5646. inclusion: function(value, options) {
  5647. // Empty values are fine
  5648. if (!v.isDefined(value)) {
  5649. return;
  5650. }
  5651. if (v.isArray(options)) {
  5652. options = {within: options};
  5653. }
  5654. options = v.extend({}, this.options, options);
  5655. if (v.contains(options.within, value)) {
  5656. return;
  5657. }
  5658. var message = options.message ||
  5659. this.message ||
  5660. "^%{value} is not included in the list";
  5661. return v.format(message, {value: value});
  5662. },
  5663. exclusion: function(value, options) {
  5664. // Empty values are fine
  5665. if (!v.isDefined(value)) {
  5666. return;
  5667. }
  5668. if (v.isArray(options)) {
  5669. options = {within: options};
  5670. }
  5671. options = v.extend({}, this.options, options);
  5672. if (!v.contains(options.within, value)) {
  5673. return;
  5674. }
  5675. var message = options.message || this.message || "^%{value} is restricted";
  5676. if (v.isString(options.within[value])) {
  5677. value = options.within[value];
  5678. }
  5679. return v.format(message, {value: value});
  5680. },
  5681. email: v.extend(function(value, options) {
  5682. options = v.extend({}, this.options, options);
  5683. var message = options.message || this.message || "is not a valid email";
  5684. // Empty values are fine
  5685. if (!v.isDefined(value)) {
  5686. return;
  5687. }
  5688. if (!v.isString(value)) {
  5689. return message;
  5690. }
  5691. if (!this.PATTERN.exec(value)) {
  5692. return message;
  5693. }
  5694. }, {
  5695. PATTERN: /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i
  5696. }),
  5697. equality: function(value, options, attribute, attributes, globalOptions) {
  5698. if (!v.isDefined(value)) {
  5699. return;
  5700. }
  5701. if (v.isString(options)) {
  5702. options = {attribute: options};
  5703. }
  5704. options = v.extend({}, this.options, options);
  5705. var message = options.message ||
  5706. this.message ||
  5707. "is not equal to %{attribute}";
  5708. if (v.isEmpty(options.attribute) || !v.isString(options.attribute)) {
  5709. throw new Error("The attribute must be a non empty string");
  5710. }
  5711. var otherValue = v.getDeepObjectValue(attributes, options.attribute)
  5712. , comparator = options.comparator || function(v1, v2) {
  5713. return v1 === v2;
  5714. }
  5715. , prettify = options.prettify ||
  5716. (globalOptions && globalOptions.prettify) ||
  5717. v.prettify;
  5718. if (!comparator(value, otherValue, options, attribute, attributes)) {
  5719. return v.format(message, {attribute: prettify(options.attribute)});
  5720. }
  5721. },
  5722. // A URL validator that is used to validate URLs with the ability to
  5723. // restrict schemes and some domains.
  5724. url: function(value, options) {
  5725. if (!v.isDefined(value)) {
  5726. return;
  5727. }
  5728. options = v.extend({}, this.options, options);
  5729. var message = options.message || this.message || "is not a valid url"
  5730. , schemes = options.schemes || this.schemes || ['http', 'https']
  5731. , allowLocal = options.allowLocal || this.allowLocal || false
  5732. , allowDataUrl = options.allowDataUrl || this.allowDataUrl || false;
  5733. if (!v.isString(value)) {
  5734. return message;
  5735. }
  5736. // https://gist.github.com/dperini/729294
  5737. var regex =
  5738. "^" +
  5739. // protocol identifier
  5740. "(?:(?:" + schemes.join("|") + ")://)" +
  5741. // user:pass authentication
  5742. "(?:\\S+(?::\\S*)?@)?" +
  5743. "(?:";
  5744. var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
  5745. if (allowLocal) {
  5746. tld += "?";
  5747. } else {
  5748. regex +=
  5749. // IP address exclusion
  5750. // private & local networks
  5751. "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  5752. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  5753. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})";
  5754. }
  5755. regex +=
  5756. // IP address dotted notation octets
  5757. // excludes loopback network 0.0.0.0
  5758. // excludes reserved space >= 224.0.0.0
  5759. // excludes network & broacast addresses
  5760. // (first & last IP address of each class)
  5761. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  5762. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  5763. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  5764. "|" +
  5765. // host name
  5766. "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
  5767. // domain name
  5768. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
  5769. tld +
  5770. ")" +
  5771. // port number
  5772. "(?::\\d{2,5})?" +
  5773. // resource path
  5774. "(?:[/?#]\\S*)?" +
  5775. "$";
  5776. if (allowDataUrl) {
  5777. // RFC 2397
  5778. var mediaType = "\\w+\\/[-+.\\w]+(?:;[\\w=]+)*";
  5779. var urlchar = "[A-Za-z0-9-_.!~\\*'();\\/?:@&=+$,%]*";
  5780. var dataurl = "data:(?:"+mediaType+")?(?:;base64)?,"+urlchar;
  5781. regex = "(?:"+regex+")|(?:^"+dataurl+"$)";
  5782. }
  5783. var PATTERN = new RegExp(regex, 'i');
  5784. if (!PATTERN.exec(value)) {
  5785. return message;
  5786. }
  5787. },
  5788. type: v.extend(function(value, originalOptions, attribute, attributes, globalOptions) {
  5789. if (v.isString(originalOptions)) {
  5790. originalOptions = {type: originalOptions};
  5791. }
  5792. if (!v.isDefined(value)) {
  5793. return;
  5794. }
  5795. var options = v.extend({}, this.options, originalOptions);
  5796. var type = options.type;
  5797. if (!v.isDefined(type)) {
  5798. throw new Error("No type was specified");
  5799. }
  5800. var check;
  5801. if (v.isFunction(type)) {
  5802. check = type;
  5803. } else {
  5804. check = this.types[type];
  5805. }
  5806. if (!v.isFunction(check)) {
  5807. throw new Error("validate.validators.type.types." + type + " must be a function.");
  5808. }
  5809. if (!check(value, options, attribute, attributes, globalOptions)) {
  5810. var message = originalOptions.message ||
  5811. this.messages[type] ||
  5812. this.message ||
  5813. options.message ||
  5814. (v.isFunction(type) ? "must be of the correct type" : "must be of type %{type}");
  5815. if (v.isFunction(message)) {
  5816. message = message(value, originalOptions, attribute, attributes, globalOptions);
  5817. }
  5818. return v.format(message, {attribute: v.prettify(attribute), type: type});
  5819. }
  5820. }, {
  5821. types: {
  5822. object: function(value) {
  5823. return v.isObject(value) && !v.isArray(value);
  5824. },
  5825. array: v.isArray,
  5826. integer: v.isInteger,
  5827. number: v.isNumber,
  5828. string: v.isString,
  5829. date: v.isDate,
  5830. boolean: v.isBoolean
  5831. },
  5832. messages: {}
  5833. })
  5834. };
  5835. validate.formatters = {
  5836. detailed: function(errors) {return errors;},
  5837. flat: v.flattenErrorsToArray,
  5838. grouped: function(errors) {
  5839. var attr;
  5840. errors = v.groupErrorsByAttribute(errors);
  5841. for (attr in errors) {
  5842. errors[attr] = v.flattenErrorsToArray(errors[attr]);
  5843. }
  5844. return errors;
  5845. },
  5846. constraint: function(errors) {
  5847. var attr;
  5848. errors = v.groupErrorsByAttribute(errors);
  5849. for (attr in errors) {
  5850. errors[attr] = errors[attr].map(function(result) {
  5851. return result.validator;
  5852. }).sort();
  5853. }
  5854. return errors;
  5855. }
  5856. };
  5857. validate.exposeModule(validate, this, exports, module, __webpack_require__.amdD);
  5858. }).call(this,
  5859. true ? /* istanbul ignore next */ exports : 0,
  5860. true ? /* istanbul ignore next */ module : 0,
  5861. __webpack_require__.amdD);
  5862. /***/ }),
  5863. /***/ "./node_modules/axios/package.json":
  5864. /*!*****************************************!*\
  5865. !*** ./node_modules/axios/package.json ***!
  5866. \*****************************************/
  5867. /***/ ((module) => {
  5868. "use strict";
  5869. module.exports = JSON.parse('{"_from":"axios@^0.21.1","_id":"axios@0.21.4","_inBundle":false,"_integrity":"sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.21.1","name":"axios","escapedName":"axios","rawSpec":"^0.21.1","saveSpec":null,"fetchSpec":"^0.21.1"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.21.4.tgz","_shasum":"c67b90dc0568e5c1cf2b0b858c43ba28e2eda575","_spec":"axios@^0.21.1","_where":"/home/herrhase/Workspace/herrhase/nano-buckets","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundleDependencies":false,"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"^1.14.0"},"deprecated":false,"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.3.0","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^23.0.0","grunt-karma":"^4.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^4.0.2","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^6.3.2","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^2.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^4.3.6","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.8","karma-webpack":"^4.0.2","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^8.2.1","sinon":"^4.5.0","terser-webpack-plugin":"^4.2.3","typescript":"^4.0.5","url-search-params":"^0.10.0","webpack":"^4.44.2","webpack-dev-server":"^3.11.0"},"homepage":"https://axios-http.com","jsdelivr":"dist/axios.min.js","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","unpkg":"dist/axios.min.js","version":"0.21.4"}');
  5870. /***/ })
  5871. /******/ });
  5872. /************************************************************************/
  5873. /******/ // The module cache
  5874. /******/ var __webpack_module_cache__ = {};
  5875. /******/
  5876. /******/ // The require function
  5877. /******/ function __webpack_require__(moduleId) {
  5878. /******/ // Check if module is in cache
  5879. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  5880. /******/ if (cachedModule !== undefined) {
  5881. /******/ return cachedModule.exports;
  5882. /******/ }
  5883. /******/ // Create a new module (and put it into the cache)
  5884. /******/ var module = __webpack_module_cache__[moduleId] = {
  5885. /******/ id: moduleId,
  5886. /******/ loaded: false,
  5887. /******/ exports: {}
  5888. /******/ };
  5889. /******/
  5890. /******/ // Execute the module function
  5891. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  5892. /******/
  5893. /******/ // Flag the module as loaded
  5894. /******/ module.loaded = true;
  5895. /******/
  5896. /******/ // Return the exports of the module
  5897. /******/ return module.exports;
  5898. /******/ }
  5899. /******/
  5900. /************************************************************************/
  5901. /******/ /* webpack/runtime/amd define */
  5902. /******/ (() => {
  5903. /******/ __webpack_require__.amdD = function () {
  5904. /******/ throw new Error('define cannot be used indirect');
  5905. /******/ };
  5906. /******/ })();
  5907. /******/
  5908. /******/ /* webpack/runtime/compat get default export */
  5909. /******/ (() => {
  5910. /******/ // getDefaultExport function for compatibility with non-harmony modules
  5911. /******/ __webpack_require__.n = (module) => {
  5912. /******/ var getter = module && module.__esModule ?
  5913. /******/ () => (module['default']) :
  5914. /******/ () => (module);
  5915. /******/ __webpack_require__.d(getter, { a: getter });
  5916. /******/ return getter;
  5917. /******/ };
  5918. /******/ })();
  5919. /******/
  5920. /******/ /* webpack/runtime/define property getters */
  5921. /******/ (() => {
  5922. /******/ // define getter functions for harmony exports
  5923. /******/ __webpack_require__.d = (exports, definition) => {
  5924. /******/ for(var key in definition) {
  5925. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  5926. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  5927. /******/ }
  5928. /******/ }
  5929. /******/ };
  5930. /******/ })();
  5931. /******/
  5932. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  5933. /******/ (() => {
  5934. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  5935. /******/ })();
  5936. /******/
  5937. /******/ /* webpack/runtime/make namespace object */
  5938. /******/ (() => {
  5939. /******/ // define __esModule on exports
  5940. /******/ __webpack_require__.r = (exports) => {
  5941. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  5942. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  5943. /******/ }
  5944. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  5945. /******/ };
  5946. /******/ })();
  5947. /******/
  5948. /******/ /* webpack/runtime/node module decorator */
  5949. /******/ (() => {
  5950. /******/ __webpack_require__.nmd = (module) => {
  5951. /******/ module.paths = [];
  5952. /******/ if (!module.children) module.children = [];
  5953. /******/ return module;
  5954. /******/ };
  5955. /******/ })();
  5956. /******/
  5957. /************************************************************************/
  5958. var __webpack_exports__ = {};
  5959. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  5960. (() => {
  5961. "use strict";
  5962. /*!***************************************!*\
  5963. !*** ./resources/js/bucket-single.js ***!
  5964. \***************************************/
  5965. __webpack_require__.r(__webpack_exports__);
  5966. /* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js");
  5967. /* harmony import */ var _components_note_form_riot__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./components/note-form.riot */ "./resources/js/components/note-form.riot");
  5968. riot__WEBPACK_IMPORTED_MODULE_1__.register('note-form', _components_note_form_riot__WEBPACK_IMPORTED_MODULE_0__["default"]);
  5969. riot__WEBPACK_IMPORTED_MODULE_1__.mount('note-form');
  5970. })();
  5971. /******/ })()
  5972. ;