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.
- package/LICENSE +21 -0
- package/README.md +64 -38
- package/a11y.d.ts +128 -0
- package/data.d.ts +294 -0
- package/dist/a11y.js +510 -0
- package/dist/a11y.min.js +413 -0
- package/dist/actions.js +158 -0
- package/dist/actions.min.js +112 -0
- package/dist/animation.js +481 -0
- package/dist/animation.min.js +295 -0
- package/dist/async.js +180 -0
- package/dist/async.min.js +134 -0
- package/dist/components.js +577 -0
- package/dist/components.min.js +413 -0
- package/dist/data.js +1212 -0
- package/dist/data.min.js +918 -0
- package/dist/diagnostics.js +187 -0
- package/dist/diagnostics.min.js +134 -0
- package/dist/dom.js +796 -0
- package/dist/dom.min.js +603 -0
- package/dist/entries/a11y.js +43 -0
- package/dist/entries/a11y.min.js +43 -0
- package/dist/entries/data.js +29 -0
- package/dist/entries/data.min.js +29 -0
- package/dist/entries/dom.js +45 -0
- package/dist/entries/dom.min.js +45 -0
- package/dist/entries/form.js +31 -0
- package/dist/entries/form.min.js +31 -0
- package/dist/entries/internal.js +123 -0
- package/dist/entries/internal.min.js +123 -0
- package/dist/entries/motion.js +23 -0
- package/dist/entries/motion.min.js +23 -0
- package/dist/entries/ui.js +25 -0
- package/dist/entries/ui.min.js +25 -0
- package/dist/env.js +5 -0
- package/dist/env.min.js +5 -0
- package/dist/errors.js +1518 -0
- package/dist/errors.min.js +548 -0
- package/dist/form.js +936 -0
- package/dist/form.min.js +703 -0
- package/dist/guardrails.js +84 -0
- package/dist/guardrails.min.js +55 -0
- package/dist/h.js +232 -0
- package/dist/h.min.js +171 -0
- package/dist/head.js +241 -0
- package/dist/head.min.js +207 -0
- package/dist/helpers.js +126 -0
- package/dist/helpers.min.js +98 -0
- package/dist/hooks.js +255 -0
- package/dist/hooks.min.js +153 -0
- package/dist/hot.js +215 -0
- package/dist/hot.min.js +24 -0
- package/dist/hydration-data.js +495 -0
- package/dist/hydration-data.min.js +371 -0
- package/dist/import-changes.js +273 -0
- package/dist/import-changes.min.js +272 -0
- package/dist/index.js +95 -0
- package/dist/index.min.js +95 -227
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.min.js +10 -1
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.min.js +15 -1
- package/dist/live.js +54 -0
- package/dist/live.min.js +49 -0
- package/dist/markup-rules.js +250 -0
- package/dist/markup-rules.min.js +213 -0
- package/dist/reactive.js +3334 -0
- package/dist/reactive.min.js +2033 -0
- package/dist/render.js +4746 -0
- package/dist/render.min.js +2797 -1
- package/dist/scheduler.js +225 -0
- package/dist/scheduler.min.js +162 -0
- package/dist/selector.js +11 -0
- package/dist/selector.min.js +10 -0
- package/dist/server-context.js +148 -0
- package/dist/server-context.min.js +121 -0
- package/dist/skeleton.js +342 -0
- package/dist/skeleton.min.js +310 -0
- package/dist/store.js +72 -0
- package/dist/store.min.js +50 -0
- package/dist/testing.js +720 -0
- package/dist/testing.min.js +458 -1
- package/dist/vnode-adoption.js +19 -0
- package/dist/vnode-adoption.min.js +19 -0
- package/dist/vnode-renderer.js +61 -0
- package/dist/vnode-renderer.min.js +47 -0
- package/dom.d.ts +44 -0
- package/form.d.ts +218 -0
- package/hot.d.ts +35 -0
- package/index.d.ts +421 -736
- package/internal.d.ts +284 -0
- package/jsx-runtime.d.ts +160 -137
- package/markup-rules.d.ts +83 -0
- package/motion.d.ts +156 -0
- package/package.json +117 -3
- package/render.d.ts +278 -29
- package/src/a11y.js +64 -59
- package/src/actions.js +226 -0
- package/src/animation.js +105 -57
- package/src/async.js +259 -0
- package/src/components.js +495 -144
- package/src/data.js +1410 -1159
- package/src/diagnostics.js +263 -0
- package/src/dom.js +1159 -872
- package/src/entries/a11y.js +24 -0
- package/src/entries/data.js +17 -0
- package/src/entries/dom.js +29 -0
- package/src/entries/form.js +16 -0
- package/src/entries/internal.js +63 -0
- package/src/entries/motion.js +13 -0
- package/src/entries/ui.js +13 -0
- package/src/env-development.js +12 -0
- package/src/env.js +33 -0
- package/src/errors.js +1144 -168
- package/src/form.js +723 -225
- package/src/guardrails.js +38 -126
- package/src/h.js +227 -152
- package/src/head.js +189 -19
- package/src/helpers.js +47 -75
- package/src/hooks.js +233 -248
- package/src/hot.js +316 -0
- package/src/hydration-data.js +859 -16
- package/src/import-changes.js +156 -0
- package/src/index.js +38 -188
- package/src/jsx-dev-runtime.js +7 -14
- package/src/jsx-runtime.js +25 -9
- package/src/live.js +80 -0
- package/src/markup-rules.js +387 -0
- package/src/reactive.js +4400 -862
- package/src/render.js +6502 -2570
- package/src/scheduler.js +56 -21
- package/src/selector.js +31 -0
- package/src/server-context.js +252 -22
- package/src/skeleton.js +22 -12
- package/src/store.js +17 -31
- package/src/testing.js +389 -63
- package/src/vnode-adoption.js +48 -0
- package/src/vnode-renderer.js +114 -0
- package/testing.d.ts +81 -1
- package/ui.d.ts +20 -0
- package/dist/chunk-6YOUZ6T4.min.js +0 -1
- package/dist/chunk-FN6HXME3.min.js +0 -11
- package/dist/chunk-VKZY7JPN.min.js +0 -1
- package/src/agent-context.js +0 -127
- 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;
|