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.

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