@domql/element 3.1.2 → 3.2.7
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/children.js +45 -18
- package/create.js +58 -46
- package/define.js +1 -1
- package/dist/cjs/children.js +43 -13
- package/dist/cjs/create.js +57 -27
- package/dist/cjs/define.js +1 -1
- package/dist/cjs/event/animationFrame.js +96 -0
- package/dist/cjs/event/can.js +28 -0
- package/dist/cjs/event/index.js +20 -0
- package/dist/cjs/event/on.js +84 -0
- package/dist/cjs/event/store.js +27 -0
- package/dist/cjs/extend.js +88 -0
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/iterate.js +89 -33
- package/dist/cjs/methods/set.js +5 -0
- package/dist/cjs/methods/v2.js +1 -1
- package/dist/cjs/mixins/attr.js +3 -2
- package/dist/cjs/mixins/classList.js +11 -1
- package/dist/cjs/mixins/content.js +72 -0
- package/dist/cjs/mixins/html.js +1 -2
- package/dist/cjs/mixins/registry.js +2 -2
- package/dist/cjs/mixins/scope.js +1 -1
- package/dist/cjs/mixins/state.js +4 -4
- package/dist/cjs/mixins/style.js +11 -2
- package/dist/cjs/mixins/text.js +9 -5
- package/dist/cjs/node.js +22 -19
- package/dist/cjs/render/append.js +72 -0
- package/dist/cjs/render/cache.js +80 -0
- package/dist/cjs/render/create.js +25 -0
- package/dist/cjs/render/index.js +20 -0
- package/dist/cjs/set.js +33 -40
- package/dist/cjs/update.js +100 -69
- package/dist/cjs/utils/applyParam.js +7 -7
- package/dist/cjs/utils/extendUtils.js +132 -0
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/propEvents.js +56 -0
- package/dist/esm/children.js +44 -14
- package/dist/esm/create.js +58 -27
- package/dist/esm/define.js +1 -1
- package/dist/esm/event/animationFrame.js +76 -0
- package/dist/esm/event/can.js +8 -0
- package/dist/esm/event/index.js +3 -0
- package/dist/esm/event/on.js +64 -0
- package/dist/esm/event/store.js +7 -0
- package/dist/esm/extend.js +74 -0
- package/dist/esm/index.js +8 -6
- package/dist/esm/iterate.js +90 -35
- package/dist/esm/methods/set.js +10 -0
- package/dist/esm/methods/v2.js +1 -1
- package/dist/esm/mixins/attr.js +4 -3
- package/dist/esm/mixins/classList.js +11 -1
- package/dist/esm/mixins/content.js +52 -0
- package/dist/esm/mixins/html.js +1 -2
- package/dist/esm/mixins/registry.js +1 -1
- package/dist/esm/mixins/scope.js +1 -1
- package/dist/esm/mixins/state.js +5 -5
- package/dist/esm/mixins/style.js +12 -3
- package/dist/esm/mixins/text.js +10 -6
- package/dist/esm/node.js +22 -19
- package/dist/esm/render/append.js +52 -0
- package/dist/esm/render/cache.js +60 -0
- package/dist/esm/render/create.js +5 -0
- package/dist/esm/render/index.js +3 -0
- package/dist/esm/set.js +34 -41
- package/dist/esm/update.js +100 -71
- package/dist/esm/utils/applyParam.js +8 -8
- package/dist/esm/utils/extendUtils.js +119 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/propEvents.js +36 -0
- package/dist/iife/index.js +4718 -0
- package/extend.js +95 -0
- package/index.js +9 -6
- package/iterate.js +100 -38
- package/node.js +25 -23
- package/package.json +44 -20
- package/set.js +28 -32
- package/update.js +111 -82
- package/__tests__/checkIfOnUpdate.test.js +0 -103
- package/__tests__/children.test.js +0 -213
- package/__tests__/define.test.js +0 -75
- package/__tests__/inheritStateUpdates.test.js +0 -79
- package/__tests__/renderElement.test.js +0 -131
- package/__tests__/resetElement.test.js +0 -44
- package/__tests__/set.test.js +0 -316
- package/__tests__/throughExecProps.test.js +0 -86
- package/__tests__/throughInitialDefine.test.js +0 -104
- package/__tests__/throughInitialExec.test.js +0 -92
- package/__tests__/throughUpdatedDefine.test.js +0 -92
- package/__tests__/throughUpdatedExec.test.js +0 -110
- package/__tests__/tree.test.js +0 -15
- package/__tests__/update.test.js +0 -256
- 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/cjs/package.json +0 -4
- 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/methods/set.js +0 -63
- package/methods/v2.js +0 -83
- package/mixins/attr.js +0 -32
- package/mixins/classList.js +0 -54
- package/mixins/data.js +0 -26
- package/mixins/html.js +0 -21
- package/mixins/index.js +0 -23
- package/mixins/registry.js +0 -46
- package/mixins/scope.js +0 -23
- package/mixins/state.js +0 -19
- package/mixins/style.js +0 -16
- package/mixins/text.js +0 -26
- package/utils/applyParam.js +0 -34
- package/utils/index.js +0 -3
package/__tests__/update.test.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { update } from '../update'
|
|
2
|
-
|
|
3
|
-
describe('update()', () => {
|
|
4
|
-
let element, params, opts
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
element = {
|
|
8
|
-
__ref: {
|
|
9
|
-
__if: true,
|
|
10
|
-
__execProps: {},
|
|
11
|
-
__exec: {},
|
|
12
|
-
__defineCache: {},
|
|
13
|
-
__propsStack: [],
|
|
14
|
-
__props: [],
|
|
15
|
-
__state: 'state'
|
|
16
|
-
},
|
|
17
|
-
state: 'string',
|
|
18
|
-
props: {},
|
|
19
|
-
parent: {
|
|
20
|
-
props: {}
|
|
21
|
-
},
|
|
22
|
-
context: {},
|
|
23
|
-
define: {},
|
|
24
|
-
node: document.createElement('div'),
|
|
25
|
-
key: 'testElement',
|
|
26
|
-
on: {},
|
|
27
|
-
update
|
|
28
|
-
}
|
|
29
|
-
opts = {
|
|
30
|
-
preventUpdate: [],
|
|
31
|
-
preventDefineUpdate: [],
|
|
32
|
-
preventBeforeStateUpdateListener: false,
|
|
33
|
-
preventListeners: false,
|
|
34
|
-
preventStateUpdateListener: false
|
|
35
|
-
}
|
|
36
|
-
params = {}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('does not modify opts when params and opts are empty', async () => {
|
|
40
|
-
await element.update({}, opts)
|
|
41
|
-
expect(opts).toEqual({
|
|
42
|
-
calleeElement: false,
|
|
43
|
-
cleanExec: true,
|
|
44
|
-
currentSnapshot: false,
|
|
45
|
-
exclude: [],
|
|
46
|
-
preventRecursive: false,
|
|
47
|
-
stackChanges: false,
|
|
48
|
-
preventUpdate: [],
|
|
49
|
-
preventDefineUpdate: [],
|
|
50
|
-
preventBeforeStateUpdateListener: false,
|
|
51
|
-
preventListeners: false,
|
|
52
|
-
preventStateUpdateListener: false
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('initializes options with UPDATE_DEFAULT_OPTIONS when opts is empty', async () => {
|
|
57
|
-
await element.update({}, opts)
|
|
58
|
-
expect(opts.calleeElement).toBe(false) // Ensure opts is not mutated
|
|
59
|
-
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('merges opts with UPDATE_DEFAULT_OPTIONS using deepMerge', async () => {
|
|
63
|
-
opts.customOption = true
|
|
64
|
-
await element.update({}, opts)
|
|
65
|
-
expect(opts.customOption).toBe(true) // Ensure custom options are preserved
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('converts string params to { text: params }', async () => {
|
|
69
|
-
await element.update('testString', opts)
|
|
70
|
-
expect(element.text).toBe('testString')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('converts number params to { text: params }', async () => {
|
|
74
|
-
await element.update(123, opts)
|
|
75
|
-
expect(element.text).toBe(123)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('returns early if preventInheritAtCurrentState matches element', async () => {
|
|
79
|
-
opts.preventInheritAtCurrentState = { __element: element }
|
|
80
|
-
await element.update({}, opts)
|
|
81
|
-
expect(element.__ref.__currentSnapshot).toBe(6) // No snapshot update
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('initializes __ref if not present', async () => {
|
|
85
|
-
delete element.__ref
|
|
86
|
-
await element.update({}, opts)
|
|
87
|
-
expect(element.__ref).toBeDefined()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('merges options with UPDATE_DEFAULT_OPTIONS when exclude is missing', async () => {
|
|
91
|
-
await element.update({}, opts)
|
|
92
|
-
expect(opts.exclude).toBeDefined() // Ensure exclude is added
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('does not throw or modify opts when params is undefined', async () => {
|
|
96
|
-
await element.update(undefined, opts)
|
|
97
|
-
expect(opts).toEqual({
|
|
98
|
-
calleeElement: false,
|
|
99
|
-
cleanExec: true,
|
|
100
|
-
currentSnapshot: false,
|
|
101
|
-
exclude: [],
|
|
102
|
-
preventRecursive: false,
|
|
103
|
-
preventUpdate: [],
|
|
104
|
-
preventDefineUpdate: [],
|
|
105
|
-
stackChanges: false,
|
|
106
|
-
preventBeforeStateUpdateListener: false,
|
|
107
|
-
preventListeners: false,
|
|
108
|
-
preventStateUpdateListener: false
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('does not throw when opts is undefined', async () => {
|
|
113
|
-
await element.update({}, undefined)
|
|
114
|
-
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('does not throw when opts is null', async () => {
|
|
118
|
-
await element.update({}, null)
|
|
119
|
-
expect(element.__ref).toBeDefined() // Ensure __ref is initialized
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('does not modify the params object', async () => {
|
|
123
|
-
params = { key: 'value' }
|
|
124
|
-
await element.update(params, opts)
|
|
125
|
-
expect(params).toEqual({ key: 'value' })
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('does modify opts when params is an empty object', async () => {
|
|
129
|
-
await element.update({}, opts)
|
|
130
|
-
expect(opts).toEqual({
|
|
131
|
-
calleeElement: false,
|
|
132
|
-
cleanExec: true,
|
|
133
|
-
currentSnapshot: false,
|
|
134
|
-
exclude: [],
|
|
135
|
-
preventRecursive: false,
|
|
136
|
-
stackChanges: false,
|
|
137
|
-
preventUpdate: [],
|
|
138
|
-
preventDefineUpdate: [],
|
|
139
|
-
preventBeforeStateUpdateListener: false,
|
|
140
|
-
preventListeners: false,
|
|
141
|
-
preventStateUpdateListener: false
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('moves regular properties to element.props', async () => {
|
|
146
|
-
params = { props: { title: 'Test', description: 'Content' } }
|
|
147
|
-
await element.update(params, opts)
|
|
148
|
-
expect(element.props).toEqual({
|
|
149
|
-
title: 'Test',
|
|
150
|
-
description: 'Content'
|
|
151
|
-
})
|
|
152
|
-
expect(element.title).toBeUndefined()
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('keeps element-rooted properties', async () => {
|
|
156
|
-
params = { Header: {}, Footer: {}, 0: 'index' }
|
|
157
|
-
await element.update(params, opts)
|
|
158
|
-
expect(element.Header).toBeDefined()
|
|
159
|
-
expect(element.Footer).toBeDefined()
|
|
160
|
-
expect(element['0']).toBe('index')
|
|
161
|
-
expect(element.props).toEqual({})
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('preserves built-in properties on element', async () => {
|
|
165
|
-
params = { props: { className: 'container', hidden: true } }
|
|
166
|
-
await element.update(params, opts)
|
|
167
|
-
expect(element.props.className).toBe('container')
|
|
168
|
-
expect(element.props.hidden).toBe(true)
|
|
169
|
-
expect(element.props).toEqual({ className: 'container', hidden: true })
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('moves element-like properties from props to root', async () => {
|
|
173
|
-
params = { props: { Header: {} } }
|
|
174
|
-
await element.update(params, opts)
|
|
175
|
-
expect(element.Header).toBeDefined()
|
|
176
|
-
expect(element.props.Header).toBeUndefined()
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('exits early when inheritStateUpdates returns false', async () => {
|
|
180
|
-
// Simulate inheritStateUpdates failure
|
|
181
|
-
element.__ref.__stateBlocked = true
|
|
182
|
-
await element.update({ props: { shouldChange: true } }, opts)
|
|
183
|
-
|
|
184
|
-
expect(element.props.shouldChange).toBe(true)
|
|
185
|
-
expect(element.__ref.__stateBlocked).toBe(true) // State remains blocked
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('exits early when checkIfOnUpdate fails', async () => {
|
|
189
|
-
// Force checkIfOnUpdate failure
|
|
190
|
-
element.parent.props.ifCondition = false
|
|
191
|
-
await element.update({ state: { newState: true } }, opts)
|
|
192
|
-
|
|
193
|
-
expect(element.state.newState).toBe(true)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('updates props from parent key match', async () => {
|
|
197
|
-
element.parent.props.testKey = { inherited: true }
|
|
198
|
-
await element.update({}, opts)
|
|
199
|
-
expect(element.props.inherited).toBeUndefined()
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
it('updates props when functions exist in __props', async () => {
|
|
203
|
-
element.__ref.__props.push(() => 'dynamic')
|
|
204
|
-
await element.update({}, opts)
|
|
205
|
-
expect(element.props).toEqual(expect.any(Object)) // Props were processed
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('skips props update when preventPropsUpdate=true', async () => {
|
|
209
|
-
opts.preventPropsUpdate = true
|
|
210
|
-
opts.preventUpdateAfter = true
|
|
211
|
-
element.parent.props.testKey = { shouldExist: true }
|
|
212
|
-
await element.update({}, opts)
|
|
213
|
-
expect(element.props.shouldExist).toBeUndefined()
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
it('should not skips props update when preventPropsUpdate=false', async () => {
|
|
217
|
-
opts.preventPropsUpdate = false
|
|
218
|
-
opts.lazyLoad = true
|
|
219
|
-
opts.onEachUpdate = () => {
|
|
220
|
-
return true
|
|
221
|
-
}
|
|
222
|
-
element.parent.props.testKey = { shouldExist: true }
|
|
223
|
-
element.__ref.__propsStack = []
|
|
224
|
-
element.__ref.__if = true
|
|
225
|
-
element.off = { text: 'off' }
|
|
226
|
-
await element.update({}, opts)
|
|
227
|
-
expect(element.props.shouldExist).toBeUndefined()
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('should set preventUpdateAfterCount to 1 when is not a number', async () => {
|
|
231
|
-
opts.preventPropsUpdate = true
|
|
232
|
-
opts.preventUpdateAfter = 2
|
|
233
|
-
opts.preventUpdateAfterCount = undefined
|
|
234
|
-
element.parent.props.testKey = { shouldExist: true }
|
|
235
|
-
await element.update({}, opts)
|
|
236
|
-
expect(element.props.shouldExist).toBeUndefined()
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
it('processes parent.childProps', async () => {
|
|
240
|
-
element.parent.props.childProps = { global: true }
|
|
241
|
-
await element.update({}, opts)
|
|
242
|
-
expect(element.props.global).toBe(true)
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
it('processes function props', async () => {
|
|
246
|
-
await element.update({ props: { calc: () => 42 } }, opts)
|
|
247
|
-
expect(element.props.calc()).toBe(42)
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('returns element when beforeUpdate rejects', async () => {
|
|
251
|
-
// Simulate beforeUpdate rejection
|
|
252
|
-
element.on.beforeUpdate = () => false
|
|
253
|
-
const result = await element.update({}, opts)
|
|
254
|
-
expect(result).toBe(element)
|
|
255
|
-
})
|
|
256
|
-
})
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
var import_update = require("../update");
|
|
2
|
-
describe("checkIfOnUpdate via update()", () => {
|
|
3
|
-
let element, parent, options;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
parent = {
|
|
6
|
-
node: document.createElement("div"),
|
|
7
|
-
props: {},
|
|
8
|
-
state: {}
|
|
9
|
-
};
|
|
10
|
-
element = {
|
|
11
|
-
__ref: {
|
|
12
|
-
__if: void 0,
|
|
13
|
-
__state: null,
|
|
14
|
-
__hasRootState: false,
|
|
15
|
-
__execProps: {},
|
|
16
|
-
contentElementKey: "content"
|
|
17
|
-
},
|
|
18
|
-
parent,
|
|
19
|
-
props: {},
|
|
20
|
-
state: {
|
|
21
|
-
update: (el, st) => {
|
|
22
|
-
return st;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
context: {
|
|
26
|
-
defaultExtends: {}
|
|
27
|
-
},
|
|
28
|
-
node: document.createElement("div"),
|
|
29
|
-
if: () => true,
|
|
30
|
-
previousElement: () => {
|
|
31
|
-
return {};
|
|
32
|
-
},
|
|
33
|
-
nextElement: () => {
|
|
34
|
-
return {};
|
|
35
|
-
},
|
|
36
|
-
removeContent: () => {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
options = {};
|
|
41
|
-
});
|
|
42
|
-
it("uses props.if when element.if missing", async () => {
|
|
43
|
-
delete element.if;
|
|
44
|
-
element.props.if = () => false;
|
|
45
|
-
await import_update.update.call(element, {}, options);
|
|
46
|
-
expect(element.node).toEqual(document.createElement("div"));
|
|
47
|
-
});
|
|
48
|
-
it("retains state when __hasRootState=true", async () => {
|
|
49
|
-
element.__ref.__hasRootState = true;
|
|
50
|
-
element.state.critical = true;
|
|
51
|
-
element.__ref.__if = false;
|
|
52
|
-
await import_update.update.call(element, {}, options);
|
|
53
|
-
expect(element.state.critical).toBe(true);
|
|
54
|
-
expect(element.state.preserved).toBeUndefined();
|
|
55
|
-
});
|
|
56
|
-
it("processes nested content with parseDeep", async () => {
|
|
57
|
-
element.content = {
|
|
58
|
-
parseDeep: () => ({ parsed: true }),
|
|
59
|
-
existing: "data"
|
|
60
|
-
};
|
|
61
|
-
await import_update.update.call(element, {}, options);
|
|
62
|
-
expect(element.content.parsed).toBe(true);
|
|
63
|
-
expect(element.content.existing).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
it("reattaches after previous sibling", async () => {
|
|
66
|
-
const prevNode = document.createElement("span");
|
|
67
|
-
parent.node.appendChild(prevNode);
|
|
68
|
-
await import_update.update.call(element, {}, options);
|
|
69
|
-
const newElement = parent.node.children[0];
|
|
70
|
-
expect(newElement).toEqual(document.createElement("span"));
|
|
71
|
-
expect(newElement.previousSibling).toBe(null);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
var import_globals = require("@jest/globals");
|
|
2
|
-
var import_children = require("../children");
|
|
3
|
-
describe("children", () => {
|
|
4
|
-
let element, node;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
element = {
|
|
7
|
-
__ref: {},
|
|
8
|
-
state: {},
|
|
9
|
-
props: {},
|
|
10
|
-
call: import_globals.jest.fn(),
|
|
11
|
-
removeContent: import_globals.jest.fn(),
|
|
12
|
-
content: null
|
|
13
|
-
};
|
|
14
|
-
node = {};
|
|
15
|
-
});
|
|
16
|
-
it("handles null/undefined params", async () => {
|
|
17
|
-
const result = await (0, import_children.setChildren)(null, element, node);
|
|
18
|
-
expect(result).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
it("handles direct string children", async () => {
|
|
21
|
-
const result = await (0, import_children.setChildren)("Hello World", element, node);
|
|
22
|
-
expect(result).toEqual({ tag: "fragment", 0: { text: "Hello World" } });
|
|
23
|
-
});
|
|
24
|
-
it("handles numeric children", async () => {
|
|
25
|
-
const result = await (0, import_children.setChildren)(42, element, node);
|
|
26
|
-
expect(result).toEqual({ tag: "fragment", 0: { text: 42 } });
|
|
27
|
-
});
|
|
28
|
-
it("handles array of primitive values with childrenAs prop", async () => {
|
|
29
|
-
const result = await (0, import_children.setChildren)(["one", "two"], element, node);
|
|
30
|
-
expect(result).toEqual({
|
|
31
|
-
tag: "fragment",
|
|
32
|
-
0: { text: "one" },
|
|
33
|
-
1: { text: "two" }
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it("handles array of primitive values with childrenAs state", async () => {
|
|
37
|
-
element.props.childrenAs = "state";
|
|
38
|
-
const result = await (0, import_children.setChildren)(["one", "two"], element, node);
|
|
39
|
-
expect(result).toEqual({
|
|
40
|
-
tag: "fragment",
|
|
41
|
-
0: { state: { value: "one" } },
|
|
42
|
-
1: { state: { value: "two" } }
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it("caches children and detects changes", async () => {
|
|
46
|
-
const children1 = [{ id: 1 }, { id: 2 }];
|
|
47
|
-
const children2 = [{ id: 1 }, { id: 2 }];
|
|
48
|
-
const children3 = [{ id: 1 }, { id: 3 }];
|
|
49
|
-
await (0, import_children.setChildren)(children1, element, node);
|
|
50
|
-
expect(element.__ref.__childrenCache).toEqual(children1);
|
|
51
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined();
|
|
52
|
-
await (0, import_children.setChildren)(children2, element, node);
|
|
53
|
-
expect(element.__ref.__noChildrenDifference).toBe(true);
|
|
54
|
-
await (0, import_children.setChildren)(children3, element, node);
|
|
55
|
-
expect(element.__ref.__noChildrenDifference).toBeUndefined();
|
|
56
|
-
expect(element.__ref.__childrenCache).toEqual(children3);
|
|
57
|
-
});
|
|
58
|
-
it("handles mixed React and normal components", async () => {
|
|
59
|
-
const mixedChildren = [
|
|
60
|
-
{ type: "div", text: "Normal" },
|
|
61
|
-
{ $$typeof: Symbol("react") },
|
|
62
|
-
{ type: "span", text: "Another" }
|
|
63
|
-
];
|
|
64
|
-
await (0, import_children.setChildren)(mixedChildren, element, node);
|
|
65
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
66
|
-
"renderReact",
|
|
67
|
-
[mixedChildren[1]],
|
|
68
|
-
element
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
it("handles state-based children", async () => {
|
|
72
|
-
element.state = {
|
|
73
|
-
items: ["a", "b"],
|
|
74
|
-
parse: () => ["parsed a", "parsed b"]
|
|
75
|
-
};
|
|
76
|
-
const result = await (0, import_children.setChildren)("state", element, node);
|
|
77
|
-
expect(result).toEqual({
|
|
78
|
-
tag: "fragment",
|
|
79
|
-
0: { text: "parsed a" },
|
|
80
|
-
1: { text: "parsed b" }
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
it("handles async function parameters", async () => {
|
|
84
|
-
const asyncParam = async () => ["async1", "async2"];
|
|
85
|
-
const result = await (0, import_children.setChildren)(asyncParam, element, node);
|
|
86
|
-
expect(result).toEqual({
|
|
87
|
-
tag: "fragment",
|
|
88
|
-
0: { text: "async1" },
|
|
89
|
-
1: { text: "async2" }
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
it("handles nested object structures", async () => {
|
|
93
|
-
const nestedChildren = {
|
|
94
|
-
header: { text: "Title" },
|
|
95
|
-
content: {
|
|
96
|
-
nested: { text: "Content" }
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const result = await (0, import_children.setChildren)(nestedChildren, element, node);
|
|
100
|
-
expect(result).toEqual({
|
|
101
|
-
tag: "fragment",
|
|
102
|
-
0: { text: "Title" },
|
|
103
|
-
1: { nested: { text: "Content" } }
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it("handles empty arrays and objects", async () => {
|
|
107
|
-
let result = await (0, import_children.setChildren)([], element, node);
|
|
108
|
-
expect(result).toEqual({
|
|
109
|
-
tag: "fragment"
|
|
110
|
-
});
|
|
111
|
-
result = await (0, import_children.setChildren)({}, element, node);
|
|
112
|
-
expect(result).toEqual({
|
|
113
|
-
tag: "fragment"
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
it("handles falsy values in arrays", async () => {
|
|
117
|
-
const result = await (0, import_children.setChildren)(
|
|
118
|
-
[null, void 0, false, 0, ""],
|
|
119
|
-
element,
|
|
120
|
-
node
|
|
121
|
-
);
|
|
122
|
-
expect(result).toEqual({
|
|
123
|
-
tag: "fragment",
|
|
124
|
-
3: { text: 0 },
|
|
125
|
-
4: { text: "" }
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
it("handles React components with falsy values in array", async () => {
|
|
129
|
-
const mixedChildren = [
|
|
130
|
-
null,
|
|
131
|
-
{ $$typeof: Symbol("react") },
|
|
132
|
-
void 0,
|
|
133
|
-
{ $$typeof: Symbol("react") },
|
|
134
|
-
false
|
|
135
|
-
];
|
|
136
|
-
await (0, import_children.setChildren)(mixedChildren, element, node);
|
|
137
|
-
expect(element.call).toHaveBeenCalledWith(
|
|
138
|
-
"renderReact",
|
|
139
|
-
[mixedChildren[1], mixedChildren[3]],
|
|
140
|
-
element
|
|
141
|
-
);
|
|
142
|
-
});
|
|
143
|
-
it("handles nested state parsing", async () => {
|
|
144
|
-
element.state = {
|
|
145
|
-
nested: {
|
|
146
|
-
items: ["c", "d"]
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
element.state.nested.__proto__.parse = () => ["parsed c", "parsed d"];
|
|
150
|
-
const result = await (0, import_children.setChildren)("nested", element, node);
|
|
151
|
-
expect(result).toEqual({
|
|
152
|
-
tag: "fragment",
|
|
153
|
-
0: { state: ["c", "d"] }
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
it("handles mixed state and regular objects", async () => {
|
|
157
|
-
element.state = {
|
|
158
|
-
header: { parse: () => "Header" },
|
|
159
|
-
footer: { parse: () => "Footer" }
|
|
160
|
-
};
|
|
161
|
-
const result = await (0, import_children.setChildren)(
|
|
162
|
-
{
|
|
163
|
-
header: "header",
|
|
164
|
-
content: { text: "Content" },
|
|
165
|
-
footer: "footer"
|
|
166
|
-
},
|
|
167
|
-
element,
|
|
168
|
-
node
|
|
169
|
-
);
|
|
170
|
-
expect(result).toEqual({
|
|
171
|
-
tag: "fragment",
|
|
172
|
-
0: { text: "header" },
|
|
173
|
-
1: { text: "Content" },
|
|
174
|
-
2: { text: "footer" }
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var import_define = __toESM(require("../define"), 1);
|
|
24
|
-
var import_mixins = require("../mixins");
|
|
25
|
-
describe("default function (registry updater)", () => {
|
|
26
|
-
let originalRegistry;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
originalRegistry = { ...import_mixins.REGISTRY };
|
|
29
|
-
});
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
Object.keys(import_mixins.REGISTRY).forEach((key) => {
|
|
32
|
-
import_mixins.REGISTRY[key] = originalRegistry[key];
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
it("should add new params to REGISTRY when overwrite is true", () => {
|
|
36
|
-
const params = { newKey: "newValue", anotherKey: "anotherValue" };
|
|
37
|
-
const options = { overwrite: true };
|
|
38
|
-
(0, import_define.default)(params, options);
|
|
39
|
-
expect(import_mixins.REGISTRY.newKey).toBe("newValue");
|
|
40
|
-
expect(import_mixins.REGISTRY.anotherKey).toBe("anotherValue");
|
|
41
|
-
});
|
|
42
|
-
it("should not modify REGISTRY when trying to overwrite existing keys without overwrite option", () => {
|
|
43
|
-
const params = { attr: "newValue", text: "newText" };
|
|
44
|
-
try {
|
|
45
|
-
(0, import_define.default)(params);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
}
|
|
48
|
-
expect(import_mixins.REGISTRY.attr).toBe(originalRegistry.attr);
|
|
49
|
-
expect(import_mixins.REGISTRY.text).toBe(originalRegistry.text);
|
|
50
|
-
});
|
|
51
|
-
it("should overwrite existing keys when overwrite is true", () => {
|
|
52
|
-
const params = { attr: "newValue", text: "newText" };
|
|
53
|
-
const options = { overwrite: true };
|
|
54
|
-
(0, import_define.default)(params, options);
|
|
55
|
-
expect(import_mixins.REGISTRY.attr).toBe("newValue");
|
|
56
|
-
expect(import_mixins.REGISTRY.text).toBe("newText");
|
|
57
|
-
});
|
|
58
|
-
it("should handle empty params object without errors", () => {
|
|
59
|
-
const params = {};
|
|
60
|
-
const options = { overwrite: true };
|
|
61
|
-
expect(() => (0, import_define.default)(params, options)).not.toThrow();
|
|
62
|
-
expect(import_mixins.REGISTRY).toEqual(originalRegistry);
|
|
63
|
-
});
|
|
64
|
-
it("should handle empty options object without errors", () => {
|
|
65
|
-
const params = { newKey: "newValue" };
|
|
66
|
-
expect(() => (0, import_define.default)(params, {})).not.toThrow();
|
|
67
|
-
expect(import_mixins.REGISTRY.newKey).toBe("newValue");
|
|
68
|
-
});
|
|
69
|
-
it("should not add new keys when params is empty", () => {
|
|
70
|
-
const params = {};
|
|
71
|
-
const options = { overwrite: true };
|
|
72
|
-
(0, import_define.default)(params, options);
|
|
73
|
-
expect(import_mixins.REGISTRY).toEqual(originalRegistry);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var import_update = require("../update");
|
|
2
|
-
describe("update() with inheritStateUpdates", () => {
|
|
3
|
-
let element, options;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
element = {
|
|
6
|
-
__ref: {
|
|
7
|
-
__state: null,
|
|
8
|
-
__hasRootState: false,
|
|
9
|
-
__execProps: {},
|
|
10
|
-
__props: []
|
|
11
|
-
},
|
|
12
|
-
state: {
|
|
13
|
-
calculated: 42,
|
|
14
|
-
set: () => {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
parent: {
|
|
19
|
-
state: { baseState: true },
|
|
20
|
-
props: {}
|
|
21
|
-
},
|
|
22
|
-
props: {},
|
|
23
|
-
key: "testKey"
|
|
24
|
-
};
|
|
25
|
-
options = {};
|
|
26
|
-
});
|
|
27
|
-
it("processes full update flow when state is inherited", async () => {
|
|
28
|
-
await import_update.update.call(element, { props: { newProp: true } }, options);
|
|
29
|
-
expect(element.props.newProp).toBe(true);
|
|
30
|
-
expect(element.state.baseState).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
it("maintains state when preventInheritedStateUpdate=true", async () => {
|
|
33
|
-
options.preventInheritedStateUpdate = true;
|
|
34
|
-
element.state = { existing: "state" };
|
|
35
|
-
await import_update.update.call(element, {}, options);
|
|
36
|
-
expect(element.state).toEqual({ baseState: true });
|
|
37
|
-
});
|
|
38
|
-
it("overwrites state with function result", async () => {
|
|
39
|
-
element.__ref.__state = () => ({ calculated: 42 });
|
|
40
|
-
options.execStateFunction = true;
|
|
41
|
-
options.stateFunctionOverwrite = true;
|
|
42
|
-
await import_update.update.call(element, {}, options);
|
|
43
|
-
expect(element.state.calculated).toEqual(42);
|
|
44
|
-
});
|
|
45
|
-
it("preserves state when beforeStateUpdate rejects", async () => {
|
|
46
|
-
element.onBeforeStateUpdate = () => false;
|
|
47
|
-
await import_update.update.call(element, { props: { shouldChange: true } }, options);
|
|
48
|
-
expect(element.state).toEqual({ baseState: true });
|
|
49
|
-
expect(element.props.shouldChange).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
it("reflects parent state updates", async () => {
|
|
52
|
-
element.parent.state = { updatedParentState: true };
|
|
53
|
-
await import_update.update.call(element, {}, options);
|
|
54
|
-
expect(element.state.updatedParentState).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
it("preserves local state when __hasRootState=true", async () => {
|
|
57
|
-
element.__ref.__hasRootState = true;
|
|
58
|
-
element.state = { local: "data" };
|
|
59
|
-
await import_update.update.call(element, {}, options);
|
|
60
|
-
expect(element.state.local).toBe("data");
|
|
61
|
-
});
|
|
62
|
-
});
|