@nokecy/qc-ui-components 2.0.0-beta.0 → 2.0.0-beta.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 (243) hide show
  1. package/dist/cjs/ConfirmPro/index.d.ts +12 -9
  2. package/dist/cjs/ConfirmPro/index.js +11 -34
  3. package/dist/cjs/ag-grid-plus/ag-gridPlus.js +422 -156
  4. package/dist/cjs/ag-grid-plus/context/gridContext.d.ts +12 -1
  5. package/dist/cjs/ag-grid-plus/context/queryFormContext.d.ts +2 -0
  6. package/dist/cjs/ag-grid-plus/context/useSchemeDataFlow.js +8 -0
  7. package/dist/cjs/ag-grid-plus/density.d.ts +25 -0
  8. package/dist/cjs/ag-grid-plus/density.js +52 -0
  9. package/dist/cjs/ag-grid-plus/index.less +36 -0
  10. package/dist/cjs/ag-grid-plus/interface.d.ts +58 -1
  11. package/dist/cjs/ag-grid-plus/interface.js +1 -1
  12. package/dist/cjs/ag-grid-plus/queryForm/index.d.ts +11 -0
  13. package/dist/cjs/ag-grid-plus/queryForm/index.js +62 -10
  14. package/dist/cjs/ag-grid-plus/queryForm/queryForm.d.ts +10 -0
  15. package/dist/cjs/ag-grid-plus/queryForm/queryForm.js +63 -26
  16. package/dist/cjs/ag-grid-plus/queryForm/queryValues.d.ts +9 -0
  17. package/dist/cjs/ag-grid-plus/queryForm/queryValues.js +61 -0
  18. package/dist/cjs/ag-grid-plus/rowColors.d.ts +12 -0
  19. package/dist/cjs/ag-grid-plus/rowColors.js +58 -0
  20. package/dist/cjs/ag-grid-plus/setting/ColumnConfigTable.d.ts +5 -0
  21. package/dist/cjs/ag-grid-plus/setting/ColumnConfigTable.js +14 -5
  22. package/dist/cjs/ag-grid-plus/setting/ColumnSetting.js +108 -76
  23. package/dist/cjs/ag-grid-plus/setting/QuerySchemeManager.js +10 -9
  24. package/dist/cjs/ag-grid-plus/setting/autoColumnMemory.d.ts +37 -0
  25. package/dist/cjs/ag-grid-plus/setting/autoColumnMemory.js +206 -0
  26. package/dist/cjs/ag-grid-plus/setting/columnGroupUtils.d.ts +2 -0
  27. package/dist/cjs/ag-grid-plus/setting/columnGroupUtils.js +19 -1
  28. package/dist/cjs/ag-grid-plus/setting/index.js +5 -14
  29. package/dist/cjs/ag-grid-plus/settingItem/index.d.ts +11 -1
  30. package/dist/cjs/ag-grid-plus/settingItem/index.js +34 -12
  31. package/dist/cjs/ag-grid-plus/shared/EmptyIllustration.d.ts +16 -0
  32. package/dist/cjs/ag-grid-plus/shared/EmptyIllustration.js +87 -0
  33. package/dist/cjs/ag-grid-plus/shared/NoRowsOverlay.js +9 -1
  34. package/dist/cjs/ag-grid-plus/shared/SkeletonOverlay.d.ts +11 -0
  35. package/dist/cjs/ag-grid-plus/shared/SkeletonOverlay.js +40 -0
  36. package/dist/cjs/ag-grid-plus/shared/storage/schemeStorageAdapter.d.ts +1 -1
  37. package/dist/cjs/ag-grid-plus/theme.d.ts +7 -1
  38. package/dist/cjs/ag-grid-plus/theme.js +31 -6
  39. package/dist/cjs/ag-grid-plus/toolBar/OverflowActions.d.ts +16 -0
  40. package/dist/cjs/ag-grid-plus/toolBar/OverflowActions.js +128 -0
  41. package/dist/cjs/ag-grid-plus/toolBar/index.d.ts +3 -1
  42. package/dist/cjs/ag-grid-plus/toolBar/index.js +43 -35
  43. package/dist/cjs/ag-grid-plus/toolBar/leftContent.d.ts +2 -2
  44. package/dist/cjs/ag-grid-plus/toolBar/leftContent.js +2 -2
  45. package/dist/cjs/ag-grid-plus/toolBar/overflow.d.ts +20 -0
  46. package/dist/cjs/ag-grid-plus/toolBar/overflow.js +48 -0
  47. package/dist/cjs/ag-grid-plus/toolBar/style.js +71 -15
  48. package/dist/cjs/ag-grid-plus/types.d.ts +6 -0
  49. package/dist/cjs/ag-grid-plus/utils/agGridCompat.js +12 -3
  50. package/dist/cjs/ag-grid-plus/utils/columnProcessors.d.ts +3 -0
  51. package/dist/cjs/ag-grid-plus/utils/columnProcessors.js +13 -2
  52. package/dist/cjs/ag-grid-plus/utils/constants.d.ts +3 -2
  53. package/dist/cjs/ag-grid-plus/utils/constants.js +3 -2
  54. package/dist/cjs/ag-grid-plus/utils/crossPageSelection.d.ts +21 -0
  55. package/dist/cjs/ag-grid-plus/utils/crossPageSelection.js +58 -0
  56. package/dist/cjs/ag-grid-plus/utils/emptyState.d.ts +2 -0
  57. package/dist/cjs/ag-grid-plus/utils/emptyState.js +9 -5
  58. package/dist/cjs/ag-grid-plus/utils/listKeyboard.d.ts +24 -0
  59. package/dist/cjs/ag-grid-plus/utils/listKeyboard.js +83 -0
  60. package/dist/cjs/ag-grid-plus/utils/pagination.d.ts +26 -0
  61. package/dist/cjs/ag-grid-plus/utils/pagination.js +69 -0
  62. package/dist/cjs/ag-grid-plus/utils/queryDispatch.d.ts +7 -0
  63. package/dist/cjs/ag-grid-plus/utils/queryDispatch.js +17 -0
  64. package/dist/cjs/ag-grid-plus/utils/statusPill.d.ts +25 -0
  65. package/dist/cjs/ag-grid-plus/utils/statusPill.js +196 -0
  66. package/dist/cjs/ag-grid-plus/utils/valueEnumColor.d.ts +6 -1
  67. package/dist/cjs/ag-grid-plus/utils/valueEnumColor.js +13 -9
  68. package/dist/cjs/ag-grid-plus/utils/valueFormat.d.ts +19 -0
  69. package/dist/cjs/ag-grid-plus/utils/valueFormat.js +73 -0
  70. package/dist/cjs/ag-grid-plus/utils.js +3 -2
  71. package/dist/cjs/array-table/arrayAddBtn.d.ts +1 -0
  72. package/dist/cjs/array-table/arrayAddBtn.js +2 -2
  73. package/dist/cjs/array-table/autoHeight.d.ts +18 -0
  74. package/dist/cjs/array-table/autoHeight.js +30 -0
  75. package/dist/cjs/array-table/batchRemove.d.ts +2 -2
  76. package/dist/cjs/array-table/cellEditorMarker.d.ts +18 -0
  77. package/dist/cjs/array-table/cellEditorMarker.js +92 -0
  78. package/dist/cjs/array-table/errorLocator.d.ts +29 -0
  79. package/dist/cjs/array-table/errorLocator.js +101 -0
  80. package/dist/cjs/array-table/hooks.d.ts +52 -4
  81. package/dist/cjs/array-table/hooks.js +251 -18
  82. package/dist/cjs/array-table/index.d.ts +6 -0
  83. package/dist/cjs/array-table/index.js +167 -23
  84. package/dist/cjs/array-table/interface.d.ts +22 -0
  85. package/dist/cjs/array-table/preview.js +39 -5
  86. package/dist/cjs/array-table/rowFeedback.d.ts +2 -2
  87. package/dist/cjs/array-table/rowFeedback.js +8 -8
  88. package/dist/cjs/array-table/summary.d.ts +25 -0
  89. package/dist/cjs/array-table/summary.js +70 -0
  90. package/dist/cjs/array-table/theme.d.ts +35 -5
  91. package/dist/cjs/array-table/theme.js +49 -12
  92. package/dist/cjs/array-table/title.d.ts +3 -0
  93. package/dist/cjs/array-table/title.js +29 -0
  94. package/dist/cjs/array-table/utils.d.ts +2 -1
  95. package/dist/cjs/array-table/utils.js +94 -23
  96. package/dist/cjs/card/pro-card/Card/useLegacyItems.d.ts +1 -1
  97. package/dist/cjs/dateCellEditor/DateCellEditor.d.ts +5 -0
  98. package/dist/cjs/dateCellEditor/DateCellEditor.js +42 -17
  99. package/dist/cjs/deleteConfirm/index.d.ts +14 -0
  100. package/dist/cjs/deleteConfirm/index.js +73 -12
  101. package/dist/cjs/dialogSelect/index.d.ts +19 -0
  102. package/dist/cjs/dialogSelect/index.js +189 -15
  103. package/dist/cjs/dialogSelect/index.less +18 -0
  104. package/dist/cjs/documentPage/documentPage.d.ts +6 -3
  105. package/dist/cjs/documentPage/documentPage.js +23 -8
  106. package/dist/cjs/documentPage/index.d.ts +2 -0
  107. package/dist/cjs/documentPage/index.js +19 -0
  108. package/dist/cjs/documentPage/leaveGuard.d.ts +31 -0
  109. package/dist/cjs/documentPage/leaveGuard.js +91 -0
  110. package/dist/cjs/draggableModal/index.d.ts +24 -1
  111. package/dist/cjs/draggableModal/index.js +36 -6
  112. package/dist/cjs/fullScreenAlert/index.less +10 -10
  113. package/dist/cjs/index.d.ts +2 -0
  114. package/dist/cjs/index.js +15 -0
  115. package/dist/cjs/readPretty/arrayTable.js +5 -1
  116. package/dist/cjs/scanCollect/ScanFeedbackInput.d.ts +26 -0
  117. package/dist/cjs/scanCollect/ScanFeedbackInput.js +113 -0
  118. package/dist/cjs/scanCollect/index.d.ts +4 -0
  119. package/dist/cjs/scanCollect/index.js +14 -0
  120. package/dist/cjs/scanCollect/scanSound.d.ts +15 -0
  121. package/dist/cjs/scanCollect/scanSound.js +91 -0
  122. package/dist/esm/ConfirmPro/index.d.ts +12 -9
  123. package/dist/esm/ConfirmPro/index.js +11 -34
  124. package/dist/esm/ag-grid-plus/ag-gridPlus.js +423 -156
  125. package/dist/esm/ag-grid-plus/context/gridContext.d.ts +12 -1
  126. package/dist/esm/ag-grid-plus/context/queryFormContext.d.ts +2 -0
  127. package/dist/esm/ag-grid-plus/context/useSchemeDataFlow.js +8 -0
  128. package/dist/esm/ag-grid-plus/density.d.ts +25 -0
  129. package/dist/esm/ag-grid-plus/density.js +45 -0
  130. package/dist/esm/ag-grid-plus/index.less +36 -0
  131. package/dist/esm/ag-grid-plus/interface.d.ts +58 -1
  132. package/dist/esm/ag-grid-plus/interface.js +2 -0
  133. package/dist/esm/ag-grid-plus/queryForm/index.d.ts +11 -0
  134. package/dist/esm/ag-grid-plus/queryForm/index.js +62 -10
  135. package/dist/esm/ag-grid-plus/queryForm/queryForm.d.ts +10 -0
  136. package/dist/esm/ag-grid-plus/queryForm/queryForm.js +64 -26
  137. package/dist/esm/ag-grid-plus/queryForm/queryValues.d.ts +9 -0
  138. package/dist/esm/ag-grid-plus/queryForm/queryValues.js +54 -0
  139. package/dist/esm/ag-grid-plus/rowColors.d.ts +12 -0
  140. package/dist/esm/ag-grid-plus/rowColors.js +50 -0
  141. package/dist/esm/ag-grid-plus/setting/ColumnConfigTable.d.ts +5 -0
  142. package/dist/esm/ag-grid-plus/setting/ColumnConfigTable.js +14 -5
  143. package/dist/esm/ag-grid-plus/setting/ColumnSetting.js +110 -78
  144. package/dist/esm/ag-grid-plus/setting/QuerySchemeManager.js +10 -9
  145. package/dist/esm/ag-grid-plus/setting/autoColumnMemory.d.ts +37 -0
  146. package/dist/esm/ag-grid-plus/setting/autoColumnMemory.js +198 -0
  147. package/dist/esm/ag-grid-plus/setting/columnGroupUtils.d.ts +2 -0
  148. package/dist/esm/ag-grid-plus/setting/columnGroupUtils.js +18 -1
  149. package/dist/esm/ag-grid-plus/setting/index.js +6 -15
  150. package/dist/esm/ag-grid-plus/settingItem/index.d.ts +11 -1
  151. package/dist/esm/ag-grid-plus/settingItem/index.js +35 -13
  152. package/dist/esm/ag-grid-plus/shared/EmptyIllustration.d.ts +16 -0
  153. package/dist/esm/ag-grid-plus/shared/EmptyIllustration.js +82 -0
  154. package/dist/esm/ag-grid-plus/shared/NoRowsOverlay.js +9 -1
  155. package/dist/esm/ag-grid-plus/shared/SkeletonOverlay.d.ts +11 -0
  156. package/dist/esm/ag-grid-plus/shared/SkeletonOverlay.js +34 -0
  157. package/dist/esm/ag-grid-plus/shared/storage/schemeStorageAdapter.d.ts +1 -1
  158. package/dist/esm/ag-grid-plus/theme.d.ts +7 -1
  159. package/dist/esm/ag-grid-plus/theme.js +31 -6
  160. package/dist/esm/ag-grid-plus/toolBar/OverflowActions.d.ts +16 -0
  161. package/dist/esm/ag-grid-plus/toolBar/OverflowActions.js +120 -0
  162. package/dist/esm/ag-grid-plus/toolBar/index.d.ts +3 -1
  163. package/dist/esm/ag-grid-plus/toolBar/index.js +43 -35
  164. package/dist/esm/ag-grid-plus/toolBar/leftContent.d.ts +2 -2
  165. package/dist/esm/ag-grid-plus/toolBar/leftContent.js +2 -2
  166. package/dist/esm/ag-grid-plus/toolBar/overflow.d.ts +20 -0
  167. package/dist/esm/ag-grid-plus/toolBar/overflow.js +41 -0
  168. package/dist/esm/ag-grid-plus/toolBar/style.js +71 -15
  169. package/dist/esm/ag-grid-plus/types.d.ts +6 -0
  170. package/dist/esm/ag-grid-plus/utils/agGridCompat.js +12 -3
  171. package/dist/esm/ag-grid-plus/utils/columnProcessors.d.ts +3 -0
  172. package/dist/esm/ag-grid-plus/utils/columnProcessors.js +14 -3
  173. package/dist/esm/ag-grid-plus/utils/constants.d.ts +3 -2
  174. package/dist/esm/ag-grid-plus/utils/constants.js +3 -2
  175. package/dist/esm/ag-grid-plus/utils/crossPageSelection.d.ts +21 -0
  176. package/dist/esm/ag-grid-plus/utils/crossPageSelection.js +52 -0
  177. package/dist/esm/ag-grid-plus/utils/emptyState.d.ts +2 -0
  178. package/dist/esm/ag-grid-plus/utils/emptyState.js +9 -5
  179. package/dist/esm/ag-grid-plus/utils/listKeyboard.d.ts +24 -0
  180. package/dist/esm/ag-grid-plus/utils/listKeyboard.js +77 -0
  181. package/dist/esm/ag-grid-plus/utils/pagination.d.ts +26 -0
  182. package/dist/esm/ag-grid-plus/utils/pagination.js +60 -0
  183. package/dist/esm/ag-grid-plus/utils/queryDispatch.d.ts +7 -0
  184. package/dist/esm/ag-grid-plus/utils/queryDispatch.js +11 -0
  185. package/dist/esm/ag-grid-plus/utils/statusPill.d.ts +25 -0
  186. package/dist/esm/ag-grid-plus/utils/statusPill.js +192 -0
  187. package/dist/esm/ag-grid-plus/utils/valueEnumColor.d.ts +6 -1
  188. package/dist/esm/ag-grid-plus/utils/valueEnumColor.js +12 -8
  189. package/dist/esm/ag-grid-plus/utils/valueFormat.d.ts +19 -0
  190. package/dist/esm/ag-grid-plus/utils/valueFormat.js +63 -0
  191. package/dist/esm/ag-grid-plus/utils.js +3 -2
  192. package/dist/esm/array-table/arrayAddBtn.d.ts +1 -0
  193. package/dist/esm/array-table/arrayAddBtn.js +1 -1
  194. package/dist/esm/array-table/autoHeight.d.ts +18 -0
  195. package/dist/esm/array-table/autoHeight.js +25 -0
  196. package/dist/esm/array-table/batchRemove.d.ts +2 -2
  197. package/dist/esm/array-table/cellEditorMarker.d.ts +18 -0
  198. package/dist/esm/array-table/cellEditorMarker.js +84 -0
  199. package/dist/esm/array-table/errorLocator.d.ts +29 -0
  200. package/dist/esm/array-table/errorLocator.js +95 -0
  201. package/dist/esm/array-table/hooks.d.ts +52 -4
  202. package/dist/esm/array-table/hooks.js +251 -17
  203. package/dist/esm/array-table/index.d.ts +6 -0
  204. package/dist/esm/array-table/index.js +170 -25
  205. package/dist/esm/array-table/interface.d.ts +22 -0
  206. package/dist/esm/array-table/preview.js +43 -7
  207. package/dist/esm/array-table/rowFeedback.d.ts +2 -2
  208. package/dist/esm/array-table/rowFeedback.js +8 -8
  209. package/dist/esm/array-table/summary.d.ts +25 -0
  210. package/dist/esm/array-table/summary.js +66 -0
  211. package/dist/esm/array-table/theme.d.ts +35 -5
  212. package/dist/esm/array-table/theme.js +47 -12
  213. package/dist/esm/array-table/title.d.ts +3 -0
  214. package/dist/esm/array-table/title.js +24 -0
  215. package/dist/esm/array-table/utils.d.ts +2 -1
  216. package/dist/esm/array-table/utils.js +93 -22
  217. package/dist/esm/card/pro-card/Card/useLegacyItems.d.ts +1 -1
  218. package/dist/esm/dateCellEditor/DateCellEditor.d.ts +5 -0
  219. package/dist/esm/dateCellEditor/DateCellEditor.js +42 -17
  220. package/dist/esm/deleteConfirm/index.d.ts +14 -0
  221. package/dist/esm/deleteConfirm/index.js +72 -12
  222. package/dist/esm/dialogSelect/index.d.ts +19 -0
  223. package/dist/esm/dialogSelect/index.js +190 -16
  224. package/dist/esm/dialogSelect/index.less +18 -0
  225. package/dist/esm/documentPage/documentPage.d.ts +6 -3
  226. package/dist/esm/documentPage/documentPage.js +23 -8
  227. package/dist/esm/documentPage/index.d.ts +2 -0
  228. package/dist/esm/documentPage/index.js +1 -0
  229. package/dist/esm/documentPage/leaveGuard.d.ts +31 -0
  230. package/dist/esm/documentPage/leaveGuard.js +86 -0
  231. package/dist/esm/draggableModal/index.d.ts +24 -1
  232. package/dist/esm/draggableModal/index.js +35 -5
  233. package/dist/esm/fullScreenAlert/index.less +10 -10
  234. package/dist/esm/index.d.ts +2 -0
  235. package/dist/esm/index.js +1 -0
  236. package/dist/esm/readPretty/arrayTable.js +6 -2
  237. package/dist/esm/scanCollect/ScanFeedbackInput.d.ts +26 -0
  238. package/dist/esm/scanCollect/ScanFeedbackInput.js +107 -0
  239. package/dist/esm/scanCollect/index.d.ts +4 -0
  240. package/dist/esm/scanCollect/index.js +2 -0
  241. package/dist/esm/scanCollect/scanSound.d.ts +15 -0
  242. package/dist/esm/scanCollect/scanSound.js +84 -0
  243. package/package.json +2 -2
@@ -13,12 +13,48 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
13
13
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
14
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
- import React from "react";
17
- import { Modal } from "antd";
16
+ import React, { useState } from "react";
17
+ import { Input, Modal } from "antd";
18
18
  import { ExclamationCircleFilled } from "@ant-design/icons";
19
19
  import { jsx as _jsx } from "react/jsx-runtime";
20
- import { Fragment as _Fragment } from "react/jsx-runtime";
21
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ import { Fragment as _Fragment } from "react/jsx-runtime";
22
+ /** 确认框默认宽度,对应规范「确认、单字段编辑 Modal 560」。 */
23
+ export var CONFIRM_DIALOG_WIDTH = 560;
24
+
25
+ /** 输入确认区:正文 + 一行输入框,键入值与 expected 完全一致时通知外层点亮确认按钮。 */
26
+ var TypeToConfirm = function TypeToConfirm(_ref) {
27
+ var body = _ref.body,
28
+ expected = _ref.expected,
29
+ onMatchChange = _ref.onMatchChange;
30
+ var _useState = useState(''),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ value = _useState2[0],
33
+ setValue = _useState2[1];
34
+ return /*#__PURE__*/_jsxs("div", {
35
+ children: [/*#__PURE__*/_jsx("div", {
36
+ style: {
37
+ marginBottom: 12
38
+ },
39
+ children: body
40
+ }), /*#__PURE__*/_jsxs("div", {
41
+ style: {
42
+ marginBottom: 8
43
+ },
44
+ children: ["\u8BF7\u8F93\u5165 ", /*#__PURE__*/_jsx("strong", {
45
+ children: expected
46
+ }), " \u4EE5\u786E\u8BA4"]
47
+ }), /*#__PURE__*/_jsx(Input, {
48
+ value: value,
49
+ "aria-label": "\u8F93\u5165 ".concat(expected, " \u4EE5\u786E\u8BA4"),
50
+ onChange: function onChange(event) {
51
+ setValue(event.target.value);
52
+ onMatchChange(event.target.value === expected);
53
+ }
54
+ })]
55
+ });
56
+ };
57
+
22
58
  /**
23
59
  * DeleteConfirm 删除确认组件
24
60
  *
@@ -44,6 +80,11 @@ var DeleteConfirm = function DeleteConfirm(props) {
44
80
  okText = props.okText,
45
81
  _props$danger = props.danger,
46
82
  danger = _props$danger === void 0 ? true : _props$danger,
83
+ confirmText = props.confirmText,
84
+ _props$autoFocusButto = props.autoFocusButton,
85
+ autoFocusButton = _props$autoFocusButto === void 0 ? 'cancel' : _props$autoFocusButto,
86
+ _props$width = props.width,
87
+ width = _props$width === void 0 ? CONFIRM_DIALOG_WIDTH : _props$width,
47
88
  children = props.children;
48
89
 
49
90
  // 保留宿主主题,并让 antd 接管异步提交的加载与失败恢复。@author nokecy
@@ -52,8 +93,8 @@ var DeleteConfirm = function DeleteConfirm(props) {
52
93
  modal = _Modal$useModal2[0],
53
94
  contextHolder = _Modal$useModal2[1];
54
95
  var showPromiseConfirm = /*#__PURE__*/function () {
55
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
56
- var titleText, contentText;
96
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
97
+ var titleText, contentText, typed, instance;
57
98
  return _regeneratorRuntime().wrap(function _callee$(_context) {
58
99
  while (1) switch (_context.prev = _context.next) {
59
100
  case 0:
@@ -62,14 +103,33 @@ var DeleteConfirm = function DeleteConfirm(props) {
62
103
  // 不传时的兜底只承诺「不可撤销」:原来的默认正文是把 title 拼进去,
63
104
  // 拼出来是一句病句,而且始终没告诉用户动的是哪条数据。@author nokecy
64
105
  contentText = content || '该操作不可撤销,请确认后继续。';
65
- _context.next = 4;
66
- return modal.confirm(_objectSpread(_objectSpread({
106
+ typed = typeof confirmText === 'string' && confirmText.length > 0;
107
+ _context.next = 5;
108
+ return instance = modal.confirm(_objectSpread(_objectSpread({
67
109
  title: titleText,
68
110
  icon: /*#__PURE__*/_jsx(ExclamationCircleFilled, {}),
69
- content: contentText,
70
- okButtonProps: {
111
+ width: width,
112
+ focusable: {
113
+ autoFocusButton: autoFocusButton
114
+ },
115
+ content: typed ? /*#__PURE__*/_jsx(TypeToConfirm, {
116
+ body: contentText,
117
+ expected: confirmText,
118
+ onMatchChange: function onMatchChange(matched) {
119
+ var _instance;
120
+ return (_instance = instance) === null || _instance === void 0 ? void 0 : _instance.update({
121
+ okButtonProps: {
122
+ danger: danger,
123
+ disabled: !matched
124
+ }
125
+ });
126
+ }
127
+ }) : contentText,
128
+ okButtonProps: _objectSpread({
71
129
  danger: danger
72
- }
130
+ }, typed ? {
131
+ disabled: true
132
+ } : {})
73
133
  }, okText ? {
74
134
  okText: okText
75
135
  } : {}), {}, {
@@ -81,14 +141,14 @@ var DeleteConfirm = function DeleteConfirm(props) {
81
141
  });
82
142
  }
83
143
  }));
84
- case 4:
144
+ case 5:
85
145
  case "end":
86
146
  return _context.stop();
87
147
  }
88
148
  }, _callee);
89
149
  }));
90
150
  return function showPromiseConfirm(_x) {
91
- return _ref.apply(this, arguments);
151
+ return _ref2.apply(this, arguments);
92
152
  };
93
153
  }();
94
154
  return /*#__PURE__*/_jsxs(_Fragment, {
@@ -49,7 +49,26 @@ interface IDialogSelectProps extends SelectProps<any> {
49
49
  }) => React.ReactNode;
50
50
  /** 选择窗口里使用的表格组件,默认 `AgGridPlus`;宿主可注入自己封装过的表格基座。 */
51
51
  gridComponent?: React.ComponentType<any>;
52
+ /**
53
+ * 候选面板第一列(编码)取的字段名。传入后候选渲染成「编码 | 名称」两列,编码在前(DESIGN.md §6.12)。
54
+ * 不传则保持 Select 默认的单列文字。
55
+ */
56
+ codeField?: string;
57
+ /** `onSearch` 的防抖毫秒数,默认 200(§6.12);0 关闭防抖。仅在传了 `onSearch` 时有意义。 */
58
+ searchDebounce?: number;
59
+ /**
60
+ * 远程检索时候选面板最多展示的条数,默认 20,超出写「仅显示前 20 条,继续输入可缩小范围」,不静默截断。
61
+ * 只在传了 `onSearch`(服务端检索)时生效;本地全量下拉不截断。传 0 关闭。
62
+ */
63
+ maxOptions?: number;
64
+ /**
65
+ * 「最近使用」的存储键。传入后输入框为空时候选面板先列最近选过的至多 5 条,其后是档案候选。
66
+ * 存在 localStorage,需要「按用户记」时由调用方把用户标识拼进键里;不传则不启用。
67
+ */
68
+ recentKey?: string;
52
69
  }
70
+ /** 候选面板最小宽,栅格里的输入区放不下两列时仍可读(§6.12)。 */
71
+ export declare const DIALOG_SELECT_MIN_POPUP_WIDTH = 360;
53
72
  export { IDialogSelectProps };
54
73
  declare const _default: (props: IDialogSelectProps) => React.ReactElement;
55
74
  export default _default;
@@ -1,5 +1,5 @@
1
- var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "resolveSelected", "selectedScopeKey", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"],
2
- _excluded2 = ["request", "columnDefs", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "resolveSelected", "selectedScopeKey", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"];
1
+ var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "resolveSelected", "selectedScopeKey", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent", "codeField", "searchDebounce", "maxOptions", "recentKey"],
2
+ _excluded2 = ["request", "columnDefs", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "resolveSelected", "selectedScopeKey", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent", "codeField", "searchDebounce", "maxOptions", "recentKey"];
3
3
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
4
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
5
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -9,6 +9,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
9
9
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
10
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
11
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
16
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
17
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
18
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -21,9 +25,9 @@ import { AutoComplete, ConfigProvider, theme } from 'antd';
21
25
  import { observer, useField } from '@nokecy/formily-react';
22
26
  import { Select } from '@nokecy/formily-antd';
23
27
  import { SearchOutlined } from '@ant-design/icons';
24
- import React, { useState } from 'react';
28
+ import React, { useEffect, useMemo, useState } from 'react';
25
29
  import { AgGridPlus } from "../ag-grid-plus/index";
26
- import { useBoolean, useControllableValue } from 'ahooks';
30
+ import { useBoolean, useControllableValue, useDebounceFn } from 'ahooks';
27
31
  import DraggableModal from "../draggableModal/index";
28
32
  import { Select as ReadingSelect } from "../readPretty/controls";
29
33
  import { normalizeSelectValue } from "../readPretty/selectValue";
@@ -36,6 +40,30 @@ import "./index.less";
36
40
  import { jsx as _jsx } from "react/jsx-runtime";
37
41
  import { jsxs as _jsxs } from "react/jsx-runtime";
38
42
  import { Fragment as _Fragment } from "react/jsx-runtime";
43
+ /** 候选面板最小宽,栅格里的输入区放不下两列时仍可读(§6.12)。 */
44
+ export var DIALOG_SELECT_MIN_POPUP_WIDTH = 360;
45
+ /** 最近使用的上限(§6.12)。 */
46
+ var RECENT_LIMIT = 5;
47
+ var recentStorageKey = function recentStorageKey(key) {
48
+ return "qc-dialog-select:recent:".concat(key);
49
+ };
50
+ var readRecent = function readRecent(key) {
51
+ if (!key) return [];
52
+ try {
53
+ var _window$localStorage$;
54
+ var parsed = JSON.parse((_window$localStorage$ = window.localStorage.getItem(recentStorageKey(key))) !== null && _window$localStorage$ !== void 0 ? _window$localStorage$ : '[]');
55
+ return Array.isArray(parsed) ? parsed.slice(0, RECENT_LIMIT) : [];
56
+ } catch (_unused) {
57
+ return [];
58
+ }
59
+ };
60
+ var writeRecent = function writeRecent(key, items) {
61
+ try {
62
+ window.localStorage.setItem(recentStorageKey(key), JSON.stringify(items.slice(0, RECENT_LIMIT)));
63
+ } catch (_unused2) {
64
+ // 存储不可用时静默放弃,不影响选择本身。
65
+ }
66
+ };
39
67
  var DialogSelectInner = function DialogSelectInner(props) {
40
68
  var _rest$labelRender, _selectRows$length;
41
69
  // 这些是本组件自己的属性,不能透传给 Select(否则会落到 DOM 上触发未知属性告警)。
@@ -64,6 +92,12 @@ var DialogSelectInner = function DialogSelectInner(props) {
64
92
  dialogIsRowSelectable = props.dialogIsRowSelectable,
65
93
  dialogRenderer = props.dialogRenderer,
66
94
  gridComponent = props.gridComponent,
95
+ codeField = props.codeField,
96
+ _props$searchDebounce = props.searchDebounce,
97
+ searchDebounce = _props$searchDebounce === void 0 ? 200 : _props$searchDebounce,
98
+ _props$maxOptions = props.maxOptions,
99
+ maxOptions = _props$maxOptions === void 0 ? 20 : _props$maxOptions,
100
+ recentKey = props.recentKey,
67
101
  rest = _objectWithoutProperties(props, _excluded);
68
102
  var Grid = gridComponent !== null && gridComponent !== void 0 ? gridComponent : AgGridPlus;
69
103
  var _useControllableValue = useControllableValue(props),
@@ -88,6 +122,99 @@ var DialogSelectInner = function DialogSelectInner(props) {
88
122
  var selectionMode = dialogMode !== null && dialogMode !== void 0 ? dialogMode : isMultipleValue ? 'multiple' : 'single';
89
123
  var key = valueField !== null && valueField !== void 0 ? valueField : 'id';
90
124
  var localData = Array.isArray(dialogDataSource);
125
+
126
+ // 候选面板:防抖检索、最近使用、前 N 条上限。
127
+ var _useState3 = useState(''),
128
+ _useState4 = _slicedToArray(_useState3, 2),
129
+ searchText = _useState4[0],
130
+ setSearchText = _useState4[1];
131
+ var _useState5 = useState(function () {
132
+ return readRecent(recentKey);
133
+ }),
134
+ _useState6 = _slicedToArray(_useState5, 2),
135
+ recent = _useState6[0],
136
+ setRecent = _useState6[1];
137
+ useEffect(function () {
138
+ return setRecent(readRecent(recentKey));
139
+ }, [recentKey]);
140
+ var remember = function remember(items) {
141
+ if (!recentKey) return;
142
+ var merged = [].concat(_toConsumableArray(items), _toConsumableArray(recent.filter(function (old) {
143
+ return !items.some(function (it) {
144
+ return it.value === old.value;
145
+ });
146
+ }))).slice(0, RECENT_LIMIT);
147
+ setRecent(merged);
148
+ writeRecent(recentKey, merged);
149
+ };
150
+ var hostOnSearch = rest.onSearch;
151
+ var _useDebounceFn = useDebounceFn(function (text) {
152
+ return hostOnSearch === null || hostOnSearch === void 0 ? void 0 : hostOnSearch(text);
153
+ }, {
154
+ wait: searchDebounce
155
+ }),
156
+ debouncedSearch = _useDebounceFn.run;
157
+ var handleSearch = hostOnSearch ? function (text) {
158
+ setSearchText(text);
159
+ if (searchDebounce > 0) debouncedSearch(text);else hostOnSearch(text);
160
+ } : undefined;
161
+ var remoteSearch = !!hostOnSearch;
162
+ var _useMemo = useMemo(function () {
163
+ var source = rest.options;
164
+ if (!Array.isArray(source)) return {
165
+ options: source,
166
+ truncated: false
167
+ };
168
+ var showRecent = recent.length > 0 && !searchText;
169
+ var recentValues = showRecent ? new Set(recent.map(function (it) {
170
+ return it.value;
171
+ })) : undefined;
172
+ var plain = recentValues ? source.filter(function (it) {
173
+ return !recentValues.has(it.value);
174
+ }) : source;
175
+ var limit = remoteSearch && maxOptions > 0 ? maxOptions : Infinity;
176
+ var cut = plain.length > limit;
177
+ var list = cut ? plain.slice(0, limit) : plain;
178
+ return {
179
+ options: showRecent ? [{
180
+ label: '最近使用',
181
+ options: recent
182
+ }].concat(_toConsumableArray(list)) : list,
183
+ truncated: cut
184
+ };
185
+ }, [rest.options, recent, searchText, remoteSearch, maxOptions]),
186
+ panelOptions = _useMemo.options,
187
+ truncated = _useMemo.truncated;
188
+ var optionRender = codeField ? function (option) {
189
+ var _option$data;
190
+ return /*#__PURE__*/_jsxs("span", {
191
+ className: "qc-dialog-select-option",
192
+ children: [/*#__PURE__*/_jsx("span", {
193
+ className: "qc-dialog-select-option-code",
194
+ children: (_option$data = option.data) === null || _option$data === void 0 ? void 0 : _option$data[codeField]
195
+ }), /*#__PURE__*/_jsx("span", {
196
+ className: "qc-dialog-select-option-name",
197
+ children: option.label
198
+ })]
199
+ });
200
+ } : undefined;
201
+ var hostPopupRender = rest.popupRender;
202
+ var popupRender = truncated ? function (menu) {
203
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
204
+ args[_key - 1] = arguments[_key];
205
+ }
206
+ return /*#__PURE__*/_jsxs(_Fragment, {
207
+ children: [hostPopupRender ? hostPopupRender.apply(void 0, [menu].concat(args)) : menu, /*#__PURE__*/_jsx("div", {
208
+ className: "qc-dialog-select-hint",
209
+ style: {
210
+ padding: '4px 12px',
211
+ fontSize: 12,
212
+ color: token.colorTextTertiary
213
+ },
214
+ children: "\u4EC5\u663E\u793A\u524D ".concat(maxOptions, " \u6761\uFF0C\u7EE7\u7EED\u8F93\u5165\u53EF\u7F29\u5C0F\u8303\u56F4")
215
+ })]
216
+ });
217
+ } : hostPopupRender;
91
218
  var getValue = function getValue(rows) {
92
219
  var row = rows[0];
93
220
  var labelKey = labelField !== null && labelField !== void 0 ? labelField : 'name';
@@ -116,6 +243,12 @@ var DialogSelectInner = function DialogSelectInner(props) {
116
243
  if (dialogIsRowSelectable && rows.some(function (row) {
117
244
  return !dialogIsRowSelectable(row);
118
245
  })) return;
246
+ remember(rows.map(function (row) {
247
+ return _objectSpread({
248
+ value: row[key],
249
+ label: row[labelField !== null && labelField !== void 0 ? labelField : 'name']
250
+ }, codeField ? _defineProperty({}, codeField, row[codeField]) : {});
251
+ }));
119
252
  setState(getValue(rows));
120
253
  close();
121
254
  // 回传完整数据行,供调用方回填关联字段。
@@ -150,14 +283,51 @@ var DialogSelectInner = function DialogSelectInner(props) {
150
283
  '--qc-dialog-select-trigger-color': token.colorTextTertiary,
151
284
  '--qc-dialog-select-trigger-hover': token.colorPrimary
152
285
  };
153
- var commonProps = _objectSpread(_objectSpread({}, rest), {}, {
286
+ var commonProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
287
+ popupMatchSelectWidth: DIALOG_SELECT_MIN_POPUP_WIDTH
288
+ }, rest), panelOptions !== rest.options ? {
289
+ options: panelOptions
290
+ } : {}), optionRender && !rest.optionRender ? {
291
+ optionRender: optionRender
292
+ } : {}), handleSearch ? {
293
+ onSearch: handleSearch
294
+ } : {}), popupRender ? {
295
+ popupRender: popupRender
296
+ } : {}), {}, {
297
+ onSelect: function onSelect(value, option) {
298
+ var _option$value, _rest$onSelect;
299
+ if (recentKey && option) remember([_objectSpread({
300
+ value: (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : value,
301
+ label: option.label
302
+ }, codeField ? _defineProperty({}, codeField, option[codeField]) : {})]);
303
+ (_rest$onSelect = rest.onSelect) === null || _rest$onSelect === void 0 || _rest$onSelect.call(rest, value, option);
304
+ },
305
+ onOpenChange: function onOpenChange(open) {
306
+ var _rest$onOpenChange, _onDropdownVisibleCha, _ref3;
307
+ // 收起后清空检索词,下次展开才会重新展示「最近使用」。
308
+ if (!open) setSearchText('');
309
+ (_rest$onOpenChange = rest.onOpenChange) === null || _rest$onOpenChange === void 0 || _rest$onOpenChange.call(rest, open);
310
+ // antd 6 同时认 onOpenChange 与旧的 onDropdownVisibleChange,这里接管前者,旧回调要手动转发。
311
+ (_onDropdownVisibleCha = (_ref3 = rest).onDropdownVisibleChange) === null || _onDropdownVisibleCha === void 0 || _onDropdownVisibleCha.call(_ref3, open);
312
+ },
313
+ onKeyDown: function onKeyDown(event) {
314
+ var _rest$onKeyDown;
315
+ (_rest$onKeyDown = rest.onKeyDown) === null || _rest$onKeyDown === void 0 || _rest$onKeyDown.call(rest, event);
316
+ // F7 打开选择窗(§6.12);与点放大镜等价。
317
+ if (event.key === 'F7' && canOpen && !event.defaultPrevented) {
318
+ event.preventDefault();
319
+ event.stopPropagation();
320
+ setSelectRows(undefined);
321
+ setTrue();
322
+ }
323
+ },
154
324
  labelRender: displayField === 'value' ? function (item) {
155
325
  return formatSelectDisplay(item, 'value');
156
326
  } : (_rest$labelRender = rest.labelRender) !== null && _rest$labelRender !== void 0 ? _rest$labelRender : function (item) {
157
- var _ref, _selectedLabels$find$, _selectedLabels$find;
158
- return (_ref = (_selectedLabels$find$ = (_selectedLabels$find = selectedLabels.find(function (option) {
327
+ var _ref4, _selectedLabels$find$, _selectedLabels$find;
328
+ return (_ref4 = (_selectedLabels$find$ = (_selectedLabels$find = selectedLabels.find(function (option) {
159
329
  return option.value === item.value;
160
- })) === null || _selectedLabels$find === void 0 ? void 0 : _selectedLabels$find.label) !== null && _selectedLabels$find$ !== void 0 ? _selectedLabels$find$ : item.label) !== null && _ref !== void 0 ? _ref : item.value;
330
+ })) === null || _selectedLabels$find === void 0 ? void 0 : _selectedLabels$find.label) !== null && _selectedLabels$find$ !== void 0 ? _selectedLabels$find$ : item.label) !== null && _ref4 !== void 0 ? _ref4 : item.value;
161
331
  },
162
332
  className: mergedClassName,
163
333
  value: selectedDisplayValue(state, selectedLabels, props.labelInValue),
@@ -200,8 +370,8 @@ var DialogSelectInner = function DialogSelectInner(props) {
200
370
  dataSource: dialogDataSource,
201
371
  hidePagination: localData
202
372
  }, localData ? {
203
- getRowId: function getRowId(_ref2) {
204
- var data = _ref2.data;
373
+ getRowId: function getRowId(_ref5) {
374
+ var data = _ref5.data;
205
375
  return String(data[key]);
206
376
  }
207
377
  } : {}), {}, {
@@ -210,8 +380,8 @@ var DialogSelectInner = function DialogSelectInner(props) {
210
380
  },
211
381
  pageSize: dialogPageSize,
212
382
  pageSizeOptions: dialogPageSizeOptions,
213
- onFirstDataRendered: function onFirstDataRendered(_ref3) {
214
- var api = _ref3.api;
383
+ onFirstDataRendered: function onFirstDataRendered(_ref6) {
384
+ var api = _ref6.api;
215
385
  // 重开弹窗要把已经选中的行勾回来,否则用户会以为之前的选择丢了。
216
386
  // 放在首屏数据渲染完成时做:弹窗是 destroyOnClose,打开的那一刻表格还没有数据。@author nokecy
217
387
  var current = Array.isArray(state) ? state : state == null ? [] : [state];
@@ -233,13 +403,13 @@ var DialogSelectInner = function DialogSelectInner(props) {
233
403
  return !!node.data && dialogIsRowSelectable(node.data);
234
404
  }
235
405
  } : selectionMode === 'multiple' ? 'multiple' : 'single',
236
- onRowDoubleClicked: function onRowDoubleClicked(_ref4) {
237
- var data = _ref4.data;
406
+ onRowDoubleClicked: function onRowDoubleClicked(_ref7) {
407
+ var data = _ref7.data;
238
408
  if (dialogIsRowSelectable && !dialogIsRowSelectable(data)) return;
239
409
  confirmRows([data]);
240
410
  },
241
411
  request: localData ? undefined : ( /*#__PURE__*/function () {
242
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, _, record) {
412
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, _, record) {
243
413
  var adapter, data;
244
414
  return _regeneratorRuntime().wrap(function _callee$(_context) {
245
415
  while (1) switch (_context.prev = _context.next) {
@@ -273,7 +443,7 @@ var DialogSelectInner = function DialogSelectInner(props) {
273
443
  }, _callee);
274
444
  }));
275
445
  return function (_x, _x2, _x3) {
276
- return _ref5.apply(this, arguments);
446
+ return _ref8.apply(this, arguments);
277
447
  };
278
448
  }()),
279
449
  columnDefs: columnDefs
@@ -327,6 +497,10 @@ var DialogSelect = observer(function (props) {
327
497
  dialogIsRowSelectable = safeProps.dialogIsRowSelectable,
328
498
  dialogRenderer = safeProps.dialogRenderer,
329
499
  gridComponent = safeProps.gridComponent,
500
+ codeField = safeProps.codeField,
501
+ searchDebounce = safeProps.searchDebounce,
502
+ maxOptions = safeProps.maxOptions,
503
+ recentKey = safeProps.recentKey,
330
504
  selectProps = _objectWithoutProperties(safeProps, _excluded2);
331
505
  if (displayField === 'value') return /*#__PURE__*/_jsx("span", {
332
506
  children: formatSelectDisplay('value' in safeProps ? safeProps.value : safeProps.defaultValue, 'value') || '—'
@@ -47,3 +47,21 @@
47
47
  padding-inline-end: 38px;
48
48
  }
49
49
  }
50
+
51
+ // 候选面板挂在 body 下,不在 .qc-dialog-select 里,所以写在顶层:「编码 | 名称」两列,编码等宽数字(§6.12)。
52
+ .qc-dialog-select-option {
53
+ display: grid;
54
+ grid-template-columns: minmax(72px, max-content) 1fr;
55
+ column-gap: 12px;
56
+ align-items: center;
57
+
58
+ .qc-dialog-select-option-code {
59
+ font-variant-numeric: tabular-nums;
60
+ }
61
+
62
+ .qc-dialog-select-option-name {
63
+ overflow: hidden;
64
+ text-overflow: ellipsis;
65
+ white-space: nowrap;
66
+ }
67
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
+ import type { LeaveGuardOptions } from './leaveGuard';
2
3
  import type { Form } from '@nokecy/formily-core';
3
4
  /**
4
5
  * 宿主自己的未保存登记(例如接入页签关闭、离开页面的统一拦截)。
@@ -19,13 +20,13 @@ export declare const formatValidationFeedback: (address?: string, title?: unknow
19
20
  * - 传入宿主的 `tracker` 时由它记录未保存状态(例如统一拦截关页签);不传时只在本页记录。
20
21
  * @author nokecy
21
22
  */
22
- export declare const useDocumentEditState: (tracker?: DocumentDirtyTracker) => {
23
+ export declare const useDocumentEditState: (tracker?: DocumentDirtyTracker, leaveOptions?: LeaveGuardOptions) => {
23
24
  dirty: boolean;
24
25
  markDirty: (form?: Form) => void;
25
26
  markClean: () => void;
26
27
  changed: import("react").RefObject<boolean>;
27
28
  markChanged: () => void;
28
- guardDiscard: (action: '返回' | '刷新' | '离开', proceed: () => void) => void;
29
+ guardDiscard: (_action: '返回' | '刷新' | '离开', proceed: () => void) => void;
29
30
  };
30
31
  /**
31
32
  * 单据动作忙态:同一时刻只执行一个动作,只有被点的按钮转圈,其余互斥动作禁用(§5.3)。
@@ -68,9 +69,11 @@ export declare const pickPrimaryAction: <K extends string>(candidates: [K, boole
68
69
  */
69
70
  export declare const validateBeforeConfirm: (validate?: () => Promise<unknown>, context?: {
70
71
  /** 携带实际表单以显示出错字段标题和明细行号。@author nokecy */
71
- form?: Pick<Form<any>, "queryFeedbacks" | "query"> | undefined;
72
+ form?: Pick<Form<any>, "query" | "queryFeedbacks"> | undefined;
72
73
  /** 校验失败后展开编辑入口或定位字段,不执行保存和提交。@author nokecy */
73
74
  onInvalid?: ((address?: string) => void) | undefined;
75
+ /** 校验失败后切到错误页签、展开折叠并聚焦首个错误字段(§6.4),默认 false,提示仍用本函数的文案。 */
76
+ locate?: boolean | undefined;
74
77
  /** 自定义提示文字;默认「第 N 行 · 字段原因」或「「字段」原因」。 */
75
78
  formatFeedback?: ((address: string | undefined, title: unknown, reason: string) => string) | undefined;
76
79
  } | undefined) => Promise<boolean>;
@@ -2,6 +2,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
2
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
10
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
11
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
12
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -10,6 +15,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
10
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
16
  import { Modal, message } from 'antd';
12
17
  import { useCallback, useRef, useState } from 'react';
18
+ import { confirmDiscardChanges, useLeaveGuard } from "./leaveGuard";
19
+ import { focusFirstError } from '@nokecy/formily-antd';
13
20
 
14
21
  /**
15
22
  * 宿主自己的未保存登记(例如接入页签关闭、离开页面的统一拦截)。
@@ -35,7 +42,7 @@ export var formatValidationFeedback = function formatValidationFeedback(address,
35
42
  * - 传入宿主的 `tracker` 时由它记录未保存状态(例如统一拦截关页签);不传时只在本页记录。
36
43
  * @author nokecy
37
44
  */
38
- export var useDocumentEditState = function useDocumentEditState(tracker) {
45
+ export var useDocumentEditState = function useDocumentEditState(tracker, leaveOptions) {
39
46
  var _useState = useState(false),
40
47
  _useState2 = _slicedToArray(_useState, 2),
41
48
  localDirty = _useState2[0],
@@ -53,13 +60,18 @@ export var useDocumentEditState = function useDocumentEditState(tracker) {
53
60
  var markChanged = useCallback(function () {
54
61
  changed.current = true;
55
62
  }, []);
56
- /** 返回、刷新等会丢弃录入的动作:有未保存修改先确认。 */
57
- var guardDiscard = function guardDiscard(action, proceed) {
63
+ // 传了宿主登记时,离开拦截由宿主统一负责,本页不再重复注册 beforeunload,除非显式开启。
64
+ useLeaveGuard(dirty, _objectSpread({
65
+ beforeUnload: !tracker
66
+ }, leaveOptions));
67
+ /**
68
+ * 返回、刷新等会丢弃录入的动作:有未保存修改先确认(文案「有未保存的修改,离开后将丢失」,
69
+ * 按钮「继续编辑 / 放弃修改」,§6.8)。`action` 仅为保持调用签名,不再进入文案。
70
+ */
71
+ var guardDiscard = function guardDiscard(_action, proceed) {
58
72
  if (!dirty) return proceed();
59
- Modal.confirm({
60
- title: "\u786E\u8BA4".concat(action),
61
- content: '未保存的修改将丢失。',
62
- onOk: proceed
73
+ void confirmDiscardChanges().then(function (ok) {
74
+ return ok && proceed();
63
75
  });
64
76
  };
65
77
  return {
@@ -242,8 +254,11 @@ export var validateBeforeConfirm = /*#__PURE__*/function () {
242
254
  validation = _context3.t0; // 阅读态字段可能不进入 Formily 的错误数组,仍保留业务校验给出的具体原因。@author nokecy
243
255
  message.error(typeof _reason === 'string' && _reason.trim() ? ((_context$formatFeedba = context === null || context === void 0 ? void 0 : context.formatFeedback) !== null && _context$formatFeedba !== void 0 ? _context$formatFeedba : formatValidationFeedback)(_address, field === null || field === void 0 ? void 0 : field.title, _reason) : (validation === null || validation === void 0 ? void 0 : validation.name) === 'ValidateError' && (_validation$message = validation.message) !== null && _validation$message !== void 0 && _validation$message.trim() ? validation.message : '表单校验未通过,请检查填写内容');
244
256
  context === null || context === void 0 || (_context$onInvalid = context.onInvalid) === null || _context$onInvalid === void 0 || _context$onInvalid.call(context, _address);
257
+ if (context !== null && context !== void 0 && context.locate && context.form) void focusFirstError(context.form, {
258
+ notify: false
259
+ });
245
260
  return _context3.abrupt("return", false);
246
- case 18:
261
+ case 19:
247
262
  case "end":
248
263
  return _context3.stop();
249
264
  }
@@ -15,6 +15,8 @@ export { formatDocumentTime, latestDocumentAuditStep, normalizeDocumentAuditStep
15
15
  export type { DocumentAuditStep } from './documentAudit';
16
16
  export { confirmDocumentAction, formatValidationFeedback, pickPrimaryAction, reloadAfterAction, submitButtonLabel, useDocumentActions, useDocumentEditState, validateBeforeConfirm, warnSavedButActionFailed, } from './documentPage';
17
17
  export type { DocumentDirtyTracker } from './documentPage';
18
+ export { LEAVE_GUARD_TEXT, confirmDiscardChanges, useLeaveGuard } from './leaveGuard';
19
+ export type { LeaveGuardOptions, RouteBlocker } from './leaveGuard';
18
20
  export { useHeaderItemToggleGrid } from './useHeaderItemToggleGrid';
19
21
  export type { HeaderItemModeLabels, HeaderItemReadScope, HeaderItemViewMode, UseHeaderItemToggleGridOptions } from './useHeaderItemToggleGrid';
20
22
  export { createHeaderItemGetRowId, getHeaderItemRowId } from './headerItemRowId';