@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.
Files changed (52) hide show
  1. package/dist/chunk-BN_g-Awi.js +18 -0
  2. package/dist/clean-props-ChPEW0vT.js +9 -0
  3. package/dist/collapsible-BBV8R9Wm.js +259 -0
  4. package/dist/collection-DR2kMzrX.js +218 -0
  5. package/dist/components/accordion/index.d.ts +195 -0
  6. package/dist/components/accordion/index.js +361 -0
  7. package/dist/components/angle-slider/index.d.ts +230 -0
  8. package/dist/components/angle-slider/index.js +371 -0
  9. package/dist/components/avatar/index.d.ts +116 -0
  10. package/dist/components/avatar/index.js +177 -0
  11. package/dist/components/bottom-sheet/index.d.ts +241 -0
  12. package/dist/components/bottom-sheet/index.js +429 -0
  13. package/dist/components/carousel/index.d.ts +306 -0
  14. package/dist/components/carousel/index.js +500 -0
  15. package/dist/components/checkbox/index.d.ts +273 -0
  16. package/dist/components/checkbox/index.js +500 -0
  17. package/dist/components/client-only/index.d.ts +20 -0
  18. package/dist/components/client-only/index.js +22 -0
  19. package/dist/components/clipboard/index.d.ts +204 -0
  20. package/dist/components/clipboard/index.js +297 -0
  21. package/dist/components/collapsible/index.d.ts +163 -0
  22. package/dist/components/collapsible/index.js +7 -0
  23. package/dist/components/collection/index.d.ts +2 -0
  24. package/dist/components/collection/index.js +4 -0
  25. package/dist/components/field/index.d.ts +326 -0
  26. package/dist/components/field/index.js +7 -0
  27. package/dist/components/fieldset/index.d.ts +161 -0
  28. package/dist/components/fieldset/index.js +7 -0
  29. package/dist/components/presence/index.d.ts +3 -0
  30. package/dist/components/presence/index.js +6 -0
  31. package/dist/components/select/index.d.ts +429 -0
  32. package/dist/components/select/index.js +769 -0
  33. package/dist/core-DNndr38p.js +337 -0
  34. package/dist/create-split-props-YZ3qgXe_.js +11 -0
  35. package/dist/factory-BH3WrWd2.js +68 -0
  36. package/dist/factory-D_ge_w76.d.ts +8 -0
  37. package/dist/field-DnHnX3Tf.js +501 -0
  38. package/dist/fieldset-DzhN7Zrg.js +278 -0
  39. package/dist/index-B66Om_3U.d.ts +22 -0
  40. package/dist/index-DqRk-Yea.d.ts +199 -0
  41. package/dist/index-rHf4D8np.d.ts +57 -0
  42. package/dist/index.d.ts +10 -34
  43. package/dist/index.js +4 -551
  44. package/dist/presence-CvUnYMZQ.js +105 -0
  45. package/dist/presence-types-Bv1E60Cw.d.ts +13 -0
  46. package/dist/providers-B2CNPFg1.js +108 -0
  47. package/dist/types-Bj-dS2Hc.d.ts +9 -0
  48. package/dist/use-forward-expose-4p5AGAI3.js +67 -0
  49. package/dist/use-render-strategy-BkxoN6ll.js +7 -0
  50. package/dist/use-render-strategy-CHj_pCfT.d.ts +9 -0
  51. package/dist/utils-B4FuOOE-.js +51 -0
  52. package/package.json +58 -2
package/dist/index.js CHANGED
@@ -1,553 +1,6 @@
1
- import { INIT_STATE, MachineStatus, createScope, mergeProps } 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 { Fragment, camelize, computed, createCommentVNode, createElementBlock, defineComponent, getCurrentInstance, inject, nextTick, onBeforeUnmount, onMounted, onUnmounted, openBlock, provide, ref, renderSlot, shallowRef, toHandlerKey, toRef, toValue, watch } from "vue";
5
- import { getDocument, getWindow } from "@sprawlify/primitives/dom-query";
6
- import { createCollator, createFilter, isRTL } from "@sprawlify/primitives/i18n-utils";
1
+ import { n as useMachine, r as normalizeProps, t as mergeProps } from "./core-DNndr38p.js";
2
+ import { a as useLocaleContext, c as useEnvironmentContext, i as DEFAULT_LOCALE, n as useCollator, o as environment_provider_default, r as locale_provider_default, s as DEFAULT_ENVIRONMENT, t as useFilter } from "./providers-B2CNPFg1.js";
3
+ import { r as createContext, t as useForwardExpose } from "./use-forward-expose-4p5AGAI3.js";
4
+ import { n as useForwardProps, r as useEmitAsProps, t as useForwardPropsEmits } from "./utils-B4FuOOE-.js";
7
5
 
8
- //#region src/core/normalize-props.ts
9
- function toCase(txt) {
10
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
11
- }
12
- const propMap = {
13
- htmlFor: "for",
14
- className: "class",
15
- onDoubleClick: "onDblclick",
16
- onChange: "onInput",
17
- onFocus: "onFocusin",
18
- onBlur: "onFocusout",
19
- defaultValue: "value",
20
- defaultChecked: "checked"
21
- };
22
- const preserveKeys = "viewBox,className,preserveAspectRatio,fillRule,clipPath,clipRule,strokeWidth,strokeLinecap,strokeLinejoin,strokeDasharray,strokeDashoffset,strokeMiterlimit".split(",");
23
- function toVueProp(prop) {
24
- if (prop in propMap) return propMap[prop];
25
- if (prop.startsWith("on")) return `on${toCase(prop.substr(2))}`;
26
- if (preserveKeys.includes(prop)) return prop;
27
- return prop.toLowerCase();
28
- }
29
- const normalizeProps = createNormalizer((props) => {
30
- const normalized = {};
31
- for (const key in props) {
32
- const value = props[key];
33
- if (key === "children") {
34
- if (typeof value === "string") normalized["innerHTML"] = value;
35
- else if (process.env.NODE_ENV !== "production" && value != null) console.warn("[Vue Normalize Prop] : avoid passing non-primitive value as `children`");
36
- } else normalized[toVueProp(key)] = props[key];
37
- }
38
- return normalized;
39
- });
40
-
41
- //#endregion
42
- //#region src/core/bindable.ts
43
- function bindable(props) {
44
- const initial = props().defaultValue ?? props().value;
45
- const eq = props().isEqual ?? Object.is;
46
- const v = shallowRef(initial);
47
- const controlled = computed(() => props().value !== void 0);
48
- return {
49
- initial,
50
- ref: shallowRef(controlled.value ? props().value : v.value),
51
- get() {
52
- return controlled.value ? props().value : v.value;
53
- },
54
- set(val) {
55
- const prev = controlled.value ? props().value : v.value;
56
- const next = isFunction(val) ? val(prev) : val;
57
- if (props().debug) console.log(`[bindable > ${props().debug}] setValue`, {
58
- next,
59
- prev
60
- });
61
- if (!controlled.value) v.value = next;
62
- if (!eq(next, prev)) props().onChange?.(next, prev);
63
- },
64
- invoke(nextValue, prevValue) {
65
- props().onChange?.(nextValue, prevValue);
66
- },
67
- hash(value) {
68
- return props().hash?.(value) ?? String(value);
69
- }
70
- };
71
- }
72
- bindable.cleanup = (fn) => {
73
- onUnmounted(() => fn());
74
- };
75
- bindable.ref = (defaultValue) => {
76
- let value = defaultValue;
77
- return {
78
- get: () => value,
79
- set: (next) => {
80
- value = next;
81
- }
82
- };
83
- };
84
-
85
- //#endregion
86
- //#region src/core/refs.ts
87
- function useRefs(refs) {
88
- const ref = { current: refs };
89
- return {
90
- get(key) {
91
- return ref.current[key];
92
- },
93
- set(key, value) {
94
- ref.current[key] = value;
95
- }
96
- };
97
- }
98
-
99
- //#endregion
100
- //#region src/core/track.ts
101
- const useTrack = (deps, effect) => {
102
- watch(() => [...deps.map((d) => d())], (current, previous) => {
103
- let changed = false;
104
- for (let i = 0; i < current.length; i++) if (!isEqual(previous[i], toValue(current[i]))) {
105
- changed = true;
106
- break;
107
- }
108
- if (changed) effect();
109
- });
110
- };
111
-
112
- //#endregion
113
- //#region src/core/machine.ts
114
- function useMachine(machine, userProps = {}) {
115
- const scope = computed(() => {
116
- const { id, ids, getRootNode } = toValue(userProps);
117
- return createScope({
118
- id,
119
- ids,
120
- getRootNode
121
- });
122
- });
123
- const debug = (...args) => {
124
- if (machine.debug) console.log(...args);
125
- };
126
- const prop = useProp(computed(() => machine.props?.({
127
- props: compact(toValue(userProps)),
128
- get scope() {
129
- return scope.value;
130
- }
131
- }) ?? toValue(userProps)));
132
- const context = machine.context?.({
133
- prop,
134
- bindable,
135
- get scope() {
136
- return scope.value;
137
- },
138
- flush,
139
- getContext() {
140
- return ctx;
141
- },
142
- getComputed() {
143
- return computed$1;
144
- },
145
- getRefs() {
146
- return refs;
147
- },
148
- getEvent() {
149
- return getEvent();
150
- }
151
- });
152
- const ctx = {
153
- get(key) {
154
- return context[key]?.get();
155
- },
156
- set(key, value) {
157
- context[key]?.set(value);
158
- },
159
- initial(key) {
160
- return context[key]?.initial;
161
- },
162
- hash(key) {
163
- const current = context[key]?.get();
164
- return context[key]?.hash(current);
165
- }
166
- };
167
- let effects = /* @__PURE__ */ new Map();
168
- let transitionRef = null;
169
- const previousEventRef = { current: null };
170
- const eventRef = { current: { type: "" } };
171
- const getEvent = () => ({
172
- ...eventRef.current,
173
- current() {
174
- return eventRef.current;
175
- },
176
- previous() {
177
- return previousEventRef.current;
178
- }
179
- });
180
- const getState = () => ({
181
- ...state,
182
- matches(...values) {
183
- const currentState = state.get();
184
- return values.includes(currentState);
185
- },
186
- hasTag(tag) {
187
- const currentState = state.get();
188
- return !!machine.states[currentState]?.tags?.includes(tag);
189
- }
190
- });
191
- const refs = useRefs(machine.refs?.({
192
- prop,
193
- context: ctx
194
- }) ?? {});
195
- const getParams = () => ({
196
- state: getState(),
197
- context: ctx,
198
- event: getEvent(),
199
- prop,
200
- send,
201
- action,
202
- guard,
203
- track: useTrack,
204
- refs,
205
- computed: computed$1,
206
- flush,
207
- get scope() {
208
- return scope.value;
209
- },
210
- choose
211
- });
212
- const action = (keys) => {
213
- const strs = isFunction(keys) ? keys(getParams()) : keys;
214
- if (!strs) return;
215
- const fns = strs.map((s) => {
216
- const fn = machine.implementations?.actions?.[s];
217
- if (!fn) warn(`[sprawlify-js] No implementation found for action "${JSON.stringify(s)}"`);
218
- return fn;
219
- });
220
- for (const fn of fns) fn?.(getParams());
221
- };
222
- const guard = (str) => {
223
- if (isFunction(str)) return str(getParams());
224
- return machine.implementations?.guards?.[str](getParams());
225
- };
226
- const effect = (keys) => {
227
- const strs = isFunction(keys) ? keys(getParams()) : keys;
228
- if (!strs) return;
229
- const fns = strs.map((s) => {
230
- const fn = machine.implementations?.effects?.[s];
231
- if (!fn) warn(`[sprawlify-js] No implementation found for effect "${JSON.stringify(s)}"`);
232
- return fn;
233
- });
234
- const cleanups = [];
235
- for (const fn of fns) {
236
- const cleanup = fn?.(getParams());
237
- if (cleanup) cleanups.push(cleanup);
238
- }
239
- return () => cleanups.forEach((fn) => fn?.());
240
- };
241
- const choose = (transitions) => {
242
- return toArray(transitions).find((t) => {
243
- let result = !t.guard;
244
- if (isString(t.guard)) result = !!guard(t.guard);
245
- else if (isFunction(t.guard)) result = t.guard(getParams());
246
- return result;
247
- });
248
- };
249
- const computed$1 = (key) => {
250
- ensure(machine.computed, () => `[sprawlify-js] No computed object found on machine`);
251
- const fn = machine.computed[key];
252
- return fn({
253
- context: ctx,
254
- event: getEvent(),
255
- prop,
256
- refs,
257
- get scope() {
258
- return scope.value;
259
- },
260
- computed: computed$1
261
- });
262
- };
263
- const state = bindable(() => ({
264
- defaultValue: machine.initialState({ prop }),
265
- onChange(nextState, prevState) {
266
- if (prevState) {
267
- effects.get(prevState)?.();
268
- effects.delete(prevState);
269
- }
270
- if (prevState) action(machine.states[prevState]?.exit);
271
- action(transitionRef?.actions);
272
- const cleanup = effect(machine.states[nextState]?.effects);
273
- if (cleanup) effects.set(nextState, cleanup);
274
- if (prevState === INIT_STATE) {
275
- action(machine.entry);
276
- const cleanup = effect(machine.effects);
277
- if (cleanup) effects.set(INIT_STATE, cleanup);
278
- }
279
- action(machine.states[nextState]?.entry);
280
- }
281
- }));
282
- let status = MachineStatus.NotStarted;
283
- onMounted(() => {
284
- const started = status === MachineStatus.Started;
285
- status = MachineStatus.Started;
286
- debug(started ? "rehydrating..." : "initializing...");
287
- state.invoke(state.initial, INIT_STATE);
288
- });
289
- onBeforeUnmount(() => {
290
- status = MachineStatus.Stopped;
291
- debug("unmounting...");
292
- const fns = effects.values();
293
- for (const fn of fns) fn?.();
294
- effects = /* @__PURE__ */ new Map();
295
- action(machine.exit);
296
- });
297
- const send = (event) => {
298
- if (status !== MachineStatus.Started) return;
299
- previousEventRef.current = eventRef.current;
300
- eventRef.current = event;
301
- const currentState = state.get();
302
- const transition = choose(machine.states[currentState].on?.[event.type] ?? machine.on?.[event.type]);
303
- if (!transition) return;
304
- transitionRef = transition;
305
- const target = transition.target ?? currentState;
306
- debug("transition", event.type, transition.target || currentState, `(${transition.actions})`);
307
- const changed = target !== currentState;
308
- if (changed) state.set(target);
309
- else if (transition.reenter && !changed) state.invoke(currentState, currentState);
310
- else action(transition.actions);
311
- };
312
- machine.watch?.(getParams());
313
- return {
314
- state: getState(),
315
- send,
316
- context: ctx,
317
- prop,
318
- get scope() {
319
- return scope.value;
320
- },
321
- refs,
322
- computed: computed$1,
323
- event: getEvent(),
324
- getStatus: () => status
325
- };
326
- }
327
- function useProp(valueRef) {
328
- return function get(key) {
329
- return valueRef.value[key];
330
- };
331
- }
332
- const flush = (fn) => {
333
- nextTick().then(() => {
334
- fn();
335
- });
336
- };
337
-
338
- //#endregion
339
- //#region src/utils/run-if-fn.ts
340
- const isFunction$1 = (value) => typeof value === "function";
341
- const runIfFn = (valueOrFn, ...args) => isFunction$1(valueOrFn) ? valueOrFn(...args) : valueOrFn;
342
-
343
- //#endregion
344
- //#region src/utils/create-context.ts
345
- const createContext = (id) => {
346
- const contextId = Symbol(id);
347
- const provider = (value) => provide(contextId, value);
348
- const consumer = (fallback) => inject(contextId, fallback);
349
- return [
350
- provider,
351
- consumer,
352
- contextId
353
- ];
354
- };
355
-
356
- //#endregion
357
- //#region src/providers/environment/use-environment-context.ts
358
- const [EnvironmentContextProvider, useEnvironmentContext] = createContext("EnvironmentContext");
359
- const DEFAULT_ENVIRONMENT = computed(() => ({
360
- getRootNode: () => document,
361
- getDocument: () => document,
362
- getWindow: () => window
363
- }));
364
-
365
- //#endregion
366
- //#region src/providers/environment/environment-provider.vue?vue&type=script&setup=true&lang.ts
367
- var environment_provider_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
368
- __name: "environment-provider",
369
- props: { value: {
370
- type: Function,
371
- required: false,
372
- skipCheck: true
373
- } },
374
- setup(__props) {
375
- const props = __props;
376
- const spanRef = ref(null);
377
- const getRootNode = () => runIfFn(props.value) ?? spanRef.value?.getRootNode() ?? document;
378
- EnvironmentContextProvider(computed(() => ({
379
- getRootNode,
380
- getDocument: () => getDocument(getRootNode()),
381
- getWindow: () => getWindow(getRootNode())
382
- })));
383
- return (_ctx, _cache) => {
384
- return openBlock(), createElementBlock(Fragment, null, [renderSlot(_ctx.$slots, "default"), !props.value ? (openBlock(), createElementBlock("span", {
385
- key: 0,
386
- hidden: "",
387
- ref_key: "spanRef",
388
- ref: spanRef
389
- }, null, 512)) : createCommentVNode("v-if", true)], 64);
390
- };
391
- }
392
- });
393
-
394
- //#endregion
395
- //#region src/providers/environment/environment-provider.vue
396
- var environment_provider_default = environment_provider_vue_vue_type_script_setup_true_lang_default;
397
-
398
- //#endregion
399
- //#region src/providers/locale/use-locale-context.ts
400
- const DEFAULT_LOCALE = computed(() => ({
401
- dir: "ltr",
402
- locale: "en-US"
403
- }));
404
- const [LocaleContextProvider, useLocaleContext] = createContext("LocaleContext");
405
-
406
- //#endregion
407
- //#region src/providers/locale/locale-provider.vue?vue&type=script&setup=true&lang.ts
408
- var locale_provider_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
409
- __name: "locale-provider",
410
- props: { locale: {
411
- type: String,
412
- required: true
413
- } },
414
- setup(__props) {
415
- const props = __props;
416
- LocaleContextProvider(computed(() => ({
417
- locale: props.locale,
418
- dir: isRTL(props.locale) ? "rtl" : "ltr"
419
- })));
420
- return (_ctx, _cache) => {
421
- return renderSlot(_ctx.$slots, "default");
422
- };
423
- }
424
- });
425
-
426
- //#endregion
427
- //#region src/providers/locale/locale-provider.vue
428
- var locale_provider_default = locale_provider_vue_vue_type_script_setup_true_lang_default;
429
-
430
- //#endregion
431
- //#region src/providers/locale/use-collator.ts
432
- function useCollator(propsOrFn = {}) {
433
- const env = useLocaleContext();
434
- return computed(() => {
435
- const props = toValue(propsOrFn);
436
- const locale = props.locale ?? env.value.locale;
437
- const { locale: _, ...options } = props;
438
- return createCollator(locale, options);
439
- });
440
- }
441
-
442
- //#endregion
443
- //#region src/providers/locale/use-filter.ts
444
- function useFilter(props) {
445
- const env = useLocaleContext(DEFAULT_LOCALE);
446
- const locale = computed(() => props.locale ?? env.value.locale);
447
- return computed(() => createFilter({
448
- ...props,
449
- locale: locale.value
450
- }));
451
- }
452
-
453
- //#endregion
454
- //#region src/utils/use-emits-as-props.ts
455
- function useEmitAsProps(emit) {
456
- const vm = getCurrentInstance();
457
- const events = vm?.type.emits;
458
- const result = {};
459
- if (!events?.length) console.warn(`No emitted event found. Please check component: ${vm?.type.__name}`);
460
- for (const event of events) result[toHandlerKey(camelize(event))] = (...arg) => emit(event, ...arg);
461
- return result;
462
- }
463
-
464
- //#endregion
465
- //#region src/utils/unref-element.ts
466
- function unrefElement(elRef) {
467
- const plain = toValue(elRef);
468
- return plain?.$el ?? plain;
469
- }
470
-
471
- //#endregion
472
- //#region src/utils/use-forward-expose.ts
473
- const isElement = (el) => Object.prototype.hasOwnProperty.call(el, "nodeName") && typeof el.nodeName === "string";
474
- function useForwardExpose() {
475
- const instance = getCurrentInstance();
476
- const currentRef = ref();
477
- const currentElement = computed(() => {
478
- return ["#text", "#comment"].includes(currentRef.value?.$el.nodeName) ? currentRef.value?.$el.nextElementSibling : unrefElement(currentRef);
479
- });
480
- const localExpose = Object.assign({}, instance.exposed);
481
- const ret = {};
482
- for (const key in instance.props) Object.defineProperty(ret, key, {
483
- enumerable: true,
484
- configurable: true,
485
- get: () => instance.props[key]
486
- });
487
- if (Object.keys(localExpose).length > 0) for (const key in localExpose) Object.defineProperty(ret, key, {
488
- enumerable: true,
489
- configurable: true,
490
- get: () => localExpose[key]
491
- });
492
- Object.defineProperty(ret, "$el", {
493
- enumerable: true,
494
- configurable: true,
495
- get: () => instance.vnode.el
496
- });
497
- instance.exposed = ret;
498
- function forwardRef(ref) {
499
- currentRef.value = ref;
500
- if (isElement(ref) || !ref) return;
501
- Object.defineProperty(ret, "$el", {
502
- enumerable: true,
503
- configurable: true,
504
- get: () => ref.$el
505
- });
506
- instance.exposed = ret;
507
- }
508
- return {
509
- forwardRef,
510
- currentRef,
511
- currentElement
512
- };
513
- }
514
-
515
- //#endregion
516
- //#region src/utils/use-forward-props.ts
517
- function useForwardProps(props) {
518
- const vm = getCurrentInstance();
519
- const defaultProps = Object.keys(vm?.type.props ?? {}).reduce((prev, curr) => {
520
- const defaultValue = (vm?.type.props[curr]).default;
521
- if (defaultValue !== void 0) prev[curr] = defaultValue;
522
- return prev;
523
- }, {});
524
- const refProps = toRef(props);
525
- return computed(() => {
526
- const preservedProps = {};
527
- const assignedProps = vm?.vnode.props ?? {};
528
- Object.keys(assignedProps).forEach((key) => {
529
- preservedProps[camelize(key)] = assignedProps[key];
530
- });
531
- return Object.keys({
532
- ...defaultProps,
533
- ...preservedProps
534
- }).reduce((prev, curr) => {
535
- if (refProps.value[curr] !== void 0) prev[curr] = refProps.value[curr];
536
- return prev;
537
- }, {});
538
- });
539
- }
540
-
541
- //#endregion
542
- //#region src/utils/use-forward-props-emits.ts
543
- function useForwardPropsEmits(props, emit) {
544
- const parsedProps = useForwardProps(props);
545
- const emitsAsProps = emit ? useEmitAsProps(emit) : {};
546
- return computed(() => ({
547
- ...parsedProps.value,
548
- ...emitsAsProps
549
- }));
550
- }
551
-
552
- //#endregion
553
6
  export { DEFAULT_ENVIRONMENT, DEFAULT_LOCALE, environment_provider_default as EnvironmentProvider, locale_provider_default as LocaleProvider, createContext, mergeProps, normalizeProps, useCollator, useEmitAsProps, useEnvironmentContext, useFilter, useForwardExpose, useForwardProps, useForwardPropsEmits, useLocaleContext, useMachine };
@@ -0,0 +1,105 @@
1
+ import { n as useMachine, r as normalizeProps$1 } from "./core-DNndr38p.js";
2
+ import { r as createContext, t as useForwardExpose } from "./use-forward-expose-4p5AGAI3.js";
3
+ import { t as sprawlify } from "./factory-BH3WrWd2.js";
4
+ import { computed, createBlock, createCommentVNode, defineComponent, mergeDefaults, mergeProps, openBlock, ref, renderSlot, toValue, unref, watch, withCtx } from "vue";
5
+ import * as presence from "@sprawlify/primitives/machines/presence";
6
+
7
+ //#region src/components/presence/use-presence.ts
8
+ const usePresence = (props, emit) => {
9
+ const wasEverPresent = ref(false);
10
+ const nodeRef = ref(null);
11
+ const machineProps = computed(() => {
12
+ return {
13
+ present: toValue(props).present,
14
+ onExitComplete: () => emit?.("exitComplete")
15
+ };
16
+ });
17
+ const service = useMachine(presence.machine, machineProps);
18
+ const api = computed(() => presence.connect(service, normalizeProps$1));
19
+ watch(() => api.value.present, () => {
20
+ if (api.value.present) wasEverPresent.value = true;
21
+ });
22
+ watch(nodeRef, () => {
23
+ if (nodeRef.value) {
24
+ const node = nodeRef.value.$el ? nodeRef.value.$el : nodeRef.value;
25
+ if (node) api.value.setNode(node);
26
+ }
27
+ });
28
+ return computed(() => {
29
+ const localProps = toValue(props);
30
+ return {
31
+ present: api.value.present,
32
+ unmounted: !api.value.present && !wasEverPresent.value && localProps.lazyMount || localProps?.unmountOnExit && !api.value?.present && wasEverPresent.value,
33
+ presenceProps: {
34
+ ref: nodeRef,
35
+ hidden: !api.value.present,
36
+ "data-state": api.value.skip && localProps.skipAnimationOnMount ? void 0 : localProps?.present ? "open" : "closed"
37
+ }
38
+ };
39
+ });
40
+ };
41
+
42
+ //#endregion
43
+ //#region src/components/presence/use-presence-context.ts
44
+ const [PresenceProvider, usePresenceContext] = createContext("PresenceContext");
45
+
46
+ //#endregion
47
+ //#region src/components/presence/presence.vue?vue&type=script&setup=true&lang.ts
48
+ var presence_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
49
+ __name: "presence",
50
+ props: /* @__PURE__ */ mergeDefaults({
51
+ immediate: {
52
+ type: Boolean,
53
+ required: false
54
+ },
55
+ lazyMount: {
56
+ type: Boolean,
57
+ required: false
58
+ },
59
+ present: {
60
+ type: Boolean,
61
+ required: false
62
+ },
63
+ skipAnimationOnMount: {
64
+ type: Boolean,
65
+ required: false
66
+ },
67
+ unmountOnExit: {
68
+ type: Boolean,
69
+ required: false
70
+ },
71
+ asChild: {
72
+ type: Boolean,
73
+ required: false
74
+ }
75
+ }, {
76
+ immediate: void 0,
77
+ lazyMount: void 0,
78
+ present: void 0,
79
+ skipAnimationOnMount: void 0,
80
+ unmountOnExit: void 0
81
+ }),
82
+ emits: ["exitComplete"],
83
+ setup(__props, { emit: __emit }) {
84
+ const presence = usePresence(__props, __emit);
85
+ PresenceProvider(presence);
86
+ useForwardExpose();
87
+ return (_ctx, _cache) => {
88
+ return !unref(presence).unmounted ? (openBlock(), createBlock(unref(sprawlify).div, mergeProps({ key: 0 }, unref(presence).presenceProps, {
89
+ "as-child": __props.asChild,
90
+ "data-scope": "presence",
91
+ "data-part": "root"
92
+ }), {
93
+ default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
94
+ _: 3
95
+ }, 16, ["as-child"])) : createCommentVNode("v-if", true);
96
+ };
97
+ }
98
+ });
99
+
100
+ //#endregion
101
+ //#region src/components/presence/presence.vue
102
+ var presence_default = presence_vue_vue_type_script_setup_true_lang_default;
103
+
104
+ //#endregion
105
+ export { usePresence as i, PresenceProvider as n, usePresenceContext as r, presence_default as t };
@@ -0,0 +1,13 @@
1
+ //#region src/components/presence/presence-types.d.ts
2
+ interface RootProps {
3
+ immediate?: boolean;
4
+ lazyMount?: boolean;
5
+ present?: boolean;
6
+ skipAnimationOnMount?: boolean;
7
+ unmountOnExit?: boolean;
8
+ }
9
+ type RootEmits = {
10
+ exitComplete: [];
11
+ };
12
+ //#endregion
13
+ export { RootProps as n, RootEmits as t };