@domql/element 2.31.26 → 2.31.28

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/methods/index.js CHANGED
@@ -75,6 +75,12 @@ export function lookdown(param) {
75
75
 
76
76
  if (v === param) return childElem
77
77
  else if (isFunction(param)) {
78
+ if (!childElem) {
79
+ this.error(
80
+ `"${v}" found in element __children, but content is not defined`
81
+ )
82
+ continue
83
+ }
78
84
  const exec = param(childElem, childElem.state, childElem.context)
79
85
  if (childElem.state && exec) {
80
86
  return childElem
@@ -98,6 +104,12 @@ export function lookdownAll(param, results = []) {
98
104
 
99
105
  if (v === param) results.push(childElem)
100
106
  else if (isFunction(param)) {
107
+ if (!childElem) {
108
+ this.error(
109
+ `"${v}" found in element __children, but content is not defined`
110
+ )
111
+ continue
112
+ }
101
113
  const exec = param(childElem, childElem.state, childElem.context)
102
114
  if (childElem.state && exec) results.push(childElem)
103
115
  }
@@ -121,7 +133,7 @@ export function setNodeStyles(params = {}) {
121
133
  return el
122
134
  }
123
135
 
124
- export async function remove(opts) {
136
+ export async function remove(opts = {}) {
125
137
  const element = this
126
138
  const beforeRemoveReturns = triggerEventOn('beforeRemove', element, opts)
127
139
  if (beforeRemoveReturns === false) return element
@@ -144,10 +156,10 @@ export function get(param) {
144
156
  return element[param]
145
157
  }
146
158
 
147
- export function setProps(param, options) {
159
+ export function setProps(param, opts = {}) {
148
160
  const element = this
149
161
  if (!param || !element.props) return
150
- element.update({ props: param }, options)
162
+ element.update({ props: param }, opts)
151
163
  return element
152
164
  }
153
165
 
@@ -274,6 +286,8 @@ export function error(...params) {
274
286
  // if (isNotProduction()) {
275
287
  if (params[params.length - 1]?.debugger) debugger // eslint-disable-line
276
288
  if (params[params.length - 1]?.verbose) verbose.call(this, ...params)
289
+ if (isFunction(params[params.length - 1]?.onError))
290
+ params[params.length - 1]?.onError.call(this, ...params)
277
291
  console.error(...params, this)
278
292
  // }
279
293
  }
@@ -289,8 +303,8 @@ export function nextElement() {
289
303
  return parent[nextChild]
290
304
  }
291
305
 
292
- export async function append(el, key) {
293
- return await create(el, this, key)
306
+ export async function append(el, key, opts) {
307
+ return await create(el, this, key, opts)
294
308
  }
295
309
 
296
310
  export function previousElement(el) {
@@ -363,8 +377,8 @@ export function call(fnKey, ...args) {
363
377
  // Return synchronous results directly
364
378
  return result
365
379
  } catch (error) {
366
- console.error(`Error calling '${fnKey}':`, error)
367
- throw error
380
+ console.error(`Error calling '${fnKey}'`)
381
+ throw new Error(error)
368
382
  }
369
383
  }
370
384
 
package/mixins/content.js CHANGED
@@ -43,7 +43,7 @@ export const removeContent = function (el, opts = {}) {
43
43
  __cached[contentElementKey].remove()
44
44
  }
45
45
 
46
- ref.__children.splice(ref.__children.indexOf(element[contentElementKey]), 1)
46
+ ref.__children.splice(ref.__children.indexOf(contentElementKey), 1)
47
47
 
48
48
  delete element[contentElementKey]
49
49
  }
@@ -53,7 +53,7 @@ export const removeContent = function (el, opts = {}) {
53
53
  * Appends anything as content
54
54
  * an original one as a child
55
55
  */
56
- export async function setContent (param, element, node, opts) {
56
+ export async function setContent(param, element, node, opts) {
57
57
  const contentElementKey = setContentKey(element, opts)
58
58
  if (param && element) {
59
59
  if (element[contentElementKey]?.update) {
package/node.js CHANGED
@@ -70,7 +70,8 @@ export const createNode = async (element, options) => {
70
70
  }
71
71
  }
72
72
 
73
- for (const param in element) {
73
+ const keys = Object.keys(element)
74
+ for (const param of keys) {
74
75
  const value = element[param]
75
76
 
76
77
  if (!Object.hasOwnProperty.call(element, param)) continue
@@ -83,6 +84,10 @@ export const createNode = async (element, options) => {
83
84
  )
84
85
  continue
85
86
 
87
+ if (param === 'onClick') {
88
+ debugger
89
+ }
90
+
86
91
  const isElement = await applyParam(param, element, options)
87
92
  if (!isElement) continue
88
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.31.26",
3
+ "version": "2.31.28",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -27,12 +27,12 @@
27
27
  "prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/event": "^2.31.26",
31
- "@domql/render": "^2.31.26",
32
- "@domql/state": "^2.31.26",
33
- "@domql/utils": "^2.31.26"
30
+ "@domql/event": "^2.31.28",
31
+ "@domql/render": "^2.31.28",
32
+ "@domql/state": "^2.31.28",
33
+ "@domql/utils": "^2.31.28"
34
34
  },
35
- "gitHead": "126577d65a218af7e2f66b0a3f9691942ee8b9d2",
35
+ "gitHead": "62fc6275cd961fffd78b8f4c7474e10a61251c38",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.27.1"
38
38
  }
package/update.js CHANGED
@@ -45,6 +45,11 @@ const UPDATE_DEFAULT_OPTIONS = {
45
45
  excludes: METHODS_EXL
46
46
  }
47
47
 
48
+ // const updateStack = []
49
+ // requestAnimationFrame(() => {
50
+ // updateStack.forEach()
51
+ // })
52
+
48
53
  export const update = async function (params = {}, opts) {
49
54
  const calleeElementCache = opts?.calleeElement
50
55
  const options = deepClone(
@@ -53,13 +58,30 @@ export const update = async function (params = {}, opts) {
53
58
  : UPDATE_DEFAULT_OPTIONS,
54
59
  { exclude: ['calleeElement'] }
55
60
  )
56
- options.calleeElement = calleeElementCache
57
61
  const element = this
62
+ options.calleeElement = calleeElementCache || this
58
63
  const { parent, node, key } = element
59
64
  const { excludes, preventInheritAtCurrentState } = options
60
65
 
61
66
  let ref = element.__ref
62
67
  if (!ref) ref = element.__ref = {}
68
+
69
+ // self calling is detected
70
+ if (this === options.calleeElement && !options.allowStorm) {
71
+ if (ref.__selfCallIteration === undefined) ref.__selfCallIteration = 0
72
+ else ref.__selfCallIteration++
73
+ // prevent storm
74
+ if (ref.__selfCallIteration > 100) {
75
+ ref.__selfCallIteration = 0
76
+ return this.error('Potential self calling loop in update detected', opts)
77
+ }
78
+ // make storm detection time based
79
+ const stormTimeout = setTimeout(() => {
80
+ ref.__selfCallIteration = 0
81
+ clearTimeout(stormTimeout)
82
+ }, 350)
83
+ }
84
+
63
85
  const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
64
86
  element,
65
87
  options
@@ -89,7 +111,7 @@ export const update = async function (params = {}, opts) {
89
111
  if (ref.__if && !options.preventPropsUpdate) {
90
112
  const hasParentProps =
91
113
  parent.props && (parent.props[key] || parent.props.childProps)
92
- const hasFunctionInProps = ref.__props.filter(v => isFunction(v))
114
+ const hasFunctionInProps = ref.__props.filter((v) => isFunction(v))
93
115
  const props = params.props || hasParentProps || hasFunctionInProps.length
94
116
  if (props) updateProps(props, element, parent)
95
117
  }
@@ -144,7 +166,8 @@ export const update = async function (params = {}, opts) {
144
166
  else options.preventUpdateAfterCount++
145
167
  }
146
168
 
147
- for (const param in element) {
169
+ const keys = Object.keys(element)
170
+ for (const param of keys) {
148
171
  const prop = element[param]
149
172
 
150
173
  if (!Object.hasOwnProperty.call(element, param)) continue
@@ -389,7 +412,7 @@ const inheritStateUpdates = async (element, options) => {
389
412
 
390
413
  const createStateUpdate = async (element, parent, options) => {
391
414
  const __stateChildren = element.state.__children
392
- const newState = await createState(element, parent)
415
+ const newState = await createState(element, parent, options)
393
416
  element.state = newState
394
417
  for (const child in __stateChildren) {
395
418
  // check this for inherited states