@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,56 @@
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 { createCell } from '@tanstack/react-table';
11
+ var CustomGetterFeature = {
12
+ createTable: function createTable(table) {
13
+ table.$getInnerRef = function $getInnerRef() {
14
+ var _a;
15
+ // @ts-expect-error innerRef
16
+ return (_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.innerRef;
17
+ };
18
+ table.$getCell = function $getCell(cellId) {
19
+ var firstUnderscoreIndex = cellId.indexOf('_');
20
+ var rowId = cellId.slice(0, firstUnderscoreIndex);
21
+ var columnId = cellId.slice(firstUnderscoreIndex + 1);
22
+ var row = table.getRow(rowId);
23
+ if (!row) return null;
24
+ var column = table.getColumn(columnId);
25
+ if (!column) return null;
26
+ return createCell(table, row, column, columnId);
27
+ };
28
+ table.$getRealtimeRowData = function getTableRealtimeRowData(rowId) {
29
+ var _a;
30
+ try {
31
+ var row = table.getRow(rowId);
32
+ if (!row) return undefined;
33
+ var subscription = (_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.subscription;
34
+ if (!subscription) return undefined;
35
+ var rowIndex = row.index;
36
+ return subscription.getValue()[rowIndex];
37
+ } catch (error) {
38
+ return undefined;
39
+ }
40
+ };
41
+ },
42
+ createRow: function createRow(row, table) {
43
+ row.$getRealtimeRowData = function getRealtimeRowData() {
44
+ // 这里的 row.original 实际上没用
45
+ // getRealtimeRowData 会返回 undefined 是因为 rowId 可能会被用户误传
46
+ // 但此处的 rowId 是不会错误的,所以只是留一个 fallback
47
+ return table.$getRealtimeRowData(row.id) || row.original;
48
+ };
49
+ },
50
+ createCell: function createCell(cell, column, row) {
51
+ cell.$getRealtimeRowData = function getRealtimeCellRowData() {
52
+ return row.$getRealtimeRowData();
53
+ };
54
+ }
55
+ };
56
+ export { CustomGetterFeature };
@@ -0,0 +1,35 @@
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 { EMPTY_VALUE } from '../../const.js';
11
+ import '../../utils/cls.js';
12
+ import { isEmptyValue } from '../../utils/grouping.js';
13
+
14
+ /**
15
+ * 自定义分组特性
16
+ * 主要用于处理分组值为null或undefined的情况,将不同类型的空值统一为一个特殊标记
17
+ * 这样所有的空值都会被归为同一组,而不是分散在不同的组中
18
+ */
19
+ var CustomGroupingFeature = {
20
+ createRow: function createRow(row) {
21
+ // 保存原始的getGroupingValue方法
22
+ var originalGetGroupingValue = row.getGroupingValue;
23
+ // 重写getGroupingValue方法,统一处理空值
24
+ row.getGroupingValue = function (columnId) {
25
+ // 获取原始分组值
26
+ var value = originalGetGroupingValue.call(this, columnId);
27
+ // 如果是空值,统一返回特殊标记
28
+ if (isEmptyValue(value)) {
29
+ return EMPTY_VALUE;
30
+ }
31
+ return value;
32
+ };
33
+ }
34
+ };
35
+ export { CustomGroupingFeature };
@@ -0,0 +1,38 @@
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 { dftPageSize } from '../pagination/use-opts.js';
11
+
12
+ // 内置 Feature 的覆写逻辑
13
+ var OverridesFeature = {
14
+ createTable: function createTable(table) {
15
+ // 覆写 resetPagination 方法
16
+ if (!table.originalResetPagination) table.originalResetPagination = table.resetPagination;
17
+ table.resetPagination = function resetPagination(defaultState) {
18
+ var _a;
19
+ // 先从分页状态中取行数,否则从 table 实例数据上取
20
+ // 原因是后端分页时,table 实例上只有一页的数据,不准
21
+ var rowCount = (_a = table.getState().pagination.rowCount) !== null && _a !== void 0 ? _a : table.getRowCount();
22
+ if (defaultState) {
23
+ var pageSize = dftPageSize;
24
+ table.setPagination({
25
+ pageIndex: 0,
26
+ pageSize: pageSize,
27
+ rowCount: rowCount
28
+ });
29
+ } else {
30
+ var pagination = table.initialState.pagination;
31
+ table.setPagination(Object.assign(Object.assign({}, pagination), {
32
+ rowCount: rowCount
33
+ }));
34
+ }
35
+ };
36
+ }
37
+ };
38
+ export { OverridesFeature };
@@ -0,0 +1,135 @@
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 { Schedular } from '@hi-ui/schema-utils';
11
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
12
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
13
+ if (it) return (it = it.call(o)).next.bind(it);
14
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
15
+ if (it) o = it;
16
+ var i = 0;
17
+ return function () {
18
+ if (i >= o.length) return {
19
+ done: true
20
+ };
21
+ return {
22
+ done: false,
23
+ value: o[i++]
24
+ };
25
+ };
26
+ }
27
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
28
+ }
29
+ function _unsupportedIterableToArray(o, minLen) {
30
+ if (!o) return;
31
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
32
+ var n = Object.prototype.toString.call(o).slice(8, -1);
33
+ if (n === "Object" && o.constructor) n = o.constructor.name;
34
+ if (n === "Map" || n === "Set") return Array.from(o);
35
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
36
+ }
37
+ function _arrayLikeToArray(arr, len) {
38
+ if (len == null || len > arr.length) len = arr.length;
39
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
40
+ arr2[i] = arr[i];
41
+ }
42
+ return arr2;
43
+ }
44
+ var CustomRowSelectionFeature = {
45
+ createTable: function createTable(table) {
46
+ table.$rowSelectionCache = {
47
+ selectedRows: [],
48
+ selectedRowKeys: [],
49
+ selectedRowEntries: []
50
+ };
51
+ table.$selectedRowsCache = new Map();
52
+ table.$getRowSelection = function $getRowSelection(state) {
53
+ var newState = state || table.getState().rowSelection;
54
+ // 如果 state 为空,则说明不是在变更时调用的,直接返回缓存
55
+ if (!state) return table.$rowSelectionCache;
56
+ var innerRef = table.$getInnerRef();
57
+ var allRows = innerRef.current.subscription.getValue();
58
+ var preserveSelectedRows = getEnablePreserveSelectedRows();
59
+ var selectedRowKeys = [];
60
+ var selectedRows = [];
61
+ var selectedRowEntries = [];
62
+ for (var _i = 0, _Object$entries = Object.entries(newState); _i < _Object$entries.length; _i++) {
63
+ var _Object$entries$_i = _Object$entries[_i],
64
+ rowId = _Object$entries$_i[0],
65
+ selected = _Object$entries$_i[1];
66
+ if (!selected) continue; // selected 应该不可能为 false,此处保留用作保险
67
+ selectedRowKeys.push(rowId);
68
+ try {
69
+ var row = table.getRow(rowId);
70
+ var rowData = allRows[row.index];
71
+ selectedRows.push(rowData);
72
+ selectedRowEntries.push([rowId, rowData]);
73
+ } catch (error) {
74
+ // 走到这里,说明 getRow 执行失败了
75
+ if (preserveSelectedRows) {
76
+ var _rowData = table.$selectedRowsCache.get(rowId);
77
+ if (_rowData) {
78
+ selectedRows.push(_rowData);
79
+ selectedRowEntries.push([rowId, _rowData]);
80
+ }
81
+ }
82
+ }
83
+ }
84
+ var selection = {
85
+ selectedRows: selectedRows,
86
+ selectedRowKeys: selectedRowKeys,
87
+ selectedRowEntries: selectedRowEntries
88
+ };
89
+ table.$rowSelectionCache = selection;
90
+ return selection;
91
+ };
92
+ table.$updateSelectedRowsCache = function $updateSelectedRowsCache(entries) {
93
+ var preserveSelectedRows = getEnablePreserveSelectedRows();
94
+ // 仅在开启 preserveSelectedRows 时才更新缓存
95
+ if (preserveSelectedRows) {
96
+ for (var _iterator = _createForOfIteratorHelperLoose(entries), _step; !(_step = _iterator()).done;) {
97
+ var _step$value = _step.value,
98
+ _rowId = _step$value[0],
99
+ rowData = _step$value[1];
100
+ table.$selectedRowsCache.set(_rowId, rowData);
101
+ }
102
+ // 清除已经取消选择的行的缓存记录
103
+ var innerRef = table.$getInnerRef();
104
+ var rowSelectionState = innerRef.current.rowSelectionState;
105
+ var stateValue = rowSelectionState.getValue();
106
+ for (var rowId in stateValue) {
107
+ if (stateValue[rowId] === false) {
108
+ table.$selectedRowsCache["delete"](rowId);
109
+ }
110
+ }
111
+ }
112
+ };
113
+ function getEnablePreserveSelectedRows() {
114
+ var _a;
115
+ var innerRef = table.$getInnerRef();
116
+ return (_a = innerRef.current.propsRef.current.rowSelection) === null || _a === void 0 ? void 0 : _a.preserveSelectedRows;
117
+ }
118
+ },
119
+ createRow: function createRow(row) {
120
+ row.$afterToggleSelected = function afterToggleSelected() {
121
+ var parentRows = row.getParentRows();
122
+ // 父行不会很多,所以直接反序后遍历
123
+ parentRows.toReversed().forEach(function (parentRow) {
124
+ // 使用微任务调度则是因为,状态的变更稍微有一点点延迟,会拿不到实时的状态
125
+ Schedular.nextMicro(function () {
126
+ var isParentSelected = parentRow.getIsAllSubRowsSelected();
127
+ parentRow.toggleSelected(isParentSelected, {
128
+ selectChildren: false
129
+ });
130
+ });
131
+ });
132
+ };
133
+ }
134
+ };
135
+ export { CustomRowSelectionFeature };
@@ -0,0 +1,143 @@
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 { useEffect } from 'react';
12
+ import { useDebounceFn } from 'ahooks';
13
+ import { isNil } from 'lodash-es';
14
+ import { useReadonlyRef, useDeepCompareFlag, useIsFirstMount } from '@hi-ui/schema-hooks';
15
+ import { useEditableSchemaTableCtx } from '../../ctx.js';
16
+
17
+ // 单纯只是为了包装一下 useAsyncData
18
+ // ~~避免在 Table 最顶层调用时频繁触发重渲染~~
19
+ // NOTE 上述目的没有达到,暂时先留着吧,指不定后面又有新用途了
20
+ function AsyncDataGetter() {
21
+ var ctx = useEditableSchemaTableCtx();
22
+ var innerRef = useReadonlyRef(function () {
23
+ return ctx;
24
+ });
25
+ useAsyncData({
26
+ innerRef: innerRef
27
+ });
28
+ return null;
29
+ }
30
+ function useAsyncData(ctx) {
31
+ var innerRef = ctx.innerRef;
32
+ var globalStaticRef = innerRef.current.globalStaticRef;
33
+ var enableAsyncData = globalStaticRef.current.enableAsyncData;
34
+ // 分页/筛选状态变更时,table会自动触发重渲染,此处不必单独监听
35
+ var _innerRef$current = innerRef.current,
36
+ filterState = _innerRef$current.filterState,
37
+ sorterState = _innerRef$current.sorterState,
38
+ paginationState = _innerRef$current.paginationState;
39
+ // 异步数据源需要监听的状态
40
+ var _paginationState$getV = paginationState.getValue(),
41
+ pageSize = _paginationState$getV.pageSize,
42
+ pageIndex = _paginationState$getV.pageIndex;
43
+ // 如果启用了远程筛选,则使用筛选状态,否则不监听 filters 变化
44
+ var filters = filterState.getValue();
45
+ var effectiveFilters = globalStaticRef.current.enableRemoteFilter ? filters : undefined;
46
+ var hasFilterChanged = useDeepCompareFlag([effectiveFilters]);
47
+ var sorters = sorterState.getValue();
48
+ // 如果启用了远程排序,则使用排序状态,否则不监听 sorters 变化
49
+ var effectiveSorters = globalStaticRef.current.enableRemoteSorter ? sorters : undefined;
50
+ var hasSorterChanged = useDeepCompareFlag([effectiveSorters]);
51
+ // 标记是否初次挂载
52
+ var isFirstMountRef = useIsFirstMount();
53
+ var _useDebounceFn = useDebounceFn(function fetchData() {
54
+ var _a;
55
+ // 内部主动设置的分页状态,不请求数据
56
+ // 内部主动设置的分页状态,不请求数据
57
+ var fromCustomPagination = innerRef.current.table.getState().pagination.$fromCustom;
58
+ if (fromCustomPagination) return;
59
+ // 启用 blockInitialRequest 时,初次挂载时不请求数据
60
+ // 启用 blockInitialRequest 时,初次挂载时不请求数据
61
+ var propsRef = innerRef.current.propsRef;
62
+ var blockInitialRequest = (_a = propsRef.current.asyncData) === null || _a === void 0 ? void 0 : _a.blockInitialRequest;
63
+ if (isFirstMountRef.current && blockInitialRequest) return;
64
+ // 真实请求逻辑
65
+ // 真实请求逻辑
66
+ if (enableAsyncData) {
67
+ var globalActionsRef = innerRef.current.globalActionsRef;
68
+ globalActionsRef.current.updateDataSource();
69
+ }
70
+ },
71
+ // 16 毫秒内的变更仅触发一次请求
72
+ // 以达到短时间内多次状态变更的批处理效果
73
+ {
74
+ wait: 16
75
+ }),
76
+ fetchData = _useDebounceFn.run;
77
+ useEffect(function () {
78
+ fetchData();
79
+ }, [fetchData,
80
+ // 不会触发重渲染
81
+ isFirstMountRef, enableAsyncData, innerRef,
82
+ // 以下为触发请求接口的值
83
+ pageSize, pageIndex, hasFilterChanged, hasSorterChanged]);
84
+ }
85
+ function validateResData(data) {
86
+ // 空值检查
87
+ if (isNil(data)) {
88
+ console.warn('EditTable useAsyncData: 主数据不能为空');
89
+ return false;
90
+ }
91
+ // 对象类型检查
92
+ if (_typeof(data) !== 'object' || Array.isArray(data)) {
93
+ console.warn('EditTable useAsyncData: useAsyncData: 主数据必须是对象类型');
94
+ return false;
95
+ }
96
+ var pass = true;
97
+ var res = data;
98
+ // 必要字段存在性检查
99
+ if (!('list' in res)) {
100
+ console.warn('EditTable useAsyncData: 主数据缺少必要字段: list');
101
+ pass = false;
102
+ }
103
+ if (!('total' in res)) {
104
+ console.warn('EditTable useAsyncData: 主数据缺少必要字段: total');
105
+ pass = false;
106
+ }
107
+ if (!('pageSize' in res)) {
108
+ console.warn('EditTable useAsyncData: 主数据缺少必要字段: pageSize');
109
+ pass = false;
110
+ }
111
+ if (!('current' in res)) {
112
+ console.warn('EditTable useAsyncData: 主数据缺少必要字段: current');
113
+ pass = false;
114
+ }
115
+ // 分阶段检查,本阶段未通过,不再检查剩余项目
116
+ if (!pass) return false;
117
+ // 字段类型检查
118
+ if (!Array.isArray(res.list)) {
119
+ console.warn('EditTable useAsyncData: list字段必须是数组类型');
120
+ pass = false;
121
+ }
122
+ if (typeof res.total !== 'number') {
123
+ console.warn('EditTable useAsyncData: total字段必须是数字类型');
124
+ pass = false;
125
+ }
126
+ if (typeof res.pageSize !== 'number') {
127
+ console.warn('EditTable useAsyncData: pageSize字段必须是数字类型');
128
+ pass = false;
129
+ }
130
+ if (typeof res.current !== 'number') {
131
+ console.warn('EditTable useAsyncData: current字段必须是数字类型');
132
+ pass = false;
133
+ }
134
+ // list数组内容检查
135
+ if (res.list.some(function (item) {
136
+ return isNil(item) || _typeof(item) !== 'object' || Array.isArray(item);
137
+ })) {
138
+ console.warn('EditTable useAsyncData: list数组的每一项必须是对象类型');
139
+ pass = false;
140
+ }
141
+ return pass;
142
+ }
143
+ export { AsyncDataGetter, useAsyncData, validateResData };
@@ -0,0 +1,133 @@
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 _regeneratorRuntime from '@babel/runtime/regenerator';
11
+ import { __awaiter } from 'tslib';
12
+ import { useCallback } from 'react';
13
+ import { getPipeGetterValue } from '@hi-ui/schema-utils';
14
+ import { validateResData } from './getter.js';
15
+ function useGetDataSource(ctx) {
16
+ var innerRef = ctx.innerRef;
17
+ var getDataSource = useCallback(function getDataSource(customParams) {
18
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
19
+ var _a, _innerRef$current, table, globalStaticRef, propsRef, enableAsyncData, _ref, dataSourceFn, dftData, _table$getState, _table$getState$pagin, pageIndex, pageSize, sorting, columnFilters, params, enablePagination, enableRemoteFilter, enableRemoteSorter, pipeParams, beforeRequest, finalParams;
20
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
21
+ while (1) {
22
+ switch (_context.prev = _context.next) {
23
+ case 0:
24
+ _innerRef$current = innerRef.current, table = _innerRef$current.table, globalStaticRef = _innerRef$current.globalStaticRef, propsRef = _innerRef$current.propsRef;
25
+ enableAsyncData = globalStaticRef.current.enableAsyncData;
26
+ _ref = propsRef.current.asyncData || {}, dataSourceFn = _ref.request;
27
+ dftData = {
28
+ list: [],
29
+ total: 0,
30
+ pageSize: 0,
31
+ current: 0
32
+ };
33
+ if (!(!enableAsyncData || !dataSourceFn)) {
34
+ _context.next = 6;
35
+ break;
36
+ }
37
+ return _context.abrupt("return", dftData);
38
+ case 6:
39
+ _table$getState = table.getState(), _table$getState$pagin = _table$getState.pagination, pageIndex = _table$getState$pagin.pageIndex, pageSize = _table$getState$pagin.pageSize, sorting = _table$getState.sorting, columnFilters = _table$getState.columnFilters;
40
+ params = {}; // 分页
41
+ // 其实只要启用异步数据源,基本上一定会有分页
42
+ // 还是判断一下吧,就当是用来收窄类型
43
+ enablePagination = globalStaticRef.current.enablePagination;
44
+ if (enablePagination) {
45
+ params.pagination = {
46
+ current: pageIndex + 1,
47
+ pageSize: pageSize
48
+ };
49
+ }
50
+ // 筛选
51
+ enableRemoteFilter = globalStaticRef.current.enableRemoteFilter;
52
+ if (enableRemoteFilter) params.filters = columnFilters;
53
+ // 排序
54
+ enableRemoteSorter = globalStaticRef.current.enableRemoteSorter;
55
+ if (enableRemoteSorter) params.sorters = sorting;
56
+ // 若有传入 customParams,则使用 customParams 处理 params
57
+ pipeParams = getPipeGetterValue(params, customParams); // 使用 beforeRequest 处理 pipeParams
58
+ beforeRequest = ((_a = propsRef.current.asyncData) === null || _a === void 0 ? void 0 : _a.beforeRequest) || function (params) {
59
+ return params;
60
+ };
61
+ _context.next = 18;
62
+ return beforeRequest(pipeParams);
63
+ case 18:
64
+ finalParams = _context.sent;
65
+ if (finalParams) {
66
+ _context.next = 21;
67
+ break;
68
+ }
69
+ return _context.abrupt("return", dftData);
70
+ case 21:
71
+ return _context.abrupt("return", dataSourceFn(finalParams));
72
+ case 22:
73
+ case "end":
74
+ return _context.stop();
75
+ }
76
+ }
77
+ }, _callee);
78
+ }));
79
+ }, [innerRef]);
80
+ var updateDataSource = useCallback(function updateDataSource(params) {
81
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
82
+ var _a, data, _innerRef$current2, propsRef, globalStaticRef, enableDataValidate, enablePagination, _innerRef$current3, subscription, paginationState, table, _data$pageSize, dataPageSize, _data$current, current, _data$total, rowCount, pageIndex, nextState;
83
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
84
+ while (1) {
85
+ switch (_context2.prev = _context2.next) {
86
+ case 0:
87
+ _context2.next = 2;
88
+ return getDataSource(params);
89
+ case 2:
90
+ data = _context2.sent;
91
+ if (data) {
92
+ _context2.next = 5;
93
+ break;
94
+ }
95
+ return _context2.abrupt("return");
96
+ case 5:
97
+ _innerRef$current2 = innerRef.current, propsRef = _innerRef$current2.propsRef, globalStaticRef = _innerRef$current2.globalStaticRef; // 如果启用了数据完整性验证,并且启用了分页,则验证数据
98
+ enableDataValidate = (_a = propsRef.current.asyncData) === null || _a === void 0 ? void 0 : _a.enableDataValidate;
99
+ enablePagination = globalStaticRef.current.enablePagination;
100
+ if (enableDataValidate && enablePagination) validateResData(data);
101
+ _innerRef$current3 = innerRef.current, subscription = _innerRef$current3.subscription, paginationState = _innerRef$current3.paginationState, table = _innerRef$current3.table; // 表格数据直接更新到主数据订阅
102
+ subscription.setValue(data.list);
103
+ // 如果启用了分页,则更新分页状态
104
+ if (enablePagination) {
105
+ _data$pageSize = data.pageSize, dataPageSize = _data$pageSize === void 0 ? 10 : _data$pageSize, _data$current = data.current, current = _data$current === void 0 ? 1 : _data$current, _data$total = data.total, rowCount = _data$total === void 0 ? 0 : _data$total;
106
+ pageIndex = current - 1;
107
+ nextState = {
108
+ pageIndex: pageIndex,
109
+ pageSize: dataPageSize,
110
+ rowCount: rowCount
111
+ }; // 更新分页状态订阅
112
+ paginationState.setValue(nextState);
113
+ // 最后更新 table 分页状态 // 不触发 onPaginationChange
114
+ table.setState(function (state) {
115
+ return Object.assign(Object.assign({}, state), {
116
+ pagination: nextState
117
+ });
118
+ });
119
+ }
120
+ case 12:
121
+ case "end":
122
+ return _context2.stop();
123
+ }
124
+ }
125
+ }, _callee2);
126
+ }));
127
+ }, [getDataSource, innerRef]);
128
+ return {
129
+ getDataSource: getDataSource,
130
+ updateDataSource: updateDataSource
131
+ };
132
+ }
133
+ export { useGetDataSource };
@@ -0,0 +1,34 @@
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 { mergeValues } from '@hi-ui/schema-utils';
12
+ import { useRequest } from 'ahooks';
13
+
14
+ /**
15
+ * 定义的可编辑表的异步数据请求方法
16
+ * @desc 默认需要手动调用 fetchData 方法
17
+ * @desc 本质是 ahooks 的 useRequest 方法
18
+ */
19
+ function useDataFetcher(getter, extraOpts) {
20
+ var _a = useRequest(getter, mergeValues({
21
+ manual: true
22
+ }, extraOpts)),
23
+ runAsync = _a.runAsync,
24
+ rest = __rest(_a, ["runAsync"]);
25
+ return Object.assign(Object.assign({}, rest), {
26
+ runAsync: runAsync,
27
+ fetchData: runAsync
28
+ });
29
+ }
30
+ /** 定义表格异步数据请求方法 */
31
+ function defineDataFetcher(getter) {
32
+ return getter;
33
+ }
34
+ export { defineDataFetcher, useDataFetcher };
@@ -0,0 +1,79 @@
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 _regeneratorRuntime from '@babel/runtime/regenerator';
11
+ import { __awaiter } from 'tslib';
12
+ import { useCallback } from 'react';
13
+ import { Schedular } from '@hi-ui/schema-utils';
14
+ function useResetDataSource(ctx) {
15
+ var innerRef = ctx.innerRef;
16
+ var resetDataSource = useCallback(function resetDataSource(opts) {
17
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
18
+ var _a, _innerRef$current, table, globalStaticRef, propsRef, enableAsyncData, prevState, _innerRef$current2, filterState, sorterState, paginationState;
19
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
20
+ while (1) {
21
+ switch (_context.prev = _context.next) {
22
+ case 0:
23
+ _innerRef$current = innerRef.current, table = _innerRef$current.table, globalStaticRef = _innerRef$current.globalStaticRef, propsRef = _innerRef$current.propsRef;
24
+ enableAsyncData = globalStaticRef.current.enableAsyncData;
25
+ if (enableAsyncData) {
26
+ _context.next = 4;
27
+ break;
28
+ }
29
+ return _context.abrupt("return");
30
+ case 4:
31
+ prevState = table.getState();
32
+ _innerRef$current2 = innerRef.current, filterState = _innerRef$current2.filterState, sorterState = _innerRef$current2.sorterState, paginationState = _innerRef$current2.paginationState; // 先重置内部订阅
33
+ filterState.setValue(function (prev) {
34
+ return prev.length > 0 ? [] : prev;
35
+ });
36
+ sorterState.setValue(function (prev) {
37
+ return prev.length > 0 ? [] : prev;
38
+ });
39
+ paginationState.mergeValue({
40
+ pageIndex: 0,
41
+ pageSize: (_a = propsRef.current.pagination) === null || _a === void 0 ? void 0 : _a.pageSize
42
+ });
43
+ // 再更新表格状态
44
+ table.setState(function (state) {
45
+ return Object.assign(Object.assign({}, state), {
46
+ columnFilters: filterState.getValue(),
47
+ sorting: sorterState.getValue(),
48
+ pagination: paginationState.getValue()
49
+ });
50
+ });
51
+ // 有任意一个状态变更,均可触发请求(只触发一次)
52
+ // 方式是通过暂存的 prevState 来判断前后是否发生变化
53
+ Schedular.nextMicro(function () {
54
+ var _a;
55
+ if (prevState.pagination.pageIndex !== 0) {
56
+ return table.setPageIndex(paginationState.getValue().pageIndex);
57
+ }
58
+ if (prevState.pagination.pageSize !== ((_a = propsRef.current.pagination) === null || _a === void 0 ? void 0 : _a.pageSize)) {
59
+ return table.setPageSize(paginationState.getValue().pageSize);
60
+ }
61
+ if (prevState.columnFilters.length > 0) {
62
+ return table.setColumnFilters(filterState.getValue());
63
+ }
64
+ // 启用强制请求时,无论是否有变化都请求一次
65
+ if (opts === null || opts === void 0 ? void 0 : opts.forceRequest) {
66
+ innerRef.current.globalActionsRef.current.updateDataSource();
67
+ }
68
+ });
69
+ case 11:
70
+ case "end":
71
+ return _context.stop();
72
+ }
73
+ }
74
+ }, _callee);
75
+ }));
76
+ }, [innerRef]);
77
+ return resetDataSource;
78
+ }
79
+ export { useResetDataSource };
@@ -0,0 +1,22 @@
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 { getBoolConfig } from '@hi-ui/schema-utils';
11
+ function getGroupingConfig(field) {
12
+ var _a;
13
+ var groupingConfig = (_a = field.control) === null || _a === void 0 ? void 0 : _a.grouping;
14
+ if (!groupingConfig) return undefined;
15
+ var config = getBoolConfig(groupingConfig, {
16
+ aggregationFn: 'count'
17
+ }, {
18
+ mergeDft: true
19
+ });
20
+ return config;
21
+ }
22
+ export { getGroupingConfig };