@zat-design/sisyphus-react 4.6.4 → 4.6.5-beta.2
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/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- package/es/ProDrawerForm/index.js +1 -47
- package/es/ProDrawerForm/style/index.less +0 -12
- package/es/ProEditTable/components/RenderField/index.js +8 -2
- package/es/ProEditTable/components/RenderField/tools.d.ts +4 -0
- package/es/ProEditTable/components/RenderField/tools.js +14 -0
- package/es/ProEditTable/style/index.less +8 -0
- package/es/ProForm/components/combination/FormList/components/ActionButton.js +6 -1
- package/es/ProForm/components/combination/FormList/components/TabsFields.js +134 -62
- package/es/ProForm/components/combination/FormList/style/index.less +175 -44
- package/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +10 -11
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +12 -9
- package/es/ProLayout/utils/index.d.ts +11 -0
- package/es/ProLayout/utils/index.js +53 -2
- package/package.json +9 -1
|
@@ -1,50 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
createContext,
|
|
4
|
-
forwardRef,
|
|
5
|
-
useContext,
|
|
6
|
-
useEffect,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
useMemo
|
|
9
|
-
} from "react";
|
|
2
|
+
import { createContext, forwardRef, useContext, useImperativeHandle, useMemo } from "react";
|
|
10
3
|
import { ProDrawer, ProModal } from "./components";
|
|
11
4
|
import ProForm from "../ProForm";
|
|
12
5
|
import { resolveDrawerSize } from "./utils";
|
|
13
6
|
import locale from "../locale";
|
|
14
7
|
const ProDrawerFormContext = createContext(null);
|
|
15
|
-
const scrollLockClassName = "pro-drawer-form-scroll-lock";
|
|
16
|
-
let openDrawerCount = 0;
|
|
17
|
-
let lockedScrollLeft = 0;
|
|
18
|
-
let lockedScrollTop = 0;
|
|
19
|
-
const lockRootScroll = () => {
|
|
20
|
-
if (typeof document === "undefined") {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
if (openDrawerCount === 0) {
|
|
24
|
-
const scrollingElement = document.scrollingElement ?? document.documentElement;
|
|
25
|
-
lockedScrollLeft = scrollingElement.scrollLeft;
|
|
26
|
-
lockedScrollTop = scrollingElement.scrollTop;
|
|
27
|
-
document.body.style.setProperty("--pro-drawer-form-scroll-top", `-${lockedScrollTop}px`);
|
|
28
|
-
document.body.style.setProperty("--pro-drawer-form-scroll-left", `-${lockedScrollLeft}px`);
|
|
29
|
-
document.documentElement.classList.add(scrollLockClassName);
|
|
30
|
-
document.body.classList.add(scrollLockClassName);
|
|
31
|
-
}
|
|
32
|
-
openDrawerCount += 1;
|
|
33
|
-
return () => {
|
|
34
|
-
openDrawerCount = Math.max(0, openDrawerCount - 1);
|
|
35
|
-
if (openDrawerCount === 0) {
|
|
36
|
-
document.documentElement.classList.remove(scrollLockClassName);
|
|
37
|
-
document.body.classList.remove(scrollLockClassName);
|
|
38
|
-
document.body.style.removeProperty("--pro-drawer-form-scroll-top");
|
|
39
|
-
document.body.style.removeProperty("--pro-drawer-form-scroll-left");
|
|
40
|
-
if (lockedScrollLeft !== 0 || lockedScrollTop !== 0) {
|
|
41
|
-
window.scrollTo(lockedScrollLeft, lockedScrollTop);
|
|
42
|
-
}
|
|
43
|
-
lockedScrollLeft = 0;
|
|
44
|
-
lockedScrollTop = 0;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
8
|
const useProDrawerFormContext = () => useContext(ProDrawerFormContext);
|
|
49
9
|
const ProDrawerForm = forwardRef((props, ref) => {
|
|
50
10
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -67,12 +27,6 @@ const ProDrawerForm = forwardRef((props, ref) => {
|
|
|
67
27
|
} = props;
|
|
68
28
|
const nextIsView = isView || disabled;
|
|
69
29
|
const nextOkText = okText ?? (mode === "Drawer" ? (_d = (_c = locale) == null ? void 0 : _c.ProDrawerForm) == null ? void 0 : _d.save : (_f = (_e = locale) == null ? void 0 : _e.ProDrawerForm) == null ? void 0 : _f.confirm);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!open || mode !== "Drawer") {
|
|
72
|
-
return void 0;
|
|
73
|
-
}
|
|
74
|
-
return lockRootScroll();
|
|
75
|
-
}, [mode, open]);
|
|
76
30
|
const { width: deprecatedWidth, ...restPropsWithoutWidth } = restProps;
|
|
77
31
|
const width = resolveDrawerSize(size, deprecatedWidth);
|
|
78
32
|
const [form] = ProForm.useForm(originalForm);
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
@import '../../style/variables.less';
|
|
2
2
|
|
|
3
|
-
html.pro-drawer-form-scroll-lock {
|
|
4
|
-
overflow: hidden !important;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
body.pro-drawer-form-scroll-lock {
|
|
8
|
-
position: fixed !important;
|
|
9
|
-
top: var(--pro-drawer-form-scroll-top, 0);
|
|
10
|
-
left: var(--pro-drawer-form-scroll-left, 0);
|
|
11
|
-
width: 100%;
|
|
12
|
-
overflow: hidden !important;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
3
|
.pro-drawer {
|
|
16
4
|
.original-value-tooltip {
|
|
17
5
|
position: fixed;
|
|
@@ -35,7 +35,8 @@ import {
|
|
|
35
35
|
OMIT_FORM_ITEM_AND_DOM_KEYS,
|
|
36
36
|
arePropsEqual,
|
|
37
37
|
hasRowFunctionDependency,
|
|
38
|
-
mergeOnFieldChangeRow
|
|
38
|
+
mergeOnFieldChangeRow,
|
|
39
|
+
stabilizeDatePickerValueProps
|
|
39
40
|
} from "./tools";
|
|
40
41
|
const RenderField = ({ text: value, record, index, column, config }) => {
|
|
41
42
|
var _a, _b, _c;
|
|
@@ -573,6 +574,7 @@ const RenderField = ({ text: value, record, index, column, config }) => {
|
|
|
573
574
|
if (["Select", "ProSelect", "ProEnum"].includes(type)) {
|
|
574
575
|
componentProps.scrollFollowParent = false;
|
|
575
576
|
}
|
|
577
|
+
const datePickerValueRef = useRef(void 0);
|
|
576
578
|
const finalFormItemProps = useMemo(() => {
|
|
577
579
|
const defaultTransformProps = defaultTransform();
|
|
578
580
|
const namesTransformProps = namesTransform();
|
|
@@ -588,7 +590,7 @@ const RenderField = ({ text: value, record, index, column, config }) => {
|
|
|
588
590
|
}
|
|
589
591
|
return transformNormalize(value2, prevValue, allValues, isDiffMode);
|
|
590
592
|
} : userNormalize || transformNormalize;
|
|
591
|
-
const
|
|
593
|
+
const mergedGetValueProps = transformGetValueProps && userGetValueProps ? (value2, ...args) => {
|
|
592
594
|
const transformValueProps = transformGetValueProps(value2, ...args) || {};
|
|
593
595
|
const nextValue = Object.prototype.hasOwnProperty.call(transformValueProps, "value") ? transformValueProps.value : value2;
|
|
594
596
|
const userValueProps = userGetValueProps(nextValue, ...args) || {};
|
|
@@ -597,6 +599,10 @@ const RenderField = ({ text: value, record, index, column, config }) => {
|
|
|
597
599
|
...userValueProps
|
|
598
600
|
};
|
|
599
601
|
} : userGetValueProps || transformGetValueProps;
|
|
602
|
+
const finalGetValueProps = type === "DatePicker" && transformGetValueProps && mergedGetValueProps ? (...args) => {
|
|
603
|
+
const valueProps = mergedGetValueProps(...args);
|
|
604
|
+
return valueProps ? stabilizeDatePickerValueProps(datePickerValueRef, valueProps) : valueProps;
|
|
605
|
+
} : mergedGetValueProps;
|
|
600
606
|
return {
|
|
601
607
|
...lastFormItemProps,
|
|
602
608
|
...defaultTransformProps,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { InternalNamePath, NamePath } from 'antd/lib/form/interface';
|
|
2
2
|
import { GetOriginalValueParams, RenderFieldComparableProps } from './propsType';
|
|
3
|
+
/** 避免等值日期在表格重渲染时产生新引用,导致 DatePicker 面板状态被重置。 */
|
|
4
|
+
export declare const stabilizeDatePickerValueProps: (valueRef: {
|
|
5
|
+
current: any;
|
|
6
|
+
}, valueProps: Record<string, any>) => Record<string, any>;
|
|
3
7
|
/** 判断列是否包含可能依赖整行数据的函数型配置。 */
|
|
4
8
|
export declare const hasRowFunctionDependency: (column: Record<string, any> | null | undefined) => boolean;
|
|
5
9
|
/**
|
|
@@ -2,6 +2,7 @@ import get from "lodash/get";
|
|
|
2
2
|
import isEqual from "lodash/isEqual";
|
|
3
3
|
import isEqualWith from "lodash/isEqualWith";
|
|
4
4
|
import isFunction from "lodash/isFunction";
|
|
5
|
+
import dayjs from "dayjs";
|
|
5
6
|
import { customEqualForFunction } from "../../../utils";
|
|
6
7
|
import { getNamePath, isRecordShallowEqual } from "../../utils/tools";
|
|
7
8
|
const ROW_FUNCTION_DEPENDENCY_KEYS = [
|
|
@@ -15,6 +16,18 @@ const ROW_FUNCTION_DEPENDENCY_KEYS = [
|
|
|
15
16
|
"valueType",
|
|
16
17
|
"viewRender"
|
|
17
18
|
];
|
|
19
|
+
const stabilizeDatePickerValueProps = (valueRef, valueProps) => {
|
|
20
|
+
const previousValue = valueRef.current;
|
|
21
|
+
const nextValue = valueProps.value;
|
|
22
|
+
if (dayjs.isDayjs(previousValue) && dayjs.isDayjs(nextValue) && previousValue.valueOf() === nextValue.valueOf() && previousValue.utcOffset() === nextValue.utcOffset() && previousValue.locale() === nextValue.locale()) {
|
|
23
|
+
return {
|
|
24
|
+
...valueProps,
|
|
25
|
+
value: previousValue
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
valueRef.current = nextValue;
|
|
29
|
+
return valueProps;
|
|
30
|
+
};
|
|
18
31
|
const hasRowFunctionDependency = (column) => ROW_FUNCTION_DEPENDENCY_KEYS.some((key) => isFunction(column == null ? void 0 : column[key]));
|
|
19
32
|
const mergeOnFieldChangeRow = (beforeRow, mutatedRow, latestStoreRow) => {
|
|
20
33
|
const before = beforeRow || {};
|
|
@@ -220,6 +233,7 @@ export {
|
|
|
220
233
|
getOriginalValue,
|
|
221
234
|
hasRowFunctionDependency,
|
|
222
235
|
mergeOnFieldChangeRow,
|
|
236
|
+
stabilizeDatePickerValueProps,
|
|
223
237
|
toNamePath,
|
|
224
238
|
toNamePaths
|
|
225
239
|
};
|
|
@@ -239,6 +239,14 @@
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
.@{ant-prefix}-table-tbody
|
|
243
|
+
.is-editing:not(.@{ant-prefix}-table-measure-row):not(.@{ant-prefix}-table-row-extra)
|
|
244
|
+
.@{ant-prefix}-form-item-control {
|
|
245
|
+
min-height: calc(
|
|
246
|
+
var(--zaui-height-size-lg; 32px) * var(--zaui-size; 1)
|
|
247
|
+
) !important;
|
|
248
|
+
}
|
|
249
|
+
|
|
242
250
|
.@{ant-prefix}-table-tbody
|
|
243
251
|
.is-editing:not(.@{ant-prefix}-table-measure-row):not(.@{ant-prefix}-table-row-extra)
|
|
244
252
|
.@{ant-prefix}-form-item.@{ant-prefix}-form-item-has-error {
|
|
@@ -10,6 +10,7 @@ import omit from "lodash/omit";
|
|
|
10
10
|
import classNames from "classnames";
|
|
11
11
|
import { useMemo } from "react";
|
|
12
12
|
import {
|
|
13
|
+
CloseOutlined,
|
|
13
14
|
CopyOutlined,
|
|
14
15
|
PlusSquareOutlined,
|
|
15
16
|
ArrowUpOutlined,
|
|
@@ -37,7 +38,7 @@ const getDefaultActions = (mode) => {
|
|
|
37
38
|
remove(index);
|
|
38
39
|
},
|
|
39
40
|
label: locale.ProForm.formListActions[1],
|
|
40
|
-
icon: mode === "
|
|
41
|
+
icon: mode === "tabs" ? /* @__PURE__ */ jsx(CloseOutlined, {}) : mode === "less" ? /* @__PURE__ */ jsx(ProIcon, { component: close2Svg, size: 14, className: "single-delete" }) : /* @__PURE__ */ jsx(ProIcon, { component: deleteSvg, size: 18 })
|
|
41
42
|
},
|
|
42
43
|
copy: {
|
|
43
44
|
onClick: (record, { namePath, index, operation }) => {
|
|
@@ -196,6 +197,8 @@ const ActionButton = (props) => {
|
|
|
196
197
|
title: title ?? `${locale.ProForm.formListConfirmMessage}`,
|
|
197
198
|
onCancel: (e) => e.stopPropagation(),
|
|
198
199
|
onConfirm: (e) => {
|
|
200
|
+
if (mode === "tabs")
|
|
201
|
+
e == null ? void 0 : e.stopPropagation();
|
|
199
202
|
if (type === "add") {
|
|
200
203
|
handleAddClick();
|
|
201
204
|
} else {
|
|
@@ -209,6 +212,7 @@ const ActionButton = (props) => {
|
|
|
209
212
|
...defaultRest,
|
|
210
213
|
...omit(rest, filterKeys),
|
|
211
214
|
className: "pro-form-list-delete-icon",
|
|
215
|
+
"data-form-list-action": mode === "tabs" ? type : void 0,
|
|
212
216
|
type: "text",
|
|
213
217
|
onClick: (e) => e.stopPropagation(),
|
|
214
218
|
children: label || defaultLabel
|
|
@@ -227,6 +231,7 @@ const ActionButton = (props) => {
|
|
|
227
231
|
}),
|
|
228
232
|
...defaultRest,
|
|
229
233
|
...omit(rest, filterKeys),
|
|
234
|
+
"data-form-list-action": mode === "tabs" ? type : void 0,
|
|
230
235
|
type: "text",
|
|
231
236
|
onClick: (e) => {
|
|
232
237
|
e.stopPropagation();
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { Badge, Row, Tabs, theme, Tooltip } from "antd";
|
|
4
5
|
import { PlusOutlined } from "@ant-design/icons";
|
|
5
|
-
import { DndContext } from "@dnd-kit/core";
|
|
6
|
-
import { horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable";
|
|
7
|
-
import { CSS } from "@dnd-kit/utilities";
|
|
6
|
+
import { DndContext, DragOverlay, useDraggable, useDroppable } from "@dnd-kit/core";
|
|
8
7
|
import isFunction from "lodash/isFunction";
|
|
9
8
|
import dragSvg from "../../../../../assets/drag.svg";
|
|
10
9
|
import ProIcon from "../../../../../ProIcon";
|
|
@@ -21,6 +20,7 @@ import {
|
|
|
21
20
|
} from "../toolbarActions";
|
|
22
21
|
import { subscribeFormListTabsValidation } from "../tabsValidation";
|
|
23
22
|
const MemoRenderFields = React.memo(RenderFields, memoWith);
|
|
23
|
+
const MAX_TAB_TITLE_LENGTH = 10;
|
|
24
24
|
const getTabErrorCounts = (errorFields, fields, namePath) => {
|
|
25
25
|
const uniqueErrors = /* @__PURE__ */ new Map();
|
|
26
26
|
errorFields.forEach((errorField) => {
|
|
@@ -48,27 +48,40 @@ const SortableTabLabel = ({
|
|
|
48
48
|
draggable,
|
|
49
49
|
fieldKey
|
|
50
50
|
}) => {
|
|
51
|
+
const instanceId = useId();
|
|
52
|
+
const id = `${fieldKey}-${instanceId}`;
|
|
51
53
|
const {
|
|
52
54
|
attributes,
|
|
53
55
|
listeners,
|
|
54
56
|
setActivatorNodeRef,
|
|
55
|
-
setNodeRef,
|
|
56
|
-
transform,
|
|
57
|
-
transition,
|
|
57
|
+
setNodeRef: setDragNodeRef,
|
|
58
58
|
isDragging
|
|
59
|
-
} =
|
|
60
|
-
id
|
|
59
|
+
} = useDraggable({
|
|
60
|
+
id,
|
|
61
|
+
data: { fieldKey },
|
|
61
62
|
disabled: disabled || !draggable
|
|
62
63
|
});
|
|
64
|
+
const { setNodeRef: setDropNodeRef, isOver } = useDroppable({
|
|
65
|
+
id,
|
|
66
|
+
data: { fieldKey },
|
|
67
|
+
disabled: disabled || !draggable
|
|
68
|
+
});
|
|
69
|
+
const setNodeRef = useCallback(
|
|
70
|
+
(node) => {
|
|
71
|
+
setDragNodeRef(node);
|
|
72
|
+
setDropNodeRef(node);
|
|
73
|
+
},
|
|
74
|
+
[setDragNodeRef, setDropNodeRef]
|
|
75
|
+
);
|
|
63
76
|
return /* @__PURE__ */ jsxs(
|
|
64
77
|
"div",
|
|
65
78
|
{
|
|
66
79
|
ref: setNodeRef,
|
|
67
80
|
className: "pro-form-list-tabs-label",
|
|
81
|
+
"data-drag-over": isOver || void 0,
|
|
82
|
+
"data-form-list-field-key": fieldKey,
|
|
68
83
|
style: {
|
|
69
|
-
opacity: isDragging ? 0.4 : void 0
|
|
70
|
-
transform: CSS.Translate.toString(transform),
|
|
71
|
-
transition
|
|
84
|
+
opacity: isDragging ? 0.4 : void 0
|
|
72
85
|
},
|
|
73
86
|
children: [
|
|
74
87
|
!disabled && draggable && /* @__PURE__ */ jsx(
|
|
@@ -78,7 +91,7 @@ const SortableTabLabel = ({
|
|
|
78
91
|
...listeners,
|
|
79
92
|
ref: setActivatorNodeRef,
|
|
80
93
|
className: "pro-form-list-tabs-drag-handle",
|
|
81
|
-
children: /* @__PURE__ */ jsx(ProIcon, { component: dragSvg, size: 16
|
|
94
|
+
children: /* @__PURE__ */ jsx(ProIcon, { component: dragSvg, size: 16 })
|
|
82
95
|
}
|
|
83
96
|
),
|
|
84
97
|
children
|
|
@@ -87,6 +100,20 @@ const SortableTabLabel = ({
|
|
|
87
100
|
);
|
|
88
101
|
};
|
|
89
102
|
const TabsFields = (props) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const { token } = theme.useToken();
|
|
105
|
+
const tabsStyle = {
|
|
106
|
+
"--pro-form-list-tabs-primary": token.colorPrimary,
|
|
107
|
+
"--pro-form-list-tabs-primary-hover": token.colorPrimaryHover,
|
|
108
|
+
"--pro-form-list-tabs-primary-bg": token.colorPrimaryBg,
|
|
109
|
+
"--pro-form-list-tabs-text": token.colorText,
|
|
110
|
+
"--pro-form-list-tabs-muted": token.colorTextDescription,
|
|
111
|
+
"--pro-form-list-tabs-close": token.colorTextQuaternary,
|
|
112
|
+
"--pro-form-list-tabs-border": token.colorBorder,
|
|
113
|
+
"--pro-form-list-tabs-bg": token.colorBgContainer,
|
|
114
|
+
"--pro-form-list-tabs-error": token.colorError,
|
|
115
|
+
"--pro-form-list-tabs-solid-text": token.colorTextLightSolid
|
|
116
|
+
};
|
|
90
117
|
const {
|
|
91
118
|
actionProps,
|
|
92
119
|
diffConfig,
|
|
@@ -108,6 +135,7 @@ const TabsFields = (props) => {
|
|
|
108
135
|
const fieldKeys = fields.map((field) => String(field.key));
|
|
109
136
|
const fieldKeysSignature = fieldKeys.join("\0");
|
|
110
137
|
const [activeKey, setActiveKey] = useState(fieldKeys[0]);
|
|
138
|
+
const [draggedKey, setDraggedKey] = useState();
|
|
111
139
|
const [validationErrorFields, setValidationErrorFields] = useState([]);
|
|
112
140
|
const activeIndexRef = useRef(0);
|
|
113
141
|
const fieldKeysRef = useRef(fieldKeys);
|
|
@@ -136,21 +164,22 @@ const TabsFields = (props) => {
|
|
|
136
164
|
const fallbackIndex = Math.min(activeIndexRef.current, fieldKeys.length - 1);
|
|
137
165
|
setActiveKey(fallbackIndex >= 0 ? fieldKeys[fallbackIndex] : void 0);
|
|
138
166
|
}, [activeKey, fieldKeysSignature]);
|
|
167
|
+
const activateFirstError = useCallback((errorFields) => {
|
|
168
|
+
const counts = getTabErrorCounts(errorFields, fieldsRef.current, namePathRef.current);
|
|
169
|
+
const firstErrorIndex = fieldsRef.current.findIndex((field) => counts.has(String(field.key)));
|
|
170
|
+
if (firstErrorIndex < 0)
|
|
171
|
+
return;
|
|
172
|
+
activeIndexRef.current = firstErrorIndex;
|
|
173
|
+
setActiveKey(String(fieldsRef.current[firstErrorIndex].key));
|
|
174
|
+
}, []);
|
|
139
175
|
useEffect(
|
|
140
176
|
() => subscribeFormListTabsValidation(form, (event) => {
|
|
141
177
|
setValidationErrorFields(event.errorFields);
|
|
142
178
|
if (event.reason !== "submitFailed")
|
|
143
179
|
return;
|
|
144
|
-
|
|
145
|
-
const firstErrorIndex = fieldsRef.current.findIndex(
|
|
146
|
-
(field) => counts.has(String(field.key))
|
|
147
|
-
);
|
|
148
|
-
if (firstErrorIndex < 0)
|
|
149
|
-
return;
|
|
150
|
-
activeIndexRef.current = firstErrorIndex;
|
|
151
|
-
setActiveKey(String(fieldsRef.current[firstErrorIndex].key));
|
|
180
|
+
activateFirstError(event.errorFields);
|
|
152
181
|
}),
|
|
153
|
-
[form]
|
|
182
|
+
[form, activateFirstError]
|
|
154
183
|
);
|
|
155
184
|
const validateCurrent = useCallback(async () => {
|
|
156
185
|
if (!activeKey)
|
|
@@ -165,13 +194,31 @@ const TabsFields = (props) => {
|
|
|
165
194
|
return false;
|
|
166
195
|
}
|
|
167
196
|
}, [activeKey, fieldKeysSignature, form, namePath]);
|
|
197
|
+
const validateAllItems = useCallback(async () => {
|
|
198
|
+
if (!fieldsRef.current.length || !(form == null ? void 0 : form.validateFields))
|
|
199
|
+
return true;
|
|
200
|
+
try {
|
|
201
|
+
await form.validateFields(
|
|
202
|
+
fieldsRef.current.map((field) => [...namePathRef.current, field.name]),
|
|
203
|
+
{ recursive: true }
|
|
204
|
+
);
|
|
205
|
+
setValidationErrorFields([]);
|
|
206
|
+
return true;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error && typeof error === "object" && "errorFields" in error && Array.isArray(error.errorFields) && !("outOfDate" in error && error.outOfDate)) {
|
|
209
|
+
setValidationErrorFields(error.errorFields);
|
|
210
|
+
activateFirstError(error.errorFields);
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}, [form, activateFirstError]);
|
|
168
215
|
const runAfterValidation = useCallback(
|
|
169
|
-
async (callback) => {
|
|
216
|
+
async (callback, validate = validateCurrent) => {
|
|
170
217
|
if (validatingRef.current)
|
|
171
218
|
return false;
|
|
172
219
|
validatingRef.current = true;
|
|
173
220
|
try {
|
|
174
|
-
if (!await
|
|
221
|
+
if (!await validate())
|
|
175
222
|
return false;
|
|
176
223
|
return await callback();
|
|
177
224
|
} finally {
|
|
@@ -199,7 +246,7 @@ const TabsFields = (props) => {
|
|
|
199
246
|
if (!added)
|
|
200
247
|
pendingAddKeysRef.current = null;
|
|
201
248
|
return added;
|
|
202
|
-
});
|
|
249
|
+
}, validateAllItems);
|
|
203
250
|
};
|
|
204
251
|
const handleChange = (nextActiveKey) => {
|
|
205
252
|
if (nextActiveKey === activeKey)
|
|
@@ -214,10 +261,14 @@ const TabsFields = (props) => {
|
|
|
214
261
|
});
|
|
215
262
|
};
|
|
216
263
|
const handleDragEnd = ({ active, over }) => {
|
|
217
|
-
|
|
264
|
+
var _a2, _b;
|
|
265
|
+
setDraggedKey(void 0);
|
|
266
|
+
const sourceKey = (_a2 = active.data.current) == null ? void 0 : _a2.fieldKey;
|
|
267
|
+
const targetKey = (_b = over == null ? void 0 : over.data.current) == null ? void 0 : _b.fieldKey;
|
|
268
|
+
if (!over || sourceKey === targetKey)
|
|
218
269
|
return;
|
|
219
|
-
const activeIndex = fieldKeys.indexOf(
|
|
220
|
-
const overIndex = fieldKeys.indexOf(
|
|
270
|
+
const activeIndex = fieldKeys.indexOf(sourceKey);
|
|
271
|
+
const overIndex = fieldKeys.indexOf(targetKey);
|
|
221
272
|
if (activeIndex >= 0 && overIndex >= 0)
|
|
222
273
|
operation.move(activeIndex, overIndex);
|
|
223
274
|
};
|
|
@@ -233,7 +284,7 @@ const TabsFields = (props) => {
|
|
|
233
284
|
const result = await runAfterValidation(() => {
|
|
234
285
|
didRun = true;
|
|
235
286
|
return callback ? callback(record, option) : item.type === "copy" ? true : void 0;
|
|
236
|
-
});
|
|
287
|
+
}, validateAllItems);
|
|
237
288
|
return didRun ? result : FORM_LIST_ACTION_ABORT;
|
|
238
289
|
}
|
|
239
290
|
};
|
|
@@ -244,6 +295,9 @@ const TabsFields = (props) => {
|
|
|
244
295
|
const record = form.getFieldValue(itemNamePath);
|
|
245
296
|
const tabTitle = isFunction(title) ? title(record, index, form) : title;
|
|
246
297
|
const renderedTitle = tabTitle ?? `Tab ${index + 1}`;
|
|
298
|
+
const titleChars = typeof renderedTitle === "string" || typeof renderedTitle === "number" ? Array.from(String(renderedTitle)) : void 0;
|
|
299
|
+
const isTitleOverflow = titleChars && titleChars.length > MAX_TAB_TITLE_LENGTH;
|
|
300
|
+
const displayTitle = isTitleOverflow ? `${titleChars.slice(0, MAX_TAB_TITLE_LENGTH).join("")}...` : renderedTitle;
|
|
247
301
|
const tabActionProps = wrapValidatedActions(actionProps || void 0);
|
|
248
302
|
const errorCount = errorCounts.get(fieldKey) || 0;
|
|
249
303
|
return {
|
|
@@ -258,33 +312,27 @@ const TabsFields = (props) => {
|
|
|
258
312
|
count: errorCount,
|
|
259
313
|
overflowCount: 99,
|
|
260
314
|
size: "small",
|
|
261
|
-
children: /* @__PURE__ */ jsxs(
|
|
262
|
-
"span",
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
isView
|
|
283
|
-
}
|
|
284
|
-
)
|
|
285
|
-
]
|
|
286
|
-
}
|
|
287
|
-
)
|
|
315
|
+
children: /* @__PURE__ */ jsxs("span", { className: "pro-form-list-tabs-title-content", children: [
|
|
316
|
+
isTitleOverflow ? /* @__PURE__ */ jsx(Tooltip, { title: renderedTitle, placement: "top", children: /* @__PURE__ */ jsx("span", { className: "pro-form-list-tabs-title", children: displayTitle }) }) : /* @__PURE__ */ jsx("span", { className: "pro-form-list-tabs-title", children: displayTitle }),
|
|
317
|
+
actionProps !== false && /* @__PURE__ */ jsx(
|
|
318
|
+
ActionButton,
|
|
319
|
+
{
|
|
320
|
+
min,
|
|
321
|
+
max,
|
|
322
|
+
index,
|
|
323
|
+
length: fields.length,
|
|
324
|
+
operation,
|
|
325
|
+
namePath: itemNamePath,
|
|
326
|
+
form,
|
|
327
|
+
field: { ...field, key: fieldKey },
|
|
328
|
+
fields,
|
|
329
|
+
actionProps: tabActionProps,
|
|
330
|
+
mode: "tabs",
|
|
331
|
+
disabled,
|
|
332
|
+
isView
|
|
333
|
+
}
|
|
334
|
+
)
|
|
335
|
+
] })
|
|
288
336
|
}
|
|
289
337
|
) }),
|
|
290
338
|
children: /* @__PURE__ */ jsx("div", { className: "pro-form-list-tabs-content", children: /* @__PURE__ */ jsx(Row, { gutter: 16, className: "pro-form-list-fields", children: /* @__PURE__ */ jsx(
|
|
@@ -300,16 +348,24 @@ const TabsFields = (props) => {
|
|
|
300
348
|
) }) })
|
|
301
349
|
};
|
|
302
350
|
});
|
|
303
|
-
|
|
304
|
-
|
|
351
|
+
const draggedLabel = (_a = items.find((item) => item.key === draggedKey)) == null ? void 0 : _a.label;
|
|
352
|
+
return /* @__PURE__ */ jsxs(
|
|
353
|
+
DndContext,
|
|
305
354
|
{
|
|
306
|
-
|
|
307
|
-
|
|
355
|
+
onDragStart: ({ active }) => {
|
|
356
|
+
var _a2;
|
|
357
|
+
return setDraggedKey((_a2 = active.data.current) == null ? void 0 : _a2.fieldKey);
|
|
358
|
+
},
|
|
359
|
+
onDragCancel: () => setDraggedKey(void 0),
|
|
360
|
+
onDragEnd: handleDragEnd,
|
|
308
361
|
children: [
|
|
309
362
|
/* @__PURE__ */ jsx(
|
|
310
363
|
Tabs,
|
|
311
364
|
{
|
|
312
365
|
className: "pro-form-list-tabs",
|
|
366
|
+
style: tabsStyle,
|
|
367
|
+
classNames: { popup: { root: "pro-form-list-tabs-dropdown" } },
|
|
368
|
+
more: { overlayStyle: tabsStyle },
|
|
313
369
|
type: "editable-card",
|
|
314
370
|
size: "small",
|
|
315
371
|
activeKey,
|
|
@@ -337,10 +393,26 @@ const TabsFields = (props) => {
|
|
|
337
393
|
emptyBtnText,
|
|
338
394
|
onAdd: handleAdd
|
|
339
395
|
}
|
|
396
|
+
),
|
|
397
|
+
typeof document !== "undefined" && createPortal(
|
|
398
|
+
/* @__PURE__ */ jsx(DragOverlay, { dropAnimation: null, zIndex: token.zIndexPopupBase + 100, children: React.isValidElement(draggedLabel) && /* @__PURE__ */ jsx(
|
|
399
|
+
"div",
|
|
400
|
+
{
|
|
401
|
+
className: "pro-form-list-tabs pro-form-list-tabs-drag-overlay",
|
|
402
|
+
style: tabsStyle,
|
|
403
|
+
"data-active": draggedKey === activeKey,
|
|
404
|
+
"aria-hidden": "true",
|
|
405
|
+
children: /* @__PURE__ */ jsxs("div", { className: "pro-form-list-tabs-label", children: [
|
|
406
|
+
/* @__PURE__ */ jsx("span", { className: "pro-form-list-tabs-drag-handle", children: /* @__PURE__ */ jsx(ProIcon, { component: dragSvg, size: 16 }) }),
|
|
407
|
+
draggedLabel.props.children
|
|
408
|
+
] })
|
|
409
|
+
}
|
|
410
|
+
) }),
|
|
411
|
+
document.body
|
|
340
412
|
)
|
|
341
413
|
]
|
|
342
414
|
}
|
|
343
|
-
)
|
|
415
|
+
);
|
|
344
416
|
};
|
|
345
417
|
var TabsFields_default = TabsFields;
|
|
346
418
|
export {
|