@rockshin/tao-ui 0.0.43 → 0.0.44
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/README.md +1 -1
- package/component-manifest.json +4 -2
- package/dist/components/form/field-control.d.ts +6 -0
- package/dist/components/form/field-control.js +42 -0
- package/dist/components/form/form-context.d.ts +3 -0
- package/dist/components/form/form-item.d.ts +2 -1
- package/dist/components/form/form-item.js +55 -42
- package/dist/components/form/form.d.ts +5 -5
- package/dist/components/form/form.js +86 -68
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/use-form.d.ts +16 -0
- package/dist/components/form/use-form.js +69 -0
- package/dist/components/form-field/form-field-view.d.ts +4 -2
- package/dist/components/form-field/form-field-view.js +42 -35
- package/dist/docs/components/form.doc.js +3 -1
- package/dist/entries/form.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/llms.txt +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ export default function App() {
|
|
|
43
43
|
|
|
44
44
|
### Accessibility
|
|
45
45
|
|
|
46
|
-
Use `FormField` or `Form.Item` to label controls and associate help/validation messages. Input, Textarea, InputNumber, Select, Checkbox, Radio, Switch and the date pickers forward field ARIA attributes to their interactive elements; CheckboxGroup and RadioGroup expose group labels and validation messages. Placeholders are not a substitute for a label.
|
|
46
|
+
Use `FormField` or `Form.Item` to label controls and associate help/validation messages. Input, Textarea, InputNumber, Select, Checkbox, Radio, Switch and the date pickers forward field ARIA attributes to their interactive elements; CheckboxGroup and RadioGroup expose group labels and validation messages. Placeholders are not a substitute for a label. For long forms, call `form.scrollToField(name, { focus: true })` using `Form.useForm()`, the Form ref or `Form.useFormInstance()`; nested and full `Form.List` paths are supported. Custom controls must forward `ref` or `id`, and the target field must be mounted.
|
|
47
47
|
|
|
48
48
|
Radio maps `aria-required` to native `required`; an explicit `required` prop takes precedence. Group options retain their native disabled state, including explicit `disabled={false}` overrides.
|
|
49
49
|
|
package/component-manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"packageName": "@rockshin/tao-ui",
|
|
4
|
-
"generatedAt": "2026-11-
|
|
4
|
+
"generatedAt": "2026-11-05T15:23:43.221Z",
|
|
5
5
|
"components": [
|
|
6
6
|
{
|
|
7
7
|
"name": "affix",
|
|
@@ -1020,7 +1020,8 @@
|
|
|
1020
1020
|
"source": "src/components/form/form.tsx",
|
|
1021
1021
|
"story": "stories/form.stories.tsx",
|
|
1022
1022
|
"tests": [
|
|
1023
|
-
"tests/form/form.test.tsx"
|
|
1023
|
+
"tests/form/form.test.tsx",
|
|
1024
|
+
"tests/form/form-scroll.test.tsx"
|
|
1024
1025
|
],
|
|
1025
1026
|
"semanticParts": [
|
|
1026
1027
|
"root"
|
|
@@ -1043,6 +1044,7 @@
|
|
|
1043
1044
|
"Declare validation as rules on Form.Item; the required mark is inferred from rules.",
|
|
1044
1045
|
"Use dependencies for cross-field rules such as password confirmation.",
|
|
1045
1046
|
"Use Form.useForm() for imperative control (setFieldsValue, resetFields, submit).",
|
|
1047
|
+
"Call form.scrollToField(name, { focus: true }) to reveal a mounted field, including full Form.List paths; custom controls must forward ref or id.",
|
|
1046
1048
|
"Set size or disabled on Form to cascade them to every control inside."
|
|
1047
1049
|
],
|
|
1048
1050
|
"avoid": [
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
/** Register the actual control, including noStyle and Form.List fields. */
|
|
3
|
+
export declare function FieldControl({ name, children, }: {
|
|
4
|
+
name: (string | number)[];
|
|
5
|
+
children: ReactElement<Record<string, unknown>>;
|
|
6
|
+
}): ReactElement<Record<string, unknown>, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getNodeRef, supportNodeRef } from "@rc-component/util/es/ref";
|
|
2
|
+
import useLayoutEffect from "@rc-component/util/es/hooks/useLayoutEffect";
|
|
3
|
+
import { cloneElement, useId, useMemo } from "react";
|
|
4
|
+
import { mergeRefs } from "../../utils/refs.js";
|
|
5
|
+
import { useFormLayout } from "./form-context.js";
|
|
6
|
+
import { fieldKey } from "./use-form.js";
|
|
7
|
+
function FieldControl({ name, children }) {
|
|
8
|
+
const { fields } = useFormLayout();
|
|
9
|
+
const generatedId = useId();
|
|
10
|
+
const id = 'string' == typeof children.props.id ? children.props.id : `${generatedId}-control`;
|
|
11
|
+
const key = fieldKey(name);
|
|
12
|
+
const target = useMemo(()=>({
|
|
13
|
+
id,
|
|
14
|
+
instance: null
|
|
15
|
+
}), [
|
|
16
|
+
id
|
|
17
|
+
]);
|
|
18
|
+
const childRef = getNodeRef(children);
|
|
19
|
+
const ref = useMemo(()=>mergeRefs((instance)=>{
|
|
20
|
+
target.instance = instance;
|
|
21
|
+
}, childRef), [
|
|
22
|
+
target,
|
|
23
|
+
childRef
|
|
24
|
+
]);
|
|
25
|
+
useLayoutEffect(()=>{
|
|
26
|
+
fields?.set(key, target);
|
|
27
|
+
return ()=>{
|
|
28
|
+
fields?.delete(key);
|
|
29
|
+
};
|
|
30
|
+
}, [
|
|
31
|
+
fields,
|
|
32
|
+
key,
|
|
33
|
+
target
|
|
34
|
+
]);
|
|
35
|
+
return /*#__PURE__*/ cloneElement(children, {
|
|
36
|
+
id,
|
|
37
|
+
...supportNodeRef(children) ? {
|
|
38
|
+
ref
|
|
39
|
+
} : {}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { FieldControl };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { FormFieldLayout } from '../form-field/form-field-view.js';
|
|
2
|
+
import type { FieldTarget, FormInstance } from './use-form.js';
|
|
2
3
|
export interface FormLayoutContextValue {
|
|
3
4
|
layout: FormFieldLayout;
|
|
5
|
+
form?: FormInstance;
|
|
6
|
+
fields?: Map<string, FieldTarget>;
|
|
4
7
|
}
|
|
5
8
|
/** Internal layout channel: Form → Form.Item. */
|
|
6
9
|
export declare const FormLayoutContext: import("react").Context<FormLayoutContextValue>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Meta, type NamePath, type Rule } from '@rc-component/form';
|
|
2
2
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
3
3
|
import type { TaoStatus } from '../../provider/tao-provider.js';
|
|
4
4
|
import type { SemanticClassNames, SemanticStyles } from '../../utils/semantic.js';
|
|
5
|
+
import type { FormInstance } from './use-form.js';
|
|
5
6
|
export type FormItemSemanticPart = 'root' | 'label' | 'error' | 'description';
|
|
6
7
|
export type FormItemValidateStatus = TaoStatus;
|
|
7
8
|
export type FormItemChildren<Values = Record<string, unknown>> = ReactNode | ((control: Record<string, unknown>, meta: Meta, form: FormInstance<Values>) => ReactNode);
|
|
@@ -4,10 +4,11 @@ import { Field } from "@rc-component/form";
|
|
|
4
4
|
import { cloneElement, isValidElement } from "react";
|
|
5
5
|
import { FormFieldView } from "../form-field/form-field-view.js";
|
|
6
6
|
import { useFormLayout } from "./form-context.js";
|
|
7
|
+
import { FieldControl } from "./field-control.js";
|
|
7
8
|
function FormItem(t0) {
|
|
8
|
-
const $ = c(
|
|
9
|
+
const $ = c(41);
|
|
9
10
|
const { name, label, required, rules, help, extra, validateStatus, initialValue, valuePropName, getValueFromEvent, trigger, validateTrigger, noStyle, dependencies, shouldUpdate, normalize, preserve, messageVariables, validateFirst, htmlFor, className, style, classNames, styles, children } = t0;
|
|
10
|
-
const { layout } = useFormLayout();
|
|
11
|
+
const { layout, form: formInstance } = useFormLayout();
|
|
11
12
|
let t1;
|
|
12
13
|
if ($[0] !== required || $[1] !== rules) {
|
|
13
14
|
t1 = required ?? rules?.some(_temp) ?? false;
|
|
@@ -17,7 +18,7 @@ function FormItem(t0) {
|
|
|
17
18
|
} else t1 = $[2];
|
|
18
19
|
const requiredMark = t1;
|
|
19
20
|
let t2;
|
|
20
|
-
if ($[3] !== className || $[4] !== classNames || $[5] !== extra || $[6] !== help || $[7] !== htmlFor || $[8] !== label || $[9] !== layout || $[10] !==
|
|
21
|
+
if ($[3] !== className || $[4] !== classNames || $[5] !== extra || $[6] !== help || $[7] !== htmlFor || $[8] !== label || $[9] !== layout || $[10] !== name || $[11] !== noStyle || $[12] !== requiredMark || $[13] !== style || $[14] !== styles || $[15] !== validateStatus || $[16] !== valuePropName) {
|
|
21
22
|
t2 = (content, meta, control)=>{
|
|
22
23
|
const status = validateStatus ?? (meta?.errors.length ? "error" : meta?.warnings.length ? "warning" : void 0);
|
|
23
24
|
const message = help ?? meta?.errors[0] ?? meta?.warnings[0];
|
|
@@ -37,7 +38,13 @@ function FormItem(t0) {
|
|
|
37
38
|
...controlProps,
|
|
38
39
|
value: ""
|
|
39
40
|
};
|
|
40
|
-
if (noStyle)
|
|
41
|
+
if (noStyle) {
|
|
42
|
+
const child = /*#__PURE__*/ isValidElement(content) && controlProps ? /*#__PURE__*/ cloneElement(content, controlProps) : content;
|
|
43
|
+
return null != name && meta && /*#__PURE__*/ isValidElement(child) ? /*#__PURE__*/ jsx(FieldControl, {
|
|
44
|
+
name: meta.name,
|
|
45
|
+
children: child
|
|
46
|
+
}) : child;
|
|
47
|
+
}
|
|
41
48
|
return /*#__PURE__*/ jsx(FormFieldView, {
|
|
42
49
|
formItem: true,
|
|
43
50
|
label: label,
|
|
@@ -48,6 +55,10 @@ function FormItem(t0) {
|
|
|
48
55
|
description: descriptionSlot,
|
|
49
56
|
layout: layout,
|
|
50
57
|
controlProps: controlProps,
|
|
58
|
+
renderControl: null != name && meta ? (child_0)=>/*#__PURE__*/ jsx(FieldControl, {
|
|
59
|
+
name: meta.name,
|
|
60
|
+
children: child_0
|
|
61
|
+
}) : void 0,
|
|
51
62
|
className: className,
|
|
52
63
|
style: style,
|
|
53
64
|
classNames: classNames,
|
|
@@ -62,40 +73,42 @@ function FormItem(t0) {
|
|
|
62
73
|
$[7] = htmlFor;
|
|
63
74
|
$[8] = label;
|
|
64
75
|
$[9] = layout;
|
|
65
|
-
$[10] =
|
|
66
|
-
$[11] =
|
|
67
|
-
$[12] =
|
|
68
|
-
$[13] =
|
|
69
|
-
$[14] =
|
|
70
|
-
$[15] =
|
|
71
|
-
$[16] =
|
|
72
|
-
|
|
76
|
+
$[10] = name;
|
|
77
|
+
$[11] = noStyle;
|
|
78
|
+
$[12] = requiredMark;
|
|
79
|
+
$[13] = style;
|
|
80
|
+
$[14] = styles;
|
|
81
|
+
$[15] = validateStatus;
|
|
82
|
+
$[16] = valuePropName;
|
|
83
|
+
$[17] = t2;
|
|
84
|
+
} else t2 = $[17];
|
|
73
85
|
const renderShell = t2;
|
|
74
86
|
if (null == name && null == dependencies && null == shouldUpdate) {
|
|
75
87
|
const t3 = children;
|
|
76
88
|
let t4;
|
|
77
|
-
if ($[
|
|
89
|
+
if ($[18] !== renderShell || $[19] !== t3) {
|
|
78
90
|
t4 = renderShell(t3, void 0, null);
|
|
79
|
-
$[
|
|
80
|
-
$[
|
|
81
|
-
$[
|
|
82
|
-
} else t4 = $[
|
|
91
|
+
$[18] = renderShell;
|
|
92
|
+
$[19] = t3;
|
|
93
|
+
$[20] = t4;
|
|
94
|
+
} else t4 = $[20];
|
|
83
95
|
return t4;
|
|
84
96
|
}
|
|
85
97
|
const t3 = name ?? void 0;
|
|
86
98
|
let t4;
|
|
87
|
-
if ($[
|
|
88
|
-
t4 = (control_0, meta_0
|
|
89
|
-
const content_0 = "function" == typeof children ? children(control_0, meta_0,
|
|
99
|
+
if ($[21] !== children || $[22] !== formInstance || $[23] !== name || $[24] !== renderShell) {
|
|
100
|
+
t4 = (control_0, meta_0)=>{
|
|
101
|
+
const content_0 = "function" == typeof children ? children(control_0, meta_0, formInstance) : children;
|
|
90
102
|
return renderShell(content_0, meta_0, null != name ? control_0 : null);
|
|
91
103
|
};
|
|
92
|
-
$[
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
$[
|
|
96
|
-
|
|
104
|
+
$[21] = children;
|
|
105
|
+
$[22] = formInstance;
|
|
106
|
+
$[23] = name;
|
|
107
|
+
$[24] = renderShell;
|
|
108
|
+
$[25] = t4;
|
|
109
|
+
} else t4 = $[25];
|
|
97
110
|
let t5;
|
|
98
|
-
if ($[
|
|
111
|
+
if ($[26] !== dependencies || $[27] !== getValueFromEvent || $[28] !== initialValue || $[29] !== messageVariables || $[30] !== normalize || $[31] !== preserve || $[32] !== rules || $[33] !== shouldUpdate || $[34] !== t3 || $[35] !== t4 || $[36] !== trigger || $[37] !== validateFirst || $[38] !== validateTrigger || $[39] !== valuePropName) {
|
|
99
112
|
t5 = /*#__PURE__*/ jsx(Field, {
|
|
100
113
|
name: t3,
|
|
101
114
|
rules: rules,
|
|
@@ -112,22 +125,22 @@ function FormItem(t0) {
|
|
|
112
125
|
validateFirst: validateFirst,
|
|
113
126
|
children: t4
|
|
114
127
|
});
|
|
115
|
-
$[
|
|
116
|
-
$[
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
119
|
-
$[
|
|
120
|
-
$[
|
|
121
|
-
$[
|
|
122
|
-
$[
|
|
123
|
-
$[
|
|
124
|
-
$[
|
|
125
|
-
$[
|
|
126
|
-
$[
|
|
127
|
-
$[
|
|
128
|
-
$[
|
|
129
|
-
$[
|
|
130
|
-
} else t5 = $[
|
|
128
|
+
$[26] = dependencies;
|
|
129
|
+
$[27] = getValueFromEvent;
|
|
130
|
+
$[28] = initialValue;
|
|
131
|
+
$[29] = messageVariables;
|
|
132
|
+
$[30] = normalize;
|
|
133
|
+
$[31] = preserve;
|
|
134
|
+
$[32] = rules;
|
|
135
|
+
$[33] = shouldUpdate;
|
|
136
|
+
$[34] = t3;
|
|
137
|
+
$[35] = t4;
|
|
138
|
+
$[36] = trigger;
|
|
139
|
+
$[37] = validateFirst;
|
|
140
|
+
$[38] = validateTrigger;
|
|
141
|
+
$[39] = valuePropName;
|
|
142
|
+
$[40] = t5;
|
|
143
|
+
} else t5 = $[40];
|
|
131
144
|
return t5;
|
|
132
145
|
}
|
|
133
146
|
function _temp(rule) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { List, type FormProps as RcFormProps, useWatch } from '@rc-component/form';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import { type TaoSize } from '../../provider/tao-provider.js';
|
|
4
4
|
import { type SemanticClassNames, type SemanticStyles } from '../../utils/semantic.js';
|
|
5
5
|
import { FormItem, type FormItemProps } from './form-item.js';
|
|
6
|
+
import { type FormInstance, useForm } from './use-form.js';
|
|
6
7
|
import './form.css';
|
|
7
8
|
export type FormSemanticPart = 'root';
|
|
8
|
-
export interface FormProps<Values = Record<string, unknown>> extends Omit<RcFormProps<Values>, 'component'> {
|
|
9
|
+
export interface FormProps<Values = Record<string, unknown>> extends Omit<RcFormProps<Values>, 'component' | 'form'> {
|
|
10
|
+
form?: FormInstance<Values>;
|
|
9
11
|
/** Label/control arrangement inherited by Form.Item. Defaults to 'vertical'. */
|
|
10
12
|
layout?: 'vertical' | 'horizontal';
|
|
11
13
|
/** Cascades a control size to everything inside the form. */
|
|
@@ -17,9 +19,7 @@ export interface FormProps<Values = Record<string, unknown>> extends Omit<RcForm
|
|
|
17
19
|
styles?: SemanticStyles<FormSemanticPart>;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
|
-
* Returns the instance of the enclosing Form
|
|
21
|
-
* InternalFormInstance (a superset of FormInstance), same source antd's
|
|
22
|
-
* useFormInstance reads from.
|
|
22
|
+
* Returns the enhanced instance of the enclosing Form.
|
|
23
23
|
*/
|
|
24
24
|
declare function useFormInstance<Values = Record<string, unknown>>(): FormInstance<Values>;
|
|
25
25
|
export declare const Form: (<Values = Record<string, unknown>>(props: FormProps<Values> & {
|
|
@@ -1,121 +1,139 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
-
import _rc_component_form, {
|
|
3
|
+
import _rc_component_form, { FormProvider, List, useWatch } from "@rc-component/form";
|
|
4
4
|
import { forwardRef, useContext } from "react";
|
|
5
5
|
import { TaoProvider } from "../../provider/tao-provider.js";
|
|
6
6
|
import { cx } from "../../utils/semantic.js";
|
|
7
7
|
import { FormLayoutContext } from "./form-context.js";
|
|
8
8
|
import { FormItem } from "./form-item.js";
|
|
9
|
+
import { getFieldRegistry, useForm } from "./use-form.js";
|
|
9
10
|
import "./form.css";
|
|
10
11
|
import { interopDefault } from "../../utils/interop-default.js";
|
|
11
12
|
const RcFormComponent = /*#__PURE__*/ interopDefault(_rc_component_form);
|
|
12
13
|
function FormInner(t0, ref) {
|
|
13
|
-
const $ = c(
|
|
14
|
+
const $ = c(37);
|
|
14
15
|
let children;
|
|
15
16
|
let className;
|
|
16
17
|
let classNames;
|
|
17
18
|
let disabled;
|
|
19
|
+
let form;
|
|
18
20
|
let rcProps;
|
|
19
21
|
let size;
|
|
20
22
|
let style;
|
|
21
23
|
let styles;
|
|
22
24
|
let t1;
|
|
23
25
|
if ($[0] !== t0) {
|
|
24
|
-
({ layout: t1, size, disabled, children, className, style, classNames, styles, ...rcProps } = t0);
|
|
26
|
+
({ layout: t1, size, disabled, children, className, style, classNames, styles, form, ...rcProps } = t0);
|
|
25
27
|
$[0] = t0;
|
|
26
28
|
$[1] = children;
|
|
27
29
|
$[2] = className;
|
|
28
30
|
$[3] = classNames;
|
|
29
31
|
$[4] = disabled;
|
|
30
|
-
$[5] =
|
|
31
|
-
$[6] =
|
|
32
|
-
$[7] =
|
|
33
|
-
$[8] =
|
|
34
|
-
$[9] =
|
|
32
|
+
$[5] = form;
|
|
33
|
+
$[6] = rcProps;
|
|
34
|
+
$[7] = size;
|
|
35
|
+
$[8] = style;
|
|
36
|
+
$[9] = styles;
|
|
37
|
+
$[10] = t1;
|
|
35
38
|
} else {
|
|
36
39
|
children = $[1];
|
|
37
40
|
className = $[2];
|
|
38
41
|
classNames = $[3];
|
|
39
42
|
disabled = $[4];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
form = $[5];
|
|
44
|
+
rcProps = $[6];
|
|
45
|
+
size = $[7];
|
|
46
|
+
style = $[8];
|
|
47
|
+
styles = $[9];
|
|
48
|
+
t1 = $[10];
|
|
45
49
|
}
|
|
46
50
|
const layout = void 0 === t1 ? "vertical" : t1;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
$[
|
|
53
|
-
$[
|
|
54
|
-
} else
|
|
55
|
-
const layoutValue = t2;
|
|
56
|
-
const t3 = classNames?.root;
|
|
51
|
+
const [instance] = useForm(form);
|
|
52
|
+
const t2 = instance;
|
|
53
|
+
let t3;
|
|
54
|
+
if ($[11] !== instance) {
|
|
55
|
+
t3 = getFieldRegistry(instance);
|
|
56
|
+
$[11] = instance;
|
|
57
|
+
$[12] = t3;
|
|
58
|
+
} else t3 = $[12];
|
|
57
59
|
let t4;
|
|
58
|
-
if ($[
|
|
59
|
-
t4 =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if ($[13] !== layout || $[14] !== t2 || $[15] !== t3) {
|
|
61
|
+
t4 = {
|
|
62
|
+
layout,
|
|
63
|
+
form: t2,
|
|
64
|
+
fields: t3
|
|
65
|
+
};
|
|
66
|
+
$[13] = layout;
|
|
67
|
+
$[14] = t2;
|
|
68
|
+
$[15] = t3;
|
|
69
|
+
$[16] = t4;
|
|
70
|
+
} else t4 = $[16];
|
|
71
|
+
const layoutValue = t4;
|
|
72
|
+
const t5 = classNames?.root;
|
|
65
73
|
let t6;
|
|
66
|
-
if ($[
|
|
67
|
-
t6 =
|
|
68
|
-
|
|
74
|
+
if ($[17] !== className || $[18] !== t5) {
|
|
75
|
+
t6 = cx(t5, className);
|
|
76
|
+
$[17] = className;
|
|
77
|
+
$[18] = t5;
|
|
78
|
+
$[19] = t6;
|
|
79
|
+
} else t6 = $[19];
|
|
80
|
+
const t7 = styles?.root;
|
|
81
|
+
let t8;
|
|
82
|
+
if ($[20] !== style || $[21] !== t7) {
|
|
83
|
+
t8 = {
|
|
84
|
+
...t7,
|
|
69
85
|
...style
|
|
70
86
|
};
|
|
71
|
-
$[
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
} else
|
|
75
|
-
let
|
|
76
|
-
if ($[
|
|
77
|
-
|
|
87
|
+
$[20] = style;
|
|
88
|
+
$[21] = t7;
|
|
89
|
+
$[22] = t8;
|
|
90
|
+
} else t8 = $[22];
|
|
91
|
+
let t9;
|
|
92
|
+
if ($[23] !== children || $[24] !== instance || $[25] !== rcProps || $[26] !== ref || $[27] !== t6 || $[28] !== t8) {
|
|
93
|
+
t9 = /*#__PURE__*/ jsx(RcFormComponent, {
|
|
78
94
|
"data-tao-form": "",
|
|
79
95
|
ref: ref,
|
|
80
|
-
className:
|
|
81
|
-
style:
|
|
96
|
+
className: t6,
|
|
97
|
+
style: t8,
|
|
82
98
|
...rcProps,
|
|
99
|
+
form: instance,
|
|
83
100
|
children: children
|
|
84
101
|
});
|
|
85
|
-
$[
|
|
86
|
-
$[
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
90
|
-
$[
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
$[23] = children;
|
|
103
|
+
$[24] = instance;
|
|
104
|
+
$[25] = rcProps;
|
|
105
|
+
$[26] = ref;
|
|
106
|
+
$[27] = t6;
|
|
107
|
+
$[28] = t8;
|
|
108
|
+
$[29] = t9;
|
|
109
|
+
} else t9 = $[29];
|
|
110
|
+
let t10;
|
|
111
|
+
if ($[30] !== disabled || $[31] !== size || $[32] !== t9) {
|
|
112
|
+
t10 = /*#__PURE__*/ jsx(TaoProvider, {
|
|
95
113
|
size: size,
|
|
96
114
|
disabled: disabled,
|
|
97
|
-
children:
|
|
115
|
+
children: t9
|
|
98
116
|
});
|
|
99
|
-
$[
|
|
100
|
-
$[
|
|
101
|
-
$[
|
|
102
|
-
$[
|
|
103
|
-
} else
|
|
104
|
-
let
|
|
105
|
-
if ($[
|
|
106
|
-
|
|
117
|
+
$[30] = disabled;
|
|
118
|
+
$[31] = size;
|
|
119
|
+
$[32] = t9;
|
|
120
|
+
$[33] = t10;
|
|
121
|
+
} else t10 = $[33];
|
|
122
|
+
let t11;
|
|
123
|
+
if ($[34] !== layoutValue || $[35] !== t10) {
|
|
124
|
+
t11 = /*#__PURE__*/ jsx(FormLayoutContext.Provider, {
|
|
107
125
|
value: layoutValue,
|
|
108
|
-
children:
|
|
126
|
+
children: t10
|
|
109
127
|
});
|
|
110
|
-
$[
|
|
111
|
-
$[
|
|
112
|
-
$[
|
|
113
|
-
} else
|
|
114
|
-
return
|
|
128
|
+
$[34] = layoutValue;
|
|
129
|
+
$[35] = t10;
|
|
130
|
+
$[36] = t11;
|
|
131
|
+
} else t11 = $[36];
|
|
132
|
+
return t11;
|
|
115
133
|
}
|
|
116
134
|
const ForwardedForm = /*#__PURE__*/ forwardRef(FormInner);
|
|
117
135
|
function useFormInstance() {
|
|
118
|
-
return useContext(
|
|
136
|
+
return useContext(FormLayoutContext).form;
|
|
119
137
|
}
|
|
120
138
|
const Form = Object.assign(ForwardedForm, {
|
|
121
139
|
Item: FormItem,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FormInstance as RcFormInstance, type NamePath } from '@rc-component/form';
|
|
2
|
+
import { type Options } from 'scroll-into-view-if-needed';
|
|
3
|
+
export type FormScrollOptions = Options & {
|
|
4
|
+
focus?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface FormInstance<Values = any> extends RcFormInstance<Values> {
|
|
7
|
+
/** Scroll a mounted field into view; optionally focus its control. */
|
|
8
|
+
scrollToField: (name: NamePath<Values>, options?: FormScrollOptions) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface FieldTarget {
|
|
11
|
+
id: string;
|
|
12
|
+
instance: unknown;
|
|
13
|
+
}
|
|
14
|
+
export declare function getFieldRegistry(form: object): Map<string, FieldTarget> | undefined;
|
|
15
|
+
export declare function fieldKey(name: unknown): string;
|
|
16
|
+
export declare function useForm<Values = any>(form?: FormInstance<Values>): [FormInstance<Values>];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
2
|
+
import { useForm } from "@rc-component/form";
|
|
3
|
+
import { getDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
|
4
|
+
import scroll_into_view_if_needed from "scroll-into-view-if-needed";
|
|
5
|
+
const use_form_scroll = scroll_into_view_if_needed;
|
|
6
|
+
const fieldRegistries = new WeakMap();
|
|
7
|
+
function getFieldRegistry(form) {
|
|
8
|
+
return fieldRegistries.get(form);
|
|
9
|
+
}
|
|
10
|
+
function fieldKey(name) {
|
|
11
|
+
return JSON.stringify(Array.isArray(name) ? name : [
|
|
12
|
+
name
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
function use_form_useForm(form) {
|
|
16
|
+
const $ = c(4);
|
|
17
|
+
const [rcForm] = useForm(form);
|
|
18
|
+
let t0;
|
|
19
|
+
bb0: {
|
|
20
|
+
if (form) {
|
|
21
|
+
t0 = form;
|
|
22
|
+
break bb0;
|
|
23
|
+
}
|
|
24
|
+
let instance;
|
|
25
|
+
if ($[0] !== rcForm) {
|
|
26
|
+
const fields = new Map();
|
|
27
|
+
instance = {
|
|
28
|
+
...rcForm,
|
|
29
|
+
scrollToField (name, t1) {
|
|
30
|
+
const options = void 0 === t1 ? {} : t1;
|
|
31
|
+
const target = fields.get(fieldKey(name));
|
|
32
|
+
if (!target) return;
|
|
33
|
+
const node = getDOM(target.instance) ?? document.getElementById(target.id);
|
|
34
|
+
if (!node) return;
|
|
35
|
+
const { focus, ...scrollOptions } = options;
|
|
36
|
+
use_form_scroll(node, {
|
|
37
|
+
scrollMode: "if-needed",
|
|
38
|
+
block: "nearest",
|
|
39
|
+
...scrollOptions
|
|
40
|
+
});
|
|
41
|
+
if (focus) {
|
|
42
|
+
const control = target.instance;
|
|
43
|
+
if ("function" == typeof control?.focus) control.focus({
|
|
44
|
+
preventScroll: true
|
|
45
|
+
});
|
|
46
|
+
else node.focus({
|
|
47
|
+
preventScroll: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
fieldRegistries.set(instance, fields);
|
|
53
|
+
$[0] = rcForm;
|
|
54
|
+
$[1] = instance;
|
|
55
|
+
} else instance = $[1];
|
|
56
|
+
t0 = instance;
|
|
57
|
+
}
|
|
58
|
+
const wrapped = t0;
|
|
59
|
+
let t1;
|
|
60
|
+
if ($[2] !== wrapped) {
|
|
61
|
+
t1 = [
|
|
62
|
+
wrapped
|
|
63
|
+
];
|
|
64
|
+
$[2] = wrapped;
|
|
65
|
+
$[3] = t1;
|
|
66
|
+
} else t1 = $[3];
|
|
67
|
+
return t1;
|
|
68
|
+
}
|
|
69
|
+
export { fieldKey, getFieldRegistry, use_form_useForm as useForm };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CSSProperties, type ReactNode } from 'react';
|
|
1
|
+
import { type CSSProperties, type ReactElement, type ReactNode } from 'react';
|
|
2
2
|
import { type SemanticClassNames, type SemanticStyles } from '../../utils/semantic.js';
|
|
3
3
|
export type FormFieldLayout = 'vertical' | 'horizontal';
|
|
4
4
|
export interface FormFieldViewProps {
|
|
@@ -17,6 +17,8 @@ export interface FormFieldViewProps {
|
|
|
17
17
|
* `value`/`onChange`/`status`). View-owned id/aria attributes win.
|
|
18
18
|
*/
|
|
19
19
|
controlProps?: Record<string, unknown>;
|
|
20
|
+
/** Internal hook for bound forms to register the final control and its id. */
|
|
21
|
+
renderControl?: (control: ReactElement<Record<string, unknown>>) => ReactNode;
|
|
20
22
|
children?: ReactNode;
|
|
21
23
|
className?: string;
|
|
22
24
|
style?: CSSProperties;
|
|
@@ -29,4 +31,4 @@ export interface FormFieldViewProps {
|
|
|
29
31
|
* with the aria wiring (describedby/errormessage/invalid/required) applied
|
|
30
32
|
* to the child control. Not part of the public API.
|
|
31
33
|
*/
|
|
32
|
-
export declare function FormFieldView({ formItem, label, htmlFor, required, error, warning, description, layout, controlProps, children, className, style, classNames, styles, }: FormFieldViewProps): import("react").JSX.Element;
|
|
34
|
+
export declare function FormFieldView({ formItem, label, htmlFor, required, error, warning, description, layout, controlProps, renderControl, children, className, style, classNames, styles, }: FormFieldViewProps): import("react").JSX.Element;
|
|
@@ -4,8 +4,8 @@ import { cloneElement, isValidElement, useId } from "react";
|
|
|
4
4
|
import { FieldLabelContext } from "../../utils/field-label.js";
|
|
5
5
|
import { cx } from "../../utils/semantic.js";
|
|
6
6
|
function FormFieldView(t0) {
|
|
7
|
-
const $ = c(
|
|
8
|
-
const { formItem, label, htmlFor, required, error, warning, description, layout: t1, controlProps, children, className, style, classNames, styles } = t0;
|
|
7
|
+
const $ = c(57);
|
|
8
|
+
const { formItem, label, htmlFor, required, error, warning, description, layout: t1, controlProps, renderControl, children, className, style, classNames, styles } = t0;
|
|
9
9
|
const layout = void 0 === t1 ? "vertical" : t1;
|
|
10
10
|
const generatedId = useId();
|
|
11
11
|
const child = /*#__PURE__*/ isValidElement(children) ? children : null;
|
|
@@ -128,41 +128,48 @@ function FormFieldView(t0) {
|
|
|
128
128
|
$[37] = t12;
|
|
129
129
|
} else t12 = $[37];
|
|
130
130
|
let t13;
|
|
131
|
-
if ($[38] !== control || $[39] !==
|
|
132
|
-
t13 = /*#__PURE__*/
|
|
133
|
-
value: label,
|
|
134
|
-
children: control
|
|
135
|
-
});
|
|
131
|
+
if ($[38] !== control || $[39] !== renderControl) {
|
|
132
|
+
t13 = renderControl && /*#__PURE__*/ isValidElement(control) ? renderControl(control) : control;
|
|
136
133
|
$[38] = control;
|
|
137
|
-
$[39] =
|
|
134
|
+
$[39] = renderControl;
|
|
138
135
|
$[40] = t13;
|
|
139
136
|
} else t13 = $[40];
|
|
140
137
|
let t14;
|
|
141
|
-
if ($[41] !==
|
|
142
|
-
t14 =
|
|
143
|
-
|
|
144
|
-
children:
|
|
145
|
-
})
|
|
146
|
-
$[41] =
|
|
147
|
-
$[42] =
|
|
138
|
+
if ($[41] !== label || $[42] !== t13) {
|
|
139
|
+
t14 = /*#__PURE__*/ jsx(FieldLabelContext.Provider, {
|
|
140
|
+
value: label,
|
|
141
|
+
children: t13
|
|
142
|
+
});
|
|
143
|
+
$[41] = label;
|
|
144
|
+
$[42] = t13;
|
|
148
145
|
$[43] = t14;
|
|
149
146
|
} else t14 = $[43];
|
|
150
147
|
let t15;
|
|
151
|
-
if ($[44] !==
|
|
152
|
-
t15 = /*#__PURE__*/
|
|
153
|
-
"data-tao-form-
|
|
154
|
-
children:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
$[44] = t13;
|
|
160
|
-
$[45] = t14;
|
|
148
|
+
if ($[44] !== formItem || $[45] !== message) {
|
|
149
|
+
t15 = formItem ? /*#__PURE__*/ jsx("div", {
|
|
150
|
+
"data-tao-form-message": "",
|
|
151
|
+
children: message
|
|
152
|
+
}) : message;
|
|
153
|
+
$[44] = formItem;
|
|
154
|
+
$[45] = message;
|
|
161
155
|
$[46] = t15;
|
|
162
156
|
} else t15 = $[46];
|
|
163
157
|
let t16;
|
|
164
|
-
if ($[47] !==
|
|
158
|
+
if ($[47] !== t14 || $[48] !== t15) {
|
|
165
159
|
t16 = /*#__PURE__*/ jsxs("div", {
|
|
160
|
+
"data-tao-form-control": "",
|
|
161
|
+
children: [
|
|
162
|
+
t14,
|
|
163
|
+
t15
|
|
164
|
+
]
|
|
165
|
+
});
|
|
166
|
+
$[47] = t14;
|
|
167
|
+
$[48] = t15;
|
|
168
|
+
$[49] = t16;
|
|
169
|
+
} else t16 = $[49];
|
|
170
|
+
let t17;
|
|
171
|
+
if ($[50] !== t10 || $[51] !== t11 || $[52] !== t12 || $[53] !== t16 || $[54] !== t7 || $[55] !== t9) {
|
|
172
|
+
t17 = /*#__PURE__*/ jsxs("div", {
|
|
166
173
|
className: t7,
|
|
167
174
|
style: t9,
|
|
168
175
|
"data-tao-form-field": "",
|
|
@@ -170,17 +177,17 @@ function FormFieldView(t0) {
|
|
|
170
177
|
"data-tao-layout": t11,
|
|
171
178
|
children: [
|
|
172
179
|
t12,
|
|
173
|
-
|
|
180
|
+
t16
|
|
174
181
|
]
|
|
175
182
|
});
|
|
176
|
-
$[
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
179
|
-
$[50] = t15;
|
|
180
|
-
$[51] = t7;
|
|
181
|
-
$[52] = t9;
|
|
183
|
+
$[50] = t10;
|
|
184
|
+
$[51] = t11;
|
|
185
|
+
$[52] = t12;
|
|
182
186
|
$[53] = t16;
|
|
183
|
-
|
|
184
|
-
|
|
187
|
+
$[54] = t7;
|
|
188
|
+
$[55] = t9;
|
|
189
|
+
$[56] = t17;
|
|
190
|
+
} else t17 = $[56];
|
|
191
|
+
return t17;
|
|
185
192
|
}
|
|
186
193
|
export { FormFieldView };
|
|
@@ -9,7 +9,8 @@ const formDoc = {
|
|
|
9
9
|
source: 'src/components/form/form.tsx',
|
|
10
10
|
story: 'stories/form.stories.tsx',
|
|
11
11
|
tests: [
|
|
12
|
-
'tests/form/form.test.tsx'
|
|
12
|
+
'tests/form/form.test.tsx',
|
|
13
|
+
'tests/form/form-scroll.test.tsx'
|
|
13
14
|
],
|
|
14
15
|
semanticParts: [
|
|
15
16
|
'root'
|
|
@@ -32,6 +33,7 @@ const formDoc = {
|
|
|
32
33
|
'Declare validation as rules on Form.Item; the required mark is inferred from rules.',
|
|
33
34
|
'Use dependencies for cross-field rules such as password confirmation.',
|
|
34
35
|
'Use Form.useForm() for imperative control (setFieldsValue, resetFields, submit).',
|
|
36
|
+
'Call form.scrollToField(name, { focus: true }) to reveal a mounted field, including full Form.List paths; custom controls must forward ref or id.',
|
|
35
37
|
'Set size or disabled on Form to cascade them to every control inside.'
|
|
36
38
|
],
|
|
37
39
|
avoid: [
|
package/dist/entries/form.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import '../theme/theme.css';
|
|
2
2
|
import '../theme/control.css';
|
|
3
|
-
export type {
|
|
4
|
-
export { Form, type FormItemChildren, type FormItemProps, type FormItemSemanticPart, type FormItemValidateStatus, type FormProps, type FormSemanticPart, } from '../components/form/index.js';
|
|
3
|
+
export type { NamePath, Rule, RuleObject, } from '@rc-component/form';
|
|
4
|
+
export { Form, type FormInstance, type FormScrollOptions, type FormItemChildren, type FormItemProps, type FormItemSemanticPart, type FormItemValidateStatus, type FormProps, type FormSemanticPart, } from '../components/form/index.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './theme/theme.css';
|
|
2
2
|
import './theme/control.css';
|
|
3
|
-
export type {
|
|
3
|
+
export type { NamePath, Rule, RuleObject, } from '@rc-component/form';
|
|
4
4
|
export { Affix, type AffixProps, type AffixRef, type AffixSemanticPart, } from './components/affix/affix.js';
|
|
5
5
|
export { Alert, type AlertProps, type AlertSemanticPart, type AlertType, } from './components/alert/alert.js';
|
|
6
6
|
export type { AutoCompleteOption, AutoCompleteProps, AutoCompleteRef, AutoCompleteSemanticPart, AutoCompleteSemanticType, DataSourceItemObject, DataSourceItemType, } from './components/auto-complete/auto-complete.js';
|
|
@@ -29,7 +29,7 @@ export { Drawer, type DrawerPlacement, type DrawerProps, type DrawerResizableCon
|
|
|
29
29
|
export { Dropdown, type DropdownButtonProps, type DropdownPlacement, type DropdownProps, type DropdownSemanticPart, type DropdownTrigger, type MenuDividerType, type MenuGroupType, type MenuItem, type MenuItemType, type MenuProps, } from './components/dropdown/dropdown.js';
|
|
30
30
|
export { Empty, type EmptyProps, type EmptyRef, type EmptySemanticPart, } from './components/empty/empty.js';
|
|
31
31
|
export { type BackTopProps, FloatButton, type FloatButtonBackTopProps, type FloatButtonBadgeProps, type FloatButtonElement, type FloatButtonGroupProps, type FloatButtonGroupRef, type FloatButtonGroupSemanticPart, type FloatButtonGroupTrigger, type FloatButtonProps, type FloatButtonRef, type FloatButtonSemanticPart, type FloatButtonShape, type FloatButtonType, } from './components/float-button/float-button.js';
|
|
32
|
-
export { Form, type FormItemChildren, type FormItemProps, type FormItemSemanticPart, type FormItemValidateStatus, type FormProps, type FormSemanticPart, } from './components/form/index.js';
|
|
32
|
+
export { Form, type FormInstance, type FormScrollOptions, type FormItemChildren, type FormItemProps, type FormItemSemanticPart, type FormItemValidateStatus, type FormProps, type FormSemanticPart, } from './components/form/index.js';
|
|
33
33
|
export { FormActions, type FormActionsProps, type FormActionsSemanticPart, } from './components/form-actions/form-actions.js';
|
|
34
34
|
export { FormField, type FormFieldProps, type FormFieldSemanticPart, } from './components/form-field/form-field.js';
|
|
35
35
|
export { FormSection, type FormSectionProps, type FormSectionSemanticPart, } from './components/form-section/form-section.js';
|
package/llms.txt
CHANGED
|
@@ -356,7 +356,7 @@ Collects and validates field values with an antd-aligned API (rules, dependencie
|
|
|
356
356
|
- Exports: `Form`
|
|
357
357
|
- Source: `src/components/form/form.tsx`
|
|
358
358
|
- Storybook: `stories/form.stories.tsx`
|
|
359
|
-
- Tests: `tests/form/form.test.tsx`
|
|
359
|
+
- Tests: `tests/form/form.test.tsx`, `tests/form/form-scroll.test.tsx`
|
|
360
360
|
- Semantic parts: `root`
|
|
361
361
|
|
|
362
362
|
Use Form with Form.Item when fields need a value store, rule validation, or submit handling. Use the lighter FormField when you manage state yourself.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rockshin/tao-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A modern React component library with semantic DOM customization and OKLCH-based theming.",
|
|
6
6
|
"keywords": [
|
|
@@ -151,8 +151,10 @@
|
|
|
151
151
|
"@rc-component/tree": "~1.5.3",
|
|
152
152
|
"@rc-component/tree-select": "~1.19.0",
|
|
153
153
|
"@rc-component/upload": "~1.1.1",
|
|
154
|
+
"@rc-component/util": "1.14.0",
|
|
154
155
|
"dayjs": "^1.11.23",
|
|
155
156
|
"react-compiler-runtime": "^1.0.0",
|
|
156
|
-
"react-remove-scroll": "^2.7.2"
|
|
157
|
+
"react-remove-scroll": "^2.7.2",
|
|
158
|
+
"scroll-into-view-if-needed": "3.1.0"
|
|
157
159
|
}
|
|
158
160
|
}
|