what-core 0.14.0 → 0.15.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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
package/form.d.ts ADDED
@@ -0,0 +1,218 @@
1
+ // what-core/form (what-framework/form): form state, validation and bound fields.
2
+ import type { Computed, VNode, VNodeChild } from './index.js';
3
+
4
+ // --- Forms ---
5
+
6
+ export interface FieldError {
7
+ type?: string;
8
+ message?: string;
9
+ [key: string]: any;
10
+ }
11
+
12
+ /**
13
+ * What register() actually hands back, which varies by control type. The event
14
+ * handler is LOWERCASE (`onchange`), because that is the key the DOM binding
15
+ * and the merge in <Input>/<Radio> look for; `onInput` was declared here and
16
+ * register() has never defined it, so `register('email').onInput(e)`
17
+ * type-checked and threw at the first keystroke. `onchange` is React's change
18
+ * event, as every onChange is: a text field fires it as the user types.
19
+ *
20
+ * `value` and the checkbox `checked` are getters, and the radio `checked` is a
21
+ * thunk. Compiled JSX's spread (`<input {...register('email')} />`) reads them
22
+ * in its binding, so the input follows setValue and reset. An h() call reads
23
+ * them once: a JavaScript spread (`h('input', { ...register('email') })`)
24
+ * copies the value, so a later setValue does not show; give `value` as an
25
+ * accessor after the spread, or use `Input` (docs/API.md, Forms).
26
+ *
27
+ * A closed type alias rather than an interface: the key set really is closed
28
+ * (this is the whole object register() builds), and closing it is what makes
29
+ * the phantom `onInput` an error again instead of an `any` off an index
30
+ * signature. It must stay a `type`, not an `interface`, because only a type
31
+ * alias gets the implicit index signature that `h('input', register(name))`
32
+ * needs to be assignable to Record<string, any>.
33
+ */
34
+ export type RegisterProps = {
35
+ name: string;
36
+ onBlur: () => void;
37
+ onFocus: () => void;
38
+ ref?: any;
39
+ /** text/select/textarea, and the option's own value on a radio. */
40
+ value?: any;
41
+ /** checkbox/radio only. */
42
+ checked?: boolean | (() => boolean);
43
+ /** Every control: each edit of a text field or a textarea, as the user types, a select's pick and a checkbox's or a radio's. */
44
+ onchange?: (e: any) => void;
45
+ /**
46
+ * @deprecated text/select/textarea only: the `onchange` handler, kept for
47
+ * 0.14 code that wires `oninput: register('x').oninput`. Not enumerable, so
48
+ * a spread attaches only `onchange`.
49
+ */
50
+ oninput?: (e: any) => void;
51
+ };
52
+
53
+ /** `TValues` is the form's values type, given to useForm or inferred from its defaultValues. */
54
+ export interface FormState<TValues extends object = Record<string, any>> {
55
+ readonly values: TValues;
56
+ readonly errors: Record<string, FieldError>;
57
+ error: (name: string) => FieldError | null;
58
+ readonly touched: Record<string, boolean>;
59
+ isDirty: () => boolean;
60
+ isValid: Computed<boolean>;
61
+ /** True while the resolver is running. Present since resolvers went async; never declared. */
62
+ isValidating: () => boolean;
63
+ isSubmitting: () => boolean;
64
+ isSubmitted: () => boolean;
65
+ submitCount: () => number;
66
+ dirtyFields: Computed<Record<string, boolean>>;
67
+ }
68
+
69
+ /** What unregister() keeps of a field it forgets (React Hook Form's options). */
70
+ export interface UnregisterOptions {
71
+ keepValue?: boolean;
72
+ keepError?: boolean;
73
+ keepTouched?: boolean;
74
+ /** Keep the field's default, so a later reset(), or the field registered again, starts from it. A form or field with shouldUnregister keeps it. */
75
+ keepDefaultValue?: boolean;
76
+ }
77
+
78
+ /** A form's state as useFieldArray works with it: `useForm().control`. */
79
+ export interface FormControl {
80
+ /** @internal */
81
+ x: (make: (...args: any[]) => any) => any;
82
+ }
83
+
84
+ /**
85
+ * A field's name is a path: `register('vehicles.0.vin')` reads and writes
86
+ * `values.vehicles[0].vin`, so `values` and what the submit handler gets are
87
+ * nested. `errors`, `touched` and `dirtyFields` are keyed by the field's name
88
+ * (`'vehicles.0.vin'`), as zodResolver reports a nested issue.
89
+ */
90
+ export interface UseFormReturn<TValues extends object = Record<string, any>> {
91
+ /** `options.shouldUnregister` forgets the field when the component (or scope) that registered it goes. */
92
+ register: (name: string, options?: Record<string, any>) => RegisterProps;
93
+ /**
94
+ * Forget fields, or every field: their values (and defaults), errors and
95
+ * touched state, each unless the options keep it. A validation of one still
96
+ * in flight never lands.
97
+ */
98
+ unregister: (name?: string | readonly string[], options?: UnregisterOptions) => void;
99
+ control: FormControl;
100
+ handleSubmit: (
101
+ onValid: (values: TValues) => void | Promise<void>,
102
+ onInvalid?: (errors: Record<string, FieldError>) => void,
103
+ ) => (e?: Event) => Promise<void>;
104
+ setValue: (name: string, value: any, options?: Record<string, any>) => void;
105
+ getValue: (name: string) => any;
106
+ setError: (name: string, error: FieldError | null) => void;
107
+ clearError: (name: string) => void;
108
+ clearErrors: () => void;
109
+ /** Back to the defaults, or to `newValues`, which become the defaults that dirtyFields measures from (React Hook Form's reset). */
110
+ reset: (newValues?: Partial<TValues>) => void;
111
+ watch: (name?: string) => Computed<any>;
112
+ validate: (fieldName?: string) => Promise<boolean>;
113
+ formState: FormState<TValues>;
114
+ }
115
+
116
+ /**
117
+ * `useForm<LoginValues>()` types the values the submit handler, formState.values
118
+ * and reset() take; without it they are inferred from `defaultValues`, and
119
+ * without either they are Record<string, any>.
120
+ */
121
+ export function useForm<TValues extends object = Record<string, any>>(options?: {
122
+ defaultValues?: Partial<TValues>;
123
+ mode?: 'onSubmit' | 'onChange' | 'onBlur';
124
+ /** Forget each field when the component (or scope) that registered it goes, keeping its default for when it is registered again. */
125
+ shouldUnregister?: boolean;
126
+ reValidateMode?: 'onChange' | 'onBlur';
127
+ /**
128
+ * Given every value; for one field's own validation (a keystroke in
129
+ * `mode: 'onChange'`), also `{ names: [field] }`, so a resolver can check
130
+ * that field alone.
131
+ */
132
+ resolver?: (values: Record<string, any>, context?: undefined, options?: ResolverOptions) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
133
+ }): UseFormReturn<TValues>;
134
+
135
+ /** What a resolver is told about a validation: `names` is set when it is for those fields only. */
136
+ export interface ResolverOptions {
137
+ names?: string[];
138
+ }
139
+
140
+ /**
141
+ * The items of an array field (React Hook Form's useFieldArray). `fields()`
142
+ * lists them, each with an `id` to key its row by; an item's values, errors
143
+ * and touched state move with it, and a removed item's go with it. A field
144
+ * registered in a row (`register(\`vehicles.${index}.vin\`)`) keeps its item
145
+ * while rows move around it.
146
+ */
147
+ export interface UseFieldArrayReturn<TItem extends object = Record<string, any>> {
148
+ fields: Computed<Array<TItem & { id: string }>>;
149
+ append: (value: TItem | TItem[]) => void;
150
+ prepend: (value: TItem | TItem[]) => void;
151
+ insert: (index: number, value: TItem | TItem[]) => void;
152
+ /** The items at these indexes, or every item. */
153
+ remove: (index?: number | number[]) => void;
154
+ move: (from: number, to: number) => void;
155
+ swap: (indexA: number, indexB: number) => void;
156
+ /** The item at `index` becomes a new item with these values: its row is built again. */
157
+ update: (index: number, value: TItem) => void;
158
+ replace: (values: TItem[]) => void;
159
+ }
160
+
161
+ export function useFieldArray<TItem extends object = Record<string, any>>(
162
+ options: { control: FormControl; name: string } | { form: { control: FormControl }; name: string },
163
+ ): UseFieldArrayReturn<TItem>;
164
+
165
+ export function useField(name: string, options?: {
166
+ validate?: (value: any) => string | null | Promise<string | null>;
167
+ defaultValue?: any;
168
+ }): {
169
+ name: string;
170
+ value: () => any;
171
+ error: () => string | null;
172
+ isTouched: () => boolean;
173
+ isDirty: () => boolean;
174
+ setValue: (value: any) => void;
175
+ setError: (error: string | null) => void;
176
+ validate: () => Promise<boolean>;
177
+ reset: () => void;
178
+ inputProps: () => Record<string, any>;
179
+ };
180
+
181
+ export const rules: {
182
+ required: (message?: string) => (value: any) => string | void;
183
+ minLength: (min: number, message?: string) => (value: any) => string | void;
184
+ maxLength: (max: number, message?: string) => (value: any) => string | void;
185
+ min: (min: number, message?: string) => (value: any) => string | void;
186
+ max: (max: number, message?: string) => (value: any) => string | void;
187
+ pattern: (regex: RegExp, message?: string) => (value: any) => string | void;
188
+ email: (message?: string) => (value: any) => string | void;
189
+ url: (message?: string) => (value: any) => string | void;
190
+ match: (field: string, message?: string) => (value: any, values: Record<string, any>) => string | void;
191
+ custom: <T extends (...args: any[]) => any>(validator: T) => T;
192
+ };
193
+
194
+ export function simpleResolver(ruleMap: Record<string, Array<(value: any, values: Record<string, any>) => string | void>>):
195
+ (values: Record<string, any>, context?: unknown, options?: ResolverOptions) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
196
+
197
+ export function zodResolver(schema: { parseAsync: (values: any) => Promise<any> }):
198
+ (values: Record<string, any>) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
199
+
200
+ export function yupResolver(schema: { validate: (values: any, options?: any) => Promise<any> }):
201
+ (values: Record<string, any>) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
202
+
203
+ export function Input(props: Record<string, any>): VNode;
204
+ export function Textarea(props: Record<string, any>): VNode;
205
+ export function Select(props: Record<string, any>): VNode;
206
+ export function Checkbox(props: Record<string, any>): VNode;
207
+ export function Radio(props: Record<string, any>): VNode;
208
+
209
+ /**
210
+ * The field's error message, kept current: it appears, changes and goes away
211
+ * with the error. Returns the reactive function that renders it.
212
+ */
213
+ export function ErrorMessage(props: {
214
+ name: string;
215
+ formState?: FormState;
216
+ errors?: Record<string, FieldError> | (() => Record<string, FieldError>);
217
+ render?: (args: { message?: string; type?: string }) => VNodeChild;
218
+ }): () => VNodeChild;
package/hot.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ // what-core/hot: the hot replacement runtime what-compiler's Vite plugin
2
+ // calls from each module of the app in the dev server (src/hot.js). Not for
3
+ // applications: the plugin writes every call.
4
+
5
+ /** @internal A module's hot context. */
6
+ export interface HotModule {
7
+ /** The callback of `import.meta.hot.accept()`. */
8
+ accept(module: unknown): void;
9
+ /** Register a component the module declares, with its state signature (null keeps no state); returns `fn`. */
10
+ component<F extends Function>(name: string, fn: F, signature: string | null, deps: () => unknown[], state?: string | null): F;
11
+ /** A state call of a component's body: the value the same call made in the version this instance replaces, or `init()`. */
12
+ state<T>(site: string, init: () => T, reducer?: 1): T;
13
+ /** Register an exported function, compared with its next version. */
14
+ fn(name: string, signature: string | null, deps: () => unknown[]): void;
15
+ /** A module-scope value: the previous version's while its source and what it reads are unchanged. */
16
+ keep<T>(name: string, signature: string | null, deps: () => unknown[], init: () => T): T;
17
+ /** The module ran to its end; `exported` names its exports other than components. */
18
+ done(exported: string[]): void;
19
+ }
20
+
21
+ /** @internal The hot context of the module whose `import.meta.hot` is `hot`. */
22
+ export function _$hot(hot: unknown, accepts: 0 | 1, file: string): HotModule;
23
+
24
+ /** @internal what-react's Fast Refresh: record a refresh it applied as a devtools `hmr:update` event. */
25
+ export function _hotUpdated(record: {
26
+ files: string[];
27
+ components: string[];
28
+ remounted: string[];
29
+ instances: number;
30
+ ms: number;
31
+ failed?: Array<{ component: string; message: string }>;
32
+ }): void;
33
+
34
+ /** @internal what-react's Fast Refresh: what a React component is known by across its versions, so a native component that renders one is not built again for its new version. */
35
+ export function _hotIdentity(of: (fn: Function) => unknown): void;