@canlooks/can-ui 0.0.174 → 0.0.176

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.
@@ -143,7 +143,9 @@ exports.Curd = (0, react_1.memo)((props) => {
143
143
  const setInnerRows = (data) => {
144
144
  setOptions?.(data);
145
145
  _setInnerRows(data);
146
- containerRef.current.scrollTop = containerRef.current.scrollLeft = 0;
146
+ if (containerRef.current) {
147
+ containerRef.current.scrollTop = containerRef.current.scrollLeft = 0;
148
+ }
147
149
  };
148
150
  const [innerTotal, setInnerTotal] = (0, utils_1.useDerivedState)(props.paginationProps?.total || 0);
149
151
  const suppressReload = (0, react_1.useRef)(false);
@@ -19,7 +19,7 @@ interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps,
19
19
  wrapperRef?: Ref<HTMLFormElement>;
20
20
  initialValue?: V;
21
21
  onChange?(field: FieldPath, value: any, formValue: V): void;
22
- onFinish?(value: V): void;
22
+ onFinish?(value: V): any;
23
23
  items?: (FormItemProps & Obj)[];
24
24
  descriptionsProps?: DescriptionsProps;
25
25
  }
@@ -39,8 +39,7 @@ declare const FormValueContext: React.Context<FormValueContext<any>>;
39
39
  export declare function useFormValueContext<V extends FormValue>(): FormValueContext<V>;
40
40
  export declare function useFormStyleContext(): FormSharedProps;
41
41
  export type FormRef<V extends FormValue = FormValue> = {
42
- /** 存在校验不通过的字段时会得到`null` */
43
- submit(): Promise<V | null>;
42
+ submit(): Promise<V>;
44
43
  getFieldValue<T = any>(field: FieldPath): T;
45
44
  getFormValue(): V;
46
45
  getFieldError(field: FieldPath): FieldError | undefined;
@@ -78,16 +78,11 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
78
78
  const itemsContainer = (0, react_1.useRef)(new Map());
79
79
  const submitHandler = async (e) => {
80
80
  e?.preventDefault();
81
- try {
82
- await Promise.all([...itemsContainer.current].map(async ([, item]) => {
83
- return await item.validate() || Promise.reject();
84
- }));
85
- onFinish?.(formValue.current);
86
- return formValue.current;
87
- }
88
- catch (e) {
89
- return null;
90
- }
81
+ await Promise.all([...itemsContainer.current].map(async ([field, item]) => {
82
+ return await item.validate() || Promise.reject(new TypeError(`Invalid field: "${field}"`));
83
+ }));
84
+ await onFinish?.(formValue.current);
85
+ return formValue.current;
91
86
  };
92
87
  const formRef = (0, react_1.useRef)(null);
93
88
  formRef.current = {
@@ -140,7 +140,9 @@ export const Curd = memo((props) => {
140
140
  const setInnerRows = (data) => {
141
141
  setOptions?.(data);
142
142
  _setInnerRows(data);
143
- containerRef.current.scrollTop = containerRef.current.scrollLeft = 0;
143
+ if (containerRef.current) {
144
+ containerRef.current.scrollTop = containerRef.current.scrollLeft = 0;
145
+ }
144
146
  };
145
147
  const [innerTotal, setInnerTotal] = useDerivedState(props.paginationProps?.total || 0);
146
148
  const suppressReload = useRef(false);
@@ -19,7 +19,7 @@ interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps,
19
19
  wrapperRef?: Ref<HTMLFormElement>;
20
20
  initialValue?: V;
21
21
  onChange?(field: FieldPath, value: any, formValue: V): void;
22
- onFinish?(value: V): void;
22
+ onFinish?(value: V): any;
23
23
  items?: (FormItemProps & Obj)[];
24
24
  descriptionsProps?: DescriptionsProps;
25
25
  }
@@ -39,8 +39,7 @@ declare const FormValueContext: React.Context<FormValueContext<any>>;
39
39
  export declare function useFormValueContext<V extends FormValue>(): FormValueContext<V>;
40
40
  export declare function useFormStyleContext(): FormSharedProps;
41
41
  export type FormRef<V extends FormValue = FormValue> = {
42
- /** 存在校验不通过的字段时会得到`null` */
43
- submit(): Promise<V | null>;
42
+ submit(): Promise<V>;
44
43
  getFieldValue<T = any>(field: FieldPath): T;
45
44
  getFormValue(): V;
46
45
  getFieldError(field: FieldPath): FieldError | undefined;
@@ -72,16 +72,11 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
72
72
  const itemsContainer = useRef(new Map());
73
73
  const submitHandler = async (e) => {
74
74
  e?.preventDefault();
75
- try {
76
- await Promise.all([...itemsContainer.current].map(async ([, item]) => {
77
- return await item.validate() || Promise.reject();
78
- }));
79
- onFinish?.(formValue.current);
80
- return formValue.current;
81
- }
82
- catch (e) {
83
- return null;
84
- }
75
+ await Promise.all([...itemsContainer.current].map(async ([field, item]) => {
76
+ return await item.validate() || Promise.reject(new TypeError(`Invalid field: "${field}"`));
77
+ }));
78
+ await onFinish?.(formValue.current);
79
+ return formValue.current;
85
80
  };
86
81
  const formRef = useRef(null);
87
82
  formRef.current = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.174",
3
+ "version": "0.0.176",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",