@hzab/edit-table 0.1.9 → 0.1.11

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/CHANGELOG.md CHANGED
@@ -1,4 +1,25 @@
1
- # @hzab/edit-table@0.1.5
1
+ # @hzab/edit-table
2
+
3
+ ## 0.1.11
4
+
5
+ ### Patch Changes
6
+
7
+ - feat:支持checkbox 传入配置禁用
8
+
9
+
10
+
11
+
12
+ ## 0.1.10
13
+
14
+ ### Patch Changes
15
+
16
+ feat:支持checkbox 传入配置禁用
17
+
18
+ - 8d7ccee: 文档站入站(docs-site-plan.md 步骤 5):把 README / 包内 docs 里指向**仓库内私有文件**的链接改为文字说明
19
+
20
+ 涉及 `CHANGELOG.md`、`REVIEW.md`、仓库级 `docs/archive/**` 与 `docs/source-sync.md`。
21
+ 这些文件不随包发布,链接在 npm 页面与文档站上都是死链(文档站会被 VitePress 死链检查拦下构建)。
22
+ 改法统一为「删链接语法、保留文字并标明仓库内路径」,内容本身无删减。
2
23
 
3
24
  ## 0.1.9
4
25
 
@@ -130,30 +151,30 @@
130
151
  - Updated dependencies [0617135]
131
152
  - @hzab/utils@1.1.8
132
153
  - @hzab/form-render@1.7.20
133
-
134
- chore: 本仓迁移版本首次发布(源码直出 `main: "src"` + 类型入口指向 `dist`)
135
-
136
- - `getVal` 改由 `@hzab/utils` 提供,移除对 `@hzab/list-render` 的运行时依赖(打破两包循环依赖)
137
- - 跨包依赖由 `peerDependencies` 调整为 `dependencies`(修正构建顺序)
138
- - 组件运行时行为与 0.1.4 保持一致
139
-
140
- # @hzab/edit-table@0.1.4
141
-
142
- fix: 编辑数据优化
143
- feat:高亮选中行
144
-
145
- # @hzab/edit-table@0.1.2
146
-
147
- fix: checkbox 选择子项时拿到对应行的数据
148
-
149
- # @hzab/edit-table@0.1.1
150
-
151
- fix: 无数据时取消聚焦框
152
-
153
- # @hzab/edit-table@0.1.0
154
-
155
- feat: 组件优化,批量提交
156
-
157
- # @hzab/edit-table@0.0.1
158
-
159
- 组件初始化
154
+
155
+ chore: 本仓迁移版本首次发布(源码直出 `main: "src"` + 类型入口指向 `dist`)
156
+
157
+ - `getVal` 改由 `@hzab/utils` 提供,移除对 `@hzab/list-render` 的运行时依赖(打破两包循环依赖)
158
+ - 跨包依赖由 `peerDependencies` 调整为 `dependencies`(修正构建顺序)
159
+ - 组件运行时行为与 0.1.4 保持一致
160
+
161
+ # @hzab/edit-table@0.1.4
162
+
163
+ fix: 编辑数据优化
164
+ feat:高亮选中行
165
+
166
+ # @hzab/edit-table@0.1.2
167
+
168
+ fix: checkbox 选择子项时拿到对应行的数据
169
+
170
+ # @hzab/edit-table@0.1.1
171
+
172
+ fix: 无数据时取消聚焦框
173
+
174
+ # @hzab/edit-table@0.1.0
175
+
176
+ feat: 组件优化,批量提交
177
+
178
+ # @hzab/edit-table@0.0.1
179
+
180
+ 组件初始化
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 CaiYansong
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CaiYansong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,170 +1,170 @@
1
- # @hzab/edit-table
2
-
3
- 可编辑表格:基于 `@silevis/reactgrid` 的单元格级编辑表格,支持批量提交、公式列、展开行与自定义单元格模板。
4
-
5
- - Node.js ≥ 24
6
-
7
- ## 安装
8
-
9
- ```bash
10
- pnpm add @hzab/edit-table
11
- ```
12
-
13
- 本包同时发布到**公共 npm**(`registry.npmjs.org`,public access)与企业私有源(ld / old)。默认源可直接安装,
14
- 无需额外配置;若团队要求走内网源,见[消费方接入指南 §2](../../../docs/consumer-access.md#2-可选改为从企业私有源安装)。
15
-
16
- 消费方需自备 peerDependencies:`@ant-design/icons`、`@hzab/form-render`、`@hzab/utils`、`@silevis/reactgrid`、`antd`、`react`、`react-dom`(本包不会随包安装)。
17
-
18
- > **发布形态**:本包在本仓以**源码直出**方式发布——`main` 指向 `src`,由消费方打包器编译
19
- > TypeScript 与 `.less` 样式;`@hzab/edit-table/src/*` 深路径同样可直接引用。随包发布的 `dist/` 仅用于
20
- > 类型解析(`types` → `dist/index.d.ts`),不是运行时入口。消费方需要承担的编译责任见
21
- > [消费方接入指南 §4](../../../docs/consumer-access.md#4-src-直出包消费方要承担的编译责任)。
22
-
23
- ## 快速开始
24
-
25
- 默认导出即组件(内部为 `forwardRef`):
26
-
27
- ```jsx
28
- import { useMemo, useRef } from "react";
29
- import CellEditTable from "@hzab/edit-table";
30
-
31
- const columns = [
32
- { key: "name", title: "姓名", width: 120 },
33
- { key: "age", type: "Number", title: "年龄", width: 80 },
34
- { key: "birthday", type: "DatePicker", title: "生日", width: 160 },
35
- { key: "memo", type: "Input.TextArea", title: "备注", width: 200, nonEditable: true },
36
- ];
37
-
38
- function Demo() {
39
- const tableRef = useRef(null);
40
-
41
- const dataSource = useMemo(
42
- () => [
43
- { id: 1, name: "张三", age: 30, birthday: "1994-01-01" },
44
- { id: 2, name: "李四", age: 28, birthday: "1996-06-15" },
45
- ],
46
- [],
47
- );
48
-
49
- return (
50
- <CellEditTable
51
- ref={tableRef}
52
- rowKey="id"
53
- columns={columns}
54
- dataSource={dataSource}
55
- onEditSubmit={async (rows) => {
56
- // rows:本次变更后的整行对象数组(批量编辑时一次提交多行)
57
- await saveRows(rows);
58
- }}
59
- onChange={(row) => console.log("单元格变更", row)}
60
- getList={() => console.log("提交失败后重新拉取列表")}
61
- />
62
- );
63
- }
64
- ```
65
-
66
- ## API
67
-
68
- ### 组件 Props
69
-
70
- | 属性 | 类型 | 必须 | 默认值 | 说明 |
71
- | ----------------- | ---------------------------------------- | ---- | ------- | -------------------------------------------------------------------------------- |
72
- | `columns` | Array | 是 | - | 列定义,详见「columns 列配置」 |
73
- | `dataSource` | Array | 是 | - | 数据源;元素需含 `rowKey` 指定的唯一字段 |
74
- | `rowKey` | string | 否 | `"id"` | 唯一值字段名 |
75
- | `onEditSubmit` | `(rows) => void \| Promise` | 否 | - | 编辑提交回调,入参为**整行对象数组**;抛错时会调用 `getList()` |
76
- | `onChange` | `(row) => void` | 否 | - | 单个单元格变更后回调,入参为该行最新数据 |
77
- | `getList` | `() => void` | 否 | - | 重新拉取列表;`onEditSubmit` 抛错时被调用 |
78
- | `query` | Object | 否 | - | 列表查询参数;`query.pageNum` 变化时会清空行选中 |
79
- | `loading` | boolean | 否 | - | 加载中;为真时渲染上一帧行数据并显示 `Spin` |
80
- | `headerRowHeight` | number | 否 | `44` | 表头行高 |
81
- | `rowHeight` | number | 否 | `44` | 数据行高 |
82
- | `isExpand` | boolean | 否 | `false` | 是否在首列插入展开列,展开 `record.children` 子行 |
83
- | `rowSelection` | Object | 否 | - | 行选择配置:`width`、`style`、`selectedRowKeys`、`onChange(keys, rows)` |
84
- | `formulaConfig` | Object | 否 | - | 公式/计算列配置,详见下节 |
85
- | `reactGridProps` | Object | 否 | `{}` | 透传给 `@silevis/reactgrid` 的 `ReactGrid`,另含本包扩展项(见下节) |
86
- | `reactGridStyle` | Object | 否 | - | 外层容器 `div` 的行内样式 |
87
- | `className` | string | 否 | - | 外层容器 `div` 的 className |
88
- | `onRow` | `(record, rowIndex, colIndex) => Object` | 否 | - | 逐单元格回调,返回值会合并进该单元格定义(可覆盖 `text` / `value` / `style` 等) |
89
- | `Slots` | Object | 否 | - | 插槽,详见「Slots」 |
90
-
91
- ### columns 列配置
92
-
93
- `columns` 元素除自身字段外,会被展开进对应单元格定义。
94
-
95
- | 字段 | 类型 | 说明 |
96
- | ------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97
- | `key` | string | 对应数据字段名(即单元格 `columnId`) |
98
- | `title` | string \| Function | 表头文案;为函数且返回 ReactElement 时按自定义表头组件渲染(自动包 `WidthWrapHoc`) |
99
- | `width` | number | 列宽 |
100
- | `type` | string | 单元格模板类型,默认 `"text"`。内置模板来自 `@hzab/form-render` 的 `antdComponents` 与 `customComponents`,另加本包的 `DatePicker.*` / `Input.*` / `TimePicker.*` 细分项(如 `Number`、`DatePicker`、`Input.TextArea`、`DatePicker.RangePicker`) |
101
- | `nonEditable` | boolean | 该列不可编辑 |
102
- | `onCell` | `(record, rowIndex, colIndex) => Object` | 逐单元格回调,返回值合并进单元格定义(优先级高于 `onRow`) |
103
- | `cellProps` | Object | 直接合并进单元格定义的 props |
104
- | `children` | Array | 多级表头 |
105
-
106
- 本包额外提供的内置模板名:`DatePicker.MonthPicker`、`DatePicker.QuarterPicker`、`DatePicker.RangePicker`、
107
- `DatePicker.TimePicker`、`DatePicker.WeekPicker`、`DatePicker.YearPicker`、`Input.Password`、`Input.Search`、
108
- `Input.TextArea`、`TimePicker.RangePicker`。
109
-
110
- ### `formulaConfig`:计算列
111
-
112
- 以**目标列的 `key`** 为键,声明该列的值与样式如何由整行数据算出:
113
-
114
- ```js
115
- const formulaConfig = {
116
- total: {
117
- // 返回该列的显示值与值(text 与 value 用同一结果)
118
- setCellData: (row) => Number(row.price || 0) * Number(row.count || 0),
119
- // 返回单元格 style;入参为 setCellData 的结果,setCellData 缺省时回退整行
120
- setCellStyle: (value) => (Number(value) > 1000 ? { background: "#fff1f0" } : undefined),
121
- },
122
- };
123
- ```
124
-
125
- 计算列会在**初始化渲染**与**每次单元格变更后**重算。
126
-
127
- ### `reactGridProps` 扩展项
128
-
129
- 除 `ReactGrid` 自身的 props(如 `enableFillHandle`、`enableRangeSelection`、`onSelectionChanged`,
130
- 参考 [@silevis/reactgrid 文档](https://reactgrid.com/))外,本包识别以下键:
131
-
132
- | 键 | 类型 | 说明 |
133
- | ------------------------- | ------------------------- | -------------------------------------------------------------------- |
134
- | `customCellTemplates` | Object | 注册自定义单元格模板(`{ 模板名: 组件 }`),供 `columns[].type` 引用 |
135
- | `highlights` | Array | 高亮单元格/区域;缺省时使用内部维护的高亮状态 |
136
- | `isRowHighlights` | boolean | 为真时按行高亮(单元格 `columnId` 参与判断) |
137
- | `onFocusLocationChanging` | `(cell, rows) => boolean` | 进入编辑态前回调;返回 `false` 阻止进入编辑 |
138
-
139
- `_$actions`、`rowSelection`、`ExpandListTemplate` 三类内置列不会触发 `onFocusLocationChanging`。
140
-
141
- ### Slots
142
-
143
- | 插槽 | 入参 | 说明 |
144
- | ------------------ | ------------------------ | -------------- |
145
- | `tableActionsSlot` | 单元格 props + `rowData` | 覆盖操作列渲染 |
146
- | `actionPrefixSlot` | 同上 | 操作按钮左侧 |
147
- | `actionCenterSlot` | 同上 | 操作按钮中间 |
148
- | `actionSuffixSlot` | 同上 | 操作按钮右侧 |
149
-
150
- ### ref 方法
151
-
152
- `ref.current` 暴露:
153
-
154
- | 字段 | 说明 |
155
- | ------ | ------------------------------------------ |
156
- | `rows` | 当前表格行数据(`ReactGrid` 的 rows 结构) |
157
-
158
- ## 注意事项
159
-
160
- - **提交粒度**:单次变更立即以「单行数组」调用 `onEditSubmit`;一次 `ReactGrid` 变更回调里含多行时按**批量**提交一次。
161
- `onEditSubmit` 抛错会调用 `getList()` 回滚视图。
162
- - **样式**:组件内已 `import "@silevis/reactgrid/styles.css"` 与 `./index.less`;src 直出模式下由消费方打包器编译这些样式。
163
- - **与 `@hzab/list-render` 的关系**:两者互为 `peerDependencies`(来源仓的容器/扩展设计)。
164
- 本仓内同时安装时 `pnpm install` 会提示 `There are cyclic workspace dependencies: edit-table, list-render`,属预期,
165
- 见 [src-direct-compliance-tracking.md](../../../docs/archive/src-direct-compliance-tracking.md)。
166
-
167
- ## 相关文档
168
-
169
- - [消费方接入指南](../../../docs/consumer-access.md)
170
- - [CHANGELOG.md](./CHANGELOG.md)
1
+ # @hzab/edit-table
2
+
3
+ 可编辑表格:基于 `@silevis/reactgrid` 的单元格级编辑表格,支持批量提交、公式列、展开行与自定义单元格模板。
4
+
5
+ - Node.js ≥ 24
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @hzab/edit-table
11
+ ```
12
+
13
+ 本包同时发布到**公共 npm**(`registry.npmjs.org`,public access)与企业私有源(ld / old)。默认源可直接安装,
14
+ 无需额外配置;若团队要求走内网源,见[消费方接入指南 §2](../../../docs/guides/consumer-access.md#2-可选改为从企业私有源安装)。
15
+
16
+ 消费方需自备 peerDependencies:`@ant-design/icons`、`@hzab/form-render`、`@hzab/utils`、`@silevis/reactgrid`、`antd`、`react`、`react-dom`(本包不会随包安装)。
17
+
18
+ > **发布形态**:本包在本仓以**源码直出**方式发布——`main` 指向 `src`,由消费方打包器编译
19
+ > TypeScript 与 `.less` 样式;`@hzab/edit-table/src/*` 深路径同样可直接引用。随包发布的 `dist/` 仅用于
20
+ > 类型解析(`types` → `dist/index.d.ts`),不是运行时入口。消费方需要承担的编译责任见
21
+ > [消费方接入指南 §4](../../../docs/guides/consumer-access.md#4-src-直出包消费方要承担的编译责任)。
22
+
23
+ ## 快速开始
24
+
25
+ 默认导出即组件(内部为 `forwardRef`):
26
+
27
+ ```jsx
28
+ import { useMemo, useRef } from "react";
29
+ import CellEditTable from "@hzab/edit-table";
30
+
31
+ const columns = [
32
+ { key: "name", title: "姓名", width: 120 },
33
+ { key: "age", type: "Number", title: "年龄", width: 80 },
34
+ { key: "birthday", type: "DatePicker", title: "生日", width: 160 },
35
+ { key: "memo", type: "Input.TextArea", title: "备注", width: 200, nonEditable: true },
36
+ ];
37
+
38
+ function Demo() {
39
+ const tableRef = useRef(null);
40
+
41
+ const dataSource = useMemo(
42
+ () => [
43
+ { id: 1, name: "张三", age: 30, birthday: "1994-01-01" },
44
+ { id: 2, name: "李四", age: 28, birthday: "1996-06-15" },
45
+ ],
46
+ [],
47
+ );
48
+
49
+ return (
50
+ <CellEditTable
51
+ ref={tableRef}
52
+ rowKey="id"
53
+ columns={columns}
54
+ dataSource={dataSource}
55
+ onEditSubmit={async (rows) => {
56
+ // rows:本次变更后的整行对象数组(批量编辑时一次提交多行)
57
+ await saveRows(rows);
58
+ }}
59
+ onChange={(row) => console.log("单元格变更", row)}
60
+ getList={() => console.log("提交失败后重新拉取列表")}
61
+ />
62
+ );
63
+ }
64
+ ```
65
+
66
+ ## API
67
+
68
+ ### 组件 Props
69
+
70
+ | 属性 | 类型 | 必须 | 默认值 | 说明 |
71
+ | ----------------- | ---------------------------------------- | ---- | ------- | -------------------------------------------------------------------------------- |
72
+ | `columns` | Array | 是 | - | 列定义,详见「columns 列配置」 |
73
+ | `dataSource` | Array | 是 | - | 数据源;元素需含 `rowKey` 指定的唯一字段 |
74
+ | `rowKey` | string | 否 | `"id"` | 唯一值字段名 |
75
+ | `onEditSubmit` | `(rows) => void \| Promise` | 否 | - | 编辑提交回调,入参为**整行对象数组**;抛错时会调用 `getList()` |
76
+ | `onChange` | `(row) => void` | 否 | - | 单个单元格变更后回调,入参为该行最新数据 |
77
+ | `getList` | `() => void` | 否 | - | 重新拉取列表;`onEditSubmit` 抛错时被调用 |
78
+ | `query` | Object | 否 | - | 列表查询参数;`query.pageNum` 变化时会清空行选中 |
79
+ | `loading` | boolean | 否 | - | 加载中;为真时渲染上一帧行数据并显示 `Spin` |
80
+ | `headerRowHeight` | number | 否 | `44` | 表头行高 |
81
+ | `rowHeight` | number | 否 | `44` | 数据行高 |
82
+ | `isExpand` | boolean | 否 | `false` | 是否在首列插入展开列,展开 `record.children` 子行 |
83
+ | `rowSelection` | Object | 否 | - | 行选择配置:`width`、`style`、`selectedRowKeys`、`onChange(keys, rows)` |
84
+ | `formulaConfig` | Object | 否 | - | 公式/计算列配置,详见下节 |
85
+ | `reactGridProps` | Object | 否 | `{}` | 透传给 `@silevis/reactgrid` 的 `ReactGrid`,另含本包扩展项(见下节) |
86
+ | `reactGridStyle` | Object | 否 | - | 外层容器 `div` 的行内样式 |
87
+ | `className` | string | 否 | - | 外层容器 `div` 的 className |
88
+ | `onRow` | `(record, rowIndex, colIndex) => Object` | 否 | - | 逐单元格回调,返回值会合并进该单元格定义(可覆盖 `text` / `value` / `style` 等) |
89
+ | `Slots` | Object | 否 | - | 插槽,详见「Slots」 |
90
+
91
+ ### columns 列配置
92
+
93
+ `columns` 元素除自身字段外,会被展开进对应单元格定义。
94
+
95
+ | 字段 | 类型 | 说明 |
96
+ | ------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97
+ | `key` | string | 对应数据字段名(即单元格 `columnId`) |
98
+ | `title` | string \| Function | 表头文案;为函数且返回 ReactElement 时按自定义表头组件渲染(自动包 `WidthWrapHoc`) |
99
+ | `width` | number | 列宽 |
100
+ | `type` | string | 单元格模板类型,默认 `"text"`。内置模板来自 `@hzab/form-render` 的 `antdComponents` 与 `customComponents`,另加本包的 `DatePicker.*` / `Input.*` / `TimePicker.*` 细分项(如 `Number`、`DatePicker`、`Input.TextArea`、`DatePicker.RangePicker`) |
101
+ | `nonEditable` | boolean | 该列不可编辑 |
102
+ | `onCell` | `(record, rowIndex, colIndex) => Object` | 逐单元格回调,返回值合并进单元格定义(优先级高于 `onRow`) |
103
+ | `cellProps` | Object | 直接合并进单元格定义的 props |
104
+ | `children` | Array | 多级表头 |
105
+
106
+ 本包额外提供的内置模板名:`DatePicker.MonthPicker`、`DatePicker.QuarterPicker`、`DatePicker.RangePicker`、
107
+ `DatePicker.TimePicker`、`DatePicker.WeekPicker`、`DatePicker.YearPicker`、`Input.Password`、`Input.Search`、
108
+ `Input.TextArea`、`TimePicker.RangePicker`。
109
+
110
+ ### `formulaConfig`:计算列
111
+
112
+ 以**目标列的 `key`** 为键,声明该列的值与样式如何由整行数据算出:
113
+
114
+ ```js
115
+ const formulaConfig = {
116
+ total: {
117
+ // 返回该列的显示值与值(text 与 value 用同一结果)
118
+ setCellData: (row) => Number(row.price || 0) * Number(row.count || 0),
119
+ // 返回单元格 style;入参为 setCellData 的结果,setCellData 缺省时回退整行
120
+ setCellStyle: (value) => (Number(value) > 1000 ? { background: "#fff1f0" } : undefined),
121
+ },
122
+ };
123
+ ```
124
+
125
+ 计算列会在**初始化渲染**与**每次单元格变更后**重算。
126
+
127
+ ### `reactGridProps` 扩展项
128
+
129
+ 除 `ReactGrid` 自身的 props(如 `enableFillHandle`、`enableRangeSelection`、`onSelectionChanged`,
130
+ 参考 [@silevis/reactgrid 文档](https://reactgrid.com/))外,本包识别以下键:
131
+
132
+ | 键 | 类型 | 说明 |
133
+ | ------------------------- | ------------------------- | -------------------------------------------------------------------- |
134
+ | `customCellTemplates` | Object | 注册自定义单元格模板(`{ 模板名: 组件 }`),供 `columns[].type` 引用 |
135
+ | `highlights` | Array | 高亮单元格/区域;缺省时使用内部维护的高亮状态 |
136
+ | `isRowHighlights` | boolean | 为真时按行高亮(单元格 `columnId` 参与判断) |
137
+ | `onFocusLocationChanging` | `(cell, rows) => boolean` | 进入编辑态前回调;返回 `false` 阻止进入编辑 |
138
+
139
+ `_$actions`、`rowSelection`、`ExpandListTemplate` 三类内置列不会触发 `onFocusLocationChanging`。
140
+
141
+ ### Slots
142
+
143
+ | 插槽 | 入参 | 说明 |
144
+ | ------------------ | ------------------------ | -------------- |
145
+ | `tableActionsSlot` | 单元格 props + `rowData` | 覆盖操作列渲染 |
146
+ | `actionPrefixSlot` | 同上 | 操作按钮左侧 |
147
+ | `actionCenterSlot` | 同上 | 操作按钮中间 |
148
+ | `actionSuffixSlot` | 同上 | 操作按钮右侧 |
149
+
150
+ ### ref 方法
151
+
152
+ `ref.current` 暴露:
153
+
154
+ | 字段 | 说明 |
155
+ | ------ | ------------------------------------------ |
156
+ | `rows` | 当前表格行数据(`ReactGrid` 的 rows 结构) |
157
+
158
+ ## 注意事项
159
+
160
+ - **提交粒度**:单次变更立即以「单行数组」调用 `onEditSubmit`;一次 `ReactGrid` 变更回调里含多行时按**批量**提交一次。
161
+ `onEditSubmit` 抛错会调用 `getList()` 回滚视图。
162
+ - **样式**:组件内已 `import "@silevis/reactgrid/styles.css"` 与 `./index.less`;src 直出模式下由消费方打包器编译这些样式。
163
+ - **与 `@hzab/list-render` 的关系**:两者互为 `peerDependencies`(来源仓的容器/扩展设计)。
164
+ 本仓内同时安装时 `pnpm install` 会提示 `There are cyclic workspace dependencies: edit-table, list-render`,属预期,
165
+ 见仓库内 `docs/archive/src-direct-compliance-tracking.md`。
166
+
167
+ ## 相关文档
168
+
169
+ - [消费方接入指南](../../../docs/guides/consumer-access.md)
170
+ - 版本变更记录见仓库内 `CHANGELOG.md`
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- let e=require("react"),t=require("antd"),n=require("@silevis/reactgrid"),r=require("@hzab/form-render"),i=require("@ant-design/icons"),a=require("react/jsx-runtime"),o=require("react/compiler-runtime"),s=require("@hzab/utils/src/formily/field");require("@silevis/reactgrid/styles.css");var c={"DatePicker.MonthPicker":t.DatePicker.MonthPicker,"DatePicker.QuarterPicker":t.DatePicker.QuarterPicker,"DatePicker.RangePicker":t.DatePicker.RangePicker,"DatePicker.TimePicker":t.DatePicker.TimePicker,"DatePicker.WeekPicker":t.DatePicker.WeekPicker,"DatePicker.YearPicker":t.DatePicker.YearPicker,"Input.Password":t.Input.Password,"Input.Search":t.Input.Search,"Input.TextArea":t.Input.TextArea,"TimePicker.RangePicker":t.TimePicker.RangePicker},l=[`DatePicker`,`DatePicker.MonthPicker`,`DatePicker.QuarterPicker`,`DatePicker.RangePicker`,`DatePicker.TimePicker`,`DatePicker.WeekPicker`,`DatePicker.YearPicker`,`TimePicker.RangePicker`],u=(r,o={})=>{class s{getCompatibleCell(e){let t;try{t=(0,n.getCellProperty)(e,`values`,`object`)}catch{t=[]}let r=e.selectedValue?parseFloat(e.selectedValue):NaN,i=!0;try{i=(0,n.getCellProperty)(e,`isDisabled`,`boolean`)}catch{i=!1}let a=e.selectedValue,o=a||``;return{...e,selectedValue:a,text:o,value:r,values:t,isDisabled:i}}update(e,t){let n=e.values.some(e=>e.value==t.text)?t.text:t?.text||void 0;return this.getCompatibleCell({...e,selectedValue:n})}getClassName(e,t){return``}handleCompositionEnd(e,t){return{cell:{...e},enableEditMode:!1}}render(s,c,u){let[d,f]=(0,e.useState)(!1),[p,m]=(0,e.useState)(!1),h=s?.columnId+s?.rowId,[g,_]=(0,e.useState)(s?.text),[v,y]=(0,e.useState)(!1),b=(0,e.useRef)(s?.text),x=(0,e.useRef)();(0,e.useEffect)(()=>{_(s?.text),b.current=s?.text},[s?.text]),(0,e.useEffect)(()=>{function e(e){window.gridEditId!=h&&f(!1)}return document.addEventListener(`click`,e),()=>{document.removeEventListener(`click`,e)}},[]);let S=e=>{let t=!1,n=!1;for(let n of s?.validatorList||[]){n?.pattern?.test(e)&&(t=!0);break}n=!t&&Array.isArray(s?.validatorList)&&s?.validatorList?.length>0,y(n)};(0,e.useEffect)(()=>{if(!p)return;let e=setTimeout(()=>{let e=document.querySelector(`.ant-picker-dropdown`);if(!e)return;let t=e=>{e.stopPropagation()};return e.addEventListener(`pointerdown`,t,!0),()=>{e.removeEventListener(`pointerdown`,t,!0)}},0);return()=>clearTimeout(e)},[p]);let C=()=>{let e=b.current;u(this.getCompatibleCell({...s,text:e,selectedValue:e}),!0)},w=(0,e.useMemo)(()=>l?.includes(s?.type)?{open:p,onOpenChange:e=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{m(e)},80)}}:{},[s]);return(0,e.useEffect)(()=>{!d&&s.type==`Upload`&&window.uploadEdit&&window.uploadEdit==h&&(window.uploadEdit=null,C())},[d,g]),(0,a.jsxs)(`div`,{className:`base-hoc ${d?`base-hoc-edit`:``}`,onDoubleClick:e=>{s?.nonEditable||(s.type===`Upload`&&(window.uploadEdit=h),f(!0))},children:[(0,a.jsx)(r,{...o,onPointerDown:e=>e.stopPropagation(),componentProps:{style:{width:`100%`,display:`flex`,alignItems:`center`},value:g,options:s.values,onChange:e=>{let t=e?.target?.value??e;_(t),b.current=t,S(t)},onBlur:e=>{C(),l?.includes(s?.type)||f(!1)},onPointerDown:e=>{e.stopPropagation()},onKeyDown:e=>{((0,n.isAlphaNumericKey)(e.keyCode)||(0,n.isNavigationKey)(e.keyCode))&&e.stopPropagation()},...w,...s?.getField&&s?.getField()[`x-component-props`]||{}},pattern:d?``:`readPretty`,cell:s}),v&&(0,a.jsx)(t.Popover,{content:s?.validatorMessage??`该字段不合法`,children:(0,a.jsx)(i.InfoCircleOutlined,{className:`validator-icon`})})]})}}return new s},d=t=>{let{pattern:n,cell:r,componentProps:i,Com:o,cellRender:c}=t,l=(0,e.useMemo)(()=>{if(r?.getField)return(0,s.getVal)({...r?.getField&&r?.getField(),enum:r?.getField()?.enum||r?.values},{[r?.getField&&r?.getField().name]:r.text})},[r]);return c&&c(t)?(0,a.jsx)(c,{...t}):(0,a.jsx)(`div`,{className:`base-hoc`,children:n==`readPretty`?(0,a.jsx)(`div`,{children:l}):(0,a.jsx)(o,{className:`rg-input`,ref:e=>{e&&e.focus()},...i})})},f=e=>{let n=(0,o.c)(5),r=e?.componentProps,i;n[0]===r?i=n[1]:(i={...r,type:`number`},n[0]=r,n[1]=i);let s;return n[2]!==e||n[3]!==i?(s=(0,a.jsx)(d,{...e,componentProps:i,Com:t.Input}),n[2]=e,n[3]=i,n[4]=s):s=n[4],s},p=t=>{let n=(0,o.c)(21),{cell:r}=t,{setExpandKeys:s,expandKeys:c,rowKey:l,setNewDataSource:u,record:d}=r,[f,p]=(0,e.useState)(!1),m;n[0]!==d||n[1]!==l||n[2]!==u?(m=e=>{u(t=>{let n=[...t],r=d?.children?.map(e=>e?.[l]);if(e){let e=t?.findIndex(e=>e?.[l]==d?.[l]);return(t?.filter(e=>r?.includes(e?.[l]))||[])?.length==0&&n.splice(e+1,0,...d?.children||[]),[...n]}return t?.filter(e=>!r?.includes(e?.[l]))})},n[0]=d,n[1]=l,n[2]=u,n[3]=m):m=n[3];let h=m,g;n[4]!==c||n[5]!==h||n[6]!==d||n[7]!==l?(g=()=>{c?.includes(d?.[l])&&(p(!0),h(!0))},n[4]=c,n[5]=h,n[6]=d,n[7]=l,n[8]=g):g=n[8];let _=r?.record,v;n[9]===_?v=n[10]:(v=[_],n[9]=_,n[10]=v),(0,e.useEffect)(g,v);let y;n[11]!==f||n[12]!==h||n[13]!==d||n[14]!==l||n[15]!==s?(y=()=>{s(e=>e?.includes(d?.[l])?e?.filter(e=>e!=d?.[l]):[...e,d?.[l]]),p(!f),h(!f)},n[11]=f,n[12]=h,n[13]=d,n[14]=l,n[15]=s,n[16]=y):y=n[16];let b=y,x;return n[17]!==f||n[18]!==b||n[19]!==d?.children?(x=(0,a.jsx)(`div`,{className:`expandList-template`,children:d?.children?(0,a.jsx)(a.Fragment,{children:f?(0,a.jsx)(i.MinusCircleOutlined,{className:`expandList-template-icon`,onClick:b}):(0,a.jsx)(i.PlusCircleOutlined,{className:`expandList-template-icon`,onClick:b})}):(0,a.jsx)(`div`,{style:{width:14}})}),n[17]=f,n[18]=b,n[19]=d?.children,n[20]=x):x=n[20],x};function m(e){return typeof e==`object`&&!!e}var h=e=>typeof e?.title==`function`?m(e?.title())?e?.title()?.props.children:String(e?.title())||``:String(e?.title)||``;function g(e,t=40){let n=e=>e.reduce((e,t)=>t.children?.length?[...e,...n(t.children)]:[...e,t],[]),r=(e,t=1)=>e.reduce((e,n)=>n.children?.length?Math.max(e,r(n.children,t+1)):Math.max(e,t),t),i=n(e),a=r(e),o=i.length,s=(e,t=0)=>e.map(e=>{if(!(e.children?.length>0))return{...e,rowspan:a-t,colspan:1,_depth:t,_isLeaf:!0};let r=n(e.children).length;return{...e,rowspan:1,colspan:r,_depth:t,_isLeaf:!1,children:s(e.children,t+1)}}),c=s(e,0),l=Array.from({length:a},(e,n)=>({rowId:`header-${n}`,height:t,cells:[]})),u=e=>[`rowSelection`,`ExpandListTemplate`].includes(e?.type)?e?.type:m(typeof e?.title==`function`?e?.title():null)?`${e?.dataIndex}`:`header`,d=(e,t=0)=>{e.forEach(e=>{if(e._isLeaf){let n={...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:e.rowspan,style:e?.style?e?.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}};e.sorter&&(n.sorter=e.sorter),e.key&&(n.key=e.key),l[t].cells.push(n)}else l[t].cells.push({...e,type:u(e),text:h(e),colspan:e.colspan,style:e?.style?e?.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),e.children&&d(e.children,t+1)})};d(c,0),l.forEach((e,t)=>{let n=[],r=0,s=0;for(;r<o;){let o=e.cells[s];if(!o){let e=i[r];n.push({...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:t===a-1?1:void 0,style:e?.style?e?.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),r++,s++;continue}let c=o.colspan||1;if((o.rowspan||1)>1&&t>0){r+=c,s++;continue}n.push(o),r+=c,s++;for(let e=1;e<c;e++)n.push({type:`header`,text:``})}e.cells=n});let f=l[a-1],p=[];return i.forEach((e,t)=>{let n=f.cells.find(t=>t.dataIndex===e.dataIndex&&t.text===e.title);n?p.push(n):p.push({...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:1,style:e?.style?e?.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}})}),f.cells=p,l.forEach(e=>{for(;e.cells.length<o;)e.cells.push({type:`header`,text:``})}),l}function _(e){let t=[];function n(e){e.forEach(e=>{if(e.children&&e.children.length>0)n(e.children);else{let{title:n,dataIndex:r,key:i,width:a,sorter:o,k:s,...c}=e;t.push({type:`Input`,dataIndex:r,title:n,...i&&{key:i},...a&&{width:a},...o&&{sorter:o},...s&&{k:s},...c})}})}return n(e),t}function v(i,o){let{columns:s,dataSource:l,formulaConfig:h,onChange:v,reactGridProps:y={},onEditSubmit:b,headerRowHeight:x=44,rowHeight:S=44,reactGridStyle:C,className:w,Slots:T,rowSelection:E,rowKey:D=`id`,query:O,loading:k,isExpand:A=!1,getList:j,onRow:M}=i,[N,P]=(0,e.useState)([]),[F,I]=(0,e.useState)([]),L=(0,e.useRef)([]),[R,z]=(0,e.useState)([]),[B,V]=(0,e.useState)([]),[H,U]=(0,e.useState)([]),[W,G]=(0,e.useState)([]),[K,ee]=(0,e.useState)([]),[te,q]=(0,e.useState)([]),J=(0,e.useRef)(),ne=(0,e.useRef)(),Y=(0,e.useRef)();(0,e.useImperativeHandle)(o,()=>({rows:F}));let X=(e,t=0)=>{e?.forEach(e=>{e.level=t+1,e?.children&&X(e?.children,e.level)})};(0,e.useEffect)(()=>{X(l),U(l)},[l]),(0,e.useEffect)(()=>{F.map(e=>e.rowId)?.includes(J.current)||q([])},[F]);let re=e=>{let t=e?.cells?.[0]?.record,n=[`_$actions`,`rowSelection`],r={id:e?.rowId};return e?.cells?.forEach(e=>{e?.columnId&&!n?.includes(e?.columnId)&&(r[e?.columnId]=e?.text||e?.value||e?.selectedValue||``,e?.type==`Number`&&(r[e?.columnId]=e?.value))}),{...t,...r}};(0,e.useEffect)(()=>{if(Array.isArray(s)&&s?.length>0){A&&s.unshift({type:`ExpandListTemplate`,width:14,key:`ExpandListTemplate`,nonEditable:!0,style:E?.style||{background:`rgba(128, 128, 128, 0.1)`}}),E&&s.unshift({type:`rowSelection`,nonEditable:!0,width:E?.width||30,key:`rowSelection`,style:E?.style||{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),P(g(s,x));let e=_(s);z(e?.map((e,t)=>({...e,columnId:e?.dataIndex||e?.key||e?.name||``})))}},[s,E]);let Z={},Q=e=>{e?.forEach(e=>{if(m(typeof e?.title==`function`?e?.title():null)){let t=e?.title;Z[e?.dataIndex]=u(t)}e?.children&&Q(e?.children)})};(0,e.useEffect)(()=>{Q(s),ee(Z)},[s]),(0,e.useEffect)(()=>{let e=R?.map(e=>e?.columnId),t=H?.map((t,n)=>({rowId:t[D],height:S,cells:e?.map((e,r)=>{let i={},a=R[r],o=t[e],s=a?.type??`text`;if(h){for(let n in h)if(n==e){let e=h[n];i={text:e?.setCellData&&e?.setCellData(t),value:e?.setCellData&&e?.setCellData(t),style:e?.setCellStyle&&e?.setCellStyle(e?.setCellData&&e?.setCellData(t)||t)}}}return{...a,record:t,rowId:t[D]||a?.type,type:s,nonEditable:a?.nonEditable,text:String(o||``),value:o,selectedValue:o||``,style:a?.type==`rowSelection`?{display:`flex`,justifyContent:`center`}:{},...M&&M(t,n,r)||{},...a?.onCell&&a?.onCell(t,n,r)||{},...a?.cellProps||{},setNewDataSource:U,setExpandKeys:G,rowKey:D,expandKeys:W,Slots:T,...i}})})),n=[...N,...t];I(n)},[H,R,N]),(0,e.useEffect)(()=>{k&&((F?.find(e=>e?.rowId==Y.current?.rowId))?.cells?.find(e=>e?.columnId==Y.current?.columnId),{...Y.current},L.current=F)},[k,F]);let ie=async e=>{let t=[];if(!Array.isArray(e)||e.length===0)return;let n=!1;if(e?.length>1&&(n=!0),I(r=>(e.forEach(async e=>{let i=r.findIndex(t=>t.rowId==e.rowId),a=R.findIndex(t=>t.columnId==e.columnId);if(r[i].cells[a]={...e.newCell},Y.current={...e.newCell},t.push(re(r[i])),h)for(let e in h){let t=h[e],n=R.findIndex(t=>t.columnId==e),a={...r[i].cells[n],text:t?.setCellData&&t?.setCellData(r[i]),value:t?.setCellData&&t?.setCellData(r[i]),style:t?.setCellStyle&&t?.setCellStyle(t?.setCellData&&t?.setCellData(r[i])||r[i])};r[i].cells[n]=a}if(b&&!n)try{await b(t)}catch{j&&j()}v&&v(r[i])}),[...r])),n)try{b&&await b(t)}catch{j&&j()}},ae=(0,e.useMemo)(()=>{let e={...r.antdComponents||{},...r.customComponents||{},...c},t={};for(let n in e)t[n]=u(t=>(0,a.jsx)(d,{...t,...i,Com:e[n]}));return t},[r.antdComponents,r.customComponents]),oe=e=>{let t=F?.find(t=>t?.rowId==e?.cell?.rowId);return(0,a.jsxs)(`div`,{onPointerDown:e=>e.stopPropagation(),children:[T?.tableActionsSlot&&(0,a.jsx)(T.tableActionsSlot,{...e?.cell,rowData:t}),T?.actionPrefixSlot&&(0,a.jsx)(T.actionPrefixSlot,{...e?.cell,rowData:t}),T?.actionCenterSlot&&(0,a.jsx)(T.actionCenterSlot,{...e?.cell,rowData:t}),T?.actionSuffixSlot&&(0,a.jsx)(T.actionSuffixSlot,{...e?.cell,rowData:t})]})};function $(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&r.children.length&&n(r.children)}return n(e),t}let se=e=>{let{record:n,rowId:r}=e?.cell,i=$(l);return(0,a.jsx)(t.Checkbox,{...e?.componentProps,checked:E?.selectedRowKeys?.includes(n&&n[D]||``)||E?.selectedRowKeys?.length==i?.length&&i?.length>0,indeterminate:!r&&E?.selectedRowKeys?.length>0&&E?.selectedRowKeys?.length<i?.length,onChange:e=>{if(e.target.checked&&r){let e=[...E?.selectedRowKeys,n[D]],t=i?.filter(t=>e?.includes(t[D]));E?.onChange(e,t)}else if(!e.target.checked&&r){let e=E?.selectedRowKeys?.filter(e=>e!=n[D]),t=i?.filter(t=>e?.includes(t[D]));E?.onChange(E?.selectedRowKeys?.filter(e=>e!=n[D]),t)}else if(e.target.checked&&!r){let e=i?.map(e=>e[D]),t=i?.filter(t=>e?.includes(t[D]));E?.onChange(i?.map(e=>e[D]),t)}else!e.target.checked&&!r&&E?.onChange([],[])}})};(0,e.useEffect)(()=>{if(E){let e=$(l)?.filter(e=>B?.includes(e[D]));E?.onChange(B,e)}},[B,l]),(0,e.useEffect)(()=>{V([])},[O?.pageNum]);let ce=(0,e.useMemo)(()=>{let e={};for(let t in y?.customCellTemplates){let n=y?.customCellTemplates[t];e[t]=u(n)}return e},[y?.customCellTemplates]),le=(e,t)=>{let n=t?.find(t=>t?.rowId==e?.rowId)?.cells?.map(t=>({columnId:t?.columnId,rowId:e?.rowId,className:`custom-highlights-row`,borderColor:`transparent`}));J.current=e?.rowId,q(n)};return(0,a.jsx)(t.Spin,{spinning:k,children:(0,a.jsxs)(`div`,{className:`grid-container ${w}`,style:C,children:[(0,a.jsx)(n.ReactGrid,{ref:ne,rows:k?L.current:F,columns:R,onCellsChanged:ie,enableFillHandle:!0,enableRangeSelection:!0,horizontalStickyBreakpoint:120,...y,highlights:y?.highlights??te,onFocusLocationChanging:e=>{let t=e?.columnId+e?.rowId;return window.gridEditId=t,typeof e?.rowId==`string`&&e?.rowId?.indexOf(`header-`)>-1||(y?.isRowHighlights&&e?.columnId&&le(e,F),[`_$actions`,`rowSelection`,`ExpandListTemplate`].includes(e?.columnId))?!1:y?.onFocusLocationChanging?y?.onFocusLocationChanging(e,F):e},customCellTemplates:{ExpandListTemplate:u(p),...ae,...ce,...K,_$actions:u(oe),rowSelection:u(se),Number:u(f,i)}},l?.length==0?0:1),l?.length<=0&&(0,a.jsx)(`div`,{className:`grid-container-empty`,children:(0,a.jsx)(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE})})]})})}var y=(0,e.forwardRef)(v);module.exports=y;
1
+ let e=require("react"),t=require("antd"),n=require("@silevis/reactgrid"),r=require("@hzab/form-render"),i=require("@ant-design/icons"),a=require("react/jsx-runtime"),o=require("react/compiler-runtime"),s=require("@hzab/utils/src/formily/field");require("@silevis/reactgrid/styles.css");var c={"DatePicker.MonthPicker":t.DatePicker.MonthPicker,"DatePicker.QuarterPicker":t.DatePicker.QuarterPicker,"DatePicker.RangePicker":t.DatePicker.RangePicker,"DatePicker.TimePicker":t.DatePicker.TimePicker,"DatePicker.WeekPicker":t.DatePicker.WeekPicker,"DatePicker.YearPicker":t.DatePicker.YearPicker,"Input.Password":t.Input.Password,"Input.Search":t.Input.Search,"Input.TextArea":t.Input.TextArea,"TimePicker.RangePicker":t.TimePicker.RangePicker},l=[`DatePicker`,`DatePicker.MonthPicker`,`DatePicker.QuarterPicker`,`DatePicker.RangePicker`,`DatePicker.TimePicker`,`DatePicker.WeekPicker`,`DatePicker.YearPicker`,`TimePicker.RangePicker`],u=(r,o={})=>{class s{getCompatibleCell(e){let t;try{t=(0,n.getCellProperty)(e,`values`,`object`)}catch(e){t=[]}let r=e.selectedValue?parseFloat(e.selectedValue):NaN,i=!0;try{i=(0,n.getCellProperty)(e,`isDisabled`,`boolean`)}catch(e){i=!1}let a=e.selectedValue,o=a||``;return{...e,selectedValue:a,text:o,value:r,values:t,isDisabled:i}}update(e,t){let n=e.values.some(e=>e.value==t.text)?t.text:(t==null?void 0:t.text)||void 0;return this.getCompatibleCell({...e,selectedValue:n})}getClassName(e,t){return``}handleCompositionEnd(e,t){return{cell:{...e},enableEditMode:!1}}render(s,c,u){var d;let[f,p]=(0,e.useState)(!1),[m,h]=(0,e.useState)(!1),g=(s==null?void 0:s.columnId)+(s==null?void 0:s.rowId),[_,v]=(0,e.useState)(s==null?void 0:s.text),[y,b]=(0,e.useState)(!1),x=(0,e.useRef)(s==null?void 0:s.text),S=(0,e.useRef)();(0,e.useEffect)(()=>{v(s==null?void 0:s.text),x.current=s==null?void 0:s.text},[s==null?void 0:s.text]),(0,e.useEffect)(()=>{function e(e){window.gridEditId!=g&&p(!1)}return document.addEventListener(`click`,e),()=>{document.removeEventListener(`click`,e)}},[]);let C=e=>{var t;let n=!1,r=!1;for(let t of(s==null?void 0:s.validatorList)||[]){var i;t!=null&&(i=t.pattern)!=null&&i.test(e)&&(n=!0);break}r=!n&&Array.isArray(s==null?void 0:s.validatorList)&&(s==null||(t=s.validatorList)==null?void 0:t.length)>0,b(r)};(0,e.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>{let e=document.querySelector(`.ant-picker-dropdown`);if(!e)return;let t=e=>{e.stopPropagation()};return e.addEventListener(`pointerdown`,t,!0),()=>{e.removeEventListener(`pointerdown`,t,!0)}},0);return()=>clearTimeout(e)},[m]);let w=()=>{let e=x.current;u(this.getCompatibleCell({...s,text:e,selectedValue:e}),!0)},T=(0,e.useMemo)(()=>l!=null&&l.includes(s==null?void 0:s.type)?{open:m,onOpenChange:e=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{h(e)},80)}}:{},[s]);return(0,e.useEffect)(()=>{!f&&s.type==`Upload`&&window.uploadEdit&&window.uploadEdit==g&&(window.uploadEdit=null,w())},[f,_]),(0,a.jsxs)(`div`,{className:`base-hoc ${f?`base-hoc-edit`:``}`,onDoubleClick:e=>{s!=null&&s.nonEditable||(s.type===`Upload`&&(window.uploadEdit=g),p(!0))},children:[(0,a.jsx)(r,{...o,onPointerDown:e=>e.stopPropagation(),componentProps:{style:{width:`100%`,display:`flex`,alignItems:`center`},value:_,options:s.values,onChange:e=>{var t,n;let r=(t=e==null||(n=e.target)==null?void 0:n.value)==null?e:t;v(r),x.current=r,C(r)},onBlur:e=>{w(),l!=null&&l.includes(s==null?void 0:s.type)||p(!1)},onPointerDown:e=>{e.stopPropagation()},onKeyDown:e=>{((0,n.isAlphaNumericKey)(e.keyCode)||(0,n.isNavigationKey)(e.keyCode))&&e.stopPropagation()},...T,...(s==null?void 0:s.getField)&&(s==null?void 0:s.getField()[`x-component-props`])||{}},pattern:f?``:`readPretty`,cell:s}),y&&(0,a.jsx)(t.Popover,{content:(d=s==null?void 0:s.validatorMessage)==null?`该字段不合法`:d,children:(0,a.jsx)(i.InfoCircleOutlined,{className:`validator-icon`})})]})}}return new s},d=t=>{let{pattern:n,cell:r,componentProps:i,Com:o,cellRender:c}=t,l=(0,e.useMemo)(()=>{var e;if(r!=null&&r.getField)return(0,s.getVal)({...(r==null?void 0:r.getField)&&(r==null?void 0:r.getField()),enum:(r==null||(e=r.getField())==null?void 0:e.enum)||(r==null?void 0:r.values)},{[(r==null?void 0:r.getField)&&(r==null?void 0:r.getField().name)]:r.text})},[r]);return c&&c(t)?(0,a.jsx)(c,{...t}):(0,a.jsx)(`div`,{className:`base-hoc`,children:n==`readPretty`?(0,a.jsx)(`div`,{children:l}):(0,a.jsx)(o,{className:`rg-input`,ref:e=>{e&&e.focus()},...i})})},f=e=>{let n=(0,o.c)(5),r=e==null?void 0:e.componentProps,i;n[0]===r?i=n[1]:(i={...r,type:`number`},n[0]=r,n[1]=i);let s;return n[2]!==e||n[3]!==i?(s=(0,a.jsx)(d,{...e,componentProps:i,Com:t.Input}),n[2]=e,n[3]=i,n[4]=s):s=n[4],s},p=t=>{let n=(0,o.c)(21),{cell:r}=t,{setExpandKeys:s,expandKeys:c,rowKey:l,setNewDataSource:u,record:d}=r,[f,p]=(0,e.useState)(!1),m;n[0]!==d||n[1]!==l||n[2]!==u?(m=e=>{u(t=>{var n;let r=[...t],i=d==null||(n=d.children)==null?void 0:n.map(e=>e==null?void 0:e[l]);if(e){let e=t==null?void 0:t.findIndex(e=>(e==null?void 0:e[l])==(d==null?void 0:d[l])),n=(t==null?void 0:t.filter(e=>i==null?void 0:i.includes(e==null?void 0:e[l])))||[];return(n==null?void 0:n.length)==0&&r.splice(e+1,0,...(d==null?void 0:d.children)||[]),[...r]}return t==null?void 0:t.filter(e=>!(i!=null&&i.includes(e==null?void 0:e[l])))})},n[0]=d,n[1]=l,n[2]=u,n[3]=m):m=n[3];let h=m,g;n[4]!==c||n[5]!==h||n[6]!==d||n[7]!==l?(g=()=>{c!=null&&c.includes(d==null?void 0:d[l])&&(p(!0),h(!0))},n[4]=c,n[5]=h,n[6]=d,n[7]=l,n[8]=g):g=n[8];let _=r==null?void 0:r.record,v;n[9]===_?v=n[10]:(v=[_],n[9]=_,n[10]=v),(0,e.useEffect)(g,v);let y;n[11]!==f||n[12]!==h||n[13]!==d||n[14]!==l||n[15]!==s?(y=()=>{s(e=>e!=null&&e.includes(d==null?void 0:d[l])?e==null?void 0:e.filter(e=>e!=(d==null?void 0:d[l])):[...e,d==null?void 0:d[l]]),p(!f),h(!f)},n[11]=f,n[12]=h,n[13]=d,n[14]=l,n[15]=s,n[16]=y):y=n[16];let b=y,x;return n[17]!==f||n[18]!==b||n[19]!==(d==null?void 0:d.children)?(x=(0,a.jsx)(`div`,{className:`expandList-template`,children:d!=null&&d.children?(0,a.jsx)(a.Fragment,{children:f?(0,a.jsx)(i.MinusCircleOutlined,{className:`expandList-template-icon`,onClick:b}):(0,a.jsx)(i.PlusCircleOutlined,{className:`expandList-template-icon`,onClick:b})}):(0,a.jsx)(`div`,{style:{width:14}})}),n[17]=f,n[18]=b,n[19]=d==null?void 0:d.children,n[20]=x):x=n[20],x};function m(e){return typeof e==`object`&&!!e}var h=e=>{var t;return typeof(e==null?void 0:e.title)==`function`?m(e==null?void 0:e.title())?e==null||(t=e.title())==null?void 0:t.props.children:String(e==null?void 0:e.title())||``:String(e==null?void 0:e.title)||``};function g(e,t=40){let n=e=>e.reduce((e,t)=>{var r;return(r=t.children)!=null&&r.length?[...e,...n(t.children)]:[...e,t]},[]),r=(e,t=1)=>e.reduce((e,n)=>{var i;return(i=n.children)!=null&&i.length?Math.max(e,r(n.children,t+1)):Math.max(e,t)},t),i=n(e),a=r(e),o=i.length,s=(e,t=0)=>e.map(e=>{var r;if(!(((r=e.children)==null?void 0:r.length)>0))return{...e,rowspan:a-t,colspan:1,_depth:t,_isLeaf:!0};let i=n(e.children).length;return{...e,rowspan:1,colspan:i,_depth:t,_isLeaf:!1,children:s(e.children,t+1)}}),c=s(e,0),l=Array.from({length:a},(e,n)=>({rowId:`header-${n}`,height:t,cells:[]})),u=e=>{var t;return(t=[`rowSelection`,`ExpandListTemplate`])!=null&&t.includes(e==null?void 0:e.type)?e==null?void 0:e.type:m(typeof(e==null?void 0:e.title)==`function`?e==null?void 0:e.title():null)?`${e==null?void 0:e.dataIndex}`:`header`},d=(e,t=0)=>{e.forEach(e=>{if(e._isLeaf){let n={...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:e.rowspan,style:e!=null&&e.style?e==null?void 0:e.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}};e.sorter&&(n.sorter=e.sorter),e.key&&(n.key=e.key),l[t].cells.push(n)}else l[t].cells.push({...e,type:u(e),text:h(e),colspan:e.colspan,style:e!=null&&e.style?e==null?void 0:e.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),e.children&&d(e.children,t+1)})};d(c,0),l.forEach((e,t)=>{let n=[],r=0,s=0;for(;r<o;){let o=e.cells[s];if(!o){let e=i[r];n.push({...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:t===a-1?1:void 0,style:e!=null&&e.style?e==null?void 0:e.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),r++,s++;continue}let c=o.colspan||1;if((o.rowspan||1)>1&&t>0){r+=c,s++;continue}n.push(o),r+=c,s++;for(let e=1;e<c;e++)n.push({type:`header`,text:``})}e.cells=n});let f=l[a-1],p=[];return i.forEach((e,t)=>{let n=f.cells.find(t=>t.dataIndex===e.dataIndex&&t.text===e.title);n?p.push(n):p.push({...e,type:u(e),text:h(e),dataIndex:e.dataIndex,width:e.width,rowspan:1,style:e!=null&&e.style?e==null?void 0:e.style:{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}})}),f.cells=p,l.forEach(e=>{for(;e.cells.length<o;)e.cells.push({type:`header`,text:``})}),l}function _(e){let t=[];function n(e){e.forEach(e=>{if(e.children&&e.children.length>0)n(e.children);else{let{title:n,dataIndex:r,key:i,width:a,sorter:o,k:s,...c}=e;t.push({type:`Input`,dataIndex:r,title:n,...i&&{key:i},...a&&{width:a},...o&&{sorter:o},...s&&{k:s},...c})}})}return n(e),t}function v(i,o){var s;let{columns:l,dataSource:h,formulaConfig:v,onChange:y,reactGridProps:b={},onEditSubmit:x,headerRowHeight:S=44,rowHeight:C=44,reactGridStyle:w,className:T,Slots:E,rowSelection:D,rowKey:O=`id`,query:k,loading:A,isExpand:j=!1,getList:M,onRow:N}=i,[P,F]=(0,e.useState)([]),[I,L]=(0,e.useState)([]),R=(0,e.useRef)([]),[z,B]=(0,e.useState)([]),[V,H]=(0,e.useState)([]),[U,W]=(0,e.useState)([]),[G,K]=(0,e.useState)([]),[ee,te]=(0,e.useState)([]),[ne,q]=(0,e.useState)([]),J=(0,e.useRef)(),re=(0,e.useRef)(),Y=(0,e.useRef)();(0,e.useImperativeHandle)(o,()=>({rows:I}));let X=(e,t=0)=>{e==null||e.forEach(e=>{e.level=t+1,e!=null&&e.children&&X(e==null?void 0:e.children,e.level)})};(0,e.useEffect)(()=>{X(h),W(h)},[h]),(0,e.useEffect)(()=>{let e=I.map(e=>e.rowId);e!=null&&e.includes(J.current)||q([])},[I]);let ie=e=>{var t,n;let r=e==null||(t=e.cells)==null||(t=t[0])==null?void 0:t.record,i=[`_$actions`,`rowSelection`],a={id:e==null?void 0:e.rowId};return e==null||(n=e.cells)==null||n.forEach(e=>{e!=null&&e.columnId&&!(i!=null&&i.includes(e==null?void 0:e.columnId))&&(a[e==null?void 0:e.columnId]=(e==null?void 0:e.text)||(e==null?void 0:e.value)||(e==null?void 0:e.selectedValue)||``,(e==null?void 0:e.type)==`Number`&&(a[e==null?void 0:e.columnId]=e==null?void 0:e.value))}),{...r,...a}};(0,e.useEffect)(()=>{if(Array.isArray(l)&&(l==null?void 0:l.length)>0){j&&l.unshift({type:`ExpandListTemplate`,width:14,key:`ExpandListTemplate`,nonEditable:!0,style:(D==null?void 0:D.style)||{background:`rgba(128, 128, 128, 0.1)`}}),D&&l.unshift({type:`rowSelection`,nonEditable:!0,width:(D==null?void 0:D.width)||30,key:`rowSelection`,style:(D==null?void 0:D.style)||{background:`rgba(128, 128, 128, 0.1)`,display:`flex`,justifyContent:`center`}}),F(g(l,S));let e=_(l);B(e==null?void 0:e.map((e,t)=>({...e,columnId:(e==null?void 0:e.dataIndex)||(e==null?void 0:e.key)||(e==null?void 0:e.name)||``})))}},[l,D]);let Z={},Q=e=>{e==null||e.forEach(e=>{if(m(typeof(e==null?void 0:e.title)==`function`?e==null?void 0:e.title():null)){let t=e==null?void 0:e.title;Z[e==null?void 0:e.dataIndex]=u(t)}e!=null&&e.children&&Q(e==null?void 0:e.children)})};(0,e.useEffect)(()=>{Q(l),te(Z)},[l]),(0,e.useEffect)(()=>{let e=z==null?void 0:z.map(e=>e==null?void 0:e.columnId),t=U==null?void 0:U.map((t,n)=>({rowId:t[O],height:C,cells:e==null?void 0:e.map((e,r)=>{var i;let a={},o=z[r],s=t[e],c=(i=o==null?void 0:o.type)==null?`text`:i;if(v){for(let n in v)if(n==e){let e=v[n];a={text:(e==null?void 0:e.setCellData)&&(e==null?void 0:e.setCellData(t)),value:(e==null?void 0:e.setCellData)&&(e==null?void 0:e.setCellData(t)),style:(e==null?void 0:e.setCellStyle)&&(e==null?void 0:e.setCellStyle((e==null?void 0:e.setCellData)&&(e==null?void 0:e.setCellData(t))||t))}}}return{...o,record:t,rowId:t[O]||(o==null?void 0:o.type),type:c,nonEditable:o==null?void 0:o.nonEditable,text:String(s||``),value:s,selectedValue:s||``,style:(o==null?void 0:o.type)==`rowSelection`?{display:`flex`,justifyContent:`center`}:{},...N&&N(t,n,r)||{},...(o==null?void 0:o.onCell)&&(o==null?void 0:o.onCell(t,n,r))||{},...(o==null?void 0:o.cellProps)||{},setNewDataSource:W,setExpandKeys:K,rowKey:O,expandKeys:G,Slots:E,...a}})})),n=[...P,...t];L(n)},[U,z,P]),(0,e.useEffect)(()=>{if(A){var e;let t=I==null?void 0:I.find(e=>{var t;return(e==null?void 0:e.rowId)==((t=Y.current)==null?void 0:t.rowId)});t==null||(e=t.cells)==null||e.find(e=>{var t;return(e==null?void 0:e.columnId)==((t=Y.current)==null?void 0:t.columnId)}),{...Y.current},R.current=I}},[A,I]);let ae=async e=>{let t=[];if(!Array.isArray(e)||e.length===0)return;let n=!1;if((e==null?void 0:e.length)>1&&(n=!0),L(r=>(e.forEach(async e=>{let i=r.findIndex(t=>t.rowId==e.rowId),a=z.findIndex(t=>t.columnId==e.columnId);if(r[i].cells[a]={...e.newCell},Y.current={...e.newCell},t.push(ie(r[i])),v)for(let e in v){let t=v[e],n=z.findIndex(t=>t.columnId==e),a={...r[i].cells[n],text:(t==null?void 0:t.setCellData)&&(t==null?void 0:t.setCellData(r[i])),value:(t==null?void 0:t.setCellData)&&(t==null?void 0:t.setCellData(r[i])),style:(t==null?void 0:t.setCellStyle)&&(t==null?void 0:t.setCellStyle((t==null?void 0:t.setCellData)&&(t==null?void 0:t.setCellData(r[i]))||r[i]))};r[i].cells[n]=a}if(x&&!n)try{await x(t)}catch(e){M&&M()}y&&y(r[i])}),[...r])),n)try{x&&await x(t)}catch(e){M&&M()}},oe=(0,e.useMemo)(()=>{let e={...r.antdComponents||{},...r.customComponents||{},...c},t={};for(let n in e)t[n]=u(t=>(0,a.jsx)(d,{...t,...i,Com:e[n]}));return t},[r.antdComponents,r.customComponents]),se=e=>{let t=I==null?void 0:I.find(t=>{var n;return(t==null?void 0:t.rowId)==(e==null||(n=e.cell)==null?void 0:n.rowId)});return(0,a.jsxs)(`div`,{onPointerDown:e=>e.stopPropagation(),children:[(E==null?void 0:E.tableActionsSlot)&&(0,a.jsx)(E.tableActionsSlot,{...e==null?void 0:e.cell,rowData:t}),(E==null?void 0:E.actionPrefixSlot)&&(0,a.jsx)(E.actionPrefixSlot,{...e==null?void 0:e.cell,rowData:t}),(E==null?void 0:E.actionCenterSlot)&&(0,a.jsx)(E.actionCenterSlot,{...e==null?void 0:e.cell,rowData:t}),(E==null?void 0:E.actionSuffixSlot)&&(0,a.jsx)(E.actionSuffixSlot,{...e==null?void 0:e.cell,rowData:t})]})};function $(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&r.children.length&&n(r.children)}return n(e),t}let ce=e=>{var n,r,i,o,s,c;let{record:l,rowId:u}=e==null?void 0:e.cell,d=(n=$(h))==null?void 0:n.filter(e=>{var t;return!(D!=null&&(t=D.getCheckboxProps)!=null&&(t=t.call(D,e))!=null&&t.disabled)}),f=typeof(D==null?void 0:D.getCheckboxProps)==`function`?D==null||(r=D.getCheckboxProps)==null?void 0:r.call(D,l):{};return(0,a.jsx)(t.Checkbox,{...e==null?void 0:e.componentProps,checked:(D==null||(i=D.selectedRowKeys)==null?void 0:i.includes(l&&l[O]||``))||!u&&(D==null||(o=D.selectedRowKeys)==null?void 0:o.length)==(d==null?void 0:d.length)&&(d==null?void 0:d.length)>0,indeterminate:!u&&(D==null||(s=D.selectedRowKeys)==null?void 0:s.length)>0&&(D==null||(c=D.selectedRowKeys)==null?void 0:c.length)<(d==null?void 0:d.length),onChange:e=>{if(e.target.checked&&u){let e=[...D==null?void 0:D.selectedRowKeys,l[O]],t=d==null?void 0:d.filter(t=>e==null?void 0:e.includes(t[O]));D==null||D.onChange(e,t)}else if(!e.target.checked&&u){var t,n;let e=D==null||(t=D.selectedRowKeys)==null?void 0:t.filter(e=>e!=l[O]),r=d==null?void 0:d.filter(t=>e==null?void 0:e.includes(t[O]));D==null||D.onChange(D==null||(n=D.selectedRowKeys)==null?void 0:n.filter(e=>e!=l[O]),r)}else if(e.target.checked&&!u){let e=d==null?void 0:d.map(e=>e[O]),t=d==null?void 0:d.filter(t=>e==null?void 0:e.includes(t[O]));D==null||D.onChange(d==null?void 0:d.map(e=>e[O]),t)}else!e.target.checked&&!u&&(D==null||D.onChange([],[]))},...f})};(0,e.useEffect)(()=>{if(D){var e;let t=(e=$(h))==null?void 0:e.filter(e=>{var t;return!(D!=null&&(t=D.getCheckboxProps)!=null&&(t=t.call(D,e))!=null&&t.disabled)}),n=t==null?void 0:t.filter(e=>V==null?void 0:V.includes(e[O]));D==null||D.onChange(V,n)}},[V,h]),(0,e.useEffect)(()=>{H([])},[k==null?void 0:k.pageNum]);let le=(0,e.useMemo)(()=>{let e={};for(let t in b==null?void 0:b.customCellTemplates)e[t]=u(b==null?void 0:b.customCellTemplates[t]);return e},[b==null?void 0:b.customCellTemplates]),ue=(e,t)=>{var n;let r=t==null||(n=t.find(t=>(t==null?void 0:t.rowId)==(e==null?void 0:e.rowId)))==null||(n=n.cells)==null?void 0:n.map(t=>({columnId:t==null?void 0:t.columnId,rowId:e==null?void 0:e.rowId,className:`custom-highlights-row`,borderColor:`transparent`}));J.current=e==null?void 0:e.rowId,q(r)};return(0,a.jsx)(t.Spin,{spinning:A,children:(0,a.jsxs)(`div`,{className:`grid-container ${T}`,style:w,children:[(0,a.jsx)(n.ReactGrid,{ref:re,rows:A?R.current:I,columns:z,onCellsChanged:ae,enableFillHandle:!0,enableRangeSelection:!0,horizontalStickyBreakpoint:120,...b,highlights:(s=b==null?void 0:b.highlights)==null?ne:s,onFocusLocationChanging:e=>{var t,n;let r=(e==null?void 0:e.columnId)+(e==null?void 0:e.rowId);return window.gridEditId=r,typeof(e==null?void 0:e.rowId)==`string`&&(e==null||(t=e.rowId)==null?void 0:t.indexOf(`header-`))>-1||(b!=null&&b.isRowHighlights&&e!=null&&e.columnId&&ue(e,I),(n=[`_$actions`,`rowSelection`,`ExpandListTemplate`])!=null&&n.includes(e==null?void 0:e.columnId))?!1:b!=null&&b.onFocusLocationChanging?b==null?void 0:b.onFocusLocationChanging(e,I):e},customCellTemplates:{ExpandListTemplate:u(p),...oe,...le,...ee,_$actions:u(se),rowSelection:u(ce),Number:u(f,i)}},(h==null?void 0:h.length)==0?0:1),(h==null?void 0:h.length)<=0&&(0,a.jsx)(`div`,{className:`grid-container-empty`,children:(0,a.jsx)(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE})})]})})}var y=(0,e.forwardRef)(v);module.exports=y;