@ant-design/pro-components 3.0.1-0 → 3.1.0-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/pro-components.min.js +1 -1
- package/es/card/ProCard.js +4 -2
- package/es/card/components/Actions/style.d.ts +1 -1
- package/es/card/components/Card/index.js +8 -4
- package/es/card/components/Card/style.d.ts +1 -1
- package/es/card/components/CheckCard/index.d.ts +6 -0
- package/es/card/components/CheckCard/index.js +2 -1
- package/es/card/components/CheckCard/style.d.ts +1 -1
- package/es/card/components/Divider/style.d.ts +1 -1
- package/es/card/components/Loading/style.d.ts +1 -1
- package/es/card/components/Operation/style.d.ts +1 -1
- package/es/card/components/Statistic/style.d.ts +1 -1
- package/es/card/components/Statistic/style.js +2 -6
- package/es/card/components/StatisticCard/index.js +4 -2
- package/es/card/components/StatisticCard/style.d.ts +1 -1
- package/es/card/typing.d.ts +5 -0
- package/es/descriptions/index.js +2 -1
- package/es/field/ValueTypeToComponent.js +4 -4
- package/es/field/components/Cascader/index.d.ts +0 -1
- package/es/field/components/Checkbox/index.d.ts +0 -1
- package/es/field/components/ColorPicker/index.d.ts +1 -1
- package/es/field/components/Percent/util.d.ts +1 -1
- package/es/field/components/Radio/index.d.ts +0 -1
- package/es/field/components/Segmented/index.d.ts +0 -1
- package/es/field/components/Select/LightSelect/index.js +1 -2
- package/es/field/components/Select/SearchSelect/index.d.ts +6 -1
- package/es/field/components/Select/SearchSelect/index.js +101 -15
- package/es/field/components/Select/index.d.ts +0 -3
- package/es/field/components/Select/index.js +5 -3
- package/es/field/components/TreeSelect/index.d.ts +0 -1
- package/es/form/BaseForm/BaseForm.d.ts +3 -0
- package/es/form/BaseForm/BaseForm.js +9 -2
- package/es/form/BaseForm/LightWrapper/style.d.ts +1 -1
- package/es/form/components/Captcha/index.d.ts +8 -2
- package/es/form/components/Captcha/index.js +9 -1
- package/es/form/components/DatePicker/BaseDatePicker.js +20 -12
- package/es/form/components/DateRangePicker/BaseDateRanger.js +38 -13
- package/es/form/components/FormItem/Group/index.js +1 -1
- package/es/form/components/FormItem/Group/style.d.ts +1 -1
- package/es/form/components/List/index.d.ts +1 -1
- package/es/form/components/List/style.d.ts +1 -1
- package/es/form/components/SchemaForm/index.js +1 -2
- package/es/form/components/Text/index.js +4 -2
- package/es/form/components/UploadButton/index.d.ts +1 -1
- package/es/form/components/UploadButton/index.js +3 -3
- package/es/form/index.d.ts +1 -0
- package/es/form/layouts/DrawerForm/index.d.ts +1 -1
- package/es/form/layouts/DrawerForm/index.js +3 -2
- package/es/form/layouts/DrawerForm/style.d.ts +1 -1
- package/es/form/layouts/LightFilter/style.d.ts +1 -1
- package/es/form/layouts/LoginForm/index.d.ts +1 -1
- package/es/form/layouts/LoginForm/style.d.ts +1 -1
- package/es/form/layouts/LoginFormPage/index.d.ts +1 -1
- package/es/form/layouts/LoginFormPage/style.d.ts +1 -1
- package/es/form/layouts/ModalForm/index.js +2 -1
- package/es/form/layouts/ProForm/index.d.ts +1 -1
- package/es/form/layouts/QueryFilter/index.d.ts +2 -1
- package/es/form/layouts/QueryFilter/style.d.ts +1 -1
- package/es/form/layouts/StepsForm/index.js +15 -2
- package/es/form/layouts/StepsForm/style.d.ts +1 -1
- package/es/layout/components/AppsLogoComponents/index.js +3 -1
- package/es/layout/components/AppsLogoComponents/style/index.d.ts +1 -1
- package/es/layout/components/CollapsedIcon/style.d.ts +1 -1
- package/es/layout/components/FooterToolbar/style/index.d.ts +1 -1
- package/es/layout/components/FooterToolbar/style/stylish.d.ts +1 -1
- package/es/layout/components/GlobalFooter/index.d.ts +1 -1
- package/es/layout/components/GlobalFooter/style.d.ts +1 -1
- package/es/layout/components/GlobalHeader/rightContentStyle.d.ts +1 -1
- package/es/layout/components/GlobalHeader/style.d.ts +1 -1
- package/es/layout/components/GridContent/style.d.ts +1 -1
- package/es/layout/components/Header/style/header.d.ts +1 -1
- package/es/layout/components/Header/style/stylish.d.ts +1 -1
- package/es/layout/components/Help/ProHelpDrawer.d.ts +1 -1
- package/es/layout/components/Help/ProHelpDrawer.js +3 -1
- package/es/layout/components/Help/ProHelpPopover.js +1 -1
- package/es/layout/components/Help/style.d.ts +1 -1
- package/es/layout/components/PageContainer/style/index.d.ts +1 -1
- package/es/layout/components/PageContainer/style/stylish.d.ts +1 -1
- package/es/layout/components/PageHeader/style/index.d.ts +1 -1
- package/es/layout/components/SettingDrawer/index.js +2 -2
- package/es/layout/components/SettingDrawer/style/index.d.ts +1 -1
- package/es/layout/components/SiderMenu/BaseMenu.d.ts +1 -1
- package/es/layout/components/SiderMenu/BaseMenu.js +3 -3
- package/es/layout/components/SiderMenu/SiderMenu.js +8 -8
- package/es/layout/components/SiderMenu/index.js +11 -6
- package/es/layout/components/SiderMenu/style/index.d.ts +1 -1
- package/es/layout/components/SiderMenu/style/menu.d.ts +1 -1
- package/es/layout/components/SiderMenu/style/stylish.d.ts +1 -1
- package/es/layout/components/TopNavHeader/style.d.ts +1 -1
- package/es/layout/defaultSettings.d.ts +6 -0
- package/es/layout/style/index.d.ts +1 -1
- package/es/list/style/index.d.ts +1 -1
- package/es/provider/index.d.ts +1 -0
- package/es/provider/index.js +11 -6
- package/es/provider/useStyle/index.d.ts +2 -1
- package/es/provider/useStyle/index.js +20 -12
- package/es/table/Table.js +412 -280
- package/es/table/components/Alert/index.d.ts +1 -1
- package/es/table/components/Alert/style.d.ts +1 -1
- package/es/table/components/ColumnSetting/index.d.ts +1 -1
- package/es/table/components/ColumnSetting/index.js +15 -3
- package/es/table/components/ColumnSetting/style.d.ts +1 -1
- package/es/table/components/DragSortTable/index.d.ts +1 -1
- package/es/table/components/DragSortTable/style.d.ts +1 -1
- package/es/table/components/EditableTable/index.js +530 -197
- package/es/table/components/ListToolBar/style.d.ts +1 -1
- package/es/table/style/index.d.ts +1 -1
- package/es/table/typing.d.ts +37 -12
- package/es/table/useFetchData.js +8 -13
- package/es/table/utils/columnRender.d.ts +1 -1
- package/es/table/utils/genProColumnToColumn.d.ts +2 -2
- package/es/table/utils/genProColumnToColumn.js +5 -17
- package/es/table/utils/index.d.ts +60 -5
- package/es/table/utils/index.js +157 -18
- package/es/utils/components/DropdownFooter/style.d.ts +1 -1
- package/es/utils/components/FieldLabel/style.d.ts +1 -1
- package/es/utils/components/FilterDropdown/index.js +1 -1
- package/es/utils/components/FilterDropdown/style.d.ts +1 -1
- package/es/utils/components/InlineErrorFormItem/style.d.ts +1 -1
- package/es/utils/components/LabelIconTip/style.d.ts +1 -1
- package/es/utils/conversionMomentValue/index.js +14 -2
- package/es/utils/proFieldParsingText/index.js +1 -1
- package/es/utils/typing.d.ts +1 -1
- package/es/utils/useEditableArray/index.d.ts +3 -6
- package/es/utils/useEditableArray/index.js +562 -318
- package/es/utils/useEditableMap/index.js +82 -25
- package/es/utils/useMediaQuery/query.js +11 -5
- package/lib/card/ProCard.js +4 -2
- package/lib/card/components/Actions/style.d.ts +1 -1
- package/lib/card/components/Card/index.js +8 -4
- package/lib/card/components/Card/style.d.ts +1 -1
- package/lib/card/components/CheckCard/index.d.ts +6 -0
- package/lib/card/components/CheckCard/index.js +2 -1
- package/lib/card/components/CheckCard/style.d.ts +1 -1
- package/lib/card/components/Divider/style.d.ts +1 -1
- package/lib/card/components/Loading/style.d.ts +1 -1
- package/lib/card/components/Operation/style.d.ts +1 -1
- package/lib/card/components/Statistic/style.d.ts +1 -1
- package/lib/card/components/Statistic/style.js +2 -6
- package/lib/card/components/StatisticCard/index.js +4 -2
- package/lib/card/components/StatisticCard/style.d.ts +1 -1
- package/lib/card/typing.d.ts +5 -0
- package/lib/descriptions/index.js +2 -1
- package/lib/field/ValueTypeToComponent.js +4 -4
- package/lib/field/components/Cascader/index.d.ts +0 -1
- package/lib/field/components/Checkbox/index.d.ts +0 -1
- package/lib/field/components/ColorPicker/index.d.ts +1 -1
- package/lib/field/components/Percent/util.d.ts +1 -1
- package/lib/field/components/Radio/index.d.ts +0 -1
- package/lib/field/components/Segmented/index.d.ts +0 -1
- package/lib/field/components/Select/LightSelect/index.js +1 -2
- package/lib/field/components/Select/SearchSelect/index.d.ts +6 -1
- package/lib/field/components/Select/SearchSelect/index.js +101 -15
- package/lib/field/components/Select/index.d.ts +0 -3
- package/lib/field/components/Select/index.js +5 -3
- package/lib/field/components/TreeSelect/index.d.ts +0 -1
- package/lib/form/BaseForm/BaseForm.d.ts +3 -0
- package/lib/form/BaseForm/BaseForm.js +9 -2
- package/lib/form/BaseForm/LightWrapper/style.d.ts +1 -1
- package/lib/form/components/Captcha/index.d.ts +8 -2
- package/lib/form/components/Captcha/index.js +9 -1
- package/lib/form/components/DatePicker/BaseDatePicker.js +19 -11
- package/lib/form/components/DateRangePicker/BaseDateRanger.js +37 -12
- package/lib/form/components/Digit/DigitRange.d.ts +1 -1
- package/lib/form/components/FormItem/Group/index.js +1 -1
- package/lib/form/components/FormItem/Group/style.d.ts +1 -1
- package/lib/form/components/List/index.d.ts +1 -1
- package/lib/form/components/List/style.d.ts +1 -1
- package/lib/form/components/SchemaForm/index.js +1 -2
- package/lib/form/components/Text/index.js +4 -2
- package/lib/form/components/UploadButton/index.d.ts +1 -1
- package/lib/form/components/UploadButton/index.js +3 -3
- package/lib/form/index.d.ts +1 -0
- package/lib/form/layouts/DrawerForm/index.d.ts +1 -1
- package/lib/form/layouts/DrawerForm/index.js +3 -2
- package/lib/form/layouts/DrawerForm/style.d.ts +1 -1
- package/lib/form/layouts/LightFilter/style.d.ts +1 -1
- package/lib/form/layouts/LoginForm/index.d.ts +1 -1
- package/lib/form/layouts/LoginForm/style.d.ts +1 -1
- package/lib/form/layouts/LoginFormPage/index.d.ts +1 -1
- package/lib/form/layouts/LoginFormPage/style.d.ts +1 -1
- package/lib/form/layouts/ModalForm/index.js +2 -1
- package/lib/form/layouts/ProForm/index.d.ts +2 -2
- package/lib/form/layouts/QueryFilter/index.d.ts +2 -1
- package/lib/form/layouts/QueryFilter/style.d.ts +1 -1
- package/lib/form/layouts/StepsForm/index.js +15 -2
- package/lib/form/layouts/StepsForm/style.d.ts +1 -1
- package/lib/layout/components/AppsLogoComponents/index.js +3 -1
- package/lib/layout/components/AppsLogoComponents/style/index.d.ts +1 -1
- package/lib/layout/components/CollapsedIcon/style.d.ts +1 -1
- package/lib/layout/components/FooterToolbar/style/index.d.ts +1 -1
- package/lib/layout/components/FooterToolbar/style/stylish.d.ts +1 -1
- package/lib/layout/components/GlobalFooter/index.d.ts +1 -1
- package/lib/layout/components/GlobalFooter/style.d.ts +1 -1
- package/lib/layout/components/GlobalHeader/rightContentStyle.d.ts +1 -1
- package/lib/layout/components/GlobalHeader/style.d.ts +1 -1
- package/lib/layout/components/GridContent/style.d.ts +1 -1
- package/lib/layout/components/Header/style/header.d.ts +1 -1
- package/lib/layout/components/Header/style/stylish.d.ts +1 -1
- package/lib/layout/components/Help/ProHelpDrawer.d.ts +1 -1
- package/lib/layout/components/Help/ProHelpDrawer.js +3 -1
- package/lib/layout/components/Help/ProHelpPopover.js +1 -1
- package/lib/layout/components/Help/style.d.ts +1 -1
- package/lib/layout/components/PageContainer/style/index.d.ts +1 -1
- package/lib/layout/components/PageContainer/style/stylish.d.ts +1 -1
- package/lib/layout/components/PageHeader/style/index.d.ts +1 -1
- package/lib/layout/components/SettingDrawer/index.js +2 -2
- package/lib/layout/components/SettingDrawer/style/index.d.ts +1 -1
- package/lib/layout/components/SiderMenu/BaseMenu.d.ts +1 -1
- package/lib/layout/components/SiderMenu/BaseMenu.js +3 -3
- package/lib/layout/components/SiderMenu/SiderMenu.js +8 -8
- package/lib/layout/components/SiderMenu/index.js +11 -6
- package/lib/layout/components/SiderMenu/style/index.d.ts +1 -1
- package/lib/layout/components/SiderMenu/style/menu.d.ts +1 -1
- package/lib/layout/components/SiderMenu/style/stylish.d.ts +1 -1
- package/lib/layout/components/TopNavHeader/style.d.ts +1 -1
- package/lib/layout/defaultSettings.d.ts +6 -0
- package/lib/layout/style/index.d.ts +1 -1
- package/lib/list/style/index.d.ts +1 -1
- package/lib/provider/index.d.ts +1 -0
- package/lib/provider/index.js +11 -6
- package/lib/provider/useStyle/index.d.ts +2 -1
- package/lib/provider/useStyle/index.js +20 -12
- package/lib/table/Table.js +422 -290
- package/lib/table/components/Alert/index.d.ts +1 -1
- package/lib/table/components/Alert/style.d.ts +1 -1
- package/lib/table/components/ColumnSetting/index.d.ts +1 -1
- package/lib/table/components/ColumnSetting/index.js +15 -3
- package/lib/table/components/ColumnSetting/style.d.ts +1 -1
- package/lib/table/components/DragSortTable/index.d.ts +1 -1
- package/lib/table/components/DragSortTable/style.d.ts +1 -1
- package/lib/table/components/EditableTable/index.js +529 -196
- package/lib/table/components/ListToolBar/style.d.ts +1 -1
- package/lib/table/style/index.d.ts +1 -1
- package/lib/table/typing.d.ts +37 -12
- package/lib/table/useFetchData.js +8 -13
- package/lib/table/utils/columnRender.d.ts +1 -1
- package/lib/table/utils/genProColumnToColumn.d.ts +2 -2
- package/lib/table/utils/genProColumnToColumn.js +4 -16
- package/lib/table/utils/index.d.ts +60 -5
- package/lib/table/utils/index.js +159 -20
- package/lib/utils/components/DropdownFooter/style.d.ts +1 -1
- package/lib/utils/components/FieldLabel/style.d.ts +1 -1
- package/lib/utils/components/FilterDropdown/index.js +1 -1
- package/lib/utils/components/FilterDropdown/style.d.ts +1 -1
- package/lib/utils/components/InlineErrorFormItem/style.d.ts +1 -1
- package/lib/utils/components/LabelIconTip/style.d.ts +1 -1
- package/lib/utils/conversionMomentValue/index.js +14 -2
- package/lib/utils/proFieldParsingText/index.js +1 -1
- package/lib/utils/typing.d.ts +1 -1
- package/lib/utils/useEditableArray/index.d.ts +3 -6
- package/lib/utils/useEditableArray/index.js +568 -324
- package/lib/utils/useEditableMap/index.js +82 -25
- package/lib/utils/useMediaQuery/query.js +10 -4
- package/package.json +45 -45
|
@@ -8,7 +8,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
8
8
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
9
9
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
10
10
|
var _excluded = ["map_row_parentKey"],
|
|
11
|
-
_excluded2 = ["map_row_parentKey", "map_row_key"],
|
|
11
|
+
_excluded2 = ["map_row_parentKey", "map_row_key", "isNewRecord"],
|
|
12
12
|
_excluded3 = ["map_row_key"];
|
|
13
13
|
/* eslint-disable react-hooks/exhaustive-deps */import { LoadingOutlined } from '@ant-design/icons';
|
|
14
14
|
import { get, warning as rcWarning, set, useMergedState } from '@rc-component/util';
|
|
@@ -37,11 +37,132 @@ export var recordKeyToString = function recordKeyToString(rowKey) {
|
|
|
37
37
|
if (Array.isArray(rowKey)) return rowKey.join(',');
|
|
38
38
|
return rowKey;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* 扁平化记录树结构为 Map
|
|
42
|
+
*/
|
|
43
|
+
function flattenRecordsToMap(records, getRowKey, childrenColumnName, parentKey, parentIndex) {
|
|
44
|
+
var kvMap = new Map();
|
|
45
|
+
records.forEach(function (record, index) {
|
|
46
|
+
var eachIndex = (parentIndex || 0) * 10 + index;
|
|
47
|
+
var recordKey = getRowKey(record, eachIndex).toString();
|
|
48
|
+
var hasChildren = record && _typeof(record) === 'object' && childrenColumnName in record;
|
|
49
|
+
if (hasChildren) {
|
|
50
|
+
var children = record[childrenColumnName] || [];
|
|
51
|
+
var childrenMap = flattenRecordsToMap(children, getRowKey, childrenColumnName, recordKey, eachIndex);
|
|
52
|
+
childrenMap.forEach(function (value, key) {
|
|
53
|
+
return kvMap.set(key, value);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
var newRecord = _objectSpread(_objectSpread({}, record), {}, {
|
|
57
|
+
map_row_key: recordKey,
|
|
58
|
+
map_row_parentKey: parentKey
|
|
59
|
+
});
|
|
60
|
+
delete newRecord.children;
|
|
61
|
+
if (!parentKey) {
|
|
62
|
+
delete newRecord.map_row_parentKey;
|
|
63
|
+
}
|
|
64
|
+
kvMap.set(recordKey, newRecord);
|
|
65
|
+
});
|
|
66
|
+
return kvMap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 重建树结构
|
|
71
|
+
*/
|
|
72
|
+
function rebuildTreeStructure(map, childrenColumnName, action) {
|
|
73
|
+
var childrenMap = new Map();
|
|
74
|
+
var result = [];
|
|
75
|
+
var addNewRecordToChildren = function addNewRecordToChildren(fillChildren) {
|
|
76
|
+
map.forEach(function (value) {
|
|
77
|
+
if (value.map_row_parentKey != null && !value.map_row_key) {
|
|
78
|
+
var map_row_parentKey = value.map_row_parentKey,
|
|
79
|
+
rest = _objectWithoutProperties(value, _excluded);
|
|
80
|
+
var parentKeyStr = String(map_row_parentKey);
|
|
81
|
+
if (!childrenMap.has(parentKeyStr)) {
|
|
82
|
+
childrenMap.set(parentKeyStr, []);
|
|
83
|
+
}
|
|
84
|
+
if (fillChildren) {
|
|
85
|
+
var _childrenMap$get;
|
|
86
|
+
(_childrenMap$get = childrenMap.get(parentKeyStr)) === null || _childrenMap$get === void 0 || _childrenMap$get.push(rest);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
addNewRecordToChildren(action === 'top');
|
|
92
|
+
|
|
93
|
+
// 第一步:将所有有 parentKey 的节点添加到 childrenMap
|
|
94
|
+
// 这一步不获取 children,只是添加节点到对应的父节点下
|
|
95
|
+
map.forEach(function (value) {
|
|
96
|
+
if (value.map_row_parentKey != null && value.map_row_key) {
|
|
97
|
+
var _ref = value,
|
|
98
|
+
map_row_parentKey = _ref.map_row_parentKey,
|
|
99
|
+
map_row_key = _ref.map_row_key,
|
|
100
|
+
isNewRecord = _ref.isNewRecord,
|
|
101
|
+
rest = _objectWithoutProperties(_ref, _excluded2);
|
|
102
|
+
var _record = _objectSpread(_objectSpread({}, rest), {}, {
|
|
103
|
+
map_row_key: map_row_key
|
|
104
|
+
});
|
|
105
|
+
// 确保 parentKey 的类型转换与 flattenRecordsToMap 中的 recordKey 一致
|
|
106
|
+
// 在 flattenRecordsToMap 中,recordKey 被转换为字符串:getRowKey(record, eachIndex).toString()
|
|
107
|
+
// 所以这里也需要确保 parentKey 被转换为字符串,并且类型一致
|
|
108
|
+
var parentKeyStr = map_row_parentKey != null ? String(map_row_parentKey) : null;
|
|
109
|
+
if (!parentKeyStr) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!childrenMap.has(parentKeyStr)) {
|
|
113
|
+
childrenMap.set(parentKeyStr, []);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 如果是新记录且 action 为 'top',添加到数组开头;否则添加到末尾
|
|
117
|
+
if (isNewRecord && action === 'top') {
|
|
118
|
+
var _childrenMap$get2;
|
|
119
|
+
(_childrenMap$get2 = childrenMap.get(parentKeyStr)) === null || _childrenMap$get2 === void 0 || _childrenMap$get2.unshift(_record);
|
|
120
|
+
} else {
|
|
121
|
+
var _childrenMap$get3;
|
|
122
|
+
(_childrenMap$get3 = childrenMap.get(parentKeyStr)) === null || _childrenMap$get3 === void 0 || _childrenMap$get3.push(_record);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// 第二步:为所有节点获取 children
|
|
128
|
+
// 这一步确保所有子节点都已经被添加到 childrenMap,所以可以正确获取 children
|
|
129
|
+
map.forEach(function (value) {
|
|
130
|
+
if (value.map_row_parentKey != null && value.map_row_key) {
|
|
131
|
+
var _ref2 = value,
|
|
132
|
+
map_row_parentKey = _ref2.map_row_parentKey,
|
|
133
|
+
map_row_key = _ref2.map_row_key;
|
|
134
|
+
var parentKeyStr = map_row_parentKey != null ? String(map_row_parentKey) : null;
|
|
135
|
+
if (!parentKeyStr) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
var children = childrenMap.get(parentKeyStr);
|
|
139
|
+
if (children && children.length > 0) {
|
|
140
|
+
// 找到对应的 record 并添加 children
|
|
141
|
+
var recordIndex = children.findIndex(function (r) {
|
|
142
|
+
// 比较时需要确保类型一致
|
|
143
|
+
var recordKey = r.map_row_key || r.id;
|
|
144
|
+
return String(recordKey) === String(map_row_key);
|
|
145
|
+
});
|
|
146
|
+
if (recordIndex >= 0 && childrenMap.has(map_row_key)) {
|
|
147
|
+
children[recordIndex] = _objectSpread(_objectSpread({}, children[recordIndex]), {}, _defineProperty({}, childrenColumnName, childrenMap.get(map_row_key)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
addNewRecordToChildren(action === 'update');
|
|
153
|
+
map.forEach(function (value) {
|
|
154
|
+
if (!value.map_row_parentKey) {
|
|
155
|
+
var map_row_key = value.map_row_key,
|
|
156
|
+
rest = _objectWithoutProperties(value, _excluded3);
|
|
157
|
+
var _record2 = map_row_key && childrenMap.has(map_row_key) ? _objectSpread(_objectSpread({}, rest), {}, _defineProperty({}, childrenColumnName, childrenMap.get(map_row_key))) : rest;
|
|
158
|
+
result.push(_record2);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
|
|
40
164
|
/**
|
|
41
165
|
* 使用map 来删除数据,性能一般 但是准确率比较高
|
|
42
|
-
*
|
|
43
|
-
* @param keyProps
|
|
44
|
-
* @param action
|
|
45
166
|
*/
|
|
46
167
|
export function editableRowByKey(keyProps, action) {
|
|
47
168
|
var _recordKeyToString;
|
|
@@ -51,95 +172,25 @@ export function editableRowByKey(keyProps, action) {
|
|
|
51
172
|
_keyProps$childrenCol = keyProps.childrenColumnName,
|
|
52
173
|
childrenColumnName = _keyProps$childrenCol === void 0 ? 'children' : _keyProps$childrenCol;
|
|
53
174
|
var key = (_recordKeyToString = recordKeyToString(keyProps.key)) === null || _recordKeyToString === void 0 ? void 0 : _recordKeyToString.toString();
|
|
54
|
-
var kvMap =
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 打平这个数组
|
|
58
|
-
*
|
|
59
|
-
* @param records
|
|
60
|
-
* @param parentKey
|
|
61
|
-
*/
|
|
62
|
-
function dig(records, map_row_parentKey, map_row_index) {
|
|
63
|
-
records.forEach(function (record, index) {
|
|
64
|
-
var eachIndex = (map_row_index || 0) * 10 + index;
|
|
65
|
-
var recordKey = getRowKey(record, eachIndex).toString();
|
|
66
|
-
// children 取在前面方便拼的时候按照反顺序放回去
|
|
67
|
-
if (record && _typeof(record) === 'object' && childrenColumnName in record) {
|
|
68
|
-
dig(record[childrenColumnName] || [], recordKey, eachIndex);
|
|
69
|
-
}
|
|
70
|
-
var newRecord = _objectSpread(_objectSpread({}, record), {}, {
|
|
71
|
-
map_row_key: recordKey,
|
|
72
|
-
children: undefined,
|
|
73
|
-
map_row_parentKey: map_row_parentKey
|
|
74
|
-
});
|
|
75
|
-
delete newRecord.children;
|
|
76
|
-
if (!map_row_parentKey) {
|
|
77
|
-
delete newRecord.map_row_parentKey;
|
|
78
|
-
}
|
|
79
|
-
kvMap.set(recordKey, newRecord);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (action === 'top') {
|
|
83
|
-
kvMap.set(key, _objectSpread(_objectSpread({}, kvMap.get(key)), row));
|
|
84
|
-
}
|
|
85
|
-
dig(data);
|
|
86
|
-
if (action === 'update') {
|
|
87
|
-
kvMap.set(key, _objectSpread(_objectSpread({}, kvMap.get(key)), row));
|
|
88
|
-
}
|
|
175
|
+
var kvMap = flattenRecordsToMap(data, getRowKey, childrenColumnName);
|
|
89
176
|
if (action === 'delete') {
|
|
90
177
|
kvMap.delete(key);
|
|
178
|
+
} else if (action === 'top' || action === 'update') {
|
|
179
|
+
var existingRecord = kvMap.get(key);
|
|
180
|
+
if (existingRecord) {
|
|
181
|
+
kvMap.set(key, _objectSpread(_objectSpread({}, existingRecord), row));
|
|
182
|
+
} else {
|
|
183
|
+
// 如果记录不存在,创建一个新记录(用于新增场景)
|
|
184
|
+
// 保留 map_row_parentKey 以便正确处理嵌套子节点
|
|
185
|
+
// 添加标记以便在 rebuildTreeStructure 中识别新记录
|
|
186
|
+
kvMap.set(key, _objectSpread(_objectSpread({}, row), {}, {
|
|
187
|
+
map_row_key: key,
|
|
188
|
+
map_row_parentKey: row.map_row_parentKey,
|
|
189
|
+
isNewRecord: true
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
91
192
|
}
|
|
92
|
-
|
|
93
|
-
var kvArrayMap = new Map();
|
|
94
|
-
var kvSource = [];
|
|
95
|
-
var fillNewRecord = function fillNewRecord() {
|
|
96
|
-
var fillChildren = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
97
|
-
map.forEach(function (value) {
|
|
98
|
-
if (value.map_row_parentKey && !value.map_row_key) {
|
|
99
|
-
var map_row_parentKey = value.map_row_parentKey,
|
|
100
|
-
rest = _objectWithoutProperties(value, _excluded);
|
|
101
|
-
if (!kvArrayMap.has(map_row_parentKey)) {
|
|
102
|
-
kvArrayMap.set(map_row_parentKey, []);
|
|
103
|
-
}
|
|
104
|
-
if (fillChildren) {
|
|
105
|
-
var _kvArrayMap$get;
|
|
106
|
-
(_kvArrayMap$get = kvArrayMap.get(map_row_parentKey)) === null || _kvArrayMap$get === void 0 || _kvArrayMap$get.push(rest);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
fillNewRecord(action === 'top');
|
|
112
|
-
map.forEach(function (value) {
|
|
113
|
-
if (value.map_row_parentKey && value.map_row_key) {
|
|
114
|
-
var _kvArrayMap$get2;
|
|
115
|
-
var map_row_parentKey = value.map_row_parentKey,
|
|
116
|
-
map_row_key = value.map_row_key,
|
|
117
|
-
rest = _objectWithoutProperties(value, _excluded2);
|
|
118
|
-
if (kvArrayMap.has(map_row_key)) {
|
|
119
|
-
rest[childrenColumnName] = kvArrayMap.get(map_row_key);
|
|
120
|
-
}
|
|
121
|
-
if (!kvArrayMap.has(map_row_parentKey)) {
|
|
122
|
-
kvArrayMap.set(map_row_parentKey, []);
|
|
123
|
-
}
|
|
124
|
-
(_kvArrayMap$get2 = kvArrayMap.get(map_row_parentKey)) === null || _kvArrayMap$get2 === void 0 || _kvArrayMap$get2.push(rest);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
fillNewRecord(action === 'update');
|
|
128
|
-
map.forEach(function (value) {
|
|
129
|
-
if (!value.map_row_parentKey) {
|
|
130
|
-
var map_row_key = value.map_row_key,
|
|
131
|
-
rest = _objectWithoutProperties(value, _excluded3);
|
|
132
|
-
if (map_row_key && kvArrayMap.has(map_row_key)) {
|
|
133
|
-
var item = _objectSpread(_objectSpread({}, rest), {}, _defineProperty({}, childrenColumnName, kvArrayMap.get(map_row_key)));
|
|
134
|
-
kvSource.push(item);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
kvSource.push(rest);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return kvSource;
|
|
141
|
-
};
|
|
142
|
-
return fill(kvMap);
|
|
193
|
+
return rebuildTreeStructure(kvMap, childrenColumnName, action);
|
|
143
194
|
}
|
|
144
195
|
|
|
145
196
|
/**
|
|
@@ -147,14 +198,14 @@ export function editableRowByKey(keyProps, action) {
|
|
|
147
198
|
*
|
|
148
199
|
* @param ActionRenderConfig
|
|
149
200
|
*/
|
|
150
|
-
export function SaveEditableAction(
|
|
151
|
-
var recordKey =
|
|
152
|
-
onSave =
|
|
153
|
-
row =
|
|
154
|
-
children =
|
|
155
|
-
newLineConfig =
|
|
156
|
-
editorType =
|
|
157
|
-
tableName =
|
|
201
|
+
export function SaveEditableAction(_ref3, ref) {
|
|
202
|
+
var recordKey = _ref3.recordKey,
|
|
203
|
+
onSave = _ref3.onSave,
|
|
204
|
+
row = _ref3.row,
|
|
205
|
+
children = _ref3.children,
|
|
206
|
+
newLineConfig = _ref3.newLineConfig,
|
|
207
|
+
editorType = _ref3.editorType,
|
|
208
|
+
tableName = _ref3.tableName;
|
|
158
209
|
var context = useContext(ProFormContext);
|
|
159
210
|
var form = Form.useFormInstance();
|
|
160
211
|
var _useMountMergeState = useMountMergeState(false),
|
|
@@ -173,11 +224,24 @@ export function SaveEditableAction(_ref, ref) {
|
|
|
173
224
|
return key === null || key === void 0 ? void 0 : key.toString();
|
|
174
225
|
}).flat(1).filter(Boolean);
|
|
175
226
|
setLoading(true);
|
|
176
|
-
_context.
|
|
227
|
+
_context.prev = 4;
|
|
228
|
+
_context.next = 7;
|
|
177
229
|
return form.validateFields(namePath, {
|
|
178
230
|
recursive: true
|
|
179
231
|
});
|
|
180
|
-
case
|
|
232
|
+
case 7:
|
|
233
|
+
_context.next = 13;
|
|
234
|
+
break;
|
|
235
|
+
case 9:
|
|
236
|
+
_context.prev = 9;
|
|
237
|
+
_context.t0 = _context["catch"](4);
|
|
238
|
+
setLoading(false);
|
|
239
|
+
// 重新抛出验证错误,让表单显示错误信息
|
|
240
|
+
// validateFields 抛出错误时,表单会自动设置错误状态并显示错误
|
|
241
|
+
// 错误对象包含 errorFields,表单会根据这些字段显示错误
|
|
242
|
+
// 确保错误被正确传播,这样表单可以正确显示验证错误
|
|
243
|
+
throw _context.t0;
|
|
244
|
+
case 13:
|
|
181
245
|
fields = (context === null || context === void 0 || (_context$getFieldForm = context.getFieldFormatValue) === null || _context$getFieldForm === void 0 ? void 0 : _context$getFieldForm.call(context, namePath)) || form.getFieldValue(namePath); // 处理 dataIndex 为数组的情况
|
|
182
246
|
if (Array.isArray(recordKey) && recordKey.length > 1) {
|
|
183
247
|
// 获取 namepath
|
|
@@ -186,25 +250,25 @@ export function SaveEditableAction(_ref, ref) {
|
|
|
186
250
|
set(fields, recordKeyPath, curValue);
|
|
187
251
|
}
|
|
188
252
|
data = isMapEditor ? set({}, namePath, fields) : fields; // 获取数据并保存
|
|
189
|
-
_context.next =
|
|
253
|
+
_context.next = 18;
|
|
190
254
|
return onSave === null || onSave === void 0 ? void 0 : onSave(recordKey,
|
|
191
255
|
// 如果是 map 模式,fields 就是一个值,所以需要set 到对象中
|
|
192
256
|
// 数据模式 fields 是一个对象,所以不需要
|
|
193
257
|
merge({}, row, data), row, newLineConfig);
|
|
194
|
-
case
|
|
258
|
+
case 18:
|
|
195
259
|
res = _context.sent;
|
|
196
260
|
setLoading(false);
|
|
197
261
|
return _context.abrupt("return", res);
|
|
198
|
-
case
|
|
199
|
-
_context.prev =
|
|
200
|
-
_context.
|
|
262
|
+
case 23:
|
|
263
|
+
_context.prev = 23;
|
|
264
|
+
_context.t1 = _context["catch"](0);
|
|
201
265
|
setLoading(false);
|
|
202
|
-
throw _context.
|
|
203
|
-
case
|
|
266
|
+
throw _context.t1;
|
|
267
|
+
case 27:
|
|
204
268
|
case "end":
|
|
205
269
|
return _context.stop();
|
|
206
270
|
}
|
|
207
|
-
}, _callee, null, [[0,
|
|
271
|
+
}, _callee, null, [[0, 23], [4, 9]]);
|
|
208
272
|
})));
|
|
209
273
|
|
|
210
274
|
// 保存数据
|
|
@@ -215,7 +279,7 @@ export function SaveEditableAction(_ref, ref) {
|
|
|
215
279
|
}, [save]);
|
|
216
280
|
return /*#__PURE__*/_jsxs("a", {
|
|
217
281
|
onClick: ( /*#__PURE__*/function () {
|
|
218
|
-
var
|
|
282
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(e) {
|
|
219
283
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
220
284
|
while (1) switch (_context2.prev = _context2.next) {
|
|
221
285
|
case 0:
|
|
@@ -237,7 +301,7 @@ export function SaveEditableAction(_ref, ref) {
|
|
|
237
301
|
}, _callee2, null, [[2, 7]]);
|
|
238
302
|
}));
|
|
239
303
|
return function (_x) {
|
|
240
|
-
return
|
|
304
|
+
return _ref5.apply(this, arguments);
|
|
241
305
|
};
|
|
242
306
|
}()),
|
|
243
307
|
children: [loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
@@ -252,20 +316,20 @@ export function SaveEditableAction(_ref, ref) {
|
|
|
252
316
|
*
|
|
253
317
|
* @param ActionRenderConfig
|
|
254
318
|
*/
|
|
255
|
-
export var DeleteEditableAction = function DeleteEditableAction(
|
|
256
|
-
var recordKey =
|
|
257
|
-
onDelete =
|
|
258
|
-
preEditRowRef =
|
|
259
|
-
row =
|
|
260
|
-
children =
|
|
261
|
-
deletePopconfirmMessage =
|
|
319
|
+
export var DeleteEditableAction = function DeleteEditableAction(_ref6) {
|
|
320
|
+
var recordKey = _ref6.recordKey,
|
|
321
|
+
onDelete = _ref6.onDelete,
|
|
322
|
+
preEditRowRef = _ref6.preEditRowRef,
|
|
323
|
+
row = _ref6.row,
|
|
324
|
+
children = _ref6.children,
|
|
325
|
+
deletePopconfirmMessage = _ref6.deletePopconfirmMessage;
|
|
262
326
|
var _useMountMergeState3 = useMountMergeState(function () {
|
|
263
327
|
return false;
|
|
264
328
|
}),
|
|
265
329
|
_useMountMergeState4 = _slicedToArray(_useMountMergeState3, 2),
|
|
266
330
|
loading = _useMountMergeState4[0],
|
|
267
331
|
setLoading = _useMountMergeState4[1];
|
|
268
|
-
var
|
|
332
|
+
var onConfirm = useRefFunction( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
269
333
|
var res;
|
|
270
334
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
271
335
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -277,26 +341,34 @@ export var DeleteEditableAction = function DeleteEditableAction(_ref4) {
|
|
|
277
341
|
case 4:
|
|
278
342
|
res = _context3.sent;
|
|
279
343
|
setLoading(false);
|
|
344
|
+
// 如果返回 false,阻止删除操作
|
|
345
|
+
if (!(res === false)) {
|
|
346
|
+
_context3.next = 8;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
return _context3.abrupt("return", false);
|
|
350
|
+
case 8:
|
|
280
351
|
return _context3.abrupt("return", res);
|
|
281
|
-
case
|
|
282
|
-
_context3.prev =
|
|
352
|
+
case 11:
|
|
353
|
+
_context3.prev = 11;
|
|
283
354
|
_context3.t0 = _context3["catch"](0);
|
|
284
355
|
setLoading(false);
|
|
285
356
|
return _context3.abrupt("return", null);
|
|
286
|
-
case
|
|
287
|
-
_context3.prev =
|
|
357
|
+
case 15:
|
|
358
|
+
_context3.prev = 15;
|
|
288
359
|
if (preEditRowRef) preEditRowRef.current = null;
|
|
289
|
-
return _context3.finish(
|
|
290
|
-
case
|
|
360
|
+
return _context3.finish(15);
|
|
361
|
+
case 18:
|
|
291
362
|
case "end":
|
|
292
363
|
return _context3.stop();
|
|
293
364
|
}
|
|
294
|
-
}, _callee3, null, [[0,
|
|
365
|
+
}, _callee3, null, [[0, 11, 15, 18]]);
|
|
295
366
|
})));
|
|
296
367
|
return children !== false ? /*#__PURE__*/_jsx(Popconfirm, {
|
|
297
|
-
title: deletePopconfirmMessage,
|
|
298
|
-
onConfirm:
|
|
299
|
-
|
|
368
|
+
title: deletePopconfirmMessage || '确定要删除这条记录吗?',
|
|
369
|
+
onConfirm: onConfirm,
|
|
370
|
+
getPopupContainer: function getPopupContainer(triggerNode) {
|
|
371
|
+
return triggerNode.parentElement || document.body;
|
|
300
372
|
},
|
|
301
373
|
children: /*#__PURE__*/_jsxs("a", {
|
|
302
374
|
children: [loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
@@ -321,7 +393,7 @@ var CancelEditableAction = function CancelEditableAction(props) {
|
|
|
321
393
|
var form = Form.useFormInstance();
|
|
322
394
|
return /*#__PURE__*/_jsx("a", {
|
|
323
395
|
onClick: ( /*#__PURE__*/function () {
|
|
324
|
-
var
|
|
396
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(e) {
|
|
325
397
|
var _context$getFieldForm2;
|
|
326
398
|
var isMapEditor, namePath, fields, record, res, _props$onDelete;
|
|
327
399
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
@@ -360,7 +432,7 @@ var CancelEditableAction = function CancelEditableAction(props) {
|
|
|
360
432
|
}, _callee4);
|
|
361
433
|
}));
|
|
362
434
|
return function (_x2) {
|
|
363
|
-
return
|
|
435
|
+
return _ref8.apply(this, arguments);
|
|
364
436
|
};
|
|
365
437
|
}()),
|
|
366
438
|
children: cancelText || '取消'
|
|
@@ -407,30 +479,39 @@ export function useEditableArray(props) {
|
|
|
407
479
|
_useState2 = _slicedToArray(_useState, 2),
|
|
408
480
|
newLineRecordCache = _useState2[0],
|
|
409
481
|
setNewLineRecordCache = _useState2[1];
|
|
410
|
-
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* 构建数据源 key 索引映射表
|
|
485
|
+
*/
|
|
486
|
+
var buildDataSourceKeyIndexMap = useRefFunction(function () {
|
|
411
487
|
var map = new Map();
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
var
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
488
|
+
var traverseRecords = function traverseRecords(records, parentKey) {
|
|
489
|
+
records === null || records === void 0 || records.forEach(function (record, index) {
|
|
490
|
+
var indexKey = parentKey == null ? index.toString() : "".concat(parentKey, "_").concat(index);
|
|
491
|
+
var recordKey = recordKeyToString(props.getRowKey(record, -1));
|
|
492
|
+
|
|
493
|
+
// 如果 recordKey 是 undefined 或 null,跳过
|
|
494
|
+
if (recordKey == null) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
map.set(indexKey, recordKey);
|
|
498
|
+
map.set(recordKey.toString(), indexKey);
|
|
499
|
+
var children = props.childrenColumnName && (record === null || record === void 0 ? void 0 : record[props.childrenColumnName]);
|
|
500
|
+
if (children) {
|
|
501
|
+
traverseRecords(children, indexKey);
|
|
421
502
|
}
|
|
422
503
|
});
|
|
423
504
|
};
|
|
424
|
-
|
|
505
|
+
traverseRecords(props.dataSource);
|
|
425
506
|
return map;
|
|
426
|
-
};
|
|
507
|
+
});
|
|
427
508
|
var initDataSourceKeyIndexMap = useMemo(function () {
|
|
428
|
-
return
|
|
509
|
+
return buildDataSourceKeyIndexMap();
|
|
429
510
|
}, []);
|
|
430
511
|
var dataSourceKeyIndexMapRef = useRef(initDataSourceKeyIndexMap);
|
|
431
512
|
var newLineRecordRef = useRef(undefined);
|
|
432
513
|
useDeepCompareEffectDebounce(function () {
|
|
433
|
-
dataSourceKeyIndexMapRef.current =
|
|
514
|
+
dataSourceKeyIndexMapRef.current = buildDataSourceKeyIndexMap();
|
|
434
515
|
}, [props.dataSource]);
|
|
435
516
|
|
|
436
517
|
// 这里这么做是为了存上次的状态,不然每次存一下再拿
|
|
@@ -457,96 +538,205 @@ export function useEditableArray(props) {
|
|
|
457
538
|
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
|
458
539
|
editableKeys = _useMergedState2[0],
|
|
459
540
|
setEditableRowKeys = _useMergedState2[1];
|
|
460
|
-
|
|
461
|
-
/** 一个用来标志的set 提供了方便的 api 来去重什么的 */
|
|
462
|
-
var editableKeysSet = useMemo(function () {
|
|
463
|
-
var keys = editableType === 'single' ? editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.slice(0, 1) : editableKeys;
|
|
464
|
-
return new Set(keys);
|
|
465
|
-
}, [(editableKeys || []).join(','), editableType]);
|
|
466
541
|
var editableKeysRef = usePrevious(editableKeys);
|
|
467
542
|
|
|
543
|
+
/**
|
|
544
|
+
* 检查 key 是否在编辑列表中
|
|
545
|
+
*/
|
|
546
|
+
var checkKeyInEditableList = useRefFunction(function (key, keysList) {
|
|
547
|
+
return keysList.includes(key);
|
|
548
|
+
});
|
|
549
|
+
|
|
468
550
|
/** 这行是不是编辑状态 */
|
|
469
551
|
var isEditable = useRefFunction(function (row) {
|
|
470
|
-
var _props$getRowKey, _props$
|
|
471
|
-
|
|
472
|
-
var
|
|
473
|
-
|
|
474
|
-
var recordKey = (_props$getRowKey2 = props.getRowKey(row, -1)) === null || _props$getRowKey2 === void 0 || (_props$getRowKey2$toS = _props$getRowKey2.toString) === null || _props$getRowKey2$toS === void 0 ? void 0 : _props$getRowKey2$toS.call(_props$getRowKey2);
|
|
475
|
-
|
|
476
|
-
// 都转化为了字符串,不然 number 和 string
|
|
477
|
-
var stringEditableKeys = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.map(function (key) {
|
|
552
|
+
var _props$getRowKey, _props$getRowKey2;
|
|
553
|
+
var recordKeyWithIndex = (_props$getRowKey = props.getRowKey(row, row.index)) === null || _props$getRowKey === void 0 ? void 0 : _props$getRowKey.toString();
|
|
554
|
+
var recordKey = (_props$getRowKey2 = props.getRowKey(row, -1)) === null || _props$getRowKey2 === void 0 ? void 0 : _props$getRowKey2.toString();
|
|
555
|
+
var stringEditableKeys = (editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.map(function (key) {
|
|
478
556
|
return key === null || key === void 0 ? void 0 : key.toString();
|
|
479
|
-
});
|
|
557
|
+
})) || [];
|
|
480
558
|
var stringEditableKeysRef = (editableKeysRef === null || editableKeysRef === void 0 ? void 0 : editableKeysRef.map(function (key) {
|
|
481
559
|
return key === null || key === void 0 ? void 0 : key.toString();
|
|
482
560
|
})) || [];
|
|
483
|
-
var preIsEditable =
|
|
561
|
+
var preIsEditable = checkKeyInEditableList(recordKey, stringEditableKeysRef) || checkKeyInEditableList(recordKeyWithIndex, stringEditableKeysRef);
|
|
484
562
|
return {
|
|
485
563
|
recordKey: recordKey,
|
|
486
|
-
isEditable:
|
|
564
|
+
isEditable: checkKeyInEditableList(recordKey, stringEditableKeys) || checkKeyInEditableList(recordKeyWithIndex, stringEditableKeys),
|
|
487
565
|
preIsEditable: preIsEditable
|
|
488
566
|
};
|
|
489
567
|
});
|
|
490
568
|
|
|
491
569
|
/**
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* @param recordKey
|
|
570
|
+
* 验证是否可以开始编辑
|
|
495
571
|
*/
|
|
496
|
-
var
|
|
497
|
-
var
|
|
498
|
-
|
|
499
|
-
if (editableKeysSet.size > 0 && editableType === 'single' && props.onlyOneLineEditorAlertMessage !== false) {
|
|
572
|
+
var validateCanStartEdit = useRefFunction(function () {
|
|
573
|
+
var hasEditableKeys = editableKeys && editableKeys.length > 0;
|
|
574
|
+
if (hasEditableKeys && editableType === 'single' && props.onlyOneLineEditorAlertMessage !== false) {
|
|
500
575
|
warning(props.onlyOneLineEditorAlertMessage || intl.getMessage('editableTable.onlyOneLineEditor', '只能同时编辑一行'));
|
|
501
576
|
return false;
|
|
502
577
|
}
|
|
503
|
-
|
|
504
|
-
|
|
578
|
+
return true;
|
|
579
|
+
});
|
|
505
580
|
|
|
506
|
-
|
|
507
|
-
|
|
581
|
+
/**
|
|
582
|
+
* 查找记录
|
|
583
|
+
*/
|
|
584
|
+
var findRecordByKey = useRefFunction(function (recordKey) {
|
|
585
|
+
var _props$dataSource$fin, _props$dataSource;
|
|
586
|
+
return (_props$dataSource$fin = (_props$dataSource = props.dataSource) === null || _props$dataSource === void 0 ? void 0 : _props$dataSource.find(function (recordData, index) {
|
|
508
587
|
return props.getRowKey(recordData, index) === recordKey;
|
|
509
|
-
})) !== null &&
|
|
588
|
+
})) !== null && _props$dataSource$fin !== void 0 ? _props$dataSource$fin : null;
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* 进入编辑状态
|
|
593
|
+
*/
|
|
594
|
+
var startEditable = useRefFunction(function (recordKey, record) {
|
|
595
|
+
var _ref9;
|
|
596
|
+
if (!validateCanStartEdit()) {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
var isAlreadyEditable = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.some(function (key) {
|
|
600
|
+
return key === recordKey || (key === null || key === void 0 ? void 0 : key.toString()) === (recordKey === null || recordKey === void 0 ? void 0 : recordKey.toString());
|
|
601
|
+
});
|
|
602
|
+
if (!isAlreadyEditable) {
|
|
603
|
+
var newKeys = editableKeys ? [].concat(_toConsumableArray(editableKeys), [recordKey]) : [recordKey];
|
|
604
|
+
setEditableRowKeys(newKeys);
|
|
605
|
+
}
|
|
606
|
+
preEditRowRef.current = (_ref9 = record !== null && record !== void 0 ? record : findRecordByKey(recordKey)) !== null && _ref9 !== void 0 ? _ref9 : null;
|
|
510
607
|
return true;
|
|
511
608
|
});
|
|
512
609
|
|
|
610
|
+
/**
|
|
611
|
+
* 清理编辑状态
|
|
612
|
+
*/
|
|
613
|
+
var clearEditableState = useRefFunction(function (recordKey) {
|
|
614
|
+
var _editableKeys$filter;
|
|
615
|
+
var relayKey = recordKeyToString(recordKey);
|
|
616
|
+
var relayKeyStr = relayKey != null ? relayKey.toString() : null;
|
|
617
|
+
if (relayKeyStr == null) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
var newKeys = (_editableKeys$filter = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.filter(function (key) {
|
|
621
|
+
return (key === null || key === void 0 ? void 0 : key.toString()) !== relayKeyStr && key !== relayKey;
|
|
622
|
+
})) !== null && _editableKeys$filter !== void 0 ? _editableKeys$filter : [];
|
|
623
|
+
setEditableRowKeys(newKeys);
|
|
624
|
+
});
|
|
625
|
+
|
|
513
626
|
/**
|
|
514
627
|
* 退出编辑状态
|
|
515
|
-
*
|
|
516
|
-
* @param recordKey
|
|
517
628
|
*/
|
|
518
629
|
var cancelEditable = useRefFunction( /*#__PURE__*/function () {
|
|
519
|
-
var
|
|
520
|
-
var relayKey,
|
|
630
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(recordKey, needReTry) {
|
|
631
|
+
var relayKey, relayKeyStr, mappedKey, isInEditableSet, _newLineRecordCache$o, keyForFind, _record3, _originRow, cacheRecordKey, cacheKey, cacheKeyStr, _newLineConfig, _recordKeyToString2, _cacheRecordKey, _cacheKeyStr, originRow, _props$formProps, formRef, _form, namePath, _recordKeyToString3, recordKeyStr;
|
|
521
632
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
522
633
|
while (1) switch (_context5.prev = _context5.next) {
|
|
523
634
|
case 0:
|
|
524
|
-
relayKey = recordKeyToString(recordKey)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
635
|
+
relayKey = recordKeyToString(recordKey);
|
|
636
|
+
relayKeyStr = relayKey != null ? relayKey.toString() : null;
|
|
637
|
+
mappedKey = relayKeyStr != null ? dataSourceKeyIndexMapRef.current.get(relayKeyStr) : undefined;
|
|
638
|
+
isInEditableSet = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.some(function (key) {
|
|
639
|
+
if (relayKeyStr == null) return false;
|
|
640
|
+
return (key === null || key === void 0 ? void 0 : key.toString()) === relayKeyStr || key === relayKey;
|
|
641
|
+
});
|
|
642
|
+
if (!(!isInEditableSet && mappedKey && (needReTry !== null && needReTry !== void 0 ? needReTry : true) && props.tableName)) {
|
|
643
|
+
_context5.next = 8;
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
_context5.next = 7;
|
|
647
|
+
return cancelEditable(mappedKey, false);
|
|
648
|
+
case 7:
|
|
649
|
+
return _context5.abrupt("return", _context5.sent);
|
|
650
|
+
case 8:
|
|
651
|
+
if (!(props.onCancel && isInEditableSet)) {
|
|
652
|
+
_context5.next = 24;
|
|
529
653
|
break;
|
|
530
654
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
655
|
+
keyForFind = Array.isArray(recordKey) ? recordKey[0] : recordKey;
|
|
656
|
+
_record3 = findRecordByKey(keyForFind);
|
|
657
|
+
_originRow = preEditRowRef.current; // 比较 recordKey 时需要考虑类型转换
|
|
658
|
+
// newLineRecordCache.options.recordKey 是 addEditRecord 时设置的 recordKey
|
|
659
|
+
// 而 recordKey 是 cancelEditable 的参数,需要确保它们匹配
|
|
660
|
+
cacheRecordKey = newLineRecordCache === null || newLineRecordCache === void 0 || (_newLineRecordCache$o = newLineRecordCache.options) === null || _newLineRecordCache$o === void 0 ? void 0 : _newLineRecordCache$o.recordKey;
|
|
661
|
+
cacheKey = cacheRecordKey != null ? recordKeyToString(cacheRecordKey) : null;
|
|
662
|
+
cacheKeyStr = cacheKey != null ? cacheKey.toString() : null; // 检查 newLineRecordCache 是否匹配当前的 recordKey
|
|
663
|
+
_newLineConfig = newLineRecordCache != null && cacheRecordKey != null && (cacheRecordKey === recordKey || cacheKeyStr != null && relayKeyStr != null && cacheKeyStr === relayKeyStr || (cacheRecordKey === null || cacheRecordKey === void 0 ? void 0 : cacheRecordKey.toString()) === (recordKey === null || recordKey === void 0 ? void 0 : recordKey.toString()) || String(cacheRecordKey) === String(recordKey)) ? newLineRecordCache : undefined; // 调用 onCancel,即使找不到记录(新行编辑场景)
|
|
664
|
+
// 对于新行编辑,record 可能为 null,但 newLineConfig 应该包含 defaultValue
|
|
665
|
+
_context5.prev = 16;
|
|
666
|
+
_context5.next = 19;
|
|
667
|
+
return props.onCancel(recordKey, _record3 || (_newLineConfig === null || _newLineConfig === void 0 ? void 0 : _newLineConfig.defaultValue) || {}, _originRow || _record3 || (_newLineConfig === null || _newLineConfig === void 0 ? void 0 : _newLineConfig.defaultValue) || {}, _newLineConfig);
|
|
668
|
+
case 19:
|
|
669
|
+
_context5.next = 24;
|
|
670
|
+
break;
|
|
671
|
+
case 21:
|
|
672
|
+
_context5.prev = 21;
|
|
673
|
+
_context5.t0 = _context5["catch"](16);
|
|
674
|
+
// 如果 onCancel 抛出异常,仍然继续清理状态
|
|
675
|
+
console.error('onCancel error:', _context5.t0);
|
|
676
|
+
case 24:
|
|
677
|
+
// 清理 newLineRecordCache,需要比较 recordKey(考虑类型转换)
|
|
678
|
+
if (newLineRecordCache) {
|
|
679
|
+
_cacheRecordKey = newLineRecordCache.options.recordKey; // 重用之前计算的 relayKeyStr
|
|
680
|
+
_cacheKeyStr = _cacheRecordKey != null ? (_recordKeyToString2 = recordKeyToString(_cacheRecordKey)) === null || _recordKeyToString2 === void 0 ? void 0 : _recordKeyToString2.toString() : null;
|
|
681
|
+
if (_cacheRecordKey === recordKey || _cacheKeyStr != null && relayKeyStr != null && _cacheKeyStr === relayKeyStr || (_cacheRecordKey === null || _cacheRecordKey === void 0 ? void 0 : _cacheRecordKey.toString()) === (recordKey === null || recordKey === void 0 ? void 0 : recordKey.toString()) || String(_cacheRecordKey) === String(recordKey)) {
|
|
682
|
+
setNewLineRecordCache(undefined);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// 先清理 preEditRowRef 并重置表单字段,然后再清除编辑状态
|
|
687
|
+
// 这样在清除编辑状态前,表单字段已经被清除,表格重新渲染时就不会显示输入框
|
|
688
|
+
originRow = preEditRowRef.current;
|
|
689
|
+
if (originRow && props.getRowKey(originRow, -1) === recordKey && isInEditableSet) {
|
|
690
|
+
try {
|
|
691
|
+
// 尝试通过 formProps.formRef 访问 form
|
|
692
|
+
formRef = (_props$formProps = props.formProps) === null || _props$formProps === void 0 ? void 0 : _props$formProps.formRef;
|
|
693
|
+
_form = (formRef === null || formRef === void 0 ? void 0 : formRef.current) || props.form;
|
|
694
|
+
if (_form) {
|
|
695
|
+
if (props.tableName) {
|
|
696
|
+
// name 模式:重置为原始值
|
|
697
|
+
namePath = [props.tableName, recordKey].flat(1).filter(Boolean);
|
|
698
|
+
_form.setFieldsValue(set({}, namePath, originRow));
|
|
699
|
+
} else {
|
|
700
|
+
// 非 name 模式:清除该行的所有表单字段
|
|
701
|
+
// 在非 name 模式下,表单字段路径是 [recordKey, columnDataIndex]
|
|
702
|
+
// 如 [624748504, 'title'],需要清除所有以 recordKey 开头的字段
|
|
703
|
+
recordKeyStr = (_recordKeyToString3 = recordKeyToString(recordKey)) === null || _recordKeyToString3 === void 0 ? void 0 : _recordKeyToString3.toString();
|
|
704
|
+
if (recordKeyStr) {
|
|
705
|
+
try {
|
|
706
|
+
// 在非 name 模式下,表单字段以嵌套对象的形式存储
|
|
707
|
+
// 比如 { '624748504': { 'title': 'value', 'state': 'value' } }
|
|
708
|
+
// 需要清除整个嵌套对象
|
|
709
|
+
// 先使用 resetFields 清除字段状态
|
|
710
|
+
_form.resetFields([[recordKeyStr]]);
|
|
711
|
+
|
|
712
|
+
// 然后使用 setFieldsValue 清除字段值
|
|
713
|
+
// 这样可以确保字段被完全清除,表格重新渲染时不会显示输入框
|
|
714
|
+
_form.setFieldsValue(_defineProperty({}, recordKeyStr, undefined));
|
|
715
|
+
} catch (error) {
|
|
716
|
+
// 如果清除失败,忽略错误
|
|
717
|
+
console.warn('Failed to clear form fields in cancelEditable:', error);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
} catch (error) {
|
|
723
|
+
// 如果访问 form 失败,忽略错误
|
|
724
|
+
console.warn('Failed to reset form fields in cancelEditable:', error);
|
|
725
|
+
}
|
|
726
|
+
preEditRowRef.current = null;
|
|
537
727
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
728
|
+
|
|
729
|
+
// 最后清除编辑状态,这样表格会重新渲染,输入框会消失
|
|
730
|
+
clearEditableState(recordKey);
|
|
541
731
|
return _context5.abrupt("return", true);
|
|
542
|
-
case
|
|
732
|
+
case 29:
|
|
543
733
|
case "end":
|
|
544
734
|
return _context5.stop();
|
|
545
735
|
}
|
|
546
|
-
}, _callee5);
|
|
736
|
+
}, _callee5, null, [[16, 21]]);
|
|
547
737
|
}));
|
|
548
738
|
return function (_x3, _x4) {
|
|
549
|
-
return
|
|
739
|
+
return _ref10.apply(this, arguments);
|
|
550
740
|
};
|
|
551
741
|
}());
|
|
552
742
|
var propsOnValuesChange = useDebounceFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
@@ -569,149 +759,199 @@ export function useEditableArray(props) {
|
|
|
569
759
|
}
|
|
570
760
|
}, _callee6);
|
|
571
761
|
})), 64);
|
|
572
|
-
var onValuesChange = useRefFunction(function (value, values) {
|
|
573
|
-
var _Object$keys$pop;
|
|
574
|
-
if (!props.onValuesChange) {
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
var dataSource = props.dataSource;
|
|
578
762
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
763
|
+
/**
|
|
764
|
+
* 构建表单字段路径
|
|
765
|
+
*/
|
|
766
|
+
var buildFormFieldPath = useRefFunction(function (recordKey) {
|
|
767
|
+
return [props.tableName || '', recordKey].flat(1).filter(function (key) {
|
|
768
|
+
return key || key === 0;
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* 更新数据源中的编辑行
|
|
774
|
+
*/
|
|
775
|
+
var updateDataSourceWithEditableRows = useRefFunction(function (dataSource, values) {
|
|
776
|
+
var updatedDataSource = dataSource;
|
|
582
777
|
editableKeys === null || editableKeys === void 0 || editableKeys.forEach(function (eachRecordKey) {
|
|
583
|
-
if ((newLineRecordCache === null || newLineRecordCache === void 0 ? void 0 : newLineRecordCache.options.recordKey) === eachRecordKey)
|
|
778
|
+
if ((newLineRecordCache === null || newLineRecordCache === void 0 ? void 0 : newLineRecordCache.options.recordKey) === eachRecordKey) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
584
781
|
var recordKey = eachRecordKey.toString();
|
|
585
|
-
|
|
586
|
-
var editRow = get(values,
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
data:
|
|
782
|
+
var fieldPath = buildFormFieldPath(recordKey);
|
|
783
|
+
var editRow = get(values, fieldPath);
|
|
784
|
+
if (!editRow) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
updatedDataSource = editableRowByKey({
|
|
788
|
+
data: updatedDataSource,
|
|
592
789
|
getRowKey: props.getRowKey,
|
|
593
790
|
row: editRow,
|
|
594
791
|
key: recordKey,
|
|
595
792
|
childrenColumnName: props.childrenColumnName || 'children'
|
|
596
793
|
}, 'update');
|
|
597
794
|
});
|
|
598
|
-
|
|
599
|
-
|
|
795
|
+
return updatedDataSource;
|
|
796
|
+
});
|
|
600
797
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
798
|
+
/**
|
|
799
|
+
* 获取当前编辑的行数据
|
|
800
|
+
*/
|
|
801
|
+
var getCurrentEditRow = useRefFunction(function (value, values, dataSource) {
|
|
802
|
+
var _valueKeys$pop;
|
|
803
|
+
var valueKeys = Object.keys(value || {});
|
|
804
|
+
if (valueKeys.length === 0) {
|
|
805
|
+
return (newLineRecordCache === null || newLineRecordCache === void 0 ? void 0 : newLineRecordCache.defaultValue) || {};
|
|
806
|
+
}
|
|
807
|
+
var recordKey = ((_valueKeys$pop = valueKeys.pop()) === null || _valueKeys$pop === void 0 ? void 0 : _valueKeys$pop.toString()) || '';
|
|
808
|
+
if (!recordKey) {
|
|
809
|
+
return (newLineRecordCache === null || newLineRecordCache === void 0 ? void 0 : newLineRecordCache.defaultValue) || {};
|
|
810
|
+
}
|
|
811
|
+
var fieldPath = buildFormFieldPath(recordKey);
|
|
812
|
+
var newLineRecordData = _objectSpread(_objectSpread({}, newLineRecordCache === null || newLineRecordCache === void 0 ? void 0 : newLineRecordCache.defaultValue), get(values, fieldPath));
|
|
813
|
+
var existsInDataSource = dataSourceKeyIndexMapRef.current.has(recordKeyToString(recordKey));
|
|
814
|
+
if (existsInDataSource) {
|
|
815
|
+
var foundRow = dataSource.find(function (item, index) {
|
|
816
|
+
var _props$getRowKey3;
|
|
817
|
+
var key = (_props$getRowKey3 = props.getRowKey(item, index)) === null || _props$getRowKey3 === void 0 ? void 0 : _props$getRowKey3.toString();
|
|
818
|
+
return key === recordKey;
|
|
819
|
+
});
|
|
820
|
+
return foundRow || newLineRecordData;
|
|
821
|
+
}
|
|
822
|
+
return newLineRecordData;
|
|
823
|
+
});
|
|
824
|
+
var onValuesChange = useRefFunction(function (value, values) {
|
|
825
|
+
if (!props.onValuesChange) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
var updatedDataSource = updateDataSourceWithEditableRows(props.dataSource, values);
|
|
829
|
+
var editRow = getCurrentEditRow(value, values, updatedDataSource);
|
|
830
|
+
propsOnValuesChange.run(editRow, updatedDataSource);
|
|
613
831
|
});
|
|
614
832
|
var saveRefsMap = useRef(new Map());
|
|
615
833
|
useEffect(function () {
|
|
616
|
-
|
|
834
|
+
var _editableKeys$map;
|
|
835
|
+
var editableKeysSet = new Set((_editableKeys$map = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.map(function (key) {
|
|
836
|
+
return key === null || key === void 0 ? void 0 : key.toString();
|
|
837
|
+
})) !== null && _editableKeys$map !== void 0 ? _editableKeys$map : []);
|
|
617
838
|
saveRefsMap.current.forEach(function (ref, key) {
|
|
618
|
-
if (!editableKeysSet.has(key)) {
|
|
839
|
+
if (!editableKeysSet.has(key === null || key === void 0 ? void 0 : key.toString())) {
|
|
619
840
|
saveRefsMap.current.delete(key);
|
|
620
841
|
}
|
|
621
842
|
});
|
|
622
|
-
}, [
|
|
843
|
+
}, [editableKeys]);
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* 获取保存引用
|
|
847
|
+
*/
|
|
848
|
+
var getSaveRef = useRefFunction(function (recordKey) {
|
|
849
|
+
var relayKey = recordKeyToString(recordKey);
|
|
850
|
+
return saveRefsMap.current.get(relayKey) || saveRefsMap.current.get(relayKey.toString());
|
|
851
|
+
});
|
|
852
|
+
|
|
623
853
|
/**
|
|
624
854
|
* 保存编辑行
|
|
625
|
-
*
|
|
626
|
-
* @param recordKey
|
|
627
|
-
* @param needReTry
|
|
628
855
|
*/
|
|
629
856
|
var saveEditable = useRefFunction( /*#__PURE__*/function () {
|
|
630
|
-
var
|
|
631
|
-
var relayKey,
|
|
857
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(recordKey, needReTry) {
|
|
858
|
+
var relayKey, relayKeyStr, mappedKey, isInEditableSet, saveRef;
|
|
632
859
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
633
860
|
while (1) switch (_context7.prev = _context7.next) {
|
|
634
861
|
case 0:
|
|
635
862
|
relayKey = recordKeyToString(recordKey);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
863
|
+
relayKeyStr = relayKey.toString();
|
|
864
|
+
mappedKey = dataSourceKeyIndexMapRef.current.get(relayKeyStr);
|
|
865
|
+
isInEditableSet = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.some(function (key) {
|
|
866
|
+
return (key === null || key === void 0 ? void 0 : key.toString()) === relayKeyStr || key === relayKey;
|
|
867
|
+
});
|
|
868
|
+
if (!(!isInEditableSet && mappedKey && (needReTry !== null && needReTry !== void 0 ? needReTry : true) && props.tableName)) {
|
|
869
|
+
_context7.next = 8;
|
|
640
870
|
break;
|
|
641
871
|
}
|
|
642
|
-
_context7.next =
|
|
643
|
-
return saveEditable(
|
|
644
|
-
case
|
|
872
|
+
_context7.next = 7;
|
|
873
|
+
return saveEditable(mappedKey, false);
|
|
874
|
+
case 7:
|
|
645
875
|
return _context7.abrupt("return", _context7.sent);
|
|
646
|
-
case
|
|
647
|
-
saveRef =
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
_context7.next = 15;
|
|
653
|
-
break;
|
|
654
|
-
case 12:
|
|
655
|
-
_context7.prev = 12;
|
|
656
|
-
_context7.t0 = _context7["catch"](7);
|
|
876
|
+
case 8:
|
|
877
|
+
saveRef = getSaveRef(recordKey);
|
|
878
|
+
if (saveRef !== null && saveRef !== void 0 && saveRef.current) {
|
|
879
|
+
_context7.next = 11;
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
657
882
|
return _context7.abrupt("return", false);
|
|
658
|
-
case
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
883
|
+
case 11:
|
|
884
|
+
_context7.next = 13;
|
|
885
|
+
return saveRef.current.save();
|
|
886
|
+
case 13:
|
|
887
|
+
clearEditableState(recordKey);
|
|
662
888
|
return _context7.abrupt("return", true);
|
|
663
|
-
case
|
|
889
|
+
case 15:
|
|
664
890
|
case "end":
|
|
665
891
|
return _context7.stop();
|
|
666
892
|
}
|
|
667
|
-
}, _callee7
|
|
893
|
+
}, _callee7);
|
|
668
894
|
}));
|
|
669
895
|
return function (_x5, _x6) {
|
|
670
|
-
return
|
|
896
|
+
return _ref12.apply(this, arguments);
|
|
671
897
|
};
|
|
672
898
|
}());
|
|
673
899
|
|
|
674
900
|
/**
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* @param row
|
|
678
|
-
* @param options
|
|
679
|
-
* @name 增加新的行
|
|
901
|
+
* 验证是否可以新增记录
|
|
680
902
|
*/
|
|
681
|
-
var
|
|
903
|
+
var validateCanAddRecord = useRefFunction(function (options) {
|
|
682
904
|
if (options !== null && options !== void 0 && options.parentKey && !dataSourceKeyIndexMapRef.current.has(recordKeyToString(options === null || options === void 0 ? void 0 : options.parentKey).toString())) {
|
|
683
905
|
console.warn("can't find record by key", options === null || options === void 0 ? void 0 : options.parentKey);
|
|
684
906
|
return false;
|
|
685
907
|
}
|
|
686
|
-
// 暂时不支持多行新增
|
|
687
908
|
if (newLineRecordRef.current && props.onlyAddOneLineAlertMessage !== false) {
|
|
688
909
|
warning(props.onlyAddOneLineAlertMessage || intl.getMessage('editableTable.onlyAddOneLine', '只能新增一行'));
|
|
689
910
|
return false;
|
|
690
911
|
}
|
|
691
|
-
|
|
692
|
-
if (editableKeysSet.size > 0 && editableType === 'single' && props.onlyOneLineEditorAlertMessage !== false) {
|
|
693
|
-
warning(props.onlyOneLineEditorAlertMessage || intl.getMessage('editableTable.onlyOneLineEditor', '只能同时编辑一行'));
|
|
912
|
+
if (!validateCanStartEdit()) {
|
|
694
913
|
return false;
|
|
695
914
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
915
|
+
return true;
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* 验证记录 key 是否有效
|
|
920
|
+
*/
|
|
921
|
+
var validateRecordKey = useRefFunction(function (recordKey) {
|
|
922
|
+
if (recordKey == null && recordKey !== 0 && recordKey !== '') {
|
|
923
|
+
noteOnce(false, '请设置 recordCreatorProps.record 并返回一个唯一的key \n https://procomponents.ant.design/components/editable-table#editable-%E6%96%B0%E5%BB%BA%E8%A1%8C');
|
|
700
924
|
throw new Error('请设置 recordCreatorProps.record 并返回一个唯一的key');
|
|
701
925
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
if ((options
|
|
709
|
-
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* 增加新的行
|
|
930
|
+
*/
|
|
931
|
+
var addEditRecord = useRefFunction(function (row, options) {
|
|
932
|
+
if (!validateCanAddRecord(options)) {
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
var recordKey = props.getRowKey(row, -1);
|
|
936
|
+
validateRecordKey(recordKey);
|
|
937
|
+
var isAlreadyEditable = editableKeys === null || editableKeys === void 0 ? void 0 : editableKeys.some(function (key) {
|
|
938
|
+
return key === recordKey || (key === null || key === void 0 ? void 0 : key.toString()) === (recordKey === null || recordKey === void 0 ? void 0 : recordKey.toString());
|
|
939
|
+
});
|
|
940
|
+
if (!isAlreadyEditable) {
|
|
941
|
+
var newKeys = editableKeys ? [].concat(_toConsumableArray(editableKeys), [recordKey]) : [recordKey];
|
|
942
|
+
setEditableRowKeys(newKeys);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// 处理 parentKey:如果是函数,调用它
|
|
946
|
+
var parentKeyValue = typeof (options === null || options === void 0 ? void 0 : options.parentKey) === 'function' ? options.parentKey() : options === null || options === void 0 ? void 0 : options.parentKey;
|
|
947
|
+
var isDataSourceMode = (options === null || options === void 0 ? void 0 : options.newRecordType) === 'dataSource' || props.tableName && (options === null || options === void 0 ? void 0 : options.newRecordType) !== 'cache';
|
|
948
|
+
if (isDataSourceMode) {
|
|
949
|
+
var _recordKeyToString4;
|
|
710
950
|
var actionProps = {
|
|
711
951
|
data: props.dataSource,
|
|
712
952
|
getRowKey: props.getRowKey,
|
|
713
953
|
row: _objectSpread(_objectSpread({}, row), {}, {
|
|
714
|
-
map_row_parentKey:
|
|
954
|
+
map_row_parentKey: parentKeyValue ? (_recordKeyToString4 = recordKeyToString(parentKeyValue)) === null || _recordKeyToString4 === void 0 ? void 0 : _recordKeyToString4.toString() : undefined
|
|
715
955
|
}),
|
|
716
956
|
key: recordKey,
|
|
717
957
|
childrenColumnName: props.childrenColumnName || 'children'
|
|
@@ -721,6 +961,7 @@ export function useEditableArray(props) {
|
|
|
721
961
|
setNewLineRecordCache({
|
|
722
962
|
defaultValue: row,
|
|
723
963
|
options: _objectSpread(_objectSpread({}, options), {}, {
|
|
964
|
+
parentKey: parentKeyValue,
|
|
724
965
|
recordKey: recordKey
|
|
725
966
|
})
|
|
726
967
|
});
|
|
@@ -731,9 +972,9 @@ export function useEditableArray(props) {
|
|
|
731
972
|
var deleteText = (props === null || props === void 0 ? void 0 : props.deleteText) || intl.getMessage('editableTable.action.delete', '删除');
|
|
732
973
|
var cancelText = (props === null || props === void 0 ? void 0 : props.cancelText) || intl.getMessage('editableTable.action.cancel', '取消');
|
|
733
974
|
var actionSaveRef = useRefFunction( /*#__PURE__*/function () {
|
|
734
|
-
var
|
|
735
|
-
var _props$onSave
|
|
736
|
-
var res,
|
|
975
|
+
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(recordKey, editRow, originRow, newLine) {
|
|
976
|
+
var _props$onSave;
|
|
977
|
+
var res, _ref14, options, isNewLine, _recordKeyToString5, _options$parentKey, actionProps;
|
|
737
978
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
738
979
|
while (1) switch (_context8.prev = _context8.next) {
|
|
739
980
|
case 0:
|
|
@@ -741,47 +982,44 @@ export function useEditableArray(props) {
|
|
|
741
982
|
return props === null || props === void 0 || (_props$onSave = props.onSave) === null || _props$onSave === void 0 ? void 0 : _props$onSave.call(props, recordKey, editRow, originRow, newLine);
|
|
742
983
|
case 2:
|
|
743
984
|
res = _context8.sent;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
if ((options === null || options === void 0 ? void 0 : options.position) === 'top') {
|
|
753
|
-
props.setDataSource([editRow].concat(_toConsumableArray(props.dataSource)));
|
|
985
|
+
_ref14 = newLine || newLineRecordRef.current || {}, options = _ref14.options;
|
|
986
|
+
isNewLine = !(options !== null && options !== void 0 && options.parentKey) && (options === null || options === void 0 ? void 0 : options.recordKey) === recordKey;
|
|
987
|
+
if (isNewLine) {
|
|
988
|
+
if ((options === null || options === void 0 ? void 0 : options.position) === 'top') {
|
|
989
|
+
props.setDataSource([editRow].concat(_toConsumableArray(props.dataSource)));
|
|
990
|
+
} else {
|
|
991
|
+
props.setDataSource([].concat(_toConsumableArray(props.dataSource), [editRow]));
|
|
992
|
+
}
|
|
754
993
|
} else {
|
|
755
|
-
|
|
994
|
+
actionProps = {
|
|
995
|
+
data: props.dataSource,
|
|
996
|
+
getRowKey: props.getRowKey,
|
|
997
|
+
row: options ? _objectSpread(_objectSpread({}, editRow), {}, {
|
|
998
|
+
map_row_parentKey: (_recordKeyToString5 = recordKeyToString((_options$parentKey = options === null || options === void 0 ? void 0 : options.parentKey) !== null && _options$parentKey !== void 0 ? _options$parentKey : '')) === null || _recordKeyToString5 === void 0 ? void 0 : _recordKeyToString5.toString()
|
|
999
|
+
}) : editRow,
|
|
1000
|
+
key: recordKey,
|
|
1001
|
+
childrenColumnName: props.childrenColumnName || 'children'
|
|
1002
|
+
};
|
|
1003
|
+
props.setDataSource(editableRowByKey(actionProps, (options === null || options === void 0 ? void 0 : options.position) === 'top' ? 'top' : 'update'));
|
|
756
1004
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
data: props.dataSource,
|
|
761
|
-
getRowKey: props.getRowKey,
|
|
762
|
-
row: options ? _objectSpread(_objectSpread({}, editRow), {}, {
|
|
763
|
-
map_row_parentKey: (_recordKeyToString4 = recordKeyToString((_options$parentKey = options === null || options === void 0 ? void 0 : options.parentKey) !== null && _options$parentKey !== void 0 ? _options$parentKey : '')) === null || _recordKeyToString4 === void 0 ? void 0 : _recordKeyToString4.toString()
|
|
764
|
-
}) : editRow,
|
|
765
|
-
key: recordKey,
|
|
766
|
-
childrenColumnName: props.childrenColumnName || 'children'
|
|
767
|
-
};
|
|
768
|
-
props.setDataSource(editableRowByKey(actionProps, (options === null || options === void 0 ? void 0 : options.position) === 'top' ? 'top' : 'update'));
|
|
769
|
-
_context8.next = 13;
|
|
1005
|
+
|
|
1006
|
+
// 保存时解除编辑模式,统一在这里调用一次
|
|
1007
|
+
_context8.next = 8;
|
|
770
1008
|
return cancelEditable(recordKey);
|
|
771
|
-
case
|
|
1009
|
+
case 8:
|
|
772
1010
|
return _context8.abrupt("return", res);
|
|
773
|
-
case
|
|
1011
|
+
case 9:
|
|
774
1012
|
case "end":
|
|
775
1013
|
return _context8.stop();
|
|
776
1014
|
}
|
|
777
1015
|
}, _callee8);
|
|
778
1016
|
}));
|
|
779
1017
|
return function (_x7, _x8, _x9, _x10) {
|
|
780
|
-
return
|
|
1018
|
+
return _ref13.apply(this, arguments);
|
|
781
1019
|
};
|
|
782
1020
|
}());
|
|
783
1021
|
var actionDeleteRef = useRefFunction( /*#__PURE__*/function () {
|
|
784
|
-
var
|
|
1022
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(recordKey, editRow) {
|
|
785
1023
|
var _props$onDelete2;
|
|
786
1024
|
var actionProps, res;
|
|
787
1025
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
@@ -798,23 +1036,29 @@ export function useEditableArray(props) {
|
|
|
798
1036
|
return props === null || props === void 0 || (_props$onDelete2 = props.onDelete) === null || _props$onDelete2 === void 0 ? void 0 : _props$onDelete2.call(props, recordKey, editRow);
|
|
799
1037
|
case 3:
|
|
800
1038
|
res = _context9.sent;
|
|
801
|
-
|
|
802
|
-
|
|
1039
|
+
if (!(res === false)) {
|
|
1040
|
+
_context9.next = 6;
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
return _context9.abrupt("return", false);
|
|
803
1044
|
case 6:
|
|
1045
|
+
_context9.next = 8;
|
|
1046
|
+
return cancelEditable(recordKey, false);
|
|
1047
|
+
case 8:
|
|
804
1048
|
props.setDataSource(editableRowByKey(actionProps, 'delete'));
|
|
805
1049
|
return _context9.abrupt("return", res);
|
|
806
|
-
case
|
|
1050
|
+
case 10:
|
|
807
1051
|
case "end":
|
|
808
1052
|
return _context9.stop();
|
|
809
1053
|
}
|
|
810
1054
|
}, _callee9);
|
|
811
1055
|
}));
|
|
812
1056
|
return function (_x11, _x12) {
|
|
813
|
-
return
|
|
1057
|
+
return _ref15.apply(this, arguments);
|
|
814
1058
|
};
|
|
815
1059
|
}());
|
|
816
1060
|
var actionCancelRef = useRefFunction( /*#__PURE__*/function () {
|
|
817
|
-
var
|
|
1061
|
+
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(recordKey, editRow, originRow, newLine) {
|
|
818
1062
|
var _props$onCancel;
|
|
819
1063
|
var res;
|
|
820
1064
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
@@ -832,7 +1076,7 @@ export function useEditableArray(props) {
|
|
|
832
1076
|
}, _callee10);
|
|
833
1077
|
}));
|
|
834
1078
|
return function (_x13, _x14, _x15, _x16) {
|
|
835
|
-
return
|
|
1079
|
+
return _ref16.apply(this, arguments);
|
|
836
1080
|
};
|
|
837
1081
|
}());
|
|
838
1082
|
|