@vizejs/composable 0.809.0 → 0.811.0
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/abort-signal.mjs +0 -62
- package/dist/active-element.mjs +0 -11
- package/dist/animate.mjs +0 -19
- package/dist/async-resource.mjs +0 -17
- package/dist/battery.mjs +0 -13
- package/dist/breakpoints.mjs +0 -24
- package/dist/capability.mjs +0 -12
- package/dist/{catalog-BRX-Wg8B.mjs → catalog-CcpCnLjb.mjs} +0 -14
- package/dist/catalog.mjs +1 -1
- package/dist/color-mode.mjs +0 -23
- package/dist/computed-with-control.mjs +0 -22
- package/dist/create-event-hook.mjs +0 -27
- package/dist/create-global-state.mjs +0 -23
- package/dist/create-shared-composable.mjs +0 -23
- package/dist/device-motion.mjs +0 -11
- package/dist/device-orientation.mjs +0 -23
- package/dist/device-pixel-ratio.mjs +0 -11
- package/dist/disposal-scope.mjs +0 -25
- package/dist/document-visibility.mjs +0 -14
- package/dist/draggable.mjs +0 -14
- package/dist/element-bounding.mjs +0 -14
- package/dist/element-by-point.mjs +0 -10
- package/dist/element-hover.mjs +0 -13
- package/dist/element-target.mjs +0 -30
- package/dist/focus.mjs +0 -23
- package/dist/fps.mjs +0 -12
- package/dist/geolocation.mjs +0 -14
- package/dist/i18n.mjs +0 -86
- package/dist/icu-message.mjs +0 -58
- package/dist/idle.mjs +0 -16
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/infinite-scroll.mjs +0 -16
- package/dist/intersection-observer.mjs +0 -27
- package/dist/locale.mjs +0 -20
- package/dist/magic-keys.mjs +0 -35
- package/dist/math.mjs +0 -37
- package/dist/media-query.mjs +0 -29
- package/dist/mouse-in-element.mjs +0 -12
- package/dist/mouse.mjs +0 -12
- package/dist/mutation-observer.mjs +0 -15
- package/dist/network.mjs +0 -24
- package/dist/on-click-outside.mjs +0 -16
- package/dist/on-key-stroke.mjs +0 -33
- package/dist/on-long-press.mjs +0 -14
- package/dist/on-start-typing.mjs +0 -23
- package/dist/page-leave.mjs +0 -11
- package/dist/parent-element.mjs +0 -9
- package/dist/pinch.mjs +0 -14
- package/dist/pointer-lock.mjs +0 -23
- package/dist/pointer.mjs +0 -18
- package/dist/preferences.mjs +0 -31
- package/dist/preferred-languages.mjs +0 -13
- package/dist/ref-auto-reset.mjs +0 -24
- package/dist/ref-debounced.mjs +0 -22
- package/dist/ref-default.mjs +0 -21
- package/dist/resize-observer.mjs +0 -31
- package/dist/resolver.mjs +1 -58
- package/dist/retry-async.mjs +0 -25
- package/dist/retry-delay.mjs +0 -23
- package/dist/scope.mjs +0 -14
- package/dist/screen-orientation.mjs +0 -15
- package/dist/scroll-lock.mjs +0 -14
- package/dist/scroll.mjs +0 -27
- package/dist/standard-schema.mjs +0 -31
- package/dist/swipe.mjs +0 -36
- package/dist/temporal.mjs +0 -30
- package/dist/text-selection.mjs +0 -15
- package/dist/textarea-autosize.mjs +0 -13
- package/dist/to-reactive.mjs +0 -20
- package/dist/transition.mjs +0 -7
- package/dist/until.mjs +0 -25
- package/dist/use-array.mjs +0 -52
- package/dist/use-barcode-detector.mjs +0 -25
- package/dist/use-bluetooth.mjs +0 -27
- package/dist/use-broadcast-channel.mjs +0 -30
- package/dist/use-builtin-ai.mjs +0 -68
- package/dist/use-clipboard.mjs +0 -27
- package/dist/use-compression-stream.mjs +0 -78
- package/dist/use-contact-picker.mjs +0 -22
- package/dist/use-cookie.mjs +0 -63
- package/dist/use-countdown.mjs +0 -22
- package/dist/use-counter.mjs +0 -29
- package/dist/use-css-var.mjs +0 -28
- package/dist/use-date-format.mjs +0 -48
- package/dist/use-date-time-format.mjs +0 -22
- package/dist/use-debounced.mjs +0 -39
- package/dist/use-display-media.mjs +0 -22
- package/dist/use-display-names.mjs +0 -19
- package/dist/use-document-title.mjs +0 -25
- package/dist/use-drop-zone.mjs +0 -36
- package/dist/use-event-source.mjs +0 -25
- package/dist/use-eye-dropper.mjs +0 -19
- package/dist/use-favicon.mjs +0 -23
- package/dist/use-fetch.mjs +0 -27
- package/dist/use-field.mjs +0 -27
- package/dist/use-file-dialog.mjs +0 -21
- package/dist/{use-form-C2JXZ0i7.mjs → use-form-BZqwMs6k.mjs} +143 -70
- package/dist/use-form-field-props.mjs +0 -57
- package/dist/use-form.d.mts +123 -18
- package/dist/use-form.mjs +1 -1
- package/dist/use-fullscreen.mjs +0 -23
- package/dist/use-gamepad.mjs +0 -50
- package/dist/use-hid.mjs +0 -25
- package/dist/use-history.mjs +0 -43
- package/dist/use-id-generator.mjs +0 -21
- package/dist/use-image.mjs +0 -22
- package/dist/use-indexed-db.mjs +0 -39
- package/dist/use-interval.mjs +0 -28
- package/dist/use-list-format.mjs +0 -18
- package/dist/use-machine.mjs +0 -34
- package/dist/use-map.mjs +0 -28
- package/dist/use-media-controls.mjs +0 -28
- package/dist/use-mounted.mjs +0 -18
- package/dist/use-navigation-api.mjs +0 -27
- package/dist/use-notification.mjs +0 -24
- package/dist/use-number-format.mjs +0 -23
- package/dist/use-object-url.mjs +0 -22
- package/dist/use-offset-pagination.mjs +0 -18
- package/dist/use-payment-request.mjs +0 -25
- package/dist/use-performance-observer.mjs +0 -27
- package/dist/use-permission.mjs +0 -26
- package/dist/use-plural-rules.mjs +0 -21
- package/dist/use-push-subscription.mjs +0 -28
- package/dist/use-queue.mjs +0 -29
- package/dist/use-raf-fn.mjs +0 -23
- package/dist/use-relative-time-format.mjs +0 -35
- package/dist/use-request-idle-callback.mjs +0 -42
- package/dist/use-route-query.mjs +0 -17
- package/dist/use-scheduler-post-task.mjs +0 -27
- package/dist/use-screen-details.mjs +0 -42
- package/dist/use-script-tag.mjs +0 -28
- package/dist/use-segmenter.mjs +0 -20
- package/dist/use-serial.mjs +0 -24
- package/dist/use-service-worker.mjs +0 -27
- package/dist/use-set.mjs +0 -23
- package/dist/use-share.mjs +0 -23
- package/dist/use-sorted-locale.mjs +0 -20
- package/dist/use-speech-recognition.mjs +0 -24
- package/dist/use-speech-synthesis.mjs +0 -26
- package/dist/use-stack.mjs +0 -27
- package/dist/use-storage-estimate.mjs +0 -41
- package/dist/use-storage.mjs +0 -68
- package/dist/use-style-tag.mjs +0 -22
- package/dist/use-supported.mjs +0 -17
- package/dist/use-throttled.mjs +0 -46
- package/dist/use-time-ago.mjs +0 -22
- package/dist/use-toggle.mjs +0 -19
- package/dist/use-url-hash.mjs +0 -28
- package/dist/use-url-search-params.mjs +0 -99
- package/dist/use-usb.mjs +0 -23
- package/dist/use-user-activation.mjs +0 -22
- package/dist/use-user-media.mjs +0 -50
- package/dist/use-vibrate.mjs +0 -21
- package/dist/use-view-transition.mjs +0 -22
- package/dist/use-visual-viewport.mjs +0 -25
- package/dist/use-wake-lock.mjs +0 -21
- package/dist/use-web-authn.mjs +0 -61
- package/dist/use-web-locks.mjs +0 -25
- package/dist/use-web-midi.mjs +0 -22
- package/dist/use-web-vitals.mjs +0 -41
- package/dist/use-websocket.mjs +0 -27
- package/dist/use-worker-fn.mjs +0 -37
- package/dist/virtual-list.mjs +0 -14
- package/dist/whenever.mjs +0 -21
- package/dist/window-size.mjs +0 -12
- package/package.json +2 -2
- package/registry/files/form-control-types.ts +260 -0
- package/registry/files/form-dirty.ts +131 -0
- package/registry/files/form-options.ts +156 -0
- package/registry/files/form-path-types.ts +135 -0
- package/registry/files/use-form.ts +102 -449
- package/registry/registry.json +28 -4
package/dist/use-form.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { d as StandardSchemaV1 } from "./standard-schema-DmNgFVK5.mjs";
|
|
2
|
-
import { ComputedRef, Ref, ShallowRef, WritableComputedRef } from "vue";
|
|
2
|
+
import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef, WritableComputedRef } from "vue";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/form-path-types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Path and error types for {@link useForm}.
|
|
7
|
+
*
|
|
8
|
+
* Paths are template-literal keys, bounded at eight levels so type checking
|
|
9
|
+
* stays fast. Leaves stop the walk.
|
|
10
|
+
*/
|
|
5
11
|
/** Values treated as leaves: paths never descend into them. */
|
|
6
12
|
type FormLeaf = string | number | bigint | boolean | symbol | null | undefined | Date | RegExp | Blob | Map<unknown, unknown> | Set<unknown> | ((...arguments_: never[]) => unknown);
|
|
7
13
|
type Decrement = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
@@ -15,7 +21,7 @@ type Decrement = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
|
15
21
|
type FormPath<Values, Depth extends number = 8> = [Depth] extends [never] ? never : Values extends FormLeaf ? never : Values extends readonly (infer Item)[] ? `${number}` | `${number}.${FormPath<Item, Decrement[Depth]>}` : { [Key in keyof Values & string]: Key | (FormPath<Values[Key], Decrement[Depth]> extends infer Rest extends string ? [Rest] extends [never] ? never : `${Key}.${Rest}` : never) }[keyof Values & string];
|
|
16
22
|
/** Value type found at `Path` inside `Values`. */
|
|
17
23
|
type FormPathValue<Values, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Values extends readonly (infer Item)[] ? Head extends `${number}` ? FormPathValue<Item, Rest> : never : Head extends keyof Values ? FormPathValue<Values[Head], Rest> : never : Values extends readonly (infer Item)[] ? Path extends `${number}` ? Item : never : Path extends keyof Values ? Values[Path] : never;
|
|
18
|
-
/** Paths whose value is an array (usable with
|
|
24
|
+
/** Paths whose value is an array (usable with field arrays). */
|
|
19
25
|
type FormArrayPath<Values> = { [Path in FormPath<Values>]: FormPathValue<Values, Path> extends readonly unknown[] ? Path : never }[FormPath<Values>];
|
|
20
26
|
/** Item type of the array at `Path`. */
|
|
21
27
|
type FormArrayItem<Values, Path extends string> = FormPathValue<Values, Path> extends readonly (infer Item)[] ? Item : never;
|
|
@@ -49,19 +55,32 @@ type FormValidator<Values> = (values: Values, context: {
|
|
|
49
55
|
}) => FormErrors<Values> | undefined | void | Promise<FormErrors<Values> | undefined | void>;
|
|
50
56
|
/** Per-field validators keyed by path. */
|
|
51
57
|
type FormFieldValidators<Values> = { readonly [Path in FormPath<Values>]?: FieldValidator<FormPathValue<Values, Path>, Values> };
|
|
58
|
+
/** One dirty branch: `true` for a leaf, or a nested map when children differ. */
|
|
59
|
+
type DirtyNode<Values> = true | DirtyFields<Values>;
|
|
60
|
+
/**
|
|
61
|
+
* Nested dirty flags against the initial values.
|
|
62
|
+
*
|
|
63
|
+
* A dirty leaf is `true`. Clean branches are omitted. Array indexes stay
|
|
64
|
+
* aligned with the value, and a clean item is `undefined`.
|
|
65
|
+
*/
|
|
66
|
+
type DirtyFields<Values> = Values extends FormLeaf ? true : Values extends readonly (infer Item)[] ? readonly (DirtyNode<Item> | undefined)[] : Values extends object ? { readonly [Key in keyof Values]?: DirtyNode<Values[Key]> } : true;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/form-options.d.ts
|
|
52
69
|
/** When validation runs automatically. */
|
|
53
70
|
type FormValidationTrigger = "change" | "blur" | "submit";
|
|
54
|
-
/**
|
|
71
|
+
/** How many messages each path keeps after validation. */
|
|
72
|
+
type FormCriteriaMode = "all" | "first";
|
|
73
|
+
/** Discriminated outcome of validation and submission. */
|
|
55
74
|
type FormResult<Output> = {
|
|
56
75
|
/** Every validator passed. */readonly status: "valid"; /** Schema output, or the values when no schema is configured. */
|
|
57
76
|
readonly value: Output;
|
|
58
77
|
} | {
|
|
59
78
|
/** At least one validator failed. */readonly status: "invalid"; /** Errors keyed by path. */
|
|
60
|
-
readonly errors:
|
|
79
|
+
readonly errors: Readonly<Record<string, readonly string[]>>;
|
|
61
80
|
} | {
|
|
62
81
|
/** A newer validation started before this one finished. */readonly status: "superseded";
|
|
63
82
|
};
|
|
64
|
-
/** Options for
|
|
83
|
+
/** Options for `useForm`. */
|
|
65
84
|
interface UseFormOptions<Values extends object, Output> {
|
|
66
85
|
/** Initial values, or a factory producing fresh initial values. */
|
|
67
86
|
readonly initialValues: Values | (() => Values);
|
|
@@ -97,7 +116,21 @@ interface UseFormOptions<Values extends object, Output> {
|
|
|
97
116
|
*/
|
|
98
117
|
readonly revalidateOn?: FormValidationTrigger;
|
|
99
118
|
/**
|
|
100
|
-
*
|
|
119
|
+
* `"all"` records every message. `"first"` keeps the earliest message in
|
|
120
|
+
* source order: schema, then the form validator, then the field validator.
|
|
121
|
+
*
|
|
122
|
+
* @default "all"
|
|
123
|
+
*/
|
|
124
|
+
readonly criteriaMode?: FormCriteriaMode;
|
|
125
|
+
/**
|
|
126
|
+
* When true, value writes, field-array edits, and submission do nothing.
|
|
127
|
+
* `setError`, `setErrors`, and `reset` still run. A ref or getter tracks.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
readonly disabled?: MaybeRefOrGetter<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Default submit handler for `submit`.
|
|
101
134
|
*
|
|
102
135
|
* @default undefined
|
|
103
136
|
*/
|
|
@@ -105,7 +138,7 @@ interface UseFormOptions<Values extends object, Output> {
|
|
|
105
138
|
readonly signal: AbortSignal;
|
|
106
139
|
}) => unknown;
|
|
107
140
|
}
|
|
108
|
-
/** Options for
|
|
141
|
+
/** Options for `setValue`. */
|
|
109
142
|
interface SetFieldValueOptions {
|
|
110
143
|
/**
|
|
111
144
|
* Mark the field touched.
|
|
@@ -120,7 +153,45 @@ interface SetFieldValueOptions {
|
|
|
120
153
|
*/
|
|
121
154
|
readonly validate?: boolean;
|
|
122
155
|
}
|
|
123
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* What {@link FormControls.reset} retains. Every omitted flag clears that state.
|
|
158
|
+
*/
|
|
159
|
+
interface FormResetOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Keep values that differ from the previous initial values. Clean fields
|
|
162
|
+
* take the reset values. Added keys stay, and removed keys stay removed.
|
|
163
|
+
*
|
|
164
|
+
* @default false
|
|
165
|
+
*/
|
|
166
|
+
readonly keepDirtyValues?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Keep the current errors.
|
|
169
|
+
*
|
|
170
|
+
* @default false
|
|
171
|
+
*/
|
|
172
|
+
readonly keepErrors?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Keep touched fields.
|
|
175
|
+
*
|
|
176
|
+
* @default false
|
|
177
|
+
*/
|
|
178
|
+
readonly keepTouched?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Keep the submit count.
|
|
181
|
+
*
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
readonly keepSubmitCount?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Keep whether the latest finished submit succeeded.
|
|
187
|
+
*
|
|
188
|
+
* @default false
|
|
189
|
+
*/
|
|
190
|
+
readonly keepIsSubmitSuccessful?: boolean;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/form-control-types.d.ts
|
|
194
|
+
/** Reactive controls for one field, returned by `field`. */
|
|
124
195
|
interface FormFieldControls<Value, Path extends string = string> {
|
|
125
196
|
/** Dotted path of the field (also a suitable `name` attribute). */
|
|
126
197
|
readonly path: Path;
|
|
@@ -158,7 +229,7 @@ interface FormArrayEntry<Item, Path extends string = string> {
|
|
|
158
229
|
/** Current item value. */
|
|
159
230
|
readonly value: Item;
|
|
160
231
|
}
|
|
161
|
-
/** Typed operations on an array field, returned by
|
|
232
|
+
/** Typed operations on an array field, returned by `fieldArray`. */
|
|
162
233
|
interface FormFieldArrayControls<Item, Path extends string = string> {
|
|
163
234
|
/** Entries with stable keys. */
|
|
164
235
|
readonly entries: ComputedRef<readonly FormArrayEntry<Item, Path>[]>;
|
|
@@ -177,7 +248,7 @@ interface FormFieldArrayControls<Item, Path extends string = string> {
|
|
|
177
248
|
/** Replace all items and reset their state. */
|
|
178
249
|
readonly replace: (items: readonly Item[]) => void;
|
|
179
250
|
}
|
|
180
|
-
/** Reactive state and actions returned by
|
|
251
|
+
/** Reactive state and actions returned by `useForm`. */
|
|
181
252
|
interface FormControls<Values extends object, Output> {
|
|
182
253
|
/** Current values. Mutations are tracked (dirty state derives from them). */
|
|
183
254
|
readonly values: Ref<Values>;
|
|
@@ -187,12 +258,21 @@ interface FormControls<Values extends object, Output> {
|
|
|
187
258
|
readonly valid: ComputedRef<boolean>;
|
|
188
259
|
/** Whether any value differs from its initial value. */
|
|
189
260
|
readonly dirty: ComputedRef<boolean>;
|
|
261
|
+
/** Nested flags for values that differ from the initial values. */
|
|
262
|
+
readonly dirtyFields: ComputedRef<DirtyFields<Values>>;
|
|
190
263
|
/** Whether any validation is pending. */
|
|
191
264
|
readonly validating: ComputedRef<boolean>;
|
|
192
265
|
/** Whether a submission is in progress. */
|
|
193
266
|
readonly submitting: Readonly<Ref<boolean>>;
|
|
194
|
-
/** Number of submit attempts. */
|
|
267
|
+
/** Number of submit attempts. Disabled submits are not counted. */
|
|
195
268
|
readonly submitCount: Readonly<Ref<number>>;
|
|
269
|
+
/**
|
|
270
|
+
* Whether the latest finished submit was valid and its handler settled.
|
|
271
|
+
* A superseded submit leaves this flag unchanged.
|
|
272
|
+
*/
|
|
273
|
+
readonly isSubmitSuccessful: Readonly<Ref<boolean>>;
|
|
274
|
+
/** Whether value writes, field-array edits, and submission are ignored. */
|
|
275
|
+
readonly disabled: ComputedRef<boolean>;
|
|
196
276
|
/**
|
|
197
277
|
* Typed controls for one field.
|
|
198
278
|
*
|
|
@@ -215,7 +295,14 @@ interface FormControls<Values extends object, Output> {
|
|
|
215
295
|
*/
|
|
216
296
|
readonly getValue: <Path extends FormPath<Values>>(path: Path) => FormPathValue<Values, Path>;
|
|
217
297
|
/**
|
|
218
|
-
*
|
|
298
|
+
* Read a path as a computed ref that tracks later edits.
|
|
299
|
+
*
|
|
300
|
+
* @param path Dotted path.
|
|
301
|
+
* @returns The value at that path.
|
|
302
|
+
*/
|
|
303
|
+
readonly watch: <Path extends FormPath<Values>>(path: Path) => ComputedRef<FormPathValue<Values, Path>>;
|
|
304
|
+
/**
|
|
305
|
+
* Write the value at a path. Does nothing while `disabled` is true.
|
|
219
306
|
*
|
|
220
307
|
* @param path Dotted path.
|
|
221
308
|
* @param value New value.
|
|
@@ -224,6 +311,7 @@ interface FormControls<Values extends object, Output> {
|
|
|
224
311
|
readonly setValue: <Path extends FormPath<Values>>(path: Path, value: FormPathValue<Values, Path>, options?: SetFieldValueOptions) => void;
|
|
225
312
|
/**
|
|
226
313
|
* Replace (or shallowly merge) the values without touching initial values.
|
|
314
|
+
* Does nothing while `disabled` is true.
|
|
227
315
|
*
|
|
228
316
|
* @param values New values.
|
|
229
317
|
* @param options `merge: true` shallowly merges top-level keys.
|
|
@@ -244,6 +332,13 @@ interface FormControls<Values extends object, Output> {
|
|
|
244
332
|
* @param errors Errors keyed by path.
|
|
245
333
|
*/
|
|
246
334
|
readonly setErrors: (errors: FormErrors<Values>) => void;
|
|
335
|
+
/**
|
|
336
|
+
* Set one path's errors without replacing the others.
|
|
337
|
+
*
|
|
338
|
+
* @param path Dotted path. `""` is the form-level error.
|
|
339
|
+
* @param message Messages for that path. An empty result clears it.
|
|
340
|
+
*/
|
|
341
|
+
readonly setError: (path: FormPath<Values> | "", message: ValidatorResult) => void;
|
|
247
342
|
/**
|
|
248
343
|
* Clear errors of one path, or all errors.
|
|
249
344
|
*
|
|
@@ -258,7 +353,8 @@ interface FormControls<Values extends object, Output> {
|
|
|
258
353
|
readonly validate: () => Promise<FormResult<Output>>;
|
|
259
354
|
/**
|
|
260
355
|
* Validate and, when valid, call `handler` (or the `onSubmit` option).
|
|
261
|
-
* A newer submit aborts an older one's pending validation.
|
|
356
|
+
* A newer submit aborts an older one's pending validation. Does nothing
|
|
357
|
+
* while `disabled` is true.
|
|
262
358
|
*
|
|
263
359
|
* @param handler Submit handler overriding `onSubmit`.
|
|
264
360
|
* @returns The validation result.
|
|
@@ -276,12 +372,16 @@ interface FormControls<Values extends object, Output> {
|
|
|
276
372
|
readonly signal: AbortSignal;
|
|
277
373
|
}) => unknown) => (event?: Event) => Promise<FormResult<Output>>;
|
|
278
374
|
/**
|
|
279
|
-
* Restore initial values (or install new ones)
|
|
375
|
+
* Restore initial values (or install new ones). Omitted keep-flags clear
|
|
376
|
+
* that piece of state. Still runs while `disabled` is true.
|
|
280
377
|
*
|
|
281
378
|
* @param values New initial values.
|
|
379
|
+
* @param options State to retain.
|
|
282
380
|
*/
|
|
283
|
-
readonly reset: (values?: Values) => void;
|
|
381
|
+
readonly reset: (values?: Values, options?: FormResetOptions) => void;
|
|
284
382
|
}
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/use-form.d.ts
|
|
285
385
|
/**
|
|
286
386
|
* Fully typed form state with validation, field arrays, and submission.
|
|
287
387
|
*
|
|
@@ -292,7 +392,12 @@ interface FormControls<Values extends object, Output> {
|
|
|
292
392
|
* … via the `~standard` protocol), a whole-form validator, and per-field
|
|
293
393
|
* validators; all may be asynchronous. A newer validation aborts older ones
|
|
294
394
|
* through their `signal` and their results are discarded, so a slow check
|
|
295
|
-
* can never overwrite fresher errors.
|
|
395
|
+
* can never overwrite fresher errors. `criteriaMode: "first"` keeps one
|
|
396
|
+
* message per path, in source order: schema, form validator, field validator.
|
|
397
|
+
* `dirtyFields` mirrors edited branches, `watch` reads one path, and
|
|
398
|
+
* `setError` updates a single path. `disabled` ignores writes and submission.
|
|
399
|
+
* `reset` can keep dirty values, errors, touched fields, the submit count,
|
|
400
|
+
* or the success flag.
|
|
296
401
|
*
|
|
297
402
|
* This composable owns the *values*. `@vizejs/ui/form` owns accessible
|
|
298
403
|
* error presentation (error summaries, focus management, native constraint
|
|
@@ -321,4 +426,4 @@ interface FormControls<Values extends object, Output> {
|
|
|
321
426
|
*/
|
|
322
427
|
declare function useForm<Values extends object, Output = Values>(options: UseFormOptions<Values, Output>): FormControls<Values, Output>;
|
|
323
428
|
//#endregion
|
|
324
|
-
export { FieldValidator, FieldValidatorContext, FormArrayEntry, FormArrayItem, FormArrayPath, FormControls, FormErrorRecord, FormErrors, FormFieldArrayControls, FormFieldControls, FormFieldValidators, FormLeaf, FormPath, FormPathValue, FormResult, FormValidationTrigger, FormValidator, SetFieldValueOptions, UseFormOptions, ValidatorResult, useForm };
|
|
429
|
+
export { type DirtyFields, type DirtyNode, type FieldValidator, type FieldValidatorContext, type FormArrayEntry, type FormArrayItem, type FormArrayPath, type FormControls, type FormCriteriaMode, type FormErrorRecord, type FormErrors, type FormFieldArrayControls, type FormFieldControls, type FormFieldValidators, type FormLeaf, type FormPath, type FormPathValue, type FormResetOptions, type FormResult, type FormValidationTrigger, type FormValidator, type SetFieldValueOptions, type UseFormOptions, type ValidatorResult, useForm };
|
package/dist/use-form.mjs
CHANGED
package/dist/use-fullscreen.mjs
CHANGED
|
@@ -8,29 +8,6 @@ function browserFullscreenHost() {
|
|
|
8
8
|
function currentElement(host) {
|
|
9
9
|
return host.fullscreenElement ?? host.webkitFullscreenElement ?? null;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Enter, exit, and observe fullscreen for an element.
|
|
13
|
-
*
|
|
14
|
-
* Supports the standard Fullscreen API and the WebKit-prefixed variant.
|
|
15
|
-
* `isFullscreen` is true only while *this* target is the fullscreen element
|
|
16
|
-
* and follows `fullscreenchange`, so pressing Escape is reflected. Listeners
|
|
17
|
-
* are removed when the owning scope stops; with `autoExit` the target also
|
|
18
|
-
* leaves fullscreen then.
|
|
19
|
-
*
|
|
20
|
-
* Server rendering: `supported` and `isFullscreen` are false and nothing is
|
|
21
|
-
* requested.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const player = useTemplateRef<HTMLElement>("player");
|
|
26
|
-
* const { toggle, isFullscreen } = useFullscreen(player);
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param target Reactive element; defaults to the document element.
|
|
30
|
-
* @param options Capability, navigation UI, and exit policy.
|
|
31
|
-
* @default options {}
|
|
32
|
-
* @returns Fullscreen state and actions.
|
|
33
|
-
*/
|
|
34
11
|
function useFullscreen(target, options = {}) {
|
|
35
12
|
const isFullscreen = ref(false);
|
|
36
13
|
const resolveHost = () => options.host === void 0 ? browserFullscreenHost() : toValue(options.host) ?? void 0;
|
package/dist/use-gamepad.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { tryOnScopeDispose } from "./scope.mjs";
|
|
|
2
2
|
import { useRafFn } from "./use-raf-fn.mjs";
|
|
3
3
|
import { computed, hasInjectionContext, readonly, shallowReadonly, shallowRef, toValue, watch, watchPostEffect } from "vue";
|
|
4
4
|
//#region src/use-gamepad.ts
|
|
5
|
-
/** Button indices of the W3C "standard" gamepad mapping. */
|
|
6
5
|
const standardGamepadButtons = {
|
|
7
6
|
faceBottom: 0,
|
|
8
7
|
faceRight: 1,
|
|
@@ -22,7 +21,6 @@ const standardGamepadButtons = {
|
|
|
22
21
|
dpadRight: 15,
|
|
23
22
|
home: 16
|
|
24
23
|
};
|
|
25
|
-
/** Axis indices of the W3C "standard" gamepad mapping. */
|
|
26
24
|
const standardGamepadAxes = {
|
|
27
25
|
leftStickX: 0,
|
|
28
26
|
leftStickY: 1,
|
|
@@ -42,12 +40,6 @@ function isAxisBinding(binding) {
|
|
|
42
40
|
function checkIndex(index, key) {
|
|
43
41
|
if (!Number.isInteger(index) || index < 0) throw invalidMapping(`"${key}" index must be a non-negative integer; received ${index}`);
|
|
44
42
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Copy a live pad into an immutable {@link GamepadSnapshot}.
|
|
47
|
-
*
|
|
48
|
-
* @param pad Live `Gamepad` (or compatible) object.
|
|
49
|
-
* @returns The copied state.
|
|
50
|
-
*/
|
|
51
43
|
function snapshotGamepad(pad) {
|
|
52
44
|
return {
|
|
53
45
|
id: pad.id,
|
|
@@ -64,22 +56,6 @@ function snapshotGamepad(pad) {
|
|
|
64
56
|
vibration: pad.vibrationActuator != null
|
|
65
57
|
};
|
|
66
58
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Derive typed named state from a snapshot. Missing buttons read as released
|
|
69
|
-
* and missing axes as `0`; axis dead zones are applied and rescaled.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* const state = mapGamepad(pad, { jump: { button: 0 }, moveX: { axis: 0, deadzone: 0.1 } });
|
|
74
|
-
* state.jump.pressed; state.moveX; // boolean, number
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @param snapshot Copied pad state.
|
|
78
|
-
* @param mapping Named button and axis bindings.
|
|
79
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_GAMEPAD_INVALID_MAPPING` for a
|
|
80
|
-
* negative or fractional index or a dead zone outside `[0, 1)`.
|
|
81
|
-
* @returns State keyed like `mapping`.
|
|
82
|
-
*/
|
|
83
59
|
function mapGamepad(snapshot, mapping) {
|
|
84
60
|
const result = {};
|
|
85
61
|
for (const [key, binding] of Object.entries(mapping)) if (isAxisBinding(binding)) {
|
|
@@ -100,32 +76,6 @@ function mapGamepad(snapshot, mapping) {
|
|
|
100
76
|
}
|
|
101
77
|
return result;
|
|
102
78
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Track connected gamepads as immutable snapshots, polled on animation
|
|
105
|
-
* frames, with optional typed named bindings.
|
|
106
|
-
*
|
|
107
|
-
* Pads are re-read every frame while active and on `gamepadconnected` /
|
|
108
|
-
* `gamepaddisconnected`; `gamepads` is replaced only when a pad's timestamp
|
|
109
|
-
* or connection changed. Entries are plain copies, so they are safe to keep
|
|
110
|
-
* or serialize. The frame loop and listeners stop with the owning reactive
|
|
111
|
-
* scope; outside a scope call `pause()`.
|
|
112
|
-
*
|
|
113
|
-
* Server rendering: no frames or listeners, `supported` is false and
|
|
114
|
-
* `gamepads` is empty.
|
|
115
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
116
|
-
* renders this server state first.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* const { gamepads } = useGamepad({ mapping: { jump: { button: 0 }, moveX: { axis: 0, deadzone: 0.1 } } });
|
|
121
|
-
* const player = computed(() => gamepads.value[0]?.mapped);
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @param options Host, mapping, and scheduler.
|
|
125
|
-
* @default options {}
|
|
126
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_GAMEPAD_INVALID_MAPPING` for an invalid mapping.
|
|
127
|
-
* @returns Pad state and polling controls.
|
|
128
|
-
*/
|
|
129
79
|
function useGamepad(options = {}) {
|
|
130
80
|
const gamepads = shallowRef([]);
|
|
131
81
|
const error = shallowRef(void 0);
|
package/dist/use-hid.mjs
CHANGED
|
@@ -22,31 +22,6 @@ function describe(device) {
|
|
|
22
22
|
opened: device.opened
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Talk to human-interface devices with the WebHID API.
|
|
27
|
-
*
|
|
28
|
-
* `devices` lists granted devices as plain snapshots and follows the host's
|
|
29
|
-
* `connect` / `disconnect` events. Devices opened through `open()` forward
|
|
30
|
-
* `inputreport` events to `onInputReport`. Every action resolves to a
|
|
31
|
-
* boolean or value and records failures in `error`. Report listeners are
|
|
32
|
-
* removed and opened devices closed when the owning reactive scope stops;
|
|
33
|
-
* outside a scope call `close()` per device.
|
|
34
|
-
*
|
|
35
|
-
* Server rendering: `supported` is false and `devices` is empty.
|
|
36
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
37
|
-
* renders this server state first.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const hid = useHID({ onInputReport: ({ reportId, data }) => read(reportId, data) });
|
|
42
|
-
* const [device] = await hid.requestDevice([{ vendorId: 0x054c }]);
|
|
43
|
-
* if (device) await hid.open(device);
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @param options Host and input report callback.
|
|
47
|
-
* @default options {}
|
|
48
|
-
* @returns HID state and actions.
|
|
49
|
-
*/
|
|
50
25
|
function useHID(options = {}) {
|
|
51
26
|
const devices = shallowRef([]);
|
|
52
27
|
const error = shallowRef(void 0);
|
package/dist/use-history.mjs
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
1
|
import { tryOnScopeDispose } from "./scope.mjs";
|
|
2
2
|
import { computed, shallowRef, watch } from "vue";
|
|
3
3
|
//#region src/use-history.ts
|
|
4
|
-
/**
|
|
5
|
-
* Record bounded undo/redo history over the writes of a ref.
|
|
6
|
-
*
|
|
7
|
-
* Recording is shallow and identity-based, matching Vue's own change
|
|
8
|
-
* detection: assignments to `source.value` are recorded (observed with
|
|
9
|
-
* `flush: "sync"`, so every synchronous write counts), writes that are
|
|
10
|
-
* `Object.is`-equal to the current value are not changes, and in-place
|
|
11
|
-
* mutations of object values are invisible — pair mutable values with
|
|
12
|
-
* {@link UseHistoryOptions.clone} and reassign. Undoing and redoing restore
|
|
13
|
-
* values through `clone` as well, so snapshots never share identity with the
|
|
14
|
-
* live value unless the default identity clone is kept. When a
|
|
15
|
-
* user-provided `clone` throws, the failed operation leaves history
|
|
16
|
-
* unchanged and the error propagates.
|
|
17
|
-
*
|
|
18
|
-
* Safe during server rendering: no browser globals are read and no timers
|
|
19
|
-
* start. Cleanup rule: when the owning reactive scope stops, recording stops
|
|
20
|
-
* and every retained snapshot is released, so `undo`/`redo` return `false`
|
|
21
|
-
* afterwards; call inside an active scope, or the watcher lives as long as
|
|
22
|
-
* the source.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const text = shallowRef("");
|
|
27
|
-
* const { undo, redo, batch } = useHistory(text);
|
|
28
|
-
* text.value = "a";
|
|
29
|
-
* batch(() => {
|
|
30
|
-
* text.value = "ab";
|
|
31
|
-
* text.value = "abc";
|
|
32
|
-
* });
|
|
33
|
-
* undo(); // text.value === "a" (the batch is one step)
|
|
34
|
-
* redo(); // text.value === "abc"
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param source Ref whose writes are recorded.
|
|
38
|
-
* @param options Retention bound and snapshot cloning.
|
|
39
|
-
* @default options {}
|
|
40
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_HISTORY_INVALID_CAPACITY` when
|
|
41
|
-
* the capacity is not an integer greater than zero.
|
|
42
|
-
* @throws `Error` tagged `VIZE_COMPOSE_HISTORY_IN_BATCH` when `undo`,
|
|
43
|
-
* `redo`, or `clear` is called inside {@link HistoryControls.batch}, where
|
|
44
|
-
* stack movement would corrupt the pending group.
|
|
45
|
-
* @returns Reactive undo/redo state and controls.
|
|
46
|
-
*/
|
|
47
4
|
function useHistory(source, options = {}) {
|
|
48
5
|
const capacity = options.capacity ?? 100;
|
|
49
6
|
if (!Number.isInteger(capacity) || capacity < 1) throw new RangeError(`[VIZE_COMPOSE_HISTORY_INVALID_CAPACITY] capacity must be an integer greater than zero; received ${String(capacity)}`);
|
|
@@ -3,27 +3,6 @@ import { hasInjectionContext, useId } from "vue";
|
|
|
3
3
|
function sanitize(part) {
|
|
4
4
|
return part.replaceAll(/[^\w-]/g, "-");
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Create an SSR-stable id factory for one component.
|
|
8
|
-
*
|
|
9
|
-
* Each call to the returned function yields
|
|
10
|
-
* `<prefix>-<seed>-<hint>-<n>` with a per-generator counter, so as long as
|
|
11
|
-
* ids are generated in the same order on the server and the client (for
|
|
12
|
-
* example during `setup`), the markup hydrates without mismatches. The seed
|
|
13
|
-
* comes from Vue's `useId()` inside components, which is itself stable across
|
|
14
|
-
* SSR and hydration; outside components pass an explicit `seed`. Characters
|
|
15
|
-
* outside `[A-Za-z0-9_-]` are replaced so ids are valid in selectors.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const nextId = useIdGenerator({ prefix: "field" });
|
|
20
|
-
* const inputId = nextId("input"); // "field-v-0-input-0"
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param options Prefix and seed.
|
|
24
|
-
* @default options {}
|
|
25
|
-
* @returns The id factory.
|
|
26
|
-
*/
|
|
27
6
|
function useIdGenerator(options = {}) {
|
|
28
7
|
const seed = options.seed ?? (hasInjectionContext() ? useId() : "root");
|
|
29
8
|
const base = `${sanitize(options.prefix ?? "vize")}-${sanitize(seed)}`;
|
package/dist/use-image.mjs
CHANGED
|
@@ -17,28 +17,6 @@ function applySource(image, source) {
|
|
|
17
17
|
if (source.srcset !== void 0) image.srcset = source.srcset;
|
|
18
18
|
image.src = source.src;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Preload an image and track its loading state.
|
|
22
|
-
*
|
|
23
|
-
* A detached image is created for every source; the newest load wins, and
|
|
24
|
-
* superseded images have their listeners removed and their `src` cleared so
|
|
25
|
-
* the browser can abort the download. Use it to show a placeholder until
|
|
26
|
-
* the real image is decoded, or to validate URLs before rendering them.
|
|
27
|
-
*
|
|
28
|
-
* Server rendering: no image is created and `status` stays `"idle"`. The
|
|
29
|
-
* pending load is cancelled when the owning reactive scope stops.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* const { ready } = useImage(() => ({ src: avatarUrl.value }));
|
|
34
|
-
* // <img v-if="ready" :src="avatarUrl"> <Skeleton v-else />
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param source Reactive image attributes.
|
|
38
|
-
* @param options Timing and capability.
|
|
39
|
-
* @default options {}
|
|
40
|
-
* @returns Image state and actions.
|
|
41
|
-
*/
|
|
42
20
|
function useImage(source, options = {}) {
|
|
43
21
|
const status = ref("idle");
|
|
44
22
|
const image = shallowRef(void 0);
|
package/dist/use-indexed-db.mjs
CHANGED
|
@@ -34,17 +34,6 @@ function openDatabase(factory, name, store, version) {
|
|
|
34
34
|
return openDatabase(factory, name, store, next);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a small promise-based key-value store on one IndexedDB object
|
|
39
|
-
* store. The connection opens lazily on the first operation, the store is
|
|
40
|
-
* created on demand, and writes resolve once their transaction commits.
|
|
41
|
-
* Without IndexedDB (server rendering, privacy modes) every operation
|
|
42
|
-
* rejects with a tagged `[VIZE_COMPOSE_INDEXED_DB_UNAVAILABLE]` error.
|
|
43
|
-
*
|
|
44
|
-
* @param options Database, store, and implementation.
|
|
45
|
-
* @default options {}
|
|
46
|
-
* @returns Key-value operations.
|
|
47
|
-
*/
|
|
48
37
|
function createIndexedDBKeyval(options = {}) {
|
|
49
38
|
const name = options.database ?? "vize-keyval";
|
|
50
39
|
const store = options.store ?? "keyval";
|
|
@@ -91,34 +80,6 @@ function sameKind(defaults, candidate) {
|
|
|
91
80
|
if (typeof defaults === "object") return typeof candidate === "object" && candidate !== null && !Array.isArray(candidate);
|
|
92
81
|
return typeof candidate === typeof defaults;
|
|
93
82
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Synchronize a reactive value with one IndexedDB key.
|
|
96
|
-
*
|
|
97
|
-
* Values are stored by structured clone, so objects, arrays, `Map`, `Set`,
|
|
98
|
-
* `Date`, typed arrays, and `Blob`s round-trip without a serializer. The
|
|
99
|
-
* value is loaded asynchronously: `state` holds the default until `ready`
|
|
100
|
-
* becomes `true`. Loaded values pass `validate` before they are accepted.
|
|
101
|
-
* Assignments and nested mutations are written back; changing the reactive
|
|
102
|
-
* `key` loads the new key (stale loads are discarded).
|
|
103
|
-
*
|
|
104
|
-
* Server rendering: without a browser `window` nothing is opened, `state`
|
|
105
|
-
* is the default, and `ready` stays `false`, so server and client first
|
|
106
|
-
* render identically. The connection closes and watchers stop with the
|
|
107
|
-
* owning reactive scope. Failures never reject; they are exposed through
|
|
108
|
-
* `error` and `onError`.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* const { state: draft, ready } = useIndexedDB("draft", { title: "", body: "" });
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* @typeParam Value Stored value type, inferred from `defaultValue`.
|
|
116
|
-
* @param key Reactive IndexedDB key.
|
|
117
|
-
* @param defaultValue Value used until loaded, and when absent or invalid.
|
|
118
|
-
* @param options Database, store, implementation, and validation.
|
|
119
|
-
* @default options {}
|
|
120
|
-
* @returns The synchronized value and its controls.
|
|
121
|
-
*/
|
|
122
83
|
function useIndexedDB(key, defaultValue, options = {}) {
|
|
123
84
|
const state = ref(defaultValue);
|
|
124
85
|
const supported = ref(false);
|
package/dist/use-interval.mjs
CHANGED
|
@@ -11,34 +11,6 @@ function resolveIntervalMs(value) {
|
|
|
11
11
|
if (!Number.isFinite(value) || value <= 0) throw new RangeError(`[VIZE_COMPOSE_INTERVAL_INVALID_DELAY] intervalMs must be finite and greater than zero; received ${String(value)}`);
|
|
12
12
|
return Math.max(1, Math.trunc(value));
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Call a function on a fixed, pausable interval.
|
|
16
|
-
*
|
|
17
|
-
* `intervalMs` is reactive: while active, a change replaces the running timer
|
|
18
|
-
* with one using the new period. The timer is cleared when the owning
|
|
19
|
-
* reactive scope stops; call inside an active scope, or call `pause()`
|
|
20
|
-
* yourself.
|
|
21
|
-
*
|
|
22
|
-
* Server rendering is hydration-stable: without a browser `window` (and
|
|
23
|
-
* with {@link UseIntervalFnOptions.runOnServer} disabled) `isActive` reports
|
|
24
|
-
* the requested state but no host timer is created, so nothing leaks and
|
|
25
|
-
* the server snapshot matches the client's initial render.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const { pause, resume, isActive } = useIntervalFn(() => poll(), 5_000);
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @param callback Invoked on every tick.
|
|
33
|
-
* @param intervalMs Reactive period in milliseconds; must be finite and
|
|
34
|
-
* greater than zero. Fractions are truncated.
|
|
35
|
-
* @param options Start, server, and scheduler policy.
|
|
36
|
-
* @default options {}
|
|
37
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_INTERVAL_INVALID_DELAY` when the
|
|
38
|
-
* resolved period is invalid, synchronously at creation and whenever a timer
|
|
39
|
-
* would start.
|
|
40
|
-
* @returns Pause/resume controls.
|
|
41
|
-
*/
|
|
42
14
|
function useIntervalFn(callback, intervalMs, options = {}) {
|
|
43
15
|
const scheduler = options.scheduler ?? defaultScheduler;
|
|
44
16
|
const isActive = shallowRef(false);
|
package/dist/use-list-format.mjs
CHANGED
|
@@ -4,24 +4,6 @@ import { computed, toValue } from "vue";
|
|
|
4
4
|
function browserLanguage() {
|
|
5
5
|
return typeof window === "undefined" ? void 0 : window.navigator.language;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Join strings into a locale-aware list with `Intl.ListFormat`
|
|
9
|
-
* (`"a, b, and c"`, `"a、b、c"`, `"a, b or c"`).
|
|
10
|
-
*
|
|
11
|
-
* Follows reactive items and options; formatters are cached per locale and
|
|
12
|
-
* option set through {@link useLocale}. Invalid options surface as the
|
|
13
|
-
* platform's `RangeError`. No listeners or timers are created.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const { formatted } = useListFormat(names, { locale: "en", type: "disjunction" });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param items Reactive list of strings.
|
|
21
|
-
* @param options Reactive locale and `Intl.ListFormat` options.
|
|
22
|
-
* @default options {}
|
|
23
|
-
* @returns Reactive formatted output and formatting helpers.
|
|
24
|
-
*/
|
|
25
7
|
function useListFormat(items, options = {}) {
|
|
26
8
|
const localeControls = useLocale(() => toValue(options).locale, { detect: browserLanguage });
|
|
27
9
|
const formatter = computed(() => {
|