@shikiform/react 0.0.0-stage → 0.1.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.
@@ -0,0 +1,243 @@
1
+ import * as react from 'react';
2
+ import { ComponentProps, MouseEvent, ReactNode, ComponentType } from 'react';
3
+ import { R as ResetState, F as FormSubmitHandlers, S as SubmitState, C as CheckedFieldProps, a as FieldProps, A as ArrayContainerSlot, b as ArrayKey, U as UseFieldOptions, c as FieldBinding, d as ArrayHandle, e as UseFormOptions } from './use-watch-BZlpyvHw.js';
4
+ export { f as ArrayErrors, g as ArrayField, h as ArrayScope, i as ArrayScopeValue, B as BlurFlag, j as BlurOn, k as ClickEvent, l as ComponentStatics, m as ConnectEnhancer, n as ConnectFieldProps, o as ConnectedComponent, p as Field, q as FieldComponents, r as FieldDecorators, s as FieldGroup, t as FieldGroupHandle, u as FieldKit, v as FieldKitDecorator, w as FieldKitSpec, x as FieldPropKey, y as FieldSlot, z as FieldStateKey, D as Form, E as FormDomProps, G as FormProps, O as ObjectField, P as PropsMapping, H as PropsTransform, I as RegisteredComponentSlot, J as RegisteredDecoratorSlot, K as RegisteredSlot, L as RowScope, M as ScopeValue, T as TreeField, N as UI, Q as UIProps, V as UiBinding, W as UseResetOptions, X as UseSubmitOptions, Y as Watch, Z as connect, _ as mapBlur, $ as mapFieldProps, a0 as mapProps, a1 as mapReadPretty, a2 as useArray, a3 as useArrayErrors, a4 as useArrayField, a5 as useField, a6 as useFieldGroup, a7 as useFieldGroupErrors, a8 as useForm, a9 as useFormContext, aa as useFormMessage, ab as useIndex, ac as useRecord, ad as useReset, ae as useSubmit, af as useTreeField, ag as useTreeNode, ah as useWatch } from './use-watch-BZlpyvHw.js';
5
+ import { FieldPath, PathValue, ArrayPath, ArrayItemOf, Draft, DefaultSubmit, FieldsInput, FormOptions, FormInstance, ResolveSubmit, Pattern } from '@shikiform/core/internal';
6
+ export { ArrayItemOf, Display, Draft, EffectDef, EnumBinding, EnumOption, EnumSource, FieldEnum, FieldError, FieldPath, FieldSpec, FieldUiSpec, FormInstance, FormMessageKey, FormMessages, FormOptions, MessageArgs, MessageBase, MessageParams, MessageTemplate, MoveResult, NoParams, NormalizePath, PathValue, Pattern, Pos, RowContext, RowDraft, Rule, RulesInput, ShikiConflictError, ShikiCycleError, ShikiUsageError, SubmitResult, SubmitValues, TemplatePath, TreeMoveParams, UiDisplay, UiDraft, UiName, UiNames, ValidateCtx, ValidateTrigger, ValuePath, createForm, defineEffects, enUS, get, getDefaultMessages, set, setDefaultMessages, zhCN } from '@shikiform/core';
7
+
8
+ type ButtonPass = Omit<ComponentProps<'button'>, 'onClick' | 'type' | 'disabled' | 'children'>;
9
+ type SubmitProps<T = any> = FormSubmitHandlers<T> & ButtonPass & {
10
+ /**
11
+ * Render your own element and merge submit behavior onto it.
12
+ * `<Submit asChild><button>保存</button></Submit>`.
13
+ */
14
+ asChild?: boolean;
15
+ /** Button label, a render prop that receives {@link SubmitState}, or the `asChild` element. */
16
+ children?: ReactNode | ((state: SubmitState<MouseEvent<HTMLButtonElement>>) => ReactNode);
17
+ /** Overrides `!$canSubmit`. */
18
+ disabled?: boolean;
19
+ /** Runs first. `preventDefault` skips a self-managed submit (`onSubmit` passed). */
20
+ onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
21
+ };
22
+ /**
23
+ * Headless submit control for the surrounding form. No Ant Design.
24
+ *
25
+ * - Render prop: `{(state) => <button type={state.type} disabled={state.disabled} onClick={state.onClick}>保存</button>}`.
26
+ * - `asChild`: behavior is merged onto the single child (`disabled`, `type`, `aria-busy`, `data-loading`, `onClick`).
27
+ * - Otherwise a native `<button>`. Label defaults to `messages.submit` (`提交`).
28
+ *
29
+ * Without `onSubmit` the button is `type="submit"` and `<Form onSubmit>` handles it (Enter works the same).
30
+ * With `onSubmit` the click runs `form.submit` itself, so it also works outside a `<form>` element.
31
+ */
32
+ declare function Submit<T = any>({ asChild, children, onSubmit, onInvalid, onSubmitError, onClick, disabled, className, ...rest }: SubmitProps<T>): react.JSX.Element;
33
+ type ResetProps<T = any> = Omit<ButtonPass, 'onClick'> & {
34
+ /** Reset to these values and make them the new initial values (`form.reset(values)`). Default: the current initial values. */
35
+ values?: T;
36
+ /**
37
+ * Called after `form.reset`, with the restored values. Use it to query again.
38
+ * `onClick` still runs first; `preventDefault` skips the reset and this callback.
39
+ */
40
+ afterReset?: (values: T) => void;
41
+ /** Runs before the reset. `preventDefault` skips the reset. */
42
+ onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
43
+ asChild?: boolean;
44
+ children?: ReactNode | ((state: ResetState<MouseEvent<HTMLButtonElement>>) => ReactNode);
45
+ className?: string;
46
+ disabled?: boolean;
47
+ };
48
+ /**
49
+ * Headless reset control for the surrounding form: `form.reset()` on click. No Ant Design.
50
+ * `type` is `'button'` so the browser's native reset does not bypass the store.
51
+ * Label defaults to `messages.reset` (`重置`). `afterReset` runs after the values are restored.
52
+ *
53
+ * ```tsx
54
+ * <Reset afterReset={(values) => search(values)} asChild><button>重置</button></Reset>
55
+ * ```
56
+ */
57
+ declare function Reset<T = any>({ asChild, children, values, afterReset, onClick, className, disabled, ...rest }: ResetProps<T>): react.JSX.Element;
58
+
59
+ /**
60
+ * Field components whose names are checked against `T`, the value at the current scope.
61
+ * Names stay relative at runtime, exactly like the plain components: these are the same components with types.
62
+ * `ArrayField` hands each row the same set typed as one row; `ObjectField` hands its function children the set
63
+ * typed as that object.
64
+ */
65
+ type ScopeFields<T> = {
66
+ Field: <N extends FieldPath<T>, C extends ComponentType<any> = ComponentType<any>, D extends ComponentType<any> = ComponentType<any>>(props: CheckedFieldProps<T, N, C, D>) => ReactNode;
67
+ ObjectField: <N extends FieldPath<T>>(props: {
68
+ name: N;
69
+ display?: FieldProps['display'];
70
+ children?: ReactNode | ((scope: ScopeFields<NonNullable<PathValue<T, N & string>>>) => ReactNode);
71
+ }) => ReactNode;
72
+ ArrayField: <N extends ArrayPath<T>, C extends ComponentType<any> = ComponentType<any>>(props: {
73
+ name: N;
74
+ rowKey?: string;
75
+ component?: ArrayContainerSlot<C>;
76
+ virtualScroll?: {
77
+ height: number;
78
+ rowHeight?: number;
79
+ overscan?: number;
80
+ };
81
+ children?: (row: ArrayKey & ScopeFields<ArrayItemOf<T, N & string>>) => ReactNode;
82
+ }) => ReactNode;
83
+ };
84
+ /**
85
+ * {@link typed}'s return: {@link ScopeFields} for the form root plus typed hooks.
86
+ * `useField` / `useArrayField` names are relative to the calling component's scope, typed against `T`.
87
+ * `useWatch` / `Watch` select from the root draft (`Draft<TRoot>`).
88
+ */
89
+ type FieldsOf<T, F> = {
90
+ fields?: F & FieldsInput<T>;
91
+ };
92
+ type TypedForm<T, TRoot = T> = ScopeFields<T> & {
93
+ useField: <N extends FieldPath<T>>(name: N, options?: UseFieldOptions<PathValue<T, N & string>>) => FieldBinding<PathValue<T, N & string>>;
94
+ useArrayField: <N extends ArrayPath<T>>(name: N, rowKey?: string) => ArrayHandle<ArrayItemOf<T, N & string>>;
95
+ useWatch: <S>(select: (d: Draft<TRoot>) => S) => S;
96
+ Watch: <S>(props: {
97
+ select: (d: Draft<TRoot>) => S;
98
+ children: (value: S) => ReactNode;
99
+ }) => ReactNode;
100
+ /**
101
+ * Same `createForm`, with `T` already fixed, so `fields` still decides which `virtual` / `none` paths are optional
102
+ * on submit. `createForm<T>(options)` does not: its submit type is `T`.
103
+ */
104
+ createForm: <TSubmit = DefaultSubmit, const F extends FieldsInput<T> = {}>(options?: Omit<FormOptions<T>, 'fields'> & FieldsOf<T, F>) => FormInstance<T, ResolveSubmit<T, TSubmit, F>>;
105
+ /** Same `useForm`. See {@link TypedForm.createForm}. `useForm()` with no arguments is not this; it is an empty form. */
106
+ useForm: <TSubmit = DefaultSubmit, const F extends FieldsInput<T> = {}>(options?: Omit<UseFormOptions<T>, 'fields'> & FieldsOf<T, F>) => FormInstance<T, ResolveSubmit<T, TSubmit, F>>;
107
+ };
108
+ /**
109
+ * The name-checked field components and hooks for one form.
110
+ * No new runtime: each member is the plain component / hook with the form's types, so names still resolve
111
+ * relative to the enclosing scope.
112
+ *
113
+ * ```tsx
114
+ * const form = useForm({ initialValues: { email: '', items: [{ name: '' }] } })
115
+ * const F = typed(form)
116
+ * <Form form={form}>
117
+ * <F.Field name="email" /> // 'emial' does not compile
118
+ * <F.ArrayField name="items">
119
+ * {(row) => <row.Field name="name" />} // checked against one item, binds items.<i>.name
120
+ * </F.ArrayField>
121
+ * <F.Watch select={(d) => d.$canSubmit}>{(ok) => <button disabled={!ok}>提交</button>}</F.Watch>
122
+ * </Form>
123
+ * ```
124
+ *
125
+ * `typed<Row>()` (no form) types a component that renders inside a scope — a row, or a reusable fragment under an
126
+ * `<ObjectField name="address">`: `typed<Address>().Field`. Its `useWatch` still reads the root draft; pass the
127
+ * root as the second argument (`typed<Row, Values>()`) to type it.
128
+ * The same object has `createForm` / `useForm`: `typed<Values>().useForm({ fields })` keeps `Values` and still infers
129
+ * which `fields` paths are optional on submit. `useForm<Values>(options)` does not.
130
+ */
131
+ declare function typed<T, TRoot = T>(): TypedForm<T, TRoot>;
132
+ declare function typed<T>(form: FormInstance<T, any>): TypedForm<T>;
133
+
134
+ /**
135
+ * What {@link useFieldDecorator} returns. Library-agnostic: no Ant Design props.
136
+ * Spread `labelProps` / `errorProps` / `descriptionProps` in your own markup, or spread `control`
137
+ * onto a widget that draws its own label and error (Mantine).
138
+ */
139
+ interface FieldDecorator {
140
+ /** DOM id of the control (`htmlFor` / `aria-*` point here). */
141
+ id: string;
142
+ /** `options.label` when passed, otherwise the field title. */
143
+ label: ReactNode;
144
+ /** `options.description` when passed, otherwise the field description. */
145
+ description: ReactNode;
146
+ /**
147
+ * Whether to show the required mark. The field's `required`, hidden in `readPretty`, unless `asterisk` forces it.
148
+ */
149
+ required: boolean;
150
+ errors: readonly string[];
151
+ warnings: readonly string[];
152
+ /** `errors[0]`, for a control that takes one error string. */
153
+ error: string | undefined;
154
+ /** True when `errors` is non-empty. Warnings alone are not invalid. */
155
+ invalid: boolean;
156
+ validating: boolean;
157
+ disabled: boolean;
158
+ readOnly: boolean;
159
+ pattern: Pattern;
160
+ /** Space-separated ids for `aria-describedby`. Undefined when there is nothing to point at. */
161
+ describedBy: string | undefined;
162
+ /** Spread onto `<label>`. `htmlFor` is omitted in `readPretty` (the view is text). */
163
+ labelProps: {
164
+ id: string;
165
+ htmlFor?: string;
166
+ };
167
+ /** Spread onto the description element. Undefined when there is no description. */
168
+ descriptionProps: {
169
+ id: string;
170
+ } | undefined;
171
+ /** Spread onto the error element. Undefined when there is no error. */
172
+ errorProps: {
173
+ id: string;
174
+ role: 'alert';
175
+ } | undefined;
176
+ /** Spread onto the warning element. Undefined when errors win or there is no warning. */
177
+ warningProps: {
178
+ id: string;
179
+ } | undefined;
180
+ /**
181
+ * Props for a control that draws its own label and error. Do not also spread this onto a `connect()`ed
182
+ * control: `connect` already sets `id`, `disabled`, `readOnly`, and `onBlur`.
183
+ */
184
+ control: {
185
+ id: string;
186
+ label: ReactNode;
187
+ description: ReactNode;
188
+ required: boolean;
189
+ error: string | undefined;
190
+ disabled: boolean;
191
+ readOnly: boolean;
192
+ onBlur: () => void;
193
+ 'aria-invalid': true | undefined;
194
+ 'aria-required': true | undefined;
195
+ 'aria-describedby': string | undefined;
196
+ 'aria-errormessage': string | undefined;
197
+ };
198
+ }
199
+ interface FieldDecoratorOptions {
200
+ /** A binding from `useField(name)`. Default: the surrounding `<Field>`. */
201
+ field?: FieldBinding<any>;
202
+ /** Wins over the field title. */
203
+ label?: ReactNode;
204
+ /** Wins over the field description. */
205
+ description?: ReactNode;
206
+ /** Force the required mark on (`true`) or off (`false`). Default: `field.required`, hidden in `readPretty`. */
207
+ asterisk?: boolean;
208
+ }
209
+ /**
210
+ * Label, required mark, description, and errors for the current field, as plain data (not Ant Design props).
211
+ * One hook covers a decorator (`labelProps` + children + `errorProps`) and a control that draws its own
212
+ * chrome (`control`, the Mantine shape). Must run inside `<Field>`, or be given `options.field`.
213
+ *
214
+ * ```tsx
215
+ * function FormItem({ children }: { children?: ReactNode }) {
216
+ * const d = useFieldDecorator()
217
+ * return (
218
+ * <div>
219
+ * <label {...d.labelProps}>{d.label}{d.required && <span>*</span>}</label>
220
+ * {children}
221
+ * {d.descriptionProps && <p {...d.descriptionProps}>{d.description}</p>}
222
+ * {d.errorProps && <p {...d.errorProps}>{d.errors.join('、')}</p>}
223
+ * </div>
224
+ * )
225
+ * }
226
+ * ```
227
+ */
228
+ declare function useFieldDecorator(options?: FieldDecoratorOptions): FieldDecorator;
229
+
230
+ /**
231
+ * Windowed list. `@tanstack/react-virtual` is the scroll engine.
232
+ * Pass the row as `children(index)` — the row should subscribe to its own fields,
233
+ * so a cell edit does not re-render the other mounted rows.
234
+ */
235
+ declare function VirtualRows({ count, height, rowHeight, overscan, children, }: {
236
+ count: number;
237
+ height: number;
238
+ rowHeight?: number;
239
+ overscan?: number;
240
+ children: (index: number) => ReactNode;
241
+ }): react.JSX.Element;
242
+
243
+ export { ArrayContainerSlot, ArrayHandle, ArrayKey, FieldBinding, type FieldDecorator, type FieldDecoratorOptions, FieldProps, FormSubmitHandlers, Reset, type ResetProps, ResetState, type ScopeFields, Submit, type SubmitProps, SubmitState, type TypedForm, UseFieldOptions, UseFormOptions, VirtualRows, typed, useFieldDecorator };
package/dist/index.js ADDED
@@ -0,0 +1,150 @@
1
+ import { useSubmit, useFormMessage, useReset, useForm, Watch, useWatch, useArrayField, useField, Field, ArrayField, ObjectField, useFieldContextOrNull } from './chunk-EYDJ6I7P.js';
2
+ export { ArrayField, ArrayScope, Field, FieldGroup, FieldKit, Form, ObjectField, RowScope, TreeField, UI, VirtualRows, Watch, connect, mapBlur, mapFieldProps, mapProps, mapReadPretty, useArray, useArrayErrors, useArrayField, useField, useFieldGroup, useFieldGroupErrors, useForm, useFormContext, useFormMessage, useIndex, useRecord, useReset, useSubmit, useTreeField, useTreeNode, useWatch } from './chunk-EYDJ6I7P.js';
3
+ import { isValidElement, cloneElement } from 'react';
4
+ import { createForm, ShikiUsageError } from '@shikiform/core/internal';
5
+ import { jsx, Fragment } from 'react/jsx-runtime';
6
+ export { EnumSource, ShikiConflictError, ShikiCycleError, ShikiUsageError, createForm, defineEffects, enUS, get, getDefaultMessages, set, setDefaultMessages, zhCN } from '@shikiform/core';
7
+
8
+ function buttonDom(state) {
9
+ return {
10
+ type: state.type,
11
+ disabled: state.disabled,
12
+ "aria-busy": state["aria-busy"],
13
+ "data-loading": state["data-loading"],
14
+ onClick: state.onClick
15
+ };
16
+ }
17
+ function mergeAsChild(child, behavior, caller) {
18
+ if (!isValidElement(child)) {
19
+ throw new ShikiUsageError(
20
+ `[shikiform] ${caller} asChild expects a single React element, e.g. <${caller} asChild><button>\u4FDD\u5B58</button></${caller}>.`
21
+ );
22
+ }
23
+ const theirs = child.props ?? {};
24
+ const onClick = (event) => {
25
+ theirs.onClick?.(event);
26
+ if (!event.defaultPrevented) behavior.onClick(event);
27
+ };
28
+ return cloneElement(child, {
29
+ ...behavior,
30
+ ...theirs,
31
+ onClick,
32
+ type: theirs.type ?? behavior.type,
33
+ disabled: theirs.disabled ?? ("disabled" in behavior ? behavior.disabled : void 0),
34
+ "aria-busy": theirs["aria-busy"] ?? ("aria-busy" in behavior ? behavior["aria-busy"] : void 0),
35
+ "data-loading": theirs["data-loading"] ?? ("data-loading" in behavior ? behavior["data-loading"] : void 0)
36
+ });
37
+ }
38
+ function Submit({
39
+ asChild,
40
+ children,
41
+ onSubmit,
42
+ onInvalid,
43
+ onSubmitError,
44
+ onClick,
45
+ disabled,
46
+ className,
47
+ ...rest
48
+ }) {
49
+ const options = { onSubmit, onInvalid, onSubmitError, onClick, disabled };
50
+ const state = useSubmit(options);
51
+ const t = useFormMessage();
52
+ if (typeof children === "function") return /* @__PURE__ */ jsx(Fragment, { children: children(state) });
53
+ if (asChild) return mergeAsChild(children, buttonDom(state), "Submit");
54
+ return /* @__PURE__ */ jsx(
55
+ "button",
56
+ {
57
+ ...rest,
58
+ className,
59
+ type: state.type,
60
+ disabled: state.disabled,
61
+ "aria-busy": state["aria-busy"],
62
+ "data-loading": state["data-loading"],
63
+ onClick: state.onClick,
64
+ children: children ?? t("submit")
65
+ }
66
+ );
67
+ }
68
+ function Reset({ asChild, children, values, afterReset, onClick, className, disabled, ...rest }) {
69
+ const options = { values, afterReset, onClick, disabled };
70
+ const state = useReset(options);
71
+ const t = useFormMessage();
72
+ if (typeof children === "function") return /* @__PURE__ */ jsx(Fragment, { children: children(state) });
73
+ if (asChild) {
74
+ return mergeAsChild(children, {
75
+ type: "button",
76
+ disabled: state.disabled,
77
+ onClick: state.onClick
78
+ }, "Reset");
79
+ }
80
+ return /* @__PURE__ */ jsx("button", { ...rest, className, type: "button", disabled: state.disabled, onClick: state.onClick, children: children ?? t("reset") });
81
+ }
82
+ function typed(_form) {
83
+ return handles;
84
+ }
85
+ function TypedArrayField({ children, ...props }) {
86
+ return /* @__PURE__ */ jsx(ArrayField, { ...props, children: children ? (row) => children({ ...row, ...scope }) : void 0 });
87
+ }
88
+ function TypedObjectField({ children, ...props }) {
89
+ return /* @__PURE__ */ jsx(ObjectField, { ...props, children: typeof children === "function" ? children(scope) : children });
90
+ }
91
+ var scope = { Field, ObjectField: TypedObjectField, ArrayField: TypedArrayField };
92
+ var handles = { ...scope, useField, useArrayField, useWatch, Watch, createForm, useForm };
93
+ var NO_FIELD = '[shikiform] useFieldDecorator() reads the surrounding <Field>, but this component is not inside one. Render it as a <Field decorator> (or inside <Field name="\u2026">), or pass the binding: useFieldDecorator({ field }).';
94
+ function present(value) {
95
+ return value != null && value !== false && value !== "";
96
+ }
97
+ function useFieldDecorator(options) {
98
+ const contextual = useFieldContextOrNull();
99
+ const field = options?.field ?? contextual;
100
+ if (!field) throw new ShikiUsageError(NO_FIELD);
101
+ const label = options && options.label !== void 0 ? options.label : field.title;
102
+ const description = options && options.description !== void 0 ? options.description : field.description;
103
+ const required = options?.asterisk !== void 0 ? options.asterisk : field.required && field.pattern !== "readPretty";
104
+ const errors = field.errors;
105
+ const warnings = field.warnings;
106
+ const invalid = errors.length > 0;
107
+ const errorId = invalid ? `${field.id}-error` : void 0;
108
+ const warningId = !invalid && warnings.length > 0 ? `${field.id}-warning` : void 0;
109
+ const descriptionId = present(description) ? `${field.id}-description` : void 0;
110
+ const describedBy = [descriptionId, errorId ?? warningId].filter(Boolean).join(" ") || void 0;
111
+ const labelProps = { id: `${field.id}-label` };
112
+ if (field.pattern !== "readPretty") labelProps.htmlFor = field.id;
113
+ return {
114
+ id: field.id,
115
+ label,
116
+ description,
117
+ required,
118
+ errors,
119
+ warnings,
120
+ error: errors[0],
121
+ invalid,
122
+ validating: field.validating,
123
+ disabled: field.disabled,
124
+ readOnly: field.readOnly,
125
+ pattern: field.pattern,
126
+ describedBy,
127
+ labelProps,
128
+ descriptionProps: descriptionId ? { id: descriptionId } : void 0,
129
+ errorProps: errorId ? { id: errorId, role: "alert" } : void 0,
130
+ warningProps: warningId ? { id: warningId } : void 0,
131
+ control: {
132
+ id: field.id,
133
+ label,
134
+ description,
135
+ required,
136
+ error: errors[0],
137
+ disabled: field.disabled,
138
+ readOnly: field.readOnly,
139
+ onBlur: field.onBlur,
140
+ "aria-invalid": invalid ? true : void 0,
141
+ "aria-required": field.required ? true : void 0,
142
+ "aria-describedby": describedBy,
143
+ "aria-errormessage": errorId
144
+ }
145
+ };
146
+ }
147
+
148
+ export { Reset, Submit, typed, useFieldDecorator };
149
+ //# sourceMappingURL=index.js.map
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/buttons.tsx","../src/factory/typed.tsx","../src/hooks/use-field-decorator.ts"],"names":["jsx","ShikiUsageError"],"mappings":";;;;;;;AAgBA,SAAS,UAAU,KAAA,EAA8D;AAC/E,EAAA,OAAO;AAAA,IACL,MAAM,KAAA,CAAM,IAAA;AAAA,IACZ,UAAU,KAAA,CAAM,QAAA;AAAA,IAChB,WAAA,EAAa,MAAM,WAAW,CAAA;AAAA,IAC9B,cAAA,EAAgB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A,MACzC,kBAAA,EAAoB,WAAA;AAAA,MACpB,mBAAA,EAAqB;AAAA;AACvB,GACF;AACF","file":"index.js","sourcesContent":["import { Children, cloneElement, isValidElement, type ComponentProps, type MouseEvent, type ReactElement, type ReactNode } from 'react'\nimport { ShikiUsageError } from '@shikiform/core/internal'\nimport { useFormMessage } from '../hooks/use-form-message'\nimport { useReset, useSubmit, type ResetState, type SubmitState, type UseResetOptions, type UseSubmitOptions } from '../hooks/use-submit'\nimport type { FormSubmitHandlers } from './fields'\n\ntype ButtonPass = Omit<ComponentProps<'button'>, 'onClick' | 'type' | 'disabled' | 'children'>\n\ntype AsChildBehavior = {\n type: 'submit' | 'button'\n disabled?: boolean\n 'aria-busy'?: true\n 'data-loading'?: ''\n onClick: (event: MouseEvent<HTMLElement>) => void\n}\n\nfunction buttonDom(state: SubmitState<MouseEvent<HTMLElement>>): AsChildBehavior {\n return {\n type: state.type,\n disabled: state.disabled,\n 'aria-busy': state['aria-busy'],\n 'data-loading': state['data-loading'],\n onClick: state.onClick,\n }\n}\n\n/**\n * Put `behavior` on a single element child. The child's own props win, except `onClick` (child, then ours,\n * unless the child calls `preventDefault`) and `disabled` / `type` / busy flags (child wins only when set).\n */\nfunction mergeAsChild(child: ReactNode, behavior: AsChildBehavior, caller: string): ReactElement {\n if (!isValidElement(child)) {\n throw new ShikiUsageError(\n `[shikiform] ${caller} asChild expects a single React element, e.g. <${caller} asChild><button>保存</button></${caller}>.`,\n )\n }\n const theirs = (child.props ?? {}) as Record<string, any>\n const onClick = (event: MouseEvent<HTMLElement>) => {\n theirs.onClick?.(event)\n if (!event.defaultPrevented) behavior.onClick(event)\n }\n return cloneElement(child as ReactElement<Record<string, unknown>>, {\n ...behavior,\n ...theirs,\n onClick,\n type: theirs.type ?? behavior.type,\n disabled: theirs.disabled ?? ('disabled' in behavior ? behavior.disabled : undefined),\n 'aria-busy': theirs['aria-busy'] ?? ('aria-busy' in behavior ? behavior['aria-busy'] : undefined),\n 'data-loading': theirs['data-loading'] ?? ('data-loading' in behavior ? behavior['data-loading'] : undefined),\n })\n}\n\nexport type SubmitProps<T = any> = FormSubmitHandlers<T> & ButtonPass & {\n /**\n * Render your own element and merge submit behavior onto it.\n * `<Submit asChild><button>保存</button></Submit>`.\n */\n asChild?: boolean\n /** Button label, a render prop that receives {@link SubmitState}, or the `asChild` element. */\n children?: ReactNode | ((state: SubmitState<MouseEvent<HTMLButtonElement>>) => ReactNode)\n /** Overrides `!$canSubmit`. */\n disabled?: boolean\n /** Runs first. `preventDefault` skips a self-managed submit (`onSubmit` passed). */\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void\n}\n\n/**\n * Headless submit control for the surrounding form. No Ant Design.\n *\n * - Render prop: `{(state) => <button type={state.type} disabled={state.disabled} onClick={state.onClick}>保存</button>}`.\n * - `asChild`: behavior is merged onto the single child (`disabled`, `type`, `aria-busy`, `data-loading`, `onClick`).\n * - Otherwise a native `<button>`. Label defaults to `messages.submit` (`提交`).\n *\n * Without `onSubmit` the button is `type=\"submit\"` and `<Form onSubmit>` handles it (Enter works the same).\n * With `onSubmit` the click runs `form.submit` itself, so it also works outside a `<form>` element.\n */\nexport function Submit<T = any>({\n asChild, children, onSubmit, onInvalid, onSubmitError, onClick, disabled, className, ...rest\n}: SubmitProps<T>) {\n const options: UseSubmitOptions<T, MouseEvent<HTMLButtonElement>> = { onSubmit, onInvalid, onSubmitError, onClick, disabled }\n const state = useSubmit<T, MouseEvent<HTMLButtonElement>>(options)\n const t = useFormMessage()\n if (typeof children === 'function') return <>{children(state)}</>\n if (asChild) return mergeAsChild(children, buttonDom(state as SubmitState<MouseEvent<HTMLElement>>), 'Submit')\n return (\n <button\n {...rest}\n className={className}\n type={state.type}\n disabled={state.disabled}\n aria-busy={state['aria-busy']}\n data-loading={state['data-loading']}\n onClick={state.onClick}\n >\n {children ?? t('submit')}\n </button>\n )\n}\n\nexport type ResetProps<T = any> = Omit<ButtonPass, 'onClick'> & {\n /** Reset to these values and make them the new initial values (`form.reset(values)`). Default: the current initial values. */\n values?: T\n /**\n * Called after `form.reset`, with the restored values. Use it to query again.\n * `onClick` still runs first; `preventDefault` skips the reset and this callback.\n */\n afterReset?: (values: T) => void\n /** Runs before the reset. `preventDefault` skips the reset. */\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void\n asChild?: boolean\n children?: ReactNode | ((state: ResetState<MouseEvent<HTMLButtonElement>>) => ReactNode)\n className?: string\n disabled?: boolean\n}\n\n/**\n * Headless reset control for the surrounding form: `form.reset()` on click. No Ant Design.\n * `type` is `'button'` so the browser's native reset does not bypass the store.\n * Label defaults to `messages.reset` (`重置`). `afterReset` runs after the values are restored.\n *\n * ```tsx\n * <Reset afterReset={(values) => search(values)} asChild><button>重置</button></Reset>\n * ```\n */\nexport function Reset<T = any>({ asChild, children, values, afterReset, onClick, className, disabled, ...rest }: ResetProps<T>) {\n const options: UseResetOptions<T, MouseEvent<HTMLButtonElement>> = { values, afterReset, onClick, disabled }\n const state = useReset<T, MouseEvent<HTMLButtonElement>>(options)\n const t = useFormMessage()\n if (typeof children === 'function') return <>{children(state)}</>\n if (asChild) {\n return mergeAsChild(children, {\n type: 'button',\n disabled: state.disabled,\n onClick: state.onClick as (event: MouseEvent<HTMLElement>) => void,\n }, 'Reset')\n }\n return (\n <button {...rest} className={className} type=\"button\" disabled={state.disabled} onClick={state.onClick}>\n {children ?? t('reset')}\n </button>\n )\n}\n","import type { ComponentType, ReactNode } from 'react'\nimport { createForm, type DefaultSubmit, type FieldsInput, type FormInstance, type FormOptions, type ResolveSubmit } from '@shikiform/core/internal'\nimport type { ArrayItemOf, ArrayPath, Draft, FieldPath, PathValue } from '@shikiform/core/internal'\nimport { useForm, type UseFormOptions } from '../hooks/use-form'\nimport { ArrayField, Field, ObjectField, Watch, type ArrayContainerSlot, type CheckedFieldProps, type FieldProps } from '../components/fields'\nimport { useArrayField, type ArrayHandle, type ArrayKey } from '../hooks/use-array'\nimport { useField, type FieldBinding, type UseFieldOptions } from '../hooks/use-field'\nimport { useWatch } from '../hooks/use-watch'\n\n/**\n * Field components whose names are checked against `T`, the value at the current scope.\n * Names stay relative at runtime, exactly like the plain components: these are the same components with types.\n * `ArrayField` hands each row the same set typed as one row; `ObjectField` hands its function children the set\n * typed as that object.\n */\nexport type ScopeFields<T> = {\n Field: <N extends FieldPath<T>, C extends ComponentType<any> = ComponentType<any>, D extends ComponentType<any> = ComponentType<any>>(\n props: CheckedFieldProps<T, N, C, D>,\n ) => ReactNode\n ObjectField: <N extends FieldPath<T>>(props: {\n name: N\n display?: FieldProps['display']\n children?: ReactNode | ((scope: ScopeFields<NonNullable<PathValue<T, N & string>>>) => ReactNode)\n }) => ReactNode\n ArrayField: <N extends ArrayPath<T>, C extends ComponentType<any> = ComponentType<any>>(props: {\n name: N\n rowKey?: string\n component?: ArrayContainerSlot<C>\n virtualScroll?: { height: number; rowHeight?: number; overscan?: number }\n children?: (row: ArrayKey & ScopeFields<ArrayItemOf<T, N & string>>) => ReactNode\n }) => ReactNode\n}\n\n/**\n * {@link typed}'s return: {@link ScopeFields} for the form root plus typed hooks.\n * `useField` / `useArrayField` names are relative to the calling component's scope, typed against `T`.\n * `useWatch` / `Watch` select from the root draft (`Draft<TRoot>`).\n */\ntype FieldsOf<T, F> = { fields?: F & FieldsInput<T> }\n\nexport type TypedForm<T, TRoot = T> = ScopeFields<T> & {\n useField: <N extends FieldPath<T>>(name: N, options?: UseFieldOptions<PathValue<T, N & string>>) => FieldBinding<PathValue<T, N & string>>\n useArrayField: <N extends ArrayPath<T>>(name: N, rowKey?: string) => ArrayHandle<ArrayItemOf<T, N & string>>\n useWatch: <S>(select: (d: Draft<TRoot>) => S) => S\n Watch: <S>(props: { select: (d: Draft<TRoot>) => S; children: (value: S) => ReactNode }) => ReactNode\n /**\n * Same `createForm`, with `T` already fixed, so `fields` still decides which `virtual` / `none` paths are optional\n * on submit. `createForm<T>(options)` does not: its submit type is `T`.\n */\n createForm: <TSubmit = DefaultSubmit, const F extends FieldsInput<T> = {}>(\n options?: Omit<FormOptions<T>, 'fields'> & FieldsOf<T, F>,\n ) => FormInstance<T, ResolveSubmit<T, TSubmit, F>>\n /** Same `useForm`. See {@link TypedForm.createForm}. `useForm()` with no arguments is not this; it is an empty form. */\n useForm: <TSubmit = DefaultSubmit, const F extends FieldsInput<T> = {}>(\n options?: Omit<UseFormOptions<T>, 'fields'> & FieldsOf<T, F>,\n ) => FormInstance<T, ResolveSubmit<T, TSubmit, F>>\n}\n\n/**\n * The name-checked field components and hooks for one form.\n * No new runtime: each member is the plain component / hook with the form's types, so names still resolve\n * relative to the enclosing scope.\n *\n * ```tsx\n * const form = useForm({ initialValues: { email: '', items: [{ name: '' }] } })\n * const F = typed(form)\n * <Form form={form}>\n * <F.Field name=\"email\" /> // 'emial' does not compile\n * <F.ArrayField name=\"items\">\n * {(row) => <row.Field name=\"name\" />} // checked against one item, binds items.<i>.name\n * </F.ArrayField>\n * <F.Watch select={(d) => d.$canSubmit}>{(ok) => <button disabled={!ok}>提交</button>}</F.Watch>\n * </Form>\n * ```\n *\n * `typed<Row>()` (no form) types a component that renders inside a scope — a row, or a reusable fragment under an\n * `<ObjectField name=\"address\">`: `typed<Address>().Field`. Its `useWatch` still reads the root draft; pass the\n * root as the second argument (`typed<Row, Values>()`) to type it.\n * The same object has `createForm` / `useForm`: `typed<Values>().useForm({ fields })` keeps `Values` and still infers\n * which `fields` paths are optional on submit. `useForm<Values>(options)` does not.\n */\nexport function typed<T, TRoot = T>(): TypedForm<T, TRoot>\nexport function typed<T>(form: FormInstance<T, any>): TypedForm<T>\nexport function typed(_form?: FormInstance<any, any>): TypedForm<any> {\n return handles\n}\n\nfunction TypedArrayField({ children, ...props }: { name: string; rowKey?: string; component?: ArrayContainerSlot; virtualScroll?: { height: number; rowHeight?: number; overscan?: number }; children?: (row: any) => ReactNode }) {\n return <ArrayField {...props}>{children ? (row) => children({ ...row, ...scope }) : undefined}</ArrayField>\n}\nfunction TypedObjectField({ children, ...props }: { name: string; display?: FieldProps['display']; children?: ReactNode | ((scope: any) => ReactNode) }) {\n return <ObjectField {...props}>{typeof children === 'function' ? children(scope) : children}</ObjectField>\n}\n\nconst scope = { Field, ObjectField: TypedObjectField, ArrayField: TypedArrayField }\nconst handles = { ...scope, useField, useArrayField, useWatch, Watch, createForm, useForm } as unknown as TypedForm<any>\n","import type { ReactNode } from 'react'\nimport type { Pattern } from '@shikiform/core/internal'\nimport { ShikiUsageError } from '@shikiform/core/internal'\nimport { useFieldContextOrNull } from '../field-context'\nimport type { FieldBinding } from './use-field'\n\n/**\n * What {@link useFieldDecorator} returns. Library-agnostic: no Ant Design props.\n * Spread `labelProps` / `errorProps` / `descriptionProps` in your own markup, or spread `control`\n * onto a widget that draws its own label and error (Mantine).\n */\nexport interface FieldDecorator {\n /** DOM id of the control (`htmlFor` / `aria-*` point here). */\n id: string\n /** `options.label` when passed, otherwise the field title. */\n label: ReactNode\n /** `options.description` when passed, otherwise the field description. */\n description: ReactNode\n /**\n * Whether to show the required mark. The field's `required`, hidden in `readPretty`, unless `asterisk` forces it.\n */\n required: boolean\n errors: readonly string[]\n warnings: readonly string[]\n /** `errors[0]`, for a control that takes one error string. */\n error: string | undefined\n /** True when `errors` is non-empty. Warnings alone are not invalid. */\n invalid: boolean\n validating: boolean\n disabled: boolean\n readOnly: boolean\n pattern: Pattern\n /** Space-separated ids for `aria-describedby`. Undefined when there is nothing to point at. */\n describedBy: string | undefined\n /** Spread onto `<label>`. `htmlFor` is omitted in `readPretty` (the view is text). */\n labelProps: { id: string; htmlFor?: string }\n /** Spread onto the description element. Undefined when there is no description. */\n descriptionProps: { id: string } | undefined\n /** Spread onto the error element. Undefined when there is no error. */\n errorProps: { id: string; role: 'alert' } | undefined\n /** Spread onto the warning element. Undefined when errors win or there is no warning. */\n warningProps: { id: string } | undefined\n /**\n * Props for a control that draws its own label and error. Do not also spread this onto a `connect()`ed\n * control: `connect` already sets `id`, `disabled`, `readOnly`, and `onBlur`.\n */\n control: {\n id: string\n label: ReactNode\n description: ReactNode\n required: boolean\n error: string | undefined\n disabled: boolean\n readOnly: boolean\n onBlur: () => void\n 'aria-invalid': true | undefined\n 'aria-required': true | undefined\n 'aria-describedby': string | undefined\n 'aria-errormessage': string | undefined\n }\n}\n\nexport interface FieldDecoratorOptions {\n /** A binding from `useField(name)`. Default: the surrounding `<Field>`. */\n field?: FieldBinding<any>\n /** Wins over the field title. */\n label?: ReactNode\n /** Wins over the field description. */\n description?: ReactNode\n /** Force the required mark on (`true`) or off (`false`). Default: `field.required`, hidden in `readPretty`. */\n asterisk?: boolean\n}\n\nconst NO_FIELD =\n '[shikiform] useFieldDecorator() reads the surrounding <Field>, but this component is not inside one. ' +\n 'Render it as a <Field decorator> (or inside <Field name=\"…\">), or pass the binding: useFieldDecorator({ field }).'\n\nfunction present(value: ReactNode): boolean {\n return value != null && value !== false && value !== ''\n}\n\n/**\n * Label, required mark, description, and errors for the current field, as plain data (not Ant Design props).\n * One hook covers a decorator (`labelProps` + children + `errorProps`) and a control that draws its own\n * chrome (`control`, the Mantine shape). Must run inside `<Field>`, or be given `options.field`.\n *\n * ```tsx\n * function FormItem({ children }: { children?: ReactNode }) {\n * const d = useFieldDecorator()\n * return (\n * <div>\n * <label {...d.labelProps}>{d.label}{d.required && <span>*</span>}</label>\n * {children}\n * {d.descriptionProps && <p {...d.descriptionProps}>{d.description}</p>}\n * {d.errorProps && <p {...d.errorProps}>{d.errors.join('、')}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useFieldDecorator(options?: FieldDecoratorOptions): FieldDecorator {\n const contextual = useFieldContextOrNull()\n const field = options?.field ?? contextual\n if (!field) throw new ShikiUsageError(NO_FIELD)\n const label = options && options.label !== undefined ? options.label : field.title\n const description = options && options.description !== undefined ? options.description : field.description\n const required = options?.asterisk !== undefined ? options.asterisk : field.required && field.pattern !== 'readPretty'\n const errors = field.errors\n const warnings = field.warnings\n const invalid = errors.length > 0\n const errorId = invalid ? `${field.id}-error` : undefined\n const warningId = !invalid && warnings.length > 0 ? `${field.id}-warning` : undefined\n const descriptionId = present(description) ? `${field.id}-description` : undefined\n const describedBy = [descriptionId, errorId ?? warningId].filter(Boolean).join(' ') || undefined\n const labelProps: FieldDecorator['labelProps'] = { id: `${field.id}-label` }\n if (field.pattern !== 'readPretty') labelProps.htmlFor = field.id\n return {\n id: field.id,\n label,\n description,\n required,\n errors,\n warnings,\n error: errors[0],\n invalid,\n validating: field.validating,\n disabled: field.disabled,\n readOnly: field.readOnly,\n pattern: field.pattern,\n describedBy,\n labelProps,\n descriptionProps: descriptionId ? { id: descriptionId } : undefined,\n errorProps: errorId ? { id: errorId, role: 'alert' } : undefined,\n warningProps: warningId ? { id: warningId } : undefined,\n control: {\n id: field.id,\n label,\n description,\n required,\n error: errors[0],\n disabled: field.disabled,\n readOnly: field.readOnly,\n onBlur: field.onBlur,\n 'aria-invalid': invalid ? true : undefined,\n 'aria-required': field.required ? true : undefined,\n 'aria-describedby': describedBy,\n 'aria-errormessage': errorId,\n },\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { c as FieldBinding } from './use-watch-BZlpyvHw.js';
2
+ export { ai as ArrayContext, g as ArrayField, b as ArrayKey, B as BlurFlag, j as BlurOn, l as ComponentStatics, m as ConnectEnhancer, n as ConnectFieldProps, o as ConnectedComponent, aj as DragProps, s as FieldGroup, ak as FieldGroupStore, x as FieldPropKey, z as FieldStateKey, D as Form, al as FormContext, F as FormSubmitHandlers, am as PropsEnhancer, P as PropsMapping, H as PropsTransform, an as ReadPrettyEnhancer, L as RowScope, ao as RowWrapContext, ap as ScopeContext, Z as connect, _ as mapBlur, $ as mapFieldProps, a0 as mapProps, a1 as mapReadPretty, a2 as useArray, aq as useArrayAt, a3 as useArrayErrors, ar as useFieldGroupRegistration, a8 as useForm, aa as useFormMessage, as as useGroupsErrors, ab as useIndex, ac as useRecord, at as useRequiredForm, ad as useReset, au as useScope, ae as useSubmit, av as useUiNodeOrNull, ah as useWatch, aw as valueFromEvent } from './use-watch-BZlpyvHw.js';
3
+ import * as react from 'react';
4
+ import { ReactNode } from 'react';
5
+ import '@shikiform/core/internal';
6
+
7
+ /**
8
+ * Internal, outside-field tolerant read: the surrounding field, or `null`. For components (`FormItem`, `connect`)
9
+ * that throw their own, more specific error. Public code uses `useField()` with no name.
10
+ */
11
+ declare function useFieldContextOrNull<TValue = any>(): FieldBinding<TValue> | null;
12
+
13
+ /**
14
+ * Internal prefix for field DOM ids. `<Form>` and shadow drafts provide it.
15
+ * Not a public component: two forms on one page must not share `id="email"`.
16
+ */
17
+ declare function IdPrefixProvider({ prefix, children }: {
18
+ prefix: string;
19
+ children: ReactNode;
20
+ }): react.JSX.Element;
21
+ /**
22
+ * Prefix for one `<Form>` (or a shadow draft, which has no `id` prop).
23
+ * An explicit `id` wins; otherwise React `useId()`. `useId` always runs.
24
+ */
25
+ declare function useAutoIdPrefix(explicit?: string): string;
26
+
27
+ export { FieldBinding, IdPrefixProvider, useAutoIdPrefix, useFieldContextOrNull };
@@ -0,0 +1,3 @@
1
+ export { ArrayContext, ArrayField, FieldGroup, FieldGroupStore, Form, FormContext, IdPrefixProvider, RowScope, RowWrapContext, ScopeContext, connect, mapBlur, mapFieldProps, mapProps, mapReadPretty, useArray, useArrayAt, useArrayErrors, useAutoIdPrefix, useFieldContextOrNull, useFieldGroupRegistration, useForm, useFormMessage, useGroupsErrors, useIndex, useRecord, useRequiredForm, useReset, useScope, useSubmit, useUiNodeOrNull, useWatch, valueFromEvent } from './chunk-EYDJ6I7P.js';
2
+ //# sourceMappingURL=internal.js.map
3
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"internal.js"}