@sprawlify/solid 0.0.14 → 0.0.16
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-B5so6B0y.jsx +18 -0
- package/dist/chunk-B93cd-Dz.js +18 -0
- package/dist/collapsible-CX2tnXKq.js +131 -0
- package/dist/collapsible-sG-Rzvf2.jsx +119 -0
- package/dist/collection-BRr4O2_i.jsx +220 -0
- package/dist/collection-zj3lxnwW.js +220 -0
- package/dist/components/accordion/index.d.ts +69 -0
- package/dist/components/accordion/index.js +185 -0
- package/dist/components/accordion/index.jsx +159 -0
- package/dist/components/angle-slider/index.d.ts +74 -0
- package/dist/components/angle-slider/index.js +157 -0
- package/dist/components/angle-slider/index.jsx +146 -0
- package/dist/components/avatar/index.d.ts +49 -0
- package/dist/components/avatar/index.js +97 -0
- package/dist/components/avatar/index.jsx +90 -0
- package/dist/components/bottom-sheet/index.d.ts +80 -0
- package/dist/components/bottom-sheet/index.js +220 -0
- package/dist/components/bottom-sheet/index.jsx +179 -0
- package/dist/components/carousel/index.d.ts +98 -0
- package/dist/components/carousel/index.js +209 -0
- package/dist/components/carousel/index.jsx +194 -0
- package/dist/components/checkbox/index.d.ts +138 -0
- package/dist/components/checkbox/index.js +267 -0
- package/dist/components/checkbox/index.jsx +249 -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 +151 -0
- package/dist/components/clipboard/index.jsx +134 -0
- package/dist/components/collapsible/index.d.ts +60 -0
- package/dist/components/collapsible/index.js +9 -0
- package/dist/components/collapsible/index.jsx +9 -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/color-picker/index.d.ts +183 -0
- package/dist/components/color-picker/index.js +500 -0
- package/dist/components/color-picker/index.jsx +436 -0
- package/dist/components/combobox/index.d.ts +134 -0
- package/dist/components/combobox/index.js +357 -0
- package/dist/components/combobox/index.jsx +315 -0
- package/dist/components/date-picker/index.d.ts +165 -0
- package/dist/components/date-picker/index.js +476 -0
- package/dist/components/date-picker/index.jsx +415 -0
- package/dist/components/dialog/index.d.ts +80 -0
- package/dist/components/dialog/index.js +219 -0
- package/dist/components/dialog/index.jsx +173 -0
- package/dist/components/download-trigger/index.d.ts +25 -0
- package/dist/components/download-trigger/index.js +42 -0
- package/dist/components/download-trigger/index.jsx +38 -0
- package/dist/components/editable/index.d.ts +79 -0
- package/dist/components/editable/index.js +190 -0
- package/dist/components/editable/index.jsx +181 -0
- package/dist/components/field/index.d.ts +201 -0
- package/dist/components/field/index.js +10 -0
- package/dist/components/field/index.jsx +10 -0
- package/dist/components/fieldset/index.d.ts +109 -0
- package/dist/components/fieldset/index.js +9 -0
- package/dist/components/fieldset/index.jsx +9 -0
- package/dist/components/highlight/index.d.ts +15 -0
- package/dist/components/highlight/index.js +47 -0
- package/dist/components/highlight/index.jsx +31 -0
- package/dist/components/presence/index.d.ts +5 -0
- package/dist/components/presence/index.js +9 -0
- package/dist/components/presence/index.jsx +9 -0
- package/dist/components/select/index.d.ts +134 -0
- package/dist/components/select/index.js +363 -0
- package/dist/components/select/index.jsx +312 -0
- package/dist/compose-refs-BVVIB7xn.js +20 -0
- package/dist/compose-refs-icUeuyHm.jsx +20 -0
- package/dist/core-DbInRfhI.jsx +416 -0
- package/dist/core-oNB2jGcl.js +416 -0
- package/dist/create-split-props-B8A7_AF7.jsx +7 -0
- package/dist/create-split-props-pQu7jijw.js +7 -0
- package/dist/factory-4A25bngy.d.ts +14 -0
- package/dist/factory-Ch5jgk20.jsx +37 -0
- package/dist/factory-PGDAvOKb.js +43 -0
- package/dist/field-BRr9Zdes.jsx +260 -0
- package/dist/field-CoYiA2ek.js +288 -0
- package/dist/fieldset-B_LyllEa.jsx +169 -0
- package/dist/fieldset-BrJqMLEd.js +184 -0
- package/dist/index-C7N791Fc.d.ts +23 -0
- package/dist/index-GEfvAmRc.d.ts +76 -0
- package/dist/index-j2avJy7D.d.ts +38 -0
- package/dist/index-oc8gLl07.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-Bmn43U_q.jsx +68 -0
- package/dist/presence-BpwBRlZW.js +81 -0
- package/dist/providers-Bo0OFe08.js +96 -0
- package/dist/providers-DFaRRd80.jsx +82 -0
- package/dist/render-strategy-BNECKEQk.d.ts +9 -0
- package/dist/render-strategy-CdJhRv3I.jsx +12 -0
- package/dist/render-strategy-DFlz7Uc4.js +12 -0
- package/dist/run-if-fn-A3VwXy-o.jsx +6 -0
- package/dist/run-if-fn-D5794CxE.js +6 -0
- package/dist/types-Dbw4va3W.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-DQi-Cen5.js +0 -0
- package/dist/utils-vSjszv0W.jsx +0 -0
- package/package.json +102 -2
- /package/dist/{utils-DSKoW7eB.jsx → create-context-C3rvZvkc.jsx} +0 -0
- /package/dist/{utils-GEMuT7an.js → create-context-GfQ_MylE.js} +0 -0
- /package/dist/{index-C_ThrXdH.d.ts → index-B6dBCfnB.d.ts} +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { Key } from "@solid-primitives/keyed";
|
|
2
|
+
import { INIT_STATE, MachineStatus, createScope, mergeProps } from "@sprawlify/primitives/core";
|
|
3
|
+
import { compact, ensure, isEqual, isFunction, isNumber, isObject, isString, toArray, warn } from "@sprawlify/primitives/utils";
|
|
4
|
+
import { createEffect, createMemo, createSignal, mergeProps as mergeProps$1, onCleanup, onMount, untrack } from "solid-js";
|
|
5
|
+
import { createNormalizer } from "@sprawlify/primitives/types";
|
|
6
|
+
|
|
7
|
+
//#region src/core/bindable.ts
|
|
8
|
+
function createBindable(props) {
|
|
9
|
+
const initial = props().value ?? props().defaultValue;
|
|
10
|
+
const eq = props().isEqual ?? Object.is;
|
|
11
|
+
const [value, setValue] = createSignal(initial);
|
|
12
|
+
const controlled = createMemo(() => props().value != void 0);
|
|
13
|
+
const valueRef = { current: value() };
|
|
14
|
+
const prevValue = { current: void 0 };
|
|
15
|
+
createEffect(() => {
|
|
16
|
+
const v = controlled() ? props().value : value();
|
|
17
|
+
prevValue.current = v;
|
|
18
|
+
valueRef.current = v;
|
|
19
|
+
});
|
|
20
|
+
const set = (v) => {
|
|
21
|
+
const prev = prevValue.current;
|
|
22
|
+
const next = isFunction(v) ? v(valueRef.current) : v;
|
|
23
|
+
if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
|
|
24
|
+
next,
|
|
25
|
+
prev
|
|
26
|
+
});
|
|
27
|
+
if (!controlled()) setValue(next);
|
|
28
|
+
if (!eq(next, prev)) props().onChange?.(next, prev);
|
|
29
|
+
};
|
|
30
|
+
function get() {
|
|
31
|
+
const v = controlled() ? props().value : value;
|
|
32
|
+
return isFunction(v) ? v() : v;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
initial,
|
|
36
|
+
ref: valueRef,
|
|
37
|
+
get,
|
|
38
|
+
set,
|
|
39
|
+
invoke(nextValue, prevValue$1) {
|
|
40
|
+
props().onChange?.(nextValue, prevValue$1);
|
|
41
|
+
},
|
|
42
|
+
hash(value$1) {
|
|
43
|
+
return props().hash?.(value$1) ?? String(value$1);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
createBindable.cleanup = (fn) => {
|
|
48
|
+
onCleanup(() => fn());
|
|
49
|
+
};
|
|
50
|
+
createBindable.ref = (defaultValue) => {
|
|
51
|
+
let value = defaultValue;
|
|
52
|
+
return {
|
|
53
|
+
get: () => value,
|
|
54
|
+
set: (next) => {
|
|
55
|
+
value = next;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/core/refs.ts
|
|
62
|
+
function createRefs(refs) {
|
|
63
|
+
const ref = { current: refs };
|
|
64
|
+
return {
|
|
65
|
+
get(key) {
|
|
66
|
+
return ref.current[key];
|
|
67
|
+
},
|
|
68
|
+
set(key, value) {
|
|
69
|
+
ref.current[key] = value;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/core/track.ts
|
|
76
|
+
function access$1(v) {
|
|
77
|
+
if (isFunction(v)) return v();
|
|
78
|
+
return v;
|
|
79
|
+
}
|
|
80
|
+
const createTrack = (deps, effect) => {
|
|
81
|
+
let prevDeps = [];
|
|
82
|
+
let isFirstRun = true;
|
|
83
|
+
createEffect(() => {
|
|
84
|
+
if (isFirstRun) {
|
|
85
|
+
prevDeps = deps.map((d) => access$1(d));
|
|
86
|
+
isFirstRun = false;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let changed = false;
|
|
90
|
+
for (let i = 0; i < deps.length; i++) if (!isEqual(prevDeps[i], access$1(deps[i]))) {
|
|
91
|
+
changed = true;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (changed) {
|
|
95
|
+
prevDeps = deps.map((d) => access$1(d));
|
|
96
|
+
effect();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/core/machine.ts
|
|
103
|
+
function useMachine(machine, userProps = {}) {
|
|
104
|
+
const scope = createMemo(() => {
|
|
105
|
+
const { id, ids, getRootNode } = access(userProps);
|
|
106
|
+
return createScope({
|
|
107
|
+
id,
|
|
108
|
+
ids,
|
|
109
|
+
getRootNode
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
const debug = (...args) => {
|
|
113
|
+
if (machine.debug) console.log(...args);
|
|
114
|
+
};
|
|
115
|
+
const prop = createProp(createMemo(() => machine.props?.({
|
|
116
|
+
props: compact(access(userProps)),
|
|
117
|
+
scope: scope()
|
|
118
|
+
}) ?? access(userProps)));
|
|
119
|
+
const context = machine.context?.({
|
|
120
|
+
prop,
|
|
121
|
+
bindable: createBindable,
|
|
122
|
+
get scope() {
|
|
123
|
+
return scope();
|
|
124
|
+
},
|
|
125
|
+
flush,
|
|
126
|
+
getContext() {
|
|
127
|
+
return ctx;
|
|
128
|
+
},
|
|
129
|
+
getComputed() {
|
|
130
|
+
return computed;
|
|
131
|
+
},
|
|
132
|
+
getRefs() {
|
|
133
|
+
return refs;
|
|
134
|
+
},
|
|
135
|
+
getEvent() {
|
|
136
|
+
return getEvent();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const ctx = {
|
|
140
|
+
get(key) {
|
|
141
|
+
return context?.[key].get();
|
|
142
|
+
},
|
|
143
|
+
set(key, value) {
|
|
144
|
+
context?.[key].set(value);
|
|
145
|
+
},
|
|
146
|
+
initial(key) {
|
|
147
|
+
return context?.[key].initial;
|
|
148
|
+
},
|
|
149
|
+
hash(key) {
|
|
150
|
+
const current = context?.[key].get();
|
|
151
|
+
return context?.[key].hash(current);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const effects = { current: /* @__PURE__ */ new Map() };
|
|
155
|
+
const transitionRef = { current: null };
|
|
156
|
+
const previousEventRef = { current: null };
|
|
157
|
+
const eventRef = { current: { type: "" } };
|
|
158
|
+
const getEvent = () => mergeProps$1(eventRef.current, {
|
|
159
|
+
current() {
|
|
160
|
+
return eventRef.current;
|
|
161
|
+
},
|
|
162
|
+
previous() {
|
|
163
|
+
return previousEventRef.current;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const getState = () => mergeProps$1(state, {
|
|
167
|
+
matches(...values) {
|
|
168
|
+
const current = state.get();
|
|
169
|
+
return values.includes(current);
|
|
170
|
+
},
|
|
171
|
+
hasTag(tag) {
|
|
172
|
+
const current = state.get();
|
|
173
|
+
return !!machine.states[current]?.tags?.includes(tag);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const refs = createRefs(machine.refs?.({
|
|
177
|
+
prop,
|
|
178
|
+
context: ctx
|
|
179
|
+
}) ?? {});
|
|
180
|
+
const getParams = () => ({
|
|
181
|
+
state: getState(),
|
|
182
|
+
context: ctx,
|
|
183
|
+
event: getEvent(),
|
|
184
|
+
prop,
|
|
185
|
+
send,
|
|
186
|
+
action,
|
|
187
|
+
guard,
|
|
188
|
+
track: createTrack,
|
|
189
|
+
refs,
|
|
190
|
+
computed,
|
|
191
|
+
flush,
|
|
192
|
+
get scope() {
|
|
193
|
+
return scope();
|
|
194
|
+
},
|
|
195
|
+
choose
|
|
196
|
+
});
|
|
197
|
+
const action = (keys) => {
|
|
198
|
+
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
199
|
+
if (!strs) return;
|
|
200
|
+
const fns = strs.map((s) => {
|
|
201
|
+
const fn = machine.implementations?.actions?.[s];
|
|
202
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
203
|
+
return fn;
|
|
204
|
+
});
|
|
205
|
+
for (const fn of fns) fn?.(getParams());
|
|
206
|
+
};
|
|
207
|
+
const guard = (str) => {
|
|
208
|
+
if (isFunction(str)) return str(getParams());
|
|
209
|
+
return machine.implementations?.guards?.[str](getParams());
|
|
210
|
+
};
|
|
211
|
+
const effect = (keys) => {
|
|
212
|
+
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
213
|
+
if (!strs) return;
|
|
214
|
+
const fns = strs.map((s) => {
|
|
215
|
+
const fn = machine.implementations?.effects?.[s];
|
|
216
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
217
|
+
return fn;
|
|
218
|
+
});
|
|
219
|
+
const cleanups = [];
|
|
220
|
+
for (const fn of fns) {
|
|
221
|
+
const cleanup = fn?.(getParams());
|
|
222
|
+
if (cleanup) cleanups.push(cleanup);
|
|
223
|
+
}
|
|
224
|
+
return () => cleanups.forEach((fn) => fn?.());
|
|
225
|
+
};
|
|
226
|
+
const choose = (transitions) => {
|
|
227
|
+
return toArray(transitions).find((t) => {
|
|
228
|
+
let result = !t.guard;
|
|
229
|
+
if (isString(t.guard)) result = !!guard(t.guard);
|
|
230
|
+
else if (isFunction(t.guard)) result = t.guard(getParams());
|
|
231
|
+
return result;
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
const computed = (key) => {
|
|
235
|
+
ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
236
|
+
const fn = machine.computed[key];
|
|
237
|
+
return fn({
|
|
238
|
+
context: ctx,
|
|
239
|
+
event: eventRef.current,
|
|
240
|
+
prop,
|
|
241
|
+
refs,
|
|
242
|
+
scope: scope(),
|
|
243
|
+
computed
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
const state = createBindable(() => ({
|
|
247
|
+
defaultValue: machine.initialState({ prop }),
|
|
248
|
+
onChange(nextState, prevState) {
|
|
249
|
+
if (prevState) {
|
|
250
|
+
effects.current.get(prevState)?.();
|
|
251
|
+
effects.current.delete(prevState);
|
|
252
|
+
}
|
|
253
|
+
if (prevState) action(machine.states[prevState]?.exit);
|
|
254
|
+
action(transitionRef.current?.actions);
|
|
255
|
+
const cleanup = effect(machine.states[nextState]?.effects);
|
|
256
|
+
if (cleanup) effects.current.set(nextState, cleanup);
|
|
257
|
+
if (prevState === INIT_STATE) {
|
|
258
|
+
action(machine.entry);
|
|
259
|
+
const cleanup$1 = effect(machine.effects);
|
|
260
|
+
if (cleanup$1) effects.current.set(INIT_STATE, cleanup$1);
|
|
261
|
+
}
|
|
262
|
+
action(machine.states[nextState]?.entry);
|
|
263
|
+
}
|
|
264
|
+
}));
|
|
265
|
+
let status = MachineStatus.NotStarted;
|
|
266
|
+
onMount(() => {
|
|
267
|
+
const started = status === MachineStatus.Started;
|
|
268
|
+
status = MachineStatus.Started;
|
|
269
|
+
debug(started ? "rehydrating..." : "initializing...");
|
|
270
|
+
state.invoke(state.initial, INIT_STATE);
|
|
271
|
+
});
|
|
272
|
+
onCleanup(() => {
|
|
273
|
+
debug("unmounting...");
|
|
274
|
+
status = MachineStatus.Stopped;
|
|
275
|
+
effects.current.forEach((fn) => fn?.());
|
|
276
|
+
effects.current = /* @__PURE__ */ new Map();
|
|
277
|
+
transitionRef.current = null;
|
|
278
|
+
action(machine.exit);
|
|
279
|
+
});
|
|
280
|
+
const send = (event) => {
|
|
281
|
+
queueMicrotask(() => {
|
|
282
|
+
if (status !== MachineStatus.Started) return;
|
|
283
|
+
previousEventRef.current = eventRef.current;
|
|
284
|
+
eventRef.current = event;
|
|
285
|
+
let currentState = untrack(() => state.get());
|
|
286
|
+
const transition = choose(machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]);
|
|
287
|
+
if (!transition) return;
|
|
288
|
+
transitionRef.current = transition;
|
|
289
|
+
const target = transition.target ?? currentState;
|
|
290
|
+
debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
|
|
291
|
+
const changed = target !== currentState;
|
|
292
|
+
if (changed) state.set(target);
|
|
293
|
+
else if (transition.reenter && !changed) state.invoke(currentState, currentState);
|
|
294
|
+
else action(transition.actions);
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
machine.watch?.(getParams());
|
|
298
|
+
return {
|
|
299
|
+
state: getState(),
|
|
300
|
+
send,
|
|
301
|
+
context: ctx,
|
|
302
|
+
prop,
|
|
303
|
+
get scope() {
|
|
304
|
+
return scope();
|
|
305
|
+
},
|
|
306
|
+
refs,
|
|
307
|
+
computed,
|
|
308
|
+
event: getEvent(),
|
|
309
|
+
getStatus: () => status
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function flush(fn) {
|
|
313
|
+
fn();
|
|
314
|
+
}
|
|
315
|
+
function access(value) {
|
|
316
|
+
return isFunction(value) ? value() : value;
|
|
317
|
+
}
|
|
318
|
+
function createProp(value) {
|
|
319
|
+
return function get(key) {
|
|
320
|
+
return value()[key];
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/core/merge-props.ts
|
|
326
|
+
function mergeProps$2(...sources) {
|
|
327
|
+
const target = {};
|
|
328
|
+
for (let i = 0; i < sources.length; i++) {
|
|
329
|
+
let source = sources[i];
|
|
330
|
+
if (typeof source === "function") source = source();
|
|
331
|
+
if (source) {
|
|
332
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
333
|
+
for (const key in descriptors) {
|
|
334
|
+
if (key in target) continue;
|
|
335
|
+
Object.defineProperty(target, key, {
|
|
336
|
+
enumerable: true,
|
|
337
|
+
get() {
|
|
338
|
+
let e = {};
|
|
339
|
+
if (key === "style" || key === "class" || key === "className" || key.startsWith("on")) {
|
|
340
|
+
for (let i$1 = 0; i$1 < sources.length; i$1++) {
|
|
341
|
+
let s = sources[i$1];
|
|
342
|
+
if (typeof s === "function") s = s();
|
|
343
|
+
e = mergeProps(e, { [key]: (s || {})[key] });
|
|
344
|
+
}
|
|
345
|
+
return e[key];
|
|
346
|
+
}
|
|
347
|
+
for (let i$1 = sources.length - 1; i$1 >= 0; i$1--) {
|
|
348
|
+
let v, s = sources[i$1];
|
|
349
|
+
if (typeof s === "function") s = s();
|
|
350
|
+
v = (s || {})[key];
|
|
351
|
+
if (v !== void 0) return v;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return target;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/core/normalize-props.ts
|
|
363
|
+
const eventMap = {
|
|
364
|
+
onFocus: "onFocusIn",
|
|
365
|
+
onBlur: "onFocusOut",
|
|
366
|
+
onDoubleClick: "onDblClick",
|
|
367
|
+
onChange: "onInput",
|
|
368
|
+
defaultChecked: "checked",
|
|
369
|
+
defaultValue: "value",
|
|
370
|
+
htmlFor: "for",
|
|
371
|
+
className: "class"
|
|
372
|
+
};
|
|
373
|
+
const format = (v) => v.startsWith("--") ? v : hyphenateStyleName(v);
|
|
374
|
+
function toSolidProp(prop) {
|
|
375
|
+
return prop in eventMap ? eventMap[prop] : prop;
|
|
376
|
+
}
|
|
377
|
+
const normalizeProps = createNormalizer((props) => {
|
|
378
|
+
const normalized = {};
|
|
379
|
+
for (const key in props) {
|
|
380
|
+
const value = props[key];
|
|
381
|
+
if (key === "readOnly" && value === false) continue;
|
|
382
|
+
if (key === "style" && isObject(value)) {
|
|
383
|
+
normalized["style"] = cssify(value);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (key === "children") {
|
|
387
|
+
if (isString(value)) normalized["textContent"] = value;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
normalized[toSolidProp(key)] = value;
|
|
391
|
+
}
|
|
392
|
+
return normalized;
|
|
393
|
+
});
|
|
394
|
+
function cssify(style) {
|
|
395
|
+
let css = {};
|
|
396
|
+
for (const property in style) {
|
|
397
|
+
const value = style[property];
|
|
398
|
+
if (!isString(value) && !isNumber(value)) continue;
|
|
399
|
+
css[format(property)] = value;
|
|
400
|
+
}
|
|
401
|
+
return css;
|
|
402
|
+
}
|
|
403
|
+
const uppercasePattern = /[A-Z]/g;
|
|
404
|
+
const msPattern = /^ms-/;
|
|
405
|
+
function toHyphenLower(match) {
|
|
406
|
+
return "-" + match.toLowerCase();
|
|
407
|
+
}
|
|
408
|
+
const cache = {};
|
|
409
|
+
function hyphenateStyleName(name) {
|
|
410
|
+
if (cache.hasOwnProperty(name)) return cache[name];
|
|
411
|
+
var hName = name.replace(uppercasePattern, toHyphenLower);
|
|
412
|
+
return cache[name] = msPattern.test(hName) ? "-" + hName : hName;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
//#endregion
|
|
416
|
+
export { useMachine as i, normalizeProps as n, mergeProps$2 as r, Key as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentProps, JSX } from "solid-js";
|
|
2
|
+
|
|
3
|
+
//#region src/components/factory.d.ts
|
|
4
|
+
type ElementType = keyof JSX.IntrinsicElements;
|
|
5
|
+
type ParentProps$1<T extends ElementType> = (userProps?: JSX.IntrinsicElements[T]) => JSX.HTMLAttributes<any>;
|
|
6
|
+
type PolymorphicProps<T extends ElementType> = {
|
|
7
|
+
/**
|
|
8
|
+
* Use the provided child element as the default rendered element, combining their props and behavior.
|
|
9
|
+
*/
|
|
10
|
+
asChild?: (props: ParentProps$1<T>) => JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
type HTMLProps<E$1 extends ElementType> = JSX.IntrinsicElements[E$1];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { PolymorphicProps as n, HTMLProps as t };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { r as mergeProps$1 } from "./core-DbInRfhI.jsx";
|
|
2
|
+
import { Show, splitProps } from "solid-js";
|
|
3
|
+
import { Dynamic } from "solid-js/web";
|
|
4
|
+
|
|
5
|
+
//#region src/components/factory.tsx
|
|
6
|
+
const withAsProp = (Component) => {
|
|
7
|
+
const SprawlifyComponent = (props) => {
|
|
8
|
+
const [localProps, parentProps] = splitProps(props, ["asChild"]);
|
|
9
|
+
return <Show when={localProps.asChild} fallback={<Dynamic component={Component} {...parentProps} />}>
|
|
10
|
+
{(asChild) => {
|
|
11
|
+
const propsFn = (userProps) => {
|
|
12
|
+
const [, restProps] = splitProps(parentProps, ["ref"]);
|
|
13
|
+
return mergeProps$1(restProps, userProps);
|
|
14
|
+
};
|
|
15
|
+
return asChild()(propsFn);
|
|
16
|
+
}}
|
|
17
|
+
</Show>;
|
|
18
|
+
};
|
|
19
|
+
return SprawlifyComponent;
|
|
20
|
+
};
|
|
21
|
+
function jsxFactory() {
|
|
22
|
+
const cache = /* @__PURE__ */ new Map();
|
|
23
|
+
return new Proxy(withAsProp, {
|
|
24
|
+
apply(_target, _thisArg, argArray) {
|
|
25
|
+
return withAsProp(argArray[0]);
|
|
26
|
+
},
|
|
27
|
+
get(_, element) {
|
|
28
|
+
const asElement = element;
|
|
29
|
+
if (!cache.has(asElement)) cache.set(asElement, withAsProp(asElement));
|
|
30
|
+
return cache.get(asElement);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const sprawlify = jsxFactory();
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { sprawlify as t };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { r as mergeProps$2 } from "./core-oNB2jGcl.js";
|
|
2
|
+
import { Show, splitProps } from "solid-js";
|
|
3
|
+
import { Dynamic, createComponent, mergeProps as mergeProps$1 } from "solid-js/web";
|
|
4
|
+
|
|
5
|
+
//#region src/components/factory.tsx
|
|
6
|
+
const withAsProp = (Component) => {
|
|
7
|
+
const SprawlifyComponent = (props) => {
|
|
8
|
+
const [localProps, parentProps] = splitProps(props, ["asChild"]);
|
|
9
|
+
return createComponent(Show, {
|
|
10
|
+
get when() {
|
|
11
|
+
return localProps.asChild;
|
|
12
|
+
},
|
|
13
|
+
get fallback() {
|
|
14
|
+
return createComponent(Dynamic, mergeProps$1({ component: Component }, parentProps));
|
|
15
|
+
},
|
|
16
|
+
children: (asChild) => {
|
|
17
|
+
const propsFn = (userProps) => {
|
|
18
|
+
const [, restProps] = splitProps(parentProps, ["ref"]);
|
|
19
|
+
return mergeProps$2(restProps, userProps);
|
|
20
|
+
};
|
|
21
|
+
return asChild()(propsFn);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return SprawlifyComponent;
|
|
26
|
+
};
|
|
27
|
+
function jsxFactory() {
|
|
28
|
+
const cache = /* @__PURE__ */ new Map();
|
|
29
|
+
return new Proxy(withAsProp, {
|
|
30
|
+
apply(_target, _thisArg, argArray) {
|
|
31
|
+
return withAsProp(argArray[0]);
|
|
32
|
+
},
|
|
33
|
+
get(_, element) {
|
|
34
|
+
const asElement = element;
|
|
35
|
+
if (!cache.has(asElement)) cache.set(asElement, withAsProp(asElement));
|
|
36
|
+
return cache.get(asElement);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const sprawlify = jsxFactory();
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { sprawlify as t };
|