tdesign-react
Version:
TDesign Component for React
83 lines (79 loc) • 4.6 kB
JavaScript
/**
* tdesign v1.13.2
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _slicedToArray } from '../../_chunks/dep-118954e6.js';
import { _ as _defineProperty } from '../../_chunks/dep-8618a2f1.js';
import { _ as _toConsumableArray } from '../../_chunks/dep-132961ab.js';
import { isObject, isArray, isEmpty, has, get } from 'lodash-es';
import '../../_chunks/dep-61f5e3d1.js';
import '../../_chunks/dep-c37cc2fd.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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function getMapValue(name, formMapRef) {
if (!formMapRef.current) return;
var mapKeys = _toConsumableArray(formMapRef.current.keys());
var key = mapKeys.find(function (key2) {
return String(key2) === String(name);
});
return formMapRef.current.get(key);
}
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 isFormList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (Array.isArray(name)) {
if (isFormList) {
var fieldValue = name.reduceRight(function (prev, curr) {
var arr = [];
if (/^\d+$/.test(String(curr))) arr[curr] = prev;
return arr.length ? arr : _defineProperty({}, curr, prev);
}, value);
return _objectSpread({}, fieldValue);
}
return name.reduceRight(function (prev, curr, currentIndex) {
if (currentIndex === name.length - 1) {
return _defineProperty({}, curr, value);
}
return _defineProperty({}, curr, prev);
}, {});
}
return _defineProperty({}, name, value);
}
function travelMapFromObject(obj, formMapRef, callback) {
var _iterator = _createForOfIteratorHelper(formMapRef.current.entries()),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _slicedToArray(_step.value, 2),
mapName = _step$value[0],
formItemRef = _step$value[1];
if (has(obj, mapName)) {
callback(formItemRef, get(obj, mapName));
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
export { calcFieldValue, getMapValue, objectToArray, travelMapFromObject };
//# sourceMappingURL=index.js.map