@zag-js/tabs 0.0.0-dev-20220413175519 → 0.0.0-dev-20220416152643
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.js +46 -794
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +45 -793
- package/dist/index.mjs.map +3 -3
- package/dist/tabs.dom.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -18,7 +16,6 @@ var __spreadValues = (a, b) => {
|
|
|
18
16
|
}
|
|
19
17
|
return a;
|
|
20
18
|
};
|
|
21
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
19
|
var __export = (target, all) => {
|
|
23
20
|
for (var name in all)
|
|
24
21
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -41,101 +38,47 @@ __export(src_exports, {
|
|
|
41
38
|
});
|
|
42
39
|
module.exports = __toCommonJS(src_exports);
|
|
43
40
|
|
|
44
|
-
// ../../utilities/dom/
|
|
41
|
+
// ../../utilities/dom/dist/index.mjs
|
|
45
42
|
var dataAttr = (guard) => {
|
|
46
43
|
return guard ? "" : void 0;
|
|
47
44
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
function getStyleCache() {
|
|
46
|
+
;
|
|
47
|
+
globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap();
|
|
48
|
+
return globalThis.__styleCache__;
|
|
49
|
+
}
|
|
50
|
+
function getComputedStyle2(el) {
|
|
52
51
|
var _a;
|
|
53
52
|
if (!el)
|
|
54
53
|
return {};
|
|
55
|
-
|
|
54
|
+
const cache = getStyleCache();
|
|
55
|
+
let style = cache.get(el);
|
|
56
56
|
if (!style) {
|
|
57
57
|
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
58
58
|
style = win.getComputedStyle(el);
|
|
59
|
-
|
|
59
|
+
cache.set(el, style);
|
|
60
60
|
}
|
|
61
61
|
return style;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
65
63
|
function nextTick(fn) {
|
|
66
64
|
const set = /* @__PURE__ */ new Set();
|
|
67
|
-
function
|
|
65
|
+
function raf2(fn2) {
|
|
68
66
|
const id = globalThis.requestAnimationFrame(fn2);
|
|
69
67
|
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
70
68
|
}
|
|
71
|
-
|
|
69
|
+
raf2(() => raf2(fn));
|
|
72
70
|
return function cleanup() {
|
|
73
71
|
set.forEach(function(fn2) {
|
|
74
72
|
fn2();
|
|
75
73
|
});
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
|
-
|
|
79
|
-
// ../../utilities/core/src/array.ts
|
|
80
|
-
var first = (v) => v[0];
|
|
81
|
-
var last = (v) => v[v.length - 1];
|
|
82
|
-
function clear(v) {
|
|
83
|
-
while (v.length > 0)
|
|
84
|
-
v.pop();
|
|
85
|
-
return v;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ../../utilities/core/src/functions.ts
|
|
89
|
-
var runIfFn = (v, ...a) => {
|
|
90
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
91
|
-
return res != null ? res : void 0;
|
|
92
|
-
};
|
|
93
|
-
var cast = (v) => v;
|
|
94
|
-
var noop = () => {
|
|
95
|
-
};
|
|
96
|
-
var uuid = /* @__PURE__ */ (() => {
|
|
97
|
-
let id = 0;
|
|
98
|
-
return () => {
|
|
99
|
-
id++;
|
|
100
|
-
return id.toString(36);
|
|
101
|
-
};
|
|
102
|
-
})();
|
|
103
|
-
|
|
104
|
-
// ../../utilities/core/src/guard.ts
|
|
105
|
-
var ua = (v) => isDom() && v.test(navigator.userAgent);
|
|
106
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
107
|
-
var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
|
|
108
|
-
var isArray = (v) => Array.isArray(v);
|
|
109
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
110
|
-
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
111
|
-
var isString = (v) => typeof v === "string";
|
|
112
|
-
var isFunction = (v) => typeof v === "function";
|
|
113
|
-
|
|
114
|
-
// ../../utilities/core/src/warning.ts
|
|
115
|
-
function warn(...a) {
|
|
116
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
117
|
-
const c = a.length === 2 ? a[0] : true;
|
|
118
|
-
if (c && void 0 !== "production") {
|
|
119
|
-
console.warn(m);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function invariant(...a) {
|
|
123
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
124
|
-
const c = a.length === 2 ? a[0] : true;
|
|
125
|
-
if (c && void 0 !== "production") {
|
|
126
|
-
throw new Error(m);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ../../utilities/dom/src/query.ts
|
|
131
76
|
function isHTMLElement(v) {
|
|
132
77
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
133
78
|
}
|
|
134
79
|
var isDisabled = (el) => {
|
|
135
80
|
return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
|
|
136
81
|
};
|
|
137
|
-
|
|
138
|
-
// ../../utilities/dom/src/focusable.ts
|
|
139
82
|
var focusableSelector = /* @__PURE__ */ [
|
|
140
83
|
"input:not([disabled]):not([type=hidden])",
|
|
141
84
|
"select:not([disabled])",
|
|
@@ -154,7 +97,7 @@ var focusableSelector = /* @__PURE__ */ [
|
|
|
154
97
|
"details > summary:first-of-type"
|
|
155
98
|
].join(",");
|
|
156
99
|
function isHidden(el, until) {
|
|
157
|
-
const style =
|
|
100
|
+
const style = getComputedStyle2(el);
|
|
158
101
|
if (!el || style.getPropertyValue("visibility") === "hidden")
|
|
159
102
|
return true;
|
|
160
103
|
while (el) {
|
|
@@ -180,8 +123,6 @@ var isFocusable = (el) => {
|
|
|
180
123
|
return false;
|
|
181
124
|
return el == null ? void 0 : el.matches(focusableSelector);
|
|
182
125
|
};
|
|
183
|
-
|
|
184
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
185
126
|
var rtlKeyMap = {
|
|
186
127
|
ArrowLeft: "ArrowRight",
|
|
187
128
|
ArrowRight: "ArrowLeft",
|
|
@@ -208,8 +149,6 @@ function getEventKey(event, options = {}) {
|
|
|
208
149
|
}
|
|
209
150
|
return key;
|
|
210
151
|
}
|
|
211
|
-
|
|
212
|
-
// ../../utilities/dom/src/nodelist.ts
|
|
213
152
|
function queryAll(root, selector) {
|
|
214
153
|
var _a;
|
|
215
154
|
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []);
|
|
@@ -234,12 +173,19 @@ function prevById(v, id, loop = true) {
|
|
|
234
173
|
return v[idx];
|
|
235
174
|
}
|
|
236
175
|
|
|
237
|
-
// ../../types/
|
|
176
|
+
// ../../types/dist/index.mjs
|
|
238
177
|
function createNormalizer(fn) {
|
|
239
178
|
return { button: fn, label: fn, input: fn, output: fn, element: fn };
|
|
240
179
|
}
|
|
241
180
|
var normalizeProp = createNormalizer((v) => v);
|
|
242
181
|
|
|
182
|
+
// ../../utilities/core/dist/index.mjs
|
|
183
|
+
var first = (v) => v[0];
|
|
184
|
+
var last = (v) => v[v.length - 1];
|
|
185
|
+
var ua = (v) => isDom() && v.test(navigator.userAgent);
|
|
186
|
+
var isDom = () => !!(typeof window !== "undefined");
|
|
187
|
+
var isSafari = () => ua(/^((?!chrome|android).)*safari/i);
|
|
188
|
+
|
|
243
189
|
// src/tabs.dom.ts
|
|
244
190
|
var dom = {
|
|
245
191
|
getDoc: (ctx) => {
|
|
@@ -248,25 +194,25 @@ var dom = {
|
|
|
248
194
|
},
|
|
249
195
|
getRootId: (ctx) => {
|
|
250
196
|
var _a, _b;
|
|
251
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs
|
|
197
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.root) != null ? _b : `tabs:${ctx.uid}`;
|
|
252
198
|
},
|
|
253
199
|
getTriggerGroupId: (ctx) => {
|
|
254
200
|
var _a, _b;
|
|
255
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs
|
|
201
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.triggerGroup) != null ? _b : `tabs:${ctx.uid}:trigger-group`;
|
|
256
202
|
},
|
|
257
203
|
getContentId: (ctx, id) => {
|
|
258
204
|
var _a, _b;
|
|
259
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs
|
|
205
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `tabs:${ctx.uid}:content-${id}`;
|
|
260
206
|
},
|
|
261
207
|
getContentGroupId: (ctx) => {
|
|
262
208
|
var _a, _b;
|
|
263
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs
|
|
209
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.contentGroup) != null ? _b : `tabs:${ctx.uid}:content-group`;
|
|
264
210
|
},
|
|
265
211
|
getTriggerId: (ctx, id) => {
|
|
266
212
|
var _a, _b;
|
|
267
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs
|
|
213
|
+
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `tabs:${ctx.uid}:trigger-${id}`;
|
|
268
214
|
},
|
|
269
|
-
getIndicatorId: (ctx) => `tabs
|
|
215
|
+
getIndicatorId: (ctx) => `tabs:${ctx.uid}:indicator`,
|
|
270
216
|
getTriggerGroupEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getTriggerGroupId(ctx)),
|
|
271
217
|
getContentEl: (ctx, id) => dom.getDoc(ctx).getElementById(dom.getContentId(ctx, id)),
|
|
272
218
|
getTriggerEl: (ctx, id) => dom.getDoc(ctx).getElementById(dom.getTriggerId(ctx, id)),
|
|
@@ -282,12 +228,23 @@ var dom = {
|
|
|
282
228
|
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
283
229
|
getRectById: (ctx, id) => {
|
|
284
230
|
var _a;
|
|
285
|
-
const empty = {
|
|
231
|
+
const empty = {
|
|
232
|
+
offsetLeft: 0,
|
|
233
|
+
offsetTop: 0,
|
|
234
|
+
offsetWidth: 0,
|
|
235
|
+
offsetHeight: 0
|
|
236
|
+
};
|
|
286
237
|
const tab = (_a = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id))) != null ? _a : empty;
|
|
287
238
|
if (ctx.isVertical) {
|
|
288
|
-
return {
|
|
239
|
+
return {
|
|
240
|
+
top: `${tab.offsetTop}px`,
|
|
241
|
+
height: `${tab.offsetHeight}px`
|
|
242
|
+
};
|
|
289
243
|
}
|
|
290
|
-
return {
|
|
244
|
+
return {
|
|
245
|
+
left: `${tab.offsetLeft}px`,
|
|
246
|
+
width: `${tab.offsetWidth}px`
|
|
247
|
+
};
|
|
291
248
|
},
|
|
292
249
|
getActiveContentEl: (ctx) => {
|
|
293
250
|
if (!ctx.value)
|
|
@@ -439,715 +396,10 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
439
396
|
};
|
|
440
397
|
}
|
|
441
398
|
|
|
442
|
-
// ../../../node_modules/@zag-js/core/src/index.ts
|
|
443
|
-
var import_vanilla3 = require("valtio/vanilla");
|
|
444
|
-
|
|
445
|
-
// ../../core/src/action-utils.ts
|
|
446
|
-
function isGuardHelper(value) {
|
|
447
|
-
return isObject(value) && value.predicate != null;
|
|
448
|
-
}
|
|
449
|
-
function determineActionsFn(values, guardMap) {
|
|
450
|
-
return (context, event) => {
|
|
451
|
-
if (isGuardHelper(values))
|
|
452
|
-
return values.predicate(guardMap != null ? guardMap : {})(context, event);
|
|
453
|
-
return values;
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// ../../core/src/guard-utils.ts
|
|
458
|
-
function or(...conditions) {
|
|
459
|
-
return {
|
|
460
|
-
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
|
|
461
|
-
var _a;
|
|
462
|
-
if (isString(condition)) {
|
|
463
|
-
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
|
|
464
|
-
}
|
|
465
|
-
if (isFunction(condition)) {
|
|
466
|
-
return condition(ctx, event);
|
|
467
|
-
}
|
|
468
|
-
return condition.predicate(guards2)(ctx, event);
|
|
469
|
-
}).some(Boolean)
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
function and(...conditions) {
|
|
473
|
-
return {
|
|
474
|
-
predicate: (guards2) => (ctx, event) => conditions.map((condition) => {
|
|
475
|
-
var _a;
|
|
476
|
-
if (isString(condition)) {
|
|
477
|
-
return !!((_a = guards2[condition]) == null ? void 0 : _a.call(guards2, ctx, event));
|
|
478
|
-
}
|
|
479
|
-
if (isFunction(condition)) {
|
|
480
|
-
return condition(ctx, event);
|
|
481
|
-
}
|
|
482
|
-
return condition.predicate(guards2)(ctx, event);
|
|
483
|
-
}).every(Boolean)
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
function not(condition) {
|
|
487
|
-
return {
|
|
488
|
-
predicate: (guardMap) => (ctx, event) => {
|
|
489
|
-
var _a;
|
|
490
|
-
if (isString(condition)) {
|
|
491
|
-
return !((_a = guardMap[condition]) == null ? void 0 : _a.call(guardMap, ctx, event));
|
|
492
|
-
}
|
|
493
|
-
if (isFunction(condition)) {
|
|
494
|
-
return !condition(ctx, event);
|
|
495
|
-
}
|
|
496
|
-
return !condition.predicate(guardMap)(ctx, event);
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
var guards = { or, and, not };
|
|
501
|
-
function isGuardHelper2(value) {
|
|
502
|
-
return isObject(value) && value.predicate != null;
|
|
503
|
-
}
|
|
504
|
-
var TruthyGuard = () => true;
|
|
505
|
-
function determineGuardFn(guard, guardMap) {
|
|
506
|
-
guard = guard != null ? guard : TruthyGuard;
|
|
507
|
-
return (context, event) => {
|
|
508
|
-
if (isString(guard)) {
|
|
509
|
-
const value = guardMap == null ? void 0 : guardMap[guard];
|
|
510
|
-
return isFunction(value) ? value(context, event) : value;
|
|
511
|
-
}
|
|
512
|
-
if (isGuardHelper2(guard)) {
|
|
513
|
-
return guard.predicate(guardMap != null ? guardMap : {})(context, event);
|
|
514
|
-
}
|
|
515
|
-
return guard == null ? void 0 : guard(context, event);
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// ../../../node_modules/klona/json/index.mjs
|
|
520
|
-
function klona(val) {
|
|
521
|
-
var k, out, tmp;
|
|
522
|
-
if (Array.isArray(val)) {
|
|
523
|
-
out = Array(k = val.length);
|
|
524
|
-
while (k--)
|
|
525
|
-
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
526
|
-
return out;
|
|
527
|
-
}
|
|
528
|
-
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
529
|
-
out = {};
|
|
530
|
-
for (k in val) {
|
|
531
|
-
if (k === "__proto__") {
|
|
532
|
-
Object.defineProperty(out, k, {
|
|
533
|
-
value: klona(val[k]),
|
|
534
|
-
configurable: true,
|
|
535
|
-
enumerable: true,
|
|
536
|
-
writable: true
|
|
537
|
-
});
|
|
538
|
-
} else {
|
|
539
|
-
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
return out;
|
|
543
|
-
}
|
|
544
|
-
return val;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// ../../core/src/machine.ts
|
|
548
|
-
var import_utils11 = require("valtio/utils");
|
|
549
|
-
var import_vanilla2 = require("valtio/vanilla");
|
|
550
|
-
|
|
551
|
-
// ../../core/src/create-proxy.ts
|
|
552
|
-
var import_vanilla = require("valtio/vanilla");
|
|
553
|
-
function createProxy(config) {
|
|
554
|
-
var _a;
|
|
555
|
-
const state = (0, import_vanilla.proxy)({
|
|
556
|
-
value: "",
|
|
557
|
-
previousValue: "",
|
|
558
|
-
event: cast({}),
|
|
559
|
-
context: (_a = config.context) != null ? _a : cast({}),
|
|
560
|
-
done: false,
|
|
561
|
-
tags: [],
|
|
562
|
-
hasTag(tag) {
|
|
563
|
-
return this.tags.includes(tag);
|
|
564
|
-
},
|
|
565
|
-
matches(...value) {
|
|
566
|
-
return value.includes(this.value);
|
|
567
|
-
},
|
|
568
|
-
can(event) {
|
|
569
|
-
return cast(this).nextEvents.includes(event);
|
|
570
|
-
},
|
|
571
|
-
get nextEvents() {
|
|
572
|
-
var _a2, _b, _c, _d;
|
|
573
|
-
const stateEvents = (_c = (_b = (_a2 = config.states) == null ? void 0 : _a2[this.value]) == null ? void 0 : _b["on"]) != null ? _c : {};
|
|
574
|
-
const globalEvents = (_d = config == null ? void 0 : config.on) != null ? _d : {};
|
|
575
|
-
return Object.keys(__spreadValues(__spreadValues({}, stateEvents), globalEvents));
|
|
576
|
-
},
|
|
577
|
-
get changed() {
|
|
578
|
-
if (this.event.value === "machine.init" /* Init */ || !this.previousValue)
|
|
579
|
-
return false;
|
|
580
|
-
return this.value !== this.previousValue;
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return cast(state);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// ../../core/src/delay-utils.ts
|
|
587
|
-
function determineDelayFn(delay, delaysMap) {
|
|
588
|
-
return (context, event) => {
|
|
589
|
-
if (isNumber(delay))
|
|
590
|
-
return delay;
|
|
591
|
-
if (isFunction(delay)) {
|
|
592
|
-
return delay(context, event);
|
|
593
|
-
}
|
|
594
|
-
if (isString(delay)) {
|
|
595
|
-
const value = Number.parseFloat(delay);
|
|
596
|
-
if (!Number.isNaN(value)) {
|
|
597
|
-
return value;
|
|
598
|
-
}
|
|
599
|
-
if (delaysMap) {
|
|
600
|
-
const valueOrFn = delaysMap == null ? void 0 : delaysMap[delay];
|
|
601
|
-
if (valueOrFn == null) {
|
|
602
|
-
const msg = `[machine] Cannot determine delay for ${delay}. It doesn't exist in options.delays`;
|
|
603
|
-
throw new Error(msg);
|
|
604
|
-
}
|
|
605
|
-
return isFunction(valueOrFn) ? valueOrFn(context, event) : valueOrFn;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// ../../core/src/utils.ts
|
|
612
|
-
function toEvent(event) {
|
|
613
|
-
const obj = isString(event) ? { type: event } : event;
|
|
614
|
-
return obj;
|
|
615
|
-
}
|
|
616
|
-
function toArray(value) {
|
|
617
|
-
if (!value)
|
|
618
|
-
return [];
|
|
619
|
-
return isArray(value) ? value : [value];
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// ../../core/src/transition-utils.ts
|
|
623
|
-
function toTarget(target) {
|
|
624
|
-
return isString(target) ? { target } : target;
|
|
625
|
-
}
|
|
626
|
-
function determineTransitionFn(transitions, guardMap) {
|
|
627
|
-
return (context, event) => {
|
|
628
|
-
return toArray(transitions).map(toTarget).find((transition) => {
|
|
629
|
-
var _a;
|
|
630
|
-
const determineGuard = determineGuardFn(transition.guard, guardMap);
|
|
631
|
-
const guard = determineGuard(context, event);
|
|
632
|
-
return (_a = guard != null ? guard : transition.target) != null ? _a : transition.actions;
|
|
633
|
-
});
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
function toTransition(transition, current) {
|
|
637
|
-
const _transition = isString(transition) ? toTarget(transition) : transition;
|
|
638
|
-
const fn = (t) => {
|
|
639
|
-
const isTargetless = t.actions && !t.target;
|
|
640
|
-
if (isTargetless && current)
|
|
641
|
-
t.target = current;
|
|
642
|
-
return t;
|
|
643
|
-
};
|
|
644
|
-
if (isArray(_transition)) {
|
|
645
|
-
return _transition.map(fn);
|
|
646
|
-
}
|
|
647
|
-
if (isObject(_transition)) {
|
|
648
|
-
return fn(cast(_transition));
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// ../../core/src/machine.ts
|
|
653
|
-
var Machine = class {
|
|
654
|
-
constructor(config, options) {
|
|
655
|
-
this.config = config;
|
|
656
|
-
this.status = "Not Started" /* NotStarted */;
|
|
657
|
-
this.type = "machine" /* Machine */;
|
|
658
|
-
this.activityEvents = /* @__PURE__ */ new Map();
|
|
659
|
-
this.delayedEvents = /* @__PURE__ */ new Map();
|
|
660
|
-
this.stateListeners = /* @__PURE__ */ new Set();
|
|
661
|
-
this.eventListeners = /* @__PURE__ */ new Set();
|
|
662
|
-
this.doneListeners = /* @__PURE__ */ new Set();
|
|
663
|
-
this.contextWatchers = /* @__PURE__ */ new Set();
|
|
664
|
-
this.removeStateListener = noop;
|
|
665
|
-
this.removeEventListener = noop;
|
|
666
|
-
this.children = /* @__PURE__ */ new Map();
|
|
667
|
-
this.start = (init) => {
|
|
668
|
-
if (this.status === "Running" /* Running */) {
|
|
669
|
-
return this;
|
|
670
|
-
}
|
|
671
|
-
this.status = "Running" /* Running */;
|
|
672
|
-
const event = toEvent("machine.init" /* Init */);
|
|
673
|
-
if (init) {
|
|
674
|
-
const resolved = isObject(init) ? init : { context: this.config.context, value: init };
|
|
675
|
-
this.setState(resolved.value);
|
|
676
|
-
this.setContext(resolved.context);
|
|
677
|
-
}
|
|
678
|
-
const transition = {
|
|
679
|
-
target: !!init ? void 0 : this.config.initial
|
|
680
|
-
};
|
|
681
|
-
const info = this.getNextStateInfo(transition, event);
|
|
682
|
-
info.target = cast(info.target || transition.target);
|
|
683
|
-
this.initialState = info;
|
|
684
|
-
this.performStateChangeEffects(info.target, info, event);
|
|
685
|
-
this.removeStateListener = (0, import_vanilla2.subscribe)(this.state, () => {
|
|
686
|
-
this.stateListeners.forEach((listener) => {
|
|
687
|
-
listener(this.stateSnapshot);
|
|
688
|
-
});
|
|
689
|
-
}, this.sync);
|
|
690
|
-
this.removeEventListener = (0, import_utils11.subscribeKey)(this.state, "event", (value) => {
|
|
691
|
-
if (this.config.onEvent) {
|
|
692
|
-
this.executeActions(this.config.onEvent, value);
|
|
693
|
-
}
|
|
694
|
-
for (const listener of this.eventListeners) {
|
|
695
|
-
listener(value);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
this.setupContextWatchers();
|
|
699
|
-
this.executeActivities(toEvent("machine.start" /* Start */), toArray(this.config.activities), "machine.start" /* Start */);
|
|
700
|
-
this.executeActions(this.config.entry, toEvent("machine.start" /* Start */));
|
|
701
|
-
return this;
|
|
702
|
-
};
|
|
703
|
-
this.setupContextWatchers = () => {
|
|
704
|
-
var _a;
|
|
705
|
-
for (const [key, fn] of Object.entries((_a = this.config.watch) != null ? _a : {})) {
|
|
706
|
-
this.contextWatchers.add((0, import_utils11.subscribeKey)(this.state.context, key, () => {
|
|
707
|
-
this.executeActions(fn, this.state.event);
|
|
708
|
-
}));
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
this.setupComputed = () => {
|
|
712
|
-
var _a;
|
|
713
|
-
const computed = cast((_a = this.config.computed) != null ? _a : {});
|
|
714
|
-
const deriveFns = Object.fromEntries(Object.entries(computed).map(([key, fn]) => [key, (get) => fn(get(this.state.context))]));
|
|
715
|
-
(0, import_utils11.derive)(deriveFns, { proxy: this.state.context });
|
|
716
|
-
};
|
|
717
|
-
this.detachComputed = () => {
|
|
718
|
-
(0, import_utils11.underive)(this.state.context, { delete: true });
|
|
719
|
-
};
|
|
720
|
-
this.stop = () => {
|
|
721
|
-
if (this.status === "Stopped" /* Stopped */)
|
|
722
|
-
return;
|
|
723
|
-
this.setState(null);
|
|
724
|
-
this.setEvent("machine.stop" /* Stop */);
|
|
725
|
-
if (this.config.context) {
|
|
726
|
-
this.setContext(this.config.context);
|
|
727
|
-
}
|
|
728
|
-
this.stopStateListeners();
|
|
729
|
-
this.stopChildren();
|
|
730
|
-
this.stopActivities();
|
|
731
|
-
this.stopDelayedEvents();
|
|
732
|
-
this.stopContextWatchers();
|
|
733
|
-
this.stopEventListeners();
|
|
734
|
-
this.detachComputed();
|
|
735
|
-
this.status = "Stopped" /* Stopped */;
|
|
736
|
-
this.executeActions(this.config.exit, toEvent("machine.stop" /* Stop */));
|
|
737
|
-
return this;
|
|
738
|
-
};
|
|
739
|
-
this.stopEventListeners = () => {
|
|
740
|
-
this.eventListeners.clear();
|
|
741
|
-
this.removeEventListener();
|
|
742
|
-
};
|
|
743
|
-
this.stopStateListeners = () => {
|
|
744
|
-
this.removeStateListener();
|
|
745
|
-
this.stateListeners.clear();
|
|
746
|
-
};
|
|
747
|
-
this.stopContextWatchers = () => {
|
|
748
|
-
this.contextWatchers.forEach((fn) => fn());
|
|
749
|
-
this.contextWatchers.clear();
|
|
750
|
-
};
|
|
751
|
-
this.stopDelayedEvents = () => {
|
|
752
|
-
this.delayedEvents.forEach((state) => {
|
|
753
|
-
state.forEach((stop) => stop());
|
|
754
|
-
});
|
|
755
|
-
this.delayedEvents.clear();
|
|
756
|
-
};
|
|
757
|
-
this.stopActivities = (state) => {
|
|
758
|
-
var _a, _b;
|
|
759
|
-
if (state) {
|
|
760
|
-
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.forEach((stop) => stop());
|
|
761
|
-
(_b = this.activityEvents.get(state)) == null ? void 0 : _b.clear();
|
|
762
|
-
this.activityEvents.delete(state);
|
|
763
|
-
} else {
|
|
764
|
-
this.activityEvents.forEach((state2) => {
|
|
765
|
-
state2.forEach((stop) => stop());
|
|
766
|
-
state2.clear();
|
|
767
|
-
});
|
|
768
|
-
this.activityEvents.clear();
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
this.sendChild = (evt, to) => {
|
|
772
|
-
const event = toEvent(evt);
|
|
773
|
-
const id = runIfFn(to, this.contextSnapshot);
|
|
774
|
-
const child = this.children.get(id);
|
|
775
|
-
if (!child) {
|
|
776
|
-
invariant(`[machine/send-child] Cannot send '${event.type}' event to unknown child`);
|
|
777
|
-
}
|
|
778
|
-
child.send(event);
|
|
779
|
-
};
|
|
780
|
-
this.stopChild = (id) => {
|
|
781
|
-
if (!this.children.has(id)) {
|
|
782
|
-
invariant("[machine/stop-child] Cannot stop unknown child");
|
|
783
|
-
}
|
|
784
|
-
this.children.get(id).stop();
|
|
785
|
-
this.children.delete(id);
|
|
786
|
-
};
|
|
787
|
-
this.removeChild = (id) => {
|
|
788
|
-
this.children.delete(id);
|
|
789
|
-
};
|
|
790
|
-
this.stopChildren = () => {
|
|
791
|
-
this.children.forEach((child) => child.stop());
|
|
792
|
-
this.children.clear();
|
|
793
|
-
};
|
|
794
|
-
this.setParent = (parent) => {
|
|
795
|
-
this.parent = parent;
|
|
796
|
-
};
|
|
797
|
-
this.spawn = (src, id) => {
|
|
798
|
-
const actor = runIfFn(src);
|
|
799
|
-
if (id)
|
|
800
|
-
actor.id = id;
|
|
801
|
-
actor.type = "machine.actor" /* Actor */;
|
|
802
|
-
actor.setParent(this);
|
|
803
|
-
this.children.set(actor.id, cast(actor));
|
|
804
|
-
actor.onDone(() => {
|
|
805
|
-
this.removeChild(actor.id);
|
|
806
|
-
}).start();
|
|
807
|
-
return cast((0, import_vanilla2.ref)(actor));
|
|
808
|
-
};
|
|
809
|
-
this.addActivityCleanup = (state, cleanup) => {
|
|
810
|
-
var _a;
|
|
811
|
-
if (!state)
|
|
812
|
-
return;
|
|
813
|
-
if (!this.activityEvents.has(state)) {
|
|
814
|
-
this.activityEvents.set(state, /* @__PURE__ */ new Set([cleanup]));
|
|
815
|
-
} else {
|
|
816
|
-
(_a = this.activityEvents.get(state)) == null ? void 0 : _a.add(cleanup);
|
|
817
|
-
}
|
|
818
|
-
};
|
|
819
|
-
this.setState = (target) => {
|
|
820
|
-
this.state.previousValue = this.state.value;
|
|
821
|
-
this.state.value = target;
|
|
822
|
-
const stateNode = this.getStateNode(target);
|
|
823
|
-
if (target == null) {
|
|
824
|
-
clear(this.state.tags);
|
|
825
|
-
} else {
|
|
826
|
-
this.state.tags = toArray(stateNode == null ? void 0 : stateNode.tags);
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
this.setContext = (context) => {
|
|
830
|
-
for (const key in context) {
|
|
831
|
-
this.state.context[key] = context[key];
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
this.withContext = (context) => {
|
|
835
|
-
this.detachComputed();
|
|
836
|
-
const newContext = __spreadValues(__spreadValues({}, this.config.context), context);
|
|
837
|
-
return new Machine(__spreadProps(__spreadValues({}, this.config), { context: newContext }), this.options);
|
|
838
|
-
};
|
|
839
|
-
this.withOptions = (options) => {
|
|
840
|
-
this.detachComputed();
|
|
841
|
-
return new Machine(this.config, __spreadValues(__spreadValues({}, this.options), options));
|
|
842
|
-
};
|
|
843
|
-
this.setActions = (actions) => {
|
|
844
|
-
this.actionMap = __spreadValues(__spreadValues({}, this.actionMap), actions);
|
|
845
|
-
};
|
|
846
|
-
this.clone = () => {
|
|
847
|
-
this.detachComputed();
|
|
848
|
-
return new Machine(this.config, this.options);
|
|
849
|
-
};
|
|
850
|
-
this.getStateNode = (state) => {
|
|
851
|
-
var _a;
|
|
852
|
-
if (!state)
|
|
853
|
-
return;
|
|
854
|
-
return (_a = this.config.states) == null ? void 0 : _a[state];
|
|
855
|
-
};
|
|
856
|
-
this.getNextStateInfo = (transitions, event) => {
|
|
857
|
-
var _a;
|
|
858
|
-
const transition = this.determineTransition(transitions, event);
|
|
859
|
-
const target = (_a = transition == null ? void 0 : transition.target) != null ? _a : this.state.value;
|
|
860
|
-
const stateNode = this.getStateNode(target);
|
|
861
|
-
return {
|
|
862
|
-
transition,
|
|
863
|
-
stateNode,
|
|
864
|
-
target
|
|
865
|
-
};
|
|
866
|
-
};
|
|
867
|
-
this.getActionFromDelayedTransition = (transition) => {
|
|
868
|
-
const event = toEvent("machine.after" /* After */);
|
|
869
|
-
const determineDelay = determineDelayFn(transition.delay, this.delayMap);
|
|
870
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
871
|
-
let id;
|
|
872
|
-
return {
|
|
873
|
-
entry: () => {
|
|
874
|
-
id = globalThis.setTimeout(() => {
|
|
875
|
-
const current = this.state.value;
|
|
876
|
-
const next = this.getNextStateInfo(transition, event);
|
|
877
|
-
this.performStateChangeEffects(current, next, event);
|
|
878
|
-
}, delay);
|
|
879
|
-
},
|
|
880
|
-
exit: () => {
|
|
881
|
-
globalThis.clearTimeout(id);
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
};
|
|
885
|
-
this.getDelayedEventActions = (state) => {
|
|
886
|
-
const stateNode = this.getStateNode(state);
|
|
887
|
-
const event = toEvent("machine.after" /* After */);
|
|
888
|
-
if (!stateNode || !stateNode.after)
|
|
889
|
-
return;
|
|
890
|
-
const entries = [];
|
|
891
|
-
const exits = [];
|
|
892
|
-
if (isArray(stateNode.after)) {
|
|
893
|
-
const transition = this.determineTransition(stateNode.after, event);
|
|
894
|
-
if (!transition)
|
|
895
|
-
return;
|
|
896
|
-
const actions = this.getActionFromDelayedTransition(transition);
|
|
897
|
-
entries.push(actions.entry);
|
|
898
|
-
exits.push(actions.exit);
|
|
899
|
-
} else if (isObject(stateNode.after)) {
|
|
900
|
-
for (const delay in stateNode.after) {
|
|
901
|
-
const transition = stateNode.after[delay];
|
|
902
|
-
let resolvedTransition = {};
|
|
903
|
-
if (isArray(transition)) {
|
|
904
|
-
const picked = this.determineTransition(transition, event);
|
|
905
|
-
if (picked)
|
|
906
|
-
resolvedTransition = picked;
|
|
907
|
-
} else if (isString(transition)) {
|
|
908
|
-
resolvedTransition = { target: transition, delay };
|
|
909
|
-
} else {
|
|
910
|
-
resolvedTransition = __spreadProps(__spreadValues({}, transition), { delay });
|
|
911
|
-
}
|
|
912
|
-
const actions = this.getActionFromDelayedTransition(resolvedTransition);
|
|
913
|
-
entries.push(actions.entry);
|
|
914
|
-
exits.push(actions.exit);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
return { entries, exits };
|
|
918
|
-
};
|
|
919
|
-
this.executeActions = (actions, event) => {
|
|
920
|
-
var _a;
|
|
921
|
-
const _actions = determineActionsFn(actions, this.guardMap)(this.contextSnapshot, event);
|
|
922
|
-
for (const action of toArray(_actions)) {
|
|
923
|
-
const fn = isString(action) ? (_a = this.actionMap) == null ? void 0 : _a[action] : action;
|
|
924
|
-
warn(isString(action) && !fn, `[machine/exec-action] No implementation found for action: \`${action}\``);
|
|
925
|
-
fn == null ? void 0 : fn(this.state.context, event, this.meta);
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
this.executeActivities = (event, activities, state) => {
|
|
929
|
-
var _a;
|
|
930
|
-
for (const activity of activities) {
|
|
931
|
-
const fn = isString(activity) ? (_a = this.activityMap) == null ? void 0 : _a[activity] : activity;
|
|
932
|
-
if (!fn) {
|
|
933
|
-
warn(`[machine/exec-activity] No implementation found for activity: \`${activity}\``);
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
const cleanup = fn(this.state.context, event, this.meta);
|
|
937
|
-
if (cleanup) {
|
|
938
|
-
this.addActivityCleanup(state != null ? state : this.state.value, cleanup);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
this.createEveryActivities = (every, callbackfn) => {
|
|
943
|
-
if (!every)
|
|
944
|
-
return;
|
|
945
|
-
const event = toEvent("machine.every" /* Every */);
|
|
946
|
-
if (isArray(every)) {
|
|
947
|
-
const picked = toArray(every).find((t) => {
|
|
948
|
-
const determineDelay2 = determineDelayFn(t.delay, this.delayMap);
|
|
949
|
-
t.delay = determineDelay2(this.contextSnapshot, event);
|
|
950
|
-
const determineGuard = determineGuardFn(t.guard, this.guardMap);
|
|
951
|
-
const guard = determineGuard(this.contextSnapshot, event);
|
|
952
|
-
return guard != null ? guard : t.delay;
|
|
953
|
-
});
|
|
954
|
-
if (!picked)
|
|
955
|
-
return;
|
|
956
|
-
const determineDelay = determineDelayFn(picked.delay, this.delayMap);
|
|
957
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
958
|
-
const activity = () => {
|
|
959
|
-
const id = globalThis.setInterval(() => {
|
|
960
|
-
this.executeActions(picked.actions, event);
|
|
961
|
-
}, delay);
|
|
962
|
-
return () => {
|
|
963
|
-
globalThis.clearInterval(id);
|
|
964
|
-
};
|
|
965
|
-
};
|
|
966
|
-
callbackfn(activity);
|
|
967
|
-
} else {
|
|
968
|
-
for (const interval in every) {
|
|
969
|
-
const actions = every == null ? void 0 : every[interval];
|
|
970
|
-
const determineDelay = determineDelayFn(interval, this.delayMap);
|
|
971
|
-
const delay = determineDelay(this.contextSnapshot, event);
|
|
972
|
-
const activity = () => {
|
|
973
|
-
const id = globalThis.setInterval(() => {
|
|
974
|
-
this.executeActions(actions, event);
|
|
975
|
-
}, delay);
|
|
976
|
-
return () => {
|
|
977
|
-
globalThis.clearInterval(id);
|
|
978
|
-
};
|
|
979
|
-
};
|
|
980
|
-
callbackfn(activity);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
this.setEvent = (event) => {
|
|
985
|
-
this.state.event = (0, import_vanilla2.ref)(toEvent(event));
|
|
986
|
-
};
|
|
987
|
-
this.performExitEffects = (current, event) => {
|
|
988
|
-
const currentState = this.state.value;
|
|
989
|
-
const stateNode = current ? this.getStateNode(current) : void 0;
|
|
990
|
-
this.stopActivities(currentState);
|
|
991
|
-
const _exit = determineActionsFn(stateNode == null ? void 0 : stateNode.exit, this.guardMap)(this.contextSnapshot, event);
|
|
992
|
-
const exitActions = toArray(_exit);
|
|
993
|
-
const afterExitActions = this.delayedEvents.get(currentState);
|
|
994
|
-
if (afterExitActions) {
|
|
995
|
-
exitActions.push(...afterExitActions);
|
|
996
|
-
}
|
|
997
|
-
this.executeActions(exitActions, event);
|
|
998
|
-
this.eventListeners.clear();
|
|
999
|
-
};
|
|
1000
|
-
this.performEntryEffects = (next, event) => {
|
|
1001
|
-
const stateNode = this.getStateNode(next);
|
|
1002
|
-
const activities = toArray(stateNode == null ? void 0 : stateNode.activities);
|
|
1003
|
-
this.createEveryActivities(stateNode == null ? void 0 : stateNode.every, (activity) => {
|
|
1004
|
-
activities.unshift(activity);
|
|
1005
|
-
});
|
|
1006
|
-
if (activities.length > 0) {
|
|
1007
|
-
this.executeActivities(event, activities);
|
|
1008
|
-
}
|
|
1009
|
-
const _entry = determineActionsFn(stateNode == null ? void 0 : stateNode.entry, this.guardMap)(this.contextSnapshot, event);
|
|
1010
|
-
const entryActions = toArray(_entry);
|
|
1011
|
-
const afterActions = this.getDelayedEventActions(next);
|
|
1012
|
-
if ((stateNode == null ? void 0 : stateNode.after) && afterActions) {
|
|
1013
|
-
this.delayedEvents.set(next, afterActions == null ? void 0 : afterActions.exits);
|
|
1014
|
-
entryActions.push(...afterActions.entries);
|
|
1015
|
-
}
|
|
1016
|
-
this.executeActions(entryActions, event);
|
|
1017
|
-
if ((stateNode == null ? void 0 : stateNode.type) === "final") {
|
|
1018
|
-
this.state.done = true;
|
|
1019
|
-
this.doneListeners.forEach((listener) => {
|
|
1020
|
-
listener(this.stateSnapshot);
|
|
1021
|
-
});
|
|
1022
|
-
this.stop();
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
this.performTransitionEffects = (transition, event) => {
|
|
1026
|
-
const t = this.determineTransition(transition, event);
|
|
1027
|
-
this.executeActions(t == null ? void 0 : t.actions, event);
|
|
1028
|
-
};
|
|
1029
|
-
this.performStateChangeEffects = (current, next, event) => {
|
|
1030
|
-
var _a, _b;
|
|
1031
|
-
this.setEvent(event);
|
|
1032
|
-
next.target = (_b = (_a = next.target) != null ? _a : this.state.value) != null ? _b : void 0;
|
|
1033
|
-
const ok = next.target && next.target !== this.state.value;
|
|
1034
|
-
if (ok) {
|
|
1035
|
-
this.performExitEffects(current, event);
|
|
1036
|
-
}
|
|
1037
|
-
this.performTransitionEffects(next == null ? void 0 : next.transition, event);
|
|
1038
|
-
this.setState(next.target);
|
|
1039
|
-
if (ok) {
|
|
1040
|
-
this.performEntryEffects(next.target, event);
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
this.determineTransition = (transition, event) => {
|
|
1044
|
-
const fn = determineTransitionFn(transition, this.guardMap);
|
|
1045
|
-
return fn == null ? void 0 : fn(this.contextSnapshot, event);
|
|
1046
|
-
};
|
|
1047
|
-
this.sendParent = (evt) => {
|
|
1048
|
-
var _a;
|
|
1049
|
-
if (!this.parent) {
|
|
1050
|
-
invariant("[machine/send-parent] Cannot send event to an unknown parent");
|
|
1051
|
-
}
|
|
1052
|
-
const event = toEvent(evt);
|
|
1053
|
-
(_a = this.parent) == null ? void 0 : _a.send(event);
|
|
1054
|
-
};
|
|
1055
|
-
this.send = (evt) => {
|
|
1056
|
-
const event = toEvent(evt);
|
|
1057
|
-
this.transition(this.state.value, event);
|
|
1058
|
-
};
|
|
1059
|
-
this.transition = (state, evt) => {
|
|
1060
|
-
var _a, _b, _c;
|
|
1061
|
-
const stateNode = isString(state) ? this.getStateNode(state) : state == null ? void 0 : state.stateNode;
|
|
1062
|
-
const event = toEvent(evt);
|
|
1063
|
-
if (!stateNode && !this.config.on) {
|
|
1064
|
-
const msg = this.status === "Stopped" /* Stopped */ ? "[machine/transition] Cannot transition a stopped machine" : "[machine/transition] State does not have a definition";
|
|
1065
|
-
warn(msg);
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
const transitionConfig = (_c = (_a = stateNode == null ? void 0 : stateNode.on) == null ? void 0 : _a[event.type]) != null ? _c : (_b = this.config.on) == null ? void 0 : _b[event.type];
|
|
1069
|
-
const transition = toTransition(transitionConfig, this.state.value);
|
|
1070
|
-
if (!transition)
|
|
1071
|
-
return;
|
|
1072
|
-
const info = this.getNextStateInfo(transition, event);
|
|
1073
|
-
this.performStateChangeEffects(this.state.value, info, event);
|
|
1074
|
-
return info.stateNode;
|
|
1075
|
-
};
|
|
1076
|
-
this.subscribe = (listener) => {
|
|
1077
|
-
this.stateListeners.add(listener);
|
|
1078
|
-
if (this.status === "Running" /* Running */) {
|
|
1079
|
-
listener(this.stateSnapshot);
|
|
1080
|
-
}
|
|
1081
|
-
return () => {
|
|
1082
|
-
this.stateListeners.delete(listener);
|
|
1083
|
-
};
|
|
1084
|
-
};
|
|
1085
|
-
this.onDone = (listener) => {
|
|
1086
|
-
this.doneListeners.add(listener);
|
|
1087
|
-
return this;
|
|
1088
|
-
};
|
|
1089
|
-
this.onTransition = (listener) => {
|
|
1090
|
-
this.stateListeners.add(listener);
|
|
1091
|
-
if (this.status === "Running" /* Running */) {
|
|
1092
|
-
listener(this.stateSnapshot);
|
|
1093
|
-
}
|
|
1094
|
-
return this;
|
|
1095
|
-
};
|
|
1096
|
-
this.onEvent = (listener) => {
|
|
1097
|
-
listener(this.state.event);
|
|
1098
|
-
this.eventListeners.add(listener);
|
|
1099
|
-
return this;
|
|
1100
|
-
};
|
|
1101
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
1102
|
-
this.options = klona(options);
|
|
1103
|
-
this.id = (_a = config.id) != null ? _a : `machine-${uuid()}`;
|
|
1104
|
-
this.guardMap = (_c = (_b = this.options) == null ? void 0 : _b.guards) != null ? _c : {};
|
|
1105
|
-
this.actionMap = (_e = (_d = this.options) == null ? void 0 : _d.actions) != null ? _e : {};
|
|
1106
|
-
this.delayMap = (_g = (_f = this.options) == null ? void 0 : _f.delays) != null ? _g : {};
|
|
1107
|
-
this.activityMap = (_i = (_h = this.options) == null ? void 0 : _h.activities) != null ? _i : {};
|
|
1108
|
-
this.sync = (_k = (_j = this.options) == null ? void 0 : _j.sync) != null ? _k : false;
|
|
1109
|
-
this.state = createProxy(klona(config));
|
|
1110
|
-
this.setupComputed();
|
|
1111
|
-
const event = toEvent("machine.created" /* Created */);
|
|
1112
|
-
this.executeActions(config == null ? void 0 : config.created, event);
|
|
1113
|
-
}
|
|
1114
|
-
get stateSnapshot() {
|
|
1115
|
-
return cast((0, import_vanilla2.snapshot)(this.state));
|
|
1116
|
-
}
|
|
1117
|
-
get contextSnapshot() {
|
|
1118
|
-
return this.stateSnapshot.context;
|
|
1119
|
-
}
|
|
1120
|
-
get self() {
|
|
1121
|
-
const _self = this;
|
|
1122
|
-
return {
|
|
1123
|
-
id: this.id,
|
|
1124
|
-
send: this.send.bind(this),
|
|
1125
|
-
sendParent: this.sendParent.bind(this),
|
|
1126
|
-
sendChild: this.sendChild.bind(this),
|
|
1127
|
-
stop: this.stop.bind(this),
|
|
1128
|
-
stopChild: this.stopChild.bind(this),
|
|
1129
|
-
spawn: this.spawn.bind(this),
|
|
1130
|
-
get state() {
|
|
1131
|
-
return _self.stateSnapshot;
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
}
|
|
1135
|
-
get meta() {
|
|
1136
|
-
return {
|
|
1137
|
-
state: this.stateSnapshot,
|
|
1138
|
-
guards: this.guardMap,
|
|
1139
|
-
send: this.send.bind(this),
|
|
1140
|
-
listen: this.onEvent.bind(this),
|
|
1141
|
-
self: this.self,
|
|
1142
|
-
getState: () => this.stateSnapshot
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
var createMachine = (config, options) => new Machine(config, options);
|
|
1147
|
-
|
|
1148
399
|
// src/tabs.machine.ts
|
|
1149
|
-
var
|
|
1150
|
-
var
|
|
400
|
+
var import_core = require("@zag-js/core");
|
|
401
|
+
var { not } = import_core.guards;
|
|
402
|
+
var machine = (0, import_core.createMachine)({
|
|
1151
403
|
initial: "unknown",
|
|
1152
404
|
context: {
|
|
1153
405
|
dir: "ltr",
|
|
@@ -1232,7 +484,7 @@ var machine = createMachine({
|
|
|
1232
484
|
actions: "focusLastTab"
|
|
1233
485
|
},
|
|
1234
486
|
ENTER: {
|
|
1235
|
-
guard:
|
|
487
|
+
guard: not("selectOnFocus"),
|
|
1236
488
|
actions: "setValue"
|
|
1237
489
|
},
|
|
1238
490
|
TAB_FOCUS: [
|
|
@@ -1259,7 +511,7 @@ var machine = createMachine({
|
|
|
1259
511
|
setupDocument(ctx, evt) {
|
|
1260
512
|
ctx.uid = evt.id;
|
|
1261
513
|
if (evt.doc)
|
|
1262
|
-
ctx.doc = (0,
|
|
514
|
+
ctx.doc = (0, import_core.ref)(evt.doc);
|
|
1263
515
|
},
|
|
1264
516
|
setFocusedValue(ctx, evt) {
|
|
1265
517
|
ctx.focusedValue = evt.value;
|