wcs-core 2.5.2 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +17 -1
- package/dist/cjs/component-fc28ed16.js +1074 -0
- package/dist/cjs/helpers-6abce594.js +86 -0
- package/dist/cjs/{index-e05c3e1f.js → index-3cb9d725.js} +165 -87
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/{esm/wcs-action-bar_47.entry.js → cjs/lodash-776d6f03.js} +12499 -22628
- package/dist/cjs/popper-6a290c40.js +1731 -0
- package/dist/cjs/select-arrow-76ccf86d.js +36 -0
- package/dist/cjs/wcs-action-bar.cjs.entry.js +24 -0
- package/dist/cjs/wcs-app.cjs.entry.js +2 -2
- package/dist/cjs/wcs-badge.cjs.entry.js +27 -0
- package/dist/cjs/wcs-button.cjs.entry.js +86 -0
- package/dist/cjs/wcs-card-body.cjs.entry.js +19 -0
- package/dist/cjs/wcs-card.cjs.entry.js +20 -0
- package/dist/cjs/wcs-checkbox.cjs.entry.js +47 -0
- package/dist/cjs/wcs-com-nav-category.cjs.entry.js +63 -0
- package/dist/cjs/wcs-com-nav-submenu.cjs.entry.js +69 -0
- package/dist/cjs/wcs-com-nav.cjs.entry.js +19 -0
- package/dist/cjs/wcs-divider.cjs.entry.js +19 -0
- package/dist/cjs/wcs-dropdown-divider.cjs.entry.js +19 -0
- package/dist/cjs/wcs-dropdown-header.cjs.entry.js +19 -0
- package/dist/cjs/wcs-dropdown-item.cjs.entry.js +23 -0
- package/dist/cjs/wcs-dropdown.cjs.entry.js +90 -0
- package/dist/cjs/wcs-editable-field.cjs.entry.js +225 -0
- package/dist/cjs/wcs-error_2.cjs.entry.js +137 -0
- package/dist/cjs/wcs-field-content.cjs.entry.js +16 -0
- package/dist/cjs/wcs-field-label.cjs.entry.js +16 -0
- package/dist/cjs/wcs-field.cjs.entry.js +19 -0
- package/dist/cjs/wcs-footer.cjs.entry.js +19 -0
- package/dist/cjs/wcs-galactic-menu.cjs.entry.js +58 -0
- package/dist/cjs/wcs-galactic.cjs.entry.js +41 -0
- package/dist/cjs/wcs-grid-column.cjs.entry.js +77 -0
- package/dist/cjs/wcs-grid-custom-cell.cjs.entry.js +16 -0
- package/dist/cjs/wcs-grid-pagination.cjs.entry.js +4 -4
- package/dist/cjs/wcs-grid.cjs.entry.js +332 -0
- package/dist/cjs/wcs-header.cjs.entry.js +25 -0
- package/dist/cjs/wcs-hint.cjs.entry.js +20 -0
- package/dist/cjs/wcs-horizontal-stepper.cjs.entry.js +114 -0
- package/dist/cjs/wcs-icon.cjs.entry.js +2 -2
- package/dist/cjs/wcs-input.cjs.entry.js +228 -0
- package/dist/cjs/wcs-label.cjs.entry.js +20 -0
- package/dist/cjs/wcs-list-item-properties.cjs.entry.js +19 -0
- package/dist/cjs/wcs-list-item-property.cjs.entry.js +19 -0
- package/dist/cjs/wcs-list-item.cjs.entry.js +23 -0
- package/dist/cjs/wcs-mat-icon.cjs.entry.js +73 -0
- package/dist/cjs/wcs-modal.cjs.entry.js +45 -0
- package/dist/cjs/wcs-nav-item.cjs.entry.js +23 -0
- package/dist/cjs/wcs-nav.cjs.entry.js +19 -0
- package/dist/cjs/wcs-progress-bar.cjs.entry.js +47 -0
- package/dist/cjs/wcs-progress-radial.cjs.entry.js +30 -0
- package/dist/cjs/wcs-radio-group.cjs.entry.js +65 -0
- package/dist/cjs/wcs-radio.cjs.entry.js +49 -0
- package/dist/cjs/wcs-select_2.cjs.entry.js +4916 -0
- package/dist/cjs/wcs-spinner.cjs.entry.js +21 -0
- package/dist/cjs/wcs-switch.cjs.entry.js +42 -0
- package/dist/cjs/wcs-tab.cjs.entry.js +20 -0
- package/dist/cjs/wcs-tabs.cjs.entry.js +159 -0
- package/dist/cjs/wcs-textarea.cjs.entry.js +224 -0
- package/dist/cjs/wcs-tooltip.cjs.entry.js +129 -0
- package/dist/cjs/wcs.cjs.js +3 -3
- package/dist/collection/collection-manifest.json +5 -2
- package/dist/collection/components/button/button.css +79 -75
- package/dist/collection/components/button/button.js +23 -11
- package/dist/collection/components/checkbox/checkbox.css +18 -7
- package/dist/collection/components/checkbox/checkbox.js +24 -2
- package/dist/collection/components/com-nav/com-nav.css +1 -2
- package/dist/collection/components/com-nav-category/com-nav-category.css +5 -6
- package/dist/collection/components/com-nav-category/com-nav-category.js +31 -1
- package/dist/collection/components/com-nav-submenu/com-nav-submenu.css +1 -2
- package/dist/collection/components/com-nav-submenu/com-nav-submenu.js +21 -1
- package/dist/collection/components/dropdown/dropdown-interface.js +1 -0
- package/dist/collection/components/dropdown/dropdown.css +46 -38
- package/dist/collection/components/dropdown/dropdown.js +90 -29
- package/dist/collection/components/dropdown-divider/dropdown-divider.css +7 -0
- package/dist/collection/components/dropdown-divider/dropdown-divider.js +14 -0
- package/dist/collection/components/dropdown-header/dropdown-header.css +8 -0
- package/dist/collection/components/dropdown-header/dropdown-header.js +15 -0
- package/dist/collection/components/footer/footer.css +1 -1
- package/dist/collection/components/form-field/form-field.css +1 -1
- package/dist/collection/components/grid/grid.js +75 -13
- package/dist/collection/components/grid-column/grid-column.css +5 -0
- package/dist/collection/components/grid-column/grid-column.js +69 -3
- package/dist/collection/components/grid-custom-cell/grid-custom-cell.js +45 -0
- package/dist/collection/components/grid-pagination/grid-pagination.js +4 -4
- package/dist/collection/components/header/header.css +1 -1
- package/dist/collection/components/input/input.css +48 -0
- package/dist/collection/components/input/input.js +40 -4
- package/dist/collection/components/radio/radio.component.js +1 -1
- package/dist/collection/components/radio/radio.css +18 -4
- package/dist/collection/components/radio-group/radio-group.js +7 -2
- package/dist/collection/components/select/select.css +81 -77
- package/dist/collection/components/select/select.js +2 -2
- package/dist/collection/components/select-option/select-option.css +79 -75
- package/dist/collection/components/select-option/select-option.js +6 -7
- package/dist/collection/components/switch/switch.css +53 -16
- package/dist/collection/components/switch/switch.js +55 -6
- package/dist/collection/components/tab/tab.js +4 -4
- package/dist/collection/components/tabs/tabs.js +1 -1
- package/dist/collection/components/textarea/textarea.css +4 -0
- package/dist/collection/components/textarea/textarea.js +2 -2
- package/dist/collection/components/tooltip/tooltip.js +2 -2
- package/dist/collection/utils/helpers.js +4 -0
- package/dist/esm/component-6b4d470f.js +1072 -0
- package/dist/esm/helpers-e2993152.js +77 -0
- package/dist/esm/{index-c619b1fa.js → index-b982604a.js} +165 -88
- package/dist/esm/loader.js +3 -3
- package/dist/{cjs/wcs-action-bar_47.cjs.entry.js → esm/lodash-d6d9d079.js} +12610 -22791
- package/dist/esm/popper-e5fdfb6a.js +1729 -0
- package/dist/esm/select-arrow-73ac4016.js +34 -0
- package/dist/esm/wcs-action-bar.entry.js +20 -0
- package/dist/esm/wcs-app.entry.js +2 -2
- package/dist/esm/wcs-badge.entry.js +23 -0
- package/dist/esm/wcs-button.entry.js +82 -0
- package/dist/esm/wcs-card-body.entry.js +15 -0
- package/dist/esm/wcs-card.entry.js +16 -0
- package/dist/esm/wcs-checkbox.entry.js +43 -0
- package/dist/esm/wcs-com-nav-category.entry.js +59 -0
- package/dist/esm/wcs-com-nav-submenu.entry.js +65 -0
- package/dist/esm/wcs-com-nav.entry.js +15 -0
- package/dist/esm/wcs-divider.entry.js +15 -0
- package/dist/esm/wcs-dropdown-divider.entry.js +15 -0
- package/dist/esm/wcs-dropdown-header.entry.js +15 -0
- package/dist/esm/wcs-dropdown-item.entry.js +19 -0
- package/dist/esm/wcs-dropdown.entry.js +86 -0
- package/dist/esm/wcs-editable-field.entry.js +221 -0
- package/dist/esm/wcs-error_2.entry.js +132 -0
- package/dist/esm/wcs-field-content.entry.js +12 -0
- package/dist/esm/wcs-field-label.entry.js +12 -0
- package/dist/esm/wcs-field.entry.js +15 -0
- package/dist/esm/wcs-footer.entry.js +15 -0
- package/dist/esm/wcs-galactic-menu.entry.js +54 -0
- package/dist/esm/wcs-galactic.entry.js +37 -0
- package/dist/esm/wcs-grid-column.entry.js +73 -0
- package/dist/esm/wcs-grid-custom-cell.entry.js +12 -0
- package/dist/esm/wcs-grid-pagination.entry.js +4 -4
- package/dist/esm/wcs-grid.entry.js +328 -0
- package/dist/esm/wcs-header.entry.js +21 -0
- package/dist/esm/wcs-hint.entry.js +16 -0
- package/dist/esm/wcs-horizontal-stepper.entry.js +110 -0
- package/dist/esm/wcs-icon.entry.js +2 -2
- package/dist/esm/wcs-input.entry.js +224 -0
- package/dist/esm/wcs-label.entry.js +16 -0
- package/dist/esm/wcs-list-item-properties.entry.js +15 -0
- package/dist/esm/wcs-list-item-property.entry.js +15 -0
- package/dist/esm/wcs-list-item.entry.js +19 -0
- package/dist/esm/wcs-mat-icon.entry.js +69 -0
- package/dist/esm/wcs-modal.entry.js +41 -0
- package/dist/esm/wcs-nav-item.entry.js +19 -0
- package/dist/esm/wcs-nav.entry.js +15 -0
- package/dist/esm/wcs-progress-bar.entry.js +43 -0
- package/dist/esm/wcs-progress-radial.entry.js +26 -0
- package/dist/esm/wcs-radio-group.entry.js +61 -0
- package/dist/esm/wcs-radio.entry.js +45 -0
- package/dist/esm/wcs-select_2.entry.js +4911 -0
- package/dist/esm/wcs-spinner.entry.js +17 -0
- package/dist/esm/wcs-switch.entry.js +38 -0
- package/dist/esm/wcs-tab.entry.js +16 -0
- package/dist/esm/wcs-tabs.entry.js +155 -0
- package/dist/esm/wcs-textarea.entry.js +220 -0
- package/dist/esm/wcs-tooltip.entry.js +125 -0
- package/dist/esm/wcs.js +3 -3
- package/dist/types/components/button/button.d.ts +7 -3
- package/dist/types/components/checkbox/checkbox.d.ts +4 -0
- package/dist/types/components/com-nav-category/com-nav-category.d.ts +7 -0
- package/dist/types/components/com-nav-submenu/com-nav-submenu.d.ts +7 -0
- package/dist/types/components/dropdown/dropdown-interface.d.ts +1 -0
- package/dist/types/components/dropdown/dropdown.d.ts +13 -16
- package/dist/types/components/dropdown-divider/dropdown-divider.d.ts +3 -0
- package/dist/types/components/dropdown-header/dropdown-header.d.ts +3 -0
- package/dist/types/components/grid/grid.d.ts +18 -0
- package/dist/types/components/grid-column/grid-column.d.ts +5 -0
- package/dist/types/components/grid-custom-cell/grid-custom-cell.d.ts +12 -0
- package/dist/types/components/input/input.d.ts +8 -0
- package/dist/types/components/radio-group/radio-group-interface.d.ts +1 -0
- package/dist/types/components/radio-group/radio-group.d.ts +2 -2
- package/dist/types/components/select-option/select-option.d.ts +2 -0
- package/dist/types/components/switch/switch-interface.d.ts +1 -0
- package/dist/types/components/switch/switch.d.ts +10 -2
- package/dist/types/components.d.ts +148 -4
- package/dist/types/stencil-public-runtime.d.ts +183 -182
- package/dist/types/utils/helpers.d.ts +1 -0
- package/dist/wcs/p-03b2e238.entry.js +1 -0
- package/dist/wcs/p-15008e35.entry.js +1 -0
- package/dist/wcs/p-16dfbae8.js +127 -0
- package/dist/wcs/p-17c6db7f.entry.js +1 -0
- package/dist/wcs/p-1dce7e63.entry.js +1 -0
- package/dist/wcs/p-1f5aed36.entry.js +1 -0
- package/dist/wcs/p-214236db.entry.js +1 -0
- package/dist/wcs/p-26b5c0a3.entry.js +1 -0
- package/dist/wcs/p-2e6265dc.entry.js +1 -0
- package/dist/wcs/p-384068f7.entry.js +1 -0
- package/dist/wcs/p-41037455.entry.js +1 -0
- package/dist/wcs/p-474d6601.entry.js +1 -0
- package/dist/wcs/p-55fdc284.entry.js +1 -0
- package/dist/wcs/p-57247184.entry.js +1 -0
- package/dist/wcs/p-5b35b232.entry.js +1 -0
- package/dist/wcs/p-600a9cc0.entry.js +1 -0
- package/dist/wcs/p-60b51967.entry.js +1 -0
- package/dist/wcs/p-64523291.entry.js +1 -0
- package/dist/wcs/p-65c5ccc5.entry.js +1 -0
- package/dist/wcs/p-688fea65.entry.js +1 -0
- package/dist/wcs/p-716d5921.entry.js +1 -0
- package/dist/wcs/p-7206e492.entry.js +1 -0
- package/dist/wcs/p-7219c04b.js +1 -0
- package/dist/wcs/p-8137f075.entry.js +1 -0
- package/dist/wcs/p-8864a491.entry.js +1 -0
- package/dist/wcs/p-8c8740e3.entry.js +1 -0
- package/dist/wcs/p-91a2de07.entry.js +1 -0
- package/dist/wcs/p-94a31f64.entry.js +1 -0
- package/dist/wcs/p-979dfd78.entry.js +1 -0
- package/dist/wcs/p-9ba52bc4.entry.js +1 -0
- package/dist/wcs/p-a1ee1551.entry.js +1 -0
- package/dist/wcs/p-a92d369e.entry.js +1 -0
- package/dist/wcs/p-a978c1e3.entry.js +1 -0
- package/dist/wcs/p-adef7aaf.js +1 -0
- package/dist/wcs/p-b5138986.js +1 -0
- package/dist/wcs/p-b7184d59.entry.js +1 -0
- package/dist/wcs/p-bbf1ef42.entry.js +1 -0
- package/dist/wcs/p-c7d6d3e1.entry.js +15 -0
- package/dist/wcs/p-cf4d7a83.js +1 -0
- package/dist/wcs/p-d7dec082.entry.js +1 -0
- package/dist/wcs/p-db68379f.entry.js +1 -0
- package/dist/wcs/p-dbbc3f58.entry.js +1 -0
- package/dist/wcs/p-dc817204.entry.js +1 -0
- package/dist/wcs/p-e0163de8.entry.js +1 -0
- package/dist/wcs/p-e4236d32.entry.js +1 -0
- package/dist/wcs/p-e43358e4.entry.js +1 -0
- package/dist/wcs/p-e65d1c27.entry.js +1 -0
- package/dist/wcs/p-e9ce507c.entry.js +1 -0
- package/dist/wcs/p-ea3e93e9.entry.js +1 -0
- package/dist/wcs/p-ed6e8541.entry.js +1 -0
- package/dist/wcs/p-f46e6c3c.js +1 -0
- package/dist/wcs/p-f9944bde.entry.js +1 -0
- package/dist/wcs/p-fa173947.entry.js +1 -0
- package/dist/wcs/p-fb1577b5.entry.js +1 -0
- package/dist/wcs/p-fbaf299d.entry.js +1 -0
- package/dist/wcs/p-febe9ccc.entry.js +1 -0
- package/dist/wcs/p-ff6d0dfd.entry.js +1 -0
- package/dist/wcs/wcs.esm.js +1 -1
- package/loader/index.d.ts +0 -1
- package/package.json +22 -21
- package/dist/wcs/p-16dca526.entry.js +0 -1
- package/dist/wcs/p-4f228fcb.entry.js +0 -134
- package/dist/wcs/p-66520e5a.entry.js +0 -1
- package/dist/wcs/p-d31287c6.entry.js +0 -1
- package/dist/wcs/p-f73f235b.js +0 -1
- package/schematics/.gitignore +0 -18
- package/schematics/.npmignore +0 -4
- package/schematics/collection.json +0 -9
- package/schematics/src/ng-add/files/fonts/avenir-black.woff +0 -0
- package/schematics/src/ng-add/files/fonts/avenir-book.woff +0 -0
- package/schematics/src/ng-add/files/fonts/avenir-lighter.woff +0 -0
- package/schematics/src/ng-add/files/fonts/avenir-medium.woff +0 -0
- package/schematics/src/ng-add/files/sncf-logo.png +0 -0
- package/schematics/src/ng-add/index.d.ts +0 -3
- package/schematics/src/ng-add/index.js +0 -119
- package/schematics/src/ng-add/index.js.map +0 -1
- package/schematics/src/ng-add/schema.json +0 -5
|
@@ -0,0 +1,4916 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const index = require('./index-3cb9d725.js');
|
|
6
|
+
const lodash = require('./lodash-776d6f03.js');
|
|
7
|
+
const selectArrow = require('./select-arrow-76ccf86d.js');
|
|
8
|
+
const helpers = require('./helpers-6abce594.js');
|
|
9
|
+
const component = require('./component-fc28ed16.js');
|
|
10
|
+
|
|
11
|
+
/*! *****************************************************************************
|
|
12
|
+
Copyright (c) Microsoft Corporation.
|
|
13
|
+
|
|
14
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
+
purpose with or without fee is hereby granted.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
+
***************************************************************************** */
|
|
25
|
+
var __assign = function () {
|
|
26
|
+
__assign = Object.assign || function __assign(t) {
|
|
27
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
28
|
+
s = arguments[i];
|
|
29
|
+
|
|
30
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return t;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return __assign.apply(this, arguments);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function __rest(s, e) {
|
|
40
|
+
var t = {};
|
|
41
|
+
|
|
42
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
43
|
+
|
|
44
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
45
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function __values(o) {
|
|
51
|
+
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
52
|
+
m = s && o[s],
|
|
53
|
+
i = 0;
|
|
54
|
+
if (m) return m.call(o);
|
|
55
|
+
if (o && typeof o.length === "number") return {
|
|
56
|
+
next: function () {
|
|
57
|
+
if (o && i >= o.length) o = void 0;
|
|
58
|
+
return {
|
|
59
|
+
value: o && o[i++],
|
|
60
|
+
done: !o
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __read(o, n) {
|
|
68
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
69
|
+
if (!m) return o;
|
|
70
|
+
var i = m.call(o),
|
|
71
|
+
r,
|
|
72
|
+
ar = [],
|
|
73
|
+
e;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
e = {
|
|
79
|
+
error: error
|
|
80
|
+
};
|
|
81
|
+
} finally {
|
|
82
|
+
try {
|
|
83
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
84
|
+
} finally {
|
|
85
|
+
if (e) throw e.error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return ar;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function __spread() {
|
|
93
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
94
|
+
|
|
95
|
+
return ar;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var STATE_DELIMITER = '.';
|
|
99
|
+
var EMPTY_ACTIVITY_MAP = {};
|
|
100
|
+
var DEFAULT_GUARD_TYPE = 'xstate.guard';
|
|
101
|
+
var TARGETLESS_KEY = '';
|
|
102
|
+
|
|
103
|
+
function keys(value) {
|
|
104
|
+
return Object.keys(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function matchesState(parentStateId, childStateId, delimiter) {
|
|
108
|
+
if (delimiter === void 0) {
|
|
109
|
+
delimiter = STATE_DELIMITER;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var parentStateValue = toStateValue(parentStateId, delimiter);
|
|
113
|
+
var childStateValue = toStateValue(childStateId, delimiter);
|
|
114
|
+
|
|
115
|
+
if (isString(childStateValue)) {
|
|
116
|
+
if (isString(parentStateValue)) {
|
|
117
|
+
return childStateValue === parentStateValue;
|
|
118
|
+
} // Parent more specific than child
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (isString(parentStateValue)) {
|
|
125
|
+
return parentStateValue in childStateValue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return keys(parentStateValue).every(function (key) {
|
|
129
|
+
if (!(key in childStateValue)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return matchesState(parentStateValue[key], childStateValue[key]);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function getEventType(event) {
|
|
138
|
+
try {
|
|
139
|
+
return isString(event) || typeof event === 'number' ? "" + event : event.type;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw new Error('Events must be strings or objects with a string event.type property.');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function toStatePath(stateId, delimiter) {
|
|
146
|
+
try {
|
|
147
|
+
if (isArray(stateId)) {
|
|
148
|
+
return stateId;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return stateId.toString().split(delimiter);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
throw new Error("'" + stateId + "' is not a valid state path.");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function isStateLike(state) {
|
|
158
|
+
return typeof state === 'object' && 'value' in state && 'context' in state && 'event' in state && '_event' in state;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function toStateValue(stateValue, delimiter) {
|
|
162
|
+
if (isStateLike(stateValue)) {
|
|
163
|
+
return stateValue.value;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (isArray(stateValue)) {
|
|
167
|
+
return pathToStateValue(stateValue);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof stateValue !== 'string') {
|
|
171
|
+
return stateValue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var statePath = toStatePath(stateValue, delimiter);
|
|
175
|
+
return pathToStateValue(statePath);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function pathToStateValue(statePath) {
|
|
179
|
+
if (statePath.length === 1) {
|
|
180
|
+
return statePath[0];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var value = {};
|
|
184
|
+
var marker = value;
|
|
185
|
+
|
|
186
|
+
for (var i = 0; i < statePath.length - 1; i++) {
|
|
187
|
+
if (i === statePath.length - 2) {
|
|
188
|
+
marker[statePath[i]] = statePath[i + 1];
|
|
189
|
+
} else {
|
|
190
|
+
marker[statePath[i]] = {};
|
|
191
|
+
marker = marker[statePath[i]];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function mapValues(collection, iteratee) {
|
|
199
|
+
var result = {};
|
|
200
|
+
var collectionKeys = keys(collection);
|
|
201
|
+
|
|
202
|
+
for (var i = 0; i < collectionKeys.length; i++) {
|
|
203
|
+
var key = collectionKeys[i];
|
|
204
|
+
result[key] = iteratee(collection[key], key, collection, i);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function mapFilterValues(collection, iteratee, predicate) {
|
|
211
|
+
var e_1, _a;
|
|
212
|
+
|
|
213
|
+
var result = {};
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
for (var _b = __values(keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
217
|
+
var key = _c.value;
|
|
218
|
+
var item = collection[key];
|
|
219
|
+
|
|
220
|
+
if (!predicate(item)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
result[key] = iteratee(item, key, collection);
|
|
225
|
+
}
|
|
226
|
+
} catch (e_1_1) {
|
|
227
|
+
e_1 = {
|
|
228
|
+
error: e_1_1
|
|
229
|
+
};
|
|
230
|
+
} finally {
|
|
231
|
+
try {
|
|
232
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
233
|
+
} finally {
|
|
234
|
+
if (e_1) throw e_1.error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Retrieves a value at the given path.
|
|
242
|
+
* @param props The deep path to the prop of the desired value
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
var path = function (props) {
|
|
247
|
+
return function (object) {
|
|
248
|
+
var e_2, _a;
|
|
249
|
+
|
|
250
|
+
var result = object;
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
|
|
254
|
+
var prop = props_1_1.value;
|
|
255
|
+
result = result[prop];
|
|
256
|
+
}
|
|
257
|
+
} catch (e_2_1) {
|
|
258
|
+
e_2 = {
|
|
259
|
+
error: e_2_1
|
|
260
|
+
};
|
|
261
|
+
} finally {
|
|
262
|
+
try {
|
|
263
|
+
if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
|
|
264
|
+
} finally {
|
|
265
|
+
if (e_2) throw e_2.error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return result;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Retrieves a value at the given path via the nested accessor prop.
|
|
274
|
+
* @param props The deep path to the prop of the desired value
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
function nestedPath(props, accessorProp) {
|
|
279
|
+
return function (object) {
|
|
280
|
+
var e_3, _a;
|
|
281
|
+
|
|
282
|
+
var result = object;
|
|
283
|
+
|
|
284
|
+
try {
|
|
285
|
+
for (var props_2 = __values(props), props_2_1 = props_2.next(); !props_2_1.done; props_2_1 = props_2.next()) {
|
|
286
|
+
var prop = props_2_1.value;
|
|
287
|
+
result = result[accessorProp][prop];
|
|
288
|
+
}
|
|
289
|
+
} catch (e_3_1) {
|
|
290
|
+
e_3 = {
|
|
291
|
+
error: e_3_1
|
|
292
|
+
};
|
|
293
|
+
} finally {
|
|
294
|
+
try {
|
|
295
|
+
if (props_2_1 && !props_2_1.done && (_a = props_2.return)) _a.call(props_2);
|
|
296
|
+
} finally {
|
|
297
|
+
if (e_3) throw e_3.error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return result;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function toStatePaths(stateValue) {
|
|
306
|
+
if (!stateValue) {
|
|
307
|
+
return [[]];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (isString(stateValue)) {
|
|
311
|
+
return [[stateValue]];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
var result = flatten(keys(stateValue).map(function (key) {
|
|
315
|
+
var subStateValue = stateValue[key];
|
|
316
|
+
|
|
317
|
+
if (typeof subStateValue !== 'string' && (!subStateValue || !Object.keys(subStateValue).length)) {
|
|
318
|
+
return [[key]];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return toStatePaths(stateValue[key]).map(function (subPath) {
|
|
322
|
+
return [key].concat(subPath);
|
|
323
|
+
});
|
|
324
|
+
}));
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function flatten(array) {
|
|
329
|
+
var _a;
|
|
330
|
+
|
|
331
|
+
return (_a = []).concat.apply(_a, __spread(array));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function toArrayStrict(value) {
|
|
335
|
+
if (isArray(value)) {
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return [value];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function toArray(value) {
|
|
343
|
+
if (value === undefined) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return toArrayStrict(value);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function mapContext(mapper, context, _event) {
|
|
351
|
+
var e_5, _a;
|
|
352
|
+
|
|
353
|
+
if (isFunction(mapper)) {
|
|
354
|
+
return mapper(context, _event.data);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
var result = {};
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
for (var _b = __values(Object.keys(mapper)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
361
|
+
var key = _c.value;
|
|
362
|
+
var subMapper = mapper[key];
|
|
363
|
+
|
|
364
|
+
if (isFunction(subMapper)) {
|
|
365
|
+
result[key] = subMapper(context, _event.data);
|
|
366
|
+
} else {
|
|
367
|
+
result[key] = subMapper;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} catch (e_5_1) {
|
|
371
|
+
e_5 = {
|
|
372
|
+
error: e_5_1
|
|
373
|
+
};
|
|
374
|
+
} finally {
|
|
375
|
+
try {
|
|
376
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
377
|
+
} finally {
|
|
378
|
+
if (e_5) throw e_5.error;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function isBuiltInEvent(eventType) {
|
|
386
|
+
return /^(done|error)\./.test(eventType);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function isPromiseLike(value) {
|
|
390
|
+
if (value instanceof Promise) {
|
|
391
|
+
return true;
|
|
392
|
+
} // Check if shape matches the Promise/A+ specification for a "thenable".
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
if (value !== null && (isFunction(value) || typeof value === 'object') && isFunction(value.then)) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function partition(items, predicate) {
|
|
403
|
+
var e_6, _a;
|
|
404
|
+
|
|
405
|
+
var _b = __read([[], []], 2),
|
|
406
|
+
truthy = _b[0],
|
|
407
|
+
falsy = _b[1];
|
|
408
|
+
|
|
409
|
+
try {
|
|
410
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
411
|
+
var item = items_1_1.value;
|
|
412
|
+
|
|
413
|
+
if (predicate(item)) {
|
|
414
|
+
truthy.push(item);
|
|
415
|
+
} else {
|
|
416
|
+
falsy.push(item);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} catch (e_6_1) {
|
|
420
|
+
e_6 = {
|
|
421
|
+
error: e_6_1
|
|
422
|
+
};
|
|
423
|
+
} finally {
|
|
424
|
+
try {
|
|
425
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
426
|
+
} finally {
|
|
427
|
+
if (e_6) throw e_6.error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return [truthy, falsy];
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function updateHistoryStates(hist, stateValue) {
|
|
435
|
+
return mapValues(hist.states, function (subHist, key) {
|
|
436
|
+
if (!subHist) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
var subStateValue = (isString(stateValue) ? undefined : stateValue[key]) || (subHist ? subHist.current : undefined);
|
|
441
|
+
|
|
442
|
+
if (!subStateValue) {
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
current: subStateValue,
|
|
448
|
+
states: updateHistoryStates(subHist, subStateValue)
|
|
449
|
+
};
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function updateHistoryValue(hist, stateValue) {
|
|
454
|
+
return {
|
|
455
|
+
current: stateValue,
|
|
456
|
+
states: updateHistoryStates(hist, stateValue)
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function updateContext(context, _event, assignActions, state) {
|
|
461
|
+
|
|
462
|
+
var updatedContext = context ? assignActions.reduce(function (acc, assignAction) {
|
|
463
|
+
var e_7, _a;
|
|
464
|
+
|
|
465
|
+
var assignment = assignAction.assignment;
|
|
466
|
+
var meta = {
|
|
467
|
+
state: state,
|
|
468
|
+
action: assignAction,
|
|
469
|
+
_event: _event
|
|
470
|
+
};
|
|
471
|
+
var partialUpdate = {};
|
|
472
|
+
|
|
473
|
+
if (isFunction(assignment)) {
|
|
474
|
+
partialUpdate = assignment(acc, _event.data, meta);
|
|
475
|
+
} else {
|
|
476
|
+
try {
|
|
477
|
+
for (var _b = __values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
478
|
+
var key = _c.value;
|
|
479
|
+
var propAssignment = assignment[key];
|
|
480
|
+
partialUpdate[key] = isFunction(propAssignment) ? propAssignment(acc, _event.data, meta) : propAssignment;
|
|
481
|
+
}
|
|
482
|
+
} catch (e_7_1) {
|
|
483
|
+
e_7 = {
|
|
484
|
+
error: e_7_1
|
|
485
|
+
};
|
|
486
|
+
} finally {
|
|
487
|
+
try {
|
|
488
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
489
|
+
} finally {
|
|
490
|
+
if (e_7) throw e_7.error;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return Object.assign({}, acc, partialUpdate);
|
|
496
|
+
}, context) : context;
|
|
497
|
+
return updatedContext;
|
|
498
|
+
} // tslint:disable-next-line:no-empty
|
|
499
|
+
|
|
500
|
+
function isArray(value) {
|
|
501
|
+
return Array.isArray(value);
|
|
502
|
+
} // tslint:disable-next-line:ban-types
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
function isFunction(value) {
|
|
506
|
+
return typeof value === 'function';
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function isString(value) {
|
|
510
|
+
return typeof value === 'string';
|
|
511
|
+
} // export function memoizedGetter<T, TP extends { prototype: object }>(
|
|
512
|
+
// o: TP,
|
|
513
|
+
// property: string,
|
|
514
|
+
// getter: () => T
|
|
515
|
+
// ): void {
|
|
516
|
+
// Object.defineProperty(o.prototype, property, {
|
|
517
|
+
// get: getter,
|
|
518
|
+
// enumerable: false,
|
|
519
|
+
// configurable: false
|
|
520
|
+
// });
|
|
521
|
+
// }
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
function toGuard(condition, guardMap) {
|
|
525
|
+
if (!condition) {
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (isString(condition)) {
|
|
530
|
+
return {
|
|
531
|
+
type: DEFAULT_GUARD_TYPE,
|
|
532
|
+
name: condition,
|
|
533
|
+
predicate: guardMap ? guardMap[condition] : undefined
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (isFunction(condition)) {
|
|
538
|
+
return {
|
|
539
|
+
type: DEFAULT_GUARD_TYPE,
|
|
540
|
+
name: condition.name,
|
|
541
|
+
predicate: condition
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return condition;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function isObservable(value) {
|
|
549
|
+
try {
|
|
550
|
+
return 'subscribe' in value && isFunction(value.subscribe);
|
|
551
|
+
} catch (e) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
var symbolObservable = /*#__PURE__*/function () {
|
|
557
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
558
|
+
}();
|
|
559
|
+
|
|
560
|
+
function isMachine(value) {
|
|
561
|
+
try {
|
|
562
|
+
return '__xstatenode' in value;
|
|
563
|
+
} catch (e) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function isActor$1(value) {
|
|
569
|
+
return !!value && typeof value.send === 'function';
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function toEventObject(event, payload // id?: TEvent['type']
|
|
573
|
+
) {
|
|
574
|
+
if (isString(event) || typeof event === 'number') {
|
|
575
|
+
return __assign({
|
|
576
|
+
type: event
|
|
577
|
+
}, payload);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return event;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function toSCXMLEvent(event, scxmlEvent) {
|
|
584
|
+
if (!isString(event) && '$$type' in event && event.$$type === 'scxml') {
|
|
585
|
+
return event;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
var eventObject = toEventObject(event);
|
|
589
|
+
return __assign({
|
|
590
|
+
name: eventObject.type,
|
|
591
|
+
data: eventObject,
|
|
592
|
+
$$type: 'scxml',
|
|
593
|
+
type: 'external'
|
|
594
|
+
}, scxmlEvent);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function toTransitionConfigArray(event, configLike) {
|
|
598
|
+
var transitions = toArrayStrict(configLike).map(function (transitionLike) {
|
|
599
|
+
if (typeof transitionLike === 'undefined' || typeof transitionLike === 'string' || isMachine(transitionLike)) {
|
|
600
|
+
return {
|
|
601
|
+
target: transitionLike,
|
|
602
|
+
event: event
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return __assign(__assign({}, transitionLike), {
|
|
607
|
+
event: event
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
return transitions;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function normalizeTarget(target) {
|
|
614
|
+
if (target === undefined || target === TARGETLESS_KEY) {
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
return toArray(target);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function evaluateGuard(machine, guard, context, _event, state) {
|
|
622
|
+
var guards = machine.options.guards;
|
|
623
|
+
var guardMeta = {
|
|
624
|
+
state: state,
|
|
625
|
+
cond: guard,
|
|
626
|
+
_event: _event
|
|
627
|
+
}; // TODO: do not hardcode!
|
|
628
|
+
|
|
629
|
+
if (guard.type === DEFAULT_GUARD_TYPE) {
|
|
630
|
+
return guard.predicate(context, _event.data, guardMeta);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
var condFn = guards[guard.type];
|
|
634
|
+
|
|
635
|
+
if (!condFn) {
|
|
636
|
+
throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return condFn(context, _event.data, guardMeta);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function toInvokeSource$1(src) {
|
|
643
|
+
if (typeof src === 'string') {
|
|
644
|
+
return {
|
|
645
|
+
type: src
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return src;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
653
|
+
if (typeof nextHandler === 'object') {
|
|
654
|
+
return nextHandler;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
var noop = function () {
|
|
658
|
+
return void 0;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
return {
|
|
662
|
+
next: nextHandler,
|
|
663
|
+
error: errorHandler || noop,
|
|
664
|
+
complete: completionHandler || noop
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
var ActionTypes;
|
|
669
|
+
|
|
670
|
+
(function (ActionTypes) {
|
|
671
|
+
ActionTypes["Start"] = "xstate.start";
|
|
672
|
+
ActionTypes["Stop"] = "xstate.stop";
|
|
673
|
+
ActionTypes["Raise"] = "xstate.raise";
|
|
674
|
+
ActionTypes["Send"] = "xstate.send";
|
|
675
|
+
ActionTypes["Cancel"] = "xstate.cancel";
|
|
676
|
+
ActionTypes["NullEvent"] = "";
|
|
677
|
+
ActionTypes["Assign"] = "xstate.assign";
|
|
678
|
+
ActionTypes["After"] = "xstate.after";
|
|
679
|
+
ActionTypes["DoneState"] = "done.state";
|
|
680
|
+
ActionTypes["DoneInvoke"] = "done.invoke";
|
|
681
|
+
ActionTypes["Log"] = "xstate.log";
|
|
682
|
+
ActionTypes["Init"] = "xstate.init";
|
|
683
|
+
ActionTypes["Invoke"] = "xstate.invoke";
|
|
684
|
+
ActionTypes["ErrorExecution"] = "error.execution";
|
|
685
|
+
ActionTypes["ErrorCommunication"] = "error.communication";
|
|
686
|
+
ActionTypes["ErrorPlatform"] = "error.platform";
|
|
687
|
+
ActionTypes["ErrorCustom"] = "xstate.error";
|
|
688
|
+
ActionTypes["Update"] = "xstate.update";
|
|
689
|
+
ActionTypes["Pure"] = "xstate.pure";
|
|
690
|
+
ActionTypes["Choose"] = "xstate.choose";
|
|
691
|
+
})(ActionTypes || (ActionTypes = {}));
|
|
692
|
+
|
|
693
|
+
var SpecialTargets;
|
|
694
|
+
|
|
695
|
+
(function (SpecialTargets) {
|
|
696
|
+
SpecialTargets["Parent"] = "#_parent";
|
|
697
|
+
SpecialTargets["Internal"] = "#_internal";
|
|
698
|
+
})(SpecialTargets || (SpecialTargets = {}));
|
|
699
|
+
|
|
700
|
+
var start$1 = ActionTypes.Start;
|
|
701
|
+
var stop$1 = ActionTypes.Stop;
|
|
702
|
+
var raise$1 = ActionTypes.Raise;
|
|
703
|
+
var send$1 = ActionTypes.Send;
|
|
704
|
+
var cancel$1 = ActionTypes.Cancel;
|
|
705
|
+
var nullEvent = ActionTypes.NullEvent;
|
|
706
|
+
var assign = ActionTypes.Assign;
|
|
707
|
+
var log = ActionTypes.Log;
|
|
708
|
+
var init = ActionTypes.Init;
|
|
709
|
+
var invoke = ActionTypes.Invoke;
|
|
710
|
+
var errorPlatform = ActionTypes.ErrorPlatform;
|
|
711
|
+
var error$1 = ActionTypes.ErrorCustom;
|
|
712
|
+
var update = ActionTypes.Update;
|
|
713
|
+
var choose = ActionTypes.Choose;
|
|
714
|
+
var pure = ActionTypes.Pure;
|
|
715
|
+
|
|
716
|
+
var initEvent = /*#__PURE__*/toSCXMLEvent({
|
|
717
|
+
type: init
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
function getActionFunction(actionType, actionFunctionMap) {
|
|
721
|
+
return actionFunctionMap ? actionFunctionMap[actionType] || undefined : undefined;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function toActionObject(action, actionFunctionMap) {
|
|
725
|
+
var actionObject;
|
|
726
|
+
|
|
727
|
+
if (isString(action) || typeof action === 'number') {
|
|
728
|
+
var exec = getActionFunction(action, actionFunctionMap);
|
|
729
|
+
|
|
730
|
+
if (isFunction(exec)) {
|
|
731
|
+
actionObject = {
|
|
732
|
+
type: action,
|
|
733
|
+
exec: exec
|
|
734
|
+
};
|
|
735
|
+
} else if (exec) {
|
|
736
|
+
actionObject = exec;
|
|
737
|
+
} else {
|
|
738
|
+
actionObject = {
|
|
739
|
+
type: action,
|
|
740
|
+
exec: undefined
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
} else if (isFunction(action)) {
|
|
744
|
+
actionObject = {
|
|
745
|
+
// Convert action to string if unnamed
|
|
746
|
+
type: action.name || action.toString(),
|
|
747
|
+
exec: action
|
|
748
|
+
};
|
|
749
|
+
} else {
|
|
750
|
+
var exec = getActionFunction(action.type, actionFunctionMap);
|
|
751
|
+
|
|
752
|
+
if (isFunction(exec)) {
|
|
753
|
+
actionObject = __assign(__assign({}, action), {
|
|
754
|
+
exec: exec
|
|
755
|
+
});
|
|
756
|
+
} else if (exec) {
|
|
757
|
+
var actionType = exec.type || action.type;
|
|
758
|
+
actionObject = __assign(__assign(__assign({}, exec), action), {
|
|
759
|
+
type: actionType
|
|
760
|
+
});
|
|
761
|
+
} else {
|
|
762
|
+
actionObject = action;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
Object.defineProperty(actionObject, 'toString', {
|
|
767
|
+
value: function () {
|
|
768
|
+
return actionObject.type;
|
|
769
|
+
},
|
|
770
|
+
enumerable: false,
|
|
771
|
+
configurable: true
|
|
772
|
+
});
|
|
773
|
+
return actionObject;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
var toActionObjects = function (action, actionFunctionMap) {
|
|
777
|
+
if (!action) {
|
|
778
|
+
return [];
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
var actions = isArray(action) ? action : [action];
|
|
782
|
+
return actions.map(function (subAction) {
|
|
783
|
+
return toActionObject(subAction, actionFunctionMap);
|
|
784
|
+
});
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
function toActivityDefinition(action) {
|
|
788
|
+
var actionObject = toActionObject(action);
|
|
789
|
+
return __assign(__assign({
|
|
790
|
+
id: isString(action) ? action : actionObject.id
|
|
791
|
+
}, actionObject), {
|
|
792
|
+
type: actionObject.type
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Raises an event. This places the event in the internal event queue, so that
|
|
797
|
+
* the event is immediately consumed by the machine in the current step.
|
|
798
|
+
*
|
|
799
|
+
* @param eventType The event to raise.
|
|
800
|
+
*/
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
function raise(event) {
|
|
804
|
+
if (!isString(event)) {
|
|
805
|
+
return send(event, {
|
|
806
|
+
to: SpecialTargets.Internal
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
return {
|
|
811
|
+
type: raise$1,
|
|
812
|
+
event: event
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
function resolveRaise(action) {
|
|
817
|
+
return {
|
|
818
|
+
type: raise$1,
|
|
819
|
+
_event: toSCXMLEvent(action.event)
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Sends an event. This returns an action that will be read by an interpreter to
|
|
824
|
+
* send the event in the next step, after the current step is finished executing.
|
|
825
|
+
*
|
|
826
|
+
* @param event The event to send.
|
|
827
|
+
* @param options Options to pass into the send event:
|
|
828
|
+
* - `id` - The unique send event identifier (used with `cancel()`).
|
|
829
|
+
* - `delay` - The number of milliseconds to delay the sending of the event.
|
|
830
|
+
* - `to` - The target of this event (by default, the machine the event was sent from).
|
|
831
|
+
*/
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
function send(event, options) {
|
|
835
|
+
return {
|
|
836
|
+
to: options ? options.to : undefined,
|
|
837
|
+
type: send$1,
|
|
838
|
+
event: isFunction(event) ? event : toEventObject(event),
|
|
839
|
+
delay: options ? options.delay : undefined,
|
|
840
|
+
id: options && options.id !== undefined ? options.id : isFunction(event) ? event.name : getEventType(event)
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function resolveSend(action, ctx, _event, delaysMap) {
|
|
845
|
+
var meta = {
|
|
846
|
+
_event: _event
|
|
847
|
+
}; // TODO: helper function for resolving Expr
|
|
848
|
+
|
|
849
|
+
var resolvedEvent = toSCXMLEvent(isFunction(action.event) ? action.event(ctx, _event.data, meta) : action.event);
|
|
850
|
+
var resolvedDelay;
|
|
851
|
+
|
|
852
|
+
if (isString(action.delay)) {
|
|
853
|
+
var configDelay = delaysMap && delaysMap[action.delay];
|
|
854
|
+
resolvedDelay = isFunction(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
|
|
855
|
+
} else {
|
|
856
|
+
resolvedDelay = isFunction(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
var resolvedTarget = isFunction(action.to) ? action.to(ctx, _event.data, meta) : action.to;
|
|
860
|
+
return __assign(__assign({}, action), {
|
|
861
|
+
to: resolvedTarget,
|
|
862
|
+
_event: resolvedEvent,
|
|
863
|
+
event: resolvedEvent.data,
|
|
864
|
+
delay: resolvedDelay
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
var resolveLog = function (action, ctx, _event) {
|
|
869
|
+
return __assign(__assign({}, action), {
|
|
870
|
+
value: isString(action.expr) ? action.expr : action.expr(ctx, _event.data, {
|
|
871
|
+
_event: _event
|
|
872
|
+
})
|
|
873
|
+
});
|
|
874
|
+
};
|
|
875
|
+
/**
|
|
876
|
+
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
877
|
+
* be executed, nor will its event be sent, unless it has already been sent
|
|
878
|
+
* (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
|
|
879
|
+
*
|
|
880
|
+
* @param sendId The `id` of the `send(...)` action to cancel.
|
|
881
|
+
*/
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
var cancel = function (sendId) {
|
|
885
|
+
return {
|
|
886
|
+
type: cancel$1,
|
|
887
|
+
sendId: sendId
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
/**
|
|
891
|
+
* Starts an activity.
|
|
892
|
+
*
|
|
893
|
+
* @param activity The activity to start.
|
|
894
|
+
*/
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
function start(activity) {
|
|
898
|
+
var activityDef = toActivityDefinition(activity);
|
|
899
|
+
return {
|
|
900
|
+
type: ActionTypes.Start,
|
|
901
|
+
activity: activityDef,
|
|
902
|
+
exec: undefined
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Stops an activity.
|
|
907
|
+
*
|
|
908
|
+
* @param actorRef The activity to stop.
|
|
909
|
+
*/
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
function stop(actorRef) {
|
|
913
|
+
var activity = isFunction(actorRef) ? actorRef : toActivityDefinition(actorRef);
|
|
914
|
+
return {
|
|
915
|
+
type: ActionTypes.Stop,
|
|
916
|
+
activity: activity,
|
|
917
|
+
exec: undefined
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function resolveStop(action, context, _event) {
|
|
922
|
+
var actorRefOrString = isFunction(action.activity) ? action.activity(context, _event.data) : action.activity;
|
|
923
|
+
var resolvedActorRef = typeof actorRefOrString === 'string' ? {
|
|
924
|
+
id: actorRefOrString
|
|
925
|
+
} : actorRefOrString;
|
|
926
|
+
var actionObject = {
|
|
927
|
+
type: ActionTypes.Stop,
|
|
928
|
+
activity: resolvedActorRef
|
|
929
|
+
};
|
|
930
|
+
return actionObject;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Returns an event type that represents an implicit event that
|
|
934
|
+
* is sent after the specified `delay`.
|
|
935
|
+
*
|
|
936
|
+
* @param delayRef The delay in milliseconds
|
|
937
|
+
* @param id The state node ID where this event is handled
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
function after(delayRef, id) {
|
|
942
|
+
var idSuffix = id ? "#" + id : '';
|
|
943
|
+
return ActionTypes.After + "(" + delayRef + ")" + idSuffix;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Returns an event that represents that a final state node
|
|
947
|
+
* has been reached in the parent state node.
|
|
948
|
+
*
|
|
949
|
+
* @param id The final state node's parent state node `id`
|
|
950
|
+
* @param data The data to pass into the event
|
|
951
|
+
*/
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
function done(id, data) {
|
|
955
|
+
var type = ActionTypes.DoneState + "." + id;
|
|
956
|
+
var eventObject = {
|
|
957
|
+
type: type,
|
|
958
|
+
data: data
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
eventObject.toString = function () {
|
|
962
|
+
return type;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
return eventObject;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Returns an event that represents that an invoked service has terminated.
|
|
969
|
+
*
|
|
970
|
+
* An invoked service is terminated when it has reached a top-level final state node,
|
|
971
|
+
* but not when it is canceled.
|
|
972
|
+
*
|
|
973
|
+
* @param id The final state node ID
|
|
974
|
+
* @param data The data to pass into the event
|
|
975
|
+
*/
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
function doneInvoke(id, data) {
|
|
979
|
+
var type = ActionTypes.DoneInvoke + "." + id;
|
|
980
|
+
var eventObject = {
|
|
981
|
+
type: type,
|
|
982
|
+
data: data
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
eventObject.toString = function () {
|
|
986
|
+
return type;
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
return eventObject;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function error(id, data) {
|
|
993
|
+
var type = ActionTypes.ErrorPlatform + "." + id;
|
|
994
|
+
var eventObject = {
|
|
995
|
+
type: type,
|
|
996
|
+
data: data
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
eventObject.toString = function () {
|
|
1000
|
+
return type;
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
return eventObject;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function resolveActions(machine, currentState, currentContext, _event, actions) {
|
|
1007
|
+
var _a = __read(partition(actions, function (action) {
|
|
1008
|
+
return action.type === assign;
|
|
1009
|
+
}), 2),
|
|
1010
|
+
assignActions = _a[0],
|
|
1011
|
+
otherActions = _a[1];
|
|
1012
|
+
|
|
1013
|
+
var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
|
|
1014
|
+
var resolvedActions = flatten(otherActions.map(function (actionObject) {
|
|
1015
|
+
var _a;
|
|
1016
|
+
|
|
1017
|
+
switch (actionObject.type) {
|
|
1018
|
+
case raise$1:
|
|
1019
|
+
return resolveRaise(actionObject);
|
|
1020
|
+
|
|
1021
|
+
case send$1:
|
|
1022
|
+
var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
|
|
1023
|
+
|
|
1024
|
+
return sendAction;
|
|
1025
|
+
|
|
1026
|
+
case log:
|
|
1027
|
+
return resolveLog(actionObject, updatedContext, _event);
|
|
1028
|
+
|
|
1029
|
+
case choose:
|
|
1030
|
+
{
|
|
1031
|
+
var chooseAction = actionObject;
|
|
1032
|
+
var matchedActions = (_a = chooseAction.conds.find(function (condition) {
|
|
1033
|
+
var guard = toGuard(condition.cond, machine.options.guards);
|
|
1034
|
+
return !guard || evaluateGuard(machine, guard, updatedContext, _event, currentState);
|
|
1035
|
+
})) === null || _a === void 0 ? void 0 : _a.actions;
|
|
1036
|
+
|
|
1037
|
+
if (!matchedActions) {
|
|
1038
|
+
return [];
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
var resolved = resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions));
|
|
1042
|
+
updatedContext = resolved[1];
|
|
1043
|
+
return resolved[0];
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
case pure:
|
|
1047
|
+
{
|
|
1048
|
+
var matchedActions = actionObject.get(updatedContext, _event.data);
|
|
1049
|
+
|
|
1050
|
+
if (!matchedActions) {
|
|
1051
|
+
return [];
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
var resolved = resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions));
|
|
1055
|
+
updatedContext = resolved[1];
|
|
1056
|
+
return resolved[0];
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
case stop$1:
|
|
1060
|
+
{
|
|
1061
|
+
return resolveStop(actionObject, updatedContext, _event);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
default:
|
|
1065
|
+
return toActionObject(actionObject, machine.options.actions);
|
|
1066
|
+
}
|
|
1067
|
+
}));
|
|
1068
|
+
return [resolvedActions, updatedContext];
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
var isLeafNode = function (stateNode) {
|
|
1072
|
+
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
function getChildren(stateNode) {
|
|
1076
|
+
return keys(stateNode.states).map(function (key) {
|
|
1077
|
+
return stateNode.states[key];
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function getAllStateNodes(stateNode) {
|
|
1082
|
+
var stateNodes = [stateNode];
|
|
1083
|
+
|
|
1084
|
+
if (isLeafNode(stateNode)) {
|
|
1085
|
+
return stateNodes;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return stateNodes.concat(flatten(getChildren(stateNode).map(getAllStateNodes)));
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
function getConfiguration(prevStateNodes, stateNodes) {
|
|
1092
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
1093
|
+
|
|
1094
|
+
var prevConfiguration = new Set(prevStateNodes);
|
|
1095
|
+
var prevAdjList = getAdjList(prevConfiguration);
|
|
1096
|
+
var configuration = new Set(stateNodes);
|
|
1097
|
+
|
|
1098
|
+
try {
|
|
1099
|
+
// add all ancestors
|
|
1100
|
+
for (var configuration_1 = __values(configuration), configuration_1_1 = configuration_1.next(); !configuration_1_1.done; configuration_1_1 = configuration_1.next()) {
|
|
1101
|
+
var s = configuration_1_1.value;
|
|
1102
|
+
var m = s.parent;
|
|
1103
|
+
|
|
1104
|
+
while (m && !configuration.has(m)) {
|
|
1105
|
+
configuration.add(m);
|
|
1106
|
+
m = m.parent;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
} catch (e_1_1) {
|
|
1110
|
+
e_1 = {
|
|
1111
|
+
error: e_1_1
|
|
1112
|
+
};
|
|
1113
|
+
} finally {
|
|
1114
|
+
try {
|
|
1115
|
+
if (configuration_1_1 && !configuration_1_1.done && (_a = configuration_1.return)) _a.call(configuration_1);
|
|
1116
|
+
} finally {
|
|
1117
|
+
if (e_1) throw e_1.error;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
var adjList = getAdjList(configuration);
|
|
1122
|
+
|
|
1123
|
+
try {
|
|
1124
|
+
// add descendants
|
|
1125
|
+
for (var configuration_2 = __values(configuration), configuration_2_1 = configuration_2.next(); !configuration_2_1.done; configuration_2_1 = configuration_2.next()) {
|
|
1126
|
+
var s = configuration_2_1.value; // if previously active, add existing child nodes
|
|
1127
|
+
|
|
1128
|
+
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
1129
|
+
if (prevAdjList.get(s)) {
|
|
1130
|
+
prevAdjList.get(s).forEach(function (sn) {
|
|
1131
|
+
return configuration.add(sn);
|
|
1132
|
+
});
|
|
1133
|
+
} else {
|
|
1134
|
+
s.initialStateNodes.forEach(function (sn) {
|
|
1135
|
+
return configuration.add(sn);
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
} else {
|
|
1139
|
+
if (s.type === 'parallel') {
|
|
1140
|
+
try {
|
|
1141
|
+
for (var _e = (e_3 = void 0, __values(getChildren(s))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1142
|
+
var child = _f.value;
|
|
1143
|
+
|
|
1144
|
+
if (child.type === 'history') {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
if (!configuration.has(child)) {
|
|
1149
|
+
configuration.add(child);
|
|
1150
|
+
|
|
1151
|
+
if (prevAdjList.get(child)) {
|
|
1152
|
+
prevAdjList.get(child).forEach(function (sn) {
|
|
1153
|
+
return configuration.add(sn);
|
|
1154
|
+
});
|
|
1155
|
+
} else {
|
|
1156
|
+
child.initialStateNodes.forEach(function (sn) {
|
|
1157
|
+
return configuration.add(sn);
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
} catch (e_3_1) {
|
|
1163
|
+
e_3 = {
|
|
1164
|
+
error: e_3_1
|
|
1165
|
+
};
|
|
1166
|
+
} finally {
|
|
1167
|
+
try {
|
|
1168
|
+
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
|
|
1169
|
+
} finally {
|
|
1170
|
+
if (e_3) throw e_3.error;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
} catch (e_2_1) {
|
|
1177
|
+
e_2 = {
|
|
1178
|
+
error: e_2_1
|
|
1179
|
+
};
|
|
1180
|
+
} finally {
|
|
1181
|
+
try {
|
|
1182
|
+
if (configuration_2_1 && !configuration_2_1.done && (_b = configuration_2.return)) _b.call(configuration_2);
|
|
1183
|
+
} finally {
|
|
1184
|
+
if (e_2) throw e_2.error;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
try {
|
|
1189
|
+
// add all ancestors
|
|
1190
|
+
for (var configuration_3 = __values(configuration), configuration_3_1 = configuration_3.next(); !configuration_3_1.done; configuration_3_1 = configuration_3.next()) {
|
|
1191
|
+
var s = configuration_3_1.value;
|
|
1192
|
+
var m = s.parent;
|
|
1193
|
+
|
|
1194
|
+
while (m && !configuration.has(m)) {
|
|
1195
|
+
configuration.add(m);
|
|
1196
|
+
m = m.parent;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
} catch (e_4_1) {
|
|
1200
|
+
e_4 = {
|
|
1201
|
+
error: e_4_1
|
|
1202
|
+
};
|
|
1203
|
+
} finally {
|
|
1204
|
+
try {
|
|
1205
|
+
if (configuration_3_1 && !configuration_3_1.done && (_d = configuration_3.return)) _d.call(configuration_3);
|
|
1206
|
+
} finally {
|
|
1207
|
+
if (e_4) throw e_4.error;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
return configuration;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
function getValueFromAdj(baseNode, adjList) {
|
|
1215
|
+
var childStateNodes = adjList.get(baseNode);
|
|
1216
|
+
|
|
1217
|
+
if (!childStateNodes) {
|
|
1218
|
+
return {}; // todo: fix?
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
if (baseNode.type === 'compound') {
|
|
1222
|
+
var childStateNode = childStateNodes[0];
|
|
1223
|
+
|
|
1224
|
+
if (childStateNode) {
|
|
1225
|
+
if (isLeafNode(childStateNode)) {
|
|
1226
|
+
return childStateNode.key;
|
|
1227
|
+
}
|
|
1228
|
+
} else {
|
|
1229
|
+
return {};
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
var stateValue = {};
|
|
1234
|
+
childStateNodes.forEach(function (csn) {
|
|
1235
|
+
stateValue[csn.key] = getValueFromAdj(csn, adjList);
|
|
1236
|
+
});
|
|
1237
|
+
return stateValue;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
function getAdjList(configuration) {
|
|
1241
|
+
var e_5, _a;
|
|
1242
|
+
|
|
1243
|
+
var adjList = new Map();
|
|
1244
|
+
|
|
1245
|
+
try {
|
|
1246
|
+
for (var configuration_4 = __values(configuration), configuration_4_1 = configuration_4.next(); !configuration_4_1.done; configuration_4_1 = configuration_4.next()) {
|
|
1247
|
+
var s = configuration_4_1.value;
|
|
1248
|
+
|
|
1249
|
+
if (!adjList.has(s)) {
|
|
1250
|
+
adjList.set(s, []);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
if (s.parent) {
|
|
1254
|
+
if (!adjList.has(s.parent)) {
|
|
1255
|
+
adjList.set(s.parent, []);
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
adjList.get(s.parent).push(s);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
} catch (e_5_1) {
|
|
1262
|
+
e_5 = {
|
|
1263
|
+
error: e_5_1
|
|
1264
|
+
};
|
|
1265
|
+
} finally {
|
|
1266
|
+
try {
|
|
1267
|
+
if (configuration_4_1 && !configuration_4_1.done && (_a = configuration_4.return)) _a.call(configuration_4);
|
|
1268
|
+
} finally {
|
|
1269
|
+
if (e_5) throw e_5.error;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
return adjList;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
function getValue(rootNode, configuration) {
|
|
1277
|
+
var config = getConfiguration([rootNode], configuration);
|
|
1278
|
+
return getValueFromAdj(rootNode, getAdjList(config));
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
function has(iterable, item) {
|
|
1282
|
+
if (Array.isArray(iterable)) {
|
|
1283
|
+
return iterable.some(function (member) {
|
|
1284
|
+
return member === item;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
if (iterable instanceof Set) {
|
|
1289
|
+
return iterable.has(item);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return false; // TODO: fix
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function nextEvents(configuration) {
|
|
1296
|
+
return flatten(__spread(new Set(configuration.map(function (sn) {
|
|
1297
|
+
return sn.ownEvents;
|
|
1298
|
+
}))));
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
function isInFinalState(configuration, stateNode) {
|
|
1302
|
+
if (stateNode.type === 'compound') {
|
|
1303
|
+
return getChildren(stateNode).some(function (s) {
|
|
1304
|
+
return s.type === 'final' && has(configuration, s);
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
if (stateNode.type === 'parallel') {
|
|
1309
|
+
return getChildren(stateNode).every(function (sn) {
|
|
1310
|
+
return isInFinalState(configuration, sn);
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function stateValuesEqual(a, b) {
|
|
1318
|
+
if (a === b) {
|
|
1319
|
+
return true;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
if (a === undefined || b === undefined) {
|
|
1323
|
+
return false;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
if (isString(a) || isString(b)) {
|
|
1327
|
+
return a === b;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
var aKeys = keys(a);
|
|
1331
|
+
var bKeys = keys(b);
|
|
1332
|
+
return aKeys.length === bKeys.length && aKeys.every(function (key) {
|
|
1333
|
+
return stateValuesEqual(a[key], b[key]);
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
function isState(state) {
|
|
1338
|
+
if (isString(state)) {
|
|
1339
|
+
return false;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
return 'value' in state && 'history' in state;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
function bindActionToState(action, state) {
|
|
1346
|
+
var exec = action.exec;
|
|
1347
|
+
|
|
1348
|
+
var boundAction = __assign(__assign({}, action), {
|
|
1349
|
+
exec: exec !== undefined ? function () {
|
|
1350
|
+
return exec(state.context, state.event, {
|
|
1351
|
+
action: action,
|
|
1352
|
+
state: state,
|
|
1353
|
+
_event: state._event
|
|
1354
|
+
});
|
|
1355
|
+
} : undefined
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1358
|
+
return boundAction;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
var State =
|
|
1362
|
+
/*#__PURE__*/
|
|
1363
|
+
|
|
1364
|
+
/** @class */
|
|
1365
|
+
function () {
|
|
1366
|
+
/**
|
|
1367
|
+
* Creates a new State instance.
|
|
1368
|
+
* @param value The state value
|
|
1369
|
+
* @param context The extended state
|
|
1370
|
+
* @param historyValue The tree representing historical values of the state nodes
|
|
1371
|
+
* @param history The previous state
|
|
1372
|
+
* @param actions An array of action objects to execute as side-effects
|
|
1373
|
+
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
|
|
1374
|
+
* @param meta
|
|
1375
|
+
* @param events Internal event queue. Should be empty with run-to-completion semantics.
|
|
1376
|
+
* @param configuration
|
|
1377
|
+
*/
|
|
1378
|
+
function State(config) {
|
|
1379
|
+
var _this = this;
|
|
1380
|
+
|
|
1381
|
+
this.actions = [];
|
|
1382
|
+
this.activities = EMPTY_ACTIVITY_MAP;
|
|
1383
|
+
this.meta = {};
|
|
1384
|
+
this.events = [];
|
|
1385
|
+
this.value = config.value;
|
|
1386
|
+
this.context = config.context;
|
|
1387
|
+
this._event = config._event;
|
|
1388
|
+
this._sessionid = config._sessionid;
|
|
1389
|
+
this.event = this._event.data;
|
|
1390
|
+
this.historyValue = config.historyValue;
|
|
1391
|
+
this.history = config.history;
|
|
1392
|
+
this.actions = config.actions || [];
|
|
1393
|
+
this.activities = config.activities || EMPTY_ACTIVITY_MAP;
|
|
1394
|
+
this.meta = config.meta || {};
|
|
1395
|
+
this.events = config.events || [];
|
|
1396
|
+
this.matches = this.matches.bind(this);
|
|
1397
|
+
this.toStrings = this.toStrings.bind(this);
|
|
1398
|
+
this.configuration = config.configuration;
|
|
1399
|
+
this.transitions = config.transitions;
|
|
1400
|
+
this.children = config.children;
|
|
1401
|
+
this.done = !!config.done;
|
|
1402
|
+
Object.defineProperty(this, 'nextEvents', {
|
|
1403
|
+
get: function () {
|
|
1404
|
+
return nextEvents(_this.configuration);
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
/**
|
|
1409
|
+
* Creates a new State instance for the given `stateValue` and `context`.
|
|
1410
|
+
* @param stateValue
|
|
1411
|
+
* @param context
|
|
1412
|
+
*/
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
State.from = function (stateValue, context) {
|
|
1416
|
+
if (stateValue instanceof State) {
|
|
1417
|
+
if (stateValue.context !== context) {
|
|
1418
|
+
return new State({
|
|
1419
|
+
value: stateValue.value,
|
|
1420
|
+
context: context,
|
|
1421
|
+
_event: stateValue._event,
|
|
1422
|
+
_sessionid: null,
|
|
1423
|
+
historyValue: stateValue.historyValue,
|
|
1424
|
+
history: stateValue.history,
|
|
1425
|
+
actions: [],
|
|
1426
|
+
activities: stateValue.activities,
|
|
1427
|
+
meta: {},
|
|
1428
|
+
events: [],
|
|
1429
|
+
configuration: [],
|
|
1430
|
+
transitions: [],
|
|
1431
|
+
children: {}
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
return stateValue;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
var _event = initEvent;
|
|
1439
|
+
return new State({
|
|
1440
|
+
value: stateValue,
|
|
1441
|
+
context: context,
|
|
1442
|
+
_event: _event,
|
|
1443
|
+
_sessionid: null,
|
|
1444
|
+
historyValue: undefined,
|
|
1445
|
+
history: undefined,
|
|
1446
|
+
actions: [],
|
|
1447
|
+
activities: undefined,
|
|
1448
|
+
meta: undefined,
|
|
1449
|
+
events: [],
|
|
1450
|
+
configuration: [],
|
|
1451
|
+
transitions: [],
|
|
1452
|
+
children: {}
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
/**
|
|
1456
|
+
* Creates a new State instance for the given `config`.
|
|
1457
|
+
* @param config The state config
|
|
1458
|
+
*/
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
State.create = function (config) {
|
|
1462
|
+
return new State(config);
|
|
1463
|
+
};
|
|
1464
|
+
/**
|
|
1465
|
+
* Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
|
|
1466
|
+
* @param stateValue
|
|
1467
|
+
* @param context
|
|
1468
|
+
*/
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
State.inert = function (stateValue, context) {
|
|
1472
|
+
if (stateValue instanceof State) {
|
|
1473
|
+
if (!stateValue.actions.length) {
|
|
1474
|
+
return stateValue;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
var _event = initEvent;
|
|
1478
|
+
return new State({
|
|
1479
|
+
value: stateValue.value,
|
|
1480
|
+
context: context,
|
|
1481
|
+
_event: _event,
|
|
1482
|
+
_sessionid: null,
|
|
1483
|
+
historyValue: stateValue.historyValue,
|
|
1484
|
+
history: stateValue.history,
|
|
1485
|
+
activities: stateValue.activities,
|
|
1486
|
+
configuration: stateValue.configuration,
|
|
1487
|
+
transitions: [],
|
|
1488
|
+
children: {}
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
return State.from(stateValue, context);
|
|
1493
|
+
};
|
|
1494
|
+
/**
|
|
1495
|
+
* Returns an array of all the string leaf state node paths.
|
|
1496
|
+
* @param stateValue
|
|
1497
|
+
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
1498
|
+
*/
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
State.prototype.toStrings = function (stateValue, delimiter) {
|
|
1502
|
+
var _this = this;
|
|
1503
|
+
|
|
1504
|
+
if (stateValue === void 0) {
|
|
1505
|
+
stateValue = this.value;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
if (delimiter === void 0) {
|
|
1509
|
+
delimiter = '.';
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
if (isString(stateValue)) {
|
|
1513
|
+
return [stateValue];
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
var valueKeys = keys(stateValue);
|
|
1517
|
+
return valueKeys.concat.apply(valueKeys, __spread(valueKeys.map(function (key) {
|
|
1518
|
+
return _this.toStrings(stateValue[key], delimiter).map(function (s) {
|
|
1519
|
+
return key + delimiter + s;
|
|
1520
|
+
});
|
|
1521
|
+
})));
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
State.prototype.toJSON = function () {
|
|
1525
|
+
var _a = this,
|
|
1526
|
+
jsonValues = __rest(_a, ["configuration", "transitions"]);
|
|
1527
|
+
|
|
1528
|
+
return jsonValues;
|
|
1529
|
+
};
|
|
1530
|
+
/**
|
|
1531
|
+
* Whether the current state value is a subset of the given parent state value.
|
|
1532
|
+
* @param parentStateValue
|
|
1533
|
+
*/
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
State.prototype.matches = function (parentStateValue) {
|
|
1537
|
+
return matchesState(parentStateValue, this.value);
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
return State;
|
|
1541
|
+
}();
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Maintains a stack of the current service in scope.
|
|
1545
|
+
* This is used to provide the correct service to spawn().
|
|
1546
|
+
*/
|
|
1547
|
+
|
|
1548
|
+
var provide = function (service, fn) {
|
|
1549
|
+
var result = fn(service);
|
|
1550
|
+
return result;
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
function createNullActor(id) {
|
|
1554
|
+
return {
|
|
1555
|
+
id: id,
|
|
1556
|
+
send: function () {
|
|
1557
|
+
return void 0;
|
|
1558
|
+
},
|
|
1559
|
+
subscribe: function () {
|
|
1560
|
+
return {
|
|
1561
|
+
unsubscribe: function () {
|
|
1562
|
+
return void 0;
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
},
|
|
1566
|
+
toJSON: function () {
|
|
1567
|
+
return {
|
|
1568
|
+
id: id
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Creates a deferred actor that is able to be invoked given the provided
|
|
1575
|
+
* invocation information in its `.meta` value.
|
|
1576
|
+
*
|
|
1577
|
+
* @param invokeDefinition The meta information needed to invoke the actor.
|
|
1578
|
+
*/
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
function createInvocableActor(invokeDefinition, machine, context, _event) {
|
|
1582
|
+
var _a;
|
|
1583
|
+
|
|
1584
|
+
var invokeSrc = toInvokeSource$1(invokeDefinition.src);
|
|
1585
|
+
var serviceCreator = (_a = machine === null || machine === void 0 ? void 0 : machine.options.services) === null || _a === void 0 ? void 0 : _a[invokeSrc.type];
|
|
1586
|
+
var resolvedData = invokeDefinition.data ? mapContext(invokeDefinition.data, context, _event) : undefined;
|
|
1587
|
+
var tempActor = serviceCreator ? createDeferredActor(serviceCreator, invokeDefinition.id, resolvedData) : createNullActor(invokeDefinition.id);
|
|
1588
|
+
tempActor.meta = invokeDefinition;
|
|
1589
|
+
return tempActor;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
function createDeferredActor(entity, id, data) {
|
|
1593
|
+
var tempActor = createNullActor(id);
|
|
1594
|
+
tempActor.deferred = true;
|
|
1595
|
+
|
|
1596
|
+
if (isMachine(entity)) {
|
|
1597
|
+
// "mute" the existing service scope so potential spawned actors within the `.initialState` stay deferred here
|
|
1598
|
+
tempActor.state = provide(undefined, function () {
|
|
1599
|
+
return (data ? entity.withContext(data) : entity).initialState;
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
return tempActor;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
function isActor(item) {
|
|
1607
|
+
try {
|
|
1608
|
+
return typeof item.send === 'function';
|
|
1609
|
+
} catch (e) {
|
|
1610
|
+
return false;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
function isSpawnedActor(item) {
|
|
1615
|
+
return isActor(item) && 'id' in item;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function toInvokeSource(src) {
|
|
1619
|
+
if (typeof src === 'string') {
|
|
1620
|
+
var simpleSrc = {
|
|
1621
|
+
type: src
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
simpleSrc.toString = function () {
|
|
1625
|
+
return src;
|
|
1626
|
+
}; // v4 compat - TODO: remove in v5
|
|
1627
|
+
|
|
1628
|
+
|
|
1629
|
+
return simpleSrc;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
return src;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
function toInvokeDefinition(invokeConfig) {
|
|
1636
|
+
return __assign(__assign({
|
|
1637
|
+
type: invoke
|
|
1638
|
+
}, invokeConfig), {
|
|
1639
|
+
toJSON: function () {
|
|
1640
|
+
var invokeDef = __rest(invokeConfig, ["onDone", "onError"]);
|
|
1641
|
+
|
|
1642
|
+
return __assign(__assign({}, invokeDef), {
|
|
1643
|
+
type: invoke,
|
|
1644
|
+
src: toInvokeSource(invokeConfig.src)
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
var NULL_EVENT = '';
|
|
1651
|
+
var STATE_IDENTIFIER = '#';
|
|
1652
|
+
var WILDCARD = '*';
|
|
1653
|
+
var EMPTY_OBJECT = {};
|
|
1654
|
+
|
|
1655
|
+
var isStateId = function (str) {
|
|
1656
|
+
return str[0] === STATE_IDENTIFIER;
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
var createDefaultOptions = function () {
|
|
1660
|
+
return {
|
|
1661
|
+
actions: {},
|
|
1662
|
+
guards: {},
|
|
1663
|
+
services: {},
|
|
1664
|
+
activities: {},
|
|
1665
|
+
delays: {}
|
|
1666
|
+
};
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
var StateNode =
|
|
1670
|
+
/*#__PURE__*/
|
|
1671
|
+
|
|
1672
|
+
/** @class */
|
|
1673
|
+
function () {
|
|
1674
|
+
function StateNode(
|
|
1675
|
+
/**
|
|
1676
|
+
* The raw config used to create the machine.
|
|
1677
|
+
*/
|
|
1678
|
+
config, options,
|
|
1679
|
+
/**
|
|
1680
|
+
* The initial extended state
|
|
1681
|
+
*/
|
|
1682
|
+
context) {
|
|
1683
|
+
var _this = this;
|
|
1684
|
+
|
|
1685
|
+
this.config = config;
|
|
1686
|
+
this.context = context;
|
|
1687
|
+
/**
|
|
1688
|
+
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
1689
|
+
*/
|
|
1690
|
+
|
|
1691
|
+
this.order = -1;
|
|
1692
|
+
this.__xstatenode = true;
|
|
1693
|
+
this.__cache = {
|
|
1694
|
+
events: undefined,
|
|
1695
|
+
relativeValue: new Map(),
|
|
1696
|
+
initialStateValue: undefined,
|
|
1697
|
+
initialState: undefined,
|
|
1698
|
+
on: undefined,
|
|
1699
|
+
transitions: undefined,
|
|
1700
|
+
candidates: {},
|
|
1701
|
+
delayedTransitions: undefined
|
|
1702
|
+
};
|
|
1703
|
+
this.idMap = {};
|
|
1704
|
+
this.options = Object.assign(createDefaultOptions(), options);
|
|
1705
|
+
this.parent = this.options._parent;
|
|
1706
|
+
this.key = this.config.key || this.options._key || this.config.id || '(machine)';
|
|
1707
|
+
this.machine = this.parent ? this.parent.machine : this;
|
|
1708
|
+
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
1709
|
+
this.delimiter = this.config.delimiter || (this.parent ? this.parent.delimiter : STATE_DELIMITER);
|
|
1710
|
+
this.id = this.config.id || __spread([this.machine.key], this.path).join(this.delimiter);
|
|
1711
|
+
this.version = this.parent ? this.parent.version : this.config.version;
|
|
1712
|
+
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
|
|
1713
|
+
|
|
1714
|
+
this.initial = this.config.initial;
|
|
1715
|
+
this.states = this.config.states ? mapValues(this.config.states, function (stateConfig, key) {
|
|
1716
|
+
var _a;
|
|
1717
|
+
|
|
1718
|
+
var stateNode = new StateNode(stateConfig, {
|
|
1719
|
+
_parent: _this,
|
|
1720
|
+
_key: key
|
|
1721
|
+
});
|
|
1722
|
+
Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));
|
|
1723
|
+
return stateNode;
|
|
1724
|
+
}) : EMPTY_OBJECT; // Document order
|
|
1725
|
+
|
|
1726
|
+
var order = 0;
|
|
1727
|
+
|
|
1728
|
+
function dfs(stateNode) {
|
|
1729
|
+
var e_1, _a;
|
|
1730
|
+
|
|
1731
|
+
stateNode.order = order++;
|
|
1732
|
+
|
|
1733
|
+
try {
|
|
1734
|
+
for (var _b = __values(getChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1735
|
+
var child = _c.value;
|
|
1736
|
+
dfs(child);
|
|
1737
|
+
}
|
|
1738
|
+
} catch (e_1_1) {
|
|
1739
|
+
e_1 = {
|
|
1740
|
+
error: e_1_1
|
|
1741
|
+
};
|
|
1742
|
+
} finally {
|
|
1743
|
+
try {
|
|
1744
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1745
|
+
} finally {
|
|
1746
|
+
if (e_1) throw e_1.error;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
dfs(this); // History config
|
|
1752
|
+
|
|
1753
|
+
this.history = this.config.history === true ? 'shallow' : this.config.history || false;
|
|
1754
|
+
this._transient = !!this.config.always || (!this.config.on ? false : Array.isArray(this.config.on) ? this.config.on.some(function (_a) {
|
|
1755
|
+
var event = _a.event;
|
|
1756
|
+
return event === NULL_EVENT;
|
|
1757
|
+
}) : NULL_EVENT in this.config.on);
|
|
1758
|
+
this.strict = !!this.config.strict; // TODO: deprecate (entry)
|
|
1759
|
+
|
|
1760
|
+
this.onEntry = toArray(this.config.entry || this.config.onEntry).map(function (action) {
|
|
1761
|
+
return toActionObject(action);
|
|
1762
|
+
}); // TODO: deprecate (exit)
|
|
1763
|
+
|
|
1764
|
+
this.onExit = toArray(this.config.exit || this.config.onExit).map(function (action) {
|
|
1765
|
+
return toActionObject(action);
|
|
1766
|
+
});
|
|
1767
|
+
this.meta = this.config.meta;
|
|
1768
|
+
this.doneData = this.type === 'final' ? this.config.data : undefined;
|
|
1769
|
+
this.invoke = toArray(this.config.invoke).map(function (invokeConfig, i) {
|
|
1770
|
+
var _a, _b;
|
|
1771
|
+
|
|
1772
|
+
if (isMachine(invokeConfig)) {
|
|
1773
|
+
_this.machine.options.services = __assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
|
|
1774
|
+
return toInvokeDefinition({
|
|
1775
|
+
src: invokeConfig.id,
|
|
1776
|
+
id: invokeConfig.id
|
|
1777
|
+
});
|
|
1778
|
+
} else if (isString(invokeConfig.src)) {
|
|
1779
|
+
return toInvokeDefinition(__assign(__assign({}, invokeConfig), {
|
|
1780
|
+
id: invokeConfig.id || invokeConfig.src,
|
|
1781
|
+
src: invokeConfig.src
|
|
1782
|
+
}));
|
|
1783
|
+
} else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
|
|
1784
|
+
var invokeSrc = _this.id + ":invocation[" + i + "]"; // TODO: util function
|
|
1785
|
+
|
|
1786
|
+
_this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
|
|
1787
|
+
return toInvokeDefinition(__assign(__assign({
|
|
1788
|
+
id: invokeSrc
|
|
1789
|
+
}, invokeConfig), {
|
|
1790
|
+
src: invokeSrc
|
|
1791
|
+
}));
|
|
1792
|
+
} else {
|
|
1793
|
+
var invokeSource = invokeConfig.src;
|
|
1794
|
+
return toInvokeDefinition(__assign(__assign({
|
|
1795
|
+
id: invokeSource.type
|
|
1796
|
+
}, invokeConfig), {
|
|
1797
|
+
src: invokeSource
|
|
1798
|
+
}));
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
this.activities = toArray(this.config.activities).concat(this.invoke).map(function (activity) {
|
|
1802
|
+
return toActivityDefinition(activity);
|
|
1803
|
+
});
|
|
1804
|
+
this.transition = this.transition.bind(this); // TODO: this is the real fix for initialization once
|
|
1805
|
+
// state node getters are deprecated
|
|
1806
|
+
// if (!this.parent) {
|
|
1807
|
+
// this._init();
|
|
1808
|
+
// }
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
StateNode.prototype._init = function () {
|
|
1812
|
+
if (this.__cache.transitions) {
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
getAllStateNodes(this).forEach(function (stateNode) {
|
|
1817
|
+
return stateNode.on;
|
|
1818
|
+
});
|
|
1819
|
+
};
|
|
1820
|
+
/**
|
|
1821
|
+
* Clones this state machine with custom options and context.
|
|
1822
|
+
*
|
|
1823
|
+
* @param options Options (actions, guards, activities, services) to recursively merge with the existing options.
|
|
1824
|
+
* @param context Custom context (will override predefined context)
|
|
1825
|
+
*/
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
StateNode.prototype.withConfig = function (options, context) {
|
|
1829
|
+
if (context === void 0) {
|
|
1830
|
+
context = this.context;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
var _a = this.options,
|
|
1834
|
+
actions = _a.actions,
|
|
1835
|
+
activities = _a.activities,
|
|
1836
|
+
guards = _a.guards,
|
|
1837
|
+
services = _a.services,
|
|
1838
|
+
delays = _a.delays;
|
|
1839
|
+
return new StateNode(this.config, {
|
|
1840
|
+
actions: __assign(__assign({}, actions), options.actions),
|
|
1841
|
+
activities: __assign(__assign({}, activities), options.activities),
|
|
1842
|
+
guards: __assign(__assign({}, guards), options.guards),
|
|
1843
|
+
services: __assign(__assign({}, services), options.services),
|
|
1844
|
+
delays: __assign(__assign({}, delays), options.delays)
|
|
1845
|
+
}, context);
|
|
1846
|
+
};
|
|
1847
|
+
/**
|
|
1848
|
+
* Clones this state machine with custom context.
|
|
1849
|
+
*
|
|
1850
|
+
* @param context Custom context (will override predefined context, not recursive)
|
|
1851
|
+
*/
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
StateNode.prototype.withContext = function (context) {
|
|
1855
|
+
return new StateNode(this.config, this.options, context);
|
|
1856
|
+
};
|
|
1857
|
+
|
|
1858
|
+
Object.defineProperty(StateNode.prototype, "definition", {
|
|
1859
|
+
/**
|
|
1860
|
+
* The well-structured state node definition.
|
|
1861
|
+
*/
|
|
1862
|
+
get: function () {
|
|
1863
|
+
return {
|
|
1864
|
+
id: this.id,
|
|
1865
|
+
key: this.key,
|
|
1866
|
+
version: this.version,
|
|
1867
|
+
context: this.context,
|
|
1868
|
+
type: this.type,
|
|
1869
|
+
initial: this.initial,
|
|
1870
|
+
history: this.history,
|
|
1871
|
+
states: mapValues(this.states, function (state) {
|
|
1872
|
+
return state.definition;
|
|
1873
|
+
}),
|
|
1874
|
+
on: this.on,
|
|
1875
|
+
transitions: this.transitions,
|
|
1876
|
+
entry: this.onEntry,
|
|
1877
|
+
exit: this.onExit,
|
|
1878
|
+
activities: this.activities || [],
|
|
1879
|
+
meta: this.meta,
|
|
1880
|
+
order: this.order || -1,
|
|
1881
|
+
data: this.doneData,
|
|
1882
|
+
invoke: this.invoke
|
|
1883
|
+
};
|
|
1884
|
+
},
|
|
1885
|
+
enumerable: false,
|
|
1886
|
+
configurable: true
|
|
1887
|
+
});
|
|
1888
|
+
|
|
1889
|
+
StateNode.prototype.toJSON = function () {
|
|
1890
|
+
return this.definition;
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1893
|
+
Object.defineProperty(StateNode.prototype, "on", {
|
|
1894
|
+
/**
|
|
1895
|
+
* The mapping of events to transitions.
|
|
1896
|
+
*/
|
|
1897
|
+
get: function () {
|
|
1898
|
+
if (this.__cache.on) {
|
|
1899
|
+
return this.__cache.on;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
var transitions = this.transitions;
|
|
1903
|
+
return this.__cache.on = transitions.reduce(function (map, transition) {
|
|
1904
|
+
map[transition.eventType] = map[transition.eventType] || [];
|
|
1905
|
+
map[transition.eventType].push(transition);
|
|
1906
|
+
return map;
|
|
1907
|
+
}, {});
|
|
1908
|
+
},
|
|
1909
|
+
enumerable: false,
|
|
1910
|
+
configurable: true
|
|
1911
|
+
});
|
|
1912
|
+
Object.defineProperty(StateNode.prototype, "after", {
|
|
1913
|
+
get: function () {
|
|
1914
|
+
return this.__cache.delayedTransitions || (this.__cache.delayedTransitions = this.getDelayedTransitions(), this.__cache.delayedTransitions);
|
|
1915
|
+
},
|
|
1916
|
+
enumerable: false,
|
|
1917
|
+
configurable: true
|
|
1918
|
+
});
|
|
1919
|
+
Object.defineProperty(StateNode.prototype, "transitions", {
|
|
1920
|
+
/**
|
|
1921
|
+
* All the transitions that can be taken from this state node.
|
|
1922
|
+
*/
|
|
1923
|
+
get: function () {
|
|
1924
|
+
return this.__cache.transitions || (this.__cache.transitions = this.formatTransitions(), this.__cache.transitions);
|
|
1925
|
+
},
|
|
1926
|
+
enumerable: false,
|
|
1927
|
+
configurable: true
|
|
1928
|
+
});
|
|
1929
|
+
|
|
1930
|
+
StateNode.prototype.getCandidates = function (eventName) {
|
|
1931
|
+
if (this.__cache.candidates[eventName]) {
|
|
1932
|
+
return this.__cache.candidates[eventName];
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
var transient = eventName === NULL_EVENT;
|
|
1936
|
+
var candidates = this.transitions.filter(function (transition) {
|
|
1937
|
+
var sameEventType = transition.eventType === eventName; // null events should only match against eventless transitions
|
|
1938
|
+
|
|
1939
|
+
return transient ? sameEventType : sameEventType || transition.eventType === WILDCARD;
|
|
1940
|
+
});
|
|
1941
|
+
this.__cache.candidates[eventName] = candidates;
|
|
1942
|
+
return candidates;
|
|
1943
|
+
};
|
|
1944
|
+
/**
|
|
1945
|
+
* All delayed transitions from the config.
|
|
1946
|
+
*/
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
StateNode.prototype.getDelayedTransitions = function () {
|
|
1950
|
+
var _this = this;
|
|
1951
|
+
|
|
1952
|
+
var afterConfig = this.config.after;
|
|
1953
|
+
|
|
1954
|
+
if (!afterConfig) {
|
|
1955
|
+
return [];
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
var mutateEntryExit = function (delay, i) {
|
|
1959
|
+
var delayRef = isFunction(delay) ? _this.id + ":delay[" + i + "]" : delay;
|
|
1960
|
+
var eventType = after(delayRef, _this.id);
|
|
1961
|
+
|
|
1962
|
+
_this.onEntry.push(send(eventType, {
|
|
1963
|
+
delay: delay
|
|
1964
|
+
}));
|
|
1965
|
+
|
|
1966
|
+
_this.onExit.push(cancel(eventType));
|
|
1967
|
+
|
|
1968
|
+
return eventType;
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
var delayedTransitions = isArray(afterConfig) ? afterConfig.map(function (transition, i) {
|
|
1972
|
+
var eventType = mutateEntryExit(transition.delay, i);
|
|
1973
|
+
return __assign(__assign({}, transition), {
|
|
1974
|
+
event: eventType
|
|
1975
|
+
});
|
|
1976
|
+
}) : flatten(keys(afterConfig).map(function (delay, i) {
|
|
1977
|
+
var configTransition = afterConfig[delay];
|
|
1978
|
+
var resolvedTransition = isString(configTransition) ? {
|
|
1979
|
+
target: configTransition
|
|
1980
|
+
} : configTransition;
|
|
1981
|
+
var resolvedDelay = !isNaN(+delay) ? +delay : delay;
|
|
1982
|
+
var eventType = mutateEntryExit(resolvedDelay, i);
|
|
1983
|
+
return toArray(resolvedTransition).map(function (transition) {
|
|
1984
|
+
return __assign(__assign({}, transition), {
|
|
1985
|
+
event: eventType,
|
|
1986
|
+
delay: resolvedDelay
|
|
1987
|
+
});
|
|
1988
|
+
});
|
|
1989
|
+
}));
|
|
1990
|
+
return delayedTransitions.map(function (delayedTransition) {
|
|
1991
|
+
var delay = delayedTransition.delay;
|
|
1992
|
+
return __assign(__assign({}, _this.formatTransition(delayedTransition)), {
|
|
1993
|
+
delay: delay
|
|
1994
|
+
});
|
|
1995
|
+
});
|
|
1996
|
+
};
|
|
1997
|
+
/**
|
|
1998
|
+
* Returns the state nodes represented by the current state value.
|
|
1999
|
+
*
|
|
2000
|
+
* @param state The state value or State instance
|
|
2001
|
+
*/
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
StateNode.prototype.getStateNodes = function (state) {
|
|
2005
|
+
var _a;
|
|
2006
|
+
|
|
2007
|
+
var _this = this;
|
|
2008
|
+
|
|
2009
|
+
if (!state) {
|
|
2010
|
+
return [];
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
var stateValue = state instanceof State ? state.value : toStateValue(state, this.delimiter);
|
|
2014
|
+
|
|
2015
|
+
if (isString(stateValue)) {
|
|
2016
|
+
var initialStateValue = this.getStateNode(stateValue).initial;
|
|
2017
|
+
return initialStateValue !== undefined ? this.getStateNodes((_a = {}, _a[stateValue] = initialStateValue, _a)) : [this.states[stateValue]];
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
var subStateKeys = keys(stateValue);
|
|
2021
|
+
var subStateNodes = subStateKeys.map(function (subStateKey) {
|
|
2022
|
+
return _this.getStateNode(subStateKey);
|
|
2023
|
+
});
|
|
2024
|
+
return subStateNodes.concat(subStateKeys.reduce(function (allSubStateNodes, subStateKey) {
|
|
2025
|
+
var subStateNode = _this.getStateNode(subStateKey).getStateNodes(stateValue[subStateKey]);
|
|
2026
|
+
|
|
2027
|
+
return allSubStateNodes.concat(subStateNode);
|
|
2028
|
+
}, []));
|
|
2029
|
+
};
|
|
2030
|
+
/**
|
|
2031
|
+
* Returns `true` if this state node explicitly handles the given event.
|
|
2032
|
+
*
|
|
2033
|
+
* @param event The event in question
|
|
2034
|
+
*/
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
StateNode.prototype.handles = function (event) {
|
|
2038
|
+
var eventType = getEventType(event);
|
|
2039
|
+
return this.events.includes(eventType);
|
|
2040
|
+
};
|
|
2041
|
+
/**
|
|
2042
|
+
* Resolves the given `state` to a new `State` instance relative to this machine.
|
|
2043
|
+
*
|
|
2044
|
+
* This ensures that `.events` and `.nextEvents` represent the correct values.
|
|
2045
|
+
*
|
|
2046
|
+
* @param state The state to resolve
|
|
2047
|
+
*/
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
StateNode.prototype.resolveState = function (state) {
|
|
2051
|
+
var configuration = Array.from(getConfiguration([], this.getStateNodes(state.value)));
|
|
2052
|
+
return new State(__assign(__assign({}, state), {
|
|
2053
|
+
value: this.resolve(state.value),
|
|
2054
|
+
configuration: configuration,
|
|
2055
|
+
done: isInFinalState(configuration, this)
|
|
2056
|
+
}));
|
|
2057
|
+
};
|
|
2058
|
+
|
|
2059
|
+
StateNode.prototype.transitionLeafNode = function (stateValue, state, _event) {
|
|
2060
|
+
var stateNode = this.getStateNode(stateValue);
|
|
2061
|
+
var next = stateNode.next(state, _event);
|
|
2062
|
+
|
|
2063
|
+
if (!next || !next.transitions.length) {
|
|
2064
|
+
return this.next(state, _event);
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
return next;
|
|
2068
|
+
};
|
|
2069
|
+
|
|
2070
|
+
StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
|
|
2071
|
+
var subStateKeys = keys(stateValue);
|
|
2072
|
+
var stateNode = this.getStateNode(subStateKeys[0]);
|
|
2073
|
+
|
|
2074
|
+
var next = stateNode._transition(stateValue[subStateKeys[0]], state, _event);
|
|
2075
|
+
|
|
2076
|
+
if (!next || !next.transitions.length) {
|
|
2077
|
+
return this.next(state, _event);
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
return next;
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
StateNode.prototype.transitionParallelNode = function (stateValue, state, _event) {
|
|
2084
|
+
var e_2, _a;
|
|
2085
|
+
|
|
2086
|
+
var transitionMap = {};
|
|
2087
|
+
|
|
2088
|
+
try {
|
|
2089
|
+
for (var _b = __values(keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2090
|
+
var subStateKey = _c.value;
|
|
2091
|
+
var subStateValue = stateValue[subStateKey];
|
|
2092
|
+
|
|
2093
|
+
if (!subStateValue) {
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
var subStateNode = this.getStateNode(subStateKey);
|
|
2098
|
+
|
|
2099
|
+
var next = subStateNode._transition(subStateValue, state, _event);
|
|
2100
|
+
|
|
2101
|
+
if (next) {
|
|
2102
|
+
transitionMap[subStateKey] = next;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
} catch (e_2_1) {
|
|
2106
|
+
e_2 = {
|
|
2107
|
+
error: e_2_1
|
|
2108
|
+
};
|
|
2109
|
+
} finally {
|
|
2110
|
+
try {
|
|
2111
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2112
|
+
} finally {
|
|
2113
|
+
if (e_2) throw e_2.error;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
var stateTransitions = keys(transitionMap).map(function (key) {
|
|
2118
|
+
return transitionMap[key];
|
|
2119
|
+
});
|
|
2120
|
+
var enabledTransitions = flatten(stateTransitions.map(function (st) {
|
|
2121
|
+
return st.transitions;
|
|
2122
|
+
}));
|
|
2123
|
+
var willTransition = stateTransitions.some(function (st) {
|
|
2124
|
+
return st.transitions.length > 0;
|
|
2125
|
+
});
|
|
2126
|
+
|
|
2127
|
+
if (!willTransition) {
|
|
2128
|
+
return this.next(state, _event);
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
var entryNodes = flatten(stateTransitions.map(function (t) {
|
|
2132
|
+
return t.entrySet;
|
|
2133
|
+
}));
|
|
2134
|
+
var configuration = flatten(keys(transitionMap).map(function (key) {
|
|
2135
|
+
return transitionMap[key].configuration;
|
|
2136
|
+
}));
|
|
2137
|
+
return {
|
|
2138
|
+
transitions: enabledTransitions,
|
|
2139
|
+
entrySet: entryNodes,
|
|
2140
|
+
exitSet: flatten(stateTransitions.map(function (t) {
|
|
2141
|
+
return t.exitSet;
|
|
2142
|
+
})),
|
|
2143
|
+
configuration: configuration,
|
|
2144
|
+
source: state,
|
|
2145
|
+
actions: flatten(keys(transitionMap).map(function (key) {
|
|
2146
|
+
return transitionMap[key].actions;
|
|
2147
|
+
}))
|
|
2148
|
+
};
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
StateNode.prototype._transition = function (stateValue, state, _event) {
|
|
2152
|
+
// leaf node
|
|
2153
|
+
if (isString(stateValue)) {
|
|
2154
|
+
return this.transitionLeafNode(stateValue, state, _event);
|
|
2155
|
+
} // hierarchical node
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
if (keys(stateValue).length === 1) {
|
|
2159
|
+
return this.transitionCompoundNode(stateValue, state, _event);
|
|
2160
|
+
} // orthogonal node
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
return this.transitionParallelNode(stateValue, state, _event);
|
|
2164
|
+
};
|
|
2165
|
+
|
|
2166
|
+
StateNode.prototype.next = function (state, _event) {
|
|
2167
|
+
var e_3, _a;
|
|
2168
|
+
|
|
2169
|
+
var _this = this;
|
|
2170
|
+
|
|
2171
|
+
var eventName = _event.name;
|
|
2172
|
+
var actions = [];
|
|
2173
|
+
var nextStateNodes = [];
|
|
2174
|
+
var selectedTransition;
|
|
2175
|
+
|
|
2176
|
+
try {
|
|
2177
|
+
for (var _b = __values(this.getCandidates(eventName)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2178
|
+
var candidate = _c.value;
|
|
2179
|
+
var cond = candidate.cond,
|
|
2180
|
+
stateIn = candidate.in;
|
|
2181
|
+
var resolvedContext = state.context;
|
|
2182
|
+
var isInState = stateIn ? isString(stateIn) && isStateId(stateIn) ? // Check if in state by ID
|
|
2183
|
+
state.matches(toStateValue(this.getStateNodeById(stateIn).path, this.delimiter)) : // Check if in state by relative grandparent
|
|
2184
|
+
matchesState(toStateValue(stateIn, this.delimiter), path(this.path.slice(0, -2))(state.value)) : true;
|
|
2185
|
+
var guardPassed = false;
|
|
2186
|
+
|
|
2187
|
+
try {
|
|
2188
|
+
guardPassed = !cond || evaluateGuard(this.machine, cond, resolvedContext, _event, state);
|
|
2189
|
+
} catch (err) {
|
|
2190
|
+
throw new Error("Unable to evaluate guard '" + (cond.name || cond.type) + "' in transition for event '" + eventName + "' in state node '" + this.id + "':\n" + err.message);
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
if (guardPassed && isInState) {
|
|
2194
|
+
if (candidate.target !== undefined) {
|
|
2195
|
+
nextStateNodes = candidate.target;
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
actions.push.apply(actions, __spread(candidate.actions));
|
|
2199
|
+
selectedTransition = candidate;
|
|
2200
|
+
break;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
} catch (e_3_1) {
|
|
2204
|
+
e_3 = {
|
|
2205
|
+
error: e_3_1
|
|
2206
|
+
};
|
|
2207
|
+
} finally {
|
|
2208
|
+
try {
|
|
2209
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2210
|
+
} finally {
|
|
2211
|
+
if (e_3) throw e_3.error;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
if (!selectedTransition) {
|
|
2216
|
+
return undefined;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
if (!nextStateNodes.length) {
|
|
2220
|
+
return {
|
|
2221
|
+
transitions: [selectedTransition],
|
|
2222
|
+
entrySet: [],
|
|
2223
|
+
exitSet: [],
|
|
2224
|
+
configuration: state.value ? [this] : [],
|
|
2225
|
+
source: state,
|
|
2226
|
+
actions: actions
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
var allNextStateNodes = flatten(nextStateNodes.map(function (stateNode) {
|
|
2231
|
+
return _this.getRelativeStateNodes(stateNode, state.historyValue);
|
|
2232
|
+
}));
|
|
2233
|
+
var isInternal = !!selectedTransition.internal;
|
|
2234
|
+
var reentryNodes = isInternal ? [] : flatten(allNextStateNodes.map(function (n) {
|
|
2235
|
+
return _this.nodesFromChild(n);
|
|
2236
|
+
}));
|
|
2237
|
+
return {
|
|
2238
|
+
transitions: [selectedTransition],
|
|
2239
|
+
entrySet: reentryNodes,
|
|
2240
|
+
exitSet: isInternal ? [] : [this],
|
|
2241
|
+
configuration: allNextStateNodes,
|
|
2242
|
+
source: state,
|
|
2243
|
+
actions: actions
|
|
2244
|
+
};
|
|
2245
|
+
};
|
|
2246
|
+
|
|
2247
|
+
StateNode.prototype.nodesFromChild = function (childStateNode) {
|
|
2248
|
+
if (childStateNode.escapes(this)) {
|
|
2249
|
+
return [];
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
var nodes = [];
|
|
2253
|
+
var marker = childStateNode;
|
|
2254
|
+
|
|
2255
|
+
while (marker && marker !== this) {
|
|
2256
|
+
nodes.push(marker);
|
|
2257
|
+
marker = marker.parent;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
nodes.push(this); // inclusive
|
|
2261
|
+
|
|
2262
|
+
return nodes;
|
|
2263
|
+
};
|
|
2264
|
+
/**
|
|
2265
|
+
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
|
|
2266
|
+
* this state node, it does not escape.
|
|
2267
|
+
*/
|
|
2268
|
+
|
|
2269
|
+
|
|
2270
|
+
StateNode.prototype.escapes = function (stateNode) {
|
|
2271
|
+
if (this === stateNode) {
|
|
2272
|
+
return false;
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
var parent = this.parent;
|
|
2276
|
+
|
|
2277
|
+
while (parent) {
|
|
2278
|
+
if (parent === stateNode) {
|
|
2279
|
+
return false;
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
parent = parent.parent;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
return true;
|
|
2286
|
+
};
|
|
2287
|
+
|
|
2288
|
+
StateNode.prototype.getActions = function (transition, currentContext, _event, prevState) {
|
|
2289
|
+
var e_4, _a, e_5, _b;
|
|
2290
|
+
|
|
2291
|
+
var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
|
|
2292
|
+
var resolvedConfig = transition.configuration.length ? getConfiguration(prevConfig, transition.configuration) : prevConfig;
|
|
2293
|
+
|
|
2294
|
+
try {
|
|
2295
|
+
for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
|
|
2296
|
+
var sn = resolvedConfig_1_1.value;
|
|
2297
|
+
|
|
2298
|
+
if (!has(prevConfig, sn)) {
|
|
2299
|
+
transition.entrySet.push(sn);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
} catch (e_4_1) {
|
|
2303
|
+
e_4 = {
|
|
2304
|
+
error: e_4_1
|
|
2305
|
+
};
|
|
2306
|
+
} finally {
|
|
2307
|
+
try {
|
|
2308
|
+
if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
|
|
2309
|
+
} finally {
|
|
2310
|
+
if (e_4) throw e_4.error;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
try {
|
|
2315
|
+
for (var prevConfig_1 = __values(prevConfig), prevConfig_1_1 = prevConfig_1.next(); !prevConfig_1_1.done; prevConfig_1_1 = prevConfig_1.next()) {
|
|
2316
|
+
var sn = prevConfig_1_1.value;
|
|
2317
|
+
|
|
2318
|
+
if (!has(resolvedConfig, sn) || has(transition.exitSet, sn.parent)) {
|
|
2319
|
+
transition.exitSet.push(sn);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
} catch (e_5_1) {
|
|
2323
|
+
e_5 = {
|
|
2324
|
+
error: e_5_1
|
|
2325
|
+
};
|
|
2326
|
+
} finally {
|
|
2327
|
+
try {
|
|
2328
|
+
if (prevConfig_1_1 && !prevConfig_1_1.done && (_b = prevConfig_1.return)) _b.call(prevConfig_1);
|
|
2329
|
+
} finally {
|
|
2330
|
+
if (e_5) throw e_5.error;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
if (!transition.source) {
|
|
2335
|
+
transition.exitSet = []; // Ensure that root StateNode (machine) is entered
|
|
2336
|
+
|
|
2337
|
+
transition.entrySet.push(this);
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
var doneEvents = flatten(transition.entrySet.map(function (sn) {
|
|
2341
|
+
var events = [];
|
|
2342
|
+
|
|
2343
|
+
if (sn.type !== 'final') {
|
|
2344
|
+
return events;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
var parent = sn.parent;
|
|
2348
|
+
|
|
2349
|
+
if (!parent.parent) {
|
|
2350
|
+
return events;
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
events.push(done(sn.id, sn.doneData), // TODO: deprecate - final states should not emit done events for their own state.
|
|
2354
|
+
done(parent.id, sn.doneData ? mapContext(sn.doneData, currentContext, _event) : undefined));
|
|
2355
|
+
var grandparent = parent.parent;
|
|
2356
|
+
|
|
2357
|
+
if (grandparent.type === 'parallel') {
|
|
2358
|
+
if (getChildren(grandparent).every(function (parentNode) {
|
|
2359
|
+
return isInFinalState(transition.configuration, parentNode);
|
|
2360
|
+
})) {
|
|
2361
|
+
events.push(done(grandparent.id));
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
return events;
|
|
2366
|
+
}));
|
|
2367
|
+
transition.exitSet.sort(function (a, b) {
|
|
2368
|
+
return b.order - a.order;
|
|
2369
|
+
});
|
|
2370
|
+
transition.entrySet.sort(function (a, b) {
|
|
2371
|
+
return a.order - b.order;
|
|
2372
|
+
});
|
|
2373
|
+
var entryStates = new Set(transition.entrySet);
|
|
2374
|
+
var exitStates = new Set(transition.exitSet);
|
|
2375
|
+
|
|
2376
|
+
var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
|
|
2377
|
+
return __spread(stateNode.activities.map(function (activity) {
|
|
2378
|
+
return start(activity);
|
|
2379
|
+
}), stateNode.onEntry);
|
|
2380
|
+
})).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
|
|
2381
|
+
return __spread(stateNode.onExit, stateNode.activities.map(function (activity) {
|
|
2382
|
+
return stop(activity);
|
|
2383
|
+
}));
|
|
2384
|
+
}))], 2),
|
|
2385
|
+
entryActions = _c[0],
|
|
2386
|
+
exitActions = _c[1];
|
|
2387
|
+
|
|
2388
|
+
var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
|
|
2389
|
+
return actions;
|
|
2390
|
+
};
|
|
2391
|
+
/**
|
|
2392
|
+
* Determines the next state given the current `state` and sent `event`.
|
|
2393
|
+
*
|
|
2394
|
+
* @param state The current State instance or state value
|
|
2395
|
+
* @param event The event that was sent at the current state
|
|
2396
|
+
* @param context The current context (extended state) of the current state
|
|
2397
|
+
*/
|
|
2398
|
+
|
|
2399
|
+
|
|
2400
|
+
StateNode.prototype.transition = function (state, event, context) {
|
|
2401
|
+
if (state === void 0) {
|
|
2402
|
+
state = this.initialState;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
var _event = toSCXMLEvent(event);
|
|
2406
|
+
|
|
2407
|
+
var currentState;
|
|
2408
|
+
|
|
2409
|
+
if (state instanceof State) {
|
|
2410
|
+
currentState = context === undefined ? state : this.resolveState(State.from(state, context));
|
|
2411
|
+
} else {
|
|
2412
|
+
var resolvedStateValue = isString(state) ? this.resolve(pathToStateValue(this.getResolvedPath(state))) : this.resolve(state);
|
|
2413
|
+
var resolvedContext = context ? context : this.machine.context;
|
|
2414
|
+
currentState = this.resolveState(State.from(resolvedStateValue, resolvedContext));
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
if (this.strict) {
|
|
2418
|
+
if (!this.events.includes(_event.name) && !isBuiltInEvent(_event.name)) {
|
|
2419
|
+
throw new Error("Machine '" + this.id + "' does not accept event '" + _event.name + "'");
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
var stateTransition = this._transition(currentState.value, currentState, _event) || {
|
|
2424
|
+
transitions: [],
|
|
2425
|
+
configuration: [],
|
|
2426
|
+
entrySet: [],
|
|
2427
|
+
exitSet: [],
|
|
2428
|
+
source: currentState,
|
|
2429
|
+
actions: []
|
|
2430
|
+
};
|
|
2431
|
+
var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
|
|
2432
|
+
var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
|
|
2433
|
+
stateTransition.configuration = __spread(resolvedConfig);
|
|
2434
|
+
return this.resolveTransition(stateTransition, currentState, _event);
|
|
2435
|
+
};
|
|
2436
|
+
|
|
2437
|
+
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
|
|
2438
|
+
var _a;
|
|
2439
|
+
|
|
2440
|
+
var currentActions = state.actions;
|
|
2441
|
+
state = this.transition(state, _event); // Save original event to state
|
|
2442
|
+
// TODO: this should be the raised event! Delete in V5 (breaking)
|
|
2443
|
+
|
|
2444
|
+
state._event = originalEvent;
|
|
2445
|
+
state.event = originalEvent.data;
|
|
2446
|
+
|
|
2447
|
+
(_a = state.actions).unshift.apply(_a, __spread(currentActions));
|
|
2448
|
+
|
|
2449
|
+
return state;
|
|
2450
|
+
};
|
|
2451
|
+
|
|
2452
|
+
StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
|
|
2453
|
+
var e_6, _a;
|
|
2454
|
+
|
|
2455
|
+
var _this = this;
|
|
2456
|
+
|
|
2457
|
+
if (_event === void 0) {
|
|
2458
|
+
_event = initEvent;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
if (context === void 0) {
|
|
2462
|
+
context = this.machine.context;
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
var configuration = stateTransition.configuration; // Transition will "apply" if:
|
|
2466
|
+
// - this is the initial state (there is no current state)
|
|
2467
|
+
// - OR there are transitions
|
|
2468
|
+
|
|
2469
|
+
var willTransition = !currentState || stateTransition.transitions.length > 0;
|
|
2470
|
+
var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
|
|
2471
|
+
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
|
|
2472
|
+
var currentContext = currentState ? currentState.context : context;
|
|
2473
|
+
var actions = this.getActions(stateTransition, currentContext, _event, currentState);
|
|
2474
|
+
var activities = currentState ? __assign({}, currentState.activities) : {};
|
|
2475
|
+
|
|
2476
|
+
try {
|
|
2477
|
+
for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
|
|
2478
|
+
var action = actions_1_1.value;
|
|
2479
|
+
|
|
2480
|
+
if (action.type === start$1) {
|
|
2481
|
+
activities[action.activity.id || action.activity.type] = action;
|
|
2482
|
+
} else if (action.type === stop$1) {
|
|
2483
|
+
activities[action.activity.id || action.activity.type] = false;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
} catch (e_6_1) {
|
|
2487
|
+
e_6 = {
|
|
2488
|
+
error: e_6_1
|
|
2489
|
+
};
|
|
2490
|
+
} finally {
|
|
2491
|
+
try {
|
|
2492
|
+
if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
|
|
2493
|
+
} finally {
|
|
2494
|
+
if (e_6) throw e_6.error;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
var _b = __read(resolveActions(this, currentState, currentContext, _event, actions), 2),
|
|
2499
|
+
resolvedActions = _b[0],
|
|
2500
|
+
updatedContext = _b[1];
|
|
2501
|
+
|
|
2502
|
+
var _c = __read(partition(resolvedActions, function (action) {
|
|
2503
|
+
return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
|
|
2504
|
+
}), 2),
|
|
2505
|
+
raisedEvents = _c[0],
|
|
2506
|
+
nonRaisedActions = _c[1];
|
|
2507
|
+
|
|
2508
|
+
var invokeActions = resolvedActions.filter(function (action) {
|
|
2509
|
+
var _a;
|
|
2510
|
+
|
|
2511
|
+
return action.type === start$1 && ((_a = action.activity) === null || _a === void 0 ? void 0 : _a.type) === invoke;
|
|
2512
|
+
});
|
|
2513
|
+
var children = invokeActions.reduce(function (acc, action) {
|
|
2514
|
+
acc[action.activity.id] = createInvocableActor(action.activity, _this.machine, updatedContext, _event);
|
|
2515
|
+
return acc;
|
|
2516
|
+
}, currentState ? __assign({}, currentState.children) : {});
|
|
2517
|
+
var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
|
|
2518
|
+
var meta = resolvedConfiguration.reduce(function (acc, stateNode) {
|
|
2519
|
+
if (stateNode.meta !== undefined) {
|
|
2520
|
+
acc[stateNode.id] = stateNode.meta;
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
return acc;
|
|
2524
|
+
}, {});
|
|
2525
|
+
var isDone = isInFinalState(resolvedConfiguration, this);
|
|
2526
|
+
var nextState = new State({
|
|
2527
|
+
value: resolvedStateValue || currentState.value,
|
|
2528
|
+
context: updatedContext,
|
|
2529
|
+
_event: _event,
|
|
2530
|
+
// Persist _sessionid between states
|
|
2531
|
+
_sessionid: currentState ? currentState._sessionid : null,
|
|
2532
|
+
historyValue: resolvedStateValue ? historyValue ? updateHistoryValue(historyValue, resolvedStateValue) : undefined : currentState ? currentState.historyValue : undefined,
|
|
2533
|
+
history: !resolvedStateValue || stateTransition.source ? currentState : undefined,
|
|
2534
|
+
actions: resolvedStateValue ? nonRaisedActions : [],
|
|
2535
|
+
activities: resolvedStateValue ? activities : currentState ? currentState.activities : {},
|
|
2536
|
+
meta: resolvedStateValue ? meta : currentState ? currentState.meta : undefined,
|
|
2537
|
+
events: [],
|
|
2538
|
+
configuration: resolvedConfiguration,
|
|
2539
|
+
transitions: stateTransition.transitions,
|
|
2540
|
+
children: children,
|
|
2541
|
+
done: isDone
|
|
2542
|
+
});
|
|
2543
|
+
var didUpdateContext = currentContext !== updatedContext;
|
|
2544
|
+
nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
|
|
2545
|
+
|
|
2546
|
+
var history = nextState.history;
|
|
2547
|
+
|
|
2548
|
+
if (history) {
|
|
2549
|
+
delete history.history;
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
if (!resolvedStateValue) {
|
|
2553
|
+
return nextState;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
var maybeNextState = nextState;
|
|
2557
|
+
|
|
2558
|
+
if (!isDone) {
|
|
2559
|
+
var isTransient = this._transient || configuration.some(function (stateNode) {
|
|
2560
|
+
return stateNode._transient;
|
|
2561
|
+
});
|
|
2562
|
+
|
|
2563
|
+
if (isTransient) {
|
|
2564
|
+
maybeNextState = this.resolveRaisedTransition(maybeNextState, {
|
|
2565
|
+
type: nullEvent
|
|
2566
|
+
}, _event);
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
while (raisedEvents.length) {
|
|
2570
|
+
var raisedEvent = raisedEvents.shift();
|
|
2571
|
+
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event);
|
|
2572
|
+
}
|
|
2573
|
+
} // Detect if state changed
|
|
2574
|
+
|
|
2575
|
+
|
|
2576
|
+
var changed = maybeNextState.changed || (history ? !!maybeNextState.actions.length || didUpdateContext || typeof history.value !== typeof maybeNextState.value || !stateValuesEqual(maybeNextState.value, history.value) : undefined);
|
|
2577
|
+
maybeNextState.changed = changed; // Preserve original history after raised events
|
|
2578
|
+
|
|
2579
|
+
maybeNextState.history = history;
|
|
2580
|
+
return maybeNextState;
|
|
2581
|
+
};
|
|
2582
|
+
/**
|
|
2583
|
+
* Returns the child state node from its relative `stateKey`, or throws.
|
|
2584
|
+
*/
|
|
2585
|
+
|
|
2586
|
+
|
|
2587
|
+
StateNode.prototype.getStateNode = function (stateKey) {
|
|
2588
|
+
if (isStateId(stateKey)) {
|
|
2589
|
+
return this.machine.getStateNodeById(stateKey);
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
if (!this.states) {
|
|
2593
|
+
throw new Error("Unable to retrieve child state '" + stateKey + "' from '" + this.id + "'; no child states exist.");
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
var result = this.states[stateKey];
|
|
2597
|
+
|
|
2598
|
+
if (!result) {
|
|
2599
|
+
throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
return result;
|
|
2603
|
+
};
|
|
2604
|
+
/**
|
|
2605
|
+
* Returns the state node with the given `stateId`, or throws.
|
|
2606
|
+
*
|
|
2607
|
+
* @param stateId The state ID. The prefix "#" is removed.
|
|
2608
|
+
*/
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
StateNode.prototype.getStateNodeById = function (stateId) {
|
|
2612
|
+
var resolvedStateId = isStateId(stateId) ? stateId.slice(STATE_IDENTIFIER.length) : stateId;
|
|
2613
|
+
|
|
2614
|
+
if (resolvedStateId === this.id) {
|
|
2615
|
+
return this;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
var stateNode = this.machine.idMap[resolvedStateId];
|
|
2619
|
+
|
|
2620
|
+
if (!stateNode) {
|
|
2621
|
+
throw new Error("Child state node '#" + resolvedStateId + "' does not exist on machine '" + this.id + "'");
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
return stateNode;
|
|
2625
|
+
};
|
|
2626
|
+
/**
|
|
2627
|
+
* Returns the relative state node from the given `statePath`, or throws.
|
|
2628
|
+
*
|
|
2629
|
+
* @param statePath The string or string array relative path to the state node.
|
|
2630
|
+
*/
|
|
2631
|
+
|
|
2632
|
+
|
|
2633
|
+
StateNode.prototype.getStateNodeByPath = function (statePath) {
|
|
2634
|
+
if (typeof statePath === 'string' && isStateId(statePath)) {
|
|
2635
|
+
try {
|
|
2636
|
+
return this.getStateNodeById(statePath.slice(1));
|
|
2637
|
+
} catch (e) {// try individual paths
|
|
2638
|
+
// throw e;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
var arrayStatePath = toStatePath(statePath, this.delimiter).slice();
|
|
2643
|
+
var currentStateNode = this;
|
|
2644
|
+
|
|
2645
|
+
while (arrayStatePath.length) {
|
|
2646
|
+
var key = arrayStatePath.shift();
|
|
2647
|
+
|
|
2648
|
+
if (!key.length) {
|
|
2649
|
+
break;
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
currentStateNode = currentStateNode.getStateNode(key);
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
return currentStateNode;
|
|
2656
|
+
};
|
|
2657
|
+
/**
|
|
2658
|
+
* Resolves a partial state value with its full representation in this machine.
|
|
2659
|
+
*
|
|
2660
|
+
* @param stateValue The partial state value to resolve.
|
|
2661
|
+
*/
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
StateNode.prototype.resolve = function (stateValue) {
|
|
2665
|
+
var _a;
|
|
2666
|
+
|
|
2667
|
+
var _this = this;
|
|
2668
|
+
|
|
2669
|
+
if (!stateValue) {
|
|
2670
|
+
return this.initialStateValue || EMPTY_OBJECT; // TODO: type-specific properties
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
switch (this.type) {
|
|
2674
|
+
case 'parallel':
|
|
2675
|
+
return mapValues(this.initialStateValue, function (subStateValue, subStateKey) {
|
|
2676
|
+
return subStateValue ? _this.getStateNode(subStateKey).resolve(stateValue[subStateKey] || subStateValue) : EMPTY_OBJECT;
|
|
2677
|
+
});
|
|
2678
|
+
|
|
2679
|
+
case 'compound':
|
|
2680
|
+
if (isString(stateValue)) {
|
|
2681
|
+
var subStateNode = this.getStateNode(stateValue);
|
|
2682
|
+
|
|
2683
|
+
if (subStateNode.type === 'parallel' || subStateNode.type === 'compound') {
|
|
2684
|
+
return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
return stateValue;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
if (!keys(stateValue).length) {
|
|
2691
|
+
return this.initialStateValue || {};
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
return mapValues(stateValue, function (subStateValue, subStateKey) {
|
|
2695
|
+
return subStateValue ? _this.getStateNode(subStateKey).resolve(subStateValue) : EMPTY_OBJECT;
|
|
2696
|
+
});
|
|
2697
|
+
|
|
2698
|
+
default:
|
|
2699
|
+
return stateValue || EMPTY_OBJECT;
|
|
2700
|
+
}
|
|
2701
|
+
};
|
|
2702
|
+
|
|
2703
|
+
StateNode.prototype.getResolvedPath = function (stateIdentifier) {
|
|
2704
|
+
if (isStateId(stateIdentifier)) {
|
|
2705
|
+
var stateNode = this.machine.idMap[stateIdentifier.slice(STATE_IDENTIFIER.length)];
|
|
2706
|
+
|
|
2707
|
+
if (!stateNode) {
|
|
2708
|
+
throw new Error("Unable to find state node '" + stateIdentifier + "'");
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
return stateNode.path;
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
return toStatePath(stateIdentifier, this.delimiter);
|
|
2715
|
+
};
|
|
2716
|
+
|
|
2717
|
+
Object.defineProperty(StateNode.prototype, "initialStateValue", {
|
|
2718
|
+
get: function () {
|
|
2719
|
+
var _a;
|
|
2720
|
+
|
|
2721
|
+
if (this.__cache.initialStateValue) {
|
|
2722
|
+
return this.__cache.initialStateValue;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
var initialStateValue;
|
|
2726
|
+
|
|
2727
|
+
if (this.type === 'parallel') {
|
|
2728
|
+
initialStateValue = mapFilterValues(this.states, function (state) {
|
|
2729
|
+
return state.initialStateValue || EMPTY_OBJECT;
|
|
2730
|
+
}, function (stateNode) {
|
|
2731
|
+
return !(stateNode.type === 'history');
|
|
2732
|
+
});
|
|
2733
|
+
} else if (this.initial !== undefined) {
|
|
2734
|
+
if (!this.states[this.initial]) {
|
|
2735
|
+
throw new Error("Initial state '" + this.initial + "' not found on '" + this.key + "'");
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
initialStateValue = isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
this.__cache.initialStateValue = initialStateValue;
|
|
2742
|
+
return this.__cache.initialStateValue;
|
|
2743
|
+
},
|
|
2744
|
+
enumerable: false,
|
|
2745
|
+
configurable: true
|
|
2746
|
+
});
|
|
2747
|
+
|
|
2748
|
+
StateNode.prototype.getInitialState = function (stateValue, context) {
|
|
2749
|
+
var configuration = this.getStateNodes(stateValue);
|
|
2750
|
+
return this.resolveTransition({
|
|
2751
|
+
configuration: configuration,
|
|
2752
|
+
entrySet: configuration,
|
|
2753
|
+
exitSet: [],
|
|
2754
|
+
transitions: [],
|
|
2755
|
+
source: undefined,
|
|
2756
|
+
actions: []
|
|
2757
|
+
}, undefined, undefined, context);
|
|
2758
|
+
};
|
|
2759
|
+
|
|
2760
|
+
Object.defineProperty(StateNode.prototype, "initialState", {
|
|
2761
|
+
/**
|
|
2762
|
+
* The initial State instance, which includes all actions to be executed from
|
|
2763
|
+
* entering the initial state.
|
|
2764
|
+
*/
|
|
2765
|
+
get: function () {
|
|
2766
|
+
this._init(); // TODO: this should be in the constructor (see note in constructor)
|
|
2767
|
+
|
|
2768
|
+
|
|
2769
|
+
var initialStateValue = this.initialStateValue;
|
|
2770
|
+
|
|
2771
|
+
if (!initialStateValue) {
|
|
2772
|
+
throw new Error("Cannot retrieve initial state from simple state '" + this.id + "'.");
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
return this.getInitialState(initialStateValue);
|
|
2776
|
+
},
|
|
2777
|
+
enumerable: false,
|
|
2778
|
+
configurable: true
|
|
2779
|
+
});
|
|
2780
|
+
Object.defineProperty(StateNode.prototype, "target", {
|
|
2781
|
+
/**
|
|
2782
|
+
* The target state value of the history state node, if it exists. This represents the
|
|
2783
|
+
* default state value to transition to if no history value exists yet.
|
|
2784
|
+
*/
|
|
2785
|
+
get: function () {
|
|
2786
|
+
var target;
|
|
2787
|
+
|
|
2788
|
+
if (this.type === 'history') {
|
|
2789
|
+
var historyConfig = this.config;
|
|
2790
|
+
|
|
2791
|
+
if (isString(historyConfig.target)) {
|
|
2792
|
+
target = isStateId(historyConfig.target) ? pathToStateValue(this.machine.getStateNodeById(historyConfig.target).path.slice(this.path.length - 1)) : historyConfig.target;
|
|
2793
|
+
} else {
|
|
2794
|
+
target = historyConfig.target;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
return target;
|
|
2799
|
+
},
|
|
2800
|
+
enumerable: false,
|
|
2801
|
+
configurable: true
|
|
2802
|
+
});
|
|
2803
|
+
/**
|
|
2804
|
+
* Returns the leaf nodes from a state path relative to this state node.
|
|
2805
|
+
*
|
|
2806
|
+
* @param relativeStateId The relative state path to retrieve the state nodes
|
|
2807
|
+
* @param history The previous state to retrieve history
|
|
2808
|
+
* @param resolve Whether state nodes should resolve to initial child state nodes
|
|
2809
|
+
*/
|
|
2810
|
+
|
|
2811
|
+
StateNode.prototype.getRelativeStateNodes = function (relativeStateId, historyValue, resolve) {
|
|
2812
|
+
if (resolve === void 0) {
|
|
2813
|
+
resolve = true;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
return resolve ? relativeStateId.type === 'history' ? relativeStateId.resolveHistory(historyValue) : relativeStateId.initialStateNodes : [relativeStateId];
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
Object.defineProperty(StateNode.prototype, "initialStateNodes", {
|
|
2820
|
+
get: function () {
|
|
2821
|
+
var _this = this;
|
|
2822
|
+
|
|
2823
|
+
if (isLeafNode(this)) {
|
|
2824
|
+
return [this];
|
|
2825
|
+
} // Case when state node is compound but no initial state is defined
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
if (this.type === 'compound' && !this.initial) {
|
|
2829
|
+
|
|
2830
|
+
return [this];
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
var initialStateNodePaths = toStatePaths(this.initialStateValue);
|
|
2834
|
+
return flatten(initialStateNodePaths.map(function (initialPath) {
|
|
2835
|
+
return _this.getFromRelativePath(initialPath);
|
|
2836
|
+
}));
|
|
2837
|
+
},
|
|
2838
|
+
enumerable: false,
|
|
2839
|
+
configurable: true
|
|
2840
|
+
});
|
|
2841
|
+
/**
|
|
2842
|
+
* Retrieves state nodes from a relative path to this state node.
|
|
2843
|
+
*
|
|
2844
|
+
* @param relativePath The relative path from this state node
|
|
2845
|
+
* @param historyValue
|
|
2846
|
+
*/
|
|
2847
|
+
|
|
2848
|
+
StateNode.prototype.getFromRelativePath = function (relativePath) {
|
|
2849
|
+
if (!relativePath.length) {
|
|
2850
|
+
return [this];
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
var _a = __read(relativePath),
|
|
2854
|
+
stateKey = _a[0],
|
|
2855
|
+
childStatePath = _a.slice(1);
|
|
2856
|
+
|
|
2857
|
+
if (!this.states) {
|
|
2858
|
+
throw new Error("Cannot retrieve subPath '" + stateKey + "' from node with no states");
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
var childStateNode = this.getStateNode(stateKey);
|
|
2862
|
+
|
|
2863
|
+
if (childStateNode.type === 'history') {
|
|
2864
|
+
return childStateNode.resolveHistory();
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
if (!this.states[stateKey]) {
|
|
2868
|
+
throw new Error("Child state '" + stateKey + "' does not exist on '" + this.id + "'");
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
return this.states[stateKey].getFromRelativePath(childStatePath);
|
|
2872
|
+
};
|
|
2873
|
+
|
|
2874
|
+
StateNode.prototype.historyValue = function (relativeStateValue) {
|
|
2875
|
+
if (!keys(this.states).length) {
|
|
2876
|
+
return undefined;
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
return {
|
|
2880
|
+
current: relativeStateValue || this.initialStateValue,
|
|
2881
|
+
states: mapFilterValues(this.states, function (stateNode, key) {
|
|
2882
|
+
if (!relativeStateValue) {
|
|
2883
|
+
return stateNode.historyValue();
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
var subStateValue = isString(relativeStateValue) ? undefined : relativeStateValue[key];
|
|
2887
|
+
return stateNode.historyValue(subStateValue || stateNode.initialStateValue);
|
|
2888
|
+
}, function (stateNode) {
|
|
2889
|
+
return !stateNode.history;
|
|
2890
|
+
})
|
|
2891
|
+
};
|
|
2892
|
+
};
|
|
2893
|
+
/**
|
|
2894
|
+
* Resolves to the historical value(s) of the parent state node,
|
|
2895
|
+
* represented by state nodes.
|
|
2896
|
+
*
|
|
2897
|
+
* @param historyValue
|
|
2898
|
+
*/
|
|
2899
|
+
|
|
2900
|
+
|
|
2901
|
+
StateNode.prototype.resolveHistory = function (historyValue) {
|
|
2902
|
+
var _this = this;
|
|
2903
|
+
|
|
2904
|
+
if (this.type !== 'history') {
|
|
2905
|
+
return [this];
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
var parent = this.parent;
|
|
2909
|
+
|
|
2910
|
+
if (!historyValue) {
|
|
2911
|
+
var historyTarget = this.target;
|
|
2912
|
+
return historyTarget ? flatten(toStatePaths(historyTarget).map(function (relativeChildPath) {
|
|
2913
|
+
return parent.getFromRelativePath(relativeChildPath);
|
|
2914
|
+
})) : parent.initialStateNodes;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
var subHistoryValue = nestedPath(parent.path, 'states')(historyValue).current;
|
|
2918
|
+
|
|
2919
|
+
if (isString(subHistoryValue)) {
|
|
2920
|
+
return [parent.getStateNode(subHistoryValue)];
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2923
|
+
return flatten(toStatePaths(subHistoryValue).map(function (subStatePath) {
|
|
2924
|
+
return _this.history === 'deep' ? parent.getFromRelativePath(subStatePath) : [parent.states[subStatePath[0]]];
|
|
2925
|
+
}));
|
|
2926
|
+
};
|
|
2927
|
+
|
|
2928
|
+
Object.defineProperty(StateNode.prototype, "stateIds", {
|
|
2929
|
+
/**
|
|
2930
|
+
* All the state node IDs of this state node and its descendant state nodes.
|
|
2931
|
+
*/
|
|
2932
|
+
get: function () {
|
|
2933
|
+
var _this = this;
|
|
2934
|
+
|
|
2935
|
+
var childStateIds = flatten(keys(this.states).map(function (stateKey) {
|
|
2936
|
+
return _this.states[stateKey].stateIds;
|
|
2937
|
+
}));
|
|
2938
|
+
return [this.id].concat(childStateIds);
|
|
2939
|
+
},
|
|
2940
|
+
enumerable: false,
|
|
2941
|
+
configurable: true
|
|
2942
|
+
});
|
|
2943
|
+
Object.defineProperty(StateNode.prototype, "events", {
|
|
2944
|
+
/**
|
|
2945
|
+
* All the event types accepted by this state node and its descendants.
|
|
2946
|
+
*/
|
|
2947
|
+
get: function () {
|
|
2948
|
+
var e_7, _a, e_8, _b;
|
|
2949
|
+
|
|
2950
|
+
if (this.__cache.events) {
|
|
2951
|
+
return this.__cache.events;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
var states = this.states;
|
|
2955
|
+
var events = new Set(this.ownEvents);
|
|
2956
|
+
|
|
2957
|
+
if (states) {
|
|
2958
|
+
try {
|
|
2959
|
+
for (var _c = __values(keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2960
|
+
var stateId = _d.value;
|
|
2961
|
+
var state = states[stateId];
|
|
2962
|
+
|
|
2963
|
+
if (state.states) {
|
|
2964
|
+
try {
|
|
2965
|
+
for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2966
|
+
var event_1 = _f.value;
|
|
2967
|
+
events.add("" + event_1);
|
|
2968
|
+
}
|
|
2969
|
+
} catch (e_8_1) {
|
|
2970
|
+
e_8 = {
|
|
2971
|
+
error: e_8_1
|
|
2972
|
+
};
|
|
2973
|
+
} finally {
|
|
2974
|
+
try {
|
|
2975
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
2976
|
+
} finally {
|
|
2977
|
+
if (e_8) throw e_8.error;
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
} catch (e_7_1) {
|
|
2983
|
+
e_7 = {
|
|
2984
|
+
error: e_7_1
|
|
2985
|
+
};
|
|
2986
|
+
} finally {
|
|
2987
|
+
try {
|
|
2988
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
2989
|
+
} finally {
|
|
2990
|
+
if (e_7) throw e_7.error;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
return this.__cache.events = Array.from(events);
|
|
2996
|
+
},
|
|
2997
|
+
enumerable: false,
|
|
2998
|
+
configurable: true
|
|
2999
|
+
});
|
|
3000
|
+
Object.defineProperty(StateNode.prototype, "ownEvents", {
|
|
3001
|
+
/**
|
|
3002
|
+
* All the events that have transitions directly from this state node.
|
|
3003
|
+
*
|
|
3004
|
+
* Excludes any inert events.
|
|
3005
|
+
*/
|
|
3006
|
+
get: function () {
|
|
3007
|
+
var events = new Set(this.transitions.filter(function (transition) {
|
|
3008
|
+
return !(!transition.target && !transition.actions.length && transition.internal);
|
|
3009
|
+
}).map(function (transition) {
|
|
3010
|
+
return transition.eventType;
|
|
3011
|
+
}));
|
|
3012
|
+
return Array.from(events);
|
|
3013
|
+
},
|
|
3014
|
+
enumerable: false,
|
|
3015
|
+
configurable: true
|
|
3016
|
+
});
|
|
3017
|
+
|
|
3018
|
+
StateNode.prototype.resolveTarget = function (_target) {
|
|
3019
|
+
var _this = this;
|
|
3020
|
+
|
|
3021
|
+
if (_target === undefined) {
|
|
3022
|
+
// an undefined target signals that the state node should not transition from that state when receiving that event
|
|
3023
|
+
return undefined;
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
return _target.map(function (target) {
|
|
3027
|
+
if (!isString(target)) {
|
|
3028
|
+
return target;
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
var isInternalTarget = target[0] === _this.delimiter; // If internal target is defined on machine,
|
|
3032
|
+
// do not include machine key on target
|
|
3033
|
+
|
|
3034
|
+
if (isInternalTarget && !_this.parent) {
|
|
3035
|
+
return _this.getStateNodeByPath(target.slice(1));
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
var resolvedTarget = isInternalTarget ? _this.key + target : target;
|
|
3039
|
+
|
|
3040
|
+
if (_this.parent) {
|
|
3041
|
+
try {
|
|
3042
|
+
var targetStateNode = _this.parent.getStateNodeByPath(resolvedTarget);
|
|
3043
|
+
|
|
3044
|
+
return targetStateNode;
|
|
3045
|
+
} catch (err) {
|
|
3046
|
+
throw new Error("Invalid transition definition for state node '" + _this.id + "':\n" + err.message);
|
|
3047
|
+
}
|
|
3048
|
+
} else {
|
|
3049
|
+
return _this.getStateNodeByPath(resolvedTarget);
|
|
3050
|
+
}
|
|
3051
|
+
});
|
|
3052
|
+
};
|
|
3053
|
+
|
|
3054
|
+
StateNode.prototype.formatTransition = function (transitionConfig) {
|
|
3055
|
+
var _this = this;
|
|
3056
|
+
|
|
3057
|
+
var normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
3058
|
+
var internal = 'internal' in transitionConfig ? transitionConfig.internal : normalizedTarget ? normalizedTarget.some(function (_target) {
|
|
3059
|
+
return isString(_target) && _target[0] === _this.delimiter;
|
|
3060
|
+
}) : true;
|
|
3061
|
+
var guards = this.machine.options.guards;
|
|
3062
|
+
var target = this.resolveTarget(normalizedTarget);
|
|
3063
|
+
|
|
3064
|
+
var transition = __assign(__assign({}, transitionConfig), {
|
|
3065
|
+
actions: toActionObjects(toArray(transitionConfig.actions)),
|
|
3066
|
+
cond: toGuard(transitionConfig.cond, guards),
|
|
3067
|
+
target: target,
|
|
3068
|
+
source: this,
|
|
3069
|
+
internal: internal,
|
|
3070
|
+
eventType: transitionConfig.event,
|
|
3071
|
+
toJSON: function () {
|
|
3072
|
+
return __assign(__assign({}, transition), {
|
|
3073
|
+
target: transition.target ? transition.target.map(function (t) {
|
|
3074
|
+
return "#" + t.id;
|
|
3075
|
+
}) : undefined,
|
|
3076
|
+
source: "#" + _this.id
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
});
|
|
3080
|
+
|
|
3081
|
+
return transition;
|
|
3082
|
+
};
|
|
3083
|
+
|
|
3084
|
+
StateNode.prototype.formatTransitions = function () {
|
|
3085
|
+
var e_9, _a;
|
|
3086
|
+
|
|
3087
|
+
var _this = this;
|
|
3088
|
+
|
|
3089
|
+
var onConfig;
|
|
3090
|
+
|
|
3091
|
+
if (!this.config.on) {
|
|
3092
|
+
onConfig = [];
|
|
3093
|
+
} else if (Array.isArray(this.config.on)) {
|
|
3094
|
+
onConfig = this.config.on;
|
|
3095
|
+
} else {
|
|
3096
|
+
var _b = this.config.on,
|
|
3097
|
+
_c = WILDCARD,
|
|
3098
|
+
_d = _b[_c],
|
|
3099
|
+
wildcardConfigs = _d === void 0 ? [] : _d,
|
|
3100
|
+
strictTransitionConfigs_1 = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
3101
|
+
|
|
3102
|
+
onConfig = flatten(keys(strictTransitionConfigs_1).map(function (key) {
|
|
3103
|
+
|
|
3104
|
+
var transitionConfigArray = toTransitionConfigArray(key, strictTransitionConfigs_1[key]);
|
|
3105
|
+
|
|
3106
|
+
return transitionConfigArray;
|
|
3107
|
+
}).concat(toTransitionConfigArray(WILDCARD, wildcardConfigs)));
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
var eventlessConfig = this.config.always ? toTransitionConfigArray('', this.config.always) : [];
|
|
3111
|
+
var doneConfig = this.config.onDone ? toTransitionConfigArray(String(done(this.id)), this.config.onDone) : [];
|
|
3112
|
+
|
|
3113
|
+
var invokeConfig = flatten(this.invoke.map(function (invokeDef) {
|
|
3114
|
+
var settleTransitions = [];
|
|
3115
|
+
|
|
3116
|
+
if (invokeDef.onDone) {
|
|
3117
|
+
settleTransitions.push.apply(settleTransitions, __spread(toTransitionConfigArray(String(doneInvoke(invokeDef.id)), invokeDef.onDone)));
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
if (invokeDef.onError) {
|
|
3121
|
+
settleTransitions.push.apply(settleTransitions, __spread(toTransitionConfigArray(String(error(invokeDef.id)), invokeDef.onError)));
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
return settleTransitions;
|
|
3125
|
+
}));
|
|
3126
|
+
var delayedTransitions = this.after;
|
|
3127
|
+
var formattedTransitions = flatten(__spread(doneConfig, invokeConfig, onConfig, eventlessConfig).map(function (transitionConfig) {
|
|
3128
|
+
return toArray(transitionConfig).map(function (transition) {
|
|
3129
|
+
return _this.formatTransition(transition);
|
|
3130
|
+
});
|
|
3131
|
+
}));
|
|
3132
|
+
|
|
3133
|
+
try {
|
|
3134
|
+
for (var delayedTransitions_1 = __values(delayedTransitions), delayedTransitions_1_1 = delayedTransitions_1.next(); !delayedTransitions_1_1.done; delayedTransitions_1_1 = delayedTransitions_1.next()) {
|
|
3135
|
+
var delayedTransition = delayedTransitions_1_1.value;
|
|
3136
|
+
formattedTransitions.push(delayedTransition);
|
|
3137
|
+
}
|
|
3138
|
+
} catch (e_9_1) {
|
|
3139
|
+
e_9 = {
|
|
3140
|
+
error: e_9_1
|
|
3141
|
+
};
|
|
3142
|
+
} finally {
|
|
3143
|
+
try {
|
|
3144
|
+
if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
|
|
3145
|
+
} finally {
|
|
3146
|
+
if (e_9) throw e_9.error;
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
return formattedTransitions;
|
|
3151
|
+
};
|
|
3152
|
+
|
|
3153
|
+
return StateNode;
|
|
3154
|
+
}();
|
|
3155
|
+
|
|
3156
|
+
function Machine(config, options, initialContext) {
|
|
3157
|
+
if (initialContext === void 0) {
|
|
3158
|
+
initialContext = config.context;
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
var resolvedInitialContext = typeof initialContext === 'function' ? initialContext() : initialContext;
|
|
3162
|
+
return new StateNode(config, options, resolvedInitialContext);
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
var defaultOptions = {
|
|
3166
|
+
deferEvents: false
|
|
3167
|
+
};
|
|
3168
|
+
|
|
3169
|
+
var Scheduler =
|
|
3170
|
+
/*#__PURE__*/
|
|
3171
|
+
|
|
3172
|
+
/** @class */
|
|
3173
|
+
function () {
|
|
3174
|
+
function Scheduler(options) {
|
|
3175
|
+
this.processingEvent = false;
|
|
3176
|
+
this.queue = [];
|
|
3177
|
+
this.initialized = false;
|
|
3178
|
+
this.options = __assign(__assign({}, defaultOptions), options);
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
Scheduler.prototype.initialize = function (callback) {
|
|
3182
|
+
this.initialized = true;
|
|
3183
|
+
|
|
3184
|
+
if (callback) {
|
|
3185
|
+
if (!this.options.deferEvents) {
|
|
3186
|
+
this.schedule(callback);
|
|
3187
|
+
return;
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
this.process(callback);
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
this.flushEvents();
|
|
3194
|
+
};
|
|
3195
|
+
|
|
3196
|
+
Scheduler.prototype.schedule = function (task) {
|
|
3197
|
+
if (!this.initialized || this.processingEvent) {
|
|
3198
|
+
this.queue.push(task);
|
|
3199
|
+
return;
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
if (this.queue.length !== 0) {
|
|
3203
|
+
throw new Error('Event queue should be empty when it is not processing events');
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
this.process(task);
|
|
3207
|
+
this.flushEvents();
|
|
3208
|
+
};
|
|
3209
|
+
|
|
3210
|
+
Scheduler.prototype.clear = function () {
|
|
3211
|
+
this.queue = [];
|
|
3212
|
+
};
|
|
3213
|
+
|
|
3214
|
+
Scheduler.prototype.flushEvents = function () {
|
|
3215
|
+
var nextCallback = this.queue.shift();
|
|
3216
|
+
|
|
3217
|
+
while (nextCallback) {
|
|
3218
|
+
this.process(nextCallback);
|
|
3219
|
+
nextCallback = this.queue.shift();
|
|
3220
|
+
}
|
|
3221
|
+
};
|
|
3222
|
+
|
|
3223
|
+
Scheduler.prototype.process = function (callback) {
|
|
3224
|
+
this.processingEvent = true;
|
|
3225
|
+
|
|
3226
|
+
try {
|
|
3227
|
+
callback();
|
|
3228
|
+
} catch (e) {
|
|
3229
|
+
// there is no use to keep the future events
|
|
3230
|
+
// as the situation is not anymore the same
|
|
3231
|
+
this.clear();
|
|
3232
|
+
throw e;
|
|
3233
|
+
} finally {
|
|
3234
|
+
this.processingEvent = false;
|
|
3235
|
+
}
|
|
3236
|
+
};
|
|
3237
|
+
|
|
3238
|
+
return Scheduler;
|
|
3239
|
+
}();
|
|
3240
|
+
|
|
3241
|
+
var children = /*#__PURE__*/new Map();
|
|
3242
|
+
var sessionIdIndex = 0;
|
|
3243
|
+
var registry = {
|
|
3244
|
+
bookId: function () {
|
|
3245
|
+
return "x:" + sessionIdIndex++;
|
|
3246
|
+
},
|
|
3247
|
+
register: function (id, actor) {
|
|
3248
|
+
children.set(id, actor);
|
|
3249
|
+
return id;
|
|
3250
|
+
},
|
|
3251
|
+
get: function (id) {
|
|
3252
|
+
return children.get(id);
|
|
3253
|
+
},
|
|
3254
|
+
free: function (id) {
|
|
3255
|
+
children.delete(id);
|
|
3256
|
+
}
|
|
3257
|
+
};
|
|
3258
|
+
|
|
3259
|
+
function getGlobal() {
|
|
3260
|
+
if (typeof self !== 'undefined') {
|
|
3261
|
+
return self;
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
if (typeof window !== 'undefined') {
|
|
3265
|
+
return window;
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
if (typeof global !== 'undefined') {
|
|
3269
|
+
return global;
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
return undefined;
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
var DEFAULT_SPAWN_OPTIONS = {
|
|
3276
|
+
sync: false,
|
|
3277
|
+
autoForward: false
|
|
3278
|
+
};
|
|
3279
|
+
var InterpreterStatus;
|
|
3280
|
+
|
|
3281
|
+
(function (InterpreterStatus) {
|
|
3282
|
+
InterpreterStatus[InterpreterStatus["NotStarted"] = 0] = "NotStarted";
|
|
3283
|
+
InterpreterStatus[InterpreterStatus["Running"] = 1] = "Running";
|
|
3284
|
+
InterpreterStatus[InterpreterStatus["Stopped"] = 2] = "Stopped";
|
|
3285
|
+
})(InterpreterStatus || (InterpreterStatus = {}));
|
|
3286
|
+
|
|
3287
|
+
var Interpreter =
|
|
3288
|
+
/*#__PURE__*/
|
|
3289
|
+
|
|
3290
|
+
/** @class */
|
|
3291
|
+
function () {
|
|
3292
|
+
/**
|
|
3293
|
+
* Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.
|
|
3294
|
+
*
|
|
3295
|
+
* @param machine The machine to be interpreted
|
|
3296
|
+
* @param options Interpreter options
|
|
3297
|
+
*/
|
|
3298
|
+
function Interpreter(machine, options) {
|
|
3299
|
+
var _this = this;
|
|
3300
|
+
|
|
3301
|
+
if (options === void 0) {
|
|
3302
|
+
options = Interpreter.defaultOptions;
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3305
|
+
this.machine = machine;
|
|
3306
|
+
this.scheduler = new Scheduler();
|
|
3307
|
+
this.delayedEventsMap = {};
|
|
3308
|
+
this.listeners = new Set();
|
|
3309
|
+
this.contextListeners = new Set();
|
|
3310
|
+
this.stopListeners = new Set();
|
|
3311
|
+
this.doneListeners = new Set();
|
|
3312
|
+
this.eventListeners = new Set();
|
|
3313
|
+
this.sendListeners = new Set();
|
|
3314
|
+
/**
|
|
3315
|
+
* Whether the service is started.
|
|
3316
|
+
*/
|
|
3317
|
+
|
|
3318
|
+
this.initialized = false;
|
|
3319
|
+
this.status = InterpreterStatus.NotStarted;
|
|
3320
|
+
this.children = new Map();
|
|
3321
|
+
this.forwardTo = new Set();
|
|
3322
|
+
/**
|
|
3323
|
+
* Alias for Interpreter.prototype.start
|
|
3324
|
+
*/
|
|
3325
|
+
|
|
3326
|
+
this.init = this.start;
|
|
3327
|
+
/**
|
|
3328
|
+
* Sends an event to the running interpreter to trigger a transition.
|
|
3329
|
+
*
|
|
3330
|
+
* An array of events (batched) can be sent as well, which will send all
|
|
3331
|
+
* batched events to the running interpreter. The listeners will be
|
|
3332
|
+
* notified only **once** when all events are processed.
|
|
3333
|
+
*
|
|
3334
|
+
* @param event The event(s) to send
|
|
3335
|
+
*/
|
|
3336
|
+
|
|
3337
|
+
this.send = function (event, payload) {
|
|
3338
|
+
if (isArray(event)) {
|
|
3339
|
+
_this.batch(event);
|
|
3340
|
+
|
|
3341
|
+
return _this.state;
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
var _event = toSCXMLEvent(toEventObject(event, payload));
|
|
3345
|
+
|
|
3346
|
+
if (_this.status === InterpreterStatus.Stopped) {
|
|
3347
|
+
|
|
3348
|
+
return _this.state;
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
if (_this.status !== InterpreterStatus.Running && !_this.options.deferEvents) {
|
|
3352
|
+
throw new Error("Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: " + JSON.stringify(_event.data));
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
_this.scheduler.schedule(function () {
|
|
3356
|
+
// Forward copy of event to child actors
|
|
3357
|
+
_this.forward(_event);
|
|
3358
|
+
|
|
3359
|
+
var nextState = _this.nextState(_event);
|
|
3360
|
+
|
|
3361
|
+
_this.update(nextState, _event);
|
|
3362
|
+
});
|
|
3363
|
+
|
|
3364
|
+
return _this._state; // TODO: deprecate (should return void)
|
|
3365
|
+
// tslint:disable-next-line:semicolon
|
|
3366
|
+
};
|
|
3367
|
+
|
|
3368
|
+
this.sendTo = function (event, to) {
|
|
3369
|
+
var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
|
|
3370
|
+
var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
|
|
3371
|
+
|
|
3372
|
+
if (!target) {
|
|
3373
|
+
if (!isParent) {
|
|
3374
|
+
throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
|
|
3375
|
+
} // tslint:disable-next-line:no-console
|
|
3376
|
+
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
if ('machine' in target) {
|
|
3381
|
+
// Send SCXML events to machines
|
|
3382
|
+
target.send(__assign(__assign({}, event), {
|
|
3383
|
+
name: event.name === error$1 ? "" + error(_this.id) : event.name,
|
|
3384
|
+
origin: _this.sessionId
|
|
3385
|
+
}));
|
|
3386
|
+
} else {
|
|
3387
|
+
// Send normal events to other targets
|
|
3388
|
+
target.send(event.data);
|
|
3389
|
+
}
|
|
3390
|
+
};
|
|
3391
|
+
|
|
3392
|
+
var resolvedOptions = __assign(__assign({}, Interpreter.defaultOptions), options);
|
|
3393
|
+
|
|
3394
|
+
var clock = resolvedOptions.clock,
|
|
3395
|
+
logger = resolvedOptions.logger,
|
|
3396
|
+
parent = resolvedOptions.parent,
|
|
3397
|
+
id = resolvedOptions.id;
|
|
3398
|
+
var resolvedId = id !== undefined ? id : machine.id;
|
|
3399
|
+
this.id = resolvedId;
|
|
3400
|
+
this.logger = logger;
|
|
3401
|
+
this.clock = clock;
|
|
3402
|
+
this.parent = parent;
|
|
3403
|
+
this.options = resolvedOptions;
|
|
3404
|
+
this.scheduler = new Scheduler({
|
|
3405
|
+
deferEvents: this.options.deferEvents
|
|
3406
|
+
});
|
|
3407
|
+
this.sessionId = registry.bookId();
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
Object.defineProperty(Interpreter.prototype, "initialState", {
|
|
3411
|
+
get: function () {
|
|
3412
|
+
var _this = this;
|
|
3413
|
+
|
|
3414
|
+
if (this._initialState) {
|
|
3415
|
+
return this._initialState;
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
return provide(this, function () {
|
|
3419
|
+
_this._initialState = _this.machine.initialState;
|
|
3420
|
+
return _this._initialState;
|
|
3421
|
+
});
|
|
3422
|
+
},
|
|
3423
|
+
enumerable: false,
|
|
3424
|
+
configurable: true
|
|
3425
|
+
});
|
|
3426
|
+
Object.defineProperty(Interpreter.prototype, "state", {
|
|
3427
|
+
get: function () {
|
|
3428
|
+
|
|
3429
|
+
return this._state;
|
|
3430
|
+
},
|
|
3431
|
+
enumerable: false,
|
|
3432
|
+
configurable: true
|
|
3433
|
+
});
|
|
3434
|
+
/**
|
|
3435
|
+
* Executes the actions of the given state, with that state's `context` and `event`.
|
|
3436
|
+
*
|
|
3437
|
+
* @param state The state whose actions will be executed
|
|
3438
|
+
* @param actionsConfig The action implementations to use
|
|
3439
|
+
*/
|
|
3440
|
+
|
|
3441
|
+
Interpreter.prototype.execute = function (state, actionsConfig) {
|
|
3442
|
+
var e_1, _a;
|
|
3443
|
+
|
|
3444
|
+
try {
|
|
3445
|
+
for (var _b = __values(state.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3446
|
+
var action = _c.value;
|
|
3447
|
+
this.exec(action, state, actionsConfig);
|
|
3448
|
+
}
|
|
3449
|
+
} catch (e_1_1) {
|
|
3450
|
+
e_1 = {
|
|
3451
|
+
error: e_1_1
|
|
3452
|
+
};
|
|
3453
|
+
} finally {
|
|
3454
|
+
try {
|
|
3455
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3456
|
+
} finally {
|
|
3457
|
+
if (e_1) throw e_1.error;
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
};
|
|
3461
|
+
|
|
3462
|
+
Interpreter.prototype.update = function (state, _event) {
|
|
3463
|
+
var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
|
|
3464
|
+
|
|
3465
|
+
var _this = this; // Attach session ID to state
|
|
3466
|
+
|
|
3467
|
+
|
|
3468
|
+
state._sessionid = this.sessionId; // Update state
|
|
3469
|
+
|
|
3470
|
+
this._state = state; // Execute actions
|
|
3471
|
+
|
|
3472
|
+
if (this.options.execute) {
|
|
3473
|
+
this.execute(this.state);
|
|
3474
|
+
} // Update children
|
|
3475
|
+
|
|
3476
|
+
|
|
3477
|
+
this.children.forEach(function (child) {
|
|
3478
|
+
_this.state.children[child.id] = child;
|
|
3479
|
+
}); // Dev tools
|
|
3480
|
+
|
|
3481
|
+
if (this.devTools) {
|
|
3482
|
+
this.devTools.send(_event.data, state);
|
|
3483
|
+
} // Execute listeners
|
|
3484
|
+
|
|
3485
|
+
|
|
3486
|
+
if (state.event) {
|
|
3487
|
+
try {
|
|
3488
|
+
for (var _e = __values(this.eventListeners), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
3489
|
+
var listener = _f.value;
|
|
3490
|
+
listener(state.event);
|
|
3491
|
+
}
|
|
3492
|
+
} catch (e_2_1) {
|
|
3493
|
+
e_2 = {
|
|
3494
|
+
error: e_2_1
|
|
3495
|
+
};
|
|
3496
|
+
} finally {
|
|
3497
|
+
try {
|
|
3498
|
+
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
3499
|
+
} finally {
|
|
3500
|
+
if (e_2) throw e_2.error;
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
try {
|
|
3506
|
+
for (var _g = __values(this.listeners), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
3507
|
+
var listener = _h.value;
|
|
3508
|
+
listener(state, state.event);
|
|
3509
|
+
}
|
|
3510
|
+
} catch (e_3_1) {
|
|
3511
|
+
e_3 = {
|
|
3512
|
+
error: e_3_1
|
|
3513
|
+
};
|
|
3514
|
+
} finally {
|
|
3515
|
+
try {
|
|
3516
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
3517
|
+
} finally {
|
|
3518
|
+
if (e_3) throw e_3.error;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
try {
|
|
3523
|
+
for (var _j = __values(this.contextListeners), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
3524
|
+
var contextListener = _k.value;
|
|
3525
|
+
contextListener(this.state.context, this.state.history ? this.state.history.context : undefined);
|
|
3526
|
+
}
|
|
3527
|
+
} catch (e_4_1) {
|
|
3528
|
+
e_4 = {
|
|
3529
|
+
error: e_4_1
|
|
3530
|
+
};
|
|
3531
|
+
} finally {
|
|
3532
|
+
try {
|
|
3533
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
3534
|
+
} finally {
|
|
3535
|
+
if (e_4) throw e_4.error;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
var isDone = isInFinalState(state.configuration || [], this.machine);
|
|
3540
|
+
|
|
3541
|
+
if (this.state.configuration && isDone) {
|
|
3542
|
+
// get final child state node
|
|
3543
|
+
var finalChildStateNode = state.configuration.find(function (sn) {
|
|
3544
|
+
return sn.type === 'final' && sn.parent === _this.machine;
|
|
3545
|
+
});
|
|
3546
|
+
var doneData = finalChildStateNode && finalChildStateNode.doneData ? mapContext(finalChildStateNode.doneData, state.context, _event) : undefined;
|
|
3547
|
+
|
|
3548
|
+
try {
|
|
3549
|
+
for (var _l = __values(this.doneListeners), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
3550
|
+
var listener = _m.value;
|
|
3551
|
+
listener(doneInvoke(this.id, doneData));
|
|
3552
|
+
}
|
|
3553
|
+
} catch (e_5_1) {
|
|
3554
|
+
e_5 = {
|
|
3555
|
+
error: e_5_1
|
|
3556
|
+
};
|
|
3557
|
+
} finally {
|
|
3558
|
+
try {
|
|
3559
|
+
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
3560
|
+
} finally {
|
|
3561
|
+
if (e_5) throw e_5.error;
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
this.stop();
|
|
3566
|
+
}
|
|
3567
|
+
};
|
|
3568
|
+
/*
|
|
3569
|
+
* Adds a listener that is notified whenever a state transition happens. The listener is called with
|
|
3570
|
+
* the next state and the event object that caused the state transition.
|
|
3571
|
+
*
|
|
3572
|
+
* @param listener The state listener
|
|
3573
|
+
*/
|
|
3574
|
+
|
|
3575
|
+
|
|
3576
|
+
Interpreter.prototype.onTransition = function (listener) {
|
|
3577
|
+
this.listeners.add(listener); // Send current state to listener
|
|
3578
|
+
|
|
3579
|
+
if (this.status === InterpreterStatus.Running) {
|
|
3580
|
+
listener(this.state, this.state.event);
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
return this;
|
|
3584
|
+
};
|
|
3585
|
+
|
|
3586
|
+
Interpreter.prototype.subscribe = function (nextListenerOrObserver, _, // TODO: error listener
|
|
3587
|
+
completeListener) {
|
|
3588
|
+
var _this = this;
|
|
3589
|
+
|
|
3590
|
+
if (!nextListenerOrObserver) {
|
|
3591
|
+
return {
|
|
3592
|
+
unsubscribe: function () {
|
|
3593
|
+
return void 0;
|
|
3594
|
+
}
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
var listener;
|
|
3599
|
+
var resolvedCompleteListener = completeListener;
|
|
3600
|
+
|
|
3601
|
+
if (typeof nextListenerOrObserver === 'function') {
|
|
3602
|
+
listener = nextListenerOrObserver;
|
|
3603
|
+
} else {
|
|
3604
|
+
listener = nextListenerOrObserver.next.bind(nextListenerOrObserver);
|
|
3605
|
+
resolvedCompleteListener = nextListenerOrObserver.complete.bind(nextListenerOrObserver);
|
|
3606
|
+
}
|
|
3607
|
+
|
|
3608
|
+
this.listeners.add(listener); // Send current state to listener
|
|
3609
|
+
|
|
3610
|
+
if (this.status === InterpreterStatus.Running) {
|
|
3611
|
+
listener(this.state);
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
if (resolvedCompleteListener) {
|
|
3615
|
+
this.onDone(resolvedCompleteListener);
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
return {
|
|
3619
|
+
unsubscribe: function () {
|
|
3620
|
+
listener && _this.listeners.delete(listener);
|
|
3621
|
+
resolvedCompleteListener && _this.doneListeners.delete(resolvedCompleteListener);
|
|
3622
|
+
}
|
|
3623
|
+
};
|
|
3624
|
+
};
|
|
3625
|
+
/**
|
|
3626
|
+
* Adds an event listener that is notified whenever an event is sent to the running interpreter.
|
|
3627
|
+
* @param listener The event listener
|
|
3628
|
+
*/
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
Interpreter.prototype.onEvent = function (listener) {
|
|
3632
|
+
this.eventListeners.add(listener);
|
|
3633
|
+
return this;
|
|
3634
|
+
};
|
|
3635
|
+
/**
|
|
3636
|
+
* Adds an event listener that is notified whenever a `send` event occurs.
|
|
3637
|
+
* @param listener The event listener
|
|
3638
|
+
*/
|
|
3639
|
+
|
|
3640
|
+
|
|
3641
|
+
Interpreter.prototype.onSend = function (listener) {
|
|
3642
|
+
this.sendListeners.add(listener);
|
|
3643
|
+
return this;
|
|
3644
|
+
};
|
|
3645
|
+
/**
|
|
3646
|
+
* Adds a context listener that is notified whenever the state context changes.
|
|
3647
|
+
* @param listener The context listener
|
|
3648
|
+
*/
|
|
3649
|
+
|
|
3650
|
+
|
|
3651
|
+
Interpreter.prototype.onChange = function (listener) {
|
|
3652
|
+
this.contextListeners.add(listener);
|
|
3653
|
+
return this;
|
|
3654
|
+
};
|
|
3655
|
+
/**
|
|
3656
|
+
* Adds a listener that is notified when the machine is stopped.
|
|
3657
|
+
* @param listener The listener
|
|
3658
|
+
*/
|
|
3659
|
+
|
|
3660
|
+
|
|
3661
|
+
Interpreter.prototype.onStop = function (listener) {
|
|
3662
|
+
this.stopListeners.add(listener);
|
|
3663
|
+
return this;
|
|
3664
|
+
};
|
|
3665
|
+
/**
|
|
3666
|
+
* Adds a state listener that is notified when the statechart has reached its final state.
|
|
3667
|
+
* @param listener The state listener
|
|
3668
|
+
*/
|
|
3669
|
+
|
|
3670
|
+
|
|
3671
|
+
Interpreter.prototype.onDone = function (listener) {
|
|
3672
|
+
this.doneListeners.add(listener);
|
|
3673
|
+
return this;
|
|
3674
|
+
};
|
|
3675
|
+
/**
|
|
3676
|
+
* Removes a listener.
|
|
3677
|
+
* @param listener The listener to remove
|
|
3678
|
+
*/
|
|
3679
|
+
|
|
3680
|
+
|
|
3681
|
+
Interpreter.prototype.off = function (listener) {
|
|
3682
|
+
this.listeners.delete(listener);
|
|
3683
|
+
this.eventListeners.delete(listener);
|
|
3684
|
+
this.sendListeners.delete(listener);
|
|
3685
|
+
this.stopListeners.delete(listener);
|
|
3686
|
+
this.doneListeners.delete(listener);
|
|
3687
|
+
this.contextListeners.delete(listener);
|
|
3688
|
+
return this;
|
|
3689
|
+
};
|
|
3690
|
+
/**
|
|
3691
|
+
* Starts the interpreter from the given state, or the initial state.
|
|
3692
|
+
* @param initialState The state to start the statechart from
|
|
3693
|
+
*/
|
|
3694
|
+
|
|
3695
|
+
|
|
3696
|
+
Interpreter.prototype.start = function (initialState) {
|
|
3697
|
+
var _this = this;
|
|
3698
|
+
|
|
3699
|
+
if (this.status === InterpreterStatus.Running) {
|
|
3700
|
+
// Do not restart the service if it is already started
|
|
3701
|
+
return this;
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
registry.register(this.sessionId, this);
|
|
3705
|
+
this.initialized = true;
|
|
3706
|
+
this.status = InterpreterStatus.Running;
|
|
3707
|
+
var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
|
|
3708
|
+
return isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
|
|
3709
|
+
});
|
|
3710
|
+
|
|
3711
|
+
if (this.options.devTools) {
|
|
3712
|
+
this.attachDev();
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
this.scheduler.initialize(function () {
|
|
3716
|
+
_this.update(resolvedState, initEvent);
|
|
3717
|
+
});
|
|
3718
|
+
return this;
|
|
3719
|
+
};
|
|
3720
|
+
/**
|
|
3721
|
+
* Stops the interpreter and unsubscribe all listeners.
|
|
3722
|
+
*
|
|
3723
|
+
* This will also notify the `onStop` listeners.
|
|
3724
|
+
*/
|
|
3725
|
+
|
|
3726
|
+
|
|
3727
|
+
Interpreter.prototype.stop = function () {
|
|
3728
|
+
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
|
|
3729
|
+
|
|
3730
|
+
var _this = this;
|
|
3731
|
+
|
|
3732
|
+
try {
|
|
3733
|
+
for (var _f = __values(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
3734
|
+
var listener = _g.value;
|
|
3735
|
+
this.listeners.delete(listener);
|
|
3736
|
+
}
|
|
3737
|
+
} catch (e_6_1) {
|
|
3738
|
+
e_6 = {
|
|
3739
|
+
error: e_6_1
|
|
3740
|
+
};
|
|
3741
|
+
} finally {
|
|
3742
|
+
try {
|
|
3743
|
+
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
3744
|
+
} finally {
|
|
3745
|
+
if (e_6) throw e_6.error;
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
|
|
3749
|
+
try {
|
|
3750
|
+
for (var _h = __values(this.stopListeners), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
3751
|
+
var listener = _j.value; // call listener, then remove
|
|
3752
|
+
|
|
3753
|
+
listener();
|
|
3754
|
+
this.stopListeners.delete(listener);
|
|
3755
|
+
}
|
|
3756
|
+
} catch (e_7_1) {
|
|
3757
|
+
e_7 = {
|
|
3758
|
+
error: e_7_1
|
|
3759
|
+
};
|
|
3760
|
+
} finally {
|
|
3761
|
+
try {
|
|
3762
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
3763
|
+
} finally {
|
|
3764
|
+
if (e_7) throw e_7.error;
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
|
|
3768
|
+
try {
|
|
3769
|
+
for (var _k = __values(this.contextListeners), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
3770
|
+
var listener = _l.value;
|
|
3771
|
+
this.contextListeners.delete(listener);
|
|
3772
|
+
}
|
|
3773
|
+
} catch (e_8_1) {
|
|
3774
|
+
e_8 = {
|
|
3775
|
+
error: e_8_1
|
|
3776
|
+
};
|
|
3777
|
+
} finally {
|
|
3778
|
+
try {
|
|
3779
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
3780
|
+
} finally {
|
|
3781
|
+
if (e_8) throw e_8.error;
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
|
|
3785
|
+
try {
|
|
3786
|
+
for (var _m = __values(this.doneListeners), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
3787
|
+
var listener = _o.value;
|
|
3788
|
+
this.doneListeners.delete(listener);
|
|
3789
|
+
}
|
|
3790
|
+
} catch (e_9_1) {
|
|
3791
|
+
e_9 = {
|
|
3792
|
+
error: e_9_1
|
|
3793
|
+
};
|
|
3794
|
+
} finally {
|
|
3795
|
+
try {
|
|
3796
|
+
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
3797
|
+
} finally {
|
|
3798
|
+
if (e_9) throw e_9.error;
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
if (!this.initialized) {
|
|
3803
|
+
// Interpreter already stopped; do nothing
|
|
3804
|
+
return this;
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
this.state.configuration.forEach(function (stateNode) {
|
|
3808
|
+
var e_11, _a;
|
|
3809
|
+
|
|
3810
|
+
try {
|
|
3811
|
+
for (var _b = __values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3812
|
+
var action = _c.value;
|
|
3813
|
+
|
|
3814
|
+
_this.exec(action, _this.state);
|
|
3815
|
+
}
|
|
3816
|
+
} catch (e_11_1) {
|
|
3817
|
+
e_11 = {
|
|
3818
|
+
error: e_11_1
|
|
3819
|
+
};
|
|
3820
|
+
} finally {
|
|
3821
|
+
try {
|
|
3822
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3823
|
+
} finally {
|
|
3824
|
+
if (e_11) throw e_11.error;
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
}); // Stop all children
|
|
3828
|
+
|
|
3829
|
+
this.children.forEach(function (child) {
|
|
3830
|
+
if (isFunction(child.stop)) {
|
|
3831
|
+
child.stop();
|
|
3832
|
+
}
|
|
3833
|
+
});
|
|
3834
|
+
|
|
3835
|
+
try {
|
|
3836
|
+
// Cancel all delayed events
|
|
3837
|
+
for (var _p = __values(keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
3838
|
+
var key = _q.value;
|
|
3839
|
+
this.clock.clearTimeout(this.delayedEventsMap[key]);
|
|
3840
|
+
}
|
|
3841
|
+
} catch (e_10_1) {
|
|
3842
|
+
e_10 = {
|
|
3843
|
+
error: e_10_1
|
|
3844
|
+
};
|
|
3845
|
+
} finally {
|
|
3846
|
+
try {
|
|
3847
|
+
if (_q && !_q.done && (_e = _p.return)) _e.call(_p);
|
|
3848
|
+
} finally {
|
|
3849
|
+
if (e_10) throw e_10.error;
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
|
|
3853
|
+
this.scheduler.clear();
|
|
3854
|
+
this.initialized = false;
|
|
3855
|
+
this.status = InterpreterStatus.Stopped;
|
|
3856
|
+
registry.free(this.sessionId);
|
|
3857
|
+
return this;
|
|
3858
|
+
};
|
|
3859
|
+
|
|
3860
|
+
Interpreter.prototype.batch = function (events) {
|
|
3861
|
+
var _this = this;
|
|
3862
|
+
|
|
3863
|
+
if (this.status === InterpreterStatus.NotStarted && this.options.deferEvents) ; else if (this.status !== InterpreterStatus.Running) {
|
|
3864
|
+
throw new Error( // tslint:disable-next-line:max-line-length
|
|
3865
|
+
events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.");
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
this.scheduler.schedule(function () {
|
|
3869
|
+
var e_12, _a;
|
|
3870
|
+
|
|
3871
|
+
var nextState = _this.state;
|
|
3872
|
+
var batchChanged = false;
|
|
3873
|
+
var batchedActions = [];
|
|
3874
|
+
|
|
3875
|
+
var _loop_1 = function (event_1) {
|
|
3876
|
+
var _event = toSCXMLEvent(event_1);
|
|
3877
|
+
|
|
3878
|
+
_this.forward(_event);
|
|
3879
|
+
|
|
3880
|
+
nextState = provide(_this, function () {
|
|
3881
|
+
return _this.machine.transition(nextState, _event);
|
|
3882
|
+
});
|
|
3883
|
+
batchedActions.push.apply(batchedActions, __spread(nextState.actions.map(function (a) {
|
|
3884
|
+
return bindActionToState(a, nextState);
|
|
3885
|
+
})));
|
|
3886
|
+
batchChanged = batchChanged || !!nextState.changed;
|
|
3887
|
+
};
|
|
3888
|
+
|
|
3889
|
+
try {
|
|
3890
|
+
for (var events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
|
|
3891
|
+
var event_1 = events_1_1.value;
|
|
3892
|
+
|
|
3893
|
+
_loop_1(event_1);
|
|
3894
|
+
}
|
|
3895
|
+
} catch (e_12_1) {
|
|
3896
|
+
e_12 = {
|
|
3897
|
+
error: e_12_1
|
|
3898
|
+
};
|
|
3899
|
+
} finally {
|
|
3900
|
+
try {
|
|
3901
|
+
if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
|
|
3902
|
+
} finally {
|
|
3903
|
+
if (e_12) throw e_12.error;
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
nextState.changed = batchChanged;
|
|
3908
|
+
nextState.actions = batchedActions;
|
|
3909
|
+
|
|
3910
|
+
_this.update(nextState, toSCXMLEvent(events[events.length - 1]));
|
|
3911
|
+
});
|
|
3912
|
+
};
|
|
3913
|
+
/**
|
|
3914
|
+
* Returns a send function bound to this interpreter instance.
|
|
3915
|
+
*
|
|
3916
|
+
* @param event The event to be sent by the sender.
|
|
3917
|
+
*/
|
|
3918
|
+
|
|
3919
|
+
|
|
3920
|
+
Interpreter.prototype.sender = function (event) {
|
|
3921
|
+
return this.send.bind(this, event);
|
|
3922
|
+
};
|
|
3923
|
+
/**
|
|
3924
|
+
* Returns the next state given the interpreter's current state and the event.
|
|
3925
|
+
*
|
|
3926
|
+
* This is a pure method that does _not_ update the interpreter's state.
|
|
3927
|
+
*
|
|
3928
|
+
* @param event The event to determine the next state
|
|
3929
|
+
*/
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
Interpreter.prototype.nextState = function (event) {
|
|
3933
|
+
var _this = this;
|
|
3934
|
+
|
|
3935
|
+
var _event = toSCXMLEvent(event);
|
|
3936
|
+
|
|
3937
|
+
if (_event.name.indexOf(errorPlatform) === 0 && !this.state.nextEvents.some(function (nextEvent) {
|
|
3938
|
+
return nextEvent.indexOf(errorPlatform) === 0;
|
|
3939
|
+
})) {
|
|
3940
|
+
throw _event.data.data;
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
var nextState = provide(this, function () {
|
|
3944
|
+
return _this.machine.transition(_this.state, _event);
|
|
3945
|
+
});
|
|
3946
|
+
return nextState;
|
|
3947
|
+
};
|
|
3948
|
+
|
|
3949
|
+
Interpreter.prototype.forward = function (event) {
|
|
3950
|
+
var e_13, _a;
|
|
3951
|
+
|
|
3952
|
+
try {
|
|
3953
|
+
for (var _b = __values(this.forwardTo), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3954
|
+
var id = _c.value;
|
|
3955
|
+
var child = this.children.get(id);
|
|
3956
|
+
|
|
3957
|
+
if (!child) {
|
|
3958
|
+
throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
child.send(event);
|
|
3962
|
+
}
|
|
3963
|
+
} catch (e_13_1) {
|
|
3964
|
+
e_13 = {
|
|
3965
|
+
error: e_13_1
|
|
3966
|
+
};
|
|
3967
|
+
} finally {
|
|
3968
|
+
try {
|
|
3969
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3970
|
+
} finally {
|
|
3971
|
+
if (e_13) throw e_13.error;
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
|
|
3976
|
+
Interpreter.prototype.defer = function (sendAction) {
|
|
3977
|
+
var _this = this;
|
|
3978
|
+
|
|
3979
|
+
this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
|
|
3980
|
+
if (sendAction.to) {
|
|
3981
|
+
_this.sendTo(sendAction._event, sendAction.to);
|
|
3982
|
+
} else {
|
|
3983
|
+
_this.send(sendAction._event);
|
|
3984
|
+
}
|
|
3985
|
+
}, sendAction.delay);
|
|
3986
|
+
};
|
|
3987
|
+
|
|
3988
|
+
Interpreter.prototype.cancel = function (sendId) {
|
|
3989
|
+
this.clock.clearTimeout(this.delayedEventsMap[sendId]);
|
|
3990
|
+
delete this.delayedEventsMap[sendId];
|
|
3991
|
+
};
|
|
3992
|
+
|
|
3993
|
+
Interpreter.prototype.exec = function (action, state, actionFunctionMap) {
|
|
3994
|
+
if (actionFunctionMap === void 0) {
|
|
3995
|
+
actionFunctionMap = this.machine.options.actions;
|
|
3996
|
+
}
|
|
3997
|
+
|
|
3998
|
+
var context = state.context,
|
|
3999
|
+
_event = state._event;
|
|
4000
|
+
var actionOrExec = action.exec || getActionFunction(action.type, actionFunctionMap);
|
|
4001
|
+
var exec = isFunction(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
|
|
4002
|
+
|
|
4003
|
+
if (exec) {
|
|
4004
|
+
try {
|
|
4005
|
+
return exec(context, _event.data, {
|
|
4006
|
+
action: action,
|
|
4007
|
+
state: this.state,
|
|
4008
|
+
_event: _event
|
|
4009
|
+
});
|
|
4010
|
+
} catch (err) {
|
|
4011
|
+
if (this.parent) {
|
|
4012
|
+
this.parent.send({
|
|
4013
|
+
type: 'xstate.error',
|
|
4014
|
+
data: err
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
throw err;
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
|
|
4022
|
+
switch (action.type) {
|
|
4023
|
+
case send$1:
|
|
4024
|
+
var sendAction = action;
|
|
4025
|
+
|
|
4026
|
+
if (typeof sendAction.delay === 'number') {
|
|
4027
|
+
this.defer(sendAction);
|
|
4028
|
+
return;
|
|
4029
|
+
} else {
|
|
4030
|
+
if (sendAction.to) {
|
|
4031
|
+
this.sendTo(sendAction._event, sendAction.to);
|
|
4032
|
+
} else {
|
|
4033
|
+
this.send(sendAction._event);
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
|
|
4037
|
+
break;
|
|
4038
|
+
|
|
4039
|
+
case cancel$1:
|
|
4040
|
+
this.cancel(action.sendId);
|
|
4041
|
+
break;
|
|
4042
|
+
|
|
4043
|
+
case start$1:
|
|
4044
|
+
{
|
|
4045
|
+
var activity = action.activity; // If the activity will be stopped right after it's started
|
|
4046
|
+
// (such as in transient states)
|
|
4047
|
+
// don't bother starting the activity.
|
|
4048
|
+
|
|
4049
|
+
if (!this.state.activities[activity.id || activity.type]) {
|
|
4050
|
+
break;
|
|
4051
|
+
} // Invoked services
|
|
4052
|
+
|
|
4053
|
+
|
|
4054
|
+
if (activity.type === ActionTypes.Invoke) {
|
|
4055
|
+
var invokeSource = toInvokeSource$1(activity.src);
|
|
4056
|
+
var serviceCreator = this.machine.options.services ? this.machine.options.services[invokeSource.type] : undefined;
|
|
4057
|
+
var id = activity.id,
|
|
4058
|
+
data = activity.data;
|
|
4059
|
+
|
|
4060
|
+
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
|
|
4061
|
+
|
|
4062
|
+
if (!serviceCreator) {
|
|
4063
|
+
|
|
4064
|
+
return;
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4067
|
+
var resolvedData = data ? mapContext(data, context, _event) : undefined;
|
|
4068
|
+
var source = isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
|
|
4069
|
+
data: resolvedData,
|
|
4070
|
+
src: invokeSource
|
|
4071
|
+
}) : serviceCreator;
|
|
4072
|
+
|
|
4073
|
+
if (isPromiseLike(source)) {
|
|
4074
|
+
this.spawnPromise(Promise.resolve(source), id);
|
|
4075
|
+
} else if (isFunction(source)) {
|
|
4076
|
+
this.spawnCallback(source, id);
|
|
4077
|
+
} else if (isObservable(source)) {
|
|
4078
|
+
this.spawnObservable(source, id);
|
|
4079
|
+
} else if (isMachine(source)) {
|
|
4080
|
+
// TODO: try/catch here
|
|
4081
|
+
this.spawnMachine(resolvedData ? source.withContext(resolvedData) : source, {
|
|
4082
|
+
id: id,
|
|
4083
|
+
autoForward: autoForward
|
|
4084
|
+
});
|
|
4085
|
+
} else ;
|
|
4086
|
+
} else {
|
|
4087
|
+
this.spawnActivity(activity);
|
|
4088
|
+
}
|
|
4089
|
+
|
|
4090
|
+
break;
|
|
4091
|
+
}
|
|
4092
|
+
|
|
4093
|
+
case stop$1:
|
|
4094
|
+
{
|
|
4095
|
+
this.stopChild(action.activity.id);
|
|
4096
|
+
break;
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
case log:
|
|
4100
|
+
var label = action.label,
|
|
4101
|
+
value = action.value;
|
|
4102
|
+
|
|
4103
|
+
if (label) {
|
|
4104
|
+
this.logger(label, value);
|
|
4105
|
+
} else {
|
|
4106
|
+
this.logger(value);
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
break;
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4112
|
+
return undefined;
|
|
4113
|
+
};
|
|
4114
|
+
|
|
4115
|
+
Interpreter.prototype.removeChild = function (childId) {
|
|
4116
|
+
this.children.delete(childId);
|
|
4117
|
+
this.forwardTo.delete(childId);
|
|
4118
|
+
delete this.state.children[childId];
|
|
4119
|
+
};
|
|
4120
|
+
|
|
4121
|
+
Interpreter.prototype.stopChild = function (childId) {
|
|
4122
|
+
var child = this.children.get(childId);
|
|
4123
|
+
|
|
4124
|
+
if (!child) {
|
|
4125
|
+
return;
|
|
4126
|
+
}
|
|
4127
|
+
|
|
4128
|
+
this.removeChild(childId);
|
|
4129
|
+
|
|
4130
|
+
if (isFunction(child.stop)) {
|
|
4131
|
+
child.stop();
|
|
4132
|
+
}
|
|
4133
|
+
};
|
|
4134
|
+
|
|
4135
|
+
Interpreter.prototype.spawn = function (entity, name, options) {
|
|
4136
|
+
if (isPromiseLike(entity)) {
|
|
4137
|
+
return this.spawnPromise(Promise.resolve(entity), name);
|
|
4138
|
+
} else if (isFunction(entity)) {
|
|
4139
|
+
return this.spawnCallback(entity, name);
|
|
4140
|
+
} else if (isSpawnedActor(entity)) {
|
|
4141
|
+
return this.spawnActor(entity);
|
|
4142
|
+
} else if (isObservable(entity)) {
|
|
4143
|
+
return this.spawnObservable(entity, name);
|
|
4144
|
+
} else if (isMachine(entity)) {
|
|
4145
|
+
return this.spawnMachine(entity, __assign(__assign({}, options), {
|
|
4146
|
+
id: name
|
|
4147
|
+
}));
|
|
4148
|
+
} else {
|
|
4149
|
+
throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
|
|
4150
|
+
}
|
|
4151
|
+
};
|
|
4152
|
+
|
|
4153
|
+
Interpreter.prototype.spawnMachine = function (machine, options) {
|
|
4154
|
+
var _this = this;
|
|
4155
|
+
|
|
4156
|
+
if (options === void 0) {
|
|
4157
|
+
options = {};
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
var childService = new Interpreter(machine, __assign(__assign({}, this.options), {
|
|
4161
|
+
parent: this,
|
|
4162
|
+
id: options.id || machine.id
|
|
4163
|
+
}));
|
|
4164
|
+
|
|
4165
|
+
var resolvedOptions = __assign(__assign({}, DEFAULT_SPAWN_OPTIONS), options);
|
|
4166
|
+
|
|
4167
|
+
if (resolvedOptions.sync) {
|
|
4168
|
+
childService.onTransition(function (state) {
|
|
4169
|
+
_this.send(update, {
|
|
4170
|
+
state: state,
|
|
4171
|
+
id: childService.id
|
|
4172
|
+
});
|
|
4173
|
+
});
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
var actor = childService;
|
|
4177
|
+
this.children.set(childService.id, actor);
|
|
4178
|
+
|
|
4179
|
+
if (resolvedOptions.autoForward) {
|
|
4180
|
+
this.forwardTo.add(childService.id);
|
|
4181
|
+
}
|
|
4182
|
+
|
|
4183
|
+
childService.onDone(function (doneEvent) {
|
|
4184
|
+
_this.removeChild(childService.id);
|
|
4185
|
+
|
|
4186
|
+
_this.send(toSCXMLEvent(doneEvent, {
|
|
4187
|
+
origin: childService.id
|
|
4188
|
+
}));
|
|
4189
|
+
}).start();
|
|
4190
|
+
return actor;
|
|
4191
|
+
};
|
|
4192
|
+
|
|
4193
|
+
Interpreter.prototype.spawnPromise = function (promise, id) {
|
|
4194
|
+
var _this = this;
|
|
4195
|
+
|
|
4196
|
+
var canceled = false;
|
|
4197
|
+
promise.then(function (response) {
|
|
4198
|
+
if (!canceled) {
|
|
4199
|
+
_this.removeChild(id);
|
|
4200
|
+
|
|
4201
|
+
_this.send(toSCXMLEvent(doneInvoke(id, response), {
|
|
4202
|
+
origin: id
|
|
4203
|
+
}));
|
|
4204
|
+
}
|
|
4205
|
+
}, function (errorData) {
|
|
4206
|
+
if (!canceled) {
|
|
4207
|
+
_this.removeChild(id);
|
|
4208
|
+
|
|
4209
|
+
var errorEvent = error(id, errorData);
|
|
4210
|
+
|
|
4211
|
+
try {
|
|
4212
|
+
// Send "error.platform.id" to this (parent).
|
|
4213
|
+
_this.send(toSCXMLEvent(errorEvent, {
|
|
4214
|
+
origin: id
|
|
4215
|
+
}));
|
|
4216
|
+
} catch (error) {
|
|
4217
|
+
|
|
4218
|
+
if (_this.devTools) {
|
|
4219
|
+
_this.devTools.send(errorEvent, _this.state);
|
|
4220
|
+
}
|
|
4221
|
+
|
|
4222
|
+
if (_this.machine.strict) {
|
|
4223
|
+
// it would be better to always stop the state machine if unhandled
|
|
4224
|
+
// exception/promise rejection happens but because we don't want to
|
|
4225
|
+
// break existing code so enforce it on strict mode only especially so
|
|
4226
|
+
// because documentation says that onError is optional
|
|
4227
|
+
_this.stop();
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
});
|
|
4232
|
+
var actor = {
|
|
4233
|
+
id: id,
|
|
4234
|
+
send: function () {
|
|
4235
|
+
return void 0;
|
|
4236
|
+
},
|
|
4237
|
+
subscribe: function (next, handleError, complete) {
|
|
4238
|
+
var observer = toObserver(next, handleError, complete);
|
|
4239
|
+
var unsubscribed = false;
|
|
4240
|
+
promise.then(function (response) {
|
|
4241
|
+
if (unsubscribed) {
|
|
4242
|
+
return;
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
observer.next(response);
|
|
4246
|
+
|
|
4247
|
+
if (unsubscribed) {
|
|
4248
|
+
return;
|
|
4249
|
+
}
|
|
4250
|
+
|
|
4251
|
+
observer.complete();
|
|
4252
|
+
}, function (err) {
|
|
4253
|
+
if (unsubscribed) {
|
|
4254
|
+
return;
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
observer.error(err);
|
|
4258
|
+
});
|
|
4259
|
+
return {
|
|
4260
|
+
unsubscribe: function () {
|
|
4261
|
+
return unsubscribed = true;
|
|
4262
|
+
}
|
|
4263
|
+
};
|
|
4264
|
+
},
|
|
4265
|
+
stop: function () {
|
|
4266
|
+
canceled = true;
|
|
4267
|
+
},
|
|
4268
|
+
toJSON: function () {
|
|
4269
|
+
return {
|
|
4270
|
+
id: id
|
|
4271
|
+
};
|
|
4272
|
+
}
|
|
4273
|
+
};
|
|
4274
|
+
this.children.set(id, actor);
|
|
4275
|
+
return actor;
|
|
4276
|
+
};
|
|
4277
|
+
|
|
4278
|
+
Interpreter.prototype.spawnCallback = function (callback, id) {
|
|
4279
|
+
var _this = this;
|
|
4280
|
+
|
|
4281
|
+
var canceled = false;
|
|
4282
|
+
var receivers = new Set();
|
|
4283
|
+
var listeners = new Set();
|
|
4284
|
+
|
|
4285
|
+
var receive = function (e) {
|
|
4286
|
+
listeners.forEach(function (listener) {
|
|
4287
|
+
return listener(e);
|
|
4288
|
+
});
|
|
4289
|
+
|
|
4290
|
+
if (canceled) {
|
|
4291
|
+
return;
|
|
4292
|
+
}
|
|
4293
|
+
|
|
4294
|
+
_this.send(toSCXMLEvent(e, {
|
|
4295
|
+
origin: id
|
|
4296
|
+
}));
|
|
4297
|
+
};
|
|
4298
|
+
|
|
4299
|
+
var callbackStop;
|
|
4300
|
+
|
|
4301
|
+
try {
|
|
4302
|
+
callbackStop = callback(receive, function (newListener) {
|
|
4303
|
+
receivers.add(newListener);
|
|
4304
|
+
});
|
|
4305
|
+
} catch (err) {
|
|
4306
|
+
this.send(error(id, err));
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
if (isPromiseLike(callbackStop)) {
|
|
4310
|
+
// it turned out to be an async function, can't reliably check this before calling `callback`
|
|
4311
|
+
// because transpiled async functions are not recognizable
|
|
4312
|
+
return this.spawnPromise(callbackStop, id);
|
|
4313
|
+
}
|
|
4314
|
+
|
|
4315
|
+
var actor = {
|
|
4316
|
+
id: id,
|
|
4317
|
+
send: function (event) {
|
|
4318
|
+
return receivers.forEach(function (receiver) {
|
|
4319
|
+
return receiver(event);
|
|
4320
|
+
});
|
|
4321
|
+
},
|
|
4322
|
+
subscribe: function (next) {
|
|
4323
|
+
listeners.add(next);
|
|
4324
|
+
return {
|
|
4325
|
+
unsubscribe: function () {
|
|
4326
|
+
listeners.delete(next);
|
|
4327
|
+
}
|
|
4328
|
+
};
|
|
4329
|
+
},
|
|
4330
|
+
stop: function () {
|
|
4331
|
+
canceled = true;
|
|
4332
|
+
|
|
4333
|
+
if (isFunction(callbackStop)) {
|
|
4334
|
+
callbackStop();
|
|
4335
|
+
}
|
|
4336
|
+
},
|
|
4337
|
+
toJSON: function () {
|
|
4338
|
+
return {
|
|
4339
|
+
id: id
|
|
4340
|
+
};
|
|
4341
|
+
}
|
|
4342
|
+
};
|
|
4343
|
+
this.children.set(id, actor);
|
|
4344
|
+
return actor;
|
|
4345
|
+
};
|
|
4346
|
+
|
|
4347
|
+
Interpreter.prototype.spawnObservable = function (source, id) {
|
|
4348
|
+
var _this = this;
|
|
4349
|
+
|
|
4350
|
+
var subscription = source.subscribe(function (value) {
|
|
4351
|
+
_this.send(toSCXMLEvent(value, {
|
|
4352
|
+
origin: id
|
|
4353
|
+
}));
|
|
4354
|
+
}, function (err) {
|
|
4355
|
+
_this.removeChild(id);
|
|
4356
|
+
|
|
4357
|
+
_this.send(toSCXMLEvent(error(id, err), {
|
|
4358
|
+
origin: id
|
|
4359
|
+
}));
|
|
4360
|
+
}, function () {
|
|
4361
|
+
_this.removeChild(id);
|
|
4362
|
+
|
|
4363
|
+
_this.send(toSCXMLEvent(doneInvoke(id), {
|
|
4364
|
+
origin: id
|
|
4365
|
+
}));
|
|
4366
|
+
});
|
|
4367
|
+
var actor = {
|
|
4368
|
+
id: id,
|
|
4369
|
+
send: function () {
|
|
4370
|
+
return void 0;
|
|
4371
|
+
},
|
|
4372
|
+
subscribe: function (next, handleError, complete) {
|
|
4373
|
+
return source.subscribe(next, handleError, complete);
|
|
4374
|
+
},
|
|
4375
|
+
stop: function () {
|
|
4376
|
+
return subscription.unsubscribe();
|
|
4377
|
+
},
|
|
4378
|
+
toJSON: function () {
|
|
4379
|
+
return {
|
|
4380
|
+
id: id
|
|
4381
|
+
};
|
|
4382
|
+
}
|
|
4383
|
+
};
|
|
4384
|
+
this.children.set(id, actor);
|
|
4385
|
+
return actor;
|
|
4386
|
+
};
|
|
4387
|
+
|
|
4388
|
+
Interpreter.prototype.spawnActor = function (actor) {
|
|
4389
|
+
this.children.set(actor.id, actor);
|
|
4390
|
+
return actor;
|
|
4391
|
+
};
|
|
4392
|
+
|
|
4393
|
+
Interpreter.prototype.spawnActivity = function (activity) {
|
|
4394
|
+
var implementation = this.machine.options && this.machine.options.activities ? this.machine.options.activities[activity.type] : undefined;
|
|
4395
|
+
|
|
4396
|
+
if (!implementation) {
|
|
4397
|
+
|
|
4398
|
+
|
|
4399
|
+
return;
|
|
4400
|
+
} // Start implementation
|
|
4401
|
+
|
|
4402
|
+
|
|
4403
|
+
var dispose = implementation(this.state.context, activity);
|
|
4404
|
+
this.spawnEffect(activity.id, dispose);
|
|
4405
|
+
};
|
|
4406
|
+
|
|
4407
|
+
Interpreter.prototype.spawnEffect = function (id, dispose) {
|
|
4408
|
+
this.children.set(id, {
|
|
4409
|
+
id: id,
|
|
4410
|
+
send: function () {
|
|
4411
|
+
return void 0;
|
|
4412
|
+
},
|
|
4413
|
+
subscribe: function () {
|
|
4414
|
+
return {
|
|
4415
|
+
unsubscribe: function () {
|
|
4416
|
+
return void 0;
|
|
4417
|
+
}
|
|
4418
|
+
};
|
|
4419
|
+
},
|
|
4420
|
+
stop: dispose || undefined,
|
|
4421
|
+
toJSON: function () {
|
|
4422
|
+
return {
|
|
4423
|
+
id: id
|
|
4424
|
+
};
|
|
4425
|
+
}
|
|
4426
|
+
});
|
|
4427
|
+
};
|
|
4428
|
+
|
|
4429
|
+
Interpreter.prototype.attachDev = function () {
|
|
4430
|
+
var global = getGlobal();
|
|
4431
|
+
|
|
4432
|
+
if (this.options.devTools && global) {
|
|
4433
|
+
if (global.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
4434
|
+
var devToolsOptions = typeof this.options.devTools === 'object' ? this.options.devTools : undefined;
|
|
4435
|
+
this.devTools = global.__REDUX_DEVTOOLS_EXTENSION__.connect(__assign(__assign({
|
|
4436
|
+
name: this.id,
|
|
4437
|
+
autoPause: true,
|
|
4438
|
+
stateSanitizer: function (state) {
|
|
4439
|
+
return {
|
|
4440
|
+
value: state.value,
|
|
4441
|
+
context: state.context,
|
|
4442
|
+
actions: state.actions
|
|
4443
|
+
};
|
|
4444
|
+
}
|
|
4445
|
+
}, devToolsOptions), {
|
|
4446
|
+
features: __assign({
|
|
4447
|
+
jump: false,
|
|
4448
|
+
skip: false
|
|
4449
|
+
}, devToolsOptions ? devToolsOptions.features : undefined)
|
|
4450
|
+
}), this.machine);
|
|
4451
|
+
this.devTools.init(this.state);
|
|
4452
|
+
} // add XState-specific dev tooling hook
|
|
4453
|
+
}
|
|
4454
|
+
};
|
|
4455
|
+
|
|
4456
|
+
Interpreter.prototype.toJSON = function () {
|
|
4457
|
+
return {
|
|
4458
|
+
id: this.id
|
|
4459
|
+
};
|
|
4460
|
+
};
|
|
4461
|
+
|
|
4462
|
+
Interpreter.prototype[symbolObservable] = function () {
|
|
4463
|
+
return this;
|
|
4464
|
+
};
|
|
4465
|
+
/**
|
|
4466
|
+
* The default interpreter options:
|
|
4467
|
+
*
|
|
4468
|
+
* - `clock` uses the global `setTimeout` and `clearTimeout` functions
|
|
4469
|
+
* - `logger` uses the global `console.log()` method
|
|
4470
|
+
*/
|
|
4471
|
+
|
|
4472
|
+
|
|
4473
|
+
Interpreter.defaultOptions = /*#__PURE__*/function (global) {
|
|
4474
|
+
return {
|
|
4475
|
+
execute: true,
|
|
4476
|
+
deferEvents: true,
|
|
4477
|
+
clock: {
|
|
4478
|
+
setTimeout: function (fn, ms) {
|
|
4479
|
+
return setTimeout(fn, ms);
|
|
4480
|
+
},
|
|
4481
|
+
clearTimeout: function (id) {
|
|
4482
|
+
return clearTimeout(id);
|
|
4483
|
+
}
|
|
4484
|
+
},
|
|
4485
|
+
logger: global.console.log.bind(console),
|
|
4486
|
+
devTools: false
|
|
4487
|
+
};
|
|
4488
|
+
}(typeof self !== 'undefined' ? self : global);
|
|
4489
|
+
|
|
4490
|
+
Interpreter.interpret = interpret;
|
|
4491
|
+
return Interpreter;
|
|
4492
|
+
}();
|
|
4493
|
+
/**
|
|
4494
|
+
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
4495
|
+
*
|
|
4496
|
+
* @param machine The machine to interpret
|
|
4497
|
+
* @param options Interpreter options
|
|
4498
|
+
*/
|
|
4499
|
+
|
|
4500
|
+
|
|
4501
|
+
function interpret(machine, options) {
|
|
4502
|
+
var interpreter = new Interpreter(machine, options);
|
|
4503
|
+
return interpreter;
|
|
4504
|
+
}
|
|
4505
|
+
|
|
4506
|
+
const SelectChips = ({ disabled, option, onRemove }) => {
|
|
4507
|
+
const style = {};
|
|
4508
|
+
if (option.chipColor) {
|
|
4509
|
+
style['color'] = option.chipColor;
|
|
4510
|
+
}
|
|
4511
|
+
if (option.chipBackgroundColor) {
|
|
4512
|
+
style['background-color'] = option.chipBackgroundColor;
|
|
4513
|
+
}
|
|
4514
|
+
return (index.h("label", { class: "wcs-select-chip", style: style, onClick: (e) => e.stopImmediatePropagation() },
|
|
4515
|
+
index.h("div", null, option.displayText),
|
|
4516
|
+
disabled ?
|
|
4517
|
+
null :
|
|
4518
|
+
index.h("div", { onClick: () => onRemove(option) },
|
|
4519
|
+
index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "20", height: "12", viewBox: "0 0 20 12", class: "chip" },
|
|
4520
|
+
index.h("path", { d: "M2,0 6,4 10,0 12,2 8,6 12,10 10,12 6,8 2,12 0,10 4,6 0,2 2,0", fill: option.chipColor, transform: "translate(8 0)" })))));
|
|
4521
|
+
};
|
|
4522
|
+
|
|
4523
|
+
const selectCss = "@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface{--mdc-ripple-fg-size:0;--mdc-ripple-left:0;--mdc-ripple-top:0;--mdc-ripple-fg-scale:1;--mdc-ripple-fg-translate-end:0;--mdc-ripple-fg-translate-start:0;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);will-change:transform, opacity;position:relative;outline:none;overflow:hidden}.mdc-ripple-surface::before,.mdc-ripple-surface::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:\"\"}.mdc-ripple-surface::before{transition:opacity 15ms linear, background-color 15ms linear;z-index:1;z-index:var(--mdc-ripple-z-index, 1)}.mdc-ripple-surface::after{z-index:0;z-index:var(--mdc-ripple-z-index, 0)}.mdc-ripple-surface.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-ripple-surface.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-ripple-surface.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-ripple-surface.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards, mdc-ripple-fg-opacity-in 75ms forwards}.mdc-ripple-surface.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-ripple-surface::before,.mdc-ripple-surface::after{top:calc(50% - 100%);left:calc(50% - 100%);width:200%;height:200%}.mdc-ripple-surface.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface[data-mdc-ripple-is-unbounded],.mdc-ripple-upgraded--unbounded{overflow:visible}.mdc-ripple-surface[data-mdc-ripple-is-unbounded]::before,.mdc-ripple-surface[data-mdc-ripple-is-unbounded]::after,.mdc-ripple-upgraded--unbounded::before,.mdc-ripple-upgraded--unbounded::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::before,.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::after,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::before,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::after,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface::before,.mdc-ripple-surface::after{background-color:#000;background-color:var(--mdc-ripple-color, #000)}.mdc-ripple-surface:hover::before,.mdc-ripple-surface.mdc-ripple-surface--hover::before{opacity:0.04;opacity:var(--mdc-ripple-hover-opacity, 0.04)}.mdc-ripple-surface.mdc-ripple-upgraded--background-focused::before,.mdc-ripple-surface:not(.mdc-ripple-upgraded):focus::before{transition-duration:75ms;opacity:0.12;opacity:var(--mdc-ripple-focus-opacity, 0.12)}.mdc-ripple-surface:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-ripple-surface:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:0.12;opacity:var(--mdc-ripple-press-opacity, 0.12)}.mdc-ripple-surface.mdc-ripple-upgraded{--mdc-ripple-fg-opacity:var(--mdc-ripple-press-opacity, 0.12)}:host{--wcs-select-ligther-percentage:40;--wcs-select-border-radius:var(--wcs-border-radius);--wcs-select-background-color:var(--wcs-light);--wcs-select-placeholder-color:var(--wcs-text-medium);--wcs-select-value-color:var(--wcs-primary);--wcs-select-border-color:transparent;--wcs-select-overlay-max-height:360px;--wcs-select-option-height:42px;display:block;position:relative;outline:none;user-select:none}:host svg{flex-shrink:0}:host .arrow{fill:var(--wcs-select-value-color)}:host .chip{fill:var(--wcs-contrast);opacity:calc((100 - var(--wcs-select-ligther-percentage)) / 100)}:host .chip:hover{opacity:100}:host([class~=expanded][overlaydirection=top]) .wcs-select-control{border:var(--wcs-select-border-color) solid 1px;border-top-left-radius:0;border-top-right-radius:0}:host([class~=expanded][overlaydirection=bottom]) .wcs-select-control{border:var(--wcs-select-border-color) solid 1px;border-bottom-left-radius:0;border-bottom-right-radius:0}:host(.expanded){--wcs-select-border-color:var(--wcs-text-light)}:host(.expanded) .wcs-select-options{display:block}:host(:not(.expanded):focus) .wcs-select-control{border:var(--wcs-primary) solid 1px}:host([disabled]) .wcs-select-control,:host([disabled]) label{cursor:default;pointer-events:none}:host([disabled]) label{color:var(--wcs-text-disabled)}:host([disabled]) .arrow{fill:var(--wcs-text-medium)}label{padding:calc(var(--wcs-padding) / 2) var(--wcs-padding);font-weight:500;cursor:pointer;color:var(--wcs-select-color);transition:color 125ms ease-in;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}:host([chips]) .wcs-select-control{flex-wrap:wrap}.wcs-select-control{--mdc-ripple-fg-size:0;--mdc-ripple-left:0;--mdc-ripple-top:0;--mdc-ripple-fg-scale:1;--mdc-ripple-fg-translate-end:0;--mdc-ripple-fg-translate-start:0;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);will-change:transform, opacity;overflow:hidden;display:flex;align-items:center;padding-right:var(--wcs-text-padding);background-color:var(--wcs-select-background-color);border-radius:var(--wcs-select-border-radius);border:var(--wcs-select-border-color) solid 1px;font-size:1rem;line-height:1.5;cursor:pointer}.wcs-select-control::before,.wcs-select-control::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:\"\"}.wcs-select-control::before{transition:opacity 15ms linear, background-color 15ms linear;z-index:1;z-index:var(--mdc-ripple-z-index, 1)}.wcs-select-control::after{z-index:0;z-index:var(--mdc-ripple-z-index, 0)}.wcs-select-control.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.wcs-select-control.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.wcs-select-control.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.wcs-select-control.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards, mdc-ripple-fg-opacity-in 75ms forwards}.wcs-select-control.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.wcs-select-control::before,.wcs-select-control::after{top:calc(50% - 100%);left:calc(50% - 100%);width:200%;height:200%}.wcs-select-control.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.wcs-select-control::before,.wcs-select-control::after{background-color:#999;background-color:var(--mdc-ripple-color, #999)}.wcs-select-control:hover::before,.wcs-select-control.mdc-ripple-surface--hover::before{opacity:0.1;opacity:var(--mdc-ripple-hover-opacity, 0.1)}.wcs-select-control.mdc-ripple-upgraded--background-focused::before,.wcs-select-control:not(.mdc-ripple-upgraded):focus::before{transition-duration:75ms;opacity:0.2;opacity:var(--mdc-ripple-focus-opacity, 0.2)}.wcs-select-control:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.wcs-select-control:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:0.3;opacity:var(--mdc-ripple-press-opacity, 0.3)}.wcs-select-control.mdc-ripple-upgraded{--mdc-ripple-fg-opacity:var(--mdc-ripple-press-opacity, 0.3)}.wcs-select-placeholder{color:var(--wcs-select-placeholder-color);font-style:italic;font-weight:400}.wcs-select-value{color:var(--wcs-select-value-color);font-weight:var(--wcs-font-weight-form-value)}.wcs-select-chip{color:var(--wcs-contrast);background-color:var(--wcs-base);border-radius:0.75rem;display:flex;align-items:center;margin:calc(var(--wcs-base-margin) / 2);padding:calc((var(--wcs-padding) - 8px) / 2) var(--wcs-padding);overflow:initial}:host([overlaydirection=top]) .wcs-select-options{-webkit-transform:translateY(-100%);transform:translateY(-100%);border-left:var(--wcs-select-border-color) solid 1px;border-right:var(--wcs-select-border-color) solid 1px;border-top:var(--wcs-select-border-color) solid 1px;border-top-right-radius:var(--wcs-border-radius);border-top-left-radius:var(--wcs-border-radius)}:host([overlaydirection=bottom]) .wcs-select-options{border-left:var(--wcs-select-border-color) solid 1px;border-right:var(--wcs-select-border-color) solid 1px;border-bottom:var(--wcs-select-border-color) solid 1px;border-bottom-right-radius:var(--wcs-border-radius);border-bottom-left-radius:var(--wcs-border-radius)}.wcs-select-options{display:none;position:absolute;z-index:1;margin:0;max-height:var(--wcs-select-overlay-max-height);overflow-y:auto;background-color:var(--wcs-white);color:var(--wcs-text-medium)}";
|
|
4524
|
+
|
|
4525
|
+
const SELECT_MACHINE_CONFIG = {
|
|
4526
|
+
key: 'select',
|
|
4527
|
+
initial: 'closed',
|
|
4528
|
+
states: {
|
|
4529
|
+
closed: {
|
|
4530
|
+
entry: ['close'],
|
|
4531
|
+
on: {
|
|
4532
|
+
CLICK: 'opened',
|
|
4533
|
+
OPEN: 'opened',
|
|
4534
|
+
OPTION_CLICKED: { actions: ['selectOption'] }
|
|
4535
|
+
},
|
|
4536
|
+
},
|
|
4537
|
+
opened: {
|
|
4538
|
+
entry: ['open'],
|
|
4539
|
+
on: {
|
|
4540
|
+
CLICK: 'closed',
|
|
4541
|
+
CLOSE: 'closed',
|
|
4542
|
+
OPTION_CLICKED: { actions: ['selectOption'] }
|
|
4543
|
+
},
|
|
4544
|
+
},
|
|
4545
|
+
}
|
|
4546
|
+
};
|
|
4547
|
+
let Select = class {
|
|
4548
|
+
constructor(hostRef) {
|
|
4549
|
+
index.registerInstance(this, hostRef);
|
|
4550
|
+
this.wcsChange = index.createEvent(this, "wcsChange", 7);
|
|
4551
|
+
this.wcsFocus = index.createEvent(this, "wcsFocus", 7);
|
|
4552
|
+
this.wcsBlur = index.createEvent(this, "wcsBlur", 7);
|
|
4553
|
+
/** Wether the select is expanded */
|
|
4554
|
+
this.expanded = false;
|
|
4555
|
+
/** Wether the component is fully loaded in the DOM. */
|
|
4556
|
+
this.hasLoaded = false;
|
|
4557
|
+
/** If `true`, the user cannot interact with the select. */
|
|
4558
|
+
this.disabled = false;
|
|
4559
|
+
/** If `true`, the user can select multiple values at once. */
|
|
4560
|
+
this.multiple = false;
|
|
4561
|
+
/** If `true`, selected items are shown in chips mode. */
|
|
4562
|
+
this.chips = false;
|
|
4563
|
+
/** Function used to compare options, default : deep comparison. */
|
|
4564
|
+
this.compareWith = (optionValue, selectedValue) => lodash.lodash.isEqual(optionValue, selectedValue);
|
|
4565
|
+
this.overlayDirection = 'bottom';
|
|
4566
|
+
}
|
|
4567
|
+
/** Open the component. */
|
|
4568
|
+
async open() {
|
|
4569
|
+
this.stateService.send('OPEN');
|
|
4570
|
+
}
|
|
4571
|
+
/** Close the component. */
|
|
4572
|
+
async close() {
|
|
4573
|
+
this.stateService.send('CLOSE');
|
|
4574
|
+
}
|
|
4575
|
+
onValueChangeHandler(newValue) {
|
|
4576
|
+
this.updateSelectedValue(newValue);
|
|
4577
|
+
this.emitChange(this.value);
|
|
4578
|
+
}
|
|
4579
|
+
updateSelectedValue(value) {
|
|
4580
|
+
// If no value is passed, the select is reset.
|
|
4581
|
+
if (!value) {
|
|
4582
|
+
this.reset();
|
|
4583
|
+
}
|
|
4584
|
+
if (this.multiple) {
|
|
4585
|
+
// If user don't give an array, we provide one
|
|
4586
|
+
if (!Array.isArray(value)) {
|
|
4587
|
+
value = [value];
|
|
4588
|
+
}
|
|
4589
|
+
this.values = [];
|
|
4590
|
+
this.options.forEach((opt) => {
|
|
4591
|
+
const isSelected = value ?
|
|
4592
|
+
value.findIndex(v => this.compareWith(opt.value, v)) !== -1
|
|
4593
|
+
: false;
|
|
4594
|
+
if (isSelected) {
|
|
4595
|
+
this.values.push({
|
|
4596
|
+
value: opt.value,
|
|
4597
|
+
displayText: opt.innerText,
|
|
4598
|
+
chipColor: opt.chipColor,
|
|
4599
|
+
chipBackgroundColor: opt.chipBackgroundColor
|
|
4600
|
+
});
|
|
4601
|
+
}
|
|
4602
|
+
opt.selected = isSelected;
|
|
4603
|
+
});
|
|
4604
|
+
// update select placeholder text
|
|
4605
|
+
this.displayText = this.values.length !== 0
|
|
4606
|
+
? this.values.map(v => v.displayText).join(', ')
|
|
4607
|
+
: undefined;
|
|
4608
|
+
}
|
|
4609
|
+
else {
|
|
4610
|
+
this.options.forEach((opt) => {
|
|
4611
|
+
const isSelected = this.compareWith(opt.value, value);
|
|
4612
|
+
if (isSelected) {
|
|
4613
|
+
this.displayText = opt.innerText;
|
|
4614
|
+
}
|
|
4615
|
+
opt.selected = isSelected;
|
|
4616
|
+
});
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
/**
|
|
4620
|
+
* Reset the select: unselects all options for multiple mode and displays the placeholder
|
|
4621
|
+
* @private
|
|
4622
|
+
*/
|
|
4623
|
+
reset() {
|
|
4624
|
+
this.values = [];
|
|
4625
|
+
this.displayText = undefined;
|
|
4626
|
+
this.options.forEach((opt) => {
|
|
4627
|
+
opt.selected = false;
|
|
4628
|
+
});
|
|
4629
|
+
}
|
|
4630
|
+
componentDidLoad() {
|
|
4631
|
+
this.optionsEl = this.el.shadowRoot.querySelector('.wcs-select-options');
|
|
4632
|
+
this.controlEl = this.el.shadowRoot.querySelector('.wcs-select-control');
|
|
4633
|
+
const stateMachine = Machine(SELECT_MACHINE_CONFIG, this.initMachineOptions());
|
|
4634
|
+
this.stateService = interpret(stateMachine);
|
|
4635
|
+
if (this.multiple) {
|
|
4636
|
+
this.values = [];
|
|
4637
|
+
}
|
|
4638
|
+
this.addRippleEffect();
|
|
4639
|
+
this.stateService.start();
|
|
4640
|
+
if (this.optionsEl.querySelector('slot') === null) {
|
|
4641
|
+
this.replaceOptions_firefoxBefore63();
|
|
4642
|
+
this.listenDomUpdate_firefoxBefore63();
|
|
4643
|
+
}
|
|
4644
|
+
if (this.value !== undefined) {
|
|
4645
|
+
this.updateSelectedValue(this.value);
|
|
4646
|
+
}
|
|
4647
|
+
// TODO: is this still usefull for anything ?
|
|
4648
|
+
this.hasLoaded = true;
|
|
4649
|
+
}
|
|
4650
|
+
emitChange(newValue) {
|
|
4651
|
+
this.wcsChange.emit({
|
|
4652
|
+
value: newValue
|
|
4653
|
+
});
|
|
4654
|
+
}
|
|
4655
|
+
replaceOptions_firefoxBefore63() {
|
|
4656
|
+
Array.from(this.el.querySelectorAll('wcs-select-option'))
|
|
4657
|
+
.forEach(option => {
|
|
4658
|
+
if (option.parentNode === this.el) {
|
|
4659
|
+
this.el.removeChild(option);
|
|
4660
|
+
this.optionsEl.appendChild(option);
|
|
4661
|
+
}
|
|
4662
|
+
});
|
|
4663
|
+
}
|
|
4664
|
+
listenDomUpdate_firefoxBefore63() {
|
|
4665
|
+
const observer = new MutationObserver((mutationsList) => {
|
|
4666
|
+
for (const mutation of mutationsList) {
|
|
4667
|
+
if (mutation.type === 'childList') {
|
|
4668
|
+
this.replaceOptions_firefoxBefore63();
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
});
|
|
4672
|
+
observer.observe(this.el, { childList: true });
|
|
4673
|
+
}
|
|
4674
|
+
componentWillUpdate() {
|
|
4675
|
+
if (this.multiple) {
|
|
4676
|
+
this.options
|
|
4677
|
+
.forEach((opt) => opt.multiple = true);
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
get options() {
|
|
4681
|
+
var _a;
|
|
4682
|
+
const opts = (_a = this.el) === null || _a === void 0 ? void 0 : _a.querySelectorAll('wcs-select-option');
|
|
4683
|
+
if (opts && opts.length !== 0) {
|
|
4684
|
+
return opts;
|
|
4685
|
+
}
|
|
4686
|
+
return [];
|
|
4687
|
+
}
|
|
4688
|
+
initMachineOptions() {
|
|
4689
|
+
return {
|
|
4690
|
+
actions: {
|
|
4691
|
+
open: () => {
|
|
4692
|
+
if (!this.disabled) {
|
|
4693
|
+
this.updateOverlayDirection();
|
|
4694
|
+
this.expanded = true;
|
|
4695
|
+
this.focused = true;
|
|
4696
|
+
}
|
|
4697
|
+
},
|
|
4698
|
+
close: () => {
|
|
4699
|
+
this.focused = true;
|
|
4700
|
+
this.expanded = false;
|
|
4701
|
+
},
|
|
4702
|
+
selectOption: (_, event) => {
|
|
4703
|
+
if (event.type === 'OPTION_CLICKED') {
|
|
4704
|
+
this.handleClickEvent(event.value);
|
|
4705
|
+
}
|
|
4706
|
+
}
|
|
4707
|
+
},
|
|
4708
|
+
guards: {
|
|
4709
|
+
enabled: () => !this.disabled
|
|
4710
|
+
}
|
|
4711
|
+
};
|
|
4712
|
+
}
|
|
4713
|
+
/**
|
|
4714
|
+
* This method controls whether or not the overlay has enough space to be displayed
|
|
4715
|
+
* at the bottom of the select component.
|
|
4716
|
+
*
|
|
4717
|
+
* It compute the size of the expended select by adding the theoretical dimensions of the
|
|
4718
|
+
* overlay calculated from the number of options plus the initial select size.
|
|
4719
|
+
* @private
|
|
4720
|
+
*/
|
|
4721
|
+
updateOverlayDirection() {
|
|
4722
|
+
// We retrieve values from CSS variables
|
|
4723
|
+
const overlayMaxHeight = +getComputedStyle(this.el).getPropertyValue('--wcs-select-overlay-max-height').replace(/\D/g, '');
|
|
4724
|
+
const optionSize = +getComputedStyle(this.el).getPropertyValue('--wcs-select-option-height').replace(/\D/g, '');
|
|
4725
|
+
const selectBounding = this.el.getBoundingClientRect();
|
|
4726
|
+
const maxOptionsCount = Math.floor(overlayMaxHeight / optionSize);
|
|
4727
|
+
// Maximum size of the overlay is 360px, otherwise the size is calculated from the number of options
|
|
4728
|
+
const optionsOverlaySize = this.options.length > maxOptionsCount ? overlayMaxHeight + 1 : this.options.length * optionSize + 1;
|
|
4729
|
+
const remainingHeightAfterOpen = window.innerHeight - (selectBounding.y + selectBounding.height + optionsOverlaySize);
|
|
4730
|
+
// There are not enough pixels to open the overlay below the component
|
|
4731
|
+
if (remainingHeightAfterOpen < 0) {
|
|
4732
|
+
this.overlayDirection = 'top';
|
|
4733
|
+
}
|
|
4734
|
+
else {
|
|
4735
|
+
this.overlayDirection = 'bottom';
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
updateOverlayMargin() {
|
|
4739
|
+
if (this.controlEl && this.optionsEl) {
|
|
4740
|
+
if (this.overlayDirection === 'top') {
|
|
4741
|
+
this.optionsEl.style.marginTop = '-' + this.controlEl.getBoundingClientRect().height + 'px';
|
|
4742
|
+
}
|
|
4743
|
+
else {
|
|
4744
|
+
this.optionsEl.style.marginTop = '0';
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
}
|
|
4748
|
+
handleClickEvent(event) {
|
|
4749
|
+
if (this.multiple) {
|
|
4750
|
+
this.handleClickOnMultiple(event);
|
|
4751
|
+
}
|
|
4752
|
+
else {
|
|
4753
|
+
this.handleNormalClick(event);
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
handleClickOnMultiple(event) {
|
|
4757
|
+
const index = this.values.findIndex(v => v.value === event.value);
|
|
4758
|
+
if (index === -1) {
|
|
4759
|
+
const { value, displayText, chipColor, chipBackgroundColor } = event;
|
|
4760
|
+
this.values.push({ value, displayText, chipColor, chipBackgroundColor });
|
|
4761
|
+
event.source.selected = true;
|
|
4762
|
+
}
|
|
4763
|
+
else {
|
|
4764
|
+
event.source.selected = false;
|
|
4765
|
+
this.values.splice(index, 1);
|
|
4766
|
+
}
|
|
4767
|
+
this.updateValueWithValues();
|
|
4768
|
+
}
|
|
4769
|
+
updateValueWithValues() {
|
|
4770
|
+
this.value = this.values.map(v => v.value);
|
|
4771
|
+
this.displayText = this.values.length !== 0
|
|
4772
|
+
? this.values.map(v => v.displayText).join(', ')
|
|
4773
|
+
: undefined;
|
|
4774
|
+
}
|
|
4775
|
+
handleNormalClick(event) {
|
|
4776
|
+
// Reset other options to false if they were selected.
|
|
4777
|
+
this.options
|
|
4778
|
+
.forEach(option => {
|
|
4779
|
+
if (option.selected)
|
|
4780
|
+
option.selected = false;
|
|
4781
|
+
});
|
|
4782
|
+
event.source.selected = true;
|
|
4783
|
+
this.value = event.value;
|
|
4784
|
+
this.displayText = event.displayText;
|
|
4785
|
+
this.stateService.send('CLOSE');
|
|
4786
|
+
}
|
|
4787
|
+
disconnectedCallback() {
|
|
4788
|
+
this.stateService.stop();
|
|
4789
|
+
}
|
|
4790
|
+
addRippleEffect() {
|
|
4791
|
+
// TODO: wrap MDCRipple dependency so we can eventually write our own or at least decouple a bit.
|
|
4792
|
+
const ripple = new component.MDCRipple(this.controlEl);
|
|
4793
|
+
ripple.unbounded = false;
|
|
4794
|
+
}
|
|
4795
|
+
get hasValue() {
|
|
4796
|
+
// TODO: change this behavior.
|
|
4797
|
+
return this.displayText !== undefined;
|
|
4798
|
+
}
|
|
4799
|
+
onMouseDown(event) {
|
|
4800
|
+
const clickOnScroll = helpers.isElement(event.target)
|
|
4801
|
+
&& (event.offsetX > event.target.clientWidth
|
|
4802
|
+
|| event.offsetY > event.target.clientHeight);
|
|
4803
|
+
const clickOnRemoveChip = event.composedPath()
|
|
4804
|
+
.filter(x => {
|
|
4805
|
+
const el = x;
|
|
4806
|
+
return el.nodeName === 'svg' && el.classList.contains('chip');
|
|
4807
|
+
})
|
|
4808
|
+
.length > 0;
|
|
4809
|
+
if (!clickOnScroll && !clickOnRemoveChip) {
|
|
4810
|
+
this.stateService.send('CLICK');
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
onWindowClickEvent(event) {
|
|
4814
|
+
// We search in the full path of the event, because if a select is used in another web component,
|
|
4815
|
+
// the event captured by the windows will target the parent web component and not the select.
|
|
4816
|
+
const clickedOnSelectOrChildren = event.composedPath().map(x => x.nodeName).indexOf('WCS-SELECT') !== -1;
|
|
4817
|
+
// TODO: Move this logic in the state machine
|
|
4818
|
+
// FIXME: Doesnt work with single + disabled option
|
|
4819
|
+
if (this.expanded && !clickedOnSelectOrChildren) {
|
|
4820
|
+
this.stateService.send('CLOSE');
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
selectedOptionChanged(event) {
|
|
4824
|
+
this.sendOptionClickedToStateMachine(event.detail);
|
|
4825
|
+
}
|
|
4826
|
+
sendOptionClickedToStateMachine(event) {
|
|
4827
|
+
this.stateService.send({ type: 'OPTION_CLICKED', value: event });
|
|
4828
|
+
}
|
|
4829
|
+
onSlotchange() {
|
|
4830
|
+
this.updateSelectedValue(this.value);
|
|
4831
|
+
}
|
|
4832
|
+
removeChip(v) {
|
|
4833
|
+
this.options
|
|
4834
|
+
.forEach(opt => {
|
|
4835
|
+
if (opt.value === v.value) {
|
|
4836
|
+
this.sendOptionClickedToStateMachine(Object.assign(Object.assign({}, v), { source: opt }));
|
|
4837
|
+
}
|
|
4838
|
+
});
|
|
4839
|
+
}
|
|
4840
|
+
render() {
|
|
4841
|
+
if (this.hasLoaded) {
|
|
4842
|
+
this.updateStyles();
|
|
4843
|
+
}
|
|
4844
|
+
this.updateOverlayMargin();
|
|
4845
|
+
return (index.h(index.Host, Object.assign({ class: this.expanded ? 'expanded ' : '', overlayDirection: this.overlayDirection }, this.focusedAttributes()), index.h("div", { class: "wcs-select-control" }, this.hasValue
|
|
4846
|
+
? (this.chips ?
|
|
4847
|
+
this.values.map((option) => index.h(SelectChips, { disabled: this.disabled, option: option, onRemove: this.removeChip.bind(this) }))
|
|
4848
|
+
: index.h("label", { class: "wcs-select-value" }, this.displayText))
|
|
4849
|
+
: index.h("label", { class: "wcs-select-placeholder" }, this.placeholder), index.h(selectArrow.SelectArrow, { up: this.expanded })), index.h("div", { class: "wcs-select-options" }, index.h("slot", { name: "wcs-select-option", onSlotchange: this.onSlotchange.bind(this) }))));
|
|
4850
|
+
}
|
|
4851
|
+
updateStyles() {
|
|
4852
|
+
// Make the options container width the same width as everything.
|
|
4853
|
+
const borderSize = 1;
|
|
4854
|
+
// TODO: Consider using a mutation observer to rerender the size each time ?
|
|
4855
|
+
// Be cautious as it may cause infinite loop with render ?
|
|
4856
|
+
this.optionsEl.setAttribute('style', `width: ${Math.ceil(this.el.offsetWidth - 2 * borderSize)}px;`);
|
|
4857
|
+
}
|
|
4858
|
+
focusedAttributes() {
|
|
4859
|
+
return !this.disabled ? { tabIndex: 0 } : {};
|
|
4860
|
+
}
|
|
4861
|
+
get el() { return index.getElement(this); }
|
|
4862
|
+
static get watchers() { return {
|
|
4863
|
+
"value": ["onValueChangeHandler"]
|
|
4864
|
+
}; }
|
|
4865
|
+
};
|
|
4866
|
+
Select.style = selectCss;
|
|
4867
|
+
|
|
4868
|
+
const selectOptionCss = "@keyframes mdc-ripple-fg-radius-in{from{animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transform:translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1)}to{transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}}@keyframes mdc-ripple-fg-opacity-in{from{animation-timing-function:linear;opacity:0}to{opacity:var(--mdc-ripple-fg-opacity, 0)}}@keyframes mdc-ripple-fg-opacity-out{from{animation-timing-function:linear;opacity:var(--mdc-ripple-fg-opacity, 0)}to{opacity:0}}.mdc-ripple-surface{--mdc-ripple-fg-size:0;--mdc-ripple-left:0;--mdc-ripple-top:0;--mdc-ripple-fg-scale:1;--mdc-ripple-fg-translate-end:0;--mdc-ripple-fg-translate-start:0;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);will-change:transform, opacity;position:relative;outline:none;overflow:hidden}.mdc-ripple-surface::before,.mdc-ripple-surface::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:\"\"}.mdc-ripple-surface::before{transition:opacity 15ms linear, background-color 15ms linear;z-index:1;z-index:var(--mdc-ripple-z-index, 1)}.mdc-ripple-surface::after{z-index:0;z-index:var(--mdc-ripple-z-index, 0)}.mdc-ripple-surface.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}.mdc-ripple-surface.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}.mdc-ripple-surface.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}.mdc-ripple-surface.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards, mdc-ripple-fg-opacity-in 75ms forwards}.mdc-ripple-surface.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}.mdc-ripple-surface::before,.mdc-ripple-surface::after{top:calc(50% - 100%);left:calc(50% - 100%);width:200%;height:200%}.mdc-ripple-surface.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface[data-mdc-ripple-is-unbounded],.mdc-ripple-upgraded--unbounded{overflow:visible}.mdc-ripple-surface[data-mdc-ripple-is-unbounded]::before,.mdc-ripple-surface[data-mdc-ripple-is-unbounded]::after,.mdc-ripple-upgraded--unbounded::before,.mdc-ripple-upgraded--unbounded::after{top:calc(50% - 50%);left:calc(50% - 50%);width:100%;height:100%}.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::before,.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::after,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::before,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::after{top:var(--mdc-ripple-top, calc(50% - 50%));left:var(--mdc-ripple-left, calc(50% - 50%));width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface[data-mdc-ripple-is-unbounded].mdc-ripple-upgraded::after,.mdc-ripple-upgraded--unbounded.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}.mdc-ripple-surface::before,.mdc-ripple-surface::after{background-color:#000;background-color:var(--mdc-ripple-color, #000)}.mdc-ripple-surface:hover::before,.mdc-ripple-surface.mdc-ripple-surface--hover::before{opacity:0.04;opacity:var(--mdc-ripple-hover-opacity, 0.04)}.mdc-ripple-surface.mdc-ripple-upgraded--background-focused::before,.mdc-ripple-surface:not(.mdc-ripple-upgraded):focus::before{transition-duration:75ms;opacity:0.12;opacity:var(--mdc-ripple-focus-opacity, 0.12)}.mdc-ripple-surface:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}.mdc-ripple-surface:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:0.12;opacity:var(--mdc-ripple-press-opacity, 0.12)}.mdc-ripple-surface.mdc-ripple-upgraded{--mdc-ripple-fg-opacity:var(--mdc-ripple-press-opacity, 0.12)}wcs-select-option{--mdc-ripple-fg-size:0;--mdc-ripple-left:0;--mdc-ripple-top:0;--mdc-ripple-fg-scale:1;--mdc-ripple-fg-translate-end:0;--mdc-ripple-fg-translate-start:0;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);will-change:transform, opacity;overflow:hidden;display:flex;padding:0 var(--wcs-padding);height:var(--wcs-select-option-height);line-height:42px;cursor:pointer;user-select:none;font-weight:500;font-size:1rem;color:var(--wcs-black)}wcs-select-option::before,wcs-select-option::after{position:absolute;border-radius:50%;opacity:0;pointer-events:none;content:\"\"}wcs-select-option::before{transition:opacity 15ms linear, background-color 15ms linear;z-index:1;z-index:var(--mdc-ripple-z-index, 1)}wcs-select-option::after{z-index:0;z-index:var(--mdc-ripple-z-index, 0)}wcs-select-option.mdc-ripple-upgraded::before{transform:scale(var(--mdc-ripple-fg-scale, 1))}wcs-select-option.mdc-ripple-upgraded::after{top:0;left:0;transform:scale(0);transform-origin:center center}wcs-select-option.mdc-ripple-upgraded--unbounded::after{top:var(--mdc-ripple-top, 0);left:var(--mdc-ripple-left, 0)}wcs-select-option.mdc-ripple-upgraded--foreground-activation::after{animation:mdc-ripple-fg-radius-in 225ms forwards, mdc-ripple-fg-opacity-in 75ms forwards}wcs-select-option.mdc-ripple-upgraded--foreground-deactivation::after{animation:mdc-ripple-fg-opacity-out 150ms;transform:translate(var(--mdc-ripple-fg-translate-end, 0)) scale(var(--mdc-ripple-fg-scale, 1))}wcs-select-option::before,wcs-select-option::after{top:calc(50% - 100%);left:calc(50% - 100%);width:200%;height:200%}wcs-select-option.mdc-ripple-upgraded::after{width:var(--mdc-ripple-fg-size, 100%);height:var(--mdc-ripple-fg-size, 100%)}wcs-select-option::before,wcs-select-option::after{background-color:#999;background-color:var(--mdc-ripple-color, #999)}wcs-select-option:hover::before,wcs-select-option.mdc-ripple-surface--hover::before{opacity:0.1;opacity:var(--mdc-ripple-hover-opacity, 0.1)}wcs-select-option.mdc-ripple-upgraded--background-focused::before,wcs-select-option:not(.mdc-ripple-upgraded):focus::before{transition-duration:75ms;opacity:0.2;opacity:var(--mdc-ripple-focus-opacity, 0.2)}wcs-select-option:not(.mdc-ripple-upgraded)::after{transition:opacity 150ms linear}wcs-select-option:not(.mdc-ripple-upgraded):active::after{transition-duration:75ms;opacity:0.3;opacity:var(--mdc-ripple-press-opacity, 0.3)}wcs-select-option.mdc-ripple-upgraded{--mdc-ripple-fg-opacity:var(--mdc-ripple-press-opacity, 0.3)}wcs-select-option:hover{color:var(--wcs-primary);background-color:var(--wcs-light)}wcs-select-option[disabled]{cursor:default;pointer-events:none;color:var(--wcs-text-disabled)}wcs-select-option[selected]{color:var(--wcs-primary);background-color:var(--wcs-light)}wcs-select-option[multiple] wcs-checkbox{pointer-events:none;margin-right:10px}wcs-select-option[multiple]:hover wcs-checkbox{--wcs-checkbox-border-color:var(--wcs-primary)}";
|
|
4869
|
+
|
|
4870
|
+
let SelectOption = class {
|
|
4871
|
+
constructor(hostRef) {
|
|
4872
|
+
index.registerInstance(this, hostRef);
|
|
4873
|
+
this.wcsSelectOptionClick = index.createEvent(this, "wcsSelectOptionClick", 7);
|
|
4874
|
+
/** Wether this option can be selected. */
|
|
4875
|
+
this.disabled = false;
|
|
4876
|
+
/** Wether this option is selected. */
|
|
4877
|
+
this.selected = false;
|
|
4878
|
+
/**
|
|
4879
|
+
* This property musn't be set by hand, it is used by the `wcs-select` component.
|
|
4880
|
+
* If you want a multiple select, set `multiple` attribute on the parent select instead.
|
|
4881
|
+
* @internal
|
|
4882
|
+
* @ignore
|
|
4883
|
+
*/
|
|
4884
|
+
this.multiple = false;
|
|
4885
|
+
}
|
|
4886
|
+
componentWillLoad() {
|
|
4887
|
+
if (this.value === undefined) {
|
|
4888
|
+
// If no value was given we use the text content instead.
|
|
4889
|
+
this.value = this.el.innerText || '';
|
|
4890
|
+
}
|
|
4891
|
+
}
|
|
4892
|
+
componentDidLoad() {
|
|
4893
|
+
this.mdcRipple = new component.MDCRipple(this.el);
|
|
4894
|
+
}
|
|
4895
|
+
onMouseDown(event) {
|
|
4896
|
+
if (!this.disabled) {
|
|
4897
|
+
event.stopPropagation();
|
|
4898
|
+
// We select inner HTML as it's what's passed into the slot.
|
|
4899
|
+
const displayText = this.el.innerText;
|
|
4900
|
+
this.wcsSelectOptionClick.emit({
|
|
4901
|
+
source: this.el,
|
|
4902
|
+
value: this.value,
|
|
4903
|
+
displayText
|
|
4904
|
+
});
|
|
4905
|
+
}
|
|
4906
|
+
}
|
|
4907
|
+
render() {
|
|
4908
|
+
return (index.h(index.Host, { slot: "wcs-select-option" }, this.multiple &&
|
|
4909
|
+
index.h("wcs-checkbox", { checked: this.selected }), index.h("slot", null)));
|
|
4910
|
+
}
|
|
4911
|
+
get el() { return index.getElement(this); }
|
|
4912
|
+
};
|
|
4913
|
+
SelectOption.style = selectOptionCss;
|
|
4914
|
+
|
|
4915
|
+
exports.wcs_select = Select;
|
|
4916
|
+
exports.wcs_select_option = SelectOption;
|