@domql/element 2.31.26 → 2.31.27
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 +107 -8
- package/dist/cjs/create.js +135 -69
- package/dist/cjs/iterate.js +2 -0
- package/dist/cjs/methods/index.js +22 -8
- package/dist/cjs/mixins/content.js +1 -1
- package/dist/cjs/node.js +5 -1
- package/dist/cjs/update.js +16 -3
- package/dist/esm/create.js +136 -70
- package/dist/esm/extend.js +1 -1
- package/dist/esm/iterate.js +3 -1
- package/dist/esm/methods/index.js +22 -8
- package/dist/esm/mixins/content.js +1 -1
- package/dist/esm/node.js +5 -1
- package/dist/esm/update.js +16 -3
- package/extend.js +1 -1
- package/iterate.js +6 -4
- package/methods/index.js +21 -7
- package/mixins/content.js +2 -2
- package/node.js +6 -1
- package/package.json +6 -6
- package/update.js +27 -4
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,
|
|
159
|
+
export function setProps(param, opts = {}) {
|
|
148
160
|
const element = this
|
|
149
161
|
if (!param || !element.props) return
|
|
150
|
-
element.update({ props: param },
|
|
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}'
|
|
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(
|
|
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
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "2.31.27",
|
|
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.
|
|
31
|
-
"@domql/render": "^2.31.
|
|
32
|
-
"@domql/state": "^2.31.
|
|
33
|
-
"@domql/utils": "^2.31.
|
|
30
|
+
"@domql/event": "^2.31.27",
|
|
31
|
+
"@domql/render": "^2.31.27",
|
|
32
|
+
"@domql/state": "^2.31.27",
|
|
33
|
+
"@domql/utils": "^2.31.27"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0edcd5aae5c16b6a53a7e9b6512bb2562e8eb8a1",
|
|
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
|
-
|
|
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
|