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