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.

9663 lines
278 KiB

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