@domql/element 2.5.117 → 2.5.120

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/create.js CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  applyVariant,
36
36
  checkIfKeyIsComponent,
37
37
  createValidDomqlObjectFromSugar,
38
+ detectInfiniteLoop,
38
39
  isVariant
39
40
  } from './utils/component'
40
41
 
@@ -46,8 +47,6 @@ const ENV = process.env.NODE_ENV
46
47
  const create = (element, parent, key, options = OPTIONS.create || {}, attachOptions) => {
47
48
  cacheOptions(element, options)
48
49
 
49
- // if (key === 'Title') debugger
50
-
51
50
  // if element is STRING
52
51
  if (checkIfPrimitive(element)) {
53
52
  element = applyValueAsText(element, parent, key)
@@ -212,12 +211,23 @@ const addElementIntoParentChildren = (element, parent) => {
212
211
  if (parent.__ref && parent.__ref.__children) parent.__ref.__children.push(element.key)
213
212
  }
214
213
 
214
+ const visitedElements = new WeakMap()
215
215
  const renderElement = (element, parent, options, attachOptions) => {
216
+ if (visitedElements.has(element)) {
217
+ console.warn('Cyclic rendering detected:', element)
218
+ return
219
+ }
220
+
221
+ visitedElements.set(element, true)
222
+
216
223
  const { __ref: ref, key } = element
217
224
 
218
225
  // CREATE a real NODE
219
226
  try {
227
+ const isInfiniteLoop = detectInfiniteLoop(ref.__path)
228
+ if (ref.__uniqId || isInfiniteLoop) return
220
229
  createNode(element, options)
230
+ ref.__uniqId = Math.random()
221
231
  } catch (e) {
222
232
  if (ENV === 'test' || ENV === 'development') console.warn(element, e)
223
233
  }
@@ -167,10 +167,20 @@ const addElementIntoParentChildren = (element, parent) => {
167
167
  if (parent.__ref && parent.__ref.__children)
168
168
  parent.__ref.__children.push(element.key);
169
169
  };
170
+ const visitedElements = /* @__PURE__ */ new WeakMap();
170
171
  const renderElement = (element, parent, options, attachOptions) => {
172
+ if (visitedElements.has(element)) {
173
+ console.warn("Cyclic rendering detected:", element);
174
+ return;
175
+ }
176
+ visitedElements.set(element, true);
171
177
  const { __ref: ref, key } = element;
172
178
  try {
179
+ const isInfiniteLoop = (0, import_component.detectInfiniteLoop)(ref.__path);
180
+ if (ref.__uniqId || isInfiniteLoop)
181
+ return;
173
182
  (0, import_node.default)(element, options);
183
+ ref.__uniqId = Math.random();
174
184
  } catch (e) {
175
185
  if (ENV === "test" || ENV === "development")
176
186
  console.warn(element, e);
@@ -28,7 +28,8 @@ let mainExtend;
28
28
  const applyExtend = (element, parent, options = {}) => {
29
29
  if ((0, import_utils.isFunction)(element))
30
30
  element = (0, import_utils.exec)(element, parent);
31
- let { extend, props, __ref } = element;
31
+ const { props, __ref } = element;
32
+ let extend = (props == null ? void 0 : props.extends) || element.extend;
32
33
  const context = element.context || parent.context;
33
34
  extend = (0, import_utils2.fallbackStringExtend)(extend, context, options);
34
35
  const extendStack = (0, import_utils2.getExtendStack)(extend, context);
package/dist/cjs/node.js CHANGED
@@ -78,7 +78,9 @@ const createNode = (element, options) => {
78
78
  if (isElement) {
79
79
  const { hasDefine, hasContextDefine } = isElement;
80
80
  if (element[param] && !hasDefine && !hasContextDefine) {
81
- const createAsync = () => (0, import_create.default)((0, import_utils.exec)(value, element), element, param, options);
81
+ const createAsync = () => {
82
+ (0, import_create.default)((0, import_utils.exec)(value, element), element, param, options);
83
+ };
82
84
  if (element.props && element.props.lazyLoad || options.lazyLoad) {
83
85
  window.requestAnimationFrame(() => createAsync());
84
86
  } else
@@ -25,6 +25,7 @@ __export(component_exports, {
25
25
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
26
26
  checkIfKeyIsProperty: () => checkIfKeyIsProperty,
27
27
  createValidDomqlObjectFromSugar: () => createValidDomqlObjectFromSugar,
28
+ detectInfiniteLoop: () => detectInfiniteLoop,
28
29
  extendizeByKey: () => extendizeByKey,
29
30
  hasVariantProp: () => hasVariantProp,
30
31
  isVariant: () => isVariant,
@@ -33,20 +34,8 @@ __export(component_exports, {
33
34
  module.exports = __toCommonJS(component_exports);
34
35
  var import_utils = require("@domql/utils");
35
36
  var import_extend = require("../extend");
37
+ var import_mixins = require("../mixins");
36
38
  const ENV = "development";
37
- const DOMQL_BUILTINS = [
38
- "extend",
39
- "childExtend",
40
- "childExtendRecursive",
41
- "define",
42
- "props",
43
- "state",
44
- "on",
45
- "if",
46
- "attr",
47
- "key",
48
- "tag"
49
- ];
50
39
  const checkIfKeyIsComponent = (key) => {
51
40
  const isFirstKeyString = (0, import_utils.isString)(key);
52
41
  if (!isFirstKeyString)
@@ -77,17 +66,16 @@ const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
77
66
  for (const k in el) {
78
67
  const prop = el[k];
79
68
  const isEvent = k.startsWith("on");
80
- const isMethod = k.startsWith("$");
81
69
  if (isEvent) {
82
70
  const onKey = replaceOnKeys(prop);
83
71
  newElem.on[onKey] = prop;
84
- } else if (!isMethod && checkIfKeyIsProperty(k)) {
85
- if (!DOMQL_BUILTINS.includes(k))
86
- newElem.props[k] = prop;
87
- } else if (checkIfKeyIsComponent(k)) {
72
+ }
73
+ const isComponent = checkIfKeyIsComponent(k);
74
+ const isRegistry = import_mixins.registry[k];
75
+ if (isComponent || isRegistry) {
88
76
  newElem[k] = prop;
89
77
  } else {
90
- newElem[k] = prop;
78
+ newElem.props[k] = prop;
91
79
  }
92
80
  }
93
81
  return newElem;
@@ -187,3 +175,24 @@ const applyVariant = (element) => {
187
175
  });
188
176
  return element;
189
177
  };
178
+ const detectInfiniteLoop = (actions) => {
179
+ const maxRepeats = 10;
180
+ let pattern = [];
181
+ let repeatCount = 0;
182
+ for (let i = 0; i < actions.length; i++) {
183
+ if (pattern.length < 2) {
184
+ pattern.push(actions[i]);
185
+ } else {
186
+ if (actions[i] === pattern[i % 2]) {
187
+ repeatCount++;
188
+ } else {
189
+ pattern = [actions[i]];
190
+ repeatCount = 0;
191
+ }
192
+ if (repeatCount > maxRepeats * 2) {
193
+ console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
194
+ return true;
195
+ }
196
+ }
197
+ }
198
+ };
@@ -68,7 +68,7 @@ const deepClone = (obj, exclude = METHODS_EXL, seen = /* @__PURE__ */ new WeakMa
68
68
  if (obj === null || typeof obj !== "object") {
69
69
  return obj;
70
70
  }
71
- if (obj instanceof Node || obj === window || obj instanceof Document) {
71
+ if (obj instanceof window.Node || obj === window || obj instanceof window.Document) {
72
72
  return obj;
73
73
  }
74
74
  if (seen.has(obj)) {
package/extend.js CHANGED
@@ -20,7 +20,8 @@ let mainExtend
20
20
  export const applyExtend = (element, parent, options = {}) => {
21
21
  if (isFunction(element)) element = exec(element, parent)
22
22
 
23
- let { extend, props, __ref } = element
23
+ const { props, __ref } = element
24
+ let extend = props?.extends || element.extend
24
25
  const context = element.context || parent.context
25
26
 
26
27
  extend = fallbackStringExtend(extend, context, options)
package/node.js CHANGED
@@ -73,7 +73,9 @@ export const createNode = (element, options) => {
73
73
  if (isElement) {
74
74
  const { hasDefine, hasContextDefine } = isElement
75
75
  if (element[param] && !hasDefine && !hasContextDefine) {
76
- const createAsync = () => create(exec(value, element), element, param, options)
76
+ const createAsync = () => {
77
+ create(exec(value, element), element, param, options)
78
+ }
77
79
 
78
80
  if ((element.props && element.props.lazyLoad) || options.lazyLoad) {
79
81
  window.requestAnimationFrame(() => createAsync())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.117",
3
+ "version": "2.5.120",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -31,7 +31,7 @@
31
31
  "@domql/state": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "56be344ba28e3cb51c146c1b74fe3c0e21341879",
34
+ "gitHead": "ca99941529086268c7c106229ef1873faf5ac54c",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
package/props/create.js CHANGED
@@ -51,10 +51,6 @@ export const syncProps = (props, element) => {
51
51
  export const createProps = function (element, parent, cached) {
52
52
  const { __ref: ref } = element
53
53
 
54
- // if (element.parent.key === '0' && element.key === 'editor') {
55
- // debugger
56
- // }
57
-
58
54
  const applyProps = () => {
59
55
  const propsStack = cached || createPropsStack(element, parent)
60
56
  if (propsStack.length) {
package/update.js CHANGED
@@ -82,7 +82,6 @@ const update = function (params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
82
82
 
83
83
  const overwriteChanges = overwriteDeep(element, params, METHODS_EXL)
84
84
  const execChanges = throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
85
- // if (element.key === 'Navigation') debugger
86
85
  const definedChanges = throughUpdatedDefine(element)
87
86
 
88
87
  if (!options.isForced && !options.preventListeners) {
@@ -2,22 +2,9 @@
2
2
 
3
3
  import { exec, isArray, isFunction, isObject, isString, joinArrays, overwriteDeep } from '@domql/utils'
4
4
  import { applyExtend } from '../extend'
5
+ import { registry } from '../mixins'
5
6
  const ENV = process.env.NODE_ENV
6
7
 
7
- const DOMQL_BUILTINS = [
8
- 'extend',
9
- 'childExtend',
10
- 'childExtendRecursive',
11
- 'define',
12
- 'props',
13
- 'state',
14
- 'on',
15
- 'if',
16
- 'attr',
17
- 'key',
18
- 'tag'
19
- ]
20
-
21
8
  export const checkIfKeyIsComponent = (key) => {
22
9
  const isFirstKeyString = isString(key)
23
10
  if (!isFirstKeyString) return
@@ -50,16 +37,18 @@ export const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
50
37
  for (const k in el) {
51
38
  const prop = el[k]
52
39
  const isEvent = k.startsWith('on')
53
- const isMethod = k.startsWith('$')
54
40
  if (isEvent) {
55
41
  const onKey = replaceOnKeys(prop)
56
42
  newElem.on[onKey] = prop
57
- } else if (!isMethod && checkIfKeyIsProperty(k)) {
58
- if (!DOMQL_BUILTINS.includes(k)) newElem.props[k] = prop
59
- } else if (checkIfKeyIsComponent(k)) {
43
+ // } else if (!isMethod && checkIfKeyIsProperty(k)) {
44
+ }
45
+
46
+ const isComponent = checkIfKeyIsComponent(k)
47
+ const isRegistry = registry[k]
48
+ if (isComponent || isRegistry) {
60
49
  newElem[k] = prop
61
50
  } else {
62
- newElem[k] = prop
51
+ newElem.props[k] = prop
63
52
  }
64
53
  }
65
54
  return newElem
@@ -176,3 +165,31 @@ export const applyVariant = (element) => {
176
165
 
177
166
  return element
178
167
  }
168
+
169
+ export const detectInfiniteLoop = (actions) => {
170
+ const maxRepeats = 10 // Maximum allowed repetitions
171
+ let pattern = []
172
+ let repeatCount = 0
173
+
174
+ for (let i = 0; i < actions.length; i++) {
175
+ if (pattern.length < 2) {
176
+ // Build the initial pattern with two consecutive elements
177
+ pattern.push(actions[i])
178
+ } else {
179
+ // Check if the current element follows the repeating pattern
180
+ if (actions[i] === pattern[i % 2]) {
181
+ repeatCount++
182
+ } else {
183
+ // If there's a mismatch, reset the pattern and repeat counter
184
+ pattern = [actions[i]]
185
+ repeatCount = 0
186
+ }
187
+
188
+ // If the pattern has repeated more than `maxRepeats` times, throw a warning
189
+ if (repeatCount > maxRepeats * 2) { // *2 because it increments for both "Hgroup" and "content"
190
+ console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
191
+ return true
192
+ }
193
+ }
194
+ }
195
+ }
package/utils/object.js CHANGED
@@ -45,7 +45,7 @@ export const deepClone = (obj, exclude = METHODS_EXL, seen = new WeakMap()) => {
45
45
  }
46
46
 
47
47
  // Check for DOM nodes, Window, or Document
48
- if (obj instanceof Node || obj === window || obj instanceof Document) {
48
+ if (obj instanceof window.Node || obj === window || obj instanceof window.Document) {
49
49
  return obj
50
50
  }
51
51