tdesign-react
Version:
TDesign Component for React
133 lines (129 loc) • 5.61 kB
JavaScript
/**
* tdesign v1.16.2
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _defineProperty } from '../../_chunks/dep-d67deb2c.js';
import { _ as _slicedToArray } from '../../_chunks/dep-10d5731f.js';
import { _ as _toConsumableArray } from '../../_chunks/dep-a3a3e527.js';
import { has, get, isObject, isArray, isEmpty } from 'lodash-es';
import '../../_chunks/dep-8abcbcbc.js';
import '../../_chunks/dep-74a10cfb.js';
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function swap(arr, i, j) {
var _ref = [arr[j], arr[i]];
arr[i] = _ref[0];
arr[j] = _ref[1];
}
function convertNameToArray(name) {
if (name === void 0 || name === null) return [];
return Array.isArray(name) ? name : [name];
}
function concatName() {
for (var _len = arguments.length, name = new Array(_len), _key = 0; _key < _len; _key++) {
name[_key] = arguments[_key];
}
return name.flatMap(function (p) {
return convertNameToArray(p);
});
}
function findFormItem(name, formMapRef) {
if (!formMapRef.current) return;
var mapKeys = _toConsumableArray(formMapRef.current.keys());
var key = mapKeys.find(function (key2) {
return String(key2) === String(name);
});
var ref = formMapRef.current.get(key);
return ref !== null && ref !== void 0 ? ref : findFormItemDeep(name, formMapRef);
}
function findFormItemDeep(name, formMapRef) {
if (!(formMapRef !== null && formMapRef !== void 0 && formMapRef.current)) return;
var targetPath = convertNameToArray(name);
var _iterator = _createForOfIteratorHelper(formMapRef.current.entries()),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _slicedToArray(_step.value, 2),
key = _step$value[0],
ref = _step$value[1];
var keyPath = convertNameToArray(key);
if (String(keyPath) === String(targetPath)) {
return ref;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
var _iterator2 = _createForOfIteratorHelper(formMapRef.current.entries()),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _step2$value = _slicedToArray(_step2.value, 2),
_ref2 = _step2$value[1];
var formItem = _ref2 === null || _ref2 === void 0 ? void 0 : _ref2.current;
if (!(formItem !== null && formItem !== void 0 && formItem.isFormList) || !formItem.formListMapRef) continue;
var found = findFormItemDeep(name, formItem.formListMapRef);
if (found) return found;
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
function objectToArray(obj) {
var result = [];
function traverse(current) {
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (isObject(current) && !isArray(current) && !isEmpty(current)) {
Object.keys(current).forEach(function (key) {
traverse(current[key], [].concat(_toConsumableArray(path), [key]));
});
} else {
result.push(path);
}
}
traverse(obj);
return result;
}
function calcFieldValue(name, value) {
var numericKeyAsIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (!Array.isArray(name)) return _defineProperty({}, name, value);
var result = value;
for (var i = name.length - 1; i >= 0; i--) {
var key = name[i];
var isNumberKey = typeof key === "number" && numericKeyAsIndex;
if (isNumberKey) {
var arr = [];
arr[key] = result;
result = arr;
} else {
result = _defineProperty({}, key, result);
}
}
return result;
}
function travelMapFromObject(obj, formMapRef, callback) {
var _iterator3 = _createForOfIteratorHelper(formMapRef.current.entries()),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _step3$value = _slicedToArray(_step3.value, 2),
mapName = _step3$value[0],
formItemRef = _step3$value[1];
if (has(obj, mapName)) {
callback(formItemRef, get(obj, mapName));
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
}
export { calcFieldValue, concatName, convertNameToArray, findFormItem, objectToArray, swap, travelMapFromObject };
//# sourceMappingURL=index.js.map