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.

9945 lines
285 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
  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 expr2="expr2" 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': 'expr2',
  119. 'selector': '[expr2]',
  120. 'template': template(
  121. '<ul><li expr3="expr3"></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': 'expr3',
  150. 'selector': '[expr3]',
  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/loading.riot":
  169. /*!**********************************************!*\
  170. !*** ./resources/js/components/loading.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 default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  179. 'css': null,
  180. 'exports': {},
  181. 'template': function(
  182. template,
  183. expressionTypes,
  184. bindingTypes,
  185. getComponent
  186. ) {
  187. return template(
  188. '<div class="loading-wrapper"><div expr36="expr36" class="loading"></div></div>',
  189. [
  190. {
  191. 'type': bindingTypes.IF,
  192. 'evaluate': function(
  193. _scope
  194. ) {
  195. return _scope.props.loading;
  196. },
  197. 'redundantAttribute': 'expr36',
  198. 'selector': '[expr36]',
  199. 'template': template(
  200. '<span></span><span></span><span></span>',
  201. []
  202. )
  203. }
  204. ]
  205. );
  206. },
  207. 'name': 'app-loading'
  208. });
  209. /***/ }),
  210. /***/ "./resources/js/components/modal.riot":
  211. /*!********************************************!*\
  212. !*** ./resources/js/components/modal.riot ***!
  213. \********************************************/
  214. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  215. "use strict";
  216. __webpack_require__.r(__webpack_exports__);
  217. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  218. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  219. /* harmony export */ });
  220. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  221. 'css': null,
  222. 'exports': {
  223. state: {
  224. confirm: {}
  225. },
  226. onMounted() {
  227. this.root.addEventListener('open', this.__open)
  228. this.root.addEventListener('close', this.__close)
  229. },
  230. __open(event) {
  231. // adding confirm function to state
  232. this.state.confirm = event.detail.confirm
  233. this.state.body = event.detail.body
  234. this.$('.modal').classList.add('modal--open')
  235. this.update()
  236. },
  237. __close(event) {
  238. this.$('.modal').classList.remove('modal--open')
  239. this.update()
  240. },
  241. /**
  242. *
  243. * @param {[type]} event
  244. * @return {[type]}
  245. *
  246. */
  247. handleConfirm(event) {
  248. event.preventDefault()
  249. // calling confirm function
  250. this.state.confirm()
  251. this.__close()
  252. },
  253. /**
  254. *
  255. *
  256. * @param {object} event
  257. *
  258. */
  259. handleClose(event) {
  260. event.preventDefault()
  261. this.__close()
  262. }
  263. },
  264. 'template': function(
  265. template,
  266. expressionTypes,
  267. bindingTypes,
  268. getComponent
  269. ) {
  270. return template(
  271. '<div class="modal"><div class="modal__inner"><div class="modal__title center"><slot expr32="expr32" name="title"></slot></div><div expr33="expr33" class="modal__body"> </div><div class="modal__footer"><button expr34="expr34" class="button button--outline button--danger">\n Confirm\n </button><button expr35="expr35" class="button button--outline float-right">\n Reject\n </button></div></div></div>',
  272. [
  273. {
  274. 'type': bindingTypes.SLOT,
  275. 'attributes': [],
  276. 'name': 'title',
  277. 'redundantAttribute': 'expr32',
  278. 'selector': '[expr32]'
  279. },
  280. {
  281. 'redundantAttribute': 'expr33',
  282. 'selector': '[expr33]',
  283. 'expressions': [
  284. {
  285. 'type': expressionTypes.TEXT,
  286. 'childNodeIndex': 0,
  287. 'evaluate': function(
  288. _scope
  289. ) {
  290. return [
  291. _scope.state.body
  292. ].join(
  293. ''
  294. );
  295. }
  296. }
  297. ]
  298. },
  299. {
  300. 'redundantAttribute': 'expr34',
  301. 'selector': '[expr34]',
  302. 'expressions': [
  303. {
  304. 'type': expressionTypes.EVENT,
  305. 'name': 'onclick',
  306. 'evaluate': function(
  307. _scope
  308. ) {
  309. return (event) => { _scope.handleConfirm(event) };
  310. }
  311. }
  312. ]
  313. },
  314. {
  315. 'redundantAttribute': 'expr35',
  316. 'selector': '[expr35]',
  317. 'expressions': [
  318. {
  319. 'type': expressionTypes.EVENT,
  320. 'name': 'onclick',
  321. 'evaluate': function(
  322. _scope
  323. ) {
  324. return (event) => { _scope.handleClose(event) };
  325. }
  326. }
  327. ]
  328. }
  329. ]
  330. );
  331. },
  332. 'name': 'app-modal'
  333. });
  334. /***/ }),
  335. /***/ "./resources/js/components/sidebar-button.riot":
  336. /*!*****************************************************!*\
  337. !*** ./resources/js/components/sidebar-button.riot ***!
  338. \*****************************************************/
  339. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  340. "use strict";
  341. __webpack_require__.r(__webpack_exports__);
  342. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  343. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  344. /* harmony export */ });
  345. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  346. 'css': null,
  347. 'exports': {
  348. state: {
  349. element: undefined,
  350. data: false
  351. },
  352. /**
  353. *
  354. *
  355. */
  356. onBeforeMount() {
  357. if (this.root.innerHTML) {
  358. this.content = this.root.innerHTML;
  359. this.root.innerHTML = '';
  360. }
  361. if (!this.props.event) {
  362. console.error('sidebar-button: attribute for name of custom event is missing')
  363. }
  364. if (!this.props.selector) {
  365. console.error('sidebar-button: attribute for selector to send custom event is missing')
  366. }
  367. if (this.props.data) {
  368. this.state.data = this.props.data
  369. }
  370. },
  371. /**
  372. *
  373. *
  374. */
  375. onMounted() {
  376. this.state.element = document.querySelector(this.props.selector)
  377. // adding innerHtml to button
  378. if (this.content) {
  379. this.$('button').innerHTML = this.content;
  380. }
  381. },
  382. /**
  383. * create custom event with props
  384. *
  385. * @param {[type]} event
  386. * @return {[type]}
  387. */
  388. handleClick(event) {
  389. event.preventDefault()
  390. const customEvent = new CustomEvent(this.props.event, {
  391. 'detail': {
  392. 'data': this.state.data
  393. }
  394. })
  395. this.state.element.dispatchEvent(customEvent)
  396. }
  397. },
  398. 'template': function(
  399. template,
  400. expressionTypes,
  401. bindingTypes,
  402. getComponent
  403. ) {
  404. return template(
  405. '<button expr0="expr0" class="button m-bottom-0" type="button"><slot expr1="expr1"></slot></button>',
  406. [
  407. {
  408. 'redundantAttribute': 'expr0',
  409. 'selector': '[expr0]',
  410. 'expressions': [
  411. {
  412. 'type': expressionTypes.EVENT,
  413. 'name': 'onclick',
  414. 'evaluate': function(
  415. _scope
  416. ) {
  417. return (event) => { _scope.handleClick(event) };
  418. }
  419. }
  420. ]
  421. },
  422. {
  423. 'type': bindingTypes.SLOT,
  424. 'attributes': [],
  425. 'name': 'default',
  426. 'redundantAttribute': 'expr1',
  427. 'selector': '[expr1]'
  428. }
  429. ]
  430. );
  431. },
  432. 'name': 'app-sidebar-button'
  433. });
  434. /***/ }),
  435. /***/ "./resources/js/components/users.riot":
  436. /*!********************************************!*\
  437. !*** ./resources/js/components/users.riot ***!
  438. \********************************************/
  439. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  440. "use strict";
  441. __webpack_require__.r(__webpack_exports__);
  442. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  443. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  444. /* harmony export */ });
  445. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  446. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);
  447. /* harmony import */ var lodash_remove__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash.remove */ "./node_modules/lodash.remove/index.js");
  448. /* harmony import */ var lodash_remove__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_remove__WEBPACK_IMPORTED_MODULE_1__);
  449. /* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js");
  450. /* harmony import */ var _modal_riot__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modal.riot */ "./resources/js/components/modal.riot");
  451. riot__WEBPACK_IMPORTED_MODULE_3__.register('app-modal', _modal_riot__WEBPACK_IMPORTED_MODULE_2__.default)
  452. riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-modal')
  453. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  454. 'css': null,
  455. 'exports': {
  456. state: {
  457. users: [],
  458. maxLength: 0
  459. },
  460. onBeforeMount() {
  461. this.fetch()
  462. },
  463. /**
  464. *
  465. * @param {[type]} event
  466. * @param {[type]} user
  467. * @return {[type]}
  468. *
  469. */
  470. handleUpdate(event, user) {
  471. const customEvent = new CustomEvent('app-users-form-open', {
  472. 'detail': user
  473. })
  474. document.querySelector('app-users-form').dispatchEvent(customEvent);
  475. },
  476. handleDelete(event, user) {
  477. event.preventDefault()
  478. const customEvent = new CustomEvent('open', {
  479. 'detail': {
  480. 'confirm': () => {
  481. axios__WEBPACK_IMPORTED_MODULE_0___default().delete('/api/users/v1/' + user._id)
  482. .then((response) => {
  483. // removing from buckets
  484. lodash_remove__WEBPACK_IMPORTED_MODULE_1___default()(this.state.users, function(u) {
  485. return u._id === user._id
  486. })
  487. this.update()
  488. })
  489. },
  490. // @TODO find a better solution to create body text
  491. 'body': 'Do you want delete ' + user.email + '?'
  492. }
  493. })
  494. this.$('#user-delete-confirm').dispatchEvent(customEvent);
  495. },
  496. /**
  497. * getting all buckets
  498. *
  499. *
  500. */
  501. fetch() {
  502. axios__WEBPACK_IMPORTED_MODULE_0___default().get('/api/users/v1').then((response) => {
  503. this.state.users = response.data.data
  504. this.update()
  505. })
  506. }
  507. },
  508. 'template': function(
  509. template,
  510. expressionTypes,
  511. bindingTypes,
  512. getComponent
  513. ) {
  514. return template(
  515. '<div class="buckets"><table class="table"><thead><tr class="table__tr"><th class="table__th">\n Email\n </th><th class="table__th">\n Display Name\n </th><th class="table__th" colspan="2">\n Roles\n </th></tr></thead><tbody><tr expr4="expr4" class="table__tr"></tr></tbody></table><app-modal expr10="expr10" id="user-delete-confirm"></app-modal><div expr11="expr11" class="grid"></div></div>',
  516. [
  517. {
  518. 'type': bindingTypes.EACH,
  519. 'getKey': null,
  520. 'condition': null,
  521. 'template': template(
  522. '<td expr5="expr5" class="table__td"> </td><td expr6="expr6" class="table__td"> </td><td class="table__td"><div expr7="expr7"></div></td><td class="table__td right"><app-sidebar-button expr8="expr8" class="m-bottom-0 m-right-3" event="app-users-form-open" selector="app-users-form"></app-sidebar-button><button expr9="expr9" class="button button--small m-bottom-0" type="button"><svg class="icon" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-delete"/></svg></button></td>',
  523. [
  524. {
  525. 'redundantAttribute': 'expr5',
  526. 'selector': '[expr5]',
  527. 'expressions': [
  528. {
  529. 'type': expressionTypes.TEXT,
  530. 'childNodeIndex': 0,
  531. 'evaluate': function(
  532. _scope
  533. ) {
  534. return [
  535. _scope.user.email
  536. ].join(
  537. ''
  538. );
  539. }
  540. }
  541. ]
  542. },
  543. {
  544. 'redundantAttribute': 'expr6',
  545. 'selector': '[expr6]',
  546. 'expressions': [
  547. {
  548. 'type': expressionTypes.TEXT,
  549. 'childNodeIndex': 0,
  550. 'evaluate': function(
  551. _scope
  552. ) {
  553. return [
  554. _scope.user.display_name
  555. ].join(
  556. ''
  557. );
  558. }
  559. }
  560. ]
  561. },
  562. {
  563. 'type': bindingTypes.IF,
  564. 'evaluate': function(
  565. _scope
  566. ) {
  567. return _scope.user.roles && _scope.user.roles.indexOf('admin') >= 0;
  568. },
  569. 'redundantAttribute': 'expr7',
  570. 'selector': '[expr7]',
  571. 'template': template(
  572. '\n Admin\n <svg class="icon" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-check"/></svg>',
  573. []
  574. )
  575. },
  576. {
  577. 'type': bindingTypes.TAG,
  578. 'getComponent': getComponent,
  579. 'evaluate': function(
  580. _scope
  581. ) {
  582. return 'app-sidebar-button';
  583. },
  584. 'slots': [
  585. {
  586. 'id': 'default',
  587. 'html': '<svg class="icon" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-edit"/></svg>',
  588. 'bindings': []
  589. }
  590. ],
  591. 'attributes': [
  592. {
  593. 'type': expressionTypes.ATTRIBUTE,
  594. 'name': 'data',
  595. 'evaluate': function(
  596. _scope
  597. ) {
  598. return _scope.user;
  599. }
  600. }
  601. ],
  602. 'redundantAttribute': 'expr8',
  603. 'selector': '[expr8]'
  604. },
  605. {
  606. 'redundantAttribute': 'expr9',
  607. 'selector': '[expr9]',
  608. 'expressions': [
  609. {
  610. 'type': expressionTypes.EVENT,
  611. 'name': 'onclick',
  612. 'evaluate': function(
  613. _scope
  614. ) {
  615. return (event) => { _scope.handleDelete(event, _scope.user) };
  616. }
  617. }
  618. ]
  619. }
  620. ]
  621. ),
  622. 'redundantAttribute': 'expr4',
  623. 'selector': '[expr4]',
  624. 'itemName': 'user',
  625. 'indexName': null,
  626. 'evaluate': function(
  627. _scope
  628. ) {
  629. return _scope.state.users;
  630. }
  631. },
  632. {
  633. 'type': bindingTypes.TAG,
  634. 'getComponent': getComponent,
  635. 'evaluate': function(
  636. _scope
  637. ) {
  638. return 'app-modal';
  639. },
  640. 'slots': [
  641. {
  642. 'id': 'title',
  643. 'html': '<span slot="title"><svg class="icon fill-text-contrast" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg>\n Delete\n </span>',
  644. 'bindings': []
  645. }
  646. ],
  647. 'attributes': [],
  648. 'redundantAttribute': 'expr10',
  649. 'selector': '[expr10]'
  650. },
  651. {
  652. 'type': bindingTypes.IF,
  653. 'evaluate': function(
  654. _scope
  655. ) {
  656. return _scope.state.maxLength > _scope.state.users.length;
  657. },
  658. 'redundantAttribute': 'expr11',
  659. 'selector': '[expr11]',
  660. 'template': template(
  661. '<div class="col-12"><div class="buckets__more"><button expr12="expr12" type="button" class="button">\n More\n <svg class="icon" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-arrow-down"/></svg></button></div></div>',
  662. [
  663. {
  664. 'redundantAttribute': 'expr12',
  665. 'selector': '[expr12]',
  666. 'expressions': [
  667. {
  668. 'type': expressionTypes.EVENT,
  669. 'name': 'onclick',
  670. 'evaluate': function(
  671. _scope
  672. ) {
  673. return _scope.handleClick;
  674. }
  675. }
  676. ]
  677. }
  678. ]
  679. )
  680. }
  681. ]
  682. );
  683. },
  684. 'name': 'app-users'
  685. });
  686. /***/ }),
  687. /***/ "./resources/js/components/users/form.riot":
  688. /*!*************************************************!*\
  689. !*** ./resources/js/components/users/form.riot ***!
  690. \*************************************************/
  691. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  692. "use strict";
  693. __webpack_require__.r(__webpack_exports__);
  694. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  695. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  696. /* harmony export */ });
  697. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  698. /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);
  699. /* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js");
  700. /* harmony import */ var _FormValidator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../../FormValidator */ "./resources/js/FormValidator.js");
  701. /* harmony import */ var _field_error_riot__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../field-error.riot */ "./resources/js/components/field-error.riot");
  702. /* harmony import */ var _loading_riot__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../loading.riot */ "./resources/js/components/loading.riot");
  703. riot__WEBPACK_IMPORTED_MODULE_4__.register('field-error', _field_error_riot__WEBPACK_IMPORTED_MODULE_2__.default)
  704. riot__WEBPACK_IMPORTED_MODULE_4__.mount('field-error')
  705. riot__WEBPACK_IMPORTED_MODULE_4__.register('app-loading', _loading_riot__WEBPACK_IMPORTED_MODULE_3__.default)
  706. riot__WEBPACK_IMPORTED_MODULE_4__.mount('app-loading')
  707. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
  708. 'css': null,
  709. 'exports': {
  710. state: {
  711. user: {
  712. },
  713. loading: false
  714. },
  715. /**
  716. *
  717. *
  718. */
  719. onMounted(props, state) {
  720. this.root.addEventListener('app-users-form-open', (event) => {
  721. this.$('.sidebar').classList.add('sidebar--open')
  722. // check for data, and if user is send add to state
  723. if (event.detail.data) {
  724. this.state.user = event.detail.data
  725. this.state.formValidation.setConstraits({
  726. 'email': {
  727. 'length': {
  728. 'maximum': 255
  729. },
  730. 'email': true,
  731. 'presence': true
  732. }
  733. })
  734. this.update()
  735. }
  736. })
  737. // create form validation
  738. this.state.formValidation = new _FormValidator__WEBPACK_IMPORTED_MODULE_1__.default('#app-users-form', {
  739. 'email': {
  740. 'length': {
  741. 'maximum': 255
  742. },
  743. 'email': true,
  744. 'presence': true
  745. },
  746. 'password': {
  747. 'length': {
  748. 'maximum': 64
  749. },
  750. 'presence': true
  751. }
  752. }, (event, data) => {
  753. this.handleSubmit(event, data)
  754. })
  755. },
  756. /**
  757. * close current form
  758. *
  759. *
  760. * @param {object} event
  761. *
  762. */
  763. handleClose(event)
  764. {
  765. event.preventDefault()
  766. this.$('.sidebar').classList.remove('sidebar--open')
  767. this.reset()
  768. },
  769. /**
  770. *
  771. *
  772. */
  773. handleSubmit(event, data) {
  774. let method = 'post'
  775. let url = '/api/users/v1'
  776. // user is set and has id, send as put with id
  777. if (this.state.user && this.state.user._id) {
  778. method = 'put'
  779. url += '/' + this.state.user._id
  780. }
  781. this.state.loading = true
  782. this.update()
  783. axios__WEBPACK_IMPORTED_MODULE_0___default()({
  784. method: method,
  785. url: url,
  786. data: data
  787. }).then((response) => {
  788. console.log(response)
  789. this.state.user = response.data.data
  790. // check if submit has close-attribute
  791. if (event.submitter.attributes.close) {
  792. this.$('#sidebar-user-form-close').click()
  793. }
  794. this.state.loading = false
  795. this.update()
  796. })
  797. },
  798. /**
  799. *
  800. *
  801. */
  802. reset() {
  803. this.state.user = { }
  804. this.update()
  805. }
  806. },
  807. 'template': function(
  808. template,
  809. expressionTypes,
  810. bindingTypes,
  811. getComponent
  812. ) {
  813. return template(
  814. '<div class="sidebar"><div class="sidebar__inner"><div class="bar"><div class="bar__main"><span expr22="expr22"></span><span expr23="expr23"></span></div><div class="bar__end"><button expr24="expr24" id="sidebar-user-form-close" class="button button--transparent" type="button"><svg class="icon fill-text-contrast" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg></button></div></div><div class="sidebar__body"><form id="app-users-form" novalidate><div class="field-group"><label class="field-label">\n E-Mail\n <input expr25="expr25" name="email" type="text" class="field-text"/></label><field-error expr26="expr26" name="email"></field-error></div><div class="field-group"><label class="field-label">\n Display Name\n <input expr27="expr27" name="display_name" type="text" class="field-text"/></label><field-error expr28="expr28" name="display_name"></field-error></div><div class="field-group"><label class="field-label">\n Password\n <input name="password" type="password" class="field-text"/></label><field-error expr29="expr29" name="password"></field-error></div><div class="field-group"><label class="field-label"><input name="roles[]" type="checkbox" class="field-choice" value="admin"/><svg class="icon field-choice__unchecked" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-checkbox"/></svg><svg class="icon field-choice__checked" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-checkbox-checked"/></svg>\n Admin\n </label><field-error expr30="expr30" name="roles"></field-error></div></form></div><div class="sidebar__footer"><button class="button m-bottom-0" type="submit" form="app-users-form">\n Save\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-check"/></svg></button><button class="button m-bottom-0" type="submit" form="app-users-form" close>\n Save and Close\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-arrow-right"/></svg></button></div><app-loading expr31="expr31"></app-loading></div></div>',
  815. [
  816. {
  817. 'type': bindingTypes.IF,
  818. 'evaluate': function(
  819. _scope
  820. ) {
  821. return !_scope.state.user._id;
  822. },
  823. 'redundantAttribute': 'expr22',
  824. 'selector': '[expr22]',
  825. 'template': template(
  826. '\n Create User\n ',
  827. []
  828. )
  829. },
  830. {
  831. 'type': bindingTypes.IF,
  832. 'evaluate': function(
  833. _scope
  834. ) {
  835. return _scope.state.user._id;
  836. },
  837. 'redundantAttribute': 'expr23',
  838. 'selector': '[expr23]',
  839. 'template': template(
  840. '\n Update User\n ',
  841. []
  842. )
  843. },
  844. {
  845. 'redundantAttribute': 'expr24',
  846. 'selector': '[expr24]',
  847. 'expressions': [
  848. {
  849. 'type': expressionTypes.EVENT,
  850. 'name': 'onclick',
  851. 'evaluate': function(
  852. _scope
  853. ) {
  854. return (event) => { _scope.handleClose(event) };
  855. }
  856. }
  857. ]
  858. },
  859. {
  860. 'redundantAttribute': 'expr25',
  861. 'selector': '[expr25]',
  862. 'expressions': [
  863. {
  864. 'type': expressionTypes.VALUE,
  865. 'evaluate': function(
  866. _scope
  867. ) {
  868. return _scope.state.user.email;
  869. }
  870. }
  871. ]
  872. },
  873. {
  874. 'type': bindingTypes.TAG,
  875. 'getComponent': getComponent,
  876. 'evaluate': function(
  877. _scope
  878. ) {
  879. return 'field-error';
  880. },
  881. 'slots': [],
  882. 'attributes': [],
  883. 'redundantAttribute': 'expr26',
  884. 'selector': '[expr26]'
  885. },
  886. {
  887. 'redundantAttribute': 'expr27',
  888. 'selector': '[expr27]',
  889. 'expressions': [
  890. {
  891. 'type': expressionTypes.VALUE,
  892. 'evaluate': function(
  893. _scope
  894. ) {
  895. return _scope.state.user.display_name;
  896. }
  897. }
  898. ]
  899. },
  900. {
  901. 'type': bindingTypes.TAG,
  902. 'getComponent': getComponent,
  903. 'evaluate': function(
  904. _scope
  905. ) {
  906. return 'field-error';
  907. },
  908. 'slots': [],
  909. 'attributes': [],
  910. 'redundantAttribute': 'expr28',
  911. 'selector': '[expr28]'
  912. },
  913. {
  914. 'type': bindingTypes.TAG,
  915. 'getComponent': getComponent,
  916. 'evaluate': function(
  917. _scope
  918. ) {
  919. return 'field-error';
  920. },
  921. 'slots': [],
  922. 'attributes': [],
  923. 'redundantAttribute': 'expr29',
  924. 'selector': '[expr29]'
  925. },
  926. {
  927. 'type': bindingTypes.TAG,
  928. 'getComponent': getComponent,
  929. 'evaluate': function(
  930. _scope
  931. ) {
  932. return 'field-error';
  933. },
  934. 'slots': [],
  935. 'attributes': [],
  936. 'redundantAttribute': 'expr30',
  937. 'selector': '[expr30]'
  938. },
  939. {
  940. 'type': bindingTypes.TAG,
  941. 'getComponent': getComponent,
  942. 'evaluate': function(
  943. _scope
  944. ) {
  945. return 'app-loading';
  946. },
  947. 'slots': [],
  948. 'attributes': [
  949. {
  950. 'type': expressionTypes.ATTRIBUTE,
  951. 'name': 'loading',
  952. 'evaluate': function(
  953. _scope
  954. ) {
  955. return _scope.state.loading;
  956. }
  957. }
  958. ],
  959. 'redundantAttribute': 'expr31',
  960. 'selector': '[expr31]'
  961. }
  962. ]
  963. );
  964. },
  965. 'name': 'app-users-form'
  966. });
  967. /***/ }),
  968. /***/ "./node_modules/axios/index.js":
  969. /*!*************************************!*\
  970. !*** ./node_modules/axios/index.js ***!
  971. \*************************************/
  972. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  973. module.exports = __webpack_require__(/*! ./lib/axios */ "./node_modules/axios/lib/axios.js");
  974. /***/ }),
  975. /***/ "./node_modules/axios/lib/adapters/xhr.js":
  976. /*!************************************************!*\
  977. !*** ./node_modules/axios/lib/adapters/xhr.js ***!
  978. \************************************************/
  979. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  980. "use strict";
  981. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  982. var settle = __webpack_require__(/*! ./../core/settle */ "./node_modules/axios/lib/core/settle.js");
  983. var cookies = __webpack_require__(/*! ./../helpers/cookies */ "./node_modules/axios/lib/helpers/cookies.js");
  984. var buildURL = __webpack_require__(/*! ./../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  985. var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./node_modules/axios/lib/core/buildFullPath.js");
  986. var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./node_modules/axios/lib/helpers/parseHeaders.js");
  987. var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./node_modules/axios/lib/helpers/isURLSameOrigin.js");
  988. var createError = __webpack_require__(/*! ../core/createError */ "./node_modules/axios/lib/core/createError.js");
  989. module.exports = function xhrAdapter(config) {
  990. return new Promise(function dispatchXhrRequest(resolve, reject) {
  991. var requestData = config.data;
  992. var requestHeaders = config.headers;
  993. if (utils.isFormData(requestData)) {
  994. delete requestHeaders['Content-Type']; // Let the browser set it
  995. }
  996. var request = new XMLHttpRequest();
  997. // HTTP basic authentication
  998. if (config.auth) {
  999. var username = config.auth.username || '';
  1000. var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
  1001. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  1002. }
  1003. var fullPath = buildFullPath(config.baseURL, config.url);
  1004. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  1005. // Set the request timeout in MS
  1006. request.timeout = config.timeout;
  1007. // Listen for ready state
  1008. request.onreadystatechange = function handleLoad() {
  1009. if (!request || request.readyState !== 4) {
  1010. return;
  1011. }
  1012. // The request errored out and we didn't get a response, this will be
  1013. // handled by onerror instead
  1014. // With one exception: request that using file: protocol, most browsers
  1015. // will return status as 0 even though it's a successful request
  1016. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  1017. return;
  1018. }
  1019. // Prepare the response
  1020. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  1021. var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
  1022. var response = {
  1023. data: responseData,
  1024. status: request.status,
  1025. statusText: request.statusText,
  1026. headers: responseHeaders,
  1027. config: config,
  1028. request: request
  1029. };
  1030. settle(resolve, reject, response);
  1031. // Clean up request
  1032. request = null;
  1033. };
  1034. // Handle browser request cancellation (as opposed to a manual cancellation)
  1035. request.onabort = function handleAbort() {
  1036. if (!request) {
  1037. return;
  1038. }
  1039. reject(createError('Request aborted', config, 'ECONNABORTED', request));
  1040. // Clean up request
  1041. request = null;
  1042. };
  1043. // Handle low level network errors
  1044. request.onerror = function handleError() {
  1045. // Real errors are hidden from us by the browser
  1046. // onerror should only fire if it's a network error
  1047. reject(createError('Network Error', config, null, request));
  1048. // Clean up request
  1049. request = null;
  1050. };
  1051. // Handle timeout
  1052. request.ontimeout = function handleTimeout() {
  1053. var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
  1054. if (config.timeoutErrorMessage) {
  1055. timeoutErrorMessage = config.timeoutErrorMessage;
  1056. }
  1057. reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
  1058. request));
  1059. // Clean up request
  1060. request = null;
  1061. };
  1062. // Add xsrf header
  1063. // This is only done if running in a standard browser environment.
  1064. // Specifically not if we're in a web worker, or react-native.
  1065. if (utils.isStandardBrowserEnv()) {
  1066. // Add xsrf header
  1067. var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
  1068. cookies.read(config.xsrfCookieName) :
  1069. undefined;
  1070. if (xsrfValue) {
  1071. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  1072. }
  1073. }
  1074. // Add headers to the request
  1075. if ('setRequestHeader' in request) {
  1076. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  1077. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  1078. // Remove Content-Type if data is undefined
  1079. delete requestHeaders[key];
  1080. } else {
  1081. // Otherwise add header to the request
  1082. request.setRequestHeader(key, val);
  1083. }
  1084. });
  1085. }
  1086. // Add withCredentials to request if needed
  1087. if (!utils.isUndefined(config.withCredentials)) {
  1088. request.withCredentials = !!config.withCredentials;
  1089. }
  1090. // Add responseType to request if needed
  1091. if (config.responseType) {
  1092. try {
  1093. request.responseType = config.responseType;
  1094. } catch (e) {
  1095. // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
  1096. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
  1097. if (config.responseType !== 'json') {
  1098. throw e;
  1099. }
  1100. }
  1101. }
  1102. // Handle progress if needed
  1103. if (typeof config.onDownloadProgress === 'function') {
  1104. request.addEventListener('progress', config.onDownloadProgress);
  1105. }
  1106. // Not all browsers support upload events
  1107. if (typeof config.onUploadProgress === 'function' && request.upload) {
  1108. request.upload.addEventListener('progress', config.onUploadProgress);
  1109. }
  1110. if (config.cancelToken) {
  1111. // Handle cancellation
  1112. config.cancelToken.promise.then(function onCanceled(cancel) {
  1113. if (!request) {
  1114. return;
  1115. }
  1116. request.abort();
  1117. reject(cancel);
  1118. // Clean up request
  1119. request = null;
  1120. });
  1121. }
  1122. if (!requestData) {
  1123. requestData = null;
  1124. }
  1125. // Send the request
  1126. request.send(requestData);
  1127. });
  1128. };
  1129. /***/ }),
  1130. /***/ "./node_modules/axios/lib/axios.js":
  1131. /*!*****************************************!*\
  1132. !*** ./node_modules/axios/lib/axios.js ***!
  1133. \*****************************************/
  1134. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1135. "use strict";
  1136. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  1137. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  1138. var Axios = __webpack_require__(/*! ./core/Axios */ "./node_modules/axios/lib/core/Axios.js");
  1139. var mergeConfig = __webpack_require__(/*! ./core/mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  1140. var defaults = __webpack_require__(/*! ./defaults */ "./node_modules/axios/lib/defaults.js");
  1141. /**
  1142. * Create an instance of Axios
  1143. *
  1144. * @param {Object} defaultConfig The default config for the instance
  1145. * @return {Axios} A new instance of Axios
  1146. */
  1147. function createInstance(defaultConfig) {
  1148. var context = new Axios(defaultConfig);
  1149. var instance = bind(Axios.prototype.request, context);
  1150. // Copy axios.prototype to instance
  1151. utils.extend(instance, Axios.prototype, context);
  1152. // Copy context to instance
  1153. utils.extend(instance, context);
  1154. return instance;
  1155. }
  1156. // Create the default instance to be exported
  1157. var axios = createInstance(defaults);
  1158. // Expose Axios class to allow class inheritance
  1159. axios.Axios = Axios;
  1160. // Factory for creating new instances
  1161. axios.create = function create(instanceConfig) {
  1162. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  1163. };
  1164. // Expose Cancel & CancelToken
  1165. axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  1166. axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./node_modules/axios/lib/cancel/CancelToken.js");
  1167. axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  1168. // Expose all/spread
  1169. axios.all = function all(promises) {
  1170. return Promise.all(promises);
  1171. };
  1172. axios.spread = __webpack_require__(/*! ./helpers/spread */ "./node_modules/axios/lib/helpers/spread.js");
  1173. // Expose isAxiosError
  1174. axios.isAxiosError = __webpack_require__(/*! ./helpers/isAxiosError */ "./node_modules/axios/lib/helpers/isAxiosError.js");
  1175. module.exports = axios;
  1176. // Allow use of default import syntax in TypeScript
  1177. module.exports.default = axios;
  1178. /***/ }),
  1179. /***/ "./node_modules/axios/lib/cancel/Cancel.js":
  1180. /*!*************************************************!*\
  1181. !*** ./node_modules/axios/lib/cancel/Cancel.js ***!
  1182. \*************************************************/
  1183. /***/ ((module) => {
  1184. "use strict";
  1185. /**
  1186. * A `Cancel` is an object that is thrown when an operation is canceled.
  1187. *
  1188. * @class
  1189. * @param {string=} message The message.
  1190. */
  1191. function Cancel(message) {
  1192. this.message = message;
  1193. }
  1194. Cancel.prototype.toString = function toString() {
  1195. return 'Cancel' + (this.message ? ': ' + this.message : '');
  1196. };
  1197. Cancel.prototype.__CANCEL__ = true;
  1198. module.exports = Cancel;
  1199. /***/ }),
  1200. /***/ "./node_modules/axios/lib/cancel/CancelToken.js":
  1201. /*!******************************************************!*\
  1202. !*** ./node_modules/axios/lib/cancel/CancelToken.js ***!
  1203. \******************************************************/
  1204. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1205. "use strict";
  1206. var Cancel = __webpack_require__(/*! ./Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  1207. /**
  1208. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  1209. *
  1210. * @class
  1211. * @param {Function} executor The executor function.
  1212. */
  1213. function CancelToken(executor) {
  1214. if (typeof executor !== 'function') {
  1215. throw new TypeError('executor must be a function.');
  1216. }
  1217. var resolvePromise;
  1218. this.promise = new Promise(function promiseExecutor(resolve) {
  1219. resolvePromise = resolve;
  1220. });
  1221. var token = this;
  1222. executor(function cancel(message) {
  1223. if (token.reason) {
  1224. // Cancellation has already been requested
  1225. return;
  1226. }
  1227. token.reason = new Cancel(message);
  1228. resolvePromise(token.reason);
  1229. });
  1230. }
  1231. /**
  1232. * Throws a `Cancel` if cancellation has been requested.
  1233. */
  1234. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  1235. if (this.reason) {
  1236. throw this.reason;
  1237. }
  1238. };
  1239. /**
  1240. * Returns an object that contains a new `CancelToken` and a function that, when called,
  1241. * cancels the `CancelToken`.
  1242. */
  1243. CancelToken.source = function source() {
  1244. var cancel;
  1245. var token = new CancelToken(function executor(c) {
  1246. cancel = c;
  1247. });
  1248. return {
  1249. token: token,
  1250. cancel: cancel
  1251. };
  1252. };
  1253. module.exports = CancelToken;
  1254. /***/ }),
  1255. /***/ "./node_modules/axios/lib/cancel/isCancel.js":
  1256. /*!***************************************************!*\
  1257. !*** ./node_modules/axios/lib/cancel/isCancel.js ***!
  1258. \***************************************************/
  1259. /***/ ((module) => {
  1260. "use strict";
  1261. module.exports = function isCancel(value) {
  1262. return !!(value && value.__CANCEL__);
  1263. };
  1264. /***/ }),
  1265. /***/ "./node_modules/axios/lib/core/Axios.js":
  1266. /*!**********************************************!*\
  1267. !*** ./node_modules/axios/lib/core/Axios.js ***!
  1268. \**********************************************/
  1269. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1270. "use strict";
  1271. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1272. var buildURL = __webpack_require__(/*! ../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  1273. var InterceptorManager = __webpack_require__(/*! ./InterceptorManager */ "./node_modules/axios/lib/core/InterceptorManager.js");
  1274. var dispatchRequest = __webpack_require__(/*! ./dispatchRequest */ "./node_modules/axios/lib/core/dispatchRequest.js");
  1275. var mergeConfig = __webpack_require__(/*! ./mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  1276. /**
  1277. * Create a new instance of Axios
  1278. *
  1279. * @param {Object} instanceConfig The default config for the instance
  1280. */
  1281. function Axios(instanceConfig) {
  1282. this.defaults = instanceConfig;
  1283. this.interceptors = {
  1284. request: new InterceptorManager(),
  1285. response: new InterceptorManager()
  1286. };
  1287. }
  1288. /**
  1289. * Dispatch a request
  1290. *
  1291. * @param {Object} config The config specific for this request (merged with this.defaults)
  1292. */
  1293. Axios.prototype.request = function request(config) {
  1294. /*eslint no-param-reassign:0*/
  1295. // Allow for axios('example/url'[, config]) a la fetch API
  1296. if (typeof config === 'string') {
  1297. config = arguments[1] || {};
  1298. config.url = arguments[0];
  1299. } else {
  1300. config = config || {};
  1301. }
  1302. config = mergeConfig(this.defaults, config);
  1303. // Set config.method
  1304. if (config.method) {
  1305. config.method = config.method.toLowerCase();
  1306. } else if (this.defaults.method) {
  1307. config.method = this.defaults.method.toLowerCase();
  1308. } else {
  1309. config.method = 'get';
  1310. }
  1311. // Hook up interceptors middleware
  1312. var chain = [dispatchRequest, undefined];
  1313. var promise = Promise.resolve(config);
  1314. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  1315. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  1316. });
  1317. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  1318. chain.push(interceptor.fulfilled, interceptor.rejected);
  1319. });
  1320. while (chain.length) {
  1321. promise = promise.then(chain.shift(), chain.shift());
  1322. }
  1323. return promise;
  1324. };
  1325. Axios.prototype.getUri = function getUri(config) {
  1326. config = mergeConfig(this.defaults, config);
  1327. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  1328. };
  1329. // Provide aliases for supported request methods
  1330. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  1331. /*eslint func-names:0*/
  1332. Axios.prototype[method] = function(url, config) {
  1333. return this.request(mergeConfig(config || {}, {
  1334. method: method,
  1335. url: url,
  1336. data: (config || {}).data
  1337. }));
  1338. };
  1339. });
  1340. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  1341. /*eslint func-names:0*/
  1342. Axios.prototype[method] = function(url, data, config) {
  1343. return this.request(mergeConfig(config || {}, {
  1344. method: method,
  1345. url: url,
  1346. data: data
  1347. }));
  1348. };
  1349. });
  1350. module.exports = Axios;
  1351. /***/ }),
  1352. /***/ "./node_modules/axios/lib/core/InterceptorManager.js":
  1353. /*!***********************************************************!*\
  1354. !*** ./node_modules/axios/lib/core/InterceptorManager.js ***!
  1355. \***********************************************************/
  1356. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1357. "use strict";
  1358. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1359. function InterceptorManager() {
  1360. this.handlers = [];
  1361. }
  1362. /**
  1363. * Add a new interceptor to the stack
  1364. *
  1365. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  1366. * @param {Function} rejected The function to handle `reject` for a `Promise`
  1367. *
  1368. * @return {Number} An ID used to remove interceptor later
  1369. */
  1370. InterceptorManager.prototype.use = function use(fulfilled, rejected) {
  1371. this.handlers.push({
  1372. fulfilled: fulfilled,
  1373. rejected: rejected
  1374. });
  1375. return this.handlers.length - 1;
  1376. };
  1377. /**
  1378. * Remove an interceptor from the stack
  1379. *
  1380. * @param {Number} id The ID that was returned by `use`
  1381. */
  1382. InterceptorManager.prototype.eject = function eject(id) {
  1383. if (this.handlers[id]) {
  1384. this.handlers[id] = null;
  1385. }
  1386. };
  1387. /**
  1388. * Iterate over all the registered interceptors
  1389. *
  1390. * This method is particularly useful for skipping over any
  1391. * interceptors that may have become `null` calling `eject`.
  1392. *
  1393. * @param {Function} fn The function to call for each interceptor
  1394. */
  1395. InterceptorManager.prototype.forEach = function forEach(fn) {
  1396. utils.forEach(this.handlers, function forEachHandler(h) {
  1397. if (h !== null) {
  1398. fn(h);
  1399. }
  1400. });
  1401. };
  1402. module.exports = InterceptorManager;
  1403. /***/ }),
  1404. /***/ "./node_modules/axios/lib/core/buildFullPath.js":
  1405. /*!******************************************************!*\
  1406. !*** ./node_modules/axios/lib/core/buildFullPath.js ***!
  1407. \******************************************************/
  1408. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1409. "use strict";
  1410. var isAbsoluteURL = __webpack_require__(/*! ../helpers/isAbsoluteURL */ "./node_modules/axios/lib/helpers/isAbsoluteURL.js");
  1411. var combineURLs = __webpack_require__(/*! ../helpers/combineURLs */ "./node_modules/axios/lib/helpers/combineURLs.js");
  1412. /**
  1413. * Creates a new URL by combining the baseURL with the requestedURL,
  1414. * only when the requestedURL is not already an absolute URL.
  1415. * If the requestURL is absolute, this function returns the requestedURL untouched.
  1416. *
  1417. * @param {string} baseURL The base URL
  1418. * @param {string} requestedURL Absolute or relative URL to combine
  1419. * @returns {string} The combined full path
  1420. */
  1421. module.exports = function buildFullPath(baseURL, requestedURL) {
  1422. if (baseURL && !isAbsoluteURL(requestedURL)) {
  1423. return combineURLs(baseURL, requestedURL);
  1424. }
  1425. return requestedURL;
  1426. };
  1427. /***/ }),
  1428. /***/ "./node_modules/axios/lib/core/createError.js":
  1429. /*!****************************************************!*\
  1430. !*** ./node_modules/axios/lib/core/createError.js ***!
  1431. \****************************************************/
  1432. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1433. "use strict";
  1434. var enhanceError = __webpack_require__(/*! ./enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  1435. /**
  1436. * Create an Error with the specified message, config, error code, request and response.
  1437. *
  1438. * @param {string} message The error message.
  1439. * @param {Object} config The config.
  1440. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  1441. * @param {Object} [request] The request.
  1442. * @param {Object} [response] The response.
  1443. * @returns {Error} The created error.
  1444. */
  1445. module.exports = function createError(message, config, code, request, response) {
  1446. var error = new Error(message);
  1447. return enhanceError(error, config, code, request, response);
  1448. };
  1449. /***/ }),
  1450. /***/ "./node_modules/axios/lib/core/dispatchRequest.js":
  1451. /*!********************************************************!*\
  1452. !*** ./node_modules/axios/lib/core/dispatchRequest.js ***!
  1453. \********************************************************/
  1454. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1455. "use strict";
  1456. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1457. var transformData = __webpack_require__(/*! ./transformData */ "./node_modules/axios/lib/core/transformData.js");
  1458. var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  1459. var defaults = __webpack_require__(/*! ../defaults */ "./node_modules/axios/lib/defaults.js");
  1460. /**
  1461. * Throws a `Cancel` if cancellation has been requested.
  1462. */
  1463. function throwIfCancellationRequested(config) {
  1464. if (config.cancelToken) {
  1465. config.cancelToken.throwIfRequested();
  1466. }
  1467. }
  1468. /**
  1469. * Dispatch a request to the server using the configured adapter.
  1470. *
  1471. * @param {object} config The config that is to be used for the request
  1472. * @returns {Promise} The Promise to be fulfilled
  1473. */
  1474. module.exports = function dispatchRequest(config) {
  1475. throwIfCancellationRequested(config);
  1476. // Ensure headers exist
  1477. config.headers = config.headers || {};
  1478. // Transform request data
  1479. config.data = transformData(
  1480. config.data,
  1481. config.headers,
  1482. config.transformRequest
  1483. );
  1484. // Flatten headers
  1485. config.headers = utils.merge(
  1486. config.headers.common || {},
  1487. config.headers[config.method] || {},
  1488. config.headers
  1489. );
  1490. utils.forEach(
  1491. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  1492. function cleanHeaderConfig(method) {
  1493. delete config.headers[method];
  1494. }
  1495. );
  1496. var adapter = config.adapter || defaults.adapter;
  1497. return adapter(config).then(function onAdapterResolution(response) {
  1498. throwIfCancellationRequested(config);
  1499. // Transform response data
  1500. response.data = transformData(
  1501. response.data,
  1502. response.headers,
  1503. config.transformResponse
  1504. );
  1505. return response;
  1506. }, function onAdapterRejection(reason) {
  1507. if (!isCancel(reason)) {
  1508. throwIfCancellationRequested(config);
  1509. // Transform response data
  1510. if (reason && reason.response) {
  1511. reason.response.data = transformData(
  1512. reason.response.data,
  1513. reason.response.headers,
  1514. config.transformResponse
  1515. );
  1516. }
  1517. }
  1518. return Promise.reject(reason);
  1519. });
  1520. };
  1521. /***/ }),
  1522. /***/ "./node_modules/axios/lib/core/enhanceError.js":
  1523. /*!*****************************************************!*\
  1524. !*** ./node_modules/axios/lib/core/enhanceError.js ***!
  1525. \*****************************************************/
  1526. /***/ ((module) => {
  1527. "use strict";
  1528. /**
  1529. * Update an Error with the specified config, error code, and response.
  1530. *
  1531. * @param {Error} error The error to update.
  1532. * @param {Object} config The config.
  1533. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  1534. * @param {Object} [request] The request.
  1535. * @param {Object} [response] The response.
  1536. * @returns {Error} The error.
  1537. */
  1538. module.exports = function enhanceError(error, config, code, request, response) {
  1539. error.config = config;
  1540. if (code) {
  1541. error.code = code;
  1542. }
  1543. error.request = request;
  1544. error.response = response;
  1545. error.isAxiosError = true;
  1546. error.toJSON = function toJSON() {
  1547. return {
  1548. // Standard
  1549. message: this.message,
  1550. name: this.name,
  1551. // Microsoft
  1552. description: this.description,
  1553. number: this.number,
  1554. // Mozilla
  1555. fileName: this.fileName,
  1556. lineNumber: this.lineNumber,
  1557. columnNumber: this.columnNumber,
  1558. stack: this.stack,
  1559. // Axios
  1560. config: this.config,
  1561. code: this.code
  1562. };
  1563. };
  1564. return error;
  1565. };
  1566. /***/ }),
  1567. /***/ "./node_modules/axios/lib/core/mergeConfig.js":
  1568. /*!****************************************************!*\
  1569. !*** ./node_modules/axios/lib/core/mergeConfig.js ***!
  1570. \****************************************************/
  1571. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1572. "use strict";
  1573. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  1574. /**
  1575. * Config-specific merge-function which creates a new config-object
  1576. * by merging two configuration objects together.
  1577. *
  1578. * @param {Object} config1
  1579. * @param {Object} config2
  1580. * @returns {Object} New object resulting from merging config2 to config1
  1581. */
  1582. module.exports = function mergeConfig(config1, config2) {
  1583. // eslint-disable-next-line no-param-reassign
  1584. config2 = config2 || {};
  1585. var config = {};
  1586. var valueFromConfig2Keys = ['url', 'method', 'data'];
  1587. var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
  1588. var defaultToConfig2Keys = [
  1589. 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
  1590. 'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
  1591. 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
  1592. 'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
  1593. 'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
  1594. ];
  1595. var directMergeKeys = ['validateStatus'];
  1596. function getMergedValue(target, source) {
  1597. if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
  1598. return utils.merge(target, source);
  1599. } else if (utils.isPlainObject(source)) {
  1600. return utils.merge({}, source);
  1601. } else if (utils.isArray(source)) {
  1602. return source.slice();
  1603. }
  1604. return source;
  1605. }
  1606. function mergeDeepProperties(prop) {
  1607. if (!utils.isUndefined(config2[prop])) {
  1608. config[prop] = getMergedValue(config1[prop], config2[prop]);
  1609. } else if (!utils.isUndefined(config1[prop])) {
  1610. config[prop] = getMergedValue(undefined, config1[prop]);
  1611. }
  1612. }
  1613. utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
  1614. if (!utils.isUndefined(config2[prop])) {
  1615. config[prop] = getMergedValue(undefined, config2[prop]);
  1616. }
  1617. });
  1618. utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
  1619. utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
  1620. if (!utils.isUndefined(config2[prop])) {
  1621. config[prop] = getMergedValue(undefined, config2[prop]);
  1622. } else if (!utils.isUndefined(config1[prop])) {
  1623. config[prop] = getMergedValue(undefined, config1[prop]);
  1624. }
  1625. });
  1626. utils.forEach(directMergeKeys, function merge(prop) {
  1627. if (prop in config2) {
  1628. config[prop] = getMergedValue(config1[prop], config2[prop]);
  1629. } else if (prop in config1) {
  1630. config[prop] = getMergedValue(undefined, config1[prop]);
  1631. }
  1632. });
  1633. var axiosKeys = valueFromConfig2Keys
  1634. .concat(mergeDeepPropertiesKeys)
  1635. .concat(defaultToConfig2Keys)
  1636. .concat(directMergeKeys);
  1637. var otherKeys = Object
  1638. .keys(config1)
  1639. .concat(Object.keys(config2))
  1640. .filter(function filterAxiosKeys(key) {
  1641. return axiosKeys.indexOf(key) === -1;
  1642. });
  1643. utils.forEach(otherKeys, mergeDeepProperties);
  1644. return config;
  1645. };
  1646. /***/ }),
  1647. /***/ "./node_modules/axios/lib/core/settle.js":
  1648. /*!***********************************************!*\
  1649. !*** ./node_modules/axios/lib/core/settle.js ***!
  1650. \***********************************************/
  1651. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1652. "use strict";
  1653. var createError = __webpack_require__(/*! ./createError */ "./node_modules/axios/lib/core/createError.js");
  1654. /**
  1655. * Resolve or reject a Promise based on response status.
  1656. *
  1657. * @param {Function} resolve A function that resolves the promise.
  1658. * @param {Function} reject A function that rejects the promise.
  1659. * @param {object} response The response.
  1660. */
  1661. module.exports = function settle(resolve, reject, response) {
  1662. var validateStatus = response.config.validateStatus;
  1663. if (!response.status || !validateStatus || validateStatus(response.status)) {
  1664. resolve(response);
  1665. } else {
  1666. reject(createError(
  1667. 'Request failed with status code ' + response.status,
  1668. response.config,
  1669. null,
  1670. response.request,
  1671. response
  1672. ));
  1673. }
  1674. };
  1675. /***/ }),
  1676. /***/ "./node_modules/axios/lib/core/transformData.js":
  1677. /*!******************************************************!*\
  1678. !*** ./node_modules/axios/lib/core/transformData.js ***!
  1679. \******************************************************/
  1680. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1681. "use strict";
  1682. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1683. /**
  1684. * Transform the data for a request or a response
  1685. *
  1686. * @param {Object|String} data The data to be transformed
  1687. * @param {Array} headers The headers for the request or response
  1688. * @param {Array|Function} fns A single function or Array of functions
  1689. * @returns {*} The resulting transformed data
  1690. */
  1691. module.exports = function transformData(data, headers, fns) {
  1692. /*eslint no-param-reassign:0*/
  1693. utils.forEach(fns, function transform(fn) {
  1694. data = fn(data, headers);
  1695. });
  1696. return data;
  1697. };
  1698. /***/ }),
  1699. /***/ "./node_modules/axios/lib/defaults.js":
  1700. /*!********************************************!*\
  1701. !*** ./node_modules/axios/lib/defaults.js ***!
  1702. \********************************************/
  1703. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1704. "use strict";
  1705. /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
  1706. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  1707. var normalizeHeaderName = __webpack_require__(/*! ./helpers/normalizeHeaderName */ "./node_modules/axios/lib/helpers/normalizeHeaderName.js");
  1708. var DEFAULT_CONTENT_TYPE = {
  1709. 'Content-Type': 'application/x-www-form-urlencoded'
  1710. };
  1711. function setContentTypeIfUnset(headers, value) {
  1712. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  1713. headers['Content-Type'] = value;
  1714. }
  1715. }
  1716. function getDefaultAdapter() {
  1717. var adapter;
  1718. if (typeof XMLHttpRequest !== 'undefined') {
  1719. // For browsers use XHR adapter
  1720. adapter = __webpack_require__(/*! ./adapters/xhr */ "./node_modules/axios/lib/adapters/xhr.js");
  1721. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  1722. // For node use HTTP adapter
  1723. adapter = __webpack_require__(/*! ./adapters/http */ "./node_modules/axios/lib/adapters/xhr.js");
  1724. }
  1725. return adapter;
  1726. }
  1727. var defaults = {
  1728. adapter: getDefaultAdapter(),
  1729. transformRequest: [function transformRequest(data, headers) {
  1730. normalizeHeaderName(headers, 'Accept');
  1731. normalizeHeaderName(headers, 'Content-Type');
  1732. if (utils.isFormData(data) ||
  1733. utils.isArrayBuffer(data) ||
  1734. utils.isBuffer(data) ||
  1735. utils.isStream(data) ||
  1736. utils.isFile(data) ||
  1737. utils.isBlob(data)
  1738. ) {
  1739. return data;
  1740. }
  1741. if (utils.isArrayBufferView(data)) {
  1742. return data.buffer;
  1743. }
  1744. if (utils.isURLSearchParams(data)) {
  1745. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  1746. return data.toString();
  1747. }
  1748. if (utils.isObject(data)) {
  1749. setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
  1750. return JSON.stringify(data);
  1751. }
  1752. return data;
  1753. }],
  1754. transformResponse: [function transformResponse(data) {
  1755. /*eslint no-param-reassign:0*/
  1756. if (typeof data === 'string') {
  1757. try {
  1758. data = JSON.parse(data);
  1759. } catch (e) { /* Ignore */ }
  1760. }
  1761. return data;
  1762. }],
  1763. /**
  1764. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  1765. * timeout is not created.
  1766. */
  1767. timeout: 0,
  1768. xsrfCookieName: 'XSRF-TOKEN',
  1769. xsrfHeaderName: 'X-XSRF-TOKEN',
  1770. maxContentLength: -1,
  1771. maxBodyLength: -1,
  1772. validateStatus: function validateStatus(status) {
  1773. return status >= 200 && status < 300;
  1774. }
  1775. };
  1776. defaults.headers = {
  1777. common: {
  1778. 'Accept': 'application/json, text/plain, */*'
  1779. }
  1780. };
  1781. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  1782. defaults.headers[method] = {};
  1783. });
  1784. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  1785. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  1786. });
  1787. module.exports = defaults;
  1788. /***/ }),
  1789. /***/ "./node_modules/axios/lib/helpers/bind.js":
  1790. /*!************************************************!*\
  1791. !*** ./node_modules/axios/lib/helpers/bind.js ***!
  1792. \************************************************/
  1793. /***/ ((module) => {
  1794. "use strict";
  1795. module.exports = function bind(fn, thisArg) {
  1796. return function wrap() {
  1797. var args = new Array(arguments.length);
  1798. for (var i = 0; i < args.length; i++) {
  1799. args[i] = arguments[i];
  1800. }
  1801. return fn.apply(thisArg, args);
  1802. };
  1803. };
  1804. /***/ }),
  1805. /***/ "./node_modules/axios/lib/helpers/buildURL.js":
  1806. /*!****************************************************!*\
  1807. !*** ./node_modules/axios/lib/helpers/buildURL.js ***!
  1808. \****************************************************/
  1809. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1810. "use strict";
  1811. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1812. function encode(val) {
  1813. return encodeURIComponent(val).
  1814. replace(/%3A/gi, ':').
  1815. replace(/%24/g, '$').
  1816. replace(/%2C/gi, ',').
  1817. replace(/%20/g, '+').
  1818. replace(/%5B/gi, '[').
  1819. replace(/%5D/gi, ']');
  1820. }
  1821. /**
  1822. * Build a URL by appending params to the end
  1823. *
  1824. * @param {string} url The base of the url (e.g., http://www.google.com)
  1825. * @param {object} [params] The params to be appended
  1826. * @returns {string} The formatted url
  1827. */
  1828. module.exports = function buildURL(url, params, paramsSerializer) {
  1829. /*eslint no-param-reassign:0*/
  1830. if (!params) {
  1831. return url;
  1832. }
  1833. var serializedParams;
  1834. if (paramsSerializer) {
  1835. serializedParams = paramsSerializer(params);
  1836. } else if (utils.isURLSearchParams(params)) {
  1837. serializedParams = params.toString();
  1838. } else {
  1839. var parts = [];
  1840. utils.forEach(params, function serialize(val, key) {
  1841. if (val === null || typeof val === 'undefined') {
  1842. return;
  1843. }
  1844. if (utils.isArray(val)) {
  1845. key = key + '[]';
  1846. } else {
  1847. val = [val];
  1848. }
  1849. utils.forEach(val, function parseValue(v) {
  1850. if (utils.isDate(v)) {
  1851. v = v.toISOString();
  1852. } else if (utils.isObject(v)) {
  1853. v = JSON.stringify(v);
  1854. }
  1855. parts.push(encode(key) + '=' + encode(v));
  1856. });
  1857. });
  1858. serializedParams = parts.join('&');
  1859. }
  1860. if (serializedParams) {
  1861. var hashmarkIndex = url.indexOf('#');
  1862. if (hashmarkIndex !== -1) {
  1863. url = url.slice(0, hashmarkIndex);
  1864. }
  1865. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  1866. }
  1867. return url;
  1868. };
  1869. /***/ }),
  1870. /***/ "./node_modules/axios/lib/helpers/combineURLs.js":
  1871. /*!*******************************************************!*\
  1872. !*** ./node_modules/axios/lib/helpers/combineURLs.js ***!
  1873. \*******************************************************/
  1874. /***/ ((module) => {
  1875. "use strict";
  1876. /**
  1877. * Creates a new URL by combining the specified URLs
  1878. *
  1879. * @param {string} baseURL The base URL
  1880. * @param {string} relativeURL The relative URL
  1881. * @returns {string} The combined URL
  1882. */
  1883. module.exports = function combineURLs(baseURL, relativeURL) {
  1884. return relativeURL
  1885. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  1886. : baseURL;
  1887. };
  1888. /***/ }),
  1889. /***/ "./node_modules/axios/lib/helpers/cookies.js":
  1890. /*!***************************************************!*\
  1891. !*** ./node_modules/axios/lib/helpers/cookies.js ***!
  1892. \***************************************************/
  1893. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1894. "use strict";
  1895. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1896. module.exports = (
  1897. utils.isStandardBrowserEnv() ?
  1898. // Standard browser envs support document.cookie
  1899. (function standardBrowserEnv() {
  1900. return {
  1901. write: function write(name, value, expires, path, domain, secure) {
  1902. var cookie = [];
  1903. cookie.push(name + '=' + encodeURIComponent(value));
  1904. if (utils.isNumber(expires)) {
  1905. cookie.push('expires=' + new Date(expires).toGMTString());
  1906. }
  1907. if (utils.isString(path)) {
  1908. cookie.push('path=' + path);
  1909. }
  1910. if (utils.isString(domain)) {
  1911. cookie.push('domain=' + domain);
  1912. }
  1913. if (secure === true) {
  1914. cookie.push('secure');
  1915. }
  1916. document.cookie = cookie.join('; ');
  1917. },
  1918. read: function read(name) {
  1919. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  1920. return (match ? decodeURIComponent(match[3]) : null);
  1921. },
  1922. remove: function remove(name) {
  1923. this.write(name, '', Date.now() - 86400000);
  1924. }
  1925. };
  1926. })() :
  1927. // Non standard browser env (web workers, react-native) lack needed support.
  1928. (function nonStandardBrowserEnv() {
  1929. return {
  1930. write: function write() {},
  1931. read: function read() { return null; },
  1932. remove: function remove() {}
  1933. };
  1934. })()
  1935. );
  1936. /***/ }),
  1937. /***/ "./node_modules/axios/lib/helpers/isAbsoluteURL.js":
  1938. /*!*********************************************************!*\
  1939. !*** ./node_modules/axios/lib/helpers/isAbsoluteURL.js ***!
  1940. \*********************************************************/
  1941. /***/ ((module) => {
  1942. "use strict";
  1943. /**
  1944. * Determines whether the specified URL is absolute
  1945. *
  1946. * @param {string} url The URL to test
  1947. * @returns {boolean} True if the specified URL is absolute, otherwise false
  1948. */
  1949. module.exports = function isAbsoluteURL(url) {
  1950. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  1951. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  1952. // by any combination of letters, digits, plus, period, or hyphen.
  1953. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  1954. };
  1955. /***/ }),
  1956. /***/ "./node_modules/axios/lib/helpers/isAxiosError.js":
  1957. /*!********************************************************!*\
  1958. !*** ./node_modules/axios/lib/helpers/isAxiosError.js ***!
  1959. \********************************************************/
  1960. /***/ ((module) => {
  1961. "use strict";
  1962. /**
  1963. * Determines whether the payload is an error thrown by Axios
  1964. *
  1965. * @param {*} payload The value to test
  1966. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  1967. */
  1968. module.exports = function isAxiosError(payload) {
  1969. return (typeof payload === 'object') && (payload.isAxiosError === true);
  1970. };
  1971. /***/ }),
  1972. /***/ "./node_modules/axios/lib/helpers/isURLSameOrigin.js":
  1973. /*!***********************************************************!*\
  1974. !*** ./node_modules/axios/lib/helpers/isURLSameOrigin.js ***!
  1975. \***********************************************************/
  1976. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1977. "use strict";
  1978. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1979. module.exports = (
  1980. utils.isStandardBrowserEnv() ?
  1981. // Standard browser envs have full support of the APIs needed to test
  1982. // whether the request URL is of the same origin as current location.
  1983. (function standardBrowserEnv() {
  1984. var msie = /(msie|trident)/i.test(navigator.userAgent);
  1985. var urlParsingNode = document.createElement('a');
  1986. var originURL;
  1987. /**
  1988. * Parse a URL to discover it's components
  1989. *
  1990. * @param {String} url The URL to be parsed
  1991. * @returns {Object}
  1992. */
  1993. function resolveURL(url) {
  1994. var href = url;
  1995. if (msie) {
  1996. // IE needs attribute set twice to normalize properties
  1997. urlParsingNode.setAttribute('href', href);
  1998. href = urlParsingNode.href;
  1999. }
  2000. urlParsingNode.setAttribute('href', href);
  2001. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  2002. return {
  2003. href: urlParsingNode.href,
  2004. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  2005. host: urlParsingNode.host,
  2006. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  2007. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  2008. hostname: urlParsingNode.hostname,
  2009. port: urlParsingNode.port,
  2010. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  2011. urlParsingNode.pathname :
  2012. '/' + urlParsingNode.pathname
  2013. };
  2014. }
  2015. originURL = resolveURL(window.location.href);
  2016. /**
  2017. * Determine if a URL shares the same origin as the current location
  2018. *
  2019. * @param {String} requestURL The URL to test
  2020. * @returns {boolean} True if URL shares the same origin, otherwise false
  2021. */
  2022. return function isURLSameOrigin(requestURL) {
  2023. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  2024. return (parsed.protocol === originURL.protocol &&
  2025. parsed.host === originURL.host);
  2026. };
  2027. })() :
  2028. // Non standard browser envs (web workers, react-native) lack needed support.
  2029. (function nonStandardBrowserEnv() {
  2030. return function isURLSameOrigin() {
  2031. return true;
  2032. };
  2033. })()
  2034. );
  2035. /***/ }),
  2036. /***/ "./node_modules/axios/lib/helpers/normalizeHeaderName.js":
  2037. /*!***************************************************************!*\
  2038. !*** ./node_modules/axios/lib/helpers/normalizeHeaderName.js ***!
  2039. \***************************************************************/
  2040. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2041. "use strict";
  2042. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  2043. module.exports = function normalizeHeaderName(headers, normalizedName) {
  2044. utils.forEach(headers, function processHeader(value, name) {
  2045. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  2046. headers[normalizedName] = value;
  2047. delete headers[name];
  2048. }
  2049. });
  2050. };
  2051. /***/ }),
  2052. /***/ "./node_modules/axios/lib/helpers/parseHeaders.js":
  2053. /*!********************************************************!*\
  2054. !*** ./node_modules/axios/lib/helpers/parseHeaders.js ***!
  2055. \********************************************************/
  2056. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2057. "use strict";
  2058. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2059. // Headers whose duplicates are ignored by node
  2060. // c.f. https://nodejs.org/api/http.html#http_message_headers
  2061. var ignoreDuplicateOf = [
  2062. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  2063. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  2064. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  2065. 'referer', 'retry-after', 'user-agent'
  2066. ];
  2067. /**
  2068. * Parse headers into an object
  2069. *
  2070. * ```
  2071. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  2072. * Content-Type: application/json
  2073. * Connection: keep-alive
  2074. * Transfer-Encoding: chunked
  2075. * ```
  2076. *
  2077. * @param {String} headers Headers needing to be parsed
  2078. * @returns {Object} Headers parsed into an object
  2079. */
  2080. module.exports = function parseHeaders(headers) {
  2081. var parsed = {};
  2082. var key;
  2083. var val;
  2084. var i;
  2085. if (!headers) { return parsed; }
  2086. utils.forEach(headers.split('\n'), function parser(line) {
  2087. i = line.indexOf(':');
  2088. key = utils.trim(line.substr(0, i)).toLowerCase();
  2089. val = utils.trim(line.substr(i + 1));
  2090. if (key) {
  2091. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  2092. return;
  2093. }
  2094. if (key === 'set-cookie') {
  2095. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  2096. } else {
  2097. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  2098. }
  2099. }
  2100. });
  2101. return parsed;
  2102. };
  2103. /***/ }),
  2104. /***/ "./node_modules/axios/lib/helpers/spread.js":
  2105. /*!**************************************************!*\
  2106. !*** ./node_modules/axios/lib/helpers/spread.js ***!
  2107. \**************************************************/
  2108. /***/ ((module) => {
  2109. "use strict";
  2110. /**
  2111. * Syntactic sugar for invoking a function and expanding an array for arguments.
  2112. *
  2113. * Common use case would be to use `Function.prototype.apply`.
  2114. *
  2115. * ```js
  2116. * function f(x, y, z) {}
  2117. * var args = [1, 2, 3];
  2118. * f.apply(null, args);
  2119. * ```
  2120. *
  2121. * With `spread` this example can be re-written.
  2122. *
  2123. * ```js
  2124. * spread(function(x, y, z) {})([1, 2, 3]);
  2125. * ```
  2126. *
  2127. * @param {Function} callback
  2128. * @returns {Function}
  2129. */
  2130. module.exports = function spread(callback) {
  2131. return function wrap(arr) {
  2132. return callback.apply(null, arr);
  2133. };
  2134. };
  2135. /***/ }),
  2136. /***/ "./node_modules/axios/lib/utils.js":
  2137. /*!*****************************************!*\
  2138. !*** ./node_modules/axios/lib/utils.js ***!
  2139. \*****************************************/
  2140. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2141. "use strict";
  2142. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  2143. /*global toString:true*/
  2144. // utils is a library of generic helper functions non-specific to axios
  2145. var toString = Object.prototype.toString;
  2146. /**
  2147. * Determine if a value is an Array
  2148. *
  2149. * @param {Object} val The value to test
  2150. * @returns {boolean} True if value is an Array, otherwise false
  2151. */
  2152. function isArray(val) {
  2153. return toString.call(val) === '[object Array]';
  2154. }
  2155. /**
  2156. * Determine if a value is undefined
  2157. *
  2158. * @param {Object} val The value to test
  2159. * @returns {boolean} True if the value is undefined, otherwise false
  2160. */
  2161. function isUndefined(val) {
  2162. return typeof val === 'undefined';
  2163. }
  2164. /**
  2165. * Determine if a value is a Buffer
  2166. *
  2167. * @param {Object} val The value to test
  2168. * @returns {boolean} True if value is a Buffer, otherwise false
  2169. */
  2170. function isBuffer(val) {
  2171. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  2172. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  2173. }
  2174. /**
  2175. * Determine if a value is an ArrayBuffer
  2176. *
  2177. * @param {Object} val The value to test
  2178. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  2179. */
  2180. function isArrayBuffer(val) {
  2181. return toString.call(val) === '[object ArrayBuffer]';
  2182. }
  2183. /**
  2184. * Determine if a value is a FormData
  2185. *
  2186. * @param {Object} val The value to test
  2187. * @returns {boolean} True if value is an FormData, otherwise false
  2188. */
  2189. function isFormData(val) {
  2190. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  2191. }
  2192. /**
  2193. * Determine if a value is a view on an ArrayBuffer
  2194. *
  2195. * @param {Object} val The value to test
  2196. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  2197. */
  2198. function isArrayBufferView(val) {
  2199. var result;
  2200. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  2201. result = ArrayBuffer.isView(val);
  2202. } else {
  2203. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  2204. }
  2205. return result;
  2206. }
  2207. /**
  2208. * Determine if a value is a String
  2209. *
  2210. * @param {Object} val The value to test
  2211. * @returns {boolean} True if value is a String, otherwise false
  2212. */
  2213. function isString(val) {
  2214. return typeof val === 'string';
  2215. }
  2216. /**
  2217. * Determine if a value is a Number
  2218. *
  2219. * @param {Object} val The value to test
  2220. * @returns {boolean} True if value is a Number, otherwise false
  2221. */
  2222. function isNumber(val) {
  2223. return typeof val === 'number';
  2224. }
  2225. /**
  2226. * Determine if a value is an Object
  2227. *
  2228. * @param {Object} val The value to test
  2229. * @returns {boolean} True if value is an Object, otherwise false
  2230. */
  2231. function isObject(val) {
  2232. return val !== null && typeof val === 'object';
  2233. }
  2234. /**
  2235. * Determine if a value is a plain Object
  2236. *
  2237. * @param {Object} val The value to test
  2238. * @return {boolean} True if value is a plain Object, otherwise false
  2239. */
  2240. function isPlainObject(val) {
  2241. if (toString.call(val) !== '[object Object]') {
  2242. return false;
  2243. }
  2244. var prototype = Object.getPrototypeOf(val);
  2245. return prototype === null || prototype === Object.prototype;
  2246. }
  2247. /**
  2248. * Determine if a value is a Date
  2249. *
  2250. * @param {Object} val The value to test
  2251. * @returns {boolean} True if value is a Date, otherwise false
  2252. */
  2253. function isDate(val) {
  2254. return toString.call(val) === '[object Date]';
  2255. }
  2256. /**
  2257. * Determine if a value is a File
  2258. *
  2259. * @param {Object} val The value to test
  2260. * @returns {boolean} True if value is a File, otherwise false
  2261. */
  2262. function isFile(val) {
  2263. return toString.call(val) === '[object File]';
  2264. }
  2265. /**
  2266. * Determine if a value is a Blob
  2267. *
  2268. * @param {Object} val The value to test
  2269. * @returns {boolean} True if value is a Blob, otherwise false
  2270. */
  2271. function isBlob(val) {
  2272. return toString.call(val) === '[object Blob]';
  2273. }
  2274. /**
  2275. * Determine if a value is a Function
  2276. *
  2277. * @param {Object} val The value to test
  2278. * @returns {boolean} True if value is a Function, otherwise false
  2279. */
  2280. function isFunction(val) {
  2281. return toString.call(val) === '[object Function]';
  2282. }
  2283. /**
  2284. * Determine if a value is a Stream
  2285. *
  2286. * @param {Object} val The value to test
  2287. * @returns {boolean} True if value is a Stream, otherwise false
  2288. */
  2289. function isStream(val) {
  2290. return isObject(val) && isFunction(val.pipe);
  2291. }
  2292. /**
  2293. * Determine if a value is a URLSearchParams object
  2294. *
  2295. * @param {Object} val The value to test
  2296. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  2297. */
  2298. function isURLSearchParams(val) {
  2299. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  2300. }
  2301. /**
  2302. * Trim excess whitespace off the beginning and end of a string
  2303. *
  2304. * @param {String} str The String to trim
  2305. * @returns {String} The String freed of excess whitespace
  2306. */
  2307. function trim(str) {
  2308. return str.replace(/^\s*/, '').replace(/\s*$/, '');
  2309. }
  2310. /**
  2311. * Determine if we're running in a standard browser environment
  2312. *
  2313. * This allows axios to run in a web worker, and react-native.
  2314. * Both environments support XMLHttpRequest, but not fully standard globals.
  2315. *
  2316. * web workers:
  2317. * typeof window -> undefined
  2318. * typeof document -> undefined
  2319. *
  2320. * react-native:
  2321. * navigator.product -> 'ReactNative'
  2322. * nativescript
  2323. * navigator.product -> 'NativeScript' or 'NS'
  2324. */
  2325. function isStandardBrowserEnv() {
  2326. if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
  2327. navigator.product === 'NativeScript' ||
  2328. navigator.product === 'NS')) {
  2329. return false;
  2330. }
  2331. return (
  2332. typeof window !== 'undefined' &&
  2333. typeof document !== 'undefined'
  2334. );
  2335. }
  2336. /**
  2337. * Iterate over an Array or an Object invoking a function for each item.
  2338. *
  2339. * If `obj` is an Array callback will be called passing
  2340. * the value, index, and complete array for each item.
  2341. *
  2342. * If 'obj' is an Object callback will be called passing
  2343. * the value, key, and complete object for each property.
  2344. *
  2345. * @param {Object|Array} obj The object to iterate
  2346. * @param {Function} fn The callback to invoke for each item
  2347. */
  2348. function forEach(obj, fn) {
  2349. // Don't bother if no value provided
  2350. if (obj === null || typeof obj === 'undefined') {
  2351. return;
  2352. }
  2353. // Force an array if not already something iterable
  2354. if (typeof obj !== 'object') {
  2355. /*eslint no-param-reassign:0*/
  2356. obj = [obj];
  2357. }
  2358. if (isArray(obj)) {
  2359. // Iterate over array values
  2360. for (var i = 0, l = obj.length; i < l; i++) {
  2361. fn.call(null, obj[i], i, obj);
  2362. }
  2363. } else {
  2364. // Iterate over object keys
  2365. for (var key in obj) {
  2366. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  2367. fn.call(null, obj[key], key, obj);
  2368. }
  2369. }
  2370. }
  2371. }
  2372. /**
  2373. * Accepts varargs expecting each argument to be an object, then
  2374. * immutably merges the properties of each object and returns result.
  2375. *
  2376. * When multiple objects contain the same key the later object in
  2377. * the arguments list will take precedence.
  2378. *
  2379. * Example:
  2380. *
  2381. * ```js
  2382. * var result = merge({foo: 123}, {foo: 456});
  2383. * console.log(result.foo); // outputs 456
  2384. * ```
  2385. *
  2386. * @param {Object} obj1 Object to merge
  2387. * @returns {Object} Result of all merge properties
  2388. */
  2389. function merge(/* obj1, obj2, obj3, ... */) {
  2390. var result = {};
  2391. function assignValue(val, key) {
  2392. if (isPlainObject(result[key]) && isPlainObject(val)) {
  2393. result[key] = merge(result[key], val);
  2394. } else if (isPlainObject(val)) {
  2395. result[key] = merge({}, val);
  2396. } else if (isArray(val)) {
  2397. result[key] = val.slice();
  2398. } else {
  2399. result[key] = val;
  2400. }
  2401. }
  2402. for (var i = 0, l = arguments.length; i < l; i++) {
  2403. forEach(arguments[i], assignValue);
  2404. }
  2405. return result;
  2406. }
  2407. /**
  2408. * Extends object a by mutably adding to it the properties of object b.
  2409. *
  2410. * @param {Object} a The object to be extended
  2411. * @param {Object} b The object to copy properties from
  2412. * @param {Object} thisArg The object to bind function to
  2413. * @return {Object} The resulting value of object a
  2414. */
  2415. function extend(a, b, thisArg) {
  2416. forEach(b, function assignValue(val, key) {
  2417. if (thisArg && typeof val === 'function') {
  2418. a[key] = bind(val, thisArg);
  2419. } else {
  2420. a[key] = val;
  2421. }
  2422. });
  2423. return a;
  2424. }
  2425. /**
  2426. * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  2427. *
  2428. * @param {string} content with BOM
  2429. * @return {string} content value without BOM
  2430. */
  2431. function stripBOM(content) {
  2432. if (content.charCodeAt(0) === 0xFEFF) {
  2433. content = content.slice(1);
  2434. }
  2435. return content;
  2436. }
  2437. module.exports = {
  2438. isArray: isArray,
  2439. isArrayBuffer: isArrayBuffer,
  2440. isBuffer: isBuffer,
  2441. isFormData: isFormData,
  2442. isArrayBufferView: isArrayBufferView,
  2443. isString: isString,
  2444. isNumber: isNumber,
  2445. isObject: isObject,
  2446. isPlainObject: isPlainObject,
  2447. isUndefined: isUndefined,
  2448. isDate: isDate,
  2449. isFile: isFile,
  2450. isBlob: isBlob,
  2451. isFunction: isFunction,
  2452. isStream: isStream,
  2453. isURLSearchParams: isURLSearchParams,
  2454. isStandardBrowserEnv: isStandardBrowserEnv,
  2455. forEach: forEach,
  2456. merge: merge,
  2457. extend: extend,
  2458. trim: trim,
  2459. stripBOM: stripBOM
  2460. };
  2461. /***/ }),
  2462. /***/ "./resources/js/FormValidator.js":
  2463. /*!***************************************!*\
  2464. !*** ./resources/js/FormValidator.js ***!
  2465. \***************************************/
  2466. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  2467. "use strict";
  2468. __webpack_require__.r(__webpack_exports__);
  2469. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  2470. /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
  2471. /* harmony export */ });
  2472. /* harmony import */ var validate_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! validate.js */ "./node_modules/validate.js/validate.js");
  2473. /* harmony import */ var validate_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(validate_js__WEBPACK_IMPORTED_MODULE_0__);
  2474. /* harmony import */ var form_serialize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! form-serialize */ "./node_modules/form-serialize/index.js");
  2475. /* harmony import */ var form_serialize__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(form_serialize__WEBPACK_IMPORTED_MODULE_1__);
  2476. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2477. 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); } }
  2478. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2479. /**
  2480. * Form Validator with RiotJS Components
  2481. *
  2482. *
  2483. *
  2484. *
  2485. */
  2486. var FormValidator = /*#__PURE__*/function () {
  2487. /**
  2488. *
  2489. * @param {[type]} formSelector [description]
  2490. * @param {[type]} constraits [description]
  2491. */
  2492. function FormValidator(formSelector, constraits, onSuccess) {
  2493. var _this = this;
  2494. _classCallCheck(this, FormValidator);
  2495. // getting selector to find form-element
  2496. this.formSelector = formSelector; // constraits for validate.js
  2497. this.constraits = constraits; // get form and elements
  2498. this.form = document.querySelector(this.formSelector);
  2499. if (!this.form) {
  2500. console.error('FormValidator: form not found, querySelector not found "' + this.formSelector + '"');
  2501. }
  2502. this.elements = this.form.querySelectorAll('field-error'); // adding submit event
  2503. this.form.addEventListener('submit', function (event) {
  2504. _this.onSubmit(event);
  2505. }); // adding event if a element is updated
  2506. this.form.addEventListener('field-update', function (event) {
  2507. _this.onFieldUpdate(event);
  2508. });
  2509. this.onSuccess = onSuccess;
  2510. }
  2511. /**
  2512. *
  2513. *
  2514. */
  2515. _createClass(FormValidator, [{
  2516. key: "setConstraits",
  2517. value: function setConstraits(constraits) {
  2518. this.constraits = constraits;
  2519. }
  2520. /**
  2521. *
  2522. *
  2523. */
  2524. }, {
  2525. key: "getConstraits",
  2526. value: function getConstraits(constraits) {
  2527. return this.constraits;
  2528. }
  2529. /**
  2530. *
  2531. * @param {[type]} event [description]
  2532. * @return {[type]} [description]
  2533. */
  2534. }, {
  2535. key: "onSubmit",
  2536. value: function onSubmit(event) {
  2537. var _this2 = this;
  2538. event.preventDefault();
  2539. var errors = validate_js__WEBPACK_IMPORTED_MODULE_0___default()(form_serialize__WEBPACK_IMPORTED_MODULE_1___default()(event.target, {
  2540. hash: true
  2541. }), this.constraits, {
  2542. fullMessages: false
  2543. });
  2544. if (errors) {
  2545. // send each element a event
  2546. this.elements.forEach(function (element) {
  2547. var elementErrors = false; // check for errors by name
  2548. if (errors[element.attributes.name.nodeValue]) {
  2549. elementErrors = errors[element.attributes.name.nodeValue];
  2550. }
  2551. _this2.dispatchCustomEvent(elementErrors, element);
  2552. });
  2553. } else {
  2554. this.onSuccess(event, form_serialize__WEBPACK_IMPORTED_MODULE_1___default()(event.target, {
  2555. hash: true
  2556. }));
  2557. }
  2558. }
  2559. /**
  2560. *
  2561. *
  2562. * @param {Event} event
  2563. *
  2564. */
  2565. }, {
  2566. key: "onFieldUpdate",
  2567. value: function onFieldUpdate(event) {
  2568. var _this3 = this;
  2569. // workaround, make sure that value for single is undefined if it is empty
  2570. if (event.detail.value == '') {
  2571. event.detail.value = undefined;
  2572. }
  2573. 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
  2574. this.elements.forEach(function (element) {
  2575. if (element.attributes.name.nodeValue == event.detail.name) {
  2576. _this3.dispatchCustomEvent(errors, element);
  2577. }
  2578. });
  2579. }
  2580. /**
  2581. * dispatch event to single element
  2582. *
  2583. * @param {Array} errors
  2584. * @param {Element} element
  2585. *
  2586. */
  2587. }, {
  2588. key: "dispatchCustomEvent",
  2589. value: function dispatchCustomEvent(errors, element) {
  2590. var detail = false;
  2591. if (errors) {
  2592. detail = errors;
  2593. }
  2594. var formValidationEvent = new CustomEvent('form-validation', {
  2595. 'detail': detail
  2596. });
  2597. element.dispatchEvent(formValidationEvent);
  2598. }
  2599. }]);
  2600. return FormValidator;
  2601. }();
  2602. /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FormValidator);
  2603. /***/ }),
  2604. /***/ "./node_modules/form-serialize/index.js":
  2605. /*!**********************************************!*\
  2606. !*** ./node_modules/form-serialize/index.js ***!
  2607. \**********************************************/
  2608. /***/ ((module) => {
  2609. // get successful control from form and assemble into object
  2610. // http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2
  2611. // types which indicate a submit action and are not successful controls
  2612. // these will be ignored
  2613. var k_r_submitter = /^(?:submit|button|image|reset|file)$/i;
  2614. // node names which could be successful controls
  2615. var k_r_success_contrls = /^(?:input|select|textarea|keygen)/i;
  2616. // Matches bracket notation.
  2617. var brackets = /(\[[^\[\]]*\])/g;
  2618. // serializes form fields
  2619. // @param form MUST be an HTMLForm element
  2620. // @param options is an optional argument to configure the serialization. Default output
  2621. // with no options specified is a url encoded string
  2622. // - hash: [true | false] Configure the output type. If true, the output will
  2623. // be a js object.
  2624. // - serializer: [function] Optional serializer function to override the default one.
  2625. // The function takes 3 arguments (result, key, value) and should return new result
  2626. // hash and url encoded str serializers are provided with this module
  2627. // - disabled: [true | false]. If true serialize disabled fields.
  2628. // - empty: [true | false]. If true serialize empty fields
  2629. function serialize(form, options) {
  2630. if (typeof options != 'object') {
  2631. options = { hash: !!options };
  2632. }
  2633. else if (options.hash === undefined) {
  2634. options.hash = true;
  2635. }
  2636. var result = (options.hash) ? {} : '';
  2637. var serializer = options.serializer || ((options.hash) ? hash_serializer : str_serialize);
  2638. var elements = form && form.elements ? form.elements : [];
  2639. //Object store each radio and set if it's empty or not
  2640. var radio_store = Object.create(null);
  2641. for (var i=0 ; i<elements.length ; ++i) {
  2642. var element = elements[i];
  2643. // ingore disabled fields
  2644. if ((!options.disabled && element.disabled) || !element.name) {
  2645. continue;
  2646. }
  2647. // ignore anyhting that is not considered a success field
  2648. if (!k_r_success_contrls.test(element.nodeName) ||
  2649. k_r_submitter.test(element.type)) {
  2650. continue;
  2651. }
  2652. var key = element.name;
  2653. var val = element.value;
  2654. // we can't just use element.value for checkboxes cause some browsers lie to us
  2655. // they say "on" for value when the box isn't checked
  2656. if ((element.type === 'checkbox' || element.type === 'radio') && !element.checked) {
  2657. val = undefined;
  2658. }
  2659. // If we want empty elements
  2660. if (options.empty) {
  2661. // for checkbox
  2662. if (element.type === 'checkbox' && !element.checked) {
  2663. val = '';
  2664. }
  2665. // for radio
  2666. if (element.type === 'radio') {
  2667. if (!radio_store[element.name] && !element.checked) {
  2668. radio_store[element.name] = false;
  2669. }
  2670. else if (element.checked) {
  2671. radio_store[element.name] = true;
  2672. }
  2673. }
  2674. // if options empty is true, continue only if its radio
  2675. if (val == undefined && element.type == 'radio') {
  2676. continue;
  2677. }
  2678. }
  2679. else {
  2680. // value-less fields are ignored unless options.empty is true
  2681. if (!val) {
  2682. continue;
  2683. }
  2684. }
  2685. // multi select boxes
  2686. if (element.type === 'select-multiple') {
  2687. val = [];
  2688. var selectOptions = element.options;
  2689. var isSelectedOptions = false;
  2690. for (var j=0 ; j<selectOptions.length ; ++j) {
  2691. var option = selectOptions[j];
  2692. var allowedEmpty = options.empty && !option.value;
  2693. var hasValue = (option.value || allowedEmpty);
  2694. if (option.selected && hasValue) {
  2695. isSelectedOptions = true;
  2696. // If using a hash serializer be sure to add the
  2697. // correct notation for an array in the multi-select
  2698. // context. Here the name attribute on the select element
  2699. // might be missing the trailing bracket pair. Both names
  2700. // "foo" and "foo[]" should be arrays.
  2701. if (options.hash && key.slice(key.length - 2) !== '[]') {
  2702. result = serializer(result, key + '[]', option.value);
  2703. }
  2704. else {
  2705. result = serializer(result, key, option.value);
  2706. }
  2707. }
  2708. }
  2709. // Serialize if no selected options and options.empty is true
  2710. if (!isSelectedOptions && options.empty) {
  2711. result = serializer(result, key, '');
  2712. }
  2713. continue;
  2714. }
  2715. result = serializer(result, key, val);
  2716. }
  2717. // Check for all empty radio buttons and serialize them with key=""
  2718. if (options.empty) {
  2719. for (var key in radio_store) {
  2720. if (!radio_store[key]) {
  2721. result = serializer(result, key, '');
  2722. }
  2723. }
  2724. }
  2725. return result;
  2726. }
  2727. function parse_keys(string) {
  2728. var keys = [];
  2729. var prefix = /^([^\[\]]*)/;
  2730. var children = new RegExp(brackets);
  2731. var match = prefix.exec(string);
  2732. if (match[1]) {
  2733. keys.push(match[1]);
  2734. }
  2735. while ((match = children.exec(string)) !== null) {
  2736. keys.push(match[1]);
  2737. }
  2738. return keys;
  2739. }
  2740. function hash_assign(result, keys, value) {
  2741. if (keys.length === 0) {
  2742. result = value;
  2743. return result;
  2744. }
  2745. var key = keys.shift();
  2746. var between = key.match(/^\[(.+?)\]$/);
  2747. if (key === '[]') {
  2748. result = result || [];
  2749. if (Array.isArray(result)) {
  2750. result.push(hash_assign(null, keys, value));
  2751. }
  2752. else {
  2753. // This might be the result of bad name attributes like "[][foo]",
  2754. // in this case the original `result` object will already be
  2755. // assigned to an object literal. Rather than coerce the object to
  2756. // an array, or cause an exception the attribute "_values" is
  2757. // assigned as an array.
  2758. result._values = result._values || [];
  2759. result._values.push(hash_assign(null, keys, value));
  2760. }
  2761. return result;
  2762. }
  2763. // Key is an attribute name and can be assigned directly.
  2764. if (!between) {
  2765. result[key] = hash_assign(result[key], keys, value);
  2766. }
  2767. else {
  2768. var string = between[1];
  2769. // +var converts the variable into a number
  2770. // better than parseInt because it doesn't truncate away trailing
  2771. // letters and actually fails if whole thing is not a number
  2772. var index = +string;
  2773. // If the characters between the brackets is not a number it is an
  2774. // attribute name and can be assigned directly.
  2775. if (isNaN(index)) {
  2776. result = result || {};
  2777. result[string] = hash_assign(result[string], keys, value);
  2778. }
  2779. else {
  2780. result = result || [];
  2781. result[index] = hash_assign(result[index], keys, value);
  2782. }
  2783. }
  2784. return result;
  2785. }
  2786. // Object/hash encoding serializer.
  2787. function hash_serializer(result, key, value) {
  2788. var matches = key.match(brackets);
  2789. // Has brackets? Use the recursive assignment function to walk the keys,
  2790. // construct any missing objects in the result tree and make the assignment
  2791. // at the end of the chain.
  2792. if (matches) {
  2793. var keys = parse_keys(key);
  2794. hash_assign(result, keys, value);
  2795. }
  2796. else {
  2797. // Non bracket notation can make assignments directly.
  2798. var existing = result[key];
  2799. // If the value has been assigned already (for instance when a radio and
  2800. // a checkbox have the same name attribute) convert the previous value
  2801. // into an array before pushing into it.
  2802. //
  2803. // NOTE: If this requirement were removed all hash creation and
  2804. // assignment could go through `hash_assign`.
  2805. if (existing) {
  2806. if (!Array.isArray(existing)) {
  2807. result[key] = [ existing ];
  2808. }
  2809. result[key].push(value);
  2810. }
  2811. else {
  2812. result[key] = value;
  2813. }
  2814. }
  2815. return result;
  2816. }
  2817. // urlform encoding serializer
  2818. function str_serialize(result, key, value) {
  2819. // encode newlines as \r\n cause the html spec says so
  2820. value = value.replace(/(\r)?\n/g, '\r\n');
  2821. value = encodeURIComponent(value);
  2822. // spaces should be '+' rather than '%20'.
  2823. value = value.replace(/%20/g, '+');
  2824. return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + value;
  2825. }
  2826. module.exports = serialize;
  2827. /***/ }),
  2828. /***/ "./node_modules/lodash.remove/index.js":
  2829. /*!*********************************************!*\
  2830. !*** ./node_modules/lodash.remove/index.js ***!
  2831. \*********************************************/
  2832. /***/ ((module, exports, __webpack_require__) => {
  2833. /* module decorator */ module = __webpack_require__.nmd(module);
  2834. /**
  2835. * lodash (Custom Build) <https://lodash.com/>
  2836. * Build: `lodash modularize exports="npm" -o ./`
  2837. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  2838. * Released under MIT license <https://lodash.com/license>
  2839. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  2840. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  2841. */
  2842. /** Used as the size to enable large array optimizations. */
  2843. var LARGE_ARRAY_SIZE = 200;
  2844. /** Used as the `TypeError` message for "Functions" methods. */
  2845. var FUNC_ERROR_TEXT = 'Expected a function';
  2846. /** Used to stand-in for `undefined` hash values. */
  2847. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  2848. /** Used to compose bitmasks for comparison styles. */
  2849. var UNORDERED_COMPARE_FLAG = 1,
  2850. PARTIAL_COMPARE_FLAG = 2;
  2851. /** Used as references for various `Number` constants. */
  2852. var INFINITY = 1 / 0,
  2853. MAX_SAFE_INTEGER = 9007199254740991;
  2854. /** `Object#toString` result references. */
  2855. var argsTag = '[object Arguments]',
  2856. arrayTag = '[object Array]',
  2857. boolTag = '[object Boolean]',
  2858. dateTag = '[object Date]',
  2859. errorTag = '[object Error]',
  2860. funcTag = '[object Function]',
  2861. genTag = '[object GeneratorFunction]',
  2862. mapTag = '[object Map]',
  2863. numberTag = '[object Number]',
  2864. objectTag = '[object Object]',
  2865. promiseTag = '[object Promise]',
  2866. regexpTag = '[object RegExp]',
  2867. setTag = '[object Set]',
  2868. stringTag = '[object String]',
  2869. symbolTag = '[object Symbol]',
  2870. weakMapTag = '[object WeakMap]';
  2871. var arrayBufferTag = '[object ArrayBuffer]',
  2872. dataViewTag = '[object DataView]',
  2873. float32Tag = '[object Float32Array]',
  2874. float64Tag = '[object Float64Array]',
  2875. int8Tag = '[object Int8Array]',
  2876. int16Tag = '[object Int16Array]',
  2877. int32Tag = '[object Int32Array]',
  2878. uint8Tag = '[object Uint8Array]',
  2879. uint8ClampedTag = '[object Uint8ClampedArray]',
  2880. uint16Tag = '[object Uint16Array]',
  2881. uint32Tag = '[object Uint32Array]';
  2882. /** Used to match property names within property paths. */
  2883. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  2884. reIsPlainProp = /^\w*$/,
  2885. reLeadingDot = /^\./,
  2886. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  2887. /**
  2888. * Used to match `RegExp`
  2889. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  2890. */
  2891. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  2892. /** Used to match backslashes in property paths. */
  2893. var reEscapeChar = /\\(\\)?/g;
  2894. /** Used to detect host constructors (Safari). */
  2895. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  2896. /** Used to detect unsigned integer values. */
  2897. var reIsUint = /^(?:0|[1-9]\d*)$/;
  2898. /** Used to identify `toStringTag` values of typed arrays. */
  2899. var typedArrayTags = {};
  2900. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  2901. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  2902. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  2903. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  2904. typedArrayTags[uint32Tag] = true;
  2905. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  2906. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  2907. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  2908. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  2909. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  2910. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  2911. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  2912. typedArrayTags[weakMapTag] = false;
  2913. /** Detect free variable `global` from Node.js. */
  2914. var freeGlobal = typeof __webpack_require__.g == 'object' && __webpack_require__.g && __webpack_require__.g.Object === Object && __webpack_require__.g;
  2915. /** Detect free variable `self`. */
  2916. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  2917. /** Used as a reference to the global object. */
  2918. var root = freeGlobal || freeSelf || Function('return this')();
  2919. /** Detect free variable `exports`. */
  2920. var freeExports = true && exports && !exports.nodeType && exports;
  2921. /** Detect free variable `module`. */
  2922. var freeModule = freeExports && "object" == 'object' && module && !module.nodeType && module;
  2923. /** Detect the popular CommonJS extension `module.exports`. */
  2924. var moduleExports = freeModule && freeModule.exports === freeExports;
  2925. /** Detect free variable `process` from Node.js. */
  2926. var freeProcess = moduleExports && freeGlobal.process;
  2927. /** Used to access faster Node.js helpers. */
  2928. var nodeUtil = (function() {
  2929. try {
  2930. return freeProcess && freeProcess.binding('util');
  2931. } catch (e) {}
  2932. }());
  2933. /* Node.js helper references. */
  2934. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  2935. /**
  2936. * A specialized version of `_.some` for arrays without support for iteratee
  2937. * shorthands.
  2938. *
  2939. * @private
  2940. * @param {Array} [array] The array to iterate over.
  2941. * @param {Function} predicate The function invoked per iteration.
  2942. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2943. * else `false`.
  2944. */
  2945. function arraySome(array, predicate) {
  2946. var index = -1,
  2947. length = array ? array.length : 0;
  2948. while (++index < length) {
  2949. if (predicate(array[index], index, array)) {
  2950. return true;
  2951. }
  2952. }
  2953. return false;
  2954. }
  2955. /**
  2956. * The base implementation of `_.property` without support for deep paths.
  2957. *
  2958. * @private
  2959. * @param {string} key The key of the property to get.
  2960. * @returns {Function} Returns the new accessor function.
  2961. */
  2962. function baseProperty(key) {
  2963. return function(object) {
  2964. return object == null ? undefined : object[key];
  2965. };
  2966. }
  2967. /**
  2968. * The base implementation of `_.times` without support for iteratee shorthands
  2969. * or max array length checks.
  2970. *
  2971. * @private
  2972. * @param {number} n The number of times to invoke `iteratee`.
  2973. * @param {Function} iteratee The function invoked per iteration.
  2974. * @returns {Array} Returns the array of results.
  2975. */
  2976. function baseTimes(n, iteratee) {
  2977. var index = -1,
  2978. result = Array(n);
  2979. while (++index < n) {
  2980. result[index] = iteratee(index);
  2981. }
  2982. return result;
  2983. }
  2984. /**
  2985. * The base implementation of `_.unary` without support for storing metadata.
  2986. *
  2987. * @private
  2988. * @param {Function} func The function to cap arguments for.
  2989. * @returns {Function} Returns the new capped function.
  2990. */
  2991. function baseUnary(func) {
  2992. return function(value) {
  2993. return func(value);
  2994. };
  2995. }
  2996. /**
  2997. * Gets the value at `key` of `object`.
  2998. *
  2999. * @private
  3000. * @param {Object} [object] The object to query.
  3001. * @param {string} key The key of the property to get.
  3002. * @returns {*} Returns the property value.
  3003. */
  3004. function getValue(object, key) {
  3005. return object == null ? undefined : object[key];
  3006. }
  3007. /**
  3008. * Checks if `value` is a host object in IE < 9.
  3009. *
  3010. * @private
  3011. * @param {*} value The value to check.
  3012. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  3013. */
  3014. function isHostObject(value) {
  3015. // Many host objects are `Object` objects that can coerce to strings
  3016. // despite having improperly defined `toString` methods.
  3017. var result = false;
  3018. if (value != null && typeof value.toString != 'function') {
  3019. try {
  3020. result = !!(value + '');
  3021. } catch (e) {}
  3022. }
  3023. return result;
  3024. }
  3025. /**
  3026. * Converts `map` to its key-value pairs.
  3027. *
  3028. * @private
  3029. * @param {Object} map The map to convert.
  3030. * @returns {Array} Returns the key-value pairs.
  3031. */
  3032. function mapToArray(map) {
  3033. var index = -1,
  3034. result = Array(map.size);
  3035. map.forEach(function(value, key) {
  3036. result[++index] = [key, value];
  3037. });
  3038. return result;
  3039. }
  3040. /**
  3041. * Creates a unary function that invokes `func` with its argument transformed.
  3042. *
  3043. * @private
  3044. * @param {Function} func The function to wrap.
  3045. * @param {Function} transform The argument transform.
  3046. * @returns {Function} Returns the new function.
  3047. */
  3048. function overArg(func, transform) {
  3049. return function(arg) {
  3050. return func(transform(arg));
  3051. };
  3052. }
  3053. /**
  3054. * Converts `set` to an array of its values.
  3055. *
  3056. * @private
  3057. * @param {Object} set The set to convert.
  3058. * @returns {Array} Returns the values.
  3059. */
  3060. function setToArray(set) {
  3061. var index = -1,
  3062. result = Array(set.size);
  3063. set.forEach(function(value) {
  3064. result[++index] = value;
  3065. });
  3066. return result;
  3067. }
  3068. /** Used for built-in method references. */
  3069. var arrayProto = Array.prototype,
  3070. funcProto = Function.prototype,
  3071. objectProto = Object.prototype;
  3072. /** Used to detect overreaching core-js shims. */
  3073. var coreJsData = root['__core-js_shared__'];
  3074. /** Used to detect methods masquerading as native. */
  3075. var maskSrcKey = (function() {
  3076. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  3077. return uid ? ('Symbol(src)_1.' + uid) : '';
  3078. }());
  3079. /** Used to resolve the decompiled source of functions. */
  3080. var funcToString = funcProto.toString;
  3081. /** Used to check objects for own properties. */
  3082. var hasOwnProperty = objectProto.hasOwnProperty;
  3083. /**
  3084. * Used to resolve the
  3085. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  3086. * of values.
  3087. */
  3088. var objectToString = objectProto.toString;
  3089. /** Used to detect if a method is native. */
  3090. var reIsNative = RegExp('^' +
  3091. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  3092. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  3093. );
  3094. /** Built-in value references. */
  3095. var Symbol = root.Symbol,
  3096. Uint8Array = root.Uint8Array,
  3097. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  3098. splice = arrayProto.splice;
  3099. /* Built-in method references for those with the same name as other `lodash` methods. */
  3100. var nativeKeys = overArg(Object.keys, Object);
  3101. /* Built-in method references that are verified to be native. */
  3102. var DataView = getNative(root, 'DataView'),
  3103. Map = getNative(root, 'Map'),
  3104. Promise = getNative(root, 'Promise'),
  3105. Set = getNative(root, 'Set'),
  3106. WeakMap = getNative(root, 'WeakMap'),
  3107. nativeCreate = getNative(Object, 'create');
  3108. /** Used to detect maps, sets, and weakmaps. */
  3109. var dataViewCtorString = toSource(DataView),
  3110. mapCtorString = toSource(Map),
  3111. promiseCtorString = toSource(Promise),
  3112. setCtorString = toSource(Set),
  3113. weakMapCtorString = toSource(WeakMap);
  3114. /** Used to convert symbols to primitives and strings. */
  3115. var symbolProto = Symbol ? Symbol.prototype : undefined,
  3116. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  3117. symbolToString = symbolProto ? symbolProto.toString : undefined;
  3118. /**
  3119. * Creates a hash object.
  3120. *
  3121. * @private
  3122. * @constructor
  3123. * @param {Array} [entries] The key-value pairs to cache.
  3124. */
  3125. function Hash(entries) {
  3126. var index = -1,
  3127. length = entries ? entries.length : 0;
  3128. this.clear();
  3129. while (++index < length) {
  3130. var entry = entries[index];
  3131. this.set(entry[0], entry[1]);
  3132. }
  3133. }
  3134. /**
  3135. * Removes all key-value entries from the hash.
  3136. *
  3137. * @private
  3138. * @name clear
  3139. * @memberOf Hash
  3140. */
  3141. function hashClear() {
  3142. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  3143. }
  3144. /**
  3145. * Removes `key` and its value from the hash.
  3146. *
  3147. * @private
  3148. * @name delete
  3149. * @memberOf Hash
  3150. * @param {Object} hash The hash to modify.
  3151. * @param {string} key The key of the value to remove.
  3152. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3153. */
  3154. function hashDelete(key) {
  3155. return this.has(key) && delete this.__data__[key];
  3156. }
  3157. /**
  3158. * Gets the hash value for `key`.
  3159. *
  3160. * @private
  3161. * @name get
  3162. * @memberOf Hash
  3163. * @param {string} key The key of the value to get.
  3164. * @returns {*} Returns the entry value.
  3165. */
  3166. function hashGet(key) {
  3167. var data = this.__data__;
  3168. if (nativeCreate) {
  3169. var result = data[key];
  3170. return result === HASH_UNDEFINED ? undefined : result;
  3171. }
  3172. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  3173. }
  3174. /**
  3175. * Checks if a hash value for `key` exists.
  3176. *
  3177. * @private
  3178. * @name has
  3179. * @memberOf Hash
  3180. * @param {string} key The key of the entry to check.
  3181. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3182. */
  3183. function hashHas(key) {
  3184. var data = this.__data__;
  3185. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  3186. }
  3187. /**
  3188. * Sets the hash `key` to `value`.
  3189. *
  3190. * @private
  3191. * @name set
  3192. * @memberOf Hash
  3193. * @param {string} key The key of the value to set.
  3194. * @param {*} value The value to set.
  3195. * @returns {Object} Returns the hash instance.
  3196. */
  3197. function hashSet(key, value) {
  3198. var data = this.__data__;
  3199. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  3200. return this;
  3201. }
  3202. // Add methods to `Hash`.
  3203. Hash.prototype.clear = hashClear;
  3204. Hash.prototype['delete'] = hashDelete;
  3205. Hash.prototype.get = hashGet;
  3206. Hash.prototype.has = hashHas;
  3207. Hash.prototype.set = hashSet;
  3208. /**
  3209. * Creates an list cache object.
  3210. *
  3211. * @private
  3212. * @constructor
  3213. * @param {Array} [entries] The key-value pairs to cache.
  3214. */
  3215. function ListCache(entries) {
  3216. var index = -1,
  3217. length = entries ? entries.length : 0;
  3218. this.clear();
  3219. while (++index < length) {
  3220. var entry = entries[index];
  3221. this.set(entry[0], entry[1]);
  3222. }
  3223. }
  3224. /**
  3225. * Removes all key-value entries from the list cache.
  3226. *
  3227. * @private
  3228. * @name clear
  3229. * @memberOf ListCache
  3230. */
  3231. function listCacheClear() {
  3232. this.__data__ = [];
  3233. }
  3234. /**
  3235. * Removes `key` and its value from the list cache.
  3236. *
  3237. * @private
  3238. * @name delete
  3239. * @memberOf ListCache
  3240. * @param {string} key The key of the value to remove.
  3241. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3242. */
  3243. function listCacheDelete(key) {
  3244. var data = this.__data__,
  3245. index = assocIndexOf(data, key);
  3246. if (index < 0) {
  3247. return false;
  3248. }
  3249. var lastIndex = data.length - 1;
  3250. if (index == lastIndex) {
  3251. data.pop();
  3252. } else {
  3253. splice.call(data, index, 1);
  3254. }
  3255. return true;
  3256. }
  3257. /**
  3258. * Gets the list cache value for `key`.
  3259. *
  3260. * @private
  3261. * @name get
  3262. * @memberOf ListCache
  3263. * @param {string} key The key of the value to get.
  3264. * @returns {*} Returns the entry value.
  3265. */
  3266. function listCacheGet(key) {
  3267. var data = this.__data__,
  3268. index = assocIndexOf(data, key);
  3269. return index < 0 ? undefined : data[index][1];
  3270. }
  3271. /**
  3272. * Checks if a list cache value for `key` exists.
  3273. *
  3274. * @private
  3275. * @name has
  3276. * @memberOf ListCache
  3277. * @param {string} key The key of the entry to check.
  3278. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3279. */
  3280. function listCacheHas(key) {
  3281. return assocIndexOf(this.__data__, key) > -1;
  3282. }
  3283. /**
  3284. * Sets the list cache `key` to `value`.
  3285. *
  3286. * @private
  3287. * @name set
  3288. * @memberOf ListCache
  3289. * @param {string} key The key of the value to set.
  3290. * @param {*} value The value to set.
  3291. * @returns {Object} Returns the list cache instance.
  3292. */
  3293. function listCacheSet(key, value) {
  3294. var data = this.__data__,
  3295. index = assocIndexOf(data, key);
  3296. if (index < 0) {
  3297. data.push([key, value]);
  3298. } else {
  3299. data[index][1] = value;
  3300. }
  3301. return this;
  3302. }
  3303. // Add methods to `ListCache`.
  3304. ListCache.prototype.clear = listCacheClear;
  3305. ListCache.prototype['delete'] = listCacheDelete;
  3306. ListCache.prototype.get = listCacheGet;
  3307. ListCache.prototype.has = listCacheHas;
  3308. ListCache.prototype.set = listCacheSet;
  3309. /**
  3310. * Creates a map cache object to store key-value pairs.
  3311. *
  3312. * @private
  3313. * @constructor
  3314. * @param {Array} [entries] The key-value pairs to cache.
  3315. */
  3316. function MapCache(entries) {
  3317. var index = -1,
  3318. length = entries ? entries.length : 0;
  3319. this.clear();
  3320. while (++index < length) {
  3321. var entry = entries[index];
  3322. this.set(entry[0], entry[1]);
  3323. }
  3324. }
  3325. /**
  3326. * Removes all key-value entries from the map.
  3327. *
  3328. * @private
  3329. * @name clear
  3330. * @memberOf MapCache
  3331. */
  3332. function mapCacheClear() {
  3333. this.__data__ = {
  3334. 'hash': new Hash,
  3335. 'map': new (Map || ListCache),
  3336. 'string': new Hash
  3337. };
  3338. }
  3339. /**
  3340. * Removes `key` and its value from the map.
  3341. *
  3342. * @private
  3343. * @name delete
  3344. * @memberOf MapCache
  3345. * @param {string} key The key of the value to remove.
  3346. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3347. */
  3348. function mapCacheDelete(key) {
  3349. return getMapData(this, key)['delete'](key);
  3350. }
  3351. /**
  3352. * Gets the map value for `key`.
  3353. *
  3354. * @private
  3355. * @name get
  3356. * @memberOf MapCache
  3357. * @param {string} key The key of the value to get.
  3358. * @returns {*} Returns the entry value.
  3359. */
  3360. function mapCacheGet(key) {
  3361. return getMapData(this, key).get(key);
  3362. }
  3363. /**
  3364. * Checks if a map value for `key` exists.
  3365. *
  3366. * @private
  3367. * @name has
  3368. * @memberOf MapCache
  3369. * @param {string} key The key of the entry to check.
  3370. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3371. */
  3372. function mapCacheHas(key) {
  3373. return getMapData(this, key).has(key);
  3374. }
  3375. /**
  3376. * Sets the map `key` to `value`.
  3377. *
  3378. * @private
  3379. * @name set
  3380. * @memberOf MapCache
  3381. * @param {string} key The key of the value to set.
  3382. * @param {*} value The value to set.
  3383. * @returns {Object} Returns the map cache instance.
  3384. */
  3385. function mapCacheSet(key, value) {
  3386. getMapData(this, key).set(key, value);
  3387. return this;
  3388. }
  3389. // Add methods to `MapCache`.
  3390. MapCache.prototype.clear = mapCacheClear;
  3391. MapCache.prototype['delete'] = mapCacheDelete;
  3392. MapCache.prototype.get = mapCacheGet;
  3393. MapCache.prototype.has = mapCacheHas;
  3394. MapCache.prototype.set = mapCacheSet;
  3395. /**
  3396. *
  3397. * Creates an array cache object to store unique values.
  3398. *
  3399. * @private
  3400. * @constructor
  3401. * @param {Array} [values] The values to cache.
  3402. */
  3403. function SetCache(values) {
  3404. var index = -1,
  3405. length = values ? values.length : 0;
  3406. this.__data__ = new MapCache;
  3407. while (++index < length) {
  3408. this.add(values[index]);
  3409. }
  3410. }
  3411. /**
  3412. * Adds `value` to the array cache.
  3413. *
  3414. * @private
  3415. * @name add
  3416. * @memberOf SetCache
  3417. * @alias push
  3418. * @param {*} value The value to cache.
  3419. * @returns {Object} Returns the cache instance.
  3420. */
  3421. function setCacheAdd(value) {
  3422. this.__data__.set(value, HASH_UNDEFINED);
  3423. return this;
  3424. }
  3425. /**
  3426. * Checks if `value` is in the array cache.
  3427. *
  3428. * @private
  3429. * @name has
  3430. * @memberOf SetCache
  3431. * @param {*} value The value to search for.
  3432. * @returns {number} Returns `true` if `value` is found, else `false`.
  3433. */
  3434. function setCacheHas(value) {
  3435. return this.__data__.has(value);
  3436. }
  3437. // Add methods to `SetCache`.
  3438. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  3439. SetCache.prototype.has = setCacheHas;
  3440. /**
  3441. * Creates a stack cache object to store key-value pairs.
  3442. *
  3443. * @private
  3444. * @constructor
  3445. * @param {Array} [entries] The key-value pairs to cache.
  3446. */
  3447. function Stack(entries) {
  3448. this.__data__ = new ListCache(entries);
  3449. }
  3450. /**
  3451. * Removes all key-value entries from the stack.
  3452. *
  3453. * @private
  3454. * @name clear
  3455. * @memberOf Stack
  3456. */
  3457. function stackClear() {
  3458. this.__data__ = new ListCache;
  3459. }
  3460. /**
  3461. * Removes `key` and its value from the stack.
  3462. *
  3463. * @private
  3464. * @name delete
  3465. * @memberOf Stack
  3466. * @param {string} key The key of the value to remove.
  3467. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3468. */
  3469. function stackDelete(key) {
  3470. return this.__data__['delete'](key);
  3471. }
  3472. /**
  3473. * Gets the stack value for `key`.
  3474. *
  3475. * @private
  3476. * @name get
  3477. * @memberOf Stack
  3478. * @param {string} key The key of the value to get.
  3479. * @returns {*} Returns the entry value.
  3480. */
  3481. function stackGet(key) {
  3482. return this.__data__.get(key);
  3483. }
  3484. /**
  3485. * Checks if a stack value for `key` exists.
  3486. *
  3487. * @private
  3488. * @name has
  3489. * @memberOf Stack
  3490. * @param {string} key The key of the entry to check.
  3491. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3492. */
  3493. function stackHas(key) {
  3494. return this.__data__.has(key);
  3495. }
  3496. /**
  3497. * Sets the stack `key` to `value`.
  3498. *
  3499. * @private
  3500. * @name set
  3501. * @memberOf Stack
  3502. * @param {string} key The key of the value to set.
  3503. * @param {*} value The value to set.
  3504. * @returns {Object} Returns the stack cache instance.
  3505. */
  3506. function stackSet(key, value) {
  3507. var cache = this.__data__;
  3508. if (cache instanceof ListCache) {
  3509. var pairs = cache.__data__;
  3510. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  3511. pairs.push([key, value]);
  3512. return this;
  3513. }
  3514. cache = this.__data__ = new MapCache(pairs);
  3515. }
  3516. cache.set(key, value);
  3517. return this;
  3518. }
  3519. // Add methods to `Stack`.
  3520. Stack.prototype.clear = stackClear;
  3521. Stack.prototype['delete'] = stackDelete;
  3522. Stack.prototype.get = stackGet;
  3523. Stack.prototype.has = stackHas;
  3524. Stack.prototype.set = stackSet;
  3525. /**
  3526. * Creates an array of the enumerable property names of the array-like `value`.
  3527. *
  3528. * @private
  3529. * @param {*} value The value to query.
  3530. * @param {boolean} inherited Specify returning inherited property names.
  3531. * @returns {Array} Returns the array of property names.
  3532. */
  3533. function arrayLikeKeys(value, inherited) {
  3534. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  3535. // Safari 9 makes `arguments.length` enumerable in strict mode.
  3536. var result = (isArray(value) || isArguments(value))
  3537. ? baseTimes(value.length, String)
  3538. : [];
  3539. var length = result.length,
  3540. skipIndexes = !!length;
  3541. for (var key in value) {
  3542. if ((inherited || hasOwnProperty.call(value, key)) &&
  3543. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  3544. result.push(key);
  3545. }
  3546. }
  3547. return result;
  3548. }
  3549. /**
  3550. * Gets the index at which the `key` is found in `array` of key-value pairs.
  3551. *
  3552. * @private
  3553. * @param {Array} array The array to inspect.
  3554. * @param {*} key The key to search for.
  3555. * @returns {number} Returns the index of the matched value, else `-1`.
  3556. */
  3557. function assocIndexOf(array, key) {
  3558. var length = array.length;
  3559. while (length--) {
  3560. if (eq(array[length][0], key)) {
  3561. return length;
  3562. }
  3563. }
  3564. return -1;
  3565. }
  3566. /**
  3567. * The base implementation of `_.get` without support for default values.
  3568. *
  3569. * @private
  3570. * @param {Object} object The object to query.
  3571. * @param {Array|string} path The path of the property to get.
  3572. * @returns {*} Returns the resolved value.
  3573. */
  3574. function baseGet(object, path) {
  3575. path = isKey(path, object) ? [path] : castPath(path);
  3576. var index = 0,
  3577. length = path.length;
  3578. while (object != null && index < length) {
  3579. object = object[toKey(path[index++])];
  3580. }
  3581. return (index && index == length) ? object : undefined;
  3582. }
  3583. /**
  3584. * The base implementation of `getTag`.
  3585. *
  3586. * @private
  3587. * @param {*} value The value to query.
  3588. * @returns {string} Returns the `toStringTag`.
  3589. */
  3590. function baseGetTag(value) {
  3591. return objectToString.call(value);
  3592. }
  3593. /**
  3594. * The base implementation of `_.hasIn` without support for deep paths.
  3595. *
  3596. * @private
  3597. * @param {Object} [object] The object to query.
  3598. * @param {Array|string} key The key to check.
  3599. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  3600. */
  3601. function baseHasIn(object, key) {
  3602. return object != null && key in Object(object);
  3603. }
  3604. /**
  3605. * The base implementation of `_.isEqual` which supports partial comparisons
  3606. * and tracks traversed objects.
  3607. *
  3608. * @private
  3609. * @param {*} value The value to compare.
  3610. * @param {*} other The other value to compare.
  3611. * @param {Function} [customizer] The function to customize comparisons.
  3612. * @param {boolean} [bitmask] The bitmask of comparison flags.
  3613. * The bitmask may be composed of the following flags:
  3614. * 1 - Unordered comparison
  3615. * 2 - Partial comparison
  3616. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3617. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3618. */
  3619. function baseIsEqual(value, other, customizer, bitmask, stack) {
  3620. if (value === other) {
  3621. return true;
  3622. }
  3623. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  3624. return value !== value && other !== other;
  3625. }
  3626. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  3627. }
  3628. /**
  3629. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3630. * deep comparisons and tracks traversed objects enabling objects with circular
  3631. * references to be compared.
  3632. *
  3633. * @private
  3634. * @param {Object} object The object to compare.
  3635. * @param {Object} other The other object to compare.
  3636. * @param {Function} equalFunc The function to determine equivalents of values.
  3637. * @param {Function} [customizer] The function to customize comparisons.
  3638. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  3639. * for more details.
  3640. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3641. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3642. */
  3643. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  3644. var objIsArr = isArray(object),
  3645. othIsArr = isArray(other),
  3646. objTag = arrayTag,
  3647. othTag = arrayTag;
  3648. if (!objIsArr) {
  3649. objTag = getTag(object);
  3650. objTag = objTag == argsTag ? objectTag : objTag;
  3651. }
  3652. if (!othIsArr) {
  3653. othTag = getTag(other);
  3654. othTag = othTag == argsTag ? objectTag : othTag;
  3655. }
  3656. var objIsObj = objTag == objectTag && !isHostObject(object),
  3657. othIsObj = othTag == objectTag && !isHostObject(other),
  3658. isSameTag = objTag == othTag;
  3659. if (isSameTag && !objIsObj) {
  3660. stack || (stack = new Stack);
  3661. return (objIsArr || isTypedArray(object))
  3662. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  3663. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  3664. }
  3665. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  3666. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3667. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3668. if (objIsWrapped || othIsWrapped) {
  3669. var objUnwrapped = objIsWrapped ? object.value() : object,
  3670. othUnwrapped = othIsWrapped ? other.value() : other;
  3671. stack || (stack = new Stack);
  3672. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  3673. }
  3674. }
  3675. if (!isSameTag) {
  3676. return false;
  3677. }
  3678. stack || (stack = new Stack);
  3679. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  3680. }
  3681. /**
  3682. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3683. *
  3684. * @private
  3685. * @param {Object} object The object to inspect.
  3686. * @param {Object} source The object of property values to match.
  3687. * @param {Array} matchData The property names, values, and compare flags to match.
  3688. * @param {Function} [customizer] The function to customize comparisons.
  3689. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3690. */
  3691. function baseIsMatch(object, source, matchData, customizer) {
  3692. var index = matchData.length,
  3693. length = index,
  3694. noCustomizer = !customizer;
  3695. if (object == null) {
  3696. return !length;
  3697. }
  3698. object = Object(object);
  3699. while (index--) {
  3700. var data = matchData[index];
  3701. if ((noCustomizer && data[2])
  3702. ? data[1] !== object[data[0]]
  3703. : !(data[0] in object)
  3704. ) {
  3705. return false;
  3706. }
  3707. }
  3708. while (++index < length) {
  3709. data = matchData[index];
  3710. var key = data[0],
  3711. objValue = object[key],
  3712. srcValue = data[1];
  3713. if (noCustomizer && data[2]) {
  3714. if (objValue === undefined && !(key in object)) {
  3715. return false;
  3716. }
  3717. } else {
  3718. var stack = new Stack;
  3719. if (customizer) {
  3720. var result = customizer(objValue, srcValue, key, object, source, stack);
  3721. }
  3722. if (!(result === undefined
  3723. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  3724. : result
  3725. )) {
  3726. return false;
  3727. }
  3728. }
  3729. }
  3730. return true;
  3731. }
  3732. /**
  3733. * The base implementation of `_.isNative` without bad shim checks.
  3734. *
  3735. * @private
  3736. * @param {*} value The value to check.
  3737. * @returns {boolean} Returns `true` if `value` is a native function,
  3738. * else `false`.
  3739. */
  3740. function baseIsNative(value) {
  3741. if (!isObject(value) || isMasked(value)) {
  3742. return false;
  3743. }
  3744. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  3745. return pattern.test(toSource(value));
  3746. }
  3747. /**
  3748. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3749. *
  3750. * @private
  3751. * @param {*} value The value to check.
  3752. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3753. */
  3754. function baseIsTypedArray(value) {
  3755. return isObjectLike(value) &&
  3756. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  3757. }
  3758. /**
  3759. * The base implementation of `_.iteratee`.
  3760. *
  3761. * @private
  3762. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3763. * @returns {Function} Returns the iteratee.
  3764. */
  3765. function baseIteratee(value) {
  3766. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3767. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3768. if (typeof value == 'function') {
  3769. return value;
  3770. }
  3771. if (value == null) {
  3772. return identity;
  3773. }
  3774. if (typeof value == 'object') {
  3775. return isArray(value)
  3776. ? baseMatchesProperty(value[0], value[1])
  3777. : baseMatches(value);
  3778. }
  3779. return property(value);
  3780. }
  3781. /**
  3782. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3783. *
  3784. * @private
  3785. * @param {Object} object The object to query.
  3786. * @returns {Array} Returns the array of property names.
  3787. */
  3788. function baseKeys(object) {
  3789. if (!isPrototype(object)) {
  3790. return nativeKeys(object);
  3791. }
  3792. var result = [];
  3793. for (var key in Object(object)) {
  3794. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3795. result.push(key);
  3796. }
  3797. }
  3798. return result;
  3799. }
  3800. /**
  3801. * The base implementation of `_.matches` which doesn't clone `source`.
  3802. *
  3803. * @private
  3804. * @param {Object} source The object of property values to match.
  3805. * @returns {Function} Returns the new spec function.
  3806. */
  3807. function baseMatches(source) {
  3808. var matchData = getMatchData(source);
  3809. if (matchData.length == 1 && matchData[0][2]) {
  3810. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3811. }
  3812. return function(object) {
  3813. return object === source || baseIsMatch(object, source, matchData);
  3814. };
  3815. }
  3816. /**
  3817. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3818. *
  3819. * @private
  3820. * @param {string} path The path of the property to get.
  3821. * @param {*} srcValue The value to match.
  3822. * @returns {Function} Returns the new spec function.
  3823. */
  3824. function baseMatchesProperty(path, srcValue) {
  3825. if (isKey(path) && isStrictComparable(srcValue)) {
  3826. return matchesStrictComparable(toKey(path), srcValue);
  3827. }
  3828. return function(object) {
  3829. var objValue = get(object, path);
  3830. return (objValue === undefined && objValue === srcValue)
  3831. ? hasIn(object, path)
  3832. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  3833. };
  3834. }
  3835. /**
  3836. * A specialized version of `baseProperty` which supports deep paths.
  3837. *
  3838. * @private
  3839. * @param {Array|string} path The path of the property to get.
  3840. * @returns {Function} Returns the new accessor function.
  3841. */
  3842. function basePropertyDeep(path) {
  3843. return function(object) {
  3844. return baseGet(object, path);
  3845. };
  3846. }
  3847. /**
  3848. * The base implementation of `_.pullAt` without support for individual
  3849. * indexes or capturing the removed elements.
  3850. *
  3851. * @private
  3852. * @param {Array} array The array to modify.
  3853. * @param {number[]} indexes The indexes of elements to remove.
  3854. * @returns {Array} Returns `array`.
  3855. */
  3856. function basePullAt(array, indexes) {
  3857. var length = array ? indexes.length : 0,
  3858. lastIndex = length - 1;
  3859. while (length--) {
  3860. var index = indexes[length];
  3861. if (length == lastIndex || index !== previous) {
  3862. var previous = index;
  3863. if (isIndex(index)) {
  3864. splice.call(array, index, 1);
  3865. }
  3866. else if (!isKey(index, array)) {
  3867. var path = castPath(index),
  3868. object = parent(array, path);
  3869. if (object != null) {
  3870. delete object[toKey(last(path))];
  3871. }
  3872. }
  3873. else {
  3874. delete array[toKey(index)];
  3875. }
  3876. }
  3877. }
  3878. return array;
  3879. }
  3880. /**
  3881. * The base implementation of `_.slice` without an iteratee call guard.
  3882. *
  3883. * @private
  3884. * @param {Array} array The array to slice.
  3885. * @param {number} [start=0] The start position.
  3886. * @param {number} [end=array.length] The end position.
  3887. * @returns {Array} Returns the slice of `array`.
  3888. */
  3889. function baseSlice(array, start, end) {
  3890. var index = -1,
  3891. length = array.length;
  3892. if (start < 0) {
  3893. start = -start > length ? 0 : (length + start);
  3894. }
  3895. end = end > length ? length : end;
  3896. if (end < 0) {
  3897. end += length;
  3898. }
  3899. length = start > end ? 0 : ((end - start) >>> 0);
  3900. start >>>= 0;
  3901. var result = Array(length);
  3902. while (++index < length) {
  3903. result[index] = array[index + start];
  3904. }
  3905. return result;
  3906. }
  3907. /**
  3908. * The base implementation of `_.toString` which doesn't convert nullish
  3909. * values to empty strings.
  3910. *
  3911. * @private
  3912. * @param {*} value The value to process.
  3913. * @returns {string} Returns the string.
  3914. */
  3915. function baseToString(value) {
  3916. // Exit early for strings to avoid a performance hit in some environments.
  3917. if (typeof value == 'string') {
  3918. return value;
  3919. }
  3920. if (isSymbol(value)) {
  3921. return symbolToString ? symbolToString.call(value) : '';
  3922. }
  3923. var result = (value + '');
  3924. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3925. }
  3926. /**
  3927. * Casts `value` to a path array if it's not one.
  3928. *
  3929. * @private
  3930. * @param {*} value The value to inspect.
  3931. * @returns {Array} Returns the cast property path array.
  3932. */
  3933. function castPath(value) {
  3934. return isArray(value) ? value : stringToPath(value);
  3935. }
  3936. /**
  3937. * A specialized version of `baseIsEqualDeep` for arrays with support for
  3938. * partial deep comparisons.
  3939. *
  3940. * @private
  3941. * @param {Array} array The array to compare.
  3942. * @param {Array} other The other array to compare.
  3943. * @param {Function} equalFunc The function to determine equivalents of values.
  3944. * @param {Function} customizer The function to customize comparisons.
  3945. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  3946. * for more details.
  3947. * @param {Object} stack Tracks traversed `array` and `other` objects.
  3948. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  3949. */
  3950. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  3951. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  3952. arrLength = array.length,
  3953. othLength = other.length;
  3954. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  3955. return false;
  3956. }
  3957. // Assume cyclic values are equal.
  3958. var stacked = stack.get(array);
  3959. if (stacked && stack.get(other)) {
  3960. return stacked == other;
  3961. }
  3962. var index = -1,
  3963. result = true,
  3964. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  3965. stack.set(array, other);
  3966. stack.set(other, array);
  3967. // Ignore non-index properties.
  3968. while (++index < arrLength) {
  3969. var arrValue = array[index],
  3970. othValue = other[index];
  3971. if (customizer) {
  3972. var compared = isPartial
  3973. ? customizer(othValue, arrValue, index, other, array, stack)
  3974. : customizer(arrValue, othValue, index, array, other, stack);
  3975. }
  3976. if (compared !== undefined) {
  3977. if (compared) {
  3978. continue;
  3979. }
  3980. result = false;
  3981. break;
  3982. }
  3983. // Recursively compare arrays (susceptible to call stack limits).
  3984. if (seen) {
  3985. if (!arraySome(other, function(othValue, othIndex) {
  3986. if (!seen.has(othIndex) &&
  3987. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  3988. return seen.add(othIndex);
  3989. }
  3990. })) {
  3991. result = false;
  3992. break;
  3993. }
  3994. } else if (!(
  3995. arrValue === othValue ||
  3996. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  3997. )) {
  3998. result = false;
  3999. break;
  4000. }
  4001. }
  4002. stack['delete'](array);
  4003. stack['delete'](other);
  4004. return result;
  4005. }
  4006. /**
  4007. * A specialized version of `baseIsEqualDeep` for comparing objects of
  4008. * the same `toStringTag`.
  4009. *
  4010. * **Note:** This function only supports comparing values with tags of
  4011. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  4012. *
  4013. * @private
  4014. * @param {Object} object The object to compare.
  4015. * @param {Object} other The other object to compare.
  4016. * @param {string} tag The `toStringTag` of the objects to compare.
  4017. * @param {Function} equalFunc The function to determine equivalents of values.
  4018. * @param {Function} customizer The function to customize comparisons.
  4019. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4020. * for more details.
  4021. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4022. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4023. */
  4024. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  4025. switch (tag) {
  4026. case dataViewTag:
  4027. if ((object.byteLength != other.byteLength) ||
  4028. (object.byteOffset != other.byteOffset)) {
  4029. return false;
  4030. }
  4031. object = object.buffer;
  4032. other = other.buffer;
  4033. case arrayBufferTag:
  4034. if ((object.byteLength != other.byteLength) ||
  4035. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  4036. return false;
  4037. }
  4038. return true;
  4039. case boolTag:
  4040. case dateTag:
  4041. case numberTag:
  4042. // Coerce booleans to `1` or `0` and dates to milliseconds.
  4043. // Invalid dates are coerced to `NaN`.
  4044. return eq(+object, +other);
  4045. case errorTag:
  4046. return object.name == other.name && object.message == other.message;
  4047. case regexpTag:
  4048. case stringTag:
  4049. // Coerce regexes to strings and treat strings, primitives and objects,
  4050. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  4051. // for more details.
  4052. return object == (other + '');
  4053. case mapTag:
  4054. var convert = mapToArray;
  4055. case setTag:
  4056. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  4057. convert || (convert = setToArray);
  4058. if (object.size != other.size && !isPartial) {
  4059. return false;
  4060. }
  4061. // Assume cyclic values are equal.
  4062. var stacked = stack.get(object);
  4063. if (stacked) {
  4064. return stacked == other;
  4065. }
  4066. bitmask |= UNORDERED_COMPARE_FLAG;
  4067. // Recursively compare objects (susceptible to call stack limits).
  4068. stack.set(object, other);
  4069. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  4070. stack['delete'](object);
  4071. return result;
  4072. case symbolTag:
  4073. if (symbolValueOf) {
  4074. return symbolValueOf.call(object) == symbolValueOf.call(other);
  4075. }
  4076. }
  4077. return false;
  4078. }
  4079. /**
  4080. * A specialized version of `baseIsEqualDeep` for objects with support for
  4081. * partial deep comparisons.
  4082. *
  4083. * @private
  4084. * @param {Object} object The object to compare.
  4085. * @param {Object} other The other object to compare.
  4086. * @param {Function} equalFunc The function to determine equivalents of values.
  4087. * @param {Function} customizer The function to customize comparisons.
  4088. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4089. * for more details.
  4090. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4091. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4092. */
  4093. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  4094. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  4095. objProps = keys(object),
  4096. objLength = objProps.length,
  4097. othProps = keys(other),
  4098. othLength = othProps.length;
  4099. if (objLength != othLength && !isPartial) {
  4100. return false;
  4101. }
  4102. var index = objLength;
  4103. while (index--) {
  4104. var key = objProps[index];
  4105. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  4106. return false;
  4107. }
  4108. }
  4109. // Assume cyclic values are equal.
  4110. var stacked = stack.get(object);
  4111. if (stacked && stack.get(other)) {
  4112. return stacked == other;
  4113. }
  4114. var result = true;
  4115. stack.set(object, other);
  4116. stack.set(other, object);
  4117. var skipCtor = isPartial;
  4118. while (++index < objLength) {
  4119. key = objProps[index];
  4120. var objValue = object[key],
  4121. othValue = other[key];
  4122. if (customizer) {
  4123. var compared = isPartial
  4124. ? customizer(othValue, objValue, key, other, object, stack)
  4125. : customizer(objValue, othValue, key, object, other, stack);
  4126. }
  4127. // Recursively compare objects (susceptible to call stack limits).
  4128. if (!(compared === undefined
  4129. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  4130. : compared
  4131. )) {
  4132. result = false;
  4133. break;
  4134. }
  4135. skipCtor || (skipCtor = key == 'constructor');
  4136. }
  4137. if (result && !skipCtor) {
  4138. var objCtor = object.constructor,
  4139. othCtor = other.constructor;
  4140. // Non `Object` object instances with different constructors are not equal.
  4141. if (objCtor != othCtor &&
  4142. ('constructor' in object && 'constructor' in other) &&
  4143. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  4144. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  4145. result = false;
  4146. }
  4147. }
  4148. stack['delete'](object);
  4149. stack['delete'](other);
  4150. return result;
  4151. }
  4152. /**
  4153. * Gets the data for `map`.
  4154. *
  4155. * @private
  4156. * @param {Object} map The map to query.
  4157. * @param {string} key The reference key.
  4158. * @returns {*} Returns the map data.
  4159. */
  4160. function getMapData(map, key) {
  4161. var data = map.__data__;
  4162. return isKeyable(key)
  4163. ? data[typeof key == 'string' ? 'string' : 'hash']
  4164. : data.map;
  4165. }
  4166. /**
  4167. * Gets the property names, values, and compare flags of `object`.
  4168. *
  4169. * @private
  4170. * @param {Object} object The object to query.
  4171. * @returns {Array} Returns the match data of `object`.
  4172. */
  4173. function getMatchData(object) {
  4174. var result = keys(object),
  4175. length = result.length;
  4176. while (length--) {
  4177. var key = result[length],
  4178. value = object[key];
  4179. result[length] = [key, value, isStrictComparable(value)];
  4180. }
  4181. return result;
  4182. }
  4183. /**
  4184. * Gets the native function at `key` of `object`.
  4185. *
  4186. * @private
  4187. * @param {Object} object The object to query.
  4188. * @param {string} key The key of the method to get.
  4189. * @returns {*} Returns the function if it's native, else `undefined`.
  4190. */
  4191. function getNative(object, key) {
  4192. var value = getValue(object, key);
  4193. return baseIsNative(value) ? value : undefined;
  4194. }
  4195. /**
  4196. * Gets the `toStringTag` of `value`.
  4197. *
  4198. * @private
  4199. * @param {*} value The value to query.
  4200. * @returns {string} Returns the `toStringTag`.
  4201. */
  4202. var getTag = baseGetTag;
  4203. // Fallback for data views, maps, sets, and weak maps in IE 11,
  4204. // for data views in Edge < 14, and promises in Node.js.
  4205. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  4206. (Map && getTag(new Map) != mapTag) ||
  4207. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  4208. (Set && getTag(new Set) != setTag) ||
  4209. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  4210. getTag = function(value) {
  4211. var result = objectToString.call(value),
  4212. Ctor = result == objectTag ? value.constructor : undefined,
  4213. ctorString = Ctor ? toSource(Ctor) : undefined;
  4214. if (ctorString) {
  4215. switch (ctorString) {
  4216. case dataViewCtorString: return dataViewTag;
  4217. case mapCtorString: return mapTag;
  4218. case promiseCtorString: return promiseTag;
  4219. case setCtorString: return setTag;
  4220. case weakMapCtorString: return weakMapTag;
  4221. }
  4222. }
  4223. return result;
  4224. };
  4225. }
  4226. /**
  4227. * Checks if `path` exists on `object`.
  4228. *
  4229. * @private
  4230. * @param {Object} object The object to query.
  4231. * @param {Array|string} path The path to check.
  4232. * @param {Function} hasFunc The function to check properties.
  4233. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  4234. */
  4235. function hasPath(object, path, hasFunc) {
  4236. path = isKey(path, object) ? [path] : castPath(path);
  4237. var result,
  4238. index = -1,
  4239. length = path.length;
  4240. while (++index < length) {
  4241. var key = toKey(path[index]);
  4242. if (!(result = object != null && hasFunc(object, key))) {
  4243. break;
  4244. }
  4245. object = object[key];
  4246. }
  4247. if (result) {
  4248. return result;
  4249. }
  4250. var length = object ? object.length : 0;
  4251. return !!length && isLength(length) && isIndex(key, length) &&
  4252. (isArray(object) || isArguments(object));
  4253. }
  4254. /**
  4255. * Checks if `value` is a valid array-like index.
  4256. *
  4257. * @private
  4258. * @param {*} value The value to check.
  4259. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  4260. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  4261. */
  4262. function isIndex(value, length) {
  4263. length = length == null ? MAX_SAFE_INTEGER : length;
  4264. return !!length &&
  4265. (typeof value == 'number' || reIsUint.test(value)) &&
  4266. (value > -1 && value % 1 == 0 && value < length);
  4267. }
  4268. /**
  4269. * Checks if `value` is a property name and not a property path.
  4270. *
  4271. * @private
  4272. * @param {*} value The value to check.
  4273. * @param {Object} [object] The object to query keys on.
  4274. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  4275. */
  4276. function isKey(value, object) {
  4277. if (isArray(value)) {
  4278. return false;
  4279. }
  4280. var type = typeof value;
  4281. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  4282. value == null || isSymbol(value)) {
  4283. return true;
  4284. }
  4285. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  4286. (object != null && value in Object(object));
  4287. }
  4288. /**
  4289. * Checks if `value` is suitable for use as unique object key.
  4290. *
  4291. * @private
  4292. * @param {*} value The value to check.
  4293. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  4294. */
  4295. function isKeyable(value) {
  4296. var type = typeof value;
  4297. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  4298. ? (value !== '__proto__')
  4299. : (value === null);
  4300. }
  4301. /**
  4302. * Checks if `func` has its source masked.
  4303. *
  4304. * @private
  4305. * @param {Function} func The function to check.
  4306. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  4307. */
  4308. function isMasked(func) {
  4309. return !!maskSrcKey && (maskSrcKey in func);
  4310. }
  4311. /**
  4312. * Checks if `value` is likely a prototype object.
  4313. *
  4314. * @private
  4315. * @param {*} value The value to check.
  4316. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  4317. */
  4318. function isPrototype(value) {
  4319. var Ctor = value && value.constructor,
  4320. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  4321. return value === proto;
  4322. }
  4323. /**
  4324. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  4325. *
  4326. * @private
  4327. * @param {*} value The value to check.
  4328. * @returns {boolean} Returns `true` if `value` if suitable for strict
  4329. * equality comparisons, else `false`.
  4330. */
  4331. function isStrictComparable(value) {
  4332. return value === value && !isObject(value);
  4333. }
  4334. /**
  4335. * A specialized version of `matchesProperty` for source values suitable
  4336. * for strict equality comparisons, i.e. `===`.
  4337. *
  4338. * @private
  4339. * @param {string} key The key of the property to get.
  4340. * @param {*} srcValue The value to match.
  4341. * @returns {Function} Returns the new spec function.
  4342. */
  4343. function matchesStrictComparable(key, srcValue) {
  4344. return function(object) {
  4345. if (object == null) {
  4346. return false;
  4347. }
  4348. return object[key] === srcValue &&
  4349. (srcValue !== undefined || (key in Object(object)));
  4350. };
  4351. }
  4352. /**
  4353. * Gets the parent value at `path` of `object`.
  4354. *
  4355. * @private
  4356. * @param {Object} object The object to query.
  4357. * @param {Array} path The path to get the parent value of.
  4358. * @returns {*} Returns the parent value.
  4359. */
  4360. function parent(object, path) {
  4361. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  4362. }
  4363. /**
  4364. * Converts `string` to a property path array.
  4365. *
  4366. * @private
  4367. * @param {string} string The string to convert.
  4368. * @returns {Array} Returns the property path array.
  4369. */
  4370. var stringToPath = memoize(function(string) {
  4371. string = toString(string);
  4372. var result = [];
  4373. if (reLeadingDot.test(string)) {
  4374. result.push('');
  4375. }
  4376. string.replace(rePropName, function(match, number, quote, string) {
  4377. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  4378. });
  4379. return result;
  4380. });
  4381. /**
  4382. * Converts `value` to a string key if it's not a string or symbol.
  4383. *
  4384. * @private
  4385. * @param {*} value The value to inspect.
  4386. * @returns {string|symbol} Returns the key.
  4387. */
  4388. function toKey(value) {
  4389. if (typeof value == 'string' || isSymbol(value)) {
  4390. return value;
  4391. }
  4392. var result = (value + '');
  4393. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  4394. }
  4395. /**
  4396. * Converts `func` to its source code.
  4397. *
  4398. * @private
  4399. * @param {Function} func The function to process.
  4400. * @returns {string} Returns the source code.
  4401. */
  4402. function toSource(func) {
  4403. if (func != null) {
  4404. try {
  4405. return funcToString.call(func);
  4406. } catch (e) {}
  4407. try {
  4408. return (func + '');
  4409. } catch (e) {}
  4410. }
  4411. return '';
  4412. }
  4413. /**
  4414. * Gets the last element of `array`.
  4415. *
  4416. * @static
  4417. * @memberOf _
  4418. * @since 0.1.0
  4419. * @category Array
  4420. * @param {Array} array The array to query.
  4421. * @returns {*} Returns the last element of `array`.
  4422. * @example
  4423. *
  4424. * _.last([1, 2, 3]);
  4425. * // => 3
  4426. */
  4427. function last(array) {
  4428. var length = array ? array.length : 0;
  4429. return length ? array[length - 1] : undefined;
  4430. }
  4431. /**
  4432. * Removes all elements from `array` that `predicate` returns truthy for
  4433. * and returns an array of the removed elements. The predicate is invoked
  4434. * with three arguments: (value, index, array).
  4435. *
  4436. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  4437. * to pull elements from an array by value.
  4438. *
  4439. * @static
  4440. * @memberOf _
  4441. * @since 2.0.0
  4442. * @category Array
  4443. * @param {Array} array The array to modify.
  4444. * @param {Function} [predicate=_.identity]
  4445. * The function invoked per iteration.
  4446. * @returns {Array} Returns the new array of removed elements.
  4447. * @example
  4448. *
  4449. * var array = [1, 2, 3, 4];
  4450. * var evens = _.remove(array, function(n) {
  4451. * return n % 2 == 0;
  4452. * });
  4453. *
  4454. * console.log(array);
  4455. * // => [1, 3]
  4456. *
  4457. * console.log(evens);
  4458. * // => [2, 4]
  4459. */
  4460. function remove(array, predicate) {
  4461. var result = [];
  4462. if (!(array && array.length)) {
  4463. return result;
  4464. }
  4465. var index = -1,
  4466. indexes = [],
  4467. length = array.length;
  4468. predicate = baseIteratee(predicate, 3);
  4469. while (++index < length) {
  4470. var value = array[index];
  4471. if (predicate(value, index, array)) {
  4472. result.push(value);
  4473. indexes.push(index);
  4474. }
  4475. }
  4476. basePullAt(array, indexes);
  4477. return result;
  4478. }
  4479. /**
  4480. * Creates a function that memoizes the result of `func`. If `resolver` is
  4481. * provided, it determines the cache key for storing the result based on the
  4482. * arguments provided to the memoized function. By default, the first argument
  4483. * provided to the memoized function is used as the map cache key. The `func`
  4484. * is invoked with the `this` binding of the memoized function.
  4485. *
  4486. * **Note:** The cache is exposed as the `cache` property on the memoized
  4487. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  4488. * constructor with one whose instances implement the
  4489. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  4490. * method interface of `delete`, `get`, `has`, and `set`.
  4491. *
  4492. * @static
  4493. * @memberOf _
  4494. * @since 0.1.0
  4495. * @category Function
  4496. * @param {Function} func The function to have its output memoized.
  4497. * @param {Function} [resolver] The function to resolve the cache key.
  4498. * @returns {Function} Returns the new memoized function.
  4499. * @example
  4500. *
  4501. * var object = { 'a': 1, 'b': 2 };
  4502. * var other = { 'c': 3, 'd': 4 };
  4503. *
  4504. * var values = _.memoize(_.values);
  4505. * values(object);
  4506. * // => [1, 2]
  4507. *
  4508. * values(other);
  4509. * // => [3, 4]
  4510. *
  4511. * object.a = 2;
  4512. * values(object);
  4513. * // => [1, 2]
  4514. *
  4515. * // Modify the result cache.
  4516. * values.cache.set(object, ['a', 'b']);
  4517. * values(object);
  4518. * // => ['a', 'b']
  4519. *
  4520. * // Replace `_.memoize.Cache`.
  4521. * _.memoize.Cache = WeakMap;
  4522. */
  4523. function memoize(func, resolver) {
  4524. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  4525. throw new TypeError(FUNC_ERROR_TEXT);
  4526. }
  4527. var memoized = function() {
  4528. var args = arguments,
  4529. key = resolver ? resolver.apply(this, args) : args[0],
  4530. cache = memoized.cache;
  4531. if (cache.has(key)) {
  4532. return cache.get(key);
  4533. }
  4534. var result = func.apply(this, args);
  4535. memoized.cache = cache.set(key, result);
  4536. return result;
  4537. };
  4538. memoized.cache = new (memoize.Cache || MapCache);
  4539. return memoized;
  4540. }
  4541. // Assign cache to `_.memoize`.
  4542. memoize.Cache = MapCache;
  4543. /**
  4544. * Performs a
  4545. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  4546. * comparison between two values to determine if they are equivalent.
  4547. *
  4548. * @static
  4549. * @memberOf _
  4550. * @since 4.0.0
  4551. * @category Lang
  4552. * @param {*} value The value to compare.
  4553. * @param {*} other The other value to compare.
  4554. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  4555. * @example
  4556. *
  4557. * var object = { 'a': 1 };
  4558. * var other = { 'a': 1 };
  4559. *
  4560. * _.eq(object, object);
  4561. * // => true
  4562. *
  4563. * _.eq(object, other);
  4564. * // => false
  4565. *
  4566. * _.eq('a', 'a');
  4567. * // => true
  4568. *
  4569. * _.eq('a', Object('a'));
  4570. * // => false
  4571. *
  4572. * _.eq(NaN, NaN);
  4573. * // => true
  4574. */
  4575. function eq(value, other) {
  4576. return value === other || (value !== value && other !== other);
  4577. }
  4578. /**
  4579. * Checks if `value` is likely an `arguments` object.
  4580. *
  4581. * @static
  4582. * @memberOf _
  4583. * @since 0.1.0
  4584. * @category Lang
  4585. * @param {*} value The value to check.
  4586. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  4587. * else `false`.
  4588. * @example
  4589. *
  4590. * _.isArguments(function() { return arguments; }());
  4591. * // => true
  4592. *
  4593. * _.isArguments([1, 2, 3]);
  4594. * // => false
  4595. */
  4596. function isArguments(value) {
  4597. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  4598. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  4599. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  4600. }
  4601. /**
  4602. * Checks if `value` is classified as an `Array` object.
  4603. *
  4604. * @static
  4605. * @memberOf _
  4606. * @since 0.1.0
  4607. * @category Lang
  4608. * @param {*} value The value to check.
  4609. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  4610. * @example
  4611. *
  4612. * _.isArray([1, 2, 3]);
  4613. * // => true
  4614. *
  4615. * _.isArray(document.body.children);
  4616. * // => false
  4617. *
  4618. * _.isArray('abc');
  4619. * // => false
  4620. *
  4621. * _.isArray(_.noop);
  4622. * // => false
  4623. */
  4624. var isArray = Array.isArray;
  4625. /**
  4626. * Checks if `value` is array-like. A value is considered array-like if it's
  4627. * not a function and has a `value.length` that's an integer greater than or
  4628. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  4629. *
  4630. * @static
  4631. * @memberOf _
  4632. * @since 4.0.0
  4633. * @category Lang
  4634. * @param {*} value The value to check.
  4635. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  4636. * @example
  4637. *
  4638. * _.isArrayLike([1, 2, 3]);
  4639. * // => true
  4640. *
  4641. * _.isArrayLike(document.body.children);
  4642. * // => true
  4643. *
  4644. * _.isArrayLike('abc');
  4645. * // => true
  4646. *
  4647. * _.isArrayLike(_.noop);
  4648. * // => false
  4649. */
  4650. function isArrayLike(value) {
  4651. return value != null && isLength(value.length) && !isFunction(value);
  4652. }
  4653. /**
  4654. * This method is like `_.isArrayLike` except that it also checks if `value`
  4655. * is an object.
  4656. *
  4657. * @static
  4658. * @memberOf _
  4659. * @since 4.0.0
  4660. * @category Lang
  4661. * @param {*} value The value to check.
  4662. * @returns {boolean} Returns `true` if `value` is an array-like object,
  4663. * else `false`.
  4664. * @example
  4665. *
  4666. * _.isArrayLikeObject([1, 2, 3]);
  4667. * // => true
  4668. *
  4669. * _.isArrayLikeObject(document.body.children);
  4670. * // => true
  4671. *
  4672. * _.isArrayLikeObject('abc');
  4673. * // => false
  4674. *
  4675. * _.isArrayLikeObject(_.noop);
  4676. * // => false
  4677. */
  4678. function isArrayLikeObject(value) {
  4679. return isObjectLike(value) && isArrayLike(value);
  4680. }
  4681. /**
  4682. * Checks if `value` is classified as a `Function` object.
  4683. *
  4684. * @static
  4685. * @memberOf _
  4686. * @since 0.1.0
  4687. * @category Lang
  4688. * @param {*} value The value to check.
  4689. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  4690. * @example
  4691. *
  4692. * _.isFunction(_);
  4693. * // => true
  4694. *
  4695. * _.isFunction(/abc/);
  4696. * // => false
  4697. */
  4698. function isFunction(value) {
  4699. // The use of `Object#toString` avoids issues with the `typeof` operator
  4700. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  4701. var tag = isObject(value) ? objectToString.call(value) : '';
  4702. return tag == funcTag || tag == genTag;
  4703. }
  4704. /**
  4705. * Checks if `value` is a valid array-like length.
  4706. *
  4707. * **Note:** This method is loosely based on
  4708. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  4709. *
  4710. * @static
  4711. * @memberOf _
  4712. * @since 4.0.0
  4713. * @category Lang
  4714. * @param {*} value The value to check.
  4715. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  4716. * @example
  4717. *
  4718. * _.isLength(3);
  4719. * // => true
  4720. *
  4721. * _.isLength(Number.MIN_VALUE);
  4722. * // => false
  4723. *
  4724. * _.isLength(Infinity);
  4725. * // => false
  4726. *
  4727. * _.isLength('3');
  4728. * // => false
  4729. */
  4730. function isLength(value) {
  4731. return typeof value == 'number' &&
  4732. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  4733. }
  4734. /**
  4735. * Checks if `value` is the
  4736. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  4737. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  4738. *
  4739. * @static
  4740. * @memberOf _
  4741. * @since 0.1.0
  4742. * @category Lang
  4743. * @param {*} value The value to check.
  4744. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  4745. * @example
  4746. *
  4747. * _.isObject({});
  4748. * // => true
  4749. *
  4750. * _.isObject([1, 2, 3]);
  4751. * // => true
  4752. *
  4753. * _.isObject(_.noop);
  4754. * // => true
  4755. *
  4756. * _.isObject(null);
  4757. * // => false
  4758. */
  4759. function isObject(value) {
  4760. var type = typeof value;
  4761. return !!value && (type == 'object' || type == 'function');
  4762. }
  4763. /**
  4764. * Checks if `value` is object-like. A value is object-like if it's not `null`
  4765. * and has a `typeof` result of "object".
  4766. *
  4767. * @static
  4768. * @memberOf _
  4769. * @since 4.0.0
  4770. * @category Lang
  4771. * @param {*} value The value to check.
  4772. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  4773. * @example
  4774. *
  4775. * _.isObjectLike({});
  4776. * // => true
  4777. *
  4778. * _.isObjectLike([1, 2, 3]);
  4779. * // => true
  4780. *
  4781. * _.isObjectLike(_.noop);
  4782. * // => false
  4783. *
  4784. * _.isObjectLike(null);
  4785. * // => false
  4786. */
  4787. function isObjectLike(value) {
  4788. return !!value && typeof value == 'object';
  4789. }
  4790. /**
  4791. * Checks if `value` is classified as a `Symbol` primitive or object.
  4792. *
  4793. * @static
  4794. * @memberOf _
  4795. * @since 4.0.0
  4796. * @category Lang
  4797. * @param {*} value The value to check.
  4798. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  4799. * @example
  4800. *
  4801. * _.isSymbol(Symbol.iterator);
  4802. * // => true
  4803. *
  4804. * _.isSymbol('abc');
  4805. * // => false
  4806. */
  4807. function isSymbol(value) {
  4808. return typeof value == 'symbol' ||
  4809. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  4810. }
  4811. /**
  4812. * Checks if `value` is classified as a typed array.
  4813. *
  4814. * @static
  4815. * @memberOf _
  4816. * @since 3.0.0
  4817. * @category Lang
  4818. * @param {*} value The value to check.
  4819. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  4820. * @example
  4821. *
  4822. * _.isTypedArray(new Uint8Array);
  4823. * // => true
  4824. *
  4825. * _.isTypedArray([]);
  4826. * // => false
  4827. */
  4828. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  4829. /**
  4830. * Converts `value` to a string. An empty string is returned for `null`
  4831. * and `undefined` values. The sign of `-0` is preserved.
  4832. *
  4833. * @static
  4834. * @memberOf _
  4835. * @since 4.0.0
  4836. * @category Lang
  4837. * @param {*} value The value to process.
  4838. * @returns {string} Returns the string.
  4839. * @example
  4840. *
  4841. * _.toString(null);
  4842. * // => ''
  4843. *
  4844. * _.toString(-0);
  4845. * // => '-0'
  4846. *
  4847. * _.toString([1, 2, 3]);
  4848. * // => '1,2,3'
  4849. */
  4850. function toString(value) {
  4851. return value == null ? '' : baseToString(value);
  4852. }
  4853. /**
  4854. * Gets the value at `path` of `object`. If the resolved value is
  4855. * `undefined`, the `defaultValue` is returned in its place.
  4856. *
  4857. * @static
  4858. * @memberOf _
  4859. * @since 3.7.0
  4860. * @category Object
  4861. * @param {Object} object The object to query.
  4862. * @param {Array|string} path The path of the property to get.
  4863. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  4864. * @returns {*} Returns the resolved value.
  4865. * @example
  4866. *
  4867. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  4868. *
  4869. * _.get(object, 'a[0].b.c');
  4870. * // => 3
  4871. *
  4872. * _.get(object, ['a', '0', 'b', 'c']);
  4873. * // => 3
  4874. *
  4875. * _.get(object, 'a.b.c', 'default');
  4876. * // => 'default'
  4877. */
  4878. function get(object, path, defaultValue) {
  4879. var result = object == null ? undefined : baseGet(object, path);
  4880. return result === undefined ? defaultValue : result;
  4881. }
  4882. /**
  4883. * Checks if `path` is a direct or inherited property of `object`.
  4884. *
  4885. * @static
  4886. * @memberOf _
  4887. * @since 4.0.0
  4888. * @category Object
  4889. * @param {Object} object The object to query.
  4890. * @param {Array|string} path The path to check.
  4891. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  4892. * @example
  4893. *
  4894. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  4895. *
  4896. * _.hasIn(object, 'a');
  4897. * // => true
  4898. *
  4899. * _.hasIn(object, 'a.b');
  4900. * // => true
  4901. *
  4902. * _.hasIn(object, ['a', 'b']);
  4903. * // => true
  4904. *
  4905. * _.hasIn(object, 'b');
  4906. * // => false
  4907. */
  4908. function hasIn(object, path) {
  4909. return object != null && hasPath(object, path, baseHasIn);
  4910. }
  4911. /**
  4912. * Creates an array of the own enumerable property names of `object`.
  4913. *
  4914. * **Note:** Non-object values are coerced to objects. See the
  4915. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  4916. * for more details.
  4917. *
  4918. * @static
  4919. * @since 0.1.0
  4920. * @memberOf _
  4921. * @category Object
  4922. * @param {Object} object The object to query.
  4923. * @returns {Array} Returns the array of property names.
  4924. * @example
  4925. *
  4926. * function Foo() {
  4927. * this.a = 1;
  4928. * this.b = 2;
  4929. * }
  4930. *
  4931. * Foo.prototype.c = 3;
  4932. *
  4933. * _.keys(new Foo);
  4934. * // => ['a', 'b'] (iteration order is not guaranteed)
  4935. *
  4936. * _.keys('hi');
  4937. * // => ['0', '1']
  4938. */
  4939. function keys(object) {
  4940. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  4941. }
  4942. /**
  4943. * This method returns the first argument it receives.
  4944. *
  4945. * @static
  4946. * @since 0.1.0
  4947. * @memberOf _
  4948. * @category Util
  4949. * @param {*} value Any value.
  4950. * @returns {*} Returns `value`.
  4951. * @example
  4952. *
  4953. * var object = { 'a': 1 };
  4954. *
  4955. * console.log(_.identity(object) === object);
  4956. * // => true
  4957. */
  4958. function identity(value) {
  4959. return value;
  4960. }
  4961. /**
  4962. * Creates a function that returns the value at `path` of a given object.
  4963. *
  4964. * @static
  4965. * @memberOf _
  4966. * @since 2.4.0
  4967. * @category Util
  4968. * @param {Array|string} path The path of the property to get.
  4969. * @returns {Function} Returns the new accessor function.
  4970. * @example
  4971. *
  4972. * var objects = [
  4973. * { 'a': { 'b': 2 } },
  4974. * { 'a': { 'b': 1 } }
  4975. * ];
  4976. *
  4977. * _.map(objects, _.property('a.b'));
  4978. * // => [2, 1]
  4979. *
  4980. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  4981. * // => [1, 2]
  4982. */
  4983. function property(path) {
  4984. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  4985. }
  4986. module.exports = remove;
  4987. /***/ }),
  4988. /***/ "./node_modules/process/browser.js":
  4989. /*!*****************************************!*\
  4990. !*** ./node_modules/process/browser.js ***!
  4991. \*****************************************/
  4992. /***/ ((module) => {
  4993. // shim for using process in browser
  4994. var process = module.exports = {};
  4995. // cached from whatever global is present so that test runners that stub it
  4996. // don't break things. But we need to wrap it in a try catch in case it is
  4997. // wrapped in strict mode code which doesn't define any globals. It's inside a
  4998. // function because try/catches deoptimize in certain engines.
  4999. var cachedSetTimeout;
  5000. var cachedClearTimeout;
  5001. function defaultSetTimout() {
  5002. throw new Error('setTimeout has not been defined');
  5003. }
  5004. function defaultClearTimeout () {
  5005. throw new Error('clearTimeout has not been defined');
  5006. }
  5007. (function () {
  5008. try {
  5009. if (typeof setTimeout === 'function') {
  5010. cachedSetTimeout = setTimeout;
  5011. } else {
  5012. cachedSetTimeout = defaultSetTimout;
  5013. }
  5014. } catch (e) {
  5015. cachedSetTimeout = defaultSetTimout;
  5016. }
  5017. try {
  5018. if (typeof clearTimeout === 'function') {
  5019. cachedClearTimeout = clearTimeout;
  5020. } else {
  5021. cachedClearTimeout = defaultClearTimeout;
  5022. }
  5023. } catch (e) {
  5024. cachedClearTimeout = defaultClearTimeout;
  5025. }
  5026. } ())
  5027. function runTimeout(fun) {
  5028. if (cachedSetTimeout === setTimeout) {
  5029. //normal enviroments in sane situations
  5030. return setTimeout(fun, 0);
  5031. }
  5032. // if setTimeout wasn't available but was latter defined
  5033. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  5034. cachedSetTimeout = setTimeout;
  5035. return setTimeout(fun, 0);
  5036. }
  5037. try {
  5038. // when when somebody has screwed with setTimeout but no I.E. maddness
  5039. return cachedSetTimeout(fun, 0);
  5040. } catch(e){
  5041. try {
  5042. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  5043. return cachedSetTimeout.call(null, fun, 0);
  5044. } catch(e){
  5045. // 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
  5046. return cachedSetTimeout.call(this, fun, 0);
  5047. }
  5048. }
  5049. }
  5050. function runClearTimeout(marker) {
  5051. if (cachedClearTimeout === clearTimeout) {
  5052. //normal enviroments in sane situations
  5053. return clearTimeout(marker);
  5054. }
  5055. // if clearTimeout wasn't available but was latter defined
  5056. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  5057. cachedClearTimeout = clearTimeout;
  5058. return clearTimeout(marker);
  5059. }
  5060. try {
  5061. // when when somebody has screwed with setTimeout but no I.E. maddness
  5062. return cachedClearTimeout(marker);
  5063. } catch (e){
  5064. try {
  5065. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  5066. return cachedClearTimeout.call(null, marker);
  5067. } catch (e){
  5068. // 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.
  5069. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  5070. return cachedClearTimeout.call(this, marker);
  5071. }
  5072. }
  5073. }
  5074. var queue = [];
  5075. var draining = false;
  5076. var currentQueue;
  5077. var queueIndex = -1;
  5078. function cleanUpNextTick() {
  5079. if (!draining || !currentQueue) {
  5080. return;
  5081. }
  5082. draining = false;
  5083. if (currentQueue.length) {
  5084. queue = currentQueue.concat(queue);
  5085. } else {
  5086. queueIndex = -1;
  5087. }
  5088. if (queue.length) {
  5089. drainQueue();
  5090. }
  5091. }
  5092. function drainQueue() {
  5093. if (draining) {
  5094. return;
  5095. }
  5096. var timeout = runTimeout(cleanUpNextTick);
  5097. draining = true;
  5098. var len = queue.length;
  5099. while(len) {
  5100. currentQueue = queue;
  5101. queue = [];
  5102. while (++queueIndex < len) {
  5103. if (currentQueue) {
  5104. currentQueue[queueIndex].run();
  5105. }
  5106. }
  5107. queueIndex = -1;
  5108. len = queue.length;
  5109. }
  5110. currentQueue = null;
  5111. draining = false;
  5112. runClearTimeout(timeout);
  5113. }
  5114. process.nextTick = function (fun) {
  5115. var args = new Array(arguments.length - 1);
  5116. if (arguments.length > 1) {
  5117. for (var i = 1; i < arguments.length; i++) {
  5118. args[i - 1] = arguments[i];
  5119. }
  5120. }
  5121. queue.push(new Item(fun, args));
  5122. if (queue.length === 1 && !draining) {
  5123. runTimeout(drainQueue);
  5124. }
  5125. };
  5126. // v8 likes predictible objects
  5127. function Item(fun, array) {
  5128. this.fun = fun;
  5129. this.array = array;
  5130. }
  5131. Item.prototype.run = function () {
  5132. this.fun.apply(null, this.array);
  5133. };
  5134. process.title = 'browser';
  5135. process.browser = true;
  5136. process.env = {};
  5137. process.argv = [];
  5138. process.version = ''; // empty string to avoid regexp issues
  5139. process.versions = {};
  5140. function noop() {}
  5141. process.on = noop;
  5142. process.addListener = noop;
  5143. process.once = noop;
  5144. process.off = noop;
  5145. process.removeListener = noop;
  5146. process.removeAllListeners = noop;
  5147. process.emit = noop;
  5148. process.prependListener = noop;
  5149. process.prependOnceListener = noop;
  5150. process.listeners = function (name) { return [] }
  5151. process.binding = function (name) {
  5152. throw new Error('process.binding is not supported');
  5153. };
  5154. process.cwd = function () { return '/' };
  5155. process.chdir = function (dir) {
  5156. throw new Error('process.chdir is not supported');
  5157. };
  5158. process.umask = function() { return 0; };
  5159. /***/ }),
  5160. /***/ "./node_modules/riot/riot.esm.js":
  5161. /*!***************************************!*\
  5162. !*** ./node_modules/riot/riot.esm.js ***!
  5163. \***************************************/
  5164. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  5165. "use strict";
  5166. __webpack_require__.r(__webpack_exports__);
  5167. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  5168. /* harmony export */ "__": () => (/* binding */ __),
  5169. /* harmony export */ "component": () => (/* binding */ component),
  5170. /* harmony export */ "install": () => (/* binding */ install),
  5171. /* harmony export */ "mount": () => (/* binding */ mount),
  5172. /* harmony export */ "pure": () => (/* binding */ pure),
  5173. /* harmony export */ "register": () => (/* binding */ register),
  5174. /* harmony export */ "uninstall": () => (/* binding */ uninstall),
  5175. /* harmony export */ "unmount": () => (/* binding */ unmount),
  5176. /* harmony export */ "unregister": () => (/* binding */ unregister),
  5177. /* harmony export */ "version": () => (/* binding */ version),
  5178. /* harmony export */ "withTypes": () => (/* binding */ withTypes)
  5179. /* harmony export */ });
  5180. /* Riot v6.0.1, @license MIT */
  5181. /**
  5182. * Convert a string from camel case to dash-case
  5183. * @param {string} string - probably a component tag name
  5184. * @returns {string} component name normalized
  5185. */
  5186. function camelToDashCase(string) {
  5187. return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  5188. }
  5189. /**
  5190. * Convert a string containing dashes to camel case
  5191. * @param {string} string - input string
  5192. * @returns {string} my-string -> myString
  5193. */
  5194. function dashToCamelCase(string) {
  5195. return string.replace(/-(\w)/g, (_, c) => c.toUpperCase());
  5196. }
  5197. /**
  5198. * Get all the element attributes as object
  5199. * @param {HTMLElement} element - DOM node we want to parse
  5200. * @returns {Object} all the attributes found as a key value pairs
  5201. */
  5202. function DOMattributesToObject(element) {
  5203. return Array.from(element.attributes).reduce((acc, attribute) => {
  5204. acc[dashToCamelCase(attribute.name)] = attribute.value;
  5205. return acc;
  5206. }, {});
  5207. }
  5208. /**
  5209. * Move all the child nodes from a source tag to another
  5210. * @param {HTMLElement} source - source node
  5211. * @param {HTMLElement} target - target node
  5212. * @returns {undefined} it's a void method ¯\_()_/¯
  5213. */
  5214. // Ignore this helper because it's needed only for svg tags
  5215. function moveChildren(source, target) {
  5216. if (source.firstChild) {
  5217. target.appendChild(source.firstChild);
  5218. moveChildren(source, target);
  5219. }
  5220. }
  5221. /**
  5222. * Remove the child nodes from any DOM node
  5223. * @param {HTMLElement} node - target node
  5224. * @returns {undefined}
  5225. */
  5226. function cleanNode(node) {
  5227. clearChildren(node.childNodes);
  5228. }
  5229. /**
  5230. * Clear multiple children in a node
  5231. * @param {HTMLElement[]} children - direct children nodes
  5232. * @returns {undefined}
  5233. */
  5234. function clearChildren(children) {
  5235. Array.from(children).forEach(removeChild);
  5236. }
  5237. /**
  5238. * Remove a node
  5239. * @param {HTMLElement}node - node to remove
  5240. * @returns {undefined}
  5241. */
  5242. const removeChild = node => node && node.parentNode && node.parentNode.removeChild(node);
  5243. /**
  5244. * Insert before a node
  5245. * @param {HTMLElement} newNode - node to insert
  5246. * @param {HTMLElement} refNode - ref child
  5247. * @returns {undefined}
  5248. */
  5249. const insertBefore = (newNode, refNode) => refNode && refNode.parentNode && refNode.parentNode.insertBefore(newNode, refNode);
  5250. /**
  5251. * Replace a node
  5252. * @param {HTMLElement} newNode - new node to add to the DOM
  5253. * @param {HTMLElement} replaced - node to replace
  5254. * @returns {undefined}
  5255. */
  5256. const replaceChild = (newNode, replaced) => replaced && replaced.parentNode && replaced.parentNode.replaceChild(newNode, replaced);
  5257. // Riot.js constants that can be used accross more modules
  5258. const COMPONENTS_IMPLEMENTATION_MAP$1 = new Map(),
  5259. DOM_COMPONENT_INSTANCE_PROPERTY$1 = Symbol('riot-component'),
  5260. PLUGINS_SET$1 = new Set(),
  5261. IS_DIRECTIVE = 'is',
  5262. VALUE_ATTRIBUTE = 'value',
  5263. MOUNT_METHOD_KEY = 'mount',
  5264. UPDATE_METHOD_KEY = 'update',
  5265. UNMOUNT_METHOD_KEY = 'unmount',
  5266. SHOULD_UPDATE_KEY = 'shouldUpdate',
  5267. ON_BEFORE_MOUNT_KEY = 'onBeforeMount',
  5268. ON_MOUNTED_KEY = 'onMounted',
  5269. ON_BEFORE_UPDATE_KEY = 'onBeforeUpdate',
  5270. ON_UPDATED_KEY = 'onUpdated',
  5271. ON_BEFORE_UNMOUNT_KEY = 'onBeforeUnmount',
  5272. ON_UNMOUNTED_KEY = 'onUnmounted',
  5273. PROPS_KEY = 'props',
  5274. STATE_KEY = 'state',
  5275. SLOTS_KEY = 'slots',
  5276. ROOT_KEY = 'root',
  5277. IS_PURE_SYMBOL = Symbol('pure'),
  5278. IS_COMPONENT_UPDATING = Symbol('is_updating'),
  5279. PARENT_KEY_SYMBOL = Symbol('parent'),
  5280. ATTRIBUTES_KEY_SYMBOL = Symbol('attributes'),
  5281. TEMPLATE_KEY_SYMBOL = Symbol('template');
  5282. var globals = /*#__PURE__*/Object.freeze({
  5283. __proto__: null,
  5284. COMPONENTS_IMPLEMENTATION_MAP: COMPONENTS_IMPLEMENTATION_MAP$1,
  5285. DOM_COMPONENT_INSTANCE_PROPERTY: DOM_COMPONENT_INSTANCE_PROPERTY$1,
  5286. PLUGINS_SET: PLUGINS_SET$1,
  5287. IS_DIRECTIVE: IS_DIRECTIVE,
  5288. VALUE_ATTRIBUTE: VALUE_ATTRIBUTE,
  5289. MOUNT_METHOD_KEY: MOUNT_METHOD_KEY,
  5290. UPDATE_METHOD_KEY: UPDATE_METHOD_KEY,
  5291. UNMOUNT_METHOD_KEY: UNMOUNT_METHOD_KEY,
  5292. SHOULD_UPDATE_KEY: SHOULD_UPDATE_KEY,
  5293. ON_BEFORE_MOUNT_KEY: ON_BEFORE_MOUNT_KEY,
  5294. ON_MOUNTED_KEY: ON_MOUNTED_KEY,
  5295. ON_BEFORE_UPDATE_KEY: ON_BEFORE_UPDATE_KEY,
  5296. ON_UPDATED_KEY: ON_UPDATED_KEY,
  5297. ON_BEFORE_UNMOUNT_KEY: ON_BEFORE_UNMOUNT_KEY,
  5298. ON_UNMOUNTED_KEY: ON_UNMOUNTED_KEY,
  5299. PROPS_KEY: PROPS_KEY,
  5300. STATE_KEY: STATE_KEY,
  5301. SLOTS_KEY: SLOTS_KEY,
  5302. ROOT_KEY: ROOT_KEY,
  5303. IS_PURE_SYMBOL: IS_PURE_SYMBOL,
  5304. IS_COMPONENT_UPDATING: IS_COMPONENT_UPDATING,
  5305. PARENT_KEY_SYMBOL: PARENT_KEY_SYMBOL,
  5306. ATTRIBUTES_KEY_SYMBOL: ATTRIBUTES_KEY_SYMBOL,
  5307. TEMPLATE_KEY_SYMBOL: TEMPLATE_KEY_SYMBOL
  5308. });
  5309. const EACH = 0;
  5310. const IF = 1;
  5311. const SIMPLE = 2;
  5312. const TAG = 3;
  5313. const SLOT = 4;
  5314. var bindingTypes = {
  5315. EACH,
  5316. IF,
  5317. SIMPLE,
  5318. TAG,
  5319. SLOT
  5320. };
  5321. const ATTRIBUTE = 0;
  5322. const EVENT = 1;
  5323. const TEXT = 2;
  5324. const VALUE = 3;
  5325. var expressionTypes = {
  5326. ATTRIBUTE,
  5327. EVENT,
  5328. TEXT,
  5329. VALUE
  5330. };
  5331. const HEAD_SYMBOL = Symbol('head');
  5332. const TAIL_SYMBOL = Symbol('tail');
  5333. /**
  5334. * Create the <template> fragments text nodes
  5335. * @return {Object} {{head: Text, tail: Text}}
  5336. */
  5337. function createHeadTailPlaceholders() {
  5338. const head = document.createTextNode('');
  5339. const tail = document.createTextNode('');
  5340. head[HEAD_SYMBOL] = true;
  5341. tail[TAIL_SYMBOL] = true;
  5342. return {
  5343. head,
  5344. tail
  5345. };
  5346. }
  5347. /**
  5348. * Create the template meta object in case of <template> fragments
  5349. * @param {TemplateChunk} componentTemplate - template chunk object
  5350. * @returns {Object} the meta property that will be passed to the mount function of the TemplateChunk
  5351. */
  5352. function createTemplateMeta(componentTemplate) {
  5353. const fragment = componentTemplate.dom.cloneNode(true);
  5354. const {
  5355. head,
  5356. tail
  5357. } = createHeadTailPlaceholders();
  5358. return {
  5359. avoidDOMInjection: true,
  5360. fragment,
  5361. head,
  5362. tail,
  5363. children: [head, ...Array.from(fragment.childNodes), tail]
  5364. };
  5365. }
  5366. /**
  5367. * Helper function to set an immutable property
  5368. * @param {Object} source - object where the new property will be set
  5369. * @param {string} key - object key where the new property will be stored
  5370. * @param {*} value - value of the new property
  5371. * @param {Object} options - set the propery overriding the default options
  5372. * @returns {Object} - the original object modified
  5373. */
  5374. function defineProperty(source, key, value, options) {
  5375. if (options === void 0) {
  5376. options = {};
  5377. }
  5378. /* eslint-disable fp/no-mutating-methods */
  5379. Object.defineProperty(source, key, Object.assign({
  5380. value,
  5381. enumerable: false,
  5382. writable: false,
  5383. configurable: true
  5384. }, options));
  5385. /* eslint-enable fp/no-mutating-methods */
  5386. return source;
  5387. }
  5388. /**
  5389. * Define multiple properties on a target object
  5390. * @param {Object} source - object where the new properties will be set
  5391. * @param {Object} properties - object containing as key pair the key + value properties
  5392. * @param {Object} options - set the propery overriding the default options
  5393. * @returns {Object} the original object modified
  5394. */
  5395. function defineProperties(source, properties, options) {
  5396. Object.entries(properties).forEach(_ref => {
  5397. let [key, value] = _ref;
  5398. defineProperty(source, key, value, options);
  5399. });
  5400. return source;
  5401. }
  5402. /**
  5403. * Define default properties if they don't exist on the source object
  5404. * @param {Object} source - object that will receive the default properties
  5405. * @param {Object} defaults - object containing additional optional keys
  5406. * @returns {Object} the original object received enhanced
  5407. */
  5408. function defineDefaults(source, defaults) {
  5409. Object.entries(defaults).forEach(_ref2 => {
  5410. let [key, value] = _ref2;
  5411. if (!source[key]) source[key] = value;
  5412. });
  5413. return source;
  5414. }
  5415. /**
  5416. * Get the current <template> fragment children located in between the head and tail comments
  5417. * @param {Comment} head - head comment node
  5418. * @param {Comment} tail - tail comment node
  5419. * @return {Array[]} children list of the nodes found in this template fragment
  5420. */
  5421. function getFragmentChildren(_ref) {
  5422. let {
  5423. head,
  5424. tail
  5425. } = _ref;
  5426. const nodes = walkNodes([head], head.nextSibling, n => n === tail, false);
  5427. nodes.push(tail);
  5428. return nodes;
  5429. }
  5430. /**
  5431. * Recursive function to walk all the <template> children nodes
  5432. * @param {Array[]} children - children nodes collection
  5433. * @param {ChildNode} node - current node
  5434. * @param {Function} check - exit function check
  5435. * @param {boolean} isFilterActive - filter flag to skip nodes managed by other bindings
  5436. * @returns {Array[]} children list of the nodes found in this template fragment
  5437. */
  5438. function walkNodes(children, node, check, isFilterActive) {
  5439. const {
  5440. nextSibling
  5441. } = node; // filter tail and head nodes together with all the nodes in between
  5442. // this is needed only to fix a really ugly edge case https://github.com/riot/riot/issues/2892
  5443. if (!isFilterActive && !node[HEAD_SYMBOL] && !node[TAIL_SYMBOL]) {
  5444. children.push(node);
  5445. }
  5446. if (!nextSibling || check(node)) return children;
  5447. return walkNodes(children, nextSibling, check, // activate the filters to skip nodes between <template> fragments that will be managed by other bindings
  5448. isFilterActive && !node[TAIL_SYMBOL] || nextSibling[HEAD_SYMBOL]);
  5449. }
  5450. /**
  5451. * Quick type checking
  5452. * @param {*} element - anything
  5453. * @param {string} type - type definition
  5454. * @returns {boolean} true if the type corresponds
  5455. */
  5456. function checkType(element, type) {
  5457. return typeof element === type;
  5458. }
  5459. /**
  5460. * Check if an element is part of an svg
  5461. * @param {HTMLElement} el - element to check
  5462. * @returns {boolean} true if we are in an svg context
  5463. */
  5464. function isSvg(el) {
  5465. const owner = el.ownerSVGElement;
  5466. return !!owner || owner === null;
  5467. }
  5468. /**
  5469. * Check if an element is a template tag
  5470. * @param {HTMLElement} el - element to check
  5471. * @returns {boolean} true if it's a <template>
  5472. */
  5473. function isTemplate(el) {
  5474. return el.tagName.toLowerCase() === 'template';
  5475. }
  5476. /**
  5477. * Check that will be passed if its argument is a function
  5478. * @param {*} value - value to check
  5479. * @returns {boolean} - true if the value is a function
  5480. */
  5481. function isFunction(value) {
  5482. return checkType(value, 'function');
  5483. }
  5484. /**
  5485. * Check if a value is a Boolean
  5486. * @param {*} value - anything
  5487. * @returns {boolean} true only for the value is a boolean
  5488. */
  5489. function isBoolean(value) {
  5490. return checkType(value, 'boolean');
  5491. }
  5492. /**
  5493. * Check if a value is an Object
  5494. * @param {*} value - anything
  5495. * @returns {boolean} true only for the value is an object
  5496. */
  5497. function isObject(value) {
  5498. return !isNil(value) && value.constructor === Object;
  5499. }
  5500. /**
  5501. * Check if a value is null or undefined
  5502. * @param {*} value - anything
  5503. * @returns {boolean} true only for the 'undefined' and 'null' types
  5504. */
  5505. function isNil(value) {
  5506. return value === null || value === undefined;
  5507. }
  5508. /**
  5509. * ISC License
  5510. *
  5511. * Copyright (c) 2020, Andrea Giammarchi, @WebReflection
  5512. *
  5513. * Permission to use, copy, modify, and/or distribute this software for any
  5514. * purpose with or without fee is hereby granted, provided that the above
  5515. * copyright notice and this permission notice appear in all copies.
  5516. *
  5517. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  5518. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  5519. * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  5520. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  5521. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  5522. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  5523. * PERFORMANCE OF THIS SOFTWARE.
  5524. */
  5525. // fork of https://github.com/WebReflection/udomdiff version 1.1.0
  5526. // due to https://github.com/WebReflection/udomdiff/pull/2
  5527. /* eslint-disable */
  5528. /**
  5529. * @param {Node[]} a The list of current/live children
  5530. * @param {Node[]} b The list of future children
  5531. * @param {(entry: Node, action: number) => Node} get
  5532. * The callback invoked per each entry related DOM operation.
  5533. * @param {Node} [before] The optional node used as anchor to insert before.
  5534. * @returns {Node[]} The same list of future children.
  5535. */
  5536. var udomdiff = ((a, b, get, before) => {
  5537. const bLength = b.length;
  5538. let aEnd = a.length;
  5539. let bEnd = bLength;
  5540. let aStart = 0;
  5541. let bStart = 0;
  5542. let map = null;
  5543. while (aStart < aEnd || bStart < bEnd) {
  5544. // append head, tail, or nodes in between: fast path
  5545. if (aEnd === aStart) {
  5546. // we could be in a situation where the rest of nodes that
  5547. // need to be added are not at the end, and in such case
  5548. // the node to `insertBefore`, if the index is more than 0
  5549. // must be retrieved, otherwise it's gonna be the first item.
  5550. const node = bEnd < bLength ? bStart ? get(b[bStart - 1], -0).nextSibling : get(b[bEnd - bStart], 0) : before;
  5551. while (bStart < bEnd) insertBefore(get(b[bStart++], 1), node);
  5552. } // remove head or tail: fast path
  5553. else if (bEnd === bStart) {
  5554. while (aStart < aEnd) {
  5555. // remove the node only if it's unknown or not live
  5556. if (!map || !map.has(a[aStart])) removeChild(get(a[aStart], -1));
  5557. aStart++;
  5558. }
  5559. } // same node: fast path
  5560. else if (a[aStart] === b[bStart]) {
  5561. aStart++;
  5562. bStart++;
  5563. } // same tail: fast path
  5564. else if (a[aEnd - 1] === b[bEnd - 1]) {
  5565. aEnd--;
  5566. bEnd--;
  5567. } // The once here single last swap "fast path" has been removed in v1.1.0
  5568. // https://github.com/WebReflection/udomdiff/blob/single-final-swap/esm/index.js#L69-L85
  5569. // reverse swap: also fast path
  5570. else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
  5571. // this is a "shrink" operation that could happen in these cases:
  5572. // [1, 2, 3, 4, 5]
  5573. // [1, 4, 3, 2, 5]
  5574. // or asymmetric too
  5575. // [1, 2, 3, 4, 5]
  5576. // [1, 2, 3, 5, 6, 4]
  5577. const node = get(a[--aEnd], -1).nextSibling;
  5578. insertBefore(get(b[bStart++], 1), get(a[aStart++], -1).nextSibling);
  5579. insertBefore(get(b[--bEnd], 1), node); // mark the future index as identical (yeah, it's dirty, but cheap 👍)
  5580. // The main reason to do this, is that when a[aEnd] will be reached,
  5581. // the loop will likely be on the fast path, as identical to b[bEnd].
  5582. // In the best case scenario, the next loop will skip the tail,
  5583. // but in the worst one, this node will be considered as already
  5584. // processed, bailing out pretty quickly from the map index check
  5585. a[aEnd] = b[bEnd];
  5586. } // map based fallback, "slow" path
  5587. else {
  5588. // the map requires an O(bEnd - bStart) operation once
  5589. // to store all future nodes indexes for later purposes.
  5590. // In the worst case scenario, this is a full O(N) cost,
  5591. // and such scenario happens at least when all nodes are different,
  5592. // but also if both first and last items of the lists are different
  5593. if (!map) {
  5594. map = new Map();
  5595. let i = bStart;
  5596. while (i < bEnd) map.set(b[i], i++);
  5597. } // if it's a future node, hence it needs some handling
  5598. if (map.has(a[aStart])) {
  5599. // grab the index of such node, 'cause it might have been processed
  5600. const index = map.get(a[aStart]); // if it's not already processed, look on demand for the next LCS
  5601. if (bStart < index && index < bEnd) {
  5602. let i = aStart; // counts the amount of nodes that are the same in the future
  5603. let sequence = 1;
  5604. while (++i < aEnd && i < bEnd && map.get(a[i]) === index + sequence) sequence++; // effort decision here: if the sequence is longer than replaces
  5605. // needed to reach such sequence, which would brings again this loop
  5606. // to the fast path, prepend the difference before a sequence,
  5607. // and move only the future list index forward, so that aStart
  5608. // and bStart will be aligned again, hence on the fast path.
  5609. // An example considering aStart and bStart are both 0:
  5610. // a: [1, 2, 3, 4]
  5611. // b: [7, 1, 2, 3, 6]
  5612. // this would place 7 before 1 and, from that time on, 1, 2, and 3
  5613. // will be processed at zero cost
  5614. if (sequence > index - bStart) {
  5615. const node = get(a[aStart], 0);
  5616. while (bStart < index) insertBefore(get(b[bStart++], 1), node);
  5617. } // if the effort wasn't good enough, fallback to a replace,
  5618. // moving both source and target indexes forward, hoping that some
  5619. // similar node will be found later on, to go back to the fast path
  5620. else {
  5621. replaceChild(get(b[bStart++], 1), get(a[aStart++], -1));
  5622. }
  5623. } // otherwise move the source forward, 'cause there's nothing to do
  5624. else aStart++;
  5625. } // this node has no meaning in the future list, so it's more than safe
  5626. // to remove it, and check the next live node out instead, meaning
  5627. // that only the live list index should be forwarded
  5628. else removeChild(get(a[aStart++], -1));
  5629. }
  5630. }
  5631. return b;
  5632. });
  5633. const UNMOUNT_SCOPE = Symbol('unmount');
  5634. const EachBinding = {
  5635. // dynamic binding properties
  5636. // childrenMap: null,
  5637. // node: null,
  5638. // root: null,
  5639. // condition: null,
  5640. // evaluate: null,
  5641. // template: null,
  5642. // isTemplateTag: false,
  5643. nodes: [],
  5644. // getKey: null,
  5645. // indexName: null,
  5646. // itemName: null,
  5647. // afterPlaceholder: null,
  5648. // placeholder: null,
  5649. // API methods
  5650. mount(scope, parentScope) {
  5651. return this.update(scope, parentScope);
  5652. },
  5653. update(scope, parentScope) {
  5654. const {
  5655. placeholder,
  5656. nodes,
  5657. childrenMap
  5658. } = this;
  5659. const collection = scope === UNMOUNT_SCOPE ? null : this.evaluate(scope);
  5660. const items = collection ? Array.from(collection) : []; // prepare the diffing
  5661. const {
  5662. newChildrenMap,
  5663. batches,
  5664. futureNodes
  5665. } = createPatch(items, scope, parentScope, this); // patch the DOM only if there are new nodes
  5666. udomdiff(nodes, futureNodes, patch(Array.from(childrenMap.values()), parentScope), placeholder); // trigger the mounts and the updates
  5667. batches.forEach(fn => fn()); // update the children map
  5668. this.childrenMap = newChildrenMap;
  5669. this.nodes = futureNodes; // make sure that the loop edge nodes are marked
  5670. markEdgeNodes(this.nodes);
  5671. return this;
  5672. },
  5673. unmount(scope, parentScope) {
  5674. this.update(UNMOUNT_SCOPE, parentScope);
  5675. return this;
  5676. }
  5677. };
  5678. /**
  5679. * Patch the DOM while diffing
  5680. * @param {any[]} redundant - list of all the children (template, nodes, context) added via each
  5681. * @param {*} parentScope - scope of the parent template
  5682. * @returns {Function} patch function used by domdiff
  5683. */
  5684. function patch(redundant, parentScope) {
  5685. return (item, info) => {
  5686. if (info < 0) {
  5687. // get the last element added to the childrenMap saved previously
  5688. const element = redundant[redundant.length - 1];
  5689. if (element) {
  5690. // get the nodes and the template in stored in the last child of the childrenMap
  5691. const {
  5692. template,
  5693. nodes,
  5694. context
  5695. } = element; // remove the last node (notice <template> tags might have more children nodes)
  5696. nodes.pop(); // notice that we pass null as last argument because
  5697. // the root node and its children will be removed by domdiff
  5698. if (!nodes.length) {
  5699. // we have cleared all the children nodes and we can unmount this template
  5700. redundant.pop();
  5701. template.unmount(context, parentScope, null);
  5702. }
  5703. }
  5704. }
  5705. return item;
  5706. };
  5707. }
  5708. /**
  5709. * Check whether a template must be filtered from a loop
  5710. * @param {Function} condition - filter function
  5711. * @param {Object} context - argument passed to the filter function
  5712. * @returns {boolean} true if this item should be skipped
  5713. */
  5714. function mustFilterItem(condition, context) {
  5715. return condition ? !condition(context) : false;
  5716. }
  5717. /**
  5718. * Extend the scope of the looped template
  5719. * @param {Object} scope - current template scope
  5720. * @param {Object} options - options
  5721. * @param {string} options.itemName - key to identify the looped item in the new context
  5722. * @param {string} options.indexName - key to identify the index of the looped item
  5723. * @param {number} options.index - current index
  5724. * @param {*} options.item - collection item looped
  5725. * @returns {Object} enhanced scope object
  5726. */
  5727. function extendScope(scope, _ref) {
  5728. let {
  5729. itemName,
  5730. indexName,
  5731. index,
  5732. item
  5733. } = _ref;
  5734. defineProperty(scope, itemName, item);
  5735. if (indexName) defineProperty(scope, indexName, index);
  5736. return scope;
  5737. }
  5738. /**
  5739. * Mark the first and last nodes in order to ignore them in case we need to retrieve the <template> fragment nodes
  5740. * @param {Array[]} nodes - each binding nodes list
  5741. * @returns {undefined} void function
  5742. */
  5743. function markEdgeNodes(nodes) {
  5744. const first = nodes[0];
  5745. const last = nodes[nodes.length - 1];
  5746. if (first) first[HEAD_SYMBOL] = true;
  5747. if (last) last[TAIL_SYMBOL] = true;
  5748. }
  5749. /**
  5750. * Loop the current template items
  5751. * @param {Array} items - expression collection value
  5752. * @param {*} scope - template scope
  5753. * @param {*} parentScope - scope of the parent template
  5754. * @param {EachBinding} binding - each binding object instance
  5755. * @returns {Object} data
  5756. * @returns {Map} data.newChildrenMap - a Map containing the new children template structure
  5757. * @returns {Array} data.batches - array containing the template lifecycle functions to trigger
  5758. * @returns {Array} data.futureNodes - array containing the nodes we need to diff
  5759. */
  5760. function createPatch(items, scope, parentScope, binding) {
  5761. const {
  5762. condition,
  5763. template,
  5764. childrenMap,
  5765. itemName,
  5766. getKey,
  5767. indexName,
  5768. root,
  5769. isTemplateTag
  5770. } = binding;
  5771. const newChildrenMap = new Map();
  5772. const batches = [];
  5773. const futureNodes = [];
  5774. items.forEach((item, index) => {
  5775. const context = extendScope(Object.create(scope), {
  5776. itemName,
  5777. indexName,
  5778. index,
  5779. item
  5780. });
  5781. const key = getKey ? getKey(context) : index;
  5782. const oldItem = childrenMap.get(key);
  5783. const nodes = [];
  5784. if (mustFilterItem(condition, context)) {
  5785. return;
  5786. }
  5787. const mustMount = !oldItem;
  5788. const componentTemplate = oldItem ? oldItem.template : template.clone();
  5789. const el = componentTemplate.el || root.cloneNode();
  5790. const meta = isTemplateTag && mustMount ? createTemplateMeta(componentTemplate) : componentTemplate.meta;
  5791. if (mustMount) {
  5792. batches.push(() => componentTemplate.mount(el, context, parentScope, meta));
  5793. } else {
  5794. batches.push(() => componentTemplate.update(context, parentScope));
  5795. } // create the collection of nodes to update or to add
  5796. // in case of template tags we need to add all its children nodes
  5797. if (isTemplateTag) {
  5798. nodes.push(...(mustMount ? meta.children : getFragmentChildren(meta)));
  5799. } else {
  5800. nodes.push(el);
  5801. } // delete the old item from the children map
  5802. childrenMap.delete(key);
  5803. futureNodes.push(...nodes); // update the children map
  5804. newChildrenMap.set(key, {
  5805. nodes,
  5806. template: componentTemplate,
  5807. context,
  5808. index
  5809. });
  5810. });
  5811. return {
  5812. newChildrenMap,
  5813. batches,
  5814. futureNodes
  5815. };
  5816. }
  5817. function create$6(node, _ref2) {
  5818. let {
  5819. evaluate,
  5820. condition,
  5821. itemName,
  5822. indexName,
  5823. getKey,
  5824. template
  5825. } = _ref2;
  5826. const placeholder = document.createTextNode('');
  5827. const root = node.cloneNode();
  5828. insertBefore(placeholder, node);
  5829. removeChild(node);
  5830. return Object.assign({}, EachBinding, {
  5831. childrenMap: new Map(),
  5832. node,
  5833. root,
  5834. condition,
  5835. evaluate,
  5836. isTemplateTag: isTemplate(root),
  5837. template: template.createDOM(node),
  5838. getKey,
  5839. indexName,
  5840. itemName,
  5841. placeholder
  5842. });
  5843. }
  5844. /**
  5845. * Binding responsible for the `if` directive
  5846. */
  5847. const IfBinding = {
  5848. // dynamic binding properties
  5849. // node: null,
  5850. // evaluate: null,
  5851. // isTemplateTag: false,
  5852. // placeholder: null,
  5853. // template: null,
  5854. // API methods
  5855. mount(scope, parentScope) {
  5856. return this.update(scope, parentScope);
  5857. },
  5858. update(scope, parentScope) {
  5859. const value = !!this.evaluate(scope);
  5860. const mustMount = !this.value && value;
  5861. const mustUnmount = this.value && !value;
  5862. const mount = () => {
  5863. const pristine = this.node.cloneNode();
  5864. insertBefore(pristine, this.placeholder);
  5865. this.template = this.template.clone();
  5866. this.template.mount(pristine, scope, parentScope);
  5867. };
  5868. switch (true) {
  5869. case mustMount:
  5870. mount();
  5871. break;
  5872. case mustUnmount:
  5873. this.unmount(scope);
  5874. break;
  5875. default:
  5876. if (value) this.template.update(scope, parentScope);
  5877. }
  5878. this.value = value;
  5879. return this;
  5880. },
  5881. unmount(scope, parentScope) {
  5882. this.template.unmount(scope, parentScope, true);
  5883. return this;
  5884. }
  5885. };
  5886. function create$5(node, _ref) {
  5887. let {
  5888. evaluate,
  5889. template
  5890. } = _ref;
  5891. const placeholder = document.createTextNode('');
  5892. insertBefore(placeholder, node);
  5893. removeChild(node);
  5894. return Object.assign({}, IfBinding, {
  5895. node,
  5896. evaluate,
  5897. placeholder,
  5898. template: template.createDOM(node)
  5899. });
  5900. }
  5901. /**
  5902. * Throw an error with a descriptive message
  5903. * @param { string } message - error message
  5904. * @returns { undefined } hoppla.. at this point the program should stop working
  5905. */
  5906. function panic(message) {
  5907. throw new Error(message);
  5908. }
  5909. /**
  5910. * Returns the memoized (cached) function.
  5911. * // borrowed from https://www.30secondsofcode.org/js/s/memoize
  5912. * @param {Function} fn - function to memoize
  5913. * @returns {Function} memoize function
  5914. */
  5915. function memoize(fn) {
  5916. const cache = new Map();
  5917. const cached = val => {
  5918. return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
  5919. };
  5920. cached.cache = cache;
  5921. return cached;
  5922. }
  5923. /**
  5924. * Evaluate a list of attribute expressions
  5925. * @param {Array} attributes - attribute expressions generated by the riot compiler
  5926. * @returns {Object} key value pairs with the result of the computation
  5927. */
  5928. function evaluateAttributeExpressions(attributes) {
  5929. return attributes.reduce((acc, attribute) => {
  5930. const {
  5931. value,
  5932. type
  5933. } = attribute;
  5934. switch (true) {
  5935. // spread attribute
  5936. case !attribute.name && type === ATTRIBUTE:
  5937. return Object.assign({}, acc, value);
  5938. // value attribute
  5939. case type === VALUE:
  5940. acc.value = attribute.value;
  5941. break;
  5942. // normal attributes
  5943. default:
  5944. acc[dashToCamelCase(attribute.name)] = attribute.value;
  5945. }
  5946. return acc;
  5947. }, {});
  5948. }
  5949. const ElementProto = typeof Element === 'undefined' ? {} : Element.prototype;
  5950. const isNativeHtmlProperty = memoize(name => ElementProto.hasOwnProperty(name)); // eslint-disable-line
  5951. /**
  5952. * Add all the attributes provided
  5953. * @param {HTMLElement} node - target node
  5954. * @param {Object} attributes - object containing the attributes names and values
  5955. * @returns {undefined} sorry it's a void function :(
  5956. */
  5957. function setAllAttributes(node, attributes) {
  5958. Object.entries(attributes).forEach(_ref => {
  5959. let [name, value] = _ref;
  5960. return attributeExpression(node, {
  5961. name
  5962. }, value);
  5963. });
  5964. }
  5965. /**
  5966. * Remove all the attributes provided
  5967. * @param {HTMLElement} node - target node
  5968. * @param {Object} newAttributes - object containing all the new attribute names
  5969. * @param {Object} oldAttributes - object containing all the old attribute names
  5970. * @returns {undefined} sorry it's a void function :(
  5971. */
  5972. function removeAllAttributes(node, newAttributes, oldAttributes) {
  5973. const newKeys = newAttributes ? Object.keys(newAttributes) : [];
  5974. Object.keys(oldAttributes).filter(name => !newKeys.includes(name)).forEach(attribute => node.removeAttribute(attribute));
  5975. }
  5976. /**
  5977. * Check whether the attribute value can be rendered
  5978. * @param {*} value - expression value
  5979. * @returns {boolean} true if we can render this attribute value
  5980. */
  5981. function canRenderAttribute(value) {
  5982. return value === true || ['string', 'number'].includes(typeof value);
  5983. }
  5984. /**
  5985. * Check whether the attribute should be removed
  5986. * @param {*} value - expression value
  5987. * @returns {boolean} boolean - true if the attribute can be removed}
  5988. */
  5989. function shouldRemoveAttribute(value) {
  5990. return !value && value !== 0;
  5991. }
  5992. /**
  5993. * This methods handles the DOM attributes updates
  5994. * @param {HTMLElement} node - target node
  5995. * @param {Object} expression - expression object
  5996. * @param {string} expression.name - attribute name
  5997. * @param {*} value - new expression value
  5998. * @param {*} oldValue - the old expression cached value
  5999. * @returns {undefined}
  6000. */
  6001. function attributeExpression(node, _ref2, value, oldValue) {
  6002. let {
  6003. name
  6004. } = _ref2;
  6005. // is it a spread operator? {...attributes}
  6006. if (!name) {
  6007. if (oldValue) {
  6008. // remove all the old attributes
  6009. removeAllAttributes(node, value, oldValue);
  6010. } // is the value still truthy?
  6011. if (value) {
  6012. setAllAttributes(node, value);
  6013. }
  6014. return;
  6015. } // handle boolean attributes
  6016. if (!isNativeHtmlProperty(name) && (isBoolean(value) || isObject(value) || isFunction(value))) {
  6017. node[name] = value;
  6018. }
  6019. if (shouldRemoveAttribute(value)) {
  6020. node.removeAttribute(name);
  6021. } else if (canRenderAttribute(value)) {
  6022. node.setAttribute(name, normalizeValue(name, value));
  6023. }
  6024. }
  6025. /**
  6026. * Get the value as string
  6027. * @param {string} name - attribute name
  6028. * @param {*} value - user input value
  6029. * @returns {string} input value as string
  6030. */
  6031. function normalizeValue(name, value) {
  6032. // be sure that expressions like selected={ true } will be always rendered as selected='selected'
  6033. return value === true ? name : value;
  6034. }
  6035. const RE_EVENTS_PREFIX = /^on/;
  6036. 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
  6037. const EventListener = {
  6038. handleEvent(event) {
  6039. this[event.type](event);
  6040. }
  6041. };
  6042. const ListenersWeakMap = new WeakMap();
  6043. const createListener = node => {
  6044. const listener = Object.create(EventListener);
  6045. ListenersWeakMap.set(node, listener);
  6046. return listener;
  6047. };
  6048. /**
  6049. * Set a new event listener
  6050. * @param {HTMLElement} node - target node
  6051. * @param {Object} expression - expression object
  6052. * @param {string} expression.name - event name
  6053. * @param {*} value - new expression value
  6054. * @returns {value} the callback just received
  6055. */
  6056. function eventExpression(node, _ref, value) {
  6057. let {
  6058. name
  6059. } = _ref;
  6060. const normalizedEventName = name.replace(RE_EVENTS_PREFIX, '');
  6061. const eventListener = ListenersWeakMap.get(node) || createListener(node);
  6062. const [callback, options] = getCallbackAndOptions(value);
  6063. const handler = eventListener[normalizedEventName];
  6064. const mustRemoveEvent = handler && !callback;
  6065. const mustAddEvent = callback && !handler;
  6066. if (mustRemoveEvent) {
  6067. node.removeEventListener(normalizedEventName, eventListener);
  6068. }
  6069. if (mustAddEvent) {
  6070. node.addEventListener(normalizedEventName, eventListener, options);
  6071. }
  6072. eventListener[normalizedEventName] = callback;
  6073. }
  6074. /**
  6075. * Normalize the user value in order to render a empty string in case of falsy values
  6076. * @param {*} value - user input value
  6077. * @returns {string} hopefully a string
  6078. */
  6079. function normalizeStringValue(value) {
  6080. return isNil(value) ? '' : value;
  6081. }
  6082. /**
  6083. * Get the the target text node to update or create one from of a comment node
  6084. * @param {HTMLElement} node - any html element containing childNodes
  6085. * @param {number} childNodeIndex - index of the text node in the childNodes list
  6086. * @returns {Text} the text node to update
  6087. */
  6088. const getTextNode = (node, childNodeIndex) => {
  6089. const target = node.childNodes[childNodeIndex];
  6090. if (target.nodeType === Node.COMMENT_NODE) {
  6091. const textNode = document.createTextNode('');
  6092. node.replaceChild(textNode, target);
  6093. return textNode;
  6094. }
  6095. return target;
  6096. };
  6097. /**
  6098. * This methods handles a simple text expression update
  6099. * @param {HTMLElement} node - target node
  6100. * @param {Object} data - expression object
  6101. * @param {*} value - new expression value
  6102. * @returns {undefined}
  6103. */
  6104. function textExpression(node, data, value) {
  6105. node.data = normalizeStringValue(value);
  6106. }
  6107. /**
  6108. * This methods handles the input fileds value updates
  6109. * @param {HTMLElement} node - target node
  6110. * @param {Object} expression - expression object
  6111. * @param {*} value - new expression value
  6112. * @returns {undefined}
  6113. */
  6114. function valueExpression(node, expression, value) {
  6115. node.value = normalizeStringValue(value);
  6116. }
  6117. var expressions = {
  6118. [ATTRIBUTE]: attributeExpression,
  6119. [EVENT]: eventExpression,
  6120. [TEXT]: textExpression,
  6121. [VALUE]: valueExpression
  6122. };
  6123. const Expression = {
  6124. // Static props
  6125. // node: null,
  6126. // value: null,
  6127. // API methods
  6128. /**
  6129. * Mount the expression evaluating its initial value
  6130. * @param {*} scope - argument passed to the expression to evaluate its current values
  6131. * @returns {Expression} self
  6132. */
  6133. mount(scope) {
  6134. // hopefully a pure function
  6135. this.value = this.evaluate(scope); // IO() DOM updates
  6136. apply(this, this.value);
  6137. return this;
  6138. },
  6139. /**
  6140. * Update the expression if its value changed
  6141. * @param {*} scope - argument passed to the expression to evaluate its current values
  6142. * @returns {Expression} self
  6143. */
  6144. update(scope) {
  6145. // pure function
  6146. const value = this.evaluate(scope);
  6147. if (this.value !== value) {
  6148. // IO() DOM updates
  6149. apply(this, value);
  6150. this.value = value;
  6151. }
  6152. return this;
  6153. },
  6154. /**
  6155. * Expression teardown method
  6156. * @returns {Expression} self
  6157. */
  6158. unmount() {
  6159. // unmount only the event handling expressions
  6160. if (this.type === EVENT) apply(this, null);
  6161. return this;
  6162. }
  6163. };
  6164. /**
  6165. * IO() function to handle the DOM updates
  6166. * @param {Expression} expression - expression object
  6167. * @param {*} value - current expression value
  6168. * @returns {undefined}
  6169. */
  6170. function apply(expression, value) {
  6171. return expressions[expression.type](expression.node, expression, value, expression.value);
  6172. }
  6173. function create$4(node, data) {
  6174. return Object.assign({}, Expression, data, {
  6175. node: data.type === TEXT ? getTextNode(node, data.childNodeIndex) : node
  6176. });
  6177. }
  6178. /**
  6179. * Create a flat object having as keys a list of methods that if dispatched will propagate
  6180. * on the whole collection
  6181. * @param {Array} collection - collection to iterate
  6182. * @param {Array<string>} methods - methods to execute on each item of the collection
  6183. * @param {*} context - context returned by the new methods created
  6184. * @returns {Object} a new object to simplify the the nested methods dispatching
  6185. */
  6186. function flattenCollectionMethods(collection, methods, context) {
  6187. return methods.reduce((acc, method) => {
  6188. return Object.assign({}, acc, {
  6189. [method]: scope => {
  6190. return collection.map(item => item[method](scope)) && context;
  6191. }
  6192. });
  6193. }, {});
  6194. }
  6195. function create$3(node, _ref) {
  6196. let {
  6197. expressions
  6198. } = _ref;
  6199. return Object.assign({}, flattenCollectionMethods(expressions.map(expression => create$4(node, expression)), ['mount', 'update', 'unmount']));
  6200. }
  6201. function extendParentScope(attributes, scope, parentScope) {
  6202. if (!attributes || !attributes.length) return parentScope;
  6203. const expressions = attributes.map(attr => Object.assign({}, attr, {
  6204. value: attr.evaluate(scope)
  6205. }));
  6206. return Object.assign(Object.create(parentScope || null), evaluateAttributeExpressions(expressions));
  6207. } // this function is only meant to fix an edge case
  6208. // https://github.com/riot/riot/issues/2842
  6209. const getRealParent = (scope, parentScope) => scope[PARENT_KEY_SYMBOL] || parentScope;
  6210. const SlotBinding = {
  6211. // dynamic binding properties
  6212. // node: null,
  6213. // name: null,
  6214. attributes: [],
  6215. // template: null,
  6216. getTemplateScope(scope, parentScope) {
  6217. return extendParentScope(this.attributes, scope, parentScope);
  6218. },
  6219. // API methods
  6220. mount(scope, parentScope) {
  6221. const templateData = scope.slots ? scope.slots.find(_ref => {
  6222. let {
  6223. id
  6224. } = _ref;
  6225. return id === this.name;
  6226. }) : false;
  6227. const {
  6228. parentNode
  6229. } = this.node;
  6230. const realParent = getRealParent(scope, parentScope);
  6231. this.template = templateData && create(templateData.html, templateData.bindings).createDOM(parentNode);
  6232. if (this.template) {
  6233. cleanNode(this.node);
  6234. this.template.mount(this.node, this.getTemplateScope(scope, realParent), realParent);
  6235. this.template.children = Array.from(this.node.childNodes);
  6236. }
  6237. moveSlotInnerContent(this.node);
  6238. removeChild(this.node);
  6239. return this;
  6240. },
  6241. update(scope, parentScope) {
  6242. if (this.template) {
  6243. const realParent = getRealParent(scope, parentScope);
  6244. this.template.update(this.getTemplateScope(scope, realParent), realParent);
  6245. }
  6246. return this;
  6247. },
  6248. unmount(scope, parentScope, mustRemoveRoot) {
  6249. if (this.template) {
  6250. this.template.unmount(this.getTemplateScope(scope, parentScope), null, mustRemoveRoot);
  6251. }
  6252. return this;
  6253. }
  6254. };
  6255. /**
  6256. * Move the inner content of the slots outside of them
  6257. * @param {HTMLElement} slot - slot node
  6258. * @returns {undefined} it's a void method ¯\_()_/¯
  6259. */
  6260. function moveSlotInnerContent(slot) {
  6261. const child = slot && slot.firstChild;
  6262. if (!child) return;
  6263. insertBefore(child, slot);
  6264. moveSlotInnerContent(slot);
  6265. }
  6266. /**
  6267. * Create a single slot binding
  6268. * @param {HTMLElement} node - slot node
  6269. * @param {string} name - slot id
  6270. * @param {AttributeExpressionData[]} attributes - slot attributes
  6271. * @returns {Object} Slot binding object
  6272. */
  6273. function createSlot(node, _ref2) {
  6274. let {
  6275. name,
  6276. attributes
  6277. } = _ref2;
  6278. return Object.assign({}, SlotBinding, {
  6279. attributes,
  6280. node,
  6281. name
  6282. });
  6283. }
  6284. /**
  6285. * Create a new tag object if it was registered before, otherwise fallback to the simple
  6286. * template chunk
  6287. * @param {Function} component - component factory function
  6288. * @param {Array<Object>} slots - array containing the slots markup
  6289. * @param {Array} attributes - dynamic attributes that will be received by the tag element
  6290. * @returns {TagImplementation|TemplateChunk} a tag implementation or a template chunk as fallback
  6291. */
  6292. function getTag(component, slots, attributes) {
  6293. if (slots === void 0) {
  6294. slots = [];
  6295. }
  6296. if (attributes === void 0) {
  6297. attributes = [];
  6298. }
  6299. // if this tag was registered before we will return its implementation
  6300. if (component) {
  6301. return component({
  6302. slots,
  6303. attributes
  6304. });
  6305. } // otherwise we return a template chunk
  6306. return create(slotsToMarkup(slots), [...slotBindings(slots), {
  6307. // the attributes should be registered as binding
  6308. // if we fallback to a normal template chunk
  6309. expressions: attributes.map(attr => {
  6310. return Object.assign({
  6311. type: ATTRIBUTE
  6312. }, attr);
  6313. })
  6314. }]);
  6315. }
  6316. /**
  6317. * Merge all the slots bindings into a single array
  6318. * @param {Array<Object>} slots - slots collection
  6319. * @returns {Array<Bindings>} flatten bindings array
  6320. */
  6321. function slotBindings(slots) {
  6322. return slots.reduce((acc, _ref) => {
  6323. let {
  6324. bindings
  6325. } = _ref;
  6326. return acc.concat(bindings);
  6327. }, []);
  6328. }
  6329. /**
  6330. * Merge all the slots together in a single markup string
  6331. * @param {Array<Object>} slots - slots collection
  6332. * @returns {string} markup of all the slots in a single string
  6333. */
  6334. function slotsToMarkup(slots) {
  6335. return slots.reduce((acc, slot) => {
  6336. return acc + slot.html;
  6337. }, '');
  6338. }
  6339. const TagBinding = {
  6340. // dynamic binding properties
  6341. // node: null,
  6342. // evaluate: null,
  6343. // name: null,
  6344. // slots: null,
  6345. // tag: null,
  6346. // attributes: null,
  6347. // getComponent: null,
  6348. mount(scope) {
  6349. return this.update(scope);
  6350. },
  6351. update(scope, parentScope) {
  6352. const name = this.evaluate(scope); // simple update
  6353. if (name && name === this.name) {
  6354. this.tag.update(scope);
  6355. } else {
  6356. // unmount the old tag if it exists
  6357. this.unmount(scope, parentScope, true); // mount the new tag
  6358. this.name = name;
  6359. this.tag = getTag(this.getComponent(name), this.slots, this.attributes);
  6360. this.tag.mount(this.node, scope);
  6361. }
  6362. return this;
  6363. },
  6364. unmount(scope, parentScope, keepRootTag) {
  6365. if (this.tag) {
  6366. // keep the root tag
  6367. this.tag.unmount(keepRootTag);
  6368. }
  6369. return this;
  6370. }
  6371. };
  6372. function create$2(node, _ref2) {
  6373. let {
  6374. evaluate,
  6375. getComponent,
  6376. slots,
  6377. attributes
  6378. } = _ref2;
  6379. return Object.assign({}, TagBinding, {
  6380. node,
  6381. evaluate,
  6382. slots,
  6383. attributes,
  6384. getComponent
  6385. });
  6386. }
  6387. var bindings = {
  6388. [IF]: create$5,
  6389. [SIMPLE]: create$3,
  6390. [EACH]: create$6,
  6391. [TAG]: create$2,
  6392. [SLOT]: createSlot
  6393. };
  6394. /**
  6395. * Text expressions in a template tag will get childNodeIndex value normalized
  6396. * depending on the position of the <template> tag offset
  6397. * @param {Expression[]} expressions - riot expressions array
  6398. * @param {number} textExpressionsOffset - offset of the <template> tag
  6399. * @returns {Expression[]} expressions containing the text expressions normalized
  6400. */
  6401. function fixTextExpressionsOffset(expressions, textExpressionsOffset) {
  6402. return expressions.map(e => e.type === TEXT ? Object.assign({}, e, {
  6403. childNodeIndex: e.childNodeIndex + textExpressionsOffset
  6404. }) : e);
  6405. }
  6406. /**
  6407. * Bind a new expression object to a DOM node
  6408. * @param {HTMLElement} root - DOM node where to bind the expression
  6409. * @param {TagBindingData} binding - binding data
  6410. * @param {number|null} templateTagOffset - if it's defined we need to fix the text expressions childNodeIndex offset
  6411. * @returns {Binding} Binding object
  6412. */
  6413. function create$1(root, binding, templateTagOffset) {
  6414. const {
  6415. selector,
  6416. type,
  6417. redundantAttribute,
  6418. expressions
  6419. } = binding; // find the node to apply the bindings
  6420. const node = selector ? root.querySelector(selector) : root; // remove eventually additional attributes created only to select this node
  6421. if (redundantAttribute) node.removeAttribute(redundantAttribute);
  6422. const bindingExpressions = expressions || []; // init the binding
  6423. return (bindings[type] || bindings[SIMPLE])(node, Object.assign({}, binding, {
  6424. expressions: templateTagOffset && !selector ? fixTextExpressionsOffset(bindingExpressions, templateTagOffset) : bindingExpressions
  6425. }));
  6426. }
  6427. function createHTMLTree(html, root) {
  6428. const template = isTemplate(root) ? root : document.createElement('template');
  6429. template.innerHTML = html;
  6430. return template.content;
  6431. } // for svg nodes we need a bit more work
  6432. function createSVGTree(html, container) {
  6433. // create the SVGNode
  6434. const svgNode = container.ownerDocument.importNode(new window.DOMParser().parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${html}</svg>`, 'application/xml').documentElement, true);
  6435. return svgNode;
  6436. }
  6437. /**
  6438. * Create the DOM that will be injected
  6439. * @param {Object} root - DOM node to find out the context where the fragment will be created
  6440. * @param {string} html - DOM to create as string
  6441. * @returns {HTMLDocumentFragment|HTMLElement} a new html fragment
  6442. */
  6443. function createDOMTree(root, html) {
  6444. if (isSvg(root)) return createSVGTree(html, root);
  6445. return createHTMLTree(html, root);
  6446. }
  6447. /**
  6448. * Inject the DOM tree into a target node
  6449. * @param {HTMLElement} el - target element
  6450. * @param {DocumentFragment|SVGElement} dom - dom tree to inject
  6451. * @returns {undefined}
  6452. */
  6453. function injectDOM(el, dom) {
  6454. switch (true) {
  6455. case isSvg(el):
  6456. moveChildren(dom, el);
  6457. break;
  6458. case isTemplate(el):
  6459. el.parentNode.replaceChild(dom, el);
  6460. break;
  6461. default:
  6462. el.appendChild(dom);
  6463. }
  6464. }
  6465. /**
  6466. * Create the Template DOM skeleton
  6467. * @param {HTMLElement} el - root node where the DOM will be injected
  6468. * @param {string|HTMLElement} html - HTML markup or HTMLElement that will be injected into the root node
  6469. * @returns {?DocumentFragment} fragment that will be injected into the root node
  6470. */
  6471. function createTemplateDOM(el, html) {
  6472. return html && (typeof html === 'string' ? createDOMTree(el, html) : html);
  6473. }
  6474. /**
  6475. * Get the offset of the <template> tag
  6476. * @param {HTMLElement} parentNode - template tag parent node
  6477. * @param {HTMLElement} el - the template tag we want to render
  6478. * @param {Object} meta - meta properties needed to handle the <template> tags in loops
  6479. * @returns {number} offset of the <template> tag calculated from its siblings DOM nodes
  6480. */
  6481. function getTemplateTagOffset(parentNode, el, meta) {
  6482. const siblings = Array.from(parentNode.childNodes);
  6483. return Math.max(siblings.indexOf(el), siblings.indexOf(meta.head) + 1, 0);
  6484. }
  6485. /**
  6486. * Template Chunk model
  6487. * @type {Object}
  6488. */
  6489. const TemplateChunk = Object.freeze({
  6490. // Static props
  6491. // bindings: null,
  6492. // bindingsData: null,
  6493. // html: null,
  6494. // isTemplateTag: false,
  6495. // fragment: null,
  6496. // children: null,
  6497. // dom: null,
  6498. // el: null,
  6499. /**
  6500. * Create the template DOM structure that will be cloned on each mount
  6501. * @param {HTMLElement} el - the root node
  6502. * @returns {TemplateChunk} self
  6503. */
  6504. createDOM(el) {
  6505. // make sure that the DOM gets created before cloning the template
  6506. this.dom = this.dom || createTemplateDOM(el, this.html) || document.createDocumentFragment();
  6507. return this;
  6508. },
  6509. // API methods
  6510. /**
  6511. * Attach the template to a DOM node
  6512. * @param {HTMLElement} el - target DOM node
  6513. * @param {*} scope - template data
  6514. * @param {*} parentScope - scope of the parent template tag
  6515. * @param {Object} meta - meta properties needed to handle the <template> tags in loops
  6516. * @returns {TemplateChunk} self
  6517. */
  6518. mount(el, scope, parentScope, meta) {
  6519. if (meta === void 0) {
  6520. meta = {};
  6521. }
  6522. if (!el) throw new Error('Please provide DOM node to mount properly your template');
  6523. if (this.el) this.unmount(scope); // <template> tags require a bit more work
  6524. // the template fragment might be already created via meta outside of this call
  6525. const {
  6526. fragment,
  6527. children,
  6528. avoidDOMInjection
  6529. } = meta; // <template> bindings of course can not have a root element
  6530. // so we check the parent node to set the query selector bindings
  6531. const {
  6532. parentNode
  6533. } = children ? children[0] : el;
  6534. const isTemplateTag = isTemplate(el);
  6535. const templateTagOffset = isTemplateTag ? getTemplateTagOffset(parentNode, el, meta) : null; // create the DOM if it wasn't created before
  6536. this.createDOM(el); // create the DOM of this template cloning the original DOM structure stored in this instance
  6537. // notice that if a documentFragment was passed (via meta) we will use it instead
  6538. const cloneNode = fragment || this.dom.cloneNode(true); // store root node
  6539. // notice that for template tags the root note will be the parent tag
  6540. this.el = isTemplateTag ? parentNode : el; // create the children array only for the <template> fragments
  6541. this.children = isTemplateTag ? children || Array.from(cloneNode.childNodes) : null; // inject the DOM into the el only if a fragment is available
  6542. if (!avoidDOMInjection && cloneNode) injectDOM(el, cloneNode); // create the bindings
  6543. this.bindings = this.bindingsData.map(binding => create$1(this.el, binding, templateTagOffset));
  6544. this.bindings.forEach(b => b.mount(scope, parentScope)); // store the template meta properties
  6545. this.meta = meta;
  6546. return this;
  6547. },
  6548. /**
  6549. * Update the template with fresh data
  6550. * @param {*} scope - template data
  6551. * @param {*} parentScope - scope of the parent template tag
  6552. * @returns {TemplateChunk} self
  6553. */
  6554. update(scope, parentScope) {
  6555. this.bindings.forEach(b => b.update(scope, parentScope));
  6556. return this;
  6557. },
  6558. /**
  6559. * Remove the template from the node where it was initially mounted
  6560. * @param {*} scope - template data
  6561. * @param {*} parentScope - scope of the parent template tag
  6562. * @param {boolean|null} mustRemoveRoot - if true remove the root element,
  6563. * if false or undefined clean the root tag content, if null don't touch the DOM
  6564. * @returns {TemplateChunk} self
  6565. */
  6566. unmount(scope, parentScope, mustRemoveRoot) {
  6567. if (mustRemoveRoot === void 0) {
  6568. mustRemoveRoot = false;
  6569. }
  6570. const el = this.el;
  6571. if (!el) {
  6572. return this;
  6573. }
  6574. this.bindings.forEach(b => b.unmount(scope, parentScope, mustRemoveRoot));
  6575. switch (true) {
  6576. // pure components should handle the DOM unmount updates by themselves
  6577. // for mustRemoveRoot === null don't touch the DOM
  6578. case el[IS_PURE_SYMBOL] || mustRemoveRoot === null:
  6579. break;
  6580. // if children are declared, clear them
  6581. // applicable for <template> and <slot/> bindings
  6582. case Array.isArray(this.children):
  6583. clearChildren(this.children);
  6584. break;
  6585. // clean the node children only
  6586. case !mustRemoveRoot:
  6587. cleanNode(el);
  6588. break;
  6589. // remove the root node only if the mustRemoveRoot is truly
  6590. case !!mustRemoveRoot:
  6591. removeChild(el);
  6592. break;
  6593. }
  6594. this.el = null;
  6595. return this;
  6596. },
  6597. /**
  6598. * Clone the template chunk
  6599. * @returns {TemplateChunk} a clone of this object resetting the this.el property
  6600. */
  6601. clone() {
  6602. return Object.assign({}, this, {
  6603. meta: {},
  6604. el: null
  6605. });
  6606. }
  6607. });
  6608. /**
  6609. * Create a template chunk wiring also the bindings
  6610. * @param {string|HTMLElement} html - template string
  6611. * @param {BindingData[]} bindings - bindings collection
  6612. * @returns {TemplateChunk} a new TemplateChunk copy
  6613. */
  6614. function create(html, bindings) {
  6615. if (bindings === void 0) {
  6616. bindings = [];
  6617. }
  6618. return Object.assign({}, TemplateChunk, {
  6619. html,
  6620. bindingsData: bindings
  6621. });
  6622. }
  6623. /**
  6624. * Method used to bind expressions to a DOM node
  6625. * @param {string|HTMLElement} html - your static template html structure
  6626. * @param {Array} bindings - list of the expressions to bind to update the markup
  6627. * @returns {TemplateChunk} a new TemplateChunk object having the `update`,`mount`, `unmount` and `clone` methods
  6628. *
  6629. * @example
  6630. *
  6631. * riotDOMBindings
  6632. * .template(
  6633. * `<div expr0><!----></div><div><p expr1><!----><section expr2></section></p>`,
  6634. * [
  6635. * {
  6636. * selector: '[expr0]',
  6637. * redundantAttribute: 'expr0',
  6638. * expressions: [
  6639. * {
  6640. * type: expressionTypes.TEXT,
  6641. * childNodeIndex: 0,
  6642. * evaluate(scope) {
  6643. * return scope.time;
  6644. * },
  6645. * },
  6646. * ],
  6647. * },
  6648. * {
  6649. * selector: '[expr1]',
  6650. * redundantAttribute: 'expr1',
  6651. * expressions: [
  6652. * {
  6653. * type: expressionTypes.TEXT,
  6654. * childNodeIndex: 0,
  6655. * evaluate(scope) {
  6656. * return scope.name;
  6657. * },
  6658. * },
  6659. * {
  6660. * type: 'attribute',
  6661. * name: 'style',
  6662. * evaluate(scope) {
  6663. * return scope.style;
  6664. * },
  6665. * },
  6666. * ],
  6667. * },
  6668. * {
  6669. * selector: '[expr2]',
  6670. * redundantAttribute: 'expr2',
  6671. * type: bindingTypes.IF,
  6672. * evaluate(scope) {
  6673. * return scope.isVisible;
  6674. * },
  6675. * template: riotDOMBindings.template('hello there'),
  6676. * },
  6677. * ]
  6678. * )
  6679. */
  6680. var DOMBindings = /*#__PURE__*/Object.freeze({
  6681. __proto__: null,
  6682. template: create,
  6683. createBinding: create$1,
  6684. createExpression: create$4,
  6685. bindingTypes: bindingTypes,
  6686. expressionTypes: expressionTypes
  6687. });
  6688. function noop() {
  6689. return this;
  6690. }
  6691. /**
  6692. * Autobind the methods of a source object to itself
  6693. * @param {Object} source - probably a riot tag instance
  6694. * @param {Array<string>} methods - list of the methods to autobind
  6695. * @returns {Object} the original object received
  6696. */
  6697. function autobindMethods(source, methods) {
  6698. methods.forEach(method => {
  6699. source[method] = source[method].bind(source);
  6700. });
  6701. return source;
  6702. }
  6703. /**
  6704. * Call the first argument received only if it's a function otherwise return it as it is
  6705. * @param {*} source - anything
  6706. * @returns {*} anything
  6707. */
  6708. function callOrAssign(source) {
  6709. return isFunction(source) ? source.prototype && source.prototype.constructor ? new source() : source() : source;
  6710. }
  6711. /**
  6712. * Converts any DOM node/s to a loopable array
  6713. * @param { HTMLElement|NodeList } els - single html element or a node list
  6714. * @returns { Array } always a loopable object
  6715. */
  6716. function domToArray(els) {
  6717. // can this object be already looped?
  6718. if (!Array.isArray(els)) {
  6719. // is it a node list?
  6720. 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
  6721. // it will be returned as "array" with one single entry
  6722. return [els];
  6723. } // this object could be looped out of the box
  6724. return els;
  6725. }
  6726. /**
  6727. * Simple helper to find DOM nodes returning them as array like loopable object
  6728. * @param { string|DOMNodeList } selector - either the query or the DOM nodes to arraify
  6729. * @param { HTMLElement } ctx - context defining where the query will search for the DOM nodes
  6730. * @returns { Array } DOM nodes found as array
  6731. */
  6732. function $(selector, ctx) {
  6733. return domToArray(typeof selector === 'string' ? (ctx || document).querySelectorAll(selector) : selector);
  6734. }
  6735. /**
  6736. * Normalize the return values, in case of a single value we avoid to return an array
  6737. * @param { Array } values - list of values we want to return
  6738. * @returns { Array|string|boolean } either the whole list of values or the single one found
  6739. * @private
  6740. */
  6741. const normalize = values => values.length === 1 ? values[0] : values;
  6742. /**
  6743. * Parse all the nodes received to get/remove/check their attributes
  6744. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  6745. * @param { string|Array } name - name or list of attributes
  6746. * @param { string } method - method that will be used to parse the attributes
  6747. * @returns { Array|string } result of the parsing in a list or a single value
  6748. * @private
  6749. */
  6750. function parseNodes(els, name, method) {
  6751. const names = typeof name === 'string' ? [name] : name;
  6752. return normalize(domToArray(els).map(el => {
  6753. return normalize(names.map(n => el[method](n)));
  6754. }));
  6755. }
  6756. /**
  6757. * Set any attribute on a single or a list of DOM nodes
  6758. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  6759. * @param { string|Object } name - either the name of the attribute to set
  6760. * or a list of properties as object key - value
  6761. * @param { string } value - the new value of the attribute (optional)
  6762. * @returns { HTMLElement|NodeList|Array } the original array of elements passed to this function
  6763. *
  6764. * @example
  6765. *
  6766. * import { set } from 'bianco.attr'
  6767. *
  6768. * const img = document.createElement('img')
  6769. *
  6770. * set(img, 'width', 100)
  6771. *
  6772. * // or also
  6773. * set(img, {
  6774. * width: 300,
  6775. * height: 300
  6776. * })
  6777. *
  6778. */
  6779. function set(els, name, value) {
  6780. const attrs = typeof name === 'object' ? name : {
  6781. [name]: value
  6782. };
  6783. const props = Object.keys(attrs);
  6784. domToArray(els).forEach(el => {
  6785. props.forEach(prop => el.setAttribute(prop, attrs[prop]));
  6786. });
  6787. return els;
  6788. }
  6789. /**
  6790. * Get any attribute from a single or a list of DOM nodes
  6791. * @param { HTMLElement|NodeList|Array } els - DOM node/s to parse
  6792. * @param { string|Array } name - name or list of attributes to get
  6793. * @returns { Array|string } list of the attributes found
  6794. *
  6795. * @example
  6796. *
  6797. * import { get } from 'bianco.attr'
  6798. *
  6799. * const img = document.createElement('img')
  6800. *
  6801. * get(img, 'width') // => '200'
  6802. *
  6803. * // or also
  6804. * get(img, ['width', 'height']) // => ['200', '300']
  6805. *
  6806. * // or also
  6807. * get([img1, img2], ['width', 'height']) // => [['200', '300'], ['500', '200']]
  6808. */
  6809. function get(els, name) {
  6810. return parseNodes(els, name, 'getAttribute');
  6811. }
  6812. const CSS_BY_NAME = new Map();
  6813. const STYLE_NODE_SELECTOR = 'style[riot]'; // memoized curried function
  6814. const getStyleNode = (style => {
  6815. return () => {
  6816. // lazy evaluation:
  6817. // if this function was already called before
  6818. // we return its cached result
  6819. if (style) return style; // create a new style element or use an existing one
  6820. // and cache it internally
  6821. style = $(STYLE_NODE_SELECTOR)[0] || document.createElement('style');
  6822. set(style, 'type', 'text/css');
  6823. /* istanbul ignore next */
  6824. if (!style.parentNode) document.head.appendChild(style);
  6825. return style;
  6826. };
  6827. })();
  6828. /**
  6829. * Object that will be used to inject and manage the css of every tag instance
  6830. */
  6831. var cssManager = {
  6832. CSS_BY_NAME,
  6833. /**
  6834. * Save a tag style to be later injected into DOM
  6835. * @param { string } name - if it's passed we will map the css to a tagname
  6836. * @param { string } css - css string
  6837. * @returns {Object} self
  6838. */
  6839. add(name, css) {
  6840. if (!CSS_BY_NAME.has(name)) {
  6841. CSS_BY_NAME.set(name, css);
  6842. this.inject();
  6843. }
  6844. return this;
  6845. },
  6846. /**
  6847. * Inject all previously saved tag styles into DOM
  6848. * innerHTML seems slow: http://jsperf.com/riot-insert-style
  6849. * @returns {Object} self
  6850. */
  6851. inject() {
  6852. getStyleNode().innerHTML = [...CSS_BY_NAME.values()].join('\n');
  6853. return this;
  6854. },
  6855. /**
  6856. * Remove a tag style from the DOM
  6857. * @param {string} name a registered tagname
  6858. * @returns {Object} self
  6859. */
  6860. remove(name) {
  6861. if (CSS_BY_NAME.has(name)) {
  6862. CSS_BY_NAME.delete(name);
  6863. this.inject();
  6864. }
  6865. return this;
  6866. }
  6867. };
  6868. /**
  6869. * Function to curry any javascript method
  6870. * @param {Function} fn - the target function we want to curry
  6871. * @param {...[args]} acc - initial arguments
  6872. * @returns {Function|*} it will return a function until the target function
  6873. * will receive all of its arguments
  6874. */
  6875. function curry(fn) {
  6876. for (var _len = arguments.length, acc = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  6877. acc[_key - 1] = arguments[_key];
  6878. }
  6879. return function () {
  6880. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  6881. args[_key2] = arguments[_key2];
  6882. }
  6883. args = [...acc, ...args];
  6884. return args.length < fn.length ? curry(fn, ...args) : fn(...args);
  6885. };
  6886. }
  6887. /**
  6888. * Get the tag name of any DOM node
  6889. * @param {HTMLElement} element - DOM node we want to inspect
  6890. * @returns {string} name to identify this dom node in riot
  6891. */
  6892. function getName(element) {
  6893. return get(element, IS_DIRECTIVE) || element.tagName.toLowerCase();
  6894. }
  6895. const COMPONENT_CORE_HELPERS = Object.freeze({
  6896. // component helpers
  6897. $(selector) {
  6898. return $(selector, this.root)[0];
  6899. },
  6900. $$(selector) {
  6901. return $(selector, this.root);
  6902. }
  6903. });
  6904. const PURE_COMPONENT_API = Object.freeze({
  6905. [MOUNT_METHOD_KEY]: noop,
  6906. [UPDATE_METHOD_KEY]: noop,
  6907. [UNMOUNT_METHOD_KEY]: noop
  6908. });
  6909. const COMPONENT_LIFECYCLE_METHODS = Object.freeze({
  6910. [SHOULD_UPDATE_KEY]: noop,
  6911. [ON_BEFORE_MOUNT_KEY]: noop,
  6912. [ON_MOUNTED_KEY]: noop,
  6913. [ON_BEFORE_UPDATE_KEY]: noop,
  6914. [ON_UPDATED_KEY]: noop,
  6915. [ON_BEFORE_UNMOUNT_KEY]: noop,
  6916. [ON_UNMOUNTED_KEY]: noop
  6917. });
  6918. const MOCKED_TEMPLATE_INTERFACE = Object.assign({}, PURE_COMPONENT_API, {
  6919. clone: noop,
  6920. createDOM: noop
  6921. });
  6922. /**
  6923. * Performance optimization for the recursive components
  6924. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  6925. * @returns {Object} component like interface
  6926. */
  6927. const memoizedCreateComponent = memoize(createComponent);
  6928. /**
  6929. * Evaluate the component properties either from its real attributes or from its initial user properties
  6930. * @param {HTMLElement} element - component root
  6931. * @param {Object} initialProps - initial props
  6932. * @returns {Object} component props key value pairs
  6933. */
  6934. function evaluateInitialProps(element, initialProps) {
  6935. if (initialProps === void 0) {
  6936. initialProps = {};
  6937. }
  6938. return Object.assign({}, DOMattributesToObject(element), callOrAssign(initialProps));
  6939. }
  6940. /**
  6941. * Bind a DOM node to its component object
  6942. * @param {HTMLElement} node - html node mounted
  6943. * @param {Object} component - Riot.js component object
  6944. * @returns {Object} the component object received as second argument
  6945. */
  6946. const bindDOMNodeToComponentObject = (node, component) => node[DOM_COMPONENT_INSTANCE_PROPERTY$1] = component;
  6947. /**
  6948. * Wrap the Riot.js core API methods using a mapping function
  6949. * @param {Function} mapFunction - lifting function
  6950. * @returns {Object} an object having the { mount, update, unmount } functions
  6951. */
  6952. function createCoreAPIMethods(mapFunction) {
  6953. return [MOUNT_METHOD_KEY, UPDATE_METHOD_KEY, UNMOUNT_METHOD_KEY].reduce((acc, method) => {
  6954. acc[method] = mapFunction(method);
  6955. return acc;
  6956. }, {});
  6957. }
  6958. /**
  6959. * Factory function to create the component templates only once
  6960. * @param {Function} template - component template creation function
  6961. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  6962. * @returns {TemplateChunk} template chunk object
  6963. */
  6964. function componentTemplateFactory(template, componentWrapper) {
  6965. const components = createSubcomponents(componentWrapper.exports ? componentWrapper.exports.components : {});
  6966. return template(create, expressionTypes, bindingTypes, name => {
  6967. // improve support for recursive components
  6968. if (name === componentWrapper.name) return memoizedCreateComponent(componentWrapper); // return the registered components
  6969. return components[name] || COMPONENTS_IMPLEMENTATION_MAP$1.get(name);
  6970. });
  6971. }
  6972. /**
  6973. * Create a pure component
  6974. * @param {Function} pureFactoryFunction - pure component factory function
  6975. * @param {Array} options.slots - component slots
  6976. * @param {Array} options.attributes - component attributes
  6977. * @param {Array} options.template - template factory function
  6978. * @param {Array} options.template - template factory function
  6979. * @param {any} options.props - initial component properties
  6980. * @returns {Object} pure component object
  6981. */
  6982. function createPureComponent(pureFactoryFunction, _ref) {
  6983. let {
  6984. slots,
  6985. attributes,
  6986. props,
  6987. css,
  6988. template
  6989. } = _ref;
  6990. if (template) panic('Pure components can not have html');
  6991. if (css) panic('Pure components do not have css');
  6992. const component = defineDefaults(pureFactoryFunction({
  6993. slots,
  6994. attributes,
  6995. props
  6996. }), PURE_COMPONENT_API);
  6997. return createCoreAPIMethods(method => function () {
  6998. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  6999. args[_key] = arguments[_key];
  7000. }
  7001. // intercept the mount calls to bind the DOM node to the pure object created
  7002. // see also https://github.com/riot/riot/issues/2806
  7003. if (method === MOUNT_METHOD_KEY) {
  7004. const [el] = args; // mark this node as pure element
  7005. el[IS_PURE_SYMBOL] = true;
  7006. bindDOMNodeToComponentObject(el, component);
  7007. }
  7008. component[method](...args);
  7009. return component;
  7010. });
  7011. }
  7012. /**
  7013. * Create the component interface needed for the @riotjs/dom-bindings tag bindings
  7014. * @param {RiotComponentWrapper} componentWrapper - riot compiler generated object
  7015. * @param {string} componentWrapper.css - component css
  7016. * @param {Function} componentWrapper.template - function that will return the dom-bindings template function
  7017. * @param {Object} componentWrapper.exports - component interface
  7018. * @param {string} componentWrapper.name - component name
  7019. * @returns {Object} component like interface
  7020. */
  7021. function createComponent(componentWrapper) {
  7022. const {
  7023. css,
  7024. template,
  7025. exports,
  7026. name
  7027. } = componentWrapper;
  7028. const templateFn = template ? componentTemplateFactory(template, componentWrapper) : MOCKED_TEMPLATE_INTERFACE;
  7029. return _ref2 => {
  7030. let {
  7031. slots,
  7032. attributes,
  7033. props
  7034. } = _ref2;
  7035. // pure components rendering will be managed by the end user
  7036. if (exports && exports[IS_PURE_SYMBOL]) return createPureComponent(exports, {
  7037. slots,
  7038. attributes,
  7039. props,
  7040. css,
  7041. template
  7042. });
  7043. const componentAPI = callOrAssign(exports) || {};
  7044. const component = defineComponent({
  7045. css,
  7046. template: templateFn,
  7047. componentAPI,
  7048. name
  7049. })({
  7050. slots,
  7051. attributes,
  7052. props
  7053. }); // notice that for the components create via tag binding
  7054. // we need to invert the mount (state/parentScope) arguments
  7055. // the template bindings will only forward the parentScope updates
  7056. // and never deal with the component state
  7057. return {
  7058. mount(element, parentScope, state) {
  7059. return component.mount(element, state, parentScope);
  7060. },
  7061. update(parentScope, state) {
  7062. return component.update(state, parentScope);
  7063. },
  7064. unmount(preserveRoot) {
  7065. return component.unmount(preserveRoot);
  7066. }
  7067. };
  7068. };
  7069. }
  7070. /**
  7071. * Component definition function
  7072. * @param {Object} implementation - the componen implementation will be generated via compiler
  7073. * @param {Object} component - the component initial properties
  7074. * @returns {Object} a new component implementation object
  7075. */
  7076. function defineComponent(_ref3) {
  7077. let {
  7078. css,
  7079. template,
  7080. componentAPI,
  7081. name
  7082. } = _ref3;
  7083. // add the component css into the DOM
  7084. if (css && name) cssManager.add(name, css);
  7085. return curry(enhanceComponentAPI)(defineProperties( // set the component defaults without overriding the original component API
  7086. defineDefaults(componentAPI, Object.assign({}, COMPONENT_LIFECYCLE_METHODS, {
  7087. [PROPS_KEY]: {},
  7088. [STATE_KEY]: {}
  7089. })), Object.assign({
  7090. // defined during the component creation
  7091. [SLOTS_KEY]: null,
  7092. [ROOT_KEY]: null
  7093. }, COMPONENT_CORE_HELPERS, {
  7094. name,
  7095. css,
  7096. template
  7097. })));
  7098. }
  7099. /**
  7100. * Create the bindings to update the component attributes
  7101. * @param {HTMLElement} node - node where we will bind the expressions
  7102. * @param {Array} attributes - list of attribute bindings
  7103. * @returns {TemplateChunk} - template bindings object
  7104. */
  7105. function createAttributeBindings(node, attributes) {
  7106. if (attributes === void 0) {
  7107. attributes = [];
  7108. }
  7109. const expressions = attributes.map(a => create$4(node, a));
  7110. const binding = {};
  7111. return Object.assign(binding, Object.assign({
  7112. expressions
  7113. }, createCoreAPIMethods(method => scope => {
  7114. expressions.forEach(e => e[method](scope));
  7115. return binding;
  7116. })));
  7117. }
  7118. /**
  7119. * Create the subcomponents that can be included inside a tag in runtime
  7120. * @param {Object} components - components imported in runtime
  7121. * @returns {Object} all the components transformed into Riot.Component factory functions
  7122. */
  7123. function createSubcomponents(components) {
  7124. if (components === void 0) {
  7125. components = {};
  7126. }
  7127. return Object.entries(callOrAssign(components)).reduce((acc, _ref4) => {
  7128. let [key, value] = _ref4;
  7129. acc[camelToDashCase(key)] = createComponent(value);
  7130. return acc;
  7131. }, {});
  7132. }
  7133. /**
  7134. * Run the component instance through all the plugins set by the user
  7135. * @param {Object} component - component instance
  7136. * @returns {Object} the component enhanced by the plugins
  7137. */
  7138. function runPlugins(component) {
  7139. return [...PLUGINS_SET$1].reduce((c, fn) => fn(c) || c, component);
  7140. }
  7141. /**
  7142. * Compute the component current state merging it with its previous state
  7143. * @param {Object} oldState - previous state object
  7144. * @param {Object} newState - new state givent to the `update` call
  7145. * @returns {Object} new object state
  7146. */
  7147. function computeState(oldState, newState) {
  7148. return Object.assign({}, oldState, callOrAssign(newState));
  7149. }
  7150. /**
  7151. * Add eventually the "is" attribute to link this DOM node to its css
  7152. * @param {HTMLElement} element - target root node
  7153. * @param {string} name - name of the component mounted
  7154. * @returns {undefined} it's a void function
  7155. */
  7156. function addCssHook(element, name) {
  7157. if (getName(element) !== name) {
  7158. set(element, IS_DIRECTIVE, name);
  7159. }
  7160. }
  7161. /**
  7162. * Component creation factory function that will enhance the user provided API
  7163. * @param {Object} component - a component implementation previously defined
  7164. * @param {Array} options.slots - component slots generated via riot compiler
  7165. * @param {Array} options.attributes - attribute expressions generated via riot compiler
  7166. * @returns {Riot.Component} a riot component instance
  7167. */
  7168. function enhanceComponentAPI(component, _ref5) {
  7169. let {
  7170. slots,
  7171. attributes,
  7172. props
  7173. } = _ref5;
  7174. return autobindMethods(runPlugins(defineProperties(isObject(component) ? Object.create(component) : component, {
  7175. mount(element, state, parentScope) {
  7176. if (state === void 0) {
  7177. state = {};
  7178. }
  7179. this[PARENT_KEY_SYMBOL] = parentScope;
  7180. this[ATTRIBUTES_KEY_SYMBOL] = createAttributeBindings(element, attributes).mount(parentScope);
  7181. defineProperty(this, PROPS_KEY, Object.freeze(Object.assign({}, evaluateInitialProps(element, props), evaluateAttributeExpressions(this[ATTRIBUTES_KEY_SYMBOL].expressions))));
  7182. this[STATE_KEY] = computeState(this[STATE_KEY], state);
  7183. this[TEMPLATE_KEY_SYMBOL] = this.template.createDOM(element).clone(); // link this object to the DOM node
  7184. bindDOMNodeToComponentObject(element, this); // add eventually the 'is' attribute
  7185. component.name && addCssHook(element, component.name); // define the root element
  7186. defineProperty(this, ROOT_KEY, element); // define the slots array
  7187. defineProperty(this, SLOTS_KEY, slots); // before mount lifecycle event
  7188. this[ON_BEFORE_MOUNT_KEY](this[PROPS_KEY], this[STATE_KEY]); // mount the template
  7189. this[TEMPLATE_KEY_SYMBOL].mount(element, this, parentScope);
  7190. this[ON_MOUNTED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  7191. return this;
  7192. },
  7193. update(state, parentScope) {
  7194. if (state === void 0) {
  7195. state = {};
  7196. }
  7197. if (parentScope) {
  7198. this[PARENT_KEY_SYMBOL] = parentScope;
  7199. this[ATTRIBUTES_KEY_SYMBOL].update(parentScope);
  7200. }
  7201. const newProps = evaluateAttributeExpressions(this[ATTRIBUTES_KEY_SYMBOL].expressions);
  7202. if (this[SHOULD_UPDATE_KEY](newProps, this[PROPS_KEY]) === false) return;
  7203. defineProperty(this, PROPS_KEY, Object.freeze(Object.assign({}, this[PROPS_KEY], newProps)));
  7204. this[STATE_KEY] = computeState(this[STATE_KEY], state);
  7205. this[ON_BEFORE_UPDATE_KEY](this[PROPS_KEY], this[STATE_KEY]); // avoiding recursive updates
  7206. // see also https://github.com/riot/riot/issues/2895
  7207. if (!this[IS_COMPONENT_UPDATING]) {
  7208. this[IS_COMPONENT_UPDATING] = true;
  7209. this[TEMPLATE_KEY_SYMBOL].update(this, this[PARENT_KEY_SYMBOL]);
  7210. }
  7211. this[ON_UPDATED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  7212. this[IS_COMPONENT_UPDATING] = false;
  7213. return this;
  7214. },
  7215. unmount(preserveRoot) {
  7216. this[ON_BEFORE_UNMOUNT_KEY](this[PROPS_KEY], this[STATE_KEY]);
  7217. this[ATTRIBUTES_KEY_SYMBOL].unmount(); // if the preserveRoot is null the template html will be left untouched
  7218. // in that case the DOM cleanup will happen differently from a parent node
  7219. this[TEMPLATE_KEY_SYMBOL].unmount(this, this[PARENT_KEY_SYMBOL], preserveRoot === null ? null : !preserveRoot);
  7220. this[ON_UNMOUNTED_KEY](this[PROPS_KEY], this[STATE_KEY]);
  7221. return this;
  7222. }
  7223. })), Object.keys(component).filter(prop => isFunction(component[prop])));
  7224. }
  7225. /**
  7226. * Component initialization function starting from a DOM node
  7227. * @param {HTMLElement} element - element to upgrade
  7228. * @param {Object} initialProps - initial component properties
  7229. * @param {string} componentName - component id
  7230. * @returns {Object} a new component instance bound to a DOM node
  7231. */
  7232. function mountComponent(element, initialProps, componentName) {
  7233. const name = componentName || getName(element);
  7234. if (!COMPONENTS_IMPLEMENTATION_MAP$1.has(name)) panic(`The component named "${name}" was never registered`);
  7235. const component = COMPONENTS_IMPLEMENTATION_MAP$1.get(name)({
  7236. props: initialProps
  7237. });
  7238. return component.mount(element);
  7239. }
  7240. /**
  7241. * Similar to compose but performs from left-to-right function composition.<br/>
  7242. * {@link https://30secondsofcode.org/function#composeright see also}
  7243. * @param {...[function]} fns) - list of unary function
  7244. * @returns {*} result of the computation
  7245. */
  7246. /**
  7247. * Performs right-to-left function composition.<br/>
  7248. * Use Array.prototype.reduce() to perform right-to-left function composition.<br/>
  7249. * The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.<br/>
  7250. * {@link https://30secondsofcode.org/function#compose original source code}
  7251. * @param {...[function]} fns) - list of unary function
  7252. * @returns {*} result of the computation
  7253. */
  7254. function compose() {
  7255. for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  7256. fns[_key2] = arguments[_key2];
  7257. }
  7258. return fns.reduce((f, g) => function () {
  7259. return f(g(...arguments));
  7260. });
  7261. }
  7262. const {
  7263. DOM_COMPONENT_INSTANCE_PROPERTY,
  7264. COMPONENTS_IMPLEMENTATION_MAP,
  7265. PLUGINS_SET
  7266. } = globals;
  7267. /**
  7268. * Riot public api
  7269. */
  7270. /**
  7271. * Register a custom tag by name
  7272. * @param {string} name - component name
  7273. * @param {Object} implementation - tag implementation
  7274. * @returns {Map} map containing all the components implementations
  7275. */
  7276. function register(name, _ref) {
  7277. let {
  7278. css,
  7279. template,
  7280. exports
  7281. } = _ref;
  7282. if (COMPONENTS_IMPLEMENTATION_MAP.has(name)) panic(`The component "${name}" was already registered`);
  7283. COMPONENTS_IMPLEMENTATION_MAP.set(name, createComponent({
  7284. name,
  7285. css,
  7286. template,
  7287. exports
  7288. }));
  7289. return COMPONENTS_IMPLEMENTATION_MAP;
  7290. }
  7291. /**
  7292. * Unregister a riot web component
  7293. * @param {string} name - component name
  7294. * @returns {Map} map containing all the components implementations
  7295. */
  7296. function unregister(name) {
  7297. if (!COMPONENTS_IMPLEMENTATION_MAP.has(name)) panic(`The component "${name}" was never registered`);
  7298. COMPONENTS_IMPLEMENTATION_MAP.delete(name);
  7299. cssManager.remove(name);
  7300. return COMPONENTS_IMPLEMENTATION_MAP;
  7301. }
  7302. /**
  7303. * Mounting function that will work only for the components that were globally registered
  7304. * @param {string|HTMLElement} selector - query for the selection or a DOM element
  7305. * @param {Object} initialProps - the initial component properties
  7306. * @param {string} name - optional component name
  7307. * @returns {Array} list of riot components
  7308. */
  7309. function mount(selector, initialProps, name) {
  7310. return $(selector).map(element => mountComponent(element, initialProps, name));
  7311. }
  7312. /**
  7313. * Sweet unmounting helper function for the DOM node mounted manually by the user
  7314. * @param {string|HTMLElement} selector - query for the selection or a DOM element
  7315. * @param {boolean|null} keepRootElement - if true keep the root element
  7316. * @returns {Array} list of nodes unmounted
  7317. */
  7318. function unmount(selector, keepRootElement) {
  7319. return $(selector).map(element => {
  7320. if (element[DOM_COMPONENT_INSTANCE_PROPERTY]) {
  7321. element[DOM_COMPONENT_INSTANCE_PROPERTY].unmount(keepRootElement);
  7322. }
  7323. return element;
  7324. });
  7325. }
  7326. /**
  7327. * Define a riot plugin
  7328. * @param {Function} plugin - function that will receive all the components created
  7329. * @returns {Set} the set containing all the plugins installed
  7330. */
  7331. function install(plugin) {
  7332. if (!isFunction(plugin)) panic('Plugins must be of type function');
  7333. if (PLUGINS_SET.has(plugin)) panic('This plugin was already installed');
  7334. PLUGINS_SET.add(plugin);
  7335. return PLUGINS_SET;
  7336. }
  7337. /**
  7338. * Uninstall a riot plugin
  7339. * @param {Function} plugin - plugin previously installed
  7340. * @returns {Set} the set containing all the plugins installed
  7341. */
  7342. function uninstall(plugin) {
  7343. if (!PLUGINS_SET.has(plugin)) panic('This plugin was never installed');
  7344. PLUGINS_SET.delete(plugin);
  7345. return PLUGINS_SET;
  7346. }
  7347. /**
  7348. * Helper method to create component without relying on the registered ones
  7349. * @param {Object} implementation - component implementation
  7350. * @returns {Function} function that will allow you to mount a riot component on a DOM node
  7351. */
  7352. function component(implementation) {
  7353. return function (el, props, _temp) {
  7354. let {
  7355. slots,
  7356. attributes,
  7357. parentScope
  7358. } = _temp === void 0 ? {} : _temp;
  7359. return compose(c => c.mount(el, parentScope), c => c({
  7360. props,
  7361. slots,
  7362. attributes
  7363. }), createComponent)(implementation);
  7364. };
  7365. }
  7366. /**
  7367. * Lift a riot component Interface into a pure riot object
  7368. * @param {Function} func - RiotPureComponent factory function
  7369. * @returns {Function} the lifted original function received as argument
  7370. */
  7371. function pure(func) {
  7372. if (!isFunction(func)) panic('riot.pure accepts only arguments of type "function"');
  7373. func[IS_PURE_SYMBOL] = true;
  7374. return func;
  7375. }
  7376. /**
  7377. * no-op function needed to add the proper types to your component via typescript
  7378. * @param {Function|Object} component - component default export
  7379. * @returns {Function|Object} returns exactly what it has received
  7380. */
  7381. const withTypes = component => component;
  7382. /** @type {string} current riot version */
  7383. const version = 'v6.0.1'; // expose some internal stuff that might be used from external tools
  7384. const __ = {
  7385. cssManager,
  7386. DOMBindings,
  7387. createComponent,
  7388. defineComponent,
  7389. globals
  7390. };
  7391. /***/ }),
  7392. /***/ "./node_modules/validate.js/validate.js":
  7393. /*!**********************************************!*\
  7394. !*** ./node_modules/validate.js/validate.js ***!
  7395. \**********************************************/
  7396. /***/ (function(module, exports, __webpack_require__) {
  7397. /* module decorator */ module = __webpack_require__.nmd(module);
  7398. /*!
  7399. * validate.js 0.13.1
  7400. *
  7401. * (c) 2013-2019 Nicklas Ansman, 2013 Wrapp
  7402. * Validate.js may be freely distributed under the MIT license.
  7403. * For all details and documentation:
  7404. * http://validatejs.org/
  7405. */
  7406. (function(exports, module, define) {
  7407. "use strict";
  7408. // The main function that calls the validators specified by the constraints.
  7409. // The options are the following:
  7410. // - format (string) - An option that controls how the returned value is formatted
  7411. // * flat - Returns a flat array of just the error messages
  7412. // * grouped - Returns the messages grouped by attribute (default)
  7413. // * detailed - Returns an array of the raw validation data
  7414. // - fullMessages (boolean) - If `true` (default) the attribute name is prepended to the error.
  7415. //
  7416. // Please note that the options are also passed to each validator.
  7417. var validate = function(attributes, constraints, options) {
  7418. options = v.extend({}, v.options, options);
  7419. var results = v.runValidations(attributes, constraints, options)
  7420. , attr
  7421. , validator;
  7422. if (results.some(function(r) { return v.isPromise(r.error); })) {
  7423. throw new Error("Use validate.async if you want support for promises");
  7424. }
  7425. return validate.processValidationResults(results, options);
  7426. };
  7427. var v = validate;
  7428. // Copies over attributes from one or more sources to a single destination.
  7429. // Very much similar to underscore's extend.
  7430. // The first argument is the target object and the remaining arguments will be
  7431. // used as sources.
  7432. v.extend = function(obj) {
  7433. [].slice.call(arguments, 1).forEach(function(source) {
  7434. for (var attr in source) {
  7435. obj[attr] = source[attr];
  7436. }
  7437. });
  7438. return obj;
  7439. };
  7440. v.extend(validate, {
  7441. // This is the version of the library as a semver.
  7442. // The toString function will allow it to be coerced into a string
  7443. version: {
  7444. major: 0,
  7445. minor: 13,
  7446. patch: 1,
  7447. metadata: null,
  7448. toString: function() {
  7449. var version = v.format("%{major}.%{minor}.%{patch}", v.version);
  7450. if (!v.isEmpty(v.version.metadata)) {
  7451. version += "+" + v.version.metadata;
  7452. }
  7453. return version;
  7454. }
  7455. },
  7456. // Below is the dependencies that are used in validate.js
  7457. // The constructor of the Promise implementation.
  7458. // If you are using Q.js, RSVP or any other A+ compatible implementation
  7459. // override this attribute to be the constructor of that promise.
  7460. // Since jQuery promises aren't A+ compatible they won't work.
  7461. Promise: typeof Promise !== "undefined" ? Promise : /* istanbul ignore next */ null,
  7462. EMPTY_STRING_REGEXP: /^\s*$/,
  7463. // Runs the validators specified by the constraints object.
  7464. // Will return an array of the format:
  7465. // [{attribute: "<attribute name>", error: "<validation result>"}, ...]
  7466. runValidations: function(attributes, constraints, options) {
  7467. var results = []
  7468. , attr
  7469. , validatorName
  7470. , value
  7471. , validators
  7472. , validator
  7473. , validatorOptions
  7474. , error;
  7475. if (v.isDomElement(attributes) || v.isJqueryElement(attributes)) {
  7476. attributes = v.collectFormValues(attributes);
  7477. }
  7478. // Loops through each constraints, finds the correct validator and run it.
  7479. for (attr in constraints) {
  7480. value = v.getDeepObjectValue(attributes, attr);
  7481. // This allows the constraints for an attribute to be a function.
  7482. // The function will be called with the value, attribute name, the complete dict of
  7483. // attributes as well as the options and constraints passed in.
  7484. // This is useful when you want to have different
  7485. // validations depending on the attribute value.
  7486. validators = v.result(constraints[attr], value, attributes, attr, options, constraints);
  7487. for (validatorName in validators) {
  7488. validator = v.validators[validatorName];
  7489. if (!validator) {
  7490. error = v.format("Unknown validator %{name}", {name: validatorName});
  7491. throw new Error(error);
  7492. }
  7493. validatorOptions = validators[validatorName];
  7494. // This allows the options to be a function. The function will be
  7495. // called with the value, attribute name, the complete dict of
  7496. // attributes as well as the options and constraints passed in.
  7497. // This is useful when you want to have different
  7498. // validations depending on the attribute value.
  7499. validatorOptions = v.result(validatorOptions, value, attributes, attr, options, constraints);
  7500. if (!validatorOptions) {
  7501. continue;
  7502. }
  7503. results.push({
  7504. attribute: attr,
  7505. value: value,
  7506. validator: validatorName,
  7507. globalOptions: options,
  7508. attributes: attributes,
  7509. options: validatorOptions,
  7510. error: validator.call(validator,
  7511. value,
  7512. validatorOptions,
  7513. attr,
  7514. attributes,
  7515. options)
  7516. });
  7517. }
  7518. }
  7519. return results;
  7520. },
  7521. // Takes the output from runValidations and converts it to the correct
  7522. // output format.
  7523. processValidationResults: function(errors, options) {
  7524. errors = v.pruneEmptyErrors(errors, options);
  7525. errors = v.expandMultipleErrors(errors, options);
  7526. errors = v.convertErrorMessages(errors, options);
  7527. var format = options.format || "grouped";
  7528. if (typeof v.formatters[format] === 'function') {
  7529. errors = v.formatters[format](errors);
  7530. } else {
  7531. throw new Error(v.format("Unknown format %{format}", options));
  7532. }
  7533. return v.isEmpty(errors) ? undefined : errors;
  7534. },
  7535. // Runs the validations with support for promises.
  7536. // This function will return a promise that is settled when all the
  7537. // validation promises have been completed.
  7538. // It can be called even if no validations returned a promise.
  7539. async: function(attributes, constraints, options) {
  7540. options = v.extend({}, v.async.options, options);
  7541. var WrapErrors = options.wrapErrors || function(errors) {
  7542. return errors;
  7543. };
  7544. // Removes unknown attributes
  7545. if (options.cleanAttributes !== false) {
  7546. attributes = v.cleanAttributes(attributes, constraints);
  7547. }
  7548. var results = v.runValidations(attributes, constraints, options);
  7549. return new v.Promise(function(resolve, reject) {
  7550. v.waitForResults(results).then(function() {
  7551. var errors = v.processValidationResults(results, options);
  7552. if (errors) {
  7553. reject(new WrapErrors(errors, options, attributes, constraints));
  7554. } else {
  7555. resolve(attributes);
  7556. }
  7557. }, function(err) {
  7558. reject(err);
  7559. });
  7560. });
  7561. },
  7562. single: function(value, constraints, options) {
  7563. options = v.extend({}, v.single.options, options, {
  7564. format: "flat",
  7565. fullMessages: false
  7566. });
  7567. return v({single: value}, {single: constraints}, options);
  7568. },
  7569. // Returns a promise that is resolved when all promises in the results array
  7570. // are settled. The promise returned from this function is always resolved,
  7571. // never rejected.
  7572. // This function modifies the input argument, it replaces the promises
  7573. // with the value returned from the promise.
  7574. waitForResults: function(results) {
  7575. // Create a sequence of all the results starting with a resolved promise.
  7576. return results.reduce(function(memo, result) {
  7577. // If this result isn't a promise skip it in the sequence.
  7578. if (!v.isPromise(result.error)) {
  7579. return memo;
  7580. }
  7581. return memo.then(function() {
  7582. return result.error.then(function(error) {
  7583. result.error = error || null;
  7584. });
  7585. });
  7586. }, new v.Promise(function(r) { r(); })); // A resolved promise
  7587. },
  7588. // If the given argument is a call: function the and: function return the value
  7589. // otherwise just return the value. Additional arguments will be passed as
  7590. // arguments to the function.
  7591. // Example:
  7592. // ```
  7593. // result('foo') // 'foo'
  7594. // result(Math.max, 1, 2) // 2
  7595. // ```
  7596. result: function(value) {
  7597. var args = [].slice.call(arguments, 1);
  7598. if (typeof value === 'function') {
  7599. value = value.apply(null, args);
  7600. }
  7601. return value;
  7602. },
  7603. // Checks if the value is a number. This function does not consider NaN a
  7604. // number like many other `isNumber` functions do.
  7605. isNumber: function(value) {
  7606. return typeof value === 'number' && !isNaN(value);
  7607. },
  7608. // Returns false if the object is not a function
  7609. isFunction: function(value) {
  7610. return typeof value === 'function';
  7611. },
  7612. // A simple check to verify that the value is an integer. Uses `isNumber`
  7613. // and a simple modulo check.
  7614. isInteger: function(value) {
  7615. return v.isNumber(value) && value % 1 === 0;
  7616. },
  7617. // Checks if the value is a boolean
  7618. isBoolean: function(value) {
  7619. return typeof value === 'boolean';
  7620. },
  7621. // Uses the `Object` function to check if the given argument is an object.
  7622. isObject: function(obj) {
  7623. return obj === Object(obj);
  7624. },
  7625. // Simply checks if the object is an instance of a date
  7626. isDate: function(obj) {
  7627. return obj instanceof Date;
  7628. },
  7629. // Returns false if the object is `null` of `undefined`
  7630. isDefined: function(obj) {
  7631. return obj !== null && obj !== undefined;
  7632. },
  7633. // Checks if the given argument is a promise. Anything with a `then`
  7634. // function is considered a promise.
  7635. isPromise: function(p) {
  7636. return !!p && v.isFunction(p.then);
  7637. },
  7638. isJqueryElement: function(o) {
  7639. return o && v.isString(o.jquery);
  7640. },
  7641. isDomElement: function(o) {
  7642. if (!o) {
  7643. return false;
  7644. }
  7645. if (!o.querySelectorAll || !o.querySelector) {
  7646. return false;
  7647. }
  7648. if (v.isObject(document) && o === document) {
  7649. return true;
  7650. }
  7651. // http://stackoverflow.com/a/384380/699304
  7652. /* istanbul ignore else */
  7653. if (typeof HTMLElement === "object") {
  7654. return o instanceof HTMLElement;
  7655. } else {
  7656. return o &&
  7657. typeof o === "object" &&
  7658. o !== null &&
  7659. o.nodeType === 1 &&
  7660. typeof o.nodeName === "string";
  7661. }
  7662. },
  7663. isEmpty: function(value) {
  7664. var attr;
  7665. // Null and undefined are empty
  7666. if (!v.isDefined(value)) {
  7667. return true;
  7668. }
  7669. // functions are non empty
  7670. if (v.isFunction(value)) {
  7671. return false;
  7672. }
  7673. // Whitespace only strings are empty
  7674. if (v.isString(value)) {
  7675. return v.EMPTY_STRING_REGEXP.test(value);
  7676. }
  7677. // For arrays we use the length property
  7678. if (v.isArray(value)) {
  7679. return value.length === 0;
  7680. }
  7681. // Dates have no attributes but aren't empty
  7682. if (v.isDate(value)) {
  7683. return false;
  7684. }
  7685. // If we find at least one property we consider it non empty
  7686. if (v.isObject(value)) {
  7687. for (attr in value) {
  7688. return false;
  7689. }
  7690. return true;
  7691. }
  7692. return false;
  7693. },
  7694. // Formats the specified strings with the given values like so:
  7695. // ```
  7696. // format("Foo: %{foo}", {foo: "bar"}) // "Foo bar"
  7697. // ```
  7698. // If you want to write %{...} without having it replaced simply
  7699. // prefix it with % like this `Foo: %%{foo}` and it will be returned
  7700. // as `"Foo: %{foo}"`
  7701. format: v.extend(function(str, vals) {
  7702. if (!v.isString(str)) {
  7703. return str;
  7704. }
  7705. return str.replace(v.format.FORMAT_REGEXP, function(m0, m1, m2) {
  7706. if (m1 === '%') {
  7707. return "%{" + m2 + "}";
  7708. } else {
  7709. return String(vals[m2]);
  7710. }
  7711. });
  7712. }, {
  7713. // Finds %{key} style patterns in the given string
  7714. FORMAT_REGEXP: /(%?)%\{([^\}]+)\}/g
  7715. }),
  7716. // "Prettifies" the given string.
  7717. // Prettifying means replacing [.\_-] with spaces as well as splitting
  7718. // camel case words.
  7719. prettify: function(str) {
  7720. if (v.isNumber(str)) {
  7721. // If there are more than 2 decimals round it to two
  7722. if ((str * 100) % 1 === 0) {
  7723. return "" + str;
  7724. } else {
  7725. return parseFloat(Math.round(str * 100) / 100).toFixed(2);
  7726. }
  7727. }
  7728. if (v.isArray(str)) {
  7729. return str.map(function(s) { return v.prettify(s); }).join(", ");
  7730. }
  7731. if (v.isObject(str)) {
  7732. if (!v.isDefined(str.toString)) {
  7733. return JSON.stringify(str);
  7734. }
  7735. return str.toString();
  7736. }
  7737. // Ensure the string is actually a string
  7738. str = "" + str;
  7739. return str
  7740. // Splits keys separated by periods
  7741. .replace(/([^\s])\.([^\s])/g, '$1 $2')
  7742. // Removes backslashes
  7743. .replace(/\\+/g, '')
  7744. // Replaces - and - with space
  7745. .replace(/[_-]/g, ' ')
  7746. // Splits camel cased words
  7747. .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {
  7748. return "" + m1 + " " + m2.toLowerCase();
  7749. })
  7750. .toLowerCase();
  7751. },
  7752. stringifyValue: function(value, options) {
  7753. var prettify = options && options.prettify || v.prettify;
  7754. return prettify(value);
  7755. },
  7756. isString: function(value) {
  7757. return typeof value === 'string';
  7758. },
  7759. isArray: function(value) {
  7760. return {}.toString.call(value) === '[object Array]';
  7761. },
  7762. // Checks if the object is a hash, which is equivalent to an object that
  7763. // is neither an array nor a function.
  7764. isHash: function(value) {
  7765. return v.isObject(value) && !v.isArray(value) && !v.isFunction(value);
  7766. },
  7767. contains: function(obj, value) {
  7768. if (!v.isDefined(obj)) {
  7769. return false;
  7770. }
  7771. if (v.isArray(obj)) {
  7772. return obj.indexOf(value) !== -1;
  7773. }
  7774. return value in obj;
  7775. },
  7776. unique: function(array) {
  7777. if (!v.isArray(array)) {
  7778. return array;
  7779. }
  7780. return array.filter(function(el, index, array) {
  7781. return array.indexOf(el) == index;
  7782. });
  7783. },
  7784. forEachKeyInKeypath: function(object, keypath, callback) {
  7785. if (!v.isString(keypath)) {
  7786. return undefined;
  7787. }
  7788. var key = ""
  7789. , i
  7790. , escape = false;
  7791. for (i = 0; i < keypath.length; ++i) {
  7792. switch (keypath[i]) {
  7793. case '.':
  7794. if (escape) {
  7795. escape = false;
  7796. key += '.';
  7797. } else {
  7798. object = callback(object, key, false);
  7799. key = "";
  7800. }
  7801. break;
  7802. case '\\':
  7803. if (escape) {
  7804. escape = false;
  7805. key += '\\';
  7806. } else {
  7807. escape = true;
  7808. }
  7809. break;
  7810. default:
  7811. escape = false;
  7812. key += keypath[i];
  7813. break;
  7814. }
  7815. }
  7816. return callback(object, key, true);
  7817. },
  7818. getDeepObjectValue: function(obj, keypath) {
  7819. if (!v.isObject(obj)) {
  7820. return undefined;
  7821. }
  7822. return v.forEachKeyInKeypath(obj, keypath, function(obj, key) {
  7823. if (v.isObject(obj)) {
  7824. return obj[key];
  7825. }
  7826. });
  7827. },
  7828. // This returns an object with all the values of the form.
  7829. // It uses the input name as key and the value as value
  7830. // So for example this:
  7831. // <input type="text" name="email" value="foo@bar.com" />
  7832. // would return:
  7833. // {email: "foo@bar.com"}
  7834. collectFormValues: function(form, options) {
  7835. var values = {}
  7836. , i
  7837. , j
  7838. , input
  7839. , inputs
  7840. , option
  7841. , value;
  7842. if (v.isJqueryElement(form)) {
  7843. form = form[0];
  7844. }
  7845. if (!form) {
  7846. return values;
  7847. }
  7848. options = options || {};
  7849. inputs = form.querySelectorAll("input[name], textarea[name]");
  7850. for (i = 0; i < inputs.length; ++i) {
  7851. input = inputs.item(i);
  7852. if (v.isDefined(input.getAttribute("data-ignored"))) {
  7853. continue;
  7854. }
  7855. var name = input.name.replace(/\./g, "\\\\.");
  7856. value = v.sanitizeFormValue(input.value, options);
  7857. if (input.type === "number") {
  7858. value = value ? +value : null;
  7859. } else if (input.type === "checkbox") {
  7860. if (input.attributes.value) {
  7861. if (!input.checked) {
  7862. value = values[name] || null;
  7863. }
  7864. } else {
  7865. value = input.checked;
  7866. }
  7867. } else if (input.type === "radio") {
  7868. if (!input.checked) {
  7869. value = values[name] || null;
  7870. }
  7871. }
  7872. values[name] = value;
  7873. }
  7874. inputs = form.querySelectorAll("select[name]");
  7875. for (i = 0; i < inputs.length; ++i) {
  7876. input = inputs.item(i);
  7877. if (v.isDefined(input.getAttribute("data-ignored"))) {
  7878. continue;
  7879. }
  7880. if (input.multiple) {
  7881. value = [];
  7882. for (j in input.options) {
  7883. option = input.options[j];
  7884. if (option && option.selected) {
  7885. value.push(v.sanitizeFormValue(option.value, options));
  7886. }
  7887. }
  7888. } else {
  7889. var _val = typeof input.options[input.selectedIndex] !== 'undefined' ? input.options[input.selectedIndex].value : /* istanbul ignore next */ '';
  7890. value = v.sanitizeFormValue(_val, options);
  7891. }
  7892. values[input.name] = value;
  7893. }
  7894. return values;
  7895. },
  7896. sanitizeFormValue: function(value, options) {
  7897. if (options.trim && v.isString(value)) {
  7898. value = value.trim();
  7899. }
  7900. if (options.nullify !== false && value === "") {
  7901. return null;
  7902. }
  7903. return value;
  7904. },
  7905. capitalize: function(str) {
  7906. if (!v.isString(str)) {
  7907. return str;
  7908. }
  7909. return str[0].toUpperCase() + str.slice(1);
  7910. },
  7911. // Remove all errors who's error attribute is empty (null or undefined)
  7912. pruneEmptyErrors: function(errors) {
  7913. return errors.filter(function(error) {
  7914. return !v.isEmpty(error.error);
  7915. });
  7916. },
  7917. // In
  7918. // [{error: ["err1", "err2"], ...}]
  7919. // Out
  7920. // [{error: "err1", ...}, {error: "err2", ...}]
  7921. //
  7922. // All attributes in an error with multiple messages are duplicated
  7923. // when expanding the errors.
  7924. expandMultipleErrors: function(errors) {
  7925. var ret = [];
  7926. errors.forEach(function(error) {
  7927. // Removes errors without a message
  7928. if (v.isArray(error.error)) {
  7929. error.error.forEach(function(msg) {
  7930. ret.push(v.extend({}, error, {error: msg}));
  7931. });
  7932. } else {
  7933. ret.push(error);
  7934. }
  7935. });
  7936. return ret;
  7937. },
  7938. // Converts the error mesages by prepending the attribute name unless the
  7939. // message is prefixed by ^
  7940. convertErrorMessages: function(errors, options) {
  7941. options = options || {};
  7942. var ret = []
  7943. , prettify = options.prettify || v.prettify;
  7944. errors.forEach(function(errorInfo) {
  7945. var error = v.result(errorInfo.error,
  7946. errorInfo.value,
  7947. errorInfo.attribute,
  7948. errorInfo.options,
  7949. errorInfo.attributes,
  7950. errorInfo.globalOptions);
  7951. if (!v.isString(error)) {
  7952. ret.push(errorInfo);
  7953. return;
  7954. }
  7955. if (error[0] === '^') {
  7956. error = error.slice(1);
  7957. } else if (options.fullMessages !== false) {
  7958. error = v.capitalize(prettify(errorInfo.attribute)) + " " + error;
  7959. }
  7960. error = error.replace(/\\\^/g, "^");
  7961. error = v.format(error, {
  7962. value: v.stringifyValue(errorInfo.value, options)
  7963. });
  7964. ret.push(v.extend({}, errorInfo, {error: error}));
  7965. });
  7966. return ret;
  7967. },
  7968. // In:
  7969. // [{attribute: "<attributeName>", ...}]
  7970. // Out:
  7971. // {"<attributeName>": [{attribute: "<attributeName>", ...}]}
  7972. groupErrorsByAttribute: function(errors) {
  7973. var ret = {};
  7974. errors.forEach(function(error) {
  7975. var list = ret[error.attribute];
  7976. if (list) {
  7977. list.push(error);
  7978. } else {
  7979. ret[error.attribute] = [error];
  7980. }
  7981. });
  7982. return ret;
  7983. },
  7984. // In:
  7985. // [{error: "<message 1>", ...}, {error: "<message 2>", ...}]
  7986. // Out:
  7987. // ["<message 1>", "<message 2>"]
  7988. flattenErrorsToArray: function(errors) {
  7989. return errors
  7990. .map(function(error) { return error.error; })
  7991. .filter(function(value, index, self) {
  7992. return self.indexOf(value) === index;
  7993. });
  7994. },
  7995. cleanAttributes: function(attributes, whitelist) {
  7996. function whitelistCreator(obj, key, last) {
  7997. if (v.isObject(obj[key])) {
  7998. return obj[key];
  7999. }
  8000. return (obj[key] = last ? true : {});
  8001. }
  8002. function buildObjectWhitelist(whitelist) {
  8003. var ow = {}
  8004. , lastObject
  8005. , attr;
  8006. for (attr in whitelist) {
  8007. if (!whitelist[attr]) {
  8008. continue;
  8009. }
  8010. v.forEachKeyInKeypath(ow, attr, whitelistCreator);
  8011. }
  8012. return ow;
  8013. }
  8014. function cleanRecursive(attributes, whitelist) {
  8015. if (!v.isObject(attributes)) {
  8016. return attributes;
  8017. }
  8018. var ret = v.extend({}, attributes)
  8019. , w
  8020. , attribute;
  8021. for (attribute in attributes) {
  8022. w = whitelist[attribute];
  8023. if (v.isObject(w)) {
  8024. ret[attribute] = cleanRecursive(ret[attribute], w);
  8025. } else if (!w) {
  8026. delete ret[attribute];
  8027. }
  8028. }
  8029. return ret;
  8030. }
  8031. if (!v.isObject(whitelist) || !v.isObject(attributes)) {
  8032. return {};
  8033. }
  8034. whitelist = buildObjectWhitelist(whitelist);
  8035. return cleanRecursive(attributes, whitelist);
  8036. },
  8037. exposeModule: function(validate, root, exports, module, define) {
  8038. if (exports) {
  8039. if (module && module.exports) {
  8040. exports = module.exports = validate;
  8041. }
  8042. exports.validate = validate;
  8043. } else {
  8044. root.validate = validate;
  8045. if (validate.isFunction(define) && define.amd) {
  8046. define([], function () { return validate; });
  8047. }
  8048. }
  8049. },
  8050. warn: function(msg) {
  8051. if (typeof console !== "undefined" && console.warn) {
  8052. console.warn("[validate.js] " + msg);
  8053. }
  8054. },
  8055. error: function(msg) {
  8056. if (typeof console !== "undefined" && console.error) {
  8057. console.error("[validate.js] " + msg);
  8058. }
  8059. }
  8060. });
  8061. validate.validators = {
  8062. // Presence validates that the value isn't empty
  8063. presence: function(value, options) {
  8064. options = v.extend({}, this.options, options);
  8065. if (options.allowEmpty !== false ? !v.isDefined(value) : v.isEmpty(value)) {
  8066. return options.message || this.message || "can't be blank";
  8067. }
  8068. },
  8069. length: function(value, options, attribute) {
  8070. // Empty values are allowed
  8071. if (!v.isDefined(value)) {
  8072. return;
  8073. }
  8074. options = v.extend({}, this.options, options);
  8075. var is = options.is
  8076. , maximum = options.maximum
  8077. , minimum = options.minimum
  8078. , tokenizer = options.tokenizer || function(val) { return val; }
  8079. , err
  8080. , errors = [];
  8081. value = tokenizer(value);
  8082. var length = value.length;
  8083. if(!v.isNumber(length)) {
  8084. return options.message || this.notValid || "has an incorrect length";
  8085. }
  8086. // Is checks
  8087. if (v.isNumber(is) && length !== is) {
  8088. err = options.wrongLength ||
  8089. this.wrongLength ||
  8090. "is the wrong length (should be %{count} characters)";
  8091. errors.push(v.format(err, {count: is}));
  8092. }
  8093. if (v.isNumber(minimum) && length < minimum) {
  8094. err = options.tooShort ||
  8095. this.tooShort ||
  8096. "is too short (minimum is %{count} characters)";
  8097. errors.push(v.format(err, {count: minimum}));
  8098. }
  8099. if (v.isNumber(maximum) && length > maximum) {
  8100. err = options.tooLong ||
  8101. this.tooLong ||
  8102. "is too long (maximum is %{count} characters)";
  8103. errors.push(v.format(err, {count: maximum}));
  8104. }
  8105. if (errors.length > 0) {
  8106. return options.message || errors;
  8107. }
  8108. },
  8109. numericality: function(value, options, attribute, attributes, globalOptions) {
  8110. // Empty values are fine
  8111. if (!v.isDefined(value)) {
  8112. return;
  8113. }
  8114. options = v.extend({}, this.options, options);
  8115. var errors = []
  8116. , name
  8117. , count
  8118. , checks = {
  8119. greaterThan: function(v, c) { return v > c; },
  8120. greaterThanOrEqualTo: function(v, c) { return v >= c; },
  8121. equalTo: function(v, c) { return v === c; },
  8122. lessThan: function(v, c) { return v < c; },
  8123. lessThanOrEqualTo: function(v, c) { return v <= c; },
  8124. divisibleBy: function(v, c) { return v % c === 0; }
  8125. }
  8126. , prettify = options.prettify ||
  8127. (globalOptions && globalOptions.prettify) ||
  8128. v.prettify;
  8129. // Strict will check that it is a valid looking number
  8130. if (v.isString(value) && options.strict) {
  8131. var pattern = "^-?(0|[1-9]\\d*)";
  8132. if (!options.onlyInteger) {
  8133. pattern += "(\\.\\d+)?";
  8134. }
  8135. pattern += "$";
  8136. if (!(new RegExp(pattern).test(value))) {
  8137. return options.message ||
  8138. options.notValid ||
  8139. this.notValid ||
  8140. this.message ||
  8141. "must be a valid number";
  8142. }
  8143. }
  8144. // Coerce the value to a number unless we're being strict.
  8145. if (options.noStrings !== true && v.isString(value) && !v.isEmpty(value)) {
  8146. value = +value;
  8147. }
  8148. // If it's not a number we shouldn't continue since it will compare it.
  8149. if (!v.isNumber(value)) {
  8150. return options.message ||
  8151. options.notValid ||
  8152. this.notValid ||
  8153. this.message ||
  8154. "is not a number";
  8155. }
  8156. // Same logic as above, sort of. Don't bother with comparisons if this
  8157. // doesn't pass.
  8158. if (options.onlyInteger && !v.isInteger(value)) {
  8159. return options.message ||
  8160. options.notInteger ||
  8161. this.notInteger ||
  8162. this.message ||
  8163. "must be an integer";
  8164. }
  8165. for (name in checks) {
  8166. count = options[name];
  8167. if (v.isNumber(count) && !checks[name](value, count)) {
  8168. // This picks the default message if specified
  8169. // For example the greaterThan check uses the message from
  8170. // this.notGreaterThan so we capitalize the name and prepend "not"
  8171. var key = "not" + v.capitalize(name);
  8172. var msg = options[key] ||
  8173. this[key] ||
  8174. this.message ||
  8175. "must be %{type} %{count}";
  8176. errors.push(v.format(msg, {
  8177. count: count,
  8178. type: prettify(name)
  8179. }));
  8180. }
  8181. }
  8182. if (options.odd && value % 2 !== 1) {
  8183. errors.push(options.notOdd ||
  8184. this.notOdd ||
  8185. this.message ||
  8186. "must be odd");
  8187. }
  8188. if (options.even && value % 2 !== 0) {
  8189. errors.push(options.notEven ||
  8190. this.notEven ||
  8191. this.message ||
  8192. "must be even");
  8193. }
  8194. if (errors.length) {
  8195. return options.message || errors;
  8196. }
  8197. },
  8198. datetime: v.extend(function(value, options) {
  8199. if (!v.isFunction(this.parse) || !v.isFunction(this.format)) {
  8200. throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");
  8201. }
  8202. // Empty values are fine
  8203. if (!v.isDefined(value)) {
  8204. return;
  8205. }
  8206. options = v.extend({}, this.options, options);
  8207. var err
  8208. , errors = []
  8209. , earliest = options.earliest ? this.parse(options.earliest, options) : NaN
  8210. , latest = options.latest ? this.parse(options.latest, options) : NaN;
  8211. value = this.parse(value, options);
  8212. // 86400000 is the number of milliseconds in a day, this is used to remove
  8213. // the time from the date
  8214. if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
  8215. err = options.notValid ||
  8216. options.message ||
  8217. this.notValid ||
  8218. "must be a valid date";
  8219. return v.format(err, {value: arguments[0]});
  8220. }
  8221. if (!isNaN(earliest) && value < earliest) {
  8222. err = options.tooEarly ||
  8223. options.message ||
  8224. this.tooEarly ||
  8225. "must be no earlier than %{date}";
  8226. err = v.format(err, {
  8227. value: this.format(value, options),
  8228. date: this.format(earliest, options)
  8229. });
  8230. errors.push(err);
  8231. }
  8232. if (!isNaN(latest) && value > latest) {
  8233. err = options.tooLate ||
  8234. options.message ||
  8235. this.tooLate ||
  8236. "must be no later than %{date}";
  8237. err = v.format(err, {
  8238. date: this.format(latest, options),
  8239. value: this.format(value, options)
  8240. });
  8241. errors.push(err);
  8242. }
  8243. if (errors.length) {
  8244. return v.unique(errors);
  8245. }
  8246. }, {
  8247. parse: null,
  8248. format: null
  8249. }),
  8250. date: function(value, options) {
  8251. options = v.extend({}, options, {dateOnly: true});
  8252. return v.validators.datetime.call(v.validators.datetime, value, options);
  8253. },
  8254. format: function(value, options) {
  8255. if (v.isString(options) || (options instanceof RegExp)) {
  8256. options = {pattern: options};
  8257. }
  8258. options = v.extend({}, this.options, options);
  8259. var message = options.message || this.message || "is invalid"
  8260. , pattern = options.pattern
  8261. , match;
  8262. // Empty values are allowed
  8263. if (!v.isDefined(value)) {
  8264. return;
  8265. }
  8266. if (!v.isString(value)) {
  8267. return message;
  8268. }
  8269. if (v.isString(pattern)) {
  8270. pattern = new RegExp(options.pattern, options.flags);
  8271. }
  8272. match = pattern.exec(value);
  8273. if (!match || match[0].length != value.length) {
  8274. return message;
  8275. }
  8276. },
  8277. inclusion: function(value, options) {
  8278. // Empty values are fine
  8279. if (!v.isDefined(value)) {
  8280. return;
  8281. }
  8282. if (v.isArray(options)) {
  8283. options = {within: options};
  8284. }
  8285. options = v.extend({}, this.options, options);
  8286. if (v.contains(options.within, value)) {
  8287. return;
  8288. }
  8289. var message = options.message ||
  8290. this.message ||
  8291. "^%{value} is not included in the list";
  8292. return v.format(message, {value: value});
  8293. },
  8294. exclusion: function(value, options) {
  8295. // Empty values are fine
  8296. if (!v.isDefined(value)) {
  8297. return;
  8298. }
  8299. if (v.isArray(options)) {
  8300. options = {within: options};
  8301. }
  8302. options = v.extend({}, this.options, options);
  8303. if (!v.contains(options.within, value)) {
  8304. return;
  8305. }
  8306. var message = options.message || this.message || "^%{value} is restricted";
  8307. if (v.isString(options.within[value])) {
  8308. value = options.within[value];
  8309. }
  8310. return v.format(message, {value: value});
  8311. },
  8312. email: v.extend(function(value, options) {
  8313. options = v.extend({}, this.options, options);
  8314. var message = options.message || this.message || "is not a valid email";
  8315. // Empty values are fine
  8316. if (!v.isDefined(value)) {
  8317. return;
  8318. }
  8319. if (!v.isString(value)) {
  8320. return message;
  8321. }
  8322. if (!this.PATTERN.exec(value)) {
  8323. return message;
  8324. }
  8325. }, {
  8326. 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
  8327. }),
  8328. equality: function(value, options, attribute, attributes, globalOptions) {
  8329. if (!v.isDefined(value)) {
  8330. return;
  8331. }
  8332. if (v.isString(options)) {
  8333. options = {attribute: options};
  8334. }
  8335. options = v.extend({}, this.options, options);
  8336. var message = options.message ||
  8337. this.message ||
  8338. "is not equal to %{attribute}";
  8339. if (v.isEmpty(options.attribute) || !v.isString(options.attribute)) {
  8340. throw new Error("The attribute must be a non empty string");
  8341. }
  8342. var otherValue = v.getDeepObjectValue(attributes, options.attribute)
  8343. , comparator = options.comparator || function(v1, v2) {
  8344. return v1 === v2;
  8345. }
  8346. , prettify = options.prettify ||
  8347. (globalOptions && globalOptions.prettify) ||
  8348. v.prettify;
  8349. if (!comparator(value, otherValue, options, attribute, attributes)) {
  8350. return v.format(message, {attribute: prettify(options.attribute)});
  8351. }
  8352. },
  8353. // A URL validator that is used to validate URLs with the ability to
  8354. // restrict schemes and some domains.
  8355. url: function(value, options) {
  8356. if (!v.isDefined(value)) {
  8357. return;
  8358. }
  8359. options = v.extend({}, this.options, options);
  8360. var message = options.message || this.message || "is not a valid url"
  8361. , schemes = options.schemes || this.schemes || ['http', 'https']
  8362. , allowLocal = options.allowLocal || this.allowLocal || false
  8363. , allowDataUrl = options.allowDataUrl || this.allowDataUrl || false;
  8364. if (!v.isString(value)) {
  8365. return message;
  8366. }
  8367. // https://gist.github.com/dperini/729294
  8368. var regex =
  8369. "^" +
  8370. // protocol identifier
  8371. "(?:(?:" + schemes.join("|") + ")://)" +
  8372. // user:pass authentication
  8373. "(?:\\S+(?::\\S*)?@)?" +
  8374. "(?:";
  8375. var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
  8376. if (allowLocal) {
  8377. tld += "?";
  8378. } else {
  8379. regex +=
  8380. // IP address exclusion
  8381. // private & local networks
  8382. "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  8383. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  8384. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})";
  8385. }
  8386. regex +=
  8387. // IP address dotted notation octets
  8388. // excludes loopback network 0.0.0.0
  8389. // excludes reserved space >= 224.0.0.0
  8390. // excludes network & broacast addresses
  8391. // (first & last IP address of each class)
  8392. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  8393. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  8394. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  8395. "|" +
  8396. // host name
  8397. "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
  8398. // domain name
  8399. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
  8400. tld +
  8401. ")" +
  8402. // port number
  8403. "(?::\\d{2,5})?" +
  8404. // resource path
  8405. "(?:[/?#]\\S*)?" +
  8406. "$";
  8407. if (allowDataUrl) {
  8408. // RFC 2397
  8409. var mediaType = "\\w+\\/[-+.\\w]+(?:;[\\w=]+)*";
  8410. var urlchar = "[A-Za-z0-9-_.!~\\*'();\\/?:@&=+$,%]*";
  8411. var dataurl = "data:(?:"+mediaType+")?(?:;base64)?,"+urlchar;
  8412. regex = "(?:"+regex+")|(?:^"+dataurl+"$)";
  8413. }
  8414. var PATTERN = new RegExp(regex, 'i');
  8415. if (!PATTERN.exec(value)) {
  8416. return message;
  8417. }
  8418. },
  8419. type: v.extend(function(value, originalOptions, attribute, attributes, globalOptions) {
  8420. if (v.isString(originalOptions)) {
  8421. originalOptions = {type: originalOptions};
  8422. }
  8423. if (!v.isDefined(value)) {
  8424. return;
  8425. }
  8426. var options = v.extend({}, this.options, originalOptions);
  8427. var type = options.type;
  8428. if (!v.isDefined(type)) {
  8429. throw new Error("No type was specified");
  8430. }
  8431. var check;
  8432. if (v.isFunction(type)) {
  8433. check = type;
  8434. } else {
  8435. check = this.types[type];
  8436. }
  8437. if (!v.isFunction(check)) {
  8438. throw new Error("validate.validators.type.types." + type + " must be a function.");
  8439. }
  8440. if (!check(value, options, attribute, attributes, globalOptions)) {
  8441. var message = originalOptions.message ||
  8442. this.messages[type] ||
  8443. this.message ||
  8444. options.message ||
  8445. (v.isFunction(type) ? "must be of the correct type" : "must be of type %{type}");
  8446. if (v.isFunction(message)) {
  8447. message = message(value, originalOptions, attribute, attributes, globalOptions);
  8448. }
  8449. return v.format(message, {attribute: v.prettify(attribute), type: type});
  8450. }
  8451. }, {
  8452. types: {
  8453. object: function(value) {
  8454. return v.isObject(value) && !v.isArray(value);
  8455. },
  8456. array: v.isArray,
  8457. integer: v.isInteger,
  8458. number: v.isNumber,
  8459. string: v.isString,
  8460. date: v.isDate,
  8461. boolean: v.isBoolean
  8462. },
  8463. messages: {}
  8464. })
  8465. };
  8466. validate.formatters = {
  8467. detailed: function(errors) {return errors;},
  8468. flat: v.flattenErrorsToArray,
  8469. grouped: function(errors) {
  8470. var attr;
  8471. errors = v.groupErrorsByAttribute(errors);
  8472. for (attr in errors) {
  8473. errors[attr] = v.flattenErrorsToArray(errors[attr]);
  8474. }
  8475. return errors;
  8476. },
  8477. constraint: function(errors) {
  8478. var attr;
  8479. errors = v.groupErrorsByAttribute(errors);
  8480. for (attr in errors) {
  8481. errors[attr] = errors[attr].map(function(result) {
  8482. return result.validator;
  8483. }).sort();
  8484. }
  8485. return errors;
  8486. }
  8487. };
  8488. validate.exposeModule(validate, this, exports, module, __webpack_require__.amdD);
  8489. }).call(this,
  8490. true ? /* istanbul ignore next */ exports : 0,
  8491. true ? /* istanbul ignore next */ module : 0,
  8492. __webpack_require__.amdD);
  8493. /***/ })
  8494. /******/ });
  8495. /************************************************************************/
  8496. /******/ // The module cache
  8497. /******/ var __webpack_module_cache__ = {};
  8498. /******/
  8499. /******/ // The require function
  8500. /******/ function __webpack_require__(moduleId) {
  8501. /******/ // Check if module is in cache
  8502. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  8503. /******/ if (cachedModule !== undefined) {
  8504. /******/ return cachedModule.exports;
  8505. /******/ }
  8506. /******/ // Create a new module (and put it into the cache)
  8507. /******/ var module = __webpack_module_cache__[moduleId] = {
  8508. /******/ id: moduleId,
  8509. /******/ loaded: false,
  8510. /******/ exports: {}
  8511. /******/ };
  8512. /******/
  8513. /******/ // Execute the module function
  8514. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  8515. /******/
  8516. /******/ // Flag the module as loaded
  8517. /******/ module.loaded = true;
  8518. /******/
  8519. /******/ // Return the exports of the module
  8520. /******/ return module.exports;
  8521. /******/ }
  8522. /******/
  8523. /************************************************************************/
  8524. /******/ /* webpack/runtime/amd define */
  8525. /******/ (() => {
  8526. /******/ __webpack_require__.amdD = function () {
  8527. /******/ throw new Error('define cannot be used indirect');
  8528. /******/ };
  8529. /******/ })();
  8530. /******/
  8531. /******/ /* webpack/runtime/compat get default export */
  8532. /******/ (() => {
  8533. /******/ // getDefaultExport function for compatibility with non-harmony modules
  8534. /******/ __webpack_require__.n = (module) => {
  8535. /******/ var getter = module && module.__esModule ?
  8536. /******/ () => (module['default']) :
  8537. /******/ () => (module);
  8538. /******/ __webpack_require__.d(getter, { a: getter });
  8539. /******/ return getter;
  8540. /******/ };
  8541. /******/ })();
  8542. /******/
  8543. /******/ /* webpack/runtime/define property getters */
  8544. /******/ (() => {
  8545. /******/ // define getter functions for harmony exports
  8546. /******/ __webpack_require__.d = (exports, definition) => {
  8547. /******/ for(var key in definition) {
  8548. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  8549. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  8550. /******/ }
  8551. /******/ }
  8552. /******/ };
  8553. /******/ })();
  8554. /******/
  8555. /******/ /* webpack/runtime/global */
  8556. /******/ (() => {
  8557. /******/ __webpack_require__.g = (function() {
  8558. /******/ if (typeof globalThis === 'object') return globalThis;
  8559. /******/ try {
  8560. /******/ return this || new Function('return this')();
  8561. /******/ } catch (e) {
  8562. /******/ if (typeof window === 'object') return window;
  8563. /******/ }
  8564. /******/ })();
  8565. /******/ })();
  8566. /******/
  8567. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  8568. /******/ (() => {
  8569. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  8570. /******/ })();
  8571. /******/
  8572. /******/ /* webpack/runtime/make namespace object */
  8573. /******/ (() => {
  8574. /******/ // define __esModule on exports
  8575. /******/ __webpack_require__.r = (exports) => {
  8576. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  8577. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  8578. /******/ }
  8579. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  8580. /******/ };
  8581. /******/ })();
  8582. /******/
  8583. /******/ /* webpack/runtime/node module decorator */
  8584. /******/ (() => {
  8585. /******/ __webpack_require__.nmd = (module) => {
  8586. /******/ module.paths = [];
  8587. /******/ if (!module.children) module.children = [];
  8588. /******/ return module;
  8589. /******/ };
  8590. /******/ })();
  8591. /******/
  8592. /************************************************************************/
  8593. var __webpack_exports__ = {};
  8594. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  8595. (() => {
  8596. "use strict";
  8597. /*!*******************************!*\
  8598. !*** ./resources/js/users.js ***!
  8599. \*******************************/
  8600. __webpack_require__.r(__webpack_exports__);
  8601. /* harmony import */ var riot__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! riot */ "./node_modules/riot/riot.esm.js");
  8602. /* harmony import */ var _components_users_riot__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./components/users.riot */ "./resources/js/components/users.riot");
  8603. /* harmony import */ var _components_users_form_riot__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/users/form.riot */ "./resources/js/components/users/form.riot");
  8604. /* harmony import */ var _components_sidebar_button_riot__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./components/sidebar-button.riot */ "./resources/js/components/sidebar-button.riot");
  8605. // register components for buckets
  8606. riot__WEBPACK_IMPORTED_MODULE_3__.register('app-users', _components_users_riot__WEBPACK_IMPORTED_MODULE_0__.default);
  8607. riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-users');
  8608. riot__WEBPACK_IMPORTED_MODULE_3__.register('app-users-form', _components_users_form_riot__WEBPACK_IMPORTED_MODULE_1__.default);
  8609. riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-users-form');
  8610. riot__WEBPACK_IMPORTED_MODULE_3__.register('app-sidebar-button', _components_sidebar_button_riot__WEBPACK_IMPORTED_MODULE_2__.default);
  8611. riot__WEBPACK_IMPORTED_MODULE_3__.mount('app-sidebar-button');
  8612. })();
  8613. /******/ })()
  8614. ;