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