@nokecy/qc-ui 1.1.87 → 1.1.89

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 (98) hide show
  1. package/dist/cjs/ag-grid-plus/ag-gridPlus.js +151 -145
  2. package/dist/cjs/ag-grid-plus/context/useSchemeDataFlow.js +4 -4
  3. package/dist/cjs/ag-grid-plus/interface.d.ts +8 -0
  4. package/dist/cjs/ag-grid-plus/queryForm/index.d.ts +4 -0
  5. package/dist/cjs/ag-grid-plus/queryForm/index.js +63 -53
  6. package/dist/cjs/ag-grid-plus/queryForm/queryColumns.d.ts +8 -0
  7. package/dist/cjs/ag-grid-plus/queryForm/queryColumns.js +52 -0
  8. package/dist/cjs/ag-grid-plus/queryForm/schemaKey.d.ts +15 -8
  9. package/dist/cjs/ag-grid-plus/queryForm/schemaKey.js +64 -12
  10. package/dist/cjs/ag-grid-plus/setting/ColumnConfigForm.js +3 -0
  11. package/dist/cjs/ag-grid-plus/setting/ColumnSetting.js +69 -106
  12. package/dist/cjs/ag-grid-plus/setting/QuerySchemeManager.js +3 -1
  13. package/dist/cjs/ag-grid-plus/setting/columnGroupTypes.d.ts +2 -0
  14. package/dist/cjs/ag-grid-plus/setting/columnGroupUtils.d.ts +14 -0
  15. package/dist/cjs/ag-grid-plus/setting/columnGroupUtils.js +98 -110
  16. package/dist/cjs/ag-grid-plus/types.d.ts +6 -0
  17. package/dist/cjs/array-table/batchRemove.d.ts +36 -0
  18. package/dist/cjs/array-table/batchRemove.js +299 -0
  19. package/dist/cjs/array-table/cellFocusScope.js +44 -8
  20. package/dist/cjs/array-table/cellInteractionLock.d.ts +13 -0
  21. package/dist/cjs/array-table/cellInteractionLock.js +26 -0
  22. package/dist/cjs/array-table/hooks.d.ts +11 -6
  23. package/dist/cjs/array-table/hooks.js +138 -88
  24. package/dist/cjs/array-table/index.d.ts +8 -2
  25. package/dist/cjs/array-table/index.js +55 -32
  26. package/dist/cjs/array-table/indexColumn.d.ts +1 -1
  27. package/dist/cjs/array-table/indexColumn.js +3 -2
  28. package/dist/cjs/array-table/interface.d.ts +13 -1
  29. package/dist/cjs/array-table/preview.js +8 -0
  30. package/dist/cjs/array-table/readOnlyFormatters.d.ts +9 -1
  31. package/dist/cjs/array-table/readOnlyFormatters.js +41 -13
  32. package/dist/cjs/array-table/rowIdentity.d.ts +17 -0
  33. package/dist/cjs/array-table/rowIdentity.js +43 -0
  34. package/dist/cjs/array-table/sorting.d.ts +3 -0
  35. package/dist/cjs/array-table/sorting.js +46 -0
  36. package/dist/cjs/array-table/utils.js +146 -67
  37. package/dist/cjs/dialogSelect/index.d.ts +3 -0
  38. package/dist/cjs/dialogSelect/index.js +13 -3
  39. package/dist/cjs/editable/index.js +101 -139
  40. package/dist/cjs/index.d.ts +2 -2
  41. package/dist/cjs/index.js +14 -0
  42. package/dist/cjs/readPretty/arrayTable.js +29 -14
  43. package/dist/cjs/readPretty/formily.d.ts +1 -0
  44. package/dist/cjs/readPretty/formily.js +7 -0
  45. package/dist/cjs/readPretty/index.d.ts +1 -0
  46. package/dist/cjs/readPretty/index.js +7 -0
  47. package/dist/cjs/readPretty/schemaScope.d.ts +2 -0
  48. package/dist/cjs/readPretty/schemaScope.js +49 -0
  49. package/dist/esm/ag-grid-plus/ag-gridPlus.js +151 -145
  50. package/dist/esm/ag-grid-plus/context/useSchemeDataFlow.js +4 -4
  51. package/dist/esm/ag-grid-plus/interface.d.ts +8 -0
  52. package/dist/esm/ag-grid-plus/queryForm/index.d.ts +4 -0
  53. package/dist/esm/ag-grid-plus/queryForm/index.js +64 -55
  54. package/dist/esm/ag-grid-plus/queryForm/queryColumns.d.ts +8 -0
  55. package/dist/esm/ag-grid-plus/queryForm/queryColumns.js +46 -0
  56. package/dist/esm/ag-grid-plus/queryForm/schemaKey.d.ts +15 -8
  57. package/dist/esm/ag-grid-plus/queryForm/schemaKey.js +64 -12
  58. package/dist/esm/ag-grid-plus/setting/ColumnConfigForm.js +3 -0
  59. package/dist/esm/ag-grid-plus/setting/ColumnSetting.js +70 -107
  60. package/dist/esm/ag-grid-plus/setting/QuerySchemeManager.js +3 -1
  61. package/dist/esm/ag-grid-plus/setting/columnGroupTypes.d.ts +2 -0
  62. package/dist/esm/ag-grid-plus/setting/columnGroupUtils.d.ts +14 -0
  63. package/dist/esm/ag-grid-plus/setting/columnGroupUtils.js +95 -110
  64. package/dist/esm/ag-grid-plus/types.d.ts +6 -0
  65. package/dist/esm/array-table/batchRemove.d.ts +36 -0
  66. package/dist/esm/array-table/batchRemove.js +289 -0
  67. package/dist/esm/array-table/cellFocusScope.js +45 -9
  68. package/dist/esm/array-table/cellInteractionLock.d.ts +13 -0
  69. package/dist/esm/array-table/cellInteractionLock.js +21 -0
  70. package/dist/esm/array-table/hooks.d.ts +11 -6
  71. package/dist/esm/array-table/hooks.js +139 -89
  72. package/dist/esm/array-table/index.d.ts +8 -2
  73. package/dist/esm/array-table/index.js +55 -32
  74. package/dist/esm/array-table/indexColumn.d.ts +1 -1
  75. package/dist/esm/array-table/indexColumn.js +3 -2
  76. package/dist/esm/array-table/interface.d.ts +13 -1
  77. package/dist/esm/array-table/preview.js +8 -0
  78. package/dist/esm/array-table/readOnlyFormatters.d.ts +9 -1
  79. package/dist/esm/array-table/readOnlyFormatters.js +41 -12
  80. package/dist/esm/array-table/rowIdentity.d.ts +17 -0
  81. package/dist/esm/array-table/rowIdentity.js +37 -0
  82. package/dist/esm/array-table/sorting.d.ts +3 -0
  83. package/dist/esm/array-table/sorting.js +40 -0
  84. package/dist/esm/array-table/utils.js +147 -68
  85. package/dist/esm/dialogSelect/index.d.ts +3 -0
  86. package/dist/esm/dialogSelect/index.js +13 -3
  87. package/dist/esm/editable/index.js +102 -140
  88. package/dist/esm/index.d.ts +2 -2
  89. package/dist/esm/index.js +1 -1
  90. package/dist/esm/readPretty/arrayTable.js +30 -13
  91. package/dist/esm/readPretty/formily.d.ts +1 -0
  92. package/dist/esm/readPretty/formily.js +1 -0
  93. package/dist/esm/readPretty/index.d.ts +1 -0
  94. package/dist/esm/readPretty/index.js +1 -0
  95. package/dist/esm/readPretty/schemaScope.d.ts +2 -0
  96. package/dist/esm/readPretty/schemaScope.js +42 -0
  97. package/dist/umd/qc-ui.min.js +1 -1
  98. package/package.json +1 -1
@@ -2,10 +2,13 @@ import { SelectProps } from 'antd/lib/select';
2
2
  import React from 'react';
3
3
  import { ColDef, ColGroupDef } from 'ag-grid-community';
4
4
  import type { PagedApiAdapter } from '../adapters';
5
+ import type { SelectDisplayField } from '../array-table/readOnlyFormatters';
5
6
  import './index.less';
6
7
  /** 选择窗口的行选择模式。 */
7
8
  type DialogSelectionMode = 'single' | 'multiple';
8
9
  interface IDialogSelectProps extends SelectProps<any> {
10
+ /** 回显编码或名称,保持原始 value/label 和联动回调不变。@author nokecy */
11
+ displayField?: SelectDisplayField;
9
12
  /** 隐藏选择窗口入口(输入框内的后缀图标),只保留输入与下拉。 */
10
13
  hideBtn?: boolean;
11
14
  request?: any;
@@ -1,5 +1,5 @@
1
- var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"],
2
- _excluded2 = ["request", "columnDefs", "labelField", "valueField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"];
1
+ var _excluded = ["request", "columnDefs", "value", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"],
2
+ _excluded2 = ["request", "columnDefs", "labelField", "valueField", "displayField", "onChangeItem", "hideBtn", "useAutoComplete", "queryFun", "pagedApiAdapter", "modalWidth", "dialogZIndex", "dialogMode", "dialogPageSize", "dialogPageSizeOptions", "dialogGridKey", "dialogDataSource", "dialogIsRowSelectable", "dialogRenderer", "gridComponent"];
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); }); }; }
@@ -29,6 +29,8 @@ import DraggableModal from "../draggableModal";
29
29
  import { abpPagedApiAdapter } from "../adapters";
30
30
  import { Select as ReadingSelect } from "../readPretty/controls";
31
31
  import { normalizeSelectValue } from "../readPretty/selectValue";
32
+ import { formatSelectDisplay } from "../array-table/readOnlyFormatters";
33
+ import { useCellInteractionLock } from "../array-table/cellInteractionLock";
32
34
  import "./index.less";
33
35
 
34
36
  /** 选择窗口的行选择模式。 */
@@ -41,6 +43,7 @@ var DialogSelectInner = function DialogSelectInner(props) {
41
43
  value = props.value,
42
44
  labelField = props.labelField,
43
45
  valueField = props.valueField,
46
+ displayField = props.displayField,
44
47
  onChangeItem = props.onChangeItem,
45
48
  hideBtn = props.hideBtn,
46
49
  useAutoComplete = props.useAutoComplete,
@@ -70,6 +73,7 @@ var DialogSelectInner = function DialogSelectInner(props) {
70
73
  _useBoolean2$ = _useBoolean2[1],
71
74
  setTrue = _useBoolean2$.setTrue,
72
75
  setFalse = _useBoolean2$.setFalse;
76
+ useCellInteractionLock(visible);
73
77
  var _useState = useState(undefined),
74
78
  _useState2 = _slicedToArray(_useState, 2),
75
79
  selectRows = _useState2[0],
@@ -141,7 +145,11 @@ var DialogSelectInner = function DialogSelectInner(props) {
141
145
  '--qc-dialog-select-trigger-color': token.colorTextTertiary,
142
146
  '--qc-dialog-select-trigger-hover': token.colorPrimary
143
147
  };
144
- var commonProps = _objectSpread(_objectSpread({}, rest), {}, {
148
+ var commonProps = _objectSpread(_objectSpread(_objectSpread({}, rest), displayField === 'value' ? {
149
+ labelRender: function labelRender(item) {
150
+ return formatSelectDisplay(item, 'value');
151
+ }
152
+ } : {}), {}, {
145
153
  className: mergedClassName,
146
154
  value: state,
147
155
  style: _objectSpread(_objectSpread({}, triggerStyle), rest.style || {})
@@ -281,6 +289,7 @@ var DialogSelect = observer(function (props) {
281
289
  columnDefs = safeProps.columnDefs,
282
290
  labelField = safeProps.labelField,
283
291
  valueField = safeProps.valueField,
292
+ displayField = safeProps.displayField,
284
293
  onChangeItem = safeProps.onChangeItem,
285
294
  hideBtn = safeProps.hideBtn,
286
295
  useAutoComplete = safeProps.useAutoComplete,
@@ -297,6 +306,7 @@ var DialogSelect = observer(function (props) {
297
306
  dialogRenderer = safeProps.dialogRenderer,
298
307
  gridComponent = safeProps.gridComponent,
299
308
  selectProps = _objectWithoutProperties(safeProps, _excluded2);
309
+ if (displayField === 'value') return /*#__PURE__*/React.createElement("span", null, formatSelectDisplay('value' in safeProps ? safeProps.value : safeProps.defaultValue, 'value') || '—');
300
310
  return /*#__PURE__*/React.createElement(ReadingSelect, _extends({}, selectProps, {
301
311
  disabled: true
302
312
  }));
@@ -1,6 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
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; }
5
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); } }
6
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); }); }; }
@@ -17,8 +16,9 @@ import { Popover as AntdPopover } from 'antd';
17
16
  import cls from 'classnames';
18
17
  import { FormItem } from '@formily/antd-v5';
19
18
  import { ArrayBase } from "../array-table/arrayBase";
19
+ import { CellFocusScope } from "../array-table/cellFocusScope";
20
20
  import React, { useLayoutEffect, useRef, useState } from 'react';
21
- import { useClickAway, usePrefixCls } from '@formily/antd-v5/lib/__builtins__';
21
+ import { usePrefixCls } from '@formily/antd-v5/lib/__builtins__';
22
22
  import useStyle from "./style";
23
23
  var useParentPattern = function useParentPattern() {
24
24
  var _field$parent, _field$form;
@@ -83,7 +83,6 @@ var InternalEditable = observer(function (props) {
83
83
  var pattern = useParentPattern();
84
84
  var itemProps = useFormItemProps();
85
85
  var field = useField();
86
- var basePrefixCls = usePrefixCls();
87
86
  var prefixCls = usePrefixCls('formily-editable');
88
87
  var _useStyle = useStyle(prefixCls),
89
88
  _useStyle2 = _slicedToArray(_useStyle, 2),
@@ -91,175 +90,138 @@ var InternalEditable = observer(function (props) {
91
90
  hashId = _useStyle2[1];
92
91
  var ref = useRef();
93
92
  var innerRef = useRef(null);
93
+ var focusRequestRef = useRef(false);
94
+ var focusGenerationRef = useRef(0);
95
+ var focusTimerRef = useRef();
94
96
 
95
- // 通用的聚焦函数
96
- var focusInput = React.useCallback(function () {
97
- var _innerRef$current;
98
- var input = (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.querySelector('input:not([readonly]):not([disabled]), textarea:not([readonly]):not([disabled])');
99
- if (input) {
100
- input.focus();
101
- // setSelectionRange 仅 textarea 与 text/search/url/tel/password 类型 input 支持;
102
- // checkbox/number/date 等会抛 InvalidStateError,故用白名单守卫。@author nokecy
103
- if (input.tagName === 'TEXTAREA' || /^(text|search|url|tel|password)$/i.test(input.type || 'text')) {
104
- var _input$value;
105
- var length = ((_input$value = input.value) === null || _input$value === void 0 ? void 0 : _input$value.length) || 0;
106
- setTimeout(function () {
107
- input.setSelectionRange(length, length);
108
- }, 10);
109
- }
110
- return true;
111
- }
112
- return false;
97
+ /** 离开或重新进入时作废旧聚焦任务,同时保护仍在等待的异步校验。@author nokecy */
98
+ var cancelFocusRequest = React.useCallback(function () {
99
+ focusGenerationRef.current += 1;
100
+ focusRequestRef.current = false;
101
+ clearTimeout(focusTimerRef.current);
113
102
  }, []);
103
+ var activate = function activate() {
104
+ if (ref.current || pattern !== 'editable') return;
105
+ cancelFocusRequest();
106
+ focusRequestRef.current = true;
107
+ ref.current = true;
108
+ setEditable(true);
109
+ };
114
110
 
115
- // 重试聚焦函数
116
- var retryFocus = React.useCallback(function () {
117
- if (!focusInput()) {
118
- setTimeout(function () {
119
- if (!focusInput()) {
120
- setTimeout(focusInput, 50);
121
- }
122
- }, 50);
123
- }
124
- }, [focusInput]);
111
+ /** 与懒挂载单元格共用离开规则:保留错误,且旧校验不能收起已重新进入的字段。@author nokecy */
125
112
  var recover = /*#__PURE__*/function () {
126
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
127
- var _field$errors;
128
- var errors;
113
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(isStale) {
114
+ var hadFocus,
115
+ generation,
116
+ _args = arguments;
129
117
  return _regeneratorRuntime().wrap(function _callee$(_context) {
130
118
  while (1) switch (_context.prev = _context.next) {
131
119
  case 0:
132
- if (!(editable && !(field !== null && field !== void 0 && (_field$errors = field.errors) !== null && _field$errors !== void 0 && _field$errors.length))) {
133
- _context.next = 10;
120
+ hadFocus = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
121
+ cancelFocusRequest();
122
+ generation = focusGenerationRef.current;
123
+ if (!(!ref.current || pattern !== 'editable')) {
124
+ _context.next = 5;
134
125
  break;
135
126
  }
136
- _context.prev = 1;
137
- _context.next = 4;
138
- return field.form.validate("".concat(field.path));
139
- case 4:
140
- _context.prev = 4;
141
- errors = field.form.queryFeedbacks({
142
- type: 'error',
143
- address: "".concat(field.address)
144
- });
145
- if (!(errors !== null && errors !== void 0 && errors.length)) {
146
- _context.next = 8;
127
+ return _context.abrupt("return");
128
+ case 5:
129
+ if (!(!hadFocus && isDeepEmpty(field.value))) {
130
+ _context.next = 7;
147
131
  break;
148
132
  }
149
133
  return _context.abrupt("return");
150
- case 8:
151
- if (ref.current && !(errors !== null && errors !== void 0 && errors.length)) {
152
- setEditable(false);
153
- }
154
- return _context.finish(4);
134
+ case 7:
135
+ _context.prev = 7;
136
+ _context.next = 10;
137
+ return field.validate();
155
138
  case 10:
139
+ _context.next = 15;
140
+ break;
141
+ case 12:
142
+ _context.prev = 12;
143
+ _context.t0 = _context["catch"](7);
144
+ return _context.abrupt("return");
145
+ case 15:
146
+ if (!(isStale() || generation !== focusGenerationRef.current || !ref.current || field.errors.length)) {
147
+ _context.next = 17;
148
+ break;
149
+ }
150
+ return _context.abrupt("return");
151
+ case 17:
152
+ setEditable(false);
153
+ case 18:
156
154
  case "end":
157
155
  return _context.stop();
158
156
  }
159
- }, _callee, null, [[1,, 4, 10]]);
157
+ }, _callee, null, [[7, 12]]);
160
158
  }));
161
- return function recover() {
159
+ return function recover(_x) {
162
160
  return _ref.apply(this, arguments);
163
161
  };
164
162
  }();
165
- useClickAway(function (e) {
166
- var _innerRef$current2;
167
- var target = e.target;
168
- if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-select-dropdown"))) return;
169
- if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-picker-dropdown"))) return;
170
- if (target !== null && target !== void 0 && target.closest(".".concat(basePrefixCls, "-cascader-menus"))) return;
171
163
 
172
- // 检查是否点击的是当前组件内的输入框或相关元素
173
- var inputElements = (_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : _innerRef$current2.querySelectorAll('input, textarea, .ant-input, .ant-input-wrapper');
174
- if (inputElements) {
175
- //@ts-ignore
176
- var _iterator = _createForOfIteratorHelper(inputElements),
177
- _step;
178
- try {
179
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
180
- var input = _step.value;
181
- if (target === input || input.contains(target) || target.closest('.ant-input-wrapper')) {
182
- return; // 不触发recover
183
- }
184
- }
185
- } catch (err) {
186
- _iterator.e(err);
187
- } finally {
188
- _iterator.f();
189
- }
190
- }
191
- recover();
192
- }, innerRef);
193
- var onClick = function onClick(e) {
194
- var _innerRef$current3;
195
- var target = e.target;
196
- var close = ((_innerRef$current3 = innerRef.current) === null || _innerRef$current3 === void 0 ? void 0 : _innerRef$current3.querySelector(".".concat(prefixCls, "-close-btn"))) || null;
197
- if (target !== null && target !== void 0 && target.contains(close) || close !== null && close !== void 0 && close.contains(target)) {
198
- recover();
199
- } else if (!ref.current) {
200
- // 只有在非编辑状态时才触发编辑状态
201
- setTimeout(function () {
202
- setEditable(true);
203
- setTimeout(retryFocus, 100);
204
- });
205
- } else {
206
- // 如果已经处于编辑状态,检查点击的是否是输入框或其相关元素
207
- var isInputElement = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
208
- var isInputRelated = target.closest('input, textarea, .ant-input, .ant-input-wrapper');
209
- if (isInputElement || isInputRelated) {
210
- // 如果点击的是输入框或相关元素,不做任何操作,让输入框自己处理焦点
211
- e.stopPropagation();
212
- return;
213
- }
214
- // 如果点击的是其他区域且已经处于编辑状态,也不做任何操作(保持编辑状态)
164
+ // 输入节点在本次提交后即可聚焦;少数延迟挂载组件允许短暂重试,离开和卸载会取消任务。
165
+ // 不延迟改写光标,避免用户已经切格或选中文字后再抢回焦点。@author nokecy
166
+ useLayoutEffect(function () {
167
+ if (!editable || pattern !== 'editable') {
168
+ cancelFocusRequest();
169
+ return;
215
170
  }
216
- };
217
-
218
- // 监听键盘导航事件,自动进入编辑状态
219
- React.useEffect(function () {
220
- var handleKeyDown = function handleKeyDown(e) {
221
- if (e.key === 'Enter' || e.key === 'F2') {
222
- if (!editable && pattern === 'editable') {
223
- e.preventDefault();
224
- setEditable(true);
225
- setTimeout(retryFocus, 100);
171
+ if (!focusRequestRef.current) return;
172
+ var generation = focusGenerationRef.current;
173
+ var focusInput = function focusInput() {
174
+ var attempt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
175
+ var root = innerRef.current;
176
+ if (generation !== focusGenerationRef.current || !focusRequestRef.current || !(root !== null && root !== void 0 && root.isConnected)) return;
177
+ var input = root.querySelector('input:not([readonly]):not([disabled]), textarea:not([readonly]):not([disabled])');
178
+ if (input) {
179
+ focusRequestRef.current = false;
180
+ if (document.activeElement === input) return;
181
+ input.focus();
182
+ if (!input.closest('.ant-picker') && (input.tagName === 'TEXTAREA' || /^(text|search|url|tel|password)$/i.test(input.type || 'text'))) {
183
+ var _input$value;
184
+ var length = ((_input$value = input.value) === null || _input$value === void 0 ? void 0 : _input$value.length) || 0;
185
+ input.setSelectionRange(length, length);
226
186
  }
187
+ } else if (attempt < 2) {
188
+ focusTimerRef.current = setTimeout(function () {
189
+ return focusInput(attempt + 1);
190
+ }, 50);
227
191
  }
228
192
  };
229
- var element = innerRef.current;
230
- if (element) {
231
- element.addEventListener('keydown', handleKeyDown);
232
- return function () {
233
- element.removeEventListener('keydown', handleKeyDown);
234
- };
235
- }
236
- }, [editable, pattern, setEditable, retryFocus]);
237
-
238
- // 当组件获得焦点时自动进入编辑状态
193
+ focusInput();
194
+ }, [editable, pattern, cancelFocusRequest]);
239
195
  React.useEffect(function () {
240
- var handleFocus = function handleFocus() {
241
- if (!editable && pattern === 'editable') {
242
- setEditable(true);
243
- setTimeout(retryFocus, 100);
244
- }
245
- };
246
- var element = innerRef.current;
247
- if (element) {
248
- element.addEventListener('focus', handleFocus, true);
249
- return function () {
250
- element.removeEventListener('focus', handleFocus, true);
251
- };
252
- }
253
- }, [editable, pattern, setEditable, retryFocus]);
196
+ return cancelFocusRequest;
197
+ }, [cancelFocusRequest]);
254
198
  ref.current = editable;
255
- return wrapSSR( /*#__PURE__*/React.createElement("div", {
199
+ return wrapSSR( /*#__PURE__*/React.createElement(CellFocusScope, {
200
+ onLeave: recover
201
+ }, /*#__PURE__*/React.createElement("div", {
256
202
  className: cls(prefixCls, hashId),
257
203
  ref: innerRef,
258
- onClick: onClick,
204
+ onClick: function onClick(event) {
205
+ var target = event.target;
206
+ if (target.closest(".".concat(prefixCls, "-close-btn"))) void recover(function () {
207
+ return false;
208
+ });else activate();
209
+ },
210
+ onFocusCapture: function onFocusCapture() {
211
+ cancelFocusRequest();
212
+ activate();
213
+ },
214
+ onBlurCapture: cancelFocusRequest,
215
+ onKeyDown: function onKeyDown(event) {
216
+ if (!ref.current && (event.key === 'Enter' || event.key === 'F2')) {
217
+ event.preventDefault();
218
+ activate();
219
+ }
220
+ },
259
221
  "data-editable-state": editable ? 'editing' : 'readonly'
260
222
  }, /*#__PURE__*/React.createElement("div", {
261
223
  className: "".concat(prefixCls, "-content")
262
- }, /*#__PURE__*/React.createElement(FormItem.BaseItem, _extends({}, props, itemProps), props.children))));
224
+ }, /*#__PURE__*/React.createElement(FormItem.BaseItem, _extends({}, props, itemProps), props.children)))));
263
225
  });
264
226
  var Popover = observer(function (props) {
265
227
  var field = useField();
@@ -29,8 +29,8 @@ export type * from "./importModal";
29
29
  export type * from "./fullScreenAlert";
30
30
  export type * from "./RuleBuilder";
31
31
  export type { ColumnConfig } from "./array-table/columnHelper";
32
- export { registerReadOnlyFormatter, registerReadOnlyLabels, registerReadOnlyRenderer } from "./array-table/readOnlyFormatters";
33
- export type { ReadOnlyFormatter, ReadOnlyFormatterCtx, ReadOnlyLabels, ReadOnlyRenderer } from "./array-table/readOnlyFormatters";
32
+ export { registerReadOnlyFormatter, registerReadOnlyLabels, registerReadOnlyRenderer, withReadOnlyFormatter, formatSelectDisplay } from "./array-table/readOnlyFormatters";
33
+ export type { ReadOnlyFormatter, ReadOnlyFormatterCtx, ReadOnlyLabels, ReadOnlyRenderer, SelectDisplayField } from "./array-table/readOnlyFormatters";
34
34
  export type { CentralizedColumnScheme, QueryScheme, SchemeStorageAdapter, SchemeSyncDataDto, CurrentSchemeDto, SchemeStorageConfig, LocalStorageAdapterConfig, BackendApiAdapterConfig, UseSchemeManagerConfig, GridPlusContextValue, GlobalConfigPermissions, } from "./ag-grid-plus";
35
35
  export * from './adapters';
36
36
  export * from "./readPretty";
package/dist/esm/index.js CHANGED
@@ -36,7 +36,7 @@ useSchemeManager, useGridSchemes, LocalStorageSchemeAdapter, BackendApiSchemeAda
36
36
  // 导出类型定义
37
37
 
38
38
  // ArrayTable 格子文本:业务自定义组件登记「值 -> 名称」或自定义格式化器
39
- export { registerReadOnlyFormatter, registerReadOnlyLabels, registerReadOnlyRenderer } from "./array-table/readOnlyFormatters";
39
+ export { registerReadOnlyFormatter, registerReadOnlyLabels, registerReadOnlyRenderer, withReadOnlyFormatter, formatSelectDisplay } from "./array-table/readOnlyFormatters";
40
40
 
41
41
  // 集中式方案管理类型
42
42
 
@@ -1,6 +1,12 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
3
  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); }
3
4
  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; }
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); }
4
10
  import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
5
11
  import { AgGridReact } from 'ag-grid-react';
6
12
  import { buildArrayTableColumns, useArrayTableSources } from "../array-table/utils";
@@ -9,10 +15,22 @@ import { ARRAY_TABLE_INDEX_FIELD, hasOwnIndexColumn, makeIndexColumn } from "../
9
15
  import { ARRAY_TABLE_ROW_HEIGHT, useArrayTableTheme } from "../array-table/theme";
10
16
  import { hoistStatics } from "./hoistStatics";
11
17
  import React, { useMemo, useRef } from 'react';
18
+
12
19
  /** 阅读态直接使用 ArrayTable 的列定义,避免 AgGridPlus 的原值渲染器覆盖格式化结果。@author nokecy */
20
+
13
21
  var ReadingArrayTable = observer(function (_ref) {
14
22
  var _buildArrayTableColum;
15
- var height = _ref.height;
23
+ var height = _ref.height,
24
+ _ref$rowSelection = _ref.rowSelection,
25
+ rowSelection = _ref$rowSelection === void 0 ? {
26
+ mode: 'singleRow',
27
+ enableClickSelection: true,
28
+ checkboxes: false
29
+ } : _ref$rowSelection,
30
+ selectionColumnDef = _ref.selectionColumnDef,
31
+ onSelectionChanged = _ref.onSelectionChanged,
32
+ onGridReady = _ref.onGridReady,
33
+ _onRowDataUpdated = _ref.onRowDataUpdated;
16
34
  var field = useField();
17
35
  var sources = useArrayTableSources();
18
36
  var rows = Array.isArray(field.value) ? field.value.slice() : [];
@@ -36,16 +54,15 @@ var ReadingArrayTable = observer(function (_ref) {
36
54
  sortable: true,
37
55
  filter: true
38
56
  },
39
- rowSelection: {
40
- mode: 'singleRow',
41
- enableClickSelection: true
42
- },
43
- selectionColumnDef: {
57
+ rowSelection: rowSelection,
58
+ selectionColumnDef: _objectSpread({
44
59
  pinned: 'left',
45
60
  lockPosition: true,
46
61
  width: 50,
47
62
  suppressHeaderMenuButton: true
48
- },
63
+ }, selectionColumnDef),
64
+ onSelectionChanged: onSelectionChanged,
65
+ onGridReady: onGridReady,
49
66
  columnDefs: groupColumnDefs(columns),
50
67
  rowData: rows,
51
68
  getRowId: function getRowId(_ref2) {
@@ -64,12 +81,12 @@ var ReadingArrayTable = observer(function (_ref) {
64
81
  }
65
82
  return rowId;
66
83
  },
67
- onRowDataUpdated: function onRowDataUpdated(_ref3) {
68
- var api = _ref3.api;
69
- if (showIndex) api.refreshCells({
84
+ onRowDataUpdated: function onRowDataUpdated(event) {
85
+ if (showIndex) event.api.refreshCells({
70
86
  columns: [ARRAY_TABLE_INDEX_FIELD],
71
87
  force: true
72
88
  });
89
+ _onRowDataUpdated === null || _onRowDataUpdated === void 0 || _onRowDataUpdated(event);
73
90
  }
74
91
  }));
75
92
  });
@@ -100,9 +117,9 @@ var columnsOf = function columnsOf(schema) {
100
117
  * @author nokecy
101
118
  */
102
119
  export var withReadingArrayTable = function withReadingArrayTable(Control) {
103
- var ReactiveTable = observer(function (_ref4) {
104
- var columns = _ref4.columns,
105
- tableProps = _ref4.tableProps;
120
+ var ReactiveTable = observer(function (_ref3) {
121
+ var columns = _ref3.columns,
122
+ tableProps = _ref3.tableProps;
106
123
  var field = useField();
107
124
  // 阅读视图本身未订阅列状态,在此建立依赖,条件变化后重新提取表头。@author nokecy
108
125
  var _iterator = _createForOfIteratorHelper(columns),
@@ -1,2 +1,3 @@
1
+ export { withReactiveSchemaScope } from './schemaScope';
1
2
  /** 动态表单统一入口:禁用/只读的数据控件使用阅读展示,保持字段值和校验模型。@author nokecy */
2
3
  export declare function withReadingFields(components: Record<string, any>): Record<string, any>;
@@ -14,6 +14,7 @@ import { hoistStatics } from "./hoistStatics";
14
14
  import * as Reading from "./controls";
15
15
  import { selectNumberInputTextOnClick } from "./selectNumberInputTextOnClick";
16
16
  import { withReadingArrayTable } from "./arrayTable";
17
+ export { withReactiveSchemaScope } from "./schemaScope";
17
18
 
18
19
  /** 动态表单统一入口:禁用/只读的数据控件使用阅读展示,保持字段值和校验模型。@author nokecy */
19
20
  export function withReadingFields(components) {
@@ -5,6 +5,7 @@
5
5
  */
6
6
  export * as ReadPrettyControls from './controls';
7
7
  export { withReadingFields } from './formily';
8
+ export { withReactiveSchemaScope } from './schemaScope';
8
9
  export { withReadingArrayTable } from './arrayTable';
9
10
  export { DecimalInput, DecimalPicker } from './decimal';
10
11
  export { flattenOptions, selectedLabels } from './values';
@@ -6,6 +6,7 @@
6
6
  import * as _ReadPrettyControls from "./controls";
7
7
  export { _ReadPrettyControls as ReadPrettyControls };
8
8
  export { withReadingFields } from "./formily";
9
+ export { withReactiveSchemaScope } from "./schemaScope";
9
10
  export { withReadingArrayTable } from "./arrayTable";
10
11
  export { DecimalInput, DecimalPicker } from "./decimal";
11
12
  export { flattenOptions, selectedLabels } from "./values";
@@ -0,0 +1,2 @@
1
+ /** 将 React 页面作用域接入 Formily 响应式表达式,保留字段、输入值和已有对象引用。@author nokecy */
2
+ export declare const withReactiveSchemaScope: (Control: any) => any;
@@ -0,0 +1,42 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ 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; }
4
+ 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; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ import { autorun, batch, observable, untracked } from '@formily/reactive';
9
+ import React, { useEffect, useMemo } from 'react';
10
+ import { hoistStatics } from "./hoistStatics";
11
+
12
+ /** 将 React 页面作用域接入 Formily 响应式表达式,保留字段、输入值和已有对象引用。@author nokecy */
13
+ export var withReactiveSchemaScope = function withReactiveSchemaScope(Control) {
14
+ var Component = function Component(props) {
15
+ var scope = useMemo(function () {
16
+ return observable.shallow(_objectSpread({}, props.scope));
17
+ }, []);
18
+ // 字段反应在初始化时绑定作用域,因此始终传同一对象,再于提交后同步当前页面数据。
19
+ // autorun 同时兼容调用方直接传入的 observable 作用域;untracked 避免订阅同步目标。@author nokecy
20
+ useEffect(function () {
21
+ return autorun(function () {
22
+ var _props$scope;
23
+ var current = (_props$scope = props.scope) !== null && _props$scope !== void 0 ? _props$scope : {};
24
+ var values = _objectSpread({}, current);
25
+ untracked(function () {
26
+ return batch(function () {
27
+ for (var _i = 0, _Object$keys = Object.keys(scope); _i < _Object$keys.length; _i++) {
28
+ var key = _Object$keys[_i];
29
+ if (!Object.prototype.hasOwnProperty.call(values, key)) delete scope[key];
30
+ }
31
+ Object.assign(scope, values);
32
+ });
33
+ });
34
+ });
35
+ });
36
+ return /*#__PURE__*/React.createElement(Control, _extends({}, props, {
37
+ scope: scope
38
+ }));
39
+ };
40
+ Component.displayName = 'ReactiveSchemaScope';
41
+ return hoistStatics(Component, Control);
42
+ };