@domql/element 3.0.7 → 3.1.1

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.
Files changed (47) hide show
  1. package/__tests__/inheritStateUpdates.test.js +1 -1
  2. package/__tests__/throughExecProps.test.js +12 -12
  3. package/__tests__/throughInitialDefine.test.js +16 -16
  4. package/__tests__/throughInitialExec.test.js +16 -16
  5. package/__tests__/throughUpdatedDefine.test.js +14 -14
  6. package/__tests__/update.test.js +11 -8
  7. package/create.js +1 -10
  8. package/dist/cjs/__tests__/checkIfOnUpdate.test.js +73 -0
  9. package/dist/cjs/__tests__/children.test.js +177 -0
  10. package/dist/cjs/__tests__/define.test.js +75 -0
  11. package/dist/cjs/__tests__/inheritStateUpdates.test.js +62 -0
  12. package/dist/cjs/__tests__/renderElement.test.js +138 -0
  13. package/dist/cjs/__tests__/resetElement.test.js +35 -0
  14. package/dist/cjs/__tests__/set.test.js +256 -0
  15. package/dist/cjs/__tests__/throughExecProps.test.js +62 -0
  16. package/dist/cjs/__tests__/throughInitialDefine.test.js +79 -0
  17. package/dist/cjs/__tests__/throughInitialExec.test.js +73 -0
  18. package/dist/cjs/__tests__/throughUpdatedDefine.test.js +69 -0
  19. package/dist/cjs/__tests__/throughUpdatedExec.test.js +84 -0
  20. package/dist/cjs/__tests__/tree.test.js +11 -0
  21. package/dist/cjs/__tests__/update.test.js +222 -0
  22. package/dist/cjs/create.js +2 -11
  23. package/dist/cjs/iterate.js +11 -11
  24. package/dist/cjs/update.js +3 -2
  25. package/dist/esm/__tests__/checkIfOnUpdate.test.js +73 -0
  26. package/dist/esm/__tests__/children.test.js +177 -0
  27. package/dist/esm/__tests__/define.test.js +53 -0
  28. package/dist/esm/__tests__/inheritStateUpdates.test.js +62 -0
  29. package/dist/esm/__tests__/renderElement.test.js +116 -0
  30. package/dist/esm/__tests__/resetElement.test.js +35 -0
  31. package/dist/esm/__tests__/set.test.js +256 -0
  32. package/dist/esm/__tests__/throughExecProps.test.js +62 -0
  33. package/dist/esm/__tests__/throughInitialDefine.test.js +79 -0
  34. package/dist/esm/__tests__/throughInitialExec.test.js +73 -0
  35. package/dist/esm/__tests__/throughUpdatedDefine.test.js +69 -0
  36. package/dist/esm/__tests__/throughUpdatedExec.test.js +84 -0
  37. package/dist/esm/__tests__/tree.test.js +11 -0
  38. package/dist/esm/__tests__/update.test.js +222 -0
  39. package/dist/esm/create.js +2 -11
  40. package/dist/esm/iterate.js +13 -12
  41. package/dist/esm/update.js +5 -4
  42. package/iterate.js +13 -12
  43. package/package.json +11 -12
  44. package/update.js +6 -4
  45. package/dist/cjs/utils/onlyResolveExtends.js +0 -85
  46. package/dist/esm/utils/onlyResolveExtends.js +0 -72
  47. package/utils/onlyResolveExtends.js +0 -128
@@ -55,7 +55,7 @@ describe('update() with inheritStateUpdates', () => {
55
55
 
56
56
  // Test 4: Block updates via beforeStateUpdate event
57
57
  it('preserves state when beforeStateUpdate rejects', async () => {
58
- element.props.onBeforeStateUpdate = () => false
58
+ element.onBeforeStateUpdate = () => false
59
59
  await update.call(element, { props: { shouldChange: true } }, options)
60
60
  expect(element.state).toEqual({ baseState: true })
61
61
  expect(element.props.shouldChange).toBe(true)
@@ -15,11 +15,11 @@ describe('throughExecProps', () => {
15
15
  }
16
16
  })
17
17
 
18
- it('should cache and execute define-prefixed function props', () => {
18
+ it('should cache and execute define-prefixed function props', async () => {
19
19
  element.props.isActive = () => true
20
20
  element.props.hasFeature = (el, state) => state.test === 'state'
21
21
 
22
- throughExecProps(element)
22
+ await throughExecProps(element)
23
23
 
24
24
  expect(element.props.isActive).toBe(true)
25
25
  expect(element.props.hasFeature).toBe(true)
@@ -29,48 +29,48 @@ describe('throughExecProps', () => {
29
29
  })
30
30
  })
31
31
 
32
- it('should execute cached functions from previous runs', () => {
32
+ it('should execute cached functions from previous runs', async () => {
33
33
  ref.__execProps.value = () => 'cached'
34
34
  element.props.value = 'current'
35
35
 
36
- throughExecProps(element)
36
+ await throughExecProps(element)
37
37
 
38
38
  expect(element.props.value).toBe('cached')
39
39
  })
40
40
 
41
- it('should leave non-function props unchanged', () => {
41
+ it('should leave non-function props unchanged', async () => {
42
42
  element.props.title = 'static text'
43
43
  element.props.disabled = false
44
44
 
45
- throughExecProps(element)
45
+ await throughExecProps(element)
46
46
 
47
47
  expect(element.props.title).toBe('static text')
48
48
  expect(element.props.disabled).toBe(false)
49
49
  expect(ref.__execProps).toEqual({})
50
50
  })
51
51
 
52
- it('should handle mixed define-prefixed and regular props', () => {
52
+ it('should handle mixed define-prefixed and regular props', async () => {
53
53
  element.props.useHelper = () => 'helper'
54
54
  element.props.color = 'blue'
55
55
 
56
- throughExecProps(element)
56
+ await throughExecProps(element)
57
57
 
58
58
  expect(element.props.useHelper).toBe('helper')
59
59
  expect(element.props.color).toBe('blue')
60
60
  expect(ref.__execProps).toHaveProperty('useHelper')
61
61
  })
62
62
 
63
- it('should preserve existing cache entries', () => {
63
+ it('should preserve existing cache entries', async () => {
64
64
  ref.__execProps.existing = () => 'prior'
65
65
  element.props.existing = 'new'
66
66
 
67
- throughExecProps(element)
67
+ await throughExecProps(element)
68
68
 
69
69
  expect(element.props.existing).toBe('prior')
70
70
  expect(ref.__execProps.existing).toBeInstanceOf(Function)
71
71
  })
72
72
 
73
- it('should pass correct execution context', () => {
73
+ it('should pass correct execution context', async () => {
74
74
  element.props.checkContext = function (el, state, context) {
75
75
  return (
76
76
  this === element &&
@@ -79,7 +79,7 @@ describe('throughExecProps', () => {
79
79
  )
80
80
  }
81
81
 
82
- throughExecProps(element)
82
+ await throughExecProps(element)
83
83
 
84
84
  expect(typeof element.props.checkContext).toBe('function')
85
85
  })
@@ -16,47 +16,47 @@ describe('throughInitialDefine', () => {
16
16
  }
17
17
  })
18
18
 
19
- it('should merge local and global define objects', () => {
19
+ it('should merge local and global define objects', async () => {
20
20
  element.define = { localProp: () => 'local' }
21
21
  element.context.define = { globalProp: () => 'global' }
22
22
 
23
- throughInitialDefine(element)
23
+ await throughInitialDefine(element)
24
24
 
25
25
  expect(element.localProp).toBe('local')
26
26
  expect(element.globalProp).toBe('global')
27
27
  })
28
28
 
29
- it('should cache and execute define functions', () => {
29
+ it('should cache and execute define functions', async () => {
30
30
  element.define.testProp = value => 'defined value'
31
31
  element.testProp = () => 'initial value'
32
32
 
33
- throughInitialDefine(element)
33
+ await throughInitialDefine(element)
34
34
 
35
35
  expect(element.testProp).toBe('defined value')
36
36
  expect(ref.__exec.testProp).toBeInstanceOf(Function)
37
37
  expect(ref.__defineCache.testProp).toBe('initial value')
38
38
  })
39
39
 
40
- it('should skip execution for method properties', () => {
40
+ it('should skip execution for method properties', async () => {
41
41
  element.define.update = value => 'should not execute'
42
42
  element.update = () => 'built-in method'
43
43
 
44
- throughInitialDefine(element)
44
+ await throughInitialDefine(element)
45
45
 
46
46
  expect(ref.__exec).not.toHaveProperty('update')
47
47
  expect(ref.__defineCache).not.toHaveProperty('update')
48
48
  })
49
49
 
50
- it('should handle parse method in execution result', () => {
50
+ it('should handle parse method in execution result', async () => {
51
51
  element.define.testProp = () => ({ parse: () => 'parsed value' })
52
52
  element.testProp = () => 'initial value'
53
53
 
54
- throughInitialDefine(element)
54
+ await throughInitialDefine(element)
55
55
 
56
56
  expect(ref.__defineCache.testProp).toBe('initial value')
57
57
  })
58
58
 
59
- it('should pass correct arguments to define functions', () => {
59
+ it('should pass correct arguments to define functions', async () => {
60
60
  element.define.testProp = (value, el, state, context) => ({
61
61
  valueMatch: value === 'initial value',
62
62
  elMatch: el === element,
@@ -65,7 +65,7 @@ describe('throughInitialDefine', () => {
65
65
  })
66
66
  element.testProp = 'initial value'
67
67
 
68
- throughInitialDefine(element)
68
+ await throughInitialDefine(element)
69
69
 
70
70
  expect(element.testProp).toEqual({
71
71
  valueMatch: true,
@@ -75,17 +75,17 @@ describe('throughInitialDefine', () => {
75
75
  })
76
76
  })
77
77
 
78
- it('should handle non-function element properties', () => {
78
+ it('should handle non-function element properties', async () => {
79
79
  element.define.testProp = value => 'defined value'
80
80
  element.testProp = 'non-function value'
81
81
 
82
- throughInitialDefine(element)
82
+ await throughInitialDefine(element)
83
83
 
84
84
  expect(element.testProp).toBe('defined value')
85
85
  })
86
86
 
87
- it('should handle empty define objects', () => {
88
- throughInitialDefine(element)
87
+ it('should handle empty define objects', async () => {
88
+ await throughInitialDefine(element)
89
89
 
90
90
  expect(element).toEqual({
91
91
  ...element,
@@ -93,11 +93,11 @@ describe('throughInitialDefine', () => {
93
93
  })
94
94
  })
95
95
 
96
- it('should handle null or undefined define properties', () => {
96
+ it('should handle null or undefined define properties', async () => {
97
97
  element.define.testProp = () => null
98
98
  element.testProp = 'initial value'
99
99
 
100
- throughInitialDefine(element)
100
+ await throughInitialDefine(element)
101
101
 
102
102
  expect(element.testProp).toBe('initial value')
103
103
  })
@@ -14,63 +14,63 @@ describe('throughInitialExec', () => {
14
14
  }
15
15
  })
16
16
 
17
- it('should process non-method functions and update element properties', () => {
18
- throughInitialExec(element)
17
+ it('should process non-method functions and update element properties', async () => {
18
+ await throughInitialExec(element)
19
19
 
20
20
  expect(element.customFn).toBe('executed')
21
21
  expect(ref.__exec.customFn).toBeInstanceOf(Function)
22
22
  })
23
23
 
24
- it('should skip excluded parameters', () => {
24
+ it('should skip excluded parameters', async () => {
25
25
  element.excludedFn = () => 'should not execute'
26
- throughInitialExec(element, { excludedFn: true })
26
+ await throughInitialExec(element, { excludedFn: true })
27
27
 
28
28
  expect(element.excludedFn).toBeInstanceOf(Function)
29
29
  expect(ref.__exec).not.toHaveProperty('excludedFn')
30
30
  })
31
31
 
32
- it('should skip methods from METHODS array', () => {
32
+ it('should skip methods from METHODS array', async () => {
33
33
  element.update = () => 'built-in method'
34
- throughInitialExec(element)
34
+ await throughInitialExec(element)
35
35
 
36
36
  expect(element.update).toBeInstanceOf(Function)
37
37
  expect(ref.__exec).not.toHaveProperty('update')
38
38
  })
39
39
 
40
- it('should skip methods from context.methods', () => {
40
+ it('should skip methods from context.methods', async () => {
41
41
  element.context.methods = { contextMethod: true }
42
42
  element.contextMethod = () => 'context method'
43
- throughInitialExec(element)
43
+ await throughInitialExec(element)
44
44
 
45
45
  expect(element.contextMethod).toBeInstanceOf(Function)
46
46
  expect(ref.__exec).not.toHaveProperty('contextMethod')
47
47
  })
48
48
 
49
- it('should leave non-function properties unchanged', () => {
49
+ it('should leave non-function properties unchanged', async () => {
50
50
  element.stringProp = 'text'
51
- throughInitialExec(element)
51
+ await throughInitialExec(element)
52
52
 
53
53
  expect(element.stringProp).toBe('text')
54
54
  expect(ref.__exec).not.toHaveProperty('stringProp')
55
55
  })
56
56
 
57
- it('should store original functions in __exec', () => {
57
+ it('should store original functions in __exec', async () => {
58
58
  const originalFn = () => 'original'
59
59
  element.testFn = originalFn
60
- throughInitialExec(element)
60
+ await throughInitialExec(element)
61
61
 
62
62
  expect(ref.__exec.testFn).toBe(originalFn)
63
63
  expect(element.testFn).toBe('original')
64
64
  })
65
65
 
66
- it('should execute functions with correct arguments', () => {
66
+ it('should execute functions with correct arguments', async () => {
67
67
  element.argChecker = (el, state, context) => ({
68
68
  elIsElement: el === element,
69
69
  stateMatch: state === element.state,
70
70
  contextMatch: context === element.context
71
71
  })
72
72
 
73
- throughInitialExec(element)
73
+ await throughInitialExec(element)
74
74
 
75
75
  expect(element.argChecker).toEqual({
76
76
  elIsElement: true,
@@ -79,10 +79,10 @@ describe('throughInitialExec', () => {
79
79
  })
80
80
  })
81
81
 
82
- it('should handle empty exclude object', () => {
82
+ it('should handle empty exclude object', async () => {
83
83
  element.fn1 = () => 'one'
84
84
  element.fn2 = () => 'two'
85
- throughInitialExec(element, {})
85
+ await throughInitialExec(element, {})
86
86
 
87
87
  expect(element.fn1).toBe('one')
88
88
  expect(element.fn2).toBe('two')
@@ -16,54 +16,54 @@ describe('throughUpdatedDefine', () => {
16
16
  }
17
17
  })
18
18
 
19
- it('should merge local and global define objects', () => {
19
+ it('should merge local and global define objects', async () => {
20
20
  element.define = { localProp: () => 'local' }
21
21
  element.context.define = { globalProp: () => 'global' }
22
22
 
23
- throughUpdatedDefine(element)
23
+ await throughUpdatedDefine(element)
24
24
 
25
25
  expect(element.localProp).toBe('local')
26
26
  expect(element.globalProp).toBe('global')
27
27
  })
28
28
 
29
- it('should update element properties using cached exec functions', () => {
29
+ it('should update element properties using cached exec functions', async () => {
30
30
  ref.__exec.testProp = () => 'cached value'
31
31
  element.define.testProp = cached => `updated ${cached}`
32
32
 
33
- throughUpdatedDefine(element)
33
+ await throughUpdatedDefine(element)
34
34
 
35
35
  expect(element.testProp).toBe('updated cached value')
36
36
  expect(ref.__defineCache.testProp).toBe('cached value')
37
37
  })
38
38
 
39
- it('should handle non-function cached values', () => {
39
+ it('should handle non-function cached values', async () => {
40
40
  ref.__defineCache.testProp = 'static value'
41
41
  element.define.testProp = cached => `updated ${cached}`
42
42
 
43
- throughUpdatedDefine(element)
43
+ await throughUpdatedDefine(element)
44
44
 
45
45
  expect(element.testProp).toBe('updated static value')
46
46
  })
47
47
 
48
- it('should skip updates for undefined or null results', () => {
48
+ it('should skip updates for undefined or null results', async () => {
49
49
  ref.__exec.testProp = () => 'cached value'
50
50
  element.define.testProp = () => null
51
51
  element.testProp = 'original value'
52
52
 
53
- throughUpdatedDefine(element)
53
+ await throughUpdatedDefine(element)
54
54
 
55
55
  expect(element.testProp).toBe('original value')
56
56
  })
57
57
 
58
- it('should handle empty define objects', () => {
58
+ it('should handle empty define objects', async () => {
59
59
  const originalElement = { ...element }
60
60
 
61
- throughUpdatedDefine(element)
61
+ await throughUpdatedDefine(element)
62
62
 
63
63
  expect(element).toEqual(originalElement)
64
64
  })
65
65
 
66
- it('should pass correct arguments to define functions', () => {
66
+ it('should pass correct arguments to define functions', async () => {
67
67
  element.define.testProp = (cached, el, state, context) => ({
68
68
  cachedMatch: cached === 'cached value',
69
69
  elMatch: el === element,
@@ -72,7 +72,7 @@ describe('throughUpdatedDefine', () => {
72
72
  })
73
73
  ref.__defineCache.testProp = 'cached value'
74
74
 
75
- throughUpdatedDefine(element)
75
+ await throughUpdatedDefine(element)
76
76
 
77
77
  expect(element.testProp).toEqual({
78
78
  cachedMatch: true,
@@ -82,10 +82,10 @@ describe('throughUpdatedDefine', () => {
82
82
  })
83
83
  })
84
84
 
85
- it('should return an empty changes object', () => {
85
+ it('should return an empty changes object', async () => {
86
86
  element.define.testProp = () => 'updated value'
87
87
 
88
- const changes = throughUpdatedDefine(element)
88
+ const changes = await throughUpdatedDefine(element)
89
89
 
90
90
  expect(changes).toEqual({})
91
91
  })
@@ -6,9 +6,11 @@ describe('update()', () => {
6
6
  beforeEach(() => {
7
7
  element = {
8
8
  __ref: {
9
+ __if: true,
9
10
  __execProps: {},
10
11
  __exec: {},
11
12
  __defineCache: {},
13
+ __propsStack: [],
12
14
  __props: [],
13
15
  __state: 'state'
14
16
  },
@@ -17,6 +19,7 @@ describe('update()', () => {
17
19
  parent: {
18
20
  props: {}
19
21
  },
22
+ context: {},
20
23
  define: {},
21
24
  node: document.createElement('div'),
22
25
  key: 'testElement',
@@ -233,21 +236,21 @@ describe('update()', () => {
233
236
  expect(element.props.shouldExist).toBeUndefined()
234
237
  })
235
238
 
236
- it('returns element when beforeUpdate rejects', async () => {
237
- // Simulate beforeUpdate rejection
238
- element.props.onBeforeUpdate = () => false
239
- const result = await element.update({}, opts)
240
- expect(result).toBe(element)
241
- })
242
-
243
239
  it('processes parent.childProps', async () => {
244
240
  element.parent.props.childProps = { global: true }
245
241
  await element.update({}, opts)
246
- expect(element.props.global).toBeUndefined()
242
+ expect(element.props.global).toBe(true)
247
243
  })
248
244
 
249
245
  it('processes function props', async () => {
250
246
  await element.update({ props: { calc: () => 42 } }, opts)
251
247
  expect(element.props.calc()).toBe(42)
252
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
+ })
253
256
  })
package/create.js CHANGED
@@ -51,7 +51,7 @@ export const create = async (
51
51
 
52
52
  applyExtends(element, parent, options)
53
53
 
54
- propertizeElement(element, parent)
54
+ propertizeElement.call(element, element)
55
55
 
56
56
  await triggerEventOn('start', element, options)
57
57
 
@@ -167,15 +167,6 @@ const renderElement = async (element, parent, options, attachOptions) => {
167
167
  if (element.on?.error) {
168
168
  element.on.error(e, element, element.state, element.context, options)
169
169
  }
170
- if (element.props?.onError) {
171
- element.props.onError(
172
- e,
173
- element,
174
- element.state,
175
- element.context,
176
- options
177
- )
178
- }
179
170
  }
180
171
  }
181
172
 
@@ -0,0 +1,73 @@
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
+ });