@tmagic/utils 1.8.0-manmanyu.9 → 1.8.0
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/dist/es/dom.js +2 -2
- package/dist/es/index.js +27 -7
- package/dist/tmagic-utils.umd.cjs +302 -148
- package/package.json +4 -4
- package/src/index.ts +30 -4
- package/types/index.d.ts +2294 -67
package/dist/es/dom.js
CHANGED
|
@@ -22,7 +22,7 @@ var asyncLoadJs = (() => {
|
|
|
22
22
|
};
|
|
23
23
|
setTimeout(() => {
|
|
24
24
|
reject(/* @__PURE__ */ new Error("timeout"));
|
|
25
|
-
},
|
|
25
|
+
}, 6e4);
|
|
26
26
|
}).catch((err) => {
|
|
27
27
|
loaded.delete(url);
|
|
28
28
|
throw err;
|
|
@@ -53,7 +53,7 @@ var asyncLoadCss = (() => {
|
|
|
53
53
|
};
|
|
54
54
|
setTimeout(() => {
|
|
55
55
|
reject(/* @__PURE__ */ new Error("timeout"));
|
|
56
|
-
},
|
|
56
|
+
}, 6e4);
|
|
57
57
|
}).catch((err) => {
|
|
58
58
|
loaded.delete(url);
|
|
59
59
|
throw err;
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DATA_SOURCE_SET_DATA_METHOD_NAME } from "./const.js";
|
|
2
2
|
import { addClassName, asyncLoadCss, asyncLoadJs, calcValueByFontsize, createDiv, getDocument, getElById, getIdFromEl, injectStyle, removeClassName, removeClassNameByClassName, setDslDomRelateConfig, setIdToEl } from "./dom.js";
|
|
3
|
-
import { cloneDeep, set } from "lodash-es";
|
|
3
|
+
import { cloneDeep, get, set } from "lodash-es";
|
|
4
4
|
import { NodeType } from "@tmagic/schema";
|
|
5
5
|
//#region packages/utils/src/index.ts
|
|
6
6
|
var _globalThis;
|
|
@@ -58,7 +58,7 @@ var getNodeInfo = (id, root, skip) => {
|
|
|
58
58
|
path.unshift(root);
|
|
59
59
|
info.node = path[path.length - 1];
|
|
60
60
|
info.parent = path[path.length - 2];
|
|
61
|
-
for (const item of path) if (
|
|
61
|
+
for (const item of path) if (isPageOrFragment(item)) {
|
|
62
62
|
info.page = item;
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
@@ -100,8 +100,10 @@ var setUrlParam = (name, value, url = globalThis.location.href) => {
|
|
|
100
100
|
const first = strArr.charAt(0);
|
|
101
101
|
url = url.replace(strArr, key);
|
|
102
102
|
url = url.replace(key, value ? first + extra : "");
|
|
103
|
-
} else if (value)
|
|
104
|
-
|
|
103
|
+
} else if (value) {
|
|
104
|
+
if (url.indexOf("?") > -1) url += `&${extra}`;
|
|
105
|
+
else url += `?${extra}`;
|
|
106
|
+
}
|
|
105
107
|
return url;
|
|
106
108
|
};
|
|
107
109
|
var getSearchObj = (search = globalThis.location.search ? globalThis.location.search.substring(1) : "") => {
|
|
@@ -143,6 +145,8 @@ var isPageFragment = (node) => {
|
|
|
143
145
|
if (!node) return false;
|
|
144
146
|
return Boolean(node.type?.toLowerCase() === NodeType.PAGE_FRAGMENT);
|
|
145
147
|
};
|
|
148
|
+
/** 是否为页面或页面片 */
|
|
149
|
+
var isPageOrFragment = (node) => isPage(node) || isPageFragment(node);
|
|
146
150
|
var isNumber = (value) => typeof value === "number" && !isNaN(value) || /^(-?\d+)(\.\d+)?$/.test(`${value}`);
|
|
147
151
|
var getHost = (targetUrl) => targetUrl.match(/\/\/([^/]+)/)?.[1];
|
|
148
152
|
var isSameDomain = (targetUrl = "", source = globalThis.location.host) => {
|
|
@@ -159,6 +163,12 @@ var guid = (digit = 8) => "x".repeat(digit).replace(/[xy]/g, (c) => {
|
|
|
159
163
|
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
160
164
|
});
|
|
161
165
|
var getKeysArray = (keys) => `${keys}`.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
166
|
+
/**
|
|
167
|
+
* 判断某一层 key 是否为数组下标(纯数字)
|
|
168
|
+
* @param key 单层 key
|
|
169
|
+
* @returns 是否为数组下标
|
|
170
|
+
*/
|
|
171
|
+
var isArrayIndex = (key) => /^\d+$/.test(`${key}`);
|
|
162
172
|
var getValueByKeyPath = (keys = "", data = {}) => {
|
|
163
173
|
return (Array.isArray(keys) ? keys : getKeysArray(keys)).reduce((accumulator, currentValue) => {
|
|
164
174
|
if (isObject(accumulator)) return accumulator[currentValue];
|
|
@@ -166,7 +176,18 @@ var getValueByKeyPath = (keys = "", data = {}) => {
|
|
|
166
176
|
throw new Error(`${data}中不存在${keys}`);
|
|
167
177
|
}, data);
|
|
168
178
|
};
|
|
169
|
-
var setValueByKeyPath = (keys, value, data = {}) =>
|
|
179
|
+
var setValueByKeyPath = (keys, value, data = {}) => {
|
|
180
|
+
if (typeof value === "undefined") {
|
|
181
|
+
const keyArray = getKeysArray(keys);
|
|
182
|
+
const lastKey = keyArray[keyArray.length - 1];
|
|
183
|
+
if (keyArray.length > 1 && isArrayIndex(lastKey)) {
|
|
184
|
+
const parentPath = keyArray.slice(0, -1).join(".");
|
|
185
|
+
if (typeof get(data, parentPath) === "undefined") set(data, parentPath, []);
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return set(data, keys, value);
|
|
190
|
+
};
|
|
170
191
|
var getNodes = (ids, data = []) => {
|
|
171
192
|
const nodes = [];
|
|
172
193
|
const get = function(ids, data) {
|
|
@@ -263,7 +284,6 @@ var compiledCond = (op, fieldValue, inputValue, range = []) => {
|
|
|
263
284
|
case "not_between": return range.length < 2 || fieldValue < range[0] || fieldValue > range[1];
|
|
264
285
|
case "include": return fieldValue?.includes?.(inputValue);
|
|
265
286
|
case "not_include": return typeof fieldValue === "undefined" || !fieldValue.includes?.(inputValue);
|
|
266
|
-
default: break;
|
|
267
287
|
}
|
|
268
288
|
return false;
|
|
269
289
|
};
|
|
@@ -357,4 +377,4 @@ var isValueIncludeDataSource = (value) => {
|
|
|
357
377
|
};
|
|
358
378
|
var removeDataSourceFieldPrefix = (id) => id?.replace("ds-field::", "") || "";
|
|
359
379
|
//#endregion
|
|
360
|
-
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DATA_SOURCE_SET_DATA_METHOD_NAME, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, removeDataSourceFieldPrefix, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|
|
380
|
+
export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DATA_SOURCE_SET_DATA_METHOD_NAME, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isArrayIndex, isDslNode, isNumber, isObject, isPage, isPageFragment, isPageOrFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, removeDataSourceFieldPrefix, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
|