@domql/element 2.5.120 → 2.5.122

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
@@ -214,8 +214,7 @@ const addElementIntoParentChildren = (element, parent) => {
214
214
  const visitedElements = new WeakMap()
215
215
  const renderElement = (element, parent, options, attachOptions) => {
216
216
  if (visitedElements.has(element)) {
217
- console.warn('Cyclic rendering detected:', element)
218
- return
217
+ if (ENV === 'test' || ENV === 'development') console.warn('Cyclic rendering detected:', element.__ref.__path)
219
218
  }
220
219
 
221
220
  visitedElements.set(element, true)
@@ -224,8 +223,8 @@ const renderElement = (element, parent, options, attachOptions) => {
224
223
 
225
224
  // CREATE a real NODE
226
225
  try {
227
- const isInfiniteLoop = detectInfiniteLoop(ref.__path)
228
- if (ref.__uniqId || isInfiniteLoop) return
226
+ const isInfiniteLoopDetected = detectInfiniteLoop(ref.__path)
227
+ if (ref.__uniqId || isInfiniteLoopDetected) return
229
228
  createNode(element, options)
230
229
  ref.__uniqId = Math.random()
231
230
  } catch (e) {
@@ -170,14 +170,14 @@ const addElementIntoParentChildren = (element, parent) => {
170
170
  const visitedElements = /* @__PURE__ */ new WeakMap();
171
171
  const renderElement = (element, parent, options, attachOptions) => {
172
172
  if (visitedElements.has(element)) {
173
- console.warn("Cyclic rendering detected:", element);
174
- return;
173
+ if (ENV === "test" || ENV === "development")
174
+ console.warn("Cyclic rendering detected:", element.__ref.__path);
175
175
  }
176
176
  visitedElements.set(element, true);
177
177
  const { __ref: ref, key } = element;
178
178
  try {
179
- const isInfiniteLoop = (0, import_component.detectInfiniteLoop)(ref.__path);
180
- if (ref.__uniqId || isInfiniteLoop)
179
+ const isInfiniteLoopDetected = (0, import_component.detectInfiniteLoop)(ref.__path);
180
+ if (ref.__uniqId || isInfiniteLoopDetected)
181
181
  return;
182
182
  (0, import_node.default)(element, options);
183
183
  ref.__uniqId = Math.random();
@@ -53,25 +53,25 @@ const UPDATE_DEFAULT_OPTIONS = {
53
53
  calleeElement: false,
54
54
  excludes: import_utils2.METHODS_EXL
55
55
  };
56
- const update = function(params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
57
- const calleeElementCache = opts.calleeElement;
58
- const options = (0, import_utils2.deepClone)((0, import_utils2.deepMerge)(opts, UPDATE_DEFAULT_OPTIONS), ["calleeElement"]);
56
+ const update = function(params = {}, opts) {
57
+ const calleeElementCache = opts == null ? void 0 : opts.calleeElement;
58
+ const options = (0, import_utils2.deepClone)((0, import_utils.isObject)(opts) ? (0, import_utils2.deepMerge)(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS, ["calleeElement"]);
59
59
  options.calleeElement = calleeElementCache;
60
60
  const element = this;
61
61
  const { parent, node, key } = element;
62
62
  const { excludes, preventInheritAtCurrentState } = options;
63
- if (!options.preventListeners)
64
- (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
65
- if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
66
- return;
67
- if (!excludes)
68
- (0, import_utils.merge)(options, UPDATE_DEFAULT_OPTIONS);
69
63
  let ref = element.__ref;
70
64
  if (!ref)
71
65
  ref = element.__ref = {};
72
66
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options);
73
67
  if (snapshotHasUpdated)
74
68
  return;
69
+ if (!options.preventListeners)
70
+ (0, import_event.triggerEventOnUpdate)("startUpdate", params, element, options);
71
+ if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
72
+ return;
73
+ if (!excludes)
74
+ (0, import_utils.merge)(options, UPDATE_DEFAULT_OPTIONS);
75
75
  if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
76
76
  params = { text: params };
77
77
  }
@@ -129,6 +129,9 @@ const update = function(params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
129
129
  }
130
130
  for (const param in element) {
131
131
  const prop = element[param];
132
+ if (element.Iframe && element.Overlay && element.ComponentFrameCanvas && param === "Iframe") {
133
+ console.log("isframe");
134
+ }
132
135
  if (!Object.hasOwnProperty.call(element, param))
133
136
  continue;
134
137
  const hasOnlyUpdateFalsy = onlyUpdate && (onlyUpdate !== param || !element.lookup(onlyUpdate));
@@ -166,7 +169,7 @@ const captureSnapshot = (element, options) => {
166
169
  ref.__currentSnapshot = createdStanpshot;
167
170
  return [createdStanpshot, element];
168
171
  }
169
- const snapshotOnCallee = ref.__currentSnapshot;
172
+ const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
170
173
  if (currentSnapshot < snapshotOnCallee) {
171
174
  return [snapshotOnCallee, calleeElement, true];
172
175
  }
@@ -261,7 +264,7 @@ const createStateUpdate = (element, parent, options) => {
261
264
  for (const child in __stateChildren) {
262
265
  if (newState[child])
263
266
  newState.__children[child] = __stateChildren[child];
264
- __stateChildren[child].parent = newState;
267
+ Object.getPrototypeOf(__stateChildren[child]).parent = newState;
265
268
  }
266
269
  return newState;
267
270
  };
@@ -175,22 +175,24 @@ const applyVariant = (element) => {
175
175
  });
176
176
  return element;
177
177
  };
178
- const detectInfiniteLoop = (actions) => {
178
+ const detectInfiniteLoop = (arr) => {
179
179
  const maxRepeats = 10;
180
180
  let pattern = [];
181
181
  let repeatCount = 0;
182
- for (let i = 0; i < actions.length; i++) {
182
+ for (let i = 0; i < arr.length; i++) {
183
183
  if (pattern.length < 2) {
184
- pattern.push(actions[i]);
184
+ pattern.push(arr[i]);
185
185
  } else {
186
- if (actions[i] === pattern[i % 2]) {
186
+ if (arr[i] === pattern[i % 2]) {
187
187
  repeatCount++;
188
188
  } else {
189
- pattern = [actions[i]];
190
- repeatCount = 0;
189
+ pattern = [arr[i - 1], arr[i]];
190
+ repeatCount = 1;
191
191
  }
192
- if (repeatCount > maxRepeats * 2) {
193
- console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
192
+ if (repeatCount >= maxRepeats * 2) {
193
+ if (ENV === "test" || ENV === "development") {
194
+ console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
195
+ }
194
196
  return true;
195
197
  }
196
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.120",
3
+ "version": "2.5.122",
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": "ca99941529086268c7c106229ef1873faf5ac54c",
34
+ "gitHead": "2f048372ece4d808cfaca8e43491611dafe3ad5f",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
package/update.js CHANGED
@@ -39,25 +39,24 @@ const UPDATE_DEFAULT_OPTIONS = {
39
39
  excludes: METHODS_EXL
40
40
  }
41
41
 
42
- const update = function (params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
43
- const calleeElementCache = opts.calleeElement
44
- const options = deepClone(deepMerge(opts, UPDATE_DEFAULT_OPTIONS), ['calleeElement'])
42
+ const update = function (params = {}, opts) {
43
+ const calleeElementCache = opts?.calleeElement
44
+ const options = deepClone(isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS, ['calleeElement'])
45
45
  options.calleeElement = calleeElementCache
46
46
  const element = this
47
47
  const { parent, node, key } = element
48
48
  const { excludes, preventInheritAtCurrentState } = options
49
49
 
50
- if (!options.preventListeners) triggerEventOnUpdate('startUpdate', params, element, options)
51
-
52
- if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
53
- if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
54
-
55
50
  let ref = element.__ref
56
51
  if (!ref) ref = element.__ref = {}
57
-
58
52
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options)
59
53
  if (snapshotHasUpdated) return
60
54
 
55
+ if (!options.preventListeners) triggerEventOnUpdate('startUpdate', params, element, options)
56
+
57
+ if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) return
58
+ if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
59
+
61
60
  if (isString(params) || isNumber(params)) {
62
61
  params = { text: params }
63
62
  }
@@ -113,6 +112,10 @@ const update = function (params = {}, opts = UPDATE_DEFAULT_OPTIONS) {
113
112
  for (const param in element) {
114
113
  const prop = element[param]
115
114
 
115
+ if (element.Iframe && element.Overlay && element.ComponentFrameCanvas && param === 'Iframe') {
116
+ console.log('isframe')
117
+ }
118
+
116
119
  if (!Object.hasOwnProperty.call(element, param)) continue
117
120
 
118
121
  const hasOnlyUpdateFalsy = onlyUpdate && (onlyUpdate !== param || !element.lookup(onlyUpdate))
@@ -166,7 +169,8 @@ const captureSnapshot = (element, options) => {
166
169
  return [createdStanpshot, element]
167
170
  }
168
171
 
169
- const snapshotOnCallee = ref.__currentSnapshot
172
+ const snapshotOnCallee = calleeElement.__ref.__currentSnapshot
173
+
170
174
  if (currentSnapshot < snapshotOnCallee) {
171
175
  return [snapshotOnCallee, calleeElement, true]
172
176
  }
@@ -297,7 +301,8 @@ const createStateUpdate = (element, parent, options) => {
297
301
  for (const child in __stateChildren) {
298
302
  // check this for inherited states
299
303
  if (newState[child]) newState.__children[child] = __stateChildren[child]
300
- __stateChildren[child].parent = newState
304
+ // __stateChildren[child].parent = newState
305
+ Object.getPrototypeOf(__stateChildren[child]).parent = newState
301
306
  }
302
307
  return newState
303
308
  }
@@ -166,28 +166,30 @@ export const applyVariant = (element) => {
166
166
  return element
167
167
  }
168
168
 
169
- export const detectInfiniteLoop = (actions) => {
169
+ export const detectInfiniteLoop = arr => {
170
170
  const maxRepeats = 10 // Maximum allowed repetitions
171
171
  let pattern = []
172
172
  let repeatCount = 0
173
173
 
174
- for (let i = 0; i < actions.length; i++) {
174
+ for (let i = 0; i < arr.length; i++) {
175
175
  if (pattern.length < 2) {
176
176
  // Build the initial pattern with two consecutive elements
177
- pattern.push(actions[i])
177
+ pattern.push(arr[i])
178
178
  } else {
179
179
  // Check if the current element follows the repeating pattern
180
- if (actions[i] === pattern[i % 2]) {
180
+ if (arr[i] === pattern[i % 2]) {
181
181
  repeatCount++
182
182
  } else {
183
183
  // If there's a mismatch, reset the pattern and repeat counter
184
- pattern = [actions[i]]
185
- repeatCount = 0
184
+ pattern = [arr[i - 1], arr[i]]
185
+ repeatCount = 1 // Reset to 1 because we start a new potential pattern
186
186
  }
187
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)
188
+ // If the pattern repeats more than `maxRepeats`, throw a warning
189
+ if (repeatCount >= maxRepeats * 2) {
190
+ if (ENV === 'test' || ENV === 'development') {
191
+ console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern)
192
+ }
191
193
  return true
192
194
  }
193
195
  }