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

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,12 +51,11 @@ 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;
@@ -39,12 +68,12 @@ function isValidPathInTree(dataSource, pathValues) {
39
68
  var _loop2 = function _loop2() {
40
69
  var pv = _step2.value;
41
70
  var node = level.find(function (n) {
42
- return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
71
+ return getNodeValue(n) === toStr(pv);
43
72
  });
44
73
  if (!node) return {
45
74
  v: false
46
75
  };
47
- level = Array.isArray(node.children) ? node.children : [];
76
+ level = getNodeChildren(node);
48
77
  },
49
78
  _ret;
50
79
  for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
@@ -62,13 +91,13 @@ function findPathByNodeValue(dataSource, targetValue, parentPath) {
62
91
  if (!Array.isArray(dataSource) || targetValue === '') return [];
63
92
  for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
64
93
  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) {
94
+ var curValue = getNodeValue(node);
95
+ if (!curValue) continue;
96
+ var nextPath = parentPath.concat(curValue);
97
+ if (curValue === toStr(targetValue)) {
69
98
  return nextPath;
70
99
  }
71
- var hit = findPathByNodeValue(node === null || node === void 0 ? void 0 : node.children, targetValue, nextPath);
100
+ var hit = findPathByNodeValue(getNodeChildren(node), targetValue, nextPath);
72
101
  if (hit.length > 0) return hit;
73
102
  }
74
103
  return [];
@@ -85,7 +114,7 @@ function normalizeCascaderPath(v, dataSource) {
85
114
  var path = v.filter(function (x) {
86
115
  return x != null && x !== '';
87
116
  }).map(function (x) {
88
- return String(x);
117
+ return toStr(x);
89
118
  });
90
119
  if (path.length === 0) return [];
91
120
  if (isValidPathInTree(dataSource, path)) return path;
@@ -93,14 +122,14 @@ function normalizeCascaderPath(v, dataSource) {
93
122
  }
94
123
  if (typeof v === 'number' && !Number.isNaN(v)) {
95
124
  /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
96
- return tryExpandByLeaf(String(v), [String(v)]);
125
+ return tryExpandByLeaf(toStr(v), [toStr(v)]);
97
126
  }
98
127
  if (typeof v === 'string' && v.trim()) {
99
128
  try {
100
129
  var parsed = JSON.parse(v);
101
130
  if (!Array.isArray(parsed)) return [];
102
131
  var _path = parsed.map(function (x) {
103
- return String(x);
132
+ return toStr(x);
104
133
  });
105
134
  if (_path.length === 0) return [];
106
135
  if (isValidPathInTree(dataSource, _path)) return _path;
@@ -146,6 +175,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
146
175
  screen_inner_id = props.screen_inner_id,
147
176
  range_inner_table = props.range_inner_table,
148
177
  dataSource = props.dataSource,
178
+ options = props.options,
149
179
  disableEdit = props.disableEdit,
150
180
  readOnlyProp = props.readOnly,
151
181
  disabledProp = props.disabled,
@@ -153,6 +183,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
153
183
  schemaOnChange = props.onChange,
154
184
  defaultValue = props.defaultValue,
155
185
  multiple = props.multiple;
186
+ var isMultiple = multiple === true || multiple === 'true';
156
187
  var _resolveProScreenBind = resolveProScreenBinding({
157
188
  screen_structure: screen_structure,
158
189
  screen_structure_field: screen_structure_field,
@@ -165,6 +196,12 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
165
196
  var _useProBoundValue = useProBoundValue(fieldPath, unboundInit, FORM_EMPTY_ARRAY),
166
197
  value = _useProBoundValue.value,
167
198
  commit = _useProBoundValue.commit;
199
+ // 优先 dataSource,兼容部分 schema 透传为 options
200
+ var cascaderOptions = useMemo(function () {
201
+ if (Array.isArray(dataSource)) return dataSource;
202
+ if (Array.isArray(options)) return options;
203
+ return [];
204
+ }, [dataSource, options]);
168
205
  var handleChange = function handleChange(newValue, _data, extra) {
169
206
  var next = cascaderChangeToPath(newValue, extra);
170
207
  commit(next);
@@ -173,28 +210,27 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
173
210
 
174
211
  /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
175
212
  var displayValue = useMemo(function () {
176
- return normalizeCascaderPath(value, dataSource);
177
- }, [value, dataSource]);
213
+ return normalizeCascaderPath(value, cascaderOptions);
214
+ }, [value, cascaderOptions]);
178
215
 
179
216
  /**
180
- * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
181
- * 若传入完整路径 [父,子],会把「父」当成选中项,文案只有一级。
182
- * 组件展示应传「叶子」单元素数组 [leaf],内部 getLabelPath(叶子节点) 会生成多级展示。
183
- * 多选仍传 Fusion 所需的多个 value(与表单存值一致)。
217
+ * 回显兼容:
218
+ * - 多选:沿用路径数组
219
+ * - 单选:传叶子值(字符串);部分 Fusion 版本单选不接受数组 value,传数组会不显示
184
220
  */
185
221
  var valueForFusion = useMemo(function () {
186
222
  var path = displayValue;
187
- if (multiple) {
223
+ if (isMultiple) {
188
224
  return path;
189
225
  }
190
- if (path.length === 0) return [];
191
- return [path[path.length - 1]];
192
- }, [displayValue, multiple]);
226
+ if (path.length === 0) return '';
227
+ return path[path.length - 1];
228
+ }, [displayValue, isMultiple]);
193
229
 
194
230
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
195
231
  var schemaDisplayRender = props.displayRender;
196
232
  var pathDisplayRender = useCallback(function (labels, data) {
197
- var fullLabels = resolvePathLabels(dataSource, displayValue);
233
+ var fullLabels = resolvePathLabels(cascaderOptions, displayValue);
198
234
  if (fullLabels.length > 0) {
199
235
  return fullLabels.join(' / ');
200
236
  }
@@ -202,13 +238,13 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
202
238
  return schemaDisplayRender(labels, data);
203
239
  }
204
240
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
205
- }, [dataSource, displayValue, schemaDisplayRender]);
241
+ }, [cascaderOptions, displayValue, schemaDisplayRender]);
206
242
  return /*#__PURE__*/React.createElement("span", {
207
243
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
208
244
  }, /*#__PURE__*/React.createElement(_CascaderSelect, _extends({}, props, {
209
245
  readOnly: disableEdit ? true : readOnlyProp,
210
246
  disabled: disabledProp,
211
- dataSource: dataSource,
247
+ dataSource: cascaderOptions,
212
248
  value: valueForFusion,
213
249
  onChange: handleChange,
214
250
  displayRender: pathDisplayRender
@@ -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,12 +56,11 @@ 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;
@@ -44,12 +73,12 @@ function isValidPathInTree(dataSource, pathValues) {
44
73
  var _loop2 = function _loop2() {
45
74
  var pv = _step2.value;
46
75
  var node = level.find(function (n) {
47
- return String(n === null || n === void 0 ? void 0 : n.value) === String(pv);
76
+ return getNodeValue(n) === toStr(pv);
48
77
  });
49
78
  if (!node) return {
50
79
  v: false
51
80
  };
52
- level = Array.isArray(node.children) ? node.children : [];
81
+ level = getNodeChildren(node);
53
82
  },
54
83
  _ret;
55
84
  for (var _iterator2 = _createForOfIteratorHelperLoose(pathValues), _step2; !(_step2 = _iterator2()).done;) {
@@ -67,13 +96,13 @@ function findPathByNodeValue(dataSource, targetValue, parentPath) {
67
96
  if (!Array.isArray(dataSource) || targetValue === '') return [];
68
97
  for (var _iterator3 = _createForOfIteratorHelperLoose(dataSource), _step3; !(_step3 = _iterator3()).done;) {
69
98
  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) {
99
+ var curValue = getNodeValue(node);
100
+ if (!curValue) continue;
101
+ var nextPath = parentPath.concat(curValue);
102
+ if (curValue === toStr(targetValue)) {
74
103
  return nextPath;
75
104
  }
76
- var hit = findPathByNodeValue(node === null || node === void 0 ? void 0 : node.children, targetValue, nextPath);
105
+ var hit = findPathByNodeValue(getNodeChildren(node), targetValue, nextPath);
77
106
  if (hit.length > 0) return hit;
78
107
  }
79
108
  return [];
@@ -90,7 +119,7 @@ function normalizeCascaderPath(v, dataSource) {
90
119
  var path = v.filter(function (x) {
91
120
  return x != null && x !== '';
92
121
  }).map(function (x) {
93
- return String(x);
122
+ return toStr(x);
94
123
  });
95
124
  if (path.length === 0) return [];
96
125
  if (isValidPathInTree(dataSource, path)) return path;
@@ -98,14 +127,14 @@ function normalizeCascaderPath(v, dataSource) {
98
127
  }
99
128
  if (typeof v === 'number' && !Number.isNaN(v)) {
100
129
  /** 表单里有时是数字 id(2977),需要根据 dataSource 找完整路径 */
101
- return tryExpandByLeaf(String(v), [String(v)]);
130
+ return tryExpandByLeaf(toStr(v), [toStr(v)]);
102
131
  }
103
132
  if (typeof v === 'string' && v.trim()) {
104
133
  try {
105
134
  var parsed = JSON.parse(v);
106
135
  if (!Array.isArray(parsed)) return [];
107
136
  var _path = parsed.map(function (x) {
108
- return String(x);
137
+ return toStr(x);
109
138
  });
110
139
  if (_path.length === 0) return [];
111
140
  if (isValidPathInTree(dataSource, _path)) return _path;
@@ -151,6 +180,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
151
180
  screen_inner_id = props.screen_inner_id,
152
181
  range_inner_table = props.range_inner_table,
153
182
  dataSource = props.dataSource,
183
+ options = props.options,
154
184
  disableEdit = props.disableEdit,
155
185
  readOnlyProp = props.readOnly,
156
186
  disabledProp = props.disabled,
@@ -158,6 +188,7 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
158
188
  schemaOnChange = props.onChange,
159
189
  defaultValue = props.defaultValue,
160
190
  multiple = props.multiple;
191
+ var isMultiple = multiple === true || multiple === 'true';
161
192
  var _resolveProScreenBind = (0, _utils.resolveProScreenBinding)({
162
193
  screen_structure: screen_structure,
163
194
  screen_structure_field: screen_structure_field,
@@ -170,6 +201,12 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
170
201
  var _useProBoundValue = (0, _useProBoundValue2.useProBoundValue)(fieldPath, unboundInit, _useComponentContext.FORM_EMPTY_ARRAY),
171
202
  value = _useProBoundValue.value,
172
203
  commit = _useProBoundValue.commit;
204
+ // 优先 dataSource,兼容部分 schema 透传为 options
205
+ var cascaderOptions = useMemo(function () {
206
+ if (Array.isArray(dataSource)) return dataSource;
207
+ if (Array.isArray(options)) return options;
208
+ return [];
209
+ }, [dataSource, options]);
173
210
  var handleChange = function handleChange(newValue, _data, extra) {
174
211
  var next = cascaderChangeToPath(newValue, extra);
175
212
  commit(next);
@@ -178,28 +215,27 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
178
215
 
179
216
  /** 表单/接口:优先完整路径;若仅有叶子 id(如 2977)则由 dataSource 反查完整路径 */
180
217
  var displayValue = useMemo(function () {
181
- return normalizeCascaderPath(value, dataSource);
182
- }, [value, dataSource]);
218
+ return normalizeCascaderPath(value, cascaderOptions);
219
+ }, [value, cascaderOptions]);
183
220
 
184
221
  /**
185
- * Fusion 单选:官方约定受控 value 为 string[] | number[],且实现里只对数组取 value[0] 再查节点。
186
- * 若传入完整路径 [父,子],会把「父」当成选中项,文案只有一级。
187
- * 组件展示应传「叶子」单元素数组 [leaf],内部 getLabelPath(叶子节点) 会生成多级展示。
188
- * 多选仍传 Fusion 所需的多个 value(与表单存值一致)。
222
+ * 回显兼容:
223
+ * - 多选:沿用路径数组
224
+ * - 单选:传叶子值(字符串);部分 Fusion 版本单选不接受数组 value,传数组会不显示
189
225
  */
190
226
  var valueForFusion = useMemo(function () {
191
227
  var path = displayValue;
192
- if (multiple) {
228
+ if (isMultiple) {
193
229
  return path;
194
230
  }
195
- if (path.length === 0) return [];
196
- return [path[path.length - 1]];
197
- }, [displayValue, multiple]);
231
+ if (path.length === 0) return '';
232
+ return path[path.length - 1];
233
+ }, [displayValue, isMultiple]);
198
234
 
199
235
  /** dataSource 未就绪或异步时,仍用自定义文案兜底 */
200
236
  var schemaDisplayRender = props.displayRender;
201
237
  var pathDisplayRender = useCallback(function (labels, data) {
202
- var fullLabels = resolvePathLabels(dataSource, displayValue);
238
+ var fullLabels = resolvePathLabels(cascaderOptions, displayValue);
203
239
  if (fullLabels.length > 0) {
204
240
  return fullLabels.join(' / ');
205
241
  }
@@ -207,13 +243,13 @@ var ProCascaderSelect = function ProCascaderSelect(props) {
207
243
  return schemaDisplayRender(labels, data);
208
244
  }
209
245
  return (labels && labels.length ? labels.join(' / ') : '') || ((data === null || data === void 0 ? void 0 : data.label) != null ? String(data.label) : '');
210
- }, [dataSource, displayValue, schemaDisplayRender]);
246
+ }, [cascaderOptions, displayValue, schemaDisplayRender]);
211
247
  return /*#__PURE__*/React.createElement("span", {
212
248
  className: "field-wrapper " + (disableEdit ? 'disable-edit' : 'enable-edit')
213
249
  }, /*#__PURE__*/React.createElement(_cascaderSelect["default"], (0, _extends2["default"])({}, props, {
214
250
  readOnly: disableEdit ? true : readOnlyProp,
215
251
  disabled: disabledProp,
216
- dataSource: dataSource,
252
+ dataSource: cascaderOptions,
217
253
  value: valueForFusion,
218
254
  onChange: handleChange,
219
255
  displayRender: pathDisplayRender
@@ -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.74';
104
+ version = '1.0.76';
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.74';
109
+ version = '1.0.76';
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.74",
3
+ "version": "1.0.76",
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.74/build/lowcode/assets-prod.json"
104
+ "materialSchema": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.76/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.74/build/index.html"
109
+ "homepage": "https://unpkg.com/@openli1115/lowcode-edit-pro-table@1.0.76/build/index.html"
110
110
  }