@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,36 @@
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 { getGroupedRowModel } from '@tanstack/react-table';
11
+ function useRowGroupedOpts(ctx) {
12
+ return getRowGroupedOptions(ctx);
13
+ }
14
+ /**
15
+ * 获取列分组配置选项
16
+ */
17
+ function getRowGroupedOptions(ctx) {
18
+ var enableRowGrouping = ctx.staticOptsRef.current.enableRowGrouping;
19
+ if (!enableRowGrouping) {
20
+ return {
21
+ enableGrouping: false,
22
+ onGroupingChange: function onGroupingChange() {
23
+ // empty onGroupingChange
24
+ // 起到即使主动设置 grouping 状态,也会被直接忽略的作用
25
+ }
26
+ };
27
+ }
28
+ return {
29
+ enableGrouping: true,
30
+ groupedColumnMode: false,
31
+ getGroupedRowModel: getGroupedRowModel(),
32
+ autoResetExpanded: false // 数据变化时保持分组的展开状态
33
+ };
34
+ }
35
+
36
+ export { getRowGroupedOptions, useRowGroupedOpts };
@@ -0,0 +1,51 @@
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 { useMemo } from 'react';
11
+
12
+ /**
13
+ * 根据字段配置生成表格列的初始状态
14
+ */
15
+ function getInitialColumnState(fields) {
16
+ var columnVisibility = {};
17
+ var leftPinned = [];
18
+ var rightPinned = [];
19
+ var normalColumns = [];
20
+ fields.forEach(function (field) {
21
+ var _a, _b, _c;
22
+ // 处理显隐状态
23
+ if ((_a = field.control) === null || _a === void 0 ? void 0 : _a.hidden) {
24
+ columnVisibility[field.dataIndex] = false;
25
+ }
26
+ // 处理固定状态和列顺序
27
+ if (((_b = field.control) === null || _b === void 0 ? void 0 : _b.fixed) === 'left') {
28
+ leftPinned.push(field.dataIndex);
29
+ } else if (((_c = field.control) === null || _c === void 0 ? void 0 : _c.fixed) === 'right') {
30
+ rightPinned.push(field.dataIndex);
31
+ } else {
32
+ normalColumns.push(field.dataIndex);
33
+ }
34
+ });
35
+ return {
36
+ columnVisibility: columnVisibility,
37
+ columnPinning: {
38
+ left: leftPinned.length ? leftPinned : undefined,
39
+ right: rightPinned.length ? rightPinned : undefined
40
+ },
41
+ columnOrder: [].concat(leftPinned, normalColumns, rightPinned)
42
+ };
43
+ }
44
+ function useInitialColumnState(ctx) {
45
+ var fields = ctx.fields;
46
+ return useMemo(function () {
47
+ var initialState = getInitialColumnState(fields);
48
+ return initialState;
49
+ }, [fields]);
50
+ }
51
+ export { getInitialColumnState, useInitialColumnState };
@@ -0,0 +1,102 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React, { useEffect } from 'react';
11
+ import { TableFilter } from '@hi-ui/schema-table-extensions';
12
+ import { mergeProps, rawToItems } from '@hi-ui/schema-utils';
13
+ import { useEditableSchemaTableCtx } from '../../ctx.js';
14
+
15
+ // HeaderCell 中不便集成大量的过滤器逻辑,集中在此处处理桥接逻辑
16
+ function TableFilterBridge(props) {
17
+ var _a;
18
+ var column = props.column,
19
+ filterConfig = props.filter;
20
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
21
+ table = _useEditableSchemaTab.table;
22
+ var _React$useState = React.useState([]),
23
+ filters = _React$useState[0],
24
+ setFilters = _React$useState[1];
25
+ // 外部主动设置时自动更新至内部
26
+ var filterValue = column.getFilterValue();
27
+ useEffect(function () {
28
+ if (filterValue) {
29
+ var nextValue = Array.isArray(filterValue) ? filterValue : [filterValue];
30
+ setFilters(nextValue);
31
+ } else setFilters([]);
32
+ }, [filterValue]);
33
+ var handleChange = function handleChange(filters) {
34
+ if (filters === void 0) {
35
+ filters = [];
36
+ }
37
+ setFilters(filters !== null && filters !== void 0 ? filters : []);
38
+ column.setFilterValue(filters);
39
+ };
40
+ var filterType = (filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.type) || 'text';
41
+ // 仅在 type 为 select 时,此处才有效
42
+ var options = getSelectOptions({
43
+ type: filterType,
44
+ table: table,
45
+ column: column,
46
+ filterConfig: filterConfig
47
+ });
48
+ var popoverProps = mergeProps((_a = props.field.extra) === null || _a === void 0 ? void 0 : _a.popperProps, filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.popoverProps);
49
+ return /*#__PURE__*/React.createElement(TableFilter
50
+ // 这里实际上是一段魔法代码
51
+ // TableFilter 支持按类型传入不同的 props
52
+ // 但此处若根据类型做精确传入判断,会使代码变得很多
53
+ // 读到这里时,请不要觉得困惑 😊
54
+ , Object.assign({}, filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.extraProps, {
55
+ type: filterType,
56
+ options: options,
57
+ value: filters,
58
+ onChange: handleChange,
59
+ overlay: filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.custom,
60
+ popoverProps: popoverProps
61
+ }));
62
+ }
63
+ function getSelectOptions(ctx) {
64
+ var type = ctx.type,
65
+ table = ctx.table,
66
+ column = ctx.column,
67
+ filterConfig = ctx.filterConfig;
68
+ if (type !== 'select') return [];
69
+ // 如果用户没有传入自定义的异步选项函数
70
+ // 则使用表格上下文自动生成选项信息
71
+ var syncOptsRef = {
72
+ current: null
73
+ };
74
+ // 如果用户传入了自定义的异步选项函数
75
+ // 则在此处包装表格上下文的选项信息
76
+ if (filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.options) {
77
+ var getOpts = filterConfig.options;
78
+ return function getAsyncOptsFromTableFilterBridge(keyword) {
79
+ var filterValue = column.getFilterValue();
80
+ var allFilters = table.getState().columnFilters;
81
+ var asyncOpts = getOpts({
82
+ keyword: keyword,
83
+ filterValue: filterValue,
84
+ allFilters: allFilters,
85
+ autoGenerateOpts: autoGenerateOpts
86
+ });
87
+ if (Array.isArray(asyncOpts)) return Promise.resolve(asyncOpts);else return asyncOpts;
88
+ };
89
+ }
90
+ function autoGenerateOpts() {
91
+ // 有旧值时,直接返回旧值
92
+ // 也就是说,下次挂载时,会重新执行 (因为选型隐藏时,会将筛选器卸载)
93
+ if (syncOptsRef.current) return syncOptsRef.current;
94
+ var map = column.getFacetedUniqueValues();
95
+ var opts = rawToItems(Array.from(map.keys()));
96
+ syncOptsRef.current = opts;
97
+ return opts;
98
+ }
99
+ autoGenerateOpts.syncOpts = true;
100
+ return autoGenerateOpts;
101
+ }
102
+ export { TableFilterBridge };
@@ -0,0 +1,28 @@
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
+ /**
11
+ * 自定义日期范围筛选函数
12
+ * 用于筛选日期范围内的数据
13
+ */
14
+ var inDateRange = function inDateRange(row, columnId, filterValue) {
15
+ // 如果没有筛选值或筛选值不完整,则不进行筛选
16
+ if (!filterValue || !Array.isArray(filterValue) || filterValue.length !== 2) return true;
17
+ var start = filterValue[0],
18
+ end = filterValue[1];
19
+ if (!start || !end) return true;
20
+ var value = row.getValue(columnId);
21
+ if (!value) return false;
22
+ // 将日期字符串转换为时间戳进行比较
23
+ var valueDate = new Date(value).getTime();
24
+ var startDate = new Date(start).getTime();
25
+ var endDate = new Date(end).getTime();
26
+ return valueDate >= startDate && valueDate <= endDate;
27
+ };
28
+ export { inDateRange };
@@ -0,0 +1,18 @@
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 { inDateRange } from './date.js';
11
+
12
+ /**
13
+ * 导出所有自定义筛选函数
14
+ */
15
+ var filterFns = {
16
+ inDateRange: inDateRange
17
+ };
18
+ export { filterFns };
@@ -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 { mergeValues } from '@hi-ui/schema-utils';
11
+ var typeMap = {
12
+ text: 'text',
13
+ select: 'select',
14
+ 'check-select': 'select',
15
+ tag: 'select',
16
+ number: 'number',
17
+ date: 'date'
18
+ };
19
+ var fnMap = {
20
+ text: 'includesString',
21
+ select: 'arrIncludesSome',
22
+ number: 'inNumberRange',
23
+ date: 'inDateRange',
24
+ custom: 'includesString'
25
+ };
26
+ function getFilterConfig(field) {
27
+ var _a;
28
+ var filterConfig = (_a = field.control) === null || _a === void 0 ? void 0 : _a.filter;
29
+ if (!filterConfig) return undefined;
30
+ var valueType = field.valueType;
31
+ var matchedType = typeMap[valueType] || 'text';
32
+ // 布尔值只返回默认配置
33
+ if (typeof filterConfig === 'boolean') {
34
+ return {
35
+ type: matchedType,
36
+ filterFn: fnMap[matchedType]
37
+ };
38
+ }
39
+ // 对象类型,返回合并后的用户配置
40
+ else {
41
+ var type = filterConfig.type || matchedType;
42
+ // 如果用户传入了自定义的过滤器,则使用 custom 类型
43
+ if (filterConfig.custom) type = 'custom';
44
+ // 总而言之,言而总之
45
+ // type 经过上述处理后,已经可以完全确认取值,因此保留最高优先级
46
+ // 也就是说,type 的优先级为:(存在自定义筛选器,取custom) > (存在type,取type) > 字段类型匹配 > 默认取text
47
+ // filterFn 仅经过默认匹配,因此允许被 filterConfig 中的覆盖
48
+ var dft = {
49
+ filterFn: fnMap[type]
50
+ };
51
+ return mergeValues(dft, filterConfig, {
52
+ type: type
53
+ });
54
+ }
55
+ }
56
+ export { getFilterConfig };
@@ -0,0 +1,24 @@
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 { useSubscription } from '@hi-ui/use-subscription';
11
+ import 'lodash-es';
12
+ import '@tanstack/react-table';
13
+ import '@hi-ui/schema-utils';
14
+ import '../../utils/cls.js';
15
+ import 'react';
16
+ import 'ahooks';
17
+ import '@hi-ui/schema-table-extensions';
18
+ function useFilterState() {
19
+ var filterState = useSubscription([]);
20
+ return {
21
+ filterState: filterState
22
+ };
23
+ }
24
+ export { useFilterState };
@@ -0,0 +1,82 @@
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 { isEqual } from 'lodash-es';
11
+ import { getFacetedUniqueValues, getFilteredRowModel } from '@tanstack/react-table';
12
+ import { Schedular } from '@hi-ui/schema-utils';
13
+ import '../../utils/cls.js';
14
+ import 'react';
15
+ import 'ahooks';
16
+ import { ensureStateFields } from '../../utils/state-merge.js';
17
+ import { filterFns } from './filter-fns/index.js';
18
+ function useFilterOpts(ctx) {
19
+ var innerRef = ctx.innerRef,
20
+ staticOptsRef = ctx.staticOptsRef;
21
+ return getFilterOptions({
22
+ innerRef: innerRef,
23
+ staticOptsRef: staticOptsRef
24
+ });
25
+ }
26
+ /**
27
+ * 获取表格筛选配置选项
28
+ */
29
+ function getFilterOptions(ctx) {
30
+ var _ctx$staticOptsRef$cu = ctx.staticOptsRef.current,
31
+ enableFilter = _ctx$staticOptsRef$cu.enableFilter,
32
+ enableRemoteFilter = _ctx$staticOptsRef$cu.enableRemoteFilter;
33
+ if (!enableFilter) return {};
34
+ var onColumnFiltersChange = function onColumnFiltersChange(updater) {
35
+ var _a, _b;
36
+ var innerRef = ctx.innerRef;
37
+ var _innerRef$current = innerRef.current,
38
+ table = _innerRef$current.table,
39
+ propsRef = _innerRef$current.propsRef;
40
+ var state = table.getState().columnFilters;
41
+ var newState = typeof updater === 'function' ? updater(state) : updater;
42
+ // 如果筛选状态没有变化,则不更新
43
+ if (isEqual(state, newState)) return;
44
+ // 先更新内部状态
45
+ table.setState(function (state) {
46
+ return Object.assign(Object.assign({}, state), {
47
+ columnFilters: newState
48
+ });
49
+ });
50
+ // 再更新订阅
51
+ innerRef.current.filterState.setValue(newState);
52
+ // 通知外部更新
53
+ var notifyState = ensureStateFields(state, newState, 'value', []);
54
+ (_b = (_a = propsRef.current.filter) === null || _a === void 0 ? void 0 : _a.onChange) === null || _b === void 0 ? void 0 : _b.call(_a, notifyState, {
55
+ rawState: newState
56
+ });
57
+ // 在筛选状态更新后,更新分页状态
58
+ Schedular.nextMicro(function () {
59
+ table.setPageIndex(0); // 恢复到第一页 // 同时触发重渲染
60
+ });
61
+ };
62
+
63
+ if (enableRemoteFilter) {
64
+ return {
65
+ manualFiltering: true,
66
+ getFacetedUniqueValues: getFacetedUniqueValues(),
67
+ onColumnFiltersChange: onColumnFiltersChange,
68
+ filterFns: filterFns // 添加自定义筛选函数
69
+ };
70
+ }
71
+
72
+ return {
73
+ manualFiltering: false,
74
+ // 前端筛选,使用 getFilteredRowModel
75
+ getFilteredRowModel: getFilteredRowModel(),
76
+ getFacetedUniqueValues: getFacetedUniqueValues(),
77
+ onColumnFiltersChange: onColumnFiltersChange,
78
+ filterFns: filterFns // 添加自定义筛选函数
79
+ };
80
+ }
81
+
82
+ export { getFilterOptions, useFilterOpts };
@@ -0,0 +1,62 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import { PlusSquareOutlined, MinusSquareOutlined } from '@hi-ui/icons';
12
+
13
+ // NOTE 列折叠先支持到这种程度吧,集成度还能更高一点,但是时间比较紧张,有后续诉求的话再考虑优化
14
+ // 比如默认有子列的都折叠起来,目前是全部都展开
15
+ function ColumnCollapsingAction(props) {
16
+ var table = props.table,
17
+ field = props.field;
18
+ var _table$getState = table.getState(),
19
+ columnCollapsing = _table$getState.customColumnCollapsing;
20
+ var _React$useState = React.useState(function () {
21
+ var _a;
22
+ return (_a = columnCollapsing === null || columnCollapsing === void 0 ? void 0 : columnCollapsing[field.dataIndex]) !== null && _a !== void 0 ? _a : false;
23
+ }),
24
+ hasCollapsed = _React$useState[0],
25
+ setHasCollapsed = _React$useState[1];
26
+ if (!field.children || field.children.length <= 1) return null;
27
+ var handleClick = function handleClick() {
28
+ if (!field.children) return;
29
+ if (field.children.length <= 1) return;
30
+ // 先设置内部状态
31
+ setHasCollapsed(!hasCollapsed);
32
+ // 再更新自定义状态
33
+ table.setState(function (state) {
34
+ var _Object$assign;
35
+ return Object.assign(Object.assign({}, state), {
36
+ customColumnCollapsing: Object.assign(Object.assign({}, state.customColumnCollapsing), (_Object$assign = {}, _Object$assign[field.dataIndex] = !hasCollapsed, _Object$assign))
37
+ });
38
+ });
39
+ // 最后修改列展示状态 // Record<string, boolean>
40
+ var visibilityState = field.children
41
+ // 排除最后一个子列 // 否则全都隐藏的话,父列也就不展示了
42
+ .slice(0, -1)
43
+ // 折叠时,子列不展示
44
+ .map(function (childColumn) {
45
+ var _ref;
46
+ return _ref = {}, _ref[childColumn.dataIndex] = hasCollapsed, _ref;
47
+ }).reduce(function (acc, curr) {
48
+ return Object.assign(Object.assign({}, acc), curr);
49
+ }, {});
50
+ table.setColumnVisibility(function (state) {
51
+ return Object.assign(Object.assign({}, state), visibilityState);
52
+ });
53
+ };
54
+ return /*#__PURE__*/React.createElement("span", null, hasCollapsed ? ( /*#__PURE__*/React.createElement(PlusSquareOutlined, {
55
+ size: 14,
56
+ onClick: handleClick
57
+ })) : ( /*#__PURE__*/React.createElement(MinusSquareOutlined, {
58
+ size: 14,
59
+ onClick: handleClick
60
+ })));
61
+ }
62
+ export { ColumnCollapsingAction };
@@ -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
+ import React from 'react';
11
+ import '@hi-ui/use-subscription';
12
+ import 'lodash-es';
13
+ import '@tanstack/react-table';
14
+ import '@hi-ui/schema-utils';
15
+ import '../../utils/cls.js';
16
+ import 'ahooks';
17
+ import { TableFilterBridge } from '../filter/bridge.js';
18
+ import { TableSorterBridge } from '../sorter/bridge.js';
19
+ function getHeaderActions(props) {
20
+ var _a, _b, _c, _d, _e;
21
+ var column = props.column,
22
+ field = props.field,
23
+ globalStaticRef = props.globalStaticRef;
24
+ var filterConfig = (_a = props.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.filter;
25
+ var sorterConfig = (_b = props.column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.sorter;
26
+ // filterConfig 已经在 columnDef 中转换为对象,此处仅作类型收窄
27
+ // 简而言之 filterConfig 实际为 FieldFilterConfigType | true | undefined
28
+ if (typeof filterConfig === 'boolean') return null;
29
+ // 简而言之 sorterConfig 实际为 FieldSorterConfigType | true | undefined
30
+ if (typeof sorterConfig === 'boolean') return null;
31
+ // 筛选器
32
+ var enableFilter = globalStaticRef.current.enableFilter; // 指全局开启了过滤器
33
+ var filterAvailable = enableFilter && !!filterConfig; // 指当前字段的过滤器可用
34
+ var filterEl = filterAvailable ? ( /*#__PURE__*/React.createElement(TableFilterBridge, {
35
+ key: "filter",
36
+ field: field,
37
+ column: column,
38
+ filter: filterConfig
39
+ })) : null;
40
+ // 排序器
41
+ var enableSorter = globalStaticRef.current.enableSorter && !!((_c = field.control) === null || _c === void 0 ? void 0 : _c.sorter);
42
+ var sorterAvailable = enableSorter && !!sorterConfig;
43
+ var sorterEl = sorterAvailable ? ( /*#__PURE__*/React.createElement(TableSorterBridge, {
44
+ key: "sorter",
45
+ field: field,
46
+ column: column,
47
+ sorter: sorterConfig
48
+ })) : null;
49
+ // 自定义的 actions
50
+ var actions = ((_e = (_d = field.extra) === null || _d === void 0 ? void 0 : _d.headerActions) === null || _e === void 0 ? void 0 : _e.call(_d, {
51
+ field: field,
52
+ builtin: {
53
+ sorter: sorterEl,
54
+ filter: filterEl
55
+ },
56
+ table: props.table,
57
+ column: props.column
58
+ })) || [sorterEl, filterEl];
59
+ return {
60
+ filterAvailable: filterAvailable,
61
+ sorterAvailable: sorterAvailable,
62
+ elements: actions.filter(Boolean)
63
+ };
64
+ }
65
+ export { getHeaderActions };
@@ -0,0 +1,77 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import { Pagination as Pagination$1 } from '@hi-ui/pagination';
12
+ import { mergeProps, Schedular } from '@hi-ui/schema-utils';
13
+ import { useEditableSchemaTableCtx } from '../../ctx.js';
14
+ function Pagination(props) {
15
+ var _a, _b, _c;
16
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
17
+ table = _useEditableSchemaTab.table,
18
+ paginationState = _useEditableSchemaTab.paginationState;
19
+ // 分页状态变化时,会由外部触发重渲染
20
+ // 此处不必单独监听 paginationState 状态变化
21
+ var total = paginationState.getValue().rowCount || 0;
22
+ var current = table.getState().pagination.pageIndex + 1;
23
+ var pageSize = table.getState().pagination.pageSize;
24
+ var setPageIndex = function setPageIndex(current) {
25
+ return table.setPageIndex(current - 1);
26
+ };
27
+ var handleJump = function handleJump(current) {
28
+ var _a;
29
+ setPageIndex(current);
30
+ (_a = props.onJump) === null || _a === void 0 ? void 0 : _a.call(props, current);
31
+ };
32
+ var handleChange = function handleChange(current, prev, size) {
33
+ // TODO HiUI Pagination 在 onPageSizeChange 的某些特殊情况,会额外触发一次 onChange
34
+ // 例如,分页由一个较小的值 20 变为较大的值 500 时
35
+ // 此处延迟一个队列执行,避免状态更新异常
36
+ Schedular.nextMicro(function () {
37
+ var _a;
38
+ setPageIndex(current);
39
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, current, prev, size);
40
+ });
41
+ };
42
+ var handlePageSizeChange = function handlePageSizeChange(pageSize, current) {
43
+ var _a;
44
+ // 开启自动重置 pageSize 变化时,自动重置页码至首页,否则从当前页码减1
45
+ var pageIndex = props.autoResetCurrent ? 0 : current - 1;
46
+ table.setPagination(function (state) {
47
+ return Object.assign(Object.assign({}, state), {
48
+ pageIndex: pageIndex,
49
+ pageSize: pageSize
50
+ });
51
+ });
52
+ (_a = props.onPageSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, pageSize, current);
53
+ };
54
+ var finalProps = mergeProps({
55
+ // showJumper: true,
56
+ // showPagers: true,
57
+ // showTotal: true,
58
+ pageSizeOptions: [10, 20, 50, 100]
59
+ }, props, {
60
+ current: current,
61
+ pageSize: pageSize,
62
+ total: total,
63
+ onJump: handleJump,
64
+ onChange: handleChange,
65
+ onPageSizeChange: handlePageSizeChange
66
+ });
67
+ // 仅展示总条数大于等于 pageSize 的选项
68
+ finalProps.pageSizeOptions = (_a = finalProps.pageSizeOptions) === null || _a === void 0 ? void 0 : _a.filter(function (size) {
69
+ return size <= total;
70
+ });
71
+ // 如果选项数量小于等于1,则不展示选项
72
+ if (((_c = (_b = finalProps.pageSizeOptions) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) <= 1) finalProps.pageSizeOptions = undefined;
73
+ // 如果页数小于等于1,则不展示跳转器
74
+ if (total / Math.max(pageSize, 1) <= 1) finalProps.showJumper = false;
75
+ return /*#__PURE__*/React.createElement(Pagination$1, Object.assign({}, finalProps));
76
+ }
77
+ export { Pagination };