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