@kne/super-select-plus 0.1.0 → 0.1.2
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.
- package/README.md +806 -37
- package/dist/{city-230db4c1.js → city-39702d3a.js} +1 -1
- package/dist/{city-230db4c1.js.map → city-39702d3a.js.map} +1 -1
- package/dist/{function-9db71e91.js → function-871311da.js} +1 -1
- package/dist/{function-9db71e91.js.map → function-871311da.js.map} +1 -1
- package/dist/index.css +32 -32
- package/dist/index.js +643 -237
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +427 -41
- package/dist/index.modern.js.map +1 -1
- package/dist/{industry-2e3bda15.js → industry-f570d549.js} +1 -1
- package/dist/{industry-2e3bda15.js.map → industry-f570d549.js.map} +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -71,11 +71,110 @@ const withLocale = createWithIntlProvider({
|
|
|
71
71
|
namespace: 'super-select-plus'
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
const _excluded$4 = ["data", "name", "type", "cache", "children", "getLabel", "dataFormat", "transformItem"];
|
|
74
|
+
const _excluded$4 = ["data", "name", "names", "type", "cache", "children", "getLabel", "dataFormat", "transformItem"];
|
|
75
75
|
const enumCache = new Map();
|
|
76
76
|
|
|
77
77
|
// 默认子组件渲染函数
|
|
78
|
-
const defaultChildren =
|
|
78
|
+
const defaultChildren = output => {
|
|
79
|
+
if (Array.isArray(output)) {
|
|
80
|
+
return output.map(item => get(item, 'label', '')).filter(Boolean).toString();
|
|
81
|
+
}
|
|
82
|
+
return get(output, 'label', '');
|
|
83
|
+
};
|
|
84
|
+
const getLabels = output => Array.isArray(output) ? output.map(item => get(item, 'label', '')).filter(Boolean) : output ? [get(output, 'label', '')].filter(Boolean) : [];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 将 EnumDisplay / FunctionEnum / IndustryEnum 解析结果转为选择器 value
|
|
88
|
+
* @param {Array|Object} items createEnumComponent children 第一个参数
|
|
89
|
+
* @param {Object} options valueKey / labelKey 字段映射
|
|
90
|
+
*/
|
|
91
|
+
const enumItemsToSelectValue = (items, {
|
|
92
|
+
valueKey: _valueKey = 'id',
|
|
93
|
+
labelKey: _labelKey = 'name'
|
|
94
|
+
} = {}) => (Array.isArray(items) ? items : [items]).filter(Boolean).map(item => {
|
|
95
|
+
var _item$id, _ref, _item$label;
|
|
96
|
+
return {
|
|
97
|
+
[_valueKey]: (_item$id = item.id) != null ? _item$id : item.code,
|
|
98
|
+
[_labelKey]: (_ref = (_item$label = item.label) != null ? _item$label : item.name) != null ? _ref : item.chName
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 将单个 Enum 解析结果转为选择器 value(单选)
|
|
104
|
+
*/
|
|
105
|
+
const enumItemToSelectValue = (item, options) => {
|
|
106
|
+
var _enumItemsToSelectVal;
|
|
107
|
+
return (_enumItemsToSelectVal = enumItemsToSelectValue(item, options)[0]) != null ? _enumItemsToSelectVal : null;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 将 AddressEnum 解析结果转为 SelectAddress value(支持 name 单值或 names 数组)
|
|
112
|
+
*/
|
|
113
|
+
const addressEnumToSelectValue = outputs => {
|
|
114
|
+
const list = Array.isArray(outputs) ? outputs : outputs ? [outputs] : [];
|
|
115
|
+
return list.filter(item => item == null ? void 0 : item.city).map(({
|
|
116
|
+
city
|
|
117
|
+
}) => _extends({
|
|
118
|
+
value: city.code,
|
|
119
|
+
label: city.name
|
|
120
|
+
}, city));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 将单个 AddressEnum 解析结果转为 SelectAddress value(单选)
|
|
125
|
+
*/
|
|
126
|
+
const addressEnumToSelectValueSingle = output => {
|
|
127
|
+
var _addressEnumToSelectV;
|
|
128
|
+
return (_addressEnumToSelectV = addressEnumToSelectValue(output)[0]) != null ? _addressEnumToSelectV : null;
|
|
129
|
+
};
|
|
130
|
+
const resolveOutput = (mapping, name, names) => {
|
|
131
|
+
if (names) {
|
|
132
|
+
return names.map(code => mapping.get(code));
|
|
133
|
+
}
|
|
134
|
+
return mapping.get(name);
|
|
135
|
+
};
|
|
136
|
+
const cacheOutput = (output, {
|
|
137
|
+
cacheKey,
|
|
138
|
+
type,
|
|
139
|
+
name,
|
|
140
|
+
names
|
|
141
|
+
}) => {
|
|
142
|
+
if (!cacheKey || !type) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (names) {
|
|
146
|
+
names.forEach((code, index) => {
|
|
147
|
+
const item = output[index];
|
|
148
|
+
if (item) {
|
|
149
|
+
enumCache.set(`${cacheKey}_${type}_${code}`, item);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (output) {
|
|
155
|
+
enumCache.set(`${cacheKey}_${type}_${name}`, output);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const getCachedOutput = ({
|
|
159
|
+
cacheKey,
|
|
160
|
+
type,
|
|
161
|
+
name,
|
|
162
|
+
names,
|
|
163
|
+
force
|
|
164
|
+
}) => {
|
|
165
|
+
var _enumCache$get;
|
|
166
|
+
if (force) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
if (names != null && names.length) {
|
|
170
|
+
const items = names.map(code => enumCache.get(`${cacheKey}_${type}_${code}`));
|
|
171
|
+
return items.every(Boolean) ? items : null;
|
|
172
|
+
}
|
|
173
|
+
if (name == null) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return (_enumCache$get = enumCache.get(`${cacheKey}_${type}_${name}`)) != null ? _enumCache$get : null;
|
|
177
|
+
};
|
|
79
178
|
|
|
80
179
|
/**
|
|
81
180
|
* 默认获取标签函数
|
|
@@ -104,18 +203,19 @@ const defaultTransformItem = (item, label) => _extends({}, item, {
|
|
|
104
203
|
/**
|
|
105
204
|
* 内部枚举显示组件
|
|
106
205
|
*/
|
|
107
|
-
const EnumDisplayInner = withFetch(
|
|
206
|
+
const EnumDisplayInner = withFetch(_ref2 => {
|
|
108
207
|
let {
|
|
109
208
|
data,
|
|
110
209
|
name,
|
|
210
|
+
names,
|
|
111
211
|
type,
|
|
112
212
|
cache: cacheKey,
|
|
113
213
|
children,
|
|
114
214
|
getLabel,
|
|
115
215
|
dataFormat,
|
|
116
216
|
transformItem
|
|
117
|
-
} =
|
|
118
|
-
props = _objectWithoutPropertiesLoose(
|
|
217
|
+
} = _ref2,
|
|
218
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded$4);
|
|
119
219
|
const {
|
|
120
220
|
locale
|
|
121
221
|
} = useIntl();
|
|
@@ -131,17 +231,18 @@ const EnumDisplayInner = withFetch(_ref => {
|
|
|
131
231
|
return [item.code, transformedItem];
|
|
132
232
|
}));
|
|
133
233
|
}, [formattedData, getLabel, locale, transformItem]);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
234
|
+
const output = useMemo(() => resolveOutput(mapping, name, names), [mapping, name, names]);
|
|
235
|
+
cacheOutput(output, {
|
|
236
|
+
cacheKey,
|
|
237
|
+
type,
|
|
238
|
+
name,
|
|
239
|
+
names
|
|
240
|
+
});
|
|
142
241
|
return children(output, _extends({}, props, {
|
|
143
242
|
locale,
|
|
144
|
-
mapping
|
|
243
|
+
mapping,
|
|
244
|
+
names,
|
|
245
|
+
labels: getLabels(output)
|
|
145
246
|
}));
|
|
146
247
|
});
|
|
147
248
|
|
|
@@ -149,9 +250,9 @@ const EnumDisplayInner = withFetch(_ref => {
|
|
|
149
250
|
* 枚举显示组件
|
|
150
251
|
*/
|
|
151
252
|
const EnumDisplay = withLocale(props => {
|
|
152
|
-
useIntl();
|
|
153
253
|
const {
|
|
154
254
|
name,
|
|
255
|
+
names,
|
|
155
256
|
type = 'default',
|
|
156
257
|
cache: cacheKey = 'ENUM_DATA',
|
|
157
258
|
force = false,
|
|
@@ -160,13 +261,18 @@ const EnumDisplay = withLocale(props => {
|
|
|
160
261
|
transformItem = defaultTransformItem,
|
|
161
262
|
children = defaultChildren
|
|
162
263
|
} = props;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
264
|
+
const cached = getCachedOutput({
|
|
265
|
+
cacheKey,
|
|
266
|
+
type,
|
|
267
|
+
name,
|
|
268
|
+
names,
|
|
269
|
+
force
|
|
270
|
+
});
|
|
271
|
+
if (cached) {
|
|
168
272
|
return children(cached, {
|
|
169
|
-
locale: props.locale
|
|
273
|
+
locale: props.locale,
|
|
274
|
+
names,
|
|
275
|
+
labels: getLabels(cached)
|
|
170
276
|
});
|
|
171
277
|
}
|
|
172
278
|
return /*#__PURE__*/jsx(EnumDisplayInner, _extends({}, props, {
|
|
@@ -202,16 +308,22 @@ const createEnumComponent = options => {
|
|
|
202
308
|
const EnumComponent = withLocale(props => {
|
|
203
309
|
const {
|
|
204
310
|
name,
|
|
311
|
+
names,
|
|
205
312
|
force = false,
|
|
206
313
|
children = defaultChildren
|
|
207
314
|
} = props;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
315
|
+
const cached = getCachedOutput({
|
|
316
|
+
cacheKey: cache,
|
|
317
|
+
type,
|
|
318
|
+
name,
|
|
319
|
+
names,
|
|
320
|
+
force
|
|
321
|
+
});
|
|
322
|
+
if (cached) {
|
|
213
323
|
return children(cached, {
|
|
214
|
-
locale: props.locale
|
|
324
|
+
locale: props.locale,
|
|
325
|
+
names,
|
|
326
|
+
labels: getLabels(cached)
|
|
215
327
|
});
|
|
216
328
|
}
|
|
217
329
|
return /*#__PURE__*/jsx(EnumDisplayInner, _extends({}, props, defaultApi, {
|
|
@@ -268,6 +380,151 @@ const FunctionEnum = createEnumComponent({
|
|
|
268
380
|
defaultApi: defaultFunctionApi
|
|
269
381
|
});
|
|
270
382
|
|
|
383
|
+
const getItemId = (item, valueKey = 'id') => {
|
|
384
|
+
var _ref, _ref2, _item$valueKey;
|
|
385
|
+
if (item == null) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
if (typeof item !== 'object') {
|
|
389
|
+
return item;
|
|
390
|
+
}
|
|
391
|
+
return (_ref = (_ref2 = (_item$valueKey = item[valueKey]) != null ? _item$valueKey : item.id) != null ? _ref2 : item.code) != null ? _ref : null;
|
|
392
|
+
};
|
|
393
|
+
const getItemLabel = (item, labelKey = 'name') => {
|
|
394
|
+
var _ref3, _ref4, _item$labelKey;
|
|
395
|
+
if (item == null || typeof item !== 'object') {
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
return (_ref3 = (_ref4 = (_item$labelKey = item[labelKey]) != null ? _item$labelKey : item.label) != null ? _ref4 : item.name) != null ? _ref3 : null;
|
|
399
|
+
};
|
|
400
|
+
const resolveItemFromNode = (item, node, {
|
|
401
|
+
valueKey: _valueKey = 'id',
|
|
402
|
+
labelKey: _labelKey = 'name'
|
|
403
|
+
} = {}) => {
|
|
404
|
+
const id = getItemId(item, _valueKey);
|
|
405
|
+
if (id == null) {
|
|
406
|
+
return item;
|
|
407
|
+
}
|
|
408
|
+
if (!node) {
|
|
409
|
+
const _label = getItemLabel(item, _labelKey);
|
|
410
|
+
if (typeof item === 'object') {
|
|
411
|
+
return _label != null && _label !== String(id) ? item : _extends({}, typeof item === 'object' ? item : {}, {
|
|
412
|
+
[_valueKey]: id,
|
|
413
|
+
[_labelKey]: _label || String(id)
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
[_valueKey]: id,
|
|
418
|
+
[_labelKey]: String(id)
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
const label = getItemLabel(item, _labelKey) || node[_labelKey] || node.name;
|
|
422
|
+
return _extends({}, node, typeof item === 'object' ? item : {}, {
|
|
423
|
+
[_valueKey]: id,
|
|
424
|
+
[_labelKey]: label
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 通过扁平 Map 解析 value(推荐,不依赖级联树结构)
|
|
430
|
+
*/
|
|
431
|
+
const resolveCascaderValueFromMap = (value, mapping, {
|
|
432
|
+
valueKey: _valueKey2 = 'id',
|
|
433
|
+
labelKey: _labelKey2 = 'name',
|
|
434
|
+
single: _single = false
|
|
435
|
+
} = {}) => {
|
|
436
|
+
if (value == null || !(mapping != null && mapping.size)) {
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
const resolveItem = item => resolveItemFromNode(item, mapping.get(getItemId(item, _valueKey2)), {
|
|
440
|
+
valueKey: _valueKey2,
|
|
441
|
+
labelKey: _labelKey2
|
|
442
|
+
});
|
|
443
|
+
if (_single) {
|
|
444
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
445
|
+
return current != null ? resolveItem(current) : value;
|
|
446
|
+
}
|
|
447
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 将仅含编码的 value 解析为含 label 的完整对象(城市选择器)
|
|
452
|
+
*/
|
|
453
|
+
const resolveAddressValue = (value, addressApi, {
|
|
454
|
+
single: _single2 = false
|
|
455
|
+
} = {}) => {
|
|
456
|
+
if (value == null || !addressApi) {
|
|
457
|
+
return value;
|
|
458
|
+
}
|
|
459
|
+
const resolveItem = item => {
|
|
460
|
+
var _item$value, _item$label;
|
|
461
|
+
if (item == null) {
|
|
462
|
+
return item;
|
|
463
|
+
}
|
|
464
|
+
const code = typeof item === 'object' ? (_item$value = item.value) != null ? _item$value : item.code : item;
|
|
465
|
+
if (!code) {
|
|
466
|
+
return typeof item === 'object' ? item : null;
|
|
467
|
+
}
|
|
468
|
+
const label = typeof item === 'object' ? (_item$label = item.label) != null ? _item$label : item.name : null;
|
|
469
|
+
if (label && label !== String(code)) {
|
|
470
|
+
return typeof item === 'object' ? item : {
|
|
471
|
+
value: code,
|
|
472
|
+
label
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const {
|
|
476
|
+
city
|
|
477
|
+
} = addressApi.getCity(code);
|
|
478
|
+
return city ? _extends({
|
|
479
|
+
value: code,
|
|
480
|
+
label: city.name
|
|
481
|
+
}, city) : {
|
|
482
|
+
value: code,
|
|
483
|
+
label: String(code)
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
if (_single2) {
|
|
487
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
488
|
+
return current != null ? resolveItem(current) : value;
|
|
489
|
+
}
|
|
490
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 判断是否需要将解析后的 value 同步回 onChange(仅编码 -> 含 label)
|
|
495
|
+
*/
|
|
496
|
+
const shouldSyncSelectValue = (value, resolved, {
|
|
497
|
+
valueKey: _valueKey3 = 'id',
|
|
498
|
+
labelKey: _labelKey3 = 'name',
|
|
499
|
+
single: _single3 = false
|
|
500
|
+
} = {}) => {
|
|
501
|
+
if (resolved == null || value == null) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
const needSyncItem = (original, resolvedItem) => {
|
|
505
|
+
const id = getItemId(original, _valueKey3);
|
|
506
|
+
const resolvedId = getItemId(resolvedItem, _valueKey3);
|
|
507
|
+
if (id == null || id !== resolvedId) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const resolvedLabel = getItemLabel(resolvedItem, _labelKey3);
|
|
511
|
+
if (!resolvedLabel || resolvedLabel === String(id)) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
const valueLabel = getItemLabel(original, _labelKey3);
|
|
515
|
+
return !valueLabel || valueLabel === String(id);
|
|
516
|
+
};
|
|
517
|
+
if (_single3) {
|
|
518
|
+
const original = Array.isArray(value) ? value[0] : value;
|
|
519
|
+
const resolvedItem = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
520
|
+
return needSyncItem(original, resolvedItem);
|
|
521
|
+
}
|
|
522
|
+
if (!Array.isArray(value) || !Array.isArray(resolved)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
return resolved.some((item, index) => needSyncItem(value[index], item));
|
|
526
|
+
};
|
|
527
|
+
|
|
271
528
|
const _excluded$3 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
|
|
272
529
|
const defaultFunctionData = () => {
|
|
273
530
|
return import('./function-99219f66.js').then(module => module['__esModule'] ? module.default : module);
|
|
@@ -330,6 +587,38 @@ const SelectFunctionInner = _ref => {
|
|
|
330
587
|
});
|
|
331
588
|
}, []);
|
|
332
589
|
const options = useMemo(() => transformToCascaderData$1(data, locale), [data, locale]);
|
|
590
|
+
const flatMapping = useMemo(() => {
|
|
591
|
+
const mapping = new Map();
|
|
592
|
+
data.forEach(item => {
|
|
593
|
+
mapping.set(item.code, _extends({}, item, {
|
|
594
|
+
id: item.code,
|
|
595
|
+
name: getLabelForLocal$3(item, locale)
|
|
596
|
+
}));
|
|
597
|
+
});
|
|
598
|
+
return mapping;
|
|
599
|
+
}, [data, locale]);
|
|
600
|
+
const normalizedValue = useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
601
|
+
valueKey: 'id',
|
|
602
|
+
labelKey: 'name',
|
|
603
|
+
single
|
|
604
|
+
}), [value, flatMapping, single]);
|
|
605
|
+
useEffect(() => {
|
|
606
|
+
if (!onChange || !flatMapping.size) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
610
|
+
valueKey: 'id',
|
|
611
|
+
labelKey: 'name',
|
|
612
|
+
single
|
|
613
|
+
});
|
|
614
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
615
|
+
valueKey: 'id',
|
|
616
|
+
labelKey: 'name',
|
|
617
|
+
single
|
|
618
|
+
})) {
|
|
619
|
+
onChange(resolved);
|
|
620
|
+
}
|
|
621
|
+
}, [value, flatMapping, single, onChange]);
|
|
333
622
|
const handleSearch = (searchText, {
|
|
334
623
|
mapping
|
|
335
624
|
}) => {
|
|
@@ -340,7 +629,7 @@ const SelectFunctionInner = _ref => {
|
|
|
340
629
|
});
|
|
341
630
|
};
|
|
342
631
|
return /*#__PURE__*/jsx(SelectCascader, _extends({}, props, {
|
|
343
|
-
value:
|
|
632
|
+
value: normalizedValue,
|
|
344
633
|
onChange: onChange,
|
|
345
634
|
single: single,
|
|
346
635
|
placeholder: placeholder || formatMessage({
|
|
@@ -461,6 +750,38 @@ const SelectIndustryInner = _ref => {
|
|
|
461
750
|
});
|
|
462
751
|
}, []);
|
|
463
752
|
const options = useMemo(() => transformToCascaderData(data, locale), [data, locale]);
|
|
753
|
+
const flatMapping = useMemo(() => {
|
|
754
|
+
const mapping = new Map();
|
|
755
|
+
data.filter(item => item.code !== '000').forEach(item => {
|
|
756
|
+
mapping.set(item.code, _extends({}, item, {
|
|
757
|
+
id: item.code,
|
|
758
|
+
name: getLabelForLocal$2(item, locale)
|
|
759
|
+
}));
|
|
760
|
+
});
|
|
761
|
+
return mapping;
|
|
762
|
+
}, [data, locale]);
|
|
763
|
+
const normalizedValue = useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
764
|
+
valueKey: 'id',
|
|
765
|
+
labelKey: 'name',
|
|
766
|
+
single
|
|
767
|
+
}), [value, flatMapping, single]);
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
if (!onChange || !flatMapping.size) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
773
|
+
valueKey: 'id',
|
|
774
|
+
labelKey: 'name',
|
|
775
|
+
single
|
|
776
|
+
});
|
|
777
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
778
|
+
valueKey: 'id',
|
|
779
|
+
labelKey: 'name',
|
|
780
|
+
single
|
|
781
|
+
})) {
|
|
782
|
+
onChange(resolved);
|
|
783
|
+
}
|
|
784
|
+
}, [value, flatMapping, single, onChange]);
|
|
464
785
|
const handleSearch = (searchText, {
|
|
465
786
|
mapping
|
|
466
787
|
}) => {
|
|
@@ -471,7 +792,7 @@ const SelectIndustryInner = _ref => {
|
|
|
471
792
|
});
|
|
472
793
|
};
|
|
473
794
|
return /*#__PURE__*/jsx(SelectCascader, _extends({}, props, {
|
|
474
|
-
value:
|
|
795
|
+
value: normalizedValue,
|
|
475
796
|
onChange: onChange,
|
|
476
797
|
single: single,
|
|
477
798
|
placeholder: placeholder || formatMessage({
|
|
@@ -494,8 +815,8 @@ const SelectIndustry = withLocale(SelectIndustryInner);
|
|
|
494
815
|
SelectIndustry.defaultData = defaultIndustryData;
|
|
495
816
|
SelectIndustry.Enum = IndustryEnum;
|
|
496
817
|
|
|
497
|
-
const _excluded$1 = ["data", "name", "children", "displayParent"],
|
|
498
|
-
_excluded2 = ["displayParent"];
|
|
818
|
+
const _excluded$1 = ["data", "name", "names", "children", "displayParent"],
|
|
819
|
+
_excluded2$1 = ["displayParent"];
|
|
499
820
|
const getLabelForLocal$1 = (item, locale) => {
|
|
500
821
|
if (locale === 'en-US') {
|
|
501
822
|
return get(item, 'enName') || get(item, 'name');
|
|
@@ -523,6 +844,7 @@ const AddressEnumInner = withFetch(_ref => {
|
|
|
523
844
|
let {
|
|
524
845
|
data,
|
|
525
846
|
name,
|
|
847
|
+
names,
|
|
526
848
|
children,
|
|
527
849
|
displayParent
|
|
528
850
|
} = _ref,
|
|
@@ -531,6 +853,33 @@ const AddressEnumInner = withFetch(_ref => {
|
|
|
531
853
|
locale
|
|
532
854
|
} = useIntl();
|
|
533
855
|
const addressApi = useMemo(() => createAddressApi(data), [data]);
|
|
856
|
+
const formatCityData = cityData => {
|
|
857
|
+
const {
|
|
858
|
+
city,
|
|
859
|
+
parent
|
|
860
|
+
} = cityData;
|
|
861
|
+
if (!city) {
|
|
862
|
+
return '';
|
|
863
|
+
}
|
|
864
|
+
if (displayParent && parent) {
|
|
865
|
+
return `${getLabelForLocal$1(parent, locale)}·${getLabelForLocal$1(city, locale)}`;
|
|
866
|
+
}
|
|
867
|
+
return getLabelForLocal$1(city, locale);
|
|
868
|
+
};
|
|
869
|
+
if (names != null && names.length) {
|
|
870
|
+
const outputs = names.map(code => addressApi.getCity(code));
|
|
871
|
+
const labels = outputs.map(formatCityData).filter(Boolean);
|
|
872
|
+
if (children) {
|
|
873
|
+
return children(outputs, _extends({
|
|
874
|
+
displayParent,
|
|
875
|
+
locale,
|
|
876
|
+
getLabelForLocal: getLabelForLocal$1,
|
|
877
|
+
names,
|
|
878
|
+
labels
|
|
879
|
+
}, props));
|
|
880
|
+
}
|
|
881
|
+
return labels.toString();
|
|
882
|
+
}
|
|
534
883
|
|
|
535
884
|
// 获取城市数据
|
|
536
885
|
const cityData = addressApi.getCity(name);
|
|
@@ -561,7 +910,7 @@ const AddressEnum = withLocale(props => {
|
|
|
561
910
|
const {
|
|
562
911
|
displayParent = false
|
|
563
912
|
} = props,
|
|
564
|
-
restProps = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
913
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
|
|
565
914
|
return /*#__PURE__*/jsx(AddressEnumInner, _extends({}, addressDefaultApi, {
|
|
566
915
|
displayParent: displayParent
|
|
567
916
|
}, restProps));
|
|
@@ -648,9 +997,10 @@ var classnames = createCommonjsModule(function (module) {
|
|
|
648
997
|
}());
|
|
649
998
|
});
|
|
650
999
|
|
|
651
|
-
var style = {"address":"
|
|
1000
|
+
var style = {"address":"kne-super-select-plus_MMoPf","is-popup":"kne-super-select-plus_bYKMf","title":"kne-super-select-plus_pKOHI","scroll-box":"kne-super-select-plus_MObpF","scroll-plus-box":"kne-super-select-plus_iKm8i","content":"kne-super-select-plus_BfCap","col-left":"kne-super-select-plus_BEChX","menu-list":"kne-super-select-plus_gXzFG","menu-item":"kne-super-select-plus_LasXn","col-right":"kne-super-select-plus_1jQmu","search-input":"kne-super-select-plus_YB45l","list":"kne-super-select-plus_Y-MIq","list-item":"kne-super-select-plus_6JEMZ","item-label":"kne-super-select-plus_nlduJ"};
|
|
652
1001
|
|
|
653
|
-
const _excluded = ["
|
|
1002
|
+
const _excluded = ["value", "single", "onChange"],
|
|
1003
|
+
_excluded2 = ["single", "isPopup", "showChinaQuan", "showForeignQuan"];
|
|
654
1004
|
const getLabelForLocal = (item, locale) => {
|
|
655
1005
|
if (locale === 'en-US') {
|
|
656
1006
|
return get(item, 'enName') || get(item, 'name');
|
|
@@ -965,21 +1315,53 @@ const SelectAddressInner = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
965
1315
|
const {
|
|
966
1316
|
formatMessage
|
|
967
1317
|
} = useIntl();
|
|
1318
|
+
const {
|
|
1319
|
+
value,
|
|
1320
|
+
single,
|
|
1321
|
+
onChange
|
|
1322
|
+
} = props,
|
|
1323
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1324
|
+
const [cityData, setCityData] = useState(null);
|
|
1325
|
+
useEffect(() => {
|
|
1326
|
+
defaultCityData().then(setCityData);
|
|
1327
|
+
}, []);
|
|
1328
|
+
const addressApi = useMemo(() => cityData ? createAddressApi(cityData) : null, [cityData]);
|
|
1329
|
+
const normalizedValue = useMemo(() => resolveAddressValue(value, addressApi, {
|
|
1330
|
+
single
|
|
1331
|
+
}), [value, addressApi, single]);
|
|
1332
|
+
useEffect(() => {
|
|
1333
|
+
if (!onChange || !addressApi) {
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
const resolved = resolveAddressValue(value, addressApi, {
|
|
1337
|
+
single
|
|
1338
|
+
});
|
|
1339
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
1340
|
+
valueKey: 'value',
|
|
1341
|
+
labelKey: 'label',
|
|
1342
|
+
single
|
|
1343
|
+
})) {
|
|
1344
|
+
onChange(resolved);
|
|
1345
|
+
}
|
|
1346
|
+
}, [value, addressApi, single, onChange]);
|
|
968
1347
|
return /*#__PURE__*/jsx(SelectInput, _extends({
|
|
969
1348
|
ref: ref
|
|
970
|
-
},
|
|
971
|
-
|
|
1349
|
+
}, restProps, {
|
|
1350
|
+
single: single,
|
|
1351
|
+
value: normalizedValue,
|
|
1352
|
+
onChange: onChange,
|
|
1353
|
+
placeholder: restProps.placeholder || formatMessage({
|
|
972
1354
|
id: 'addressPlaceholder'
|
|
973
1355
|
}, {
|
|
974
1356
|
defaultMessage: '请选择城市'
|
|
975
1357
|
}),
|
|
976
1358
|
children: contextProps => {
|
|
977
1359
|
const {
|
|
978
|
-
value,
|
|
1360
|
+
value: currentValue,
|
|
979
1361
|
setValue
|
|
980
1362
|
} = contextProps;
|
|
981
1363
|
return /*#__PURE__*/jsx(AddressInner, {
|
|
982
|
-
value:
|
|
1364
|
+
value: currentValue,
|
|
983
1365
|
setValue: setValue,
|
|
984
1366
|
props: props
|
|
985
1367
|
});
|
|
@@ -993,7 +1375,7 @@ const SelectAddress = withLocale(_ref => {
|
|
|
993
1375
|
showChinaQuan = false,
|
|
994
1376
|
showForeignQuan = false
|
|
995
1377
|
} = _ref,
|
|
996
|
-
props = _objectWithoutPropertiesLoose(_ref,
|
|
1378
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
997
1379
|
return /*#__PURE__*/jsx(SelectAddressInner, _extends({
|
|
998
1380
|
single: single,
|
|
999
1381
|
isPopup: isPopup,
|
|
@@ -1013,8 +1395,12 @@ var index = {
|
|
|
1013
1395
|
AddressEnum,
|
|
1014
1396
|
FunctionEnum,
|
|
1015
1397
|
IndustryEnum,
|
|
1016
|
-
EnumDisplay
|
|
1398
|
+
EnumDisplay,
|
|
1399
|
+
enumItemsToSelectValue,
|
|
1400
|
+
enumItemToSelectValue,
|
|
1401
|
+
addressEnumToSelectValue,
|
|
1402
|
+
addressEnumToSelectValueSingle
|
|
1017
1403
|
};
|
|
1018
1404
|
|
|
1019
|
-
export { AddressEnum, EnumDisplay, FunctionEnum, IndustryEnum, SelectAddress, SelectFunction, SelectIndustry, createAddressApi, index as default };
|
|
1405
|
+
export { AddressEnum, EnumDisplay, FunctionEnum, IndustryEnum, SelectAddress, SelectFunction, SelectIndustry, addressEnumToSelectValue, addressEnumToSelectValueSingle, createAddressApi, index as default, enumItemToSelectValue, enumItemsToSelectValue };
|
|
1020
1406
|
//# sourceMappingURL=index.modern.js.map
|