@kne/super-select-plus 0.1.1 → 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 +646 -17
- package/dist/index.js +374 -34
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +335 -16
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -89,17 +89,67 @@ const defaultChildren = output => {
|
|
|
89
89
|
return get__default["default"](output, 'label', '');
|
|
90
90
|
};
|
|
91
91
|
const getLabels = output => Array.isArray(output) ? output.map(item => get__default["default"](item, 'label', '')).filter(Boolean) : output ? [get__default["default"](output, 'label', '')].filter(Boolean) : [];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 将 EnumDisplay / FunctionEnum / IndustryEnum 解析结果转为选择器 value
|
|
95
|
+
* @param {Array|Object} items createEnumComponent children 第一个参数
|
|
96
|
+
* @param {Object} options valueKey / labelKey 字段映射
|
|
97
|
+
*/
|
|
98
|
+
const enumItemsToSelectValue = function (items, _temp) {
|
|
99
|
+
let _ref = _temp === void 0 ? {} : _temp,
|
|
100
|
+
_ref$valueKey = _ref.valueKey,
|
|
101
|
+
valueKey = _ref$valueKey === void 0 ? 'id' : _ref$valueKey,
|
|
102
|
+
_ref$labelKey = _ref.labelKey,
|
|
103
|
+
labelKey = _ref$labelKey === void 0 ? 'name' : _ref$labelKey;
|
|
104
|
+
return (Array.isArray(items) ? items : [items]).filter(Boolean).map(item => {
|
|
105
|
+
var _item$id, _ref2, _item$label;
|
|
106
|
+
return {
|
|
107
|
+
[valueKey]: (_item$id = item.id) != null ? _item$id : item.code,
|
|
108
|
+
[labelKey]: (_ref2 = (_item$label = item.label) != null ? _item$label : item.name) != null ? _ref2 : item.chName
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 将单个 Enum 解析结果转为选择器 value(单选)
|
|
115
|
+
*/
|
|
116
|
+
const enumItemToSelectValue = (item, options) => {
|
|
117
|
+
var _enumItemsToSelectVal;
|
|
118
|
+
return (_enumItemsToSelectVal = enumItemsToSelectValue(item, options)[0]) != null ? _enumItemsToSelectVal : null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 将 AddressEnum 解析结果转为 SelectAddress value(支持 name 单值或 names 数组)
|
|
123
|
+
*/
|
|
124
|
+
const addressEnumToSelectValue = outputs => {
|
|
125
|
+
const list = Array.isArray(outputs) ? outputs : outputs ? [outputs] : [];
|
|
126
|
+
return list.filter(item => item == null ? void 0 : item.city).map(_ref3 => {
|
|
127
|
+
let city = _ref3.city;
|
|
128
|
+
return _extends({
|
|
129
|
+
value: city.code,
|
|
130
|
+
label: city.name
|
|
131
|
+
}, city);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 将单个 AddressEnum 解析结果转为 SelectAddress value(单选)
|
|
137
|
+
*/
|
|
138
|
+
const addressEnumToSelectValueSingle = output => {
|
|
139
|
+
var _addressEnumToSelectV;
|
|
140
|
+
return (_addressEnumToSelectV = addressEnumToSelectValue(output)[0]) != null ? _addressEnumToSelectV : null;
|
|
141
|
+
};
|
|
92
142
|
const resolveOutput = (mapping, name, names) => {
|
|
93
143
|
if (names) {
|
|
94
144
|
return names.map(code => mapping.get(code));
|
|
95
145
|
}
|
|
96
146
|
return mapping.get(name);
|
|
97
147
|
};
|
|
98
|
-
const cacheOutput = (output,
|
|
99
|
-
let cacheKey =
|
|
100
|
-
type =
|
|
101
|
-
name =
|
|
102
|
-
names =
|
|
148
|
+
const cacheOutput = (output, _ref4) => {
|
|
149
|
+
let cacheKey = _ref4.cacheKey,
|
|
150
|
+
type = _ref4.type,
|
|
151
|
+
name = _ref4.name,
|
|
152
|
+
names = _ref4.names;
|
|
103
153
|
if (!cacheKey || !type) {
|
|
104
154
|
return;
|
|
105
155
|
}
|
|
@@ -116,13 +166,13 @@ const cacheOutput = (output, _ref) => {
|
|
|
116
166
|
enumCache.set(cacheKey + "_" + type + "_" + name, output);
|
|
117
167
|
}
|
|
118
168
|
};
|
|
119
|
-
const getCachedOutput =
|
|
169
|
+
const getCachedOutput = _ref5 => {
|
|
120
170
|
var _enumCache$get;
|
|
121
|
-
let cacheKey =
|
|
122
|
-
type =
|
|
123
|
-
name =
|
|
124
|
-
names =
|
|
125
|
-
force =
|
|
171
|
+
let cacheKey = _ref5.cacheKey,
|
|
172
|
+
type = _ref5.type,
|
|
173
|
+
name = _ref5.name,
|
|
174
|
+
names = _ref5.names,
|
|
175
|
+
force = _ref5.force;
|
|
126
176
|
if (force) {
|
|
127
177
|
return null;
|
|
128
178
|
}
|
|
@@ -163,17 +213,17 @@ const defaultTransformItem = (item, label) => _extends({}, item, {
|
|
|
163
213
|
/**
|
|
164
214
|
* 内部枚举显示组件
|
|
165
215
|
*/
|
|
166
|
-
const EnumDisplayInner = reactFetch.withFetch(
|
|
167
|
-
let data =
|
|
168
|
-
name =
|
|
169
|
-
names =
|
|
170
|
-
type =
|
|
171
|
-
cacheKey =
|
|
172
|
-
children =
|
|
173
|
-
getLabel =
|
|
174
|
-
dataFormat =
|
|
175
|
-
transformItem =
|
|
176
|
-
props = _objectWithoutPropertiesLoose(
|
|
216
|
+
const EnumDisplayInner = reactFetch.withFetch(_ref6 => {
|
|
217
|
+
let data = _ref6.data,
|
|
218
|
+
name = _ref6.name,
|
|
219
|
+
names = _ref6.names,
|
|
220
|
+
type = _ref6.type,
|
|
221
|
+
cacheKey = _ref6.cache,
|
|
222
|
+
children = _ref6.children,
|
|
223
|
+
getLabel = _ref6.getLabel,
|
|
224
|
+
dataFormat = _ref6.dataFormat,
|
|
225
|
+
transformItem = _ref6.transformItem,
|
|
226
|
+
props = _objectWithoutPropertiesLoose(_ref6, _excluded$4);
|
|
177
227
|
const _useIntl = reactIntl.useIntl(),
|
|
178
228
|
locale = _useIntl.locale;
|
|
179
229
|
|
|
@@ -343,6 +393,165 @@ const FunctionEnum = createEnumComponent({
|
|
|
343
393
|
defaultApi: defaultFunctionApi
|
|
344
394
|
});
|
|
345
395
|
|
|
396
|
+
const getItemId = function (item, valueKey) {
|
|
397
|
+
var _ref, _ref2, _item$valueKey;
|
|
398
|
+
if (valueKey === void 0) {
|
|
399
|
+
valueKey = 'id';
|
|
400
|
+
}
|
|
401
|
+
if (item == null) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
if (typeof item !== 'object') {
|
|
405
|
+
return item;
|
|
406
|
+
}
|
|
407
|
+
return (_ref = (_ref2 = (_item$valueKey = item[valueKey]) != null ? _item$valueKey : item.id) != null ? _ref2 : item.code) != null ? _ref : null;
|
|
408
|
+
};
|
|
409
|
+
const getItemLabel = function (item, labelKey) {
|
|
410
|
+
var _ref3, _ref4, _item$labelKey;
|
|
411
|
+
if (labelKey === void 0) {
|
|
412
|
+
labelKey = 'name';
|
|
413
|
+
}
|
|
414
|
+
if (item == null || typeof item !== 'object') {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
return (_ref3 = (_ref4 = (_item$labelKey = item[labelKey]) != null ? _item$labelKey : item.label) != null ? _ref4 : item.name) != null ? _ref3 : null;
|
|
418
|
+
};
|
|
419
|
+
const resolveItemFromNode = function (item, node, _temp) {
|
|
420
|
+
let _ref5 = _temp === void 0 ? {} : _temp,
|
|
421
|
+
_ref5$valueKey = _ref5.valueKey,
|
|
422
|
+
valueKey = _ref5$valueKey === void 0 ? 'id' : _ref5$valueKey,
|
|
423
|
+
_ref5$labelKey = _ref5.labelKey,
|
|
424
|
+
labelKey = _ref5$labelKey === void 0 ? 'name' : _ref5$labelKey;
|
|
425
|
+
const id = getItemId(item, valueKey);
|
|
426
|
+
if (id == null) {
|
|
427
|
+
return item;
|
|
428
|
+
}
|
|
429
|
+
if (!node) {
|
|
430
|
+
const label = getItemLabel(item, labelKey);
|
|
431
|
+
if (typeof item === 'object') {
|
|
432
|
+
return label != null && label !== String(id) ? item : _extends({}, typeof item === 'object' ? item : {}, {
|
|
433
|
+
[valueKey]: id,
|
|
434
|
+
[labelKey]: label || String(id)
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
[valueKey]: id,
|
|
439
|
+
[labelKey]: String(id)
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
const label = getItemLabel(item, labelKey) || node[labelKey] || node.name;
|
|
443
|
+
return _extends({}, node, typeof item === 'object' ? item : {}, {
|
|
444
|
+
[valueKey]: id,
|
|
445
|
+
[labelKey]: label
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 通过扁平 Map 解析 value(推荐,不依赖级联树结构)
|
|
451
|
+
*/
|
|
452
|
+
const resolveCascaderValueFromMap = function (value, mapping, _temp2) {
|
|
453
|
+
let _ref6 = _temp2 === void 0 ? {} : _temp2,
|
|
454
|
+
_ref6$valueKey = _ref6.valueKey,
|
|
455
|
+
valueKey = _ref6$valueKey === void 0 ? 'id' : _ref6$valueKey,
|
|
456
|
+
_ref6$labelKey = _ref6.labelKey,
|
|
457
|
+
labelKey = _ref6$labelKey === void 0 ? 'name' : _ref6$labelKey,
|
|
458
|
+
_ref6$single = _ref6.single,
|
|
459
|
+
single = _ref6$single === void 0 ? false : _ref6$single;
|
|
460
|
+
if (value == null || !(mapping != null && mapping.size)) {
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
463
|
+
const resolveItem = item => resolveItemFromNode(item, mapping.get(getItemId(item, valueKey)), {
|
|
464
|
+
valueKey,
|
|
465
|
+
labelKey
|
|
466
|
+
});
|
|
467
|
+
if (single) {
|
|
468
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
469
|
+
return current != null ? resolveItem(current) : value;
|
|
470
|
+
}
|
|
471
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* 将仅含编码的 value 解析为含 label 的完整对象(城市选择器)
|
|
476
|
+
*/
|
|
477
|
+
const resolveAddressValue = function (value, addressApi, _temp3) {
|
|
478
|
+
let _ref8 = _temp3 === void 0 ? {} : _temp3,
|
|
479
|
+
_ref8$single = _ref8.single,
|
|
480
|
+
single = _ref8$single === void 0 ? false : _ref8$single;
|
|
481
|
+
if (value == null || !addressApi) {
|
|
482
|
+
return value;
|
|
483
|
+
}
|
|
484
|
+
const resolveItem = item => {
|
|
485
|
+
var _item$value, _item$label;
|
|
486
|
+
if (item == null) {
|
|
487
|
+
return item;
|
|
488
|
+
}
|
|
489
|
+
const code = typeof item === 'object' ? (_item$value = item.value) != null ? _item$value : item.code : item;
|
|
490
|
+
if (!code) {
|
|
491
|
+
return typeof item === 'object' ? item : null;
|
|
492
|
+
}
|
|
493
|
+
const label = typeof item === 'object' ? (_item$label = item.label) != null ? _item$label : item.name : null;
|
|
494
|
+
if (label && label !== String(code)) {
|
|
495
|
+
return typeof item === 'object' ? item : {
|
|
496
|
+
value: code,
|
|
497
|
+
label
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const _addressApi$getCity = addressApi.getCity(code),
|
|
501
|
+
city = _addressApi$getCity.city;
|
|
502
|
+
return city ? _extends({
|
|
503
|
+
value: code,
|
|
504
|
+
label: city.name
|
|
505
|
+
}, city) : {
|
|
506
|
+
value: code,
|
|
507
|
+
label: String(code)
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
if (single) {
|
|
511
|
+
const current = Array.isArray(value) ? value[0] : value;
|
|
512
|
+
return current != null ? resolveItem(current) : value;
|
|
513
|
+
}
|
|
514
|
+
return Array.isArray(value) ? value.map(resolveItem) : value;
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* 判断是否需要将解析后的 value 同步回 onChange(仅编码 -> 含 label)
|
|
519
|
+
*/
|
|
520
|
+
const shouldSyncSelectValue = function (value, resolved, _temp4) {
|
|
521
|
+
let _ref9 = _temp4 === void 0 ? {} : _temp4,
|
|
522
|
+
_ref9$valueKey = _ref9.valueKey,
|
|
523
|
+
valueKey = _ref9$valueKey === void 0 ? 'id' : _ref9$valueKey,
|
|
524
|
+
_ref9$labelKey = _ref9.labelKey,
|
|
525
|
+
labelKey = _ref9$labelKey === void 0 ? 'name' : _ref9$labelKey,
|
|
526
|
+
_ref9$single = _ref9.single,
|
|
527
|
+
single = _ref9$single === void 0 ? false : _ref9$single;
|
|
528
|
+
if (resolved == null || value == null) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
const needSyncItem = (original, resolvedItem) => {
|
|
532
|
+
const id = getItemId(original, valueKey);
|
|
533
|
+
const resolvedId = getItemId(resolvedItem, valueKey);
|
|
534
|
+
if (id == null || id !== resolvedId) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
const resolvedLabel = getItemLabel(resolvedItem, labelKey);
|
|
538
|
+
if (!resolvedLabel || resolvedLabel === String(id)) {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
const valueLabel = getItemLabel(original, labelKey);
|
|
542
|
+
return !valueLabel || valueLabel === String(id);
|
|
543
|
+
};
|
|
544
|
+
if (single) {
|
|
545
|
+
const original = Array.isArray(value) ? value[0] : value;
|
|
546
|
+
const resolvedItem = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
547
|
+
return needSyncItem(original, resolvedItem);
|
|
548
|
+
}
|
|
549
|
+
if (!Array.isArray(value) || !Array.isArray(resolved)) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
return resolved.some((item, index) => needSyncItem(value[index], item));
|
|
553
|
+
};
|
|
554
|
+
|
|
346
555
|
const _excluded$3 = ["value", "onChange", "single", "placeholder", "isPopup", "overlayWidth", "apis", "onSearch"];
|
|
347
556
|
const defaultFunctionData = () => {
|
|
348
557
|
return Promise.resolve().then(function () { return require('./function-871311da.js'); }).then(module => module['__esModule'] ? module.default : module);
|
|
@@ -407,6 +616,38 @@ const SelectFunctionInner = _ref => {
|
|
|
407
616
|
});
|
|
408
617
|
}, []);
|
|
409
618
|
const options = react.useMemo(() => transformToCascaderData$1(data, locale), [data, locale]);
|
|
619
|
+
const flatMapping = react.useMemo(() => {
|
|
620
|
+
const mapping = new Map();
|
|
621
|
+
data.forEach(item => {
|
|
622
|
+
mapping.set(item.code, _extends({}, item, {
|
|
623
|
+
id: item.code,
|
|
624
|
+
name: getLabelForLocal$3(item, locale)
|
|
625
|
+
}));
|
|
626
|
+
});
|
|
627
|
+
return mapping;
|
|
628
|
+
}, [data, locale]);
|
|
629
|
+
const normalizedValue = react.useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
630
|
+
valueKey: 'id',
|
|
631
|
+
labelKey: 'name',
|
|
632
|
+
single
|
|
633
|
+
}), [value, flatMapping, single]);
|
|
634
|
+
react.useEffect(() => {
|
|
635
|
+
if (!onChange || !flatMapping.size) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
639
|
+
valueKey: 'id',
|
|
640
|
+
labelKey: 'name',
|
|
641
|
+
single
|
|
642
|
+
});
|
|
643
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
644
|
+
valueKey: 'id',
|
|
645
|
+
labelKey: 'name',
|
|
646
|
+
single
|
|
647
|
+
})) {
|
|
648
|
+
onChange(resolved);
|
|
649
|
+
}
|
|
650
|
+
}, [value, flatMapping, single, onChange]);
|
|
410
651
|
const handleSearch = (searchText, _ref2) => {
|
|
411
652
|
let mapping = _ref2.mapping;
|
|
412
653
|
if (!searchText) return Array.from(mapping.values());
|
|
@@ -416,7 +657,7 @@ const SelectFunctionInner = _ref => {
|
|
|
416
657
|
});
|
|
417
658
|
};
|
|
418
659
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
419
|
-
value:
|
|
660
|
+
value: normalizedValue,
|
|
420
661
|
onChange: onChange,
|
|
421
662
|
single: single,
|
|
422
663
|
placeholder: placeholder || formatMessage({
|
|
@@ -539,6 +780,38 @@ const SelectIndustryInner = _ref => {
|
|
|
539
780
|
});
|
|
540
781
|
}, []);
|
|
541
782
|
const options = react.useMemo(() => transformToCascaderData(data, locale), [data, locale]);
|
|
783
|
+
const flatMapping = react.useMemo(() => {
|
|
784
|
+
const mapping = new Map();
|
|
785
|
+
data.filter(item => item.code !== '000').forEach(item => {
|
|
786
|
+
mapping.set(item.code, _extends({}, item, {
|
|
787
|
+
id: item.code,
|
|
788
|
+
name: getLabelForLocal$2(item, locale)
|
|
789
|
+
}));
|
|
790
|
+
});
|
|
791
|
+
return mapping;
|
|
792
|
+
}, [data, locale]);
|
|
793
|
+
const normalizedValue = react.useMemo(() => resolveCascaderValueFromMap(value, flatMapping, {
|
|
794
|
+
valueKey: 'id',
|
|
795
|
+
labelKey: 'name',
|
|
796
|
+
single
|
|
797
|
+
}), [value, flatMapping, single]);
|
|
798
|
+
react.useEffect(() => {
|
|
799
|
+
if (!onChange || !flatMapping.size) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
const resolved = resolveCascaderValueFromMap(value, flatMapping, {
|
|
803
|
+
valueKey: 'id',
|
|
804
|
+
labelKey: 'name',
|
|
805
|
+
single
|
|
806
|
+
});
|
|
807
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
808
|
+
valueKey: 'id',
|
|
809
|
+
labelKey: 'name',
|
|
810
|
+
single
|
|
811
|
+
})) {
|
|
812
|
+
onChange(resolved);
|
|
813
|
+
}
|
|
814
|
+
}, [value, flatMapping, single, onChange]);
|
|
542
815
|
const handleSearch = (searchText, _ref2) => {
|
|
543
816
|
let mapping = _ref2.mapping;
|
|
544
817
|
if (!searchText) return Array.from(mapping.values());
|
|
@@ -548,7 +821,7 @@ const SelectIndustryInner = _ref => {
|
|
|
548
821
|
});
|
|
549
822
|
};
|
|
550
823
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectCascader, _extends({}, props, {
|
|
551
|
-
value:
|
|
824
|
+
value: normalizedValue,
|
|
552
825
|
onChange: onChange,
|
|
553
826
|
single: single,
|
|
554
827
|
placeholder: placeholder || formatMessage({
|
|
@@ -571,8 +844,8 @@ const SelectIndustry = withLocale(SelectIndustryInner);
|
|
|
571
844
|
SelectIndustry.defaultData = defaultIndustryData;
|
|
572
845
|
SelectIndustry.Enum = IndustryEnum;
|
|
573
846
|
|
|
574
|
-
const _excluded$1 = ["data", "name", "children", "displayParent"],
|
|
575
|
-
_excluded2 = ["displayParent"];
|
|
847
|
+
const _excluded$1 = ["data", "name", "names", "children", "displayParent"],
|
|
848
|
+
_excluded2$1 = ["displayParent"];
|
|
576
849
|
const getLabelForLocal$1 = (item, locale) => {
|
|
577
850
|
if (locale === 'en-US') {
|
|
578
851
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -599,12 +872,38 @@ const addressDefaultApi = {
|
|
|
599
872
|
const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
600
873
|
let data = _ref.data,
|
|
601
874
|
name = _ref.name,
|
|
875
|
+
names = _ref.names,
|
|
602
876
|
children = _ref.children,
|
|
603
877
|
displayParent = _ref.displayParent,
|
|
604
878
|
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
605
879
|
const _useIntl = reactIntl.useIntl(),
|
|
606
880
|
locale = _useIntl.locale;
|
|
607
881
|
const addressApi = react.useMemo(() => createAddressApi(data), [data]);
|
|
882
|
+
const formatCityData = cityData => {
|
|
883
|
+
const city = cityData.city,
|
|
884
|
+
parent = cityData.parent;
|
|
885
|
+
if (!city) {
|
|
886
|
+
return '';
|
|
887
|
+
}
|
|
888
|
+
if (displayParent && parent) {
|
|
889
|
+
return getLabelForLocal$1(parent, locale) + "\xB7" + getLabelForLocal$1(city, locale);
|
|
890
|
+
}
|
|
891
|
+
return getLabelForLocal$1(city, locale);
|
|
892
|
+
};
|
|
893
|
+
if (names != null && names.length) {
|
|
894
|
+
const outputs = names.map(code => addressApi.getCity(code));
|
|
895
|
+
const labels = outputs.map(formatCityData).filter(Boolean);
|
|
896
|
+
if (children) {
|
|
897
|
+
return children(outputs, _extends({
|
|
898
|
+
displayParent,
|
|
899
|
+
locale,
|
|
900
|
+
getLabelForLocal: getLabelForLocal$1,
|
|
901
|
+
names,
|
|
902
|
+
labels
|
|
903
|
+
}, props));
|
|
904
|
+
}
|
|
905
|
+
return labels.toString();
|
|
906
|
+
}
|
|
608
907
|
|
|
609
908
|
// 获取城市数据
|
|
610
909
|
const cityData = addressApi.getCity(name);
|
|
@@ -632,7 +931,7 @@ const AddressEnumInner = reactFetch.withFetch(_ref => {
|
|
|
632
931
|
const AddressEnum = withLocale(props => {
|
|
633
932
|
const _props$displayParent = props.displayParent,
|
|
634
933
|
displayParent = _props$displayParent === void 0 ? false : _props$displayParent,
|
|
635
|
-
restProps = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
934
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
|
|
636
935
|
return /*#__PURE__*/jsxRuntime.jsx(AddressEnumInner, _extends({}, addressDefaultApi, {
|
|
637
936
|
displayParent: displayParent
|
|
638
937
|
}, restProps));
|
|
@@ -721,7 +1020,8 @@ var classnames = createCommonjsModule(function (module) {
|
|
|
721
1020
|
|
|
722
1021
|
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"};
|
|
723
1022
|
|
|
724
|
-
const _excluded = ["
|
|
1023
|
+
const _excluded = ["value", "single", "onChange"],
|
|
1024
|
+
_excluded2 = ["single", "isPopup", "showChinaQuan", "showForeignQuan"];
|
|
725
1025
|
const getLabelForLocal = (item, locale) => {
|
|
726
1026
|
if (locale === 'en-US') {
|
|
727
1027
|
return get__default["default"](item, 'enName') || get__default["default"](item, 'name');
|
|
@@ -1036,19 +1336,51 @@ const AddressInner = _ref2 => {
|
|
|
1036
1336
|
const SelectAddressInner = /*#__PURE__*/react.forwardRef((props, ref) => {
|
|
1037
1337
|
const _useIntl2 = reactIntl.useIntl(),
|
|
1038
1338
|
formatMessage = _useIntl2.formatMessage;
|
|
1339
|
+
const value = props.value,
|
|
1340
|
+
single = props.single,
|
|
1341
|
+
onChange = props.onChange,
|
|
1342
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
1343
|
+
const _useState4 = react.useState(null),
|
|
1344
|
+
cityData = _useState4[0],
|
|
1345
|
+
setCityData = _useState4[1];
|
|
1346
|
+
react.useEffect(() => {
|
|
1347
|
+
defaultCityData().then(setCityData);
|
|
1348
|
+
}, []);
|
|
1349
|
+
const addressApi = react.useMemo(() => cityData ? createAddressApi(cityData) : null, [cityData]);
|
|
1350
|
+
const normalizedValue = react.useMemo(() => resolveAddressValue(value, addressApi, {
|
|
1351
|
+
single
|
|
1352
|
+
}), [value, addressApi, single]);
|
|
1353
|
+
react.useEffect(() => {
|
|
1354
|
+
if (!onChange || !addressApi) {
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
const resolved = resolveAddressValue(value, addressApi, {
|
|
1358
|
+
single
|
|
1359
|
+
});
|
|
1360
|
+
if (shouldSyncSelectValue(value, resolved, {
|
|
1361
|
+
valueKey: 'value',
|
|
1362
|
+
labelKey: 'label',
|
|
1363
|
+
single
|
|
1364
|
+
})) {
|
|
1365
|
+
onChange(resolved);
|
|
1366
|
+
}
|
|
1367
|
+
}, [value, addressApi, single, onChange]);
|
|
1039
1368
|
return /*#__PURE__*/jsxRuntime.jsx(superSelect.SelectInput, _extends({
|
|
1040
1369
|
ref: ref
|
|
1041
|
-
},
|
|
1042
|
-
|
|
1370
|
+
}, restProps, {
|
|
1371
|
+
single: single,
|
|
1372
|
+
value: normalizedValue,
|
|
1373
|
+
onChange: onChange,
|
|
1374
|
+
placeholder: restProps.placeholder || formatMessage({
|
|
1043
1375
|
id: 'addressPlaceholder'
|
|
1044
1376
|
}, {
|
|
1045
1377
|
defaultMessage: '请选择城市'
|
|
1046
1378
|
}),
|
|
1047
1379
|
children: contextProps => {
|
|
1048
|
-
const
|
|
1380
|
+
const currentValue = contextProps.value,
|
|
1049
1381
|
setValue = contextProps.setValue;
|
|
1050
1382
|
return /*#__PURE__*/jsxRuntime.jsx(AddressInner, {
|
|
1051
|
-
value:
|
|
1383
|
+
value: currentValue,
|
|
1052
1384
|
setValue: setValue,
|
|
1053
1385
|
props: props
|
|
1054
1386
|
});
|
|
@@ -1064,7 +1396,7 @@ const SelectAddress = withLocale(_ref4 => {
|
|
|
1064
1396
|
showChinaQuan = _ref4$showChinaQuan === void 0 ? false : _ref4$showChinaQuan,
|
|
1065
1397
|
_ref4$showForeignQuan = _ref4.showForeignQuan,
|
|
1066
1398
|
showForeignQuan = _ref4$showForeignQuan === void 0 ? false : _ref4$showForeignQuan,
|
|
1067
|
-
props = _objectWithoutPropertiesLoose(_ref4,
|
|
1399
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
1068
1400
|
return /*#__PURE__*/jsxRuntime.jsx(SelectAddressInner, _extends({
|
|
1069
1401
|
single: single,
|
|
1070
1402
|
isPopup: isPopup,
|
|
@@ -1084,7 +1416,11 @@ var index = {
|
|
|
1084
1416
|
AddressEnum,
|
|
1085
1417
|
FunctionEnum,
|
|
1086
1418
|
IndustryEnum,
|
|
1087
|
-
EnumDisplay
|
|
1419
|
+
EnumDisplay,
|
|
1420
|
+
enumItemsToSelectValue,
|
|
1421
|
+
enumItemToSelectValue,
|
|
1422
|
+
addressEnumToSelectValue,
|
|
1423
|
+
addressEnumToSelectValueSingle
|
|
1088
1424
|
};
|
|
1089
1425
|
|
|
1090
1426
|
exports.AddressEnum = AddressEnum;
|
|
@@ -1094,6 +1430,10 @@ exports.IndustryEnum = IndustryEnum;
|
|
|
1094
1430
|
exports.SelectAddress = SelectAddress;
|
|
1095
1431
|
exports.SelectFunction = SelectFunction;
|
|
1096
1432
|
exports.SelectIndustry = SelectIndustry;
|
|
1433
|
+
exports.addressEnumToSelectValue = addressEnumToSelectValue;
|
|
1434
|
+
exports.addressEnumToSelectValueSingle = addressEnumToSelectValueSingle;
|
|
1097
1435
|
exports.createAddressApi = createAddressApi;
|
|
1098
1436
|
exports["default"] = index;
|
|
1437
|
+
exports.enumItemToSelectValue = enumItemToSelectValue;
|
|
1438
|
+
exports.enumItemsToSelectValue = enumItemsToSelectValue;
|
|
1099
1439
|
//# sourceMappingURL=index.js.map
|