@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.
Files changed (173) hide show
  1. package/dist/abort-signal.mjs +0 -62
  2. package/dist/active-element.mjs +0 -11
  3. package/dist/animate.mjs +0 -19
  4. package/dist/async-resource.mjs +0 -17
  5. package/dist/battery.mjs +0 -13
  6. package/dist/breakpoints.mjs +0 -24
  7. package/dist/capability.mjs +0 -12
  8. package/dist/{catalog-BRX-Wg8B.mjs → catalog-CcpCnLjb.mjs} +0 -14
  9. package/dist/catalog.mjs +1 -1
  10. package/dist/color-mode.mjs +0 -23
  11. package/dist/computed-with-control.mjs +0 -22
  12. package/dist/create-event-hook.mjs +0 -27
  13. package/dist/create-global-state.mjs +0 -23
  14. package/dist/create-shared-composable.mjs +0 -23
  15. package/dist/device-motion.mjs +0 -11
  16. package/dist/device-orientation.mjs +0 -23
  17. package/dist/device-pixel-ratio.mjs +0 -11
  18. package/dist/disposal-scope.mjs +0 -25
  19. package/dist/document-visibility.mjs +0 -14
  20. package/dist/draggable.mjs +0 -14
  21. package/dist/element-bounding.mjs +0 -14
  22. package/dist/element-by-point.mjs +0 -10
  23. package/dist/element-hover.mjs +0 -13
  24. package/dist/element-target.mjs +0 -30
  25. package/dist/focus.mjs +0 -23
  26. package/dist/fps.mjs +0 -12
  27. package/dist/geolocation.mjs +0 -14
  28. package/dist/i18n.mjs +0 -86
  29. package/dist/icu-message.mjs +0 -58
  30. package/dist/idle.mjs +0 -16
  31. package/dist/index.d.mts +2 -2
  32. package/dist/index.mjs +2 -2
  33. package/dist/infinite-scroll.mjs +0 -16
  34. package/dist/intersection-observer.mjs +0 -27
  35. package/dist/locale.mjs +0 -20
  36. package/dist/magic-keys.mjs +0 -35
  37. package/dist/math.mjs +0 -37
  38. package/dist/media-query.mjs +0 -29
  39. package/dist/mouse-in-element.mjs +0 -12
  40. package/dist/mouse.mjs +0 -12
  41. package/dist/mutation-observer.mjs +0 -15
  42. package/dist/network.mjs +0 -24
  43. package/dist/on-click-outside.mjs +0 -16
  44. package/dist/on-key-stroke.mjs +0 -33
  45. package/dist/on-long-press.mjs +0 -14
  46. package/dist/on-start-typing.mjs +0 -23
  47. package/dist/page-leave.mjs +0 -11
  48. package/dist/parent-element.mjs +0 -9
  49. package/dist/pinch.mjs +0 -14
  50. package/dist/pointer-lock.mjs +0 -23
  51. package/dist/pointer.mjs +0 -18
  52. package/dist/preferences.mjs +0 -31
  53. package/dist/preferred-languages.mjs +0 -13
  54. package/dist/ref-auto-reset.mjs +0 -24
  55. package/dist/ref-debounced.mjs +0 -22
  56. package/dist/ref-default.mjs +0 -21
  57. package/dist/resize-observer.mjs +0 -31
  58. package/dist/resolver.mjs +1 -58
  59. package/dist/retry-async.mjs +0 -25
  60. package/dist/retry-delay.mjs +0 -23
  61. package/dist/scope.mjs +0 -14
  62. package/dist/screen-orientation.mjs +0 -15
  63. package/dist/scroll-lock.mjs +0 -14
  64. package/dist/scroll.mjs +0 -27
  65. package/dist/standard-schema.mjs +0 -31
  66. package/dist/swipe.mjs +0 -36
  67. package/dist/temporal.mjs +0 -30
  68. package/dist/text-selection.mjs +0 -15
  69. package/dist/textarea-autosize.mjs +0 -13
  70. package/dist/to-reactive.mjs +0 -20
  71. package/dist/transition.mjs +0 -7
  72. package/dist/until.mjs +0 -25
  73. package/dist/use-array.mjs +0 -52
  74. package/dist/use-barcode-detector.mjs +0 -25
  75. package/dist/use-bluetooth.mjs +0 -27
  76. package/dist/use-broadcast-channel.mjs +0 -30
  77. package/dist/use-builtin-ai.mjs +0 -68
  78. package/dist/use-clipboard.mjs +0 -27
  79. package/dist/use-compression-stream.mjs +0 -78
  80. package/dist/use-contact-picker.mjs +0 -22
  81. package/dist/use-cookie.mjs +0 -63
  82. package/dist/use-countdown.mjs +0 -22
  83. package/dist/use-counter.mjs +0 -29
  84. package/dist/use-css-var.mjs +0 -28
  85. package/dist/use-date-format.mjs +0 -48
  86. package/dist/use-date-time-format.mjs +0 -22
  87. package/dist/use-debounced.mjs +0 -39
  88. package/dist/use-display-media.mjs +0 -22
  89. package/dist/use-display-names.mjs +0 -19
  90. package/dist/use-document-title.mjs +0 -25
  91. package/dist/use-drop-zone.mjs +0 -36
  92. package/dist/use-event-source.mjs +0 -25
  93. package/dist/use-eye-dropper.mjs +0 -19
  94. package/dist/use-favicon.mjs +0 -23
  95. package/dist/use-fetch.mjs +0 -27
  96. package/dist/use-field.mjs +0 -27
  97. package/dist/use-file-dialog.mjs +0 -21
  98. package/dist/{use-form-C2JXZ0i7.mjs → use-form-BZqwMs6k.mjs} +143 -70
  99. package/dist/use-form-field-props.mjs +0 -57
  100. package/dist/use-form.d.mts +123 -18
  101. package/dist/use-form.mjs +1 -1
  102. package/dist/use-fullscreen.mjs +0 -23
  103. package/dist/use-gamepad.mjs +0 -50
  104. package/dist/use-hid.mjs +0 -25
  105. package/dist/use-history.mjs +0 -43
  106. package/dist/use-id-generator.mjs +0 -21
  107. package/dist/use-image.mjs +0 -22
  108. package/dist/use-indexed-db.mjs +0 -39
  109. package/dist/use-interval.mjs +0 -28
  110. package/dist/use-list-format.mjs +0 -18
  111. package/dist/use-machine.mjs +0 -34
  112. package/dist/use-map.mjs +0 -28
  113. package/dist/use-media-controls.mjs +0 -28
  114. package/dist/use-mounted.mjs +0 -18
  115. package/dist/use-navigation-api.mjs +0 -27
  116. package/dist/use-notification.mjs +0 -24
  117. package/dist/use-number-format.mjs +0 -23
  118. package/dist/use-object-url.mjs +0 -22
  119. package/dist/use-offset-pagination.mjs +0 -18
  120. package/dist/use-payment-request.mjs +0 -25
  121. package/dist/use-performance-observer.mjs +0 -27
  122. package/dist/use-permission.mjs +0 -26
  123. package/dist/use-plural-rules.mjs +0 -21
  124. package/dist/use-push-subscription.mjs +0 -28
  125. package/dist/use-queue.mjs +0 -29
  126. package/dist/use-raf-fn.mjs +0 -23
  127. package/dist/use-relative-time-format.mjs +0 -35
  128. package/dist/use-request-idle-callback.mjs +0 -42
  129. package/dist/use-route-query.mjs +0 -17
  130. package/dist/use-scheduler-post-task.mjs +0 -27
  131. package/dist/use-screen-details.mjs +0 -42
  132. package/dist/use-script-tag.mjs +0 -28
  133. package/dist/use-segmenter.mjs +0 -20
  134. package/dist/use-serial.mjs +0 -24
  135. package/dist/use-service-worker.mjs +0 -27
  136. package/dist/use-set.mjs +0 -23
  137. package/dist/use-share.mjs +0 -23
  138. package/dist/use-sorted-locale.mjs +0 -20
  139. package/dist/use-speech-recognition.mjs +0 -24
  140. package/dist/use-speech-synthesis.mjs +0 -26
  141. package/dist/use-stack.mjs +0 -27
  142. package/dist/use-storage-estimate.mjs +0 -41
  143. package/dist/use-storage.mjs +0 -68
  144. package/dist/use-style-tag.mjs +0 -22
  145. package/dist/use-supported.mjs +0 -17
  146. package/dist/use-throttled.mjs +0 -46
  147. package/dist/use-time-ago.mjs +0 -22
  148. package/dist/use-toggle.mjs +0 -19
  149. package/dist/use-url-hash.mjs +0 -28
  150. package/dist/use-url-search-params.mjs +0 -99
  151. package/dist/use-usb.mjs +0 -23
  152. package/dist/use-user-activation.mjs +0 -22
  153. package/dist/use-user-media.mjs +0 -50
  154. package/dist/use-vibrate.mjs +0 -21
  155. package/dist/use-view-transition.mjs +0 -22
  156. package/dist/use-visual-viewport.mjs +0 -25
  157. package/dist/use-wake-lock.mjs +0 -21
  158. package/dist/use-web-authn.mjs +0 -61
  159. package/dist/use-web-locks.mjs +0 -25
  160. package/dist/use-web-midi.mjs +0 -22
  161. package/dist/use-web-vitals.mjs +0 -41
  162. package/dist/use-websocket.mjs +0 -27
  163. package/dist/use-worker-fn.mjs +0 -37
  164. package/dist/virtual-list.mjs +0 -14
  165. package/dist/whenever.mjs +0 -21
  166. package/dist/window-size.mjs +0 -12
  167. package/package.json +2 -2
  168. package/registry/files/form-control-types.ts +260 -0
  169. package/registry/files/form-dirty.ts +131 -0
  170. package/registry/files/form-options.ts +156 -0
  171. package/registry/files/form-path-types.ts +135 -0
  172. package/registry/files/use-form.ts +102 -449
  173. package/registry/registry.json +28 -4
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Options for {@link useForm}: when validation runs, and what reset keeps.
3
+ */
4
+
5
+ import type { MaybeRefOrGetter } from "vue";
6
+
7
+ import type { StandardSchemaV1 } from "./standard-schema.ts";
8
+ import type { FormFieldValidators, FormValidator } from "./form-path-types.ts";
9
+
10
+ /** When validation runs automatically. */
11
+ export type FormValidationTrigger = "change" | "blur" | "submit";
12
+
13
+ /** How many messages each path keeps after validation. */
14
+ export type FormCriteriaMode = "all" | "first";
15
+
16
+ /** Discriminated outcome of validation and submission. */
17
+ export type FormResult<Output> =
18
+ | {
19
+ /** Every validator passed. */
20
+ readonly status: "valid";
21
+ /** Schema output, or the values when no schema is configured. */
22
+ readonly value: Output;
23
+ }
24
+ | {
25
+ /** At least one validator failed. */
26
+ readonly status: "invalid";
27
+ /** Errors keyed by path. */
28
+ readonly errors: Readonly<Record<string, readonly string[]>>;
29
+ }
30
+ | {
31
+ /** A newer validation started before this one finished. */
32
+ readonly status: "superseded";
33
+ };
34
+
35
+ /** Options for `useForm`. */
36
+ export interface UseFormOptions<Values extends object, Output> {
37
+ /** Initial values, or a factory producing fresh initial values. */
38
+ readonly initialValues: Values | (() => Values);
39
+
40
+ /**
41
+ * Standard Schema v1 validator for the whole form. Its output becomes the
42
+ * submitted value.
43
+ *
44
+ * @default undefined
45
+ */
46
+ readonly schema?: StandardSchemaV1<NoInfer<Values>, Output>;
47
+
48
+ /**
49
+ * Plain whole-form validator.
50
+ *
51
+ * @default undefined
52
+ */
53
+ readonly validate?: NoInfer<FormValidator<Values>>;
54
+
55
+ /**
56
+ * Plain per-field validators keyed by path.
57
+ *
58
+ * @default {}
59
+ */
60
+ readonly validators?: NoInfer<FormFieldValidators<Values>>;
61
+
62
+ /**
63
+ * When fields validate before the first submit.
64
+ *
65
+ * @default "submit"
66
+ */
67
+ readonly validateOn?: FormValidationTrigger;
68
+
69
+ /**
70
+ * When fields re-validate after the first submit.
71
+ *
72
+ * @default "change"
73
+ */
74
+ readonly revalidateOn?: FormValidationTrigger;
75
+
76
+ /**
77
+ * `"all"` records every message. `"first"` keeps the earliest message in
78
+ * source order: schema, then the form validator, then the field validator.
79
+ *
80
+ * @default "all"
81
+ */
82
+ readonly criteriaMode?: FormCriteriaMode;
83
+
84
+ /**
85
+ * When true, value writes, field-array edits, and submission do nothing.
86
+ * `setError`, `setErrors`, and `reset` still run. A ref or getter tracks.
87
+ *
88
+ * @default false
89
+ */
90
+ readonly disabled?: MaybeRefOrGetter<boolean>;
91
+
92
+ /**
93
+ * Default submit handler for `submit`.
94
+ *
95
+ * @default undefined
96
+ */
97
+ readonly onSubmit?: (value: Output, context: { readonly signal: AbortSignal }) => unknown;
98
+ }
99
+
100
+ /** Options for `setValue`. */
101
+ export interface SetFieldValueOptions {
102
+ /**
103
+ * Mark the field touched.
104
+ *
105
+ * @default false
106
+ */
107
+ readonly touch?: boolean;
108
+
109
+ /**
110
+ * Validate the field after setting it.
111
+ *
112
+ * @default true while the active trigger is "change"
113
+ */
114
+ readonly validate?: boolean;
115
+ }
116
+
117
+ /**
118
+ * What {@link FormControls.reset} retains. Every omitted flag clears that state.
119
+ */
120
+ export interface FormResetOptions {
121
+ /**
122
+ * Keep values that differ from the previous initial values. Clean fields
123
+ * take the reset values. Added keys stay, and removed keys stay removed.
124
+ *
125
+ * @default false
126
+ */
127
+ readonly keepDirtyValues?: boolean;
128
+
129
+ /**
130
+ * Keep the current errors.
131
+ *
132
+ * @default false
133
+ */
134
+ readonly keepErrors?: boolean;
135
+
136
+ /**
137
+ * Keep touched fields.
138
+ *
139
+ * @default false
140
+ */
141
+ readonly keepTouched?: boolean;
142
+
143
+ /**
144
+ * Keep the submit count.
145
+ *
146
+ * @default false
147
+ */
148
+ readonly keepSubmitCount?: boolean;
149
+
150
+ /**
151
+ * Keep whether the latest finished submit succeeded.
152
+ *
153
+ * @default false
154
+ */
155
+ readonly keepIsSubmitSuccessful?: boolean;
156
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Path and error types for {@link useForm}.
3
+ *
4
+ * Paths are template-literal keys, bounded at eight levels so type checking
5
+ * stays fast. Leaves stop the walk.
6
+ */
7
+
8
+ /** Values treated as leaves: paths never descend into them. */
9
+ export type FormLeaf =
10
+ | string
11
+ | number
12
+ | bigint
13
+ | boolean
14
+ | symbol
15
+ | null
16
+ | undefined
17
+ | Date
18
+ | RegExp
19
+ | Blob
20
+ | Map<unknown, unknown>
21
+ | Set<unknown>
22
+ | ((...arguments_: never[]) => unknown);
23
+
24
+ type Decrement = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8];
25
+
26
+ /**
27
+ * Every dotted path into `Values`, as template-literal keys.
28
+ *
29
+ * Objects contribute their string keys, arrays and tuples contribute
30
+ * `${number}` segments, and {@link FormLeaf} values end a path. Recursion
31
+ * is bounded at eight levels to keep type checking fast.
32
+ */
33
+ export type FormPath<Values, Depth extends number = 8> = [Depth] extends [never]
34
+ ? never
35
+ : Values extends FormLeaf
36
+ ? never
37
+ : Values extends readonly (infer Item)[]
38
+ ? `${number}` | `${number}.${FormPath<Item, Decrement[Depth]>}`
39
+ : {
40
+ [Key in keyof Values & string]:
41
+ | Key
42
+ | (FormPath<Values[Key], Decrement[Depth]> extends infer Rest extends string
43
+ ? [Rest] extends [never]
44
+ ? never
45
+ : `${Key}.${Rest}`
46
+ : never);
47
+ }[keyof Values & string];
48
+
49
+ /** Value type found at `Path` inside `Values`. */
50
+ export type FormPathValue<Values, Path extends string> = Path extends `${infer Head}.${infer Rest}`
51
+ ? Values extends readonly (infer Item)[]
52
+ ? Head extends `${number}`
53
+ ? FormPathValue<Item, Rest>
54
+ : never
55
+ : Head extends keyof Values
56
+ ? FormPathValue<Values[Head], Rest>
57
+ : never
58
+ : Values extends readonly (infer Item)[]
59
+ ? Path extends `${number}`
60
+ ? Item
61
+ : never
62
+ : Path extends keyof Values
63
+ ? Values[Path]
64
+ : never;
65
+
66
+ /** Paths whose value is an array (usable with field arrays). */
67
+ export type FormArrayPath<Values> = {
68
+ [Path in FormPath<Values>]: FormPathValue<Values, Path> extends readonly unknown[] ? Path : never;
69
+ }[FormPath<Values>];
70
+
71
+ /** Item type of the array at `Path`. */
72
+ export type FormArrayItem<Values, Path extends string> =
73
+ FormPathValue<Values, Path> extends readonly (infer Item)[] ? Item : never;
74
+
75
+ /**
76
+ * Error messages keyed by dotted path; `""` holds form-level errors.
77
+ *
78
+ * Known paths are typed for autocompletion; the string index signature
79
+ * stays because schemas and servers may report paths that are not fields.
80
+ */
81
+ export type FormErrors<Values> = {
82
+ readonly [Path in FormPath<Values> | ""]?: readonly string[];
83
+ } & { readonly [path: string]: readonly string[] | undefined };
84
+
85
+ /** Current errors as recorded: messages keyed by dotted path (`""` = form level). */
86
+ export type FormErrorRecord = Readonly<Record<string, readonly string[]>>;
87
+
88
+ /** Result of a validator: messages, one message, or nothing when valid. */
89
+ export type ValidatorResult = string | readonly string[] | null | undefined | void;
90
+
91
+ /** Context passed to field validators. */
92
+ export interface FieldValidatorContext<Values> {
93
+ /** Current form values (`undefined` for standalone fields). */
94
+ readonly values: Values;
95
+
96
+ /** Dotted path of the validated field. */
97
+ readonly path: string;
98
+
99
+ /** Aborted when a newer validation supersedes this one. */
100
+ readonly signal: AbortSignal;
101
+ }
102
+
103
+ /** Plain validator for one field value. */
104
+ export type FieldValidator<Value, Values = undefined> = (
105
+ value: Value,
106
+ context: FieldValidatorContext<Values>,
107
+ ) => ValidatorResult | Promise<ValidatorResult>;
108
+
109
+ /** Plain validator for the whole form, returning errors keyed by path. */
110
+ export type FormValidator<Values> = (
111
+ values: Values,
112
+ context: { readonly signal: AbortSignal },
113
+ ) => FormErrors<Values> | undefined | void | Promise<FormErrors<Values> | undefined | void>;
114
+
115
+ /** Per-field validators keyed by path. */
116
+ export type FormFieldValidators<Values> = {
117
+ readonly [Path in FormPath<Values>]?: FieldValidator<FormPathValue<Values, Path>, Values>;
118
+ };
119
+
120
+ /** One dirty branch: `true` for a leaf, or a nested map when children differ. */
121
+ export type DirtyNode<Values> = true | DirtyFields<Values>;
122
+
123
+ /**
124
+ * Nested dirty flags against the initial values.
125
+ *
126
+ * A dirty leaf is `true`. Clean branches are omitted. Array indexes stay
127
+ * aligned with the value, and a clean item is `undefined`.
128
+ */
129
+ export type DirtyFields<Values> = Values extends FormLeaf
130
+ ? true
131
+ : Values extends readonly (infer Item)[]
132
+ ? readonly (DirtyNode<Item> | undefined)[]
133
+ : Values extends object
134
+ ? { readonly [Key in keyof Values]?: DirtyNode<Values[Key]> }
135
+ : true;