@domql/element 2.31.25 → 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/set.js +0 -19
- 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/set.js +1 -20
- 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/set.js +27 -25
- package/update.js +27 -4
package/extend.js
CHANGED
package/iterate.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '@domql/utils'
|
|
13
13
|
|
|
14
14
|
import { METHODS_EXL, overwrite } from './utils/index.js'
|
|
15
|
-
import { isMethod } from './methods/index.js'
|
|
15
|
+
import { isMethod, warn } from './methods/index.js'
|
|
16
16
|
|
|
17
17
|
export const throughInitialExec = async (element, exclude = {}) => {
|
|
18
18
|
const { __ref: ref } = element
|
|
@@ -65,12 +65,14 @@ export const throughUpdatedExec = async (
|
|
|
65
65
|
return changes
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export const throughExecProps = element => {
|
|
68
|
+
export const throughExecProps = (element) => {
|
|
69
69
|
const { __ref: ref } = element
|
|
70
70
|
const { props } = element
|
|
71
71
|
for (const k in props) {
|
|
72
72
|
const isDefine =
|
|
73
73
|
k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
|
|
74
|
+
if (!ref.__execProps)
|
|
75
|
+
return warn.call(element, 'Element was not initiated to execute props')
|
|
74
76
|
const cachedExecProp = ref.__execProps[k]
|
|
75
77
|
if (isFunction(cachedExecProp)) {
|
|
76
78
|
props[k] = exec(cachedExecProp, element)
|
|
@@ -81,7 +83,7 @@ export const throughExecProps = element => {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
export const throughInitialDefine = async element => {
|
|
86
|
+
export const throughInitialDefine = async (element) => {
|
|
85
87
|
const { define, context, __ref: ref } = element
|
|
86
88
|
|
|
87
89
|
let defineObj = {}
|
|
@@ -119,7 +121,7 @@ export const throughInitialDefine = async element => {
|
|
|
119
121
|
return element
|
|
120
122
|
}
|
|
121
123
|
|
|
122
|
-
export const throughUpdatedDefine = async element => {
|
|
124
|
+
export const throughUpdatedDefine = async (element) => {
|
|
123
125
|
const { context, define, __ref: ref } = element
|
|
124
126
|
const changes = {}
|
|
125
127
|
|
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/set.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { deepContains, setContentKey } from '@domql/utils'
|
|
3
|
+
import { deepClone, deepContains, setContentKey } from '@domql/utils'
|
|
4
4
|
|
|
5
5
|
import { OPTIONS } from './cache/options.js'
|
|
6
6
|
import { create } from './create.js'
|
|
@@ -11,8 +11,6 @@ import { triggerEventOn, triggerEventOnUpdate } from '@domql/event'
|
|
|
11
11
|
export const resetElement = async (params, element, options) => {
|
|
12
12
|
if (!options.preventRemove) removeContent(element, options)
|
|
13
13
|
const { __ref: ref } = element
|
|
14
|
-
// console.warn('resetting content', ref.path)
|
|
15
|
-
if (params instanceof Promise) console.log(params, params instanceof Promise)
|
|
16
14
|
await create(params, element, ref.contentElementKey || 'content', {
|
|
17
15
|
ignoreChildExtend: true,
|
|
18
16
|
...registry.defaultOptions,
|
|
@@ -21,7 +19,7 @@ export const resetElement = async (params, element, options) => {
|
|
|
21
19
|
})
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export const reset = async options => {
|
|
22
|
+
export const reset = async (options) => {
|
|
25
23
|
const element = this
|
|
26
24
|
await create(element, element.parent, undefined, {
|
|
27
25
|
ignoreChildExtend: true,
|
|
@@ -33,7 +31,7 @@ export const reset = async options => {
|
|
|
33
31
|
|
|
34
32
|
export const set = async function (params, options = {}, el) {
|
|
35
33
|
const element = el || this
|
|
36
|
-
const { __ref: ref } = element
|
|
34
|
+
// const { __ref: ref } = element
|
|
37
35
|
|
|
38
36
|
if (
|
|
39
37
|
options.preventContentUpdate ||
|
|
@@ -45,32 +43,36 @@ export const set = async function (params, options = {}, el) {
|
|
|
45
43
|
if (options.routerContentElement !== options.lastElement.content) return
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
46
|
+
// const contentKey = setContentKey(element, options)
|
|
47
|
+
// const content = element[contentKey]
|
|
48
|
+
// const __contentRef = content && content.__ref
|
|
50
49
|
const lazyLoad = element.props && element.props.lazyLoad
|
|
51
50
|
|
|
52
51
|
const hasCollection =
|
|
53
52
|
element.$collection || element.$stateCollection || element.$propsCollection
|
|
54
53
|
if (options.preventContentUpdate === true && !hasCollection) return
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
// console.log(deepClone(params), deepClone(content))
|
|
56
|
+
// console.log(deepContains(params, content))
|
|
57
|
+
|
|
58
|
+
// if (
|
|
59
|
+
// ref.__noCollectionDifference ||
|
|
60
|
+
// (__contentRef && __contentRef.__cached && deepContains(params, content))
|
|
61
|
+
// ) {
|
|
62
|
+
// // if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
63
|
+
// // const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
64
|
+
// // 'beforeUpdate',
|
|
65
|
+
// // params,
|
|
66
|
+
// // element,
|
|
67
|
+
// // options
|
|
68
|
+
// // )
|
|
69
|
+
// // if (beforeUpdateReturns === false) return element
|
|
70
|
+
// // }
|
|
71
|
+
// // if (content?.update) await content.update()
|
|
72
|
+
// // if (!options.preventUpdateListener)
|
|
73
|
+
// // await triggerEventOn('update', element, options)
|
|
74
|
+
// return
|
|
75
|
+
// }
|
|
74
76
|
|
|
75
77
|
if (params) {
|
|
76
78
|
let { childExtend, props } = params
|
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
|