@sprawlify/react 0.0.2 → 0.0.3
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/chunk-CbegLjfk.mjs +18 -0
- package/dist/components/collapsible/index.cjs +168 -0
- package/dist/components/collapsible/index.d.cts +62 -0
- package/dist/components/collapsible/index.d.mts +60 -0
- package/dist/components/collapsible/index.mjs +149 -0
- package/dist/{utils-DQoI5AQQ.cjs → create-context-DCEySQ7J.cjs} +1 -2
- package/dist/{utils-CVmRc1p7.mjs → create-context-fSIoyq0R.mjs} +1 -2
- package/dist/factory-B_Ye-J6y.mjs +499 -0
- package/dist/factory-CfqPG186.cjs +616 -0
- package/dist/index.cjs +15 -536
- package/dist/index.d.cts +3 -28
- package/dist/index.d.mts +3 -40
- package/dist/index.mjs +3 -497
- package/dist/types-B_h5HVp2.d.cts +29 -0
- package/dist/types-CwELsIN6.d.mts +41 -0
- package/dist/utils/index.cjs +4 -3
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +2 -1
- package/dist/utils-CM4cOr5z.mjs +3 -0
- package/dist/utils-Cb5K29pi.cjs +1 -0
- package/package.json +12 -2
- /package/dist/{index-D-QxCLG0.d.cts → index-BbLlW5Mk.d.cts} +0 -0
- /package/dist/{index-BbV54I7I.d.mts → index-CgR7RZbW.d.mts} +0 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (all, symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
36
|
+
value: mod,
|
|
37
|
+
enumerable: true
|
|
38
|
+
}) : target, mod));
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
const require_create_context = require('./create-context-DCEySQ7J.cjs');
|
|
42
|
+
let __sprawlify_primitives_core = require("@sprawlify/primitives/core");
|
|
43
|
+
let __sprawlify_primitives_utils = require("@sprawlify/primitives/utils");
|
|
44
|
+
let react = require("react");
|
|
45
|
+
react = __toESM(react);
|
|
46
|
+
let react_dom = require("react-dom");
|
|
47
|
+
let __sprawlify_primitives_types = require("@sprawlify/primitives/types");
|
|
48
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
49
|
+
let __sprawlify_primitives_dom_query = require("@sprawlify/primitives/dom-query");
|
|
50
|
+
let __sprawlify_primitives_i18n_utils = require("@sprawlify/primitives/i18n-utils");
|
|
51
|
+
|
|
52
|
+
//#region src/core/use-layout-effect.ts
|
|
53
|
+
const useSafeLayoutEffect = typeof globalThis.document !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/core/bindable.ts
|
|
57
|
+
function useBindable(props) {
|
|
58
|
+
const initial = props().value ?? props().defaultValue;
|
|
59
|
+
const eq = props().isEqual ?? Object.is;
|
|
60
|
+
const [initialValue] = (0, react.useState)(initial);
|
|
61
|
+
const [value, setValue] = (0, react.useState)(initialValue);
|
|
62
|
+
const controlled = props().value !== void 0;
|
|
63
|
+
const valueRef = (0, react.useRef)(value);
|
|
64
|
+
valueRef.current = controlled ? props().value : value;
|
|
65
|
+
const prevValue = (0, react.useRef)(valueRef.current);
|
|
66
|
+
useSafeLayoutEffect(() => {
|
|
67
|
+
prevValue.current = valueRef.current;
|
|
68
|
+
}, [value, props().value]);
|
|
69
|
+
const setFn = (value$1) => {
|
|
70
|
+
const prev = prevValue.current;
|
|
71
|
+
const next = (0, __sprawlify_primitives_utils.isFunction)(value$1) ? value$1(prev) : value$1;
|
|
72
|
+
if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
|
|
73
|
+
next,
|
|
74
|
+
prev
|
|
75
|
+
});
|
|
76
|
+
if (!controlled) setValue(next);
|
|
77
|
+
if (!eq(next, prev)) props().onChange?.(next, prev);
|
|
78
|
+
};
|
|
79
|
+
function get() {
|
|
80
|
+
return controlled ? props().value : value;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
initial: initialValue,
|
|
84
|
+
ref: valueRef,
|
|
85
|
+
get,
|
|
86
|
+
set(value$1) {
|
|
87
|
+
(props().sync ? react_dom.flushSync : __sprawlify_primitives_utils.identity)(() => setFn(value$1));
|
|
88
|
+
},
|
|
89
|
+
invoke(nextValue, prevValue$1) {
|
|
90
|
+
props().onChange?.(nextValue, prevValue$1);
|
|
91
|
+
},
|
|
92
|
+
hash(value$1) {
|
|
93
|
+
return props().hash?.(value$1) ?? String(value$1);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
useBindable.cleanup = (fn) => {
|
|
98
|
+
(0, react.useEffect)(() => fn, []);
|
|
99
|
+
};
|
|
100
|
+
useBindable.ref = (defaultValue) => {
|
|
101
|
+
const value = (0, react.useRef)(defaultValue);
|
|
102
|
+
return {
|
|
103
|
+
get: () => value.current,
|
|
104
|
+
set: (next) => {
|
|
105
|
+
value.current = next;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/core/refs.ts
|
|
112
|
+
function useRefs(refs) {
|
|
113
|
+
const ref = (0, react.useRef)(refs);
|
|
114
|
+
return {
|
|
115
|
+
get(key) {
|
|
116
|
+
return ref.current[key];
|
|
117
|
+
},
|
|
118
|
+
set(key, value) {
|
|
119
|
+
ref.current[key] = value;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/core/track.ts
|
|
126
|
+
const useTrack = (deps, effect) => {
|
|
127
|
+
const render = (0, react.useRef)(false);
|
|
128
|
+
const called = (0, react.useRef)(false);
|
|
129
|
+
(0, react.useEffect)(() => {
|
|
130
|
+
if (render.current && called.current) return effect();
|
|
131
|
+
called.current = true;
|
|
132
|
+
}, [...(deps ?? []).map((d) => typeof d === "function" ? d() : d)]);
|
|
133
|
+
(0, react.useEffect)(() => {
|
|
134
|
+
render.current = true;
|
|
135
|
+
return () => {
|
|
136
|
+
render.current = false;
|
|
137
|
+
};
|
|
138
|
+
}, []);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/core/machine.ts
|
|
143
|
+
function useMachine(machine, userProps = {}) {
|
|
144
|
+
const scope = (0, react.useMemo)(() => {
|
|
145
|
+
const { id, ids, getRootNode } = userProps;
|
|
146
|
+
return (0, __sprawlify_primitives_core.createScope)({
|
|
147
|
+
id,
|
|
148
|
+
ids,
|
|
149
|
+
getRootNode
|
|
150
|
+
});
|
|
151
|
+
}, [userProps]);
|
|
152
|
+
const debug = (...args) => {
|
|
153
|
+
if (machine.debug) console.log(...args);
|
|
154
|
+
};
|
|
155
|
+
const prop = useProp(machine.props?.({
|
|
156
|
+
props: (0, __sprawlify_primitives_utils.compact)(userProps),
|
|
157
|
+
scope
|
|
158
|
+
}) ?? userProps);
|
|
159
|
+
const context = machine.context?.({
|
|
160
|
+
prop,
|
|
161
|
+
bindable: useBindable,
|
|
162
|
+
scope,
|
|
163
|
+
flush,
|
|
164
|
+
getContext() {
|
|
165
|
+
return ctx;
|
|
166
|
+
},
|
|
167
|
+
getComputed() {
|
|
168
|
+
return computed;
|
|
169
|
+
},
|
|
170
|
+
getRefs() {
|
|
171
|
+
return refs;
|
|
172
|
+
},
|
|
173
|
+
getEvent() {
|
|
174
|
+
return getEvent();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const contextRef = useLiveRef(context);
|
|
178
|
+
const ctx = {
|
|
179
|
+
get(key) {
|
|
180
|
+
return contextRef.current?.[key].ref.current;
|
|
181
|
+
},
|
|
182
|
+
set(key, value) {
|
|
183
|
+
contextRef.current?.[key].set(value);
|
|
184
|
+
},
|
|
185
|
+
initial(key) {
|
|
186
|
+
return contextRef.current?.[key].initial;
|
|
187
|
+
},
|
|
188
|
+
hash(key) {
|
|
189
|
+
const current = contextRef.current?.[key].get();
|
|
190
|
+
return contextRef.current?.[key].hash(current);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const effects = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
194
|
+
const transitionRef = (0, react.useRef)(null);
|
|
195
|
+
const previousEventRef = (0, react.useRef)(null);
|
|
196
|
+
const eventRef = (0, react.useRef)({ type: "" });
|
|
197
|
+
const getEvent = () => ({
|
|
198
|
+
...eventRef.current,
|
|
199
|
+
current() {
|
|
200
|
+
return eventRef.current;
|
|
201
|
+
},
|
|
202
|
+
previous() {
|
|
203
|
+
return previousEventRef.current;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const getState = () => ({
|
|
207
|
+
...state,
|
|
208
|
+
matches(...values) {
|
|
209
|
+
return values.includes(state.ref.current);
|
|
210
|
+
},
|
|
211
|
+
hasTag(tag) {
|
|
212
|
+
return !!machine.states[state.ref.current]?.tags?.includes(tag);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const refs = useRefs(machine.refs?.({
|
|
216
|
+
prop,
|
|
217
|
+
context: ctx
|
|
218
|
+
}) ?? {});
|
|
219
|
+
const getParams = () => ({
|
|
220
|
+
state: getState(),
|
|
221
|
+
context: ctx,
|
|
222
|
+
event: getEvent(),
|
|
223
|
+
prop,
|
|
224
|
+
send,
|
|
225
|
+
action,
|
|
226
|
+
guard,
|
|
227
|
+
track: useTrack,
|
|
228
|
+
refs,
|
|
229
|
+
computed,
|
|
230
|
+
flush,
|
|
231
|
+
scope,
|
|
232
|
+
choose
|
|
233
|
+
});
|
|
234
|
+
const action = (keys) => {
|
|
235
|
+
const strs = (0, __sprawlify_primitives_utils.isFunction)(keys) ? keys(getParams()) : keys;
|
|
236
|
+
if (!strs) return;
|
|
237
|
+
const fns = strs.map((s) => {
|
|
238
|
+
const fn = machine.implementations?.actions?.[s];
|
|
239
|
+
if (!fn) (0, __sprawlify_primitives_utils.warn)(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
240
|
+
return fn;
|
|
241
|
+
});
|
|
242
|
+
for (const fn of fns) fn?.(getParams());
|
|
243
|
+
};
|
|
244
|
+
const guard = (str) => {
|
|
245
|
+
if ((0, __sprawlify_primitives_utils.isFunction)(str)) return str(getParams());
|
|
246
|
+
return machine.implementations?.guards?.[str](getParams());
|
|
247
|
+
};
|
|
248
|
+
const effect = (keys) => {
|
|
249
|
+
const strs = (0, __sprawlify_primitives_utils.isFunction)(keys) ? keys(getParams()) : keys;
|
|
250
|
+
if (!strs) return;
|
|
251
|
+
const fns = strs.map((s) => {
|
|
252
|
+
const fn = machine.implementations?.effects?.[s];
|
|
253
|
+
if (!fn) (0, __sprawlify_primitives_utils.warn)(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
254
|
+
return fn;
|
|
255
|
+
});
|
|
256
|
+
const cleanups = [];
|
|
257
|
+
for (const fn of fns) {
|
|
258
|
+
const cleanup = fn?.(getParams());
|
|
259
|
+
if (cleanup) cleanups.push(cleanup);
|
|
260
|
+
}
|
|
261
|
+
return () => cleanups.forEach((fn) => fn?.());
|
|
262
|
+
};
|
|
263
|
+
const choose = (transitions) => {
|
|
264
|
+
return (0, __sprawlify_primitives_utils.toArray)(transitions).find((t) => {
|
|
265
|
+
let result = !t.guard;
|
|
266
|
+
if ((0, __sprawlify_primitives_utils.isString)(t.guard)) result = !!guard(t.guard);
|
|
267
|
+
else if ((0, __sprawlify_primitives_utils.isFunction)(t.guard)) result = t.guard(getParams());
|
|
268
|
+
return result;
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
const computed = (key) => {
|
|
272
|
+
(0, __sprawlify_primitives_utils.ensure)(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
273
|
+
const fn = machine.computed[key];
|
|
274
|
+
return fn({
|
|
275
|
+
context: ctx,
|
|
276
|
+
event: getEvent(),
|
|
277
|
+
prop,
|
|
278
|
+
refs,
|
|
279
|
+
scope,
|
|
280
|
+
computed
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const state = useBindable(() => ({
|
|
284
|
+
defaultValue: machine.initialState({ prop }),
|
|
285
|
+
onChange(nextState, prevState) {
|
|
286
|
+
if (prevState) {
|
|
287
|
+
effects.current.get(prevState)?.();
|
|
288
|
+
effects.current.delete(prevState);
|
|
289
|
+
}
|
|
290
|
+
if (prevState) action(machine.states[prevState]?.exit);
|
|
291
|
+
action(transitionRef.current?.actions);
|
|
292
|
+
const cleanup = effect(machine.states[nextState]?.effects);
|
|
293
|
+
if (cleanup) effects.current.set(nextState, cleanup);
|
|
294
|
+
if (prevState === __sprawlify_primitives_core.INIT_STATE) {
|
|
295
|
+
action(machine.entry);
|
|
296
|
+
const cleanup$1 = effect(machine.effects);
|
|
297
|
+
if (cleanup$1) effects.current.set(__sprawlify_primitives_core.INIT_STATE, cleanup$1);
|
|
298
|
+
}
|
|
299
|
+
action(machine.states[nextState]?.entry);
|
|
300
|
+
}
|
|
301
|
+
}));
|
|
302
|
+
const hydratedStateRef = (0, react.useRef)(void 0);
|
|
303
|
+
const statusRef = (0, react.useRef)(__sprawlify_primitives_core.MachineStatus.NotStarted);
|
|
304
|
+
useSafeLayoutEffect(() => {
|
|
305
|
+
queueMicrotask(() => {
|
|
306
|
+
const started = statusRef.current === __sprawlify_primitives_core.MachineStatus.Started;
|
|
307
|
+
statusRef.current = __sprawlify_primitives_core.MachineStatus.Started;
|
|
308
|
+
debug(started ? "rehydrating..." : "initializing...");
|
|
309
|
+
const initialState = hydratedStateRef.current ?? state.initial;
|
|
310
|
+
state.invoke(initialState, started ? state.get() : __sprawlify_primitives_core.INIT_STATE);
|
|
311
|
+
});
|
|
312
|
+
const fns = effects.current;
|
|
313
|
+
const currentState = state.ref.current;
|
|
314
|
+
return () => {
|
|
315
|
+
debug("unmounting...");
|
|
316
|
+
hydratedStateRef.current = currentState;
|
|
317
|
+
statusRef.current = __sprawlify_primitives_core.MachineStatus.Stopped;
|
|
318
|
+
fns.forEach((fn) => fn?.());
|
|
319
|
+
effects.current = /* @__PURE__ */ new Map();
|
|
320
|
+
transitionRef.current = null;
|
|
321
|
+
queueMicrotask(() => {
|
|
322
|
+
action(machine.exit);
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
}, []);
|
|
326
|
+
const getCurrentState = () => {
|
|
327
|
+
if ("ref" in state) return state.ref.current;
|
|
328
|
+
return state.get();
|
|
329
|
+
};
|
|
330
|
+
const send = (event) => {
|
|
331
|
+
queueMicrotask(() => {
|
|
332
|
+
if (statusRef.current !== __sprawlify_primitives_core.MachineStatus.Started) return;
|
|
333
|
+
previousEventRef.current = eventRef.current;
|
|
334
|
+
eventRef.current = event;
|
|
335
|
+
const currentState = getCurrentState();
|
|
336
|
+
const transition = choose(machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]);
|
|
337
|
+
if (!transition) return;
|
|
338
|
+
transitionRef.current = transition;
|
|
339
|
+
const target = transition.target ?? currentState;
|
|
340
|
+
debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
|
|
341
|
+
const changed = target !== currentState;
|
|
342
|
+
if (changed) (0, react_dom.flushSync)(() => state.set(target));
|
|
343
|
+
else if (transition.reenter && !changed) state.invoke(currentState, currentState);
|
|
344
|
+
else action(transition.actions ?? []);
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
machine.watch?.(getParams());
|
|
348
|
+
return {
|
|
349
|
+
state: getState(),
|
|
350
|
+
send,
|
|
351
|
+
context: ctx,
|
|
352
|
+
prop,
|
|
353
|
+
scope,
|
|
354
|
+
refs,
|
|
355
|
+
computed,
|
|
356
|
+
event: getEvent(),
|
|
357
|
+
getStatus: () => statusRef.current
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function useLiveRef(value) {
|
|
361
|
+
const ref = (0, react.useRef)(value);
|
|
362
|
+
ref.current = value;
|
|
363
|
+
return ref;
|
|
364
|
+
}
|
|
365
|
+
function useProp(value) {
|
|
366
|
+
const ref = useLiveRef(value);
|
|
367
|
+
return function get(key) {
|
|
368
|
+
return ref.current[key];
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function flush(fn) {
|
|
372
|
+
queueMicrotask(() => {
|
|
373
|
+
(0, react_dom.flushSync)(() => fn());
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/core/normalize-props.ts
|
|
379
|
+
const normalizeProps = (0, __sprawlify_primitives_types.createNormalizer)((v) => v);
|
|
380
|
+
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/core/portal.tsx
|
|
383
|
+
const Portal = (props) => {
|
|
384
|
+
const { children, container, disabled, getRootNode } = props;
|
|
385
|
+
if (typeof window === "undefined" || disabled) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children });
|
|
386
|
+
const doc = getRootNode?.().ownerDocument ?? document;
|
|
387
|
+
const mountNode = container?.current ?? doc.body;
|
|
388
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: react.Children.map(children, (child) => (0, react_dom.createPortal)(child, mountNode)) });
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/utils/run-if-fn.ts
|
|
393
|
+
const isFunction = (value) => typeof value === "function";
|
|
394
|
+
const runIfFn = (valueOrFn, ...args) => isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn;
|
|
395
|
+
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/providers/environment/use-environment-context.ts
|
|
398
|
+
const [EnvironmentContextProvider, useEnvironmentContext] = require_create_context.createContext({
|
|
399
|
+
name: "EnvironmentContext",
|
|
400
|
+
hookName: "useEnvironmentContext",
|
|
401
|
+
providerName: "<EnvironmentProvider />",
|
|
402
|
+
strict: false,
|
|
403
|
+
defaultValue: {
|
|
404
|
+
getRootNode: () => document,
|
|
405
|
+
getDocument: () => document,
|
|
406
|
+
getWindow: () => window
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/providers/environment/environment-provider.tsx
|
|
412
|
+
const EnvironmentProvider = (props) => {
|
|
413
|
+
const { value, children } = props;
|
|
414
|
+
const [spanRef, setSpanRef] = (0, react.useState)();
|
|
415
|
+
const getRootNode = (0, react.useMemo)(() => {
|
|
416
|
+
return () => runIfFn(value) ?? spanRef?.getRootNode() ?? document;
|
|
417
|
+
}, [value, spanRef]);
|
|
418
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(EnvironmentContextProvider, {
|
|
419
|
+
value: (0, react.useMemo)(() => ({
|
|
420
|
+
getRootNode,
|
|
421
|
+
getWindow: () => (0, __sprawlify_primitives_dom_query.getWindow)(getRootNode()),
|
|
422
|
+
getDocument: () => (0, __sprawlify_primitives_dom_query.getDocument)(getRootNode())
|
|
423
|
+
}), [getRootNode]),
|
|
424
|
+
children: [children, !value && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
425
|
+
hidden: true,
|
|
426
|
+
ref: setSpanRef
|
|
427
|
+
})]
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/providers/locale/use-locale-context.ts
|
|
433
|
+
const [LocaleContextProvider, useLocaleContext] = require_create_context.createContext({
|
|
434
|
+
name: "LocaleContext",
|
|
435
|
+
hookName: "useLocaleContext",
|
|
436
|
+
providerName: "<LocaleProvider />",
|
|
437
|
+
strict: false,
|
|
438
|
+
defaultValue: {
|
|
439
|
+
dir: "ltr",
|
|
440
|
+
locale: "en-US"
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/providers/locale/locale-provider.tsx
|
|
446
|
+
const LocaleProvider = (props) => {
|
|
447
|
+
const { children, locale } = props;
|
|
448
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocaleContextProvider, {
|
|
449
|
+
value: {
|
|
450
|
+
locale,
|
|
451
|
+
dir: (0, __sprawlify_primitives_i18n_utils.isRTL)(locale) ? "rtl" : "ltr"
|
|
452
|
+
},
|
|
453
|
+
children
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/providers/locale/use-collator.ts
|
|
459
|
+
function useCollator(props = {}) {
|
|
460
|
+
const env = useLocaleContext();
|
|
461
|
+
const locale = props.locale ?? env.locale;
|
|
462
|
+
return (0, react.useMemo)(() => {
|
|
463
|
+
const { locale: _, ...options } = props;
|
|
464
|
+
return (0, __sprawlify_primitives_i18n_utils.createCollator)(locale, options);
|
|
465
|
+
}, [locale, props]);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/providers/locale/use-filter.ts
|
|
470
|
+
function useFilter(props) {
|
|
471
|
+
const env = useLocaleContext();
|
|
472
|
+
const locale = props.locale ?? env.locale;
|
|
473
|
+
return (0, react.useMemo)(() => (0, __sprawlify_primitives_i18n_utils.createFilter)({
|
|
474
|
+
...props,
|
|
475
|
+
locale
|
|
476
|
+
}), [locale, props]);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/utils/compose-refs.ts
|
|
481
|
+
function composeRefs(...refs) {
|
|
482
|
+
return (node) => {
|
|
483
|
+
const cleanUps = [];
|
|
484
|
+
for (const ref of refs) if (typeof ref === "function") {
|
|
485
|
+
const cb = ref(node);
|
|
486
|
+
if (typeof cb === "function") cleanUps.push(cb);
|
|
487
|
+
} else if (ref) ref.current = node;
|
|
488
|
+
if (cleanUps.length) return () => {
|
|
489
|
+
for (const cleanUp of cleanUps) cleanUp();
|
|
490
|
+
};
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/components/factory.ts
|
|
496
|
+
function getRef(element) {
|
|
497
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
498
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
499
|
+
if (mayWarn) return element.ref;
|
|
500
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
501
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
502
|
+
if (mayWarn) return element.props.ref;
|
|
503
|
+
return element.props.ref || element.ref;
|
|
504
|
+
}
|
|
505
|
+
const withAsChild = (Component) => {
|
|
506
|
+
const Comp = (0, react.memo)((0, react.forwardRef)((props, ref) => {
|
|
507
|
+
const { asChild, children, ...restProps } = props;
|
|
508
|
+
if (!asChild) return (0, react.createElement)(Component, {
|
|
509
|
+
...restProps,
|
|
510
|
+
ref
|
|
511
|
+
}, children);
|
|
512
|
+
if (!(0, react.isValidElement)(children)) return null;
|
|
513
|
+
const onlyChild = react.Children.only(children);
|
|
514
|
+
const childRef = getRef(onlyChild);
|
|
515
|
+
return (0, react.cloneElement)(onlyChild, {
|
|
516
|
+
...(0, __sprawlify_primitives_core.mergeProps)(restProps, onlyChild.props),
|
|
517
|
+
ref: ref ? composeRefs(ref, childRef) : childRef
|
|
518
|
+
});
|
|
519
|
+
}));
|
|
520
|
+
Comp.displayName = typeof Component === "string" ? Component : Component.displayName || Component.name;
|
|
521
|
+
return Comp;
|
|
522
|
+
};
|
|
523
|
+
const jsxFactory = () => {
|
|
524
|
+
const cache = /* @__PURE__ */ new Map();
|
|
525
|
+
return new Proxy(withAsChild, {
|
|
526
|
+
apply(_target, _thisArg, argArray) {
|
|
527
|
+
return withAsChild(argArray[0]);
|
|
528
|
+
},
|
|
529
|
+
get(_, element) {
|
|
530
|
+
const asElement = element;
|
|
531
|
+
if (!cache.has(asElement)) cache.set(asElement, withAsChild(asElement));
|
|
532
|
+
return cache.get(asElement);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
};
|
|
536
|
+
const sprawlify = jsxFactory();
|
|
537
|
+
|
|
538
|
+
//#endregion
|
|
539
|
+
Object.defineProperty(exports, 'EnvironmentProvider', {
|
|
540
|
+
enumerable: true,
|
|
541
|
+
get: function () {
|
|
542
|
+
return EnvironmentProvider;
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
Object.defineProperty(exports, 'LocaleProvider', {
|
|
546
|
+
enumerable: true,
|
|
547
|
+
get: function () {
|
|
548
|
+
return LocaleProvider;
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
Object.defineProperty(exports, 'Portal', {
|
|
552
|
+
enumerable: true,
|
|
553
|
+
get: function () {
|
|
554
|
+
return Portal;
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
Object.defineProperty(exports, '__export', {
|
|
558
|
+
enumerable: true,
|
|
559
|
+
get: function () {
|
|
560
|
+
return __export;
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
Object.defineProperty(exports, '__toESM', {
|
|
564
|
+
enumerable: true,
|
|
565
|
+
get: function () {
|
|
566
|
+
return __toESM;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
Object.defineProperty(exports, 'jsxFactory', {
|
|
570
|
+
enumerable: true,
|
|
571
|
+
get: function () {
|
|
572
|
+
return jsxFactory;
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
Object.defineProperty(exports, 'normalizeProps', {
|
|
576
|
+
enumerable: true,
|
|
577
|
+
get: function () {
|
|
578
|
+
return normalizeProps;
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
Object.defineProperty(exports, 'sprawlify', {
|
|
582
|
+
enumerable: true,
|
|
583
|
+
get: function () {
|
|
584
|
+
return sprawlify;
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
Object.defineProperty(exports, 'useCollator', {
|
|
588
|
+
enumerable: true,
|
|
589
|
+
get: function () {
|
|
590
|
+
return useCollator;
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
Object.defineProperty(exports, 'useEnvironmentContext', {
|
|
594
|
+
enumerable: true,
|
|
595
|
+
get: function () {
|
|
596
|
+
return useEnvironmentContext;
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
Object.defineProperty(exports, 'useFilter', {
|
|
600
|
+
enumerable: true,
|
|
601
|
+
get: function () {
|
|
602
|
+
return useFilter;
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
Object.defineProperty(exports, 'useLocaleContext', {
|
|
606
|
+
enumerable: true,
|
|
607
|
+
get: function () {
|
|
608
|
+
return useLocaleContext;
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
Object.defineProperty(exports, 'useMachine', {
|
|
612
|
+
enumerable: true,
|
|
613
|
+
get: function () {
|
|
614
|
+
return useMachine;
|
|
615
|
+
}
|
|
616
|
+
});
|