@serendie/ui 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/components/CheckBox/CheckBox.js +36 -35
  2. package/dist/components/ChoiceBox/ChoiceBox.js +41 -41
  3. package/dist/components/DataTable/DataTableComponent.d.ts +3 -20
  4. package/dist/components/DataTable/DataTableComponent.js +38 -36
  5. package/dist/components/DataTable/table/HeaderCheckbox.js +29 -19
  6. package/dist/components/Search/Search.d.ts +3 -1
  7. package/dist/components/Search/Search.js +34 -33
  8. package/dist/components/Select/Select.d.ts +2 -1
  9. package/dist/components/Select/Select.js +47 -41
  10. package/dist/components/Tooltip/Tooltip.d.ts +14 -0
  11. package/dist/components/Tooltip/Tooltip.js +70 -0
  12. package/dist/components/Tooltip/index.d.ts +1 -0
  13. package/dist/components/Tooltip/index.js +4 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +12 -10
  16. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-content.js +4 -6
  17. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-indicator.js +4 -6
  18. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item-trigger.js +10 -12
  19. package/dist/node_modules/@ark-ui/react/dist/components/accordion/accordion-item.js +16 -16
  20. package/dist/node_modules/@ark-ui/react/dist/components/accordion/use-accordion.js +13 -20
  21. package/dist/node_modules/@ark-ui/react/dist/components/avatar/avatar-root.js +1 -5
  22. package/dist/node_modules/@ark-ui/react/dist/components/avatar/use-avatar.js +14 -18
  23. package/dist/node_modules/@ark-ui/react/dist/components/checkbox/checkbox-hidden-input.js +4 -6
  24. package/dist/node_modules/@ark-ui/react/dist/components/checkbox/use-checkbox.js +22 -28
  25. package/dist/node_modules/@ark-ui/react/dist/components/collapsible/collapsible-content.js +7 -9
  26. package/dist/node_modules/@ark-ui/react/dist/components/collapsible/use-collapsible.js +14 -21
  27. package/dist/node_modules/@ark-ui/react/dist/components/collection/list-collection.js +5 -0
  28. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-content.js +9 -8
  29. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-item-group.js +4 -6
  30. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-positioner.js +4 -6
  31. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-root.js +17 -18
  32. package/dist/node_modules/@ark-ui/react/dist/components/combobox/combobox-trigger.js +10 -9
  33. package/dist/node_modules/@ark-ui/react/dist/components/combobox/use-combobox-item-context.js +5 -7
  34. package/dist/node_modules/@ark-ui/react/dist/components/combobox/use-combobox.js +21 -45
  35. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-backdrop.js +10 -9
  36. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-close-trigger.js +4 -6
  37. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-content.js +6 -5
  38. package/dist/node_modules/@ark-ui/react/dist/components/dialog/dialog-description.js +4 -6
  39. package/dist/node_modules/@ark-ui/react/dist/components/dialog/use-dialog.js +13 -22
  40. package/dist/node_modules/@ark-ui/react/dist/components/factory.js +26 -24
  41. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-content.js +9 -8
  42. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-item-group.js +1 -3
  43. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-item.js +15 -13
  44. package/dist/node_modules/@ark-ui/react/dist/components/menu/menu-root.js +13 -14
  45. package/dist/node_modules/@ark-ui/react/dist/components/menu/use-menu-option-item-props-context.js +10 -0
  46. package/dist/node_modules/@ark-ui/react/dist/components/menu/use-menu.js +14 -21
  47. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-ellipsis.js +4 -6
  48. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-next-trigger.js +4 -6
  49. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-prev-trigger.js +4 -6
  50. package/dist/node_modules/@ark-ui/react/dist/components/pagination/pagination-root.js +5 -4
  51. package/dist/node_modules/@ark-ui/react/dist/components/pagination/use-pagination.js +13 -19
  52. package/dist/node_modules/@ark-ui/react/dist/components/portal/portal.js +25 -16
  53. package/dist/node_modules/@ark-ui/react/dist/components/presence/split-presence-props.js +3 -2
  54. package/dist/node_modules/@ark-ui/react/dist/components/presence/use-presence.js +18 -18
  55. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item-control.js +4 -6
  56. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item-text.js +4 -6
  57. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/radio-group-item.js +1 -5
  58. package/dist/node_modules/@ark-ui/react/dist/components/radio-group/use-radio-group.js +14 -22
  59. package/dist/node_modules/@ark-ui/react/dist/components/select/select-content.js +9 -8
  60. package/dist/node_modules/@ark-ui/react/dist/components/select/select-root.js +11 -12
  61. package/dist/node_modules/@ark-ui/react/dist/components/select/use-select.js +20 -47
  62. package/dist/node_modules/@ark-ui/react/dist/components/switch/switch-hidden-input.js +4 -6
  63. package/dist/node_modules/@ark-ui/react/dist/components/switch/use-switch.js +20 -26
  64. package/dist/node_modules/@ark-ui/react/dist/components/tabs/tabs-root.js +9 -8
  65. package/dist/node_modules/@ark-ui/react/dist/components/tabs/use-tabs.js +14 -21
  66. package/dist/node_modules/@ark-ui/react/dist/components/toast/create-toaster.js +3 -7
  67. package/dist/node_modules/@ark-ui/react/dist/components/toast/toaster.js +28 -15
  68. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-arrow-tip.js +13 -0
  69. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-arrow.js +13 -0
  70. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-content.js +15 -0
  71. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-positioner.js +14 -0
  72. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-root.js +14 -0
  73. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/tooltip-trigger.js +13 -0
  74. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/use-tooltip-context.js +10 -0
  75. package/dist/node_modules/@ark-ui/react/dist/components/tooltip/use-tooltip.js +17 -0
  76. package/dist/node_modules/@ark-ui/react/dist/utils/compose-refs.js +13 -7
  77. package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +92 -90
  78. package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +230 -216
  79. package/dist/node_modules/@zag-js/accordion/dist/index.js +210 -227
  80. package/dist/node_modules/@zag-js/aria-hidden/dist/index.js +49 -12
  81. package/dist/node_modules/@zag-js/avatar/dist/index.js +119 -134
  82. package/dist/node_modules/@zag-js/checkbox/dist/index.js +196 -197
  83. package/dist/node_modules/@zag-js/collapsible/dist/index.js +250 -198
  84. package/dist/node_modules/@zag-js/collection/dist/index.js +172 -179
  85. package/dist/node_modules/@zag-js/combobox/dist/index.js +1176 -1082
  86. package/dist/node_modules/@zag-js/core/dist/index.js +77 -496
  87. package/dist/node_modules/@zag-js/dialog/dist/index.js +243 -270
  88. package/dist/node_modules/@zag-js/dismissable/dist/index.js +62 -60
  89. package/dist/node_modules/@zag-js/dom-query/dist/index.js +465 -253
  90. package/dist/node_modules/@zag-js/focus-trap/dist/index.js +307 -0
  91. package/dist/node_modules/@zag-js/focus-visible/dist/index.js +48 -47
  92. package/dist/node_modules/@zag-js/interact-outside/dist/index.js +112 -80
  93. package/dist/node_modules/@zag-js/menu/dist/index.js +998 -884
  94. package/dist/node_modules/@zag-js/pagination/dist/index.js +207 -213
  95. package/dist/node_modules/@zag-js/popper/dist/index.js +130 -129
  96. package/dist/node_modules/@zag-js/presence/dist/index.js +139 -122
  97. package/dist/node_modules/@zag-js/radio-group/dist/index.js +297 -302
  98. package/dist/node_modules/@zag-js/react/dist/index.js +255 -103
  99. package/dist/node_modules/@zag-js/remove-scroll/dist/index.js +18 -31
  100. package/dist/node_modules/@zag-js/select/dist/index.js +889 -885
  101. package/dist/node_modules/@zag-js/store/dist/index.js +98 -137
  102. package/dist/node_modules/@zag-js/switch/dist/index.js +199 -191
  103. package/dist/node_modules/@zag-js/tabs/dist/index.js +383 -386
  104. package/dist/node_modules/@zag-js/toast/dist/index.js +646 -633
  105. package/dist/node_modules/@zag-js/tooltip/dist/index.js +459 -0
  106. package/dist/node_modules/@zag-js/types/dist/index.js +6 -6
  107. package/dist/node_modules/@zag-js/utils/dist/index.js +112 -99
  108. package/dist/node_modules/proxy-compare/dist/index.js +4 -106
  109. package/dist/styles.css +1 -1
  110. package/package.json +5 -5
  111. package/dist/node_modules/@ark-ui/react/dist/utils/use-is-server.js +0 -10
  112. package/dist/node_modules/@zag-js/dom-event/dist/index.js +0 -130
  113. package/dist/node_modules/@zag-js/element-rect/dist/index.js +0 -32
  114. package/dist/node_modules/@zag-js/form-utils/dist/index.js +0 -51
  115. package/dist/node_modules/aria-hidden/dist/es2015/index.js +0 -52
  116. package/dist/node_modules/focus-trap/dist/focus-trap.esm.js +0 -431
  117. package/dist/node_modules/klona/full/index.js +0 -21
  118. package/dist/node_modules/tabbable/dist/index.esm.js +0 -202
@@ -1,511 +1,92 @@
1
- import { snapshot as C, proxy as R, proxyWithComputed as V, subscribe as _, ref as P } from "../../store/dist/index.js";
2
- import { callAll as q, isString as v, uuid as $, cast as m, isFunction as T, noop as B, isObject as M, runIfFn as F, invariant as b, clear as H, compact as j, isArray as N, hasProp as J, warn as w, isDev as X, isPlainObject as K, isNumber as Q } from "../../utils/dist/index.js";
3
- import { klona as U } from "../../../klona/full/index.js";
4
- var Y = Object.defineProperty, Z = (e, n, o) => n in e ? Y(e, n, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[n] = o, a = (e, n, o) => Z(e, typeof n != "symbol" ? n + "" : n, o);
5
- function I(e, ...n) {
6
- for (const o of n) {
7
- const h = j(o);
8
- for (const l in h)
9
- K(o[l]) ? (e[l] || (e[l] = {}), I(e[l], o[l])) : e[l] = o[l];
1
+ import { callAll as a, isString as i } from "../../utils/dist/index.js";
2
+ import { getActiveElement as f, getDocument as d } from "../../dom-query/dist/index.js";
3
+ var l = (...t) => t.map((e) => {
4
+ var r;
5
+ return (r = e == null ? void 0 : e.trim) == null ? void 0 : r.call(e);
6
+ }).filter(Boolean).join(" "), s = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g, u = (t) => {
7
+ const e = {};
8
+ let r;
9
+ for (; r = s.exec(t); )
10
+ e[r[1]] = r[2];
11
+ return e;
12
+ }, g = (t, e) => {
13
+ if (i(t)) {
14
+ if (i(e)) return `${t};${e}`;
15
+ t = u(t);
16
+ } else i(e) && (e = u(e));
17
+ return Object.assign({}, t ?? {}, e ?? {});
18
+ };
19
+ function N(...t) {
20
+ let e = {};
21
+ for (let r of t) {
22
+ for (let n in e) {
23
+ if (n.startsWith("on") && typeof e[n] == "function" && typeof r[n] == "function") {
24
+ e[n] = a(r[n], e[n]);
25
+ continue;
26
+ }
27
+ if (n === "className" || n === "class") {
28
+ e[n] = l(e[n], r[n]);
29
+ continue;
30
+ }
31
+ if (n === "style") {
32
+ e[n] = g(e[n], r[n]);
33
+ continue;
34
+ }
35
+ e[n] = r[n] !== void 0 ? r[n] : e[n];
36
+ }
37
+ for (let n in r)
38
+ e[n] === void 0 && (e[n] = r[n]);
10
39
  }
11
40
  return e;
12
41
  }
13
- function O(e) {
14
- return U(e);
15
- }
16
- function g(e) {
17
- return v(e) ? { type: e } : e;
18
- }
19
- function x(e) {
20
- return e ? N(e) ? e.slice() : [e] : [];
21
- }
22
- function W(e) {
23
- return M(e) && e.predicate != null;
24
- }
25
- var tt = () => !0;
26
- function L(e, n, o, h) {
27
- return (l) => {
28
- var f;
29
- return v(l) ? !!((f = e[l]) != null && f.call(e, n, o, h)) : T(l) ? l(n, o, h) : l.predicate(e)(n, o, h);
30
- };
31
- }
32
- function et(...e) {
42
+ function m() {
33
43
  return {
34
- predicate: (n) => (o, h, l) => e.map(L(n, o, h, l)).some(Boolean)
44
+ and: (...t) => function(r) {
45
+ return t.every((n) => r.guard(n));
46
+ },
47
+ or: (...t) => function(r) {
48
+ return t.some((n) => r.guard(n));
49
+ },
50
+ not: (t) => function(r) {
51
+ return !r.guard(t);
52
+ }
35
53
  };
36
54
  }
37
- function it(...e) {
38
- return {
39
- predicate: (n) => (o, h, l) => e.map(L(n, o, h, l)).every(Boolean)
40
- };
55
+ function _(t) {
56
+ return t;
41
57
  }
42
- function st(e) {
58
+ function h() {
43
59
  return {
44
- predicate: (n) => (o, h, l) => !L(n, o, h, l)(e)
45
- };
46
- }
47
- var vt = { or: et, and: it, not: st };
48
- function G(e, n) {
49
- return e = e ?? tt, (o, h, l) => {
50
- if (v(e)) {
51
- const f = n[e];
52
- return T(f) ? f(o, h, l) : f;
60
+ guards: m(),
61
+ createMachine: (t) => t,
62
+ choose: (t) => function({ choose: r }) {
63
+ var n;
64
+ return (n = r(t)) == null ? void 0 : n.actions;
53
65
  }
54
- return W(e) ? e.predicate(n)(o, h, l) : e == null ? void 0 : e(o, h, l);
55
66
  };
56
67
  }
57
- function D(e, n) {
58
- return (o, h, l) => W(e) ? e.predicate(n)(o, h, l) : e;
59
- }
60
- function nt(e) {
61
- var f, S;
62
- const n = e.computed ?? m({}), o = e.context ?? m({}), h = e.initial ? (S = (f = e.states) == null ? void 0 : f[e.initial]) == null ? void 0 : S.tags : [], l = R({
63
- value: e.initial ?? "",
64
- previousValue: "",
65
- event: m({}),
66
- previousEvent: m({}),
67
- context: V(o, n),
68
- done: !1,
69
- tags: h ?? [],
70
- hasTag(t) {
71
- return this.tags.includes(t);
72
- },
73
- matches(...t) {
74
- return t.includes(this.value);
75
- },
76
- can(t) {
77
- return m(this).nextEvents.includes(t);
78
- },
79
- get nextEvents() {
80
- var i, r;
81
- const t = ((r = (i = e.states) == null ? void 0 : i[this.value]) == null ? void 0 : r.on) ?? {}, s = (e == null ? void 0 : e.on) ?? {};
82
- return Object.keys({ ...t, ...s });
83
- },
84
- get changed() {
85
- return this.event.value === "machine.init" || !this.previousValue ? !1 : this.value !== this.previousValue;
86
- }
87
- });
88
- return m(l);
89
- }
90
- function E(e, n) {
91
- return (o, h) => {
92
- if (Q(e)) return e;
93
- if (T(e))
94
- return e(o, h);
95
- if (v(e)) {
96
- const l = Number.parseFloat(e);
97
- if (!Number.isNaN(l))
98
- return l;
99
- if (n) {
100
- const f = n == null ? void 0 : n[e];
101
- return b(
102
- f == null,
103
- `[@zag-js/core > determine-delay] Cannot determine delay for \`${e}\`. It doesn't exist in \`options.delays\``
104
- ), T(f) ? f(o, h) : f;
105
- }
106
- }
68
+ var v = /* @__PURE__ */ ((t) => (t.NotStarted = "Not Started", t.Started = "Started", t.Stopped = "Stopped", t))(v || {}), p = "__init__";
69
+ function w(t) {
70
+ const e = () => {
71
+ var o;
72
+ return ((o = t.getRootNode) == null ? void 0 : o.call(t)) ?? document;
73
+ }, r = () => d(e()), n = () => r().defaultView ?? window, c = () => f(e());
74
+ return {
75
+ ...t,
76
+ getRootNode: e,
77
+ getDoc: r,
78
+ getWin: n,
79
+ getActiveElement: c,
80
+ isActiveElement: (o) => o === c(),
81
+ getById: (o) => e().getElementById(o)
107
82
  };
108
83
  }
109
- function at(e) {
110
- return v(e) ? { target: e } : e;
111
- }
112
- function rt(e, n) {
113
- return (o, h, l) => x(e).map(at).find((f) => G(f.guard, n)(o, h, l) ?? f.target ?? f.actions);
114
- }
115
- var k = class {
116
- // Let's get started!
117
- constructor(e, n) {
118
- var o, h, l, f, S;
119
- a(
120
- this,
121
- "status",
122
- "Not Started"
123
- /* NotStarted */
124
- ), a(this, "state"), a(this, "initialState"), a(this, "initialContext"), a(this, "id"), a(
125
- this,
126
- "type",
127
- "machine"
128
- /* Machine */
129
- ), a(this, "activityEvents", /* @__PURE__ */ new Map()), a(this, "delayedEvents", /* @__PURE__ */ new Map()), a(this, "stateListeners", /* @__PURE__ */ new Set()), a(this, "doneListeners", /* @__PURE__ */ new Set()), a(this, "contextWatchers", /* @__PURE__ */ new Set()), a(this, "removeStateListener", B), a(this, "parent"), a(this, "children", /* @__PURE__ */ new Map()), a(this, "guardMap"), a(this, "actionMap"), a(this, "delayMap"), a(this, "activityMap"), a(this, "sync"), a(this, "options"), a(this, "config"), a(this, "_created", () => {
130
- var s;
131
- const t = g(
132
- "machine.created"
133
- /* Created */
134
- );
135
- this.executeActions((s = this.config) == null ? void 0 : s.created, t);
136
- }), a(this, "start", (t) => {
137
- if (this.state.value = "", this.state.tags = [], this.status === "Running")
138
- return this;
139
- this.status = "Running", this.removeStateListener = _(
140
- this.state,
141
- () => {
142
- this.stateListeners.forEach((d) => {
143
- d(this.stateSnapshot);
144
- });
145
- },
146
- this.sync
147
- ), this.setupContextWatchers(), this.executeActivities(
148
- g(
149
- "machine.start"
150
- /* Start */
151
- ),
152
- x(this.config.activities),
153
- "machine.start"
154
- /* Start */
155
- ), this.executeActions(this.config.entry, g(
156
- "machine.start"
157
- /* Start */
158
- ));
159
- const s = g(
160
- "machine.init"
161
- /* Init */
162
- ), i = M(t) ? t.value : t, r = M(t) ? t.context : void 0;
163
- r && this.setContext(r);
164
- const c = {
165
- target: i ?? this.config.initial
166
- }, u = this.getNextStateInfo(c, s);
167
- return this.initialState = u, this.performStateChangeEffects(this.state.value, u, s), this;
168
- }), a(this, "setupContextWatchers", () => {
169
- const { watch: t } = this.config;
170
- if (!t) return;
171
- let s = C(this.state.context);
172
- const i = _(this.state.context, () => {
173
- var c;
174
- const r = C(this.state.context);
175
- for (const [u, d] of Object.entries(t))
176
- (((c = this.options.compareFns) == null ? void 0 : c[u]) ?? Object.is)(s[u], r[u]) || this.executeActions(d, this.state.event);
177
- s = r;
178
- });
179
- this.contextWatchers.add(i);
180
- }), a(this, "stop", () => {
181
- if (this.status !== "Stopped")
182
- return this.performExitEffects(this.state.value, g(
183
- "machine.stop"
184
- /* Stop */
185
- )), this.executeActions(this.config.exit, g(
186
- "machine.stop"
187
- /* Stop */
188
- )), this.setState(""), this.setEvent(
189
- "machine.stop"
190
- /* Stop */
191
- ), this.stopStateListeners(), this.stopChildren(), this.stopActivities(), this.stopDelayedEvents(), this.stopContextWatchers(), this.status = "Stopped", this;
192
- }), a(this, "stopStateListeners", () => {
193
- this.removeStateListener(), this.stateListeners.clear();
194
- }), a(this, "stopContextWatchers", () => {
195
- this.contextWatchers.forEach((t) => t()), this.contextWatchers.clear();
196
- }), a(this, "stopDelayedEvents", () => {
197
- this.delayedEvents.forEach((t) => {
198
- t.forEach((s) => s());
199
- }), this.delayedEvents.clear();
200
- }), a(this, "stopActivities", (t) => {
201
- var s, i;
202
- t ? ((s = this.activityEvents.get(t)) == null || s.forEach((r) => r()), (i = this.activityEvents.get(t)) == null || i.clear(), this.activityEvents.delete(t)) : (this.activityEvents.forEach((r) => {
203
- r.forEach((c) => c()), r.clear();
204
- }), this.activityEvents.clear());
205
- }), a(this, "sendChild", (t, s) => {
206
- const i = g(t), r = F(s, this.contextSnapshot), c = this.children.get(r);
207
- c || b(`[@zag-js/core] Cannot send '${i.type}' event to unknown child`), c.send(i);
208
- }), a(this, "stopChild", (t) => {
209
- this.children.has(t) || b(`[@zag-js/core > stop-child] Cannot stop unknown child ${t}`), this.children.get(t).stop(), this.children.delete(t);
210
- }), a(this, "removeChild", (t) => {
211
- this.children.delete(t);
212
- }), a(this, "stopChildren", () => {
213
- this.children.forEach((t) => t.stop()), this.children.clear();
214
- }), a(this, "setParent", (t) => {
215
- this.parent = t;
216
- }), a(this, "spawn", (t, s) => {
217
- const i = F(t);
218
- return s && (i.id = s), i.type = "machine.actor", i.setParent(this), this.children.set(i.id, m(i)), i.onDone(() => {
219
- this.removeChild(i.id);
220
- }).start(), m(P(i));
221
- }), a(this, "stopActivity", (t) => {
222
- var i;
223
- if (!this.state.value) return;
224
- const s = this.activityEvents.get(this.state.value);
225
- (i = s == null ? void 0 : s.get(t)) == null || i(), s == null || s.delete(t);
226
- }), a(this, "addActivityCleanup", (t, s, i) => {
227
- var r;
228
- t && (this.activityEvents.has(t) ? (r = this.activityEvents.get(t)) == null || r.set(s, i) : this.activityEvents.set(t, /* @__PURE__ */ new Map([[s, i]])));
229
- }), a(this, "setState", (t) => {
230
- this.state.previousValue = this.state.value, this.state.value = t;
231
- const s = this.getStateNode(t);
232
- t == null ? H(this.state.tags) : this.state.tags = x(s == null ? void 0 : s.tags);
233
- }), a(this, "setContext", (t) => {
234
- t && I(this.state.context, j(t));
235
- }), a(this, "setOptions", (t) => {
236
- const s = j(t);
237
- this.actionMap = { ...this.actionMap, ...s.actions }, this.delayMap = { ...this.delayMap, ...s.delays }, this.activityMap = { ...this.activityMap, ...s.activities }, this.guardMap = { ...this.guardMap, ...s.guards };
238
- }), a(this, "getStateNode", (t) => {
239
- var s;
240
- if (t)
241
- return (s = this.config.states) == null ? void 0 : s[t];
242
- }), a(this, "getNextStateInfo", (t, s) => {
243
- const i = this.determineTransition(t, s), r = !(i != null && i.target), c = (i == null ? void 0 : i.target) ?? this.state.value, u = this.state.value !== c, d = this.getStateNode(c), y = {
244
- reenter: !r && !u && !(i != null && i.internal),
245
- transition: i,
246
- stateNode: d,
247
- target: c,
248
- changed: u
249
- };
250
- return this.log("NextState:", `[${s.type}]`, this.state.value, "---->", y.target), y;
251
- }), a(this, "getAfterActions", (t, s) => {
252
- let i;
253
- return {
254
- entry: () => {
255
- i = globalThis.setTimeout(() => {
256
- const r = this.getNextStateInfo(t, this.state.event);
257
- this.performStateChangeEffects(this.state.value, r, this.state.event);
258
- }, s);
259
- },
260
- exit: () => {
261
- globalThis.clearTimeout(i);
262
- }
263
- };
264
- }), a(this, "getDelayedEventActions", (t) => {
265
- const s = this.getStateNode(t), i = this.state.event;
266
- if (!s || !s.after) return;
267
- const r = [], c = [];
268
- if (N(s.after)) {
269
- const u = this.determineTransition(s.after, i);
270
- if (!u) return;
271
- if (!J(u, "delay"))
272
- throw new Error(`[@zag-js/core > after] Delay is required for after transition: ${JSON.stringify(u)}`);
273
- const p = E(u.delay, this.delayMap)(this.contextSnapshot, i), y = this.getAfterActions(u, p);
274
- return r.push(y.entry), c.push(y.exit), { entries: r, exits: c };
275
- }
276
- if (M(s.after))
277
- for (const u in s.after) {
278
- const d = s.after[u], y = E(u, this.delayMap)(this.contextSnapshot, i), A = this.getAfterActions(d, y);
279
- r.push(A.entry), c.push(A.exit);
280
- }
281
- return { entries: r, exits: c };
282
- }), a(this, "executeActions", (t, s) => {
283
- var r;
284
- const i = D(t, this.guardMap)(this.contextSnapshot, s, this.guardMeta);
285
- for (const c of x(i)) {
286
- const u = v(c) ? (r = this.actionMap) == null ? void 0 : r[c] : c;
287
- w(
288
- v(c) && !u,
289
- `[@zag-js/core > execute-actions] No implementation found for action: \`${c}\``
290
- ), u == null || u(this.state.context, s, this.meta);
291
- }
292
- }), a(this, "executeActivities", (t, s, i) => {
293
- var r;
294
- for (const c of s) {
295
- const u = v(c) ? (r = this.activityMap) == null ? void 0 : r[c] : c;
296
- if (!u) {
297
- w(`[@zag-js/core > execute-activity] No implementation found for activity: \`${c}\``);
298
- continue;
299
- }
300
- const d = u(this.state.context, t, this.meta);
301
- if (d) {
302
- const p = v(c) ? c : c.name || $();
303
- this.addActivityCleanup(i ?? this.state.value, p, d);
304
- }
305
- }
306
- }), a(this, "createEveryActivities", (t, s) => {
307
- if (t)
308
- if (N(t)) {
309
- const i = x(t).find((d) => {
310
- const p = d.delay, A = E(p, this.delayMap)(this.contextSnapshot, this.state.event);
311
- return G(d.guard, this.guardMap)(this.contextSnapshot, this.state.event, this.guardMeta) ?? A != null;
312
- });
313
- if (!i) return;
314
- const c = E(i.delay, this.delayMap)(this.contextSnapshot, this.state.event);
315
- s(() => {
316
- const d = globalThis.setInterval(() => {
317
- this.executeActions(i.actions, this.state.event);
318
- }, c);
319
- return () => {
320
- globalThis.clearInterval(d);
321
- };
322
- });
323
- } else
324
- for (const i in t) {
325
- const r = t == null ? void 0 : t[i], u = E(i, this.delayMap)(this.contextSnapshot, this.state.event);
326
- s(() => {
327
- const p = globalThis.setInterval(() => {
328
- this.executeActions(r, this.state.event);
329
- }, u);
330
- return () => {
331
- globalThis.clearInterval(p);
332
- };
333
- });
334
- }
335
- }), a(this, "setEvent", (t) => {
336
- this.state.previousEvent = this.state.event, this.state.event = P(g(t));
337
- }), a(this, "performExitEffects", (t, s) => {
338
- const i = this.state.value;
339
- if (i === "") return;
340
- const r = t ? this.getStateNode(t) : void 0;
341
- this.stopActivities(i);
342
- const c = D(r == null ? void 0 : r.exit, this.guardMap)(this.contextSnapshot, s, this.guardMeta), u = x(c), d = this.delayedEvents.get(i);
343
- d && u.push(...d), this.executeActions(u, s);
344
- }), a(this, "performEntryEffects", (t, s) => {
345
- const i = this.getStateNode(t), r = x(i == null ? void 0 : i.activities);
346
- this.createEveryActivities(i == null ? void 0 : i.every, (p) => {
347
- r.unshift(p);
348
- }), r.length > 0 && this.executeActivities(s, r);
349
- const c = D(i == null ? void 0 : i.entry, this.guardMap)(
350
- this.contextSnapshot,
351
- s,
352
- this.guardMeta
353
- ), u = x(c), d = this.getDelayedEventActions(t);
354
- i != null && i.after && d && (this.delayedEvents.set(t, d == null ? void 0 : d.exits), u.push(...d.entries)), this.executeActions(u, s), (i == null ? void 0 : i.type) === "final" && (this.state.done = !0, this.doneListeners.forEach((p) => {
355
- p(this.stateSnapshot);
356
- }), this.stop());
357
- }), a(this, "performTransitionEffects", (t, s) => {
358
- const i = this.determineTransition(t, s);
359
- this.executeActions(i == null ? void 0 : i.actions, s);
360
- }), a(this, "performStateChangeEffects", (t, s, i) => {
361
- this.setEvent(i);
362
- const r = s.changed || s.reenter;
363
- r && this.performExitEffects(t, i), this.performTransitionEffects(s.transition, i), this.setState(s.target), r && this.performEntryEffects(s.target, i);
364
- }), a(this, "determineTransition", (t, s) => {
365
- const i = rt(t, this.guardMap);
366
- return i == null ? void 0 : i(this.contextSnapshot, s, this.guardMeta);
367
- }), a(this, "sendParent", (t) => {
368
- var i;
369
- this.parent || b("[@zag-js/core > send-parent] Cannot send event to an unknown parent");
370
- const s = g(t);
371
- (i = this.parent) == null || i.send(s);
372
- }), a(this, "log", (...t) => {
373
- X() && this.options.debug && console.log(...t);
374
- }), a(this, "send", (t) => {
375
- const s = g(t);
376
- this.transition(this.state.value, s);
377
- }), a(this, "transition", (t, s) => {
378
- var d, p;
379
- const i = v(t) ? this.getStateNode(t) : t == null ? void 0 : t.stateNode, r = g(s);
380
- if (!i && !this.config.on) {
381
- const y = this.status === "Stopped" ? "[@zag-js/core > transition] Cannot transition a stopped machine" : `[@zag-js/core > transition] State does not have a definition for \`state\`: ${t}, \`event\`: ${r.type}`;
382
- w(y);
383
- return;
384
- }
385
- const c = (
386
- // @ts-expect-error - Fix this
387
- ((d = i == null ? void 0 : i.on) == null ? void 0 : d[r.type]) ?? ((p = this.config.on) == null ? void 0 : p[r.type])
388
- ), u = this.getNextStateInfo(c, r);
389
- return this.performStateChangeEffects(this.state.value, u, r), u.stateNode;
390
- }), a(this, "subscribe", (t) => (this.stateListeners.add(t), this.status === "Running" && t(this.stateSnapshot), () => {
391
- this.stateListeners.delete(t);
392
- })), a(this, "onDone", (t) => (this.doneListeners.add(t), this)), a(this, "onTransition", (t) => (this.stateListeners.add(t), this.status === "Running" && t(this.stateSnapshot), this)), this.config = O(e), this.options = O(n ?? {}), this.id = this.config.id ?? `machine-${$()}`, this.guardMap = ((o = this.options) == null ? void 0 : o.guards) ?? {}, this.actionMap = ((h = this.options) == null ? void 0 : h.actions) ?? {}, this.delayMap = ((l = this.options) == null ? void 0 : l.delays) ?? {}, this.activityMap = ((f = this.options) == null ? void 0 : f.activities) ?? {}, this.sync = ((S = this.options) == null ? void 0 : S.sync) ?? !1, this.state = nt(this.config), this.initialContext = C(this.state.context);
393
- }
394
- // immutable state value
395
- get stateSnapshot() {
396
- return m(C(this.state));
397
- }
398
- getState() {
399
- return this.stateSnapshot;
400
- }
401
- // immutable context value
402
- get contextSnapshot() {
403
- return this.stateSnapshot.context;
404
- }
405
- /**
406
- * A reference to the instance methods of the machine.
407
- * Useful when spawning child machines and managing the communication between them.
408
- */
409
- get self() {
410
- const e = this;
411
- return {
412
- id: this.id,
413
- send: this.send.bind(this),
414
- sendParent: this.sendParent.bind(this),
415
- sendChild: this.sendChild.bind(this),
416
- stop: this.stop.bind(this),
417
- stopChild: this.stopChild.bind(this),
418
- spawn: this.spawn.bind(this),
419
- stopActivity: this.stopActivity.bind(this),
420
- get state() {
421
- return e.stateSnapshot;
422
- },
423
- get initialContext() {
424
- return e.initialContext;
425
- },
426
- get initialState() {
427
- var n;
428
- return ((n = e.initialState) == null ? void 0 : n.target) ?? "";
429
- }
430
- };
431
- }
432
- get meta() {
433
- var e;
434
- return {
435
- state: this.stateSnapshot,
436
- guards: this.guardMap,
437
- send: this.send.bind(this),
438
- self: this.self,
439
- initialContext: this.initialContext,
440
- initialState: ((e = this.initialState) == null ? void 0 : e.target) ?? "",
441
- getState: () => this.stateSnapshot,
442
- getAction: (n) => this.actionMap[n],
443
- getGuard: (n) => this.guardMap[n]
444
- };
445
- }
446
- get guardMeta() {
447
- return {
448
- state: this.stateSnapshot
449
- };
450
- }
451
- get [Symbol.toStringTag]() {
452
- return "Machine";
453
- }
454
- getHydrationState() {
455
- const e = this.getState();
456
- return {
457
- value: e.value,
458
- tags: e.tags
459
- };
460
- }
461
- }, gt = (e, n) => new k(e, n), yt = (e) => e instanceof k || (e == null ? void 0 : e.type) === "machine", ot = (...e) => e.map((n) => {
462
- var o;
463
- return (o = n == null ? void 0 : n.trim) == null ? void 0 : o.call(n);
464
- }).filter(Boolean).join(" "), ht = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g, z = (e) => {
465
- const n = {};
466
- let o;
467
- for (; o = ht.exec(e); )
468
- n[o[1]] = o[2];
469
- return n;
470
- }, ct = (e, n) => {
471
- if (v(e)) {
472
- if (v(n)) return `${e};${n}`;
473
- e = z(e);
474
- } else v(n) && (n = z(n));
475
- return Object.assign({}, e ?? {}, n ?? {});
476
- };
477
- function mt(...e) {
478
- let n = {};
479
- for (let o of e) {
480
- for (let h in n) {
481
- if (h.startsWith("on") && typeof n[h] == "function" && typeof o[h] == "function") {
482
- n[h] = q(o[h], n[h]);
483
- continue;
484
- }
485
- if (h === "className" || h === "class") {
486
- n[h] = ot(n[h], o[h]);
487
- continue;
488
- }
489
- if (h === "style") {
490
- n[h] = ct(n[h], o[h]);
491
- continue;
492
- }
493
- n[h] = o[h] !== void 0 ? o[h] : n[h];
494
- }
495
- for (let h in o)
496
- n[h] === void 0 && (n[h] = o[h]);
497
- }
498
- return n;
499
- }
500
84
  export {
501
- k as Machine,
502
- gt as createMachine,
503
- I as deepMerge,
504
- vt as guards,
505
- yt as isMachine,
506
- mt as mergeProps,
507
- R as proxy,
508
- P as ref,
509
- C as snapshot,
510
- _ as subscribe
85
+ p as INIT_STATE,
86
+ v as MachineStatus,
87
+ m as createGuards,
88
+ _ as createMachine,
89
+ w as createScope,
90
+ N as mergeProps,
91
+ h as setup
511
92
  };