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

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.
@@ -10,6 +10,36 @@ var _window$React = window.React,
10
10
  createElement = _window$React.createElement,
11
11
  useCallback = _window$React.useCallback,
12
12
  useMemo = _window$React.useMemo;
13
+ function toStr(v) {
14
+ if (v == null) return '';
15
+ return String(v);
16
+ }
17
+ function getNodeValue(node) {
18
+ if (!node || typeof node !== 'object') return '';
19
+ // 兼容 value/id/key 等常见字段
20
+ if (node.value != null) return toStr(node.value);
21
+ if (node.id != null) return toStr(node.id);
22
+ if (node.key != null) return toStr(node.key);
23
+ return '';
24
+ }
25
+ function getNodeLabel(node, fallback) {
26
+ if (fallback === void 0) {
27
+ fallback = '';
28
+ }
29
+ if (!node || typeof node !== 'object') return fallback;
30
+ if (node.label != null) return toStr(node.label);
31
+ if (node.name != null) return toStr(node.name);
32
+ if (node.title != null) return toStr(node.title);
33
+ return fallback;
34
+ }
35
+ function getNodeChildren(node) {
36
+ if (!node || typeof node !== 'object') return [];
37
+ // 兼容 children / options / childs 等结构
38
+ if (Array.isArray(node.children)) return node.children;
39
+ if (Array.isArray(node.options)) return node.options;
40
+ if (Array.isArray(node.childs)) return node.childs;
41
+ return [];
42
+ }
13
43
 
14
44
  /**
15
45
  * 按路径在树形 dataSource 上逐级匹配,取出每一层的 label(2 级、3 级…任意多级,长度由 pathValues 决定)。
@@ -21,39 +51,92 @@ function resolvePathLabels(dataSource, pathValues) {
21
51
  var _loop = function _loop() {
22
52
  var pv = _step.value;
23
53
  var node = level.find(function (n) {
24
- return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
54
+ return getNodeValue(n) === toStr(pv);
25
55
  });
26
56
  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 : [];
57
+ labels.push(getNodeLabel(node, toStr(pv)));
58
+ level = getNodeChildren(node);
30
59
  };
31
60
  for (var _iterator = _createForOfIteratorHelperLoose(pathValues), _step; !(_step = _iterator()).done;) {
32
61
  if (_loop()) break;
33
62
  }
34
63
  return labels;
35
64
  }
36
- function normalizeCascaderPath(v) {
65
+ function isValidPathInTree(dataSource, pathValues) {
66
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return false;
67
+ var level = dataSource;
68
+ var _loop2 = function _loop2() {
69
+ var pv = _step2.value;
70
+ var node = level.find(function (n) {
71
+ return getNodeValue(n) === toStr(pv);
72
+ });
73
+ if (!node) return {
74
+ v: false
75
+ };
76
+ level = getNodeChildren(node);
77
+ },
78
+ _ret;
79
+ for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
80
+ _ret = _loop2();
81
+ if (_ret) return _ret.v;
82
+ }
83
+ return true;
84
+ }
85
+
86
+ /** 回填仅有叶子 id(如 city=2977)时,递归反查完整路径 [provinceId, cityId] */
87
+ function findPathByNodeValue(dataSource, targetValue, parentPath) {
88
+ if (parentPath === void 0) {
89
+ parentPath = [];
90
+ }
91
+ if (!Array.isArray(dataSource) || targetValue === '') return [];
92
+ for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
93
+ var node = _step3.value;
94
+ var curValue = getNodeValue(node);
95
+ if (!curValue) continue;
96
+ var nextPath = parentPath.concat(curValue);
97
+ if (curValue === toStr(targetValue)) {
98
+ return nextPath;
99
+ }
100
+ var hit = findPathByNodeValue(getNodeChildren(node), targetValue, nextPath);
101
+ if (hit.length > 0) return hit;
102
+ }
103
+ return [];
104
+ }
105
+ function normalizeCascaderPath(v, dataSource) {
106
+ var tryExpandByLeaf = function tryExpandByLeaf(leaf, fallback) {
107
+ if (fallback === void 0) {
108
+ fallback = [];
109
+ }
110
+ var fullPath = findPathByNodeValue(dataSource, leaf);
111
+ return fullPath.length > 0 ? fullPath : fallback;
112
+ };
37
113
  if (Array.isArray(v)) {
38
- return v.filter(function (x) {
114
+ var path = v.filter(function (x) {
39
115
  return x != null && x !== '';
40
116
  }).map(function (x) {
41
- return String(x);
117
+ return toStr(x);
42
118
  });
119
+ if (path.length === 0) return [];
120
+ if (isValidPathInTree(dataSource, path)) return path;
121
+ return tryExpandByLeaf(path[path.length - 1], path);
43
122
  }
44
123
  if (typeof v === 'number' && !Number.isNaN(v)) {
45
- /** 表单里有时是数字 id(2977),Fusion dataSource string 化,需对齐 */
46
- return [String(v)];
124
+ /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
125
+ return tryExpandByLeaf(toStr(v), [toStr(v)]);
47
126
  }
48
127
  if (typeof v === 'string' && v.trim()) {
49
128
  try {
50
129
  var parsed = JSON.parse(v);
51
- return Array.isArray(parsed) ? parsed.map(function (x) {
52
- return String(x);
53
- }) : [];
130
+ if (!Array.isArray(parsed)) return [];
131
+ var _path = parsed.map(function (x) {
132
+ return toStr(x);
133
+ });
134
+ if (_path.length === 0) return [];
135
+ if (isValidPathInTree(dataSource, _path)) return _path;
136
+ return tryExpandByLeaf(_path[_path.length - 1], _path);
54
137
  } catch (_unused) {
55
- /** 历史或单值存成非 JSON 字符串时,当作单选叶子 value */
56
- return [v];
138
+ /** 历史或接口单值回填时,当作叶子值反查完整路径 */
139
+ return tryExpandByLeaf(v, [v]);
57
140
  }
58
141
  }
59
142
  return [];
@@ -92,6 +175,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
92
175
  screen_inner_id = props.screen_inner_id,
93
176
  range_inner_table = props.range_inner_table,
94
177
  dataSource = props.dataSource,
178
+ options = props.options,
95
179
  disableEdit = props.disableEdit,
96
180
  readOnlyProp = props.readOnly,
97
181
  disabledProp = props.disabled,
@@ -111,14 +195,22 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
111
195
  var _useProBoundValue = useProBoundValue(fieldPath, unboundInit, FORM_EMPTY_ARRAY),
112
196
  value = _useProBoundValue.value,
113
197
  commit = _useProBoundValue.commit;
198
+ // 优先 dataSource,兼容部分 schema 透传为 options
199
+ var cascaderOptions = useMemo(function () {
200
+ if (Array.isArray(dataSource)) return dataSource;
201
+ if (Array.isArray(options)) return options;
202
+ return [];
203
+ }, [dataSource, options]);
114
204
  var handleChange = function handleChange(newValue, _data, extra) {
115
205
  var next = cascaderChangeToPath(newValue, extra);
116
206
  commit(next);
117
207
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
118
208
  };
119
209
 
120
- /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
121
- var displayValue = normalizeCascaderPath(value);
210
+ /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
211
+ var displayValue = useMemo(function () {
212
+ return normalizeCascaderPath(value, cascaderOptions);
213
+ }, [value, cascaderOptions]);
122
214
 
123
215
  /**
124
216
  * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
@@ -138,7 +230,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
138
230
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
139
231
  var schemaDisplayRender = props.displayRender;
140
232
  var pathDisplayRender = useCallback(function (labels, data) {
141
- var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
233
+ var fullLabels = resolvePathLabels(cascaderOptions, displayValue);
142
234
  if (fullLabels.length > 0) {
143
235
  return fullLabels.join(' / ');
144
236
  }
@@ -146,13 +238,13 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
146
238
  return schemaDisplayRender(labels, data);
147
239
  }
148
240
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
149
- }, [dataSource, value, schemaDisplayRender]);
241
+ }, [cascaderOptions, displayValue, schemaDisplayRender]);
150
242
  return /*#__PURE__*/React.createElement("span", {
151
243
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
152
244
  }, /*#__PURE__*/React.createElement(_CascaderSelect, _extends({}, props, {
153
245
  readOnly: disableEdit ? true : readOnlyProp,
154
246
  disabled: disabledProp,
155
- dataSource: dataSource,
247
+ dataSource: cascaderOptions,
156
248
  value: valueForFusion,
157
249
  onChange: handleChange,
158
250
  displayRender: pathDisplayRender
@@ -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;
@@ -15,6 +15,36 @@ var _window$React = window.React,
15
15
  createElement = _window$React.createElement,
16
16
  useCallback = _window$React.useCallback,
17
17
  useMemo = _window$React.useMemo;
18
+ function toStr(v) {
19
+ if (v == null) return '';
20
+ return String(v);
21
+ }
22
+ function getNodeValue(node) {
23
+ if (!node || typeof node !== 'object') return '';
24
+ // 兼容 value/id/key 等常见字段
25
+ if (node.value != null) return toStr(node.value);
26
+ if (node.id != null) return toStr(node.id);
27
+ if (node.key != null) return toStr(node.key);
28
+ return '';
29
+ }
30
+ function getNodeLabel(node, fallback) {
31
+ if (fallback === void 0) {
32
+ fallback = '';
33
+ }
34
+ if (!node || typeof node !== 'object') return fallback;
35
+ if (node.label != null) return toStr(node.label);
36
+ if (node.name != null) return toStr(node.name);
37
+ if (node.title != null) return toStr(node.title);
38
+ return fallback;
39
+ }
40
+ function getNodeChildren(node) {
41
+ if (!node || typeof node !== 'object') return [];
42
+ // 兼容 children / options / childs 等结构
43
+ if (Array.isArray(node.children)) return node.children;
44
+ if (Array.isArray(node.options)) return node.options;
45
+ if (Array.isArray(node.childs)) return node.childs;
46
+ return [];
47
+ }
18
48
 
19
49
  /**
20
50
  * 按路径在树形 dataSource 上逐级匹配,取出每一层的 label(2 级、3 级…任意多级,长度由 pathValues 决定)。
@@ -26,39 +56,92 @@ function resolvePathLabels(dataSource, pathValues) {
26
56
  var _loop = function _loop() {
27
57
  var pv = _step.value;
28
58
  var node = level.find(function (n) {
29
- return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
59
+ return getNodeValue(n) === toStr(pv);
30
60
  });
31
61
  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 : [];
62
+ labels.push(getNodeLabel(node, toStr(pv)));
63
+ level = getNodeChildren(node);
35
64
  };
36
65
  for (var _iterator = _createForOfIteratorHelperLoose(pathValues), _step; !(_step = _iterator()).done;) {
37
66
  if (_loop()) break;
38
67
  }
39
68
  return labels;
40
69
  }
41
- function normalizeCascaderPath(v) {
70
+ function isValidPathInTree(dataSource, pathValues) {
71
+ if (!Array.isArray(dataSource) || pathValues.length === 0) return false;
72
+ var level = dataSource;
73
+ var _loop2 = function _loop2() {
74
+ var pv = _step2.value;
75
+ var node = level.find(function (n) {
76
+ return getNodeValue(n) === toStr(pv);
77
+ });
78
+ if (!node) return {
79
+ v: false
80
+ };
81
+ level = getNodeChildren(node);
82
+ },
83
+ _ret;
84
+ for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
85
+ _ret = _loop2();
86
+ if (_ret) return _ret.v;
87
+ }
88
+ return true;
89
+ }
90
+
91
+ /** 回填仅有叶子 id(如 city=2977)时,递归反查完整路径 [provinceId, cityId] */
92
+ function findPathByNodeValue(dataSource, targetValue, parentPath) {
93
+ if (parentPath === void 0) {
94
+ parentPath = [];
95
+ }
96
+ if (!Array.isArray(dataSource) || targetValue === '') return [];
97
+ for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
98
+ var node = _step3.value;
99
+ var curValue = getNodeValue(node);
100
+ if (!curValue) continue;
101
+ var nextPath = parentPath.concat(curValue);
102
+ if (curValue === toStr(targetValue)) {
103
+ return nextPath;
104
+ }
105
+ var hit = findPathByNodeValue(getNodeChildren(node), targetValue, nextPath);
106
+ if (hit.length > 0) return hit;
107
+ }
108
+ return [];
109
+ }
110
+ function normalizeCascaderPath(v, dataSource) {
111
+ var tryExpandByLeaf = function tryExpandByLeaf(leaf, fallback) {
112
+ if (fallback === void 0) {
113
+ fallback = [];
114
+ }
115
+ var fullPath = findPathByNodeValue(dataSource, leaf);
116
+ return fullPath.length > 0 ? fullPath : fallback;
117
+ };
42
118
  if (Array.isArray(v)) {
43
- return v.filter(function (x) {
119
+ var path = v.filter(function (x) {
44
120
  return x != null && x !== '';
45
121
  }).map(function (x) {
46
- return String(x);
122
+ return toStr(x);
47
123
  });
124
+ if (path.length === 0) return [];
125
+ if (isValidPathInTree(dataSource, path)) return path;
126
+ return tryExpandByLeaf(path[path.length - 1], path);
48
127
  }
49
128
  if (typeof v === 'number' && !Number.isNaN(v)) {
50
- /** 表单里有时是数字 id(2977),Fusion dataSource string 化,需对齐 */
51
- return [String(v)];
129
+ /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
130
+ return tryExpandByLeaf(toStr(v), [toStr(v)]);
52
131
  }
53
132
  if (typeof v === 'string' && v.trim()) {
54
133
  try {
55
134
  var parsed = JSON.parse(v);
56
- return Array.isArray(parsed) ? parsed.map(function (x) {
57
- return String(x);
58
- }) : [];
135
+ if (!Array.isArray(parsed)) return [];
136
+ var _path = parsed.map(function (x) {
137
+ return toStr(x);
138
+ });
139
+ if (_path.length === 0) return [];
140
+ if (isValidPathInTree(dataSource, _path)) return _path;
141
+ return tryExpandByLeaf(_path[_path.length - 1], _path);
59
142
  } catch (_unused) {
60
- /** 历史或单值存成非 JSON 字符串时,当作单选叶子 value */
61
- return [v];
143
+ /** 历史或接口单值回填时,当作叶子值反查完整路径 */
144
+ return tryExpandByLeaf(v, [v]);
62
145
  }
63
146
  }
64
147
  return [];
@@ -97,6 +180,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
97
180
  screen_inner_id = props.screen_inner_id,
98
181
  range_inner_table = props.range_inner_table,
99
182
  dataSource = props.dataSource,
183
+ options = props.options,
100
184
  disableEdit = props.disableEdit,
101
185
  readOnlyProp = props.readOnly,
102
186
  disabledProp = props.disabled,
@@ -116,14 +200,22 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
116
200
  var _useProBoundValue = (0, _useProBoundValue2.useProBoundValue)(fieldPath, unboundInit, _useComponentContext.FORM_EMPTY_ARRAY),
117
201
  value = _useProBoundValue.value,
118
202
  commit = _useProBoundValue.commit;
203
+ // 优先 dataSource,兼容部分 schema 透传为 options
204
+ var cascaderOptions = useMemo(function () {
205
+ if (Array.isArray(dataSource)) return dataSource;
206
+ if (Array.isArray(options)) return options;
207
+ return [];
208
+ }, [dataSource, options]);
119
209
  var handleChange = function handleChange(newValue, _data, extra) {
120
210
  var next = cascaderChangeToPath(newValue, extra);
121
211
  commit(next);
122
212
  schemaOnChange === null || schemaOnChange === void 0 ? void 0 : schemaOnChange(next, structureName, structureField);
123
213
  };
124
214
 
125
- /** 表单/接口:完整路径 string[],如 ['2974','2975'] */
126
- var displayValue = normalizeCascaderPath(value);
215
+ /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
216
+ var displayValue = useMemo(function () {
217
+ return normalizeCascaderPath(value, cascaderOptions);
218
+ }, [value, cascaderOptions]);
127
219
 
128
220
  /**
129
221
  * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
@@ -143,7 +235,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
143
235
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
144
236
  var schemaDisplayRender = props.displayRender;
145
237
  var pathDisplayRender = useCallback(function (labels, data) {
146
- var fullLabels = resolvePathLabels(dataSource, normalizeCascaderPath(value));
238
+ var fullLabels = resolvePathLabels(cascaderOptions, displayValue);
147
239
  if (fullLabels.length > 0) {
148
240
  return fullLabels.join(' / ');
149
241
  }
@@ -151,13 +243,13 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
151
243
  return schemaDisplayRender(labels, data);
152
244
  }
153
245
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
154
- }, [dataSource, value, schemaDisplayRender]);
246
+ }, [cascaderOptions, displayValue, schemaDisplayRender]);
155
247
  return /*#__PURE__*/React.createElement("span", {
156
248
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
157
249
  }, /*#__PURE__*/React.createElement(_cascaderSelect["default"], (0, _extends2["default"])({}, props, {
158
250
  readOnly: disableEdit ? true : readOnlyProp,
159
251
  disabled: disabledProp,
160
- dataSource: dataSource,
252
+ dataSource: cascaderOptions,
161
253
  value: valueForFusion,
162
254
  onChange: handleChange,
163
255
  displayRender: pathDisplayRender
@@ -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.75';
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.75';
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.75",
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.75/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.75/build/index.html"
110
110
  }