@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,100 @@
|
|
|
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 { cls } from '../../utils/cls.js';
|
|
12
|
+
import { useEditableSchemaTableCtx } from '../../ctx.js';
|
|
13
|
+
import '../../container/index.js';
|
|
14
|
+
import { ROW_OPERATION_COL_WIDTH } from '../../const.js';
|
|
15
|
+
import { OperationBodyCell } from './cell.js';
|
|
16
|
+
import { useTableContainer } from '../../container/ctx.js';
|
|
17
|
+
function OperationTable(props) {
|
|
18
|
+
var _a;
|
|
19
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
20
|
+
propsRef = _useEditableSchemaTab.propsRef;
|
|
21
|
+
var width = ((_a = propsRef.current.rowOperation) === null || _a === void 0 ? void 0 : _a.width) || ROW_OPERATION_COL_WIDTH;
|
|
22
|
+
return /*#__PURE__*/React.createElement("table", {
|
|
23
|
+
// table
|
|
24
|
+
className: cls('mock-operation'),
|
|
25
|
+
"data-is-operation": true,
|
|
26
|
+
style: {
|
|
27
|
+
width: width,
|
|
28
|
+
flexBasis: width
|
|
29
|
+
}
|
|
30
|
+
}, /*#__PURE__*/React.createElement("colgroup", null, /*#__PURE__*/React.createElement("col", {
|
|
31
|
+
style: {
|
|
32
|
+
width: width,
|
|
33
|
+
minWidth: width
|
|
34
|
+
}
|
|
35
|
+
})), props.children);
|
|
36
|
+
}
|
|
37
|
+
function OperationHeader() {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
|
|
40
|
+
propsRef = _useEditableSchemaTab2.propsRef;
|
|
41
|
+
var cellText = (_b = (_a = propsRef.current.rowOperation) === null || _a === void 0 ? void 0 : _a.headerText) !== null && _b !== void 0 ? _b : '操作';
|
|
42
|
+
return /*#__PURE__*/React.createElement(OperationTable, null, /*#__PURE__*/React.createElement("thead", {
|
|
43
|
+
className: cls('header')
|
|
44
|
+
}, /*#__PURE__*/React.createElement("tr", {
|
|
45
|
+
className: cls('header-row')
|
|
46
|
+
}, /*#__PURE__*/React.createElement("th", {
|
|
47
|
+
className: cls('header-cell'),
|
|
48
|
+
"data-text-align": "center"
|
|
49
|
+
}, cellText))));
|
|
50
|
+
}
|
|
51
|
+
function OperationBody() {
|
|
52
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
53
|
+
var _useEditableSchemaTab3 = useEditableSchemaTableCtx(),
|
|
54
|
+
table = _useEditableSchemaTab3.table;
|
|
55
|
+
var _useTableContainer = useTableContainer(),
|
|
56
|
+
virtualize = _useTableContainer.virtualize;
|
|
57
|
+
var _table$getRowModel = table.getRowModel(),
|
|
58
|
+
realRows = _table$getRowModel.rows;
|
|
59
|
+
return /*#__PURE__*/React.createElement(OperationTable, null, /*#__PURE__*/React.createElement("tbody", {
|
|
60
|
+
className: cls('body')
|
|
61
|
+
}, ((_b = (_a = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0) > 0 && ( /*#__PURE__*/React.createElement("tr", {
|
|
62
|
+
className: cls('body-row', 'virtual-spacer', 'virtual-spacer-top')
|
|
63
|
+
}, /*#__PURE__*/React.createElement("td", {
|
|
64
|
+
style: {
|
|
65
|
+
height: (_d = (_c = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _c === void 0 ? void 0 : _c.top) !== null && _d !== void 0 ? _d : 0
|
|
66
|
+
}
|
|
67
|
+
}))), ((virtualize === null || virtualize === void 0 ? void 0 : virtualize.rows) || realRows).map(function (rowOrVirtual) {
|
|
68
|
+
var row = 'index' in rowOrVirtual ? realRows[rowOrVirtual.index] : rowOrVirtual;
|
|
69
|
+
if (!row) return null;
|
|
70
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
71
|
+
key: row.id,
|
|
72
|
+
className: cls('body-row'),
|
|
73
|
+
"data-index": row.index,
|
|
74
|
+
"data-id": row.id
|
|
75
|
+
}, /*#__PURE__*/React.createElement("td", {
|
|
76
|
+
className: cls('body-cell'),
|
|
77
|
+
"data-text-align": "center"
|
|
78
|
+
}, /*#__PURE__*/React.createElement(OperationBodyCell, {
|
|
79
|
+
row: row
|
|
80
|
+
})));
|
|
81
|
+
}), ((_f = (_e = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _e === void 0 ? void 0 : _e.bottom) !== null && _f !== void 0 ? _f : 0) > 0 && ( /*#__PURE__*/React.createElement("tr", {
|
|
82
|
+
className: cls('body-row', 'virtual-spacer', 'virtual-spacer-bottom')
|
|
83
|
+
}, /*#__PURE__*/React.createElement("td", {
|
|
84
|
+
style: {
|
|
85
|
+
height: (_h = (_g = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _g === void 0 ? void 0 : _g.bottom) !== null && _h !== void 0 ? _h : 0
|
|
86
|
+
}
|
|
87
|
+
})))));
|
|
88
|
+
}
|
|
89
|
+
// 暂时用不上,预留位置待扩展
|
|
90
|
+
function OperationFooter() {
|
|
91
|
+
return /*#__PURE__*/React.createElement(OperationTable, null, /*#__PURE__*/React.createElement("tfoot", {
|
|
92
|
+
className: cls('footer')
|
|
93
|
+
}, /*#__PURE__*/React.createElement("tr", {
|
|
94
|
+
className: cls('footer-row')
|
|
95
|
+
}, /*#__PURE__*/React.createElement("td", {
|
|
96
|
+
className: cls('footer-cell'),
|
|
97
|
+
"data-text-align": "center"
|
|
98
|
+
}))));
|
|
99
|
+
}
|
|
100
|
+
export { OperationBody, OperationFooter, OperationHeader };
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { Checkbox } from '@hi-ui/checkbox';
|
|
12
|
+
import { Radio } from '@hi-ui/radio';
|
|
13
|
+
import { Schedular } from '@hi-ui/schema-utils';
|
|
14
|
+
import { useEditableSchemaTableCtx } from '../../ctx.js';
|
|
15
|
+
import { cls } from '../../utils/cls.js';
|
|
16
|
+
import { dftSelectionType } from './const.js';
|
|
17
|
+
function SelectionHeaderCell() {
|
|
18
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
19
|
+
table = _useEditableSchemaTab.table,
|
|
20
|
+
propsRef = _useEditableSchemaTab.propsRef;
|
|
21
|
+
// // 经过性能优化,已移除额外订阅
|
|
22
|
+
// // 此时保留,反而会导致本组件重复重渲染
|
|
23
|
+
// // 保留此处注释,用以后续调整
|
|
24
|
+
// const { rowSelectionState } = useEditableSchemaTableCtx()
|
|
25
|
+
// useSubscribe(rowSelectionState)
|
|
26
|
+
var rowSelection = propsRef.current.rowSelection;
|
|
27
|
+
if (!rowSelection) return null; // 其实走不到,仅用来收窄类型
|
|
28
|
+
var _rowSelection$type = rowSelection.type,
|
|
29
|
+
type = _rowSelection$type === void 0 ? dftSelectionType : _rowSelection$type;
|
|
30
|
+
/** 修复 <th> 元素嵌套在另一个 <th> 元素中,违反 HTML 规范的问题 */
|
|
31
|
+
if (type === 'radio') return /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
className: cls('header-cell')
|
|
33
|
+
});
|
|
34
|
+
// NOTE: 表头全选更改为仅选择当页数据
|
|
35
|
+
var checked = table.getIsAllPageRowsSelected();
|
|
36
|
+
var indeterminate = table.getIsSomePageRowsSelected();
|
|
37
|
+
var handleChange = function handleCheckAllChange(event) {
|
|
38
|
+
var innerHandler = table.getToggleAllPageRowsSelectedHandler();
|
|
39
|
+
innerHandler(event);
|
|
40
|
+
// 稍微延迟一下,等待内部状态完成更新
|
|
41
|
+
Schedular.nextMicro(function () {
|
|
42
|
+
var _a;
|
|
43
|
+
var checked = table.getIsAllPageRowsSelected();
|
|
44
|
+
var indeterminate = table.getIsSomePageRowsSelected();
|
|
45
|
+
(_a = rowSelection.onCheckAllChange) === null || _a === void 0 ? void 0 : _a.call(rowSelection, {
|
|
46
|
+
checked: checked,
|
|
47
|
+
indeterminate: indeterminate
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return /*#__PURE__*/React.createElement(Checkbox
|
|
52
|
+
// Checkbox
|
|
53
|
+
, {
|
|
54
|
+
// Checkbox
|
|
55
|
+
checked: checked,
|
|
56
|
+
indeterminate: indeterminate,
|
|
57
|
+
onChange: handleChange
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function SelectionBodyCell(props) {
|
|
61
|
+
var row = props.row;
|
|
62
|
+
var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
|
|
63
|
+
propsRef = _useEditableSchemaTab2.propsRef;
|
|
64
|
+
var rowSelection = propsRef.current.rowSelection;
|
|
65
|
+
var _ref = rowSelection || {},
|
|
66
|
+
_ref$type = _ref.type,
|
|
67
|
+
type = _ref$type === void 0 ? dftSelectionType : _ref$type;
|
|
68
|
+
// // 经过性能优化,已移除额外订阅
|
|
69
|
+
// // 此时保留,反而会导致本组件重复重渲染
|
|
70
|
+
// // 保留此处注释,用以后续调整
|
|
71
|
+
// const { rowSelectionState } = useEditableSchemaTableCtx<TData>()
|
|
72
|
+
// const { enableDynamicRowSelection } = rowSelection || {}
|
|
73
|
+
// useSubscribe(
|
|
74
|
+
// rowSelectionState,
|
|
75
|
+
// // 如果启用了动态行可选状态支持,则不订阅(相当于订阅全部变化)
|
|
76
|
+
// enableDynamicRowSelection ? undefined : [row.id]
|
|
77
|
+
// )
|
|
78
|
+
if (!rowSelection) return null; // 其实走不到,仅用来收窄类型
|
|
79
|
+
var SelectComp = type === 'radio' ? Radio : Checkbox;
|
|
80
|
+
function handleChange(event) {
|
|
81
|
+
var innerHandler = row.getToggleSelectedHandler();
|
|
82
|
+
innerHandler(event);
|
|
83
|
+
// 上面是行本身的变化处理逻辑
|
|
84
|
+
// 下面是存在父行的情况,需要处理父行的选中状态
|
|
85
|
+
row.$afterToggleSelected();
|
|
86
|
+
}
|
|
87
|
+
// 根据组件类型决定是否传递 indeterminate 属性
|
|
88
|
+
var commonProps = {
|
|
89
|
+
checked: row.getIsSelected(),
|
|
90
|
+
onChange: handleChange,
|
|
91
|
+
disabled: !row.getCanSelect()
|
|
92
|
+
};
|
|
93
|
+
// 只有 Checkbox 支持 indeterminate 属性
|
|
94
|
+
if (type === 'checkbox') {
|
|
95
|
+
return /*#__PURE__*/React.createElement(SelectComp, Object.assign({}, commonProps, {
|
|
96
|
+
indeterminate: row.getIsSomeSelected()
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
return /*#__PURE__*/React.createElement(SelectComp, Object.assign({}, commonProps));
|
|
100
|
+
}
|
|
101
|
+
export { SelectionBodyCell, SelectionHeaderCell };
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
var dftSelectionType = 'checkbox';
|
|
11
|
+
export { dftSelectionType };
|
|
@@ -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 { useSubscription } from '@hi-ui/use-subscription';
|
|
11
|
+
import 'ahooks';
|
|
12
|
+
import 'lodash-es';
|
|
13
|
+
import 'react';
|
|
14
|
+
import '../../../utils/cls.js';
|
|
15
|
+
import '@tanstack/react-table';
|
|
16
|
+
|
|
17
|
+
// 暂时没有太多逻辑,仅在此处包装
|
|
18
|
+
function useRowSelectionState() {
|
|
19
|
+
var rowSelectionState = useSubscription({});
|
|
20
|
+
return {
|
|
21
|
+
rowSelectionState: rowSelectionState
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { useRowSelectionState };
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { useEffect } from 'react';
|
|
11
|
+
import { useEditableSchemaTableCtx } from '../../../ctx.js';
|
|
12
|
+
import { cls } from '../../../utils/cls.js';
|
|
13
|
+
import 'lodash-es';
|
|
14
|
+
import '@tanstack/react-table';
|
|
15
|
+
import 'ahooks';
|
|
16
|
+
var useClickSelect = function useClickSelect() {
|
|
17
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
18
|
+
tableContainerRef = _useEditableSchemaTab.tableContainerRef,
|
|
19
|
+
propsRef = _useEditableSchemaTab.propsRef,
|
|
20
|
+
table = _useEditableSchemaTab.table;
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
// 只在开启点击行选择时启用
|
|
24
|
+
if (!((_b = (_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.rowSelection) === null || _b === void 0 ? void 0 : _b.enableClickSelect)) return;
|
|
25
|
+
if (!tableContainerRef.current) return;
|
|
26
|
+
var container = tableContainerRef.current;
|
|
27
|
+
var selector = "." + cls('body-wrapper') + " ." + cls('main-content');
|
|
28
|
+
var tableEl = container.querySelector(selector);
|
|
29
|
+
if (!tableEl) return;
|
|
30
|
+
var handleClick = function handleClick(event) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
var target = event.target;
|
|
33
|
+
// TODO 此处还能还有其他的待排除元素,待识别后更新
|
|
34
|
+
// 排除 input 元素的点击
|
|
35
|
+
if (((_a = target.tagName) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'INPUT') return;
|
|
36
|
+
// 排除 svg 元素的点击
|
|
37
|
+
if (((_b = target.tagName) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'SVG') return;
|
|
38
|
+
if (((_c = target.tagName) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === 'PATH') return;
|
|
39
|
+
// 排除 HiUI 的表单项
|
|
40
|
+
if (target.className.includes('hi')) {
|
|
41
|
+
// Select 等使用 MockInput 的组件
|
|
42
|
+
if (target.className.includes('mock-input')) return;
|
|
43
|
+
// 日期选择器组件
|
|
44
|
+
if (target.className.includes('date-picker')) return;
|
|
45
|
+
// 多选选择器组件
|
|
46
|
+
if (target.className.includes('tag-input-mock')) return;
|
|
47
|
+
}
|
|
48
|
+
// 查找当前点击的行元素
|
|
49
|
+
var rowEl = target.closest('tr[data-id]');
|
|
50
|
+
if (!rowEl) return;
|
|
51
|
+
var rowId = rowEl.getAttribute('data-id');
|
|
52
|
+
if (!rowId) return;
|
|
53
|
+
// 获取行实例并触发选中
|
|
54
|
+
var row = table.getRow(rowId);
|
|
55
|
+
if (!row) return;
|
|
56
|
+
row.toggleSelected();
|
|
57
|
+
row.$afterToggleSelected();
|
|
58
|
+
};
|
|
59
|
+
tableEl.addEventListener('click', handleClick);
|
|
60
|
+
return function () {
|
|
61
|
+
tableEl.removeEventListener('click', handleClick);
|
|
62
|
+
};
|
|
63
|
+
}, [tableContainerRef, propsRef, table]);
|
|
64
|
+
};
|
|
65
|
+
export { useClickSelect };
|
|
@@ -0,0 +1,114 @@
|
|
|
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 { useMount } from 'ahooks';
|
|
11
|
+
import { isEqual } from 'lodash-es';
|
|
12
|
+
function useRowSelectionOpts(ctx) {
|
|
13
|
+
var rowSelection = ctx.rowSelection,
|
|
14
|
+
innerRef = ctx.innerRef;
|
|
15
|
+
// 挂载时将默认选中的行同步至内部状态
|
|
16
|
+
useMount(function () {
|
|
17
|
+
if (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.dftSelectedRowKeys) {
|
|
18
|
+
var globalActionsRef = innerRef.current.globalActionsRef;
|
|
19
|
+
var keys = rowSelection.dftSelectedRowKeys;
|
|
20
|
+
globalActionsRef.current.setSelectedRowKeys(keys);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
// 启用行选择
|
|
25
|
+
enableRowSelection: (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.enableRowSelection) ? function enableRowSelection(row) {
|
|
26
|
+
var _a;
|
|
27
|
+
var tableValue = innerRef.current.subscription;
|
|
28
|
+
var rowData = tableValue.getValue()[row.index];
|
|
29
|
+
return (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.enableRowSelection) === null || _a === void 0 ? void 0 : _a.call(rowSelection, rowData, {
|
|
30
|
+
row: row
|
|
31
|
+
});
|
|
32
|
+
} : true,
|
|
33
|
+
// 启用子行选择
|
|
34
|
+
enableSubRowSelection: (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.enableSubRowSelection) ? function enableSubRowSelection(row) {
|
|
35
|
+
var _a;
|
|
36
|
+
var tableValue = innerRef.current.subscription;
|
|
37
|
+
var rowData = tableValue.getValue()[row.index];
|
|
38
|
+
return (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.enableSubRowSelection) === null || _a === void 0 ? void 0 : _a.call(rowSelection, rowData, {
|
|
39
|
+
row: row
|
|
40
|
+
});
|
|
41
|
+
} : true,
|
|
42
|
+
// 单选模式下只允许选择一行
|
|
43
|
+
enableMultiRowSelection: (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.type) !== 'radio',
|
|
44
|
+
// 选中状态变化时触发onChange
|
|
45
|
+
onRowSelectionChange: function onRowSelectionChange(updater) {
|
|
46
|
+
var _a;
|
|
47
|
+
if (!rowSelection) return;
|
|
48
|
+
var _innerRef$current = innerRef.current,
|
|
49
|
+
table = _innerRef$current.table,
|
|
50
|
+
rowSelectionState = _innerRef$current.rowSelectionState;
|
|
51
|
+
var state = table.getState().rowSelection;
|
|
52
|
+
var newState = typeof updater === 'function' ? updater(state) : updater;
|
|
53
|
+
// 如果行选择状态没有变化,则不更新
|
|
54
|
+
if (isEqual(state, newState)) return;
|
|
55
|
+
// 先同步到订阅上
|
|
56
|
+
var preState = rowSelectionState.getValue();
|
|
57
|
+
// #region generate next state
|
|
58
|
+
var nextState = {};
|
|
59
|
+
// 请勿感到迷惑,此处把 preState 的 key 全部拿出来设置一遍值
|
|
60
|
+
// 是因为取消选择时 newState 里是一个空对象,而不是 {[key]: false},会导致状态丢失
|
|
61
|
+
for (var key in preState) {
|
|
62
|
+
nextState[key] = !!newState[key];
|
|
63
|
+
}
|
|
64
|
+
// 这里则是再加一步保险,确保 newState 的 key 全部设置一遍值
|
|
65
|
+
// 其实不加也无所谓,因为 newState 的 key 是来自 preState 的
|
|
66
|
+
for (var _key in newState) {
|
|
67
|
+
nextState[_key] = !!newState[_key];
|
|
68
|
+
}
|
|
69
|
+
// #endregion
|
|
70
|
+
rowSelectionState.mergeValue(nextState);
|
|
71
|
+
// 构造数据回传给外部
|
|
72
|
+
var _table$$getRowSelecti = table.$getRowSelection(newState),
|
|
73
|
+
selectedRows = _table$$getRowSelecti.selectedRows,
|
|
74
|
+
selectedRowKeys = _table$$getRowSelecti.selectedRowKeys,
|
|
75
|
+
selectedRowEntries = _table$$getRowSelecti.selectedRowEntries;
|
|
76
|
+
// 更新选中行原始数据的缓存,内部会做判断,仅在启用 preserveSelectedRows 时才更新
|
|
77
|
+
table.$updateSelectedRowsCache(selectedRowEntries);
|
|
78
|
+
// 最后再更新内部状态 // 最后再触发重渲染
|
|
79
|
+
table.setState(function (state) {
|
|
80
|
+
return Object.assign(Object.assign({}, state), {
|
|
81
|
+
rowSelection: newState
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
(_a = rowSelection.onChange) === null || _a === void 0 ? void 0 : _a.call(rowSelection, {
|
|
85
|
+
keys: selectedRowKeys,
|
|
86
|
+
rows: selectedRows
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** 如果开启了后端分页,并且没有配置 preserveSelectedRows,则需要在分页变化时清空选中状态 */
|
|
92
|
+
function resetRowSelectionAfterPaginationChange(ctx) {
|
|
93
|
+
var _a;
|
|
94
|
+
var globalStaticRef = ctx.innerRef.current.globalStaticRef;
|
|
95
|
+
var enableAsyncData = globalStaticRef.current.enableAsyncData;
|
|
96
|
+
// 如果开启了后端分页,并且没有配置preserveSelectedRows,则需要清空选中状态
|
|
97
|
+
if (enableAsyncData) {
|
|
98
|
+
var propsRef = ctx.innerRef.current.propsRef;
|
|
99
|
+
var preserveSelectedRows = (_a = propsRef.current.rowSelection) === null || _a === void 0 ? void 0 : _a.preserveSelectedRows;
|
|
100
|
+
// 并且没有配置 preserveSelectedRows
|
|
101
|
+
if (!preserveSelectedRows) {
|
|
102
|
+
// 并且页数发生变化
|
|
103
|
+
var state = ctx.state,
|
|
104
|
+
newState = ctx.newState;
|
|
105
|
+
var hasPageIndexChanged = state.pageIndex !== newState.pageIndex;
|
|
106
|
+
// 则清空选中状态
|
|
107
|
+
if (hasPageIndexChanged) {
|
|
108
|
+
var table = ctx.innerRef.current.table;
|
|
109
|
+
table.setRowSelection({});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export { resetRowSelectionAfterPaginationChange, useRowSelectionOpts };
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { useCallback } from 'react';
|
|
11
|
+
import { isNil } from 'lodash-es';
|
|
12
|
+
function useSetSelectedRowKeys(ctx) {
|
|
13
|
+
var innerRef = ctx.innerRef;
|
|
14
|
+
var setSelectedRowKeys = useCallback(function setSelectedRowKeys(keys) {
|
|
15
|
+
var table = innerRef.current.table;
|
|
16
|
+
// 传入 null 时,清空所有选中的行
|
|
17
|
+
if (keys === null) {
|
|
18
|
+
table.setRowSelection({});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var nextKeys = Array.isArray(keys) ? keys :
|
|
22
|
+
// 如果 keys 是函数,则取出当前选中的全部行的ID
|
|
23
|
+
keys(Object.keys(table.getState().rowSelection));
|
|
24
|
+
// 函数返回 null 也可清空所有选中的行
|
|
25
|
+
if (nextKeys === null) {
|
|
26
|
+
table.setRowSelection({});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// 只要不是 undefined 或者 null 都认为是有效的
|
|
30
|
+
var validKeys = nextKeys.filter(function (key) {
|
|
31
|
+
return !isNil(key);
|
|
32
|
+
});
|
|
33
|
+
if (validKeys.length === 0) return;
|
|
34
|
+
// 有效的key全部认为要被选中
|
|
35
|
+
var newState = Object.fromEntries(validKeys.map(function (key) {
|
|
36
|
+
return [key, true];
|
|
37
|
+
}));
|
|
38
|
+
// 设置行选择状态
|
|
39
|
+
table.setRowSelection(newState);
|
|
40
|
+
}, [innerRef]);
|
|
41
|
+
return setSelectedRowKeys;
|
|
42
|
+
}
|
|
43
|
+
export { useSetSelectedRowKeys };
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { useRef, useEffect } from 'react';
|
|
11
|
+
import { useEditableSchemaTableCtx } from '../../../ctx.js';
|
|
12
|
+
import { cls } from '../../../utils/cls.js';
|
|
13
|
+
import 'lodash-es';
|
|
14
|
+
import '@tanstack/react-table';
|
|
15
|
+
import 'ahooks';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 同步表格行的 hover 状态
|
|
19
|
+
* @desc 当表格分为选择列和主内容两部分时,确保 hover 效果能同步显示在两边
|
|
20
|
+
*/
|
|
21
|
+
function useSyncHoverStyle() {
|
|
22
|
+
var _useEditableSchemaTab = useEditableSchemaTableCtx(),
|
|
23
|
+
tableContainerRef = _useEditableSchemaTab.tableContainerRef,
|
|
24
|
+
propsRef = _useEditableSchemaTab.propsRef;
|
|
25
|
+
var findClassName = "." + cls('body-row');
|
|
26
|
+
// 用ref存储上一次 hover 的行元素,避免不必要的DOM查询
|
|
27
|
+
var lastHoveredRowsRef = useRef(null);
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!tableContainerRef.current) return;
|
|
31
|
+
// 只在开启行选择时启用 hover 同步
|
|
32
|
+
if (!((_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.rowSelection)) return;
|
|
33
|
+
// // 如果开启了列分组,则不启用 hover 同步
|
|
34
|
+
// TODO 此处需进一步细化处理场景
|
|
35
|
+
// if (propsRef.current.grouping) return
|
|
36
|
+
var container = tableContainerRef.current;
|
|
37
|
+
var clearHover = function clearHover() {
|
|
38
|
+
if (lastHoveredRowsRef.current) {
|
|
39
|
+
lastHoveredRowsRef.current.forEach(function (el) {
|
|
40
|
+
return el.removeAttribute('data-hovering');
|
|
41
|
+
});
|
|
42
|
+
lastHoveredRowsRef.current = null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var handleMouseMove = function handleMouseMove(e) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
// 查找当前 hover 的行元素
|
|
48
|
+
var row = e.target.closest(findClassName);
|
|
49
|
+
// 如果没有找到行元素,清除上一次的 hover 状态
|
|
50
|
+
if (!row) return clearHover();
|
|
51
|
+
var rowId = row.getAttribute('data-id');
|
|
52
|
+
if (!rowId) return;
|
|
53
|
+
// 如果 hover 的是同一行,不做任何操作
|
|
54
|
+
if (((_b = (_a = lastHoveredRowsRef.current) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.getAttribute('data-id')) === rowId) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// 清除上一次 hover 的行
|
|
58
|
+
clearHover();
|
|
59
|
+
// 找到所有相同 id 的行并添加 hover 状态
|
|
60
|
+
var currentRows = Array.from(container.querySelectorAll("tr[data-id=\"" + rowId + "\"]"));
|
|
61
|
+
currentRows.forEach(function (el) {
|
|
62
|
+
return el.setAttribute('data-hovering', '');
|
|
63
|
+
});
|
|
64
|
+
lastHoveredRowsRef.current = currentRows;
|
|
65
|
+
};
|
|
66
|
+
// 鼠标离开表格时清除所有 hover 状态
|
|
67
|
+
var handleMouseLeave = function handleMouseLeave() {
|
|
68
|
+
return clearHover();
|
|
69
|
+
};
|
|
70
|
+
container.addEventListener('mousemove', handleMouseMove);
|
|
71
|
+
container.addEventListener('mouseleave', handleMouseLeave);
|
|
72
|
+
return function () {
|
|
73
|
+
// 清理事件监听
|
|
74
|
+
container.removeEventListener('mousemove', handleMouseMove);
|
|
75
|
+
container.removeEventListener('mouseleave', handleMouseLeave);
|
|
76
|
+
// 组件卸载时清除所有hover状态
|
|
77
|
+
clearHover();
|
|
78
|
+
};
|
|
79
|
+
}, [tableContainerRef, propsRef, findClassName]);
|
|
80
|
+
}
|
|
81
|
+
export { useSyncHoverStyle };
|