@sprawlify/vue 0.0.64 → 0.0.66
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-BN_g-Awi.js +18 -0
- package/dist/clean-props-ChPEW0vT.js +9 -0
- package/dist/collapsible-BBV8R9Wm.js +259 -0
- package/dist/collection-DR2kMzrX.js +218 -0
- package/dist/components/accordion/index.d.ts +195 -0
- package/dist/components/accordion/index.js +361 -0
- package/dist/components/angle-slider/index.d.ts +230 -0
- package/dist/components/angle-slider/index.js +371 -0
- package/dist/components/avatar/index.d.ts +116 -0
- package/dist/components/avatar/index.js +177 -0
- package/dist/components/bottom-sheet/index.d.ts +241 -0
- package/dist/components/bottom-sheet/index.js +429 -0
- package/dist/components/carousel/index.d.ts +306 -0
- package/dist/components/carousel/index.js +500 -0
- package/dist/components/checkbox/index.d.ts +273 -0
- package/dist/components/checkbox/index.js +500 -0
- package/dist/components/client-only/index.d.ts +20 -0
- package/dist/components/client-only/index.js +22 -0
- package/dist/components/clipboard/index.d.ts +204 -0
- package/dist/components/clipboard/index.js +297 -0
- package/dist/components/collapsible/index.d.ts +163 -0
- package/dist/components/collapsible/index.js +7 -0
- package/dist/components/collection/index.d.ts +2 -0
- package/dist/components/collection/index.js +4 -0
- package/dist/components/field/index.d.ts +326 -0
- package/dist/components/field/index.js +7 -0
- package/dist/components/fieldset/index.d.ts +161 -0
- package/dist/components/fieldset/index.js +7 -0
- package/dist/components/presence/index.d.ts +3 -0
- package/dist/components/presence/index.js +6 -0
- package/dist/components/select/index.d.ts +429 -0
- package/dist/components/select/index.js +769 -0
- package/dist/core-DNndr38p.js +337 -0
- package/dist/create-split-props-YZ3qgXe_.js +11 -0
- package/dist/factory-BH3WrWd2.js +68 -0
- package/dist/factory-D_ge_w76.d.ts +8 -0
- package/dist/field-DnHnX3Tf.js +501 -0
- package/dist/fieldset-DzhN7Zrg.js +278 -0
- package/dist/index-B66Om_3U.d.ts +22 -0
- package/dist/index-DqRk-Yea.d.ts +199 -0
- package/dist/index-rHf4D8np.d.ts +57 -0
- package/dist/index.d.ts +10 -34
- package/dist/index.js +4 -551
- package/dist/presence-CvUnYMZQ.js +105 -0
- package/dist/presence-types-Bv1E60Cw.d.ts +13 -0
- package/dist/providers-B2CNPFg1.js +108 -0
- package/dist/types-Bj-dS2Hc.d.ts +9 -0
- package/dist/use-forward-expose-4p5AGAI3.js +67 -0
- package/dist/use-render-strategy-BkxoN6ll.js +7 -0
- package/dist/use-render-strategy-CHj_pCfT.d.ts +9 -0
- package/dist/utils-B4FuOOE-.js +51 -0
- package/package.json +58 -2
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { INIT_STATE, MachineStatus, createScope, mergeProps as mergeProps$1 } from "@sprawlify/primitives/core";
|
|
2
|
+
import { createNormalizer } from "@sprawlify/primitives/types";
|
|
3
|
+
import { compact, ensure, isEqual, isFunction, isString, toArray, warn } from "@sprawlify/primitives/utils";
|
|
4
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, onUnmounted, shallowRef, toValue, watch } from "vue";
|
|
5
|
+
|
|
6
|
+
//#region src/core/normalize-props.ts
|
|
7
|
+
function toCase(txt) {
|
|
8
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
const propMap = {
|
|
11
|
+
htmlFor: "for",
|
|
12
|
+
className: "class",
|
|
13
|
+
onDoubleClick: "onDblclick",
|
|
14
|
+
onChange: "onInput",
|
|
15
|
+
onFocus: "onFocusin",
|
|
16
|
+
onBlur: "onFocusout",
|
|
17
|
+
defaultValue: "value",
|
|
18
|
+
defaultChecked: "checked"
|
|
19
|
+
};
|
|
20
|
+
const preserveKeys = "viewBox,className,preserveAspectRatio,fillRule,clipPath,clipRule,strokeWidth,strokeLinecap,strokeLinejoin,strokeDasharray,strokeDashoffset,strokeMiterlimit".split(",");
|
|
21
|
+
function toVueProp(prop) {
|
|
22
|
+
if (prop in propMap) return propMap[prop];
|
|
23
|
+
if (prop.startsWith("on")) return `on${toCase(prop.substr(2))}`;
|
|
24
|
+
if (preserveKeys.includes(prop)) return prop;
|
|
25
|
+
return prop.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
const normalizeProps$1 = createNormalizer((props) => {
|
|
28
|
+
const normalized = {};
|
|
29
|
+
for (const key in props) {
|
|
30
|
+
const value = props[key];
|
|
31
|
+
if (key === "children") {
|
|
32
|
+
if (typeof value === "string") normalized["innerHTML"] = value;
|
|
33
|
+
else if (process.env.NODE_ENV !== "production" && value != null) console.warn("[Vue Normalize Prop] : avoid passing non-primitive value as `children`");
|
|
34
|
+
} else normalized[toVueProp(key)] = props[key];
|
|
35
|
+
}
|
|
36
|
+
return normalized;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/core/bindable.ts
|
|
41
|
+
function bindable(props) {
|
|
42
|
+
const initial = props().defaultValue ?? props().value;
|
|
43
|
+
const eq = props().isEqual ?? Object.is;
|
|
44
|
+
const v = shallowRef(initial);
|
|
45
|
+
const controlled = computed(() => props().value !== void 0);
|
|
46
|
+
return {
|
|
47
|
+
initial,
|
|
48
|
+
ref: shallowRef(controlled.value ? props().value : v.value),
|
|
49
|
+
get() {
|
|
50
|
+
return controlled.value ? props().value : v.value;
|
|
51
|
+
},
|
|
52
|
+
set(val) {
|
|
53
|
+
const prev = controlled.value ? props().value : v.value;
|
|
54
|
+
const next = isFunction(val) ? val(prev) : val;
|
|
55
|
+
if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
|
|
56
|
+
next,
|
|
57
|
+
prev
|
|
58
|
+
});
|
|
59
|
+
if (!controlled.value) v.value = next;
|
|
60
|
+
if (!eq(next, prev)) props().onChange?.(next, prev);
|
|
61
|
+
},
|
|
62
|
+
invoke(nextValue, prevValue) {
|
|
63
|
+
props().onChange?.(nextValue, prevValue);
|
|
64
|
+
},
|
|
65
|
+
hash(value) {
|
|
66
|
+
return props().hash?.(value) ?? String(value);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
bindable.cleanup = (fn) => {
|
|
71
|
+
onUnmounted(() => fn());
|
|
72
|
+
};
|
|
73
|
+
bindable.ref = (defaultValue) => {
|
|
74
|
+
let value = defaultValue;
|
|
75
|
+
return {
|
|
76
|
+
get: () => value,
|
|
77
|
+
set: (next) => {
|
|
78
|
+
value = next;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/core/refs.ts
|
|
85
|
+
function useRefs(refs) {
|
|
86
|
+
const ref = { current: refs };
|
|
87
|
+
return {
|
|
88
|
+
get(key) {
|
|
89
|
+
return ref.current[key];
|
|
90
|
+
},
|
|
91
|
+
set(key, value) {
|
|
92
|
+
ref.current[key] = value;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/core/track.ts
|
|
99
|
+
const useTrack = (deps, effect) => {
|
|
100
|
+
watch(() => [...deps.map((d) => d())], (current, previous) => {
|
|
101
|
+
let changed = false;
|
|
102
|
+
for (let i = 0; i < current.length; i++) if (!isEqual(previous[i], toValue(current[i]))) {
|
|
103
|
+
changed = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (changed) effect();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/core/machine.ts
|
|
112
|
+
function useMachine(machine, userProps = {}) {
|
|
113
|
+
const scope = computed(() => {
|
|
114
|
+
const { id, ids, getRootNode } = toValue(userProps);
|
|
115
|
+
return createScope({
|
|
116
|
+
id,
|
|
117
|
+
ids,
|
|
118
|
+
getRootNode
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const debug = (...args) => {
|
|
122
|
+
if (machine.debug) console.log(...args);
|
|
123
|
+
};
|
|
124
|
+
const prop = useProp(computed(() => machine.props?.({
|
|
125
|
+
props: compact(toValue(userProps)),
|
|
126
|
+
get scope() {
|
|
127
|
+
return scope.value;
|
|
128
|
+
}
|
|
129
|
+
}) ?? toValue(userProps)));
|
|
130
|
+
const context = machine.context?.({
|
|
131
|
+
prop,
|
|
132
|
+
bindable,
|
|
133
|
+
get scope() {
|
|
134
|
+
return scope.value;
|
|
135
|
+
},
|
|
136
|
+
flush,
|
|
137
|
+
getContext() {
|
|
138
|
+
return ctx;
|
|
139
|
+
},
|
|
140
|
+
getComputed() {
|
|
141
|
+
return computed$1;
|
|
142
|
+
},
|
|
143
|
+
getRefs() {
|
|
144
|
+
return refs;
|
|
145
|
+
},
|
|
146
|
+
getEvent() {
|
|
147
|
+
return getEvent();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const ctx = {
|
|
151
|
+
get(key) {
|
|
152
|
+
return context[key]?.get();
|
|
153
|
+
},
|
|
154
|
+
set(key, value) {
|
|
155
|
+
context[key]?.set(value);
|
|
156
|
+
},
|
|
157
|
+
initial(key) {
|
|
158
|
+
return context[key]?.initial;
|
|
159
|
+
},
|
|
160
|
+
hash(key) {
|
|
161
|
+
const current = context[key]?.get();
|
|
162
|
+
return context[key]?.hash(current);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
let effects = /* @__PURE__ */ new Map();
|
|
166
|
+
let transitionRef = null;
|
|
167
|
+
const previousEventRef = { current: null };
|
|
168
|
+
const eventRef = { current: { type: "" } };
|
|
169
|
+
const getEvent = () => ({
|
|
170
|
+
...eventRef.current,
|
|
171
|
+
current() {
|
|
172
|
+
return eventRef.current;
|
|
173
|
+
},
|
|
174
|
+
previous() {
|
|
175
|
+
return previousEventRef.current;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
const getState = () => ({
|
|
179
|
+
...state,
|
|
180
|
+
matches(...values) {
|
|
181
|
+
const currentState = state.get();
|
|
182
|
+
return values.includes(currentState);
|
|
183
|
+
},
|
|
184
|
+
hasTag(tag) {
|
|
185
|
+
const currentState = state.get();
|
|
186
|
+
return !!machine.states[currentState]?.tags?.includes(tag);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const refs = useRefs(machine.refs?.({
|
|
190
|
+
prop,
|
|
191
|
+
context: ctx
|
|
192
|
+
}) ?? {});
|
|
193
|
+
const getParams = () => ({
|
|
194
|
+
state: getState(),
|
|
195
|
+
context: ctx,
|
|
196
|
+
event: getEvent(),
|
|
197
|
+
prop,
|
|
198
|
+
send,
|
|
199
|
+
action,
|
|
200
|
+
guard,
|
|
201
|
+
track: useTrack,
|
|
202
|
+
refs,
|
|
203
|
+
computed: computed$1,
|
|
204
|
+
flush,
|
|
205
|
+
get scope() {
|
|
206
|
+
return scope.value;
|
|
207
|
+
},
|
|
208
|
+
choose
|
|
209
|
+
});
|
|
210
|
+
const action = (keys) => {
|
|
211
|
+
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
212
|
+
if (!strs) return;
|
|
213
|
+
const fns = strs.map((s) => {
|
|
214
|
+
const fn = machine.implementations?.actions?.[s];
|
|
215
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
|
|
216
|
+
return fn;
|
|
217
|
+
});
|
|
218
|
+
for (const fn of fns) fn?.(getParams());
|
|
219
|
+
};
|
|
220
|
+
const guard = (str) => {
|
|
221
|
+
if (isFunction(str)) return str(getParams());
|
|
222
|
+
return machine.implementations?.guards?.[str](getParams());
|
|
223
|
+
};
|
|
224
|
+
const effect = (keys) => {
|
|
225
|
+
const strs = isFunction(keys) ? keys(getParams()) : keys;
|
|
226
|
+
if (!strs) return;
|
|
227
|
+
const fns = strs.map((s) => {
|
|
228
|
+
const fn = machine.implementations?.effects?.[s];
|
|
229
|
+
if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
|
|
230
|
+
return fn;
|
|
231
|
+
});
|
|
232
|
+
const cleanups = [];
|
|
233
|
+
for (const fn of fns) {
|
|
234
|
+
const cleanup = fn?.(getParams());
|
|
235
|
+
if (cleanup) cleanups.push(cleanup);
|
|
236
|
+
}
|
|
237
|
+
return () => cleanups.forEach((fn) => fn?.());
|
|
238
|
+
};
|
|
239
|
+
const choose = (transitions) => {
|
|
240
|
+
return toArray(transitions).find((t) => {
|
|
241
|
+
let result = !t.guard;
|
|
242
|
+
if (isString(t.guard)) result = !!guard(t.guard);
|
|
243
|
+
else if (isFunction(t.guard)) result = t.guard(getParams());
|
|
244
|
+
return result;
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
const computed$1 = (key) => {
|
|
248
|
+
ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
|
|
249
|
+
const fn = machine.computed[key];
|
|
250
|
+
return fn({
|
|
251
|
+
context: ctx,
|
|
252
|
+
event: getEvent(),
|
|
253
|
+
prop,
|
|
254
|
+
refs,
|
|
255
|
+
get scope() {
|
|
256
|
+
return scope.value;
|
|
257
|
+
},
|
|
258
|
+
computed: computed$1
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
const state = bindable(() => ({
|
|
262
|
+
defaultValue: machine.initialState({ prop }),
|
|
263
|
+
onChange(nextState, prevState) {
|
|
264
|
+
if (prevState) {
|
|
265
|
+
effects.get(prevState)?.();
|
|
266
|
+
effects.delete(prevState);
|
|
267
|
+
}
|
|
268
|
+
if (prevState) action(machine.states[prevState]?.exit);
|
|
269
|
+
action(transitionRef?.actions);
|
|
270
|
+
const cleanup = effect(machine.states[nextState]?.effects);
|
|
271
|
+
if (cleanup) effects.set(nextState, cleanup);
|
|
272
|
+
if (prevState === INIT_STATE) {
|
|
273
|
+
action(machine.entry);
|
|
274
|
+
const cleanup = effect(machine.effects);
|
|
275
|
+
if (cleanup) effects.set(INIT_STATE, cleanup);
|
|
276
|
+
}
|
|
277
|
+
action(machine.states[nextState]?.entry);
|
|
278
|
+
}
|
|
279
|
+
}));
|
|
280
|
+
let status = MachineStatus.NotStarted;
|
|
281
|
+
onMounted(() => {
|
|
282
|
+
const started = status === MachineStatus.Started;
|
|
283
|
+
status = MachineStatus.Started;
|
|
284
|
+
debug(started ? "rehydrating..." : "initializing...");
|
|
285
|
+
state.invoke(state.initial, INIT_STATE);
|
|
286
|
+
});
|
|
287
|
+
onBeforeUnmount(() => {
|
|
288
|
+
status = MachineStatus.Stopped;
|
|
289
|
+
debug("unmounting...");
|
|
290
|
+
const fns = effects.values();
|
|
291
|
+
for (const fn of fns) fn?.();
|
|
292
|
+
effects = /* @__PURE__ */ new Map();
|
|
293
|
+
action(machine.exit);
|
|
294
|
+
});
|
|
295
|
+
const send = (event) => {
|
|
296
|
+
if (status !== MachineStatus.Started) return;
|
|
297
|
+
previousEventRef.current = eventRef.current;
|
|
298
|
+
eventRef.current = event;
|
|
299
|
+
const currentState = state.get();
|
|
300
|
+
const transition = choose(machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]);
|
|
301
|
+
if (!transition) return;
|
|
302
|
+
transitionRef = transition;
|
|
303
|
+
const target = transition.target ?? currentState;
|
|
304
|
+
debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
|
|
305
|
+
const changed = target !== currentState;
|
|
306
|
+
if (changed) state.set(target);
|
|
307
|
+
else if (transition.reenter && !changed) state.invoke(currentState, currentState);
|
|
308
|
+
else action(transition.actions);
|
|
309
|
+
};
|
|
310
|
+
machine.watch?.(getParams());
|
|
311
|
+
return {
|
|
312
|
+
state: getState(),
|
|
313
|
+
send,
|
|
314
|
+
context: ctx,
|
|
315
|
+
prop,
|
|
316
|
+
get scope() {
|
|
317
|
+
return scope.value;
|
|
318
|
+
},
|
|
319
|
+
refs,
|
|
320
|
+
computed: computed$1,
|
|
321
|
+
event: getEvent(),
|
|
322
|
+
getStatus: () => status
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function useProp(valueRef) {
|
|
326
|
+
return function get(key) {
|
|
327
|
+
return valueRef.value[key];
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const flush = (fn) => {
|
|
331
|
+
nextTick().then(() => {
|
|
332
|
+
fn();
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
//#endregion
|
|
337
|
+
export { useMachine as n, normalizeProps$1 as r, mergeProps$1 as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/components/create-split-props.ts
|
|
2
|
+
const createSplitProps = () => (props, keys) => keys.reduce((previousValue, currentValue) => {
|
|
3
|
+
const [target, source] = previousValue;
|
|
4
|
+
const key = currentValue;
|
|
5
|
+
if (source[key] !== void 0) target[key] = source[key];
|
|
6
|
+
delete source[key];
|
|
7
|
+
return [target, source];
|
|
8
|
+
}, [{}, { ...props }]);
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { createSplitProps as t };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as mergeProps$1 } from "./core-DNndr38p.js";
|
|
2
|
+
import { Fragment, cloneVNode, defineComponent, h } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/dynamic.ts
|
|
5
|
+
const Dynamic = defineComponent({
|
|
6
|
+
name: "Dynamic",
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
setup(_, { attrs, slots }) {
|
|
9
|
+
return () => {
|
|
10
|
+
if (!slots.default) return null;
|
|
11
|
+
const children = renderSlotFragments(slots.default());
|
|
12
|
+
const [firstChildren, ...otherChildren] = children;
|
|
13
|
+
if (Object.keys(attrs).length > 0) {
|
|
14
|
+
delete firstChildren.props?.ref;
|
|
15
|
+
const mergedProps = mergeProps$1(attrs, firstChildren.props ?? {});
|
|
16
|
+
const cloned = cloneVNode(firstChildren, mergedProps);
|
|
17
|
+
for (const prop in mergedProps) if (prop.startsWith("on")) {
|
|
18
|
+
cloned.props ||= {};
|
|
19
|
+
cloned.props[prop] = mergedProps[prop];
|
|
20
|
+
}
|
|
21
|
+
return children.length === 1 ? cloned : [cloned, ...otherChildren];
|
|
22
|
+
}
|
|
23
|
+
return children;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function renderSlotFragments(children) {
|
|
28
|
+
if (!children) return [];
|
|
29
|
+
return children.flatMap((child) => {
|
|
30
|
+
if (child.type === Fragment) return renderSlotFragments(child.children);
|
|
31
|
+
return [child];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/components/factory.ts
|
|
37
|
+
const SELF_CLOSING_TAGS = "br, hr, img, input, area, textarea".split(", ");
|
|
38
|
+
const isSelfClosingTag = (tag) => typeof tag === "string" && SELF_CLOSING_TAGS.includes(tag);
|
|
39
|
+
const withAsChild = (component) => {
|
|
40
|
+
return defineComponent({
|
|
41
|
+
name: "Polymorphic",
|
|
42
|
+
inheritAttrs: false,
|
|
43
|
+
props: { asChild: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false
|
|
46
|
+
} },
|
|
47
|
+
setup(props, { attrs, slots }) {
|
|
48
|
+
if (!props.asChild) return () => h(component, attrs, isSelfClosingTag(component) ? void 0 : slots.default?.());
|
|
49
|
+
return () => h(Dynamic, attrs, slots);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
function jsxFactory() {
|
|
54
|
+
const cache = /* @__PURE__ */ new Map();
|
|
55
|
+
return new Proxy(withAsChild, {
|
|
56
|
+
apply(_target, _thisArg, argArray) {
|
|
57
|
+
return withAsChild(argArray[0]);
|
|
58
|
+
},
|
|
59
|
+
get(_, element) {
|
|
60
|
+
if (!cache.has(element)) cache.set(element, withAsChild(element));
|
|
61
|
+
return cache.get(element);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const sprawlify = jsxFactory();
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { sprawlify as t };
|