@domql/element 3.1.1 → 3.2.3
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 +4 -6
- package/__tests__/checkIfOnUpdate.test.js +12 -12
- package/__tests__/children.test.js +34 -38
- package/__tests__/inheritStateUpdates.test.js +12 -12
- package/__tests__/renderElement.test.js +11 -11
- package/__tests__/resetElement.test.js +6 -6
- package/__tests__/set.test.js +32 -36
- package/__tests__/throughExecProps.test.js +12 -12
- package/__tests__/throughInitialDefine.test.js +16 -16
- package/__tests__/throughInitialExec.test.js +16 -16
- package/__tests__/throughUpdatedDefine.test.js +14 -14
- package/__tests__/throughUpdatedExec.test.js +17 -16
- package/__tests__/update.test.js +54 -54
- package/children.js +5 -6
- package/create.js +18 -20
- package/dist/cjs/children.js +4 -2
- package/dist/cjs/create.js +16 -16
- package/dist/cjs/extend.js +88 -0
- package/dist/cjs/iterate.js +76 -20
- package/dist/cjs/mixins/content.js +73 -0
- package/dist/cjs/mixins/html.js +1 -1
- package/dist/cjs/mixins/registry.js +2 -2
- package/dist/cjs/mixins/scope.js +1 -1
- package/dist/cjs/mixins/state.js +2 -2
- package/dist/cjs/mixins/text.js +4 -4
- package/dist/cjs/node.js +15 -15
- package/dist/cjs/set.js +22 -27
- package/dist/cjs/update.js +24 -33
- package/dist/cjs/utils/applyParam.js +4 -4
- package/dist/cjs/utils/extendUtils.js +132 -0
- package/dist/cjs/utils/propEvents.js +39 -0
- package/dist/esm/children.js +5 -3
- package/dist/esm/create.js +16 -16
- package/dist/esm/extend.js +74 -0
- package/dist/esm/iterate.js +77 -22
- package/dist/esm/mixins/content.js +53 -0
- package/dist/esm/mixins/html.js +1 -1
- package/dist/esm/mixins/registry.js +1 -1
- package/dist/esm/mixins/scope.js +1 -1
- package/dist/esm/mixins/state.js +3 -3
- package/dist/esm/mixins/text.js +4 -4
- package/dist/esm/node.js +15 -15
- package/dist/esm/set.js +23 -28
- package/dist/esm/update.js +24 -33
- package/dist/esm/utils/applyParam.js +5 -5
- package/dist/esm/utils/extendUtils.js +119 -0
- package/dist/esm/utils/propEvents.js +19 -0
- package/extend.js +98 -0
- package/iterate.js +80 -25
- package/mixins/content.js +65 -0
- package/mixins/html.js +1 -1
- package/mixins/registry.js +1 -1
- package/mixins/scope.js +1 -1
- package/mixins/state.js +3 -3
- package/mixins/text.js +4 -4
- package/node.js +15 -15
- package/package.json +8 -8
- package/set.js +23 -28
- package/update.js +25 -34
- package/utils/applyParam.js +5 -5
- package/utils/extendUtils.js +149 -0
- package/utils/propEvents.js +19 -0
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/cjs/__tests__/children.test.js +0 -177
- package/dist/cjs/__tests__/define.test.js +0 -75
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/cjs/__tests__/renderElement.test.js +0 -138
- package/dist/cjs/__tests__/resetElement.test.js +0 -35
- package/dist/cjs/__tests__/set.test.js +0 -256
- package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
- package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/cjs/__tests__/tree.test.js +0 -11
- package/dist/cjs/__tests__/update.test.js +0 -222
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
- package/dist/esm/__tests__/children.test.js +0 -177
- package/dist/esm/__tests__/define.test.js +0 -53
- package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
- package/dist/esm/__tests__/renderElement.test.js +0 -116
- package/dist/esm/__tests__/resetElement.test.js +0 -35
- package/dist/esm/__tests__/set.test.js +0 -256
- package/dist/esm/__tests__/throughExecProps.test.js +0 -62
- package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
- package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
- package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
- package/dist/esm/__tests__/tree.test.js +0 -11
- package/dist/esm/__tests__/update.test.js +0 -222
package/__tests__/update.test.js
CHANGED
|
@@ -36,8 +36,8 @@ describe('update()', () => {
|
|
|
36
36
|
params = {}
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it('does not modify opts when params and opts are empty',
|
|
40
|
-
|
|
39
|
+
it('does not modify opts when params and opts are empty', () => {
|
|
40
|
+
element.update({}, opts)
|
|
41
41
|
expect(opts).toEqual({
|
|
42
42
|
calleeElement: false,
|
|
43
43
|
cleanExec: true,
|
|
@@ -53,47 +53,47 @@ describe('update()', () => {
|
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
-
it('initializes options with UPDATE_DEFAULT_OPTIONS when opts is empty',
|
|
57
|
-
|
|
56
|
+
it('initializes options with UPDATE_DEFAULT_OPTIONS when opts is empty', () => {
|
|
57
|
+
element.update({}, opts)
|
|
58
58
|
expect(opts.calleeElement).toBe(false) // Ensure opts is not mutated
|
|
59
59
|
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
it('merges opts with UPDATE_DEFAULT_OPTIONS using deepMerge',
|
|
62
|
+
it('merges opts with UPDATE_DEFAULT_OPTIONS using deepMerge', () => {
|
|
63
63
|
opts.customOption = true
|
|
64
|
-
|
|
64
|
+
element.update({}, opts)
|
|
65
65
|
expect(opts.customOption).toBe(true) // Ensure custom options are preserved
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
-
it('converts string params to { text: params }',
|
|
69
|
-
|
|
68
|
+
it('converts string params to { text: params }', () => {
|
|
69
|
+
element.update('testString', opts)
|
|
70
70
|
expect(element.text).toBe('testString')
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
it('converts number params to { text: params }',
|
|
74
|
-
|
|
73
|
+
it('converts number params to { text: params }', () => {
|
|
74
|
+
element.update(123, opts)
|
|
75
75
|
expect(element.text).toBe(123)
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
-
it('returns early if preventInheritAtCurrentState matches element',
|
|
78
|
+
it('returns early if preventInheritAtCurrentState matches element', () => {
|
|
79
79
|
opts.preventInheritAtCurrentState = { __element: element }
|
|
80
|
-
|
|
80
|
+
element.update({}, opts)
|
|
81
81
|
expect(element.__ref.__currentSnapshot).toBe(6) // No snapshot update
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
it('initializes __ref if not present',
|
|
84
|
+
it('initializes __ref if not present', () => {
|
|
85
85
|
delete element.__ref
|
|
86
|
-
|
|
86
|
+
element.update({}, opts)
|
|
87
87
|
expect(element.__ref).toBeDefined()
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
it('merges options with UPDATE_DEFAULT_OPTIONS when exclude is missing',
|
|
91
|
-
|
|
90
|
+
it('merges options with UPDATE_DEFAULT_OPTIONS when exclude is missing', () => {
|
|
91
|
+
element.update({}, opts)
|
|
92
92
|
expect(opts.exclude).toBeDefined() // Ensure exclude is added
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
it('does not throw or modify opts when params is undefined',
|
|
96
|
-
|
|
95
|
+
it('does not throw or modify opts when params is undefined', () => {
|
|
96
|
+
element.update(undefined, opts)
|
|
97
97
|
expect(opts).toEqual({
|
|
98
98
|
calleeElement: false,
|
|
99
99
|
cleanExec: true,
|
|
@@ -109,24 +109,24 @@ describe('update()', () => {
|
|
|
109
109
|
})
|
|
110
110
|
})
|
|
111
111
|
|
|
112
|
-
it('does not throw when opts is undefined',
|
|
113
|
-
|
|
112
|
+
it('does not throw when opts is undefined', () => {
|
|
113
|
+
element.update({}, undefined)
|
|
114
114
|
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
-
it('does not throw when opts is null',
|
|
118
|
-
|
|
117
|
+
it('does not throw when opts is null', () => {
|
|
118
|
+
element.update({}, null)
|
|
119
119
|
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
120
120
|
})
|
|
121
121
|
|
|
122
|
-
it('does not modify the params object',
|
|
122
|
+
it('does not modify the params object', () => {
|
|
123
123
|
params = { key: 'value' }
|
|
124
|
-
|
|
124
|
+
element.update(params, opts)
|
|
125
125
|
expect(params).toEqual({ key: 'value' })
|
|
126
126
|
})
|
|
127
127
|
|
|
128
|
-
it('does modify opts when params is an empty object',
|
|
129
|
-
|
|
128
|
+
it('does modify opts when params is an empty object', () => {
|
|
129
|
+
element.update({}, opts)
|
|
130
130
|
expect(opts).toEqual({
|
|
131
131
|
calleeElement: false,
|
|
132
132
|
cleanExec: true,
|
|
@@ -142,9 +142,9 @@ describe('update()', () => {
|
|
|
142
142
|
})
|
|
143
143
|
})
|
|
144
144
|
|
|
145
|
-
it('moves regular properties to element.props',
|
|
145
|
+
it('moves regular properties to element.props', () => {
|
|
146
146
|
params = { props: { title: 'Test', description: 'Content' } }
|
|
147
|
-
|
|
147
|
+
element.update(params, opts)
|
|
148
148
|
expect(element.props).toEqual({
|
|
149
149
|
title: 'Test',
|
|
150
150
|
description: 'Content'
|
|
@@ -152,68 +152,68 @@ describe('update()', () => {
|
|
|
152
152
|
expect(element.title).toBeUndefined()
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
it('keeps element-rooted properties',
|
|
155
|
+
it('keeps element-rooted properties', () => {
|
|
156
156
|
params = { Header: {}, Footer: {}, 0: 'index' }
|
|
157
|
-
|
|
157
|
+
element.update(params, opts)
|
|
158
158
|
expect(element.Header).toBeDefined()
|
|
159
159
|
expect(element.Footer).toBeDefined()
|
|
160
160
|
expect(element['0']).toBe('index')
|
|
161
161
|
expect(element.props).toEqual({})
|
|
162
162
|
})
|
|
163
163
|
|
|
164
|
-
it('preserves built-in properties on element',
|
|
164
|
+
it('preserves built-in properties on element', () => {
|
|
165
165
|
params = { props: { className: 'container', hidden: true } }
|
|
166
|
-
|
|
166
|
+
element.update(params, opts)
|
|
167
167
|
expect(element.props.className).toBe('container')
|
|
168
168
|
expect(element.props.hidden).toBe(true)
|
|
169
169
|
expect(element.props).toEqual({ className: 'container', hidden: true })
|
|
170
170
|
})
|
|
171
171
|
|
|
172
|
-
it('moves element-like properties from props to root',
|
|
172
|
+
it('moves element-like properties from props to root', () => {
|
|
173
173
|
params = { props: { Header: {} } }
|
|
174
|
-
|
|
174
|
+
element.update(params, opts)
|
|
175
175
|
expect(element.Header).toBeDefined()
|
|
176
176
|
expect(element.props.Header).toBeUndefined()
|
|
177
177
|
})
|
|
178
178
|
|
|
179
|
-
it('exits early when inheritStateUpdates returns false',
|
|
179
|
+
it('exits early when inheritStateUpdates returns false', () => {
|
|
180
180
|
// Simulate inheritStateUpdates failure
|
|
181
181
|
element.__ref.__stateBlocked = true
|
|
182
|
-
|
|
182
|
+
element.update({ props: { shouldChange: true } }, opts)
|
|
183
183
|
|
|
184
184
|
expect(element.props.shouldChange).toBe(true)
|
|
185
185
|
expect(element.__ref.__stateBlocked).toBe(true) // State remains blocked
|
|
186
186
|
})
|
|
187
187
|
|
|
188
|
-
it('exits early when checkIfOnUpdate fails',
|
|
188
|
+
it('exits early when checkIfOnUpdate fails', () => {
|
|
189
189
|
// Force checkIfOnUpdate failure
|
|
190
190
|
element.parent.props.ifCondition = false
|
|
191
|
-
|
|
191
|
+
element.update({ state: { newState: true } }, opts)
|
|
192
192
|
|
|
193
193
|
expect(element.state.newState).toBe(true)
|
|
194
194
|
})
|
|
195
195
|
|
|
196
|
-
it('updates props from parent key match',
|
|
196
|
+
it('updates props from parent key match', () => {
|
|
197
197
|
element.parent.props.testKey = { inherited: true }
|
|
198
|
-
|
|
198
|
+
element.update({}, opts)
|
|
199
199
|
expect(element.props.inherited).toBeUndefined()
|
|
200
200
|
})
|
|
201
201
|
|
|
202
|
-
it('updates props when functions exist in __props',
|
|
202
|
+
it('updates props when functions exist in __props', () => {
|
|
203
203
|
element.__ref.__props.push(() => 'dynamic')
|
|
204
|
-
|
|
204
|
+
element.update({}, opts)
|
|
205
205
|
expect(element.props).toEqual(expect.any(Object)) // Props were processed
|
|
206
206
|
})
|
|
207
207
|
|
|
208
|
-
it('skips props update when preventPropsUpdate=true',
|
|
208
|
+
it('skips props update when preventPropsUpdate=true', () => {
|
|
209
209
|
opts.preventPropsUpdate = true
|
|
210
210
|
opts.preventUpdateAfter = true
|
|
211
211
|
element.parent.props.testKey = { shouldExist: true }
|
|
212
|
-
|
|
212
|
+
element.update({}, opts)
|
|
213
213
|
expect(element.props.shouldExist).toBeUndefined()
|
|
214
214
|
})
|
|
215
215
|
|
|
216
|
-
it('should not skips props update when preventPropsUpdate=false',
|
|
216
|
+
it('should not skips props update when preventPropsUpdate=false', () => {
|
|
217
217
|
opts.preventPropsUpdate = false
|
|
218
218
|
opts.lazyLoad = true
|
|
219
219
|
opts.onEachUpdate = () => {
|
|
@@ -223,34 +223,34 @@ describe('update()', () => {
|
|
|
223
223
|
element.__ref.__propsStack = []
|
|
224
224
|
element.__ref.__if = true
|
|
225
225
|
element.off = { text: 'off' }
|
|
226
|
-
|
|
226
|
+
element.update({}, opts)
|
|
227
227
|
expect(element.props.shouldExist).toBeUndefined()
|
|
228
228
|
})
|
|
229
229
|
|
|
230
|
-
it('should set preventUpdateAfterCount to 1 when is not a number',
|
|
230
|
+
it('should set preventUpdateAfterCount to 1 when is not a number', () => {
|
|
231
231
|
opts.preventPropsUpdate = true
|
|
232
232
|
opts.preventUpdateAfter = 2
|
|
233
233
|
opts.preventUpdateAfterCount = undefined
|
|
234
234
|
element.parent.props.testKey = { shouldExist: true }
|
|
235
|
-
|
|
235
|
+
element.update({}, opts)
|
|
236
236
|
expect(element.props.shouldExist).toBeUndefined()
|
|
237
237
|
})
|
|
238
238
|
|
|
239
|
-
it('processes parent.childProps',
|
|
239
|
+
it('processes parent.childProps', () => {
|
|
240
240
|
element.parent.props.childProps = { global: true }
|
|
241
|
-
|
|
241
|
+
element.update({}, opts)
|
|
242
242
|
expect(element.props.global).toBe(true)
|
|
243
243
|
})
|
|
244
244
|
|
|
245
|
-
it('processes function props',
|
|
246
|
-
|
|
245
|
+
it('processes function props', () => {
|
|
246
|
+
element.update({ props: { calc: () => 42 } }, opts)
|
|
247
247
|
expect(element.props.calc()).toBe(42)
|
|
248
248
|
})
|
|
249
249
|
|
|
250
|
-
it('returns element when beforeUpdate rejects',
|
|
250
|
+
it('returns element when beforeUpdate rejects', () => {
|
|
251
251
|
// Simulate beforeUpdate rejection
|
|
252
252
|
element.on.beforeUpdate = () => false
|
|
253
|
-
const result =
|
|
253
|
+
const result = element.update({}, opts)
|
|
254
254
|
expect(result).toBe(element)
|
|
255
255
|
})
|
|
256
256
|
})
|
package/children.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
concatAddExtends,
|
|
5
5
|
deepClone,
|
|
6
|
-
|
|
6
|
+
exec,
|
|
7
7
|
getChildStateInKey,
|
|
8
8
|
isArray,
|
|
9
9
|
isDefined,
|
|
@@ -20,17 +20,16 @@ import {
|
|
|
20
20
|
* Apply data parameters on the DOM nodes
|
|
21
21
|
* this should only work if `showOnNode: true` is passed
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export function setChildren (param, element, opts) {
|
|
24
24
|
let { children, __ref: ref, state } = element
|
|
25
25
|
|
|
26
26
|
let { childrenAs } = element.props || {}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
let execParam = exec(param, element, state)
|
|
28
|
+
let execChildren = exec(children, element, state)
|
|
29
|
+
children = execParam || execChildren
|
|
30
30
|
|
|
31
31
|
if (children) {
|
|
32
32
|
if (isState(children)) children = children.parse()
|
|
33
|
-
|
|
34
33
|
if (isString(children) || isNumber(children)) {
|
|
35
34
|
if (children === 'state') children = state.parse()
|
|
36
35
|
else {
|
package/create.js
CHANGED
|
@@ -33,7 +33,7 @@ const ENV = process.env.NODE_ENV
|
|
|
33
33
|
/**
|
|
34
34
|
* Creating a DOMQL element using passed parameters
|
|
35
35
|
*/
|
|
36
|
-
export const create =
|
|
36
|
+
export const create = (
|
|
37
37
|
props,
|
|
38
38
|
parentEl,
|
|
39
39
|
passedKey,
|
|
@@ -51,21 +51,21 @@ export const create = async (
|
|
|
51
51
|
|
|
52
52
|
applyExtends(element, parent, options)
|
|
53
53
|
|
|
54
|
-
propertizeElement.call(element, element)
|
|
55
|
-
|
|
56
|
-
await triggerEventOn('start', element, options)
|
|
57
|
-
|
|
58
54
|
if (options.onlyResolveExtends) {
|
|
59
55
|
return onlyResolveExtends(element, parent, key, options)
|
|
60
56
|
}
|
|
61
57
|
|
|
58
|
+
propertizeElement.call(element, element)
|
|
59
|
+
|
|
60
|
+
triggerEventOn('start', element, options)
|
|
61
|
+
|
|
62
62
|
resetOptions(element, parent, options)
|
|
63
63
|
|
|
64
64
|
addMethods(element, parent, options)
|
|
65
65
|
|
|
66
66
|
createScope(element, parent)
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
createState(element, parent)
|
|
69
69
|
if (element.scope === 'state') element.scope = element.state
|
|
70
70
|
|
|
71
71
|
createIfConditionFlag(element, parent)
|
|
@@ -87,7 +87,7 @@ export const create = async (
|
|
|
87
87
|
// apply variants
|
|
88
88
|
// applyVariant(element, parent)
|
|
89
89
|
|
|
90
|
-
const onInit =
|
|
90
|
+
const onInit = triggerEventOn('init', element, options)
|
|
91
91
|
if (onInit === false) return element
|
|
92
92
|
|
|
93
93
|
triggerEventOn('beforeClassAssign', element, options)
|
|
@@ -95,11 +95,11 @@ export const create = async (
|
|
|
95
95
|
// generate a CLASS name
|
|
96
96
|
assignKeyAsClassname(element)
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
renderElement(element, parent, options, attachOptions)
|
|
99
99
|
|
|
100
100
|
addElementIntoParentChildren(element, parent)
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
triggerEventOn('complete', element, options)
|
|
103
103
|
|
|
104
104
|
return element
|
|
105
105
|
}
|
|
@@ -125,7 +125,7 @@ const addElementIntoParentChildren = (element, parent) => {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
const visitedElements = new WeakMap()
|
|
128
|
-
const renderElement =
|
|
128
|
+
const renderElement = (element, parent, options, attachOptions) => {
|
|
129
129
|
if (visitedElements.has(element)) {
|
|
130
130
|
if (ENV === 'test' || ENV === 'development') {
|
|
131
131
|
console.warn('Cyclic rendering detected:', element.__ref.path)
|
|
@@ -136,19 +136,19 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
136
136
|
|
|
137
137
|
const { __ref: ref, key } = element
|
|
138
138
|
|
|
139
|
-
const createNestedChild =
|
|
139
|
+
const createNestedChild = () => {
|
|
140
140
|
const isInfiniteLoopDetected = detectInfiniteLoop(ref.path)
|
|
141
141
|
if (ref.__uniqId || isInfiniteLoopDetected) return
|
|
142
|
-
|
|
142
|
+
createNode(element, options)
|
|
143
143
|
ref.__uniqId = Math.random()
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// CREATE a real NODE
|
|
147
147
|
if (ENV === 'test' || ENV === 'development') {
|
|
148
|
-
|
|
148
|
+
createNestedChild()
|
|
149
149
|
} else {
|
|
150
150
|
try {
|
|
151
|
-
|
|
151
|
+
createNestedChild()
|
|
152
152
|
} catch (e) {
|
|
153
153
|
const path = ref.path
|
|
154
154
|
if (path.includes('ComponentsGrid')) {
|
|
@@ -182,17 +182,17 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
182
182
|
applyAnimationFrame(element, options)
|
|
183
183
|
|
|
184
184
|
// run `on.render`
|
|
185
|
-
|
|
185
|
+
triggerEventOn('render', element, options)
|
|
186
186
|
// triggerEventOn('render', element, options).then(() => {})
|
|
187
187
|
|
|
188
188
|
// run `on.renderRouter`
|
|
189
|
-
|
|
189
|
+
triggerEventOn('renderRouter', element, options)
|
|
190
190
|
|
|
191
191
|
// run `on.done`
|
|
192
|
-
|
|
192
|
+
triggerEventOn('done', element, options)
|
|
193
193
|
|
|
194
194
|
// run `on.done`
|
|
195
|
-
|
|
195
|
+
triggerEventOn('create', element, options)
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
@@ -279,10 +279,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
279
279
|
// } else {
|
|
280
280
|
// return {
|
|
281
281
|
// ...element,
|
|
282
|
-
// props: {
|
|
283
282
|
// display: 'none',
|
|
284
283
|
// [key]: { display: 'block' }
|
|
285
|
-
// }
|
|
286
284
|
// }
|
|
287
285
|
// }
|
|
288
286
|
// }
|
package/dist/cjs/children.js
CHANGED
|
@@ -23,10 +23,12 @@ __export(children_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(children_exports);
|
|
25
25
|
var import_utils = require("@domql/utils");
|
|
26
|
-
|
|
26
|
+
function setChildren(param, element, opts) {
|
|
27
27
|
let { children, __ref: ref, state } = element;
|
|
28
28
|
let { childrenAs } = element.props || {};
|
|
29
|
-
|
|
29
|
+
let execParam = (0, import_utils.exec)(param, element, state);
|
|
30
|
+
let execChildren = (0, import_utils.exec)(children, element, state);
|
|
31
|
+
children = execParam || execChildren;
|
|
30
32
|
if (children) {
|
|
31
33
|
if ((0, import_utils.isState)(children)) children = children.parse();
|
|
32
34
|
if ((0, import_utils.isString)(children) || (0, import_utils.isNumber)(children)) {
|
package/dist/cjs/create.js
CHANGED
|
@@ -33,22 +33,22 @@ var import_set = require("./methods/set.js");
|
|
|
33
33
|
var import_classList = require("./mixins/classList.js");
|
|
34
34
|
var import_iterate = require("./iterate.js");
|
|
35
35
|
const ENV = "development";
|
|
36
|
-
const create =
|
|
36
|
+
const create = (props, parentEl, passedKey, options = import_utils.OPTIONS.create || {}, attachOptions) => {
|
|
37
37
|
cacheOptions(options);
|
|
38
38
|
const element = (0, import_utils.createElement)(props, parentEl, passedKey, options, import_tree.ROOT);
|
|
39
39
|
if (!element) return;
|
|
40
40
|
const { key, parent, __ref: ref } = element;
|
|
41
41
|
(0, import_utils.createRoot)(element, parent);
|
|
42
42
|
(0, import_utils.applyExtends)(element, parent, options);
|
|
43
|
-
import_utils.propertizeElement.call(element, element);
|
|
44
|
-
await (0, import_event.triggerEventOn)("start", element, options);
|
|
45
43
|
if (options.onlyResolveExtends) {
|
|
46
44
|
return onlyResolveExtends(element, parent, key, options);
|
|
47
45
|
}
|
|
46
|
+
import_utils.propertizeElement.call(element, element);
|
|
47
|
+
(0, import_event.triggerEventOn)("start", element, options);
|
|
48
48
|
resetOptions(element, parent, options);
|
|
49
49
|
(0, import_set.addMethods)(element, parent, options);
|
|
50
50
|
(0, import_utils.createScope)(element, parent);
|
|
51
|
-
|
|
51
|
+
(0, import_state.createState)(element, parent);
|
|
52
52
|
if (element.scope === "state") element.scope = element.state;
|
|
53
53
|
(0, import_utils.createIfConditionFlag)(element, parent);
|
|
54
54
|
(0, import_utils.initProps)(element, parent, options);
|
|
@@ -59,13 +59,13 @@ const create = async (props, parentEl, passedKey, options = import_utils.OPTIONS
|
|
|
59
59
|
if (element.node) {
|
|
60
60
|
if (ref.__if) return (0, import_render.assignNode)(element, parent, key, attachOptions);
|
|
61
61
|
}
|
|
62
|
-
const onInit =
|
|
62
|
+
const onInit = (0, import_event.triggerEventOn)("init", element, options);
|
|
63
63
|
if (onInit === false) return element;
|
|
64
64
|
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
65
65
|
(0, import_classList.assignKeyAsClassname)(element);
|
|
66
|
-
|
|
66
|
+
renderElement(element, parent, options, attachOptions);
|
|
67
67
|
addElementIntoParentChildren(element, parent);
|
|
68
|
-
|
|
68
|
+
(0, import_event.triggerEventOn)("complete", element, options);
|
|
69
69
|
return element;
|
|
70
70
|
};
|
|
71
71
|
const cacheOptions = (options) => {
|
|
@@ -86,7 +86,7 @@ const addElementIntoParentChildren = (element, parent) => {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
89
|
-
const renderElement =
|
|
89
|
+
const renderElement = (element, parent, options, attachOptions) => {
|
|
90
90
|
var _a, _b, _c;
|
|
91
91
|
if (visitedElements.has(element)) {
|
|
92
92
|
if (ENV === "test" || ENV === "development") {
|
|
@@ -95,17 +95,17 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
95
95
|
}
|
|
96
96
|
visitedElements.set(element, true);
|
|
97
97
|
const { __ref: ref, key } = element;
|
|
98
|
-
const createNestedChild =
|
|
98
|
+
const createNestedChild = () => {
|
|
99
99
|
const isInfiniteLoopDetected = (0, import_utils.detectInfiniteLoop)(ref.path);
|
|
100
100
|
if (ref.__uniqId || isInfiniteLoopDetected) return;
|
|
101
|
-
|
|
101
|
+
(0, import_node.createNode)(element, options);
|
|
102
102
|
ref.__uniqId = Math.random();
|
|
103
103
|
};
|
|
104
104
|
if (ENV === "test" || ENV === "development") {
|
|
105
|
-
|
|
105
|
+
createNestedChild();
|
|
106
106
|
} else {
|
|
107
107
|
try {
|
|
108
|
-
|
|
108
|
+
createNestedChild();
|
|
109
109
|
} catch (e) {
|
|
110
110
|
const path = ref.path;
|
|
111
111
|
if (path.includes("ComponentsGrid")) {
|
|
@@ -132,10 +132,10 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
132
132
|
}
|
|
133
133
|
(0, import_render.assignNode)(element, parent, key, attachOptions);
|
|
134
134
|
(0, import_event.applyAnimationFrame)(element, options);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
(0, import_event.triggerEventOn)("render", element, options);
|
|
136
|
+
(0, import_event.triggerEventOn)("renderRouter", element, options);
|
|
137
|
+
(0, import_event.triggerEventOn)("done", element, options);
|
|
138
|
+
(0, import_event.triggerEventOn)("create", element, options);
|
|
139
139
|
};
|
|
140
140
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
141
141
|
const { __ref: ref } = element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var extend_exports = {};
|
|
20
|
+
__export(extend_exports, {
|
|
21
|
+
applyExtend: () => applyExtend
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extend_exports);
|
|
24
|
+
var import_utils = require("@domql/utils");
|
|
25
|
+
var import_utils2 = require("./utils/index.js");
|
|
26
|
+
let mainExtend;
|
|
27
|
+
const applyExtend = (element, parent, options = {}) => {
|
|
28
|
+
if ((0, import_utils.isFunction)(element)) element = (0, import_utils.exec)(element, parent);
|
|
29
|
+
const { props, __ref } = element;
|
|
30
|
+
let extend = (props == null ? void 0 : props.extends) || element.extends || element.extend;
|
|
31
|
+
const variant = props == null ? void 0 : props.variant;
|
|
32
|
+
const context = element.context || parent.context;
|
|
33
|
+
extend = (0, import_utils2.fallbackStringExtend)(extend, context, options, variant);
|
|
34
|
+
const extendStack = (0, import_utils2.getExtendStack)(extend, context);
|
|
35
|
+
delete element.extend;
|
|
36
|
+
let childExtendStack = [];
|
|
37
|
+
if (parent) {
|
|
38
|
+
element.parent = parent;
|
|
39
|
+
if (!options.ignoreChildExtend && !(props && props.ignoreChildExtend)) {
|
|
40
|
+
childExtendStack = (0, import_utils2.getExtendStack)(parent.childExtend, context);
|
|
41
|
+
const ignoreChildExtendRecursive = props && props.ignoreChildExtendRecursive;
|
|
42
|
+
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
43
|
+
const canExtendRecursive = element.key !== "__text";
|
|
44
|
+
if (canExtendRecursive) {
|
|
45
|
+
const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(
|
|
46
|
+
parent.childExtendRecursive,
|
|
47
|
+
context
|
|
48
|
+
);
|
|
49
|
+
childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
|
|
50
|
+
element.childExtendRecursive = parent.childExtendRecursive;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const extendLength = extendStack.length;
|
|
56
|
+
const childExtendLength = childExtendStack.length;
|
|
57
|
+
let stack = [];
|
|
58
|
+
if (extendLength && childExtendLength) {
|
|
59
|
+
stack = (0, import_utils2.jointStacks)(extendStack, childExtendStack);
|
|
60
|
+
} else if (extendLength) {
|
|
61
|
+
stack = extendStack;
|
|
62
|
+
} else if (childExtendLength) {
|
|
63
|
+
stack = childExtendStack;
|
|
64
|
+
} else if (!context.defaultExtends) return element;
|
|
65
|
+
if (context.defaultExtends) {
|
|
66
|
+
if (!mainExtend) {
|
|
67
|
+
const defaultOptionsExtend = (0, import_utils2.getExtendStack)(
|
|
68
|
+
context.defaultExtends,
|
|
69
|
+
context
|
|
70
|
+
);
|
|
71
|
+
mainExtend = (0, import_utils2.cloneAndMergeArrayExtend)(defaultOptionsExtend);
|
|
72
|
+
delete mainExtend.extend;
|
|
73
|
+
}
|
|
74
|
+
stack = [].concat(stack, mainExtend);
|
|
75
|
+
}
|
|
76
|
+
if (__ref) __ref.__extend = stack;
|
|
77
|
+
let mergedExtend = (0, import_utils2.cloneAndMergeArrayExtend)(stack);
|
|
78
|
+
const COMPONENTS = context && context.components || options.components;
|
|
79
|
+
const component = (0, import_utils.exec)(element.component || mergedExtend.component, element);
|
|
80
|
+
if (component && COMPONENTS && COMPONENTS[component]) {
|
|
81
|
+
const componentExtend = (0, import_utils2.cloneAndMergeArrayExtend)(
|
|
82
|
+
(0, import_utils2.getExtendStack)(COMPONENTS[component])
|
|
83
|
+
);
|
|
84
|
+
mergedExtend = (0, import_utils2.deepMergeExtend)(componentExtend, mergedExtend);
|
|
85
|
+
}
|
|
86
|
+
const merged = (0, import_utils2.deepMergeExtend)(element, mergedExtend);
|
|
87
|
+
return merged;
|
|
88
|
+
};
|