@shikiform/react 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DQHRLKQS.js → chunk-A54EUYGM.js} +303 -137
- package/dist/chunk-A54EUYGM.js.map +1 -0
- package/dist/index.d.ts +17 -28
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +71 -4
- package/dist/internal.js +1 -1
- package/dist/{use-watch-9vSz8P44.d.ts → use-watch-BJDsp7Zo.d.ts} +182 -164
- package/package.json +2 -2
- package/dist/chunk-DQHRLKQS.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useSubmit, useFormMessage, useReset, useForm, Watch, useWatch, useArrayField, useField, Field, ArrayField, ObjectField, TreeField, useFieldContextOrNull } from './chunk-
|
|
2
|
-
export { ArrayField, Field,
|
|
1
|
+
import { useSubmit, useFormMessage, useReset, useForm, Watch, useWatch, useArrayField, useField, Field, ArrayField, ObjectField, TreeField, useFieldContextOrNull } from './chunk-A54EUYGM.js';
|
|
2
|
+
export { ArrayField, Field, FieldKit, Form, ObjectField, TreeField, UI, Watch, connect, mapProps, useArrayField, useField, useForm, useFormContext, useIndex, useRecord, useTreeField, useWatch } from './chunk-A54EUYGM.js';
|
|
3
3
|
import { isValidElement, cloneElement } from 'react';
|
|
4
4
|
import { createForm, ShikiUsageError } from '@shikiform/core/internal';
|
|
5
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';
|
|
6
|
+
export { EnumSource, ShikiConflictError, ShikiCycleError, ShikiUsageError, SubmitSupersededError, SubmitUnstableError, createForm, defineEffects, enUS, get, getDefaultMessages, isFieldErrors, set, setDefaultMessages, zhCN } from '@shikiform/core';
|
|
7
7
|
|
|
8
8
|
function buttonDom(state) {
|
|
9
9
|
return {
|
|
@@ -103,7 +103,7 @@ function useFieldDecorator(options) {
|
|
|
103
103
|
if (!field) throw new ShikiUsageError(NO_FIELD);
|
|
104
104
|
const label = options && options.label !== void 0 ? options.label : field.title;
|
|
105
105
|
const description = options && options.description !== void 0 ? options.description : field.description;
|
|
106
|
-
const required = options?.asterisk !== void 0 ? options.asterisk : field.required && field.
|
|
106
|
+
const required = options?.asterisk !== void 0 ? options.asterisk : field.required && !field.readOnly;
|
|
107
107
|
const errors = field.errors;
|
|
108
108
|
const warnings = field.warnings;
|
|
109
109
|
const invalid = errors.length > 0;
|
|
@@ -112,7 +112,7 @@ function useFieldDecorator(options) {
|
|
|
112
112
|
const descriptionId = present(description) ? `${field.id}-description` : void 0;
|
|
113
113
|
const describedBy = [descriptionId, errorId ?? warningId].filter(Boolean).join(" ") || void 0;
|
|
114
114
|
const labelProps = { id: `${field.id}-label` };
|
|
115
|
-
if (field.
|
|
115
|
+
if (!field.readOnly) labelProps.htmlFor = field.id;
|
|
116
116
|
return {
|
|
117
117
|
id: field.id,
|
|
118
118
|
label,
|
|
@@ -123,9 +123,9 @@ function useFieldDecorator(options) {
|
|
|
123
123
|
error: errors[0],
|
|
124
124
|
invalid,
|
|
125
125
|
validating: field.validating,
|
|
126
|
+
visible: field.visible,
|
|
126
127
|
disabled: field.disabled,
|
|
127
128
|
readOnly: field.readOnly,
|
|
128
|
-
pattern: field.pattern,
|
|
129
129
|
describedBy,
|
|
130
130
|
labelProps,
|
|
131
131
|
descriptionProps: descriptionId ? { id: descriptionId } : void 0,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,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AA,IAC9C,OAAA,EAAS;AAAA,MACP,IAAI,KAAA,CAAM,EAAA;AAAA,MACV,KAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,MACf,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,cAAA,EAAgB,UAAU,IAAA,GAAO,MAAA;AAAA,MACjC,eAAA,EAAiB,KAAA,CAAM,QAAA,GAAW,IAAA,GAAO,MAAA;AAAA,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, TreeField, Watch, type ArrayContainerSlot, type CheckedFieldProps, type FieldProps, type TreeNodeRender } 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 TreeField: <N extends ArrayPath<T>>(props: {\n name: N\n childrenKey?: string\n rowKey?: string\n children: (node: TreeNodeRender & 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}\nfunction TypedTreeField({ children, ...props }: { name: string; childrenKey?: string; rowKey?: string; children: (node: any) => ReactNode }) {\n return <TreeField {...props}>{(node) => children({ ...node, ...scope })}</TreeField>\n}\n\nconst scope = { Field, ObjectField: TypedObjectField, ArrayField: TypedArrayField, TreeField: TypedTreeField }\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"]}
|
|
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,MAAM,cAAc,CAAA;AAAA,IACpC,SAAS,KAAA,CAAM;AAAA,GACjB;AACF;AAMA,SAAS,YAAA,CAAa,KAAA,EAAkB,QAAA,EAA2B,MAAA,EAA8B;AAC/F,EAAA,IAAI,CAAC,cAAA,CAAe,KAAK,CAAA,EAAG;AAC1B,IAAA,MAAM,IAAI,eAAA;AAAA,MACR,CAAA,YAAA,EAAe,MAAM,CAAA,+CAAA,EAAkD,MAAM,2CAAiC,MAAM,CAAA,EAAA;AAAA,KACtH;AAAA,EACF;AACA,EAAA,MAAM,MAAA,GAAU,KAAA,CAAM,KAAA,IAAS,EAAC;AAChC,EAAA,MAAM,OAAA,GAAU,CAAC,KAAA,KAAmC;AAClD,IAAA,MAAA,CAAO,UAAU,KAAK,CAAA;AACtB,IAAA,IAAI,CAAC,KAAA,CAAM,gBAAA,EAAkB,QAAA,CAAS,QAAQ,KAAK,CAAA;AAAA,EACrD,CAAA;AACA,EAAA,OAAO,aAAa,KAAA,EAAgD;AAAA,IAClE,GAAG,QAAA;AAAA,IACH,GAAG,MAAA;AAAA,IACH,OAAA;AAAA,IACA,IAAA,EAAM,MAAA,CAAO,IAAA,IAAQ,QAAA,CAAS,IAAA;AAAA,IAC9B,UAAU,MAAA,CAAO,QAAA,KAAa,UAAA,IAAc,QAAA,GAAW,SAAS,QAAA,GAAW,MAAA,CAAA;AAAA,IAC3E,WAAA,EAAa,OAAO,WAAW,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gBAAA,EAAkB,aAAA,GAAgB,EAAE,EAAA,EAAI,eAAc,GAAI,MAAA;AAAA,IAC1D,YAAY,OAAA,GAAU,EAAE,IAAI,OAAA,EAAS,IAAA,EAAM,SAAQ,GAAI,MAAA;AAAA,IACvD,YAAA,EAAc,SAAA,GAAY,EAAE,EAAA,EAAI,WAAU,GAAI,MAAA;AAAA,IAC9C,OAAA,EAAS;AAAA,MACP,IAAI,KAAA,CAAM,EAAA;AAAA,MACV,KAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,MACf,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,cAAA,EAAgB,UAAU,IAAA,GAAO,MAAA;AAAA,MACjC,eAAA,EAAiB,KAAA,CAAM,QAAA,GAAW,IAAA,GAAO,MAAA;AAAA,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, TreeField, Watch, type ArrayContainerSlot, type CheckedFieldProps, type FieldProps, type TreeNodeRender } 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 visible?: FieldProps['visible']\n disabled?: FieldProps['disabled']\n readOnly?: FieldProps['readOnly']\n omit?: FieldProps['omit']\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 TreeField: <N extends ArrayPath<T>>(props: {\n name: N\n childrenKey?: string\n rowKey?: string\n children: (node: TreeNodeRender & 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, opts?: { rowKey?: string }) => ArrayHandle<ArrayItemOf<T, N & string>>) & (() => ArrayHandle<unknown>)\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 `omit: true` 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; visible?: boolean; disabled?: boolean; readOnly?: boolean; omit?: boolean; children?: ReactNode | ((scope: any) => ReactNode) }) {\n return <ObjectField {...props}>{typeof children === 'function' ? children(scope) : children}</ObjectField>\n}\nfunction TypedTreeField({ children, ...props }: { name: string; childrenKey?: string; rowKey?: string; children: (node: any) => ReactNode }) {\n return <TreeField {...props}>{(node) => children({ ...node, ...scope })}</TreeField>\n}\n\nconst scope = { Field, ObjectField: TypedObjectField, ArrayField: TypedArrayField, TreeField: TypedTreeField }\nconst handles = { ...scope, useField, useArrayField, useWatch, Watch, createForm, useForm } as unknown as TypedForm<any>\n","import type { ReactNode } from 'react'\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 when `readOnly`, 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 visible: boolean\n disabled: boolean\n readOnly: boolean\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 when `readOnly` (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 when `readOnly`. */\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.readOnly\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.readOnly) 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 visible: field.visible,\n disabled: field.disabled,\n readOnly: field.readOnly,\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"]}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as FieldBinding,
|
|
2
|
-
export {
|
|
1
|
+
import { c as FieldBinding, H as ScopeValue } from './use-watch-BJDsp7Zo.js';
|
|
2
|
+
export { a5 as ArrayContext, g as ArrayField, b as ArrayKey, a6 as ArrayScope, B as BlurFlag, i as BlurOn, j as ComponentStatics, k as ConnectEnhancer, l as ConnectFieldProps, m as ConnectedComponent, a7 as DragProps, a8 as FieldContext, t as FieldPropKey, v as FieldStateKey, w as Form, a9 as FormContext, F as FormSubmitHandlers, aa as PropsEnhancer, P as PropsMapping, z as PropsTransform, ab as RowScope, ac as RowWrapContext, ad as ScopeContext, ae as TreeContext, af as TreeScope, ag as UiNodeContext, X as connect, Y as mapProps, ah as useArrayAt, Z as useArrayField, $ as useForm, a1 as useIndex, a2 as useRecord, ai as useRequiredForm, aj as useReset, ak as useScope, al as useSubmit, am as useTreeAt, a3 as useTreeField, an as useUiNodeOrNull, a4 as useWatch, ao as valueFromEvent } from './use-watch-BJDsp7Zo.js';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
|
-
import { FormEngine } from '@shikiform/core/internal';
|
|
5
|
+
import { FieldError, FormEngine, FormMessageKey, MessageArgs } from '@shikiform/core/internal';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Windowed list. `@tanstack/react-virtual` is the scroll engine.
|
|
@@ -23,6 +23,73 @@ declare function VirtualRows({ count, height, rowHeight, overscan, children, }:
|
|
|
23
23
|
*/
|
|
24
24
|
declare function useFieldContextOrNull<TValue = any>(): FieldBinding<TValue> | null;
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A set of field paths collected from the JSX below a {@link FieldGroup}: every `<Field>` / `useField(name)` /
|
|
28
|
+
* `<ArrayField>` mounted inside registers its absolute path while mounted (nested groups register into every
|
|
29
|
+
* enclosing group). It owns no state of the form; it only answers "which fields are inside this region".
|
|
30
|
+
*
|
|
31
|
+
* Layout containers use it to badge a tab with the errors of its fields (`FormTab`, `FormCollapse`) and to validate
|
|
32
|
+
* one step (`FormStep`: `form.validate(group.paths())`). A pure-layout `FormItem` could aggregate its children's
|
|
33
|
+
* errors the same way.
|
|
34
|
+
*/
|
|
35
|
+
interface FieldGroupHandle {
|
|
36
|
+
/** Absolute paths mounted inside the group, in mount order. A path mounted twice is listed once. */
|
|
37
|
+
paths(): string[];
|
|
38
|
+
/** Called after a path is added or removed. */
|
|
39
|
+
subscribe(listener: () => void): () => void;
|
|
40
|
+
/** Bumped on every add / remove (a `useSyncExternalStore` snapshot). */
|
|
41
|
+
version(): number;
|
|
42
|
+
}
|
|
43
|
+
/** Internal: the registry behind a {@link FieldGroupHandle}. */
|
|
44
|
+
declare class FieldGroupStore implements FieldGroupHandle {
|
|
45
|
+
private counts;
|
|
46
|
+
private listeners;
|
|
47
|
+
private ver;
|
|
48
|
+
paths: () => string[];
|
|
49
|
+
version: () => number;
|
|
50
|
+
subscribe: (listener: () => void) => (() => void);
|
|
51
|
+
/** Register `path` until the returned function runs. */
|
|
52
|
+
add(path: string): () => void;
|
|
53
|
+
private changed;
|
|
54
|
+
}
|
|
55
|
+
/** Internal: `add(path)` registers into the nearest group and every group around it. */
|
|
56
|
+
interface GroupRegistrar {
|
|
57
|
+
add(path: string): () => void;
|
|
58
|
+
}
|
|
59
|
+
declare const FieldGroupContext: react.Context<GroupRegistrar | null>;
|
|
60
|
+
/** Create a group handle that lives as long as the component (pass it to {@link FieldGroup}). */
|
|
61
|
+
declare function useFieldGroup(): FieldGroupHandle;
|
|
62
|
+
/**
|
|
63
|
+
* Collect the fields rendered inside `children` into `value` (from {@link useFieldGroup}). Renders no DOM.
|
|
64
|
+
*
|
|
65
|
+
* ```tsx
|
|
66
|
+
* const group = useFieldGroup()
|
|
67
|
+
* const errors = useFieldGroupErrors(group) // FieldError[] of the fields inside
|
|
68
|
+
* <FieldGroup value={group}><Field name="a" … /><Field name="b" … /></FieldGroup>
|
|
69
|
+
* await form.validate(group.paths()) // validate only those fields
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function FieldGroup({ value, children }: {
|
|
73
|
+
value: FieldGroupHandle;
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}): react.JSX.Element;
|
|
76
|
+
/** Internal: register `path` with the enclosing groups while mounted (`useField(name)`, `useArrayField(name)`). No path skips it. */
|
|
77
|
+
declare function useFieldGroupRegistration(path: string | undefined): void;
|
|
78
|
+
/** Internal: the shown errors of each group (one entry per field with messages), re-rendering when they change. */
|
|
79
|
+
declare function useGroupsErrors(form: FormEngine<any, any>, groups: readonly FieldGroupHandle[]): FieldError[][];
|
|
80
|
+
/**
|
|
81
|
+
* The errors of the fields inside a {@link FieldGroup}: one `{ path, messages }` per field with shown errors
|
|
82
|
+
* (hidden, disabled and read-only fields excluded), re-rendering only when that list changes. `errors.length` is a tab's badge count.
|
|
83
|
+
*/
|
|
84
|
+
declare function useFieldGroupErrors(group: FieldGroupHandle): FieldError[];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Resolve built-in texts for the nearest form: its `messages` → `setDefaultMessages` → `zhCN`.
|
|
88
|
+
* Outside a form only the app defaults apply. Component labels in `@shikiform/antd` read through this,
|
|
89
|
+
* so a custom component can follow the same locale: `const t = useFormMessage(); t('submit')`.
|
|
90
|
+
*/
|
|
91
|
+
declare function useFormMessage(): <K extends FormMessageKey>(key: K, ...params: MessageArgs<K>) => string;
|
|
92
|
+
|
|
26
93
|
/**
|
|
27
94
|
* Internal prefix for field DOM ids. `<Form>` and shadow drafts provide it.
|
|
28
95
|
* Not a public component: two forms on one page must not share `id="email"`.
|
|
@@ -45,4 +112,4 @@ declare function useAutoIdPrefix(explicit?: string): string;
|
|
|
45
112
|
*/
|
|
46
113
|
declare function resolveName(form: FormEngine<any, any>, scope: ScopeValue, name: string): string;
|
|
47
114
|
|
|
48
|
-
export { FieldBinding, IdPrefixProvider, VirtualRows, resolveName, useAutoIdPrefix, useFieldContextOrNull };
|
|
115
|
+
export { FieldBinding, FieldGroup, FieldGroupContext, type FieldGroupHandle, FieldGroupStore, IdPrefixProvider, VirtualRows, resolveName, useAutoIdPrefix, useFieldContextOrNull, useFieldGroup, useFieldGroupErrors, useFieldGroupRegistration, useFormMessage, useGroupsErrors };
|
package/dist/internal.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ArrayContext, ArrayField, ArrayScope, FieldContext, FieldGroup, FieldGroupContext, FieldGroupStore, Form, FormContext, IdPrefixProvider, RowScope, RowWrapContext, ScopeContext, UiNodeContext, VirtualRows, connect, mapProps, resolveName,
|
|
1
|
+
export { ArrayContext, ArrayField, ArrayScope, FieldContext, FieldGroup, FieldGroupContext, FieldGroupStore, Form, FormContext, IdPrefixProvider, RowScope, RowWrapContext, ScopeContext, TreeContext, TreeScope, UiNodeContext, VirtualRows, connect, mapProps, resolveName, useArrayAt, useArrayField, useAutoIdPrefix, useFieldContextOrNull, useFieldGroup, useFieldGroupErrors, useFieldGroupRegistration, useForm, useFormMessage, useGroupsErrors, useIndex, useRecord, useRequiredForm, useReset, useScope, useSubmit, useTreeAt, useTreeField, useUiNodeOrNull, useWatch, valueFromEvent } from './chunk-A54EUYGM.js';
|
|
2
2
|
//# sourceMappingURL=internal.js.map
|
|
3
3
|
//# sourceMappingURL=internal.js.map
|