@wirekyt/react 0.0.1 → 0.0.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/accordion.cjs +209 -0
- package/dist/accordion.d.cts +69 -0
- package/dist/accordion.d.ts +69 -0
- package/dist/accordion.js +184 -0
- package/dist/angle-slider.cjs +193 -0
- package/dist/angle-slider.d.cts +73 -0
- package/dist/angle-slider.d.ts +73 -0
- package/dist/angle-slider.js +168 -0
- package/dist/avatar.cjs +120 -0
- package/dist/avatar.d.cts +48 -0
- package/dist/avatar.d.ts +48 -0
- package/dist/avatar.js +100 -0
- package/dist/carousel.cjs +246 -0
- package/dist/carousel.d.cts +94 -0
- package/dist/carousel.d.ts +94 -0
- package/dist/carousel.js +223 -0
- package/dist/checkbox.cjs +284 -0
- package/dist/checkbox.d.cts +115 -0
- package/dist/checkbox.d.ts +115 -0
- package/dist/checkbox.js +263 -0
- package/dist/client-only.cjs +12 -0
- package/dist/client-only.d.cts +8 -0
- package/dist/client-only.d.ts +8 -0
- package/dist/client-only.js +11 -0
- package/dist/clipboard.cjs +174 -0
- package/dist/clipboard.d.cts +70 -0
- package/dist/clipboard.d.ts +70 -0
- package/dist/clipboard.js +150 -0
- package/dist/collapsible-B62i_oPJ.cjs +185 -0
- package/dist/collapsible-CiTNjCNf.js +131 -0
- package/dist/collapsible.cjs +23 -0
- package/dist/collapsible.d.cts +56 -0
- package/dist/collapsible.d.ts +56 -0
- package/dist/collapsible.js +2 -0
- package/dist/collection-BFjWNdUS.cjs +223 -0
- package/dist/collection-BJOl6a4H.js +180 -0
- package/dist/collection.cjs +9 -0
- package/dist/collection.d.cts +2 -0
- package/dist/collection.d.ts +2 -0
- package/dist/collection.js +2 -0
- package/dist/color-picker.cjs +575 -0
- package/dist/color-picker.d.cts +179 -0
- package/dist/color-picker.d.ts +179 -0
- package/dist/color-picker.js +530 -0
- package/dist/combobox.cjs +390 -0
- package/dist/combobox.d.cts +128 -0
- package/dist/combobox.d.ts +128 -0
- package/dist/combobox.js +359 -0
- package/dist/core-CBFAnVIP.cjs +375 -0
- package/dist/core-CEYOEcVI.js +357 -0
- package/dist/date-input.cjs +217 -0
- package/dist/date-input.d.cts +69 -0
- package/dist/date-input.d.ts +69 -0
- package/dist/date-input.js +193 -0
- package/dist/date-picker.cjs +588 -0
- package/dist/date-picker.d.cts +190 -0
- package/dist/date-picker.d.ts +190 -0
- package/dist/date-picker.js +543 -0
- package/dist/dialog.cjs +199 -0
- package/dist/dialog.d.cts +78 -0
- package/dist/dialog.d.ts +78 -0
- package/dist/dialog.js +174 -0
- package/dist/download-trigger.cjs +53 -0
- package/dist/download-trigger.d.cts +22 -0
- package/dist/download-trigger.d.ts +22 -0
- package/dist/download-trigger.js +51 -0
- package/dist/drawer.cjs +296 -0
- package/dist/drawer.d.cts +115 -0
- package/dist/drawer.d.ts +115 -0
- package/dist/drawer.js +264 -0
- package/dist/editable.cjs +228 -0
- package/dist/editable.d.cts +79 -0
- package/dist/editable.d.ts +79 -0
- package/dist/editable.js +202 -0
- package/dist/environment-B6IaCAuQ.cjs +59 -0
- package/dist/environment-BTgKwk5E.js +42 -0
- package/dist/factory--dkoVnFK.d.cts +14 -0
- package/dist/factory--dkoVnFK.d.ts +14 -0
- package/dist/factory-CFFufs5e.cjs +59 -0
- package/dist/factory-Nm__-4xn.js +48 -0
- package/dist/field-Cy1E02DH.js +349 -0
- package/dist/field-x8H5uXB9.cjs +438 -0
- package/dist/field.cjs +22 -0
- package/dist/field.d.cts +129 -0
- package/dist/field.d.ts +129 -0
- package/dist/field.js +2 -0
- package/dist/fieldset-DWZXj1t5.cjs +232 -0
- package/dist/fieldset-fx44GCtM.js +178 -0
- package/dist/fieldset.cjs +18 -0
- package/dist/fieldset.d.cts +71 -0
- package/dist/fieldset.d.ts +71 -0
- package/dist/fieldset.js +3 -0
- package/dist/file-upload.cjs +328 -0
- package/dist/file-upload.d.cts +101 -0
- package/dist/file-upload.d.ts +101 -0
- package/dist/file-upload.js +298 -0
- package/dist/floating-panel.cjs +271 -0
- package/dist/floating-panel.d.cts +98 -0
- package/dist/floating-panel.d.ts +98 -0
- package/dist/floating-panel.js +242 -0
- package/dist/format.cjs +64 -0
- package/dist/format.d.cts +44 -0
- package/dist/format.d.ts +44 -0
- package/dist/format.js +54 -0
- package/dist/frame.cjs +85 -0
- package/dist/frame.d.cts +12 -0
- package/dist/frame.d.ts +12 -0
- package/dist/frame.js +84 -0
- package/dist/highlight.cjs +29 -0
- package/dist/highlight.d.cts +13 -0
- package/dist/highlight.d.ts +13 -0
- package/dist/highlight.js +27 -0
- package/dist/hover-card.cjs +154 -0
- package/dist/hover-card.d.cts +68 -0
- package/dist/hover-card.d.ts +68 -0
- package/dist/hover-card.js +131 -0
- package/dist/image-cropper.cjs +0 -0
- package/dist/image-cropper.d.cts +1 -0
- package/dist/image-cropper.d.ts +1 -0
- package/dist/image-cropper.js +0 -0
- package/dist/index-3Al0R5bH.d.cts +73 -0
- package/dist/index-B7wAg5Wf.d.ts +146 -0
- package/dist/index-BAn8qiCM.d.ts +73 -0
- package/dist/index-BSX88T_g.d.cts +146 -0
- package/dist/index-CQAbOgb7.d.cts +23 -0
- package/dist/index-CUyHBXOI.d.cts +33 -0
- package/dist/index-CW-Aj6aT.d.ts +95 -0
- package/dist/index-CxWYgVJk.d.ts +23 -0
- package/dist/index-D7JH9e9E.d.ts +33 -0
- package/dist/index-DTLK6Fuh.d.cts +95 -0
- package/dist/index-srZfUQNt.d.cts +20 -0
- package/dist/index-srZfUQNt.d.ts +20 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/json-tree-view.cjs +244 -0
- package/dist/json-tree-view.d.cts +45 -0
- package/dist/json-tree-view.d.ts +45 -0
- package/dist/json-tree-view.js +234 -0
- package/dist/listbox.cjs +290 -0
- package/dist/listbox.d.cts +109 -0
- package/dist/listbox.d.ts +109 -0
- package/dist/listbox.js +264 -0
- package/dist/marquee.cjs +164 -0
- package/dist/marquee.d.cts +60 -0
- package/dist/marquee.d.ts +60 -0
- package/dist/marquee.js +142 -0
- package/dist/menu.cjs +506 -0
- package/dist/menu.d.cts +162 -0
- package/dist/menu.d.ts +162 -0
- package/dist/menu.js +469 -0
- package/dist/navigation-menu.cjs +331 -0
- package/dist/navigation-menu.d.cts +89 -0
- package/dist/navigation-menu.d.ts +89 -0
- package/dist/navigation-menu.js +303 -0
- package/dist/number-input.cjs +222 -0
- package/dist/number-input.d.cts +73 -0
- package/dist/number-input.d.ts +73 -0
- package/dist/number-input.js +197 -0
- package/dist/pagination.cjs +183 -0
- package/dist/pagination.d.cts +68 -0
- package/dist/pagination.d.ts +68 -0
- package/dist/pagination.js +159 -0
- package/dist/password-input.cjs +179 -0
- package/dist/password-input.d.cts +65 -0
- package/dist/password-input.d.ts +65 -0
- package/dist/password-input.js +156 -0
- package/dist/pin-input.cjs +180 -0
- package/dist/pin-input.d.cts +58 -0
- package/dist/pin-input.d.ts +58 -0
- package/dist/pin-input.js +158 -0
- package/dist/popover.cjs +222 -0
- package/dist/popover.d.cts +93 -0
- package/dist/popover.d.ts +93 -0
- package/dist/popover.js +194 -0
- package/dist/portal-6_XzBXiA.cjs +33 -0
- package/dist/portal-QYL_2wB0.js +28 -0
- package/dist/portal.cjs +3 -0
- package/dist/portal.d.cts +9 -0
- package/dist/portal.d.ts +9 -0
- package/dist/portal.js +2 -0
- package/dist/presence-BOs-D6Cv.cjs +96 -0
- package/dist/presence-I8Rceflw.js +65 -0
- package/dist/presence.cjs +7 -0
- package/dist/presence.d.cts +2 -0
- package/dist/presence.d.ts +2 -0
- package/dist/presence.js +2 -0
- package/dist/progress.cjs +206 -0
- package/dist/progress.d.cts +78 -0
- package/dist/progress.d.ts +78 -0
- package/dist/progress.js +180 -0
- package/dist/providers-DrJEJcrE.cjs +128 -0
- package/dist/providers-FEHnDTvb.js +87 -0
- package/dist/qr-code.cjs +154 -0
- package/dist/qr-code.d.cts +58 -0
- package/dist/qr-code.d.ts +58 -0
- package/dist/qr-code.js +132 -0
- package/dist/radio-group.cjs +222 -0
- package/dist/radio-group.d.cts +78 -0
- package/dist/radio-group.d.ts +78 -0
- package/dist/radio-group.js +196 -0
- package/dist/rating-group.cjs +186 -0
- package/dist/rating-group.d.cts +68 -0
- package/dist/rating-group.d.ts +68 -0
- package/dist/rating-group.js +162 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/rolldown-runtime-DakpK96I.cjs +43 -0
- package/dist/scroll-area.cjs +166 -0
- package/dist/scroll-area.d.cts +67 -0
- package/dist/scroll-area.d.ts +67 -0
- package/dist/scroll-area.js +143 -0
- package/dist/segment-group.cjs +215 -0
- package/dist/segment-group.d.cts +81 -0
- package/dist/segment-group.d.ts +81 -0
- package/dist/segment-group.js +194 -0
- package/dist/select.cjs +395 -0
- package/dist/select.d.cts +132 -0
- package/dist/select.d.ts +132 -0
- package/dist/select.js +358 -0
- package/dist/signature-pad.cjs +197 -0
- package/dist/signature-pad.d.cts +68 -0
- package/dist/signature-pad.d.ts +68 -0
- package/dist/signature-pad.js +173 -0
- package/dist/slider.cjs +260 -0
- package/dist/slider.d.cts +88 -0
- package/dist/slider.d.ts +88 -0
- package/dist/slider.js +232 -0
- package/dist/steps.cjs +271 -0
- package/dist/steps.d.cts +104 -0
- package/dist/steps.d.ts +104 -0
- package/dist/steps.js +241 -0
- package/dist/swap.cjs +134 -0
- package/dist/swap.d.cts +49 -0
- package/dist/swap.d.ts +49 -0
- package/dist/swap.js +121 -0
- package/dist/switch.cjs +166 -0
- package/dist/switch.d.cts +58 -0
- package/dist/switch.d.ts +58 -0
- package/dist/switch.js +144 -0
- package/dist/tabs.cjs +177 -0
- package/dist/tabs.d.cts +59 -0
- package/dist/tabs.d.ts +59 -0
- package/dist/tabs.js +155 -0
- package/dist/tags-input.cjs +298 -0
- package/dist/tags-input.d.cts +98 -0
- package/dist/tags-input.d.ts +98 -0
- package/dist/tags-input.js +268 -0
- package/dist/timer.cjs +167 -0
- package/dist/timer.d.cts +63 -0
- package/dist/timer.d.ts +63 -0
- package/dist/timer.js +144 -0
- package/dist/toast.cjs +154 -0
- package/dist/toast.d.cts +59 -0
- package/dist/toast.d.ts +59 -0
- package/dist/toast.js +132 -0
- package/dist/toggle-group.cjs +118 -0
- package/dist/toggle-group.d.cts +43 -0
- package/dist/toggle-group.d.ts +43 -0
- package/dist/toggle-group.js +99 -0
- package/dist/toggle.cjs +85 -0
- package/dist/toggle.d.cts +38 -0
- package/dist/toggle.d.ts +38 -0
- package/dist/toggle.js +71 -0
- package/dist/tooltip.cjs +154 -0
- package/dist/tooltip.d.cts +68 -0
- package/dist/tooltip.d.ts +68 -0
- package/dist/tooltip.js +131 -0
- package/dist/tour.cjs +290 -0
- package/dist/tour.d.cts +112 -0
- package/dist/tour.d.ts +112 -0
- package/dist/tour.js +246 -0
- package/dist/tree-view-CNTEWXlu.js +339 -0
- package/dist/tree-view-CU4Hl5X1.cjs +484 -0
- package/dist/tree-view.cjs +41 -0
- package/dist/tree-view.d.cts +3 -0
- package/dist/tree-view.d.ts +3 -0
- package/dist/tree-view.js +3 -0
- package/dist/types-BQQfrr86.d.cts +6 -0
- package/dist/types-BQQfrr86.d.ts +6 -0
- package/dist/use-context-38DKWHsx.cjs +20 -0
- package/dist/use-context-CITa6pn9.js +10 -0
- package/dist/utils-Cfwm9WW1.cjs +166 -0
- package/dist/utils-CqLmqrgj.js +107 -0
- package/package.json +274 -6
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-DakpK96I.cjs");
|
|
2
|
+
let _wirekyt_dom_utils = require("@wirekyt/dom/utils");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
react = require_rolldown_runtime.__toESM(react, 1);
|
|
5
|
+
let _wirekyt_dom = require("@wirekyt/dom");
|
|
6
|
+
let react_dom = require("react-dom");
|
|
7
|
+
let _wirekyt_dom_types = require("@wirekyt/dom/types");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
//#region src/core/use-layout-effect.ts
|
|
10
|
+
const useSafeLayoutEffect = typeof globalThis.document !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/core/bindable.ts
|
|
13
|
+
function useBindable(props) {
|
|
14
|
+
const initial = props().value ?? props().defaultValue;
|
|
15
|
+
const eq = props().isEqual ?? Object.is;
|
|
16
|
+
const [initialValue] = (0, react.useState)(initial);
|
|
17
|
+
const [value, setValue] = (0, react.useState)(initialValue);
|
|
18
|
+
const controlled = props().value !== void 0;
|
|
19
|
+
const valueRef = (0, react.useRef)(value);
|
|
20
|
+
valueRef.current = controlled ? props().value : value;
|
|
21
|
+
const prevValue = (0, react.useRef)(valueRef.current);
|
|
22
|
+
useSafeLayoutEffect(() => {
|
|
23
|
+
prevValue.current = valueRef.current;
|
|
24
|
+
}, [value, props().value]);
|
|
25
|
+
const setFn = (value) => {
|
|
26
|
+
const prev = prevValue.current;
|
|
27
|
+
const next = (0, _wirekyt_dom_utils.isFunction)(value) ? value(prev) : value;
|
|
28
|
+
if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
|
|
29
|
+
next,
|
|
30
|
+
prev
|
|
31
|
+
});
|
|
32
|
+
if (!controlled) setValue(next);
|
|
33
|
+
if (!eq(next, prev)) props().onChange?.(next, prev);
|
|
34
|
+
};
|
|
35
|
+
function get() {
|
|
36
|
+
return controlled ? props().value : value;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
initial: initialValue,
|
|
40
|
+
ref: valueRef,
|
|
41
|
+
get,
|
|
42
|
+
set(value) {
|
|
43
|
+
(props().sync ? react_dom.flushSync : _wirekyt_dom_utils.identity)(() => setFn(value));
|
|
44
|
+
},
|
|
45
|
+
invoke(nextValue, prevValue) {
|
|
46
|
+
props().onChange?.(nextValue, prevValue);
|
|
47
|
+
},
|
|
48
|
+
hash(value) {
|
|
49
|
+
return props().hash?.(value) ?? String(value);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
useBindable.cleanup = (fn) => {
|
|
54
|
+
(0, react.useEffect)(() => fn, []);
|
|
55
|
+
};
|
|
56
|
+
useBindable.ref = (defaultValue) => {
|
|
57
|
+
const value = (0, react.useRef)(defaultValue);
|
|
58
|
+
return {
|
|
59
|
+
get: () => value.current,
|
|
60
|
+
set: (next) => {
|
|
61
|
+
value.current = next;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/core/refs.ts
|
|
67
|
+
function useRefs(refs) {
|
|
68
|
+
const ref = (0, react.useRef)(refs);
|
|
69
|
+
return {
|
|
70
|
+
get(key) {
|
|
71
|
+
return ref.current[key];
|
|
72
|
+
},
|
|
73
|
+
set(key, value) {
|
|
74
|
+
ref.current[key] = value;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/core/track.ts
|
|
80
|
+
const useTrack = (deps, effect) => {
|
|
81
|
+
const render = (0, react.useRef)(false);
|
|
82
|
+
const called = (0, react.useRef)(false);
|
|
83
|
+
(0, react.useEffect)(() => {
|
|
84
|
+
if (render.current && called.current) return effect();
|
|
85
|
+
called.current = true;
|
|
86
|
+
}, (deps ?? []).map((d) => typeof d === "function" ? d() : d));
|
|
87
|
+
(0, react.useEffect)(() => {
|
|
88
|
+
render.current = true;
|
|
89
|
+
return () => {
|
|
90
|
+
render.current = false;
|
|
91
|
+
};
|
|
92
|
+
}, []);
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/core/machine.ts
|
|
96
|
+
function useMachine(machine, userProps = {}) {
|
|
97
|
+
const scope = (0, react.useMemo)(() => {
|
|
98
|
+
const { id, ids, getRootNode } = userProps;
|
|
99
|
+
return (0, _wirekyt_dom.createScope)({
|
|
100
|
+
id,
|
|
101
|
+
ids,
|
|
102
|
+
getRootNode
|
|
103
|
+
});
|
|
104
|
+
}, [userProps]);
|
|
105
|
+
const debug = (...args) => {
|
|
106
|
+
if (machine.debug) console.log(...args);
|
|
107
|
+
};
|
|
108
|
+
const prop = useProp(machine.props?.({
|
|
109
|
+
props: (0, _wirekyt_dom_utils.compact)(userProps),
|
|
110
|
+
scope
|
|
111
|
+
}) ?? userProps);
|
|
112
|
+
const context = machine.context?.({
|
|
113
|
+
prop,
|
|
114
|
+
bindable: useBindable,
|
|
115
|
+
scope,
|
|
116
|
+
flush,
|
|
117
|
+
getContext() {
|
|
118
|
+
return ctx;
|
|
119
|
+
},
|
|
120
|
+
getComputed() {
|
|
121
|
+
return computed;
|
|
122
|
+
},
|
|
123
|
+
getRefs() {
|
|
124
|
+
return refs;
|
|
125
|
+
},
|
|
126
|
+
getEvent() {
|
|
127
|
+
return getEvent();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const contextRef = useLiveRef(context);
|
|
131
|
+
const ctx = {
|
|
132
|
+
get(key) {
|
|
133
|
+
return contextRef.current?.[key].ref.current;
|
|
134
|
+
},
|
|
135
|
+
set(key, value) {
|
|
136
|
+
contextRef.current?.[key].set(value);
|
|
137
|
+
},
|
|
138
|
+
initial(key) {
|
|
139
|
+
return contextRef.current?.[key].initial;
|
|
140
|
+
},
|
|
141
|
+
hash(key) {
|
|
142
|
+
const current = contextRef.current?.[key].get();
|
|
143
|
+
return contextRef.current?.[key].hash(current);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const effects = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
147
|
+
const transitionRef = (0, react.useRef)(null);
|
|
148
|
+
const previousEventRef = (0, react.useRef)(null);
|
|
149
|
+
const eventRef = (0, react.useRef)({ type: "" });
|
|
150
|
+
const getEvent = () => ({
|
|
151
|
+
...eventRef.current,
|
|
152
|
+
current() {
|
|
153
|
+
return eventRef.current;
|
|
154
|
+
},
|
|
155
|
+
previous() {
|
|
156
|
+
return previousEventRef.current;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
const getState = () => ({
|
|
160
|
+
...state,
|
|
161
|
+
matches(...values) {
|
|
162
|
+
return values.some((value) => (0, _wirekyt_dom.matchesState)(state.ref.current, value));
|
|
163
|
+
},
|
|
164
|
+
hasTag(tag) {
|
|
165
|
+
return (0, _wirekyt_dom.hasTag)(machine, state.ref.current, tag);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const refs = useRefs(machine.refs?.({
|
|
169
|
+
prop,
|
|
170
|
+
context: ctx
|
|
171
|
+
}) ?? {});
|
|
172
|
+
const getParams = () => ({
|
|
173
|
+
state: getState(),
|
|
174
|
+
context: ctx,
|
|
175
|
+
event: getEvent(),
|
|
176
|
+
prop,
|
|
177
|
+
send,
|
|
178
|
+
action,
|
|
179
|
+
guard,
|
|
180
|
+
track: useTrack,
|
|
181
|
+
refs,
|
|
182
|
+
computed,
|
|
183
|
+
flush,
|
|
184
|
+
scope,
|
|
185
|
+
choose
|
|
186
|
+
});
|
|
187
|
+
const action = (keys) => {
|
|
188
|
+
const strs = (0, _wirekyt_dom_utils.isFunction)(keys) ? keys(getParams()) : keys;
|
|
189
|
+
if (!strs) return;
|
|
190
|
+
const fns = strs.map((s) => {
|
|
191
|
+
const fn = machine.implementations?.actions?.[s];
|
|
192
|
+
if (!fn) (0, _wirekyt_dom_utils.warn)(`[wirekyt] No implementation found for action "${JSON.stringify(s)}"`);
|
|
193
|
+
return fn;
|
|
194
|
+
});
|
|
195
|
+
for (const fn of fns) fn?.(getParams());
|
|
196
|
+
};
|
|
197
|
+
const guard = (str) => {
|
|
198
|
+
if ((0, _wirekyt_dom_utils.isFunction)(str)) return str(getParams());
|
|
199
|
+
const fn = machine.implementations?.guards?.[str];
|
|
200
|
+
if (!fn) (0, _wirekyt_dom_utils.warn)(`[wirekyt] No implementation found for guard "${JSON.stringify(str)}"`);
|
|
201
|
+
return fn?.(getParams());
|
|
202
|
+
};
|
|
203
|
+
const effect = (keys) => {
|
|
204
|
+
const strs = (0, _wirekyt_dom_utils.isFunction)(keys) ? keys(getParams()) : keys;
|
|
205
|
+
if (!strs) return;
|
|
206
|
+
const fns = strs.map((s) => {
|
|
207
|
+
const fn = machine.implementations?.effects?.[s];
|
|
208
|
+
if (!fn) (0, _wirekyt_dom_utils.warn)(`[wirekyt] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
209
|
+
return fn;
|
|
210
|
+
});
|
|
211
|
+
const cleanups = [];
|
|
212
|
+
for (const fn of fns) {
|
|
213
|
+
const cleanup = fn?.(getParams());
|
|
214
|
+
if (cleanup) cleanups.push(cleanup);
|
|
215
|
+
}
|
|
216
|
+
return () => cleanups.forEach((fn) => fn?.());
|
|
217
|
+
};
|
|
218
|
+
const choose = (transitions) => {
|
|
219
|
+
return (0, _wirekyt_dom_utils.toArray)(transitions).find((t) => {
|
|
220
|
+
let result = !t.guard;
|
|
221
|
+
if ((0, _wirekyt_dom_utils.isString)(t.guard)) result = !!guard(t.guard);
|
|
222
|
+
else if ((0, _wirekyt_dom_utils.isFunction)(t.guard)) result = t.guard(getParams());
|
|
223
|
+
return result;
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
const computed = (key) => {
|
|
227
|
+
(0, _wirekyt_dom_utils.ensure)(machine.computed, () => `[wirekyt] No computed object found on machine`);
|
|
228
|
+
const fn = machine.computed[key];
|
|
229
|
+
return fn({
|
|
230
|
+
context: ctx,
|
|
231
|
+
event: getEvent(),
|
|
232
|
+
prop,
|
|
233
|
+
refs,
|
|
234
|
+
scope,
|
|
235
|
+
computed
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
const state = useBindable(() => ({
|
|
239
|
+
defaultValue: (0, _wirekyt_dom.resolveStateValue)(machine, machine.initialState({ prop })),
|
|
240
|
+
onChange(nextState, prevState) {
|
|
241
|
+
const { exiting, entering } = (0, _wirekyt_dom.getExitEnterStates)(machine, prevState, nextState, transitionRef.current?.reenter);
|
|
242
|
+
exiting.forEach((item) => {
|
|
243
|
+
effects.current.get(item.path)?.();
|
|
244
|
+
effects.current.delete(item.path);
|
|
245
|
+
});
|
|
246
|
+
exiting.forEach((item) => {
|
|
247
|
+
action(item.state?.exit);
|
|
248
|
+
});
|
|
249
|
+
action(transitionRef.current?.actions);
|
|
250
|
+
entering.forEach((item) => {
|
|
251
|
+
const cleanup = effect(item.state?.effects);
|
|
252
|
+
if (cleanup) {
|
|
253
|
+
const existing = effects.current.get(item.path);
|
|
254
|
+
effects.current.set(item.path, existing ? (0, _wirekyt_dom_utils.callAll)(existing, cleanup) : cleanup);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
if (prevState === _wirekyt_dom.INIT_STATE) {
|
|
258
|
+
action(machine.entry);
|
|
259
|
+
const cleanup = effect(machine.effects);
|
|
260
|
+
if (cleanup) {
|
|
261
|
+
const existing = effects.current.get(_wirekyt_dom.INIT_STATE);
|
|
262
|
+
effects.current.set(_wirekyt_dom.INIT_STATE, existing ? (0, _wirekyt_dom_utils.callAll)(existing, cleanup) : cleanup);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
entering.forEach((item) => {
|
|
266
|
+
action(item.state?.entry);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}));
|
|
270
|
+
const hydratedStateRef = (0, react.useRef)(void 0);
|
|
271
|
+
const statusRef = (0, react.useRef)(_wirekyt_dom.MachineStatus.NotStarted);
|
|
272
|
+
useSafeLayoutEffect(() => {
|
|
273
|
+
queueMicrotask(() => {
|
|
274
|
+
const started = statusRef.current === _wirekyt_dom.MachineStatus.Started;
|
|
275
|
+
statusRef.current = _wirekyt_dom.MachineStatus.Started;
|
|
276
|
+
debug(started ? "rehydrating..." : "initializing...");
|
|
277
|
+
const initialState = hydratedStateRef.current ?? state.initial;
|
|
278
|
+
state.invoke(initialState, started ? state.get() : _wirekyt_dom.INIT_STATE);
|
|
279
|
+
});
|
|
280
|
+
const fns = effects.current;
|
|
281
|
+
return () => {
|
|
282
|
+
const currentState = getCurrentState();
|
|
283
|
+
debug("unmounting...");
|
|
284
|
+
hydratedStateRef.current = currentState;
|
|
285
|
+
statusRef.current = _wirekyt_dom.MachineStatus.Stopped;
|
|
286
|
+
fns.forEach((fn) => fn?.());
|
|
287
|
+
effects.current = /* @__PURE__ */ new Map();
|
|
288
|
+
transitionRef.current = null;
|
|
289
|
+
queueMicrotask(() => {
|
|
290
|
+
action(machine.exit);
|
|
291
|
+
statusRef.current = _wirekyt_dom.MachineStatus.Stopped;
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
}, []);
|
|
295
|
+
const getCurrentState = () => {
|
|
296
|
+
if ("ref" in state) return state.ref.current;
|
|
297
|
+
return state.get();
|
|
298
|
+
};
|
|
299
|
+
const send = (event) => {
|
|
300
|
+
queueMicrotask(() => {
|
|
301
|
+
if (statusRef.current !== _wirekyt_dom.MachineStatus.Started) return;
|
|
302
|
+
previousEventRef.current = eventRef.current;
|
|
303
|
+
eventRef.current = event;
|
|
304
|
+
let currentState = getCurrentState();
|
|
305
|
+
const { transitions, source } = (0, _wirekyt_dom.findTransition)(machine, currentState, event.type);
|
|
306
|
+
const transition = choose(transitions);
|
|
307
|
+
if (!transition) return;
|
|
308
|
+
transitionRef.current = transition;
|
|
309
|
+
const target = (0, _wirekyt_dom.resolveStateValue)(machine, transition.target ?? currentState, source);
|
|
310
|
+
debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
|
|
311
|
+
if (target !== currentState) (0, react_dom.flushSync)(() => state.set(target));
|
|
312
|
+
else if (transition.reenter) state.invoke(currentState, currentState);
|
|
313
|
+
else action(transition.actions ?? []);
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
machine.watch?.(getParams());
|
|
317
|
+
return {
|
|
318
|
+
state: getState(),
|
|
319
|
+
send,
|
|
320
|
+
context: ctx,
|
|
321
|
+
prop,
|
|
322
|
+
scope,
|
|
323
|
+
refs,
|
|
324
|
+
computed,
|
|
325
|
+
event: getEvent(),
|
|
326
|
+
getStatus: () => statusRef.current
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function useLiveRef(value) {
|
|
330
|
+
const ref = (0, react.useRef)(value);
|
|
331
|
+
ref.current = value;
|
|
332
|
+
return ref;
|
|
333
|
+
}
|
|
334
|
+
function useProp(value) {
|
|
335
|
+
const ref = useLiveRef(value);
|
|
336
|
+
return function get(key) {
|
|
337
|
+
return ref.current[key];
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function flush(fn) {
|
|
341
|
+
queueMicrotask(() => {
|
|
342
|
+
(0, react_dom.flushSync)(() => fn());
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/core/normalize-props.ts
|
|
347
|
+
const normalizeProps = (0, _wirekyt_dom_types.createNormalizer)((v) => v);
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/core/portal.tsx
|
|
350
|
+
const Portal = (props) => {
|
|
351
|
+
const { children, container, disabled, getRootNode } = props;
|
|
352
|
+
if (typeof window === "undefined" || disabled) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children });
|
|
353
|
+
const doc = getRootNode?.().ownerDocument ?? document;
|
|
354
|
+
const mountNode = container?.current ?? doc.body;
|
|
355
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: react.Children.map(children, (child) => (0, react_dom.createPortal)(child, mountNode)) });
|
|
356
|
+
};
|
|
357
|
+
//#endregion
|
|
358
|
+
Object.defineProperty(exports, "Portal", {
|
|
359
|
+
enumerable: true,
|
|
360
|
+
get: function() {
|
|
361
|
+
return Portal;
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
Object.defineProperty(exports, "normalizeProps", {
|
|
365
|
+
enumerable: true,
|
|
366
|
+
get: function() {
|
|
367
|
+
return normalizeProps;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
Object.defineProperty(exports, "useMachine", {
|
|
371
|
+
enumerable: true,
|
|
372
|
+
get: function() {
|
|
373
|
+
return useMachine;
|
|
374
|
+
}
|
|
375
|
+
});
|