@openli1115/lowcode-edit-pro-table 1.0.73 → 1.0.74

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.
@@ -33,27 +33,81 @@ function resolvePathLabels(dataSource, pathValues) {
33
33
  }
34
34
  return labels;
35
35
  }
36
- function normalizeCascaderPath(v) {
36
+ function isValidPathInTree(dataSource, pathValues) {
37
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return false;
38
+ var level = dataSource;
39
+ var _loop2 = function _loop2() {
40
+ var pv = _step2.value;
41
+ var node = level.find(function (n) {
42
+ return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
43
+ });
44
+ if (!node) return {
45
+ v: false
46
+ };
47
+ level = Array.isArray(node.children) ? node.children : [];
48
+ },
49
+ _ret;
50
+ for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
51
+ _ret = _loop2();
52
+ if (_ret) return _ret.v;
53
+ }
54
+ return true;
55
+ }
56
+
57
+ /** 回填仅有叶子 id(如 city=2977)时,递归反查完整路径 [provinceId, cityId] */
58
+ function findPathByNodeValue(dataSource, targetValue, parentPath) {
59
+ if (parentPath === void 0) {
60
+ parentPath = [];
61
+ }
62
+ if (!Array.isArray(dataSource) || targetValue === '') return [];
63
+ for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
64
+ var node = _step3.value;
65
+ var curValue = node === null || node === void 0 ? void 0 : node.value;
66
+ if (curValue == null) continue;
67
+ var nextPath = parentPath.concat(String(curValue));
68
+ if (String(curValue) === targetValue) {
69
+ return nextPath;
70
+ }
71
+ var hit = findPathByNodeValue(node === null || node === void 0 ? void 0 : node.children, targetValue, nextPath);
72
+ if (hit.length > 0) return hit;
73
+ }
74
+ return [];
75
+ }
76
+ function normalizeCascaderPath(v, dataSource) {
77
+ var tryExpandByLeaf = function tryExpandByLeaf(leaf, fallback) {
78
+ if (fallback === void 0) {
79
+ fallback = [];
80
+ }
81
+ var fullPath = findPathByNodeValue(dataSource, leaf);
82
+ return fullPath.length > 0 ? fullPath : fallback;
83
+ };
37
84
  if (Array.isArray(v)) {
38
- return v.filter(function (x) {
85
+ var path = v.filter(function (x) {
39
86
  return x != null && x !== '';
40
87
  }).map(function (x) {
41
88
  return String(x);
42
89
  });
90
+ if (path.length === 0) return [];
91
+ if (isValidPathInTree(dataSource, path)) return path;
92
+ return tryExpandByLeaf(path[path.length - 1], path);
43
93
  }
44
94
  if (typeof v === 'number' && !Number.isNaN(v)) {
45
- /** 表单里有时是数字 id(2977),Fusion dataSource string 化,需对齐 */
46
- return [String(v)];
95
+ /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
96
+ return tryExpandByLeaf(String(v), [String(v)]);
47
97
  }
48
98
  if (typeof v === 'string' && v.trim()) {
49
99
  try {
50
100
  var parsed = JSON.parse(v);
51
- return Array.isArray(parsed) ? parsed.map(function (x) {
101
+ if (!Array.isArray(parsed)) return [];
102
+ var _path = parsed.map(function (x) {
52
103
  return String(x);
53
- }) : [];
104
+ });
105
+ if (_path.length === 0) return [];
106
+ if (isValidPathInTree(dataSource, _path)) return _path;
107
+ return tryExpandByLeaf(_path[_path.length - 1], _path);
54
108
  } catch (_unused) {
55
- /** 历史或单值存成非 JSON 字符串时,当作单选叶子 value */
56
- return [v];
109
+ /** 历史或接口单值回填时,当作叶子值反查完整路径 */
110
+ return tryExpandByLeaf(v, [v]);
57
111
  }
58
112
  }
59
113
  return [];
@@ -117,8 +171,10 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
117
171
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
118
172
  };
119
173
 
120
- /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
121
- var displayValue = normalizeCascaderPath(value);
174
+ /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
175
+ var displayValue = useMemo(function () {
176
+ return normalizeCascaderPath(value, dataSource);
177
+ }, [value, dataSource]);
122
178
 
123
179
  /**
124
180
  * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
@@ -138,7 +194,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
138
194
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
139
195
  var schemaDisplayRender = props.displayRender;
140
196
  var pathDisplayRender = useCallback(function (labels, data) {
141
- var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
197
+ var fullLabels = resolvePathLabels(dataSource, displayValue);
142
198
  if (fullLabels.length > 0) {
143
199
  return fullLabels.join(' / ');
144
200
  }
@@ -146,7 +202,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
146
202
  return schemaDisplayRender(labels, data);
147
203
  }
148
204
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
149
- }, [dataSource, value, schemaDisplayRender]);
205
+ }, [dataSource, displayValue, schemaDisplayRender]);
150
206
  return /*#__PURE__*/React.createElement("span", {
151
207
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
152
208
  }, /*#__PURE__*/React.createElement(_CascaderSelect, _extends({}, props, {
@@ -38,7 +38,11 @@ export var FormProvider = function FormProvider(_ref) {
38
38
 
39
39
  // 使用 ref 缓存初始值
40
40
  var initialValuesRef = useRef(initialValues);
41
- var _useState = useState(initialValues),
41
+
42
+ // 与外部 screenStructures 断开引用,避免逻辑流原地修改 window 对象时污染表单内部 state
43
+ var _useState = useState(function () {
44
+ return cloneDeep(initialValues);
45
+ }),
42
46
  values = _useState[0],
43
47
  setValues = _useState[1];
44
48
 
@@ -75,9 +79,11 @@ export var FormProvider = function FormProvider(_ref) {
75
79
 
76
80
  // 触发 onChange 回调,把新值通知给外部
77
81
  if (onChange) {
82
+ // 对外回传使用副本,避免 preview/window 与 FormProvider 共用同一对象引用
83
+ var outboundValues = cloneDeep(newValues);
78
84
  // 使用微任务避免阻塞渲染
79
85
  Promise.resolve().then(function () {
80
- onChange(newValues);
86
+ onChange(outboundValues);
81
87
  });
82
88
  }
83
89
  return newValues;
@@ -38,27 +38,81 @@ function resolvePathLabels(dataSource, pathValues) {
38
38
  }
39
39
  return labels;
40
40
  }
41
- function normalizeCascaderPath(v) {
41
+ function isValidPathInTree(dataSource, pathValues) {
42
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return false;
43
+ var level = dataSource;
44
+ var _loop2 = function _loop2() {
45
+ var pv = _step2.value;
46
+ var node = level.find(function (n) {
47
+ return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
48
+ });
49
+ if (!node) return {
50
+ v: false
51
+ };
52
+ level = Array.isArray(node.children) ? node.children : [];
53
+ },
54
+ _ret;
55
+ for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
56
+ _ret = _loop2();
57
+ if (_ret) return _ret.v;
58
+ }
59
+ return true;
60
+ }
61
+
62
+ /** 回填仅有叶子 id(如 city=2977)时,递归反查完整路径 [provinceId, cityId] */
63
+ function findPathByNodeValue(dataSource, targetValue, parentPath) {
64
+ if (parentPath === void 0) {
65
+ parentPath = [];
66
+ }
67
+ if (!Array.isArray(dataSource) || targetValue === '') return [];
68
+ for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
69
+ var node = _step3.value;
70
+ var curValue = node === null || node === void 0 ? void 0 : node.value;
71
+ if (curValue == null) continue;
72
+ var nextPath = parentPath.concat(String(curValue));
73
+ if (String(curValue) === targetValue) {
74
+ return nextPath;
75
+ }
76
+ var hit = findPathByNodeValue(node === null || node === void 0 ? void 0 : node.children, targetValue, nextPath);
77
+ if (hit.length > 0) return hit;
78
+ }
79
+ return [];
80
+ }
81
+ function normalizeCascaderPath(v, dataSource) {
82
+ var tryExpandByLeaf = function tryExpandByLeaf(leaf, fallback) {
83
+ if (fallback === void 0) {
84
+ fallback = [];
85
+ }
86
+ var fullPath = findPathByNodeValue(dataSource, leaf);
87
+ return fullPath.length > 0 ? fullPath : fallback;
88
+ };
42
89
  if (Array.isArray(v)) {
43
- return v.filter(function (x) {
90
+ var path = v.filter(function (x) {
44
91
  return x != null && x !== '';
45
92
  }).map(function (x) {
46
93
  return String(x);
47
94
  });
95
+ if (path.length === 0) return [];
96
+ if (isValidPathInTree(dataSource, path)) return path;
97
+ return tryExpandByLeaf(path[path.length - 1], path);
48
98
  }
49
99
  if (typeof v === 'number' && !Number.isNaN(v)) {
50
- /** 表单里有时是数字 id(2977),Fusion dataSource string 化,需对齐 */
51
- return [String(v)];
100
+ /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
101
+ return tryExpandByLeaf(String(v), [String(v)]);
52
102
  }
53
103
  if (typeof v === 'string' && v.trim()) {
54
104
  try {
55
105
  var parsed = JSON.parse(v);
56
- return Array.isArray(parsed) ? parsed.map(function (x) {
106
+ if (!Array.isArray(parsed)) return [];
107
+ var _path = parsed.map(function (x) {
57
108
  return String(x);
58
- }) : [];
109
+ });
110
+ if (_path.length === 0) return [];
111
+ if (isValidPathInTree(dataSource, _path)) return _path;
112
+ return tryExpandByLeaf(_path[_path.length - 1], _path);
59
113
  } catch (_unused) {
60
- /** 历史或单值存成非 JSON 字符串时,当作单选叶子 value */
61
- return [v];
114
+ /** 历史或接口单值回填时,当作叶子值反查完整路径 */
115
+ return tryExpandByLeaf(v, [v]);
62
116
  }
63
117
  }
64
118
  return [];
@@ -122,8 +176,10 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
122
176
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
123
177
  };
124
178
 
125
- /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
126
- var displayValue = normalizeCascaderPath(value);
179
+ /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
180
+ var displayValue = useMemo(function () {
181
+ return normalizeCascaderPath(value, dataSource);
182
+ }, [value, dataSource]);
127
183
 
128
184
  /**
129
185
  * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
@@ -143,7 +199,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
143
199
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
144
200
  var schemaDisplayRender = props.displayRender;
145
201
  var pathDisplayRender = useCallback(function (labels, data) {
146
- var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
202
+ var fullLabels = resolvePathLabels(dataSource, displayValue);
147
203
  if (fullLabels.length > 0) {
148
204
  return fullLabels.join(' / ');
149
205
  }
@@ -151,7 +207,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
151
207
  return schemaDisplayRender(labels, data);
152
208
  }
153
209
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
154
- }, [dataSource, value, schemaDisplayRender]);
210
+ }, [dataSource, displayValue, schemaDisplayRender]);
155
211
  return /*#__PURE__*/React.createElement("span", {
156
212
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
157
213
  }, /*#__PURE__*/React.createElement(_cascaderSelect["default"], (0, _extends2["default"])({}, props, {
@@ -44,7 +44,11 @@ var FormProvider = exports.FormProvider = function FormProvider(_ref) {
44
44
 
45
45
  // 使用 ref 缓存初始值
46
46
  var initialValuesRef = useRef(initialValues);
47
- var _useState = useState(initialValues),
47
+
48
+ // 与外部 screenStructures 断开引用,避免逻辑流原地修改 window 对象时污染表单内部 state
49
+ var _useState = useState(function () {
50
+ return (0, _lodash.cloneDeep)(initialValues);
51
+ }),
48
52
  values = _useState[0],
49
53
  setValues = _useState[1];
50
54
 
@@ -81,9 +85,11 @@ var FormProvider = exports.FormProvider = function FormProvider(_ref) {
81
85
 
82
86
  // 触发 onChange 回调,把新值通知给外部
83
87
  if (onChange) {
88
+ // 对外回传使用副本,避免 preview/window 与 FormProvider 共用同一对象引用
89
+ var outboundValues = (0, _lodash.cloneDeep)(newValues);
84
90
  // 使用微任务避免阻塞渲染
85
91
  Promise.resolve().then(function () {
86
- onChange(newValues);
92
+ onChange(outboundValues);
87
93
  });
88
94
  }
89
95
  return newValues;
@@ -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.73';
104
+ version = '1.0.74';
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.73';
109
+ version = '1.0.74';
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.73",
3
+ "version": "1.0.74",
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.73/build/lowcode/assets-prod.json"
104
+ "materialSchema": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.74/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.73/build/index.html"
109
+ "homepage": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.74/build/index.html"
110
110
  }