@domql/element 2.5.198 → 3.0.0
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/README.md +1 -1
- package/__tests__/checkIfOnUpdate.test.js +103 -0
- package/__tests__/children.test.js +213 -0
- package/__tests__/define.test.js +75 -0
- package/__tests__/inheritStateUpdates.test.js +79 -0
- package/__tests__/renderElement.test.js +131 -0
- package/__tests__/resetElement.test.js +44 -0
- package/__tests__/set.test.js +316 -0
- package/__tests__/throughExecProps.test.js +86 -0
- package/__tests__/throughInitialDefine.test.js +104 -0
- package/__tests__/throughInitialExec.test.js +92 -0
- package/__tests__/throughUpdatedDefine.test.js +92 -0
- package/__tests__/throughUpdatedExec.test.js +110 -0
- package/__tests__/tree.test.js +15 -0
- package/__tests__/update.test.js +253 -0
- package/children.js +105 -0
- package/create.js +125 -255
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/cjs/__tests__/children.test.js +177 -0
- package/dist/cjs/__tests__/define.test.js +75 -0
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/cjs/__tests__/renderElement.test.js +138 -0
- package/dist/cjs/__tests__/resetElement.test.js +35 -0
- package/dist/cjs/__tests__/set.test.js +256 -0
- package/dist/cjs/__tests__/throughExecProps.test.js +62 -0
- package/dist/cjs/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/cjs/__tests__/throughInitialExec.test.js +73 -0
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/cjs/__tests__/tree.test.js +11 -0
- package/dist/cjs/__tests__/update.test.js +219 -0
- package/dist/cjs/children.js +87 -0
- package/dist/cjs/create.js +74 -215
- package/dist/cjs/define.js +1 -2
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/iterate.js +37 -30
- package/dist/cjs/methods/set.js +26 -25
- package/dist/cjs/methods/v2.js +7 -17
- package/dist/cjs/mixins/attr.js +7 -10
- package/dist/cjs/mixins/classList.js +8 -16
- package/dist/cjs/mixins/data.js +2 -4
- package/dist/cjs/mixins/html.js +2 -4
- package/dist/cjs/mixins/index.js +0 -4
- package/dist/cjs/mixins/registry.js +7 -67
- package/dist/cjs/mixins/scope.js +2 -3
- package/dist/cjs/mixins/state.js +4 -7
- package/dist/cjs/mixins/style.js +2 -4
- package/dist/cjs/mixins/text.js +5 -8
- package/dist/cjs/node.js +34 -30
- package/dist/cjs/set.js +112 -47
- package/dist/cjs/update.js +123 -92
- package/dist/cjs/utils/applyParam.js +3 -4
- package/dist/cjs/utils/index.js +8 -4
- package/dist/cjs/utils/onlyResolveExtends.js +14 -30
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/esm/__tests__/children.test.js +177 -0
- package/dist/esm/__tests__/define.test.js +53 -0
- package/dist/esm/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/esm/__tests__/renderElement.test.js +116 -0
- package/dist/esm/__tests__/resetElement.test.js +35 -0
- package/dist/esm/__tests__/set.test.js +256 -0
- package/dist/esm/__tests__/throughExecProps.test.js +62 -0
- package/dist/esm/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/esm/__tests__/throughInitialExec.test.js +73 -0
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/esm/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/esm/__tests__/tree.test.js +11 -0
- package/dist/esm/__tests__/update.test.js +219 -0
- package/dist/esm/children.js +81 -0
- package/dist/esm/create.js +79 -226
- package/dist/esm/define.js +1 -2
- package/dist/esm/iterate.js +41 -33
- package/dist/esm/methods/set.js +5 -4
- package/dist/esm/methods/v2.js +7 -17
- package/dist/esm/mixins/attr.js +8 -11
- package/dist/esm/mixins/classList.js +8 -16
- package/dist/esm/mixins/data.js +3 -5
- package/dist/esm/mixins/html.js +2 -4
- package/dist/esm/mixins/index.js +0 -4
- package/dist/esm/mixins/registry.js +7 -67
- package/dist/esm/mixins/scope.js +2 -3
- package/dist/esm/mixins/state.js +5 -8
- package/dist/esm/mixins/style.js +2 -4
- package/dist/esm/mixins/text.js +6 -12
- package/dist/esm/node.js +25 -31
- package/dist/esm/set.js +112 -47
- package/dist/esm/update.js +127 -97
- package/dist/esm/utils/applyParam.js +3 -4
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/onlyResolveExtends.js +22 -31
- package/iterate.js +44 -26
- package/methods/set.js +5 -4
- package/methods/v2.js +5 -4
- package/mixins/attr.js +13 -7
- package/mixins/classList.js +7 -2
- package/mixins/data.js +1 -1
- package/mixins/index.js +1 -6
- package/mixins/registry.js +6 -53
- package/mixins/scope.js +1 -1
- package/mixins/state.js +4 -5
- package/mixins/text.js +4 -7
- package/node.js +31 -28
- package/package.json +7 -6
- package/set.js +129 -41
- package/update.js +169 -89
- package/utils/applyParam.js +7 -4
- package/utils/index.js +1 -3
- package/utils/onlyResolveExtends.js +27 -16
- package/cache/index.js +0 -3
- package/cache/options.js +0 -4
- package/dist/cjs/cache/index.js +0 -24
- package/dist/cjs/cache/options.js +0 -26
- package/dist/cjs/extend.js +0 -85
- package/dist/cjs/methods/index.js +0 -353
- package/dist/cjs/mixins/content.js +0 -74
- package/dist/cjs/props/create.js +0 -98
- package/dist/cjs/props/ignore.js +0 -24
- package/dist/cjs/props/index.js +0 -21
- package/dist/cjs/props/inherit.js +0 -53
- package/dist/cjs/props/update.js +0 -37
- package/dist/cjs/utils/component.js +0 -77
- package/dist/cjs/utils/extendUtils.js +0 -142
- package/dist/cjs/utils/object.js +0 -179
- package/dist/cjs/utils/propEvents.js +0 -41
- package/dist/esm/cache/index.js +0 -4
- package/dist/esm/cache/options.js +0 -6
- package/dist/esm/extend.js +0 -71
- package/dist/esm/methods/index.js +0 -333
- package/dist/esm/mixins/content.js +0 -54
- package/dist/esm/props/create.js +0 -78
- package/dist/esm/props/ignore.js +0 -4
- package/dist/esm/props/index.js +0 -4
- package/dist/esm/props/inherit.js +0 -33
- package/dist/esm/props/update.js +0 -17
- package/dist/esm/utils/component.js +0 -65
- package/dist/esm/utils/extendUtils.js +0 -122
- package/dist/esm/utils/object.js +0 -159
- package/dist/esm/utils/propEvents.js +0 -21
- package/extend.js +0 -90
- package/methods/index.js +0 -317
- package/mixins/content.js +0 -55
- package/props/create.js +0 -87
- package/props/ignore.js +0 -3
- package/props/index.js +0 -6
- package/props/inherit.js +0 -35
- package/props/update.js +0 -17
- package/utils/component.js +0 -68
- package/utils/extendUtils.js +0 -134
- package/utils/object.js +0 -172
- package/utils/propEvents.js +0 -19
package/iterate.js
CHANGED
|
@@ -6,28 +6,25 @@ import {
|
|
|
6
6
|
isFunction,
|
|
7
7
|
isNumber,
|
|
8
8
|
isString,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
matchesComponentNaming,
|
|
10
|
+
isContextComponent,
|
|
11
|
+
isMethod,
|
|
12
|
+
overwrite
|
|
12
13
|
} from '@domql/utils'
|
|
13
14
|
|
|
14
|
-
import { METHODS_EXL, overwrite } from './utils/index.js'
|
|
15
|
-
import { isMethod } from './methods/index.js'
|
|
16
|
-
|
|
17
15
|
export const throughInitialExec = (element, exclude = {}) => {
|
|
18
16
|
const { __ref: ref } = element
|
|
19
17
|
for (const param in element) {
|
|
20
18
|
if (exclude[param]) continue
|
|
21
19
|
const prop = element[param]
|
|
22
|
-
if (isFunction(prop) && !isMethod(param, element)
|
|
20
|
+
if (isFunction(prop) && !isMethod(param, element)) {
|
|
23
21
|
ref.__exec[param] = prop
|
|
24
22
|
element[param] = prop(element, element.state, element.context)
|
|
25
|
-
// if (isComponent)
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export const throughUpdatedExec = (element, options = {
|
|
27
|
+
export const throughUpdatedExec = (element, options = {}) => {
|
|
31
28
|
const { __ref: ref } = element
|
|
32
29
|
const changes = {}
|
|
33
30
|
|
|
@@ -41,15 +38,17 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
|
|
|
41
38
|
const execReturnsString = isString(newExec) || isNumber(newExec)
|
|
42
39
|
// if (prop && prop.node && execReturnsString) {
|
|
43
40
|
if (prop && prop.node && execReturnsString) {
|
|
44
|
-
overwrite(prop, { text: newExec }
|
|
41
|
+
overwrite(prop, { text: newExec })
|
|
45
42
|
} else if (newExec !== prop) {
|
|
46
|
-
if (
|
|
47
|
-
const { extend, ...newElem } =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
if (matchesComponentNaming(param)) {
|
|
44
|
+
const { extends: extend, ...newElem } = isContextComponent(
|
|
45
|
+
newExec,
|
|
46
|
+
element,
|
|
47
|
+
param
|
|
48
|
+
)
|
|
49
|
+
overwrite(prop, newElem)
|
|
51
50
|
} else {
|
|
52
|
-
|
|
51
|
+
changes[param] = prop
|
|
53
52
|
element[param] = newExec
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -58,11 +57,12 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
|
|
|
58
57
|
return changes
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export const throughExecProps =
|
|
60
|
+
export const throughExecProps = element => {
|
|
62
61
|
const { __ref: ref } = element
|
|
63
62
|
const { props } = element
|
|
64
63
|
for (const k in props) {
|
|
65
|
-
const isDefine =
|
|
64
|
+
const isDefine =
|
|
65
|
+
k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
|
|
66
66
|
const cachedExecProp = ref.__execProps[k]
|
|
67
67
|
if (isFunction(cachedExecProp)) {
|
|
68
68
|
props[k] = exec(cachedExecProp, element)
|
|
@@ -73,7 +73,9 @@ export const throughExecProps = (element) => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export const
|
|
76
|
+
export const isPropertyInDefines = (key, element) => {}
|
|
77
|
+
|
|
78
|
+
export const throughInitialDefine = element => {
|
|
77
79
|
const { define, context, __ref: ref } = element
|
|
78
80
|
|
|
79
81
|
let defineObj = {}
|
|
@@ -84,23 +86,30 @@ export const throughInitialDefine = (element) => {
|
|
|
84
86
|
for (const param in defineObj) {
|
|
85
87
|
let elementProp = element[param]
|
|
86
88
|
|
|
87
|
-
if (isFunction(elementProp) && !isMethod(param, element)
|
|
89
|
+
if (isFunction(elementProp) && !isMethod(param, element)) {
|
|
88
90
|
ref.__exec[param] = elementProp
|
|
89
|
-
const execParam = elementProp = exec(elementProp, element)
|
|
91
|
+
const execParam = (elementProp = exec(elementProp, element))
|
|
90
92
|
|
|
91
93
|
if (execParam) {
|
|
92
|
-
elementProp = element[param] = execParam.parse
|
|
94
|
+
elementProp = element[param] = execParam.parse
|
|
95
|
+
? execParam.parse()
|
|
96
|
+
: execParam
|
|
93
97
|
ref.__defineCache[param] = elementProp
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
const execParam = defineObj[param](
|
|
101
|
+
const execParam = defineObj[param](
|
|
102
|
+
elementProp,
|
|
103
|
+
element,
|
|
104
|
+
element.state,
|
|
105
|
+
element.context
|
|
106
|
+
)
|
|
98
107
|
if (execParam) element[param] = execParam
|
|
99
108
|
}
|
|
100
109
|
return element
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
export const throughUpdatedDefine =
|
|
112
|
+
export const throughUpdatedDefine = element => {
|
|
104
113
|
const { context, define, __ref: ref } = element
|
|
105
114
|
const changes = {}
|
|
106
115
|
|
|
@@ -110,9 +119,18 @@ export const throughUpdatedDefine = (element) => {
|
|
|
110
119
|
|
|
111
120
|
for (const param in obj) {
|
|
112
121
|
const execParam = ref.__exec[param]
|
|
113
|
-
if (execParam)
|
|
122
|
+
if (execParam) {
|
|
123
|
+
ref.__defineCache[param] = execParam(
|
|
124
|
+
element,
|
|
125
|
+
element.state,
|
|
126
|
+
element.context
|
|
127
|
+
)
|
|
128
|
+
}
|
|
114
129
|
const cached = exec(ref.__defineCache[param], element)
|
|
115
|
-
const newExecParam =
|
|
130
|
+
const newExecParam =
|
|
131
|
+
typeof obj[param] === 'function'
|
|
132
|
+
? obj[param](cached, element, element.state, element.context)
|
|
133
|
+
: undefined
|
|
116
134
|
if (newExecParam) element[param] = newExecParam
|
|
117
135
|
}
|
|
118
136
|
return changes
|
package/methods/set.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { merge, overwrite } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
import { set, reset } from '../set.js'
|
|
5
|
+
import { set, reset, updateContent, removeContent } from '../set.js'
|
|
6
6
|
import { update } from '../update.js'
|
|
7
7
|
|
|
8
|
-
import { removeContent, updateContent } from '../mixins/content.js'
|
|
9
8
|
import {
|
|
10
9
|
call,
|
|
11
10
|
error,
|
|
@@ -27,7 +26,7 @@ import {
|
|
|
27
26
|
variables,
|
|
28
27
|
verbose,
|
|
29
28
|
warn
|
|
30
|
-
} from '
|
|
29
|
+
} from '@domql/utils/methods'
|
|
31
30
|
|
|
32
31
|
export const addMethods = (element, parent, options = {}) => {
|
|
33
32
|
const proto = {
|
|
@@ -57,6 +56,8 @@ export const addMethods = (element, parent, options = {}) => {
|
|
|
57
56
|
error,
|
|
58
57
|
call
|
|
59
58
|
}
|
|
60
|
-
if (element.context.methods)
|
|
59
|
+
if (element.context.methods) {
|
|
60
|
+
;(options.strict ? merge : overwrite)(proto, element.context.methods)
|
|
61
|
+
}
|
|
61
62
|
Object.setPrototypeOf(element, proto)
|
|
62
63
|
}
|
package/methods/v2.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isDefined, isFunction, isObjectLike } from '@domql/utils'
|
|
4
|
-
import { parseFilters, REGISTRY } from '../mixins/index.js'
|
|
5
4
|
|
|
6
5
|
export const defineSetter = (element, key, get, set) =>
|
|
7
6
|
Object.defineProperty(element, key, { get, set })
|
|
@@ -10,7 +9,7 @@ export const keys = function () {
|
|
|
10
9
|
const element = this
|
|
11
10
|
const keys = []
|
|
12
11
|
for (const param in element) {
|
|
13
|
-
if (REGISTRY[param] && !parseFilters.elementKeys.includes(param)) { continue }
|
|
12
|
+
// if (REGISTRY[param] && !parseFilters.elementKeys.includes(param)) { continue }
|
|
14
13
|
keys.push(param)
|
|
15
14
|
}
|
|
16
15
|
return keys
|
|
@@ -39,7 +38,9 @@ export const parseDeep = function (excl = []) {
|
|
|
39
38
|
const obj = parse.call(element, excl)
|
|
40
39
|
for (const v in obj) {
|
|
41
40
|
if (excl.includes(v)) return
|
|
42
|
-
if (isObjectLike(obj[v])) {
|
|
41
|
+
if (isObjectLike(obj[v])) {
|
|
42
|
+
obj[v] = parseDeep.call(obj[v], excl)
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
return obj
|
|
45
46
|
}
|
|
@@ -51,7 +52,7 @@ export const log = function (...args) {
|
|
|
51
52
|
if (args.length) {
|
|
52
53
|
args.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
53
54
|
} else {
|
|
54
|
-
console.log(__ref
|
|
55
|
+
console.log(__ref?.path)
|
|
55
56
|
const keys = element.keys()
|
|
56
57
|
keys.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
57
58
|
}
|
package/mixins/attr.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { exec, isNot, isNull, isUndefined } from '@domql/utils'
|
|
3
|
+
import { deepMerge, exec, isNot, isNull, isUndefined } from '@domql/utils'
|
|
4
4
|
import { report } from '@domql/report'
|
|
5
|
-
import { deepMerge } from '../utils/index.js'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Recursively add attributes to a DOM node
|
|
@@ -12,12 +11,19 @@ export function attr (params, element, node) {
|
|
|
12
11
|
const { __attr } = ref
|
|
13
12
|
if (isNot('object')) report('HTMLInvalidAttr', params)
|
|
14
13
|
if (params) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const attrs = exec(params, element)
|
|
15
|
+
if (props.attr) deepMerge(attrs, props.attr)
|
|
16
|
+
for (const attr in attrs) {
|
|
17
|
+
const val = exec(attrs[attr], element)
|
|
18
18
|
// if (__attr[attr] === val) return
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
if (
|
|
20
|
+
val !== false &&
|
|
21
|
+
!isUndefined(val) &&
|
|
22
|
+
!isNull(val) &&
|
|
23
|
+
node.setAttribute
|
|
24
|
+
) {
|
|
25
|
+
node.setAttribute(attr, val)
|
|
26
|
+
} else if (node.removeAttribute) node.removeAttribute(attr)
|
|
21
27
|
__attr[attr] = val
|
|
22
28
|
}
|
|
23
29
|
}
|
package/mixins/classList.js
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { exec, isObject, isString } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
export const assignKeyAsClassname =
|
|
5
|
+
export const assignKeyAsClassname = element => {
|
|
6
6
|
const { key } = element
|
|
7
7
|
if (element.class === true) element.class = key
|
|
8
|
-
else if (
|
|
8
|
+
else if (
|
|
9
|
+
!element.class &&
|
|
10
|
+
typeof key === 'string' &&
|
|
11
|
+
key.charAt(0) === '_' &&
|
|
12
|
+
key.charAt(1) !== '_'
|
|
13
|
+
) {
|
|
9
14
|
element.class = key.slice(1)
|
|
10
15
|
}
|
|
11
16
|
}
|
package/mixins/data.js
CHANGED
package/mixins/index.js
CHANGED
|
@@ -2,20 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { attr } from './attr.js'
|
|
4
4
|
import { applyClasslist } from './classList.js'
|
|
5
|
-
import { setContent } from './content.js'
|
|
6
5
|
import { data } from './data.js'
|
|
7
6
|
import { html } from './html.js'
|
|
8
7
|
import { style } from './style.js'
|
|
9
8
|
import { text } from './text.js'
|
|
10
9
|
import { state } from './state.js'
|
|
11
10
|
import { scope } from './scope.js'
|
|
12
|
-
import { REGISTRY } from './registry.js'
|
|
13
|
-
|
|
14
|
-
export { REGISTRY as registry }
|
|
15
|
-
export { applyClasslist as classList }
|
|
16
|
-
export { setContent as content }
|
|
17
11
|
|
|
18
12
|
export {
|
|
13
|
+
applyClasslist as classList,
|
|
19
14
|
attr,
|
|
20
15
|
data,
|
|
21
16
|
style,
|
package/mixins/registry.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import attr from './attr.js'
|
|
4
4
|
import { classList } from './classList.js'
|
|
5
|
-
import content from './content.js'
|
|
6
5
|
import data from './data.js'
|
|
7
6
|
import html from './html.js'
|
|
8
7
|
import scope from './scope.js'
|
|
@@ -15,79 +14,33 @@ export const REGISTRY = {
|
|
|
15
14
|
style,
|
|
16
15
|
text,
|
|
17
16
|
html,
|
|
18
|
-
content,
|
|
19
17
|
data,
|
|
20
18
|
class: classList,
|
|
21
19
|
state,
|
|
22
20
|
scope,
|
|
23
|
-
|
|
24
21
|
deps: (param, el) => param || el.parent.deps,
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
extends: {},
|
|
24
|
+
children: {},
|
|
25
|
+
content: {},
|
|
26
|
+
childExtends: {},
|
|
27
|
+
childExtendsRecursive: {},
|
|
29
28
|
props: {},
|
|
30
|
-
path: {},
|
|
31
29
|
if: {},
|
|
32
30
|
define: {},
|
|
33
|
-
transform: {},
|
|
34
31
|
__name: {},
|
|
35
32
|
__ref: {},
|
|
36
33
|
__hash: {},
|
|
37
34
|
__text: {},
|
|
38
|
-
nextElement: {},
|
|
39
|
-
previousElement: {},
|
|
40
35
|
key: {},
|
|
41
36
|
tag: {},
|
|
42
37
|
query: {},
|
|
43
38
|
parent: {},
|
|
44
39
|
node: {},
|
|
45
|
-
set: {},
|
|
46
|
-
reset: {},
|
|
47
|
-
update: {},
|
|
48
|
-
error: {},
|
|
49
|
-
warn: {},
|
|
50
|
-
call: {},
|
|
51
|
-
setProps: {},
|
|
52
|
-
remove: {},
|
|
53
|
-
updateContent: {},
|
|
54
|
-
removeContent: {},
|
|
55
40
|
variables: {},
|
|
56
|
-
lookup: {},
|
|
57
|
-
lookdown: {},
|
|
58
|
-
getRef: {},
|
|
59
|
-
getPath: {},
|
|
60
|
-
lookdownAll: {},
|
|
61
|
-
setNodeStyles: {},
|
|
62
|
-
spotByPath: {},
|
|
63
|
-
keys: {},
|
|
64
|
-
log: {},
|
|
65
|
-
parse: {},
|
|
66
|
-
parseDeep: {},
|
|
67
41
|
on: {},
|
|
68
42
|
component: {},
|
|
69
|
-
context: {}
|
|
70
|
-
$collection: {},
|
|
71
|
-
$stateCollection: {},
|
|
72
|
-
$propsCollection: {},
|
|
73
|
-
$setCollection: {},
|
|
74
|
-
$setStateCollection: {},
|
|
75
|
-
$setPropsCollection: {}
|
|
43
|
+
context: {}
|
|
76
44
|
}
|
|
77
45
|
|
|
78
46
|
export default REGISTRY
|
|
79
|
-
|
|
80
|
-
// List of keys for .parse() and .parseDeep() to include in the result.
|
|
81
|
-
// Keys not in the array are excluded.
|
|
82
|
-
export const parseFilters = {
|
|
83
|
-
elementKeys: [
|
|
84
|
-
'tag', 'text', 'style', 'attr', 'class', 'state', 'props',
|
|
85
|
-
'data', 'content', 'html', 'on', 'key', 'extend', 'childExtend',
|
|
86
|
-
'childExtendRecursive', 'scope', 'query',
|
|
87
|
-
'$collection', '$stateCollection', '$propsCollection'
|
|
88
|
-
],
|
|
89
|
-
propsKeys: ['__element', 'update'],
|
|
90
|
-
stateKeys: []
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export const collectionFilters = ['$collection', '$stateCollection', '$propsCollection']
|
package/mixins/scope.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isFunction, isObject } from '@domql/utils'
|
|
|
6
6
|
* Apply data parameters on the DOM nodes
|
|
7
7
|
* this should only work if `showOnNode: true` is passed
|
|
8
8
|
*/
|
|
9
|
-
export function scope (params, element, node) {
|
|
9
|
+
export async function scope (params, element, node) {
|
|
10
10
|
if (!isObject(params)) return
|
|
11
11
|
|
|
12
12
|
// Apply data params on node
|
package/mixins/state.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { exec, isObject } from '@domql/utils'
|
|
3
|
+
import { execPromise, isObject, STATE_METHODS } from '@domql/utils'
|
|
5
4
|
|
|
6
|
-
export function state (params, element, node) {
|
|
7
|
-
const state =
|
|
5
|
+
export async function state (params, element, node) {
|
|
6
|
+
const state = await execPromise(params, element)
|
|
8
7
|
|
|
9
8
|
if (isObject(state)) {
|
|
10
9
|
for (const param in state) {
|
|
11
|
-
if (
|
|
10
|
+
if (STATE_METHODS.includes(param)) continue
|
|
12
11
|
if (!Object.hasOwnProperty.call(state, param)) continue
|
|
13
12
|
// element.state[param] = exec(state[param], element)
|
|
14
13
|
}
|
package/mixins/text.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { create } from '../create.js'
|
|
4
|
-
import {
|
|
5
|
-
exec,
|
|
6
|
-
isString
|
|
7
|
-
} from '@domql/utils'
|
|
4
|
+
import { exec, isString } from '@domql/utils'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Creates a text node and appends into
|
|
11
8
|
* an original one as a child
|
|
12
9
|
*/
|
|
13
|
-
export function text (param, element, node) {
|
|
14
|
-
let prop = exec(param, element)
|
|
10
|
+
export async function text (param, element, node) {
|
|
11
|
+
let prop = exec(param || element.props.text, element)
|
|
15
12
|
if (isString(prop) && prop.includes('{{')) {
|
|
16
13
|
prop = element.call('replaceLiteralsWithObjectFields', prop)
|
|
17
14
|
}
|
|
@@ -22,7 +19,7 @@ export function text (param, element, node) {
|
|
|
22
19
|
if (element.__text.text === prop) return
|
|
23
20
|
element.__text.text = prop
|
|
24
21
|
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
25
|
-
} else create({ tag: 'string', text: prop }, element, '__text')
|
|
22
|
+
} else await create({ tag: 'string', text: prop }, element, '__text')
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
|
package/node.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { isFunction, isMethod, isObject, isUndefined } from '@domql/utils'
|
|
4
4
|
import { applyEventsOnNode, triggerEventOn } from '@domql/event'
|
|
5
5
|
import { cacheNode } from '@domql/render'
|
|
6
|
-
import { isMethod } from './methods/index.js'
|
|
7
6
|
import { create } from './create.js'
|
|
8
7
|
|
|
9
8
|
import {
|
|
@@ -13,79 +12,75 @@ import {
|
|
|
13
12
|
} from './iterate.js'
|
|
14
13
|
import { REGISTRY } from './mixins/index.js'
|
|
15
14
|
import { applyParam } from './utils/applyParam.js'
|
|
16
|
-
import
|
|
15
|
+
import setChildren from './children.js'
|
|
16
|
+
import { setContent } from './set.js'
|
|
17
17
|
// import { defineSetter } from './methods'
|
|
18
18
|
|
|
19
19
|
const ENV = process.env.NODE_ENV
|
|
20
20
|
|
|
21
|
-
export const createNode = async (element,
|
|
21
|
+
export const createNode = async (element, opts) => {
|
|
22
22
|
// create and assign a node
|
|
23
23
|
let { node, tag, __ref: ref } = element
|
|
24
24
|
|
|
25
|
+
if (!ref.__if) return element
|
|
26
|
+
|
|
25
27
|
let isNewNode
|
|
26
28
|
|
|
27
29
|
if (!node) {
|
|
28
30
|
isNewNode = true
|
|
29
31
|
|
|
30
|
-
if (!ref.__if) return element
|
|
31
|
-
|
|
32
32
|
if (tag === 'shadow') {
|
|
33
33
|
node = element.node = element.parent.node.attachShadow({ mode: 'open' })
|
|
34
34
|
} else node = element.node = cacheNode(element)
|
|
35
35
|
|
|
36
36
|
// trigger `on.attachNode`
|
|
37
|
-
triggerEventOn('attachNode', element,
|
|
37
|
+
await triggerEventOn('attachNode', element, opts)
|
|
38
38
|
}
|
|
39
39
|
// node.dataset // .key = element.key
|
|
40
40
|
|
|
41
|
-
if (ENV === 'test' || ENV === 'development' ||
|
|
41
|
+
if (ENV === 'test' || ENV === 'development' || opts.alowRefReference) {
|
|
42
42
|
node.ref = element
|
|
43
43
|
if (isFunction(node.setAttribute)) node.setAttribute('key', element.key)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// iterate through exec props
|
|
47
|
-
throughExecProps(element)
|
|
47
|
+
await throughExecProps(element)
|
|
48
48
|
|
|
49
49
|
// iterate through define
|
|
50
|
-
throughInitialDefine(element)
|
|
50
|
+
await throughInitialDefine(element)
|
|
51
51
|
|
|
52
52
|
// iterate through exec
|
|
53
|
-
throughInitialExec(element)
|
|
54
|
-
|
|
55
|
-
if (element.tag !== 'string' && element.tag !== 'fragment') {
|
|
56
|
-
propagateEventsFromProps(element)
|
|
53
|
+
await throughInitialExec(element)
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
applyEventsOnNode(element, options)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
55
|
+
await applyEventsOnNode(element, { isNewNode, ...opts })
|
|
62
56
|
|
|
63
57
|
for (const param in element) {
|
|
64
58
|
const value = element[param]
|
|
65
59
|
|
|
66
|
-
if (!Object.hasOwnProperty.call(element, param)) continue
|
|
67
|
-
|
|
68
60
|
if (
|
|
61
|
+
!Object.hasOwnProperty.call(element, param) ||
|
|
69
62
|
isUndefined(value) ||
|
|
70
63
|
isMethod(param, element) ||
|
|
71
|
-
isVariant(param) ||
|
|
72
64
|
isObject(REGISTRY[param])
|
|
73
|
-
)
|
|
65
|
+
) {
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
74
68
|
|
|
75
|
-
const isElement = applyParam(param, element,
|
|
69
|
+
const isElement = await applyParam(param, element, opts)
|
|
76
70
|
if (isElement) {
|
|
77
71
|
const { hasDefine, hasContextDefine } = isElement
|
|
78
72
|
if (element[param] && !hasDefine && !hasContextDefine) {
|
|
79
73
|
const createAsync = async () => {
|
|
80
|
-
await create(
|
|
74
|
+
await create(value, element, param, opts)
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
|
|
77
|
+
// TODO: test this with promise
|
|
78
|
+
// handle lazy load
|
|
79
|
+
if ((element.props && element.props.lazyLoad) || opts.lazyLoad) {
|
|
84
80
|
window.requestAnimationFrame(async () => {
|
|
85
81
|
await createAsync()
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
triggerEventOn('lazyLoad', element, options)
|
|
82
|
+
if (!opts.preventUpdateListener) {
|
|
83
|
+
await triggerEventOn('lazyLoad', element, opts)
|
|
89
84
|
}
|
|
90
85
|
})
|
|
91
86
|
} else await createAsync()
|
|
@@ -93,6 +88,14 @@ export const createNode = async (element, options) => {
|
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
|
|
91
|
+
const content = element.children
|
|
92
|
+
? await setChildren(element.children, element, opts)
|
|
93
|
+
: element.content || element.content
|
|
94
|
+
|
|
95
|
+
if (content) {
|
|
96
|
+
await setContent(content, element, opts)
|
|
97
|
+
}
|
|
98
|
+
|
|
96
99
|
// node.dataset.key = key
|
|
97
100
|
return element
|
|
98
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -27,12 +27,13 @@
|
|
|
27
27
|
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^
|
|
31
|
-
"@domql/render": "^
|
|
32
|
-
"@domql/
|
|
33
|
-
"@domql/
|
|
30
|
+
"@domql/event": "^3.0.0",
|
|
31
|
+
"@domql/render": "^3.0.0",
|
|
32
|
+
"@domql/report": "^3.0.0",
|
|
33
|
+
"@domql/state": "^3.0.0",
|
|
34
|
+
"@domql/utils": "^3.0.0"
|
|
34
35
|
},
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "bcbdc271a602b958de6a60ab387ea7715a935dc1",
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@babel/core": "^7.12.0"
|
|
38
39
|
}
|