@ant-design/pro-components 3.1.0-0 → 3.1.1-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.es-PR.md +1 -3
- package/README.md +8 -10
- package/README.zh-CN.md +11 -11
- package/dist/pro-components.min.js +1 -1
- package/es/card/ProCard.js +8 -10
- package/es/card/components/Actions/index.js +25 -25
- package/es/card/components/Actions/style.js +79 -71
- package/es/card/components/Card/index.js +157 -142
- package/es/card/components/Card/style.js +249 -192
- package/es/card/components/CheckCard/Group.js +94 -115
- package/es/card/components/CheckCard/index.js +85 -79
- package/es/card/components/CheckCard/style.js +184 -168
- package/es/card/components/Divider/index.js +19 -15
- package/es/card/components/Divider/style.js +32 -29
- package/es/card/components/Loading/index.js +19 -16
- package/es/card/components/Loading/style.js +34 -31
- package/es/card/components/Operation/index.js +16 -13
- package/es/card/components/Operation/style.js +19 -18
- package/es/card/components/Statistic/index.js +46 -41
- package/es/card/components/Statistic/style.js +89 -70
- package/es/card/components/StatisticCard/index.js +46 -41
- package/es/card/components/StatisticCard/style.js +37 -35
- package/es/descriptions/index.js +214 -225
- package/es/descriptions/useFetchData.js +53 -91
- package/es/field/AllProField.js +265 -216
- package/es/field/FieldHOC/index.js +9 -14
- package/es/field/PureProField.js +82 -80
- package/es/field/ValueTypeToComponent.js +517 -618
- package/es/field/components/Cascader/index.d.ts +3 -3
- package/es/field/components/Cascader/index.js +66 -84
- package/es/field/components/Checkbox/index.d.ts +2 -2
- package/es/field/components/Checkbox/index.js +75 -72
- package/es/field/components/Code/index.js +40 -39
- package/es/field/components/ColorPicker/index.d.ts +2 -2
- package/es/field/components/ColorPicker/index.js +38 -32
- package/es/field/components/DatePicker/index.d.ts +2 -2
- package/es/field/components/DatePicker/index.js +49 -53
- package/es/field/components/Digit/index.js +41 -42
- package/es/field/components/DigitRange/index.js +71 -77
- package/es/field/components/FromNow/index.js +27 -25
- package/es/field/components/Image/index.js +28 -24
- package/es/field/components/IndexColumn/index.js +22 -16
- package/es/field/components/Money/index.js +107 -116
- package/es/field/components/Options/index.js +34 -33
- package/es/field/components/Password/index.js +35 -38
- package/es/field/components/Percent/index.js +40 -44
- package/es/field/components/Percent/util.js +3 -5
- package/es/field/components/Progress/index.js +29 -27
- package/es/field/components/Radio/index.d.ts +1 -1
- package/es/field/components/Radio/index.js +61 -62
- package/es/field/components/RangePicker/index.d.ts +2 -2
- package/es/field/components/RangePicker/index.js +52 -63
- package/es/field/components/Rate/index.js +24 -21
- package/es/field/components/Second/index.js +36 -33
- package/es/field/components/Segmented/index.d.ts +1 -1
- package/es/field/components/Segmented/index.js +37 -46
- package/es/field/components/Select/LightSelect/index.d.ts +1 -1
- package/es/field/components/Select/LightSelect/index.js +102 -109
- package/es/field/components/Select/SearchSelect/index.js +129 -155
- package/es/field/components/Select/index.d.ts +2 -2
- package/es/field/components/Select/index.js +193 -219
- package/es/field/components/Slider/index.js +25 -22
- package/es/field/components/Status/index.js +67 -78
- package/es/field/components/Switch/index.d.ts +1 -1
- package/es/field/components/Switch/index.js +32 -30
- package/es/field/components/Text/index.js +34 -37
- package/es/field/components/TextArea/index.js +26 -21
- package/es/field/components/TextArea/readonly.js +24 -21
- package/es/field/components/TimePicker/index.js +96 -105
- package/es/field/components/TreeSelect/index.d.ts +3 -3
- package/es/field/components/TreeSelect/index.js +107 -125
- package/es/form/BaseForm/BaseForm.js +416 -502
- package/es/form/BaseForm/EditOrReadOnlyContext.js +1 -1
- package/es/form/BaseForm/LightWrapper/index.js +56 -65
- package/es/form/BaseForm/LightWrapper/style.js +17 -13
- package/es/form/BaseForm/Submitter/index.js +44 -43
- package/es/form/FieldContext.js +1 -1
- package/es/form/components/Captcha/index.js +74 -134
- package/es/form/components/Cascader/index.d.ts +1 -1
- package/es/form/components/Cascader/index.js +26 -28
- package/es/form/components/Checkbox/index.js +60 -61
- package/es/form/components/ColorPicker/index.d.ts +1 -1
- package/es/form/components/ColorPicker/index.js +24 -26
- package/es/form/components/DatePicker/BaseDatePicker.js +32 -30
- package/es/form/components/DatePicker/DatePicker.js +14 -13
- package/es/form/components/DatePicker/DateTimePicker.js +11 -12
- package/es/form/components/DatePicker/MonthPicker.js +14 -13
- package/es/form/components/DatePicker/QuarterPicker.js +14 -13
- package/es/form/components/DatePicker/TimePicker.js +26 -27
- package/es/form/components/DatePicker/WeekPicker.js +14 -13
- package/es/form/components/DatePicker/YearPicker.js +14 -13
- package/es/form/components/DatePicker/index.js +1 -1
- package/es/form/components/DateRangePicker/BaseDateRanger.js +34 -34
- package/es/form/components/DateRangePicker/DateMonthRangePicker.js +15 -16
- package/es/form/components/DateRangePicker/DateQuarterRangePicker.js +15 -16
- package/es/form/components/DateRangePicker/DateTimeRangePicker.js +15 -16
- package/es/form/components/DateRangePicker/DateWeekRangePicker.js +15 -16
- package/es/form/components/DateRangePicker/DateYearRangePicker.js +15 -16
- package/es/form/components/DateRangePicker/TimeRangePicker.js +26 -29
- package/es/form/components/DateRangePicker/index.js +15 -16
- package/es/form/components/Dependency/index.js +31 -34
- package/es/form/components/Digit/DigitRange.d.ts +2 -2
- package/es/form/components/Digit/DigitRange.js +23 -24
- package/es/form/components/Digit/index.d.ts +1 -1
- package/es/form/components/Digit/index.js +27 -29
- package/es/form/components/Field/index.js +55 -63
- package/es/form/components/FieldSet/index.js +68 -76
- package/es/form/components/FormItem/FormItemRender/index.js +58 -48
- package/es/form/components/FormItem/Group/index.js +95 -95
- package/es/form/components/FormItem/Group/style.js +46 -40
- package/es/form/components/FormItem/index.js +135 -141
- package/es/form/components/FormItem/warpField.js +165 -149
- package/es/form/components/List/ListContainer.js +98 -189
- package/es/form/components/List/ListItem.js +151 -198
- package/es/form/components/List/index.js +97 -107
- package/es/form/components/List/style.js +71 -47
- package/es/form/components/Money/index.d.ts +1 -1
- package/es/form/components/Money/index.js +28 -30
- package/es/form/components/Radio/index.d.ts +2 -2
- package/es/form/components/Radio/index.js +45 -49
- package/es/form/components/Rate/index.d.ts +1 -1
- package/es/form/components/Rate/index.js +17 -20
- package/es/form/components/SchemaForm/index.js +58 -72
- package/es/form/components/SchemaForm/layoutType/Embed.js +5 -6
- package/es/form/components/SchemaForm/layoutType/StepsForm.js +22 -26
- package/es/form/components/SchemaForm/valueType/dependency.js +11 -11
- package/es/form/components/SchemaForm/valueType/divider.js +4 -5
- package/es/form/components/SchemaForm/valueType/field.js +45 -44
- package/es/form/components/SchemaForm/valueType/formList.js +8 -7
- package/es/form/components/SchemaForm/valueType/formSet.js +8 -7
- package/es/form/components/SchemaForm/valueType/group.js +7 -8
- package/es/form/components/SchemaForm/valueType/ignore.js +2 -2
- package/es/form/components/SchemaForm/valueType/index.js +5 -5
- package/es/form/components/Segmented/index.js +20 -23
- package/es/form/components/Select/index.js +69 -73
- package/es/form/components/Slider/index.d.ts +1 -1
- package/es/form/components/Slider/index.js +33 -35
- package/es/form/components/Switch/index.js +24 -26
- package/es/form/components/Text/index.js +75 -86
- package/es/form/components/TextArea/index.d.ts +1 -1
- package/es/form/components/TextArea/index.js +17 -20
- package/es/form/components/TreeSelect/index.js +20 -23
- package/es/form/components/UploadButton/index.js +56 -103
- package/es/form/components/UploadDragger/index.js +37 -44
- package/es/form/helpers/grid.js +65 -67
- package/es/form/layouts/DrawerForm/index.js +150 -241
- package/es/form/layouts/DrawerForm/style.js +26 -25
- package/es/form/layouts/LightFilter/index.d.ts +12 -1
- package/es/form/layouts/LightFilter/index.js +158 -140
- package/es/form/layouts/LightFilter/style.js +52 -48
- package/es/form/layouts/LoginForm/index.js +44 -47
- package/es/form/layouts/LoginForm/style.js +71 -67
- package/es/form/layouts/LoginFormPage/index.js +45 -48
- package/es/form/layouts/LoginFormPage/style.js +136 -126
- package/es/form/layouts/ModalForm/index.js +119 -203
- package/es/form/layouts/ProForm/index.d.ts +2 -2
- package/es/form/layouts/ProForm/index.js +5 -5
- package/es/form/layouts/QueryFilter/Actions.js +23 -22
- package/es/form/layouts/QueryFilter/index.js +178 -203
- package/es/form/layouts/QueryFilter/style.js +45 -37
- package/es/form/layouts/StepsForm/StepForm.d.ts +2 -3
- package/es/form/layouts/StepsForm/StepForm.js +50 -71
- package/es/form/layouts/StepsForm/index.js +175 -217
- package/es/form/layouts/StepsForm/style.js +30 -28
- package/es/form/layouts/index.js +1 -1
- package/es/layout/ProLayout.js +281 -292
- package/es/layout/WrapContent.js +16 -12
- package/es/layout/assert/Logo.js +95 -97
- package/es/layout/components/AppsLogoComponents/AppsLogo.js +10 -12
- package/es/layout/components/AppsLogoComponents/DefaultContent.js +17 -16
- package/es/layout/components/AppsLogoComponents/SimpleContent.js +19 -18
- package/es/layout/components/AppsLogoComponents/index.js +33 -38
- package/es/layout/components/AppsLogoComponents/style/default.js +2 -2
- package/es/layout/components/AppsLogoComponents/style/index.js +52 -50
- package/es/layout/components/AppsLogoComponents/style/simple.js +1 -1
- package/es/layout/components/CollapsedIcon/index.js +18 -15
- package/es/layout/components/CollapsedIcon/style.js +40 -40
- package/es/layout/components/Footer.js +22 -21
- package/es/layout/components/FooterToolbar/index.js +58 -52
- package/es/layout/components/FooterToolbar/style/index.js +38 -37
- package/es/layout/components/FooterToolbar/style/stylish.js +11 -9
- package/es/layout/components/GlobalFooter/index.js +25 -25
- package/es/layout/components/GlobalFooter/style.js +31 -30
- package/es/layout/components/GlobalHeader/ActionsContent.js +62 -78
- package/es/layout/components/GlobalHeader/index.js +59 -47
- package/es/layout/components/GlobalHeader/rightContentStyle.js +49 -49
- package/es/layout/components/GlobalHeader/style.js +58 -54
- package/es/layout/components/GridContent/index.js +24 -19
- package/es/layout/components/GridContent/style.js +14 -13
- package/es/layout/components/Header/index.js +63 -57
- package/es/layout/components/Header/style/header.js +49 -47
- package/es/layout/components/Header/style/stylish.js +15 -11
- package/es/layout/components/Help/AsyncContentPanel.js +13 -18
- package/es/layout/components/Help/HelpProvide.js +1 -1
- package/es/layout/components/Help/ProHelpContentPanel.js +64 -83
- package/es/layout/components/Help/ProHelpDrawer.js +25 -31
- package/es/layout/components/Help/ProHelpModal.d.ts +1 -1
- package/es/layout/components/Help/ProHelpModal.js +24 -27
- package/es/layout/components/Help/ProHelpPanel.js +86 -94
- package/es/layout/components/Help/ProHelpPopover.js +18 -16
- package/es/layout/components/Help/RenderContentPanel.js +34 -24
- package/es/layout/components/Help/Search.js +52 -78
- package/es/layout/components/Help/index.js +9 -11
- package/es/layout/components/Help/style.js +82 -75
- package/es/layout/components/PageContainer/index.js +168 -149
- package/es/layout/components/PageContainer/style/index.js +95 -78
- package/es/layout/components/PageContainer/style/stylish.js +11 -9
- package/es/layout/components/PageHeader/index.js +96 -97
- package/es/layout/components/PageHeader/style/index.js +142 -122
- package/es/layout/components/PageLoading/index.js +17 -20
- package/es/layout/components/SettingDrawer/BlockCheckbox.js +29 -32
- package/es/layout/components/SettingDrawer/LayoutChange.js +22 -22
- package/es/layout/components/SettingDrawer/RegionalChange.js +14 -15
- package/es/layout/components/SettingDrawer/ThemeColor.js +32 -35
- package/es/layout/components/SettingDrawer/index.js +137 -168
- package/es/layout/components/SettingDrawer/style/index.js +141 -137
- package/es/layout/components/SiderMenu/BaseMenu.js +235 -221
- package/es/layout/components/SiderMenu/SiderMenu.js +125 -115
- package/es/layout/components/SiderMenu/index.js +47 -42
- package/es/layout/components/SiderMenu/style/index.js +179 -161
- package/es/layout/components/SiderMenu/style/menu.js +148 -110
- package/es/layout/components/SiderMenu/style/stylish.js +15 -11
- package/es/layout/components/TopNavHeader/index.js +71 -60
- package/es/layout/components/TopNavHeader/style.js +64 -63
- package/es/layout/context/RouteContext.js +1 -1
- package/es/layout/defaultSettings.js +1 -1
- package/es/layout/getPageTitle.js +23 -24
- package/es/layout/locales/en-US.js +3 -2
- package/es/layout/locales/index.js +5 -5
- package/es/layout/locales/it-IT.js +3 -2
- package/es/layout/locales/ko-KR.js +3 -2
- package/es/layout/locales/zh-CN.js +3 -2
- package/es/layout/locales/zh-TW.js +3 -2
- package/es/layout/style/index.js +48 -42
- package/es/layout/utils/getBreadcrumbProps.js +60 -60
- package/es/layout/utils/getMenuData.js +7 -11
- package/es/layout/utils/pathTools.js +2 -6
- package/es/layout/utils/useCurrentMenuLayoutProps.js +4 -9
- package/es/layout/utils/utils.js +15 -17
- package/es/list/Item.js +157 -137
- package/es/list/ListView.js +106 -115
- package/es/list/constants.js +2 -2
- package/es/list/index.js +72 -70
- package/es/list/style/index.js +281 -213
- package/es/provider/index.js +122 -115
- package/es/provider/intl.js +53 -55
- package/es/provider/typing/layoutToken.js +26 -23
- package/es/provider/useStyle/index.js +51 -59
- package/es/provider/utils/merge.js +10 -12
- package/es/skeleton/components/Descriptions/index.js +211 -229
- package/es/skeleton/components/List/index.js +208 -223
- package/es/skeleton/components/Result/index.js +45 -47
- package/es/skeleton/index.js +13 -10
- package/es/table/Store/Provide.d.ts +4 -4
- package/es/table/Store/Provide.js +102 -117
- package/es/table/Table.d.ts +5 -2
- package/es/table/Table.js +526 -691
- package/es/table/TableSearch.d.ts +24 -0
- package/es/table/TableSearch.js +54 -0
- package/es/table/TableToolbar.d.ts +22 -0
- package/es/table/TableToolbar.js +47 -0
- package/es/table/components/Alert/index.js +41 -40
- package/es/table/components/Alert/style.js +28 -27
- package/es/table/components/ColumnSetting/index.js +228 -223
- package/es/table/components/ColumnSetting/style.js +86 -71
- package/es/table/components/DragSortTable/index.js +65 -79
- package/es/table/components/DragSortTable/style.js +20 -19
- package/es/table/components/Dropdown/index.js +42 -47
- package/es/table/components/EditableTable/CellEditorTable.js +24 -32
- package/es/table/components/EditableTable/RowEditorTable.js +23 -28
- package/es/table/components/EditableTable/index.js +295 -329
- package/es/table/components/Form/FormRender.js +99 -103
- package/es/table/components/Form/index.d.ts +4 -19
- package/es/table/components/Form/index.js +112 -159
- package/es/table/components/ListToolBar/HeaderMenu.js +44 -52
- package/es/table/components/ListToolBar/index.js +122 -147
- package/es/table/components/ListToolBar/style.js +127 -117
- package/es/table/components/ToolBar/DensityIcon.js +10 -9
- package/es/table/components/ToolBar/FullscreenIcon.js +5 -9
- package/es/table/components/ToolBar/index.d.ts +2 -8
- package/es/table/components/ToolBar/index.js +155 -195
- package/es/table/style/index.js +144 -112
- package/es/table/typing.d.ts +4 -0
- package/es/table/useFetchData.js +199 -338
- package/es/table/utils/cellRenderToFromItem.js +105 -119
- package/es/table/utils/columnRender.js +63 -54
- package/es/table/utils/columnSort.js +22 -22
- package/es/table/utils/genProColumnToColumn.d.ts +13 -9
- package/es/table/utils/genProColumnToColumn.js +121 -98
- package/es/table/utils/index.d.ts +10 -0
- package/es/table/utils/index.js +112 -178
- package/es/table/utils/useDragSort.d.ts +1 -1
- package/es/table/utils/useDragSort.js +99 -92
- package/es/table/utils/usePageInfo.d.ts +6 -0
- package/es/table/utils/usePageInfo.js +55 -0
- package/es/utils/components/DropdownFooter/index.js +23 -21
- package/es/utils/components/DropdownFooter/style.js +16 -15
- package/es/utils/components/ErrorBoundary/index.js +27 -50
- package/es/utils/components/FieldLabel/index.js +70 -70
- package/es/utils/components/FieldLabel/style.js +104 -81
- package/es/utils/components/FilterDropdown/index.d.ts +11 -0
- package/es/utils/components/FilterDropdown/index.js +43 -32
- package/es/utils/components/FilterDropdown/style.js +19 -16
- package/es/utils/components/InlineErrorFormItem/index.js +78 -78
- package/es/utils/components/InlineErrorFormItem/style.js +56 -49
- package/es/utils/components/LabelIconTip/index.js +30 -31
- package/es/utils/components/LabelIconTip/style.js +36 -35
- package/es/utils/components/ProFormContext/index.js +1 -1
- package/es/utils/conversionMomentValue/index.js +19 -22
- package/es/utils/dateArrayFormatter/index.js +9 -14
- package/es/utils/genCopyable/index.js +74 -32
- package/es/utils/getFieldPropsOrFormItemProps/index.js +1 -1
- package/es/utils/hooks/useDebounceFn/index.js +18 -51
- package/es/utils/hooks/useDebounceValue/index.js +7 -16
- package/es/utils/hooks/useDeepCompareEffect/index.js +6 -18
- package/es/utils/hooks/useDocumentTitle/index.js +2 -2
- package/es/utils/hooks/useFetchData/index.js +36 -65
- package/es/utils/hooks/useForceRender/index.js +2 -9
- package/es/utils/hooks/useLatest/index.js +2 -2
- package/es/utils/hooks/usePrevious/index.js +3 -3
- package/es/utils/hooks/useReactiveRef/index.js +2 -2
- package/es/utils/hooks/useRefCallback/index.js +3 -3
- package/es/utils/hooks/useRefFunction/index.js +4 -9
- package/es/utils/index.d.ts +1 -2
- package/es/utils/index.js +1 -2
- package/es/utils/isBrowser/index.js +2 -2
- package/es/utils/isDeepEqualReact/index.js +9 -44
- package/es/utils/isDropdownValueType/index.js +2 -2
- package/es/utils/isNil/index.js +1 -3
- package/es/utils/isUrl/index.js +2 -2
- package/es/utils/merge/index.js +10 -12
- package/es/utils/nanoid/index.js +5 -6
- package/es/utils/omitBoolean/index.js +1 -1
- package/es/utils/omitUndefined/index.js +3 -3
- package/es/utils/omitUndefinedAndEmptyArr/index.js +4 -5
- package/es/utils/parseValueToMoment/index.js +3 -7
- package/es/utils/pickProFormItemProps/index.js +3 -3
- package/es/utils/pickProProps/index.js +6 -7
- package/es/utils/proFieldParsingText/index.js +85 -98
- package/es/utils/runFunction/index.js +2 -5
- package/es/utils/stringify/index.js +1 -1
- package/es/utils/transformKeySubmitValue/index.js +99 -116
- package/es/utils/useEditableArray/index.d.ts +6 -1
- package/es/utils/useEditableArray/index.js +579 -735
- package/es/utils/useEditableMap/index.d.ts +1 -1
- package/es/utils/useEditableMap/index.js +89 -135
- package/es/utils/useMediaQuery/index.d.ts +2 -2
- package/es/utils/useMediaQuery/index.js +37 -34
- package/es/utils/useMediaQuery/query.js +7 -17
- package/es/version.js +1 -1
- package/guidelines/Guidelines.md +33 -0
- package/guidelines/components/drawer-form.md +90 -0
- package/guidelines/components/editable-pro-table.md +150 -0
- package/guidelines/components/modal-form.md +88 -0
- package/guidelines/components/pro-card.md +90 -0
- package/guidelines/components/pro-form.md +96 -0
- package/guidelines/components/pro-layout.md +84 -0
- package/guidelines/components/pro-table.md +142 -0
- package/guidelines/components/steps-form.md +105 -0
- package/guidelines/design-tokens/colors.md +58 -0
- package/guidelines/design-tokens/layout.md +53 -0
- package/guidelines/design-tokens/typography.md +49 -0
- package/guidelines/overview-components.md +55 -0
- package/guidelines/overview-icons.md +23 -0
- package/lib/card/ProCard.js +8 -10
- package/lib/card/components/Actions/index.js +25 -25
- package/lib/card/components/Actions/style.js +79 -72
- package/lib/card/components/Card/index.js +154 -139
- package/lib/card/components/Card/style.js +249 -193
- package/lib/card/components/CheckCard/Group.js +97 -115
- package/lib/card/components/CheckCard/index.js +85 -78
- package/lib/card/components/CheckCard/style.js +184 -169
- package/lib/card/components/Divider/index.js +20 -16
- package/lib/card/components/Divider/style.js +32 -30
- package/lib/card/components/Loading/index.js +19 -16
- package/lib/card/components/Loading/style.js +34 -32
- package/lib/card/components/Operation/index.js +16 -14
- package/lib/card/components/Operation/style.js +19 -19
- package/lib/card/components/Statistic/index.js +46 -42
- package/lib/card/components/Statistic/style.js +89 -71
- package/lib/card/components/StatisticCard/index.js +46 -41
- package/lib/card/components/StatisticCard/style.js +37 -36
- package/lib/card/index.js +4 -4
- package/lib/descriptions/index.js +219 -225
- package/lib/descriptions/useFetchData.js +51 -90
- package/lib/field/AllProField.js +267 -217
- package/lib/field/FieldHOC/index.js +9 -15
- package/lib/field/PureProField.js +84 -82
- package/lib/field/ValueTypeToComponent.js +517 -618
- package/lib/field/components/Cascader/index.d.ts +2 -2
- package/lib/field/components/Cascader/index.js +66 -85
- package/lib/field/components/Checkbox/index.d.ts +1 -1
- package/lib/field/components/Checkbox/index.js +75 -73
- package/lib/field/components/Code/index.js +40 -39
- package/lib/field/components/ColorPicker/index.js +38 -33
- package/lib/field/components/DatePicker/index.d.ts +1 -1
- package/lib/field/components/DatePicker/index.js +49 -53
- package/lib/field/components/Digit/index.js +41 -43
- package/lib/field/components/DigitRange/index.js +69 -76
- package/lib/field/components/FromNow/index.js +27 -25
- package/lib/field/components/Image/index.js +28 -24
- package/lib/field/components/IndexColumn/index.js +22 -17
- package/lib/field/components/Money/index.js +106 -116
- package/lib/field/components/Options/index.js +34 -34
- package/lib/field/components/Password/index.js +35 -38
- package/lib/field/components/Percent/index.js +40 -45
- package/lib/field/components/Percent/util.js +3 -6
- package/lib/field/components/Progress/index.js +29 -28
- package/lib/field/components/Radio/index.d.ts +1 -1
- package/lib/field/components/Radio/index.js +61 -63
- package/lib/field/components/RangePicker/index.d.ts +1 -1
- package/lib/field/components/RangePicker/index.js +52 -63
- package/lib/field/components/Rate/index.js +24 -21
- package/lib/field/components/Second/index.js +36 -33
- package/lib/field/components/Segmented/index.d.ts +1 -1
- package/lib/field/components/Segmented/index.js +37 -48
- package/lib/field/components/Select/LightSelect/index.d.ts +1 -1
- package/lib/field/components/Select/LightSelect/index.js +103 -110
- package/lib/field/components/Select/SearchSelect/index.js +133 -156
- package/lib/field/components/Select/index.d.ts +1 -1
- package/lib/field/components/Select/index.js +194 -218
- package/lib/field/components/Slider/index.js +25 -22
- package/lib/field/components/Status/index.js +69 -79
- package/lib/field/components/Switch/index.d.ts +1 -1
- package/lib/field/components/Switch/index.js +32 -31
- package/lib/field/components/Text/index.js +34 -38
- package/lib/field/components/TextArea/index.js +26 -21
- package/lib/field/components/TextArea/readonly.js +24 -22
- package/lib/field/components/TimePicker/index.js +96 -105
- package/lib/field/components/TreeSelect/index.d.ts +2 -2
- package/lib/field/components/TreeSelect/index.js +105 -124
- package/lib/field/index.js +34 -34
- package/lib/form/BaseForm/BaseForm.js +413 -499
- package/lib/form/BaseForm/EditOrReadOnlyContext.js +1 -1
- package/lib/form/BaseForm/LightWrapper/index.js +57 -66
- package/lib/form/BaseForm/LightWrapper/style.js +17 -14
- package/lib/form/BaseForm/Submitter/index.js +44 -44
- package/lib/form/BaseForm/index.js +3 -3
- package/lib/form/FieldContext.js +1 -1
- package/lib/form/components/Captcha/index.js +74 -135
- package/lib/form/components/Cascader/index.js +26 -29
- package/lib/form/components/Checkbox/index.js +60 -61
- package/lib/form/components/ColorPicker/index.js +24 -26
- package/lib/form/components/DatePicker/BaseDatePicker.js +32 -30
- package/lib/form/components/DatePicker/DatePicker.js +14 -13
- package/lib/form/components/DatePicker/DateTimePicker.js +11 -12
- package/lib/form/components/DatePicker/MonthPicker.js +14 -13
- package/lib/form/components/DatePicker/QuarterPicker.js +14 -13
- package/lib/form/components/DatePicker/TimePicker.js +26 -27
- package/lib/form/components/DatePicker/WeekPicker.js +14 -13
- package/lib/form/components/DatePicker/YearPicker.js +14 -13
- package/lib/form/components/DatePicker/index.js +1 -1
- package/lib/form/components/DateRangePicker/BaseDateRanger.js +34 -34
- package/lib/form/components/DateRangePicker/DateMonthRangePicker.js +15 -16
- package/lib/form/components/DateRangePicker/DateQuarterRangePicker.js +15 -16
- package/lib/form/components/DateRangePicker/DateTimeRangePicker.js +15 -16
- package/lib/form/components/DateRangePicker/DateWeekRangePicker.js +15 -16
- package/lib/form/components/DateRangePicker/DateYearRangePicker.js +15 -16
- package/lib/form/components/DateRangePicker/TimeRangePicker.js +26 -29
- package/lib/form/components/DateRangePicker/index.js +15 -16
- package/lib/form/components/Dependency/index.js +31 -35
- package/lib/form/components/Digit/DigitRange.js +23 -24
- package/lib/form/components/Digit/index.js +27 -29
- package/lib/form/components/Field/index.js +55 -63
- package/lib/form/components/FieldSet/index.js +68 -76
- package/lib/form/components/FormItem/FormItemRender/index.js +58 -48
- package/lib/form/components/FormItem/Group/index.js +95 -95
- package/lib/form/components/FormItem/Group/style.js +46 -41
- package/lib/form/components/FormItem/index.js +135 -141
- package/lib/form/components/FormItem/warpField.js +165 -149
- package/lib/form/components/List/ListContainer.js +100 -191
- package/lib/form/components/List/ListItem.js +153 -200
- package/lib/form/components/List/index.js +97 -107
- package/lib/form/components/List/style.js +71 -48
- package/lib/form/components/Money/index.js +28 -30
- package/lib/form/components/Radio/index.js +45 -49
- package/lib/form/components/Rate/index.js +17 -21
- package/lib/form/components/SchemaForm/index.js +54 -68
- package/lib/form/components/SchemaForm/layoutType/Embed.js +5 -6
- package/lib/form/components/SchemaForm/layoutType/StepsForm.js +22 -26
- package/lib/form/components/SchemaForm/layoutType/index.js +2 -2
- package/lib/form/components/SchemaForm/valueType/dependency.js +13 -12
- package/lib/form/components/SchemaForm/valueType/divider.js +6 -7
- package/lib/form/components/SchemaForm/valueType/field.js +47 -45
- package/lib/form/components/SchemaForm/valueType/formList.js +10 -9
- package/lib/form/components/SchemaForm/valueType/formSet.js +10 -8
- package/lib/form/components/SchemaForm/valueType/group.js +9 -10
- package/lib/form/components/SchemaForm/valueType/ignore.js +4 -3
- package/lib/form/components/SchemaForm/valueType/index.js +7 -6
- package/lib/form/components/Segmented/index.js +20 -24
- package/lib/form/components/Select/index.js +69 -73
- package/lib/form/components/Slider/index.js +33 -35
- package/lib/form/components/Switch/index.js +24 -26
- package/lib/form/components/Text/index.js +73 -84
- package/lib/form/components/TextArea/index.js +17 -21
- package/lib/form/components/TreeSelect/index.js +20 -23
- package/lib/form/components/UploadButton/index.js +56 -103
- package/lib/form/components/UploadDragger/index.js +37 -44
- package/lib/form/components/index.js +42 -42
- package/lib/form/helpers/grid.js +68 -69
- package/lib/form/helpers/index.js +1 -1
- package/lib/form/index.js +8 -8
- package/lib/form/layouts/DrawerForm/index.js +149 -241
- package/lib/form/layouts/DrawerForm/style.js +26 -26
- package/lib/form/layouts/LightFilter/index.d.ts +12 -1
- package/lib/form/layouts/LightFilter/index.js +158 -141
- package/lib/form/layouts/LightFilter/style.js +52 -49
- package/lib/form/layouts/LoginForm/index.js +44 -48
- package/lib/form/layouts/LoginForm/style.js +71 -68
- package/lib/form/layouts/LoginFormPage/index.js +45 -49
- package/lib/form/layouts/LoginFormPage/style.js +136 -127
- package/lib/form/layouts/ModalForm/index.js +118 -203
- package/lib/form/layouts/ProForm/index.d.ts +1 -1
- package/lib/form/layouts/ProForm/index.js +5 -5
- package/lib/form/layouts/QueryFilter/Actions.js +23 -22
- package/lib/form/layouts/QueryFilter/index.js +177 -202
- package/lib/form/layouts/QueryFilter/style.js +45 -38
- package/lib/form/layouts/StepsForm/StepForm.d.ts +2 -3
- package/lib/form/layouts/StepsForm/StepForm.js +50 -72
- package/lib/form/layouts/StepsForm/index.js +174 -216
- package/lib/form/layouts/StepsForm/style.js +30 -29
- package/lib/form/layouts/index.js +9 -9
- package/lib/index.js +11 -11
- package/lib/layout/ProLayout.js +281 -292
- package/lib/layout/WrapContent.js +18 -14
- package/lib/layout/assert/Logo.js +96 -97
- package/lib/layout/components/AppsLogoComponents/AppsLogo.js +11 -12
- package/lib/layout/components/AppsLogoComponents/DefaultContent.js +19 -17
- package/lib/layout/components/AppsLogoComponents/SimpleContent.js +22 -19
- package/lib/layout/components/AppsLogoComponents/index.js +36 -40
- package/lib/layout/components/AppsLogoComponents/style/default.js +4 -3
- package/lib/layout/components/AppsLogoComponents/style/index.js +52 -51
- package/lib/layout/components/AppsLogoComponents/style/simple.js +3 -2
- package/lib/layout/components/CollapsedIcon/index.js +20 -17
- package/lib/layout/components/CollapsedIcon/style.js +40 -41
- package/lib/layout/components/Footer.js +23 -22
- package/lib/layout/components/FooterToolbar/index.js +59 -53
- package/lib/layout/components/FooterToolbar/style/index.js +38 -38
- package/lib/layout/components/FooterToolbar/style/stylish.js +11 -10
- package/lib/layout/components/GlobalFooter/index.js +27 -27
- package/lib/layout/components/GlobalFooter/style.js +31 -31
- package/lib/layout/components/GlobalHeader/ActionsContent.js +65 -81
- package/lib/layout/components/GlobalHeader/index.js +61 -49
- package/lib/layout/components/GlobalHeader/rightContentStyle.js +49 -50
- package/lib/layout/components/GlobalHeader/style.js +58 -55
- package/lib/layout/components/GridContent/index.js +26 -21
- package/lib/layout/components/GridContent/style.js +14 -14
- package/lib/layout/components/Header/index.js +65 -59
- package/lib/layout/components/Header/style/header.js +49 -48
- package/lib/layout/components/Header/style/stylish.js +15 -12
- package/lib/layout/components/Help/AsyncContentPanel.js +15 -20
- package/lib/layout/components/Help/HelpProvide.js +1 -1
- package/lib/layout/components/Help/ProHelpContentPanel.js +66 -85
- package/lib/layout/components/Help/ProHelpDrawer.js +27 -32
- package/lib/layout/components/Help/ProHelpModal.d.ts +1 -1
- package/lib/layout/components/Help/ProHelpModal.js +26 -28
- package/lib/layout/components/Help/ProHelpPanel.js +86 -94
- package/lib/layout/components/Help/ProHelpPopover.js +20 -18
- package/lib/layout/components/Help/RenderContentPanel.js +36 -26
- package/lib/layout/components/Help/Search.js +55 -80
- package/lib/layout/components/Help/index.js +19 -20
- package/lib/layout/components/Help/style.js +82 -76
- package/lib/layout/components/PageContainer/index.js +172 -151
- package/lib/layout/components/PageContainer/style/index.js +95 -79
- package/lib/layout/components/PageContainer/style/stylish.js +11 -10
- package/lib/layout/components/PageHeader/index.js +99 -99
- package/lib/layout/components/PageHeader/style/index.js +142 -123
- package/lib/layout/components/PageLoading/index.js +18 -20
- package/lib/layout/components/SettingDrawer/BlockCheckbox.js +31 -34
- package/lib/layout/components/SettingDrawer/LayoutChange.js +25 -23
- package/lib/layout/components/SettingDrawer/RegionalChange.js +16 -16
- package/lib/layout/components/SettingDrawer/ThemeColor.js +34 -36
- package/lib/layout/components/SettingDrawer/index.js +138 -168
- package/lib/layout/components/SettingDrawer/style/index.js +141 -138
- package/lib/layout/components/SiderMenu/BaseMenu.js +235 -221
- package/lib/layout/components/SiderMenu/SiderMenu.js +128 -117
- package/lib/layout/components/SiderMenu/index.js +49 -44
- package/lib/layout/components/SiderMenu/style/index.js +179 -162
- package/lib/layout/components/SiderMenu/style/menu.js +148 -111
- package/lib/layout/components/SiderMenu/style/stylish.js +15 -12
- package/lib/layout/components/TopNavHeader/index.js +73 -62
- package/lib/layout/components/TopNavHeader/style.js +64 -64
- package/lib/layout/context/RouteContext.js +1 -1
- package/lib/layout/defaultSettings.js +1 -1
- package/lib/layout/getPageTitle.js +27 -26
- package/lib/layout/index.js +16 -16
- package/lib/layout/locales/en-US.js +3 -2
- package/lib/layout/locales/index.js +8 -6
- package/lib/layout/locales/it-IT.js +3 -2
- package/lib/layout/locales/ko-KR.js +3 -2
- package/lib/layout/locales/zh-CN.js +3 -2
- package/lib/layout/locales/zh-TW.js +3 -2
- package/lib/layout/style/index.js +48 -43
- package/lib/layout/utils/getBreadcrumbProps.js +65 -62
- package/lib/layout/utils/getMenuData.js +9 -13
- package/lib/layout/utils/pathTools.js +2 -6
- package/lib/layout/utils/useCurrentMenuLayoutProps.js +6 -11
- package/lib/layout/utils/utils.js +16 -18
- package/lib/list/Item.js +155 -136
- package/lib/list/ListView.js +110 -119
- package/lib/list/constants.js +2 -2
- package/lib/list/index.js +72 -70
- package/lib/list/style/index.js +281 -214
- package/lib/provider/index.js +128 -118
- package/lib/provider/intl.js +56 -56
- package/lib/provider/typing/layoutToken.js +28 -25
- package/lib/provider/useStyle/index.js +55 -60
- package/lib/provider/utils/merge.js +12 -14
- package/lib/skeleton/components/Descriptions/index.js +213 -229
- package/lib/skeleton/components/List/index.js +211 -221
- package/lib/skeleton/components/Result/index.js +45 -47
- package/lib/skeleton/index.js +23 -19
- package/lib/table/Store/Provide.d.ts +4 -4
- package/lib/table/Store/Provide.js +103 -117
- package/lib/table/Table.d.ts +5 -2
- package/lib/table/Table.js +524 -689
- package/lib/table/TableSearch.d.ts +24 -0
- package/lib/table/TableSearch.js +61 -0
- package/lib/table/TableToolbar.d.ts +22 -0
- package/lib/table/TableToolbar.js +55 -0
- package/lib/table/components/Alert/index.js +41 -40
- package/lib/table/components/Alert/style.js +28 -28
- package/lib/table/components/ColumnSetting/index.js +228 -224
- package/lib/table/components/ColumnSetting/style.js +86 -72
- package/lib/table/components/DragSortTable/index.js +64 -78
- package/lib/table/components/DragSortTable/style.js +20 -20
- package/lib/table/components/Dropdown/index.js +42 -48
- package/lib/table/components/EditableTable/CellEditorTable.js +24 -32
- package/lib/table/components/EditableTable/RowEditorTable.js +23 -28
- package/lib/table/components/EditableTable/index.js +293 -327
- package/lib/table/components/Form/FormRender.js +99 -104
- package/lib/table/components/Form/index.d.ts +4 -19
- package/lib/table/components/Form/index.js +113 -159
- package/lib/table/components/ListToolBar/HeaderMenu.js +42 -51
- package/lib/table/components/ListToolBar/index.js +123 -148
- package/lib/table/components/ListToolBar/style.js +127 -118
- package/lib/table/components/ToolBar/DensityIcon.js +10 -9
- package/lib/table/components/ToolBar/FullscreenIcon.js +5 -10
- package/lib/table/components/ToolBar/index.d.ts +2 -8
- package/lib/table/components/ToolBar/index.js +154 -194
- package/lib/table/index.js +27 -27
- package/lib/table/style/index.js +144 -113
- package/lib/table/typing.d.ts +4 -0
- package/lib/table/useFetchData.js +197 -337
- package/lib/table/utils/cellRenderToFromItem.js +106 -120
- package/lib/table/utils/columnRender.js +65 -54
- package/lib/table/utils/columnSort.js +24 -23
- package/lib/table/utils/genProColumnToColumn.d.ts +13 -9
- package/lib/table/utils/genProColumnToColumn.js +121 -99
- package/lib/table/utils/index.d.ts +10 -0
- package/lib/table/utils/index.js +127 -181
- package/lib/table/utils/useDragSort.d.ts +1 -1
- package/lib/table/utils/useDragSort.js +99 -93
- package/lib/table/utils/usePageInfo.d.ts +6 -0
- package/lib/table/utils/usePageInfo.js +61 -0
- package/lib/utils/components/DropdownFooter/index.js +25 -23
- package/lib/utils/components/DropdownFooter/style.js +16 -16
- package/lib/utils/components/ErrorBoundary/index.js +28 -50
- package/lib/utils/components/FieldLabel/index.js +70 -71
- package/lib/utils/components/FieldLabel/style.js +104 -82
- package/lib/utils/components/FilterDropdown/index.d.ts +11 -0
- package/lib/utils/components/FilterDropdown/index.js +44 -33
- package/lib/utils/components/FilterDropdown/style.js +19 -17
- package/lib/utils/components/InlineErrorFormItem/index.js +80 -80
- package/lib/utils/components/InlineErrorFormItem/style.js +56 -50
- package/lib/utils/components/LabelIconTip/index.js +30 -32
- package/lib/utils/components/LabelIconTip/style.js +36 -36
- package/lib/utils/components/ProFormContext/index.js +1 -1
- package/lib/utils/conversionMomentValue/index.js +22 -23
- package/lib/utils/dateArrayFormatter/index.js +11 -15
- package/lib/utils/genCopyable/index.js +75 -33
- package/lib/utils/getFieldPropsOrFormItemProps/index.js +3 -2
- package/lib/utils/hooks/useDebounceFn/index.js +18 -52
- package/lib/utils/hooks/useDebounceValue/index.js +7 -17
- package/lib/utils/hooks/useDeepCompareEffect/index.js +7 -19
- package/lib/utils/hooks/useDocumentTitle/index.js +2 -2
- package/lib/utils/hooks/useFetchData/index.js +36 -65
- package/lib/utils/hooks/useForceRender/index.js +2 -10
- package/lib/utils/hooks/useLatest/index.js +4 -3
- package/lib/utils/hooks/usePrevious/index.js +5 -4
- package/lib/utils/hooks/useReactiveRef/index.js +2 -2
- package/lib/utils/hooks/useRefCallback/index.js +3 -3
- package/lib/utils/hooks/useRefFunction/index.js +6 -11
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +57 -65
- package/lib/utils/isBrowser/index.js +4 -3
- package/lib/utils/isDeepEqualReact/index.js +9 -45
- package/lib/utils/isDropdownValueType/index.js +4 -3
- package/lib/utils/isNil/index.js +2 -3
- package/lib/utils/isUrl/index.js +4 -3
- package/lib/utils/merge/index.js +12 -14
- package/lib/utils/nanoid/index.js +7 -7
- package/lib/utils/omitBoolean/index.js +3 -2
- package/lib/utils/omitUndefined/index.js +5 -4
- package/lib/utils/omitUndefinedAndEmptyArr/index.js +6 -6
- package/lib/utils/parseValueToMoment/index.js +5 -8
- package/lib/utils/pickProFormItemProps/index.js +3 -3
- package/lib/utils/pickProProps/index.js +6 -7
- package/lib/utils/proFieldParsingText/index.js +89 -99
- package/lib/utils/runFunction/index.js +2 -5
- package/lib/utils/stringify/index.js +2 -2
- package/lib/utils/transformKeySubmitValue/index.js +101 -117
- package/lib/utils/useEditableArray/index.d.ts +6 -1
- package/lib/utils/useEditableArray/index.js +582 -735
- package/lib/utils/useEditableMap/index.d.ts +1 -1
- package/lib/utils/useEditableMap/index.js +88 -135
- package/lib/utils/useMediaQuery/index.js +40 -35
- package/lib/utils/useMediaQuery/query.js +7 -18
- package/lib/version.js +1 -1
- package/package.json +20 -31
- package/es/utils/useMountMergeState/index.d.ts +0 -2
- package/es/utils/useMountMergeState/index.js +0 -2
- package/lib/utils/useMountMergeState/index.d.ts +0 -2
- package/lib/utils/useMountMergeState/index.js +0 -12
|
@@ -1,62 +1,61 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
-
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
4
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
8
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
9
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
10
|
-
var _excluded = ["map_row_parentKey"],
|
|
11
|
-
_excluded2 = ["map_row_parentKey", "map_row_key", "isNewRecord"],
|
|
12
|
-
_excluded3 = ["map_row_key"];
|
|
13
1
|
/* eslint-disable react-hooks/exhaustive-deps */import { LoadingOutlined } from '@ant-design/icons';
|
|
14
|
-
import { get, warning as rcWarning, set,
|
|
2
|
+
import { get, warning as rcWarning, set, useControlledState } from '@rc-component/util';
|
|
15
3
|
import { Form, Popconfirm, message } from 'antd';
|
|
16
4
|
import useLazyKVMap from 'antd/lib/table/hooks/useLazyKVMap';
|
|
17
|
-
import React, { createRef, forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import React, { createRef, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
18
6
|
import { useDebounceFn, useRefFunction } from '..';
|
|
19
7
|
import { useIntl } from "../../provider";
|
|
20
8
|
import { ProFormContext } from "../components/ProFormContext";
|
|
21
9
|
import { useDeepCompareEffectDebounce } from "../hooks/useDeepCompareEffect";
|
|
22
10
|
import { usePrevious } from "../hooks/usePrevious";
|
|
23
11
|
import { merge } from "../merge";
|
|
24
|
-
import { useMountMergeState } from "../useMountMergeState";
|
|
25
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
13
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
27
|
-
|
|
14
|
+
const {
|
|
15
|
+
noteOnce
|
|
16
|
+
} = rcWarning;
|
|
28
17
|
|
|
29
18
|
/**
|
|
30
19
|
* 显示警告信息
|
|
31
20
|
* @param messageStr
|
|
32
21
|
*/
|
|
33
|
-
|
|
22
|
+
const warning = messageStr => {
|
|
34
23
|
return message.warning(messageStr);
|
|
35
24
|
};
|
|
36
|
-
export
|
|
25
|
+
export const recordKeyToString = rowKey => {
|
|
37
26
|
if (Array.isArray(rowKey)) return rowKey.join(',');
|
|
38
27
|
return rowKey;
|
|
39
28
|
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalize antd Form `NamePath` segments.
|
|
32
|
+
*
|
|
33
|
+
* - Preserve `0` (number) and other falsy-but-valid segments
|
|
34
|
+
* - Flatten nested arrays (e.g. `name={['a','b']}`)
|
|
35
|
+
* - Convert number segments to string to align with `spellNamePath` behavior
|
|
36
|
+
*/
|
|
37
|
+
const normalizeNamePath = (...segments) => {
|
|
38
|
+
return segments.flat(1).filter(key => key !== undefined && key !== null).map(key => typeof key === 'number' ? key.toString() : key);
|
|
39
|
+
};
|
|
40
40
|
/**
|
|
41
41
|
* 扁平化记录树结构为 Map
|
|
42
42
|
*/
|
|
43
43
|
function flattenRecordsToMap(records, getRowKey, childrenColumnName, parentKey, parentIndex) {
|
|
44
|
-
|
|
45
|
-
records.forEach(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
const kvMap = new Map();
|
|
45
|
+
records.forEach((record, index) => {
|
|
46
|
+
const eachIndex = (parentIndex || 0) * 10 + index;
|
|
47
|
+
const recordKey = getRowKey(record, eachIndex).toString();
|
|
48
|
+
const hasChildren = record && typeof record === 'object' && childrenColumnName in record;
|
|
49
49
|
if (hasChildren) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
childrenMap.forEach(
|
|
53
|
-
return kvMap.set(key, value);
|
|
54
|
-
});
|
|
50
|
+
const children = record[childrenColumnName] || [];
|
|
51
|
+
const childrenMap = flattenRecordsToMap(children, getRowKey, childrenColumnName, recordKey, eachIndex);
|
|
52
|
+
childrenMap.forEach((value, key) => kvMap.set(key, value));
|
|
55
53
|
}
|
|
56
|
-
|
|
54
|
+
const newRecord = {
|
|
55
|
+
...record,
|
|
57
56
|
map_row_key: recordKey,
|
|
58
57
|
map_row_parentKey: parentKey
|
|
59
|
-
}
|
|
58
|
+
};
|
|
60
59
|
delete newRecord.children;
|
|
61
60
|
if (!parentKey) {
|
|
62
61
|
delete newRecord.map_row_parentKey;
|
|
@@ -70,20 +69,21 @@ function flattenRecordsToMap(records, getRowKey, childrenColumnName, parentKey,
|
|
|
70
69
|
* 重建树结构
|
|
71
70
|
*/
|
|
72
71
|
function rebuildTreeStructure(map, childrenColumnName, action) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
map.forEach(
|
|
72
|
+
const childrenMap = new Map();
|
|
73
|
+
const result = [];
|
|
74
|
+
const addNewRecordToChildren = fillChildren => {
|
|
75
|
+
map.forEach(value => {
|
|
77
76
|
if (value.map_row_parentKey != null && !value.map_row_key) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
const {
|
|
78
|
+
map_row_parentKey,
|
|
79
|
+
...rest
|
|
80
|
+
} = value;
|
|
81
|
+
const parentKeyStr = String(map_row_parentKey);
|
|
81
82
|
if (!childrenMap.has(parentKeyStr)) {
|
|
82
83
|
childrenMap.set(parentKeyStr, []);
|
|
83
84
|
}
|
|
84
85
|
if (fillChildren) {
|
|
85
|
-
|
|
86
|
-
(_childrenMap$get = childrenMap.get(parentKeyStr)) === null || _childrenMap$get === void 0 || _childrenMap$get.push(rest);
|
|
86
|
+
childrenMap.get(parentKeyStr)?.push(rest);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
});
|
|
@@ -92,20 +92,22 @@ function rebuildTreeStructure(map, childrenColumnName, action) {
|
|
|
92
92
|
|
|
93
93
|
// 第一步:将所有有 parentKey 的节点添加到 childrenMap
|
|
94
94
|
// 这一步不获取 children,只是添加节点到对应的父节点下
|
|
95
|
-
map.forEach(
|
|
95
|
+
map.forEach(value => {
|
|
96
96
|
if (value.map_row_parentKey != null && value.map_row_key) {
|
|
97
|
-
|
|
98
|
-
map_row_parentKey
|
|
99
|
-
map_row_key
|
|
100
|
-
isNewRecord
|
|
101
|
-
rest
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
const {
|
|
98
|
+
map_row_parentKey,
|
|
99
|
+
map_row_key,
|
|
100
|
+
isNewRecord,
|
|
101
|
+
...rest
|
|
102
|
+
} = value;
|
|
103
|
+
const record = {
|
|
104
|
+
...rest,
|
|
105
|
+
map_row_key
|
|
106
|
+
};
|
|
105
107
|
// 确保 parentKey 的类型转换与 flattenRecordsToMap 中的 recordKey 一致
|
|
106
108
|
// 在 flattenRecordsToMap 中,recordKey 被转换为字符串:getRowKey(record, eachIndex).toString()
|
|
107
109
|
// 所以这里也需要确保 parentKey 被转换为字符串,并且类型一致
|
|
108
|
-
|
|
110
|
+
const parentKeyStr = map_row_parentKey != null ? String(map_row_parentKey) : null;
|
|
109
111
|
if (!parentKeyStr) {
|
|
110
112
|
return;
|
|
111
113
|
}
|
|
@@ -115,47 +117,54 @@ function rebuildTreeStructure(map, childrenColumnName, action) {
|
|
|
115
117
|
|
|
116
118
|
// 如果是新记录且 action 为 'top',添加到数组开头;否则添加到末尾
|
|
117
119
|
if (isNewRecord && action === 'top') {
|
|
118
|
-
|
|
119
|
-
(_childrenMap$get2 = childrenMap.get(parentKeyStr)) === null || _childrenMap$get2 === void 0 || _childrenMap$get2.unshift(_record);
|
|
120
|
+
childrenMap.get(parentKeyStr)?.unshift(record);
|
|
120
121
|
} else {
|
|
121
|
-
|
|
122
|
-
(_childrenMap$get3 = childrenMap.get(parentKeyStr)) === null || _childrenMap$get3 === void 0 || _childrenMap$get3.push(_record);
|
|
122
|
+
childrenMap.get(parentKeyStr)?.push(record);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
// 第二步:为所有节点获取 children
|
|
128
128
|
// 这一步确保所有子节点都已经被添加到 childrenMap,所以可以正确获取 children
|
|
129
|
-
map.forEach(
|
|
129
|
+
map.forEach(value => {
|
|
130
130
|
if (value.map_row_parentKey != null && value.map_row_key) {
|
|
131
|
-
|
|
132
|
-
map_row_parentKey
|
|
133
|
-
map_row_key
|
|
134
|
-
|
|
131
|
+
const {
|
|
132
|
+
map_row_parentKey,
|
|
133
|
+
map_row_key
|
|
134
|
+
} = value;
|
|
135
|
+
const parentKeyStr = map_row_parentKey != null ? String(map_row_parentKey) : null;
|
|
135
136
|
if (!parentKeyStr) {
|
|
136
137
|
return;
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
+
const children = childrenMap.get(parentKeyStr);
|
|
139
140
|
if (children && children.length > 0) {
|
|
140
141
|
// 找到对应的 record 并添加 children
|
|
141
|
-
|
|
142
|
+
const recordIndex = children.findIndex(r => {
|
|
142
143
|
// 比较时需要确保类型一致
|
|
143
|
-
|
|
144
|
+
const recordKey = r.map_row_key || r.id;
|
|
144
145
|
return String(recordKey) === String(map_row_key);
|
|
145
146
|
});
|
|
146
147
|
if (recordIndex >= 0 && childrenMap.has(map_row_key)) {
|
|
147
|
-
children[recordIndex] =
|
|
148
|
+
children[recordIndex] = {
|
|
149
|
+
...children[recordIndex],
|
|
150
|
+
[childrenColumnName]: childrenMap.get(map_row_key)
|
|
151
|
+
};
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
});
|
|
152
156
|
addNewRecordToChildren(action === 'update');
|
|
153
|
-
map.forEach(
|
|
157
|
+
map.forEach(value => {
|
|
154
158
|
if (!value.map_row_parentKey) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
const {
|
|
160
|
+
map_row_key,
|
|
161
|
+
...rest
|
|
162
|
+
} = value;
|
|
163
|
+
const record = map_row_key && childrenMap.has(map_row_key) ? {
|
|
164
|
+
...rest,
|
|
165
|
+
[childrenColumnName]: childrenMap.get(map_row_key)
|
|
166
|
+
} : rest;
|
|
167
|
+
result.push(record);
|
|
159
168
|
}
|
|
160
169
|
});
|
|
161
170
|
return result;
|
|
@@ -165,29 +174,33 @@ function rebuildTreeStructure(map, childrenColumnName, action) {
|
|
|
165
174
|
* 使用map 来删除数据,性能一般 但是准确率比较高
|
|
166
175
|
*/
|
|
167
176
|
export function editableRowByKey(keyProps, action) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
row
|
|
171
|
-
data
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
const {
|
|
178
|
+
getRowKey,
|
|
179
|
+
row,
|
|
180
|
+
data,
|
|
181
|
+
childrenColumnName = 'children'
|
|
182
|
+
} = keyProps;
|
|
183
|
+
const key = recordKeyToString(keyProps.key)?.toString();
|
|
184
|
+
const kvMap = flattenRecordsToMap(data, getRowKey, childrenColumnName);
|
|
176
185
|
if (action === 'delete') {
|
|
177
186
|
kvMap.delete(key);
|
|
178
187
|
} else if (action === 'top' || action === 'update') {
|
|
179
|
-
|
|
188
|
+
const existingRecord = kvMap.get(key);
|
|
180
189
|
if (existingRecord) {
|
|
181
|
-
kvMap.set(key,
|
|
190
|
+
kvMap.set(key, {
|
|
191
|
+
...existingRecord,
|
|
192
|
+
...row
|
|
193
|
+
});
|
|
182
194
|
} else {
|
|
183
195
|
// 如果记录不存在,创建一个新记录(用于新增场景)
|
|
184
196
|
// 保留 map_row_parentKey 以便正确处理嵌套子节点
|
|
185
197
|
// 添加标记以便在 rebuildTreeStructure 中识别新记录
|
|
186
|
-
kvMap.set(key,
|
|
198
|
+
kvMap.set(key, {
|
|
199
|
+
...row,
|
|
187
200
|
map_row_key: key,
|
|
188
201
|
map_row_parentKey: row.map_row_parentKey,
|
|
189
202
|
isNewRecord: true
|
|
190
|
-
})
|
|
203
|
+
});
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
206
|
return rebuildTreeStructure(kvMap, childrenColumnName, action);
|
|
@@ -198,112 +211,83 @@ export function editableRowByKey(keyProps, action) {
|
|
|
198
211
|
*
|
|
199
212
|
* @param ActionRenderConfig
|
|
200
213
|
*/
|
|
201
|
-
export function SaveEditableAction(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// 获取 namepath
|
|
248
|
-
_recordKey = _toArray(recordKey), recordKeyPath = _recordKey.slice(1); // 将目标值获取出来并设置到 fields 当中
|
|
249
|
-
curValue = get(fields, recordKeyPath);
|
|
250
|
-
set(fields, recordKeyPath, curValue);
|
|
251
|
-
}
|
|
252
|
-
data = isMapEditor ? set({}, namePath, fields) : fields; // 获取数据并保存
|
|
253
|
-
_context.next = 18;
|
|
254
|
-
return onSave === null || onSave === void 0 ? void 0 : onSave(recordKey,
|
|
255
|
-
// 如果是 map 模式,fields 就是一个值,所以需要set 到对象中
|
|
256
|
-
// 数据模式 fields 是一个对象,所以不需要
|
|
257
|
-
merge({}, row, data), row, newLineConfig);
|
|
258
|
-
case 18:
|
|
259
|
-
res = _context.sent;
|
|
260
|
-
setLoading(false);
|
|
261
|
-
return _context.abrupt("return", res);
|
|
262
|
-
case 23:
|
|
263
|
-
_context.prev = 23;
|
|
264
|
-
_context.t1 = _context["catch"](0);
|
|
265
|
-
setLoading(false);
|
|
266
|
-
throw _context.t1;
|
|
267
|
-
case 27:
|
|
268
|
-
case "end":
|
|
269
|
-
return _context.stop();
|
|
214
|
+
export function SaveEditableAction({
|
|
215
|
+
recordKey,
|
|
216
|
+
onSave,
|
|
217
|
+
row,
|
|
218
|
+
children,
|
|
219
|
+
newLineConfig,
|
|
220
|
+
editorType,
|
|
221
|
+
tableName
|
|
222
|
+
}, ref) {
|
|
223
|
+
const context = useContext(ProFormContext);
|
|
224
|
+
const form = Form.useFormInstance();
|
|
225
|
+
const [loading, setLoading] = useState(false);
|
|
226
|
+
const save = useRefFunction(async () => {
|
|
227
|
+
try {
|
|
228
|
+
const isMapEditor = editorType === 'Map';
|
|
229
|
+
// 为了兼容类型为 array 的 dataIndex,当 recordKey 是一个数组时,用于获取表单值的 key 只取第一项,
|
|
230
|
+
// 从表单中获取回来之后,再根据 namepath 获取具体的某个字段并设置
|
|
231
|
+
const namePath = normalizeNamePath(tableName, Array.isArray(recordKey) ? recordKey[0] : recordKey);
|
|
232
|
+
setLoading(true);
|
|
233
|
+
try {
|
|
234
|
+
await form.validateFields(namePath, {
|
|
235
|
+
recursive: true
|
|
236
|
+
});
|
|
237
|
+
} catch (error) {
|
|
238
|
+
setLoading(false);
|
|
239
|
+
// 重新抛出验证错误,让表单显示错误信息
|
|
240
|
+
// validateFields 抛出错误时,表单会自动设置错误状态并显示错误
|
|
241
|
+
// 错误对象包含 errorFields,表单会根据这些字段显示错误
|
|
242
|
+
// 确保错误被正确传播,这样表单可以正确显示验证错误
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
const fields = (() => {
|
|
246
|
+
// `getFieldFormatValue` will unwrap object results (by returning the first value),
|
|
247
|
+
// which breaks editable row save when `namePath` points to a row object.
|
|
248
|
+
// Prefer `getFieldFormatValueObject` and then pick the row by `namePath`.
|
|
249
|
+
const formattedObject = context?.getFieldFormatValueObject?.(namePath);
|
|
250
|
+
const formattedRow = formattedObject != null ? get(formattedObject, namePath) : null;
|
|
251
|
+
return formattedRow ?? form.getFieldValue(namePath);
|
|
252
|
+
})();
|
|
253
|
+
// 处理 dataIndex 为数组的情况
|
|
254
|
+
if (Array.isArray(recordKey) && recordKey.length > 1) {
|
|
255
|
+
// 获取 namepath
|
|
256
|
+
const [, ...recordKeyPath] = recordKey;
|
|
257
|
+
// 将目标值获取出来并设置到 fields 当中
|
|
258
|
+
const curValue = get(fields, recordKeyPath);
|
|
259
|
+
set(fields, recordKeyPath, curValue);
|
|
270
260
|
}
|
|
271
|
-
|
|
272
|
-
|
|
261
|
+
const data = isMapEditor ? set({}, namePath, fields) : fields;
|
|
262
|
+
|
|
263
|
+
// 获取数据并保存
|
|
264
|
+
const res = await onSave?.(recordKey,
|
|
265
|
+
// 如果是 map 模式,fields 就是一个值,所以需要set 到对象中
|
|
266
|
+
// 数据模式 fields 是一个对象,所以不需要
|
|
267
|
+
merge({}, row, data), row, newLineConfig);
|
|
268
|
+
setLoading(false);
|
|
269
|
+
return res;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
setLoading(false);
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
273
275
|
|
|
274
276
|
// 保存数据
|
|
275
|
-
useImperativeHandle(ref,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
};
|
|
279
|
-
}, [save]);
|
|
277
|
+
useImperativeHandle(ref, () => ({
|
|
278
|
+
save
|
|
279
|
+
}), [save]);
|
|
280
280
|
return /*#__PURE__*/_jsxs("a", {
|
|
281
|
-
onClick:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
case 5:
|
|
292
|
-
_context2.next = 9;
|
|
293
|
-
break;
|
|
294
|
-
case 7:
|
|
295
|
-
_context2.prev = 7;
|
|
296
|
-
_context2.t0 = _context2["catch"](2);
|
|
297
|
-
case 9:
|
|
298
|
-
case "end":
|
|
299
|
-
return _context2.stop();
|
|
300
|
-
}
|
|
301
|
-
}, _callee2, null, [[2, 7]]);
|
|
302
|
-
}));
|
|
303
|
-
return function (_x) {
|
|
304
|
-
return _ref5.apply(this, arguments);
|
|
305
|
-
};
|
|
306
|
-
}()),
|
|
281
|
+
onClick: async e => {
|
|
282
|
+
e.stopPropagation();
|
|
283
|
+
e.preventDefault();
|
|
284
|
+
try {
|
|
285
|
+
await save();
|
|
286
|
+
} catch {
|
|
287
|
+
// 验证错误会被 form.validateFields 抛出,这里不需要处理
|
|
288
|
+
// 错误会被表单自动显示
|
|
289
|
+
}
|
|
290
|
+
},
|
|
307
291
|
children: [loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
308
292
|
style: {
|
|
309
293
|
marginInlineEnd: 8
|
|
@@ -316,60 +300,41 @@ export function SaveEditableAction(_ref3, ref) {
|
|
|
316
300
|
*
|
|
317
301
|
* @param ActionRenderConfig
|
|
318
302
|
*/
|
|
319
|
-
export
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
_context3.prev = 0;
|
|
338
|
-
setLoading(true);
|
|
339
|
-
_context3.next = 4;
|
|
340
|
-
return onDelete === null || onDelete === void 0 ? void 0 : onDelete(recordKey, row);
|
|
341
|
-
case 4:
|
|
342
|
-
res = _context3.sent;
|
|
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:
|
|
351
|
-
return _context3.abrupt("return", res);
|
|
352
|
-
case 11:
|
|
353
|
-
_context3.prev = 11;
|
|
354
|
-
_context3.t0 = _context3["catch"](0);
|
|
355
|
-
setLoading(false);
|
|
356
|
-
return _context3.abrupt("return", null);
|
|
357
|
-
case 15:
|
|
358
|
-
_context3.prev = 15;
|
|
359
|
-
if (preEditRowRef) preEditRowRef.current = null;
|
|
360
|
-
return _context3.finish(15);
|
|
361
|
-
case 18:
|
|
362
|
-
case "end":
|
|
363
|
-
return _context3.stop();
|
|
303
|
+
export const DeleteEditableAction = ({
|
|
304
|
+
recordKey,
|
|
305
|
+
onDelete,
|
|
306
|
+
preEditRowRef,
|
|
307
|
+
preEditRowRefs,
|
|
308
|
+
row,
|
|
309
|
+
children,
|
|
310
|
+
deletePopconfirmMessage
|
|
311
|
+
}) => {
|
|
312
|
+
const [loading, setLoading] = useState(false);
|
|
313
|
+
const onConfirm = useRefFunction(async () => {
|
|
314
|
+
try {
|
|
315
|
+
setLoading(true);
|
|
316
|
+
const res = await onDelete?.(recordKey, row);
|
|
317
|
+
setLoading(false);
|
|
318
|
+
// 如果返回 false,阻止删除操作
|
|
319
|
+
if (res === false) {
|
|
320
|
+
return false;
|
|
364
321
|
}
|
|
365
|
-
|
|
366
|
-
|
|
322
|
+
return res;
|
|
323
|
+
} catch {
|
|
324
|
+
setLoading(false);
|
|
325
|
+
return null;
|
|
326
|
+
} finally {
|
|
327
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
328
|
+
if (recordKeyStr) {
|
|
329
|
+
preEditRowRefs?.current?.delete(recordKeyStr);
|
|
330
|
+
}
|
|
331
|
+
if (preEditRowRef) preEditRowRef.current = null;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
367
334
|
return children !== false ? /*#__PURE__*/_jsx(Popconfirm, {
|
|
368
335
|
title: deletePopconfirmMessage || '确定要删除这条记录吗?',
|
|
369
336
|
onConfirm: onConfirm,
|
|
370
|
-
getPopupContainer:
|
|
371
|
-
return triggerNode.parentElement || document.body;
|
|
372
|
-
},
|
|
337
|
+
getPopupContainer: triggerNode => triggerNode.parentElement || document.body,
|
|
373
338
|
children: /*#__PURE__*/_jsxs("a", {
|
|
374
339
|
children: [loading ? /*#__PURE__*/_jsx(LoadingOutlined, {
|
|
375
340
|
style: {
|
|
@@ -379,86 +344,91 @@ export var DeleteEditableAction = function DeleteEditableAction(_ref6) {
|
|
|
379
344
|
})
|
|
380
345
|
}, "delete") : null;
|
|
381
346
|
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
347
|
+
const CancelEditableAction = props => {
|
|
348
|
+
const {
|
|
349
|
+
recordKey,
|
|
350
|
+
tableName,
|
|
351
|
+
newLineConfig,
|
|
352
|
+
editorType,
|
|
353
|
+
onCancel,
|
|
354
|
+
cancelEditable,
|
|
355
|
+
row,
|
|
356
|
+
cancelText,
|
|
357
|
+
preEditRowRef,
|
|
358
|
+
preEditRowRefs
|
|
359
|
+
} = props;
|
|
360
|
+
const context = useContext(ProFormContext);
|
|
361
|
+
const form = Form.useFormInstance();
|
|
394
362
|
return /*#__PURE__*/_jsx("a", {
|
|
395
|
-
onClick:
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return _ref8.apply(this, arguments);
|
|
436
|
-
};
|
|
437
|
-
}()),
|
|
363
|
+
onClick: async e => {
|
|
364
|
+
e.stopPropagation();
|
|
365
|
+
e.preventDefault();
|
|
366
|
+
const isMapEditor = editorType === 'Map';
|
|
367
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
368
|
+
const namePath = normalizeNamePath(tableName, recordKey);
|
|
369
|
+
const fields = (() => {
|
|
370
|
+
const formattedObject = context?.getFieldFormatValueObject?.(namePath);
|
|
371
|
+
const formattedRow = formattedObject != null ? get(formattedObject, namePath) : null;
|
|
372
|
+
return formattedRow ?? form?.getFieldValue(namePath);
|
|
373
|
+
})();
|
|
374
|
+
const record = isMapEditor ? set({}, namePath, fields) : fields;
|
|
375
|
+
|
|
376
|
+
// 在清理编辑态前,先捕获“编辑前快照”(多行编辑时必须按 key 取值)
|
|
377
|
+
const cachedPreEditRow = recordKeyStr != null ? preEditRowRefs?.current?.get(recordKeyStr) : undefined;
|
|
378
|
+
const isNewLineKeyMatch = (() => {
|
|
379
|
+
const newLineKey = newLineConfig?.options?.recordKey;
|
|
380
|
+
if (newLineKey == null || recordKey == null) return false;
|
|
381
|
+
const newLineKeyStr = recordKeyToString(newLineKey)?.toString();
|
|
382
|
+
const currentKeyStr = recordKeyToString(recordKey)?.toString();
|
|
383
|
+
if (!newLineKeyStr || !currentKeyStr) return false;
|
|
384
|
+
return newLineKeyStr === currentKeyStr;
|
|
385
|
+
})();
|
|
386
|
+
const res = await onCancel?.(recordKey, record, row, newLineConfig);
|
|
387
|
+
await cancelEditable(recordKey);
|
|
388
|
+
/** 重置为默认值,不然编辑的行会丢掉 */
|
|
389
|
+
const restoreRow = cachedPreEditRow ?? preEditRowRef?.current ?? row;
|
|
390
|
+
const shouldDeleteNewRow = cachedPreEditRow === null || cachedPreEditRow === undefined && preEditRowRef?.current === null && isNewLineKeyMatch;
|
|
391
|
+
if (shouldDeleteNewRow) {
|
|
392
|
+
// 如果不存在历史值,说明是新的行,干掉他
|
|
393
|
+
await props.onDelete?.(recordKey, row);
|
|
394
|
+
} else if (restoreRow != null) {
|
|
395
|
+
form.setFieldsValue(set({}, namePath, restoreRow));
|
|
396
|
+
}
|
|
397
|
+
if (recordKeyStr) {
|
|
398
|
+
preEditRowRefs?.current?.delete(recordKeyStr);
|
|
399
|
+
}
|
|
400
|
+
if (preEditRowRef) preEditRowRef.current = null;
|
|
401
|
+
return res;
|
|
402
|
+
},
|
|
438
403
|
children: cancelText || '取消'
|
|
439
404
|
}, "cancel");
|
|
440
405
|
};
|
|
441
406
|
export function defaultActionRender(row, config) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
407
|
+
const {
|
|
408
|
+
recordKey,
|
|
409
|
+
newLineConfig,
|
|
410
|
+
saveText,
|
|
411
|
+
deleteText
|
|
412
|
+
} = config;
|
|
413
|
+
const SaveEditableActionRef = /*#__PURE__*/forwardRef(SaveEditableAction);
|
|
414
|
+
const saveRef = /*#__PURE__*/createRef();
|
|
448
415
|
return {
|
|
449
|
-
save: /*#__PURE__*/_jsx(SaveEditableActionRef,
|
|
416
|
+
save: /*#__PURE__*/_jsx(SaveEditableActionRef, {
|
|
417
|
+
...config,
|
|
450
418
|
row: row,
|
|
451
419
|
ref: saveRef,
|
|
452
420
|
children: saveText
|
|
453
|
-
}
|
|
454
|
-
saveRef
|
|
455
|
-
delete:
|
|
421
|
+
}, 'save' + recordKey),
|
|
422
|
+
saveRef,
|
|
423
|
+
delete: newLineConfig?.options.recordKey !== recordKey ? /*#__PURE__*/_jsx(DeleteEditableAction, {
|
|
424
|
+
...config,
|
|
456
425
|
row: row,
|
|
457
426
|
children: deleteText
|
|
458
|
-
}
|
|
459
|
-
cancel: /*#__PURE__*/_jsx(CancelEditableAction,
|
|
427
|
+
}, 'delete' + recordKey) : undefined,
|
|
428
|
+
cancel: /*#__PURE__*/_jsx(CancelEditableAction, {
|
|
429
|
+
...config,
|
|
460
430
|
row: row
|
|
461
|
-
}
|
|
431
|
+
}, 'cancel' + recordKey)
|
|
462
432
|
};
|
|
463
433
|
}
|
|
464
434
|
|
|
@@ -469,26 +439,24 @@ export function defaultActionRender(row, config) {
|
|
|
469
439
|
*/
|
|
470
440
|
export function useEditableArray(props) {
|
|
471
441
|
// Internationalization
|
|
472
|
-
|
|
442
|
+
const intl = useIntl();
|
|
473
443
|
|
|
474
444
|
/**
|
|
475
445
|
* 点击开始编辑之前的保存数据用的
|
|
476
446
|
*/
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
newLineRecordCache = _useState2[0],
|
|
481
|
-
setNewLineRecordCache = _useState2[1];
|
|
447
|
+
const preEditRowRef = useRef(null);
|
|
448
|
+
const preEditRowRefs = useRef(new Map());
|
|
449
|
+
const [newLineRecordCache, setNewLineRecordCache] = useState(undefined);
|
|
482
450
|
|
|
483
451
|
/**
|
|
484
452
|
* 构建数据源 key 索引映射表
|
|
485
453
|
*/
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
records
|
|
490
|
-
|
|
491
|
-
|
|
454
|
+
const buildDataSourceKeyIndexMap = useRefFunction(() => {
|
|
455
|
+
const map = new Map();
|
|
456
|
+
const traverseRecords = (records, parentKey) => {
|
|
457
|
+
records?.forEach((record, index) => {
|
|
458
|
+
const indexKey = parentKey == null ? index.toString() : `${parentKey}_${index}`;
|
|
459
|
+
const recordKey = recordKeyToString(props.getRowKey(record, -1));
|
|
492
460
|
|
|
493
461
|
// 如果 recordKey 是 undefined 或 null,跳过
|
|
494
462
|
if (recordKey == null) {
|
|
@@ -496,7 +464,7 @@ export function useEditableArray(props) {
|
|
|
496
464
|
}
|
|
497
465
|
map.set(indexKey, recordKey);
|
|
498
466
|
map.set(recordKey.toString(), indexKey);
|
|
499
|
-
|
|
467
|
+
const children = props.childrenColumnName && record?.[props.childrenColumnName];
|
|
500
468
|
if (children) {
|
|
501
469
|
traverseRecords(children, indexKey);
|
|
502
470
|
}
|
|
@@ -505,72 +473,53 @@ export function useEditableArray(props) {
|
|
|
505
473
|
traverseRecords(props.dataSource);
|
|
506
474
|
return map;
|
|
507
475
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
var newLineRecordRef = useRef(undefined);
|
|
513
|
-
useDeepCompareEffectDebounce(function () {
|
|
476
|
+
const initDataSourceKeyIndexMap = useMemo(() => buildDataSourceKeyIndexMap(), []);
|
|
477
|
+
const dataSourceKeyIndexMapRef = useRef(initDataSourceKeyIndexMap);
|
|
478
|
+
const newLineRecordRef = useRef(undefined);
|
|
479
|
+
useDeepCompareEffectDebounce(() => {
|
|
514
480
|
dataSourceKeyIndexMapRef.current = buildDataSourceKeyIndexMap();
|
|
515
481
|
}, [props.dataSource]);
|
|
516
482
|
|
|
517
483
|
// 这里这么做是为了存上次的状态,不然每次存一下再拿
|
|
518
484
|
newLineRecordRef.current = newLineRecordCache;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
})) !== null && _keys$filter !== void 0 ? _keys$filter : [], // 计算编辑的行
|
|
531
|
-
(_keys$map$filter = keys === null || keys === void 0 ? void 0 : keys.map(function (key) {
|
|
532
|
-
return getRecordByKey(key);
|
|
533
|
-
}).filter(function (key) {
|
|
534
|
-
return key !== undefined;
|
|
535
|
-
})) !== null && _keys$map$filter !== void 0 ? _keys$map$filter : []);
|
|
536
|
-
} : undefined
|
|
537
|
-
}),
|
|
538
|
-
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
|
539
|
-
editableKeys = _useMergedState2[0],
|
|
540
|
-
setEditableRowKeys = _useMergedState2[1];
|
|
541
|
-
var editableKeysRef = usePrevious(editableKeys);
|
|
485
|
+
const editableType = props.type || 'single';
|
|
486
|
+
const [getRecordByKey] = useLazyKVMap(props.dataSource, 'children', props.getRowKey);
|
|
487
|
+
const [editableKeys, setEditableRowKeysInner] = useControlledState([], props.editableKeys);
|
|
488
|
+
const setEditableRowKeys = useCallback(updater => {
|
|
489
|
+
setEditableRowKeysInner(prev => {
|
|
490
|
+
const next = typeof updater === 'function' ? updater(prev) : updater;
|
|
491
|
+
props?.onChange?.(next?.filter(key => key !== undefined) ?? [], next?.map(key => getRecordByKey(key)).filter(k => k !== undefined) ?? []);
|
|
492
|
+
return next;
|
|
493
|
+
});
|
|
494
|
+
}, [props.onChange, getRecordByKey]);
|
|
495
|
+
const editableKeysRef = usePrevious(editableKeys);
|
|
542
496
|
|
|
543
497
|
/**
|
|
544
498
|
* 检查 key 是否在编辑列表中
|
|
545
499
|
*/
|
|
546
|
-
|
|
500
|
+
const checkKeyInEditableList = useRefFunction((key, keysList) => {
|
|
547
501
|
return keysList.includes(key);
|
|
548
502
|
});
|
|
549
503
|
|
|
550
504
|
/** 这行是不是编辑状态 */
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
})) || [];
|
|
558
|
-
var stringEditableKeysRef = (editableKeysRef === null || editableKeysRef === void 0 ? void 0 : editableKeysRef.map(function (key) {
|
|
559
|
-
return key === null || key === void 0 ? void 0 : key.toString();
|
|
560
|
-
})) || [];
|
|
561
|
-
var preIsEditable = checkKeyInEditableList(recordKey, stringEditableKeysRef) || checkKeyInEditableList(recordKeyWithIndex, stringEditableKeysRef);
|
|
505
|
+
const isEditable = useRefFunction(row => {
|
|
506
|
+
const recordKeyWithIndex = props.getRowKey(row, row.index)?.toString();
|
|
507
|
+
const recordKey = props.getRowKey(row, -1)?.toString();
|
|
508
|
+
const stringEditableKeys = editableKeys?.map(key => key?.toString()) || [];
|
|
509
|
+
const stringEditableKeysRef = editableKeysRef?.map(key => key?.toString()) || [];
|
|
510
|
+
const preIsEditable = checkKeyInEditableList(recordKey, stringEditableKeysRef) || checkKeyInEditableList(recordKeyWithIndex, stringEditableKeysRef);
|
|
562
511
|
return {
|
|
563
|
-
recordKey
|
|
512
|
+
recordKey,
|
|
564
513
|
isEditable: checkKeyInEditableList(recordKey, stringEditableKeys) || checkKeyInEditableList(recordKeyWithIndex, stringEditableKeys),
|
|
565
|
-
preIsEditable
|
|
514
|
+
preIsEditable
|
|
566
515
|
};
|
|
567
516
|
});
|
|
568
517
|
|
|
569
518
|
/**
|
|
570
519
|
* 验证是否可以开始编辑
|
|
571
520
|
*/
|
|
572
|
-
|
|
573
|
-
|
|
521
|
+
const validateCanStartEdit = useRefFunction(() => {
|
|
522
|
+
const hasEditableKeys = editableKeys && editableKeys.length > 0;
|
|
574
523
|
if (hasEditableKeys && editableType === 'single' && props.onlyOneLineEditorAlertMessage !== false) {
|
|
575
524
|
warning(props.onlyOneLineEditorAlertMessage || intl.getMessage('editableTable.onlyOneLineEditor', '只能同时编辑一行'));
|
|
576
525
|
return false;
|
|
@@ -581,206 +530,168 @@ export function useEditableArray(props) {
|
|
|
581
530
|
/**
|
|
582
531
|
* 查找记录
|
|
583
532
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return (_props$dataSource$fin = (_props$dataSource = props.dataSource) === null || _props$dataSource === void 0 ? void 0 : _props$dataSource.find(function (recordData, index) {
|
|
533
|
+
const findRecordByKey = useRefFunction(recordKey => {
|
|
534
|
+
return props.dataSource?.find((recordData, index) => {
|
|
587
535
|
return props.getRowKey(recordData, index) === recordKey;
|
|
588
|
-
})
|
|
536
|
+
}) ?? null;
|
|
589
537
|
});
|
|
590
538
|
|
|
591
539
|
/**
|
|
592
540
|
* 进入编辑状态
|
|
593
541
|
*/
|
|
594
|
-
|
|
595
|
-
var _ref9;
|
|
542
|
+
const startEditable = useRefFunction((recordKey, record) => {
|
|
596
543
|
if (!validateCanStartEdit()) {
|
|
597
544
|
return false;
|
|
598
545
|
}
|
|
599
|
-
|
|
600
|
-
return key === recordKey || (key === null || key === void 0 ? void 0 : key.toString()) === (recordKey === null || recordKey === void 0 ? void 0 : recordKey.toString());
|
|
601
|
-
});
|
|
546
|
+
const isAlreadyEditable = editableKeys?.some(key => key === recordKey || key?.toString() === recordKey?.toString());
|
|
602
547
|
if (!isAlreadyEditable) {
|
|
603
|
-
|
|
548
|
+
const newKeys = editableKeys ? [...editableKeys, recordKey] : [recordKey];
|
|
604
549
|
setEditableRowKeys(newKeys);
|
|
605
550
|
}
|
|
606
|
-
preEditRowRef.current =
|
|
551
|
+
preEditRowRef.current = record ?? findRecordByKey(recordKey) ?? null;
|
|
552
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
553
|
+
if (recordKeyStr) {
|
|
554
|
+
preEditRowRefs.current.set(recordKeyStr, preEditRowRef.current);
|
|
555
|
+
}
|
|
607
556
|
return true;
|
|
608
557
|
});
|
|
609
558
|
|
|
610
559
|
/**
|
|
611
560
|
* 清理编辑状态
|
|
612
561
|
*/
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
var relayKeyStr = relayKey != null ? relayKey.toString() : null;
|
|
562
|
+
const clearEditableState = useRefFunction(recordKey => {
|
|
563
|
+
const relayKey = recordKeyToString(recordKey);
|
|
564
|
+
const relayKeyStr = relayKey != null ? relayKey.toString() : null;
|
|
617
565
|
if (relayKeyStr == null) {
|
|
618
566
|
return;
|
|
619
567
|
}
|
|
620
|
-
|
|
621
|
-
return (key === null || key === void 0 ? void 0 : key.toString()) !== relayKeyStr && key !== relayKey;
|
|
622
|
-
})) !== null && _editableKeys$filter !== void 0 ? _editableKeys$filter : [];
|
|
568
|
+
const newKeys = editableKeys?.filter(key => key?.toString() !== relayKeyStr && key !== relayKey) ?? [];
|
|
623
569
|
setEditableRowKeys(newKeys);
|
|
624
570
|
});
|
|
625
571
|
|
|
626
572
|
/**
|
|
627
573
|
* 退出编辑状态
|
|
628
574
|
*/
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
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;
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
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
|
-
}
|
|
575
|
+
const cancelEditable = useRefFunction(async (recordKey, needReTry) => {
|
|
576
|
+
const relayKey = recordKeyToString(recordKey);
|
|
577
|
+
const relayKeyStr = relayKey != null ? relayKey.toString() : null;
|
|
578
|
+
const mappedKey = relayKeyStr != null ? dataSourceKeyIndexMapRef.current.get(relayKeyStr) : undefined;
|
|
579
|
+
const isInEditableSet = editableKeys?.some(key => {
|
|
580
|
+
if (relayKeyStr == null) return false;
|
|
581
|
+
return key?.toString() === relayKeyStr || key === relayKey;
|
|
582
|
+
});
|
|
583
|
+
if (!isInEditableSet && mappedKey && (needReTry ?? true) && props.tableName) {
|
|
584
|
+
return await cancelEditable(mappedKey, false);
|
|
585
|
+
}
|
|
685
586
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
587
|
+
// 如果提供了 onCancel,尝试调用它(用于测试场景)
|
|
588
|
+
// 注意:在实际使用中,onCancel 应该在 CancelEditableAction 中被调用
|
|
589
|
+
if (props.onCancel && isInEditableSet) {
|
|
590
|
+
const keyForFind = Array.isArray(recordKey) ? recordKey[0] : recordKey;
|
|
591
|
+
const record = findRecordByKey(keyForFind);
|
|
592
|
+
const originRow = preEditRowRef.current;
|
|
593
|
+
// 比较 recordKey 时需要考虑类型转换
|
|
594
|
+
// newLineRecordCache.options.recordKey 是 addEditRecord 时设置的 recordKey
|
|
595
|
+
// 而 recordKey 是 cancelEditable 的参数,需要确保它们匹配
|
|
596
|
+
const cacheRecordKey = newLineRecordCache?.options?.recordKey;
|
|
597
|
+
const cacheKey = cacheRecordKey != null ? recordKeyToString(cacheRecordKey) : null;
|
|
598
|
+
const cacheKeyStr = cacheKey != null ? cacheKey.toString() : null;
|
|
599
|
+
// 检查 newLineRecordCache 是否匹配当前的 recordKey
|
|
600
|
+
const newLineConfig = newLineRecordCache != null && cacheRecordKey != null && (cacheRecordKey === recordKey || cacheKeyStr != null && relayKeyStr != null && cacheKeyStr === relayKeyStr || cacheRecordKey?.toString() === recordKey?.toString() || String(cacheRecordKey) === String(recordKey)) ? newLineRecordCache : undefined;
|
|
601
|
+
|
|
602
|
+
// 调用 onCancel,即使找不到记录(新行编辑场景)
|
|
603
|
+
// 对于新行编辑,record 可能为 null,但 newLineConfig 应该包含 defaultValue
|
|
604
|
+
try {
|
|
605
|
+
await props.onCancel(recordKey, record || newLineConfig?.defaultValue || {}, originRow || record || newLineConfig?.defaultValue || {}, newLineConfig);
|
|
606
|
+
} catch (error) {
|
|
607
|
+
// 如果 onCancel 抛出异常,仍然继续清理状态
|
|
608
|
+
console.error('onCancel error:', error);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// 清理 newLineRecordCache,需要比较 recordKey(考虑类型转换)
|
|
613
|
+
if (newLineRecordCache) {
|
|
614
|
+
const cacheRecordKey = newLineRecordCache.options.recordKey;
|
|
615
|
+
// 重用之前计算的 relayKeyStr
|
|
616
|
+
const cacheKeyStr = cacheRecordKey != null ? recordKeyToString(cacheRecordKey)?.toString() : null;
|
|
617
|
+
if (cacheRecordKey === recordKey || cacheKeyStr != null && relayKeyStr != null && cacheKeyStr === relayKeyStr || cacheRecordKey?.toString() === recordKey?.toString() || String(cacheRecordKey) === String(recordKey)) {
|
|
618
|
+
setNewLineRecordCache(undefined);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
711
621
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
622
|
+
// 先清理 preEditRowRef 并重置表单字段,然后再清除编辑状态
|
|
623
|
+
// 这样在清除编辑状态前,表单字段已经被清除,表格重新渲染时就不会显示输入框
|
|
624
|
+
const originRow = preEditRowRef.current;
|
|
625
|
+
if (originRow && props.getRowKey(originRow, -1) === recordKey && isInEditableSet) {
|
|
626
|
+
try {
|
|
627
|
+
// 尝试通过 formProps.formRef 访问 form
|
|
628
|
+
const formRef = props.formProps?.formRef;
|
|
629
|
+
const form = formRef?.current || props.form;
|
|
630
|
+
if (form) {
|
|
631
|
+
if (props.tableName) {
|
|
632
|
+
// name 模式:重置为原始值
|
|
633
|
+
const namePath = normalizeNamePath(props.tableName, recordKey);
|
|
634
|
+
form.setFieldsValue(set({}, namePath, originRow));
|
|
635
|
+
} else {
|
|
636
|
+
// 非 name 模式:清除该行的所有表单字段
|
|
637
|
+
// 在非 name 模式下,表单字段路径是 [recordKey, columnDataIndex]
|
|
638
|
+
// 如 [624748504, 'title'],需要清除所有以 recordKey 开头的字段
|
|
639
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
640
|
+
if (recordKeyStr) {
|
|
641
|
+
try {
|
|
642
|
+
// 在非 name 模式下,表单字段以嵌套对象的形式存储
|
|
643
|
+
// 比如 { '624748504': { 'title': 'value', 'state': 'value' } }
|
|
644
|
+
// 需要清除整个嵌套对象
|
|
645
|
+
// 先使用 resetFields 清除字段状态
|
|
646
|
+
form.resetFields([[recordKeyStr]]);
|
|
647
|
+
|
|
648
|
+
// 然后使用 setFieldsValue 清除字段值
|
|
649
|
+
// 这样可以确保字段被完全清除,表格重新渲染时不会显示输入框
|
|
650
|
+
form.setFieldsValue({
|
|
651
|
+
[recordKeyStr]: undefined
|
|
652
|
+
});
|
|
722
653
|
} catch (error) {
|
|
723
|
-
//
|
|
724
|
-
console.warn('Failed to
|
|
654
|
+
// 如果清除失败,忽略错误
|
|
655
|
+
console.warn('Failed to clear form fields in cancelEditable:', error);
|
|
725
656
|
}
|
|
726
|
-
preEditRowRef.current = null;
|
|
727
657
|
}
|
|
728
|
-
|
|
729
|
-
// 最后清除编辑状态,这样表格会重新渲染,输入框会消失
|
|
730
|
-
clearEditableState(recordKey);
|
|
731
|
-
return _context5.abrupt("return", true);
|
|
732
|
-
case 29:
|
|
733
|
-
case "end":
|
|
734
|
-
return _context5.stop();
|
|
735
|
-
}
|
|
736
|
-
}, _callee5, null, [[16, 21]]);
|
|
737
|
-
}));
|
|
738
|
-
return function (_x3, _x4) {
|
|
739
|
-
return _ref10.apply(this, arguments);
|
|
740
|
-
};
|
|
741
|
-
}());
|
|
742
|
-
var propsOnValuesChange = useDebounceFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
743
|
-
var _props$onValuesChange;
|
|
744
|
-
var _len,
|
|
745
|
-
rest,
|
|
746
|
-
_key,
|
|
747
|
-
_args6 = arguments;
|
|
748
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
749
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
750
|
-
case 0:
|
|
751
|
-
for (_len = _args6.length, rest = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
752
|
-
rest[_key] = _args6[_key];
|
|
753
658
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
return _context6.stop();
|
|
659
|
+
}
|
|
660
|
+
} catch (error) {
|
|
661
|
+
// 如果访问 form 失败,忽略错误
|
|
662
|
+
console.warn('Failed to reset form fields in cancelEditable:', error);
|
|
759
663
|
}
|
|
760
|
-
|
|
761
|
-
|
|
664
|
+
preEditRowRef.current = null;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// 最后清除编辑状态,这样表格会重新渲染,输入框会消失
|
|
668
|
+
clearEditableState(recordKey);
|
|
669
|
+
return true;
|
|
670
|
+
});
|
|
671
|
+
const propsOnValuesChange = useDebounceFn(async (...rest) => {
|
|
672
|
+
//@ts-ignore
|
|
673
|
+
props.onValuesChange?.(...rest);
|
|
674
|
+
}, 64);
|
|
762
675
|
|
|
763
676
|
/**
|
|
764
677
|
* 构建表单字段路径
|
|
765
678
|
*/
|
|
766
|
-
|
|
767
|
-
return [props.tableName || '', recordKey].flat(1).filter(
|
|
768
|
-
return key || key === 0;
|
|
769
|
-
});
|
|
679
|
+
const buildFormFieldPath = useRefFunction(recordKey => {
|
|
680
|
+
return [props.tableName || '', recordKey].flat(1).filter(key => key || key === 0);
|
|
770
681
|
});
|
|
771
682
|
|
|
772
683
|
/**
|
|
773
684
|
* 更新数据源中的编辑行
|
|
774
685
|
*/
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
editableKeys
|
|
778
|
-
if (
|
|
686
|
+
const updateDataSourceWithEditableRows = useRefFunction((dataSource, values) => {
|
|
687
|
+
let updatedDataSource = dataSource;
|
|
688
|
+
editableKeys?.forEach(eachRecordKey => {
|
|
689
|
+
if (newLineRecordCache?.options.recordKey === eachRecordKey) {
|
|
779
690
|
return;
|
|
780
691
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
692
|
+
const recordKey = eachRecordKey.toString();
|
|
693
|
+
const fieldPath = buildFormFieldPath(recordKey);
|
|
694
|
+
const editRow = get(values, fieldPath);
|
|
784
695
|
if (!editRow) {
|
|
785
696
|
return;
|
|
786
697
|
}
|
|
@@ -798,45 +709,43 @@ export function useEditableArray(props) {
|
|
|
798
709
|
/**
|
|
799
710
|
* 获取当前编辑的行数据
|
|
800
711
|
*/
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
var valueKeys = Object.keys(value || {});
|
|
712
|
+
const getCurrentEditRow = useRefFunction((value, values, dataSource) => {
|
|
713
|
+
const valueKeys = Object.keys(value || {});
|
|
804
714
|
if (valueKeys.length === 0) {
|
|
805
|
-
return
|
|
715
|
+
return newLineRecordCache?.defaultValue || {};
|
|
806
716
|
}
|
|
807
|
-
|
|
717
|
+
const recordKey = valueKeys.pop()?.toString() || '';
|
|
808
718
|
if (!recordKey) {
|
|
809
|
-
return
|
|
719
|
+
return newLineRecordCache?.defaultValue || {};
|
|
810
720
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
721
|
+
const fieldPath = buildFormFieldPath(recordKey);
|
|
722
|
+
const newLineRecordData = {
|
|
723
|
+
...newLineRecordCache?.defaultValue,
|
|
724
|
+
...get(values, fieldPath)
|
|
725
|
+
};
|
|
726
|
+
const existsInDataSource = dataSourceKeyIndexMapRef.current.has(recordKeyToString(recordKey));
|
|
814
727
|
if (existsInDataSource) {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
var key = (_props$getRowKey3 = props.getRowKey(item, index)) === null || _props$getRowKey3 === void 0 ? void 0 : _props$getRowKey3.toString();
|
|
728
|
+
const foundRow = dataSource.find((item, index) => {
|
|
729
|
+
const key = props.getRowKey(item, index)?.toString();
|
|
818
730
|
return key === recordKey;
|
|
819
731
|
});
|
|
820
732
|
return foundRow || newLineRecordData;
|
|
821
733
|
}
|
|
822
734
|
return newLineRecordData;
|
|
823
735
|
});
|
|
824
|
-
|
|
736
|
+
const onValuesChange = useRefFunction((value, values) => {
|
|
825
737
|
if (!props.onValuesChange) {
|
|
826
738
|
return;
|
|
827
739
|
}
|
|
828
|
-
|
|
829
|
-
|
|
740
|
+
const updatedDataSource = updateDataSourceWithEditableRows(props.dataSource, values);
|
|
741
|
+
const editRow = getCurrentEditRow(value, values, updatedDataSource);
|
|
830
742
|
propsOnValuesChange.run(editRow, updatedDataSource);
|
|
831
743
|
});
|
|
832
|
-
|
|
833
|
-
useEffect(
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
})) !== null && _editableKeys$map !== void 0 ? _editableKeys$map : []);
|
|
838
|
-
saveRefsMap.current.forEach(function (ref, key) {
|
|
839
|
-
if (!editableKeysSet.has(key === null || key === void 0 ? void 0 : key.toString())) {
|
|
744
|
+
const saveRefsMap = useRef(new Map());
|
|
745
|
+
useEffect(() => {
|
|
746
|
+
const editableKeysSet = new Set(editableKeys?.map(key => key?.toString()) ?? []);
|
|
747
|
+
saveRefsMap.current.forEach((ref, key) => {
|
|
748
|
+
if (!editableKeysSet.has(key?.toString())) {
|
|
840
749
|
saveRefsMap.current.delete(key);
|
|
841
750
|
}
|
|
842
751
|
});
|
|
@@ -845,64 +754,37 @@ export function useEditableArray(props) {
|
|
|
845
754
|
/**
|
|
846
755
|
* 获取保存引用
|
|
847
756
|
*/
|
|
848
|
-
|
|
849
|
-
|
|
757
|
+
const getSaveRef = useRefFunction(recordKey => {
|
|
758
|
+
const relayKey = recordKeyToString(recordKey);
|
|
850
759
|
return saveRefsMap.current.get(relayKey) || saveRefsMap.current.get(relayKey.toString());
|
|
851
760
|
});
|
|
852
761
|
|
|
853
762
|
/**
|
|
854
763
|
* 保存编辑行
|
|
855
764
|
*/
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
_context7.next = 7;
|
|
873
|
-
return saveEditable(mappedKey, false);
|
|
874
|
-
case 7:
|
|
875
|
-
return _context7.abrupt("return", _context7.sent);
|
|
876
|
-
case 8:
|
|
877
|
-
saveRef = getSaveRef(recordKey);
|
|
878
|
-
if (saveRef !== null && saveRef !== void 0 && saveRef.current) {
|
|
879
|
-
_context7.next = 11;
|
|
880
|
-
break;
|
|
881
|
-
}
|
|
882
|
-
return _context7.abrupt("return", false);
|
|
883
|
-
case 11:
|
|
884
|
-
_context7.next = 13;
|
|
885
|
-
return saveRef.current.save();
|
|
886
|
-
case 13:
|
|
887
|
-
clearEditableState(recordKey);
|
|
888
|
-
return _context7.abrupt("return", true);
|
|
889
|
-
case 15:
|
|
890
|
-
case "end":
|
|
891
|
-
return _context7.stop();
|
|
892
|
-
}
|
|
893
|
-
}, _callee7);
|
|
894
|
-
}));
|
|
895
|
-
return function (_x5, _x6) {
|
|
896
|
-
return _ref12.apply(this, arguments);
|
|
897
|
-
};
|
|
898
|
-
}());
|
|
765
|
+
const saveEditable = useRefFunction(async (recordKey, needReTry) => {
|
|
766
|
+
const relayKey = recordKeyToString(recordKey);
|
|
767
|
+
const relayKeyStr = relayKey.toString();
|
|
768
|
+
const mappedKey = dataSourceKeyIndexMapRef.current.get(relayKeyStr);
|
|
769
|
+
const isInEditableSet = editableKeys?.some(key => key?.toString() === relayKeyStr || key === relayKey);
|
|
770
|
+
if (!isInEditableSet && mappedKey && (needReTry ?? true) && props.tableName) {
|
|
771
|
+
return await saveEditable(mappedKey, false);
|
|
772
|
+
}
|
|
773
|
+
const saveRef = getSaveRef(recordKey);
|
|
774
|
+
if (!saveRef?.current) {
|
|
775
|
+
return false;
|
|
776
|
+
}
|
|
777
|
+
await saveRef.current.save();
|
|
778
|
+
clearEditableState(recordKey);
|
|
779
|
+
return true;
|
|
780
|
+
});
|
|
899
781
|
|
|
900
782
|
/**
|
|
901
783
|
* 验证是否可以新增记录
|
|
902
784
|
*/
|
|
903
|
-
|
|
904
|
-
if (options
|
|
905
|
-
console.warn("can't find record by key", options
|
|
785
|
+
const validateCanAddRecord = useRefFunction(options => {
|
|
786
|
+
if (options?.parentKey && !dataSourceKeyIndexMapRef.current.has(recordKeyToString(options?.parentKey).toString())) {
|
|
787
|
+
console.warn("can't find record by key", options?.parentKey);
|
|
906
788
|
return false;
|
|
907
789
|
}
|
|
908
790
|
if (newLineRecordRef.current && props.onlyAddOneLineAlertMessage !== false) {
|
|
@@ -918,7 +800,7 @@ export function useEditableArray(props) {
|
|
|
918
800
|
/**
|
|
919
801
|
* 验证记录 key 是否有效
|
|
920
802
|
*/
|
|
921
|
-
|
|
803
|
+
const validateRecordKey = useRefFunction(recordKey => {
|
|
922
804
|
if (recordKey == null && recordKey !== 0 && recordKey !== '') {
|
|
923
805
|
noteOnce(false, '请设置 recordCreatorProps.record 并返回一个唯一的key \n https://procomponents.ant.design/components/editable-table#editable-%E6%96%B0%E5%BB%BA%E8%A1%8C');
|
|
924
806
|
throw new Error('请设置 recordCreatorProps.record 并返回一个唯一的key');
|
|
@@ -928,183 +810,145 @@ export function useEditableArray(props) {
|
|
|
928
810
|
/**
|
|
929
811
|
* 增加新的行
|
|
930
812
|
*/
|
|
931
|
-
|
|
813
|
+
const addEditRecord = useRefFunction((row, options) => {
|
|
932
814
|
if (!validateCanAddRecord(options)) {
|
|
933
815
|
return false;
|
|
934
816
|
}
|
|
935
|
-
|
|
817
|
+
const recordKey = props.getRowKey(row, -1);
|
|
936
818
|
validateRecordKey(recordKey);
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
819
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
820
|
+
if (recordKeyStr) {
|
|
821
|
+
// 新建行:用 null 作为快照标记,避免多行编辑取消时误删其他行
|
|
822
|
+
preEditRowRefs.current.set(recordKeyStr, null);
|
|
823
|
+
}
|
|
824
|
+
const isAlreadyEditable = editableKeys?.some(key => key === recordKey || key?.toString() === recordKey?.toString());
|
|
940
825
|
if (!isAlreadyEditable) {
|
|
941
|
-
|
|
826
|
+
const newKeys = editableKeys ? [...editableKeys, recordKey] : [recordKey];
|
|
942
827
|
setEditableRowKeys(newKeys);
|
|
943
828
|
}
|
|
944
829
|
|
|
945
830
|
// 处理 parentKey:如果是函数,调用它
|
|
946
|
-
|
|
947
|
-
|
|
831
|
+
const parentKeyValue = typeof options?.parentKey === 'function' ? options.parentKey() : options?.parentKey;
|
|
832
|
+
const isDataSourceMode = options?.newRecordType === 'dataSource' || props.tableName && options?.newRecordType !== 'cache';
|
|
948
833
|
if (isDataSourceMode) {
|
|
949
|
-
|
|
950
|
-
var actionProps = {
|
|
834
|
+
const actionProps = {
|
|
951
835
|
data: props.dataSource,
|
|
952
836
|
getRowKey: props.getRowKey,
|
|
953
|
-
row:
|
|
954
|
-
|
|
955
|
-
|
|
837
|
+
row: {
|
|
838
|
+
...row,
|
|
839
|
+
map_row_parentKey: parentKeyValue ? recordKeyToString(parentKeyValue)?.toString() : undefined
|
|
840
|
+
},
|
|
956
841
|
key: recordKey,
|
|
957
842
|
childrenColumnName: props.childrenColumnName || 'children'
|
|
958
843
|
};
|
|
959
|
-
props.setDataSource(editableRowByKey(actionProps,
|
|
844
|
+
props.setDataSource(editableRowByKey(actionProps, options?.position === 'top' ? 'top' : 'update'));
|
|
960
845
|
} else {
|
|
961
846
|
setNewLineRecordCache({
|
|
962
847
|
defaultValue: row,
|
|
963
|
-
options:
|
|
848
|
+
options: {
|
|
849
|
+
...options,
|
|
964
850
|
parentKey: parentKeyValue,
|
|
965
|
-
recordKey
|
|
966
|
-
}
|
|
851
|
+
recordKey
|
|
852
|
+
}
|
|
967
853
|
});
|
|
968
854
|
}
|
|
969
855
|
return true;
|
|
970
856
|
});
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
}
|
|
857
|
+
const saveText = props?.saveText || intl.getMessage('editableTable.action.save', '保存');
|
|
858
|
+
const deleteText = props?.deleteText || intl.getMessage('editableTable.action.delete', '删除');
|
|
859
|
+
const cancelText = props?.cancelText || intl.getMessage('editableTable.action.cancel', '取消');
|
|
860
|
+
const actionSaveRef = useRefFunction(async (recordKey, editRow, originRow, newLine) => {
|
|
861
|
+
const res = await props?.onSave?.(recordKey, editRow, originRow, newLine);
|
|
862
|
+
|
|
863
|
+
// 如果 onSave 返回 false,阻止保存:不更新 dataSource,不触发 onChange
|
|
864
|
+
if (res === false) {
|
|
865
|
+
return res;
|
|
866
|
+
}
|
|
867
|
+
const {
|
|
868
|
+
options
|
|
869
|
+
} = newLine || newLineRecordRef.current || {};
|
|
870
|
+
const isNewLine = !options?.parentKey && options?.recordKey === recordKey;
|
|
871
|
+
if (isNewLine) {
|
|
872
|
+
if (options?.position === 'top') {
|
|
873
|
+
props.setDataSource([editRow, ...props.dataSource]);
|
|
874
|
+
} else {
|
|
875
|
+
props.setDataSource([...props.dataSource, editRow]);
|
|
876
|
+
}
|
|
877
|
+
} else {
|
|
878
|
+
const actionProps = {
|
|
879
|
+
data: props.dataSource,
|
|
880
|
+
getRowKey: props.getRowKey,
|
|
881
|
+
row: options ? {
|
|
882
|
+
...editRow,
|
|
883
|
+
map_row_parentKey: recordKeyToString(options?.parentKey ?? '')?.toString()
|
|
884
|
+
} : editRow,
|
|
885
|
+
key: recordKey,
|
|
886
|
+
childrenColumnName: props.childrenColumnName || 'children'
|
|
887
|
+
};
|
|
888
|
+
props.setDataSource(editableRowByKey(actionProps, options?.position === 'top' ? 'top' : 'update'));
|
|
889
|
+
}
|
|
1005
890
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
var actionDeleteRef = useRefFunction( /*#__PURE__*/function () {
|
|
1022
|
-
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(recordKey, editRow) {
|
|
1023
|
-
var _props$onDelete2;
|
|
1024
|
-
var actionProps, res;
|
|
1025
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1026
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
1027
|
-
case 0:
|
|
1028
|
-
actionProps = {
|
|
1029
|
-
data: props.dataSource,
|
|
1030
|
-
getRowKey: props.getRowKey,
|
|
1031
|
-
row: editRow,
|
|
1032
|
-
key: recordKey,
|
|
1033
|
-
childrenColumnName: props.childrenColumnName || 'children'
|
|
1034
|
-
};
|
|
1035
|
-
_context9.next = 3;
|
|
1036
|
-
return props === null || props === void 0 || (_props$onDelete2 = props.onDelete) === null || _props$onDelete2 === void 0 ? void 0 : _props$onDelete2.call(props, recordKey, editRow);
|
|
1037
|
-
case 3:
|
|
1038
|
-
res = _context9.sent;
|
|
1039
|
-
if (!(res === false)) {
|
|
1040
|
-
_context9.next = 6;
|
|
1041
|
-
break;
|
|
1042
|
-
}
|
|
1043
|
-
return _context9.abrupt("return", false);
|
|
1044
|
-
case 6:
|
|
1045
|
-
_context9.next = 8;
|
|
1046
|
-
return cancelEditable(recordKey, false);
|
|
1047
|
-
case 8:
|
|
1048
|
-
props.setDataSource(editableRowByKey(actionProps, 'delete'));
|
|
1049
|
-
return _context9.abrupt("return", res);
|
|
1050
|
-
case 10:
|
|
1051
|
-
case "end":
|
|
1052
|
-
return _context9.stop();
|
|
1053
|
-
}
|
|
1054
|
-
}, _callee9);
|
|
1055
|
-
}));
|
|
1056
|
-
return function (_x11, _x12) {
|
|
1057
|
-
return _ref15.apply(this, arguments);
|
|
1058
|
-
};
|
|
1059
|
-
}());
|
|
1060
|
-
var actionCancelRef = useRefFunction( /*#__PURE__*/function () {
|
|
1061
|
-
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(recordKey, editRow, originRow, newLine) {
|
|
1062
|
-
var _props$onCancel;
|
|
1063
|
-
var res;
|
|
1064
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1065
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
1066
|
-
case 0:
|
|
1067
|
-
_context10.next = 2;
|
|
1068
|
-
return props === null || props === void 0 || (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 ? void 0 : _props$onCancel.call(props, recordKey, editRow, originRow, newLine);
|
|
1069
|
-
case 2:
|
|
1070
|
-
res = _context10.sent;
|
|
1071
|
-
return _context10.abrupt("return", res);
|
|
1072
|
-
case 4:
|
|
1073
|
-
case "end":
|
|
1074
|
-
return _context10.stop();
|
|
1075
|
-
}
|
|
1076
|
-
}, _callee10);
|
|
1077
|
-
}));
|
|
1078
|
-
return function (_x13, _x14, _x15, _x16) {
|
|
1079
|
-
return _ref16.apply(this, arguments);
|
|
891
|
+
// 保存时解除编辑模式,统一在这里调用一次
|
|
892
|
+
await cancelEditable(recordKey);
|
|
893
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
894
|
+
if (recordKeyStr) {
|
|
895
|
+
preEditRowRefs.current.delete(recordKeyStr);
|
|
896
|
+
}
|
|
897
|
+
return res;
|
|
898
|
+
});
|
|
899
|
+
const actionDeleteRef = useRefFunction(async (recordKey, editRow) => {
|
|
900
|
+
const actionProps = {
|
|
901
|
+
data: props.dataSource,
|
|
902
|
+
getRowKey: props.getRowKey,
|
|
903
|
+
row: editRow,
|
|
904
|
+
key: recordKey,
|
|
905
|
+
childrenColumnName: props.childrenColumnName || 'children'
|
|
1080
906
|
};
|
|
1081
|
-
|
|
907
|
+
const res = await props?.onDelete?.(recordKey, editRow);
|
|
908
|
+
// 如果 onDelete 返回 false,阻止删除操作
|
|
909
|
+
if (res === false) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
// 不传递 false时,重新form.setFieldsValue同一份静态数据,会导致该行始终处于不可编辑状态
|
|
913
|
+
await cancelEditable(recordKey, false);
|
|
914
|
+
props.setDataSource(editableRowByKey(actionProps, 'delete'));
|
|
915
|
+
const recordKeyStr = recordKeyToString(recordKey)?.toString();
|
|
916
|
+
if (recordKeyStr) {
|
|
917
|
+
preEditRowRefs.current.delete(recordKeyStr);
|
|
918
|
+
}
|
|
919
|
+
return res;
|
|
920
|
+
});
|
|
921
|
+
const actionCancelRef = useRefFunction(async (recordKey, editRow, originRow, newLine) => {
|
|
922
|
+
const res = await props?.onCancel?.(recordKey, editRow, originRow, newLine);
|
|
923
|
+
return res;
|
|
924
|
+
});
|
|
1082
925
|
|
|
1083
926
|
// 如果传入了自定义的actionRender,使用useRefFunction以确保内部的事件处理函数可以访问最新的state
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
saveText
|
|
1091
|
-
cancelText
|
|
1092
|
-
deleteText
|
|
1093
|
-
addEditRecord
|
|
927
|
+
const existCustomActionRender = props.actionRender && typeof props.actionRender === 'function';
|
|
928
|
+
const customActionRender = existCustomActionRender ? props.actionRender : () => {};
|
|
929
|
+
const customActionRenderRef = useRefFunction(customActionRender);
|
|
930
|
+
const actionRender = row => {
|
|
931
|
+
const key = props.getRowKey(row, row.index);
|
|
932
|
+
const config = {
|
|
933
|
+
saveText,
|
|
934
|
+
cancelText,
|
|
935
|
+
deleteText,
|
|
936
|
+
addEditRecord,
|
|
1094
937
|
recordKey: key,
|
|
1095
|
-
cancelEditable
|
|
938
|
+
cancelEditable,
|
|
1096
939
|
index: row.index,
|
|
1097
940
|
tableName: props.tableName,
|
|
1098
941
|
newLineConfig: newLineRecordCache,
|
|
1099
942
|
onCancel: actionCancelRef,
|
|
1100
943
|
onDelete: actionDeleteRef,
|
|
1101
944
|
onSave: actionSaveRef,
|
|
1102
|
-
editableKeys
|
|
1103
|
-
setEditableRowKeys
|
|
1104
|
-
preEditRowRef
|
|
1105
|
-
|
|
945
|
+
editableKeys,
|
|
946
|
+
setEditableRowKeys,
|
|
947
|
+
preEditRowRef,
|
|
948
|
+
preEditRowRefs,
|
|
949
|
+
deletePopconfirmMessage: props.deletePopconfirmMessage || `${intl.getMessage('deleteThisLine', '删除此项')}?`
|
|
1106
950
|
};
|
|
1107
|
-
|
|
951
|
+
const renderResult = defaultActionRender(row, config);
|
|
1108
952
|
// 缓存一下saveRef
|
|
1109
953
|
if (props.tableName) {
|
|
1110
954
|
saveRefsMap.current.set(dataSourceKeyIndexMapRef.current.get(recordKeyToString(key)) || recordKeyToString(key), renderResult.saveRef);
|
|
@@ -1119,17 +963,17 @@ export function useEditableArray(props) {
|
|
|
1119
963
|
return [renderResult.save, renderResult.delete, renderResult.cancel];
|
|
1120
964
|
};
|
|
1121
965
|
return {
|
|
1122
|
-
editableKeys
|
|
1123
|
-
setEditableRowKeys
|
|
1124
|
-
isEditable
|
|
1125
|
-
actionRender
|
|
1126
|
-
startEditable
|
|
1127
|
-
cancelEditable
|
|
1128
|
-
addEditRecord
|
|
1129
|
-
saveEditable
|
|
966
|
+
editableKeys,
|
|
967
|
+
setEditableRowKeys,
|
|
968
|
+
isEditable,
|
|
969
|
+
actionRender,
|
|
970
|
+
startEditable,
|
|
971
|
+
cancelEditable,
|
|
972
|
+
addEditRecord,
|
|
973
|
+
saveEditable,
|
|
1130
974
|
newLineRecord: newLineRecordCache,
|
|
1131
975
|
preEditableKeys: editableKeysRef,
|
|
1132
|
-
onValuesChange
|
|
976
|
+
onValuesChange,
|
|
1133
977
|
getRealIndex: props.getRealIndex
|
|
1134
978
|
};
|
|
1135
979
|
}
|