@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.
Files changed (284) hide show
  1. package/README.md +11 -0
  2. package/lib/cjs/body/index.js +110 -0
  3. package/lib/cjs/body/wrapper.js +132 -0
  4. package/lib/cjs/cell/aggregated.js +76 -0
  5. package/lib/cjs/cell/dependency.js +97 -0
  6. package/lib/cjs/cell/editing.js +89 -0
  7. package/lib/cjs/cell/footer.js +64 -0
  8. package/lib/cjs/cell/header.js +76 -0
  9. package/lib/cjs/cell/index.js +204 -0
  10. package/lib/cjs/const.js +35 -0
  11. package/lib/cjs/container/base.js +39 -0
  12. package/lib/cjs/container/bottom.js +86 -0
  13. package/lib/cjs/container/col-group.js +98 -0
  14. package/lib/cjs/container/column-virtual.js +53 -0
  15. package/lib/cjs/container/ctx.js +32 -0
  16. package/lib/cjs/container/full-virtual.js +61 -0
  17. package/lib/cjs/container/hooks.js +102 -0
  18. package/lib/cjs/container/index.js +69 -0
  19. package/lib/cjs/container/row-virtual.js +50 -0
  20. package/lib/cjs/container/wrapper.js +97 -0
  21. package/lib/cjs/ctx.js +32 -0
  22. package/lib/cjs/features/_overrides/aggregated.js +44 -0
  23. package/lib/cjs/features/_overrides/getter.js +61 -0
  24. package/lib/cjs/features/_overrides/grouping.js +40 -0
  25. package/lib/cjs/features/_overrides/overrides.js +43 -0
  26. package/lib/cjs/features/_overrides/row-selection.js +140 -0
  27. package/lib/cjs/features/async-data/getter.js +150 -0
  28. package/lib/cjs/features/async-data/normal.js +145 -0
  29. package/lib/cjs/features/async-data/use-data-fetcher.js +40 -0
  30. package/lib/cjs/features/async-data/use-reset-data.js +91 -0
  31. package/lib/cjs/features/column-grouping/get-grouping-config.js +27 -0
  32. package/lib/cjs/features/column-grouping/use-opts.js +42 -0
  33. package/lib/cjs/features/column-state.js +57 -0
  34. package/lib/cjs/features/filter/bridge.js +114 -0
  35. package/lib/cjs/features/filter/filter-fns/date.js +34 -0
  36. package/lib/cjs/features/filter/filter-fns/index.js +23 -0
  37. package/lib/cjs/features/filter/get-filter-config.js +61 -0
  38. package/lib/cjs/features/filter/index.js +29 -0
  39. package/lib/cjs/features/filter/use-opts.js +88 -0
  40. package/lib/cjs/features/header-actions/components/column-collapsing.js +74 -0
  41. package/lib/cjs/features/header-actions/get-actions.js +77 -0
  42. package/lib/cjs/features/pagination/component.js +89 -0
  43. package/lib/cjs/features/pagination/use-opts.js +98 -0
  44. package/lib/cjs/features/pagination/use-state.js +44 -0
  45. package/lib/cjs/features/row-controller.js +265 -0
  46. package/lib/cjs/features/row-edit/actions.js +65 -0
  47. package/lib/cjs/features/row-edit/hooks.js +29 -0
  48. package/lib/cjs/features/row-expanding/use-opts.js +39 -0
  49. package/lib/cjs/features/row-expanding/wrapper.js +74 -0
  50. package/lib/cjs/features/row-operation/buttons.js +91 -0
  51. package/lib/cjs/features/row-operation/cell.js +43 -0
  52. package/lib/cjs/features/row-operation/index.js +21 -0
  53. package/lib/cjs/features/row-operation/wrapper.js +114 -0
  54. package/lib/cjs/features/row-selection/cell.js +114 -0
  55. package/lib/cjs/features/row-selection/const.js +16 -0
  56. package/lib/cjs/features/row-selection/hooks/index.js +29 -0
  57. package/lib/cjs/features/row-selection/hooks/use-click-select.js +70 -0
  58. package/lib/cjs/features/row-selection/hooks/use-opts.js +120 -0
  59. package/lib/cjs/features/row-selection/hooks/use-set-selected-row-keys.js +48 -0
  60. package/lib/cjs/features/row-selection/hooks/use-sync-hover-style.js +86 -0
  61. package/lib/cjs/features/row-selection/indicator.js +173 -0
  62. package/lib/cjs/features/row-selection/wrapper.js +119 -0
  63. package/lib/cjs/features/setting-bridge.js +56 -0
  64. package/lib/cjs/features/sorter/bridge.js +65 -0
  65. package/lib/cjs/features/sorter/get-sorter-config.js +46 -0
  66. package/lib/cjs/features/sorter/index.js +29 -0
  67. package/lib/cjs/features/sorter/use-opts.js +81 -0
  68. package/lib/cjs/field-bridge/bridge.js +104 -0
  69. package/lib/cjs/field-bridge/index.js +58 -0
  70. package/lib/cjs/field-bridge/toolbar.js +53 -0
  71. package/lib/cjs/footer/index.js +99 -0
  72. package/lib/cjs/footer/use-first-cell-patch.js +42 -0
  73. package/lib/cjs/header/index.js +134 -0
  74. package/lib/cjs/header/validate.js +69 -0
  75. package/lib/cjs/hooks/use-get-fields-value.js +62 -0
  76. package/lib/cjs/hooks/use-global-actions.js +65 -0
  77. package/lib/cjs/hooks/use-global-static.js +158 -0
  78. package/lib/cjs/hooks/use-initial-render.js +30 -0
  79. package/lib/cjs/hooks/use-inner-ctx.js +105 -0
  80. package/lib/cjs/hooks/use-props.js +108 -0
  81. package/lib/cjs/hooks/use-table-columns.js +76 -0
  82. package/lib/cjs/hooks/use-table-meta.js +57 -0
  83. package/lib/cjs/hooks/use-update.js +57 -0
  84. package/lib/cjs/index.js +66 -0
  85. package/lib/cjs/index.scss.js +18 -0
  86. package/lib/cjs/table.js +263 -0
  87. package/lib/cjs/utils/cls.js +19 -0
  88. package/lib/cjs/utils/fixed.js +53 -0
  89. package/lib/cjs/utils/grouping.js +42 -0
  90. package/lib/cjs/utils/state-merge.js +43 -0
  91. package/lib/esm/body/index.js +98 -0
  92. package/lib/esm/body/wrapper.js +120 -0
  93. package/lib/esm/cell/aggregated.js +64 -0
  94. package/lib/esm/cell/dependency.js +90 -0
  95. package/lib/esm/cell/editing.js +76 -0
  96. package/lib/esm/cell/footer.js +52 -0
  97. package/lib/esm/cell/header.js +63 -0
  98. package/lib/esm/cell/index.js +192 -0
  99. package/lib/esm/const.js +24 -0
  100. package/lib/esm/container/base.js +27 -0
  101. package/lib/esm/container/bottom.js +74 -0
  102. package/lib/esm/container/col-group.js +85 -0
  103. package/lib/esm/container/column-virtual.js +41 -0
  104. package/lib/esm/container/ctx.js +19 -0
  105. package/lib/esm/container/full-virtual.js +49 -0
  106. package/lib/esm/container/hooks.js +95 -0
  107. package/lib/esm/container/index.js +57 -0
  108. package/lib/esm/container/row-virtual.js +38 -0
  109. package/lib/esm/container/wrapper.js +83 -0
  110. package/lib/esm/ctx.js +17 -0
  111. package/lib/esm/features/_overrides/aggregated.js +39 -0
  112. package/lib/esm/features/_overrides/getter.js +56 -0
  113. package/lib/esm/features/_overrides/grouping.js +35 -0
  114. package/lib/esm/features/_overrides/overrides.js +38 -0
  115. package/lib/esm/features/_overrides/row-selection.js +135 -0
  116. package/lib/esm/features/async-data/getter.js +143 -0
  117. package/lib/esm/features/async-data/normal.js +133 -0
  118. package/lib/esm/features/async-data/use-data-fetcher.js +34 -0
  119. package/lib/esm/features/async-data/use-reset-data.js +79 -0
  120. package/lib/esm/features/column-grouping/get-grouping-config.js +22 -0
  121. package/lib/esm/features/column-grouping/use-opts.js +36 -0
  122. package/lib/esm/features/column-state.js +51 -0
  123. package/lib/esm/features/filter/bridge.js +102 -0
  124. package/lib/esm/features/filter/filter-fns/date.js +28 -0
  125. package/lib/esm/features/filter/filter-fns/index.js +18 -0
  126. package/lib/esm/features/filter/get-filter-config.js +56 -0
  127. package/lib/esm/features/filter/index.js +24 -0
  128. package/lib/esm/features/filter/use-opts.js +82 -0
  129. package/lib/esm/features/header-actions/components/column-collapsing.js +62 -0
  130. package/lib/esm/features/header-actions/get-actions.js +65 -0
  131. package/lib/esm/features/pagination/component.js +77 -0
  132. package/lib/esm/features/pagination/use-opts.js +91 -0
  133. package/lib/esm/features/pagination/use-state.js +39 -0
  134. package/lib/esm/features/row-controller.js +253 -0
  135. package/lib/esm/features/row-edit/actions.js +53 -0
  136. package/lib/esm/features/row-edit/hooks.js +24 -0
  137. package/lib/esm/features/row-expanding/use-opts.js +33 -0
  138. package/lib/esm/features/row-expanding/wrapper.js +62 -0
  139. package/lib/esm/features/row-operation/buttons.js +79 -0
  140. package/lib/esm/features/row-operation/cell.js +31 -0
  141. package/lib/esm/features/row-operation/index.js +16 -0
  142. package/lib/esm/features/row-operation/wrapper.js +100 -0
  143. package/lib/esm/features/row-selection/cell.js +101 -0
  144. package/lib/esm/features/row-selection/const.js +11 -0
  145. package/lib/esm/features/row-selection/hooks/index.js +24 -0
  146. package/lib/esm/features/row-selection/hooks/use-click-select.js +65 -0
  147. package/lib/esm/features/row-selection/hooks/use-opts.js +114 -0
  148. package/lib/esm/features/row-selection/hooks/use-set-selected-row-keys.js +43 -0
  149. package/lib/esm/features/row-selection/hooks/use-sync-hover-style.js +81 -0
  150. package/lib/esm/features/row-selection/indicator.js +159 -0
  151. package/lib/esm/features/row-selection/wrapper.js +107 -0
  152. package/lib/esm/features/setting-bridge.js +50 -0
  153. package/lib/esm/features/sorter/bridge.js +53 -0
  154. package/lib/esm/features/sorter/get-sorter-config.js +41 -0
  155. package/lib/esm/features/sorter/index.js +24 -0
  156. package/lib/esm/features/sorter/use-opts.js +75 -0
  157. package/lib/esm/field-bridge/bridge.js +92 -0
  158. package/lib/esm/field-bridge/index.js +44 -0
  159. package/lib/esm/field-bridge/toolbar.js +41 -0
  160. package/lib/esm/footer/index.js +87 -0
  161. package/lib/esm/footer/use-first-cell-patch.js +37 -0
  162. package/lib/esm/header/index.js +121 -0
  163. package/lib/esm/header/validate.js +64 -0
  164. package/lib/esm/hooks/use-get-fields-value.js +56 -0
  165. package/lib/esm/hooks/use-global-actions.js +60 -0
  166. package/lib/esm/hooks/use-global-static.js +152 -0
  167. package/lib/esm/hooks/use-initial-render.js +18 -0
  168. package/lib/esm/hooks/use-inner-ctx.js +100 -0
  169. package/lib/esm/hooks/use-props.js +102 -0
  170. package/lib/esm/hooks/use-table-columns.js +70 -0
  171. package/lib/esm/hooks/use-table-meta.js +51 -0
  172. package/lib/esm/hooks/use-update.js +52 -0
  173. package/lib/esm/index.js +38 -0
  174. package/lib/esm/index.scss.js +13 -0
  175. package/lib/esm/table.js +251 -0
  176. package/lib/esm/utils/cls.js +13 -0
  177. package/lib/esm/utils/fixed.js +48 -0
  178. package/lib/esm/utils/grouping.js +36 -0
  179. package/lib/esm/utils/state-merge.js +37 -0
  180. package/lib/types/body/index.d.ts +14 -0
  181. package/lib/types/body/wrapper.d.ts +18 -0
  182. package/lib/types/cell/aggregated.d.ts +35 -0
  183. package/lib/types/cell/custom.d.ts +19 -0
  184. package/lib/types/cell/dependency.d.ts +47 -0
  185. package/lib/types/cell/editing.d.ts +8 -0
  186. package/lib/types/cell/footer.d.ts +5 -0
  187. package/lib/types/cell/header.d.ts +5 -0
  188. package/lib/types/cell/index.d.ts +6 -0
  189. package/lib/types/const.d.ts +11 -0
  190. package/lib/types/container/base.d.ts +2 -0
  191. package/lib/types/container/bottom.d.ts +20 -0
  192. package/lib/types/container/col-group.d.ts +11 -0
  193. package/lib/types/container/column-virtual.d.ts +7 -0
  194. package/lib/types/container/ctx.d.ts +23 -0
  195. package/lib/types/container/full-virtual.d.ts +8 -0
  196. package/lib/types/container/hooks.d.ts +13 -0
  197. package/lib/types/container/index.d.ts +17 -0
  198. package/lib/types/container/row-virtual.d.ts +7 -0
  199. package/lib/types/container/type.d.ts +17 -0
  200. package/lib/types/container/wrapper.d.ts +12 -0
  201. package/lib/types/ctx.d.ts +41 -0
  202. package/lib/types/features/_overrides/aggregated.d.ts +2 -0
  203. package/lib/types/features/_overrides/getter.d.ts +2 -0
  204. package/lib/types/features/_overrides/grouping.d.ts +7 -0
  205. package/lib/types/features/_overrides/index.d.ts +5 -0
  206. package/lib/types/features/_overrides/overrides.d.ts +2 -0
  207. package/lib/types/features/_overrides/row-selection.d.ts +2 -0
  208. package/lib/types/features/async-data/getter.d.ts +9 -0
  209. package/lib/types/features/async-data/group.d.ts +1 -0
  210. package/lib/types/features/async-data/index.d.ts +6 -0
  211. package/lib/types/features/async-data/normal.d.ts +48 -0
  212. package/lib/types/features/async-data/type.d.ts +22 -0
  213. package/lib/types/features/async-data/use-data-fetcher.d.ts +22 -0
  214. package/lib/types/features/async-data/use-reset-data.d.ts +14 -0
  215. package/lib/types/features/column-grouping/get-grouping-config.d.ts +2 -0
  216. package/lib/types/features/column-grouping/index.d.ts +3 -0
  217. package/lib/types/features/column-grouping/use-opts.d.ts +12 -0
  218. package/lib/types/features/column-state.d.ts +15 -0
  219. package/lib/types/features/filter/bridge.d.ts +9 -0
  220. package/lib/types/features/filter/filter-fns/date.d.ts +6 -0
  221. package/lib/types/features/filter/filter-fns/index.d.ts +6 -0
  222. package/lib/types/features/filter/get-filter-config.d.ts +4 -0
  223. package/lib/types/features/filter/index.d.ts +8 -0
  224. package/lib/types/features/filter/use-opts.d.ts +62 -0
  225. package/lib/types/features/header-actions/components/column-collapsing.d.ts +4 -0
  226. package/lib/types/features/header-actions/get-actions.d.ts +13 -0
  227. package/lib/types/features/header-actions/index.d.ts +3 -0
  228. package/lib/types/features/header-actions/type.d.ts +20 -0
  229. package/lib/types/features/pagination/component.d.ts +15 -0
  230. package/lib/types/features/pagination/index.d.ts +4 -0
  231. package/lib/types/features/pagination/use-opts.d.ts +14 -0
  232. package/lib/types/features/pagination/use-state.d.ts +11 -0
  233. package/lib/types/features/row-controller.d.ts +101 -0
  234. package/lib/types/features/row-edit/actions.d.ts +12 -0
  235. package/lib/types/features/row-edit/hooks.d.ts +1 -0
  236. package/lib/types/features/row-edit/index.d.ts +2 -0
  237. package/lib/types/features/row-expanding/index.d.ts +3 -0
  238. package/lib/types/features/row-expanding/use-opts.d.ts +12 -0
  239. package/lib/types/features/row-expanding/wrapper.d.ts +11 -0
  240. package/lib/types/features/row-operation/buttons.d.ts +41 -0
  241. package/lib/types/features/row-operation/cell.d.ts +6 -0
  242. package/lib/types/features/row-operation/index.d.ts +18 -0
  243. package/lib/types/features/row-operation/wrapper.d.ts +3 -0
  244. package/lib/types/features/row-selection/cell.d.ts +62 -0
  245. package/lib/types/features/row-selection/const.d.ts +1 -0
  246. package/lib/types/features/row-selection/hooks/index.d.ts +6 -0
  247. package/lib/types/features/row-selection/hooks/use-click-select.d.ts +1 -0
  248. package/lib/types/features/row-selection/hooks/use-opts.d.ts +15 -0
  249. package/lib/types/features/row-selection/hooks/use-set-selected-row-keys.d.ts +9 -0
  250. package/lib/types/features/row-selection/hooks/use-sync-hover-style.d.ts +5 -0
  251. package/lib/types/features/row-selection/index.d.ts +7 -0
  252. package/lib/types/features/row-selection/indicator.d.ts +8 -0
  253. package/lib/types/features/row-selection/wrapper.d.ts +9 -0
  254. package/lib/types/features/setting-bridge.d.ts +14 -0
  255. package/lib/types/features/sorter/bridge.d.ts +8 -0
  256. package/lib/types/features/sorter/get-sorter-config.d.ts +7 -0
  257. package/lib/types/features/sorter/index.d.ts +8 -0
  258. package/lib/types/features/sorter/use-opts.d.ts +71 -0
  259. package/lib/types/field-bridge/bridge.d.ts +18 -0
  260. package/lib/types/field-bridge/index.d.ts +11 -0
  261. package/lib/types/field-bridge/toolbar.d.ts +9 -0
  262. package/lib/types/footer/index.d.ts +6 -0
  263. package/lib/types/footer/use-first-cell-patch.d.ts +1 -0
  264. package/lib/types/header/index.d.ts +17 -0
  265. package/lib/types/header/validate.d.ts +10 -0
  266. package/lib/types/hooks/use-get-fields-value.d.ts +14 -0
  267. package/lib/types/hooks/use-global-actions.d.ts +24 -0
  268. package/lib/types/hooks/use-global-static.d.ts +83 -0
  269. package/lib/types/hooks/use-initial-render.d.ts +1 -0
  270. package/lib/types/hooks/use-inner-ctx.d.ts +12 -0
  271. package/lib/types/hooks/use-props.d.ts +109 -0
  272. package/lib/types/hooks/use-table-columns.d.ts +11 -0
  273. package/lib/types/hooks/use-table-meta.d.ts +15 -0
  274. package/lib/types/hooks/use-update.d.ts +11 -0
  275. package/lib/types/index.d.ts +32 -0
  276. package/lib/types/table.d.ts +152 -0
  277. package/lib/types/utils/cls.d.ts +4 -0
  278. package/lib/types/utils/fixed.d.ts +11 -0
  279. package/lib/types/utils/grouping.d.ts +6 -0
  280. package/lib/types/utils/index.d.ts +5 -0
  281. package/lib/types/utils/meta.d.ts +8 -0
  282. package/lib/types/utils/state-merge.d.ts +14 -0
  283. package/package.json +90 -0
  284. package/type.d.ts +143 -0
@@ -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
+ import React from 'react';
11
+ import { cx } from '@hi-ui/classname';
12
+ import { flexRender } from '@tanstack/react-table';
13
+ import { mergeValues } from '@hi-ui/schema-utils';
14
+ import { useEditableSchemaTableCtx } from '../ctx.js';
15
+ import { RowExpandingWrapper } from '../features/row-expanding/wrapper.js';
16
+ import { getFixedStyles } from '../utils/fixed.js';
17
+ import { cls } from '../utils/cls.js';
18
+
19
+ // NOTE 此处注释:适配【行展开功能】时留
20
+ // 识别到此处包装器如果打开 memo,会导致【外部命令式设置行展开状态】时,icon 的状态会展示错误
21
+ // 原因在于,此处包装器会隔离外部设置状态后引发的重渲染,导致下面的 RowExpandingWrapper 无法重渲染
22
+ // 最初增加 memo 的目的是提升渲染性能,此处移除时经评估和实测后并不会引起突出的损耗
23
+ // 因此决定暂时移除 memo,后续如果引起问题再重新考虑使用订阅的方式触发下层组件重渲染
24
+ // export const BodyCellWrapper2 = React.memo(function BodyCellWrapper(props) {
25
+ // return <>留一个占位</>
26
+ // })
27
+ function BodyCellWrapper(props) {
28
+ var _a, _b, _c;
29
+ var cell = props.cell;
30
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
31
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef;
32
+ // 开启 fixed 时才去获取固定单元格的样式
33
+ var fixed = props.fixed ? getFixedStyles(cell.column, {
34
+ globalStaticRef: globalStaticRef
35
+ }) : {};
36
+ var fixedClassName = (fixed.className || []).map(function (c) {
37
+ return "cell--" + c;
38
+ });
39
+ var renderCase = useRenderCase();
40
+ var renderCaseMap = {
41
+ basic: BasicEl,
42
+ expanding: ExpandingEl,
43
+ grouping: GroupingEl
44
+ };
45
+ var CaseEl = renderCaseMap[renderCase];
46
+ // 获取动态属性
47
+ var dynamicAttrs = (_b = (_a = cell.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.bodyCell) === null || _b === void 0 ? void 0 : _b.call(_a, {
48
+ cell: cell,
49
+ row: cell.row,
50
+ rowData: cell.row.$getRealtimeRowData() || {},
51
+ renderCase: renderCase
52
+ });
53
+ var style = mergeValues(fixed.style, dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.style);
54
+ var textAlign = (_c = cell.column.columnDef.meta) === null || _c === void 0 ? void 0 : _c.align;
55
+ return /*#__PURE__*/React.createElement("td", Object.assign({}, dynamicAttrs, {
56
+ className: cx(cls.apply(void 0, ['body-cell'].concat(fixedClassName)), dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.className),
57
+ style: style,
58
+ "data-text-align": textAlign,
59
+ "data-id": cell.id
60
+ }), /*#__PURE__*/React.createElement(CaseEl, {
61
+ renderCase: renderCase,
62
+ cell: cell,
63
+ textAlign: textAlign
64
+ }));
65
+ }
66
+ function useRenderCase() {
67
+ var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
68
+ globalStaticRef = _useEditableSchemaTab2.globalStaticRef;
69
+ var _globalStaticRef$curr = globalStaticRef.current,
70
+ enableRowExpanding = _globalStaticRef$curr.enableRowExpanding,
71
+ enableRowGrouping = _globalStaticRef$curr.enableRowGrouping;
72
+ if (enableRowGrouping) return 'grouping';
73
+ if (enableRowExpanding) return 'expanding';
74
+ return 'basic';
75
+ }
76
+ // 普通基本元素
77
+ function BasicEl(props) {
78
+ var cell = props.cell;
79
+ return /*#__PURE__*/React.createElement(React.Fragment, null, flexRender(cell.column.columnDef.cell, cell.getContext()));
80
+ }
81
+ // 可展开元素
82
+ function ExpandingEl(props) {
83
+ var cell = props.cell,
84
+ textAlign = props.textAlign;
85
+ return /*#__PURE__*/React.createElement(RowExpandingWrapper, {
86
+ renderCase: props.renderCase,
87
+ cell: cell,
88
+ textAlign: textAlign
89
+ }, flexRender(cell.column.columnDef.cell, cell.getContext()));
90
+ }
91
+ function GroupingEl(props) {
92
+ var cell = props.cell,
93
+ textAlign = props.textAlign;
94
+ var cellIndex = cell.column.getIndex();
95
+ /** 是否聚合单元格 */
96
+ var isAggregated = cell.getIsAggregated();
97
+ /** 是否无效的聚合单元格 */
98
+ // || undefined 是为了放在data-*属性上时 false 时不会显示
99
+ var isInvalidAggregatedCell = isAggregated && cellIndex !== 0 || undefined;
100
+ /** 是否分组单元格 */
101
+ var isGrouped = cell.getIsGrouped();
102
+ // 当前行时分组行,且当前单元格是 placeholder 单元格,则不渲染
103
+ /** 是否当前行是分组行 */
104
+ var isRowGrouped = cell.row.getIsGrouped();
105
+ /** 是否当前单元格是 placeholder 单元格 */
106
+ var isPlaceholder = cell.getIsPlaceholder();
107
+ var hideRealEl =
108
+ // 无效的聚合单元格
109
+ isInvalidAggregatedCell ||
110
+ // 分组单元格
111
+ isGrouped ||
112
+ // 当前行是分组行,且当前单元格是 placeholder 单元格
113
+ isRowGrouped && isPlaceholder;
114
+ return /*#__PURE__*/React.createElement(React.Fragment, null, hideRealEl ? null : ( /*#__PURE__*/React.createElement(RowExpandingWrapper, {
115
+ renderCase: props.renderCase,
116
+ cell: cell,
117
+ textAlign: textAlign
118
+ }, flexRender(cell.column.columnDef.cell, cell.getContext()))));
119
+ }
120
+ export { BodyCellWrapper };
@@ -0,0 +1,64 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React, { useMemo } from 'react';
11
+ import { random, isNil } from 'lodash-es';
12
+ import { Tag } from '@hi-ui/tag';
13
+ import { ColorEnumPreset, colorPreset } from '@hi-ui/schema-fields';
14
+ import { useEditableSchemaTableCtx } from '../ctx.js';
15
+ import { EMPTY_VALUE } from '../const.js';
16
+ var AggregatedCell = /*#__PURE__*/React.memo(function AggregatedCell(props) {
17
+ var _a;
18
+ var row = props.row;
19
+ var groupingValue = row.groupingValue,
20
+ groupingColumnId = row.groupingColumnId;
21
+ var _useEditTableCtx = useEditableSchemaTableCtx(),
22
+ propsRef = _useEditTableCtx.propsRef;
23
+ // TODO 待增加自定义颜色配置传入
24
+ var color = useMemo(function () {
25
+ var name = ColorEnumPreset[random(0, ColorEnumPreset.length - 1)];
26
+ return colorPreset[name];
27
+ }, []);
28
+ // 如果groupingColumnId为空,则无法显示
29
+ if (isNil(groupingColumnId)) return null;
30
+ // 处理空值情况,识别特殊标记__EMPTY_VALUE__
31
+ var displayValue = groupingValue === EMPTY_VALUE ? '空值' : groupingValue;
32
+ // 当前被分组的列,经聚合函数处理后的值
33
+ var groupingColumnAggregatedValue = row.$getAggregatedValue(groupingColumnId);
34
+ var dftEl = /*#__PURE__*/React.createElement("span", {
35
+ "data-grouping-column-id": groupingColumnId,
36
+ className: "flex-center",
37
+ style: {
38
+ gap: 4
39
+ }
40
+ }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Tag, {
41
+ color: color.fore,
42
+ background: color.back
43
+ }, displayValue)), /*#__PURE__*/React.createElement("span", {
44
+ style: {
45
+ fontSize: 12
46
+ }
47
+ }, "\u5171 ", groupingColumnAggregatedValue, " \u6761"));
48
+ // 自定义【有效聚合单元格】渲染逻辑
49
+ if ((_a = propsRef.current.customCell) === null || _a === void 0 ? void 0 : _a.renderAggregatedCell) {
50
+ return propsRef.current.customCell.renderAggregatedCell(Object.assign(Object.assign({}, props), {
51
+ groupingValue: groupingValue,
52
+ groupingColumnId: groupingColumnId,
53
+ groupingColumnAggregatedValue: groupingColumnAggregatedValue,
54
+ displayValue: displayValue,
55
+ dftEl: dftEl,
56
+ color: color
57
+ }));
58
+ }
59
+ return dftEl;
60
+ }
61
+ // propsAreEqual暂时置空
62
+ );
63
+
64
+ export { AggregatedCell as default };
@@ -0,0 +1,90 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ /** @LICENSE
3
+ * @hi-ui/schema-editable-table
4
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
5
+ *
6
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ import { __rest } from 'tslib';
12
+ import { Schedular } from '@hi-ui/schema-utils';
13
+ import { BatchDepUpdate } from '@hi-ui/schema-fields';
14
+ import { generateDepPropsField } from '@hi-ui/schema-form';
15
+ function execCellDepsProcess(ctx) {
16
+ // 直接先处理值依赖
17
+ execCellValueDepFn(ctx);
18
+ // 再处理 Props 依赖
19
+ execCellPropsDepFn(ctx);
20
+ }
21
+ /**
22
+ * 处理表格单元格中的值依赖逻辑
23
+ */
24
+ function execCellValueDepFn(ctx) {
25
+ var _rowIndex, _tableValue$mergeSile;
26
+ var fieldProps = ctx.fieldProps;
27
+ var field = fieldProps.field;
28
+ // 检查字段是否有依赖配置
29
+ if (!field.dependency) return; // 没有配置依赖,直接退出
30
+ var _field$dependency = field.dependency,
31
+ deps = _field$dependency.deps,
32
+ depValueFn = _field$dependency.value;
33
+ if (!deps.length || !depValueFn) return; // 没有依赖或依赖函数,直接退出
34
+ var rowIndex = ctx.rowIndex,
35
+ changedDepValues = ctx.changedDepValues;
36
+ var currentDepValues = changedDepValues[rowIndex];
37
+ // 依赖值不存在,直接退出
38
+ if (!currentDepValues) return;
39
+ // 检查依赖的字段是否存在于当前变更的值上
40
+ // NOTE 此处仅检测了第一层的属性,暂时不支持嵌套属性的情况
41
+ var hasChanged = deps.some(function (name) {
42
+ return name in (currentDepValues || {});
43
+ });
44
+ // 依赖字段变更,才需要执行 depValueFn
45
+ if (!hasChanged) return;
46
+ var rowData = ctx.rowData,
47
+ dataKey = ctx.dataKey,
48
+ changedFieldNames = ctx.changedFieldNames,
49
+ tableValue = ctx.tableValue;
50
+ var nextValue = depValueFn(currentDepValues, {
51
+ allValues: rowData,
52
+ changedDepKeys: changedFieldNames || [],
53
+ rowIndex: rowIndex,
54
+ dataKey: dataKey,
55
+ formRef: {
56
+ current: null
57
+ },
58
+ // TODO 待更新实现
59
+ batchUpdate: BatchDepUpdate.update
60
+ });
61
+ var finalValue = BatchDepUpdate.getValues(dataKey, nextValue);
62
+ var _a = finalValue,
63
+ _b = dataKey,
64
+ fieldValue = _a[_b],
65
+ restDepValues = __rest(_a, [_typeof(_b) === "symbol" ? _b : _b + ""]);
66
+ // 关键赋值
67
+ fieldProps.value = fieldValue;
68
+ fieldProps.ctx.formBinding.value = fieldValue;
69
+ // 还要合并到 TableValue 上,但是不再触发订阅
70
+ tableValue.mergeSilently((_tableValue$mergeSile = {}, _tableValue$mergeSile[rowIndex] = (_rowIndex = {}, _rowIndex[dataKey] = nextValue, _rowIndex), _tableValue$mergeSile));
71
+ // 存在批量更新的值时,一并写到 TableValue 上,并且触发订阅
72
+ Schedular.nextMicro(function () {
73
+ var _tableValue$mergeValu;
74
+ tableValue.mergeValue((_tableValue$mergeValu = {}, _tableValue$mergeValu[rowIndex] = restDepValues, _tableValue$mergeValu));
75
+ });
76
+ }
77
+ /**
78
+ * 处理表格单元格中的 Props 依赖逻辑
79
+ */
80
+ function execCellPropsDepFn(ctx) {
81
+ var nextField = generateDepPropsField(ctx.fieldProps.field, {
82
+ formRef: {},
83
+ depValues: ctx.changedDepValues[ctx.rowIndex],
84
+ changedDepKeys: ctx.changedFieldNames || [],
85
+ allValues: ctx.rowData
86
+ });
87
+ ctx.fieldProps.field = nextField;
88
+ ctx.fieldProps.ctx.field = nextField;
89
+ }
90
+ export { execCellDepsProcess, execCellPropsDepFn, execCellValueDepFn };
@@ -0,0 +1,76 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import { useUpdate, useMemoizedFn } from 'ahooks';
12
+ import { isObjectLike, isFunction } from 'lodash-es';
13
+ import { Schedular } from '@hi-ui/schema-utils';
14
+ import { useEditableSchemaTableCtx } from '../ctx.js';
15
+ function useEditingCellFormBinding(props) {
16
+ var _a;
17
+ var getValue = props.getValue,
18
+ index = props.row.index,
19
+ id = props.column.id,
20
+ table = props.table;
21
+ var _useEditTableCtx = useEditableSchemaTableCtx(),
22
+ globalStaticRef = _useEditTableCtx.globalStaticRef;
23
+ var enableRowEdit = globalStaticRef.current.enableRowEdit;
24
+ var initialValue = getValue();
25
+ var valueRef = React.useRef(initialValue);
26
+ valueRef.current = (_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.getCellValue(index, id);
27
+ var forceUpdate = useUpdate();
28
+ var updateValue = useMemoizedFn(function (nextValue) {
29
+ var _a;
30
+ (_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.updateData(index, id, nextValue);
31
+ // 行编辑模式下,强制更新
32
+ if (enableRowEdit) forceUpdate();
33
+ }
34
+ // 移除了此处的防抖函数,原因有2
35
+ // 1. useDebounceFn 内部会在组件卸载时取消,导致 updateValue 失效,无法更新值
36
+ // 2. 大部分内置组件已在更上游处理防抖逻辑,此处没有必要再额外处理了
37
+ );
38
+
39
+ var handleChange = function handleChange(eventOrValue) {
40
+ var nextValue = normalizeValueFromChange(eventOrValue);
41
+ valueRef.current = nextValue;
42
+ updateValue(nextValue);
43
+ };
44
+ var handleBlur = function handleBlur() {
45
+ // 行编辑模式下,失焦时保持激活状态,不更新值
46
+ if (enableRowEdit) return;
47
+ // 延迟一小会儿再更新值
48
+ Schedular.nextMicro(function () {
49
+ updateValue(valueRef.current);
50
+ });
51
+ };
52
+ return {
53
+ // NOTE 此处value已被废弃,会在外部由真实的值覆盖
54
+ value: valueRef.current,
55
+ onChange: handleChange,
56
+ onBlur: handleBlur,
57
+ invalid: undefined
58
+ };
59
+ }
60
+ // fork from https://github.com/XiaoMi/hiui/blob/master/packages/ui/form/src/use-form.ts#L303
61
+ function normalizeValueFromChange(eventOrValue) {
62
+ if (!isObjectLike(eventOrValue) || !eventOrValue.target) {
63
+ return eventOrValue;
64
+ }
65
+ var event = eventOrValue;
66
+ // @see https://reactjs.org/docs/events.html#event-pooling
67
+ if (isFunction(event.persist)) {
68
+ event.persist();
69
+ }
70
+ var target = event.target || event.currentTarget;
71
+ // 待验证 // 待支持更多类型
72
+ if (target.type === 'checkbox') return target.checked;
73
+ if (target.type === 'radio') return target.checked;
74
+ return target.value;
75
+ }
76
+ export { normalizeValueFromChange, useEditingCellFormBinding };
@@ -0,0 +1,52 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { __rest } from 'tslib';
11
+ import React from 'react';
12
+ import { get } from 'lodash-es';
13
+ import { useSubscribeList, useSubscribe, NOOP_SUBSCRIPTION } from '@hi-ui/use-subscription';
14
+ import { NumberUtil } from '@hi-ui/schema-utils';
15
+ import { useEditableSchemaTableCtx } from '../ctx.js';
16
+ var FooterCell = /*#__PURE__*/React.memo(function FooterCell(props) {
17
+ var _NumberUtil$chain;
18
+ var _a;
19
+ var field = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.field;
20
+ var _b = useEditableSchemaTableCtx(),
21
+ table = _b.table,
22
+ subscription = _b.subscription,
23
+ globalStaticRef = _b.globalStaticRef,
24
+ restCtx = __rest(_b, ["table", "subscription", "globalStaticRef"]);
25
+ var invalidField = !field;
26
+ var isNotNumber = (field === null || field === void 0 ? void 0 : field.valueType) !== 'number';
27
+ var isNotAvailable = invalidField || isNotNumber;
28
+ // 用于在任意字段变更时触发重渲染,因此不关心返回结果
29
+ useSubscribeList(subscription, undefined, {
30
+ // field 不存在或者字段类型不是 number 时,不创建订阅
31
+ skipSubscribe: isNotAvailable
32
+ });
33
+ // 有效字段,且开启了筛选,则订阅筛选状态
34
+ // 不关心实际的筛选结果,仅用来触发更新
35
+ var filterState = globalStaticRef.current.enableFilter && !isNotAvailable ? restCtx.filterState : NOOP_SUBSCRIPTION;
36
+ useSubscribe(filterState, undefined);
37
+ // 首列固定展示 // TODO 待支持动态首列配置
38
+ var colIndex = props.column.getIndex();
39
+ var _enableRowSelection = globalStaticRef.current.enableRowSelection;
40
+ if (colIndex === 0 && !_enableRowSelection) return /*#__PURE__*/React.createElement(React.Fragment, null, "\u5408\u8BA1");
41
+ if (isNotAvailable) return null;
42
+ var tableData = subscription.getValue();
43
+ var filteredRows = table.getFilteredRowModel().flatRows;
44
+ var fieldData = filteredRows.map(function (row) {
45
+ return get(tableData, [row.index, field.dataIndex]);
46
+ });
47
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (_NumberUtil$chain = NumberUtil.chain(0)).add.apply(_NumberUtil$chain, fieldData).format(2));
48
+ }
49
+ // propsAreEqual暂时置空
50
+ );
51
+
52
+ export { FooterCell as default };
@@ -0,0 +1,63 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import EllipsisTooltip from '@hi-ui/ellipsis-tooltip';
12
+ import { useEditableSchemaTableCtx } from '../ctx.js';
13
+ import { cls } from '../utils/cls.js';
14
+ import { isSystemCol } from '../const.js';
15
+ import 'lodash-es';
16
+ import { getHeaderActions } from '../features/header-actions/get-actions.js';
17
+ var HeaderCell = /*#__PURE__*/React.memo(function HeaderCell(props) {
18
+ var _a, _b, _c, _d, _e;
19
+ var column = props.column,
20
+ table = props.table;
21
+ var field = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.field;
22
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
23
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef;
24
+ var invalidField = !field;
25
+ if (invalidField) return null;
26
+ // 文本对齐
27
+ var textAlign = (_b = props.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.align;
28
+ // 系统列仅包含展示功能
29
+ if (isSystemCol(column.id)) {
30
+ return /*#__PURE__*/React.createElement("div", {
31
+ className: cls('header-cell-content'),
32
+ "data-text-align": textAlign
33
+ }, /*#__PURE__*/React.createElement("span", {
34
+ className: cls('header-cell-content-title')
35
+ }, field.title));
36
+ }
37
+ // 表头操作
38
+ var actions = getHeaderActions({
39
+ column: column,
40
+ table: table,
41
+ field: field,
42
+ globalStaticRef: globalStaticRef
43
+ });
44
+ var hoverOnly = ((_d = (_c = field.control) === null || _c === void 0 ? void 0 : _c.hoverOnly) !== null && _d !== void 0 ? _d : globalStaticRef.current.enableHeaderActionHoverOnly) || undefined;
45
+ return /*#__PURE__*/React.createElement("div", {
46
+ className: cls('header-cell-content'),
47
+ "data-text-align": textAlign,
48
+ "data-has-children": field.children ? true : undefined,
49
+ "data-has-filter": (actions === null || actions === void 0 ? void 0 : actions.filterAvailable) || undefined,
50
+ "data-has-sorter": (actions === null || actions === void 0 ? void 0 : actions.sorterAvailable) || undefined,
51
+ "data-actions-count": (actions === null || actions === void 0 ? void 0 : actions.elements.length) || undefined,
52
+ "data-is-required": (_e = field.control) === null || _e === void 0 ? void 0 : _e.required,
53
+ "data-hover-only": hoverOnly
54
+ }, /*#__PURE__*/React.createElement("span", {
55
+ className: cls('header-cell-content-title')
56
+ }, /*#__PURE__*/React.createElement(EllipsisTooltip, null, field.title)), /*#__PURE__*/React.createElement("span", {
57
+ className: cls('header-cell-content-actions')
58
+ }, actions === null || actions === void 0 ? void 0 : actions.elements));
59
+ }
60
+ // propsAreEqual暂时置空
61
+ );
62
+
63
+ export { HeaderCell as default };
@@ -0,0 +1,192 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { __rest } from 'tslib';
11
+ import React from 'react';
12
+ import { isEqual } from 'lodash-es';
13
+ import { isSimpleCase, SimpleCase, EditableCase, useMatchFieldClass, useReadonly, runDynamicEditable, ReadonlyCase } from '@hi-ui/schema-fields';
14
+ import { useSubscribeList } from '@hi-ui/use-subscription';
15
+ import { SELECTED_OPTION_RAW } from '../const.js';
16
+ import { useEditableSchemaTableCtx } from '../ctx.js';
17
+ import { useRuntimeRowEditable } from '../features/row-edit/hooks.js';
18
+ import '@hi-ui/button';
19
+ import { useEditingCellFormBinding } from './editing.js';
20
+ import { execCellDepsProcess } from './dependency.js';
21
+ import '@hi-ui/ellipsis-tooltip';
22
+ import '../utils/cls.js';
23
+ import '@tanstack/react-table';
24
+ import '@hi-ui/schema-utils';
25
+ import '@hi-ui/schema-table-extensions';
26
+ import '@hi-ui/tag';
27
+ var EditableCell = /*#__PURE__*/React.memo(function EditableCellCore(props) {
28
+ var _a, _b;
29
+ var field = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.field;
30
+ var formBinding = useEditingCellFormBinding(props);
31
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
32
+ tableValue = _useEditableSchemaTab.subscription,
33
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef;
34
+ var enableRowEdit = globalStaticRef.current.enableRowEdit;
35
+ var rowIndex = props.row.index;
36
+ var dataKey = props.column.id;
37
+ var rowData = tableValue.getValue()[rowIndex];
38
+ var fieldDeps = (((_b = field === null || field === void 0 ? void 0 : field.dependency) === null || _b === void 0 ? void 0 : _b.deps) || []).map(function (dep) {
39
+ return [rowIndex, dep];
40
+ });
41
+ var _c = useSubscribeList(tableValue, [[rowIndex, dataKey]].concat(fieldDeps), {
42
+ // 此处单元格全部可编辑,全部创建监听
43
+ skipSubscribe: false,
44
+ // 行编辑模式下,从 draft 中获取值
45
+ getFieldValueFromDraft: enableRowEdit
46
+ }),
47
+ fieldValue = _c.fieldValue,
48
+ changedDepValues = _c.changedDepValues,
49
+ rest = __rest(_c, ["fieldValue", "changedDepValues"]);
50
+ if (!field) return null;
51
+ formBinding.value = fieldValue;
52
+ var nextField = Object.assign(Object.assign({}, field), {
53
+ payload: Object.assign(Object.assign({}, field.payload), {
54
+ setSelectedRawOption: function setSelectedRawOption(values) {
55
+ var _a;
56
+ if (enableRowEdit) {
57
+ var _Object$assign, _rowIndex, _tableValue$mergeDraf;
58
+ // 行编辑模式:需要获取最新的 draft 数据
59
+ var draftRowData = ((_a = tableValue.getDraft()) === null || _a === void 0 ? void 0 : _a[rowIndex]) || {};
60
+ var currentData = draftRowData[SELECTED_OPTION_RAW] || {};
61
+ var updatedData = Object.assign(Object.assign({}, currentData), (_Object$assign = {}, _Object$assign[dataKey] = values, _Object$assign));
62
+ tableValue.mergeDraft((_tableValue$mergeDraf = {}, _tableValue$mergeDraf[rowIndex] = (_rowIndex = {}, _rowIndex[SELECTED_OPTION_RAW] = updatedData, _rowIndex), _tableValue$mergeDraf));
63
+ } else {
64
+ var _Object$assign2, _rowIndex2, _tableValue$mergeSile;
65
+ // 普通模式:从当前 rowData 获取数据
66
+ var _currentData = rowData[SELECTED_OPTION_RAW] || {};
67
+ var _updatedData = Object.assign(Object.assign({}, _currentData), (_Object$assign2 = {}, _Object$assign2[dataKey] = values, _Object$assign2));
68
+ tableValue.mergeSilently((_tableValue$mergeSile = {}, _tableValue$mergeSile[rowIndex] = (_rowIndex2 = {}, _rowIndex2[SELECTED_OPTION_RAW] = _updatedData, _rowIndex2), _tableValue$mergeSile));
69
+ }
70
+ }
71
+ })
72
+ });
73
+ var fieldProps = {
74
+ value: fieldValue,
75
+ field: nextField,
76
+ FieldClass: props.FieldClass,
77
+ ctx: {
78
+ field: nextField,
79
+ rowData: rowData,
80
+ rawData: rowData,
81
+ formBinding: formBinding,
82
+ rowIndex: rowIndex,
83
+ dataKey: dataKey,
84
+ formRef: {
85
+ current: null
86
+ } // TODO 待补充实现
87
+ },
88
+
89
+ // 行编辑模式下,失焦时保持激活状态
90
+ keepActiveOnBlur: enableRowEdit,
91
+ defaultActive: props.defaultActive
92
+ };
93
+ execCellDepsProcess({
94
+ fieldProps: fieldProps,
95
+ rowData: rowData,
96
+ rowIndex: rowIndex,
97
+ dataKey: dataKey,
98
+ changedDepValues: changedDepValues,
99
+ changedFieldNames: rest.changedFieldNames,
100
+ tableValue: tableValue
101
+ });
102
+ return /*#__PURE__*/React.createElement(EditableCase, Object.assign({}, fieldProps));
103
+ }, function (prev, next) {
104
+ var _a;
105
+ // 如果 column 配置要求总是更新,则返回 false 触发重渲染
106
+ if ((_a = prev.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.shouldUpdate) return false;
107
+ // 如果 defaultActive 为 true,则直接重渲染
108
+ // TODO 此处仍有BUG,会在行交换时触发
109
+ // 暂时记录,待后续优化
110
+ if (prev.defaultActive) return false;
111
+ // NOTE Cell 暂时始终打开值比较 待补充其他case
112
+ // 其余时候比较关键数据是否相等
113
+ return isEqual(prev.getValue(), next.getValue());
114
+ });
115
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
116
+ // @ts-ignore 关闭 displayName 检查
117
+ EditableCell.displayName = 'EditableCell';
118
+ var CustomCell = /*#__PURE__*/React.memo(
119
+ // CustomCell 中的 Custom 是指包含自定义渲染
120
+ function CustomCellCore(props) {
121
+ var _a, _b, _c, _d;
122
+ var field = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.field;
123
+ var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
124
+ tableValue = _useEditableSchemaTab2.subscription,
125
+ propsRef = _useEditableSchemaTab2.propsRef;
126
+ var FieldClass = useMatchFieldClass({
127
+ name: 'TableCellWrapper',
128
+ field: field,
129
+ fieldMap: (_b = props.table.options.meta) === null || _b === void 0 ? void 0 : _b.fieldMap
130
+ });
131
+ // 行编辑状态变更时会触发组件重渲染
132
+ var runtimeEditable = useRuntimeRowEditable(props.row.index);
133
+ var selfReadonly = useReadonly(field, runtimeEditable);
134
+ var readonly = !runDynamicEditable(field, selfReadonly, function () {
135
+ return {
136
+ type: 'edit-table',
137
+ rowIndex: props.row.index,
138
+ rowId: props.row.id,
139
+ columnIndex: props.column.getIndex(),
140
+ columnId: props.column.id,
141
+ rawData: props.row.$getRealtimeRowData()
142
+ };
143
+ });
144
+ // 2. 只读状态使用 ReadonlyCase
145
+ if (readonly) {
146
+ var dataKey = props.column.id;
147
+ var rowIndex = props.row.index;
148
+ var rowData = tableValue.getValue()[rowIndex];
149
+ var value = (_d = (_c = props.table.options.meta) === null || _c === void 0 ? void 0 : _c.getCellValue(rowIndex, dataKey)) !== null && _d !== void 0 ? _d : props.getValue();
150
+ return /*#__PURE__*/React.createElement(ReadonlyCase, {
151
+ usedBy: "table",
152
+ value: value,
153
+ field: field,
154
+ FieldClass: FieldClass,
155
+ ctx: {
156
+ field: field,
157
+ rowData: rowData,
158
+ rawData: rowData,
159
+ rowIndex: rowIndex,
160
+ dataKey: dataKey
161
+ }
162
+ });
163
+ }
164
+ // 3. 可编辑状态使用 MemoCell
165
+ return /*#__PURE__*/React.createElement(EditableCell, Object.assign({}, props, {
166
+ FieldClass: FieldClass,
167
+ defaultActive: propsRef.current.defaultActive
168
+ }));
169
+ });
170
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
171
+ // @ts-ignore 关闭 displayName 检查
172
+ CustomCell.displayName = 'CustomCell';
173
+ // NOTE 此处之所以要分为 DftCell -> CustomCell -> EditableCell 三层,是因为需要区分出【简单】【只读】【可编辑】的字段
174
+ // 【简单】字段:无自定义渲染,无依赖,无表单绑定,无监听,只有最单纯的 DOM 渲染
175
+ // 【只读】字段:有自定义渲染,无依赖,无表单绑定,无监听 // TODO 后续只读部分可能会需要支持deps
176
+ // 【可编辑】字段:有自定义渲染,有依赖,有控制,有表单绑定,有监听
177
+ function DftCell(props) {
178
+ var _a;
179
+ var field = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.field;
180
+ if (!field) {
181
+ // 此处拦截,必须有 field 配置,否则报错
182
+ throw new Error('DftCell: field is required');
183
+ }
184
+ // 1. 简单字段且无自定义渲染,使用 SimpleCase
185
+ if (isSimpleCase(field)) {
186
+ return /*#__PURE__*/React.createElement(SimpleCase, {
187
+ value: props.getValue()
188
+ });
189
+ }
190
+ return /*#__PURE__*/React.createElement(CustomCell, Object.assign({}, props));
191
+ }
192
+ export { DftCell as default };