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.

9943 lines
285 KiB

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