@domql/utils 2.5.130 → 2.5.138

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/component.js CHANGED
@@ -1,6 +1,15 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isArray, isFunction, isObject, isString, joinArrays } from '.'
3
+ import {
4
+ deepCloneWithExtend,
5
+ exec,
6
+ isArray,
7
+ isFunction,
8
+ isObject,
9
+ isString,
10
+ joinArrays,
11
+ overwriteDeep
12
+ } from '.'
4
13
  const ENV = process.env.NODE_ENV
5
14
 
6
15
  export const checkIfKeyIsComponent = (key) => {
@@ -25,10 +34,16 @@ export const addAdditionalExtend = (newExtend, element) => {
25
34
  return { ...element, extend }
26
35
  }
27
36
 
37
+ const checkIfSugar = (element, parent, key) => {
38
+ const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element
39
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
40
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends
41
+ }
42
+
28
43
  export const extendizeByKey = (element, parent, key) => {
29
44
  const { context } = parent
30
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element
31
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data
45
+ const { tag, extend, childrenExtends } = element
46
+ const isSugar = checkIfSugar(element)
32
47
 
33
48
  const extendFromKey = key.includes('+')
34
49
  ? key.split('+') // get array of componentKeys
@@ -44,9 +59,10 @@ export const extendizeByKey = (element, parent, key) => {
44
59
  const isExtendKeyComponent = context && context.components[extendFromKey]
45
60
 
46
61
  if (element === isExtendKeyComponent) return element
47
- else if (!hasComponentAttrs || childProps) {
62
+ else if (isSugar) {
48
63
  return {
49
64
  extend: extendFromKey,
65
+ childExtend: childrenExtends,
50
66
  tag,
51
67
  props: { ...element }
52
68
  }
@@ -67,6 +83,27 @@ export const extendizeByKey = (element, parent, key) => {
67
83
  }
68
84
  }
69
85
 
86
+ function getCapitalCaseKeys (obj) {
87
+ return Object.keys(obj).filter(key => /^[A-Z]/.test(key))
88
+ }
89
+
90
+ export const addChildrenIfNotInOriginal = (element, parent, key) => {
91
+ const childElems = getCapitalCaseKeys(element.props)
92
+ if (!childElems.length) return element
93
+
94
+ for (const i in childElems) {
95
+ const childKey = childElems[i]
96
+ const childElem = element[childKey]
97
+ const newChild = element.props[childKey]
98
+ if (newChild.ignoreExtend) continue
99
+ if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
100
+ else {
101
+ const isSugar = checkIfSugar(childElem)
102
+ if (!isSugar) overwriteDeep(element[childKey].props, newChild)
103
+ }
104
+ }
105
+ }
106
+
70
107
  export const applyKeyComponentAsExtend = (element, parent, key) => {
71
108
  return extendizeByKey(element, parent, key) || element
72
109
  }
package/cookie.js CHANGED
@@ -27,3 +27,8 @@ export const getCookie = (cname) => {
27
27
  }
28
28
  return ''
29
29
  }
30
+
31
+ export const removeCookie = (cname) => {
32
+ if (isUndefined(document) || isUndefined(document.cookie)) return
33
+ document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
34
+ }
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var component_exports = {};
20
20
  __export(component_exports, {
21
21
  addAdditionalExtend: () => addAdditionalExtend,
22
+ addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
22
23
  applyComponentFromContext: () => applyComponentFromContext,
23
24
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
24
25
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
@@ -53,17 +54,23 @@ const addAdditionalExtend = (newExtend, element) => {
53
54
  const extend = (0, import__.joinArrays)(receivedArray, originalArray);
54
55
  return { ...element, extend };
55
56
  };
57
+ const checkIfSugar = (element, parent, key) => {
58
+ const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element;
59
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
60
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
61
+ };
56
62
  const extendizeByKey = (element, parent, key) => {
57
63
  const { context } = parent;
58
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
59
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
64
+ const { tag, extend, childrenExtends } = element;
65
+ const isSugar = checkIfSugar(element);
60
66
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
61
67
  const isExtendKeyComponent = context && context.components[extendFromKey];
62
68
  if (element === isExtendKeyComponent)
63
69
  return element;
64
- else if (!hasComponentAttrs || childProps) {
70
+ else if (isSugar) {
65
71
  return {
66
72
  extend: extendFromKey,
73
+ childExtend: childrenExtends,
67
74
  tag,
68
75
  props: { ...element }
69
76
  };
@@ -83,6 +90,28 @@ const extendizeByKey = (element, parent, key) => {
83
90
  };
84
91
  }
85
92
  };
93
+ function getCapitalCaseKeys(obj) {
94
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
95
+ }
96
+ const addChildrenIfNotInOriginal = (element, parent, key) => {
97
+ const childElems = getCapitalCaseKeys(element.props);
98
+ if (!childElems.length)
99
+ return element;
100
+ for (const i in childElems) {
101
+ const childKey = childElems[i];
102
+ const childElem = element[childKey];
103
+ const newChild = element.props[childKey];
104
+ if (newChild.ignoreExtend)
105
+ continue;
106
+ if (!childElem)
107
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
108
+ else {
109
+ const isSugar = checkIfSugar(childElem);
110
+ if (!isSugar)
111
+ (0, import__.overwriteDeep)(element[childKey].props, newChild);
112
+ }
113
+ }
114
+ };
86
115
  const applyKeyComponentAsExtend = (element, parent, key) => {
87
116
  return extendizeByKey(element, parent, key) || element;
88
117
  };
@@ -20,6 +20,7 @@ var cookie_exports = {};
20
20
  __export(cookie_exports, {
21
21
  getCookie: () => getCookie,
22
22
  isMobile: () => isMobile,
23
+ removeCookie: () => removeCookie,
23
24
  setCookie: () => setCookie
24
25
  });
25
26
  module.exports = __toCommonJS(cookie_exports);
@@ -49,3 +50,8 @@ const getCookie = (cname) => {
49
50
  }
50
51
  return "";
51
52
  };
53
+ const removeCookie = (cname) => {
54
+ if ((0, import_types.isUndefined)(import_utils.document) || (0, import_types.isUndefined)(import_utils.document.cookie))
55
+ return;
56
+ import_utils.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
57
+ };
@@ -29,6 +29,7 @@ __export(object_exports, {
29
29
  deepDiff: () => deepDiff,
30
30
  deepMerge: () => deepMerge,
31
31
  deepStringify: () => deepStringify,
32
+ deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
32
33
  detachFunctionsFromObject: () => detachFunctionsFromObject,
33
34
  detectInfiniteLoop: () => detectInfiniteLoop,
34
35
  diff: () => diff,
@@ -179,6 +180,11 @@ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
179
180
  return o;
180
181
  };
181
182
  const deepStringify = (obj, stringified = {}) => {
183
+ var _a;
184
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
185
+ console.warn("Trying to clone element or state at", obj);
186
+ obj = (_a = obj.parse) == null ? void 0 : _a.call(obj);
187
+ }
182
188
  for (const prop in obj) {
183
189
  const objProp = obj[prop];
184
190
  if ((0, import_types.isFunction)(objProp)) {
@@ -204,6 +210,39 @@ const deepStringify = (obj, stringified = {}) => {
204
210
  }
205
211
  return stringified;
206
212
  };
213
+ const MAX_DEPTH = 100;
214
+ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
215
+ if (depth > MAX_DEPTH) {
216
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
217
+ return "[MAX_DEPTH_EXCEEDED]";
218
+ }
219
+ for (const prop in obj) {
220
+ const currentPath = path ? `${path}.${prop}` : prop;
221
+ const objProp = obj[prop];
222
+ if ((0, import_types.isFunction)(objProp)) {
223
+ stringified[prop] = objProp.toString();
224
+ } else if ((0, import_types.isObject)(objProp)) {
225
+ stringified[prop] = {};
226
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
227
+ } else if ((0, import_types.isArray)(objProp)) {
228
+ stringified[prop] = [];
229
+ objProp.forEach((v, i) => {
230
+ const itemPath = `${currentPath}[${i}]`;
231
+ if ((0, import_types.isObject)(v)) {
232
+ stringified[prop][i] = {};
233
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
234
+ } else if ((0, import_types.isFunction)(v)) {
235
+ stringified[prop][i] = v.toString();
236
+ } else {
237
+ stringified[prop][i] = v;
238
+ }
239
+ });
240
+ } else {
241
+ stringified[prop] = objProp;
242
+ }
243
+ }
244
+ return stringified;
245
+ };
207
246
  const objectToString = (obj = {}, indent = 0) => {
208
247
  const spaces = " ".repeat(indent);
209
248
  let str = "{\n";
package/object.js CHANGED
@@ -199,6 +199,11 @@ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) =
199
199
  * Stringify object
200
200
  */
201
201
  export const deepStringify = (obj, stringified = {}) => {
202
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
203
+ console.warn('Trying to clone element or state at', obj)
204
+ obj = obj.parse?.()
205
+ }
206
+
202
207
  for (const prop in obj) {
203
208
  const objProp = obj[prop]
204
209
  if (isFunction(objProp)) {
@@ -225,6 +230,42 @@ export const deepStringify = (obj, stringified = {}) => {
225
230
  return stringified
226
231
  }
227
232
 
233
+ const MAX_DEPTH = 100 // Adjust this value as needed
234
+ export const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = '') => {
235
+ if (depth > MAX_DEPTH) {
236
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`)
237
+ return '[MAX_DEPTH_EXCEEDED]'
238
+ }
239
+
240
+ for (const prop in obj) {
241
+ const currentPath = path ? `${path}.${prop}` : prop
242
+ const objProp = obj[prop]
243
+
244
+ if (isFunction(objProp)) {
245
+ stringified[prop] = objProp.toString()
246
+ } else if (isObject(objProp)) {
247
+ stringified[prop] = {}
248
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath)
249
+ } else if (isArray(objProp)) {
250
+ stringified[prop] = []
251
+ objProp.forEach((v, i) => {
252
+ const itemPath = `${currentPath}[${i}]`
253
+ if (isObject(v)) {
254
+ stringified[prop][i] = {}
255
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath)
256
+ } else if (isFunction(v)) {
257
+ stringified[prop][i] = v.toString()
258
+ } else {
259
+ stringified[prop][i] = v
260
+ }
261
+ })
262
+ } else {
263
+ stringified[prop] = objProp
264
+ }
265
+ }
266
+ return stringified
267
+ }
268
+
228
269
  export const objectToString = (obj = {}, indent = 0) => {
229
270
  const spaces = ' '.repeat(indent)
230
271
  let str = '{\n'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.130",
3
+ "version": "2.5.138",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -25,7 +25,7 @@
25
25
  "build": "yarn build:cjs",
26
26
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
27
27
  },
28
- "gitHead": "88815c621b7aeb9458c779643934c0d2e5305cd2",
28
+ "gitHead": "91afb60b8354f1a95c3364be94ba74612f907918",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }