@tmagic/utils 1.5.12 → 1.5.14

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.
@@ -125,7 +125,7 @@ const sleep = (ms) => new Promise((resolve) => {
125
125
  });
126
126
  const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
127
127
  const toHump = (name = "") => name.replace(/-(\w)/g, (_all, letter) => letter.toUpperCase());
128
- const emptyFn = () => undefined;
128
+ const emptyFn = () => void 0;
129
129
  const getNodePath = (id, data = []) => {
130
130
  const path = [];
131
131
  const get = function(id2, data2) {
@@ -190,6 +190,65 @@ const getUrlParam = (param, url) => {
190
190
  }
191
191
  return "";
192
192
  };
193
+ const setUrlParam = (name, value, url = globalThis.location.href) => {
194
+ const reg = new RegExp(`[?&#]${name}=([^&#]*)`, "gi");
195
+ const matches = url.match(reg);
196
+ const key = `{key${(/* @__PURE__ */ new Date()).getTime()}}`;
197
+ let strArr;
198
+ if (matches && matches.length > 0) {
199
+ strArr = matches[matches.length - 1];
200
+ } else {
201
+ strArr = "";
202
+ }
203
+ const extra = `${name}=${value}`;
204
+ if (strArr) {
205
+ const first = strArr.charAt(0);
206
+ url = url.replace(strArr, key);
207
+ url = url.replace(key, value ? first + extra : "");
208
+ } else if (value) {
209
+ if (url.indexOf("?") > -1) {
210
+ url += `&${extra}`;
211
+ } else {
212
+ url += `?${extra}`;
213
+ }
214
+ }
215
+ return url;
216
+ };
217
+ const getSearchObj = (search = globalThis.location.search ? globalThis.location.search.substring(1) : "") => {
218
+ return search.split("&").reduce((obj, item) => {
219
+ const [a, b = ""] = item.split("=");
220
+ return { ...obj, [a]: b };
221
+ }, {});
222
+ };
223
+ const delQueStr = (url, ref) => {
224
+ let str = "";
225
+ if (url.indexOf("?") !== -1) {
226
+ str = url.substring(url.indexOf("?") + 1);
227
+ } else {
228
+ return url;
229
+ }
230
+ let arr = [];
231
+ let returnurl = "";
232
+ const isHit = Array.isArray(ref) ? function(v) {
233
+ return ~ref.indexOf(v);
234
+ } : function(v) {
235
+ return v === ref;
236
+ };
237
+ if (str.indexOf("&") !== -1) {
238
+ arr = str.split("&");
239
+ for (let i = 0, len = arr.length; i < len; i++) {
240
+ if (!isHit(arr[i].split("=")[0])) {
241
+ returnurl = `${returnurl + arr[i].split("=")[0]}=${arr[i].split("=")[1]}&`;
242
+ }
243
+ }
244
+ return returnurl ? `${url.substr(0, url.indexOf("?"))}?${returnurl.substr(0, returnurl.length - 1)}` : url.substr(0, url.indexOf("?"));
245
+ }
246
+ arr = str.split("=");
247
+ if (isHit(arr[0])) {
248
+ return url.substr(0, url.indexOf("?"));
249
+ }
250
+ return url;
251
+ };
193
252
  const isObject = (obj) => Object.prototype.toString.call(obj) === "[object Object]";
194
253
  const isPop = (node) => Boolean(node?.type?.toLowerCase().endsWith("pop"));
195
254
  const isPage = (node) => {
@@ -351,13 +410,13 @@ const compiledCond = (op, fieldValue, inputValue, range = []) => {
351
410
  const getDefaultValueFromFields = (fields) => {
352
411
  const data = {};
353
412
  const defaultValue = {
354
- string: undefined,
413
+ string: void 0,
355
414
  object: {},
356
415
  array: [],
357
- boolean: undefined,
358
- number: undefined,
416
+ boolean: void 0,
417
+ number: void 0,
359
418
  null: null,
360
- any: undefined
419
+ any: void 0
361
420
  };
362
421
  fields.forEach((field) => {
363
422
  if (typeof field.defaultValue !== "undefined") {
@@ -371,6 +430,7 @@ const getDefaultValueFromFields = (fields) => {
371
430
  data[field.name] = JSON.parse(field.defaultValue);
372
431
  } catch (e) {
373
432
  data[field.name] = defaultValue.object;
433
+ console.warn("defaultValue 解析失败", field.defaultValue, e);
374
434
  }
375
435
  return;
376
436
  }
@@ -388,7 +448,7 @@ const getDefaultValueFromFields = (fields) => {
388
448
  data[field.name] = defaultValue[field.type];
389
449
  return;
390
450
  }
391
- data[field.name] = undefined;
451
+ data[field.name] = void 0;
392
452
  });
393
453
  return data;
394
454
  };
@@ -455,4 +515,4 @@ const isValueIncludeDataSource = (value) => {
455
515
  return false;
456
516
  };
457
517
 
458
- export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
518
+ export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_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, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
@@ -17,17 +17,17 @@
17
17
  var Symbol$1 = root.Symbol;
18
18
 
19
19
  /** Used for built-in method references. */
20
- var objectProto$c = Object.prototype;
20
+ var objectProto$b = Object.prototype;
21
21
 
22
22
  /** Used to check objects for own properties. */
23
- var hasOwnProperty$9 = objectProto$c.hasOwnProperty;
23
+ var hasOwnProperty$8 = objectProto$b.hasOwnProperty;
24
24
 
25
25
  /**
26
26
  * Used to resolve the
27
27
  * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
28
28
  * of values.
29
29
  */
30
- var nativeObjectToString$1 = objectProto$c.toString;
30
+ var nativeObjectToString$1 = objectProto$b.toString;
31
31
 
32
32
  /** Built-in value references. */
33
33
  var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
@@ -40,7 +40,7 @@
40
40
  * @returns {string} Returns the raw `toStringTag`.
41
41
  */
42
42
  function getRawTag(value) {
43
- var isOwn = hasOwnProperty$9.call(value, symToStringTag$1),
43
+ var isOwn = hasOwnProperty$8.call(value, symToStringTag$1),
44
44
  tag = value[symToStringTag$1];
45
45
 
46
46
  try {
@@ -60,14 +60,14 @@
60
60
  }
61
61
 
62
62
  /** Used for built-in method references. */
63
- var objectProto$b = Object.prototype;
63
+ var objectProto$a = Object.prototype;
64
64
 
65
65
  /**
66
66
  * Used to resolve the
67
67
  * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
68
68
  * of values.
69
69
  */
70
- var nativeObjectToString = objectProto$b.toString;
70
+ var nativeObjectToString = objectProto$a.toString;
71
71
 
72
72
  /**
73
73
  * Converts `value` to a string using `Object.prototype.toString`.
@@ -348,17 +348,17 @@
348
348
 
349
349
  /** Used for built-in method references. */
350
350
  var funcProto = Function.prototype,
351
- objectProto$a = Object.prototype;
351
+ objectProto$9 = Object.prototype;
352
352
 
353
353
  /** Used to resolve the decompiled source of functions. */
354
354
  var funcToString = funcProto.toString;
355
355
 
356
356
  /** Used to check objects for own properties. */
357
- var hasOwnProperty$8 = objectProto$a.hasOwnProperty;
357
+ var hasOwnProperty$7 = objectProto$9.hasOwnProperty;
358
358
 
359
359
  /** Used to detect if a method is native. */
360
360
  var reIsNative = RegExp('^' +
361
- funcToString.call(hasOwnProperty$8).replace(reRegExpChar, '\\$&')
361
+ funcToString.call(hasOwnProperty$7).replace(reRegExpChar, '\\$&')
362
362
  .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
363
363
  );
364
364
 
@@ -433,25 +433,6 @@
433
433
  };
434
434
  }());
435
435
 
436
- /**
437
- * Copies the values of `source` to `array`.
438
- *
439
- * @private
440
- * @param {Array} source The array to copy values from.
441
- * @param {Array} [array=[]] The array to copy values to.
442
- * @returns {Array} Returns `array`.
443
- */
444
- function copyArray(source, array) {
445
- var index = -1,
446
- length = source.length;
447
-
448
- array || (array = Array(length));
449
- while (++index < length) {
450
- array[index] = source[index];
451
- }
452
- return array;
453
- }
454
-
455
436
  var defineProperty = (function() {
456
437
  try {
457
438
  var func = getNative(Object, 'defineProperty');
@@ -564,10 +545,10 @@
564
545
  }
565
546
 
566
547
  /** Used for built-in method references. */
567
- var objectProto$9 = Object.prototype;
548
+ var objectProto$8 = Object.prototype;
568
549
 
569
550
  /** Used to check objects for own properties. */
570
- var hasOwnProperty$7 = objectProto$9.hasOwnProperty;
551
+ var hasOwnProperty$6 = objectProto$8.hasOwnProperty;
571
552
 
572
553
  /**
573
554
  * Assigns `value` to `key` of `object` if the existing value is not equivalent
@@ -581,46 +562,12 @@
581
562
  */
582
563
  function assignValue(object, key, value) {
583
564
  var objValue = object[key];
584
- if (!(hasOwnProperty$7.call(object, key) && eq(objValue, value)) ||
565
+ if (!(hasOwnProperty$6.call(object, key) && eq(objValue, value)) ||
585
566
  (value === undefined && !(key in object))) {
586
567
  baseAssignValue(object, key, value);
587
568
  }
588
569
  }
589
570
 
590
- /**
591
- * Copies properties of `source` to `object`.
592
- *
593
- * @private
594
- * @param {Object} source The object to copy properties from.
595
- * @param {Array} props The property identifiers to copy.
596
- * @param {Object} [object={}] The object to copy properties to.
597
- * @param {Function} [customizer] The function to customize copied values.
598
- * @returns {Object} Returns `object`.
599
- */
600
- function copyObject(source, props, object, customizer) {
601
- var isNew = !object;
602
- object || (object = {});
603
-
604
- var index = -1,
605
- length = props.length;
606
-
607
- while (++index < length) {
608
- var key = props[index];
609
-
610
- var newValue = undefined;
611
-
612
- if (newValue === undefined) {
613
- newValue = source[key];
614
- }
615
- if (isNew) {
616
- baseAssignValue(object, key, newValue);
617
- } else {
618
- assignValue(object, key, newValue);
619
- }
620
- }
621
- return object;
622
- }
623
-
624
571
  /** Used as references for various `Number` constants. */
625
572
  var MAX_SAFE_INTEGER = 9007199254740991;
626
573
 
@@ -685,7 +632,7 @@
685
632
  }
686
633
 
687
634
  /** Used for built-in method references. */
688
- var objectProto$8 = Object.prototype;
635
+ var objectProto$7 = Object.prototype;
689
636
 
690
637
  /**
691
638
  * Checks if `value` is likely a prototype object.
@@ -696,7 +643,7 @@
696
643
  */
697
644
  function isPrototype(value) {
698
645
  var Ctor = value && value.constructor,
699
- proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$8;
646
+ proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$7;
700
647
 
701
648
  return value === proto;
702
649
  }
@@ -735,13 +682,13 @@
735
682
  }
736
683
 
737
684
  /** Used for built-in method references. */
738
- var objectProto$7 = Object.prototype;
685
+ var objectProto$6 = Object.prototype;
739
686
 
740
687
  /** Used to check objects for own properties. */
741
- var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
688
+ var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
742
689
 
743
690
  /** Built-in value references. */
744
- var propertyIsEnumerable$1 = objectProto$7.propertyIsEnumerable;
691
+ var propertyIsEnumerable$1 = objectProto$6.propertyIsEnumerable;
745
692
 
746
693
  /**
747
694
  * Checks if `value` is likely an `arguments` object.
@@ -762,7 +709,7 @@
762
709
  * // => false
763
710
  */
764
711
  var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
765
- return isObjectLike(value) && hasOwnProperty$6.call(value, 'callee') &&
712
+ return isObjectLike(value) && hasOwnProperty$5.call(value, 'callee') &&
766
713
  !propertyIsEnumerable$1.call(value, 'callee');
767
714
  };
768
715
 
@@ -935,10 +882,10 @@
935
882
  var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
936
883
 
937
884
  /** Used for built-in method references. */
938
- var objectProto$6 = Object.prototype;
885
+ var objectProto$5 = Object.prototype;
939
886
 
940
887
  /** Used to check objects for own properties. */
941
- var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
888
+ var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
942
889
 
943
890
  /**
944
891
  * Creates an array of the enumerable property names of the array-like `value`.
@@ -958,7 +905,7 @@
958
905
  length = result.length;
959
906
 
960
907
  for (var key in value) {
961
- if ((inherited || hasOwnProperty$5.call(value, key)) &&
908
+ if ((hasOwnProperty$4.call(value, key)) &&
962
909
  !(skipIndexes && (
963
910
  // Safari 9 has enumerable `arguments.length` in strict mode.
964
911
  key == 'length' ||
@@ -993,10 +940,10 @@
993
940
  var nativeKeys = overArg(Object.keys, Object);
994
941
 
995
942
  /** Used for built-in method references. */
996
- var objectProto$5 = Object.prototype;
943
+ var objectProto$4 = Object.prototype;
997
944
 
998
945
  /** Used to check objects for own properties. */
999
- var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
946
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
1000
947
 
1001
948
  /**
1002
949
  * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
@@ -1011,7 +958,7 @@
1011
958
  }
1012
959
  var result = [];
1013
960
  for (var key in Object(object)) {
1014
- if (hasOwnProperty$4.call(object, key) && key != 'constructor') {
961
+ if (hasOwnProperty$3.call(object, key) && key != 'constructor') {
1015
962
  result.push(key);
1016
963
  }
1017
964
  }
@@ -1050,80 +997,6 @@
1050
997
  return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
1051
998
  }
1052
999
 
1053
- /**
1054
- * This function is like
1055
- * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1056
- * except that it includes inherited enumerable properties.
1057
- *
1058
- * @private
1059
- * @param {Object} object The object to query.
1060
- * @returns {Array} Returns the array of property names.
1061
- */
1062
- function nativeKeysIn(object) {
1063
- var result = [];
1064
- if (object != null) {
1065
- for (var key in Object(object)) {
1066
- result.push(key);
1067
- }
1068
- }
1069
- return result;
1070
- }
1071
-
1072
- /** Used for built-in method references. */
1073
- var objectProto$4 = Object.prototype;
1074
-
1075
- /** Used to check objects for own properties. */
1076
- var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
1077
-
1078
- /**
1079
- * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
1080
- *
1081
- * @private
1082
- * @param {Object} object The object to query.
1083
- * @returns {Array} Returns the array of property names.
1084
- */
1085
- function baseKeysIn(object) {
1086
- if (!isObject$1(object)) {
1087
- return nativeKeysIn(object);
1088
- }
1089
- var isProto = isPrototype(object),
1090
- result = [];
1091
-
1092
- for (var key in object) {
1093
- if (!(key == 'constructor' && (isProto || !hasOwnProperty$3.call(object, key)))) {
1094
- result.push(key);
1095
- }
1096
- }
1097
- return result;
1098
- }
1099
-
1100
- /**
1101
- * Creates an array of the own and inherited enumerable property names of `object`.
1102
- *
1103
- * **Note:** Non-object values are coerced to objects.
1104
- *
1105
- * @static
1106
- * @memberOf _
1107
- * @since 3.0.0
1108
- * @category Object
1109
- * @param {Object} object The object to query.
1110
- * @returns {Array} Returns the array of property names.
1111
- * @example
1112
- *
1113
- * function Foo() {
1114
- * this.a = 1;
1115
- * this.b = 2;
1116
- * }
1117
- *
1118
- * Foo.prototype.c = 3;
1119
- *
1120
- * _.keysIn(new Foo);
1121
- * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
1122
- */
1123
- function keysIn(object) {
1124
- return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
1125
- }
1126
-
1127
1000
  /** Used to match property names within property paths. */
1128
1001
  var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
1129
1002
  reIsPlainProp = /^\w*$/;
@@ -1841,32 +1714,6 @@
1841
1714
  Stack.prototype.has = stackHas;
1842
1715
  Stack.prototype.set = stackSet;
1843
1716
 
1844
- /**
1845
- * The base implementation of `_.assign` without support for multiple sources
1846
- * or `customizer` functions.
1847
- *
1848
- * @private
1849
- * @param {Object} object The destination object.
1850
- * @param {Object} source The source object.
1851
- * @returns {Object} Returns `object`.
1852
- */
1853
- function baseAssign(object, source) {
1854
- return object && copyObject(source, keys(source), object);
1855
- }
1856
-
1857
- /**
1858
- * The base implementation of `_.assignIn` without support for multiple sources
1859
- * or `customizer` functions.
1860
- *
1861
- * @private
1862
- * @param {Object} object The destination object.
1863
- * @param {Object} source The source object.
1864
- * @returns {Object} Returns `object`.
1865
- */
1866
- function baseAssignIn(object, source) {
1867
- return object && copyObject(source, keysIn(source), object);
1868
- }
1869
-
1870
1717
  /** Detect free variable `exports`. */
1871
1718
  var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
1872
1719
 
@@ -1877,8 +1724,8 @@
1877
1724
  var moduleExports = freeModule && freeModule.exports === freeExports;
1878
1725
 
1879
1726
  /** Built-in value references. */
1880
- var Buffer = moduleExports ? root.Buffer : undefined,
1881
- allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
1727
+ var Buffer = moduleExports ? root.Buffer : undefined;
1728
+ Buffer ? Buffer.allocUnsafe : undefined;
1882
1729
 
1883
1730
  /**
1884
1731
  * Creates a clone of `buffer`.
@@ -1889,14 +1736,9 @@
1889
1736
  * @returns {Buffer} Returns the cloned buffer.
1890
1737
  */
1891
1738
  function cloneBuffer(buffer, isDeep) {
1892
- if (isDeep) {
1739
+ {
1893
1740
  return buffer.slice();
1894
1741
  }
1895
- var length = buffer.length,
1896
- result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
1897
-
1898
- buffer.copy(result);
1899
- return result;
1900
1742
  }
1901
1743
 
1902
1744
  /**
@@ -1952,7 +1794,7 @@
1952
1794
  var propertyIsEnumerable = objectProto$1.propertyIsEnumerable;
1953
1795
 
1954
1796
  /* Built-in method references for those with the same name as other `lodash` methods. */
1955
- var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
1797
+ var nativeGetSymbols = Object.getOwnPropertySymbols;
1956
1798
 
1957
1799
  /**
1958
1800
  * Creates an array of the own enumerable symbols of `object`.
@@ -1961,59 +1803,16 @@
1961
1803
  * @param {Object} object The object to query.
1962
1804
  * @returns {Array} Returns the array of symbols.
1963
1805
  */
1964
- var getSymbols = !nativeGetSymbols$1 ? stubArray : function(object) {
1806
+ var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
1965
1807
  if (object == null) {
1966
1808
  return [];
1967
1809
  }
1968
1810
  object = Object(object);
1969
- return arrayFilter(nativeGetSymbols$1(object), function(symbol) {
1811
+ return arrayFilter(nativeGetSymbols(object), function(symbol) {
1970
1812
  return propertyIsEnumerable.call(object, symbol);
1971
1813
  });
1972
1814
  };
1973
1815
 
1974
- /**
1975
- * Copies own symbols of `source` to `object`.
1976
- *
1977
- * @private
1978
- * @param {Object} source The object to copy symbols from.
1979
- * @param {Object} [object={}] The object to copy symbols to.
1980
- * @returns {Object} Returns `object`.
1981
- */
1982
- function copySymbols(source, object) {
1983
- return copyObject(source, getSymbols(source), object);
1984
- }
1985
-
1986
- /* Built-in method references for those with the same name as other `lodash` methods. */
1987
- var nativeGetSymbols = Object.getOwnPropertySymbols;
1988
-
1989
- /**
1990
- * Creates an array of the own and inherited enumerable symbols of `object`.
1991
- *
1992
- * @private
1993
- * @param {Object} object The object to query.
1994
- * @returns {Array} Returns the array of symbols.
1995
- */
1996
- var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
1997
- var result = [];
1998
- while (object) {
1999
- arrayPush(result, getSymbols(object));
2000
- object = getPrototype(object);
2001
- }
2002
- return result;
2003
- };
2004
-
2005
- /**
2006
- * Copies own and inherited symbols of `source` to `object`.
2007
- *
2008
- * @private
2009
- * @param {Object} source The object to copy symbols from.
2010
- * @param {Object} [object={}] The object to copy symbols to.
2011
- * @returns {Object} Returns `object`.
2012
- */
2013
- function copySymbolsIn(source, object) {
2014
- return copyObject(source, getSymbolsIn(source), object);
2015
- }
2016
-
2017
1816
  /**
2018
1817
  * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
2019
1818
  * `keysFunc` and `symbolsFunc` to get the enumerable property names and
@@ -2041,18 +1840,6 @@
2041
1840
  return baseGetAllKeys(object, keys, getSymbols);
2042
1841
  }
2043
1842
 
2044
- /**
2045
- * Creates an array of own and inherited enumerable property names and
2046
- * symbols of `object`.
2047
- *
2048
- * @private
2049
- * @param {Object} object The object to query.
2050
- * @returns {Array} Returns the array of property names and symbols.
2051
- */
2052
- function getAllKeysIn(object) {
2053
- return baseGetAllKeys(object, keysIn, getSymbolsIn);
2054
- }
2055
-
2056
1843
  /* Built-in method references that are verified to be native. */
2057
1844
  var DataView = getNative(root, 'DataView');
2058
1845
 
@@ -2161,7 +1948,7 @@
2161
1948
  * @returns {Object} Returns the cloned data view.
2162
1949
  */
2163
1950
  function cloneDataView(dataView, isDeep) {
2164
- var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
1951
+ var buffer = cloneArrayBuffer(dataView.buffer) ;
2165
1952
  return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
2166
1953
  }
2167
1954
 
@@ -2205,7 +1992,7 @@
2205
1992
  * @returns {Object} Returns the cloned typed array.
2206
1993
  */
2207
1994
  function cloneTypedArray(typedArray, isDeep) {
2208
- var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
1995
+ var buffer = cloneArrayBuffer(typedArray.buffer) ;
2209
1996
  return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
2210
1997
  }
2211
1998
 
@@ -2254,12 +2041,12 @@
2254
2041
  return new Ctor(+object);
2255
2042
 
2256
2043
  case dataViewTag$1:
2257
- return cloneDataView(object, isDeep);
2044
+ return cloneDataView(object);
2258
2045
 
2259
2046
  case float32Tag$1: case float64Tag$1:
2260
2047
  case int8Tag$1: case int16Tag$1: case int32Tag$1:
2261
2048
  case uint8Tag$1: case uint8ClampedTag$1: case uint16Tag$1: case uint32Tag$1:
2262
- return cloneTypedArray(object, isDeep);
2049
+ return cloneTypedArray(object);
2263
2050
 
2264
2051
  case mapTag$2:
2265
2052
  return new Ctor;
@@ -2364,11 +2151,6 @@
2364
2151
  */
2365
2152
  var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
2366
2153
 
2367
- /** Used to compose bitmasks for cloning. */
2368
- var CLONE_DEEP_FLAG$1 = 1,
2369
- CLONE_FLAT_FLAG = 2,
2370
- CLONE_SYMBOLS_FLAG$1 = 4;
2371
-
2372
2154
  /** `Object#toString` result references. */
2373
2155
  var argsTag = '[object Arguments]',
2374
2156
  arrayTag = '[object Array]',
@@ -2431,10 +2213,7 @@
2431
2213
  * @returns {*} Returns the cloned value.
2432
2214
  */
2433
2215
  function baseClone(value, bitmask, customizer, key, object, stack) {
2434
- var result,
2435
- isDeep = bitmask & CLONE_DEEP_FLAG$1,
2436
- isFlat = bitmask & CLONE_FLAT_FLAG,
2437
- isFull = bitmask & CLONE_SYMBOLS_FLAG$1;
2216
+ var result;
2438
2217
  if (result !== undefined) {
2439
2218
  return result;
2440
2219
  }
@@ -2444,28 +2223,20 @@
2444
2223
  var isArr = isArray(value);
2445
2224
  if (isArr) {
2446
2225
  result = initCloneArray(value);
2447
- if (!isDeep) {
2448
- return copyArray(value, result);
2449
- }
2450
2226
  } else {
2451
2227
  var tag = getTag(value),
2452
2228
  isFunc = tag == funcTag || tag == genTag;
2453
2229
 
2454
2230
  if (isBuffer(value)) {
2455
- return cloneBuffer(value, isDeep);
2231
+ return cloneBuffer(value);
2456
2232
  }
2457
2233
  if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
2458
- result = (isFlat || isFunc) ? {} : initCloneObject(value);
2459
- if (!isDeep) {
2460
- return isFlat
2461
- ? copySymbolsIn(value, baseAssignIn(result, value))
2462
- : copySymbols(value, baseAssign(result, value));
2463
- }
2234
+ result = (isFunc) ? {} : initCloneObject(value);
2464
2235
  } else {
2465
2236
  if (!cloneableTags[tag]) {
2466
2237
  return object ? value : {};
2467
2238
  }
2468
- result = initCloneByTag(value, tag, isDeep);
2239
+ result = initCloneByTag(value, tag);
2469
2240
  }
2470
2241
  }
2471
2242
  // Check for circular references and return its corresponding clone.
@@ -2486,9 +2257,8 @@
2486
2257
  });
2487
2258
  }
2488
2259
 
2489
- var keysFunc = isFull
2490
- ? (isFlat ? getAllKeysIn : getAllKeys)
2491
- : (isFlat ? keysIn : keys);
2260
+ var keysFunc = (getAllKeys)
2261
+ ;
2492
2262
 
2493
2263
  var props = isArr ? undefined : keysFunc(value);
2494
2264
  arrayEach(props || value, function(subValue, key) {
@@ -2728,7 +2498,7 @@
2728
2498
  });
2729
2499
  const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
2730
2500
  const toHump = (name = "") => name.replace(/-(\w)/g, (_all, letter) => letter.toUpperCase());
2731
- const emptyFn = () => undefined;
2501
+ const emptyFn = () => void 0;
2732
2502
  const getNodePath = (id, data = []) => {
2733
2503
  const path = [];
2734
2504
  const get = function(id2, data2) {
@@ -2793,6 +2563,65 @@
2793
2563
  }
2794
2564
  return "";
2795
2565
  };
2566
+ const setUrlParam = (name, value, url = globalThis.location.href) => {
2567
+ const reg = new RegExp(`[?&#]${name}=([^&#]*)`, "gi");
2568
+ const matches = url.match(reg);
2569
+ const key = `{key${(/* @__PURE__ */ new Date()).getTime()}}`;
2570
+ let strArr;
2571
+ if (matches && matches.length > 0) {
2572
+ strArr = matches[matches.length - 1];
2573
+ } else {
2574
+ strArr = "";
2575
+ }
2576
+ const extra = `${name}=${value}`;
2577
+ if (strArr) {
2578
+ const first = strArr.charAt(0);
2579
+ url = url.replace(strArr, key);
2580
+ url = url.replace(key, value ? first + extra : "");
2581
+ } else if (value) {
2582
+ if (url.indexOf("?") > -1) {
2583
+ url += `&${extra}`;
2584
+ } else {
2585
+ url += `?${extra}`;
2586
+ }
2587
+ }
2588
+ return url;
2589
+ };
2590
+ const getSearchObj = (search = globalThis.location.search ? globalThis.location.search.substring(1) : "") => {
2591
+ return search.split("&").reduce((obj, item) => {
2592
+ const [a, b = ""] = item.split("=");
2593
+ return { ...obj, [a]: b };
2594
+ }, {});
2595
+ };
2596
+ const delQueStr = (url, ref) => {
2597
+ let str = "";
2598
+ if (url.indexOf("?") !== -1) {
2599
+ str = url.substring(url.indexOf("?") + 1);
2600
+ } else {
2601
+ return url;
2602
+ }
2603
+ let arr = [];
2604
+ let returnurl = "";
2605
+ const isHit = Array.isArray(ref) ? function(v) {
2606
+ return ~ref.indexOf(v);
2607
+ } : function(v) {
2608
+ return v === ref;
2609
+ };
2610
+ if (str.indexOf("&") !== -1) {
2611
+ arr = str.split("&");
2612
+ for (let i = 0, len = arr.length; i < len; i++) {
2613
+ if (!isHit(arr[i].split("=")[0])) {
2614
+ returnurl = `${returnurl + arr[i].split("=")[0]}=${arr[i].split("=")[1]}&`;
2615
+ }
2616
+ }
2617
+ return returnurl ? `${url.substr(0, url.indexOf("?"))}?${returnurl.substr(0, returnurl.length - 1)}` : url.substr(0, url.indexOf("?"));
2618
+ }
2619
+ arr = str.split("=");
2620
+ if (isHit(arr[0])) {
2621
+ return url.substr(0, url.indexOf("?"));
2622
+ }
2623
+ return url;
2624
+ };
2796
2625
  const isObject = (obj) => Object.prototype.toString.call(obj) === "[object Object]";
2797
2626
  const isPop = (node) => Boolean(node?.type?.toLowerCase().endsWith("pop"));
2798
2627
  const isPage = (node) => {
@@ -2954,13 +2783,13 @@
2954
2783
  const getDefaultValueFromFields = (fields) => {
2955
2784
  const data = {};
2956
2785
  const defaultValue = {
2957
- string: undefined,
2786
+ string: void 0,
2958
2787
  object: {},
2959
2788
  array: [],
2960
- boolean: undefined,
2961
- number: undefined,
2789
+ boolean: void 0,
2790
+ number: void 0,
2962
2791
  null: null,
2963
- any: undefined
2792
+ any: void 0
2964
2793
  };
2965
2794
  fields.forEach((field) => {
2966
2795
  if (typeof field.defaultValue !== "undefined") {
@@ -2974,6 +2803,7 @@
2974
2803
  data[field.name] = JSON.parse(field.defaultValue);
2975
2804
  } catch (e) {
2976
2805
  data[field.name] = defaultValue.object;
2806
+ console.warn("defaultValue 解析失败", field.defaultValue, e);
2977
2807
  }
2978
2808
  return;
2979
2809
  }
@@ -2991,7 +2821,7 @@
2991
2821
  data[field.name] = defaultValue[field.type];
2992
2822
  return;
2993
2823
  }
2994
- data[field.name] = undefined;
2824
+ data[field.name] = void 0;
2995
2825
  });
2996
2826
  return data;
2997
2827
  };
@@ -3073,6 +2903,7 @@
3073
2903
  exports.convertToNumber = convertToNumber;
3074
2904
  exports.createDiv = createDiv;
3075
2905
  exports.dataSourceTemplateRegExp = dataSourceTemplateRegExp;
2906
+ exports.delQueStr = delQueStr;
3076
2907
  exports.emptyFn = emptyFn;
3077
2908
  exports.filterXSS = filterXSS;
3078
2909
  exports.getDefaultValueFromFields = getDefaultValueFromFields;
@@ -3088,6 +2919,7 @@
3088
2919
  exports.getNodeInfo = getNodeInfo;
3089
2920
  exports.getNodePath = getNodePath;
3090
2921
  exports.getNodes = getNodes;
2922
+ exports.getSearchObj = getSearchObj;
3091
2923
  exports.getUrlParam = getUrlParam;
3092
2924
  exports.getValueByKeyPath = getValueByKeyPath;
3093
2925
  exports.guid = guid;
@@ -3106,6 +2938,7 @@
3106
2938
  exports.replaceChildNode = replaceChildNode;
3107
2939
  exports.setDslDomRelateConfig = setDslDomRelateConfig;
3108
2940
  exports.setIdToEl = setIdToEl;
2941
+ exports.setUrlParam = setUrlParam;
3109
2942
  exports.setValueByKeyPath = setValueByKeyPath;
3110
2943
  exports.sleep = sleep;
3111
2944
  exports.toHump = toHump;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.12",
2
+ "version": "1.5.14",
3
3
  "name": "@tmagic/utils",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-utils.umd.cjs",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "typescript": "*",
37
- "@tmagic/schema": "1.5.12"
37
+ "@tmagic/schema": "1.5.14"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "typescript": {
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export * from './dom';
40
40
  // for typeof global checks without @types/node
41
41
  declare let global: {};
42
42
 
43
+ // eslint-disable-next-line @typescript-eslint/naming-convention
43
44
  let _globalThis: any;
44
45
  export const getGlobalThis = (): any =>
45
46
  _globalThis ||
@@ -47,12 +48,12 @@ export const getGlobalThis = (): any =>
47
48
  typeof globalThis !== 'undefined'
48
49
  ? globalThis
49
50
  : typeof self !== 'undefined'
50
- ? self
51
- : typeof window !== 'undefined'
52
- ? window
53
- : typeof global !== 'undefined'
54
- ? global
55
- : {});
51
+ ? self
52
+ : typeof window !== 'undefined'
53
+ ? window
54
+ : typeof global !== 'undefined'
55
+ ? global
56
+ : {});
56
57
 
57
58
  export const sleep = (ms: number): Promise<void> =>
58
59
  new Promise((resolve) => {
@@ -162,6 +163,99 @@ export const getUrlParam = (param: string, url?: string) => {
162
163
  return '';
163
164
  };
164
165
 
166
+ /**
167
+ * 设置url中指定的参数
168
+ *
169
+ * @param {string}
170
+ * name [参数名]
171
+ * @param {string}
172
+ * value [参数值]
173
+ * @param {string}
174
+ * url [发生替换的url地址|默认为location.href]
175
+ * @return {string} [返回处理后的url]
176
+ */
177
+ export const setUrlParam = (name: string, value: string, url = globalThis.location.href) => {
178
+ const reg = new RegExp(`[?&#]${name}=([^&#]*)`, 'gi');
179
+
180
+ const matches = url.match(reg);
181
+
182
+ const key = `{key${new Date().getTime()}}`;
183
+ let strArr;
184
+
185
+ if (matches && matches.length > 0) {
186
+ strArr = matches[matches.length - 1];
187
+ } else {
188
+ strArr = '';
189
+ }
190
+
191
+ const extra = `${name}=${value}`;
192
+
193
+ // 当原url中含有要替换的属性:value不为空时,仅对值做替换,为空时,直接把参数删除掉
194
+ if (strArr) {
195
+ const first = strArr.charAt(0);
196
+ url = url.replace(strArr, key);
197
+ url = url.replace(key, value ? first + extra : '');
198
+ } else if (value) {
199
+ // 当原url中不含有要替换的属性且value值不为空时,直接在url后面添加参数字符串
200
+ if (url.indexOf('?') > -1) {
201
+ url += `&${extra}`;
202
+ } else {
203
+ url += `?${extra}`;
204
+ }
205
+ }
206
+ // 其它情况直接返回原url
207
+ return url;
208
+ };
209
+
210
+ export const getSearchObj = (
211
+ search = globalThis.location.search ? globalThis.location.search.substring(1) : '',
212
+ ): Record<string, string> => {
213
+ return search.split('&').reduce((obj, item) => {
214
+ const [a, b = ''] = item.split('=');
215
+ return { ...obj, [a]: b };
216
+ }, {});
217
+ };
218
+
219
+ export const delQueStr = (url: string, ref: string[] | string) => {
220
+ let str = '';
221
+ if (url.indexOf('?') !== -1) {
222
+ str = url.substring(url.indexOf('?') + 1);
223
+ } else {
224
+ return url;
225
+ }
226
+ let arr = [];
227
+ let returnurl = '';
228
+
229
+ const isHit = Array.isArray(ref)
230
+ ? function (v: string) {
231
+ return ~ref.indexOf(v);
232
+ }
233
+ : function (v: string) {
234
+ return v === ref;
235
+ };
236
+
237
+ if (str.indexOf('&') !== -1) {
238
+ arr = str.split('&');
239
+ for (let i = 0, len = arr.length; i < len; i++) {
240
+ if (!isHit(arr[i].split('=')[0])) {
241
+ returnurl = `${returnurl + arr[i].split('=')[0]}=${arr[i].split('=')[1]}&`;
242
+ }
243
+ }
244
+
245
+ return returnurl
246
+ ? `${url.substr(0, url.indexOf('?'))}?${returnurl.substr(0, returnurl.length - 1)}`
247
+ : url.substr(0, url.indexOf('?'));
248
+ }
249
+
250
+ arr = str.split('=');
251
+
252
+ if (isHit(arr[0])) {
253
+ return url.substr(0, url.indexOf('?'));
254
+ }
255
+
256
+ return url;
257
+ };
258
+
165
259
  export const isObject = (obj: any) => Object.prototype.toString.call(obj) === '[object Object]';
166
260
 
167
261
  export const isPop = (node: MComponent | null): boolean => Boolean(node?.type?.toLowerCase().endsWith('pop'));
@@ -410,6 +504,7 @@ export const getDefaultValueFromFields = (fields: DataSchema[]) => {
410
504
  data[field.name] = JSON.parse(field.defaultValue);
411
505
  } catch (e) {
412
506
  data[field.name] = defaultValue.object;
507
+ console.warn('defaultValue 解析失败', field.defaultValue, e);
413
508
  }
414
509
  return;
415
510
  }
package/types/index.d.ts CHANGED
@@ -44,6 +44,20 @@ declare const getNodePath: (id: Id, data?: MNode$1[]) => MNode$1[];
44
44
  declare const getNodeInfo: (id: Id, root: Pick<MApp, "id" | "items"> | null) => EditorNodeInfo;
45
45
  declare const filterXSS: (str: string) => string;
46
46
  declare const getUrlParam: (param: string, url?: string) => string;
47
+ /**
48
+ * 设置url中指定的参数
49
+ *
50
+ * @param {string}
51
+ * name [参数名]
52
+ * @param {string}
53
+ * value [参数值]
54
+ * @param {string}
55
+ * url [发生替换的url地址|默认为location.href]
56
+ * @return {string} [返回处理后的url]
57
+ */
58
+ declare const setUrlParam: (name: string, value: string, url?: string) => string;
59
+ declare const getSearchObj: (search?: string) => Record<string, string>;
60
+ declare const delQueStr: (url: string, ref: string[] | string) => string;
47
61
  declare const isObject: (obj: any) => boolean;
48
62
  declare const isPop: (node: MComponent | null) => boolean;
49
63
  declare const isPage: (node?: MComponent | null) => boolean;
@@ -97,4 +111,5 @@ interface NodeItem {
97
111
  declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[], evalCbAfter?: boolean) => void;
98
112
  declare const isValueIncludeDataSource: (value: any) => boolean;
99
113
 
100
- export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, type NodeItem, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
114
+ export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_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, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
115
+ export type { NodeItem };