@openli1115/lowcode-edit-pro-table 1.0.60 → 1.0.62

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.
@@ -1,11 +1,38 @@
1
1
  import _CascaderSelect from "@alifd/next/es/cascader-select";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
4
- var _excluded = ["screen_structure", "screen_structure_field", "screen_inner_id", "range_inner_table", "dataSource", "disableEdit", "readOnly", "disabled", "value", "onChange", "defaultValue"];
3
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
6
  import { resolveProScreenBinding } from "../utils";
6
7
  import { useProBoundValue } from "../../context/useProBoundValue";
7
8
  import { FORM_EMPTY_ARRAY } from "../../context/useComponentContext";
8
- var createElement = window.React.createElement;
9
+ var _window$React = window.React,
10
+ createElement = _window$React.createElement,
11
+ useCallback = _window$React.useCallback,
12
+ useMemo = _window$React.useMemo;
13
+
14
+ /**
15
+ * 按路径在树形 dataSource 上逐级匹配,取出每一层的 label(2 级、3 级…任意多级,长度由 pathValues 决定)。
16
+ */
17
+ function resolvePathLabels(dataSource, pathValues) {
18
+ var labels = [];
19
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return labels;
20
+ var level = dataSource;
21
+ var _loop = function _loop() {
22
+ var pv = _step.value;
23
+ var node = level.find(function (n) {
24
+ return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
25
+ });
26
+ if (!node) return 1; // break
27
+ labels.push(node.label != null ? String(node.label) : String(pv));
28
+ var next = node.children;
29
+ level = Array.isArray(next) ? next : [];
30
+ };
31
+ for (var _iterator = _createForOfIteratorHelperLoose(pathValues), _step; !(_step = _iterator()).done;) {
32
+ if (_loop()) break;
33
+ }
34
+ return labels;
35
+ }
9
36
  function normalizeCascaderPath(v) {
10
37
  if (Array.isArray(v)) {
11
38
  return v.filter(function (x) {
@@ -38,7 +65,14 @@ function normalizeCascaderPath(v) {
38
65
  */
39
66
  function cascaderChangeToPath(newValue, extra) {
40
67
  if (newValue == null) return [];
41
- if (Array.isArray(newValue)) return newValue.slice();
68
+ /** 多选或已是完整路径数组时直接规范化(多级路径长度不限) */
69
+ if (Array.isArray(newValue)) {
70
+ return newValue.map(function (x) {
71
+ return x == null ? '' : String(x);
72
+ }).filter(function (x) {
73
+ return x !== '';
74
+ });
75
+ }
42
76
  var nodes = extra === null || extra === void 0 ? void 0 : extra.selectedPath;
43
77
  if (Array.isArray(nodes) && nodes.length > 0) {
44
78
  return nodes.map(function (n) {
@@ -64,7 +98,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
64
98
  _schemaValue = props.value,
65
99
  schemaOnChange = props.onChange,
66
100
  defaultValue = props.defaultValue,
67
- restProps = _objectWithoutPropertiesLoose(props, _excluded);
101
+ multiple = props.multiple;
68
102
  var _resolveProScreenBind = resolveProScreenBinding({
69
103
  screen_structure: screen_structure,
70
104
  screen_structure_field: screen_structure_field,
@@ -82,15 +116,46 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
82
116
  commit(next);
83
117
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
84
118
  };
119
+
120
+ /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
85
121
  var displayValue = normalizeCascaderPath(value);
122
+
123
+ /**
124
+ * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
125
+ * 若传入完整路径 [父,子],会把「父」当成选中项,文案只有一级。
126
+ * 组件展示应传「叶子」单元素数组 [leaf],内部 getLabelPath(叶子节点) 会生成多级展示。
127
+ * 多选仍传 Fusion 所需的多个 value(与表单存值一致)。
128
+ */
129
+ var valueForFusion = useMemo(function () {
130
+ var path = displayValue;
131
+ if (multiple) {
132
+ return path;
133
+ }
134
+ if (path.length === 0) return [];
135
+ return [path[path.length - 1]];
136
+ }, [displayValue, multiple]);
137
+
138
+ /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
139
+ var schemaDisplayRender = props.displayRender;
140
+ var pathDisplayRender = useCallback(function (labels, data) {
141
+ var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
142
+ if (fullLabels.length > 0) {
143
+ return fullLabels.join(' / ');
144
+ }
145
+ if (typeof schemaDisplayRender === 'function') {
146
+ return schemaDisplayRender(labels, data);
147
+ }
148
+ return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
149
+ }, [dataSource, value, schemaDisplayRender]);
86
150
  return /*#__PURE__*/React.createElement("span", {
87
151
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
88
152
  }, /*#__PURE__*/React.createElement(_CascaderSelect, _extends({}, props, {
89
153
  readOnly: disableEdit ? true : readOnlyProp,
90
154
  disabled: disabledProp,
91
155
  dataSource: dataSource,
92
- value: displayValue,
93
- onChange: handleChange
156
+ value: valueForFusion,
157
+ onChange: handleChange,
158
+ displayRender: pathDisplayRender
94
159
  })));
95
160
  };
96
161
  export default ProCascaderSelect;
@@ -42,15 +42,25 @@ export var FormProvider = function FormProvider(_ref) {
42
42
  values = _useState[0],
43
43
  setValues = _useState[1];
44
44
 
45
- // 仅当 initialValues 引用变化时更新状态
45
+ /**
46
+ * store 每次 dispatch 都会给新的 screenStructures 引用;若内容与表单 state 实际一致仍 setValues,
47
+ * 会整页重渲染(含 EditProTable 几十行),Fusion Overlay/Select 在 componentDidUpdate 里反复 setPosition,
48
+ * 易触发 React #185(Maximum update depth exceeded),Windows 上更明显。
49
+ */
46
50
  useEffect(function () {
47
- if (!isEqual(initialValues, initialValuesRef.current)) {
48
- console.log('[FormProvider] 🔄 useEffect triggered - initialValues:', initialValues);
51
+ if (isEqual(initialValues, initialValuesRef.current)) {
49
52
  initialValuesRef.current = initialValues;
50
- setValues(function (prev) {
51
- return _extends({}, prev, initialValues);
52
- });
53
+ return;
53
54
  }
55
+ console.log('[FormProvider] 🔄 useEffect triggered - initialValues:', initialValues);
56
+ initialValuesRef.current = initialValues;
57
+ setValues(function (prev) {
58
+ var merged = _extends({}, prev, initialValues);
59
+ if (isEqual(prev, merged)) {
60
+ return prev;
61
+ }
62
+ return merged;
63
+ });
54
64
  }, [initialValues]);
55
65
 
56
66
  // 优化 setFieldValue
@@ -5,12 +5,39 @@ exports.__esModule = true;
5
5
  exports["default"] = void 0;
6
6
  var _cascaderSelect = _interopRequireDefault(require("@alifd/next/lib/cascader-select"));
7
7
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
8
  var _utils = require("../utils");
10
9
  var _useProBoundValue2 = require("../../context/useProBoundValue");
11
10
  var _useComponentContext = require("../../context/useComponentContext");
12
- var _excluded = ["screen_structure", "screen_structure_field", "screen_inner_id", "range_inner_table", "dataSource", "disableEdit", "readOnly", "disabled", "value", "onChange", "defaultValue"];
13
- var createElement = window.React.createElement;
11
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
+ var _window$React = window.React,
15
+ createElement = _window$React.createElement,
16
+ useCallback = _window$React.useCallback,
17
+ useMemo = _window$React.useMemo;
18
+
19
+ /**
20
+ * 按路径在树形 dataSource 上逐级匹配,取出每一层的 label(2 级、3 级…任意多级,长度由 pathValues 决定)。
21
+ */
22
+ function resolvePathLabels(dataSource, pathValues) {
23
+ var labels = [];
24
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return labels;
25
+ var level = dataSource;
26
+ var _loop = function _loop() {
27
+ var pv = _step.value;
28
+ var node = level.find(function (n) {
29
+ return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
30
+ });
31
+ if (!node) return 1; // break
32
+ labels.push(node.label != null ? String(node.label) : String(pv));
33
+ var next = node.children;
34
+ level = Array.isArray(next) ? next : [];
35
+ };
36
+ for (var _iterator = _createForOfIteratorHelperLoose(pathValues), _step; !(_step = _iterator()).done;) {
37
+ if (_loop()) break;
38
+ }
39
+ return labels;
40
+ }
14
41
  function normalizeCascaderPath(v) {
15
42
  if (Array.isArray(v)) {
16
43
  return v.filter(function (x) {
@@ -43,7 +70,14 @@ function normalizeCascaderPath(v) {
43
70
  */
44
71
  function cascaderChangeToPath(newValue, extra) {
45
72
  if (newValue == null) return [];
46
- if (Array.isArray(newValue)) return newValue.slice();
73
+ /** 多选或已是完整路径数组时直接规范化(多级路径长度不限) */
74
+ if (Array.isArray(newValue)) {
75
+ return newValue.map(function (x) {
76
+ return x == null ? '' : String(x);
77
+ }).filter(function (x) {
78
+ return x !== '';
79
+ });
80
+ }
47
81
  var nodes = extra === null || extra === void 0 ? void 0 : extra.selectedPath;
48
82
  if (Array.isArray(nodes) && nodes.length > 0) {
49
83
  return nodes.map(function (n) {
@@ -69,7 +103,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
69
103
  _schemaValue = props.value,
70
104
  schemaOnChange = props.onChange,
71
105
  defaultValue = props.defaultValue,
72
- restProps = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
106
+ multiple = props.multiple;
73
107
  var _resolveProScreenBind = (0, _utils.resolveProScreenBinding)({
74
108
  screen_structure: screen_structure,
75
109
  screen_structure_field: screen_structure_field,
@@ -87,15 +121,46 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
87
121
  commit(next);
88
122
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
89
123
  };
124
+
125
+ /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
90
126
  var displayValue = normalizeCascaderPath(value);
127
+
128
+ /**
129
+ * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
130
+ * 若传入完整路径 [父,子],会把「父」当成选中项,文案只有一级。
131
+ * 组件展示应传「叶子」单元素数组 [leaf],内部 getLabelPath(叶子节点) 会生成多级展示。
132
+ * 多选仍传 Fusion 所需的多个 value(与表单存值一致)。
133
+ */
134
+ var valueForFusion = useMemo(function () {
135
+ var path = displayValue;
136
+ if (multiple) {
137
+ return path;
138
+ }
139
+ if (path.length === 0) return [];
140
+ return [path[path.length - 1]];
141
+ }, [displayValue, multiple]);
142
+
143
+ /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
144
+ var schemaDisplayRender = props.displayRender;
145
+ var pathDisplayRender = useCallback(function (labels, data) {
146
+ var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
147
+ if (fullLabels.length > 0) {
148
+ return fullLabels.join(' / ');
149
+ }
150
+ if (typeof schemaDisplayRender === 'function') {
151
+ return schemaDisplayRender(labels, data);
152
+ }
153
+ return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
154
+ }, [dataSource, value, schemaDisplayRender]);
91
155
  return /*#__PURE__*/React.createElement("span", {
92
156
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
93
157
  }, /*#__PURE__*/React.createElement(_cascaderSelect["default"], (0, _extends2["default"])({}, props, {
94
158
  readOnly: disableEdit ? true : readOnlyProp,
95
159
  disabled: disabledProp,
96
160
  dataSource: dataSource,
97
- value: displayValue,
98
- onChange: handleChange
161
+ value: valueForFusion,
162
+ onChange: handleChange,
163
+ displayRender: pathDisplayRender
99
164
  })));
100
165
  };
101
166
  var _default = exports["default"] = ProCascaderSelect;
@@ -48,15 +48,25 @@ var FormProvider = exports.FormProvider = function FormProvider(_ref) {
48
48
  values = _useState[0],
49
49
  setValues = _useState[1];
50
50
 
51
- // 仅当 initialValues 引用变化时更新状态
51
+ /**
52
+ * store 每次 dispatch 都会给新的 screenStructures 引用;若内容与表单 state 实际一致仍 setValues,
53
+ * 会整页重渲染(含 EditProTable 几十行),Fusion Overlay/Select 在 componentDidUpdate 里反复 setPosition,
54
+ * 易触发 React #185(Maximum update depth exceeded),Windows 上更明显。
55
+ */
52
56
  useEffect(function () {
53
- if (!(0, _lodash.isEqual)(initialValues, initialValuesRef.current)) {
54
- console.log('[FormProvider] 🔄 useEffect triggered - initialValues:', initialValues);
57
+ if ((0, _lodash.isEqual)(initialValues, initialValuesRef.current)) {
55
58
  initialValuesRef.current = initialValues;
56
- setValues(function (prev) {
57
- return (0, _extends2["default"])({}, prev, initialValues);
58
- });
59
+ return;
59
60
  }
61
+ console.log('[FormProvider] 🔄 useEffect triggered - initialValues:', initialValues);
62
+ initialValuesRef.current = initialValues;
63
+ setValues(function (prev) {
64
+ var merged = (0, _extends2["default"])({}, prev, initialValues);
65
+ if ((0, _lodash.isEqual)(prev, merged)) {
66
+ return prev;
67
+ }
68
+ return merged;
69
+ });
60
70
  }, [initialValues]);
61
71
 
62
72
  // 优化 setFieldValue
@@ -101,7 +101,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
101
101
  packageName = '@openli1115/lowcode-edit-pro-table';
102
102
  }
103
103
  if (version === void 0) {
104
- version = '1.0.60';
104
+ version = '1.0.62';
105
105
  }
106
106
  if (basicLibraryVersion === void 0) {
107
107
  basicLibraryVersion = {
@@ -106,7 +106,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
106
106
  packageName = '@openli1115/lowcode-edit-pro-table';
107
107
  }
108
108
  if (version === void 0) {
109
- version = '1.0.60';
109
+ version = '1.0.62';
110
110
  }
111
111
  if (basicLibraryVersion === void 0) {
112
112
  basicLibraryVersion = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openli1115/lowcode-edit-pro-table",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
4
4
  "description": "@openli1115/lowcode-edit-pro-table",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -101,10 +101,10 @@
101
101
  },
102
102
  "componentConfig": {
103
103
  "isComponentLibrary": true,
104
- "materialSchema": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.60/build/lowcode/assets-prod.json"
104
+ "materialSchema": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.62/build/lowcode/assets-prod.json"
105
105
  },
106
106
  "lcMeta": {
107
107
  "type": "component"
108
108
  },
109
- "homepage": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.60/build/index.html"
109
+ "homepage": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.62/build/index.html"
110
110
  }