@sprawlify/solid 0.0.14 → 0.0.15
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-C4aQI7lE.jsx +18 -0
- package/dist/chunk-CKcAJnC7.js +18 -0
- package/dist/collapsible-Cg7zPadX.js +129 -0
- package/dist/collapsible-CjuC6xYl.jsx +117 -0
- package/dist/collection-BiyRTWsX.js +219 -0
- package/dist/collection-BlnS2UQy.jsx +219 -0
- package/dist/components/accordion/index.d.ts +69 -0
- package/dist/components/accordion/index.js +183 -0
- package/dist/components/accordion/index.jsx +157 -0
- package/dist/components/angle-slider/index.d.ts +74 -0
- package/dist/components/angle-slider/index.js +155 -0
- package/dist/components/angle-slider/index.jsx +144 -0
- package/dist/components/avatar/index.d.ts +49 -0
- package/dist/components/avatar/index.js +95 -0
- package/dist/components/avatar/index.jsx +88 -0
- package/dist/components/bottom-sheet/index.d.ts +80 -0
- package/dist/components/bottom-sheet/index.js +218 -0
- package/dist/components/bottom-sheet/index.jsx +177 -0
- package/dist/components/carousel/index.d.ts +98 -0
- package/dist/components/carousel/index.js +207 -0
- package/dist/components/carousel/index.jsx +192 -0
- package/dist/components/checkbox/index.d.ts +138 -0
- package/dist/components/checkbox/index.js +265 -0
- package/dist/components/checkbox/index.jsx +247 -0
- package/dist/components/client-only/index.d.ts +10 -0
- package/dist/components/client-only/index.js +24 -0
- package/dist/components/client-only/index.jsx +15 -0
- package/dist/components/clipboard/index.d.ts +72 -0
- package/dist/components/clipboard/index.js +149 -0
- package/dist/components/clipboard/index.jsx +132 -0
- package/dist/components/collapsible/index.d.ts +60 -0
- package/dist/components/collapsible/index.js +8 -0
- package/dist/components/collapsible/index.jsx +8 -0
- package/dist/components/collection/index.d.ts +3 -0
- package/dist/components/collection/index.js +4 -0
- package/dist/components/collection/index.jsx +4 -0
- package/dist/components/field/index.d.ts +201 -0
- package/dist/components/field/index.js +9 -0
- package/dist/components/field/index.jsx +9 -0
- package/dist/components/fieldset/index.d.ts +109 -0
- package/dist/components/fieldset/index.js +8 -0
- package/dist/components/fieldset/index.jsx +8 -0
- package/dist/components/presence/index.d.ts +5 -0
- package/dist/components/presence/index.js +8 -0
- package/dist/components/presence/index.jsx +8 -0
- package/dist/components/select/index.d.ts +134 -0
- package/dist/components/select/index.js +361 -0
- package/dist/components/select/index.jsx +310 -0
- package/dist/compose-refs-CzyOb8yH.jsx +20 -0
- package/dist/compose-refs-vsrTrt13.js +20 -0
- package/dist/create-split-props-CQVsvhvg.jsx +41 -0
- package/dist/factory-B6RK6SH4.d.ts +14 -0
- package/dist/factory-CEdj72aS.js +47 -0
- package/dist/field-C_WuoXOj.js +287 -0
- package/dist/field-CphvciGc.jsx +259 -0
- package/dist/fieldset-BG-0ZqWT.jsx +167 -0
- package/dist/fieldset-D1BO0LmU.js +182 -0
- package/dist/index-C3ATynHc.d.ts +23 -0
- package/dist/index-DXheKbqg.d.ts +76 -0
- package/dist/index-NWiNyxpL.d.ts +38 -0
- package/dist/index-vSwYtc2L.d.ts +38 -0
- package/dist/index.d.ts +5 -29
- package/dist/index.js +4 -511
- package/dist/index.jsx +4 -497
- package/dist/presence-Bfjusgm3.js +79 -0
- package/dist/presence-arWh1hVd.jsx +66 -0
- package/dist/providers-CHqGPEsc.jsx +82 -0
- package/dist/providers-CQkAUunr.js +96 -0
- package/dist/render-strategy-COrlrUuR.js +12 -0
- package/dist/render-strategy-CZDG_yDi.jsx +12 -0
- package/dist/render-strategy-CtRkdWei.d.ts +9 -0
- package/dist/run-if-fn-DRWB51JE.jsx +421 -0
- package/dist/run-if-fn-eYlaegHy.js +421 -0
- package/dist/types-bQRbEioA.d.ts +9 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.jsx +2 -1
- package/dist/utils-DYer-9SY.js +0 -0
- package/dist/utils-DrvO4Hk3.jsx +0 -0
- package/package.json +62 -2
- /package/dist/{utils-DSKoW7eB.jsx → create-context-PS2j4mEo.js} +0 -0
- /package/dist/{utils-GEMuT7an.js → create-context-h3cXiEld.jsx} +0 -0
- /package/dist/{index-C_ThrXdH.d.ts → index-B0YoIRC4.d.ts} +0 -0
package/dist/index.jsx
CHANGED
|
@@ -1,499 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { Show, createEffect, createMemo, createSignal, mergeProps as mergeProps$2, onCleanup, onMount, untrack } from "solid-js";
|
|
6
|
-
import { createNormalizer } from "@sprawlify/primitives/types";
|
|
7
|
-
import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
|
|
8
|
-
import { createCollator, createFilter, isRTL } from "@sprawlify/primitives/i18n-utils";
|
|
1
|
+
import { a as useMachine, i as mergeProps, n as Key, r as normalizeProps } from "./run-if-fn-DRWB51JE.jsx";
|
|
2
|
+
import { t as createContext } from "./create-context-h3cXiEld.jsx";
|
|
3
|
+
import { a as EnvironmentProvider, i as useLocaleContext, n as useCollator, o as useEnvironmentContext, r as LocaleProvider, t as useFilter } from "./providers-CHqGPEsc.jsx";
|
|
4
|
+
import "./utils-DrvO4Hk3.jsx";
|
|
9
5
|
|
|
10
|
-
//#region src/core/bindable.ts
|
|
11
|
-
function createBindable(props) {
|
|
12
|
-
const initial = props().value ?? props().defaultValue;
|
|
13
|
-
const eq = props().isEqual ?? Object.is;
|
|
14
|
-
const [value, setValue] = createSignal(initial);
|
|
15
|
-
const controlled = createMemo(() => props().value != void 0);
|
|
16
|
-
const valueRef = { current: value() };
|
|
17
|
-
const prevValue = { current: void 0 };
|
|
18
|
-
createEffect(() => {
|
|
19
|
-
const v = controlled() ? props().value : value();
|
|
20
|
-
prevValue.current = v;
|
|
21
|
-
valueRef.current = v;
|
|
22
|
-
});
|
|
23
|
-
const set = (v) => {
|
|
24
|
-
const prev = prevValue.current;
|
|
25
|
-
const next = isFunction(v) ? v(valueRef.current) : v;
|
|
26
|
-
if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
|
|
27
|
-
next,
|
|
28
|
-
prev
|
|
29
|
-
});
|
|
30
|
-
if (!controlled()) setValue(next);
|
|
31
|
-
if (!eq(next, prev)) props().onChange?.(next, prev);
|
|
32
|
-
};
|
|
33
|
-
function get() {
|
|
34
|
-
const v = controlled() ? props().value : value;
|
|
35
|
-
return isFunction(v) ? v() : v;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
initial,
|
|
39
|
-
ref: valueRef,
|
|
40
|
-
get,
|
|
41
|
-
set,
|
|
42
|
-
invoke(nextValue, prevValue$1) {
|
|
43
|
-
props().onChange?.(nextValue, prevValue$1);
|
|
44
|
-
},
|
|
45
|
-
hash(value$1) {
|
|
46
|
-
return props().hash?.(value$1) ?? String(value$1);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
createBindable.cleanup = (fn) => {
|
|
51
|
-
onCleanup(() => fn());
|
|
52
|
-
};
|
|
53
|
-
createBindable.ref = (defaultValue) => {
|
|
54
|
-
let value = defaultValue;
|
|
55
|
-
return {
|
|
56
|
-
get: () => value,
|
|
57
|
-
set: (next) => {
|
|
58
|
-
value = next;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/core/refs.ts
|
|
65
|
-
function createRefs(refs) {
|
|
66
|
-
const ref = { current: refs };
|
|
67
|
-
return {
|
|
68
|
-
get(key) {
|
|
69
|
-
return ref.current[key];
|
|
70
|
-
},
|
|
71
|
-
set(key, value) {
|
|
72
|
-
ref.current[key] = value;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/core/track.ts
|
|
79
|
-
function access$1(v) {
|
|
80
|
-
if (isFunction(v)) return v();
|
|
81
|
-
return v;
|
|
82
|
-
}
|
|
83
|
-
const createTrack = (deps, effect) => {
|
|
84
|
-
let prevDeps = [];
|
|
85
|
-
let isFirstRun = true;
|
|
86
|
-
createEffect(() => {
|
|
87
|
-
if (isFirstRun) {
|
|
88
|
-
prevDeps = deps.map((d) => access$1(d));
|
|
89
|
-
isFirstRun = false;
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
let changed = false;
|
|
93
|
-
for (let i = 0; i < deps.length; i++) if (!isEqual(prevDeps[i], access$1(deps[i]))) {
|
|
94
|
-
changed = true;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
if (changed) {
|
|
98
|
-
prevDeps = deps.map((d) => access$1(d));
|
|
99
|
-
effect();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/core/machine.ts
|
|
106
|
-
function useMachine(machine, userProps = {}) {
|
|
107
|
-
const scope = createMemo(() => {
|
|
108
|
-
const { id, ids, getRootNode } = access(userProps);
|
|
109
|
-
return createScope({
|
|
110
|
-
id,
|
|
111
|
-
ids,
|
|
112
|
-
getRootNode
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
const debug = (...args) => {
|
|
116
|
-
if (machine.debug) console.log(...args);
|
|
117
|
-
};
|
|
118
|
-
const prop = createProp(createMemo(() => machine.props?.({
|
|
119
|
-
props: compact(access(userProps)),
|
|
120
|
-
scope: scope()
|
|
121
|
-
}) ?? access(userProps)));
|
|
122
|
-
const context = machine.context?.({
|
|
123
|
-
prop,
|
|
124
|
-
bindable: createBindable,
|
|
125
|
-
get scope() {
|
|
126
|
-
return scope();
|
|
127
|
-
},
|
|
128
|
-
flush,
|
|
129
|
-
getContext() {
|
|
130
|
-
return ctx;
|
|
131
|
-
},
|
|
132
|
-
getComputed() {
|
|
133
|
-
return computed;
|
|
134
|
-
},
|
|
135
|
-
getRefs() {
|
|
136
|
-
return refs;
|
|
137
|
-
},
|
|
138
|
-
getEvent() {
|
|
139
|
-
return getEvent();
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
const ctx = {
|
|
143
|
-
get(key) {
|
|
144
|
-
return context?.[key].get();
|
|
145
|
-
},
|
|
146
|
-
set(key, value) {
|
|
147
|
-
context?.[key].set(value);
|
|
148
|
-
},
|
|
149
|
-
initial(key) {
|
|
150
|
-
return context?.[key].initial;
|
|
151
|
-
},
|
|
152
|
-
hash(key) {
|
|
153
|
-
const current = context?.[key].get();
|
|
154
|
-
return context?.[key].hash(current);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const effects = { current: /* @__PURE__ */ new Map() };
|
|
158
|
-
const transitionRef = { current: null };
|
|
159
|
-
const previousEventRef = { current: null };
|
|
160
|
-
const eventRef = { current: { type: "" } };
|
|
161
|
-
const getEvent = () => mergeProps$2(eventRef.current, {
|
|
162
|
-
current() {
|
|
163
|
-
return eventRef.current;
|
|
164
|
-
},
|
|
165
|
-
previous() {
|
|
166
|
-
return previousEventRef.current;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const getState = () => mergeProps$2(state, {
|
|
170
|
-
matches(...values) {
|
|
171
|
-
const current = state.get();
|
|
172
|
-
return values.includes(current);
|
|
173
|
-
},
|
|
174
|
-
hasTag(tag) {
|
|
175
|
-
const current = state.get();
|
|
176
|
-
return !!machine.states[current]?.tags?.includes(tag);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const refs = createRefs(machine.refs?.({
|
|
180
|
-
prop,
|
|
181
|
-
context: ctx
|
|
182
|
-
}) ?? {});
|
|
183
|
-
const getParams = () => ({
|
|
184
|
-
state: getState(),
|
|
185
|
-
context: ctx,
|
|
186
|
-
event: getEvent(),
|
|
187
|
-
prop,
|
|
188
|
-
send,
|
|
189
|
-
action,
|
|
190
|
-
guard,
|
|
191
|
-
track: createTrack,
|
|
192
|
-
refs,
|
|
193
|
-
computed,
|
|
194
|
-
flush,
|
|
195
|
-
get scope() {
|
|
196
|
-
return scope();
|
|
197
|
-
},
|
|
198
|
-
choose
|
|
199
|
-
});
|
|
200
|
-
const action = (keys) => {
|
|
201
|
-
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
202
|
-
if (!strs) return;
|
|
203
|
-
const fns = strs.map((s) => {
|
|
204
|
-
const fn = machine.implementations?.actions?.[s];
|
|
205
|
-
if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
206
|
-
return fn;
|
|
207
|
-
});
|
|
208
|
-
for (const fn of fns) fn?.(getParams());
|
|
209
|
-
};
|
|
210
|
-
const guard = (str) => {
|
|
211
|
-
if (isFunction(str)) return str(getParams());
|
|
212
|
-
return machine.implementations?.guards?.[str](getParams());
|
|
213
|
-
};
|
|
214
|
-
const effect = (keys) => {
|
|
215
|
-
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
216
|
-
if (!strs) return;
|
|
217
|
-
const fns = strs.map((s) => {
|
|
218
|
-
const fn = machine.implementations?.effects?.[s];
|
|
219
|
-
if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
220
|
-
return fn;
|
|
221
|
-
});
|
|
222
|
-
const cleanups = [];
|
|
223
|
-
for (const fn of fns) {
|
|
224
|
-
const cleanup = fn?.(getParams());
|
|
225
|
-
if (cleanup) cleanups.push(cleanup);
|
|
226
|
-
}
|
|
227
|
-
return () => cleanups.forEach((fn) => fn?.());
|
|
228
|
-
};
|
|
229
|
-
const choose = (transitions) => {
|
|
230
|
-
return toArray(transitions).find((t) => {
|
|
231
|
-
let result = !t.guard;
|
|
232
|
-
if (isString(t.guard)) result = !!guard(t.guard);
|
|
233
|
-
else if (isFunction(t.guard)) result = t.guard(getParams());
|
|
234
|
-
return result;
|
|
235
|
-
});
|
|
236
|
-
};
|
|
237
|
-
const computed = (key) => {
|
|
238
|
-
ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
239
|
-
const fn = machine.computed[key];
|
|
240
|
-
return fn({
|
|
241
|
-
context: ctx,
|
|
242
|
-
event: eventRef.current,
|
|
243
|
-
prop,
|
|
244
|
-
refs,
|
|
245
|
-
scope: scope(),
|
|
246
|
-
computed
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
const state = createBindable(() => ({
|
|
250
|
-
defaultValue: machine.initialState({ prop }),
|
|
251
|
-
onChange(nextState, prevState) {
|
|
252
|
-
if (prevState) {
|
|
253
|
-
effects.current.get(prevState)?.();
|
|
254
|
-
effects.current.delete(prevState);
|
|
255
|
-
}
|
|
256
|
-
if (prevState) action(machine.states[prevState]?.exit);
|
|
257
|
-
action(transitionRef.current?.actions);
|
|
258
|
-
const cleanup = effect(machine.states[nextState]?.effects);
|
|
259
|
-
if (cleanup) effects.current.set(nextState, cleanup);
|
|
260
|
-
if (prevState === INIT_STATE) {
|
|
261
|
-
action(machine.entry);
|
|
262
|
-
const cleanup$1 = effect(machine.effects);
|
|
263
|
-
if (cleanup$1) effects.current.set(INIT_STATE, cleanup$1);
|
|
264
|
-
}
|
|
265
|
-
action(machine.states[nextState]?.entry);
|
|
266
|
-
}
|
|
267
|
-
}));
|
|
268
|
-
let status = MachineStatus.NotStarted;
|
|
269
|
-
onMount(() => {
|
|
270
|
-
const started = status === MachineStatus.Started;
|
|
271
|
-
status = MachineStatus.Started;
|
|
272
|
-
debug(started ? "rehydrating..." : "initializing...");
|
|
273
|
-
state.invoke(state.initial, INIT_STATE);
|
|
274
|
-
});
|
|
275
|
-
onCleanup(() => {
|
|
276
|
-
debug("unmounting...");
|
|
277
|
-
status = MachineStatus.Stopped;
|
|
278
|
-
effects.current.forEach((fn) => fn?.());
|
|
279
|
-
effects.current = /* @__PURE__ */ new Map();
|
|
280
|
-
transitionRef.current = null;
|
|
281
|
-
action(machine.exit);
|
|
282
|
-
});
|
|
283
|
-
const send = (event) => {
|
|
284
|
-
queueMicrotask(() => {
|
|
285
|
-
if (status !== MachineStatus.Started) return;
|
|
286
|
-
previousEventRef.current = eventRef.current;
|
|
287
|
-
eventRef.current = event;
|
|
288
|
-
let currentState = untrack(() => state.get());
|
|
289
|
-
const transition = choose(machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]);
|
|
290
|
-
if (!transition) return;
|
|
291
|
-
transitionRef.current = transition;
|
|
292
|
-
const target = transition.target ?? currentState;
|
|
293
|
-
debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
|
|
294
|
-
const changed = target !== currentState;
|
|
295
|
-
if (changed) state.set(target);
|
|
296
|
-
else if (transition.reenter && !changed) state.invoke(currentState, currentState);
|
|
297
|
-
else action(transition.actions);
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
machine.watch?.(getParams());
|
|
301
|
-
return {
|
|
302
|
-
state: getState(),
|
|
303
|
-
send,
|
|
304
|
-
context: ctx,
|
|
305
|
-
prop,
|
|
306
|
-
get scope() {
|
|
307
|
-
return scope();
|
|
308
|
-
},
|
|
309
|
-
refs,
|
|
310
|
-
computed,
|
|
311
|
-
event: getEvent(),
|
|
312
|
-
getStatus: () => status
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function flush(fn) {
|
|
316
|
-
fn();
|
|
317
|
-
}
|
|
318
|
-
function access(value) {
|
|
319
|
-
return isFunction(value) ? value() : value;
|
|
320
|
-
}
|
|
321
|
-
function createProp(value) {
|
|
322
|
-
return function get(key) {
|
|
323
|
-
return value()[key];
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/core/merge-props.ts
|
|
329
|
-
function mergeProps(...sources) {
|
|
330
|
-
const target = {};
|
|
331
|
-
for (let i = 0; i < sources.length; i++) {
|
|
332
|
-
let source = sources[i];
|
|
333
|
-
if (typeof source === "function") source = source();
|
|
334
|
-
if (source) {
|
|
335
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
336
|
-
for (const key in descriptors) {
|
|
337
|
-
if (key in target) continue;
|
|
338
|
-
Object.defineProperty(target, key, {
|
|
339
|
-
enumerable: true,
|
|
340
|
-
get() {
|
|
341
|
-
let e = {};
|
|
342
|
-
if (key === "style" || key === "class" || key === "className" || key.startsWith("on")) {
|
|
343
|
-
for (let i$1 = 0; i$1 < sources.length; i$1++) {
|
|
344
|
-
let s = sources[i$1];
|
|
345
|
-
if (typeof s === "function") s = s();
|
|
346
|
-
e = mergeProps$1(e, { [key]: (s || {})[key] });
|
|
347
|
-
}
|
|
348
|
-
return e[key];
|
|
349
|
-
}
|
|
350
|
-
for (let i$1 = sources.length - 1; i$1 >= 0; i$1--) {
|
|
351
|
-
let v, s = sources[i$1];
|
|
352
|
-
if (typeof s === "function") s = s();
|
|
353
|
-
v = (s || {})[key];
|
|
354
|
-
if (v !== void 0) return v;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return target;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
//#endregion
|
|
365
|
-
//#region src/core/normalize-props.ts
|
|
366
|
-
const eventMap = {
|
|
367
|
-
onFocus: "onFocusIn",
|
|
368
|
-
onBlur: "onFocusOut",
|
|
369
|
-
onDoubleClick: "onDblClick",
|
|
370
|
-
onChange: "onInput",
|
|
371
|
-
defaultChecked: "checked",
|
|
372
|
-
defaultValue: "value",
|
|
373
|
-
htmlFor: "for",
|
|
374
|
-
className: "class"
|
|
375
|
-
};
|
|
376
|
-
const format = (v) => v.startsWith("--") ? v : hyphenateStyleName(v);
|
|
377
|
-
function toSolidProp(prop) {
|
|
378
|
-
return prop in eventMap ? eventMap[prop] : prop;
|
|
379
|
-
}
|
|
380
|
-
const normalizeProps = createNormalizer((props) => {
|
|
381
|
-
const normalized = {};
|
|
382
|
-
for (const key in props) {
|
|
383
|
-
const value = props[key];
|
|
384
|
-
if (key === "readOnly" && value === false) continue;
|
|
385
|
-
if (key === "style" && isObject(value)) {
|
|
386
|
-
normalized["style"] = cssify(value);
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
if (key === "children") {
|
|
390
|
-
if (isString(value)) normalized["textContent"] = value;
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
normalized[toSolidProp(key)] = value;
|
|
394
|
-
}
|
|
395
|
-
return normalized;
|
|
396
|
-
});
|
|
397
|
-
function cssify(style) {
|
|
398
|
-
let css = {};
|
|
399
|
-
for (const property in style) {
|
|
400
|
-
const value = style[property];
|
|
401
|
-
if (!isString(value) && !isNumber(value)) continue;
|
|
402
|
-
css[format(property)] = value;
|
|
403
|
-
}
|
|
404
|
-
return css;
|
|
405
|
-
}
|
|
406
|
-
const uppercasePattern = /[A-Z]/g;
|
|
407
|
-
const msPattern = /^ms-/;
|
|
408
|
-
function toHyphenLower(match) {
|
|
409
|
-
return "-" + match.toLowerCase();
|
|
410
|
-
}
|
|
411
|
-
const cache = {};
|
|
412
|
-
function hyphenateStyleName(name) {
|
|
413
|
-
if (cache.hasOwnProperty(name)) return cache[name];
|
|
414
|
-
var hName = name.replace(uppercasePattern, toHyphenLower);
|
|
415
|
-
return cache[name] = msPattern.test(hName) ? "-" + hName : hName;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region src/utils/run-if-fn.ts
|
|
420
|
-
const isFunction$1 = (value) => typeof value === "function";
|
|
421
|
-
const runIfFn = (valueOrFn, ...args) => isFunction$1(valueOrFn) ? valueOrFn(...args) : valueOrFn;
|
|
422
|
-
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/providers/environment/use-environment-context.ts
|
|
425
|
-
const [EnvironmentContextProvider, useEnvironmentContext] = createContext({
|
|
426
|
-
hookName: "useEnvironmentContext",
|
|
427
|
-
providerName: "<EnvironmentProvider />",
|
|
428
|
-
strict: false,
|
|
429
|
-
defaultValue: () => ({
|
|
430
|
-
getRootNode: () => document,
|
|
431
|
-
getDocument: () => document,
|
|
432
|
-
getWindow: () => window
|
|
433
|
-
})
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
//#endregion
|
|
437
|
-
//#region src/providers/environment/environment-provider.tsx
|
|
438
|
-
const EnvironmentProvider = (props) => {
|
|
439
|
-
const [spanRef, setSpanRef] = createSignal();
|
|
440
|
-
const getRootNode = () => runIfFn(props.value) ?? spanRef()?.getRootNode() ?? document;
|
|
441
|
-
const environment = createMemo(() => ({
|
|
442
|
-
getRootNode,
|
|
443
|
-
getDocument: () => getDocument(getRootNode()),
|
|
444
|
-
getWindow: () => getWindow(getRootNode())
|
|
445
|
-
}));
|
|
446
|
-
return <EnvironmentContextProvider value={environment}>
|
|
447
|
-
{props.children}
|
|
448
|
-
<Show when={!props.value}>
|
|
449
|
-
<span hidden ref={setSpanRef} />
|
|
450
|
-
</Show>
|
|
451
|
-
</EnvironmentContextProvider>;
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region src/providers/locale/use-locale-context.ts
|
|
456
|
-
const [LocaleContextProvider, useLocaleContext] = createContext({
|
|
457
|
-
hookName: "useEnvironmentContext",
|
|
458
|
-
providerName: "<EnvironmentProvider />",
|
|
459
|
-
strict: false,
|
|
460
|
-
defaultValue: () => ({
|
|
461
|
-
dir: "ltr",
|
|
462
|
-
locale: "en-US"
|
|
463
|
-
})
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/providers/locale/locale-provider.tsx
|
|
468
|
-
const LocaleProvider = (props) => {
|
|
469
|
-
const context = createMemo(() => ({
|
|
470
|
-
locale: props.locale,
|
|
471
|
-
dir: isRTL(props.locale) ? "rtl" : "ltr"
|
|
472
|
-
}));
|
|
473
|
-
return <LocaleContextProvider value={context}>{props.children}</LocaleContextProvider>;
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
//#endregion
|
|
477
|
-
//#region src/providers/locale/use-collator.ts
|
|
478
|
-
function useCollator(props = {}) {
|
|
479
|
-
const env = useLocaleContext();
|
|
480
|
-
const locale = () => props.locale ?? env().locale;
|
|
481
|
-
return createMemo(() => {
|
|
482
|
-
const { locale: _, ...options } = props;
|
|
483
|
-
return createCollator(locale(), options);
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
//#endregion
|
|
488
|
-
//#region src/providers/locale/use-filter.ts
|
|
489
|
-
function useFilter(props) {
|
|
490
|
-
const env = useLocaleContext();
|
|
491
|
-
const locale = createMemo(() => props.locale ?? env().locale);
|
|
492
|
-
return createMemo(() => createFilter({
|
|
493
|
-
...props,
|
|
494
|
-
locale: locale()
|
|
495
|
-
}));
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
//#endregion
|
|
499
6
|
export { EnvironmentProvider, Key, LocaleProvider, createContext, mergeProps, normalizeProps, useCollator, useEnvironmentContext, useFilter, useLocaleContext, useMachine };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { a as useMachine, i as mergeProps$2, r as normalizeProps, t as runIfFn } from "./run-if-fn-eYlaegHy.js";
|
|
2
|
+
import { t as createContext$1 } from "./create-context-PS2j4mEo.js";
|
|
3
|
+
import { n as createSplitProps, t as sprawlify } from "./factory-CEdj72aS.js";
|
|
4
|
+
import { n as splitRenderStrategyProps } from "./render-strategy-COrlrUuR.js";
|
|
5
|
+
import { t as composeRefs } from "./compose-refs-vsrTrt13.js";
|
|
6
|
+
import { Show, createEffect, createMemo, createSignal } from "solid-js";
|
|
7
|
+
import { createComponent, mergeProps as mergeProps$1 } from "solid-js/web";
|
|
8
|
+
import * as presence from "@sprawlify/primitives/machines/presence";
|
|
9
|
+
|
|
10
|
+
//#region src/components/presence/split-presence-props.ts
|
|
11
|
+
const splitPresenceProps = (props) => createSplitProps()(props, [
|
|
12
|
+
"immediate",
|
|
13
|
+
"lazyMount",
|
|
14
|
+
"onExitComplete",
|
|
15
|
+
"present",
|
|
16
|
+
"skipAnimationOnMount",
|
|
17
|
+
"unmountOnExit"
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/components/presence/use-presence.ts
|
|
22
|
+
const usePresence = (props) => {
|
|
23
|
+
const [renderStrategyProps, localProps] = splitRenderStrategyProps(runIfFn(props));
|
|
24
|
+
const [wasEverPresent, setWasEverPresent] = createSignal(false);
|
|
25
|
+
const service = useMachine(presence.machine, props);
|
|
26
|
+
const api = createMemo(() => presence.connect(service, normalizeProps));
|
|
27
|
+
createEffect(() => {
|
|
28
|
+
if (api().present) setWasEverPresent(true);
|
|
29
|
+
});
|
|
30
|
+
const setNode = (node) => {
|
|
31
|
+
if (!node) return;
|
|
32
|
+
service.send({
|
|
33
|
+
type: "NODE.SET",
|
|
34
|
+
node
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return createMemo(() => ({
|
|
38
|
+
unmounted: !api().present && !wasEverPresent() && renderStrategyProps.lazyMount || renderStrategyProps.unmountOnExit && !api().present && wasEverPresent(),
|
|
39
|
+
present: api().present,
|
|
40
|
+
ref: setNode,
|
|
41
|
+
presenceProps: {
|
|
42
|
+
hidden: !api().present,
|
|
43
|
+
"data-state": api().skip && localProps.skipAnimationOnMount ? void 0 : localProps.present ? "open" : "closed"
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/presence/presence.tsx
|
|
50
|
+
const Presence = (props) => {
|
|
51
|
+
const [presenceProps, localProps] = splitPresenceProps(props);
|
|
52
|
+
const api = usePresence(presenceProps);
|
|
53
|
+
const mergedProps = mergeProps$2(() => api().presenceProps, localProps);
|
|
54
|
+
return createComponent(Show, {
|
|
55
|
+
get when() {
|
|
56
|
+
return !api().unmounted;
|
|
57
|
+
},
|
|
58
|
+
get children() {
|
|
59
|
+
return createComponent(sprawlify.div, mergeProps$1(mergedProps, {
|
|
60
|
+
ref(r$) {
|
|
61
|
+
var _ref$ = composeRefs(api().ref, props.ref);
|
|
62
|
+
typeof _ref$ === "function" && _ref$(r$);
|
|
63
|
+
},
|
|
64
|
+
"data-scope": "presence",
|
|
65
|
+
"data-part": "root"
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/components/presence/use-presence-context.ts
|
|
73
|
+
const [PresenceProvider, usePresenceContext] = createContext$1({
|
|
74
|
+
hookName: "usePresenceContext",
|
|
75
|
+
providerName: "<PresenceProvider />"
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { splitPresenceProps as a, usePresence as i, usePresenceContext as n, Presence as r, PresenceProvider as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { a as useMachine, i as mergeProps$1, r as normalizeProps, t as runIfFn } from "./run-if-fn-DRWB51JE.jsx";
|
|
2
|
+
import { t as createContext$1 } from "./create-context-h3cXiEld.jsx";
|
|
3
|
+
import { n as sprawlify, t as createSplitProps } from "./create-split-props-CQVsvhvg.jsx";
|
|
4
|
+
import { n as splitRenderStrategyProps } from "./render-strategy-CZDG_yDi.jsx";
|
|
5
|
+
import { t as composeRefs } from "./compose-refs-CzyOb8yH.jsx";
|
|
6
|
+
import { Show, createEffect, createMemo, createSignal } from "solid-js";
|
|
7
|
+
import * as presence from "@sprawlify/primitives/machines/presence";
|
|
8
|
+
|
|
9
|
+
//#region src/components/presence/split-presence-props.ts
|
|
10
|
+
const splitPresenceProps = (props) => createSplitProps()(props, [
|
|
11
|
+
"immediate",
|
|
12
|
+
"lazyMount",
|
|
13
|
+
"onExitComplete",
|
|
14
|
+
"present",
|
|
15
|
+
"skipAnimationOnMount",
|
|
16
|
+
"unmountOnExit"
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/components/presence/use-presence.ts
|
|
21
|
+
const usePresence = (props) => {
|
|
22
|
+
const [renderStrategyProps, localProps] = splitRenderStrategyProps(runIfFn(props));
|
|
23
|
+
const [wasEverPresent, setWasEverPresent] = createSignal(false);
|
|
24
|
+
const service = useMachine(presence.machine, props);
|
|
25
|
+
const api = createMemo(() => presence.connect(service, normalizeProps));
|
|
26
|
+
createEffect(() => {
|
|
27
|
+
if (api().present) setWasEverPresent(true);
|
|
28
|
+
});
|
|
29
|
+
const setNode = (node) => {
|
|
30
|
+
if (!node) return;
|
|
31
|
+
service.send({
|
|
32
|
+
type: "NODE.SET",
|
|
33
|
+
node
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
return createMemo(() => ({
|
|
37
|
+
unmounted: !api().present && !wasEverPresent() && renderStrategyProps.lazyMount || renderStrategyProps.unmountOnExit && !api().present && wasEverPresent(),
|
|
38
|
+
present: api().present,
|
|
39
|
+
ref: setNode,
|
|
40
|
+
presenceProps: {
|
|
41
|
+
hidden: !api().present,
|
|
42
|
+
"data-state": api().skip && localProps.skipAnimationOnMount ? void 0 : localProps.present ? "open" : "closed"
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/components/presence/presence.tsx
|
|
49
|
+
const Presence = (props) => {
|
|
50
|
+
const [presenceProps, localProps] = splitPresenceProps(props);
|
|
51
|
+
const api = usePresence(presenceProps);
|
|
52
|
+
const mergedProps = mergeProps$1(() => api().presenceProps, localProps);
|
|
53
|
+
return <Show when={!api().unmounted}>
|
|
54
|
+
<sprawlify.div {...mergedProps} ref={composeRefs(api().ref, props.ref)} data-scope="presence" data-part="root" />
|
|
55
|
+
</Show>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/components/presence/use-presence-context.ts
|
|
60
|
+
const [PresenceProvider, usePresenceContext] = createContext$1({
|
|
61
|
+
hookName: "usePresenceContext",
|
|
62
|
+
providerName: "<PresenceProvider />"
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { splitPresenceProps as a, usePresence as i, usePresenceContext as n, Presence as r, PresenceProvider as t };
|