@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,86 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+ var ctx = require('../../../ctx.js');
17
+ var cls = require('../../../utils/cls.js');
18
+ require('lodash-es');
19
+ require('@tanstack/react-table');
20
+ require('ahooks');
21
+
22
+ /**
23
+ * 同步表格行的 hover 状态
24
+ * @desc 当表格分为选择列和主内容两部分时,确保 hover 效果能同步显示在两边
25
+ */
26
+ function useSyncHoverStyle() {
27
+ var _useEditableSchemaTab = ctx.useEditableSchemaTableCtx(),
28
+ tableContainerRef = _useEditableSchemaTab.tableContainerRef,
29
+ propsRef = _useEditableSchemaTab.propsRef;
30
+ var findClassName = "." + cls.cls('body-row');
31
+ // 用ref存储上一次 hover 的行元素,避免不必要的DOM查询
32
+ var lastHoveredRowsRef = React.useRef(null);
33
+ React.useEffect(function () {
34
+ var _a;
35
+ if (!tableContainerRef.current) return;
36
+ // 只在开启行选择时启用 hover 同步
37
+ if (!((_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.rowSelection)) return;
38
+ // // 如果开启了列分组,则不启用 hover 同步
39
+ // TODO 此处需进一步细化处理场景
40
+ // if (propsRef.current.grouping) return
41
+ var container = tableContainerRef.current;
42
+ var clearHover = function clearHover() {
43
+ if (lastHoveredRowsRef.current) {
44
+ lastHoveredRowsRef.current.forEach(function (el) {
45
+ return el.removeAttribute('data-hovering');
46
+ });
47
+ lastHoveredRowsRef.current = null;
48
+ }
49
+ };
50
+ var handleMouseMove = function handleMouseMove(e) {
51
+ var _a, _b;
52
+ // 查找当前 hover 的行元素
53
+ var row = e.target.closest(findClassName);
54
+ // 如果没有找到行元素,清除上一次的 hover 状态
55
+ if (!row) return clearHover();
56
+ var rowId = row.getAttribute('data-id');
57
+ if (!rowId) return;
58
+ // 如果 hover 的是同一行,不做任何操作
59
+ if (((_b = (_a = lastHoveredRowsRef.current) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.getAttribute('data-id')) === rowId) {
60
+ return;
61
+ }
62
+ // 清除上一次 hover 的行
63
+ clearHover();
64
+ // 找到所有相同 id 的行并添加 hover 状态
65
+ var currentRows = Array.from(container.querySelectorAll("tr[data-id=\"" + rowId + "\"]"));
66
+ currentRows.forEach(function (el) {
67
+ return el.setAttribute('data-hovering', '');
68
+ });
69
+ lastHoveredRowsRef.current = currentRows;
70
+ };
71
+ // 鼠标离开表格时清除所有 hover 状态
72
+ var handleMouseLeave = function handleMouseLeave() {
73
+ return clearHover();
74
+ };
75
+ container.addEventListener('mousemove', handleMouseMove);
76
+ container.addEventListener('mouseleave', handleMouseLeave);
77
+ return function () {
78
+ // 清理事件监听
79
+ container.removeEventListener('mousemove', handleMouseMove);
80
+ container.removeEventListener('mouseleave', handleMouseLeave);
81
+ // 组件卸载时清除所有hover状态
82
+ clearHover();
83
+ };
84
+ }, [tableContainerRef, propsRef, findClassName]);
85
+ }
86
+ exports.useSyncHoverStyle = useSyncHoverStyle;
@@ -0,0 +1,173 @@
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 Space = require('@hi-ui/space');
18
+ var Switch = require('@hi-ui/switch');
19
+ var reactTable = require('@tanstack/react-table');
20
+ var ctx = require('../../ctx.js');
21
+ var cls = require('../../utils/cls.js');
22
+ require('lodash-es');
23
+ require('ahooks');
24
+ function _interopDefaultCompat(e) {
25
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
26
+ 'default': e
27
+ };
28
+ }
29
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
30
+ var Space__default = /*#__PURE__*/_interopDefaultCompat(Space);
31
+ var Switch__default = /*#__PURE__*/_interopDefaultCompat(Switch);
32
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
33
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
34
+ if (it) return (it = it.call(o)).next.bind(it);
35
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
36
+ if (it) o = it;
37
+ var i = 0;
38
+ return function () {
39
+ if (i >= o.length) return {
40
+ done: true
41
+ };
42
+ return {
43
+ done: false,
44
+ value: o[i++]
45
+ };
46
+ };
47
+ }
48
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
49
+ }
50
+ function _unsupportedIterableToArray(o, minLen) {
51
+ if (!o) return;
52
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
53
+ var n = Object.prototype.toString.call(o).slice(8, -1);
54
+ if (n === "Object" && o.constructor) n = o.constructor.name;
55
+ if (n === "Map" || n === "Set") return Array.from(o);
56
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
57
+ }
58
+ function _arrayLikeToArray(arr, len) {
59
+ if (len == null || len > arr.length) len = arr.length;
60
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
61
+ arr2[i] = arr[i];
62
+ }
63
+ return arr2;
64
+ }
65
+ var dftFormatter = function dftFormatter(selectedCount) {
66
+ return "\u5DF2\u9009 " + selectedCount + " \u9879";
67
+ };
68
+ function RowSelectionIndicator() {
69
+ var _useEditableSchemaTab = ctx.useEditableSchemaTableCtx(),
70
+ table = _useEditableSchemaTab.table,
71
+ propsRef = _useEditableSchemaTab.propsRef;
72
+ // 经过性能优化,已移除额外订阅
73
+ // 此时保留,反而会导致本组件重复重渲染
74
+ // 保留此处注释,用以后续调整
75
+ // const { rowSelectionState } = useEditableSchemaTableCtx()
76
+ // useSubscribe(rowSelectionState)
77
+ var selectedCount = table.$getRowSelection().selectedRowKeys.length;
78
+ var _ref = propsRef.current.rowSelection || {},
79
+ _ref$enableIndicator = _ref.enableIndicator,
80
+ enableIndicator = _ref$enableIndicator === void 0 ? {} : _ref$enableIndicator;
81
+ var _enableIndicator$form = enableIndicator.formatter,
82
+ formatter = _enableIndicator$form === void 0 ? dftFormatter : _enableIndicator$form,
83
+ enableOnlyShowSelected = enableIndicator.enableOnlyShowSelected;
84
+ return /*#__PURE__*/React__default["default"].createElement("div", {
85
+ className: cls.cls('row-selection-indicator')
86
+ }, /*#__PURE__*/React__default["default"].createElement(Space__default["default"], {
87
+ wrap: false,
88
+ style: {
89
+ whiteSpace: 'nowrap'
90
+ },
91
+ separator: enableOnlyShowSelected ? /*#__PURE__*/React__default["default"].createElement("span", {
92
+ style: {
93
+ color: 'rgba(0, 0, 0, 0.06)'
94
+ }
95
+ }, "|") : null
96
+ }, /*#__PURE__*/React__default["default"].createElement("span", null, formatter(selectedCount)), enableOnlyShowSelected ? /*#__PURE__*/React__default["default"].createElement(OnlyShowSelected, {
97
+ selectedCount: selectedCount
98
+ }) : null));
99
+ }
100
+ function OnlyShowSelected(_ref2) {
101
+ var selectedCount = _ref2.selectedCount;
102
+ var _useEditableSchemaTab2 = ctx.useEditableSchemaTableCtx(),
103
+ table = _useEditableSchemaTab2.table,
104
+ subscription = _useEditableSchemaTab2.subscription,
105
+ setDynamicOpts = _useEditableSchemaTab2.setDynamicOpts;
106
+ var checkedRef = React.useRef(false);
107
+ // 如果未选中行,且未开启开关,则禁用
108
+ var disabled = selectedCount === 0 && !checkedRef.current;
109
+ var prePaginationState = React.useRef();
110
+ return /*#__PURE__*/React__default["default"].createElement("span", null, /*#__PURE__*/React__default["default"].createElement(Switch__default["default"], {
111
+ disabled: disabled,
112
+ content: ['开', '关'],
113
+ onChange: function onChange(checked) {
114
+ checkedRef.current = checked;
115
+ if (checked) {
116
+ var keys = table.$getRowSelection().selectedRowKeys;
117
+ var rowDataList = [];
118
+ for (var _iterator = _createForOfIteratorHelperLoose(keys), _step; !(_step = _iterator()).done;) {
119
+ var rowId = _step.value;
120
+ var data = table.$getRealtimeRowData(rowId) || table.$selectedRowsCache.get(rowId);
121
+ if (data) rowDataList.push(data);
122
+ }
123
+ // 先静默更新内部订阅
124
+ subscription.setValue(rowDataList, {
125
+ silent: true
126
+ });
127
+ // 再更新分页状态
128
+ table.setPagination(function (state) {
129
+ // 暂存分页状态
130
+ prePaginationState.current = state;
131
+ var rowCount = rowDataList.length;
132
+ return Object.assign(Object.assign({}, state), {
133
+ pageIndex: 0,
134
+ rowCount: rowCount,
135
+ $fromCustom: true
136
+ });
137
+ });
138
+ // 最后换成前端分页
139
+ setDynamicOpts({
140
+ manualPagination: false,
141
+ getPaginationRowModel: reactTable.getPaginationRowModel()
142
+ });
143
+ } else {
144
+ // 先恢复内部订阅
145
+ subscription.setValue(subscription.getPrevValue(), {
146
+ silent: true
147
+ });
148
+ // 再恢复分页状态
149
+ table.setPagination(function (state) {
150
+ var preState = prePaginationState.current;
151
+ // 清空暂存的分页状态
152
+ prePaginationState.current = undefined;
153
+ return Object.assign(Object.assign({}, preState), {
154
+ $fromCustom: false
155
+ });
156
+ });
157
+ // 最后恢复成后端分页
158
+ setDynamicOpts({
159
+ manualPagination: true,
160
+ getPaginationRowModel: undefined
161
+ });
162
+ }
163
+ }
164
+ }), /*#__PURE__*/React__default["default"].createElement("span", {
165
+ style: {
166
+ position: 'relative',
167
+ top: 1,
168
+ marginLeft: 8,
169
+ userSelect: 'none'
170
+ }
171
+ }, "\u4EC5\u663E\u793A\u5DF2\u9009"));
172
+ }
173
+ exports.RowSelectionIndicator = RowSelectionIndicator;
@@ -0,0 +1,119 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ var _typeof = require("@babel/runtime/helpers/typeof");
13
+ Object.defineProperty(exports, '__esModule', {
14
+ value: true
15
+ });
16
+ var React = require('react');
17
+ var cls = require('../../utils/cls.js');
18
+ var ctx = require('../../ctx.js');
19
+ require('../../container/index.js');
20
+ var useSyncHoverStyle = require('./hooks/use-sync-hover-style.js');
21
+ var useClickSelect = require('./hooks/use-click-select.js');
22
+ var cell = require('./cell.js');
23
+ require('@hi-ui/use-subscription');
24
+ require('ahooks');
25
+ require('lodash-es');
26
+ require('@hi-ui/space');
27
+ require('@hi-ui/switch');
28
+ require('@tanstack/react-table');
29
+ var ctx$1 = require('../../container/ctx.js');
30
+ function _interopDefaultCompat(e) {
31
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
32
+ 'default': e
33
+ };
34
+ }
35
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
36
+ function SelectionTable(props) {
37
+ var width = 50;
38
+ return /*#__PURE__*/React__default["default"].createElement("table", {
39
+ className: cls.cls('mock-selection'),
40
+ "data-is-selection": true
41
+ }, /*#__PURE__*/React__default["default"].createElement("colgroup", null, /*#__PURE__*/React__default["default"].createElement("col", {
42
+ style: {
43
+ width: width,
44
+ minWidth: width
45
+ }
46
+ })), props.children);
47
+ }
48
+ function SelectionHeader() {
49
+ return /*#__PURE__*/React__default["default"].createElement(SelectionTable, null, /*#__PURE__*/React__default["default"].createElement("thead", {
50
+ className: cls.cls('header'),
51
+ style: {
52
+ height: '100%'
53
+ }
54
+ }, /*#__PURE__*/React__default["default"].createElement("tr", {
55
+ className: cls.cls('header-row')
56
+ }, /*#__PURE__*/React__default["default"].createElement("th", {
57
+ className: cls.cls('header-cell'),
58
+ "data-text-align": "center"
59
+ }, /*#__PURE__*/React__default["default"].createElement(cell.SelectionHeaderCell, null)))));
60
+ }
61
+ function SelectionBody() {
62
+ var _a, _b, _c, _d, _e, _f, _g, _h;
63
+ var _useEditableSchemaTab = ctx.useEditableSchemaTableCtx(),
64
+ table = _useEditableSchemaTab.table;
65
+ var _useTableContainer = ctx$1.useTableContainer(),
66
+ virtualize = _useTableContainer.virtualize;
67
+ var _table$getRowModel = table.getRowModel(),
68
+ realRows = _table$getRowModel.rows;
69
+ // 同步表格行的 hover 状态
70
+ useSyncHoverStyle.useSyncHoverStyle();
71
+ // 点击行选择 // 内部有开关决定是否启用
72
+ useClickSelect.useClickSelect();
73
+ return /*#__PURE__*/React__default["default"].createElement(SelectionTable, null, /*#__PURE__*/React__default["default"].createElement("tbody", {
74
+ className: cls.cls('body')
75
+ }, ((_b = (_a = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0) > 0 && ( /*#__PURE__*/React__default["default"].createElement("tr", {
76
+ className: cls.cls('body-row', 'virtual-spacer', 'virtual-spacer-top')
77
+ }, /*#__PURE__*/React__default["default"].createElement("td", {
78
+ style: {
79
+ height: (_d = (_c = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _c === void 0 ? void 0 : _c.top) !== null && _d !== void 0 ? _d : 0
80
+ }
81
+ }))), ((virtualize === null || virtualize === void 0 ? void 0 : virtualize.rows) || realRows).map(function (rowOrVirtual) {
82
+ var row = 'id' in rowOrVirtual ? rowOrVirtual : realRows[rowOrVirtual.index];
83
+ if (!row) return null;
84
+ return /*#__PURE__*/React__default["default"].createElement("tr", {
85
+ key: row.id,
86
+ className: cls.cls('body-row'),
87
+ "data-index": row.index,
88
+ "data-id": row.id
89
+ }, /*#__PURE__*/React__default["default"].createElement("td", {
90
+ className: cls.cls('body-cell'),
91
+ "data-text-align": "center"
92
+ }, /*#__PURE__*/React__default["default"].createElement(cell.SelectionBodyCell, {
93
+ row: row
94
+ })));
95
+ }), ((_f = (_e = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _e === void 0 ? void 0 : _e.bottom) !== null && _f !== void 0 ? _f : 0) > 0 && ( /*#__PURE__*/React__default["default"].createElement("tr", {
96
+ className: cls.cls('body-row', 'virtual-spacer', 'virtual-spacer-bottom')
97
+ }, /*#__PURE__*/React__default["default"].createElement("td", {
98
+ style: {
99
+ height: (_h = (_g = virtualize === null || virtualize === void 0 ? void 0 : virtualize.rowPadding) === null || _g === void 0 ? void 0 : _g.bottom) !== null && _h !== void 0 ? _h : 0
100
+ }
101
+ })))));
102
+ }
103
+ // 暂时用不上,预留位置待扩展
104
+ function SelectionFooter() {
105
+ return /*#__PURE__*/React__default["default"].createElement(SelectionTable, null, /*#__PURE__*/React__default["default"].createElement("tfoot", {
106
+ className: cls.cls('footer')
107
+ }, /*#__PURE__*/React__default["default"].createElement("tr", {
108
+ className: cls.cls('footer-row')
109
+ }, /*#__PURE__*/React__default["default"].createElement("td", {
110
+ className: cls.cls('footer-cell'),
111
+ "data-text-align": "center"
112
+ }))));
113
+ }
114
+ var RowSelection = {
115
+ Header: SelectionHeader,
116
+ Body: SelectionBody,
117
+ Footer: SelectionFooter
118
+ };
119
+ exports.RowSelection = RowSelection;
@@ -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
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var React = require('react');
16
+
17
+ /**
18
+ * 将字段配置转换为列设置需要的格式
19
+ */
20
+ function mapFieldsToColumns(fields) {
21
+ return fields.map(function (field) {
22
+ var _a, _b;
23
+ return {
24
+ id: field.dataIndex,
25
+ title: (typeof field.title === 'string' ? field.title : field._titleText) || field.dataIndex,
26
+ fixed: ((_a = field.control) === null || _a === void 0 ? void 0 : _a.fixed) || false,
27
+ hidden: (_b = field.control) === null || _b === void 0 ? void 0 : _b.hidden
28
+ };
29
+ });
30
+ }
31
+ function useTableSetting(props) {
32
+ var columns = React.useMemo(function () {
33
+ return mapFieldsToColumns(props.fields);
34
+ }, [props.fields]);
35
+ // 处理列设置变更
36
+ var handleSettingChange = function handleSettingChange(result) {
37
+ var _a, _b;
38
+ var table = (_a = props.tableRef.current) === null || _a === void 0 ? void 0 : _a.table;
39
+ if (!table) return;
40
+ (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, result);
41
+ table.setState(function (state) {
42
+ return Object.assign(Object.assign({}, state), {
43
+ columnOrder: result.keys,
44
+ columnPinning: result.grouped.fixed,
45
+ columnVisibility: result.grouped.visibility
46
+ });
47
+ });
48
+ };
49
+ return {
50
+ columns: columns,
51
+ storageKey: props.storageKey,
52
+ onChange: handleSettingChange
53
+ };
54
+ }
55
+ exports.mapFieldsToColumns = mapFieldsToColumns;
56
+ exports.useTableSetting = useTableSetting;
@@ -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
+ var _typeof = require("@babel/runtime/helpers/typeof");
13
+ Object.defineProperty(exports, '__esModule', {
14
+ value: true
15
+ });
16
+ var React = require('react');
17
+ var schemaTableExtensions = require('@hi-ui/schema-table-extensions');
18
+ var useSubscription = require('@hi-ui/use-subscription');
19
+ var schemaUtils = require('@hi-ui/schema-utils');
20
+ var ctx = require('../../ctx.js');
21
+ function _interopDefaultCompat(e) {
22
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
23
+ 'default': e
24
+ };
25
+ }
26
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
27
+ function TableSorterBridge(props) {
28
+ var _a;
29
+ var column = props.column,
30
+ sorterConfig = props.sorter;
31
+ var _useEditTableCtx = ctx.useEditableSchemaTableCtx(),
32
+ sorterState = _useEditTableCtx.sorterState,
33
+ propsRef = _useEditTableCtx.propsRef;
34
+ var _React$useState = React__default["default"].useState(null),
35
+ direction = _React$useState[0],
36
+ setDirection = _React$useState[1];
37
+ // 列的排序状态会受到全局排序状态的影响
38
+ // 全局变更时,主动触发一次自身的重渲染
39
+ useSubscription.useSubscribe(sorterState);
40
+ // 外部主动设置时自动更新至内部
41
+ var sorterValue = column.getIsSorted();
42
+ React.useEffect(function () {
43
+ setDirection(sorterValue || null);
44
+ }, [sorterValue]);
45
+ var handleChange = function handleChange(direction) {
46
+ setDirection(direction);
47
+ // 取消排序时,需要主动清除排序状态
48
+ if (direction === null) {
49
+ column.clearSorting();
50
+ return;
51
+ }
52
+ var isDesc = direction === 'desc';
53
+ // toggleSorting 需要手动传入是否降序,是否可多排序
54
+ column.toggleSorting(isDesc, column.getCanMultiSort());
55
+ };
56
+ var fieldTooltipConfig = schemaUtils.getBoolConfig(sorterConfig === null || sorterConfig === void 0 ? void 0 : sorterConfig.tooltip, {});
57
+ var propsTooltipConfig = (_a = propsRef.current.sorter) === null || _a === void 0 ? void 0 : _a.tooltip;
58
+ var tooltip = fieldTooltipConfig || propsTooltipConfig ? schemaUtils.mergeProps(propsTooltipConfig, fieldTooltipConfig) : undefined;
59
+ return /*#__PURE__*/React__default["default"].createElement(schemaTableExtensions.TableSorter, {
60
+ direction: direction,
61
+ onChange: handleChange,
62
+ tooltip: tooltip
63
+ });
64
+ }
65
+ exports.TableSorterBridge = TableSorterBridge;
@@ -0,0 +1,46 @@
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 schemaUtils = require('@hi-ui/schema-utils');
16
+ function getSorterConfig(field, ctx) {
17
+ var _a;
18
+ var sorterConfig = (_a = field.control) === null || _a === void 0 ? void 0 : _a.sorter;
19
+ if (!sorterConfig) return undefined;
20
+ var propsRef = ctx.propsRef;
21
+ var tableSorterConfig = propsRef.current.sorter;
22
+ var config = schemaUtils.getBoolConfig(sorterConfig, {
23
+ sortingFn: 'textLocalCompare'
24
+ }, {
25
+ mergeDft: true
26
+ });
27
+ if (config) {
28
+ // 如果配置为 textLocalCompare,则使用内置的 textLocalCompare 函数
29
+ if (config.sortingFn === 'textLocalCompare') config.sortingFn = textLocalCompare;
30
+ // 如果字段配置了 sortUndefined,则优先使用字段配置的 sortUndefined
31
+ // 否则使用表格配置的 sortUndefined
32
+ config.sortUndefined = config.sortUndefined || (tableSorterConfig === null || tableSorterConfig === void 0 ? void 0 : tableSorterConfig.sortUndefined);
33
+ }
34
+ return config;
35
+ }
36
+ function textLocalCompare(rowA, rowB, columnId) {
37
+ try {
38
+ var a = rowA.getValue(columnId);
39
+ var b = rowB.getValue(columnId);
40
+ return schemaUtils.localCompare(a, b);
41
+ } catch (error) {
42
+ console.log('textLocalCompare', error);
43
+ return 0;
44
+ }
45
+ }
46
+ exports.getSorterConfig = getSorterConfig;
@@ -0,0 +1,29 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var useSubscription = require('@hi-ui/use-subscription');
16
+ require('@tanstack/react-table');
17
+ require('../../utils/cls.js');
18
+ require('react');
19
+ require('lodash-es');
20
+ require('ahooks');
21
+ require('@hi-ui/schema-utils');
22
+ require('@hi-ui/schema-table-extensions');
23
+ function useSorterState() {
24
+ var sorterState = useSubscription.useSubscription([]);
25
+ return {
26
+ sorterState: sorterState
27
+ };
28
+ }
29
+ exports.useSorterState = useSorterState;
@@ -0,0 +1,81 @@
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 reactTable = require('@tanstack/react-table');
16
+ require('../../utils/cls.js');
17
+ require('react');
18
+ require('lodash-es');
19
+ require('ahooks');
20
+ var stateMerge = require('../../utils/state-merge.js');
21
+ function useSorterOpts(ctx) {
22
+ var innerRef = ctx.innerRef,
23
+ propsRef = ctx.propsRef,
24
+ staticOptsRef = ctx.staticOptsRef;
25
+ return getSorterOptions({
26
+ innerRef: innerRef,
27
+ propsRef: propsRef,
28
+ staticOptsRef: staticOptsRef
29
+ });
30
+ }
31
+ /**
32
+ * 获取表格排序配置选项
33
+ */
34
+ function getSorterOptions(ctx) {
35
+ var _ctx$staticOptsRef$cu = ctx.staticOptsRef.current,
36
+ enableSorter = _ctx$staticOptsRef$cu.enableSorter,
37
+ enableRemoteSorter = _ctx$staticOptsRef$cu.enableRemoteSorter;
38
+ if (!enableSorter) return {};
39
+ var sorterOpts = ctx.propsRef.current.sorter;
40
+ if (!sorterOpts) return {};
41
+ var onSortingChange = function onSortingChange(updater) {
42
+ var _a, _b;
43
+ var innerRef = ctx.innerRef;
44
+ var _innerRef$current = innerRef.current,
45
+ table = _innerRef$current.table,
46
+ propsRef = _innerRef$current.propsRef;
47
+ var state = table.getState().sorting;
48
+ var newState = typeof updater === 'function' ? updater(state) : updater;
49
+ // 先更新内部状态
50
+ table.setState(function (state) {
51
+ return Object.assign(Object.assign({}, state), {
52
+ sorting: newState
53
+ });
54
+ });
55
+ // 再更新订阅
56
+ innerRef.current.sorterState.setValue(newState);
57
+ // 通知外部更新
58
+ var notifyState = stateMerge.ensureStateFields(state, newState, 'desc', undefined);
59
+ (_b = (_a = propsRef.current.sorter) === null || _a === void 0 ? void 0 : _a.onChange) === null || _b === void 0 ? void 0 : _b.call(_a, notifyState, {
60
+ rawState: newState
61
+ });
62
+ };
63
+ if (enableRemoteSorter) {
64
+ return {
65
+ manualSorting: true,
66
+ enableMultiSort: sorterOpts.enableMultiSort,
67
+ maxMultiSortColCount: sorterOpts.maxMultiSortColCount,
68
+ onSortingChange: onSortingChange
69
+ };
70
+ }
71
+ return {
72
+ manualSorting: false,
73
+ enableMultiSort: sorterOpts.enableMultiSort,
74
+ maxMultiSortColCount: sorterOpts.maxMultiSortColCount,
75
+ // 前端排序,使用 getSortedRowModel
76
+ getSortedRowModel: reactTable.getSortedRowModel(),
77
+ onSortingChange: onSortingChange
78
+ };
79
+ }
80
+ exports.getSorterOptions = getSorterOptions;
81
+ exports.useSorterOpts = useSorterOpts;