@mog-sdk/node 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3415 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3397 -70
- package/dist/index.js.map +1 -1
- package/package.json +1 -5
package/dist/index.cjs
CHANGED
|
@@ -1345,8 +1345,8 @@ var init_mutation_result_handler = __esm({
|
|
|
1345
1345
|
this.coordinatorRegistry = registry2;
|
|
1346
1346
|
}
|
|
1347
1347
|
/** Set the CellMetadataCache for sync render loop patching. */
|
|
1348
|
-
setCellMetadataCache(
|
|
1349
|
-
this.cellMetadataCache =
|
|
1348
|
+
setCellMetadataCache(cache2) {
|
|
1349
|
+
this.cellMetadataCache = cache2;
|
|
1350
1350
|
}
|
|
1351
1351
|
// ===========================================================================
|
|
1352
1352
|
// Public API
|
|
@@ -4811,10 +4811,10 @@ var init_compute_core = __esm({
|
|
|
4811
4811
|
// Viewport Lifecycle
|
|
4812
4812
|
// ===========================================================================
|
|
4813
4813
|
/** Set the CellMetadataCache for sync render loop patching via MutationResultHandler. */
|
|
4814
|
-
setCellMetadataCache(
|
|
4815
|
-
this.cellMetadataCache =
|
|
4814
|
+
setCellMetadataCache(cache2) {
|
|
4815
|
+
this.cellMetadataCache = cache2;
|
|
4816
4816
|
if (this.mutationHandler) {
|
|
4817
|
-
this.mutationHandler.setCellMetadataCache(
|
|
4817
|
+
this.mutationHandler.setCellMetadataCache(cache2);
|
|
4818
4818
|
}
|
|
4819
4819
|
}
|
|
4820
4820
|
/**
|
|
@@ -5337,8 +5337,8 @@ var init_compute_bridge_gen = __esm({
|
|
|
5337
5337
|
tableClearSlicerSelection(slicer) {
|
|
5338
5338
|
return this.core.transport.call("table_clear_slicer_selection", { slicer });
|
|
5339
5339
|
}
|
|
5340
|
-
tableSelectAllSlicerValues(slicer,
|
|
5341
|
-
return this.core.transport.call("table_select_all_slicer_values", { slicer, cache });
|
|
5340
|
+
tableSelectAllSlicerValues(slicer, cache2) {
|
|
5341
|
+
return this.core.transport.call("table_select_all_slicer_values", { slicer, cache: cache2 });
|
|
5342
5342
|
}
|
|
5343
5343
|
tableSetSlicerSortOrder(slicer, order) {
|
|
5344
5344
|
return this.core.transport.call("table_set_slicer_sort_order", { slicer, order });
|
|
@@ -6243,8 +6243,8 @@ var init_compute_bridge_gen = __esm({
|
|
|
6243
6243
|
mapSlicerDisconnectionReason(reason) {
|
|
6244
6244
|
return this.core.query(this.core.transport.call("compute_map_slicer_disconnection_reason", { docId: this.core.docId, reason }));
|
|
6245
6245
|
}
|
|
6246
|
-
getSlicerItemsFromCache(
|
|
6247
|
-
return this.core.query(this.core.transport.call("compute_get_slicer_items_from_cache", { docId: this.core.docId, cache }));
|
|
6246
|
+
getSlicerItemsFromCache(cache2) {
|
|
6247
|
+
return this.core.query(this.core.transport.call("compute_get_slicer_items_from_cache", { docId: this.core.docId, cache: cache2 }));
|
|
6248
6248
|
}
|
|
6249
6249
|
isSlicerColumnConnected(sourceColumnId, tableColumns) {
|
|
6250
6250
|
return this.core.query(this.core.transport.call("compute_is_slicer_column_connected", { docId: this.core.docId, sourceColumnId, tableColumns }));
|
|
@@ -6807,8 +6807,8 @@ var init_compute_bridge = __esm({
|
|
|
6807
6807
|
initMutationHandler() {
|
|
6808
6808
|
this.core.initMutationHandler();
|
|
6809
6809
|
}
|
|
6810
|
-
setCellMetadataCache(
|
|
6811
|
-
this.core.setCellMetadataCache(
|
|
6810
|
+
setCellMetadataCache(cache2) {
|
|
6811
|
+
this.core.setCellMetadataCache(cache2);
|
|
6812
6812
|
}
|
|
6813
6813
|
getMutationHandler() {
|
|
6814
6814
|
return this.core.getMutationHandler();
|
|
@@ -8177,12 +8177,12 @@ function scaleLinear() {
|
|
|
8177
8177
|
};
|
|
8178
8178
|
return scale2;
|
|
8179
8179
|
}
|
|
8180
|
-
function generateTicks(start,
|
|
8180
|
+
function generateTicks(start, stop2, count = 10) {
|
|
8181
8181
|
if (count <= 0) return [];
|
|
8182
|
-
if (start ===
|
|
8183
|
-
const ascending = start <=
|
|
8184
|
-
const lo = ascending ? start :
|
|
8185
|
-
const hi = ascending ?
|
|
8182
|
+
if (start === stop2) return [start];
|
|
8183
|
+
const ascending = start <= stop2;
|
|
8184
|
+
const lo = ascending ? start : stop2;
|
|
8185
|
+
const hi = ascending ? stop2 : start;
|
|
8186
8186
|
const step = tickStep(lo, hi, count);
|
|
8187
8187
|
if (!isFinite(step) || step === 0) return [];
|
|
8188
8188
|
const tickStart = Math.ceil(lo / step) * step;
|
|
@@ -8194,8 +8194,8 @@ function generateTicks(start, stop, count = 10) {
|
|
|
8194
8194
|
}
|
|
8195
8195
|
return ascending ? ticks : ticks.slice().reverse();
|
|
8196
8196
|
}
|
|
8197
|
-
function tickStep(start,
|
|
8198
|
-
const step0 = Math.abs(
|
|
8197
|
+
function tickStep(start, stop2, count) {
|
|
8198
|
+
const step0 = Math.abs(stop2 - start) / Math.max(0, count);
|
|
8199
8199
|
let step1 = Math.pow(10, Math.floor(Math.log10(step0)));
|
|
8200
8200
|
const error = step0 / step1;
|
|
8201
8201
|
if (error >= Math.sqrt(50)) {
|
|
@@ -8205,24 +8205,24 @@ function tickStep(start, stop, count) {
|
|
|
8205
8205
|
} else if (error >= Math.sqrt(2)) {
|
|
8206
8206
|
step1 *= 2;
|
|
8207
8207
|
}
|
|
8208
|
-
return
|
|
8208
|
+
return stop2 < start ? -step1 : step1;
|
|
8209
8209
|
}
|
|
8210
|
-
function niceLinear(start,
|
|
8210
|
+
function niceLinear(start, stop2, count = 10) {
|
|
8211
8211
|
let prestep = NaN;
|
|
8212
|
-
let step = tickStep(start,
|
|
8212
|
+
let step = tickStep(start, stop2, count);
|
|
8213
8213
|
let iterations = 0;
|
|
8214
8214
|
while (step !== prestep && iterations++ < 10) {
|
|
8215
8215
|
prestep = step;
|
|
8216
8216
|
const newStart = Math.floor(start / step) * step;
|
|
8217
|
-
const newStop = Math.ceil(
|
|
8217
|
+
const newStop = Math.ceil(stop2 / step) * step;
|
|
8218
8218
|
step = tickStep(newStart, newStop, count);
|
|
8219
8219
|
}
|
|
8220
8220
|
if (step > 0) {
|
|
8221
|
-
return [Math.floor(start / step) * step, Math.ceil(
|
|
8221
|
+
return [Math.floor(start / step) * step, Math.ceil(stop2 / step) * step];
|
|
8222
8222
|
} else if (step < 0) {
|
|
8223
|
-
return [Math.ceil(start * step) / step, Math.floor(
|
|
8223
|
+
return [Math.ceil(start * step) / step, Math.floor(stop2 * step) / step];
|
|
8224
8224
|
}
|
|
8225
|
-
return [start,
|
|
8225
|
+
return [start, stop2];
|
|
8226
8226
|
}
|
|
8227
8227
|
function createTickFormatter(_start, _stop, _count = 10, specifier) {
|
|
8228
8228
|
if (specifier) {
|
|
@@ -16773,13 +16773,3340 @@ var init_rust_document = __esm({
|
|
|
16773
16773
|
}
|
|
16774
16774
|
});
|
|
16775
16775
|
|
|
16776
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dev/dist/xstate-dev.esm.js
|
|
16777
|
+
function getGlobal() {
|
|
16778
|
+
if (typeof globalThis !== "undefined") {
|
|
16779
|
+
return globalThis;
|
|
16780
|
+
}
|
|
16781
|
+
if (typeof self !== "undefined") {
|
|
16782
|
+
return self;
|
|
16783
|
+
}
|
|
16784
|
+
if (typeof window !== "undefined") {
|
|
16785
|
+
return window;
|
|
16786
|
+
}
|
|
16787
|
+
if (typeof global !== "undefined") {
|
|
16788
|
+
return global;
|
|
16789
|
+
}
|
|
16790
|
+
}
|
|
16791
|
+
function getDevTools() {
|
|
16792
|
+
const w = getGlobal();
|
|
16793
|
+
if (w.__xstate__) {
|
|
16794
|
+
return w.__xstate__;
|
|
16795
|
+
}
|
|
16796
|
+
return void 0;
|
|
16797
|
+
}
|
|
16798
|
+
var devToolsAdapter;
|
|
16799
|
+
var init_xstate_dev_esm = __esm({
|
|
16800
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dev/dist/xstate-dev.esm.js"() {
|
|
16801
|
+
"use strict";
|
|
16802
|
+
init_cjs_shims();
|
|
16803
|
+
devToolsAdapter = (service) => {
|
|
16804
|
+
if (typeof window === "undefined") {
|
|
16805
|
+
return;
|
|
16806
|
+
}
|
|
16807
|
+
const devTools = getDevTools();
|
|
16808
|
+
if (devTools) {
|
|
16809
|
+
devTools.register(service);
|
|
16810
|
+
}
|
|
16811
|
+
};
|
|
16812
|
+
}
|
|
16813
|
+
});
|
|
16814
|
+
|
|
16815
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/raise-b47daa89.esm.js
|
|
16816
|
+
function createAfterEvent(delayRef, id) {
|
|
16817
|
+
return {
|
|
16818
|
+
type: `xstate.after.${delayRef}.${id}`
|
|
16819
|
+
};
|
|
16820
|
+
}
|
|
16821
|
+
function createDoneStateEvent(id, output) {
|
|
16822
|
+
return {
|
|
16823
|
+
type: `xstate.done.state.${id}`,
|
|
16824
|
+
output
|
|
16825
|
+
};
|
|
16826
|
+
}
|
|
16827
|
+
function createDoneActorEvent(invokeId, output) {
|
|
16828
|
+
return {
|
|
16829
|
+
type: `xstate.done.actor.${invokeId}`,
|
|
16830
|
+
output,
|
|
16831
|
+
actorId: invokeId
|
|
16832
|
+
};
|
|
16833
|
+
}
|
|
16834
|
+
function createErrorActorEvent(id, error) {
|
|
16835
|
+
return {
|
|
16836
|
+
type: `xstate.error.actor.${id}`,
|
|
16837
|
+
error,
|
|
16838
|
+
actorId: id
|
|
16839
|
+
};
|
|
16840
|
+
}
|
|
16841
|
+
function createInitEvent(input) {
|
|
16842
|
+
return {
|
|
16843
|
+
type: XSTATE_INIT,
|
|
16844
|
+
input
|
|
16845
|
+
};
|
|
16846
|
+
}
|
|
16847
|
+
function reportUnhandledError(err2) {
|
|
16848
|
+
setTimeout(() => {
|
|
16849
|
+
throw err2;
|
|
16850
|
+
});
|
|
16851
|
+
}
|
|
16852
|
+
function matchesState(parentStateId, childStateId) {
|
|
16853
|
+
const parentStateValue = toStateValue(parentStateId);
|
|
16854
|
+
const childStateValue = toStateValue(childStateId);
|
|
16855
|
+
if (typeof childStateValue === "string") {
|
|
16856
|
+
if (typeof parentStateValue === "string") {
|
|
16857
|
+
return childStateValue === parentStateValue;
|
|
16858
|
+
}
|
|
16859
|
+
return false;
|
|
16860
|
+
}
|
|
16861
|
+
if (typeof parentStateValue === "string") {
|
|
16862
|
+
return parentStateValue in childStateValue;
|
|
16863
|
+
}
|
|
16864
|
+
return Object.keys(parentStateValue).every((key) => {
|
|
16865
|
+
if (!(key in childStateValue)) {
|
|
16866
|
+
return false;
|
|
16867
|
+
}
|
|
16868
|
+
return matchesState(parentStateValue[key], childStateValue[key]);
|
|
16869
|
+
});
|
|
16870
|
+
}
|
|
16871
|
+
function toStatePath(stateId) {
|
|
16872
|
+
if (isArray(stateId)) {
|
|
16873
|
+
return stateId;
|
|
16874
|
+
}
|
|
16875
|
+
const result = [];
|
|
16876
|
+
let segment = "";
|
|
16877
|
+
for (let i = 0; i < stateId.length; i++) {
|
|
16878
|
+
const char = stateId.charCodeAt(i);
|
|
16879
|
+
switch (char) {
|
|
16880
|
+
// \
|
|
16881
|
+
case 92:
|
|
16882
|
+
segment += stateId[i + 1];
|
|
16883
|
+
i++;
|
|
16884
|
+
continue;
|
|
16885
|
+
// .
|
|
16886
|
+
case 46:
|
|
16887
|
+
result.push(segment);
|
|
16888
|
+
segment = "";
|
|
16889
|
+
continue;
|
|
16890
|
+
}
|
|
16891
|
+
segment += stateId[i];
|
|
16892
|
+
}
|
|
16893
|
+
result.push(segment);
|
|
16894
|
+
return result;
|
|
16895
|
+
}
|
|
16896
|
+
function toStateValue(stateValue) {
|
|
16897
|
+
if (isMachineSnapshot(stateValue)) {
|
|
16898
|
+
return stateValue.value;
|
|
16899
|
+
}
|
|
16900
|
+
if (typeof stateValue !== "string") {
|
|
16901
|
+
return stateValue;
|
|
16902
|
+
}
|
|
16903
|
+
const statePath = toStatePath(stateValue);
|
|
16904
|
+
return pathToStateValue(statePath);
|
|
16905
|
+
}
|
|
16906
|
+
function pathToStateValue(statePath) {
|
|
16907
|
+
if (statePath.length === 1) {
|
|
16908
|
+
return statePath[0];
|
|
16909
|
+
}
|
|
16910
|
+
const value = {};
|
|
16911
|
+
let marker = value;
|
|
16912
|
+
for (let i = 0; i < statePath.length - 1; i++) {
|
|
16913
|
+
if (i === statePath.length - 2) {
|
|
16914
|
+
marker[statePath[i]] = statePath[i + 1];
|
|
16915
|
+
} else {
|
|
16916
|
+
const previous = marker;
|
|
16917
|
+
marker = {};
|
|
16918
|
+
previous[statePath[i]] = marker;
|
|
16919
|
+
}
|
|
16920
|
+
}
|
|
16921
|
+
return value;
|
|
16922
|
+
}
|
|
16923
|
+
function mapValues(collection, iteratee) {
|
|
16924
|
+
const result = {};
|
|
16925
|
+
const collectionKeys = Object.keys(collection);
|
|
16926
|
+
for (let i = 0; i < collectionKeys.length; i++) {
|
|
16927
|
+
const key = collectionKeys[i];
|
|
16928
|
+
result[key] = iteratee(collection[key], key, collection, i);
|
|
16929
|
+
}
|
|
16930
|
+
return result;
|
|
16931
|
+
}
|
|
16932
|
+
function toArrayStrict(value) {
|
|
16933
|
+
if (isArray(value)) {
|
|
16934
|
+
return value;
|
|
16935
|
+
}
|
|
16936
|
+
return [value];
|
|
16937
|
+
}
|
|
16938
|
+
function toArray(value) {
|
|
16939
|
+
if (value === void 0) {
|
|
16940
|
+
return [];
|
|
16941
|
+
}
|
|
16942
|
+
return toArrayStrict(value);
|
|
16943
|
+
}
|
|
16944
|
+
function resolveOutput(mapper, context, event, self2) {
|
|
16945
|
+
if (typeof mapper === "function") {
|
|
16946
|
+
return mapper({
|
|
16947
|
+
context,
|
|
16948
|
+
event,
|
|
16949
|
+
self: self2
|
|
16950
|
+
});
|
|
16951
|
+
}
|
|
16952
|
+
return mapper;
|
|
16953
|
+
}
|
|
16954
|
+
function isArray(value) {
|
|
16955
|
+
return Array.isArray(value);
|
|
16956
|
+
}
|
|
16957
|
+
function isErrorActorEvent(event) {
|
|
16958
|
+
return event.type.startsWith("xstate.error.actor");
|
|
16959
|
+
}
|
|
16960
|
+
function toTransitionConfigArray(configLike) {
|
|
16961
|
+
return toArrayStrict(configLike).map((transitionLike) => {
|
|
16962
|
+
if (typeof transitionLike === "undefined" || typeof transitionLike === "string") {
|
|
16963
|
+
return {
|
|
16964
|
+
target: transitionLike
|
|
16965
|
+
};
|
|
16966
|
+
}
|
|
16967
|
+
return transitionLike;
|
|
16968
|
+
});
|
|
16969
|
+
}
|
|
16970
|
+
function normalizeTarget(target) {
|
|
16971
|
+
if (target === void 0 || target === TARGETLESS_KEY) {
|
|
16972
|
+
return void 0;
|
|
16973
|
+
}
|
|
16974
|
+
return toArray(target);
|
|
16975
|
+
}
|
|
16976
|
+
function toObserver(nextHandler, errorHandler, completionHandler) {
|
|
16977
|
+
const isObserver = typeof nextHandler === "object";
|
|
16978
|
+
const self2 = isObserver ? nextHandler : void 0;
|
|
16979
|
+
return {
|
|
16980
|
+
next: (isObserver ? nextHandler.next : nextHandler)?.bind(self2),
|
|
16981
|
+
error: (isObserver ? nextHandler.error : errorHandler)?.bind(self2),
|
|
16982
|
+
complete: (isObserver ? nextHandler.complete : completionHandler)?.bind(self2)
|
|
16983
|
+
};
|
|
16984
|
+
}
|
|
16985
|
+
function createInvokeId(stateNodeId, index) {
|
|
16986
|
+
return `${index}.${stateNodeId}`;
|
|
16987
|
+
}
|
|
16988
|
+
function resolveReferencedActor(machine, src) {
|
|
16989
|
+
const match = src.match(/^xstate\.invoke\.(\d+)\.(.*)/);
|
|
16990
|
+
if (!match) {
|
|
16991
|
+
return machine.implementations.actors[src];
|
|
16992
|
+
}
|
|
16993
|
+
const [, indexStr, nodeId] = match;
|
|
16994
|
+
const node = machine.getStateNodeById(nodeId);
|
|
16995
|
+
const invokeConfig = node.config.invoke;
|
|
16996
|
+
return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
|
|
16997
|
+
}
|
|
16998
|
+
function matchesEventDescriptor(eventType, descriptor) {
|
|
16999
|
+
if (descriptor === eventType) {
|
|
17000
|
+
return true;
|
|
17001
|
+
}
|
|
17002
|
+
if (descriptor === WILDCARD) {
|
|
17003
|
+
return true;
|
|
17004
|
+
}
|
|
17005
|
+
if (!descriptor.endsWith(".*")) {
|
|
17006
|
+
return false;
|
|
17007
|
+
}
|
|
17008
|
+
const partialEventTokens = descriptor.split(".");
|
|
17009
|
+
const eventTokens = eventType.split(".");
|
|
17010
|
+
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
17011
|
+
const partialEventToken = partialEventTokens[tokenIndex];
|
|
17012
|
+
const eventToken = eventTokens[tokenIndex];
|
|
17013
|
+
if (partialEventToken === "*") {
|
|
17014
|
+
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
17015
|
+
return isLastToken;
|
|
17016
|
+
}
|
|
17017
|
+
if (partialEventToken !== eventToken) {
|
|
17018
|
+
return false;
|
|
17019
|
+
}
|
|
17020
|
+
}
|
|
17021
|
+
return true;
|
|
17022
|
+
}
|
|
17023
|
+
function createScheduledEventId(actorRef, id) {
|
|
17024
|
+
return `${actorRef.sessionId}.${id}`;
|
|
17025
|
+
}
|
|
17026
|
+
function createSystem(rootActor, options) {
|
|
17027
|
+
const children2 = /* @__PURE__ */ new Map();
|
|
17028
|
+
const keyedActors = /* @__PURE__ */ new Map();
|
|
17029
|
+
const reverseKeyedActors = /* @__PURE__ */ new WeakMap();
|
|
17030
|
+
const inspectionObservers = /* @__PURE__ */ new Set();
|
|
17031
|
+
const timerMap = {};
|
|
17032
|
+
const {
|
|
17033
|
+
clock,
|
|
17034
|
+
logger
|
|
17035
|
+
} = options;
|
|
17036
|
+
const scheduler = {
|
|
17037
|
+
schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
|
|
17038
|
+
const scheduledEvent = {
|
|
17039
|
+
source,
|
|
17040
|
+
target,
|
|
17041
|
+
event,
|
|
17042
|
+
delay,
|
|
17043
|
+
id,
|
|
17044
|
+
startedAt: Date.now()
|
|
17045
|
+
};
|
|
17046
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
17047
|
+
system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
|
|
17048
|
+
const timeout = clock.setTimeout(() => {
|
|
17049
|
+
delete timerMap[scheduledEventId];
|
|
17050
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
17051
|
+
system._relay(source, target, event);
|
|
17052
|
+
}, delay);
|
|
17053
|
+
timerMap[scheduledEventId] = timeout;
|
|
17054
|
+
},
|
|
17055
|
+
cancel: (source, id) => {
|
|
17056
|
+
const scheduledEventId = createScheduledEventId(source, id);
|
|
17057
|
+
const timeout = timerMap[scheduledEventId];
|
|
17058
|
+
delete timerMap[scheduledEventId];
|
|
17059
|
+
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
17060
|
+
if (timeout !== void 0) {
|
|
17061
|
+
clock.clearTimeout(timeout);
|
|
17062
|
+
}
|
|
17063
|
+
},
|
|
17064
|
+
cancelAll: (actorRef) => {
|
|
17065
|
+
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
17066
|
+
const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
|
|
17067
|
+
if (scheduledEvent.source === actorRef) {
|
|
17068
|
+
scheduler.cancel(actorRef, scheduledEvent.id);
|
|
17069
|
+
}
|
|
17070
|
+
}
|
|
17071
|
+
}
|
|
17072
|
+
};
|
|
17073
|
+
const sendInspectionEvent = (event) => {
|
|
17074
|
+
if (!inspectionObservers.size) {
|
|
17075
|
+
return;
|
|
17076
|
+
}
|
|
17077
|
+
const resolvedInspectionEvent = {
|
|
17078
|
+
...event,
|
|
17079
|
+
rootId: rootActor.sessionId
|
|
17080
|
+
};
|
|
17081
|
+
inspectionObservers.forEach((observer) => observer.next?.(resolvedInspectionEvent));
|
|
17082
|
+
};
|
|
17083
|
+
const system = {
|
|
17084
|
+
_snapshot: {
|
|
17085
|
+
_scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
|
|
17086
|
+
},
|
|
17087
|
+
_bookId: () => `x:${idCounter++}`,
|
|
17088
|
+
_register: (sessionId, actorRef) => {
|
|
17089
|
+
children2.set(sessionId, actorRef);
|
|
17090
|
+
return sessionId;
|
|
17091
|
+
},
|
|
17092
|
+
_unregister: (actorRef) => {
|
|
17093
|
+
children2.delete(actorRef.sessionId);
|
|
17094
|
+
const systemId = reverseKeyedActors.get(actorRef);
|
|
17095
|
+
if (systemId !== void 0) {
|
|
17096
|
+
keyedActors.delete(systemId);
|
|
17097
|
+
reverseKeyedActors.delete(actorRef);
|
|
17098
|
+
}
|
|
17099
|
+
},
|
|
17100
|
+
get: (systemId) => {
|
|
17101
|
+
return keyedActors.get(systemId);
|
|
17102
|
+
},
|
|
17103
|
+
getAll: () => {
|
|
17104
|
+
return Object.fromEntries(keyedActors.entries());
|
|
17105
|
+
},
|
|
17106
|
+
_set: (systemId, actorRef) => {
|
|
17107
|
+
const existing = keyedActors.get(systemId);
|
|
17108
|
+
if (existing && existing !== actorRef) {
|
|
17109
|
+
throw new Error(`Actor with system ID '${systemId}' already exists.`);
|
|
17110
|
+
}
|
|
17111
|
+
keyedActors.set(systemId, actorRef);
|
|
17112
|
+
reverseKeyedActors.set(actorRef, systemId);
|
|
17113
|
+
},
|
|
17114
|
+
inspect: (observerOrFn) => {
|
|
17115
|
+
const observer = toObserver(observerOrFn);
|
|
17116
|
+
inspectionObservers.add(observer);
|
|
17117
|
+
return {
|
|
17118
|
+
unsubscribe() {
|
|
17119
|
+
inspectionObservers.delete(observer);
|
|
17120
|
+
}
|
|
17121
|
+
};
|
|
17122
|
+
},
|
|
17123
|
+
_sendInspectionEvent: sendInspectionEvent,
|
|
17124
|
+
_relay: (source, target, event) => {
|
|
17125
|
+
system._sendInspectionEvent({
|
|
17126
|
+
type: "@xstate.event",
|
|
17127
|
+
sourceRef: source,
|
|
17128
|
+
actorRef: target,
|
|
17129
|
+
event
|
|
17130
|
+
});
|
|
17131
|
+
target._send(event);
|
|
17132
|
+
},
|
|
17133
|
+
scheduler,
|
|
17134
|
+
getSnapshot: () => {
|
|
17135
|
+
return {
|
|
17136
|
+
_scheduledEvents: {
|
|
17137
|
+
...system._snapshot._scheduledEvents
|
|
17138
|
+
}
|
|
17139
|
+
};
|
|
17140
|
+
},
|
|
17141
|
+
start: () => {
|
|
17142
|
+
const scheduledEvents = system._snapshot._scheduledEvents;
|
|
17143
|
+
system._snapshot._scheduledEvents = {};
|
|
17144
|
+
for (const scheduledId in scheduledEvents) {
|
|
17145
|
+
const {
|
|
17146
|
+
source,
|
|
17147
|
+
target,
|
|
17148
|
+
event,
|
|
17149
|
+
delay,
|
|
17150
|
+
id
|
|
17151
|
+
} = scheduledEvents[scheduledId];
|
|
17152
|
+
scheduler.schedule(source, target, event, delay, id);
|
|
17153
|
+
}
|
|
17154
|
+
},
|
|
17155
|
+
_clock: clock,
|
|
17156
|
+
_logger: logger
|
|
17157
|
+
};
|
|
17158
|
+
return system;
|
|
17159
|
+
}
|
|
17160
|
+
function createActor(logic, ...[options]) {
|
|
17161
|
+
return new Actor(logic, options);
|
|
17162
|
+
}
|
|
17163
|
+
function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
17164
|
+
sendId
|
|
17165
|
+
}) {
|
|
17166
|
+
const resolvedSendId = typeof sendId === "function" ? sendId(actionArgs, actionParams) : sendId;
|
|
17167
|
+
return [snapshot, {
|
|
17168
|
+
sendId: resolvedSendId
|
|
17169
|
+
}, void 0];
|
|
17170
|
+
}
|
|
17171
|
+
function executeCancel(actorScope, params) {
|
|
17172
|
+
actorScope.defer(() => {
|
|
17173
|
+
actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
|
|
17174
|
+
});
|
|
17175
|
+
}
|
|
17176
|
+
function cancel(sendId) {
|
|
17177
|
+
function cancel2(_args, _params) {
|
|
17178
|
+
}
|
|
17179
|
+
cancel2.type = "xstate.cancel";
|
|
17180
|
+
cancel2.sendId = sendId;
|
|
17181
|
+
cancel2.resolve = resolveCancel;
|
|
17182
|
+
cancel2.execute = executeCancel;
|
|
17183
|
+
return cancel2;
|
|
17184
|
+
}
|
|
17185
|
+
function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
17186
|
+
id,
|
|
17187
|
+
systemId,
|
|
17188
|
+
src,
|
|
17189
|
+
input,
|
|
17190
|
+
syncSnapshot
|
|
17191
|
+
}) {
|
|
17192
|
+
const logic = typeof src === "string" ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
17193
|
+
const resolvedId = typeof id === "function" ? id(actionArgs) : id;
|
|
17194
|
+
let actorRef;
|
|
17195
|
+
let resolvedInput = void 0;
|
|
17196
|
+
if (logic) {
|
|
17197
|
+
resolvedInput = typeof input === "function" ? input({
|
|
17198
|
+
context: snapshot.context,
|
|
17199
|
+
event: actionArgs.event,
|
|
17200
|
+
self: actorScope.self
|
|
17201
|
+
}) : input;
|
|
17202
|
+
actorRef = createActor(logic, {
|
|
17203
|
+
id: resolvedId,
|
|
17204
|
+
src,
|
|
17205
|
+
parent: actorScope.self,
|
|
17206
|
+
syncSnapshot,
|
|
17207
|
+
systemId,
|
|
17208
|
+
input: resolvedInput
|
|
17209
|
+
});
|
|
17210
|
+
}
|
|
17211
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
17212
|
+
children: {
|
|
17213
|
+
...snapshot.children,
|
|
17214
|
+
[resolvedId]: actorRef
|
|
17215
|
+
}
|
|
17216
|
+
}), {
|
|
17217
|
+
id,
|
|
17218
|
+
systemId,
|
|
17219
|
+
actorRef,
|
|
17220
|
+
src,
|
|
17221
|
+
input: resolvedInput
|
|
17222
|
+
}, void 0];
|
|
17223
|
+
}
|
|
17224
|
+
function executeSpawn(actorScope, {
|
|
17225
|
+
actorRef
|
|
17226
|
+
}) {
|
|
17227
|
+
if (!actorRef) {
|
|
17228
|
+
return;
|
|
17229
|
+
}
|
|
17230
|
+
actorScope.defer(() => {
|
|
17231
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
17232
|
+
return;
|
|
17233
|
+
}
|
|
17234
|
+
actorRef.start();
|
|
17235
|
+
});
|
|
17236
|
+
}
|
|
17237
|
+
function spawnChild(...[src, {
|
|
17238
|
+
id,
|
|
17239
|
+
systemId,
|
|
17240
|
+
input,
|
|
17241
|
+
syncSnapshot = false
|
|
17242
|
+
} = {}]) {
|
|
17243
|
+
function spawnChild2(_args, _params) {
|
|
17244
|
+
}
|
|
17245
|
+
spawnChild2.type = "xstate.spawnChild";
|
|
17246
|
+
spawnChild2.id = id;
|
|
17247
|
+
spawnChild2.systemId = systemId;
|
|
17248
|
+
spawnChild2.src = src;
|
|
17249
|
+
spawnChild2.input = input;
|
|
17250
|
+
spawnChild2.syncSnapshot = syncSnapshot;
|
|
17251
|
+
spawnChild2.resolve = resolveSpawn;
|
|
17252
|
+
spawnChild2.execute = executeSpawn;
|
|
17253
|
+
return spawnChild2;
|
|
17254
|
+
}
|
|
17255
|
+
function resolveStop(_, snapshot, args, actionParams, {
|
|
17256
|
+
actorRef
|
|
17257
|
+
}) {
|
|
17258
|
+
const actorRefOrString = typeof actorRef === "function" ? actorRef(args, actionParams) : actorRef;
|
|
17259
|
+
const resolvedActorRef = typeof actorRefOrString === "string" ? snapshot.children[actorRefOrString] : actorRefOrString;
|
|
17260
|
+
let children2 = snapshot.children;
|
|
17261
|
+
if (resolvedActorRef) {
|
|
17262
|
+
children2 = {
|
|
17263
|
+
...children2
|
|
17264
|
+
};
|
|
17265
|
+
delete children2[resolvedActorRef.id];
|
|
17266
|
+
}
|
|
17267
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
17268
|
+
children: children2
|
|
17269
|
+
}), resolvedActorRef, void 0];
|
|
17270
|
+
}
|
|
17271
|
+
function unregisterRecursively(actorScope, actorRef) {
|
|
17272
|
+
const snapshot = actorRef.getSnapshot();
|
|
17273
|
+
if (snapshot && "children" in snapshot) {
|
|
17274
|
+
for (const child2 of Object.values(snapshot.children)) {
|
|
17275
|
+
unregisterRecursively(actorScope, child2);
|
|
17276
|
+
}
|
|
17277
|
+
}
|
|
17278
|
+
actorScope.system._unregister(actorRef);
|
|
17279
|
+
}
|
|
17280
|
+
function executeStop(actorScope, actorRef) {
|
|
17281
|
+
if (!actorRef) {
|
|
17282
|
+
return;
|
|
17283
|
+
}
|
|
17284
|
+
unregisterRecursively(actorScope, actorRef);
|
|
17285
|
+
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
17286
|
+
actorScope.stopChild(actorRef);
|
|
17287
|
+
return;
|
|
17288
|
+
}
|
|
17289
|
+
actorScope.defer(() => {
|
|
17290
|
+
actorScope.stopChild(actorRef);
|
|
17291
|
+
});
|
|
17292
|
+
}
|
|
17293
|
+
function stopChild(actorRef) {
|
|
17294
|
+
function stop2(_args, _params) {
|
|
17295
|
+
}
|
|
17296
|
+
stop2.type = "xstate.stopChild";
|
|
17297
|
+
stop2.actorRef = actorRef;
|
|
17298
|
+
stop2.resolve = resolveStop;
|
|
17299
|
+
stop2.execute = executeStop;
|
|
17300
|
+
return stop2;
|
|
17301
|
+
}
|
|
17302
|
+
function evaluateGuard(guard, context, event, snapshot) {
|
|
17303
|
+
const {
|
|
17304
|
+
machine
|
|
17305
|
+
} = snapshot;
|
|
17306
|
+
const isInline = typeof guard === "function";
|
|
17307
|
+
const resolved = isInline ? guard : machine.implementations.guards[typeof guard === "string" ? guard : guard.type];
|
|
17308
|
+
if (!isInline && !resolved) {
|
|
17309
|
+
throw new Error(`Guard '${typeof guard === "string" ? guard : guard.type}' is not implemented.'.`);
|
|
17310
|
+
}
|
|
17311
|
+
if (typeof resolved !== "function") {
|
|
17312
|
+
return evaluateGuard(resolved, context, event, snapshot);
|
|
17313
|
+
}
|
|
17314
|
+
const guardArgs = {
|
|
17315
|
+
context,
|
|
17316
|
+
event
|
|
17317
|
+
};
|
|
17318
|
+
const guardParams = isInline || typeof guard === "string" ? void 0 : "params" in guard ? typeof guard.params === "function" ? guard.params({
|
|
17319
|
+
context,
|
|
17320
|
+
event
|
|
17321
|
+
}) : guard.params : void 0;
|
|
17322
|
+
if (!("check" in resolved)) {
|
|
17323
|
+
return resolved(guardArgs, guardParams);
|
|
17324
|
+
}
|
|
17325
|
+
const builtinGuard = resolved;
|
|
17326
|
+
return builtinGuard.check(
|
|
17327
|
+
snapshot,
|
|
17328
|
+
guardArgs,
|
|
17329
|
+
resolved
|
|
17330
|
+
// this holds all params
|
|
17331
|
+
);
|
|
17332
|
+
}
|
|
17333
|
+
function isAtomicStateNode(stateNode) {
|
|
17334
|
+
return stateNode.type === "atomic" || stateNode.type === "final";
|
|
17335
|
+
}
|
|
17336
|
+
function getChildren(stateNode) {
|
|
17337
|
+
return Object.values(stateNode.states).filter((sn) => sn.type !== "history");
|
|
17338
|
+
}
|
|
17339
|
+
function getProperAncestors(stateNode, toStateNode) {
|
|
17340
|
+
const ancestors = [];
|
|
17341
|
+
if (toStateNode === stateNode) {
|
|
17342
|
+
return ancestors;
|
|
17343
|
+
}
|
|
17344
|
+
let m = stateNode.parent;
|
|
17345
|
+
while (m && m !== toStateNode) {
|
|
17346
|
+
ancestors.push(m);
|
|
17347
|
+
m = m.parent;
|
|
17348
|
+
}
|
|
17349
|
+
return ancestors;
|
|
17350
|
+
}
|
|
17351
|
+
function getAllStateNodes(stateNodes) {
|
|
17352
|
+
const nodeSet = new Set(stateNodes);
|
|
17353
|
+
const adjList = getAdjList(nodeSet);
|
|
17354
|
+
for (const s of nodeSet) {
|
|
17355
|
+
if (s.type === "compound" && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
17356
|
+
getInitialStateNodesWithTheirAncestors(s).forEach((sn) => nodeSet.add(sn));
|
|
17357
|
+
} else {
|
|
17358
|
+
if (s.type === "parallel") {
|
|
17359
|
+
for (const child2 of getChildren(s)) {
|
|
17360
|
+
if (child2.type === "history") {
|
|
17361
|
+
continue;
|
|
17362
|
+
}
|
|
17363
|
+
if (!nodeSet.has(child2)) {
|
|
17364
|
+
const initialStates = getInitialStateNodesWithTheirAncestors(child2);
|
|
17365
|
+
for (const initialStateNode of initialStates) {
|
|
17366
|
+
nodeSet.add(initialStateNode);
|
|
17367
|
+
}
|
|
17368
|
+
}
|
|
17369
|
+
}
|
|
17370
|
+
}
|
|
17371
|
+
}
|
|
17372
|
+
}
|
|
17373
|
+
for (const s of nodeSet) {
|
|
17374
|
+
let m = s.parent;
|
|
17375
|
+
while (m) {
|
|
17376
|
+
nodeSet.add(m);
|
|
17377
|
+
m = m.parent;
|
|
17378
|
+
}
|
|
17379
|
+
}
|
|
17380
|
+
return nodeSet;
|
|
17381
|
+
}
|
|
17382
|
+
function getValueFromAdj(baseNode, adjList) {
|
|
17383
|
+
const childStateNodes = adjList.get(baseNode);
|
|
17384
|
+
if (!childStateNodes) {
|
|
17385
|
+
return {};
|
|
17386
|
+
}
|
|
17387
|
+
if (baseNode.type === "compound") {
|
|
17388
|
+
const childStateNode = childStateNodes[0];
|
|
17389
|
+
if (childStateNode) {
|
|
17390
|
+
if (isAtomicStateNode(childStateNode)) {
|
|
17391
|
+
return childStateNode.key;
|
|
17392
|
+
}
|
|
17393
|
+
} else {
|
|
17394
|
+
return {};
|
|
17395
|
+
}
|
|
17396
|
+
}
|
|
17397
|
+
const stateValue = {};
|
|
17398
|
+
for (const childStateNode of childStateNodes) {
|
|
17399
|
+
stateValue[childStateNode.key] = getValueFromAdj(childStateNode, adjList);
|
|
17400
|
+
}
|
|
17401
|
+
return stateValue;
|
|
17402
|
+
}
|
|
17403
|
+
function getAdjList(stateNodes) {
|
|
17404
|
+
const adjList = /* @__PURE__ */ new Map();
|
|
17405
|
+
for (const s of stateNodes) {
|
|
17406
|
+
if (!adjList.has(s)) {
|
|
17407
|
+
adjList.set(s, []);
|
|
17408
|
+
}
|
|
17409
|
+
if (s.parent) {
|
|
17410
|
+
if (!adjList.has(s.parent)) {
|
|
17411
|
+
adjList.set(s.parent, []);
|
|
17412
|
+
}
|
|
17413
|
+
adjList.get(s.parent).push(s);
|
|
17414
|
+
}
|
|
17415
|
+
}
|
|
17416
|
+
return adjList;
|
|
17417
|
+
}
|
|
17418
|
+
function getStateValue(rootNode, stateNodes) {
|
|
17419
|
+
const config = getAllStateNodes(stateNodes);
|
|
17420
|
+
return getValueFromAdj(rootNode, getAdjList(config));
|
|
17421
|
+
}
|
|
17422
|
+
function isInFinalState(stateNodeSet, stateNode) {
|
|
17423
|
+
if (stateNode.type === "compound") {
|
|
17424
|
+
return getChildren(stateNode).some((s) => s.type === "final" && stateNodeSet.has(s));
|
|
17425
|
+
}
|
|
17426
|
+
if (stateNode.type === "parallel") {
|
|
17427
|
+
return getChildren(stateNode).every((sn) => isInFinalState(stateNodeSet, sn));
|
|
17428
|
+
}
|
|
17429
|
+
return stateNode.type === "final";
|
|
17430
|
+
}
|
|
17431
|
+
function getCandidates(stateNode, receivedEventType) {
|
|
17432
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter((eventDescriptor) => matchesEventDescriptor(receivedEventType, eventDescriptor)).sort((a, b) => b.length - a.length).flatMap((key) => stateNode.transitions.get(key));
|
|
17433
|
+
return candidates;
|
|
17434
|
+
}
|
|
17435
|
+
function getDelayedTransitions(stateNode) {
|
|
17436
|
+
const afterConfig = stateNode.config.after;
|
|
17437
|
+
if (!afterConfig) {
|
|
17438
|
+
return [];
|
|
17439
|
+
}
|
|
17440
|
+
const mutateEntryExit = (delay) => {
|
|
17441
|
+
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
17442
|
+
const eventType = afterEvent.type;
|
|
17443
|
+
stateNode.entry.push(raise(afterEvent, {
|
|
17444
|
+
id: eventType,
|
|
17445
|
+
delay
|
|
17446
|
+
}));
|
|
17447
|
+
stateNode.exit.push(cancel(eventType));
|
|
17448
|
+
return eventType;
|
|
17449
|
+
};
|
|
17450
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap((delay) => {
|
|
17451
|
+
const configTransition = afterConfig[delay];
|
|
17452
|
+
const resolvedTransition = typeof configTransition === "string" ? {
|
|
17453
|
+
target: configTransition
|
|
17454
|
+
} : configTransition;
|
|
17455
|
+
const resolvedDelay = Number.isNaN(+delay) ? delay : +delay;
|
|
17456
|
+
const eventType = mutateEntryExit(resolvedDelay);
|
|
17457
|
+
return toArray(resolvedTransition).map((transition) => ({
|
|
17458
|
+
...transition,
|
|
17459
|
+
event: eventType,
|
|
17460
|
+
delay: resolvedDelay
|
|
17461
|
+
}));
|
|
17462
|
+
});
|
|
17463
|
+
return delayedTransitions.map((delayedTransition) => {
|
|
17464
|
+
const {
|
|
17465
|
+
delay
|
|
17466
|
+
} = delayedTransition;
|
|
17467
|
+
return {
|
|
17468
|
+
...formatTransition(stateNode, delayedTransition.event, delayedTransition),
|
|
17469
|
+
delay
|
|
17470
|
+
};
|
|
17471
|
+
});
|
|
17472
|
+
}
|
|
17473
|
+
function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
17474
|
+
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
17475
|
+
const reenter = transitionConfig.reenter ?? false;
|
|
17476
|
+
const target = resolveTarget(stateNode, normalizedTarget);
|
|
17477
|
+
const transition = {
|
|
17478
|
+
...transitionConfig,
|
|
17479
|
+
actions: toArray(transitionConfig.actions),
|
|
17480
|
+
guard: transitionConfig.guard,
|
|
17481
|
+
target,
|
|
17482
|
+
source: stateNode,
|
|
17483
|
+
reenter,
|
|
17484
|
+
eventType: descriptor,
|
|
17485
|
+
toJSON: () => ({
|
|
17486
|
+
...transition,
|
|
17487
|
+
source: `#${stateNode.id}`,
|
|
17488
|
+
target: target ? target.map((t) => `#${t.id}`) : void 0
|
|
17489
|
+
})
|
|
17490
|
+
};
|
|
17491
|
+
return transition;
|
|
17492
|
+
}
|
|
17493
|
+
function formatTransitions(stateNode) {
|
|
17494
|
+
const transitions = /* @__PURE__ */ new Map();
|
|
17495
|
+
if (stateNode.config.on) {
|
|
17496
|
+
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
17497
|
+
if (descriptor === NULL_EVENT) {
|
|
17498
|
+
throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
|
|
17499
|
+
}
|
|
17500
|
+
const transitionsConfig = stateNode.config.on[descriptor];
|
|
17501
|
+
transitions.set(descriptor, toTransitionConfigArray(transitionsConfig).map((t) => formatTransition(stateNode, descriptor, t)));
|
|
17502
|
+
}
|
|
17503
|
+
}
|
|
17504
|
+
if (stateNode.config.onDone) {
|
|
17505
|
+
const descriptor = `xstate.done.state.${stateNode.id}`;
|
|
17506
|
+
transitions.set(descriptor, toTransitionConfigArray(stateNode.config.onDone).map((t) => formatTransition(stateNode, descriptor, t)));
|
|
17507
|
+
}
|
|
17508
|
+
for (const invokeDef of stateNode.invoke) {
|
|
17509
|
+
if (invokeDef.onDone) {
|
|
17510
|
+
const descriptor = `xstate.done.actor.${invokeDef.id}`;
|
|
17511
|
+
transitions.set(descriptor, toTransitionConfigArray(invokeDef.onDone).map((t) => formatTransition(stateNode, descriptor, t)));
|
|
17512
|
+
}
|
|
17513
|
+
if (invokeDef.onError) {
|
|
17514
|
+
const descriptor = `xstate.error.actor.${invokeDef.id}`;
|
|
17515
|
+
transitions.set(descriptor, toTransitionConfigArray(invokeDef.onError).map((t) => formatTransition(stateNode, descriptor, t)));
|
|
17516
|
+
}
|
|
17517
|
+
if (invokeDef.onSnapshot) {
|
|
17518
|
+
const descriptor = `xstate.snapshot.${invokeDef.id}`;
|
|
17519
|
+
transitions.set(descriptor, toTransitionConfigArray(invokeDef.onSnapshot).map((t) => formatTransition(stateNode, descriptor, t)));
|
|
17520
|
+
}
|
|
17521
|
+
}
|
|
17522
|
+
for (const delayedTransition of stateNode.after) {
|
|
17523
|
+
let existing = transitions.get(delayedTransition.eventType);
|
|
17524
|
+
if (!existing) {
|
|
17525
|
+
existing = [];
|
|
17526
|
+
transitions.set(delayedTransition.eventType, existing);
|
|
17527
|
+
}
|
|
17528
|
+
existing.push(delayedTransition);
|
|
17529
|
+
}
|
|
17530
|
+
return transitions;
|
|
17531
|
+
}
|
|
17532
|
+
function formatRouteTransitions(rootStateNode) {
|
|
17533
|
+
const routeTransitions = [];
|
|
17534
|
+
const collectRoutes = (states) => {
|
|
17535
|
+
Object.values(states).forEach((sn) => {
|
|
17536
|
+
if (sn.config.route && sn.config.id) {
|
|
17537
|
+
const routeId = sn.config.id;
|
|
17538
|
+
const userGuard = sn.config.route.guard;
|
|
17539
|
+
const routeGuard = (args, params) => {
|
|
17540
|
+
if (args.event.to !== `#${routeId}`) {
|
|
17541
|
+
return false;
|
|
17542
|
+
}
|
|
17543
|
+
if (!userGuard) {
|
|
17544
|
+
return true;
|
|
17545
|
+
}
|
|
17546
|
+
if (typeof userGuard === "function") {
|
|
17547
|
+
return userGuard(args, params);
|
|
17548
|
+
}
|
|
17549
|
+
return true;
|
|
17550
|
+
};
|
|
17551
|
+
const transition = {
|
|
17552
|
+
...sn.config.route,
|
|
17553
|
+
guard: routeGuard,
|
|
17554
|
+
target: `#${routeId}`
|
|
17555
|
+
};
|
|
17556
|
+
routeTransitions.push(formatTransition(rootStateNode, "xstate.route", transition));
|
|
17557
|
+
}
|
|
17558
|
+
if (sn.states) {
|
|
17559
|
+
collectRoutes(sn.states);
|
|
17560
|
+
}
|
|
17561
|
+
});
|
|
17562
|
+
};
|
|
17563
|
+
collectRoutes(rootStateNode.states);
|
|
17564
|
+
if (routeTransitions.length > 0) {
|
|
17565
|
+
rootStateNode.transitions.set("xstate.route", routeTransitions);
|
|
17566
|
+
}
|
|
17567
|
+
}
|
|
17568
|
+
function formatInitialTransition(stateNode, _target) {
|
|
17569
|
+
const resolvedTarget = typeof _target === "string" ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : void 0;
|
|
17570
|
+
if (!resolvedTarget && _target) {
|
|
17571
|
+
throw new Error(
|
|
17572
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
|
|
17573
|
+
`Initial state node "${_target}" not found on parent state node #${stateNode.id}`
|
|
17574
|
+
);
|
|
17575
|
+
}
|
|
17576
|
+
const transition = {
|
|
17577
|
+
source: stateNode,
|
|
17578
|
+
actions: !_target || typeof _target === "string" ? [] : toArray(_target.actions),
|
|
17579
|
+
eventType: null,
|
|
17580
|
+
reenter: false,
|
|
17581
|
+
target: resolvedTarget ? [resolvedTarget] : [],
|
|
17582
|
+
toJSON: () => ({
|
|
17583
|
+
...transition,
|
|
17584
|
+
source: `#${stateNode.id}`,
|
|
17585
|
+
target: resolvedTarget ? [`#${resolvedTarget.id}`] : []
|
|
17586
|
+
})
|
|
17587
|
+
};
|
|
17588
|
+
return transition;
|
|
17589
|
+
}
|
|
17590
|
+
function resolveTarget(stateNode, targets) {
|
|
17591
|
+
if (targets === void 0) {
|
|
17592
|
+
return void 0;
|
|
17593
|
+
}
|
|
17594
|
+
return targets.map((target) => {
|
|
17595
|
+
if (typeof target !== "string") {
|
|
17596
|
+
return target;
|
|
17597
|
+
}
|
|
17598
|
+
if (isStateId(target)) {
|
|
17599
|
+
return stateNode.machine.getStateNodeById(target);
|
|
17600
|
+
}
|
|
17601
|
+
const isInternalTarget = target[0] === STATE_DELIMITER;
|
|
17602
|
+
if (isInternalTarget && !stateNode.parent) {
|
|
17603
|
+
return getStateNodeByPath(stateNode, target.slice(1));
|
|
17604
|
+
}
|
|
17605
|
+
const resolvedTarget = isInternalTarget ? stateNode.key + target : target;
|
|
17606
|
+
if (stateNode.parent) {
|
|
17607
|
+
try {
|
|
17608
|
+
const targetStateNode = getStateNodeByPath(stateNode.parent, resolvedTarget);
|
|
17609
|
+
return targetStateNode;
|
|
17610
|
+
} catch (err2) {
|
|
17611
|
+
throw new Error(`Invalid transition definition for state node '${stateNode.id}':
|
|
17612
|
+
${err2.message}`);
|
|
17613
|
+
}
|
|
17614
|
+
} else {
|
|
17615
|
+
throw new Error(`Invalid target: "${target}" is not a valid target from the root node. Did you mean ".${target}"?`);
|
|
17616
|
+
}
|
|
17617
|
+
});
|
|
17618
|
+
}
|
|
17619
|
+
function resolveHistoryDefaultTransition(stateNode) {
|
|
17620
|
+
const normalizedTarget = normalizeTarget(stateNode.config.target);
|
|
17621
|
+
if (!normalizedTarget) {
|
|
17622
|
+
return stateNode.parent.initial;
|
|
17623
|
+
}
|
|
17624
|
+
return {
|
|
17625
|
+
target: normalizedTarget.map((t) => typeof t === "string" ? getStateNodeByPath(stateNode.parent, t) : t)
|
|
17626
|
+
};
|
|
17627
|
+
}
|
|
17628
|
+
function isHistoryNode(stateNode) {
|
|
17629
|
+
return stateNode.type === "history";
|
|
17630
|
+
}
|
|
17631
|
+
function getInitialStateNodesWithTheirAncestors(stateNode) {
|
|
17632
|
+
const states = getInitialStateNodes(stateNode);
|
|
17633
|
+
for (const initialState of states) {
|
|
17634
|
+
for (const ancestor of getProperAncestors(initialState, stateNode)) {
|
|
17635
|
+
states.add(ancestor);
|
|
17636
|
+
}
|
|
17637
|
+
}
|
|
17638
|
+
return states;
|
|
17639
|
+
}
|
|
17640
|
+
function getInitialStateNodes(stateNode) {
|
|
17641
|
+
const set = /* @__PURE__ */ new Set();
|
|
17642
|
+
function iter(descStateNode) {
|
|
17643
|
+
if (set.has(descStateNode)) {
|
|
17644
|
+
return;
|
|
17645
|
+
}
|
|
17646
|
+
set.add(descStateNode);
|
|
17647
|
+
if (descStateNode.type === "compound") {
|
|
17648
|
+
iter(descStateNode.initial.target[0]);
|
|
17649
|
+
} else if (descStateNode.type === "parallel") {
|
|
17650
|
+
for (const child2 of getChildren(descStateNode)) {
|
|
17651
|
+
iter(child2);
|
|
17652
|
+
}
|
|
17653
|
+
}
|
|
17654
|
+
}
|
|
17655
|
+
iter(stateNode);
|
|
17656
|
+
return set;
|
|
17657
|
+
}
|
|
17658
|
+
function getStateNode(stateNode, stateKey) {
|
|
17659
|
+
if (isStateId(stateKey)) {
|
|
17660
|
+
return stateNode.machine.getStateNodeById(stateKey);
|
|
17661
|
+
}
|
|
17662
|
+
if (!stateNode.states) {
|
|
17663
|
+
throw new Error(`Unable to retrieve child state '${stateKey}' from '${stateNode.id}'; no child states exist.`);
|
|
17664
|
+
}
|
|
17665
|
+
const result = stateNode.states[stateKey];
|
|
17666
|
+
if (!result) {
|
|
17667
|
+
throw new Error(`Child state '${stateKey}' does not exist on '${stateNode.id}'`);
|
|
17668
|
+
}
|
|
17669
|
+
return result;
|
|
17670
|
+
}
|
|
17671
|
+
function getStateNodeByPath(stateNode, statePath) {
|
|
17672
|
+
if (typeof statePath === "string" && isStateId(statePath)) {
|
|
17673
|
+
try {
|
|
17674
|
+
return stateNode.machine.getStateNodeById(statePath);
|
|
17675
|
+
} catch {
|
|
17676
|
+
}
|
|
17677
|
+
}
|
|
17678
|
+
const arrayStatePath = toStatePath(statePath).slice();
|
|
17679
|
+
let currentStateNode = stateNode;
|
|
17680
|
+
while (arrayStatePath.length) {
|
|
17681
|
+
const key = arrayStatePath.shift();
|
|
17682
|
+
if (!key.length) {
|
|
17683
|
+
break;
|
|
17684
|
+
}
|
|
17685
|
+
currentStateNode = getStateNode(currentStateNode, key);
|
|
17686
|
+
}
|
|
17687
|
+
return currentStateNode;
|
|
17688
|
+
}
|
|
17689
|
+
function getStateNodes(stateNode, stateValue) {
|
|
17690
|
+
if (typeof stateValue === "string") {
|
|
17691
|
+
const childStateNode = stateNode.states[stateValue];
|
|
17692
|
+
if (!childStateNode) {
|
|
17693
|
+
throw new Error(`State '${stateValue}' does not exist on '${stateNode.id}'`);
|
|
17694
|
+
}
|
|
17695
|
+
return [stateNode, childStateNode];
|
|
17696
|
+
}
|
|
17697
|
+
const childStateKeys = Object.keys(stateValue);
|
|
17698
|
+
const childStateNodes = childStateKeys.map((subStateKey) => getStateNode(stateNode, subStateKey)).filter(Boolean);
|
|
17699
|
+
return [stateNode.machine.root, stateNode].concat(childStateNodes, childStateKeys.reduce((allSubStateNodes, subStateKey) => {
|
|
17700
|
+
const subStateNode = getStateNode(stateNode, subStateKey);
|
|
17701
|
+
if (!subStateNode) {
|
|
17702
|
+
return allSubStateNodes;
|
|
17703
|
+
}
|
|
17704
|
+
const subStateNodes = getStateNodes(subStateNode, stateValue[subStateKey]);
|
|
17705
|
+
return allSubStateNodes.concat(subStateNodes);
|
|
17706
|
+
}, []));
|
|
17707
|
+
}
|
|
17708
|
+
function transitionAtomicNode(stateNode, stateValue, snapshot, event) {
|
|
17709
|
+
const childStateNode = getStateNode(stateNode, stateValue);
|
|
17710
|
+
const next = childStateNode.next(snapshot, event);
|
|
17711
|
+
if (!next || !next.length) {
|
|
17712
|
+
return stateNode.next(snapshot, event);
|
|
17713
|
+
}
|
|
17714
|
+
return next;
|
|
17715
|
+
}
|
|
17716
|
+
function transitionCompoundNode(stateNode, stateValue, snapshot, event) {
|
|
17717
|
+
const subStateKeys = Object.keys(stateValue);
|
|
17718
|
+
const childStateNode = getStateNode(stateNode, subStateKeys[0]);
|
|
17719
|
+
const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], snapshot, event);
|
|
17720
|
+
if (!next || !next.length) {
|
|
17721
|
+
return stateNode.next(snapshot, event);
|
|
17722
|
+
}
|
|
17723
|
+
return next;
|
|
17724
|
+
}
|
|
17725
|
+
function transitionParallelNode(stateNode, stateValue, snapshot, event) {
|
|
17726
|
+
const allInnerTransitions = [];
|
|
17727
|
+
for (const subStateKey of Object.keys(stateValue)) {
|
|
17728
|
+
const subStateValue = stateValue[subStateKey];
|
|
17729
|
+
if (!subStateValue) {
|
|
17730
|
+
continue;
|
|
17731
|
+
}
|
|
17732
|
+
const subStateNode = getStateNode(stateNode, subStateKey);
|
|
17733
|
+
const innerTransitions = transitionNode(subStateNode, subStateValue, snapshot, event);
|
|
17734
|
+
if (innerTransitions) {
|
|
17735
|
+
allInnerTransitions.push(...innerTransitions);
|
|
17736
|
+
}
|
|
17737
|
+
}
|
|
17738
|
+
if (!allInnerTransitions.length) {
|
|
17739
|
+
return stateNode.next(snapshot, event);
|
|
17740
|
+
}
|
|
17741
|
+
return allInnerTransitions;
|
|
17742
|
+
}
|
|
17743
|
+
function transitionNode(stateNode, stateValue, snapshot, event) {
|
|
17744
|
+
if (typeof stateValue === "string") {
|
|
17745
|
+
return transitionAtomicNode(stateNode, stateValue, snapshot, event);
|
|
17746
|
+
}
|
|
17747
|
+
if (Object.keys(stateValue).length === 1) {
|
|
17748
|
+
return transitionCompoundNode(stateNode, stateValue, snapshot, event);
|
|
17749
|
+
}
|
|
17750
|
+
return transitionParallelNode(stateNode, stateValue, snapshot, event);
|
|
17751
|
+
}
|
|
17752
|
+
function getHistoryNodes(stateNode) {
|
|
17753
|
+
return Object.keys(stateNode.states).map((key) => stateNode.states[key]).filter((sn) => sn.type === "history");
|
|
17754
|
+
}
|
|
17755
|
+
function isDescendant(childStateNode, parentStateNode) {
|
|
17756
|
+
let marker = childStateNode;
|
|
17757
|
+
while (marker.parent && marker.parent !== parentStateNode) {
|
|
17758
|
+
marker = marker.parent;
|
|
17759
|
+
}
|
|
17760
|
+
return marker.parent === parentStateNode;
|
|
17761
|
+
}
|
|
17762
|
+
function hasIntersection(s1, s2) {
|
|
17763
|
+
const set1 = new Set(s1);
|
|
17764
|
+
const set2 = new Set(s2);
|
|
17765
|
+
for (const item of set1) {
|
|
17766
|
+
if (set2.has(item)) {
|
|
17767
|
+
return true;
|
|
17768
|
+
}
|
|
17769
|
+
}
|
|
17770
|
+
for (const item of set2) {
|
|
17771
|
+
if (set1.has(item)) {
|
|
17772
|
+
return true;
|
|
17773
|
+
}
|
|
17774
|
+
}
|
|
17775
|
+
return false;
|
|
17776
|
+
}
|
|
17777
|
+
function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
|
|
17778
|
+
const filteredTransitions = /* @__PURE__ */ new Set();
|
|
17779
|
+
for (const t1 of enabledTransitions) {
|
|
17780
|
+
let t1Preempted = false;
|
|
17781
|
+
const transitionsToRemove = /* @__PURE__ */ new Set();
|
|
17782
|
+
for (const t2 of filteredTransitions) {
|
|
17783
|
+
if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
|
|
17784
|
+
if (isDescendant(t1.source, t2.source)) {
|
|
17785
|
+
transitionsToRemove.add(t2);
|
|
17786
|
+
} else {
|
|
17787
|
+
t1Preempted = true;
|
|
17788
|
+
break;
|
|
17789
|
+
}
|
|
17790
|
+
}
|
|
17791
|
+
}
|
|
17792
|
+
if (!t1Preempted) {
|
|
17793
|
+
for (const t3 of transitionsToRemove) {
|
|
17794
|
+
filteredTransitions.delete(t3);
|
|
17795
|
+
}
|
|
17796
|
+
filteredTransitions.add(t1);
|
|
17797
|
+
}
|
|
17798
|
+
}
|
|
17799
|
+
return Array.from(filteredTransitions);
|
|
17800
|
+
}
|
|
17801
|
+
function findLeastCommonAncestor(stateNodes) {
|
|
17802
|
+
const [head, ...tail] = stateNodes;
|
|
17803
|
+
for (const ancestor of getProperAncestors(head, void 0)) {
|
|
17804
|
+
if (tail.every((sn) => isDescendant(sn, ancestor))) {
|
|
17805
|
+
return ancestor;
|
|
17806
|
+
}
|
|
17807
|
+
}
|
|
17808
|
+
}
|
|
17809
|
+
function getEffectiveTargetStates(transition, historyValue) {
|
|
17810
|
+
if (!transition.target) {
|
|
17811
|
+
return [];
|
|
17812
|
+
}
|
|
17813
|
+
const targets = /* @__PURE__ */ new Set();
|
|
17814
|
+
for (const targetNode of transition.target) {
|
|
17815
|
+
if (isHistoryNode(targetNode)) {
|
|
17816
|
+
if (historyValue[targetNode.id]) {
|
|
17817
|
+
for (const node of historyValue[targetNode.id]) {
|
|
17818
|
+
targets.add(node);
|
|
17819
|
+
}
|
|
17820
|
+
} else {
|
|
17821
|
+
for (const node of getEffectiveTargetStates(resolveHistoryDefaultTransition(targetNode), historyValue)) {
|
|
17822
|
+
targets.add(node);
|
|
17823
|
+
}
|
|
17824
|
+
}
|
|
17825
|
+
} else {
|
|
17826
|
+
targets.add(targetNode);
|
|
17827
|
+
}
|
|
17828
|
+
}
|
|
17829
|
+
return [...targets];
|
|
17830
|
+
}
|
|
17831
|
+
function getTransitionDomain(transition, historyValue) {
|
|
17832
|
+
const targetStates = getEffectiveTargetStates(transition, historyValue);
|
|
17833
|
+
if (!targetStates) {
|
|
17834
|
+
return;
|
|
17835
|
+
}
|
|
17836
|
+
if (!transition.reenter && targetStates.every((target) => target === transition.source || isDescendant(target, transition.source))) {
|
|
17837
|
+
return transition.source;
|
|
17838
|
+
}
|
|
17839
|
+
const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
|
|
17840
|
+
if (lca) {
|
|
17841
|
+
return lca;
|
|
17842
|
+
}
|
|
17843
|
+
if (transition.reenter) {
|
|
17844
|
+
return;
|
|
17845
|
+
}
|
|
17846
|
+
return transition.source.machine.root;
|
|
17847
|
+
}
|
|
17848
|
+
function computeExitSet(transitions, stateNodeSet, historyValue) {
|
|
17849
|
+
const statesToExit = /* @__PURE__ */ new Set();
|
|
17850
|
+
for (const t of transitions) {
|
|
17851
|
+
if (t.target?.length) {
|
|
17852
|
+
const domain = getTransitionDomain(t, historyValue);
|
|
17853
|
+
if (t.reenter && t.source === domain) {
|
|
17854
|
+
statesToExit.add(domain);
|
|
17855
|
+
}
|
|
17856
|
+
for (const stateNode of stateNodeSet) {
|
|
17857
|
+
if (isDescendant(stateNode, domain)) {
|
|
17858
|
+
statesToExit.add(stateNode);
|
|
17859
|
+
}
|
|
17860
|
+
}
|
|
17861
|
+
}
|
|
17862
|
+
}
|
|
17863
|
+
return [...statesToExit];
|
|
17864
|
+
}
|
|
17865
|
+
function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
17866
|
+
if (prevStateNodes.length !== nextStateNodeSet.size) {
|
|
17867
|
+
return false;
|
|
17868
|
+
}
|
|
17869
|
+
for (const node of prevStateNodes) {
|
|
17870
|
+
if (!nextStateNodeSet.has(node)) {
|
|
17871
|
+
return false;
|
|
17872
|
+
}
|
|
17873
|
+
}
|
|
17874
|
+
return true;
|
|
17875
|
+
}
|
|
17876
|
+
function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
|
|
17877
|
+
return microstep([{
|
|
17878
|
+
target: [...getInitialStateNodes(root)],
|
|
17879
|
+
source: root,
|
|
17880
|
+
reenter: true,
|
|
17881
|
+
actions: [],
|
|
17882
|
+
eventType: null,
|
|
17883
|
+
toJSON: null
|
|
17884
|
+
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
17885
|
+
}
|
|
17886
|
+
function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
|
|
17887
|
+
const actions = [];
|
|
17888
|
+
if (!transitions.length) {
|
|
17889
|
+
return [currentSnapshot, actions];
|
|
17890
|
+
}
|
|
17891
|
+
const originalExecutor = actorScope.actionExecutor;
|
|
17892
|
+
actorScope.actionExecutor = (action) => {
|
|
17893
|
+
actions.push(action);
|
|
17894
|
+
originalExecutor(action);
|
|
17895
|
+
};
|
|
17896
|
+
try {
|
|
17897
|
+
const mutStateNodeSet = new Set(currentSnapshot._nodes);
|
|
17898
|
+
let historyValue = currentSnapshot.historyValue;
|
|
17899
|
+
const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
|
|
17900
|
+
let nextState = currentSnapshot;
|
|
17901
|
+
if (!isInitial) {
|
|
17902
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
|
|
17903
|
+
}
|
|
17904
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap((t) => t.actions), internalQueue, void 0);
|
|
17905
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
17906
|
+
const nextStateNodes = [...mutStateNodeSet];
|
|
17907
|
+
if (nextState.status === "done") {
|
|
17908
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap((state) => state.exit), internalQueue, void 0);
|
|
17909
|
+
}
|
|
17910
|
+
try {
|
|
17911
|
+
if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
|
|
17912
|
+
return [nextState, actions];
|
|
17913
|
+
}
|
|
17914
|
+
return [cloneMachineSnapshot(nextState, {
|
|
17915
|
+
_nodes: nextStateNodes,
|
|
17916
|
+
historyValue
|
|
17917
|
+
}), actions];
|
|
17918
|
+
} catch (e) {
|
|
17919
|
+
throw e;
|
|
17920
|
+
}
|
|
17921
|
+
} finally {
|
|
17922
|
+
actorScope.actionExecutor = originalExecutor;
|
|
17923
|
+
}
|
|
17924
|
+
}
|
|
17925
|
+
function getMachineOutput(snapshot, event, actorScope, rootNode, rootCompletionNode) {
|
|
17926
|
+
if (rootNode.output === void 0) {
|
|
17927
|
+
return;
|
|
17928
|
+
}
|
|
17929
|
+
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output !== void 0 && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, snapshot.context, event, actorScope.self) : void 0);
|
|
17930
|
+
return resolveOutput(rootNode.output, snapshot.context, doneStateEvent, actorScope.self);
|
|
17931
|
+
}
|
|
17932
|
+
function enterStates(currentSnapshot, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
|
|
17933
|
+
let nextSnapshot = currentSnapshot;
|
|
17934
|
+
const statesToEnter = /* @__PURE__ */ new Set();
|
|
17935
|
+
const statesForDefaultEntry = /* @__PURE__ */ new Set();
|
|
17936
|
+
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
17937
|
+
if (isInitial) {
|
|
17938
|
+
statesForDefaultEntry.add(currentSnapshot.machine.root);
|
|
17939
|
+
}
|
|
17940
|
+
const completedNodes = /* @__PURE__ */ new Set();
|
|
17941
|
+
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
17942
|
+
mutStateNodeSet.add(stateNodeToEnter);
|
|
17943
|
+
const actions = [];
|
|
17944
|
+
actions.push(...stateNodeToEnter.entry);
|
|
17945
|
+
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
17946
|
+
actions.push(spawnChild(invokeDef.src, {
|
|
17947
|
+
...invokeDef,
|
|
17948
|
+
syncSnapshot: !!invokeDef.onSnapshot
|
|
17949
|
+
}));
|
|
17950
|
+
}
|
|
17951
|
+
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
17952
|
+
const initialActions = stateNodeToEnter.initial.actions;
|
|
17953
|
+
actions.push(...initialActions);
|
|
17954
|
+
}
|
|
17955
|
+
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map((invokeDef) => invokeDef.id));
|
|
17956
|
+
if (stateNodeToEnter.type === "final") {
|
|
17957
|
+
const parent = stateNodeToEnter.parent;
|
|
17958
|
+
let ancestorMarker = parent?.type === "parallel" ? parent : parent?.parent;
|
|
17959
|
+
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
17960
|
+
if (parent?.type === "compound") {
|
|
17961
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output !== void 0 ? resolveOutput(stateNodeToEnter.output, nextSnapshot.context, event, actorScope.self) : void 0));
|
|
17962
|
+
}
|
|
17963
|
+
while (ancestorMarker?.type === "parallel" && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
17964
|
+
completedNodes.add(ancestorMarker);
|
|
17965
|
+
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
17966
|
+
rootCompletionNode = ancestorMarker;
|
|
17967
|
+
ancestorMarker = ancestorMarker.parent;
|
|
17968
|
+
}
|
|
17969
|
+
if (ancestorMarker) {
|
|
17970
|
+
continue;
|
|
17971
|
+
}
|
|
17972
|
+
nextSnapshot = cloneMachineSnapshot(nextSnapshot, {
|
|
17973
|
+
status: "done",
|
|
17974
|
+
output: getMachineOutput(nextSnapshot, event, actorScope, nextSnapshot.machine.root, rootCompletionNode)
|
|
17975
|
+
});
|
|
17976
|
+
}
|
|
17977
|
+
}
|
|
17978
|
+
return nextSnapshot;
|
|
17979
|
+
}
|
|
17980
|
+
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
17981
|
+
for (const t of transitions) {
|
|
17982
|
+
const domain = getTransitionDomain(t, historyValue);
|
|
17983
|
+
for (const s of t.target || []) {
|
|
17984
|
+
if (!isHistoryNode(s) && // if the target is different than the source then it will *definitely* be entered
|
|
17985
|
+
(t.source !== s || // we know that the domain can't lie within the source
|
|
17986
|
+
// if it's different than the source then it's outside of it and it means that the target has to be entered as well
|
|
17987
|
+
t.source !== domain || // reentering transitions always enter the target, even if it's the source itself
|
|
17988
|
+
t.reenter)) {
|
|
17989
|
+
statesToEnter.add(s);
|
|
17990
|
+
statesForDefaultEntry.add(s);
|
|
17991
|
+
}
|
|
17992
|
+
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
17993
|
+
}
|
|
17994
|
+
const targetStates = getEffectiveTargetStates(t, historyValue);
|
|
17995
|
+
for (const s of targetStates) {
|
|
17996
|
+
const ancestors = getProperAncestors(s, domain);
|
|
17997
|
+
if (domain?.type === "parallel") {
|
|
17998
|
+
ancestors.push(domain);
|
|
17999
|
+
}
|
|
18000
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? void 0 : domain);
|
|
18001
|
+
}
|
|
18002
|
+
}
|
|
18003
|
+
}
|
|
18004
|
+
function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
18005
|
+
if (isHistoryNode(stateNode)) {
|
|
18006
|
+
if (historyValue[stateNode.id]) {
|
|
18007
|
+
const historyStateNodes = historyValue[stateNode.id];
|
|
18008
|
+
for (const s of historyStateNodes) {
|
|
18009
|
+
statesToEnter.add(s);
|
|
18010
|
+
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
18011
|
+
}
|
|
18012
|
+
for (const s of historyStateNodes) {
|
|
18013
|
+
addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
|
|
18014
|
+
}
|
|
18015
|
+
} else {
|
|
18016
|
+
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
18017
|
+
for (const s of historyDefaultTransition.target) {
|
|
18018
|
+
statesToEnter.add(s);
|
|
18019
|
+
if (historyDefaultTransition === stateNode.parent?.initial) {
|
|
18020
|
+
statesForDefaultEntry.add(stateNode.parent);
|
|
18021
|
+
}
|
|
18022
|
+
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
18023
|
+
}
|
|
18024
|
+
for (const s of historyDefaultTransition.target) {
|
|
18025
|
+
addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
|
|
18026
|
+
}
|
|
18027
|
+
}
|
|
18028
|
+
} else {
|
|
18029
|
+
if (stateNode.type === "compound") {
|
|
18030
|
+
const [initialState] = stateNode.initial.target;
|
|
18031
|
+
if (!isHistoryNode(initialState)) {
|
|
18032
|
+
statesToEnter.add(initialState);
|
|
18033
|
+
statesForDefaultEntry.add(initialState);
|
|
18034
|
+
}
|
|
18035
|
+
addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
|
|
18036
|
+
addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
18037
|
+
} else {
|
|
18038
|
+
if (stateNode.type === "parallel") {
|
|
18039
|
+
for (const child2 of getChildren(stateNode).filter((sn) => !isHistoryNode(sn))) {
|
|
18040
|
+
if (![...statesToEnter].some((s) => isDescendant(s, child2))) {
|
|
18041
|
+
if (!isHistoryNode(child2)) {
|
|
18042
|
+
statesToEnter.add(child2);
|
|
18043
|
+
statesForDefaultEntry.add(child2);
|
|
18044
|
+
}
|
|
18045
|
+
addDescendantStatesToEnter(child2, historyValue, statesForDefaultEntry, statesToEnter);
|
|
18046
|
+
}
|
|
18047
|
+
}
|
|
18048
|
+
}
|
|
18049
|
+
}
|
|
18050
|
+
}
|
|
18051
|
+
}
|
|
18052
|
+
function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
|
|
18053
|
+
for (const anc of ancestors) {
|
|
18054
|
+
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
18055
|
+
statesToEnter.add(anc);
|
|
18056
|
+
}
|
|
18057
|
+
if (anc.type === "parallel") {
|
|
18058
|
+
for (const child2 of getChildren(anc).filter((sn) => !isHistoryNode(sn))) {
|
|
18059
|
+
if (![...statesToEnter].some((s) => isDescendant(s, child2))) {
|
|
18060
|
+
statesToEnter.add(child2);
|
|
18061
|
+
addDescendantStatesToEnter(child2, historyValue, statesForDefaultEntry, statesToEnter);
|
|
18062
|
+
}
|
|
18063
|
+
}
|
|
18064
|
+
}
|
|
18065
|
+
}
|
|
18066
|
+
}
|
|
18067
|
+
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
18068
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
18069
|
+
}
|
|
18070
|
+
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
|
|
18071
|
+
let nextSnapshot = currentSnapshot;
|
|
18072
|
+
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
18073
|
+
statesToExit.sort((a, b) => b.order - a.order);
|
|
18074
|
+
let changedHistory;
|
|
18075
|
+
for (const exitStateNode of statesToExit) {
|
|
18076
|
+
for (const historyNode of getHistoryNodes(exitStateNode)) {
|
|
18077
|
+
let predicate;
|
|
18078
|
+
if (historyNode.history === "deep") {
|
|
18079
|
+
predicate = (sn) => isAtomicStateNode(sn) && isDescendant(sn, exitStateNode);
|
|
18080
|
+
} else {
|
|
18081
|
+
predicate = (sn) => {
|
|
18082
|
+
return sn.parent === exitStateNode;
|
|
18083
|
+
};
|
|
18084
|
+
}
|
|
18085
|
+
changedHistory ??= {
|
|
18086
|
+
...historyValue
|
|
18087
|
+
};
|
|
18088
|
+
changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
|
|
18089
|
+
}
|
|
18090
|
+
}
|
|
18091
|
+
for (const s of statesToExit) {
|
|
18092
|
+
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map((def) => stopChild(def.id))], internalQueue, void 0);
|
|
18093
|
+
mutStateNodeSet.delete(s);
|
|
18094
|
+
}
|
|
18095
|
+
return [nextSnapshot, changedHistory || historyValue];
|
|
18096
|
+
}
|
|
18097
|
+
function getAction(machine, actionType) {
|
|
18098
|
+
return machine.implementations.actions[actionType];
|
|
18099
|
+
}
|
|
18100
|
+
function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
|
|
18101
|
+
const {
|
|
18102
|
+
machine
|
|
18103
|
+
} = currentSnapshot;
|
|
18104
|
+
let intermediateSnapshot = currentSnapshot;
|
|
18105
|
+
for (const action of actions) {
|
|
18106
|
+
const isInline = typeof action === "function";
|
|
18107
|
+
const resolvedAction = isInline ? action : (
|
|
18108
|
+
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
18109
|
+
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
18110
|
+
// our logic below makes sure that we call those 2 "variants" correctly
|
|
18111
|
+
getAction(machine, typeof action === "string" ? action : action.type)
|
|
18112
|
+
);
|
|
18113
|
+
const actionArgs = {
|
|
18114
|
+
context: intermediateSnapshot.context,
|
|
18115
|
+
event,
|
|
18116
|
+
self: actorScope.self,
|
|
18117
|
+
system: actorScope.system
|
|
18118
|
+
};
|
|
18119
|
+
const actionParams = isInline || typeof action === "string" ? void 0 : "params" in action ? typeof action.params === "function" ? action.params({
|
|
18120
|
+
context: intermediateSnapshot.context,
|
|
18121
|
+
event
|
|
18122
|
+
}) : action.params : void 0;
|
|
18123
|
+
if (!resolvedAction || !("resolve" in resolvedAction)) {
|
|
18124
|
+
actorScope.actionExecutor({
|
|
18125
|
+
type: typeof action === "string" ? action : typeof action === "object" ? action.type : action.name || "(anonymous)",
|
|
18126
|
+
info: actionArgs,
|
|
18127
|
+
params: actionParams,
|
|
18128
|
+
exec: resolvedAction
|
|
18129
|
+
});
|
|
18130
|
+
continue;
|
|
18131
|
+
}
|
|
18132
|
+
const builtinAction = resolvedAction;
|
|
18133
|
+
const [nextState, params, actions2] = builtinAction.resolve(
|
|
18134
|
+
actorScope,
|
|
18135
|
+
intermediateSnapshot,
|
|
18136
|
+
actionArgs,
|
|
18137
|
+
actionParams,
|
|
18138
|
+
resolvedAction,
|
|
18139
|
+
// this holds all params
|
|
18140
|
+
extra
|
|
18141
|
+
);
|
|
18142
|
+
intermediateSnapshot = nextState;
|
|
18143
|
+
if ("retryResolve" in builtinAction) {
|
|
18144
|
+
retries?.push([builtinAction, params]);
|
|
18145
|
+
}
|
|
18146
|
+
if ("execute" in builtinAction) {
|
|
18147
|
+
actorScope.actionExecutor({
|
|
18148
|
+
type: builtinAction.type,
|
|
18149
|
+
info: actionArgs,
|
|
18150
|
+
params,
|
|
18151
|
+
exec: builtinAction.execute.bind(null, actorScope, params)
|
|
18152
|
+
});
|
|
18153
|
+
}
|
|
18154
|
+
if (actions2) {
|
|
18155
|
+
intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions2, extra, retries);
|
|
18156
|
+
}
|
|
18157
|
+
}
|
|
18158
|
+
return intermediateSnapshot;
|
|
18159
|
+
}
|
|
18160
|
+
function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
|
|
18161
|
+
const retries = deferredActorIds ? [] : void 0;
|
|
18162
|
+
const nextState = resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, {
|
|
18163
|
+
internalQueue,
|
|
18164
|
+
deferredActorIds
|
|
18165
|
+
}, retries);
|
|
18166
|
+
retries?.forEach(([builtinAction, params]) => {
|
|
18167
|
+
builtinAction.retryResolve(actorScope, nextState, params);
|
|
18168
|
+
});
|
|
18169
|
+
return nextState;
|
|
18170
|
+
}
|
|
18171
|
+
function macrostep(snapshot, event, actorScope, internalQueue) {
|
|
18172
|
+
let nextSnapshot = snapshot;
|
|
18173
|
+
const microsteps = [];
|
|
18174
|
+
function addMicrostep(step, event2, transitions) {
|
|
18175
|
+
actorScope.system._sendInspectionEvent({
|
|
18176
|
+
type: "@xstate.microstep",
|
|
18177
|
+
actorRef: actorScope.self,
|
|
18178
|
+
event: event2,
|
|
18179
|
+
snapshot: step[0],
|
|
18180
|
+
_transitions: transitions
|
|
18181
|
+
});
|
|
18182
|
+
microsteps.push(step);
|
|
18183
|
+
}
|
|
18184
|
+
if (event.type === XSTATE_STOP) {
|
|
18185
|
+
nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
|
|
18186
|
+
status: "stopped"
|
|
18187
|
+
});
|
|
18188
|
+
addMicrostep([nextSnapshot, []], event, []);
|
|
18189
|
+
return {
|
|
18190
|
+
snapshot: nextSnapshot,
|
|
18191
|
+
microsteps
|
|
18192
|
+
};
|
|
18193
|
+
}
|
|
18194
|
+
let nextEvent = event;
|
|
18195
|
+
if (nextEvent.type !== XSTATE_INIT) {
|
|
18196
|
+
const currentEvent = nextEvent;
|
|
18197
|
+
const isErr = isErrorActorEvent(currentEvent);
|
|
18198
|
+
const transitions = selectTransitions(currentEvent, nextSnapshot);
|
|
18199
|
+
if (isErr && !transitions.length) {
|
|
18200
|
+
nextSnapshot = cloneMachineSnapshot(snapshot, {
|
|
18201
|
+
status: "error",
|
|
18202
|
+
error: currentEvent.error
|
|
18203
|
+
});
|
|
18204
|
+
addMicrostep([nextSnapshot, []], currentEvent, []);
|
|
18205
|
+
return {
|
|
18206
|
+
snapshot: nextSnapshot,
|
|
18207
|
+
microsteps
|
|
18208
|
+
};
|
|
18209
|
+
}
|
|
18210
|
+
const step = microstep(
|
|
18211
|
+
transitions,
|
|
18212
|
+
snapshot,
|
|
18213
|
+
actorScope,
|
|
18214
|
+
nextEvent,
|
|
18215
|
+
false,
|
|
18216
|
+
// isInitial
|
|
18217
|
+
internalQueue
|
|
18218
|
+
);
|
|
18219
|
+
nextSnapshot = step[0];
|
|
18220
|
+
addMicrostep(step, currentEvent, transitions);
|
|
18221
|
+
}
|
|
18222
|
+
let shouldSelectEventlessTransitions = true;
|
|
18223
|
+
while (nextSnapshot.status === "active") {
|
|
18224
|
+
let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextSnapshot, nextEvent) : [];
|
|
18225
|
+
const previousState = enabledTransitions.length ? nextSnapshot : void 0;
|
|
18226
|
+
if (!enabledTransitions.length) {
|
|
18227
|
+
if (!internalQueue.length) {
|
|
18228
|
+
break;
|
|
18229
|
+
}
|
|
18230
|
+
nextEvent = internalQueue.shift();
|
|
18231
|
+
enabledTransitions = selectTransitions(nextEvent, nextSnapshot);
|
|
18232
|
+
}
|
|
18233
|
+
const step = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
|
|
18234
|
+
nextSnapshot = step[0];
|
|
18235
|
+
shouldSelectEventlessTransitions = nextSnapshot !== previousState;
|
|
18236
|
+
addMicrostep(step, nextEvent, enabledTransitions);
|
|
18237
|
+
}
|
|
18238
|
+
if (nextSnapshot.status !== "active") {
|
|
18239
|
+
stopChildren(nextSnapshot, nextEvent, actorScope);
|
|
18240
|
+
}
|
|
18241
|
+
return {
|
|
18242
|
+
snapshot: nextSnapshot,
|
|
18243
|
+
microsteps
|
|
18244
|
+
};
|
|
18245
|
+
}
|
|
18246
|
+
function stopChildren(nextState, event, actorScope) {
|
|
18247
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map((child2) => stopChild(child2)), [], void 0);
|
|
18248
|
+
}
|
|
18249
|
+
function selectTransitions(event, nextState) {
|
|
18250
|
+
return nextState.machine.getTransitionData(nextState, event);
|
|
18251
|
+
}
|
|
18252
|
+
function selectEventlessTransitions(nextState, event) {
|
|
18253
|
+
const enabledTransitionSet = /* @__PURE__ */ new Set();
|
|
18254
|
+
const atomicStates = nextState._nodes.filter(isAtomicStateNode);
|
|
18255
|
+
for (const stateNode of atomicStates) {
|
|
18256
|
+
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, void 0))) {
|
|
18257
|
+
if (!s.always) {
|
|
18258
|
+
continue;
|
|
18259
|
+
}
|
|
18260
|
+
for (const transition of s.always) {
|
|
18261
|
+
if (transition.guard === void 0 || evaluateGuard(transition.guard, nextState.context, event, nextState)) {
|
|
18262
|
+
enabledTransitionSet.add(transition);
|
|
18263
|
+
break loop;
|
|
18264
|
+
}
|
|
18265
|
+
}
|
|
18266
|
+
}
|
|
18267
|
+
}
|
|
18268
|
+
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
|
|
18269
|
+
}
|
|
18270
|
+
function resolveStateValue(rootNode, stateValue) {
|
|
18271
|
+
const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
|
|
18272
|
+
return getStateValue(rootNode, [...allStateNodes]);
|
|
18273
|
+
}
|
|
18274
|
+
function isMachineSnapshot(value) {
|
|
18275
|
+
return !!value && typeof value === "object" && "machine" in value && "value" in value;
|
|
18276
|
+
}
|
|
18277
|
+
function createMachineSnapshot(config, machine) {
|
|
18278
|
+
return {
|
|
18279
|
+
status: config.status,
|
|
18280
|
+
output: config.output,
|
|
18281
|
+
error: config.error,
|
|
18282
|
+
machine,
|
|
18283
|
+
context: config.context,
|
|
18284
|
+
_nodes: config._nodes,
|
|
18285
|
+
value: getStateValue(machine.root, config._nodes),
|
|
18286
|
+
tags: new Set(config._nodes.flatMap((sn) => sn.tags)),
|
|
18287
|
+
children: config.children,
|
|
18288
|
+
historyValue: config.historyValue || {},
|
|
18289
|
+
matches: machineSnapshotMatches,
|
|
18290
|
+
hasTag: machineSnapshotHasTag,
|
|
18291
|
+
can: machineSnapshotCan,
|
|
18292
|
+
getMeta: machineSnapshotGetMeta,
|
|
18293
|
+
toJSON: machineSnapshotToJSON
|
|
18294
|
+
};
|
|
18295
|
+
}
|
|
18296
|
+
function cloneMachineSnapshot(snapshot, config = {}) {
|
|
18297
|
+
return createMachineSnapshot({
|
|
18298
|
+
...snapshot,
|
|
18299
|
+
...config
|
|
18300
|
+
}, snapshot.machine);
|
|
18301
|
+
}
|
|
18302
|
+
function serializeHistoryValue(historyValue) {
|
|
18303
|
+
if (typeof historyValue !== "object" || historyValue === null) {
|
|
18304
|
+
return {};
|
|
18305
|
+
}
|
|
18306
|
+
const result = {};
|
|
18307
|
+
for (const key in historyValue) {
|
|
18308
|
+
const value = historyValue[key];
|
|
18309
|
+
if (Array.isArray(value)) {
|
|
18310
|
+
result[key] = value.map((item) => ({
|
|
18311
|
+
id: item.id
|
|
18312
|
+
}));
|
|
18313
|
+
}
|
|
18314
|
+
}
|
|
18315
|
+
return result;
|
|
18316
|
+
}
|
|
18317
|
+
function getPersistedSnapshot(snapshot, options) {
|
|
18318
|
+
const {
|
|
18319
|
+
_nodes: nodes,
|
|
18320
|
+
tags,
|
|
18321
|
+
machine,
|
|
18322
|
+
children: children2,
|
|
18323
|
+
context,
|
|
18324
|
+
can: can2,
|
|
18325
|
+
hasTag: hasTag2,
|
|
18326
|
+
matches: matches2,
|
|
18327
|
+
getMeta: getMeta3,
|
|
18328
|
+
toJSON: toJSON2,
|
|
18329
|
+
...jsonValues
|
|
18330
|
+
} = snapshot;
|
|
18331
|
+
const childrenJson = {};
|
|
18332
|
+
for (const id in children2) {
|
|
18333
|
+
const child2 = children2[id];
|
|
18334
|
+
childrenJson[id] = {
|
|
18335
|
+
snapshot: child2.getPersistedSnapshot(options),
|
|
18336
|
+
src: child2.src,
|
|
18337
|
+
systemId: child2.systemId,
|
|
18338
|
+
syncSnapshot: child2._syncSnapshot
|
|
18339
|
+
};
|
|
18340
|
+
}
|
|
18341
|
+
const persisted = {
|
|
18342
|
+
...jsonValues,
|
|
18343
|
+
context: persistContext(context),
|
|
18344
|
+
children: childrenJson,
|
|
18345
|
+
historyValue: serializeHistoryValue(jsonValues.historyValue)
|
|
18346
|
+
};
|
|
18347
|
+
return persisted;
|
|
18348
|
+
}
|
|
18349
|
+
function persistContext(contextPart) {
|
|
18350
|
+
let copy;
|
|
18351
|
+
for (const key in contextPart) {
|
|
18352
|
+
const value = contextPart[key];
|
|
18353
|
+
if (value && typeof value === "object") {
|
|
18354
|
+
if ("sessionId" in value && "send" in value && "ref" in value) {
|
|
18355
|
+
copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
|
|
18356
|
+
...contextPart
|
|
18357
|
+
};
|
|
18358
|
+
copy[key] = {
|
|
18359
|
+
xstate$$type: $$ACTOR_TYPE,
|
|
18360
|
+
id: value.id
|
|
18361
|
+
};
|
|
18362
|
+
} else {
|
|
18363
|
+
const result = persistContext(value);
|
|
18364
|
+
if (result !== value) {
|
|
18365
|
+
copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
|
|
18366
|
+
...contextPart
|
|
18367
|
+
};
|
|
18368
|
+
copy[key] = result;
|
|
18369
|
+
}
|
|
18370
|
+
}
|
|
18371
|
+
}
|
|
18372
|
+
}
|
|
18373
|
+
return copy ?? contextPart;
|
|
18374
|
+
}
|
|
18375
|
+
function resolveRaise(_, snapshot, args, actionParams, {
|
|
18376
|
+
event: eventOrExpr,
|
|
18377
|
+
id,
|
|
18378
|
+
delay
|
|
18379
|
+
}, {
|
|
18380
|
+
internalQueue
|
|
18381
|
+
}) {
|
|
18382
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
18383
|
+
if (typeof eventOrExpr === "string") {
|
|
18384
|
+
throw new Error(
|
|
18385
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
18386
|
+
`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`
|
|
18387
|
+
);
|
|
18388
|
+
}
|
|
18389
|
+
const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
18390
|
+
let resolvedDelay;
|
|
18391
|
+
if (typeof delay === "string") {
|
|
18392
|
+
const configDelay = delaysMap && delaysMap[delay];
|
|
18393
|
+
resolvedDelay = typeof configDelay === "function" ? configDelay(args, actionParams) : configDelay;
|
|
18394
|
+
} else {
|
|
18395
|
+
resolvedDelay = typeof delay === "function" ? delay(args, actionParams) : delay;
|
|
18396
|
+
}
|
|
18397
|
+
if (typeof resolvedDelay !== "number") {
|
|
18398
|
+
internalQueue.push(resolvedEvent);
|
|
18399
|
+
}
|
|
18400
|
+
return [snapshot, {
|
|
18401
|
+
event: resolvedEvent,
|
|
18402
|
+
id,
|
|
18403
|
+
delay: resolvedDelay
|
|
18404
|
+
}, void 0];
|
|
18405
|
+
}
|
|
18406
|
+
function executeRaise(actorScope, params) {
|
|
18407
|
+
const {
|
|
18408
|
+
event,
|
|
18409
|
+
delay,
|
|
18410
|
+
id
|
|
18411
|
+
} = params;
|
|
18412
|
+
if (typeof delay === "number") {
|
|
18413
|
+
actorScope.defer(() => {
|
|
18414
|
+
const self2 = actorScope.self;
|
|
18415
|
+
actorScope.system.scheduler.schedule(self2, self2, event, delay, id);
|
|
18416
|
+
});
|
|
18417
|
+
return;
|
|
18418
|
+
}
|
|
18419
|
+
}
|
|
18420
|
+
function raise(eventOrExpr, options) {
|
|
18421
|
+
function raise2(_args, _params) {
|
|
18422
|
+
}
|
|
18423
|
+
raise2.type = "xstate.raise";
|
|
18424
|
+
raise2.event = eventOrExpr;
|
|
18425
|
+
raise2.id = options?.id;
|
|
18426
|
+
raise2.delay = options?.delay;
|
|
18427
|
+
raise2.resolve = resolveRaise;
|
|
18428
|
+
raise2.execute = executeRaise;
|
|
18429
|
+
return raise2;
|
|
18430
|
+
}
|
|
18431
|
+
var Mailbox, STATE_DELIMITER, TARGETLESS_KEY, NULL_EVENT, STATE_IDENTIFIER, WILDCARD, XSTATE_INIT, XSTATE_ERROR, XSTATE_STOP, symbolObservable, idCounter, executingCustomAction, $$ACTOR_TYPE, ProcessingStatus, defaultOptions, Actor, isStateId, machineSnapshotMatches, machineSnapshotHasTag, machineSnapshotCan, machineSnapshotToJSON, machineSnapshotGetMeta;
|
|
18432
|
+
var init_raise_b47daa89_esm = __esm({
|
|
18433
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/raise-b47daa89.esm.js"() {
|
|
18434
|
+
"use strict";
|
|
18435
|
+
init_cjs_shims();
|
|
18436
|
+
init_xstate_dev_esm();
|
|
18437
|
+
Mailbox = class {
|
|
18438
|
+
constructor(_process) {
|
|
18439
|
+
this._process = _process;
|
|
18440
|
+
this._active = false;
|
|
18441
|
+
this._current = null;
|
|
18442
|
+
this._last = null;
|
|
18443
|
+
}
|
|
18444
|
+
start() {
|
|
18445
|
+
this._active = true;
|
|
18446
|
+
this.flush();
|
|
18447
|
+
}
|
|
18448
|
+
clear() {
|
|
18449
|
+
if (this._current) {
|
|
18450
|
+
this._current.next = null;
|
|
18451
|
+
this._last = this._current;
|
|
18452
|
+
}
|
|
18453
|
+
}
|
|
18454
|
+
enqueue(event) {
|
|
18455
|
+
const enqueued = {
|
|
18456
|
+
value: event,
|
|
18457
|
+
next: null
|
|
18458
|
+
};
|
|
18459
|
+
if (this._current) {
|
|
18460
|
+
this._last.next = enqueued;
|
|
18461
|
+
this._last = enqueued;
|
|
18462
|
+
return;
|
|
18463
|
+
}
|
|
18464
|
+
this._current = enqueued;
|
|
18465
|
+
this._last = enqueued;
|
|
18466
|
+
if (this._active) {
|
|
18467
|
+
this.flush();
|
|
18468
|
+
}
|
|
18469
|
+
}
|
|
18470
|
+
flush() {
|
|
18471
|
+
while (this._current) {
|
|
18472
|
+
const consumed = this._current;
|
|
18473
|
+
this._process(consumed.value);
|
|
18474
|
+
this._current = consumed.next;
|
|
18475
|
+
}
|
|
18476
|
+
this._last = null;
|
|
18477
|
+
}
|
|
18478
|
+
};
|
|
18479
|
+
STATE_DELIMITER = ".";
|
|
18480
|
+
TARGETLESS_KEY = "";
|
|
18481
|
+
NULL_EVENT = "";
|
|
18482
|
+
STATE_IDENTIFIER = "#";
|
|
18483
|
+
WILDCARD = "*";
|
|
18484
|
+
XSTATE_INIT = "xstate.init";
|
|
18485
|
+
XSTATE_ERROR = "xstate.error";
|
|
18486
|
+
XSTATE_STOP = "xstate.stop";
|
|
18487
|
+
symbolObservable = (() => typeof Symbol === "function" && Symbol.observable || "@@observable")();
|
|
18488
|
+
idCounter = 0;
|
|
18489
|
+
executingCustomAction = false;
|
|
18490
|
+
$$ACTOR_TYPE = 1;
|
|
18491
|
+
ProcessingStatus = /* @__PURE__ */ (function(ProcessingStatus2) {
|
|
18492
|
+
ProcessingStatus2[ProcessingStatus2["NotStarted"] = 0] = "NotStarted";
|
|
18493
|
+
ProcessingStatus2[ProcessingStatus2["Running"] = 1] = "Running";
|
|
18494
|
+
ProcessingStatus2[ProcessingStatus2["Stopped"] = 2] = "Stopped";
|
|
18495
|
+
return ProcessingStatus2;
|
|
18496
|
+
})({});
|
|
18497
|
+
defaultOptions = {
|
|
18498
|
+
clock: {
|
|
18499
|
+
setTimeout: (fn, ms) => {
|
|
18500
|
+
return setTimeout(fn, ms);
|
|
18501
|
+
},
|
|
18502
|
+
clearTimeout: (id) => {
|
|
18503
|
+
return clearTimeout(id);
|
|
18504
|
+
}
|
|
18505
|
+
},
|
|
18506
|
+
logger: console.log.bind(console),
|
|
18507
|
+
devTools: false
|
|
18508
|
+
};
|
|
18509
|
+
Actor = class {
|
|
18510
|
+
/**
|
|
18511
|
+
* Creates a new actor instance for the given logic with the provided options,
|
|
18512
|
+
* if any.
|
|
18513
|
+
*
|
|
18514
|
+
* @param logic The logic to create an actor from
|
|
18515
|
+
* @param options Actor options
|
|
18516
|
+
*/
|
|
18517
|
+
constructor(logic, options) {
|
|
18518
|
+
this.logic = logic;
|
|
18519
|
+
this._snapshot = void 0;
|
|
18520
|
+
this.clock = void 0;
|
|
18521
|
+
this.options = void 0;
|
|
18522
|
+
this.id = void 0;
|
|
18523
|
+
this.mailbox = new Mailbox(this._process.bind(this));
|
|
18524
|
+
this.observers = /* @__PURE__ */ new Set();
|
|
18525
|
+
this.eventListeners = /* @__PURE__ */ new Map();
|
|
18526
|
+
this.logger = void 0;
|
|
18527
|
+
this._processingStatus = ProcessingStatus.NotStarted;
|
|
18528
|
+
this._parent = void 0;
|
|
18529
|
+
this._syncSnapshot = void 0;
|
|
18530
|
+
this.ref = void 0;
|
|
18531
|
+
this._actorScope = void 0;
|
|
18532
|
+
this.systemId = void 0;
|
|
18533
|
+
this.sessionId = void 0;
|
|
18534
|
+
this.system = void 0;
|
|
18535
|
+
this._doneEvent = void 0;
|
|
18536
|
+
this.src = void 0;
|
|
18537
|
+
this._deferred = [];
|
|
18538
|
+
const resolvedOptions = {
|
|
18539
|
+
...defaultOptions,
|
|
18540
|
+
...options
|
|
18541
|
+
};
|
|
18542
|
+
const {
|
|
18543
|
+
clock,
|
|
18544
|
+
logger,
|
|
18545
|
+
parent,
|
|
18546
|
+
syncSnapshot,
|
|
18547
|
+
id,
|
|
18548
|
+
systemId,
|
|
18549
|
+
inspect
|
|
18550
|
+
} = resolvedOptions;
|
|
18551
|
+
this.system = parent ? parent.system : createSystem(this, {
|
|
18552
|
+
clock,
|
|
18553
|
+
logger
|
|
18554
|
+
});
|
|
18555
|
+
if (inspect && !parent) {
|
|
18556
|
+
this.system.inspect(toObserver(inspect));
|
|
18557
|
+
}
|
|
18558
|
+
this.sessionId = this.system._bookId();
|
|
18559
|
+
this.id = id ?? this.sessionId;
|
|
18560
|
+
this.logger = options?.logger ?? this.system._logger;
|
|
18561
|
+
this.clock = options?.clock ?? this.system._clock;
|
|
18562
|
+
this._parent = parent;
|
|
18563
|
+
this._syncSnapshot = syncSnapshot;
|
|
18564
|
+
this.options = resolvedOptions;
|
|
18565
|
+
this.src = resolvedOptions.src ?? logic;
|
|
18566
|
+
this.ref = this;
|
|
18567
|
+
this._actorScope = {
|
|
18568
|
+
self: this,
|
|
18569
|
+
id: this.id,
|
|
18570
|
+
sessionId: this.sessionId,
|
|
18571
|
+
logger: this.logger,
|
|
18572
|
+
defer: (fn) => {
|
|
18573
|
+
this._deferred.push(fn);
|
|
18574
|
+
},
|
|
18575
|
+
system: this.system,
|
|
18576
|
+
stopChild: (child2) => {
|
|
18577
|
+
if (child2._parent !== this) {
|
|
18578
|
+
throw new Error(`Cannot stop child actor ${child2.id} of ${this.id} because it is not a child`);
|
|
18579
|
+
}
|
|
18580
|
+
child2._stop();
|
|
18581
|
+
},
|
|
18582
|
+
emit: (emittedEvent) => {
|
|
18583
|
+
const listeners = this.eventListeners.get(emittedEvent.type);
|
|
18584
|
+
const wildcardListener = this.eventListeners.get("*");
|
|
18585
|
+
if (!listeners && !wildcardListener) {
|
|
18586
|
+
return;
|
|
18587
|
+
}
|
|
18588
|
+
const allListeners = [...listeners ? listeners.values() : [], ...wildcardListener ? wildcardListener.values() : []];
|
|
18589
|
+
for (const handler of allListeners) {
|
|
18590
|
+
try {
|
|
18591
|
+
handler(emittedEvent);
|
|
18592
|
+
} catch (err2) {
|
|
18593
|
+
reportUnhandledError(err2);
|
|
18594
|
+
}
|
|
18595
|
+
}
|
|
18596
|
+
},
|
|
18597
|
+
actionExecutor: (action) => {
|
|
18598
|
+
const exec = () => {
|
|
18599
|
+
this._actorScope.system._sendInspectionEvent({
|
|
18600
|
+
type: "@xstate.action",
|
|
18601
|
+
actorRef: this,
|
|
18602
|
+
action: {
|
|
18603
|
+
type: action.type,
|
|
18604
|
+
params: action.params
|
|
18605
|
+
}
|
|
18606
|
+
});
|
|
18607
|
+
if (!action.exec) {
|
|
18608
|
+
return;
|
|
18609
|
+
}
|
|
18610
|
+
const saveExecutingCustomAction = executingCustomAction;
|
|
18611
|
+
try {
|
|
18612
|
+
executingCustomAction = true;
|
|
18613
|
+
action.exec(action.info, action.params);
|
|
18614
|
+
} finally {
|
|
18615
|
+
executingCustomAction = saveExecutingCustomAction;
|
|
18616
|
+
}
|
|
18617
|
+
};
|
|
18618
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
18619
|
+
exec();
|
|
18620
|
+
} else {
|
|
18621
|
+
this._deferred.push(exec);
|
|
18622
|
+
}
|
|
18623
|
+
}
|
|
18624
|
+
};
|
|
18625
|
+
this.send = this.send.bind(this);
|
|
18626
|
+
this.system._sendInspectionEvent({
|
|
18627
|
+
type: "@xstate.actor",
|
|
18628
|
+
actorRef: this
|
|
18629
|
+
});
|
|
18630
|
+
if (systemId) {
|
|
18631
|
+
this.systemId = systemId;
|
|
18632
|
+
this.system._set(systemId, this);
|
|
18633
|
+
}
|
|
18634
|
+
this._initState(options?.snapshot ?? options?.state);
|
|
18635
|
+
if (systemId && this._snapshot.status !== "active") {
|
|
18636
|
+
this.system._unregister(this);
|
|
18637
|
+
}
|
|
18638
|
+
}
|
|
18639
|
+
_initState(persistedState) {
|
|
18640
|
+
try {
|
|
18641
|
+
this._snapshot = persistedState ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(persistedState, this._actorScope) : persistedState : this.logic.getInitialSnapshot(this._actorScope, this.options?.input);
|
|
18642
|
+
} catch (err2) {
|
|
18643
|
+
this._snapshot = {
|
|
18644
|
+
status: "error",
|
|
18645
|
+
output: void 0,
|
|
18646
|
+
error: err2
|
|
18647
|
+
};
|
|
18648
|
+
}
|
|
18649
|
+
}
|
|
18650
|
+
update(snapshot, event) {
|
|
18651
|
+
this._snapshot = snapshot;
|
|
18652
|
+
let deferredFn;
|
|
18653
|
+
while (deferredFn = this._deferred.shift()) {
|
|
18654
|
+
try {
|
|
18655
|
+
deferredFn();
|
|
18656
|
+
} catch (err2) {
|
|
18657
|
+
this._deferred.length = 0;
|
|
18658
|
+
this._snapshot = {
|
|
18659
|
+
...snapshot,
|
|
18660
|
+
status: "error",
|
|
18661
|
+
error: err2
|
|
18662
|
+
};
|
|
18663
|
+
}
|
|
18664
|
+
}
|
|
18665
|
+
switch (this._snapshot.status) {
|
|
18666
|
+
case "active":
|
|
18667
|
+
for (const observer of this.observers) {
|
|
18668
|
+
try {
|
|
18669
|
+
observer.next?.(snapshot);
|
|
18670
|
+
} catch (err2) {
|
|
18671
|
+
reportUnhandledError(err2);
|
|
18672
|
+
}
|
|
18673
|
+
}
|
|
18674
|
+
break;
|
|
18675
|
+
case "done":
|
|
18676
|
+
for (const observer of this.observers) {
|
|
18677
|
+
try {
|
|
18678
|
+
observer.next?.(snapshot);
|
|
18679
|
+
} catch (err2) {
|
|
18680
|
+
reportUnhandledError(err2);
|
|
18681
|
+
}
|
|
18682
|
+
}
|
|
18683
|
+
this._stopProcedure();
|
|
18684
|
+
this._complete();
|
|
18685
|
+
this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output);
|
|
18686
|
+
if (this._parent) {
|
|
18687
|
+
this.system._relay(this, this._parent, this._doneEvent);
|
|
18688
|
+
}
|
|
18689
|
+
break;
|
|
18690
|
+
case "error":
|
|
18691
|
+
this._error(this._snapshot.error);
|
|
18692
|
+
break;
|
|
18693
|
+
}
|
|
18694
|
+
this.system._sendInspectionEvent({
|
|
18695
|
+
type: "@xstate.snapshot",
|
|
18696
|
+
actorRef: this,
|
|
18697
|
+
event,
|
|
18698
|
+
snapshot
|
|
18699
|
+
});
|
|
18700
|
+
}
|
|
18701
|
+
/**
|
|
18702
|
+
* Subscribe an observer to an actor’s snapshot values.
|
|
18703
|
+
*
|
|
18704
|
+
* @remarks
|
|
18705
|
+
* The observer will receive the actor’s snapshot value when it is emitted.
|
|
18706
|
+
* The observer can be:
|
|
18707
|
+
*
|
|
18708
|
+
* - A plain function that receives the latest snapshot, or
|
|
18709
|
+
* - An observer object whose `.next(snapshot)` method receives the latest
|
|
18710
|
+
* snapshot
|
|
18711
|
+
*
|
|
18712
|
+
* @example
|
|
18713
|
+
*
|
|
18714
|
+
* ```ts
|
|
18715
|
+
* // Observer as a plain function
|
|
18716
|
+
* const subscription = actor.subscribe((snapshot) => {
|
|
18717
|
+
* console.log(snapshot);
|
|
18718
|
+
* });
|
|
18719
|
+
* ```
|
|
18720
|
+
*
|
|
18721
|
+
* @example
|
|
18722
|
+
*
|
|
18723
|
+
* ```ts
|
|
18724
|
+
* // Observer as an object
|
|
18725
|
+
* const subscription = actor.subscribe({
|
|
18726
|
+
* next(snapshot) {
|
|
18727
|
+
* console.log(snapshot);
|
|
18728
|
+
* },
|
|
18729
|
+
* error(err) {
|
|
18730
|
+
* // ...
|
|
18731
|
+
* },
|
|
18732
|
+
* complete() {
|
|
18733
|
+
* // ...
|
|
18734
|
+
* }
|
|
18735
|
+
* });
|
|
18736
|
+
* ```
|
|
18737
|
+
*
|
|
18738
|
+
* The return value of `actor.subscribe(observer)` is a subscription object
|
|
18739
|
+
* that has an `.unsubscribe()` method. You can call
|
|
18740
|
+
* `subscription.unsubscribe()` to unsubscribe the observer:
|
|
18741
|
+
*
|
|
18742
|
+
* @example
|
|
18743
|
+
*
|
|
18744
|
+
* ```ts
|
|
18745
|
+
* const subscription = actor.subscribe((snapshot) => {
|
|
18746
|
+
* // ...
|
|
18747
|
+
* });
|
|
18748
|
+
*
|
|
18749
|
+
* // Unsubscribe the observer
|
|
18750
|
+
* subscription.unsubscribe();
|
|
18751
|
+
* ```
|
|
18752
|
+
*
|
|
18753
|
+
* When the actor is stopped, all of its observers will automatically be
|
|
18754
|
+
* unsubscribed.
|
|
18755
|
+
*
|
|
18756
|
+
* @param observer - Either a plain function that receives the latest
|
|
18757
|
+
* snapshot, or an observer object whose `.next(snapshot)` method receives
|
|
18758
|
+
* the latest snapshot
|
|
18759
|
+
*/
|
|
18760
|
+
subscribe(nextListenerOrObserver, errorListener, completeListener) {
|
|
18761
|
+
const observer = toObserver(nextListenerOrObserver, errorListener, completeListener);
|
|
18762
|
+
if (this._processingStatus !== ProcessingStatus.Stopped) {
|
|
18763
|
+
this.observers.add(observer);
|
|
18764
|
+
} else {
|
|
18765
|
+
switch (this._snapshot.status) {
|
|
18766
|
+
case "done":
|
|
18767
|
+
try {
|
|
18768
|
+
observer.complete?.();
|
|
18769
|
+
} catch (err2) {
|
|
18770
|
+
reportUnhandledError(err2);
|
|
18771
|
+
}
|
|
18772
|
+
break;
|
|
18773
|
+
case "error": {
|
|
18774
|
+
const err2 = this._snapshot.error;
|
|
18775
|
+
if (!observer.error) {
|
|
18776
|
+
reportUnhandledError(err2);
|
|
18777
|
+
} else {
|
|
18778
|
+
try {
|
|
18779
|
+
observer.error(err2);
|
|
18780
|
+
} catch (err3) {
|
|
18781
|
+
reportUnhandledError(err3);
|
|
18782
|
+
}
|
|
18783
|
+
}
|
|
18784
|
+
break;
|
|
18785
|
+
}
|
|
18786
|
+
}
|
|
18787
|
+
}
|
|
18788
|
+
return {
|
|
18789
|
+
unsubscribe: () => {
|
|
18790
|
+
this.observers.delete(observer);
|
|
18791
|
+
}
|
|
18792
|
+
};
|
|
18793
|
+
}
|
|
18794
|
+
on(type, handler) {
|
|
18795
|
+
let listeners = this.eventListeners.get(type);
|
|
18796
|
+
if (!listeners) {
|
|
18797
|
+
listeners = /* @__PURE__ */ new Set();
|
|
18798
|
+
this.eventListeners.set(type, listeners);
|
|
18799
|
+
}
|
|
18800
|
+
const wrappedHandler = handler.bind(void 0);
|
|
18801
|
+
listeners.add(wrappedHandler);
|
|
18802
|
+
return {
|
|
18803
|
+
unsubscribe: () => {
|
|
18804
|
+
listeners.delete(wrappedHandler);
|
|
18805
|
+
}
|
|
18806
|
+
};
|
|
18807
|
+
}
|
|
18808
|
+
select(selector, equalityFn = Object.is) {
|
|
18809
|
+
return {
|
|
18810
|
+
subscribe: (observerOrFn) => {
|
|
18811
|
+
const observer = toObserver(observerOrFn);
|
|
18812
|
+
const snapshot = this.getSnapshot();
|
|
18813
|
+
let previousSelected = selector(snapshot);
|
|
18814
|
+
return this.subscribe((snapshot2) => {
|
|
18815
|
+
const nextSelected = selector(snapshot2);
|
|
18816
|
+
if (!equalityFn(previousSelected, nextSelected)) {
|
|
18817
|
+
previousSelected = nextSelected;
|
|
18818
|
+
observer.next?.(nextSelected);
|
|
18819
|
+
}
|
|
18820
|
+
});
|
|
18821
|
+
},
|
|
18822
|
+
get: () => selector(this.getSnapshot())
|
|
18823
|
+
};
|
|
18824
|
+
}
|
|
18825
|
+
/** Starts the Actor from the initial state */
|
|
18826
|
+
start() {
|
|
18827
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
18828
|
+
return this;
|
|
18829
|
+
}
|
|
18830
|
+
if (this._syncSnapshot) {
|
|
18831
|
+
this.subscribe({
|
|
18832
|
+
next: (snapshot) => {
|
|
18833
|
+
if (snapshot.status === "active") {
|
|
18834
|
+
this.system._relay(this, this._parent, {
|
|
18835
|
+
type: `xstate.snapshot.${this.id}`,
|
|
18836
|
+
snapshot
|
|
18837
|
+
});
|
|
18838
|
+
}
|
|
18839
|
+
},
|
|
18840
|
+
error: () => {
|
|
18841
|
+
}
|
|
18842
|
+
});
|
|
18843
|
+
}
|
|
18844
|
+
this.system._register(this.sessionId, this);
|
|
18845
|
+
if (this.systemId) {
|
|
18846
|
+
this.system._set(this.systemId, this);
|
|
18847
|
+
}
|
|
18848
|
+
this._processingStatus = ProcessingStatus.Running;
|
|
18849
|
+
const initEvent = createInitEvent(this.options.input);
|
|
18850
|
+
this.system._sendInspectionEvent({
|
|
18851
|
+
type: "@xstate.event",
|
|
18852
|
+
sourceRef: this._parent,
|
|
18853
|
+
actorRef: this,
|
|
18854
|
+
event: initEvent
|
|
18855
|
+
});
|
|
18856
|
+
const status = this._snapshot.status;
|
|
18857
|
+
switch (status) {
|
|
18858
|
+
case "done":
|
|
18859
|
+
this.update(this._snapshot, initEvent);
|
|
18860
|
+
return this;
|
|
18861
|
+
case "error":
|
|
18862
|
+
this._error(this._snapshot.error);
|
|
18863
|
+
return this;
|
|
18864
|
+
}
|
|
18865
|
+
if (!this._parent) {
|
|
18866
|
+
this.system.start();
|
|
18867
|
+
}
|
|
18868
|
+
if (this.logic.start) {
|
|
18869
|
+
try {
|
|
18870
|
+
this.logic.start(this._snapshot, this._actorScope);
|
|
18871
|
+
} catch (err2) {
|
|
18872
|
+
this._snapshot = {
|
|
18873
|
+
...this._snapshot,
|
|
18874
|
+
status: "error",
|
|
18875
|
+
error: err2
|
|
18876
|
+
};
|
|
18877
|
+
this._error(err2);
|
|
18878
|
+
return this;
|
|
18879
|
+
}
|
|
18880
|
+
}
|
|
18881
|
+
this.update(this._snapshot, initEvent);
|
|
18882
|
+
if (this.options.devTools) {
|
|
18883
|
+
this.attachDevTools();
|
|
18884
|
+
}
|
|
18885
|
+
this.mailbox.start();
|
|
18886
|
+
return this;
|
|
18887
|
+
}
|
|
18888
|
+
_process(event) {
|
|
18889
|
+
let nextState;
|
|
18890
|
+
let caughtError;
|
|
18891
|
+
try {
|
|
18892
|
+
nextState = this.logic.transition(this._snapshot, event, this._actorScope);
|
|
18893
|
+
} catch (err2) {
|
|
18894
|
+
caughtError = {
|
|
18895
|
+
err: err2
|
|
18896
|
+
};
|
|
18897
|
+
}
|
|
18898
|
+
if (caughtError) {
|
|
18899
|
+
const {
|
|
18900
|
+
err: err2
|
|
18901
|
+
} = caughtError;
|
|
18902
|
+
this._snapshot = {
|
|
18903
|
+
...this._snapshot,
|
|
18904
|
+
status: "error",
|
|
18905
|
+
error: err2
|
|
18906
|
+
};
|
|
18907
|
+
this._error(err2);
|
|
18908
|
+
return;
|
|
18909
|
+
}
|
|
18910
|
+
this.update(nextState, event);
|
|
18911
|
+
if (event.type === XSTATE_STOP) {
|
|
18912
|
+
this._stopProcedure();
|
|
18913
|
+
this._complete();
|
|
18914
|
+
}
|
|
18915
|
+
}
|
|
18916
|
+
_stop() {
|
|
18917
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
18918
|
+
return this;
|
|
18919
|
+
}
|
|
18920
|
+
this.mailbox.clear();
|
|
18921
|
+
if (this._processingStatus === ProcessingStatus.NotStarted) {
|
|
18922
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
18923
|
+
return this;
|
|
18924
|
+
}
|
|
18925
|
+
this.mailbox.enqueue({
|
|
18926
|
+
type: XSTATE_STOP
|
|
18927
|
+
});
|
|
18928
|
+
return this;
|
|
18929
|
+
}
|
|
18930
|
+
/** Stops the Actor and unsubscribe all listeners. */
|
|
18931
|
+
stop() {
|
|
18932
|
+
if (this._parent) {
|
|
18933
|
+
throw new Error("A non-root actor cannot be stopped directly.");
|
|
18934
|
+
}
|
|
18935
|
+
return this._stop();
|
|
18936
|
+
}
|
|
18937
|
+
_complete() {
|
|
18938
|
+
for (const observer of this.observers) {
|
|
18939
|
+
try {
|
|
18940
|
+
observer.complete?.();
|
|
18941
|
+
} catch (err2) {
|
|
18942
|
+
reportUnhandledError(err2);
|
|
18943
|
+
}
|
|
18944
|
+
}
|
|
18945
|
+
this.observers.clear();
|
|
18946
|
+
this.eventListeners.clear();
|
|
18947
|
+
}
|
|
18948
|
+
_reportError(err2) {
|
|
18949
|
+
if (!this.observers.size) {
|
|
18950
|
+
if (!this._parent) {
|
|
18951
|
+
reportUnhandledError(err2);
|
|
18952
|
+
}
|
|
18953
|
+
this.eventListeners.clear();
|
|
18954
|
+
return;
|
|
18955
|
+
}
|
|
18956
|
+
let reportError = false;
|
|
18957
|
+
for (const observer of this.observers) {
|
|
18958
|
+
const errorListener = observer.error;
|
|
18959
|
+
reportError ||= !errorListener;
|
|
18960
|
+
try {
|
|
18961
|
+
errorListener?.(err2);
|
|
18962
|
+
} catch (err22) {
|
|
18963
|
+
reportUnhandledError(err22);
|
|
18964
|
+
}
|
|
18965
|
+
}
|
|
18966
|
+
this.observers.clear();
|
|
18967
|
+
this.eventListeners.clear();
|
|
18968
|
+
if (reportError) {
|
|
18969
|
+
reportUnhandledError(err2);
|
|
18970
|
+
}
|
|
18971
|
+
}
|
|
18972
|
+
_error(err2) {
|
|
18973
|
+
this._stopProcedure();
|
|
18974
|
+
this._reportError(err2);
|
|
18975
|
+
if (this._parent) {
|
|
18976
|
+
this.system._relay(this, this._parent, createErrorActorEvent(this.id, err2));
|
|
18977
|
+
}
|
|
18978
|
+
}
|
|
18979
|
+
// TODO: atm children don't belong entirely to the actor so
|
|
18980
|
+
// in a way - it's not even super aware of them
|
|
18981
|
+
// so we can't stop them from here but we really should!
|
|
18982
|
+
// right now, they are being stopped within the machine's transition
|
|
18983
|
+
// but that could throw and leave us with "orphaned" active actors
|
|
18984
|
+
_stopProcedure() {
|
|
18985
|
+
if (this._processingStatus !== ProcessingStatus.Running) {
|
|
18986
|
+
return this;
|
|
18987
|
+
}
|
|
18988
|
+
this.system.scheduler.cancelAll(this);
|
|
18989
|
+
this.mailbox.clear();
|
|
18990
|
+
this.mailbox = new Mailbox(this._process.bind(this));
|
|
18991
|
+
this._processingStatus = ProcessingStatus.Stopped;
|
|
18992
|
+
this.system._unregister(this);
|
|
18993
|
+
return this;
|
|
18994
|
+
}
|
|
18995
|
+
/** @internal */
|
|
18996
|
+
_send(event) {
|
|
18997
|
+
if (this._processingStatus === ProcessingStatus.Stopped) {
|
|
18998
|
+
return;
|
|
18999
|
+
}
|
|
19000
|
+
this.mailbox.enqueue(event);
|
|
19001
|
+
}
|
|
19002
|
+
/**
|
|
19003
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
19004
|
+
*
|
|
19005
|
+
* @param event The event to send
|
|
19006
|
+
*/
|
|
19007
|
+
send(event) {
|
|
19008
|
+
this.system._relay(void 0, this, event);
|
|
19009
|
+
}
|
|
19010
|
+
attachDevTools() {
|
|
19011
|
+
const {
|
|
19012
|
+
devTools
|
|
19013
|
+
} = this.options;
|
|
19014
|
+
if (devTools) {
|
|
19015
|
+
const resolvedDevToolsAdapter = typeof devTools === "function" ? devTools : devToolsAdapter;
|
|
19016
|
+
resolvedDevToolsAdapter(this);
|
|
19017
|
+
}
|
|
19018
|
+
}
|
|
19019
|
+
toJSON() {
|
|
19020
|
+
return {
|
|
19021
|
+
xstate$$type: $$ACTOR_TYPE,
|
|
19022
|
+
id: this.id
|
|
19023
|
+
};
|
|
19024
|
+
}
|
|
19025
|
+
/**
|
|
19026
|
+
* Obtain the internal state of the actor, which can be persisted.
|
|
19027
|
+
*
|
|
19028
|
+
* @remarks
|
|
19029
|
+
* The internal state can be persisted from any actor, not only machines.
|
|
19030
|
+
*
|
|
19031
|
+
* Note that the persisted state is not the same as the snapshot from
|
|
19032
|
+
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
19033
|
+
* the actor, while snapshots represent the actor's last emitted value.
|
|
19034
|
+
*
|
|
19035
|
+
* Can be restored with {@link ActorOptions.state}
|
|
19036
|
+
* @see https://stately.ai/docs/persistence
|
|
19037
|
+
*/
|
|
19038
|
+
getPersistedSnapshot(options) {
|
|
19039
|
+
return this.logic.getPersistedSnapshot(this._snapshot, options);
|
|
19040
|
+
}
|
|
19041
|
+
[symbolObservable]() {
|
|
19042
|
+
return this;
|
|
19043
|
+
}
|
|
19044
|
+
/**
|
|
19045
|
+
* Read an actor’s snapshot synchronously.
|
|
19046
|
+
*
|
|
19047
|
+
* @remarks
|
|
19048
|
+
* The snapshot represent an actor's last emitted value.
|
|
19049
|
+
*
|
|
19050
|
+
* When an actor receives an event, its internal state may change. An actor
|
|
19051
|
+
* may emit a snapshot when a state transition occurs.
|
|
19052
|
+
*
|
|
19053
|
+
* Note that some actors, such as callback actors generated with
|
|
19054
|
+
* `fromCallback`, will not emit snapshots.
|
|
19055
|
+
* @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
|
|
19056
|
+
* @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
|
|
19057
|
+
*/
|
|
19058
|
+
getSnapshot() {
|
|
19059
|
+
return this._snapshot;
|
|
19060
|
+
}
|
|
19061
|
+
};
|
|
19062
|
+
isStateId = (str) => str[0] === STATE_IDENTIFIER;
|
|
19063
|
+
machineSnapshotMatches = function matches(testValue) {
|
|
19064
|
+
return matchesState(testValue, this.value);
|
|
19065
|
+
};
|
|
19066
|
+
machineSnapshotHasTag = function hasTag(tag) {
|
|
19067
|
+
return this.tags.has(tag);
|
|
19068
|
+
};
|
|
19069
|
+
machineSnapshotCan = function can(event) {
|
|
19070
|
+
const transitionData = this.machine.getTransitionData(this, event);
|
|
19071
|
+
return !!transitionData?.length && // Check that at least one transition is not forbidden
|
|
19072
|
+
transitionData.some((t) => t.target !== void 0 || t.actions.length);
|
|
19073
|
+
};
|
|
19074
|
+
machineSnapshotToJSON = function toJSON() {
|
|
19075
|
+
const {
|
|
19076
|
+
_nodes: nodes,
|
|
19077
|
+
tags,
|
|
19078
|
+
machine,
|
|
19079
|
+
getMeta: getMeta3,
|
|
19080
|
+
toJSON: toJSON2,
|
|
19081
|
+
can: can2,
|
|
19082
|
+
hasTag: hasTag2,
|
|
19083
|
+
matches: matches2,
|
|
19084
|
+
...jsonValues
|
|
19085
|
+
} = this;
|
|
19086
|
+
return {
|
|
19087
|
+
...jsonValues,
|
|
19088
|
+
tags: Array.from(tags)
|
|
19089
|
+
};
|
|
19090
|
+
};
|
|
19091
|
+
machineSnapshotGetMeta = function getMeta2() {
|
|
19092
|
+
return this._nodes.reduce((acc, stateNode) => {
|
|
19093
|
+
if (stateNode.meta !== void 0) {
|
|
19094
|
+
acc[stateNode.id] = stateNode.meta;
|
|
19095
|
+
}
|
|
19096
|
+
return acc;
|
|
19097
|
+
}, {});
|
|
19098
|
+
};
|
|
19099
|
+
}
|
|
19100
|
+
});
|
|
19101
|
+
|
|
19102
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/actors/dist/xstate-actors.esm.js
|
|
19103
|
+
function fromTransition(transition, initialContext3) {
|
|
19104
|
+
return {
|
|
19105
|
+
config: transition,
|
|
19106
|
+
transition: (snapshot, event, actorScope) => {
|
|
19107
|
+
return {
|
|
19108
|
+
...snapshot,
|
|
19109
|
+
context: transition(snapshot.context, event, actorScope)
|
|
19110
|
+
};
|
|
19111
|
+
},
|
|
19112
|
+
getInitialSnapshot: (_, input) => {
|
|
19113
|
+
return {
|
|
19114
|
+
status: "active",
|
|
19115
|
+
output: void 0,
|
|
19116
|
+
error: void 0,
|
|
19117
|
+
context: typeof initialContext3 === "function" ? initialContext3({
|
|
19118
|
+
input
|
|
19119
|
+
}) : initialContext3
|
|
19120
|
+
};
|
|
19121
|
+
},
|
|
19122
|
+
getPersistedSnapshot: (snapshot) => snapshot,
|
|
19123
|
+
restoreSnapshot: (snapshot) => snapshot
|
|
19124
|
+
};
|
|
19125
|
+
}
|
|
19126
|
+
function fromPromise(promiseCreator) {
|
|
19127
|
+
const logic = {
|
|
19128
|
+
config: promiseCreator,
|
|
19129
|
+
transition: (state, event, scope) => {
|
|
19130
|
+
if (state.status !== "active") {
|
|
19131
|
+
return state;
|
|
19132
|
+
}
|
|
19133
|
+
switch (event.type) {
|
|
19134
|
+
case XSTATE_PROMISE_RESOLVE: {
|
|
19135
|
+
const resolvedValue = event.data;
|
|
19136
|
+
return {
|
|
19137
|
+
...state,
|
|
19138
|
+
status: "done",
|
|
19139
|
+
output: resolvedValue,
|
|
19140
|
+
input: void 0
|
|
19141
|
+
};
|
|
19142
|
+
}
|
|
19143
|
+
case XSTATE_PROMISE_REJECT:
|
|
19144
|
+
return {
|
|
19145
|
+
...state,
|
|
19146
|
+
status: "error",
|
|
19147
|
+
error: event.data,
|
|
19148
|
+
input: void 0
|
|
19149
|
+
};
|
|
19150
|
+
case XSTATE_STOP: {
|
|
19151
|
+
controllerMap.get(scope.self)?.abort();
|
|
19152
|
+
controllerMap.delete(scope.self);
|
|
19153
|
+
return {
|
|
19154
|
+
...state,
|
|
19155
|
+
status: "stopped",
|
|
19156
|
+
input: void 0
|
|
19157
|
+
};
|
|
19158
|
+
}
|
|
19159
|
+
default:
|
|
19160
|
+
return state;
|
|
19161
|
+
}
|
|
19162
|
+
},
|
|
19163
|
+
start: (state, {
|
|
19164
|
+
self: self2,
|
|
19165
|
+
system,
|
|
19166
|
+
emit: emit2
|
|
19167
|
+
}) => {
|
|
19168
|
+
if (state.status !== "active") {
|
|
19169
|
+
return;
|
|
19170
|
+
}
|
|
19171
|
+
const controller = new AbortController();
|
|
19172
|
+
controllerMap.set(self2, controller);
|
|
19173
|
+
const resolvedPromise = Promise.resolve(promiseCreator({
|
|
19174
|
+
input: state.input,
|
|
19175
|
+
system,
|
|
19176
|
+
self: self2,
|
|
19177
|
+
signal: controller.signal,
|
|
19178
|
+
emit: emit2
|
|
19179
|
+
}));
|
|
19180
|
+
resolvedPromise.then((response) => {
|
|
19181
|
+
if (self2.getSnapshot().status !== "active") {
|
|
19182
|
+
return;
|
|
19183
|
+
}
|
|
19184
|
+
controllerMap.delete(self2);
|
|
19185
|
+
system._relay(self2, self2, {
|
|
19186
|
+
type: XSTATE_PROMISE_RESOLVE,
|
|
19187
|
+
data: response
|
|
19188
|
+
});
|
|
19189
|
+
}, (errorData) => {
|
|
19190
|
+
if (self2.getSnapshot().status !== "active") {
|
|
19191
|
+
return;
|
|
19192
|
+
}
|
|
19193
|
+
controllerMap.delete(self2);
|
|
19194
|
+
system._relay(self2, self2, {
|
|
19195
|
+
type: XSTATE_PROMISE_REJECT,
|
|
19196
|
+
data: errorData
|
|
19197
|
+
});
|
|
19198
|
+
});
|
|
19199
|
+
},
|
|
19200
|
+
getInitialSnapshot: (_, input) => {
|
|
19201
|
+
return {
|
|
19202
|
+
status: "active",
|
|
19203
|
+
output: void 0,
|
|
19204
|
+
error: void 0,
|
|
19205
|
+
input
|
|
19206
|
+
};
|
|
19207
|
+
},
|
|
19208
|
+
getPersistedSnapshot: (snapshot) => snapshot,
|
|
19209
|
+
restoreSnapshot: (snapshot) => snapshot
|
|
19210
|
+
};
|
|
19211
|
+
return logic;
|
|
19212
|
+
}
|
|
19213
|
+
var XSTATE_PROMISE_RESOLVE, XSTATE_PROMISE_REJECT, controllerMap, emptyLogic;
|
|
19214
|
+
var init_xstate_actors_esm = __esm({
|
|
19215
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/actors/dist/xstate-actors.esm.js"() {
|
|
19216
|
+
"use strict";
|
|
19217
|
+
init_cjs_shims();
|
|
19218
|
+
init_raise_b47daa89_esm();
|
|
19219
|
+
init_xstate_dev_esm();
|
|
19220
|
+
XSTATE_PROMISE_RESOLVE = "xstate.promise.resolve";
|
|
19221
|
+
XSTATE_PROMISE_REJECT = "xstate.promise.reject";
|
|
19222
|
+
controllerMap = /* @__PURE__ */ new WeakMap();
|
|
19223
|
+
emptyLogic = fromTransition((_) => void 0, void 0);
|
|
19224
|
+
}
|
|
19225
|
+
});
|
|
19226
|
+
|
|
19227
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/assign-128c3f01.esm.js
|
|
19228
|
+
function createSpawner(actorScope, {
|
|
19229
|
+
machine,
|
|
19230
|
+
context
|
|
19231
|
+
}, event, spawnedChildren) {
|
|
19232
|
+
const spawn = (src, options) => {
|
|
19233
|
+
if (typeof src === "string") {
|
|
19234
|
+
const logic = resolveReferencedActor(machine, src);
|
|
19235
|
+
if (!logic) {
|
|
19236
|
+
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
19237
|
+
}
|
|
19238
|
+
const actorRef = createActor(logic, {
|
|
19239
|
+
id: options?.id,
|
|
19240
|
+
parent: actorScope.self,
|
|
19241
|
+
syncSnapshot: options?.syncSnapshot,
|
|
19242
|
+
input: typeof options?.input === "function" ? options.input({
|
|
19243
|
+
context,
|
|
19244
|
+
event,
|
|
19245
|
+
self: actorScope.self
|
|
19246
|
+
}) : options?.input,
|
|
19247
|
+
src,
|
|
19248
|
+
systemId: options?.systemId
|
|
19249
|
+
});
|
|
19250
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
19251
|
+
return actorRef;
|
|
19252
|
+
} else {
|
|
19253
|
+
const actorRef = createActor(src, {
|
|
19254
|
+
id: options?.id,
|
|
19255
|
+
parent: actorScope.self,
|
|
19256
|
+
syncSnapshot: options?.syncSnapshot,
|
|
19257
|
+
input: options?.input,
|
|
19258
|
+
src,
|
|
19259
|
+
systemId: options?.systemId
|
|
19260
|
+
});
|
|
19261
|
+
return actorRef;
|
|
19262
|
+
}
|
|
19263
|
+
};
|
|
19264
|
+
return (src, options) => {
|
|
19265
|
+
const actorRef = spawn(src, options);
|
|
19266
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
19267
|
+
actorScope.defer(() => {
|
|
19268
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
19269
|
+
return;
|
|
19270
|
+
}
|
|
19271
|
+
actorRef.start();
|
|
19272
|
+
});
|
|
19273
|
+
return actorRef;
|
|
19274
|
+
};
|
|
19275
|
+
}
|
|
19276
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
19277
|
+
assignment
|
|
19278
|
+
}) {
|
|
19279
|
+
if (!snapshot.context) {
|
|
19280
|
+
throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
|
|
19281
|
+
}
|
|
19282
|
+
const spawnedChildren = {};
|
|
19283
|
+
const assignArgs = {
|
|
19284
|
+
context: snapshot.context,
|
|
19285
|
+
event: actionArgs.event,
|
|
19286
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
19287
|
+
self: actorScope.self,
|
|
19288
|
+
system: actorScope.system
|
|
19289
|
+
};
|
|
19290
|
+
let partialUpdate = {};
|
|
19291
|
+
if (typeof assignment === "function") {
|
|
19292
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
19293
|
+
} else {
|
|
19294
|
+
for (const key of Object.keys(assignment)) {
|
|
19295
|
+
const propAssignment = assignment[key];
|
|
19296
|
+
partialUpdate[key] = typeof propAssignment === "function" ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
19297
|
+
}
|
|
19298
|
+
}
|
|
19299
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
19300
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
19301
|
+
context: updatedContext,
|
|
19302
|
+
children: Object.keys(spawnedChildren).length ? {
|
|
19303
|
+
...snapshot.children,
|
|
19304
|
+
...spawnedChildren
|
|
19305
|
+
} : snapshot.children
|
|
19306
|
+
}), void 0, void 0];
|
|
19307
|
+
}
|
|
19308
|
+
function assign(assignment) {
|
|
19309
|
+
function assign2(_args, _params) {
|
|
19310
|
+
}
|
|
19311
|
+
assign2.type = "xstate.assign";
|
|
19312
|
+
assign2.assignment = assignment;
|
|
19313
|
+
assign2.resolve = resolveAssign;
|
|
19314
|
+
return assign2;
|
|
19315
|
+
}
|
|
19316
|
+
var init_assign_128c3f01_esm = __esm({
|
|
19317
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/assign-128c3f01.esm.js"() {
|
|
19318
|
+
"use strict";
|
|
19319
|
+
init_cjs_shims();
|
|
19320
|
+
init_raise_b47daa89_esm();
|
|
19321
|
+
}
|
|
19322
|
+
});
|
|
19323
|
+
|
|
19324
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/StateMachine-bf2cec8d.esm.js
|
|
19325
|
+
function memo(object, key, fn) {
|
|
19326
|
+
let memoizedData = cache.get(object);
|
|
19327
|
+
if (!memoizedData) {
|
|
19328
|
+
memoizedData = {
|
|
19329
|
+
[key]: fn()
|
|
19330
|
+
};
|
|
19331
|
+
cache.set(object, memoizedData);
|
|
19332
|
+
} else if (!(key in memoizedData)) {
|
|
19333
|
+
memoizedData[key] = fn();
|
|
19334
|
+
}
|
|
19335
|
+
return memoizedData[key];
|
|
19336
|
+
}
|
|
19337
|
+
var cache, EMPTY_OBJECT, toSerializableAction, StateNode, STATE_IDENTIFIER2, StateMachine;
|
|
19338
|
+
var init_StateMachine_bf2cec8d_esm = __esm({
|
|
19339
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/StateMachine-bf2cec8d.esm.js"() {
|
|
19340
|
+
"use strict";
|
|
19341
|
+
init_cjs_shims();
|
|
19342
|
+
init_raise_b47daa89_esm();
|
|
19343
|
+
init_assign_128c3f01_esm();
|
|
19344
|
+
cache = /* @__PURE__ */ new WeakMap();
|
|
19345
|
+
EMPTY_OBJECT = {};
|
|
19346
|
+
toSerializableAction = (action) => {
|
|
19347
|
+
if (typeof action === "string") {
|
|
19348
|
+
return {
|
|
19349
|
+
type: action
|
|
19350
|
+
};
|
|
19351
|
+
}
|
|
19352
|
+
if (typeof action === "function") {
|
|
19353
|
+
if ("resolve" in action) {
|
|
19354
|
+
return {
|
|
19355
|
+
type: action.type
|
|
19356
|
+
};
|
|
19357
|
+
}
|
|
19358
|
+
return {
|
|
19359
|
+
type: action.name
|
|
19360
|
+
};
|
|
19361
|
+
}
|
|
19362
|
+
return action;
|
|
19363
|
+
};
|
|
19364
|
+
StateNode = class _StateNode {
|
|
19365
|
+
constructor(config, options) {
|
|
19366
|
+
this.config = config;
|
|
19367
|
+
this.key = void 0;
|
|
19368
|
+
this.id = void 0;
|
|
19369
|
+
this.type = void 0;
|
|
19370
|
+
this.path = void 0;
|
|
19371
|
+
this.states = void 0;
|
|
19372
|
+
this.history = void 0;
|
|
19373
|
+
this.entry = void 0;
|
|
19374
|
+
this.exit = void 0;
|
|
19375
|
+
this.parent = void 0;
|
|
19376
|
+
this.machine = void 0;
|
|
19377
|
+
this.meta = void 0;
|
|
19378
|
+
this.output = void 0;
|
|
19379
|
+
this.order = -1;
|
|
19380
|
+
this.description = void 0;
|
|
19381
|
+
this.tags = [];
|
|
19382
|
+
this.transitions = void 0;
|
|
19383
|
+
this.always = void 0;
|
|
19384
|
+
this.parent = options._parent;
|
|
19385
|
+
this.key = options._key;
|
|
19386
|
+
this.machine = options._machine;
|
|
19387
|
+
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
19388
|
+
this.id = this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
|
|
19389
|
+
this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? "compound" : this.config.history ? "history" : "atomic");
|
|
19390
|
+
this.description = this.config.description;
|
|
19391
|
+
this.order = this.machine.idMap.size;
|
|
19392
|
+
this.machine.idMap.set(this.id, this);
|
|
19393
|
+
this.states = this.config.states ? mapValues(this.config.states, (stateConfig, key) => {
|
|
19394
|
+
const stateNode = new _StateNode(stateConfig, {
|
|
19395
|
+
_parent: this,
|
|
19396
|
+
_key: key,
|
|
19397
|
+
_machine: this.machine
|
|
19398
|
+
});
|
|
19399
|
+
return stateNode;
|
|
19400
|
+
}) : EMPTY_OBJECT;
|
|
19401
|
+
if (this.type === "compound" && !this.config.initial) {
|
|
19402
|
+
throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
|
|
19403
|
+
}
|
|
19404
|
+
this.history = this.config.history === true ? "shallow" : this.config.history || false;
|
|
19405
|
+
this.entry = toArray(this.config.entry).slice();
|
|
19406
|
+
this.exit = toArray(this.config.exit).slice();
|
|
19407
|
+
this.meta = this.config.meta;
|
|
19408
|
+
this.output = this.type === "final" || !this.parent ? this.config.output : void 0;
|
|
19409
|
+
this.tags = toArray(config.tags).slice();
|
|
19410
|
+
}
|
|
19411
|
+
/** @internal */
|
|
19412
|
+
_initialize() {
|
|
19413
|
+
this.transitions = formatTransitions(this);
|
|
19414
|
+
if (this.config.always) {
|
|
19415
|
+
this.always = toTransitionConfigArray(this.config.always).map((t) => formatTransition(this, NULL_EVENT, t));
|
|
19416
|
+
}
|
|
19417
|
+
Object.keys(this.states).forEach((key) => {
|
|
19418
|
+
this.states[key]._initialize();
|
|
19419
|
+
});
|
|
19420
|
+
}
|
|
19421
|
+
/** The well-structured state node definition. */
|
|
19422
|
+
get definition() {
|
|
19423
|
+
return {
|
|
19424
|
+
id: this.id,
|
|
19425
|
+
key: this.key,
|
|
19426
|
+
version: this.machine.version,
|
|
19427
|
+
type: this.type,
|
|
19428
|
+
initial: this.initial ? {
|
|
19429
|
+
target: this.initial.target,
|
|
19430
|
+
source: this,
|
|
19431
|
+
actions: this.initial.actions.map(toSerializableAction),
|
|
19432
|
+
eventType: null,
|
|
19433
|
+
reenter: false,
|
|
19434
|
+
toJSON: () => ({
|
|
19435
|
+
target: this.initial.target.map((t) => `#${t.id}`),
|
|
19436
|
+
source: `#${this.id}`,
|
|
19437
|
+
actions: this.initial.actions.map(toSerializableAction),
|
|
19438
|
+
eventType: null
|
|
19439
|
+
})
|
|
19440
|
+
} : void 0,
|
|
19441
|
+
history: this.history,
|
|
19442
|
+
states: mapValues(this.states, (state) => {
|
|
19443
|
+
return state.definition;
|
|
19444
|
+
}),
|
|
19445
|
+
on: this.on,
|
|
19446
|
+
transitions: [...this.transitions.values()].flat().map((t) => ({
|
|
19447
|
+
...t,
|
|
19448
|
+
actions: t.actions.map(toSerializableAction)
|
|
19449
|
+
})),
|
|
19450
|
+
entry: this.entry.map(toSerializableAction),
|
|
19451
|
+
exit: this.exit.map(toSerializableAction),
|
|
19452
|
+
meta: this.meta,
|
|
19453
|
+
order: this.order || -1,
|
|
19454
|
+
output: this.output,
|
|
19455
|
+
invoke: this.invoke,
|
|
19456
|
+
description: this.description,
|
|
19457
|
+
tags: this.tags
|
|
19458
|
+
};
|
|
19459
|
+
}
|
|
19460
|
+
/** @internal */
|
|
19461
|
+
toJSON() {
|
|
19462
|
+
return this.definition;
|
|
19463
|
+
}
|
|
19464
|
+
/** The logic invoked as actors by this state node. */
|
|
19465
|
+
get invoke() {
|
|
19466
|
+
return memo(this, "invoke", () => toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
19467
|
+
const {
|
|
19468
|
+
src,
|
|
19469
|
+
systemId
|
|
19470
|
+
} = invokeConfig;
|
|
19471
|
+
const resolvedId = invokeConfig.id ?? createInvokeId(this.id, i);
|
|
19472
|
+
const sourceName = typeof src === "string" ? src : `xstate.invoke.${createInvokeId(this.id, i)}`;
|
|
19473
|
+
return {
|
|
19474
|
+
...invokeConfig,
|
|
19475
|
+
src: sourceName,
|
|
19476
|
+
id: resolvedId,
|
|
19477
|
+
systemId,
|
|
19478
|
+
toJSON() {
|
|
19479
|
+
const {
|
|
19480
|
+
onDone,
|
|
19481
|
+
onError,
|
|
19482
|
+
...invokeDefValues
|
|
19483
|
+
} = invokeConfig;
|
|
19484
|
+
return {
|
|
19485
|
+
...invokeDefValues,
|
|
19486
|
+
type: "xstate.invoke",
|
|
19487
|
+
src: sourceName,
|
|
19488
|
+
id: resolvedId
|
|
19489
|
+
};
|
|
19490
|
+
}
|
|
19491
|
+
};
|
|
19492
|
+
}));
|
|
19493
|
+
}
|
|
19494
|
+
/** The mapping of events to transitions. */
|
|
19495
|
+
get on() {
|
|
19496
|
+
return memo(this, "on", () => {
|
|
19497
|
+
const transitions = this.transitions;
|
|
19498
|
+
return [...transitions].flatMap(([descriptor, t]) => t.map((t2) => [descriptor, t2])).reduce((map, [descriptor, transition]) => {
|
|
19499
|
+
map[descriptor] = map[descriptor] || [];
|
|
19500
|
+
map[descriptor].push(transition);
|
|
19501
|
+
return map;
|
|
19502
|
+
}, {});
|
|
19503
|
+
});
|
|
19504
|
+
}
|
|
19505
|
+
get after() {
|
|
19506
|
+
return memo(this, "delayedTransitions", () => getDelayedTransitions(this));
|
|
19507
|
+
}
|
|
19508
|
+
get initial() {
|
|
19509
|
+
return memo(this, "initial", () => formatInitialTransition(this, this.config.initial));
|
|
19510
|
+
}
|
|
19511
|
+
/** @internal */
|
|
19512
|
+
next(snapshot, event) {
|
|
19513
|
+
const eventType = event.type;
|
|
19514
|
+
const actions = [];
|
|
19515
|
+
let selectedTransition;
|
|
19516
|
+
const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
|
|
19517
|
+
for (const candidate of candidates) {
|
|
19518
|
+
const {
|
|
19519
|
+
guard
|
|
19520
|
+
} = candidate;
|
|
19521
|
+
const resolvedContext = snapshot.context;
|
|
19522
|
+
let guardPassed = false;
|
|
19523
|
+
try {
|
|
19524
|
+
guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
|
|
19525
|
+
} catch (err2) {
|
|
19526
|
+
const guardType = typeof guard === "string" ? guard : typeof guard === "object" ? guard.type : void 0;
|
|
19527
|
+
throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ""}in transition for event '${eventType}' in state node '${this.id}':
|
|
19528
|
+
${err2.message}`);
|
|
19529
|
+
}
|
|
19530
|
+
if (guardPassed) {
|
|
19531
|
+
actions.push(...candidate.actions);
|
|
19532
|
+
selectedTransition = candidate;
|
|
19533
|
+
break;
|
|
19534
|
+
}
|
|
19535
|
+
}
|
|
19536
|
+
return selectedTransition ? [selectedTransition] : void 0;
|
|
19537
|
+
}
|
|
19538
|
+
/** All the event types accepted by this state node and its descendants. */
|
|
19539
|
+
get events() {
|
|
19540
|
+
return memo(this, "events", () => {
|
|
19541
|
+
const {
|
|
19542
|
+
states
|
|
19543
|
+
} = this;
|
|
19544
|
+
const events = new Set(this.ownEvents);
|
|
19545
|
+
if (states) {
|
|
19546
|
+
for (const stateId of Object.keys(states)) {
|
|
19547
|
+
const state = states[stateId];
|
|
19548
|
+
if (state.states) {
|
|
19549
|
+
for (const event of state.events) {
|
|
19550
|
+
events.add(`${event}`);
|
|
19551
|
+
}
|
|
19552
|
+
}
|
|
19553
|
+
}
|
|
19554
|
+
}
|
|
19555
|
+
return Array.from(events);
|
|
19556
|
+
});
|
|
19557
|
+
}
|
|
19558
|
+
/**
|
|
19559
|
+
* All the events that have transitions directly from this state node.
|
|
19560
|
+
*
|
|
19561
|
+
* Excludes any inert events.
|
|
19562
|
+
*/
|
|
19563
|
+
get ownEvents() {
|
|
19564
|
+
const keys = Object.keys(Object.fromEntries(this.transitions));
|
|
19565
|
+
const events = new Set(keys.filter((descriptor) => {
|
|
19566
|
+
return this.transitions.get(descriptor).some((transition) => !(!transition.target && !transition.actions.length && !transition.reenter));
|
|
19567
|
+
}));
|
|
19568
|
+
return Array.from(events);
|
|
19569
|
+
}
|
|
19570
|
+
};
|
|
19571
|
+
STATE_IDENTIFIER2 = "#";
|
|
19572
|
+
StateMachine = class _StateMachine {
|
|
19573
|
+
constructor(config, implementations) {
|
|
19574
|
+
this.config = config;
|
|
19575
|
+
this.version = void 0;
|
|
19576
|
+
this.schemas = void 0;
|
|
19577
|
+
this.implementations = void 0;
|
|
19578
|
+
this.__xstatenode = true;
|
|
19579
|
+
this.idMap = /* @__PURE__ */ new Map();
|
|
19580
|
+
this.root = void 0;
|
|
19581
|
+
this.id = void 0;
|
|
19582
|
+
this.states = void 0;
|
|
19583
|
+
this.events = void 0;
|
|
19584
|
+
this.id = config.id || "(machine)";
|
|
19585
|
+
this.implementations = {
|
|
19586
|
+
actors: implementations?.actors ?? {},
|
|
19587
|
+
actions: implementations?.actions ?? {},
|
|
19588
|
+
delays: implementations?.delays ?? {},
|
|
19589
|
+
guards: implementations?.guards ?? {}
|
|
19590
|
+
};
|
|
19591
|
+
this.version = this.config.version;
|
|
19592
|
+
this.schemas = this.config.schemas;
|
|
19593
|
+
this.transition = this.transition.bind(this);
|
|
19594
|
+
this.getInitialSnapshot = this.getInitialSnapshot.bind(this);
|
|
19595
|
+
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
|
|
19596
|
+
this.restoreSnapshot = this.restoreSnapshot.bind(this);
|
|
19597
|
+
this.start = this.start.bind(this);
|
|
19598
|
+
this.root = new StateNode(config, {
|
|
19599
|
+
_key: this.id,
|
|
19600
|
+
_machine: this
|
|
19601
|
+
});
|
|
19602
|
+
this.root._initialize();
|
|
19603
|
+
formatRouteTransitions(this.root);
|
|
19604
|
+
this.states = this.root.states;
|
|
19605
|
+
this.events = this.root.events;
|
|
19606
|
+
}
|
|
19607
|
+
/**
|
|
19608
|
+
* Clones this state machine with the provided implementations.
|
|
19609
|
+
*
|
|
19610
|
+
* @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
|
|
19611
|
+
* recursively merge with the existing options.
|
|
19612
|
+
* @returns A new `StateMachine` instance with the provided implementations.
|
|
19613
|
+
*/
|
|
19614
|
+
provide(implementations) {
|
|
19615
|
+
const {
|
|
19616
|
+
actions,
|
|
19617
|
+
guards,
|
|
19618
|
+
actors,
|
|
19619
|
+
delays
|
|
19620
|
+
} = this.implementations;
|
|
19621
|
+
return new _StateMachine(this.config, {
|
|
19622
|
+
actions: {
|
|
19623
|
+
...actions,
|
|
19624
|
+
...implementations.actions
|
|
19625
|
+
},
|
|
19626
|
+
guards: {
|
|
19627
|
+
...guards,
|
|
19628
|
+
...implementations.guards
|
|
19629
|
+
},
|
|
19630
|
+
actors: {
|
|
19631
|
+
...actors,
|
|
19632
|
+
...implementations.actors
|
|
19633
|
+
},
|
|
19634
|
+
delays: {
|
|
19635
|
+
...delays,
|
|
19636
|
+
...implementations.delays
|
|
19637
|
+
}
|
|
19638
|
+
});
|
|
19639
|
+
}
|
|
19640
|
+
resolveState(config) {
|
|
19641
|
+
const resolvedStateValue = resolveStateValue(this.root, config.value);
|
|
19642
|
+
const nodeSet = getAllStateNodes(getStateNodes(this.root, resolvedStateValue));
|
|
19643
|
+
return createMachineSnapshot({
|
|
19644
|
+
_nodes: [...nodeSet],
|
|
19645
|
+
context: config.context || {},
|
|
19646
|
+
children: {},
|
|
19647
|
+
status: isInFinalState(nodeSet, this.root) ? "done" : config.status || "active",
|
|
19648
|
+
output: config.output,
|
|
19649
|
+
error: config.error,
|
|
19650
|
+
historyValue: config.historyValue
|
|
19651
|
+
}, this);
|
|
19652
|
+
}
|
|
19653
|
+
/**
|
|
19654
|
+
* Determines the next snapshot given the current `snapshot` and received
|
|
19655
|
+
* `event`. Calculates a full macrostep from all microsteps.
|
|
19656
|
+
*
|
|
19657
|
+
* @param snapshot The current snapshot
|
|
19658
|
+
* @param event The received event
|
|
19659
|
+
*/
|
|
19660
|
+
transition(snapshot, event, actorScope) {
|
|
19661
|
+
return macrostep(snapshot, event, actorScope, []).snapshot;
|
|
19662
|
+
}
|
|
19663
|
+
/**
|
|
19664
|
+
* Determines the next state given the current `state` and `event`. Calculates
|
|
19665
|
+
* a microstep.
|
|
19666
|
+
*
|
|
19667
|
+
* @param state The current state
|
|
19668
|
+
* @param event The received event
|
|
19669
|
+
*/
|
|
19670
|
+
microstep(snapshot, event, actorScope) {
|
|
19671
|
+
return macrostep(snapshot, event, actorScope, []).microsteps.map(([s]) => s);
|
|
19672
|
+
}
|
|
19673
|
+
getTransitionData(snapshot, event) {
|
|
19674
|
+
return transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
19675
|
+
}
|
|
19676
|
+
/**
|
|
19677
|
+
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
19678
|
+
* state is provided to initial actions executed in the initial state.
|
|
19679
|
+
*
|
|
19680
|
+
* @internal
|
|
19681
|
+
*/
|
|
19682
|
+
_getPreInitialState(actorScope, initEvent, internalQueue) {
|
|
19683
|
+
const {
|
|
19684
|
+
context
|
|
19685
|
+
} = this.config;
|
|
19686
|
+
const preInitial = createMachineSnapshot({
|
|
19687
|
+
context: typeof context !== "function" && context ? context : {},
|
|
19688
|
+
_nodes: [this.root],
|
|
19689
|
+
children: {},
|
|
19690
|
+
status: "active"
|
|
19691
|
+
}, this);
|
|
19692
|
+
if (typeof context === "function") {
|
|
19693
|
+
const assignment = ({
|
|
19694
|
+
spawn,
|
|
19695
|
+
event,
|
|
19696
|
+
self: self2
|
|
19697
|
+
}) => context({
|
|
19698
|
+
spawn,
|
|
19699
|
+
input: event.input,
|
|
19700
|
+
self: self2
|
|
19701
|
+
});
|
|
19702
|
+
return resolveActionsAndContext(preInitial, initEvent, actorScope, [assign(assignment)], internalQueue, void 0);
|
|
19703
|
+
}
|
|
19704
|
+
return preInitial;
|
|
19705
|
+
}
|
|
19706
|
+
/**
|
|
19707
|
+
* Returns the initial `State` instance, with reference to `self` as an
|
|
19708
|
+
* `ActorRef`.
|
|
19709
|
+
*/
|
|
19710
|
+
getInitialSnapshot(actorScope, input) {
|
|
19711
|
+
const initEvent = createInitEvent(input);
|
|
19712
|
+
const internalQueue = [];
|
|
19713
|
+
const preInitialState = this._getPreInitialState(actorScope, initEvent, internalQueue);
|
|
19714
|
+
const [nextState] = initialMicrostep(this.root, preInitialState, actorScope, initEvent, internalQueue);
|
|
19715
|
+
const {
|
|
19716
|
+
snapshot: macroState
|
|
19717
|
+
} = macrostep(nextState, initEvent, actorScope, internalQueue);
|
|
19718
|
+
return macroState;
|
|
19719
|
+
}
|
|
19720
|
+
start(snapshot) {
|
|
19721
|
+
Object.values(snapshot.children).forEach((child2) => {
|
|
19722
|
+
if (child2.getSnapshot().status === "active") {
|
|
19723
|
+
child2.start();
|
|
19724
|
+
}
|
|
19725
|
+
});
|
|
19726
|
+
}
|
|
19727
|
+
getStateNodeById(stateId) {
|
|
19728
|
+
const fullPath = toStatePath(stateId);
|
|
19729
|
+
const relativePath = fullPath.slice(1);
|
|
19730
|
+
const resolvedStateId = isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER2.length) : fullPath[0];
|
|
19731
|
+
const stateNode = this.idMap.get(resolvedStateId);
|
|
19732
|
+
if (!stateNode) {
|
|
19733
|
+
throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
|
|
19734
|
+
}
|
|
19735
|
+
return getStateNodeByPath(stateNode, relativePath);
|
|
19736
|
+
}
|
|
19737
|
+
get definition() {
|
|
19738
|
+
return this.root.definition;
|
|
19739
|
+
}
|
|
19740
|
+
toJSON() {
|
|
19741
|
+
return this.definition;
|
|
19742
|
+
}
|
|
19743
|
+
getPersistedSnapshot(snapshot, options) {
|
|
19744
|
+
return getPersistedSnapshot(snapshot, options);
|
|
19745
|
+
}
|
|
19746
|
+
restoreSnapshot(snapshot, _actorScope) {
|
|
19747
|
+
const children2 = {};
|
|
19748
|
+
const snapshotChildren = snapshot.children;
|
|
19749
|
+
Object.keys(snapshotChildren).forEach((actorId) => {
|
|
19750
|
+
const actorData = snapshotChildren[actorId];
|
|
19751
|
+
const childState = actorData.snapshot;
|
|
19752
|
+
const src = actorData.src;
|
|
19753
|
+
const logic = typeof src === "string" ? resolveReferencedActor(this, src) : src;
|
|
19754
|
+
if (!logic) {
|
|
19755
|
+
return;
|
|
19756
|
+
}
|
|
19757
|
+
const actorRef = createActor(logic, {
|
|
19758
|
+
id: actorId,
|
|
19759
|
+
parent: _actorScope.self,
|
|
19760
|
+
syncSnapshot: actorData.syncSnapshot,
|
|
19761
|
+
snapshot: childState,
|
|
19762
|
+
src,
|
|
19763
|
+
systemId: actorData.systemId
|
|
19764
|
+
});
|
|
19765
|
+
children2[actorId] = actorRef;
|
|
19766
|
+
});
|
|
19767
|
+
function resolveHistoryReferencedState(root, referenced) {
|
|
19768
|
+
if (referenced instanceof StateNode) {
|
|
19769
|
+
return referenced;
|
|
19770
|
+
}
|
|
19771
|
+
try {
|
|
19772
|
+
return root.machine.getStateNodeById(referenced.id);
|
|
19773
|
+
} catch {
|
|
19774
|
+
}
|
|
19775
|
+
}
|
|
19776
|
+
function reviveHistoryValue(root, historyValue) {
|
|
19777
|
+
if (!historyValue || typeof historyValue !== "object") {
|
|
19778
|
+
return {};
|
|
19779
|
+
}
|
|
19780
|
+
const revived = {};
|
|
19781
|
+
for (const key in historyValue) {
|
|
19782
|
+
const arr = historyValue[key];
|
|
19783
|
+
for (const item of arr) {
|
|
19784
|
+
const resolved = resolveHistoryReferencedState(root, item);
|
|
19785
|
+
if (!resolved) {
|
|
19786
|
+
continue;
|
|
19787
|
+
}
|
|
19788
|
+
revived[key] ??= [];
|
|
19789
|
+
revived[key].push(resolved);
|
|
19790
|
+
}
|
|
19791
|
+
}
|
|
19792
|
+
return revived;
|
|
19793
|
+
}
|
|
19794
|
+
const revivedHistoryValue = reviveHistoryValue(this.root, snapshot.historyValue);
|
|
19795
|
+
const restoredSnapshot = createMachineSnapshot({
|
|
19796
|
+
...snapshot,
|
|
19797
|
+
children: children2,
|
|
19798
|
+
_nodes: Array.from(getAllStateNodes(getStateNodes(this.root, snapshot.value))),
|
|
19799
|
+
historyValue: revivedHistoryValue
|
|
19800
|
+
}, this);
|
|
19801
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19802
|
+
function reviveContext(contextPart, children3) {
|
|
19803
|
+
if (seen.has(contextPart)) {
|
|
19804
|
+
return;
|
|
19805
|
+
}
|
|
19806
|
+
seen.add(contextPart);
|
|
19807
|
+
for (const key in contextPart) {
|
|
19808
|
+
const value = contextPart[key];
|
|
19809
|
+
if (value && typeof value === "object") {
|
|
19810
|
+
if ("xstate$$type" in value && value.xstate$$type === $$ACTOR_TYPE) {
|
|
19811
|
+
contextPart[key] = children3[value.id];
|
|
19812
|
+
continue;
|
|
19813
|
+
}
|
|
19814
|
+
reviveContext(value, children3);
|
|
19815
|
+
}
|
|
19816
|
+
}
|
|
19817
|
+
}
|
|
19818
|
+
reviveContext(restoredSnapshot.context, children2);
|
|
19819
|
+
return restoredSnapshot;
|
|
19820
|
+
}
|
|
19821
|
+
};
|
|
19822
|
+
}
|
|
19823
|
+
});
|
|
19824
|
+
|
|
19825
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/log-678e6837.esm.js
|
|
19826
|
+
function resolveEmit(_, snapshot, args, actionParams, {
|
|
19827
|
+
event: eventOrExpr
|
|
19828
|
+
}) {
|
|
19829
|
+
const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
19830
|
+
return [snapshot, {
|
|
19831
|
+
event: resolvedEvent
|
|
19832
|
+
}, void 0];
|
|
19833
|
+
}
|
|
19834
|
+
function executeEmit(actorScope, {
|
|
19835
|
+
event
|
|
19836
|
+
}) {
|
|
19837
|
+
actorScope.defer(() => actorScope.emit(event));
|
|
19838
|
+
}
|
|
19839
|
+
function emit(eventOrExpr) {
|
|
19840
|
+
function emit2(_args, _params) {
|
|
19841
|
+
}
|
|
19842
|
+
emit2.type = "xstate.emit";
|
|
19843
|
+
emit2.event = eventOrExpr;
|
|
19844
|
+
emit2.resolve = resolveEmit;
|
|
19845
|
+
emit2.execute = executeEmit;
|
|
19846
|
+
return emit2;
|
|
19847
|
+
}
|
|
19848
|
+
function resolveSendTo(actorScope, snapshot, args, actionParams, {
|
|
19849
|
+
to,
|
|
19850
|
+
event: eventOrExpr,
|
|
19851
|
+
id,
|
|
19852
|
+
delay
|
|
19853
|
+
}, extra) {
|
|
19854
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
19855
|
+
if (typeof eventOrExpr === "string") {
|
|
19856
|
+
throw new Error(
|
|
19857
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
19858
|
+
`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`
|
|
19859
|
+
);
|
|
19860
|
+
}
|
|
19861
|
+
const resolvedEvent = typeof eventOrExpr === "function" ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
19862
|
+
let resolvedDelay;
|
|
19863
|
+
if (typeof delay === "string") {
|
|
19864
|
+
const configDelay = delaysMap && delaysMap[delay];
|
|
19865
|
+
resolvedDelay = typeof configDelay === "function" ? configDelay(args, actionParams) : configDelay;
|
|
19866
|
+
} else {
|
|
19867
|
+
resolvedDelay = typeof delay === "function" ? delay(args, actionParams) : delay;
|
|
19868
|
+
}
|
|
19869
|
+
const resolvedTarget = typeof to === "function" ? to(args, actionParams) : to;
|
|
19870
|
+
let targetActorRef;
|
|
19871
|
+
if (typeof resolvedTarget === "string") {
|
|
19872
|
+
if (resolvedTarget === SpecialTargets.Parent) {
|
|
19873
|
+
targetActorRef = actorScope.self._parent;
|
|
19874
|
+
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
19875
|
+
targetActorRef = actorScope.self;
|
|
19876
|
+
} else if (resolvedTarget.startsWith("#_")) {
|
|
19877
|
+
targetActorRef = snapshot.children[resolvedTarget.slice(2)];
|
|
19878
|
+
} else {
|
|
19879
|
+
targetActorRef = extra.deferredActorIds?.includes(resolvedTarget) ? resolvedTarget : snapshot.children[resolvedTarget];
|
|
19880
|
+
}
|
|
19881
|
+
if (!targetActorRef) {
|
|
19882
|
+
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${snapshot.machine.id}'.`);
|
|
19883
|
+
}
|
|
19884
|
+
} else {
|
|
19885
|
+
targetActorRef = resolvedTarget || actorScope.self;
|
|
19886
|
+
}
|
|
19887
|
+
return [snapshot, {
|
|
19888
|
+
to: targetActorRef,
|
|
19889
|
+
targetId: typeof resolvedTarget === "string" ? resolvedTarget : void 0,
|
|
19890
|
+
event: resolvedEvent,
|
|
19891
|
+
id,
|
|
19892
|
+
delay: resolvedDelay
|
|
19893
|
+
}, void 0];
|
|
19894
|
+
}
|
|
19895
|
+
function retryResolveSendTo(_, snapshot, params) {
|
|
19896
|
+
if (typeof params.to === "string") {
|
|
19897
|
+
params.to = snapshot.children[params.to];
|
|
19898
|
+
}
|
|
19899
|
+
}
|
|
19900
|
+
function executeSendTo(actorScope, params) {
|
|
19901
|
+
actorScope.defer(() => {
|
|
19902
|
+
const {
|
|
19903
|
+
to,
|
|
19904
|
+
event,
|
|
19905
|
+
delay,
|
|
19906
|
+
id
|
|
19907
|
+
} = params;
|
|
19908
|
+
if (typeof delay === "number") {
|
|
19909
|
+
actorScope.system.scheduler.schedule(actorScope.self, to, event, delay, id);
|
|
19910
|
+
return;
|
|
19911
|
+
}
|
|
19912
|
+
actorScope.system._relay(
|
|
19913
|
+
actorScope.self,
|
|
19914
|
+
// at this point, in a deferred task, it should already be mutated by retryResolveSendTo
|
|
19915
|
+
// if it initially started as a string
|
|
19916
|
+
to,
|
|
19917
|
+
event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event
|
|
19918
|
+
);
|
|
19919
|
+
});
|
|
19920
|
+
}
|
|
19921
|
+
function sendTo(to, eventOrExpr, options) {
|
|
19922
|
+
function sendTo2(_args, _params) {
|
|
19923
|
+
}
|
|
19924
|
+
sendTo2.type = "xstate.sendTo";
|
|
19925
|
+
sendTo2.to = to;
|
|
19926
|
+
sendTo2.event = eventOrExpr;
|
|
19927
|
+
sendTo2.id = options?.id;
|
|
19928
|
+
sendTo2.delay = options?.delay;
|
|
19929
|
+
sendTo2.resolve = resolveSendTo;
|
|
19930
|
+
sendTo2.retryResolve = retryResolveSendTo;
|
|
19931
|
+
sendTo2.execute = executeSendTo;
|
|
19932
|
+
return sendTo2;
|
|
19933
|
+
}
|
|
19934
|
+
function sendParent(event, options) {
|
|
19935
|
+
return sendTo(SpecialTargets.Parent, event, options);
|
|
19936
|
+
}
|
|
19937
|
+
function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
|
|
19938
|
+
collect
|
|
19939
|
+
}) {
|
|
19940
|
+
const actions = [];
|
|
19941
|
+
const enqueue = function enqueue2(action) {
|
|
19942
|
+
actions.push(action);
|
|
19943
|
+
};
|
|
19944
|
+
enqueue.assign = (...args2) => {
|
|
19945
|
+
actions.push(assign(...args2));
|
|
19946
|
+
};
|
|
19947
|
+
enqueue.cancel = (...args2) => {
|
|
19948
|
+
actions.push(cancel(...args2));
|
|
19949
|
+
};
|
|
19950
|
+
enqueue.raise = (...args2) => {
|
|
19951
|
+
actions.push(raise(...args2));
|
|
19952
|
+
};
|
|
19953
|
+
enqueue.sendTo = (...args2) => {
|
|
19954
|
+
actions.push(sendTo(...args2));
|
|
19955
|
+
};
|
|
19956
|
+
enqueue.sendParent = (...args2) => {
|
|
19957
|
+
actions.push(sendParent(...args2));
|
|
19958
|
+
};
|
|
19959
|
+
enqueue.spawnChild = (...args2) => {
|
|
19960
|
+
actions.push(spawnChild(...args2));
|
|
19961
|
+
};
|
|
19962
|
+
enqueue.stopChild = (...args2) => {
|
|
19963
|
+
actions.push(stopChild(...args2));
|
|
19964
|
+
};
|
|
19965
|
+
enqueue.emit = (...args2) => {
|
|
19966
|
+
actions.push(emit(...args2));
|
|
19967
|
+
};
|
|
19968
|
+
collect({
|
|
19969
|
+
context: args.context,
|
|
19970
|
+
event: args.event,
|
|
19971
|
+
enqueue,
|
|
19972
|
+
check: (guard) => evaluateGuard(guard, snapshot.context, args.event, snapshot),
|
|
19973
|
+
self: actorScope.self,
|
|
19974
|
+
system: actorScope.system
|
|
19975
|
+
}, actionParams);
|
|
19976
|
+
return [snapshot, void 0, actions];
|
|
19977
|
+
}
|
|
19978
|
+
function enqueueActions(collect) {
|
|
19979
|
+
function enqueueActions2(_args, _params) {
|
|
19980
|
+
}
|
|
19981
|
+
enqueueActions2.type = "xstate.enqueueActions";
|
|
19982
|
+
enqueueActions2.collect = collect;
|
|
19983
|
+
enqueueActions2.resolve = resolveEnqueueActions;
|
|
19984
|
+
return enqueueActions2;
|
|
19985
|
+
}
|
|
19986
|
+
function resolveLog(_, snapshot, actionArgs, actionParams, {
|
|
19987
|
+
value,
|
|
19988
|
+
label
|
|
19989
|
+
}) {
|
|
19990
|
+
return [snapshot, {
|
|
19991
|
+
value: typeof value === "function" ? value(actionArgs, actionParams) : value,
|
|
19992
|
+
label
|
|
19993
|
+
}, void 0];
|
|
19994
|
+
}
|
|
19995
|
+
function executeLog({
|
|
19996
|
+
logger
|
|
19997
|
+
}, {
|
|
19998
|
+
value,
|
|
19999
|
+
label
|
|
20000
|
+
}) {
|
|
20001
|
+
if (label) {
|
|
20002
|
+
logger(label, value);
|
|
20003
|
+
} else {
|
|
20004
|
+
logger(value);
|
|
20005
|
+
}
|
|
20006
|
+
}
|
|
20007
|
+
function log(value = ({
|
|
20008
|
+
context,
|
|
20009
|
+
event
|
|
20010
|
+
}) => ({
|
|
20011
|
+
context,
|
|
20012
|
+
event
|
|
20013
|
+
}), label) {
|
|
20014
|
+
function log2(_args, _params) {
|
|
20015
|
+
}
|
|
20016
|
+
log2.type = "xstate.log";
|
|
20017
|
+
log2.value = value;
|
|
20018
|
+
log2.label = label;
|
|
20019
|
+
log2.resolve = resolveLog;
|
|
20020
|
+
log2.execute = executeLog;
|
|
20021
|
+
return log2;
|
|
20022
|
+
}
|
|
20023
|
+
var SpecialTargets;
|
|
20024
|
+
var init_log_678e6837_esm = __esm({
|
|
20025
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/log-678e6837.esm.js"() {
|
|
20026
|
+
"use strict";
|
|
20027
|
+
init_cjs_shims();
|
|
20028
|
+
init_raise_b47daa89_esm();
|
|
20029
|
+
init_assign_128c3f01_esm();
|
|
20030
|
+
SpecialTargets = /* @__PURE__ */ (function(SpecialTargets2) {
|
|
20031
|
+
SpecialTargets2["Parent"] = "#_parent";
|
|
20032
|
+
SpecialTargets2["Internal"] = "#_internal";
|
|
20033
|
+
return SpecialTargets2;
|
|
20034
|
+
})({});
|
|
20035
|
+
}
|
|
20036
|
+
});
|
|
20037
|
+
|
|
20038
|
+
// ../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/xstate.esm.js
|
|
20039
|
+
function createMachine(config, implementations) {
|
|
20040
|
+
return new StateMachine(config, implementations);
|
|
20041
|
+
}
|
|
20042
|
+
function setup({
|
|
20043
|
+
schemas,
|
|
20044
|
+
actors,
|
|
20045
|
+
actions,
|
|
20046
|
+
guards,
|
|
20047
|
+
delays
|
|
20048
|
+
}) {
|
|
20049
|
+
return {
|
|
20050
|
+
assign,
|
|
20051
|
+
sendTo,
|
|
20052
|
+
raise,
|
|
20053
|
+
log,
|
|
20054
|
+
cancel,
|
|
20055
|
+
stopChild,
|
|
20056
|
+
enqueueActions,
|
|
20057
|
+
emit,
|
|
20058
|
+
spawnChild,
|
|
20059
|
+
createStateConfig: (config) => config,
|
|
20060
|
+
createAction: (fn) => fn,
|
|
20061
|
+
createMachine: (config) => createMachine({
|
|
20062
|
+
...config,
|
|
20063
|
+
schemas
|
|
20064
|
+
}, {
|
|
20065
|
+
actors,
|
|
20066
|
+
actions,
|
|
20067
|
+
guards,
|
|
20068
|
+
delays
|
|
20069
|
+
}),
|
|
20070
|
+
extend: (extended) => setup({
|
|
20071
|
+
schemas,
|
|
20072
|
+
actors,
|
|
20073
|
+
actions: {
|
|
20074
|
+
...actions,
|
|
20075
|
+
...extended.actions
|
|
20076
|
+
},
|
|
20077
|
+
guards: {
|
|
20078
|
+
...guards,
|
|
20079
|
+
...extended.guards
|
|
20080
|
+
},
|
|
20081
|
+
delays: {
|
|
20082
|
+
...delays,
|
|
20083
|
+
...extended.delays
|
|
20084
|
+
}
|
|
20085
|
+
})
|
|
20086
|
+
};
|
|
20087
|
+
}
|
|
20088
|
+
var init_xstate_esm = __esm({
|
|
20089
|
+
"../../node_modules/.pnpm/xstate@5.29.0/node_modules/xstate/dist/xstate.esm.js"() {
|
|
20090
|
+
"use strict";
|
|
20091
|
+
init_cjs_shims();
|
|
20092
|
+
init_xstate_actors_esm();
|
|
20093
|
+
init_raise_b47daa89_esm();
|
|
20094
|
+
init_raise_b47daa89_esm();
|
|
20095
|
+
init_StateMachine_bf2cec8d_esm();
|
|
20096
|
+
init_assign_128c3f01_esm();
|
|
20097
|
+
init_assign_128c3f01_esm();
|
|
20098
|
+
init_log_678e6837_esm();
|
|
20099
|
+
init_xstate_dev_esm();
|
|
20100
|
+
}
|
|
20101
|
+
});
|
|
20102
|
+
|
|
16776
20103
|
// ../../kernel/src/document/document-lifecycle-machine.ts
|
|
16777
|
-
var
|
|
20104
|
+
var initialContext, documentLifecycleMachine, documentLifecycleSelectors;
|
|
16778
20105
|
var init_document_lifecycle_machine = __esm({
|
|
16779
20106
|
"../../kernel/src/document/document-lifecycle-machine.ts"() {
|
|
16780
20107
|
"use strict";
|
|
16781
20108
|
init_cjs_shims();
|
|
16782
|
-
|
|
20109
|
+
init_xstate_esm();
|
|
16783
20110
|
init_errors();
|
|
16784
20111
|
initialContext = {
|
|
16785
20112
|
docId: "",
|
|
@@ -16793,37 +20120,37 @@ var init_document_lifecycle_machine = __esm({
|
|
|
16793
20120
|
initialSheetIds: [],
|
|
16794
20121
|
error: null
|
|
16795
20122
|
};
|
|
16796
|
-
documentLifecycleMachine =
|
|
20123
|
+
documentLifecycleMachine = setup({
|
|
16797
20124
|
types: {
|
|
16798
20125
|
context: {},
|
|
16799
20126
|
events: {}
|
|
16800
20127
|
},
|
|
16801
20128
|
actors: {
|
|
16802
|
-
createEngine:
|
|
20129
|
+
createEngine: fromPromise(async ({ input }) => {
|
|
16803
20130
|
throw new KernelError(
|
|
16804
20131
|
"DOC_LIFECYCLE_ERROR",
|
|
16805
20132
|
`[documentLifecycleMachine] createEngine actor not implemented (docId: ${input.docId})`
|
|
16806
20133
|
);
|
|
16807
20134
|
}),
|
|
16808
|
-
wireContext:
|
|
20135
|
+
wireContext: fromPromise(async () => {
|
|
16809
20136
|
throw new KernelError(
|
|
16810
20137
|
"DOC_LIFECYCLE_ERROR",
|
|
16811
20138
|
"[documentLifecycleMachine] wireContext actor not implemented"
|
|
16812
20139
|
);
|
|
16813
20140
|
}),
|
|
16814
|
-
startBridge:
|
|
20141
|
+
startBridge: fromPromise(async () => {
|
|
16815
20142
|
throw new KernelError(
|
|
16816
20143
|
"DOC_LIFECYCLE_ERROR",
|
|
16817
20144
|
"[documentLifecycleMachine] startBridge actor not implemented"
|
|
16818
20145
|
);
|
|
16819
20146
|
}),
|
|
16820
|
-
hydrateXlsx:
|
|
20147
|
+
hydrateXlsx: fromPromise(async () => {
|
|
16821
20148
|
throw new KernelError(
|
|
16822
20149
|
"DOC_LIFECYCLE_ERROR",
|
|
16823
20150
|
"[documentLifecycleMachine] hydrateXlsx actor not implemented"
|
|
16824
20151
|
);
|
|
16825
20152
|
}),
|
|
16826
|
-
disposeBridge:
|
|
20153
|
+
disposeBridge: fromPromise(async () => {
|
|
16827
20154
|
throw new KernelError(
|
|
16828
20155
|
"DOC_LIFECYCLE_ERROR",
|
|
16829
20156
|
"[documentLifecycleMachine] disposeBridge actor not implemented"
|
|
@@ -16832,7 +20159,7 @@ var init_document_lifecycle_machine = __esm({
|
|
|
16832
20159
|
},
|
|
16833
20160
|
actions: {
|
|
16834
20161
|
// Store CREATE event data into context
|
|
16835
|
-
storeCreateParams:
|
|
20162
|
+
storeCreateParams: assign(({ event }) => {
|
|
16836
20163
|
if (event.type !== "CREATE") return {};
|
|
16837
20164
|
return {
|
|
16838
20165
|
docId: event.docId,
|
|
@@ -16842,7 +20169,7 @@ var init_document_lifecycle_machine = __esm({
|
|
|
16842
20169
|
};
|
|
16843
20170
|
}),
|
|
16844
20171
|
// Store CREATE_FROM_XLSX event data into context
|
|
16845
|
-
storeCreateFromXlsxParams:
|
|
20172
|
+
storeCreateFromXlsxParams: assign(({ event }) => {
|
|
16846
20173
|
if (event.type !== "CREATE_FROM_XLSX") return {};
|
|
16847
20174
|
return {
|
|
16848
20175
|
docId: event.docId,
|
|
@@ -16856,7 +20183,7 @@ var init_document_lifecycle_machine = __esm({
|
|
|
16856
20183
|
// so the event has an 'output' or 'error' property at runtime. We use 'in'
|
|
16857
20184
|
// checks to narrow the type safely since XState's action type system only
|
|
16858
20185
|
// sees the machine-level event union.
|
|
16859
|
-
storeEngineResult:
|
|
20186
|
+
storeEngineResult: assign(({ event }) => {
|
|
16860
20187
|
const output = "output" in event ? event.output : void 0;
|
|
16861
20188
|
return {
|
|
16862
20189
|
computeBridge: output?.computeBridge ?? null,
|
|
@@ -16865,35 +20192,35 @@ var init_document_lifecycle_machine = __esm({
|
|
|
16865
20192
|
};
|
|
16866
20193
|
}),
|
|
16867
20194
|
// Store wiring result (documentContext)
|
|
16868
|
-
storeWiringResult:
|
|
20195
|
+
storeWiringResult: assign(({ event }) => {
|
|
16869
20196
|
const output = "output" in event ? event.output : void 0;
|
|
16870
20197
|
return {
|
|
16871
20198
|
documentContext: output?.documentContext ?? null
|
|
16872
20199
|
};
|
|
16873
20200
|
}),
|
|
16874
20201
|
// Store sheet IDs from startBridge result
|
|
16875
|
-
storeSheetIds:
|
|
20202
|
+
storeSheetIds: assign(({ event }) => {
|
|
16876
20203
|
const output = "output" in event ? event.output : void 0;
|
|
16877
20204
|
return {
|
|
16878
20205
|
initialSheetIds: output?.sheetIds ?? []
|
|
16879
20206
|
};
|
|
16880
20207
|
}),
|
|
16881
20208
|
// Store sheet IDs from hydrateXlsx result (replaces empty IDs from startBridge)
|
|
16882
|
-
storeHydrationSheetIds:
|
|
20209
|
+
storeHydrationSheetIds: assign(({ event }) => {
|
|
16883
20210
|
const output = "output" in event ? event.output : void 0;
|
|
16884
20211
|
return {
|
|
16885
20212
|
initialSheetIds: output?.sheetIds ?? []
|
|
16886
20213
|
};
|
|
16887
20214
|
}),
|
|
16888
20215
|
// Store error into context
|
|
16889
|
-
storeError:
|
|
20216
|
+
storeError: assign(({ event }) => {
|
|
16890
20217
|
const error = "error" in event ? event.error : event;
|
|
16891
20218
|
return {
|
|
16892
20219
|
error: KernelError.from(error, "DOC_LIFECYCLE_ERROR")
|
|
16893
20220
|
};
|
|
16894
20221
|
}),
|
|
16895
20222
|
// Clear all references on dispose
|
|
16896
|
-
clearResources:
|
|
20223
|
+
clearResources: assign(() => ({
|
|
16897
20224
|
computeBridge: null,
|
|
16898
20225
|
databaseBridge: null,
|
|
16899
20226
|
rustDocument: null,
|
|
@@ -17901,8 +21228,8 @@ function setSlicerSelection(slicer, values) {
|
|
|
17901
21228
|
function clearSlicerSelection(slicer) {
|
|
17902
21229
|
return getWasm().table_clear_slicer_selection(slicer);
|
|
17903
21230
|
}
|
|
17904
|
-
function selectAllSlicerValues(slicer,
|
|
17905
|
-
return getWasm().table_select_all_slicer_values(slicer,
|
|
21231
|
+
function selectAllSlicerValues(slicer, cache2) {
|
|
21232
|
+
return getWasm().table_select_all_slicer_values(slicer, cache2);
|
|
17906
21233
|
}
|
|
17907
21234
|
function slicerToFilterCriteria(slicer) {
|
|
17908
21235
|
return getWasm().table_slicer_to_filter_criteria(slicer);
|
|
@@ -70081,12 +73408,12 @@ function getClipboardServiceSnapshot(state) {
|
|
|
70081
73408
|
function createClipboardService() {
|
|
70082
73409
|
return new ClipboardService();
|
|
70083
73410
|
}
|
|
70084
|
-
var
|
|
73411
|
+
var initialContext2, clipboardServiceMachine, ClipboardService;
|
|
70085
73412
|
var init_clipboard_service = __esm({
|
|
70086
73413
|
"../../kernel/src/services/clipboard/clipboard-service.ts"() {
|
|
70087
73414
|
"use strict";
|
|
70088
73415
|
init_cjs_shims();
|
|
70089
|
-
|
|
73416
|
+
init_xstate_esm();
|
|
70090
73417
|
init_primitives3();
|
|
70091
73418
|
initialContext2 = {
|
|
70092
73419
|
payload: null,
|
|
@@ -70095,13 +73422,13 @@ var init_clipboard_service = __esm({
|
|
|
70095
73422
|
timestamp: null,
|
|
70096
73423
|
error: null
|
|
70097
73424
|
};
|
|
70098
|
-
clipboardServiceMachine =
|
|
73425
|
+
clipboardServiceMachine = setup({
|
|
70099
73426
|
types: {
|
|
70100
73427
|
context: {},
|
|
70101
73428
|
events: {}
|
|
70102
73429
|
},
|
|
70103
73430
|
actions: {
|
|
70104
|
-
storeCopyData:
|
|
73431
|
+
storeCopyData: assign(({ event }) => {
|
|
70105
73432
|
if (event.type !== "COPY") return {};
|
|
70106
73433
|
return {
|
|
70107
73434
|
payload: event.payload,
|
|
@@ -70111,7 +73438,7 @@ var init_clipboard_service = __esm({
|
|
|
70111
73438
|
error: null
|
|
70112
73439
|
};
|
|
70113
73440
|
}),
|
|
70114
|
-
storeCutData:
|
|
73441
|
+
storeCutData: assign(({ event }) => {
|
|
70115
73442
|
if (event.type !== "CUT") return {};
|
|
70116
73443
|
return {
|
|
70117
73444
|
payload: event.payload,
|
|
@@ -70121,33 +73448,33 @@ var init_clipboard_service = __esm({
|
|
|
70121
73448
|
error: null
|
|
70122
73449
|
};
|
|
70123
73450
|
}),
|
|
70124
|
-
clearAfterCut:
|
|
73451
|
+
clearAfterCut: assign(() => ({
|
|
70125
73452
|
payload: null,
|
|
70126
73453
|
operation: null,
|
|
70127
73454
|
isStale: false,
|
|
70128
73455
|
timestamp: null,
|
|
70129
73456
|
error: null
|
|
70130
73457
|
})),
|
|
70131
|
-
clearAll:
|
|
73458
|
+
clearAll: assign(() => ({
|
|
70132
73459
|
payload: null,
|
|
70133
73460
|
operation: null,
|
|
70134
73461
|
isStale: false,
|
|
70135
73462
|
timestamp: null,
|
|
70136
73463
|
error: null
|
|
70137
73464
|
})),
|
|
70138
|
-
storeError:
|
|
73465
|
+
storeError: assign(({ event }) => {
|
|
70139
73466
|
if (event.type !== "PASTE_ERROR") return {};
|
|
70140
73467
|
return {
|
|
70141
73468
|
error: event.message
|
|
70142
73469
|
};
|
|
70143
73470
|
}),
|
|
70144
|
-
clearError:
|
|
73471
|
+
clearError: assign(() => ({
|
|
70145
73472
|
error: null
|
|
70146
73473
|
})),
|
|
70147
|
-
markStale:
|
|
73474
|
+
markStale: assign(() => ({
|
|
70148
73475
|
isStale: true
|
|
70149
73476
|
})),
|
|
70150
|
-
markFresh:
|
|
73477
|
+
markFresh: assign(() => ({
|
|
70151
73478
|
isStale: false
|
|
70152
73479
|
}))
|
|
70153
73480
|
},
|
|
@@ -70268,7 +73595,7 @@ var init_clipboard_service = __esm({
|
|
|
70268
73595
|
ClipboardService = class extends Subscribable {
|
|
70269
73596
|
constructor() {
|
|
70270
73597
|
super();
|
|
70271
|
-
this.actor =
|
|
73598
|
+
this.actor = createActor(clipboardServiceMachine, {
|
|
70272
73599
|
inspect: (evt) => typeof window !== "undefined" && window.__OS_DEVTOOLS__?.reportActor("clipboardService", evt)
|
|
70273
73600
|
});
|
|
70274
73601
|
this.actor.subscribe(() => {
|
|
@@ -72734,12 +76061,12 @@ var init_kernel_context = __esm({
|
|
|
72734
76061
|
});
|
|
72735
76062
|
|
|
72736
76063
|
// ../../kernel/src/document/document-lifecycle-system.ts
|
|
72737
|
-
var
|
|
76064
|
+
var DeferredContext, DocumentLifecycleSystem;
|
|
72738
76065
|
var init_document_lifecycle_system = __esm({
|
|
72739
76066
|
"../../kernel/src/document/document-lifecycle-system.ts"() {
|
|
72740
76067
|
"use strict";
|
|
72741
76068
|
init_cjs_shims();
|
|
72742
|
-
|
|
76069
|
+
init_xstate_esm();
|
|
72743
76070
|
init_document();
|
|
72744
76071
|
init_document_lifecycle_machine();
|
|
72745
76072
|
DeferredContext = new Proxy({}, {
|
|
@@ -72766,24 +76093,24 @@ var init_document_lifecycle_system = __esm({
|
|
|
72766
76093
|
this.napiAddon = config?.napiAddon;
|
|
72767
76094
|
const machineWithActors = documentLifecycleMachine.provide({
|
|
72768
76095
|
actors: {
|
|
72769
|
-
createEngine:
|
|
76096
|
+
createEngine: fromPromise(
|
|
72770
76097
|
async ({ input }) => this.executeCreateEngine(input)
|
|
72771
76098
|
),
|
|
72772
|
-
wireContext:
|
|
76099
|
+
wireContext: fromPromise(
|
|
72773
76100
|
async ({ input }) => this.executeWireContext(input)
|
|
72774
76101
|
),
|
|
72775
|
-
startBridge:
|
|
76102
|
+
startBridge: fromPromise(
|
|
72776
76103
|
async ({ input }) => this.executeStartBridge(input)
|
|
72777
76104
|
),
|
|
72778
|
-
hydrateXlsx:
|
|
76105
|
+
hydrateXlsx: fromPromise(
|
|
72779
76106
|
async ({ input }) => this.executeHydrateXlsx(input)
|
|
72780
76107
|
),
|
|
72781
|
-
disposeBridge:
|
|
76108
|
+
disposeBridge: fromPromise(
|
|
72782
76109
|
async ({ input }) => this.executeDisposeBridge(input)
|
|
72783
76110
|
)
|
|
72784
76111
|
}
|
|
72785
76112
|
});
|
|
72786
|
-
this.actor =
|
|
76113
|
+
this.actor = createActor(machineWithActors, {
|
|
72787
76114
|
inspect: (evt) => {
|
|
72788
76115
|
if (typeof window !== "undefined")
|
|
72789
76116
|
window.__OS_DEVTOOLS__?.reportActor("documentLifecycle", evt);
|
|
@@ -83579,18 +86906,18 @@ var WorksheetImpl = class {
|
|
|
83579
86906
|
// ===========================================================================
|
|
83580
86907
|
get cellMetadata() {
|
|
83581
86908
|
if (!this._cellMetadata) {
|
|
83582
|
-
const
|
|
83583
|
-
this._rawCellMetadataCache =
|
|
83584
|
-
this.ctx.computeBridge.setCellMetadataCache(
|
|
86909
|
+
const cache2 = createCellMetadataCache(this.workbook);
|
|
86910
|
+
this._rawCellMetadataCache = cache2;
|
|
86911
|
+
this.ctx.computeBridge.setCellMetadataCache(cache2);
|
|
83585
86912
|
this._cellMetadata = {
|
|
83586
|
-
isProjectedPosition: (row, col) =>
|
|
83587
|
-
getProjectionSourcePosition: (row, col) =>
|
|
83588
|
-
getProjectionRange: (row, col) =>
|
|
83589
|
-
hasValidationErrors: (row, col) =>
|
|
83590
|
-
evaluateViewport: (sheetId, startRow, startCol, endRow, endCol) =>
|
|
83591
|
-
onChange: (callback) =>
|
|
83592
|
-
clear: () =>
|
|
83593
|
-
destroy: () =>
|
|
86913
|
+
isProjectedPosition: (row, col) => cache2.isProjectedPosition(row, col),
|
|
86914
|
+
getProjectionSourcePosition: (row, col) => cache2.getProjectionSourcePosition(row, col),
|
|
86915
|
+
getProjectionRange: (row, col) => cache2.getProjectionRange(row, col),
|
|
86916
|
+
hasValidationErrors: (row, col) => cache2.hasValidationErrors(row, col),
|
|
86917
|
+
evaluateViewport: (sheetId, startRow, startCol, endRow, endCol) => cache2.evaluateViewport(sheetId, startRow, startCol, endRow, endCol),
|
|
86918
|
+
onChange: (callback) => cache2.onChange(callback),
|
|
86919
|
+
clear: () => cache2.clear(),
|
|
86920
|
+
destroy: () => cache2.dispose()
|
|
83594
86921
|
};
|
|
83595
86922
|
}
|
|
83596
86923
|
return this._cellMetadata;
|
|
@@ -83758,8 +87085,8 @@ var WorkbookSheetsImpl = class {
|
|
|
83758
87085
|
return new WorksheetImpl(newSheetId, ctx, workbook, resolvedName);
|
|
83759
87086
|
}
|
|
83760
87087
|
async remove(target) {
|
|
83761
|
-
const { ctx, resolveTarget } = this.deps;
|
|
83762
|
-
const sheetId = await
|
|
87088
|
+
const { ctx, resolveTarget: resolveTarget2 } = this.deps;
|
|
87089
|
+
const sheetId = await resolveTarget2(target);
|
|
83763
87090
|
const deleted = await removeSheet(ctx, sheetId);
|
|
83764
87091
|
if (!deleted) {
|
|
83765
87092
|
throw new KernelError(
|
|
@@ -83769,31 +87096,31 @@ var WorkbookSheetsImpl = class {
|
|
|
83769
87096
|
}
|
|
83770
87097
|
}
|
|
83771
87098
|
async move(name, toIndex) {
|
|
83772
|
-
const { ctx, resolveTarget } = this.deps;
|
|
83773
|
-
const sheetId = await
|
|
87099
|
+
const { ctx, resolveTarget: resolveTarget2 } = this.deps;
|
|
87100
|
+
const sheetId = await resolveTarget2(name);
|
|
83774
87101
|
const moved = await moveSheet(ctx, sheetId, toIndex);
|
|
83775
87102
|
if (!moved) {
|
|
83776
87103
|
throw new KernelError("COMPUTE_ERROR", `Failed to move sheet "${name}" to index ${toIndex}.`);
|
|
83777
87104
|
}
|
|
83778
87105
|
}
|
|
83779
87106
|
async rename(target, newName) {
|
|
83780
|
-
const { ctx, resolveTarget, workbook } = this.deps;
|
|
83781
|
-
const sheetId = await
|
|
87107
|
+
const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
|
|
87108
|
+
const sheetId = await resolveTarget2(target);
|
|
83782
87109
|
await assertNameNotTaken(ctx, newName, sheetId);
|
|
83783
87110
|
await renameSheet(ctx, sheetId, newName);
|
|
83784
87111
|
await workbook.refreshSheetMetadata();
|
|
83785
87112
|
}
|
|
83786
87113
|
async setActive(target) {
|
|
83787
|
-
const { resolveTarget, setActiveSheetId, getSheetName, workbook } = this.deps;
|
|
83788
|
-
const sheetId = await
|
|
87114
|
+
const { resolveTarget: resolveTarget2, setActiveSheetId, getSheetName, workbook } = this.deps;
|
|
87115
|
+
const sheetId = await resolveTarget2(target);
|
|
83789
87116
|
const name = await getSheetName(sheetId);
|
|
83790
87117
|
workbook._getOrCreateWorksheet(sheetId, name);
|
|
83791
87118
|
setActiveSheetId(sheetId);
|
|
83792
87119
|
await workbook.refreshSheetMetadata();
|
|
83793
87120
|
}
|
|
83794
87121
|
async copy(source, newName) {
|
|
83795
|
-
const { ctx, resolveTarget, getSheetName, workbook } = this.deps;
|
|
83796
|
-
const sourceId = await
|
|
87122
|
+
const { ctx, resolveTarget: resolveTarget2, getSheetName, workbook } = this.deps;
|
|
87123
|
+
const sourceId = await resolveTarget2(source);
|
|
83797
87124
|
const sourceName = await getSheetName(sourceId);
|
|
83798
87125
|
const copyName = newName ?? `${sourceName ?? "Sheet"} (Copy)`;
|
|
83799
87126
|
const newSheetId = await copySheet(ctx, sourceId, copyName);
|
|
@@ -83803,8 +87130,8 @@ var WorkbookSheetsImpl = class {
|
|
|
83803
87130
|
return new WorksheetImpl(newSheetId, ctx, workbook, copyName);
|
|
83804
87131
|
}
|
|
83805
87132
|
async hide(target) {
|
|
83806
|
-
const { ctx, resolveTarget, workbook } = this.deps;
|
|
83807
|
-
const sheetId = await
|
|
87133
|
+
const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
|
|
87134
|
+
const sheetId = await resolveTarget2(target);
|
|
83808
87135
|
const success = await setSheetHidden(ctx, sheetId, true);
|
|
83809
87136
|
if (!success) {
|
|
83810
87137
|
throw new KernelError(
|
|
@@ -83815,8 +87142,8 @@ var WorkbookSheetsImpl = class {
|
|
|
83815
87142
|
await workbook.refreshSheetMetadata();
|
|
83816
87143
|
}
|
|
83817
87144
|
async show(target) {
|
|
83818
|
-
const { ctx, resolveTarget, workbook } = this.deps;
|
|
83819
|
-
const sheetId = await
|
|
87145
|
+
const { ctx, resolveTarget: resolveTarget2, workbook } = this.deps;
|
|
87146
|
+
const sheetId = await resolveTarget2(target);
|
|
83820
87147
|
const success = await setSheetHidden(ctx, sheetId, false);
|
|
83821
87148
|
if (!success) {
|
|
83822
87149
|
throw new KernelError("COMPUTE_ERROR", `Failed to show sheet.`);
|