@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,41 @@
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 { useSchemaFormCtx } from '@hi-ui/schema-form';
12
+ import { TableToolbar } from '@hi-ui/schema-action-trigger';
13
+ import { NOOP_SUBSCRIPTION } from '@hi-ui/use-subscription';
14
+ import { useSubscribeTickState } from '@hi-ui/schema-hooks';
15
+ import { getGetterValue } from '@hi-ui/schema-utils';
16
+ function Toolbar(props) {
17
+ var tableCtxRef = props.ctx.tableCtxRef;
18
+ // 此处用来触发工具栏按钮的更新
19
+ // 严格比较时,使用 tickState 订阅,否则使用 NOOP_SUBSCRIPTION
20
+ var _useSchemaFormCtx = useSchemaFormCtx(),
21
+ propsRef = _useSchemaFormCtx.propsRef,
22
+ tickState = _useSchemaFormCtx.tickState;
23
+ var subscription = propsRef.current.strictValueCompare ? tickState : NOOP_SUBSCRIPTION;
24
+ useSubscribeTickState(subscription);
25
+ var dftRight = props.ctx.readonly ? [] : [{
26
+ text: '增行',
27
+ onClick: function onClick() {
28
+ var _a;
29
+ (_a = tableCtxRef.current) === null || _a === void 0 ? void 0 : _a.rowActions.addRow({});
30
+ }
31
+ }];
32
+ var getRight = props.right;
33
+ var right = getGetterValue(getRight, dftRight, [props.ctx]);
34
+ return /*#__PURE__*/React.createElement(TableToolbar, {
35
+ ctx: props.ctx,
36
+ left: props.left,
37
+ right: right,
38
+ className: "pro-edit-table__toolbar"
39
+ });
40
+ }
41
+ export { Toolbar };
@@ -0,0 +1,87 @@
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 { flexRender } from '@tanstack/react-table';
12
+ import { useEditableSchemaTableCtx } from '../ctx.js';
13
+ import '../container/index.js';
14
+ import { getFixedStyles } from '../utils/fixed.js';
15
+ import { cls } from '../utils/cls.js';
16
+ import { groupHeaders } from '../header/index.js';
17
+ import { useFirstCellPatch } from './use-first-cell-patch.js';
18
+ import { useTableContainer } from '../container/ctx.js';
19
+ var FooterCellWrapper = /*#__PURE__*/React.memo(function FooterCell(props) {
20
+ var _a;
21
+ var footer = props.footer;
22
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
23
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef;
24
+ // 开启 fixed 时才去获取固定单元格的样式
25
+ var fixed = props.fixed ? getFixedStyles(footer.column, {
26
+ globalStaticRef: globalStaticRef
27
+ }) : {};
28
+ var fixedClassName = (fixed.className || []).map(function (c) {
29
+ return "cell--" + c;
30
+ });
31
+ return /*#__PURE__*/React.createElement("td", {
32
+ className: cls.apply(void 0, ['footer-cell'].concat(fixedClassName)),
33
+ style: fixed.style,
34
+ "data-text-align": (_a = footer.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.align
35
+ }, flexRender(footer.column.columnDef.footer, footer.getContext()));
36
+ });
37
+ // 仅渲染一行footer,用来生成摘要(合计)行等
38
+ var Footer = /*#__PURE__*/React.memo(function Footer(_ref) {
39
+ var className = _ref.className;
40
+ var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
41
+ table = _useEditableSchemaTab2.table;
42
+ var _useTableContainer = useTableContainer(),
43
+ virtualize = _useTableContainer.virtualize;
44
+ useFirstCellPatch();
45
+ return /*#__PURE__*/React.createElement("tfoot", {
46
+ className: cls('footer', className)
47
+ }, table.getFooterGroups().slice(0, 1) // 第一行就是叶节点
48
+ .map(function (footerGroup) {
49
+ var _a, _b, _c, _d;
50
+ var realFooters = footerGroup.headers;
51
+ var _groupHeaders = groupHeaders(realFooters, table),
52
+ leftFooters = _groupHeaders.left,
53
+ rightFooters = _groupHeaders.right,
54
+ centerFooters = _groupHeaders.center;
55
+ return /*#__PURE__*/React.createElement("tr", {
56
+ key: footerGroup.id,
57
+ className: cls('footer-row')
58
+ }, leftFooters.map(function (footer) {
59
+ return /*#__PURE__*/React.createElement(FooterCellWrapper, {
60
+ key: footer.id,
61
+ footer: footer,
62
+ fixed: true
63
+ });
64
+ }), ((_b = (_a = virtualize === null || virtualize === void 0 ? void 0 : virtualize.colPadding) === null || _a === void 0 ? void 0 : _a.left) !== null && _b !== void 0 ? _b : 0) > 0 ? /*#__PURE__*/React.createElement("td", null) : null, ((virtualize === null || virtualize === void 0 ? void 0 : virtualize.columns) || centerFooters).map(function (footerOrVirtual) {
65
+ var footer = 'index' in footerOrVirtual ? realFooters[footerOrVirtual.index] : footerOrVirtual;
66
+ if (!footer) return null;
67
+ // 固定列不参与虚拟化
68
+ if (footer.column.getIsPinned()) return null;
69
+ return /*#__PURE__*/React.createElement(FooterCellWrapper, {
70
+ key: footer.id,
71
+ footer: footer,
72
+ fixed: true
73
+ });
74
+ }), ((_d = (_c = virtualize === null || virtualize === void 0 ? void 0 : virtualize.colPadding) === null || _c === void 0 ? void 0 : _c.right) !== null && _d !== void 0 ? _d : 0) > 0 ? /*#__PURE__*/React.createElement("td", null) : null, rightFooters.map(function (footer) {
75
+ return /*#__PURE__*/React.createElement(FooterCellWrapper, {
76
+ key: footer.id,
77
+ footer: footer,
78
+ fixed: true
79
+ });
80
+ }));
81
+ }));
82
+ }, function () {
83
+ return true;
84
+ } // 始终不由外部触发重渲染
85
+ );
86
+
87
+ export { Footer as default };
@@ -0,0 +1,37 @@
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 { useEffect } from 'react';
11
+ import { useEditableSchemaTableCtx } from '../ctx.js';
12
+ import { cls } from '../utils/cls.js';
13
+ import 'lodash-es';
14
+ import '@tanstack/react-table';
15
+ import 'ahooks';
16
+
17
+ // 简而言之,启用行选择时,把 footer 的第一个cell 的文字设置为 '合计'
18
+ // 首列固定展示 // TODO 待支持动态首列配置
19
+ function useFirstCellPatch() {
20
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
21
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef,
22
+ tableContainerRef = _useEditableSchemaTab.tableContainerRef;
23
+ var enableRowSelection = globalStaticRef.current.enableRowSelection;
24
+ useEffect(function () {
25
+ if (enableRowSelection) {
26
+ var container = tableContainerRef.current;
27
+ if (container) {
28
+ var selector = "." + cls('footer-wrapper') + " table[data-is-selection] ." + cls('footer-cell');
29
+ var firstCell = container.querySelector(selector);
30
+ if (firstCell) {
31
+ firstCell.innerHTML = '合计';
32
+ }
33
+ }
34
+ }
35
+ }, [enableRowSelection, tableContainerRef]);
36
+ }
37
+ export { useFirstCellPatch };
@@ -0,0 +1,121 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import { cx } from '@hi-ui/classname';
12
+ import { flexRender } from '@tanstack/react-table';
13
+ import { mergeValues } from '@hi-ui/schema-utils';
14
+ import { useElHovering } from '@hi-ui/schema-hooks';
15
+ import { useEditableSchemaTableCtx } from '../ctx.js';
16
+ import '../container/index.js';
17
+ import { getFixedStyles } from '../utils/fixed.js';
18
+ import { cls } from '../utils/cls.js';
19
+ import { validateHeaderCell } from './validate.js';
20
+ import { useTableContainer } from '../container/ctx.js';
21
+ var HeaderCellWrapper = /*#__PURE__*/React.memo(function HeaderCell(props) {
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
23
+ var header = props.header;
24
+ var _useEditableSchemaTab = useEditableSchemaTableCtx(),
25
+ table = _useEditableSchemaTab.table,
26
+ globalStaticRef = _useEditableSchemaTab.globalStaticRef;
27
+ // 鼠标hover时,增加 data-hovering 状态
28
+ var _useElHovering = useElHovering(),
29
+ headerCellRef = _useElHovering.elRef;
30
+ var validation = validateHeaderCell(header, table.getHeaderGroups().length);
31
+ if (!validation.isValid) return null;
32
+ // 开启 fixed 时才去获取固定单元格的样式
33
+ var fixed = props.fixed ? getFixedStyles(header.column, {
34
+ globalStaticRef: globalStaticRef
35
+ }) : {};
36
+ var fixedClassName = (fixed.className || []).map(function (c) {
37
+ return "cell--" + c;
38
+ });
39
+ // 获取动态属性
40
+ var dynamicAttrs = (_b = (_a = header.column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.headerCell) === null || _b === void 0 ? void 0 : _b.call(_a, {
41
+ header: header
42
+ });
43
+ var style = mergeValues(fixed.style, dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.style);
44
+ return /*#__PURE__*/React.createElement("th", Object.assign({}, dynamicAttrs, {
45
+ className: cx(cls.apply(void 0, ['header-cell'].concat(fixedClassName)), dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.className),
46
+ ref: headerCellRef,
47
+ colSpan: (_c = dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.colSpan) !== null && _c !== void 0 ? _c : header.colSpan,
48
+ rowSpan: (_d = dynamicAttrs === null || dynamicAttrs === void 0 ? void 0 : dynamicAttrs.rowSpan) !== null && _d !== void 0 ? _d : validation.rowSpan,
49
+ style: style,
50
+ "data-has-children": ((_e = header.column.columnDef.meta) === null || _e === void 0 ? void 0 : _e.field.children) ? true : undefined,
51
+ "data-text-align": (_f = header.column.columnDef.meta) === null || _f === void 0 ? void 0 : _f.align,
52
+ "data-field-name": (_h = (_g = header.column.columnDef.meta) === null || _g === void 0 ? void 0 : _g.field) === null || _h === void 0 ? void 0 : _h._titleText,
53
+ "data-field-key": (_k = (_j = header.column.columnDef.meta) === null || _j === void 0 ? void 0 : _j.field) === null || _k === void 0 ? void 0 : _k.dataIndex
54
+ }), flexRender(header.column.columnDef.header, header.getContext()));
55
+ });
56
+ var Header = /*#__PURE__*/React.memo(function Header(_ref) {
57
+ var className = _ref.className;
58
+ var _useEditableSchemaTab2 = useEditableSchemaTableCtx(),
59
+ table = _useEditableSchemaTab2.table;
60
+ var _useTableContainer = useTableContainer(),
61
+ virtualize = _useTableContainer.virtualize;
62
+ return /*#__PURE__*/React.createElement("thead", {
63
+ className: cls('header', className)
64
+ }, table.getHeaderGroups().map(function (headerGroup) {
65
+ var _a, _b, _c, _d;
66
+ var realHeaders = headerGroup.headers;
67
+ var _groupHeaders = groupHeaders(realHeaders, table),
68
+ leftHeaders = _groupHeaders.left,
69
+ rightHeaders = _groupHeaders.right,
70
+ centerHeaders = _groupHeaders.center;
71
+ return /*#__PURE__*/React.createElement("tr", {
72
+ key: headerGroup.id,
73
+ className: cls('header-row')
74
+ }, leftHeaders.map(function (header) {
75
+ return /*#__PURE__*/React.createElement(HeaderCellWrapper, {
76
+ key: header.id,
77
+ header: header,
78
+ fixed: true
79
+ });
80
+ }), ((_b = (_a = virtualize === null || virtualize === void 0 ? void 0 : virtualize.colPadding) === null || _a === void 0 ? void 0 : _a.left) !== null && _b !== void 0 ? _b : 0) > 0 ? /*#__PURE__*/React.createElement("th", null) : null, ((virtualize === null || virtualize === void 0 ? void 0 : virtualize.columns) || centerHeaders).map(function (headerOrVirtual) {
81
+ var header = 'index' in headerOrVirtual ? realHeaders[headerOrVirtual.index] : headerOrVirtual;
82
+ if (!header) return null;
83
+ // 固定列不参与虚拟化
84
+ if (header.column.getIsPinned()) return null;
85
+ return /*#__PURE__*/React.createElement(HeaderCellWrapper, {
86
+ key: header.id,
87
+ header: header
88
+ });
89
+ }), ((_d = (_c = virtualize === null || virtualize === void 0 ? void 0 : virtualize.colPadding) === null || _c === void 0 ? void 0 : _c.right) !== null && _d !== void 0 ? _d : 0) > 0 ? /*#__PURE__*/React.createElement("th", null) : null, rightHeaders.map(function (header) {
90
+ return /*#__PURE__*/React.createElement(HeaderCellWrapper, {
91
+ key: header.id,
92
+ header: header,
93
+ fixed: true
94
+ });
95
+ }));
96
+ }));
97
+ });
98
+ function groupHeaders(headers, table) {
99
+ var leftColumns = table.getLeftVisibleLeafColumns();
100
+ var rightColumns = table.getRightVisibleLeafColumns();
101
+ // 创建一个 Map 记录每列的位置类型
102
+ var columnPositions = new Map();
103
+ // 记录固定列的 id
104
+ leftColumns.forEach(function (col) {
105
+ return columnPositions.set(col.id, 'left');
106
+ });
107
+ rightColumns.forEach(function (col) {
108
+ return columnPositions.set(col.id, 'right');
109
+ });
110
+ // 使用 reduce 一次遍历完成分组
111
+ return headers.reduce(function (groups, header) {
112
+ var position = columnPositions.get(header.column.id) || 'center';
113
+ groups[position].push(header);
114
+ return groups;
115
+ }, {
116
+ left: [],
117
+ center: [],
118
+ right: []
119
+ });
120
+ }
121
+ export { Header as default, groupHeaders };
@@ -0,0 +1,64 @@
1
+ /** @LICENSE
2
+ * @hi-ui/schema-editable-table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/schema/schema-editable-table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ function validateHeaderCell(header, totalHeaderRows) {
11
+ var _a;
12
+ var noParent = header.column.parent === undefined;
13
+ // isCrossCol 判断的准确性待进一步验证,目前实测有效
14
+ // crossCol 是指仅有一个子元素的列 // TODO 进一步细化描述
15
+ var isCrossCol = ((_a = header.subHeaders) === null || _a === void 0 ? void 0 : _a.length) === 1;
16
+ // 占位元素
17
+ if (header.isPlaceholder) {
18
+ // 没有父元素且是交叉列
19
+ if (noParent && isCrossCol) {
20
+ var isFirstRow = header.depth === 1;
21
+ if (isFirstRow) {
22
+ return {
23
+ isValid: true,
24
+ rowSpan: totalHeaderRows,
25
+ type: 'PLACEHOLDER-NO-PARENT'
26
+ };
27
+ }
28
+ }
29
+ // 有父元素且是交叉列
30
+ if (!noParent && isCrossCol) {
31
+ var parent = header.column.parent;
32
+ if (parent && header.depth - parent.depth <= 2) {
33
+ return {
34
+ isValid: true,
35
+ rowSpan: Math.max(1, totalHeaderRows - header.depth + 1),
36
+ type: 'PLACEHOLDER-WITH-PARENT'
37
+ };
38
+ }
39
+ }
40
+ }
41
+ // 正常元素
42
+ else if (noParent) {
43
+ if (header.depth === 1) {
44
+ return {
45
+ isValid: true,
46
+ rowSpan: 1,
47
+ type: 'NORMAL-NO-PARENT'
48
+ };
49
+ }
50
+ } else {
51
+ var _parent = header.column.parent;
52
+ if (_parent && header.depth - _parent.depth <= 2) {
53
+ return {
54
+ isValid: true,
55
+ rowSpan: 1,
56
+ type: 'NORMAL-WITH-PARENT'
57
+ };
58
+ }
59
+ }
60
+ return {
61
+ isValid: false
62
+ };
63
+ }
64
+ export { validateHeaderCell };
@@ -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 { useCallback } from 'react';
11
+ import { pick, set, omit } from 'lodash-es';
12
+ function useGetFieldsValue(ctx) {
13
+ var innerRef = ctx.innerRef;
14
+ return useCallback(function getFieldsValue(opts) {
15
+ if (opts === void 0) {
16
+ opts = {};
17
+ }
18
+ var _innerRef$current = innerRef.current,
19
+ subscription = _innerRef$current.subscription,
20
+ globalStaticRef = _innerRef$current.globalStaticRef;
21
+ var allValues = subscription.getValue();
22
+ var keys = globalStaticRef.current.editableFieldKeys;
23
+ return allValues.map(function (row) {
24
+ var _a;
25
+ var values = pick(row, keys);
26
+ // 额外需要获取的 fields
27
+ if ((_a = opts.extraFields) === null || _a === void 0 ? void 0 : _a.length) {
28
+ opts.extraFields.forEach(function (field) {
29
+ set(values, field, row[field]);
30
+ });
31
+ }
32
+ return values;
33
+ });
34
+ }, [innerRef]);
35
+ }
36
+ function useGetGroupedValues(ctx) {
37
+ var innerRef = ctx.innerRef;
38
+ return useCallback(function getGroupedValues() {
39
+ var _innerRef$current2 = innerRef.current,
40
+ subscription = _innerRef$current2.subscription,
41
+ globalStaticRef = _innerRef$current2.globalStaticRef;
42
+ var allValues = subscription.getValue();
43
+ var keys = globalStaticRef.current.editableFieldKeys; // 可编辑字段
44
+ return allValues.map(function (row) {
45
+ var editable = pick(row, keys);
46
+ var readonly = omit(row, keys);
47
+ return {
48
+ editable: editable,
49
+ readonly: readonly
50
+ };
51
+ });
52
+ }, [innerRef] // innerRef
53
+ );
54
+ }
55
+
56
+ export { useGetFieldsValue, useGetGroupedValues };
@@ -0,0 +1,60 @@
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 { useMemoizedFn, useLatest } from 'ahooks';
11
+ import { useGetDataSource } from '../features/async-data/normal.js';
12
+ import { useResetDataSource } from '../features/async-data/use-reset-data.js';
13
+ import 'tslib';
14
+ import '@hi-ui/schema-utils';
15
+ import 'react';
16
+ import '../utils/cls.js';
17
+ import '../container/index.js';
18
+ import 'lodash-es';
19
+ import '@tanstack/react-table';
20
+ import '@hi-ui/checkbox';
21
+ import '@hi-ui/radio';
22
+ import '@hi-ui/use-subscription';
23
+ import '@hi-ui/space';
24
+ import '@hi-ui/switch';
25
+ import { useSetSelectedRowKeys } from '../features/row-selection/hooks/use-set-selected-row-keys.js';
26
+
27
+ /**
28
+ * 全局静态函数
29
+ */
30
+ function useGlobalStaticActions(ctx) {
31
+ var innerRef = ctx.innerRef;
32
+ // 获取异步数据源
33
+ var _useGetDataSource = useGetDataSource({
34
+ innerRef: innerRef
35
+ }),
36
+ getDataSource = _useGetDataSource.getDataSource,
37
+ updateDataSource = _useGetDataSource.updateDataSource;
38
+ // 重置分页、筛选
39
+ var resetDataSource = useResetDataSource({
40
+ innerRef: innerRef
41
+ });
42
+ var setDataSource = useMemoizedFn(
43
+ // 设置表格数据源
44
+ function setDataSource(dataSource) {
45
+ innerRef.current.subscription.setValue(dataSource);
46
+ });
47
+ // 设置行选择状态
48
+ var setSelectedRowKeys = useSetSelectedRowKeys({
49
+ innerRef: innerRef
50
+ });
51
+ var globalStaticActions = {
52
+ getDataSource: getDataSource,
53
+ updateDataSource: updateDataSource,
54
+ resetDataSource: resetDataSource,
55
+ setDataSource: setDataSource,
56
+ setSelectedRowKeys: setSelectedRowKeys
57
+ };
58
+ return useLatest(globalStaticActions);
59
+ }
60
+ export { useGlobalStaticActions };
@@ -0,0 +1,152 @@
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
+ import { useLatest } from 'ahooks';
12
+ import { ROW_OPERATION_COL_WIDTH } from '../const.js';
13
+
14
+ /**
15
+ * 从 propsRef 中生成静态配置
16
+ * @desc 是 useGlobalStatic 返回值的子集
17
+ * @desc 也就是仅包含能直接从 propsRef 中获取的选项配置
18
+ */
19
+ function genStaticOptsFromPropsRef(propsRef) {
20
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
21
+ // 是否启用异步数据
22
+ var enableAsyncData = !!((_a = propsRef.current.asyncData) === null || _a === void 0 ? void 0 : _a.request);
23
+ // 存在嵌套表头
24
+ var hasNestHeader = !!propsRef.current.fields.some(function (field) {
25
+ var _a;
26
+ return !!((_a = field.children) === null || _a === void 0 ? void 0 : _a.length);
27
+ });
28
+ var enableRowSelection = !!((_b = propsRef.current) === null || _b === void 0 ? void 0 : _b.rowSelection);
29
+ var enableRowOperation = !!((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.rowOperation);
30
+ var enableRowEdit = !!((_e = (_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.rowOperation) === null || _e === void 0 ? void 0 : _e.rowEdit);
31
+ // 操作列列宽是动态的,需要从配置中取出
32
+ var operationColWidth = ((_g = (_f = propsRef.current) === null || _f === void 0 ? void 0 : _f.rowOperation) === null || _g === void 0 ? void 0 : _g.width) || ROW_OPERATION_COL_WIDTH;
33
+ var fields = propsRef.current.fields;
34
+ // 分页
35
+ var enablePagination = !!((_h = propsRef.current) === null || _h === void 0 ? void 0 : _h.pagination);
36
+ // 是否存在过滤字段
37
+ var enableFilter = !!propsRef.current.filter && fields.some(function (field) {
38
+ var _a;
39
+ return !!((_a = field.control) === null || _a === void 0 ? void 0 : _a.filter);
40
+ });
41
+ // 表头过滤是否启用远程数据
42
+ var enableRemoteFilter = enableAsyncData && enableFilter && !!((_j = propsRef.current.filter) === null || _j === void 0 ? void 0 : _j.remote);
43
+ // 是否存在排序字段
44
+ var enableSorter = !!propsRef.current.sorter && fields.some(function (field) {
45
+ var _a;
46
+ return !!((_a = field.control) === null || _a === void 0 ? void 0 : _a.sorter);
47
+ });
48
+ // 表头排序是否启用远程数据
49
+ var enableRemoteSorter = enableAsyncData && enableSorter && !!((_k = propsRef.current.sorter) === null || _k === void 0 ? void 0 : _k.remote);
50
+ // 是否启用行展开
51
+ var enableRowExpanding = !!propsRef.current.expanding;
52
+ // 是否启用列分组
53
+ var enableRowGrouping = !!propsRef.current.grouping;
54
+ // 底部容器是否为空
55
+ var isBottomEmpty =
56
+ // 没有左侧的行选择指示器
57
+ !((_l = propsRef.current.rowSelection) === null || _l === void 0 ? void 0 : _l.enableIndicator) &&
58
+ // 也没有分页器
59
+ !propsRef.current.pagination;
60
+ return {
61
+ enableAsyncData: enableAsyncData,
62
+ hasNestHeader: hasNestHeader,
63
+ enableRowSelection: enableRowSelection,
64
+ enableRowOperation: enableRowOperation,
65
+ enableRowEdit: enableRowEdit,
66
+ operationColWidth: operationColWidth,
67
+ enablePagination: enablePagination,
68
+ enableHeaderActionHoverOnly: !!((_m = propsRef.current.headerAction) === null || _m === void 0 ? void 0 : _m.onlyVisibleOnHover),
69
+ enableFilter: enableFilter,
70
+ enableRemoteFilter: enableRemoteFilter,
71
+ enableSorter: enableSorter,
72
+ enableRemoteSorter: enableRemoteSorter,
73
+ enableRowExpanding: enableRowExpanding,
74
+ enableRowGrouping: enableRowGrouping,
75
+ isBottomEmpty: isBottomEmpty
76
+ };
77
+ }
78
+ /**
79
+ * 全局静态配置
80
+ * @desc 实际上并不是完全静态,而是指由配置生成后,禁止主动变化
81
+ */
82
+ function useGlobalStatic(ctx) {
83
+ var _a, _b, _c;
84
+ var table = ctx.table,
85
+ subscription = ctx.subscription,
86
+ propsRef = ctx.propsRef;
87
+ var isEmpty =
88
+ // 表格数据长度为0
89
+ subscription.getValue().length === 0 ||
90
+ // 表格数据过滤后长度为0
91
+ table.getFilteredRowModel().rows.length === 0;
92
+ var showFooter = !isEmpty && !!((_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.showFooter);
93
+ var hasStickyFooter = showFooter && !!((_c = (_b = propsRef.current) === null || _b === void 0 ? void 0 : _b.sticky) === null || _c === void 0 ? void 0 : _c.footer) || undefined;
94
+ var _columnPinning = table.getState().columnPinning;
95
+ var hasLeftFixed = _columnPinning.left !== undefined && _columnPinning.left.length > 0;
96
+ var hasRightFixed = _columnPinning.right !== undefined && _columnPinning.right.length > 0;
97
+ var fields = propsRef.current.fields;
98
+ var editableFieldKeys = useMemo(function () {
99
+ return genEditableFieldKeys(fields);
100
+ }, [fields]);
101
+ var staticOpts = ctx.staticOptsRef.current;
102
+ var globalStatic = {
103
+ enableAsyncData: staticOpts.enableAsyncData,
104
+ isEmpty: isEmpty,
105
+ showFooter: showFooter,
106
+ hasStickyFooter: hasStickyFooter,
107
+ hasNestHeader: staticOpts.hasNestHeader,
108
+ hasLeftFixed: hasLeftFixed,
109
+ hasRightFixed: hasRightFixed,
110
+ enableRowSelection: staticOpts.enableRowSelection,
111
+ enableRowOperation: staticOpts.enableRowOperation,
112
+ enableRowEdit: staticOpts.enableRowEdit,
113
+ operationColWidth: staticOpts.operationColWidth,
114
+ editableFieldKeys: editableFieldKeys,
115
+ enablePagination: staticOpts.enablePagination,
116
+ enableHeaderActionHoverOnly: staticOpts.enableHeaderActionHoverOnly,
117
+ enableFilter: staticOpts.enableFilter,
118
+ enableRemoteFilter: staticOpts.enableRemoteFilter,
119
+ enableSorter: staticOpts.enableSorter,
120
+ enableRemoteSorter: staticOpts.enableRemoteSorter,
121
+ enableRowExpanding: staticOpts.enableRowExpanding,
122
+ enableRowGrouping: staticOpts.enableRowGrouping,
123
+ isBottomEmpty: staticOpts.isBottomEmpty
124
+ };
125
+ return useLatest(globalStatic);
126
+ }
127
+ /**
128
+ * 生成所有可编辑字段的 key
129
+ * @desc 仅在可编辑表格中生效
130
+ */
131
+ function genEditableFieldKeys(fields) {
132
+ var result = [];
133
+ var traverse = function traverse(field) {
134
+ var _a;
135
+ // 如果有children,递归处理children
136
+ if ((_a = field.children) === null || _a === void 0 ? void 0 : _a.length) {
137
+ field.children.forEach(traverse);
138
+ return;
139
+ }
140
+ var _ref = field.control || {},
141
+ readonly = _ref.readonly,
142
+ editable = _ref.editable;
143
+ // 明确只读,不可编辑
144
+ if (readonly) return;
145
+ // 明确不可编辑
146
+ if (editable === false) return;
147
+ result.push(field.dataIndex);
148
+ };
149
+ fields.forEach(traverse);
150
+ return result;
151
+ }
152
+ export { genStaticOptsFromPropsRef, useGlobalStatic };
@@ -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 React from 'react';
11
+ import { useUpdate } from 'ahooks';
12
+ function useInitialRender() {
13
+ var forceUpdate = useUpdate();
14
+ React.useEffect(function () {
15
+ forceUpdate();
16
+ }, [forceUpdate]);
17
+ }
18
+ export { useInitialRender };