@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,65 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var ahooks = require('ahooks');
16
+ var normal = require('../features/async-data/normal.js');
17
+ var useResetData = require('../features/async-data/use-reset-data.js');
18
+ require('tslib');
19
+ require('@hi-ui/schema-utils');
20
+ require('react');
21
+ require('../utils/cls.js');
22
+ require('../container/index.js');
23
+ require('lodash-es');
24
+ require('@tanstack/react-table');
25
+ require('@hi-ui/checkbox');
26
+ require('@hi-ui/radio');
27
+ require('@hi-ui/use-subscription');
28
+ require('@hi-ui/space');
29
+ require('@hi-ui/switch');
30
+ var useSetSelectedRowKeys = require('../features/row-selection/hooks/use-set-selected-row-keys.js');
31
+
32
+ /**
33
+ * 全局静态函数
34
+ */
35
+ function useGlobalStaticActions(ctx) {
36
+ var innerRef = ctx.innerRef;
37
+ // 获取异步数据源
38
+ var _useGetDataSource = normal.useGetDataSource({
39
+ innerRef: innerRef
40
+ }),
41
+ getDataSource = _useGetDataSource.getDataSource,
42
+ updateDataSource = _useGetDataSource.updateDataSource;
43
+ // 重置分页、筛选
44
+ var resetDataSource = useResetData.useResetDataSource({
45
+ innerRef: innerRef
46
+ });
47
+ var setDataSource = ahooks.useMemoizedFn(
48
+ // 设置表格数据源
49
+ function setDataSource(dataSource) {
50
+ innerRef.current.subscription.setValue(dataSource);
51
+ });
52
+ // 设置行选择状态
53
+ var setSelectedRowKeys = useSetSelectedRowKeys.useSetSelectedRowKeys({
54
+ innerRef: innerRef
55
+ });
56
+ var globalStaticActions = {
57
+ getDataSource: getDataSource,
58
+ updateDataSource: updateDataSource,
59
+ resetDataSource: resetDataSource,
60
+ setDataSource: setDataSource,
61
+ setSelectedRowKeys: setSelectedRowKeys
62
+ };
63
+ return ahooks.useLatest(globalStaticActions);
64
+ }
65
+ exports.useGlobalStaticActions = useGlobalStaticActions;
@@ -0,0 +1,158 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+ var ahooks = require('ahooks');
17
+ var _const = require('../const.js');
18
+
19
+ /**
20
+ * 从 propsRef 中生成静态配置
21
+ * @desc 是 useGlobalStatic 返回值的子集
22
+ * @desc 也就是仅包含能直接从 propsRef 中获取的选项配置
23
+ */
24
+ function genStaticOptsFromPropsRef(propsRef) {
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
26
+ // 是否启用异步数据
27
+ var enableAsyncData = !!((_a = propsRef.current.asyncData) === null || _a === void 0 ? void 0 : _a.request);
28
+ // 存在嵌套表头
29
+ var hasNestHeader = !!propsRef.current.fields.some(function (field) {
30
+ var _a;
31
+ return !!((_a = field.children) === null || _a === void 0 ? void 0 : _a.length);
32
+ });
33
+ var enableRowSelection = !!((_b = propsRef.current) === null || _b === void 0 ? void 0 : _b.rowSelection);
34
+ var enableRowOperation = !!((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.rowOperation);
35
+ var enableRowEdit = !!((_e = (_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.rowOperation) === null || _e === void 0 ? void 0 : _e.rowEdit);
36
+ // 操作列列宽是动态的,需要从配置中取出
37
+ var operationColWidth = ((_g = (_f = propsRef.current) === null || _f === void 0 ? void 0 : _f.rowOperation) === null || _g === void 0 ? void 0 : _g.width) || _const.ROW_OPERATION_COL_WIDTH;
38
+ var fields = propsRef.current.fields;
39
+ // 分页
40
+ var enablePagination = !!((_h = propsRef.current) === null || _h === void 0 ? void 0 : _h.pagination);
41
+ // 是否存在过滤字段
42
+ var enableFilter = !!propsRef.current.filter && fields.some(function (field) {
43
+ var _a;
44
+ return !!((_a = field.control) === null || _a === void 0 ? void 0 : _a.filter);
45
+ });
46
+ // 表头过滤是否启用远程数据
47
+ var enableRemoteFilter = enableAsyncData && enableFilter && !!((_j = propsRef.current.filter) === null || _j === void 0 ? void 0 : _j.remote);
48
+ // 是否存在排序字段
49
+ var enableSorter = !!propsRef.current.sorter && fields.some(function (field) {
50
+ var _a;
51
+ return !!((_a = field.control) === null || _a === void 0 ? void 0 : _a.sorter);
52
+ });
53
+ // 表头排序是否启用远程数据
54
+ var enableRemoteSorter = enableAsyncData && enableSorter && !!((_k = propsRef.current.sorter) === null || _k === void 0 ? void 0 : _k.remote);
55
+ // 是否启用行展开
56
+ var enableRowExpanding = !!propsRef.current.expanding;
57
+ // 是否启用列分组
58
+ var enableRowGrouping = !!propsRef.current.grouping;
59
+ // 底部容器是否为空
60
+ var isBottomEmpty =
61
+ // 没有左侧的行选择指示器
62
+ !((_l = propsRef.current.rowSelection) === null || _l === void 0 ? void 0 : _l.enableIndicator) &&
63
+ // 也没有分页器
64
+ !propsRef.current.pagination;
65
+ return {
66
+ enableAsyncData: enableAsyncData,
67
+ hasNestHeader: hasNestHeader,
68
+ enableRowSelection: enableRowSelection,
69
+ enableRowOperation: enableRowOperation,
70
+ enableRowEdit: enableRowEdit,
71
+ operationColWidth: operationColWidth,
72
+ enablePagination: enablePagination,
73
+ enableHeaderActionHoverOnly: !!((_m = propsRef.current.headerAction) === null || _m === void 0 ? void 0 : _m.onlyVisibleOnHover),
74
+ enableFilter: enableFilter,
75
+ enableRemoteFilter: enableRemoteFilter,
76
+ enableSorter: enableSorter,
77
+ enableRemoteSorter: enableRemoteSorter,
78
+ enableRowExpanding: enableRowExpanding,
79
+ enableRowGrouping: enableRowGrouping,
80
+ isBottomEmpty: isBottomEmpty
81
+ };
82
+ }
83
+ /**
84
+ * 全局静态配置
85
+ * @desc 实际上并不是完全静态,而是指由配置生成后,禁止主动变化
86
+ */
87
+ function useGlobalStatic(ctx) {
88
+ var _a, _b, _c;
89
+ var table = ctx.table,
90
+ subscription = ctx.subscription,
91
+ propsRef = ctx.propsRef;
92
+ var isEmpty =
93
+ // 表格数据长度为0
94
+ subscription.getValue().length === 0 ||
95
+ // 表格数据过滤后长度为0
96
+ table.getFilteredRowModel().rows.length === 0;
97
+ var showFooter = !isEmpty && !!((_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.showFooter);
98
+ var hasStickyFooter = showFooter && !!((_c = (_b = propsRef.current) === null || _b === void 0 ? void 0 : _b.sticky) === null || _c === void 0 ? void 0 : _c.footer) || undefined;
99
+ var _columnPinning = table.getState().columnPinning;
100
+ var hasLeftFixed = _columnPinning.left !== undefined && _columnPinning.left.length > 0;
101
+ var hasRightFixed = _columnPinning.right !== undefined && _columnPinning.right.length > 0;
102
+ var fields = propsRef.current.fields;
103
+ var editableFieldKeys = React.useMemo(function () {
104
+ return genEditableFieldKeys(fields);
105
+ }, [fields]);
106
+ var staticOpts = ctx.staticOptsRef.current;
107
+ var globalStatic = {
108
+ enableAsyncData: staticOpts.enableAsyncData,
109
+ isEmpty: isEmpty,
110
+ showFooter: showFooter,
111
+ hasStickyFooter: hasStickyFooter,
112
+ hasNestHeader: staticOpts.hasNestHeader,
113
+ hasLeftFixed: hasLeftFixed,
114
+ hasRightFixed: hasRightFixed,
115
+ enableRowSelection: staticOpts.enableRowSelection,
116
+ enableRowOperation: staticOpts.enableRowOperation,
117
+ enableRowEdit: staticOpts.enableRowEdit,
118
+ operationColWidth: staticOpts.operationColWidth,
119
+ editableFieldKeys: editableFieldKeys,
120
+ enablePagination: staticOpts.enablePagination,
121
+ enableHeaderActionHoverOnly: staticOpts.enableHeaderActionHoverOnly,
122
+ enableFilter: staticOpts.enableFilter,
123
+ enableRemoteFilter: staticOpts.enableRemoteFilter,
124
+ enableSorter: staticOpts.enableSorter,
125
+ enableRemoteSorter: staticOpts.enableRemoteSorter,
126
+ enableRowExpanding: staticOpts.enableRowExpanding,
127
+ enableRowGrouping: staticOpts.enableRowGrouping,
128
+ isBottomEmpty: staticOpts.isBottomEmpty
129
+ };
130
+ return ahooks.useLatest(globalStatic);
131
+ }
132
+ /**
133
+ * 生成所有可编辑字段的 key
134
+ * @desc 仅在可编辑表格中生效
135
+ */
136
+ function genEditableFieldKeys(fields) {
137
+ var result = [];
138
+ var traverse = function traverse(field) {
139
+ var _a;
140
+ // 如果有children,递归处理children
141
+ if ((_a = field.children) === null || _a === void 0 ? void 0 : _a.length) {
142
+ field.children.forEach(traverse);
143
+ return;
144
+ }
145
+ var _ref = field.control || {},
146
+ readonly = _ref.readonly,
147
+ editable = _ref.editable;
148
+ // 明确只读,不可编辑
149
+ if (readonly) return;
150
+ // 明确不可编辑
151
+ if (editable === false) return;
152
+ result.push(field.dataIndex);
153
+ };
154
+ fields.forEach(traverse);
155
+ return result;
156
+ }
157
+ exports.genStaticOptsFromPropsRef = genStaticOptsFromPropsRef;
158
+ exports.useGlobalStatic = useGlobalStatic;
@@ -0,0 +1,30 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ var _typeof = require("@babel/runtime/helpers/typeof");
13
+ Object.defineProperty(exports, '__esModule', {
14
+ value: true
15
+ });
16
+ var React = require('react');
17
+ var ahooks = require('ahooks');
18
+ function _interopDefaultCompat(e) {
19
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
20
+ 'default': e
21
+ };
22
+ }
23
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
24
+ function useInitialRender() {
25
+ var forceUpdate = ahooks.useUpdate();
26
+ React__default["default"].useEffect(function () {
27
+ forceUpdate();
28
+ }, [forceUpdate]);
29
+ }
30
+ exports.useInitialRender = useInitialRender;
@@ -0,0 +1,105 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+ var ahooks = require('ahooks');
17
+ var useTableMeta = require('./use-table-meta.js');
18
+
19
+ /**
20
+ * 组装内部上下文
21
+ * @desc 没啥特殊逻辑,完全是Table里代码太多了,精简拆分一下
22
+ */
23
+ function useTableInnerCtx(ctx) {
24
+ var table = ctx.table,
25
+ setDynamicOpts = ctx.setDynamicOpts,
26
+ subscription = ctx.subscription,
27
+ tableContainerRef = ctx.tableContainerRef,
28
+ rowActions = ctx.rowActions,
29
+ rowSelectionState = ctx.rowSelectionState,
30
+ paginationState = ctx.paginationState,
31
+ filterState = ctx.filterState,
32
+ sorterState = ctx.sorterState,
33
+ propsRef = ctx.propsRef,
34
+ globalStaticRef = ctx.globalStaticRef,
35
+ globalActionsRef = ctx.globalActionsRef,
36
+ rerender = ctx.rerender,
37
+ getFieldsValue = ctx.getFieldsValue,
38
+ getGroupedValues = ctx.getGroupedValues;
39
+ var _globalActionsRef$cur = globalActionsRef.current,
40
+ getDataSource = _globalActionsRef$cur.getDataSource,
41
+ updateDataSource = _globalActionsRef$cur.updateDataSource,
42
+ resetDataSource = _globalActionsRef$cur.resetDataSource,
43
+ setDataSource = _globalActionsRef$cur.setDataSource,
44
+ setSelectedRowKeys = _globalActionsRef$cur.setSelectedRowKeys;
45
+ var scrollIntoView = React.useCallback(function scrollIntoView(behavior) {
46
+ if (behavior === void 0) {
47
+ behavior = 'instant';
48
+ }
49
+ var _a;
50
+ (_a = tableContainerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
51
+ top: 0,
52
+ left: 0,
53
+ behavior: behavior
54
+ });
55
+ }, [tableContainerRef]);
56
+ var exposeCtxValue = function exposeCtxValue() {
57
+ var exposed = Object.assign(Object.assign({
58
+ table: table,
59
+ subscription: subscription,
60
+ rowActions: rowActions,
61
+ rerender: rerender,
62
+ getFieldsValue: getFieldsValue,
63
+ getGroupedValues: getGroupedValues,
64
+ getDataSource: getDataSource,
65
+ updateDataSource: updateDataSource,
66
+ resetDataSource: resetDataSource,
67
+ setDataSource: setDataSource
68
+ }, useTableMeta.getCellOpFn(table)), {
69
+ setSelectedRowKeys: setSelectedRowKeys,
70
+ scrollIntoView: scrollIntoView,
71
+ innerRef: getInnerRef()
72
+ });
73
+ return exposed;
74
+ };
75
+ // 内部可能会需要暴露出去的值
76
+ var exposeCtxValueRef = ahooks.useLatest(exposeCtxValue);
77
+ var ctxValue = React.useMemo(function () {
78
+ var values = {
79
+ table: table,
80
+ setDynamicOpts: setDynamicOpts,
81
+ subscription: subscription,
82
+ tableContainerRef: tableContainerRef,
83
+ rowActions: rowActions,
84
+ rowSelectionState: rowSelectionState,
85
+ paginationState: paginationState,
86
+ filterState: filterState,
87
+ sorterState: sorterState,
88
+ propsRef: propsRef,
89
+ globalStaticRef: globalStaticRef,
90
+ globalActionsRef: globalActionsRef,
91
+ exposeCtxValueRef: exposeCtxValueRef
92
+ };
93
+ return values;
94
+ }, [table, setDynamicOpts, subscription, tableContainerRef, rowActions, rowSelectionState, paginationState, filterState, sorterState, propsRef, globalStaticRef, globalActionsRef, exposeCtxValueRef]);
95
+ function getInnerRef() {
96
+ return {
97
+ current: ctxValue
98
+ };
99
+ }
100
+ return {
101
+ ctxValue: ctxValue,
102
+ exposeCtxValue: exposeCtxValue
103
+ };
104
+ }
105
+ exports.useTableInnerCtx = useTableInnerCtx;
@@ -0,0 +1,108 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var ahooks = require('ahooks');
16
+ var schemaUtils = require('@hi-ui/schema-utils');
17
+ var useOpts = require('../features/pagination/use-opts.js');
18
+ var _const = require('../features/row-selection/const.js');
19
+ var useGlobalStatic = require('./use-global-static.js');
20
+ function getNormalizedProps(props) {
21
+ var _a;
22
+ var debugOpts = schemaUtils.getBoolConfig(props.debug, {
23
+ debugAll: true
24
+ }, {
25
+ mergeDft: false
26
+ } // 不合并默认值,用户只要传值,就都以用户为准
27
+ );
28
+ // 表头和表尾的 fixed 配置
29
+ var stickyOpts = schemaUtils.getBoolConfig(props.sticky,
30
+ // stickyOpts
31
+ {
32
+ header: true,
33
+ footer: true
34
+ }, {
35
+ mergeDft: true
36
+ });
37
+ // 虚拟化配置
38
+ var virtualizeConfig = schemaUtils.getBoolConfig(props.virtualize, {
39
+ row: true,
40
+ column: true
41
+ }, {
42
+ mergeDft: true
43
+ });
44
+ var virtualizeOpts = virtualizeConfig ? {
45
+ row: schemaUtils.getBoolConfig(virtualizeConfig === null || virtualizeConfig === void 0 ? void 0 : virtualizeConfig.row, {}),
46
+ column: schemaUtils.getBoolConfig(virtualizeConfig === null || virtualizeConfig === void 0 ? void 0 : virtualizeConfig.column, {})
47
+ } : undefined;
48
+ // 行选择配置
49
+ var rowSelectionConfig = schemaUtils.getBoolConfig(props.rowSelection, {
50
+ type: _const.dftSelectionType
51
+ }, {
52
+ mergeDft: true
53
+ });
54
+ var rowSelectionOpts = rowSelectionConfig ? Object.assign(Object.assign({}, rowSelectionConfig), {
55
+ enableIndicator: schemaUtils.getBoolConfig(rowSelectionConfig === null || rowSelectionConfig === void 0 ? void 0 : rowSelectionConfig.enableIndicator, {})
56
+ }) : undefined;
57
+ // 行操作配置
58
+ var rowOperationOpts = schemaUtils.getBoolConfig(props.rowOperation, {});
59
+ // 分页配置
60
+ var paginationOpts = schemaUtils.getBoolConfig(props.pagination, {
61
+ pageSize: useOpts.dftPageSize
62
+ }, {
63
+ mergeDft: true
64
+ });
65
+ // 筛选配置
66
+ var filterOpts = schemaUtils.getBoolConfig(props.filter, {});
67
+ // 排序配置
68
+ var sorterOpts = schemaUtils.getBoolConfig(props.sorter, {
69
+ sortUndefined: 'last'
70
+ }, {
71
+ mergeDft: true
72
+ });
73
+ var sorterTooltipOpts = schemaUtils.getBoolConfig(sorterOpts === null || sorterOpts === void 0 ? void 0 : sorterOpts.tooltip, {});
74
+ var nextSorterOpts = sorterOpts ? Object.assign(Object.assign({}, sorterOpts), {
75
+ tooltip: sorterTooltipOpts
76
+ }) : undefined;
77
+ // 列分组配置
78
+ var groupingOpts = schemaUtils.getBoolConfig(props.grouping, {});
79
+ // 行展开配置
80
+ // 如果列分组配置存在,则行展开配置默认开启
81
+ var expandingOpts = schemaUtils.getBoolConfig((_a = props.expanding) !== null && _a !== void 0 ? _a : !!groupingOpts, {});
82
+ return Object.assign(Object.assign({}, props), {
83
+ subRowKey: props.subRowKey || 'children',
84
+ debug: debugOpts,
85
+ sticky: stickyOpts,
86
+ virtualize: virtualizeOpts,
87
+ rowSelection: rowSelectionOpts,
88
+ rowOperation: rowOperationOpts,
89
+ pagination: paginationOpts,
90
+ filter: filterOpts,
91
+ sorter: nextSorterOpts,
92
+ grouping: groupingOpts,
93
+ expanding: expandingOpts
94
+ });
95
+ }
96
+ function usePropsRef(props) {
97
+ var nextProps = getNormalizedProps(props);
98
+ var propsRef = ahooks.useLatest(nextProps);
99
+ // 把只依赖 propsRef 的选项配置提前到此处生成
100
+ var staticOpts = useGlobalStatic.genStaticOptsFromPropsRef(propsRef);
101
+ var staticOptsRef = ahooks.useLatest(staticOpts);
102
+ return {
103
+ propsRef: propsRef,
104
+ staticOptsRef: staticOptsRef
105
+ };
106
+ }
107
+ exports.getNormalizedProps = getNormalizedProps;
108
+ exports.usePropsRef = usePropsRef;
@@ -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
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+ require('@hi-ui/use-subscription');
17
+ require('lodash-es');
18
+ require('@tanstack/react-table');
19
+ require('@hi-ui/schema-utils');
20
+ require('../utils/cls.js');
21
+ require('ahooks');
22
+ var getFilterConfig = require('../features/filter/get-filter-config.js');
23
+ require('@hi-ui/schema-table-extensions');
24
+ var getSorterConfig = require('../features/sorter/get-sorter-config.js');
25
+ var getGroupingConfig = require('../features/column-grouping/get-grouping-config.js');
26
+ function MapFieldConfigToColumnDef(fields, ctx) {
27
+ var propsRef = ctx.propsRef;
28
+ return fields.map(function (field) {
29
+ var _a, _b;
30
+ var filterConfig = getFilterConfig.getFilterConfig(field);
31
+ var sorterConfig = getSorterConfig.getSorterConfig(field, {
32
+ propsRef: propsRef
33
+ });
34
+ var groupingConfig = getGroupingConfig.getGroupingConfig(field);
35
+ // dataIndex 是必填项,否则无法正确渲染表格
36
+ // NOTE header 采用复杂单元格渲染后,dataIndex 必填,否则会直接导致表格崩溃
37
+ // 也就是说,打开下面 [header: field.title,] 这行的注释后,dataIndex 也可以不填[doge]
38
+ if (!field.dataIndex) {
39
+ var fieldName = field._titleText || field.title || field.key;
40
+ console.error("EditableSchemaTable: \u5B57\u6BB5\u3010" + fieldName + "\u3011\u7F3A\u5C11 dataIndex \u5C5E\u6027\uFF0C\u8BF7\u68C0\u67E5\u540E\u8865\u5145\uFF01\n");
41
+ }
42
+ return {
43
+ // header: field.title,
44
+ accessorKey: field.dataIndex,
45
+ size: (_a = field.wrapperProps) === null || _a === void 0 ? void 0 : _a.width,
46
+ columns: field.children ? MapFieldConfigToColumnDef(field.children, ctx) : undefined,
47
+ filterFn: filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.filterFn,
48
+ sortingFn: sorterConfig === null || sorterConfig === void 0 ? void 0 : sorterConfig.sortingFn,
49
+ sortUndefined: sorterConfig === null || sorterConfig === void 0 ? void 0 : sorterConfig.sortUndefined,
50
+ aggregationFn: groupingConfig === null || groupingConfig === void 0 ? void 0 : groupingConfig.aggregationFn,
51
+ // count
52
+ meta: Object.assign(Object.assign({
53
+ field: field
54
+ }, field.control), {
55
+ filter: filterConfig,
56
+ sorter: sorterConfig,
57
+ grouping: groupingConfig,
58
+ shouldUpdate: (_b = field.payload) === null || _b === void 0 ? void 0 : _b.shouldUpdate
59
+ })
60
+ // TODO 待确认还有其他的能直接透传给 ColumnDef 的属性
61
+ };
62
+ });
63
+ }
64
+
65
+ function useTableColumns(ctx) {
66
+ var propsRef = ctx.propsRef;
67
+ var fields = propsRef.current.fields;
68
+ return React.useMemo(function () {
69
+ var cols = MapFieldConfigToColumnDef(fields, {
70
+ propsRef: propsRef
71
+ });
72
+ return cols;
73
+ }, [fields, propsRef]);
74
+ }
75
+ exports.MapFieldConfigToColumnDef = MapFieldConfigToColumnDef;
76
+ exports.useTableColumns = useTableColumns;
@@ -0,0 +1,57 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var lodashEs = require('lodash-es');
16
+ var useTableMeta = function useTableMeta(tableValue, ctx) {
17
+ var updateData = function updateData(rowIndex, columnId, value) {
18
+ var _rowIndex, _patch;
19
+ var patch = (_patch = {}, _patch[rowIndex] = (_rowIndex = {}, _rowIndex[columnId] = value, _rowIndex), _patch);
20
+ // 行编辑模式下,不必检查是否相等,直接写入 draft
21
+ var enableRowEdit = ctx.innerRef.current.globalStaticRef.current.enableRowEdit;
22
+ if (enableRowEdit) {
23
+ tableValue.mergeDraft(patch);
24
+ return;
25
+ }
26
+ // 普通编辑模式
27
+ var allValues = tableValue.getValue();
28
+ var prevValue = lodashEs.get(allValues, [rowIndex, columnId]);
29
+ // 值相等,则不更新
30
+ if (lodashEs.isEqual(prevValue, value)) return;
31
+ tableValue.batchMerge(patch).then(function (result) {
32
+ var _a;
33
+ if (result) {
34
+ (_a = ctx.onValuesChange) === null || _a === void 0 ? void 0 : _a.call(ctx, result.changedValues, result.allValues);
35
+ }
36
+ });
37
+ };
38
+ var getCellValue = function getCellValue(rowIndex, columnId) {
39
+ return lodashEs.get(tableValue.getValue(), [rowIndex, columnId]);
40
+ };
41
+ return {
42
+ subscription: tableValue,
43
+ fieldMap: ctx.fieldMap,
44
+ updateData: updateData,
45
+ getCellValue: getCellValue,
46
+ innerRef: ctx.innerRef
47
+ };
48
+ };
49
+ function getCellOpFn(table) {
50
+ var _a, _b;
51
+ return {
52
+ getCellValue: (_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.getCellValue,
53
+ setCellValue: (_b = table.options.meta) === null || _b === void 0 ? void 0 : _b.updateData
54
+ };
55
+ }
56
+ exports.getCellOpFn = getCellOpFn;
57
+ exports.useTableMeta = useTableMeta;
@@ -0,0 +1,57 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+ var schemaHooks = require('@hi-ui/schema-hooks');
17
+
18
+ /**
19
+ * 监听表格数据变化,并触发重渲染
20
+ * @notice 仅在表格数据发生【全量变化】时触发重渲染
21
+ * @param tableValue 表格数据
22
+ * @returns 重渲染函数
23
+ */
24
+ // NOTE 1. pendingRef存在的意义
25
+ // 避免在同一个微任务周期内,多次触发重渲染
26
+ // 例如在循环中,多次触发 rowActions.addRow()
27
+ // NOTE 2. 重渲染次数
28
+ // 此处内部的 rerender() 会触发一次重渲染
29
+ // 随后 useReactTable 接受到新的数据后,会再次触发一次重渲染
30
+ // 两次重渲染暂不可避免,仅在此处记录
31
+ function useTableUpdate(tableValue) {
32
+ var _useUpdate = schemaHooks.useUpdate(),
33
+ forceRerenderFlag = _useUpdate[0],
34
+ rerender = _useUpdate[1];
35
+ var pendingRef = React.useRef(false);
36
+ React.useEffect(function () {
37
+ return tableValue.subscribe(function (notification) {
38
+ var _a, _b;
39
+ // 静默更新时,不再执行
40
+ if ((_a = notification.extra) === null || _a === void 0 ? void 0 : _a.silent) return;
41
+ if ((_b = notification.extra) === null || _b === void 0 ? void 0 : _b.complete) {
42
+ if (pendingRef.current) return;
43
+ pendingRef.current = true;
44
+ // 一个微任务周期内仅执行一个重渲染
45
+ Promise.resolve().then(function () {
46
+ pendingRef.current = false;
47
+ rerender();
48
+ });
49
+ }
50
+ });
51
+ }, [tableValue, rerender]);
52
+ return {
53
+ rerender: rerender,
54
+ forceRerenderFlag: forceRerenderFlag
55
+ };
56
+ }
57
+ exports.useTableUpdate = useTableUpdate;