@hi-ui/schema-editable-table 4.0.0-experimental.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.md +11 -0
- package/lib/cjs/body/index.js +110 -0
- package/lib/cjs/body/wrapper.js +132 -0
- package/lib/cjs/cell/aggregated.js +76 -0
- package/lib/cjs/cell/dependency.js +97 -0
- package/lib/cjs/cell/editing.js +89 -0
- package/lib/cjs/cell/footer.js +64 -0
- package/lib/cjs/cell/header.js +76 -0
- package/lib/cjs/cell/index.js +204 -0
- package/lib/cjs/const.js +35 -0
- package/lib/cjs/container/base.js +39 -0
- package/lib/cjs/container/bottom.js +86 -0
- package/lib/cjs/container/col-group.js +98 -0
- package/lib/cjs/container/column-virtual.js +53 -0
- package/lib/cjs/container/ctx.js +32 -0
- package/lib/cjs/container/full-virtual.js +61 -0
- package/lib/cjs/container/hooks.js +102 -0
- package/lib/cjs/container/index.js +69 -0
- package/lib/cjs/container/row-virtual.js +50 -0
- package/lib/cjs/container/wrapper.js +97 -0
- package/lib/cjs/ctx.js +32 -0
- package/lib/cjs/features/_overrides/aggregated.js +44 -0
- package/lib/cjs/features/_overrides/getter.js +61 -0
- package/lib/cjs/features/_overrides/grouping.js +40 -0
- package/lib/cjs/features/_overrides/overrides.js +43 -0
- package/lib/cjs/features/_overrides/row-selection.js +140 -0
- package/lib/cjs/features/async-data/getter.js +150 -0
- package/lib/cjs/features/async-data/normal.js +145 -0
- package/lib/cjs/features/async-data/use-data-fetcher.js +40 -0
- package/lib/cjs/features/async-data/use-reset-data.js +91 -0
- package/lib/cjs/features/column-grouping/get-grouping-config.js +27 -0
- package/lib/cjs/features/column-grouping/use-opts.js +42 -0
- package/lib/cjs/features/column-state.js +57 -0
- package/lib/cjs/features/filter/bridge.js +114 -0
- package/lib/cjs/features/filter/filter-fns/date.js +34 -0
- package/lib/cjs/features/filter/filter-fns/index.js +23 -0
- package/lib/cjs/features/filter/get-filter-config.js +61 -0
- package/lib/cjs/features/filter/index.js +29 -0
- package/lib/cjs/features/filter/use-opts.js +88 -0
- package/lib/cjs/features/header-actions/components/column-collapsing.js +74 -0
- package/lib/cjs/features/header-actions/get-actions.js +77 -0
- package/lib/cjs/features/pagination/component.js +89 -0
- package/lib/cjs/features/pagination/use-opts.js +98 -0
- package/lib/cjs/features/pagination/use-state.js +44 -0
- package/lib/cjs/features/row-controller.js +265 -0
- package/lib/cjs/features/row-edit/actions.js +65 -0
- package/lib/cjs/features/row-edit/hooks.js +29 -0
- package/lib/cjs/features/row-expanding/use-opts.js +39 -0
- package/lib/cjs/features/row-expanding/wrapper.js +74 -0
- package/lib/cjs/features/row-operation/buttons.js +91 -0
- package/lib/cjs/features/row-operation/cell.js +43 -0
- package/lib/cjs/features/row-operation/index.js +21 -0
- package/lib/cjs/features/row-operation/wrapper.js +114 -0
- package/lib/cjs/features/row-selection/cell.js +114 -0
- package/lib/cjs/features/row-selection/const.js +16 -0
- package/lib/cjs/features/row-selection/hooks/index.js +29 -0
- package/lib/cjs/features/row-selection/hooks/use-click-select.js +70 -0
- package/lib/cjs/features/row-selection/hooks/use-opts.js +120 -0
- package/lib/cjs/features/row-selection/hooks/use-set-selected-row-keys.js +48 -0
- package/lib/cjs/features/row-selection/hooks/use-sync-hover-style.js +86 -0
- package/lib/cjs/features/row-selection/indicator.js +173 -0
- package/lib/cjs/features/row-selection/wrapper.js +119 -0
- package/lib/cjs/features/setting-bridge.js +56 -0
- package/lib/cjs/features/sorter/bridge.js +65 -0
- package/lib/cjs/features/sorter/get-sorter-config.js +46 -0
- package/lib/cjs/features/sorter/index.js +29 -0
- package/lib/cjs/features/sorter/use-opts.js +81 -0
- package/lib/cjs/field-bridge/bridge.js +104 -0
- package/lib/cjs/field-bridge/index.js +58 -0
- package/lib/cjs/field-bridge/toolbar.js +53 -0
- package/lib/cjs/footer/index.js +99 -0
- package/lib/cjs/footer/use-first-cell-patch.js +42 -0
- package/lib/cjs/header/index.js +134 -0
- package/lib/cjs/header/validate.js +69 -0
- package/lib/cjs/hooks/use-get-fields-value.js +62 -0
- package/lib/cjs/hooks/use-global-actions.js +65 -0
- package/lib/cjs/hooks/use-global-static.js +158 -0
- package/lib/cjs/hooks/use-initial-render.js +30 -0
- package/lib/cjs/hooks/use-inner-ctx.js +105 -0
- package/lib/cjs/hooks/use-props.js +108 -0
- package/lib/cjs/hooks/use-table-columns.js +76 -0
- package/lib/cjs/hooks/use-table-meta.js +57 -0
- package/lib/cjs/hooks/use-update.js +57 -0
- package/lib/cjs/index.js +66 -0
- package/lib/cjs/index.scss.js +18 -0
- package/lib/cjs/table.js +263 -0
- package/lib/cjs/utils/cls.js +19 -0
- package/lib/cjs/utils/fixed.js +53 -0
- package/lib/cjs/utils/grouping.js +42 -0
- package/lib/cjs/utils/state-merge.js +43 -0
- package/lib/esm/body/index.js +98 -0
- package/lib/esm/body/wrapper.js +120 -0
- package/lib/esm/cell/aggregated.js +64 -0
- package/lib/esm/cell/dependency.js +90 -0
- package/lib/esm/cell/editing.js +76 -0
- package/lib/esm/cell/footer.js +52 -0
- package/lib/esm/cell/header.js +63 -0
- package/lib/esm/cell/index.js +192 -0
- package/lib/esm/const.js +24 -0
- package/lib/esm/container/base.js +27 -0
- package/lib/esm/container/bottom.js +74 -0
- package/lib/esm/container/col-group.js +85 -0
- package/lib/esm/container/column-virtual.js +41 -0
- package/lib/esm/container/ctx.js +19 -0
- package/lib/esm/container/full-virtual.js +49 -0
- package/lib/esm/container/hooks.js +95 -0
- package/lib/esm/container/index.js +57 -0
- package/lib/esm/container/row-virtual.js +38 -0
- package/lib/esm/container/wrapper.js +83 -0
- package/lib/esm/ctx.js +17 -0
- package/lib/esm/features/_overrides/aggregated.js +39 -0
- package/lib/esm/features/_overrides/getter.js +56 -0
- package/lib/esm/features/_overrides/grouping.js +35 -0
- package/lib/esm/features/_overrides/overrides.js +38 -0
- package/lib/esm/features/_overrides/row-selection.js +135 -0
- package/lib/esm/features/async-data/getter.js +143 -0
- package/lib/esm/features/async-data/normal.js +133 -0
- package/lib/esm/features/async-data/use-data-fetcher.js +34 -0
- package/lib/esm/features/async-data/use-reset-data.js +79 -0
- package/lib/esm/features/column-grouping/get-grouping-config.js +22 -0
- package/lib/esm/features/column-grouping/use-opts.js +36 -0
- package/lib/esm/features/column-state.js +51 -0
- package/lib/esm/features/filter/bridge.js +102 -0
- package/lib/esm/features/filter/filter-fns/date.js +28 -0
- package/lib/esm/features/filter/filter-fns/index.js +18 -0
- package/lib/esm/features/filter/get-filter-config.js +56 -0
- package/lib/esm/features/filter/index.js +24 -0
- package/lib/esm/features/filter/use-opts.js +82 -0
- package/lib/esm/features/header-actions/components/column-collapsing.js +62 -0
- package/lib/esm/features/header-actions/get-actions.js +65 -0
- package/lib/esm/features/pagination/component.js +77 -0
- package/lib/esm/features/pagination/use-opts.js +91 -0
- package/lib/esm/features/pagination/use-state.js +39 -0
- package/lib/esm/features/row-controller.js +253 -0
- package/lib/esm/features/row-edit/actions.js +53 -0
- package/lib/esm/features/row-edit/hooks.js +24 -0
- package/lib/esm/features/row-expanding/use-opts.js +33 -0
- package/lib/esm/features/row-expanding/wrapper.js +62 -0
- package/lib/esm/features/row-operation/buttons.js +79 -0
- package/lib/esm/features/row-operation/cell.js +31 -0
- package/lib/esm/features/row-operation/index.js +16 -0
- package/lib/esm/features/row-operation/wrapper.js +100 -0
- package/lib/esm/features/row-selection/cell.js +101 -0
- package/lib/esm/features/row-selection/const.js +11 -0
- package/lib/esm/features/row-selection/hooks/index.js +24 -0
- package/lib/esm/features/row-selection/hooks/use-click-select.js +65 -0
- package/lib/esm/features/row-selection/hooks/use-opts.js +114 -0
- package/lib/esm/features/row-selection/hooks/use-set-selected-row-keys.js +43 -0
- package/lib/esm/features/row-selection/hooks/use-sync-hover-style.js +81 -0
- package/lib/esm/features/row-selection/indicator.js +159 -0
- package/lib/esm/features/row-selection/wrapper.js +107 -0
- package/lib/esm/features/setting-bridge.js +50 -0
- package/lib/esm/features/sorter/bridge.js +53 -0
- package/lib/esm/features/sorter/get-sorter-config.js +41 -0
- package/lib/esm/features/sorter/index.js +24 -0
- package/lib/esm/features/sorter/use-opts.js +75 -0
- package/lib/esm/field-bridge/bridge.js +92 -0
- package/lib/esm/field-bridge/index.js +44 -0
- package/lib/esm/field-bridge/toolbar.js +41 -0
- package/lib/esm/footer/index.js +87 -0
- package/lib/esm/footer/use-first-cell-patch.js +37 -0
- package/lib/esm/header/index.js +121 -0
- package/lib/esm/header/validate.js +64 -0
- package/lib/esm/hooks/use-get-fields-value.js +56 -0
- package/lib/esm/hooks/use-global-actions.js +60 -0
- package/lib/esm/hooks/use-global-static.js +152 -0
- package/lib/esm/hooks/use-initial-render.js +18 -0
- package/lib/esm/hooks/use-inner-ctx.js +100 -0
- package/lib/esm/hooks/use-props.js +102 -0
- package/lib/esm/hooks/use-table-columns.js +70 -0
- package/lib/esm/hooks/use-table-meta.js +51 -0
- package/lib/esm/hooks/use-update.js +52 -0
- package/lib/esm/index.js +38 -0
- package/lib/esm/index.scss.js +13 -0
- package/lib/esm/table.js +251 -0
- package/lib/esm/utils/cls.js +13 -0
- package/lib/esm/utils/fixed.js +48 -0
- package/lib/esm/utils/grouping.js +36 -0
- package/lib/esm/utils/state-merge.js +37 -0
- package/lib/types/body/index.d.ts +14 -0
- package/lib/types/body/wrapper.d.ts +18 -0
- package/lib/types/cell/aggregated.d.ts +35 -0
- package/lib/types/cell/custom.d.ts +19 -0
- package/lib/types/cell/dependency.d.ts +47 -0
- package/lib/types/cell/editing.d.ts +8 -0
- package/lib/types/cell/footer.d.ts +5 -0
- package/lib/types/cell/header.d.ts +5 -0
- package/lib/types/cell/index.d.ts +6 -0
- package/lib/types/const.d.ts +11 -0
- package/lib/types/container/base.d.ts +2 -0
- package/lib/types/container/bottom.d.ts +20 -0
- package/lib/types/container/col-group.d.ts +11 -0
- package/lib/types/container/column-virtual.d.ts +7 -0
- package/lib/types/container/ctx.d.ts +23 -0
- package/lib/types/container/full-virtual.d.ts +8 -0
- package/lib/types/container/hooks.d.ts +13 -0
- package/lib/types/container/index.d.ts +17 -0
- package/lib/types/container/row-virtual.d.ts +7 -0
- package/lib/types/container/type.d.ts +17 -0
- package/lib/types/container/wrapper.d.ts +12 -0
- package/lib/types/ctx.d.ts +41 -0
- package/lib/types/features/_overrides/aggregated.d.ts +2 -0
- package/lib/types/features/_overrides/getter.d.ts +2 -0
- package/lib/types/features/_overrides/grouping.d.ts +7 -0
- package/lib/types/features/_overrides/index.d.ts +5 -0
- package/lib/types/features/_overrides/overrides.d.ts +2 -0
- package/lib/types/features/_overrides/row-selection.d.ts +2 -0
- package/lib/types/features/async-data/getter.d.ts +9 -0
- package/lib/types/features/async-data/group.d.ts +1 -0
- package/lib/types/features/async-data/index.d.ts +6 -0
- package/lib/types/features/async-data/normal.d.ts +48 -0
- package/lib/types/features/async-data/type.d.ts +22 -0
- package/lib/types/features/async-data/use-data-fetcher.d.ts +22 -0
- package/lib/types/features/async-data/use-reset-data.d.ts +14 -0
- package/lib/types/features/column-grouping/get-grouping-config.d.ts +2 -0
- package/lib/types/features/column-grouping/index.d.ts +3 -0
- package/lib/types/features/column-grouping/use-opts.d.ts +12 -0
- package/lib/types/features/column-state.d.ts +15 -0
- package/lib/types/features/filter/bridge.d.ts +9 -0
- package/lib/types/features/filter/filter-fns/date.d.ts +6 -0
- package/lib/types/features/filter/filter-fns/index.d.ts +6 -0
- package/lib/types/features/filter/get-filter-config.d.ts +4 -0
- package/lib/types/features/filter/index.d.ts +8 -0
- package/lib/types/features/filter/use-opts.d.ts +62 -0
- package/lib/types/features/header-actions/components/column-collapsing.d.ts +4 -0
- package/lib/types/features/header-actions/get-actions.d.ts +13 -0
- package/lib/types/features/header-actions/index.d.ts +3 -0
- package/lib/types/features/header-actions/type.d.ts +20 -0
- package/lib/types/features/pagination/component.d.ts +15 -0
- package/lib/types/features/pagination/index.d.ts +4 -0
- package/lib/types/features/pagination/use-opts.d.ts +14 -0
- package/lib/types/features/pagination/use-state.d.ts +11 -0
- package/lib/types/features/row-controller.d.ts +101 -0
- package/lib/types/features/row-edit/actions.d.ts +12 -0
- package/lib/types/features/row-edit/hooks.d.ts +1 -0
- package/lib/types/features/row-edit/index.d.ts +2 -0
- package/lib/types/features/row-expanding/index.d.ts +3 -0
- package/lib/types/features/row-expanding/use-opts.d.ts +12 -0
- package/lib/types/features/row-expanding/wrapper.d.ts +11 -0
- package/lib/types/features/row-operation/buttons.d.ts +41 -0
- package/lib/types/features/row-operation/cell.d.ts +6 -0
- package/lib/types/features/row-operation/index.d.ts +18 -0
- package/lib/types/features/row-operation/wrapper.d.ts +3 -0
- package/lib/types/features/row-selection/cell.d.ts +62 -0
- package/lib/types/features/row-selection/const.d.ts +1 -0
- package/lib/types/features/row-selection/hooks/index.d.ts +6 -0
- package/lib/types/features/row-selection/hooks/use-click-select.d.ts +1 -0
- package/lib/types/features/row-selection/hooks/use-opts.d.ts +15 -0
- package/lib/types/features/row-selection/hooks/use-set-selected-row-keys.d.ts +9 -0
- package/lib/types/features/row-selection/hooks/use-sync-hover-style.d.ts +5 -0
- package/lib/types/features/row-selection/index.d.ts +7 -0
- package/lib/types/features/row-selection/indicator.d.ts +8 -0
- package/lib/types/features/row-selection/wrapper.d.ts +9 -0
- package/lib/types/features/setting-bridge.d.ts +14 -0
- package/lib/types/features/sorter/bridge.d.ts +8 -0
- package/lib/types/features/sorter/get-sorter-config.d.ts +7 -0
- package/lib/types/features/sorter/index.d.ts +8 -0
- package/lib/types/features/sorter/use-opts.d.ts +71 -0
- package/lib/types/field-bridge/bridge.d.ts +18 -0
- package/lib/types/field-bridge/index.d.ts +11 -0
- package/lib/types/field-bridge/toolbar.d.ts +9 -0
- package/lib/types/footer/index.d.ts +6 -0
- package/lib/types/footer/use-first-cell-patch.d.ts +1 -0
- package/lib/types/header/index.d.ts +17 -0
- package/lib/types/header/validate.d.ts +10 -0
- package/lib/types/hooks/use-get-fields-value.d.ts +14 -0
- package/lib/types/hooks/use-global-actions.d.ts +24 -0
- package/lib/types/hooks/use-global-static.d.ts +83 -0
- package/lib/types/hooks/use-initial-render.d.ts +1 -0
- package/lib/types/hooks/use-inner-ctx.d.ts +12 -0
- package/lib/types/hooks/use-props.d.ts +109 -0
- package/lib/types/hooks/use-table-columns.d.ts +11 -0
- package/lib/types/hooks/use-table-meta.d.ts +15 -0
- package/lib/types/hooks/use-update.d.ts +11 -0
- package/lib/types/index.d.ts +32 -0
- package/lib/types/table.d.ts +152 -0
- package/lib/types/utils/cls.d.ts +4 -0
- package/lib/types/utils/fixed.d.ts +11 -0
- package/lib/types/utils/grouping.d.ts +6 -0
- package/lib/types/utils/index.d.ts +5 -0
- package/lib/types/utils/meta.d.ts +8 -0
- package/lib/types/utils/state-merge.d.ts +14 -0
- package/package.json +90 -0
- package/type.d.ts +143 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { useMemo } from 'react';
|
|
11
|
+
import { isEqual } from 'lodash-es';
|
|
12
|
+
import { getPaginationRowModel } from '@tanstack/react-table';
|
|
13
|
+
import { resetRowSelectionAfterPaginationChange } from '../row-selection/hooks/use-opts.js';
|
|
14
|
+
function usePaginationOpts(ctx) {
|
|
15
|
+
var innerRef = ctx.innerRef,
|
|
16
|
+
staticOptsRef = ctx.staticOptsRef;
|
|
17
|
+
return useMemo(function () {
|
|
18
|
+
return getPaginationOptions({
|
|
19
|
+
innerRef: innerRef,
|
|
20
|
+
staticOptsRef: staticOptsRef
|
|
21
|
+
});
|
|
22
|
+
}, [innerRef, staticOptsRef]);
|
|
23
|
+
}
|
|
24
|
+
var dftPageSize = 10;
|
|
25
|
+
/**
|
|
26
|
+
* 获取表格分页配置选项
|
|
27
|
+
*/
|
|
28
|
+
function getPaginationOptions(ctx) {
|
|
29
|
+
var _ctx$staticOptsRef$cu = ctx.staticOptsRef.current,
|
|
30
|
+
enablePagination = _ctx$staticOptsRef$cu.enablePagination,
|
|
31
|
+
enableAsyncData = _ctx$staticOptsRef$cu.enableAsyncData,
|
|
32
|
+
enableRowGrouping = _ctx$staticOptsRef$cu.enableRowGrouping;
|
|
33
|
+
// 如果没有启用分页功能
|
|
34
|
+
if (!enablePagination) {
|
|
35
|
+
// 但启用了分组功能,则需要提供分页行模型以确保分组数据正确显示
|
|
36
|
+
// 这是因为TanStack Table的行模型执行顺序中,分页模型在分组模型之后
|
|
37
|
+
// 没有分页模型可能导致分组数据无法正确渲染
|
|
38
|
+
if (enableRowGrouping) {
|
|
39
|
+
return {
|
|
40
|
+
manualPagination: false,
|
|
41
|
+
// 提供分页行模型,但不显示分页控件(由外部控制)
|
|
42
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
43
|
+
autoResetPageIndex: false,
|
|
44
|
+
initialState: {
|
|
45
|
+
pagination: {
|
|
46
|
+
pageSize: Number.MAX_SAFE_INTEGER
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// 既没有分页也没有分组,返回空配置
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
var onPaginationChange = function onPaginationChange(updater) {
|
|
55
|
+
var innerRef = ctx.innerRef;
|
|
56
|
+
var table = innerRef.current.table;
|
|
57
|
+
var state = table.getState().pagination;
|
|
58
|
+
var newState = typeof updater === 'function' ? updater(state) : updater;
|
|
59
|
+
// 如果分页状态没有变化,则不更新
|
|
60
|
+
if (isEqual(state, newState)) return;
|
|
61
|
+
// NOTE 此处修改为先更新订阅,再更新内部状态
|
|
62
|
+
// 原因是识别到,部分显式设置当前页的操作时,若先更新内部状态,可能会导致无法正确识别到页码的变化
|
|
63
|
+
// 先更新订阅
|
|
64
|
+
innerRef.current.paginationState.setValue(newState);
|
|
65
|
+
// 再更新内部状态
|
|
66
|
+
table.setState(function (state) {
|
|
67
|
+
return Object.assign(Object.assign({}, state), {
|
|
68
|
+
pagination: newState
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
// 如果开启了后端分页,并且没有配置 preserveSelectedRows,则需要清空选中状态
|
|
72
|
+
resetRowSelectionAfterPaginationChange({
|
|
73
|
+
innerRef: innerRef,
|
|
74
|
+
state: state,
|
|
75
|
+
newState: newState
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
if (enableAsyncData) {
|
|
79
|
+
return {
|
|
80
|
+
manualPagination: true,
|
|
81
|
+
onPaginationChange: onPaginationChange
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
manualPagination: false,
|
|
86
|
+
// 前端分页,才使用getPaginationRowModel
|
|
87
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
88
|
+
onPaginationChange: onPaginationChange
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export { dftPageSize, getPaginationOptions, usePaginationOpts };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { useSubscription } from '@hi-ui/use-subscription';
|
|
11
|
+
import { dftPageSize } from './use-opts.js';
|
|
12
|
+
function getInitialState(ctx) {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
var propsRef = ctx.propsRef,
|
|
15
|
+
subscription = ctx.subscription;
|
|
16
|
+
// dftPageSize 仅用于类型收窄
|
|
17
|
+
// 实际上已经在 normalizeProps 中处理了
|
|
18
|
+
var pageSize = (_b = (_a = propsRef.current.pagination) === null || _a === void 0 ? void 0 : _a.pageSize) !== null && _b !== void 0 ? _b : dftPageSize;
|
|
19
|
+
// 根据主数据订阅的长度设置 rowCount 的值
|
|
20
|
+
// 前端分页时,直接就是主数据的长度
|
|
21
|
+
// 后端分页时,rowCount 初始为0,后续会在 useAsyncData 中更新
|
|
22
|
+
var rowCount = subscription.getValue().length;
|
|
23
|
+
// 初始化分页状态,最小值为0
|
|
24
|
+
var pageIndex = ((_c = propsRef.current.pagination) === null || _c === void 0 ? void 0 : _c.defaultCurrent) ? Math.max(propsRef.current.pagination.defaultCurrent - 1, 0) : 0;
|
|
25
|
+
return {
|
|
26
|
+
pageIndex: pageIndex,
|
|
27
|
+
pageSize: pageSize,
|
|
28
|
+
rowCount: rowCount
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function usePaginationState(ctx) {
|
|
32
|
+
var paginationState = useSubscription(function () {
|
|
33
|
+
return getInitialState(ctx);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
paginationState: paginationState
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export { usePaginationState };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
11
|
+
import { produce } from 'immer';
|
|
12
|
+
import { uuid } from '@hi-ui/use-id';
|
|
13
|
+
import { cloneDeep, set } from 'lodash-es';
|
|
14
|
+
import { Subscription } from '@hi-ui/use-subscription';
|
|
15
|
+
var TableRowController = /*#__PURE__*/function () {
|
|
16
|
+
var _proto = TableRowController.prototype;
|
|
17
|
+
_proto.afterRowsOperation = function afterRowsOperation() {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = this.onValuesChange) === null || _a === void 0 ? void 0 : _a.call(this, {}, this.subscription.getValue());
|
|
20
|
+
};
|
|
21
|
+
function TableRowController(subscription, opts) {
|
|
22
|
+
var _a;
|
|
23
|
+
/** 当前正在编辑的行索引订阅 */
|
|
24
|
+
this.editingSubscription = null;
|
|
25
|
+
/** 当前正在编辑的行索引 */
|
|
26
|
+
this.editingIndex = null;
|
|
27
|
+
this.subscription = subscription;
|
|
28
|
+
// 行编辑模式下,需要知道 propsRef 以便在保存时调用 propsRef.current.onValuesChange
|
|
29
|
+
this.propsRef = opts === null || opts === void 0 ? void 0 : opts.propsRef;
|
|
30
|
+
this.onValuesChange = (_a = opts === null || opts === void 0 ? void 0 : opts.propsRef) === null || _a === void 0 ? void 0 : _a.current.onValuesChange;
|
|
31
|
+
// 如果开启了行编辑,则创建一个当前正在编辑的行索引订阅
|
|
32
|
+
if (opts === null || opts === void 0 ? void 0 : opts.rowEdit) this.editingSubscription = new Subscription({});
|
|
33
|
+
}
|
|
34
|
+
/** 检查是否处于编辑状态 */
|
|
35
|
+
_proto.checkEditing = function checkEditing() {
|
|
36
|
+
if (this.isEditing) {
|
|
37
|
+
// TODO: add logging if needed
|
|
38
|
+
// console.log('Operation blocked: table is in editing mode')
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 在指定位置添加新行
|
|
45
|
+
* @param data 行数据
|
|
46
|
+
* @param index 插入位置索引,可选,默认添加到末尾。如果为负数则插入到开头,如果超出长度则插入到末尾
|
|
47
|
+
*/;
|
|
48
|
+
_proto.addRow = function addRow(data, index) {
|
|
49
|
+
if (this.checkEditing()) return;
|
|
50
|
+
this.subscription.setValue(produce(function (draft) {
|
|
51
|
+
if (typeof index === 'number') {
|
|
52
|
+
var normalizedIndex = Math.floor(Math.max(0, Math.min(draft.length, index)));
|
|
53
|
+
draft.splice(normalizedIndex, 0, data);
|
|
54
|
+
} else {
|
|
55
|
+
draft.push(data);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
this.afterRowsOperation();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 删除指定行
|
|
62
|
+
* @param index 要删除的行索引
|
|
63
|
+
*/;
|
|
64
|
+
_proto.deleteRow = function deleteRow(index) {
|
|
65
|
+
if (this.checkEditing()) return;
|
|
66
|
+
this.subscription.setValue(produce(function (draft) {
|
|
67
|
+
if (index >= 0 && index < draft.length) {
|
|
68
|
+
draft.splice(index, 1);
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
this.afterRowsOperation();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 批量添加多行
|
|
75
|
+
* @param rows 要添加的行数据数组
|
|
76
|
+
* @param index 插入位置索引,可选,默认添加到末尾。如果为负数则插入到开头,如果超出长度则插入到末尾
|
|
77
|
+
*/;
|
|
78
|
+
_proto.addRows = function addRows(rows, index) {
|
|
79
|
+
if (this.checkEditing()) return;
|
|
80
|
+
this.subscription.setValue(produce(function (draft) {
|
|
81
|
+
if (typeof index === 'number') {
|
|
82
|
+
var normalizedIndex = Math.floor(Math.max(0, Math.min(draft.length, index)));
|
|
83
|
+
draft.splice.apply(draft, [normalizedIndex, 0].concat(rows));
|
|
84
|
+
} else {
|
|
85
|
+
draft.push.apply(draft, rows);
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
this.afterRowsOperation();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 批量删除多行
|
|
92
|
+
* @param indexes 要删除的行索引数组,会自动按从大到小排序处理
|
|
93
|
+
*/;
|
|
94
|
+
_proto.deleteRows = function deleteRows(indexes) {
|
|
95
|
+
if (this.checkEditing()) return;
|
|
96
|
+
this.subscription.setValue(produce(function (draft) {
|
|
97
|
+
// 从大到小排序,避免删除时索引变化
|
|
98
|
+
indexes.sort(function (a, b) {
|
|
99
|
+
return b - a;
|
|
100
|
+
}).forEach(function (idx) {
|
|
101
|
+
if (idx >= 0 && idx < draft.length) {
|
|
102
|
+
draft.splice(idx, 1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}));
|
|
106
|
+
this.afterRowsOperation();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 复制指定行
|
|
110
|
+
* @param sourceIndex 要复制的行索引
|
|
111
|
+
* @param options 复制选项
|
|
112
|
+
* @param options.targetIndex 目标位置索引,可选,默认复制到原位置的下一行
|
|
113
|
+
* @param options.rowKey 行数据中用于标识唯一性的字段名,默认为 'id'
|
|
114
|
+
*/;
|
|
115
|
+
_proto.copyRow = function copyRow(sourceIndex, options) {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
if (this.checkEditing()) return;
|
|
118
|
+
var sourceRow = this.getRow(sourceIndex);
|
|
119
|
+
if (!sourceRow) return;
|
|
120
|
+
// 使用 lodash 的 cloneDeep 进行深拷贝,避免引用问题
|
|
121
|
+
var copiedRow = cloneDeep(sourceRow);
|
|
122
|
+
// 生成新的唯一 ID
|
|
123
|
+
var rowKey = (_a = options === null || options === void 0 ? void 0 : options.rowKey) !== null && _a !== void 0 ? _a : 'id';
|
|
124
|
+
var newId = 'copiedRow_' + uuid();
|
|
125
|
+
set(copiedRow, rowKey, newId);
|
|
126
|
+
// 如果没有指定目标位置,默认复制到原位置的下一行
|
|
127
|
+
var insertIndex = (_b = options === null || options === void 0 ? void 0 : options.targetIndex) !== null && _b !== void 0 ? _b : sourceIndex + 1;
|
|
128
|
+
// 复用 addRow 方法,保持 targetIndex 逻辑一致
|
|
129
|
+
this.addRow(copiedRow, insertIndex);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 交换两行位置
|
|
133
|
+
* @param sourceIndex 源行索引
|
|
134
|
+
* @param targetIndex 目标行索引
|
|
135
|
+
*/;
|
|
136
|
+
_proto.swapRow = function swapRow(sourceIndex, targetIndex) {
|
|
137
|
+
if (this.checkEditing()) return;
|
|
138
|
+
var hasOperated = false;
|
|
139
|
+
this.subscription.setValue(produce(function (draft) {
|
|
140
|
+
if (sourceIndex >= 0 && sourceIndex < draft.length && targetIndex >= 0 && targetIndex < draft.length && sourceIndex !== targetIndex) {
|
|
141
|
+
var temp = draft[sourceIndex];
|
|
142
|
+
draft[sourceIndex] = draft[targetIndex];
|
|
143
|
+
draft[targetIndex] = temp;
|
|
144
|
+
hasOperated = true;
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
147
|
+
if (hasOperated) this.afterRowsOperation();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 移动行到指定位置
|
|
151
|
+
* @param sourceIndex 要移动的行索引
|
|
152
|
+
* @param targetIndex 目标位置索引
|
|
153
|
+
*/;
|
|
154
|
+
_proto.moveRow = function moveRow(sourceIndex, targetIndex) {
|
|
155
|
+
if (this.checkEditing()) return;
|
|
156
|
+
var hasOperated = false;
|
|
157
|
+
this.subscription.setValue(produce(function (draft) {
|
|
158
|
+
if (sourceIndex >= 0 && sourceIndex < draft.length && targetIndex >= 0 && targetIndex < draft.length && sourceIndex !== targetIndex) {
|
|
159
|
+
var _draft$splice = draft.splice(sourceIndex, 1),
|
|
160
|
+
movedItem = _draft$splice[0];
|
|
161
|
+
draft.splice(targetIndex, 0, movedItem);
|
|
162
|
+
hasOperated = true;
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
if (hasOperated) this.afterRowsOperation();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 获取当前所有数据
|
|
169
|
+
* @returns 当前表格的所有行数据
|
|
170
|
+
*/;
|
|
171
|
+
_proto.getData = function getData() {
|
|
172
|
+
return this.subscription.getValue();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 获取指定行数据
|
|
176
|
+
* @param index 行索引
|
|
177
|
+
* @returns 指定行的数据,如果索引无效则返回 undefined
|
|
178
|
+
*/;
|
|
179
|
+
_proto.getRow = function getRow(index) {
|
|
180
|
+
var data = this.subscription.getValue();
|
|
181
|
+
return index >= 0 && index < data.length ? data[index] : undefined;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 开始编辑指定行
|
|
185
|
+
* @param index 要编辑的行索引
|
|
186
|
+
*/;
|
|
187
|
+
_proto.startEdit = function startEdit(index) {
|
|
188
|
+
if (index < 0 || index >= this.subscription.getValue().length) return;
|
|
189
|
+
// 如果已经在编辑其他行,先取消之前的编辑
|
|
190
|
+
if (this.editingIndex !== null && this.editingIndex !== index) {
|
|
191
|
+
this.cancelEdit();
|
|
192
|
+
}
|
|
193
|
+
this.editingIndex = index;
|
|
194
|
+
if (this.editingSubscription) {
|
|
195
|
+
var _this$editingSubscrip;
|
|
196
|
+
this.editingSubscription.setValue((_this$editingSubscrip = {}, _this$editingSubscrip[index] = true, _this$editingSubscrip));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 保存当前编辑行的修改
|
|
201
|
+
*/;
|
|
202
|
+
_proto.saveEdit = function saveEdit() {
|
|
203
|
+
var _a, _b, _c;
|
|
204
|
+
if (this.editingIndex === null) return;
|
|
205
|
+
var editingIndex = this.editingIndex;
|
|
206
|
+
this.editingIndex = null;
|
|
207
|
+
var result = this.subscription.saveDraft();
|
|
208
|
+
if (result) {
|
|
209
|
+
(_c = (_a = this.propsRef) === null || _a === void 0 ? void 0 : (_b = _a.current).onValuesChange) === null || _c === void 0 ? void 0 : _c.call(_b, result.changedValues, result.allValues);
|
|
210
|
+
}
|
|
211
|
+
// 清除编辑状态
|
|
212
|
+
if (this.editingSubscription) {
|
|
213
|
+
var _this$editingSubscrip2;
|
|
214
|
+
this.editingSubscription.setValue((_this$editingSubscrip2 = {}, _this$editingSubscrip2[editingIndex] = false, _this$editingSubscrip2));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 取消当前行的编辑,还原数据
|
|
219
|
+
*/;
|
|
220
|
+
_proto.cancelEdit = function cancelEdit() {
|
|
221
|
+
if (this.editingIndex === null) return;
|
|
222
|
+
var editingIndex = this.editingIndex;
|
|
223
|
+
// 清除暂存的草稿
|
|
224
|
+
this.subscription.clearDraft();
|
|
225
|
+
this.editingIndex = null;
|
|
226
|
+
// 清除编辑状态
|
|
227
|
+
if (this.editingSubscription) {
|
|
228
|
+
var _this$editingSubscrip3;
|
|
229
|
+
this.editingSubscription.setValue((_this$editingSubscrip3 = {}, _this$editingSubscrip3[editingIndex] = false, _this$editingSubscrip3));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* 判断指定行是否处于编辑状态
|
|
234
|
+
* @param index 行索引
|
|
235
|
+
*/;
|
|
236
|
+
_proto.isRowEditing = function isRowEditing(index) {
|
|
237
|
+
return this.editingIndex === index;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 获取当前正在编辑的行索引
|
|
241
|
+
*/;
|
|
242
|
+
_proto.getEditingIndex = function getEditingIndex() {
|
|
243
|
+
return this.editingIndex;
|
|
244
|
+
};
|
|
245
|
+
_createClass(TableRowController, [{
|
|
246
|
+
key: "isEditing",
|
|
247
|
+
get: function get() {
|
|
248
|
+
return this.editingIndex !== null;
|
|
249
|
+
}
|
|
250
|
+
}]);
|
|
251
|
+
return TableRowController;
|
|
252
|
+
}();
|
|
253
|
+
export { TableRowController };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { Button } from '@hi-ui/button';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 创建行编辑按钮
|
|
15
|
+
* @param rowActions 行操作对象
|
|
16
|
+
* @param index 行索引
|
|
17
|
+
* @returns 编辑按钮对象
|
|
18
|
+
*/
|
|
19
|
+
function createEditButtons(rowActions, index) {
|
|
20
|
+
// 编辑按钮
|
|
21
|
+
var edit = /*#__PURE__*/React.createElement(Button, {
|
|
22
|
+
key: "edit",
|
|
23
|
+
appearance: "link",
|
|
24
|
+
type: "primary",
|
|
25
|
+
onClick: function onClick() {
|
|
26
|
+
return rowActions.startEdit(index);
|
|
27
|
+
}
|
|
28
|
+
}, "\u7F16\u8F91");
|
|
29
|
+
// 保存按钮
|
|
30
|
+
var save = /*#__PURE__*/React.createElement(Button, {
|
|
31
|
+
key: "save",
|
|
32
|
+
appearance: "link",
|
|
33
|
+
type: "primary",
|
|
34
|
+
onClick: function onClick() {
|
|
35
|
+
return rowActions.saveEdit();
|
|
36
|
+
}
|
|
37
|
+
}, "\u4FDD\u5B58");
|
|
38
|
+
// 取消按钮
|
|
39
|
+
var cancel = /*#__PURE__*/React.createElement(Button, {
|
|
40
|
+
key: "cancel",
|
|
41
|
+
appearance: "link",
|
|
42
|
+
type: "primary",
|
|
43
|
+
onClick: function onClick() {
|
|
44
|
+
return rowActions.cancelEdit();
|
|
45
|
+
}
|
|
46
|
+
}, "\u53D6\u6D88");
|
|
47
|
+
return {
|
|
48
|
+
edit: edit,
|
|
49
|
+
save: save,
|
|
50
|
+
cancel: cancel
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { createEditButtons };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { useSubscribe, NOOP_SUBSCRIPTION } from '@hi-ui/use-subscription';
|
|
11
|
+
import { useEditableSchemaTableCtx } from '../../ctx.js';
|
|
12
|
+
function useRuntimeRowEditable(rowIndex) {
|
|
13
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
14
|
+
rowActions = _useEditableSchemaTab.rowActions;
|
|
15
|
+
var editingSubscription = rowActions.editingSubscription;
|
|
16
|
+
// 行编辑状态变化时触发重渲染
|
|
17
|
+
// 未启用行编辑时使用空订阅,内部不会创建额外的无效订阅
|
|
18
|
+
useSubscribe(editingSubscription || NOOP_SUBSCRIPTION, [rowIndex.toString()]);
|
|
19
|
+
// 未开启行编辑则返回 undefined
|
|
20
|
+
if (!editingSubscription) return undefined;
|
|
21
|
+
// 最后由 rowActions 控制是否可编辑
|
|
22
|
+
return rowActions.isRowEditing(rowIndex);
|
|
23
|
+
}
|
|
24
|
+
export { useRuntimeRowEditable };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { getExpandedRowModel } from '@tanstack/react-table';
|
|
11
|
+
function useRowExpandedOpts(ctx) {
|
|
12
|
+
return getRowExpandedOptions(ctx);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 获取行展开配置选项
|
|
16
|
+
*/
|
|
17
|
+
function getRowExpandedOptions(ctx) {
|
|
18
|
+
var enableRowExpanding = ctx.staticOptsRef.current.enableRowExpanding;
|
|
19
|
+
if (!enableRowExpanding) {
|
|
20
|
+
return {
|
|
21
|
+
enableExpanding: false,
|
|
22
|
+
enableSubRowSelection: false,
|
|
23
|
+
getSubRows: undefined
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
enableExpanding: true,
|
|
28
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
29
|
+
// 子行不参与分页,也就是所有的子行都在本页展示
|
|
30
|
+
paginateExpandedRows: false
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { getRowExpandedOptions, useRowExpandedOpts };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { useUpdate } from 'ahooks';
|
|
12
|
+
import { CaretRightFilled } from '@hi-ui/icons';
|
|
13
|
+
import { flexRender } from '@tanstack/react-table';
|
|
14
|
+
import { cls as cls$1 } from '../../utils/cls.js';
|
|
15
|
+
var cls = function cls(el) {
|
|
16
|
+
return cls$1('body-cell_expanding' + (el ? "-" + el : ''));
|
|
17
|
+
};
|
|
18
|
+
var INDENT_VAR_NAME = '--editable-schema-table-body-cell-expanding-indent';
|
|
19
|
+
function RowExpandingWrapper(props) {
|
|
20
|
+
var _a;
|
|
21
|
+
var cell = props.cell;
|
|
22
|
+
var row = cell.row;
|
|
23
|
+
var isExpanded = row.getIsExpanded();
|
|
24
|
+
var forceUpdate = useUpdate();
|
|
25
|
+
function handleExpandClick() {
|
|
26
|
+
var innerHandler = row.getToggleExpandedHandler();
|
|
27
|
+
innerHandler();
|
|
28
|
+
forceUpdate();
|
|
29
|
+
}
|
|
30
|
+
if (cell.column.getIndex() !== 0) return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
|
|
31
|
+
// 末端行的的缩进级别需要加1
|
|
32
|
+
// 因为没有前面的折叠按钮了,视觉上缩进会少一点点
|
|
33
|
+
var indentLevel = row.depth + (((_a = row.subRows) === null || _a === void 0 ? void 0 : _a.length) ? 0 : 1);
|
|
34
|
+
var isAggregated = cell.getIsAggregated();
|
|
35
|
+
var useAggregatedEl = isAggregated && props.renderCase === 'grouping';
|
|
36
|
+
var realEl = useAggregatedEl ? getAggregatedEl(cell) : props.children;
|
|
37
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
38
|
+
// expanding
|
|
39
|
+
className: cls(),
|
|
40
|
+
"data-case": "expanding",
|
|
41
|
+
"data-text-align": props.textAlign,
|
|
42
|
+
"data-is-aggregated": isAggregated
|
|
43
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
44
|
+
className: cls('wrapper')
|
|
45
|
+
}, row.depth > 0 && ( /*#__PURE__*/React.createElement("span", {
|
|
46
|
+
className: cls('indent'),
|
|
47
|
+
"data-depth": row.depth,
|
|
48
|
+
style: {
|
|
49
|
+
width: "calc(" + indentLevel + " * var(" + INDENT_VAR_NAME + "))"
|
|
50
|
+
}
|
|
51
|
+
})), isAggregated ? ( /*#__PURE__*/React.createElement("span", {
|
|
52
|
+
// icon
|
|
53
|
+
className: cls('icon'),
|
|
54
|
+
"data-is-expanded": isExpanded,
|
|
55
|
+
onClick: handleExpandClick
|
|
56
|
+
}, row.getCanExpand() ? /*#__PURE__*/React.createElement(CaretRightFilled, null) : null)) : null), realEl);
|
|
57
|
+
}
|
|
58
|
+
function getAggregatedEl(cell) {
|
|
59
|
+
var _a;
|
|
60
|
+
return flexRender((_a = cell.column.columnDef.aggregatedCell) !== null && _a !== void 0 ? _a : cell.column.columnDef.cell, cell.getContext());
|
|
61
|
+
}
|
|
62
|
+
export { RowExpandingWrapper };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { __rest } from 'tslib';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { useSubscribe, NOOP_SUBSCRIPTION } from '@hi-ui/use-subscription';
|
|
13
|
+
import { Actions } from '@hi-ui/schema-action-trigger';
|
|
14
|
+
import { useEditableSchemaTableCtx } from '../../ctx.js';
|
|
15
|
+
import { createEditButtons } from '../row-edit/actions.js';
|
|
16
|
+
|
|
17
|
+
/** 【操作按钮组】组件 */
|
|
18
|
+
function OpButtons(props) {
|
|
19
|
+
var _a;
|
|
20
|
+
var _b = useEditableSchemaTableCtx(),
|
|
21
|
+
subscription = _b.subscription,
|
|
22
|
+
rowActions = _b.rowActions,
|
|
23
|
+
restCxt = __rest(_b, ["subscription", "rowActions"]);
|
|
24
|
+
var row = props.row,
|
|
25
|
+
rowEdit = props.rowEdit;
|
|
26
|
+
// 订阅行编辑状态
|
|
27
|
+
useSubscribe(rowActions.editingSubscription || NOOP_SUBSCRIPTION, [row.index.toString()]);
|
|
28
|
+
var rowData = subscription.getValue()[row.index];
|
|
29
|
+
var isEditing = rowActions.isRowEditing(row.index);
|
|
30
|
+
// 获取编辑按钮 - 现在在组件内部调用,符合Hook规则
|
|
31
|
+
var editButtons = rowEdit ? createEditButtons(rowActions, row.index) : null;
|
|
32
|
+
// 扩展ctx,添加行编辑相关功能
|
|
33
|
+
var ctx = Object.assign(Object.assign({}, restCxt.exposeCtxValueRef.current()), {
|
|
34
|
+
row: row,
|
|
35
|
+
rowIndex: row.index,
|
|
36
|
+
rowEdit: {
|
|
37
|
+
isEditing: false,
|
|
38
|
+
buttons: {
|
|
39
|
+
edit: /*#__PURE__*/React.createElement(React.Fragment, null),
|
|
40
|
+
save: /*#__PURE__*/React.createElement(React.Fragment, null),
|
|
41
|
+
cancel: /*#__PURE__*/React.createElement(React.Fragment, null)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
// 如果启用了行编辑,添加行编辑相关上下文
|
|
46
|
+
if (rowEdit && editButtons) {
|
|
47
|
+
ctx.rowEdit = {
|
|
48
|
+
isEditing: isEditing,
|
|
49
|
+
buttons: editButtons
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// 优先使用自定义渲染
|
|
53
|
+
if (props.render) {
|
|
54
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, props.render(rowData, ctx));
|
|
55
|
+
}
|
|
56
|
+
// 默认渲染逻辑
|
|
57
|
+
if (rowEdit && editButtons) {
|
|
58
|
+
// 如果行处于编辑状态,显示保存和取消按钮
|
|
59
|
+
if (isEditing) {
|
|
60
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, editButtons.save, editButtons.cancel);
|
|
61
|
+
}
|
|
62
|
+
// 否则显示编辑按钮
|
|
63
|
+
else {
|
|
64
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, editButtons === null || editButtons === void 0 ? void 0 : editButtons.edit);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 否则显示普通操作按钮
|
|
68
|
+
if (!((_a = props.buttons) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
69
|
+
// 如果没有按钮,则不显示任何内容
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return /*#__PURE__*/React.createElement(Actions, {
|
|
73
|
+
actions: props.buttons,
|
|
74
|
+
data: rowData,
|
|
75
|
+
ctx: ctx,
|
|
76
|
+
maxCount: props.maxCount
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export { OpButtons };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { __rest } from 'tslib';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { useEditableSchemaTableCtx } from '../../ctx.js';
|
|
13
|
+
import { cls } from '../../utils/cls.js';
|
|
14
|
+
import { OpButtons } from './buttons.js';
|
|
15
|
+
function OperationBodyCell(props) {
|
|
16
|
+
var row = props.row;
|
|
17
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
18
|
+
propsRef = _useEditableSchemaTab.propsRef;
|
|
19
|
+
var rowOperation = propsRef.current.rowOperation;
|
|
20
|
+
if (!rowOperation) return null;
|
|
21
|
+
// 下面的 data-key={width} 仅仅是为了避开定义未使用的变量检查
|
|
22
|
+
var width = rowOperation.width,
|
|
23
|
+
restOpts = __rest(rowOperation, ["width"]);
|
|
24
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
25
|
+
className: cls('operation-buttons')
|
|
26
|
+
}, /*#__PURE__*/React.createElement(OpButtons, Object.assign({
|
|
27
|
+
"data-key": width,
|
|
28
|
+
row: row
|
|
29
|
+
}, restOpts)));
|
|
30
|
+
}
|
|
31
|
+
export { OperationBodyCell };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/schema-editable-table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
import { OperationHeader, OperationBody, OperationFooter } from './wrapper.js';
|
|
11
|
+
var RowOperation = {
|
|
12
|
+
Header: OperationHeader,
|
|
13
|
+
Body: OperationBody,
|
|
14
|
+
Footer: OperationFooter
|
|
15
|
+
};
|
|
16
|
+
export { RowOperation };
|