@hzab/form-render 1.7.11 → 1.7.13
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# @hzab/form-render@1.7.13
|
|
2
|
+
|
|
3
|
+
feat: ArrayBase 相关 api 暴露
|
|
4
|
+
|
|
5
|
+
# @hzab/form-render@1.7.12
|
|
6
|
+
|
|
7
|
+
feat: ArrayBase 暴露 useArray useIndex useRecord
|
|
8
|
+
feat: ArrayTable onSortStart onSortEnd 回调
|
|
9
|
+
|
|
1
10
|
# @hzab/form-render@1.7.11
|
|
2
11
|
|
|
3
12
|
feat: 只读模式 PreviewText emptyValue 配置
|
package/package.json
CHANGED
|
@@ -52,37 +52,39 @@ export interface IArrayBaseProps {
|
|
|
52
52
|
onRemove?: (index: number) => void;
|
|
53
53
|
onMoveDown?: (index: number) => void;
|
|
54
54
|
onMoveUp?: (index: number) => void;
|
|
55
|
+
onSortStart?: (e) => void;
|
|
56
|
+
onSortEnd?: (e) => void;
|
|
55
57
|
deletePopconfirmTitle?: () => ReactNode;
|
|
56
58
|
deletePopconfirm?: boolean;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
type ComposedArrayBase = React.FC<React.PropsWithChildren<IArrayBaseProps>> &
|
|
61
|
+
export type ComposedArrayBase = React.FC<React.PropsWithChildren<IArrayBaseProps>> &
|
|
60
62
|
ArrayBaseMixins & {
|
|
61
63
|
Item?: React.FC<React.PropsWithChildren<IArrayBaseItemProps>>;
|
|
62
64
|
mixin?: <T extends JSXComponent>(target: T) => T & ArrayBaseMixins;
|
|
63
65
|
};
|
|
64
66
|
|
|
65
|
-
const ArrayBaseContext = createContext<IArrayBaseContext>(null);
|
|
67
|
+
export const ArrayBaseContext = createContext<IArrayBaseContext>(null);
|
|
66
68
|
|
|
67
|
-
const ItemContext = createContext<IArrayBaseItemProps>(null);
|
|
69
|
+
export const ItemContext = createContext<IArrayBaseItemProps>(null);
|
|
68
70
|
|
|
69
|
-
const takeRecord = (val: any, index?: number) => (typeof val === "function" ? val(index) : val);
|
|
71
|
+
export const takeRecord = (val: any, index?: number) => (typeof val === "function" ? val(index) : val);
|
|
70
72
|
|
|
71
|
-
const useArray = () => {
|
|
73
|
+
export const useArray = () => {
|
|
72
74
|
return useContext(ArrayBaseContext);
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
const useIndex = (index?: number) => {
|
|
77
|
+
export const useIndex = (index?: number) => {
|
|
76
78
|
const ctx = useContext(ItemContext);
|
|
77
79
|
return ctx ? ctx.index : index;
|
|
78
80
|
};
|
|
79
81
|
|
|
80
|
-
const useRecord = (record?: number) => {
|
|
82
|
+
export const useRecord = (record?: number) => {
|
|
81
83
|
const ctx = useContext(ItemContext);
|
|
82
84
|
return takeRecord(ctx ? ctx.record : record, ctx?.index);
|
|
83
85
|
};
|
|
84
86
|
|
|
85
|
-
const getSchemaDefaultValue = (schema: Schema) => {
|
|
87
|
+
export const getSchemaDefaultValue = (schema: Schema) => {
|
|
86
88
|
if (schema?.type === "array") return [];
|
|
87
89
|
if (schema?.type === "object") return {};
|
|
88
90
|
if (schema?.type === "void") {
|
|
@@ -93,7 +95,7 @@ const getSchemaDefaultValue = (schema: Schema) => {
|
|
|
93
95
|
}
|
|
94
96
|
};
|
|
95
97
|
|
|
96
|
-
const getDefaultValue = (defaultValue: any, schema: Schema) => {
|
|
98
|
+
export const getDefaultValue = (defaultValue: any, schema: Schema) => {
|
|
97
99
|
if (isValid(defaultValue)) return clone(defaultValue);
|
|
98
100
|
if (Array.isArray(schema?.items)) return getSchemaDefaultValue(schema?.items[0]);
|
|
99
101
|
return getSchemaDefaultValue(schema?.items);
|
|
@@ -109,7 +111,7 @@ ArrayBase.Item = ({ children, ...props }) => {
|
|
|
109
111
|
return <ItemContext.Provider value={props}>{children}</ItemContext.Provider>;
|
|
110
112
|
};
|
|
111
113
|
|
|
112
|
-
const SortHandle = SortableHandle((props: any) => {
|
|
114
|
+
export const SortHandle = SortableHandle((props: any) => {
|
|
113
115
|
const prefixCls = usePrefixCls("formily-array-base");
|
|
114
116
|
return (
|
|
115
117
|
<MenuOutlined {...props} className={cls(`${prefixCls}-sort-handle`, props.className)} style={{ ...props.style }} />
|
|
@@ -8,33 +8,33 @@ import { ISchema } from "@formily/json-schema";
|
|
|
8
8
|
import { usePrefixCls } from "c-formily-antd/lib/__builtins__";
|
|
9
9
|
import { ArrayBase, ArrayBaseMixins, IArrayBaseProps } from "../ArrayBase";
|
|
10
10
|
|
|
11
|
-
type ComposedArrayCards = React.FC<React.PropsWithChildren<CardProps & IArrayBaseProps>> & ArrayBaseMixins;
|
|
11
|
+
export type ComposedArrayCards = React.FC<React.PropsWithChildren<CardProps & IArrayBaseProps>> & ArrayBaseMixins;
|
|
12
12
|
|
|
13
|
-
const isAdditionComponent = (schema: ISchema) => {
|
|
13
|
+
export const isAdditionComponent = (schema: ISchema) => {
|
|
14
14
|
return schema["x-component"]?.indexOf("Addition") > -1;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const isIndexComponent = (schema: ISchema) => {
|
|
17
|
+
export const isIndexComponent = (schema: ISchema) => {
|
|
18
18
|
return schema["x-component"]?.indexOf?.("Index") > -1;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const isRemoveComponent = (schema: ISchema) => {
|
|
21
|
+
export const isRemoveComponent = (schema: ISchema) => {
|
|
22
22
|
return schema["x-component"]?.indexOf?.("Remove") > -1;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const isCopyComponent = (schema: ISchema) => {
|
|
25
|
+
export const isCopyComponent = (schema: ISchema) => {
|
|
26
26
|
return schema["x-component"]?.indexOf?.("Copy") > -1;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const isMoveUpComponent = (schema: ISchema) => {
|
|
29
|
+
export const isMoveUpComponent = (schema: ISchema) => {
|
|
30
30
|
return schema["x-component"]?.indexOf?.("MoveUp") > -1;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const isMoveDownComponent = (schema: ISchema) => {
|
|
33
|
+
export const isMoveDownComponent = (schema: ISchema) => {
|
|
34
34
|
return schema["x-component"]?.indexOf?.("MoveDown") > -1;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const isOperationComponent = (schema: ISchema) => {
|
|
37
|
+
export const isOperationComponent = (schema: ISchema) => {
|
|
38
38
|
return (
|
|
39
39
|
isAdditionComponent(schema) ||
|
|
40
40
|
isRemoveComponent(schema) ||
|
|
@@ -11,14 +11,14 @@ import { Schema } from "@formily/json-schema";
|
|
|
11
11
|
import { usePrefixCls, SortableContainer, SortableElement } from "c-formily-antd/lib/__builtins__";
|
|
12
12
|
import { ArrayBase, ArrayBaseMixins, IArrayBaseProps } from "../ArrayBase";
|
|
13
13
|
|
|
14
|
-
interface ObservableColumnSource {
|
|
14
|
+
export interface ObservableColumnSource {
|
|
15
15
|
field: GeneralField;
|
|
16
16
|
columnProps: ColumnProps<any>;
|
|
17
17
|
schema: Schema;
|
|
18
18
|
display: FieldDisplayTypes;
|
|
19
19
|
name: string;
|
|
20
20
|
}
|
|
21
|
-
interface IArrayTablePaginationProps extends PaginationProps {
|
|
21
|
+
export interface IArrayTablePaginationProps extends PaginationProps {
|
|
22
22
|
dataSource?: any[];
|
|
23
23
|
showPagination?: boolean;
|
|
24
24
|
children?: (
|
|
@@ -30,38 +30,38 @@ interface IArrayTablePaginationProps extends PaginationProps {
|
|
|
30
30
|
) => React.ReactElement;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
interface IStatusSelectProps extends SelectProps<any> {
|
|
33
|
+
export interface IStatusSelectProps extends SelectProps<any> {
|
|
34
34
|
pageSize?: number;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
type ComposedArrayTable = React.FC<React.PropsWithChildren<TableProps<any> & IArrayBaseProps>> &
|
|
37
|
+
export type ComposedArrayTable = React.FC<React.PropsWithChildren<TableProps<any> & IArrayBaseProps>> &
|
|
38
38
|
ArrayBaseMixins & {
|
|
39
39
|
Column?: React.FC<React.PropsWithChildren<ColumnProps<any>>>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
interface PaginationAction {
|
|
42
|
+
export interface PaginationAction {
|
|
43
43
|
totalPage?: number;
|
|
44
44
|
pageSize?: number;
|
|
45
45
|
showPagination?: boolean;
|
|
46
46
|
changePage?: (page: number) => void;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const SortableRow = SortableElement((props: any) => <tr {...props} />);
|
|
50
|
-
const SortableBody = SortableContainer((props: any) => <tbody {...props} />);
|
|
49
|
+
export const SortableRow = SortableElement((props: any) => <tr {...props} />);
|
|
50
|
+
export const SortableBody = SortableContainer((props: any) => <tbody {...props} />);
|
|
51
51
|
|
|
52
|
-
const isColumnComponent = (schema: Schema) => {
|
|
52
|
+
export const isColumnComponent = (schema: Schema) => {
|
|
53
53
|
return schema["x-component"]?.indexOf("Column") > -1;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
const isOperationsComponent = (schema: Schema) => {
|
|
56
|
+
export const isOperationsComponent = (schema: Schema) => {
|
|
57
57
|
return schema["x-component"]?.indexOf("Operations") > -1;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const isAdditionComponent = (schema: Schema) => {
|
|
60
|
+
export const isAdditionComponent = (schema: Schema) => {
|
|
61
61
|
return schema["x-component"]?.indexOf("Addition") > -1;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const useArrayTableSources = () => {
|
|
64
|
+
export const useArrayTableSources = () => {
|
|
65
65
|
const arrayField = useField();
|
|
66
66
|
const schema = useFieldSchema();
|
|
67
67
|
const parseSources = (schema: Schema): ObservableColumnSource[] => {
|
|
@@ -105,7 +105,7 @@ const useArrayTableSources = () => {
|
|
|
105
105
|
return parseArrayItems(schema.items);
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
const useArrayTableColumns = (
|
|
108
|
+
export const useArrayTableColumns = (
|
|
109
109
|
dataSource: any[],
|
|
110
110
|
field: ArrayField,
|
|
111
111
|
sources: ObservableColumnSource[],
|
|
@@ -130,7 +130,7 @@ const useArrayTableColumns = (
|
|
|
130
130
|
}, []);
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
const useAddition = () => {
|
|
133
|
+
export const useAddition = () => {
|
|
134
134
|
const schema = useFieldSchema();
|
|
135
135
|
return schema.reduceProperties((addition, schema, key) => {
|
|
136
136
|
if (isAdditionComponent(schema)) {
|
|
@@ -140,11 +140,11 @@ const useAddition = () => {
|
|
|
140
140
|
}, null);
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
const schedulerRequest = {
|
|
143
|
+
export const schedulerRequest = {
|
|
144
144
|
request: null,
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const StatusSelect: ReactFC<IStatusSelectProps> = observer(
|
|
147
|
+
export const StatusSelect: ReactFC<IStatusSelectProps> = observer(
|
|
148
148
|
(props) => {
|
|
149
149
|
const field = useField<ArrayField>();
|
|
150
150
|
const prefixCls = usePrefixCls("formily-array-table");
|
|
@@ -193,8 +193,8 @@ const StatusSelect: ReactFC<IStatusSelectProps> = observer(
|
|
|
193
193
|
},
|
|
194
194
|
);
|
|
195
195
|
|
|
196
|
-
const PaginationContext = createContext<PaginationAction>({});
|
|
197
|
-
const usePagination = () => {
|
|
196
|
+
export const PaginationContext = createContext<PaginationAction>({});
|
|
197
|
+
export const usePagination = () => {
|
|
198
198
|
return useContext(PaginationContext);
|
|
199
199
|
};
|
|
200
200
|
|
|
@@ -313,10 +313,10 @@ export const ArrayTable: ComposedArrayTable = observer((props) => {
|
|
|
313
313
|
});
|
|
314
314
|
};
|
|
315
315
|
const getWrapperComp = useCallback(
|
|
316
|
-
(dataSource: any[], start: number) => (
|
|
316
|
+
(dataSource: any[], start: number) => (wrapperProps: any) =>
|
|
317
317
|
(
|
|
318
318
|
<SortableBody
|
|
319
|
-
{...
|
|
319
|
+
{...wrapperProps}
|
|
320
320
|
start={start}
|
|
321
321
|
list={dataSource.slice()}
|
|
322
322
|
accessibility={{
|
|
@@ -324,11 +324,14 @@ export const ArrayTable: ComposedArrayTable = observer((props) => {
|
|
|
324
324
|
}}
|
|
325
325
|
onSortStart={(event) => {
|
|
326
326
|
addTdStyles(event.active.id as number);
|
|
327
|
+
props.onSortStart && props.onSortStart(event);
|
|
327
328
|
}}
|
|
328
|
-
onSortEnd={(
|
|
329
|
+
onSortEnd={(params) => {
|
|
330
|
+
const { oldIndex, newIndex } = params;
|
|
329
331
|
field.move(oldIndex, newIndex);
|
|
332
|
+
props.onSortEnd && props.onSortEnd(params);
|
|
330
333
|
}}
|
|
331
|
-
className={cls(`${prefixCls}-sort-helper`,
|
|
334
|
+
className={cls(`${prefixCls}-sort-helper`, wrapperProps.className)}
|
|
332
335
|
/>
|
|
333
336
|
),
|
|
334
337
|
[field],
|
|
@@ -389,7 +392,7 @@ ArrayTable.Column = () => {
|
|
|
389
392
|
|
|
390
393
|
ArrayBase.mixin(ArrayTable);
|
|
391
394
|
|
|
392
|
-
const Addition: ArrayBaseMixins["Addition"] = (props) => {
|
|
395
|
+
export const Addition: ArrayBaseMixins["Addition"] = (props) => {
|
|
393
396
|
const array = ArrayBase.useArray();
|
|
394
397
|
const { totalPage = 0, pageSize = 10, changePage, showPagination } = usePagination();
|
|
395
398
|
return (
|
package/src/index.tsx
CHANGED
|
@@ -179,13 +179,12 @@ const FormRender = forwardRef((props: any, parentRef) => {
|
|
|
179
179
|
wrapperCol={props.schema.form.wrapperCol}
|
|
180
180
|
onAutoSubmit={autoSubmit}
|
|
181
181
|
onAutoSubmitFailed={autoSubmitFailed}
|
|
182
|
+
previewTextPlaceholder={props?.emptyValue}
|
|
182
183
|
>
|
|
183
|
-
<
|
|
184
|
-
<
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
</FormLayout>
|
|
188
|
-
</PreviewText.Placeholder>
|
|
184
|
+
<FormLayout {...formLayoutProps}>
|
|
185
|
+
<SchemaField schema={schema}></SchemaField>
|
|
186
|
+
<div className="form-render-footer xxm">{footer}</div>
|
|
187
|
+
</FormLayout>
|
|
189
188
|
</Form>
|
|
190
189
|
</GlobalPropsContext.Provider>
|
|
191
190
|
);
|