funda-ui 4.2.811 → 4.3.123
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/NativeSelect/index.d.ts +3 -1
- package/NativeSelect/index.js +162 -49
- package/Select/index.d.ts +4 -1
- package/Select/index.js +163 -51
- package/lib/cjs/NativeSelect/index.d.ts +3 -1
- package/lib/cjs/NativeSelect/index.js +162 -49
- package/lib/cjs/Select/index.d.ts +4 -1
- package/lib/cjs/Select/index.js +163 -51
- package/lib/esm/NativeSelect/index.tsx +132 -32
- package/lib/esm/NativeSelect/native-select-utils/func.ts +9 -0
- package/lib/esm/Select/index.tsx +120 -22
- package/lib/esm/Select/select-utils/func.ts +8 -0
- package/package.json +1 -1
package/NativeSelect/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export interface OptionConfig {
|
|
|
8
8
|
export declare type NativeSelectOptionChangeFnType = (arg1: any, arg2: any, arg3?: any, arg4?: any) => void;
|
|
9
9
|
export declare type NativeSelectProps = {
|
|
10
10
|
wrapperClassName?: string;
|
|
11
|
-
|
|
11
|
+
defaultValue?: string | OptionConfig;
|
|
12
|
+
value?: string | OptionConfig;
|
|
12
13
|
label?: React.ReactNode | string;
|
|
13
14
|
name?: string;
|
|
14
15
|
disabled?: any;
|
|
@@ -22,6 +23,7 @@ export declare type NativeSelectProps = {
|
|
|
22
23
|
style?: React.CSSProperties;
|
|
23
24
|
tabIndex?: number;
|
|
24
25
|
[key: `data-${string}`]: string | undefined;
|
|
26
|
+
firstRequestAutoExec?: boolean;
|
|
25
27
|
fetchFuncAsync?: any;
|
|
26
28
|
fetchFuncMethod?: string;
|
|
27
29
|
fetchFuncMethodParams?: any[];
|
package/NativeSelect/index.js
CHANGED
|
@@ -1238,6 +1238,15 @@ function optionsFlat(allData) {
|
|
|
1238
1238
|
});
|
|
1239
1239
|
return flatItems;
|
|
1240
1240
|
}
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Determine whether it is an object or not
|
|
1244
|
+
* @param value
|
|
1245
|
+
* @returns
|
|
1246
|
+
*/
|
|
1247
|
+
function isObject(value) {
|
|
1248
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
1249
|
+
}
|
|
1241
1250
|
// EXTERNAL MODULE: ../Utils/dist/cjs/useComId.js
|
|
1242
1251
|
var useComId = __webpack_require__(85);
|
|
1243
1252
|
var useComId_default = /*#__PURE__*/__webpack_require__.n(useComId);
|
|
@@ -1250,7 +1259,7 @@ var object = __webpack_require__(575);
|
|
|
1250
1259
|
// EXTERNAL MODULE: ../Utils/dist/cjs/cls.js
|
|
1251
1260
|
var cls = __webpack_require__(188);
|
|
1252
1261
|
;// CONCATENATED MODULE: ./src/index.tsx
|
|
1253
|
-
var _excluded = ["wrapperClassName", "disabled", "required", "value", "label", "name", "id", "options", "hierarchical", "indentation", "doubleIndent", "style", "tabIndex", "fetchFuncAsync", "fetchFuncMethod", "fetchFuncMethodParams", "fetchCallback", "onFetch", "onChange", "onBlur", "onFocus"];
|
|
1262
|
+
var _excluded = ["wrapperClassName", "disabled", "required", "defaultValue", "value", "label", "name", "id", "options", "hierarchical", "indentation", "doubleIndent", "style", "tabIndex", "firstRequestAutoExec", "fetchFuncAsync", "fetchFuncMethod", "fetchFuncMethodParams", "fetchCallback", "onFetch", "onChange", "onBlur", "onFocus"];
|
|
1254
1263
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1255
1264
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
1256
1265
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -1279,6 +1288,7 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1279
1288
|
var wrapperClassName = props.wrapperClassName,
|
|
1280
1289
|
disabled = props.disabled,
|
|
1281
1290
|
required = props.required,
|
|
1291
|
+
defaultValue = props.defaultValue,
|
|
1282
1292
|
value = props.value,
|
|
1283
1293
|
label = props.label,
|
|
1284
1294
|
name = props.name,
|
|
@@ -1289,6 +1299,7 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1289
1299
|
doubleIndent = props.doubleIndent,
|
|
1290
1300
|
style = props.style,
|
|
1291
1301
|
tabIndex = props.tabIndex,
|
|
1302
|
+
firstRequestAutoExec = props.firstRequestAutoExec,
|
|
1292
1303
|
fetchFuncAsync = props.fetchFuncAsync,
|
|
1293
1304
|
fetchFuncMethod = props.fetchFuncMethod,
|
|
1294
1305
|
fetchFuncMethodParams = props.fetchFuncMethodParams,
|
|
@@ -1298,6 +1309,7 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1298
1309
|
onBlur = props.onBlur,
|
|
1299
1310
|
onFocus = props.onFocus,
|
|
1300
1311
|
attributes = _objectWithoutProperties(props, _excluded);
|
|
1312
|
+
var FIRST_REQUEST_AUTO = typeof firstRequestAutoExec === 'undefined' ? true : firstRequestAutoExec;
|
|
1301
1313
|
var INDENT_PLACEHOLDER = doubleIndent ? " " : " ";
|
|
1302
1314
|
var INDENT_LAST_PLACEHOLDER = "".concat(typeof indentation !== 'undefined' && indentation !== '' ? "".concat(indentation, " ") : '');
|
|
1303
1315
|
var uniqueID = useComId_default()();
|
|
@@ -1322,6 +1334,10 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1322
1334
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
1323
1335
|
controlValue = _useState6[0],
|
|
1324
1336
|
setControlValue = _useState6[1];
|
|
1337
|
+
var _useState7 = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(false),
|
|
1338
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
1339
|
+
firstRequestExecuted = _useState8[0],
|
|
1340
|
+
setFirstRequestExecuted = _useState8[1];
|
|
1325
1341
|
var optionsFormatGroupOpt = function optionsFormatGroupOpt(allData) {
|
|
1326
1342
|
allData.forEach(function (item) {
|
|
1327
1343
|
if (typeof item.optgroup !== 'undefined') {
|
|
@@ -1329,26 +1345,88 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1329
1345
|
}
|
|
1330
1346
|
});
|
|
1331
1347
|
};
|
|
1332
|
-
function
|
|
1348
|
+
var finalRes = function finalRes(val) {
|
|
1349
|
+
return isObject(val) ? val.value : val;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
// Generate list of options
|
|
1353
|
+
var selectOptionsList = Array.isArray(dataInit) ? dataInit.map(function (item, index) {
|
|
1354
|
+
if (typeof item.optgroup !== 'undefined') {
|
|
1355
|
+
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("optgroup", {
|
|
1356
|
+
key: 'optgroup-' + index,
|
|
1357
|
+
label: item.label
|
|
1358
|
+
}, item.optgroup.map(function (opt, optIndex) {
|
|
1359
|
+
var _disabled = typeof opt.disabled === 'undefined' ? false : opt.disabled;
|
|
1360
|
+
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("option", {
|
|
1361
|
+
key: 'option-' + optIndex,
|
|
1362
|
+
value: opt.value,
|
|
1363
|
+
dangerouslySetInnerHTML: {
|
|
1364
|
+
__html: "".concat(typeof opt.listItemLabel === 'undefined' ? opt.label : opt.listItemLabel)
|
|
1365
|
+
},
|
|
1366
|
+
disabled: _disabled
|
|
1367
|
+
});
|
|
1368
|
+
}));
|
|
1369
|
+
} else {
|
|
1370
|
+
var _disabled = typeof item.disabled === 'undefined' ? false : item.disabled;
|
|
1371
|
+
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("option", {
|
|
1372
|
+
key: 'option-' + index,
|
|
1373
|
+
value: item.value,
|
|
1374
|
+
dangerouslySetInnerHTML: {
|
|
1375
|
+
__html: "".concat(typeof item.listItemLabel === 'undefined' ? item.label : item.listItemLabel)
|
|
1376
|
+
},
|
|
1377
|
+
disabled: _disabled
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
}) : null;
|
|
1381
|
+
|
|
1382
|
+
// If the current value is not one of the options, the default value is displayed
|
|
1383
|
+
var extraSelectOption = function extraSelectOption() {
|
|
1384
|
+
if (!Array.isArray(dataInit)) return null;
|
|
1385
|
+
var curValue = defaultValue;
|
|
1386
|
+
if (typeof curValue === 'undefined') {
|
|
1387
|
+
curValue = value;
|
|
1388
|
+
}
|
|
1389
|
+
if (typeof curValue === 'undefined') return null;
|
|
1390
|
+
|
|
1391
|
+
// if the value is not object
|
|
1392
|
+
if (!isObject(curValue)) return null;
|
|
1393
|
+
var hasExtraOpt = optionsFlat(dataInit).some(function (option) {
|
|
1394
|
+
return option.value === finalRes(curValue);
|
|
1395
|
+
});
|
|
1396
|
+
if (!hasExtraOpt) {
|
|
1397
|
+
var _disabled = typeof curValue.disabled === 'undefined' ? false : curValue.disabled;
|
|
1398
|
+
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("option", {
|
|
1399
|
+
value: curValue.value,
|
|
1400
|
+
dangerouslySetInnerHTML: {
|
|
1401
|
+
__html: "".concat(typeof curValue.listItemLabel === 'undefined' ? curValue.label : curValue.listItemLabel)
|
|
1402
|
+
},
|
|
1403
|
+
disabled: _disabled
|
|
1404
|
+
});
|
|
1405
|
+
} else {
|
|
1406
|
+
return null;
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
function fetchData(_x2, _x3, _x4) {
|
|
1333
1410
|
return _fetchData.apply(this, arguments);
|
|
1334
|
-
}
|
|
1411
|
+
}
|
|
1335
1412
|
function _fetchData() {
|
|
1336
|
-
_fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
1337
|
-
var response, _ORGIN_DATA;
|
|
1413
|
+
_fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, valueToInputDefault, inputDefault) {
|
|
1414
|
+
var defaultValue, response, _ORGIN_DATA;
|
|
1338
1415
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1339
1416
|
while (1) switch (_context.prev = _context.next) {
|
|
1340
1417
|
case 0:
|
|
1341
|
-
//
|
|
1342
|
-
|
|
1418
|
+
// Determine whether the default value is user query input or default input
|
|
1419
|
+
defaultValue = valueToInputDefault; // set default value
|
|
1420
|
+
if (typeof defaultValue !== 'undefined' && defaultValue !== '') selectRef.current.dataset.value = defaultValue;
|
|
1343
1421
|
|
|
1344
1422
|
//
|
|
1345
1423
|
if (!(_typeof(fetchFuncAsync) === 'object')) {
|
|
1346
|
-
_context.next =
|
|
1424
|
+
_context.next = 18;
|
|
1347
1425
|
break;
|
|
1348
1426
|
}
|
|
1349
|
-
_context.next =
|
|
1427
|
+
_context.next = 5;
|
|
1350
1428
|
return fetchFuncAsync["".concat(fetchFuncMethod)].apply(fetchFuncAsync, _toConsumableArray(params.split(',')));
|
|
1351
|
-
case
|
|
1429
|
+
case 5:
|
|
1352
1430
|
response = _context.sent;
|
|
1353
1431
|
_ORGIN_DATA = response.data; // reset data structure
|
|
1354
1432
|
if (typeof fetchCallback === 'function') {
|
|
@@ -1363,7 +1441,7 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1363
1441
|
}
|
|
1364
1442
|
|
|
1365
1443
|
// set "<select>" value
|
|
1366
|
-
setControlValue(
|
|
1444
|
+
setControlValue(defaultValue); // value must be initialized
|
|
1367
1445
|
|
|
1368
1446
|
// Set hierarchical categories ( with sub-categories )
|
|
1369
1447
|
if (hierarchical) {
|
|
@@ -1381,9 +1459,9 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1381
1459
|
//
|
|
1382
1460
|
onFetch === null || onFetch === void 0 ? void 0 : onFetch(_ORGIN_DATA);
|
|
1383
1461
|
return _context.abrupt("return", _ORGIN_DATA);
|
|
1384
|
-
case
|
|
1462
|
+
case 18:
|
|
1385
1463
|
// set "<select>" value
|
|
1386
|
-
setControlValue(
|
|
1464
|
+
setControlValue(defaultValue); // value must be initialized
|
|
1387
1465
|
|
|
1388
1466
|
// remove Duplicate objects from JSON Array
|
|
1389
1467
|
optionsFormatGroupOpt(optionsDataInit); // prevent the value from being filtered out
|
|
@@ -1395,7 +1473,7 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1395
1473
|
//
|
|
1396
1474
|
onFetch === null || onFetch === void 0 ? void 0 : onFetch(optionsDataInit);
|
|
1397
1475
|
return _context.abrupt("return", optionsDataInit);
|
|
1398
|
-
case
|
|
1476
|
+
case 24:
|
|
1399
1477
|
case "end":
|
|
1400
1478
|
return _context.stop();
|
|
1401
1479
|
}
|
|
@@ -1403,6 +1481,33 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1403
1481
|
}));
|
|
1404
1482
|
return _fetchData.apply(this, arguments);
|
|
1405
1483
|
}
|
|
1484
|
+
function handleFirstFetch() {
|
|
1485
|
+
return _handleFirstFetch.apply(this, arguments);
|
|
1486
|
+
} //
|
|
1487
|
+
function _handleFirstFetch() {
|
|
1488
|
+
_handleFirstFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
1489
|
+
var inputVal,
|
|
1490
|
+
_params,
|
|
1491
|
+
res,
|
|
1492
|
+
_args2 = arguments;
|
|
1493
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1494
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1495
|
+
case 0:
|
|
1496
|
+
inputVal = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : null;
|
|
1497
|
+
_params = fetchFuncMethodParams || [];
|
|
1498
|
+
_context2.next = 4;
|
|
1499
|
+
return fetchData(_params.join(','), finalRes(inputVal), inputVal);
|
|
1500
|
+
case 4:
|
|
1501
|
+
res = _context2.sent;
|
|
1502
|
+
return _context2.abrupt("return", res);
|
|
1503
|
+
case 6:
|
|
1504
|
+
case "end":
|
|
1505
|
+
return _context2.stop();
|
|
1506
|
+
}
|
|
1507
|
+
}, _callee2);
|
|
1508
|
+
}));
|
|
1509
|
+
return _handleFirstFetch.apply(this, arguments);
|
|
1510
|
+
}
|
|
1406
1511
|
function handleFocus(event) {
|
|
1407
1512
|
var _rootRef$current;
|
|
1408
1513
|
(_rootRef$current = rootRef.current) === null || _rootRef$current === void 0 ? void 0 : _rootRef$current.classList.add('focus');
|
|
@@ -1411,20 +1516,26 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1411
1516
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
1412
1517
|
}
|
|
1413
1518
|
function handleChange(event) {
|
|
1414
|
-
var _rootRef$current2;
|
|
1519
|
+
var _curItem$callback, _rootRef$current2;
|
|
1415
1520
|
var val = event.target.value;
|
|
1521
|
+
var curIndex = event.target.selectedIndex;
|
|
1522
|
+
var curItem = optionsFlat(dataInit)[curIndex];
|
|
1416
1523
|
|
|
1417
1524
|
//----
|
|
1418
1525
|
// update value
|
|
1419
1526
|
setControlValue(val);
|
|
1420
1527
|
|
|
1528
|
+
//----
|
|
1529
|
+
// Callback
|
|
1530
|
+
(_curItem$callback = curItem.callback) === null || _curItem$callback === void 0 ? void 0 : _curItem$callback.call(curItem);
|
|
1531
|
+
|
|
1421
1532
|
//----
|
|
1422
1533
|
//remove focus style
|
|
1423
1534
|
(_rootRef$current2 = rootRef.current) === null || _rootRef$current2 === void 0 ? void 0 : _rootRef$current2.classList.remove('focus');
|
|
1424
1535
|
|
|
1425
1536
|
//
|
|
1426
1537
|
if (typeof onChange === 'function') {
|
|
1427
|
-
onChange(event,
|
|
1538
|
+
onChange(event, curItem.value, curItem, curIndex);
|
|
1428
1539
|
event.target.blur();
|
|
1429
1540
|
}
|
|
1430
1541
|
}
|
|
@@ -1437,42 +1548,39 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1437
1548
|
//
|
|
1438
1549
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
1439
1550
|
}
|
|
1551
|
+
function activate() {
|
|
1552
|
+
// trigger the first asynchronous request when the options area is expanded
|
|
1553
|
+
if (!FIRST_REQUEST_AUTO && !firstRequestExecuted) {
|
|
1554
|
+
var curValue = defaultValue;
|
|
1555
|
+
if (typeof curValue === 'undefined') {
|
|
1556
|
+
curValue = value;
|
|
1557
|
+
}
|
|
1558
|
+
handleFirstFetch(curValue);
|
|
1440
1559
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
if (typeof item.optgroup !== 'undefined') {
|
|
1444
|
-
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("optgroup", {
|
|
1445
|
-
key: 'optgroup-' + index,
|
|
1446
|
-
label: item.label
|
|
1447
|
-
}, item.optgroup.map(function (opt, optIndex) {
|
|
1448
|
-
var _disabled = typeof opt.disabled === 'undefined' ? false : opt.disabled;
|
|
1449
|
-
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("option", {
|
|
1450
|
-
key: 'option-' + optIndex,
|
|
1451
|
-
value: opt.value,
|
|
1452
|
-
dangerouslySetInnerHTML: {
|
|
1453
|
-
__html: "".concat(typeof opt.listItemLabel === 'undefined' ? opt.label : opt.listItemLabel)
|
|
1454
|
-
},
|
|
1455
|
-
disabled: _disabled
|
|
1456
|
-
});
|
|
1457
|
-
}));
|
|
1458
|
-
} else {
|
|
1459
|
-
var _disabled = typeof item.disabled === 'undefined' ? false : item.disabled;
|
|
1460
|
-
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("option", {
|
|
1461
|
-
key: 'option-' + index,
|
|
1462
|
-
value: item.value,
|
|
1463
|
-
dangerouslySetInnerHTML: {
|
|
1464
|
-
__html: "".concat(typeof item.listItemLabel === 'undefined' ? item.label : item.listItemLabel)
|
|
1465
|
-
},
|
|
1466
|
-
disabled: _disabled
|
|
1467
|
-
});
|
|
1560
|
+
//
|
|
1561
|
+
setFirstRequestExecuted(true);
|
|
1468
1562
|
}
|
|
1469
|
-
}
|
|
1563
|
+
}
|
|
1470
1564
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1471
1565
|
// data init
|
|
1472
1566
|
//--------------
|
|
1473
|
-
|
|
1474
|
-
|
|
1567
|
+
if (FIRST_REQUEST_AUTO) {
|
|
1568
|
+
handleFirstFetch(value);
|
|
1569
|
+
}
|
|
1475
1570
|
}, [value, options]);
|
|
1571
|
+
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1572
|
+
// update default value (It does not re-render the component because the incoming value changes.)
|
|
1573
|
+
//--------------
|
|
1574
|
+
if (typeof defaultValue !== 'undefined') {
|
|
1575
|
+
//REQUIRED
|
|
1576
|
+
|
|
1577
|
+
// data init
|
|
1578
|
+
//--------------
|
|
1579
|
+
if (FIRST_REQUEST_AUTO) {
|
|
1580
|
+
handleFirstFetch(defaultValue);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}, []);
|
|
1476
1584
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement("div", {
|
|
1477
1585
|
className: (0,cls.clsWrite)(wrapperClassName, 'mb-3 position-relative'),
|
|
1478
1586
|
ref: rootRef
|
|
@@ -1497,16 +1605,21 @@ var NativeSelect = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_
|
|
|
1497
1605
|
tabIndex: tabIndex || 0,
|
|
1498
1606
|
className: "form-select",
|
|
1499
1607
|
id: idRes,
|
|
1500
|
-
name: name
|
|
1501
|
-
|
|
1608
|
+
name: name
|
|
1609
|
+
|
|
1610
|
+
// `value` prop on `select` should not be null. Consider using an empty string
|
|
1611
|
+
// to clear the component or `undefined` for uncontrolled components.
|
|
1612
|
+
,
|
|
1613
|
+
value: controlValue === null ? undefined : controlValue // do not use `defaultValue`
|
|
1502
1614
|
,
|
|
1503
1615
|
onFocus: handleFocus,
|
|
1616
|
+
onClick: activate,
|
|
1504
1617
|
onBlur: handleBlur,
|
|
1505
1618
|
onChange: handleChange,
|
|
1506
1619
|
disabled: disabled || null,
|
|
1507
1620
|
required: required || null,
|
|
1508
1621
|
style: style
|
|
1509
|
-
}, attributes), !hasErr ? selectOptionsList : null)));
|
|
1622
|
+
}, attributes), !hasErr ? /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, extraSelectOption(), selectOptionsList) : null)));
|
|
1510
1623
|
});
|
|
1511
1624
|
/* harmony default export */ const src = (NativeSelect);
|
|
1512
1625
|
})();
|
package/Select/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface OptionConfig {
|
|
|
17
17
|
listItemLabel?: any;
|
|
18
18
|
value: any;
|
|
19
19
|
queryString: string | number;
|
|
20
|
+
callback?: () => void;
|
|
20
21
|
}
|
|
21
22
|
export interface MultiSelectConfig {
|
|
22
23
|
valid: boolean;
|
|
@@ -45,7 +46,8 @@ export declare type SelectProps = {
|
|
|
45
46
|
multiSelectSelectedItemOnlyStatus?: multiSelectSelectedItemOnlyStatusConfig;
|
|
46
47
|
renderSelectedValue?: (selectedData: MultiSelectControlValConfig, removeFunc: (e: React.MouseEvent) => void) => void;
|
|
47
48
|
cleanTrigger?: CleanTriggerConfig;
|
|
48
|
-
|
|
49
|
+
defaultValue?: string | OptionConfig;
|
|
50
|
+
value?: string | OptionConfig;
|
|
49
51
|
label?: React.ReactNode | string;
|
|
50
52
|
name?: string;
|
|
51
53
|
disabled?: any;
|
|
@@ -59,6 +61,7 @@ export declare type SelectProps = {
|
|
|
59
61
|
doubleIndent?: boolean;
|
|
60
62
|
winWidth?: string | Function;
|
|
61
63
|
controlArrow?: React.ReactNode;
|
|
64
|
+
firstRequestAutoExec?: boolean;
|
|
62
65
|
fetchTrigger?: boolean;
|
|
63
66
|
fetchTriggerForDefaultData?: MultiSelectDataConfig | null;
|
|
64
67
|
/** Set the depth value of the control to control the display of the pop-up layer appear above.
|