@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.
Files changed (90) hide show
  1. package/README.md +4 -6
  2. package/__tests__/checkIfOnUpdate.test.js +12 -12
  3. package/__tests__/children.test.js +34 -38
  4. package/__tests__/inheritStateUpdates.test.js +12 -12
  5. package/__tests__/renderElement.test.js +11 -11
  6. package/__tests__/resetElement.test.js +6 -6
  7. package/__tests__/set.test.js +32 -36
  8. package/__tests__/throughExecProps.test.js +12 -12
  9. package/__tests__/throughInitialDefine.test.js +16 -16
  10. package/__tests__/throughInitialExec.test.js +16 -16
  11. package/__tests__/throughUpdatedDefine.test.js +14 -14
  12. package/__tests__/throughUpdatedExec.test.js +17 -16
  13. package/__tests__/update.test.js +54 -54
  14. package/children.js +5 -6
  15. package/create.js +18 -20
  16. package/dist/cjs/children.js +4 -2
  17. package/dist/cjs/create.js +16 -16
  18. package/dist/cjs/extend.js +88 -0
  19. package/dist/cjs/iterate.js +76 -20
  20. package/dist/cjs/mixins/content.js +73 -0
  21. package/dist/cjs/mixins/html.js +1 -1
  22. package/dist/cjs/mixins/registry.js +2 -2
  23. package/dist/cjs/mixins/scope.js +1 -1
  24. package/dist/cjs/mixins/state.js +2 -2
  25. package/dist/cjs/mixins/text.js +4 -4
  26. package/dist/cjs/node.js +15 -15
  27. package/dist/cjs/set.js +22 -27
  28. package/dist/cjs/update.js +24 -33
  29. package/dist/cjs/utils/applyParam.js +4 -4
  30. package/dist/cjs/utils/extendUtils.js +132 -0
  31. package/dist/cjs/utils/propEvents.js +39 -0
  32. package/dist/esm/children.js +5 -3
  33. package/dist/esm/create.js +16 -16
  34. package/dist/esm/extend.js +74 -0
  35. package/dist/esm/iterate.js +77 -22
  36. package/dist/esm/mixins/content.js +53 -0
  37. package/dist/esm/mixins/html.js +1 -1
  38. package/dist/esm/mixins/registry.js +1 -1
  39. package/dist/esm/mixins/scope.js +1 -1
  40. package/dist/esm/mixins/state.js +3 -3
  41. package/dist/esm/mixins/text.js +4 -4
  42. package/dist/esm/node.js +15 -15
  43. package/dist/esm/set.js +23 -28
  44. package/dist/esm/update.js +24 -33
  45. package/dist/esm/utils/applyParam.js +5 -5
  46. package/dist/esm/utils/extendUtils.js +119 -0
  47. package/dist/esm/utils/propEvents.js +19 -0
  48. package/extend.js +98 -0
  49. package/iterate.js +80 -25
  50. package/mixins/content.js +65 -0
  51. package/mixins/html.js +1 -1
  52. package/mixins/registry.js +1 -1
  53. package/mixins/scope.js +1 -1
  54. package/mixins/state.js +3 -3
  55. package/mixins/text.js +4 -4
  56. package/node.js +15 -15
  57. package/package.json +8 -8
  58. package/set.js +23 -28
  59. package/update.js +25 -34
  60. package/utils/applyParam.js +5 -5
  61. package/utils/extendUtils.js +149 -0
  62. package/utils/propEvents.js +19 -0
  63. package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
  64. package/dist/cjs/__tests__/children.test.js +0 -177
  65. package/dist/cjs/__tests__/define.test.js +0 -75
  66. package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
  67. package/dist/cjs/__tests__/renderElement.test.js +0 -138
  68. package/dist/cjs/__tests__/resetElement.test.js +0 -35
  69. package/dist/cjs/__tests__/set.test.js +0 -256
  70. package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
  71. package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
  72. package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
  73. package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
  74. package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
  75. package/dist/cjs/__tests__/tree.test.js +0 -11
  76. package/dist/cjs/__tests__/update.test.js +0 -222
  77. package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
  78. package/dist/esm/__tests__/children.test.js +0 -177
  79. package/dist/esm/__tests__/define.test.js +0 -53
  80. package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
  81. package/dist/esm/__tests__/renderElement.test.js +0 -116
  82. package/dist/esm/__tests__/resetElement.test.js +0 -35
  83. package/dist/esm/__tests__/set.test.js +0 -256
  84. package/dist/esm/__tests__/throughExecProps.test.js +0 -62
  85. package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
  86. package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
  87. package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
  88. package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
  89. package/dist/esm/__tests__/tree.test.js +0 -11
  90. package/dist/esm/__tests__/update.test.js +0 -222
@@ -1,177 +0,0 @@
1
- import { jest } from "@jest/globals";
2
- import { setChildren } from "../children";
3
- describe("children", () => {
4
- let element, node;
5
- beforeEach(() => {
6
- element = {
7
- __ref: {},
8
- state: {},
9
- props: {},
10
- call: jest.fn(),
11
- removeContent: jest.fn(),
12
- content: null
13
- };
14
- node = {};
15
- });
16
- it("handles null/undefined params", async () => {
17
- const result = await setChildren(null, element, node);
18
- expect(result).toBeUndefined();
19
- });
20
- it("handles direct string children", async () => {
21
- const result = await 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 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 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 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 setChildren(children1, element, node);
50
- expect(element.__ref.__childrenCache).toEqual(children1);
51
- expect(element.__ref.__noChildrenDifference).toBeUndefined();
52
- await setChildren(children2, element, node);
53
- expect(element.__ref.__noChildrenDifference).toBe(true);
54
- await 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 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 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 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 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 setChildren([], element, node);
108
- expect(result).toEqual({
109
- tag: "fragment"
110
- });
111
- result = await setChildren({}, element, node);
112
- expect(result).toEqual({
113
- tag: "fragment"
114
- });
115
- });
116
- it("handles falsy values in arrays", async () => {
117
- const result = await 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 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 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 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,53 +0,0 @@
1
- import define from "../define";
2
- import { REGISTRY } from "../mixins";
3
- describe("default function (registry updater)", () => {
4
- let originalRegistry;
5
- beforeEach(() => {
6
- originalRegistry = { ...REGISTRY };
7
- });
8
- afterEach(() => {
9
- Object.keys(REGISTRY).forEach((key) => {
10
- REGISTRY[key] = originalRegistry[key];
11
- });
12
- });
13
- it("should add new params to REGISTRY when overwrite is true", () => {
14
- const params = { newKey: "newValue", anotherKey: "anotherValue" };
15
- const options = { overwrite: true };
16
- define(params, options);
17
- expect(REGISTRY.newKey).toBe("newValue");
18
- expect(REGISTRY.anotherKey).toBe("anotherValue");
19
- });
20
- it("should not modify REGISTRY when trying to overwrite existing keys without overwrite option", () => {
21
- const params = { attr: "newValue", text: "newText" };
22
- try {
23
- define(params);
24
- } catch (e) {
25
- }
26
- expect(REGISTRY.attr).toBe(originalRegistry.attr);
27
- expect(REGISTRY.text).toBe(originalRegistry.text);
28
- });
29
- it("should overwrite existing keys when overwrite is true", () => {
30
- const params = { attr: "newValue", text: "newText" };
31
- const options = { overwrite: true };
32
- define(params, options);
33
- expect(REGISTRY.attr).toBe("newValue");
34
- expect(REGISTRY.text).toBe("newText");
35
- });
36
- it("should handle empty params object without errors", () => {
37
- const params = {};
38
- const options = { overwrite: true };
39
- expect(() => define(params, options)).not.toThrow();
40
- expect(REGISTRY).toEqual(originalRegistry);
41
- });
42
- it("should handle empty options object without errors", () => {
43
- const params = { newKey: "newValue" };
44
- expect(() => define(params, {})).not.toThrow();
45
- expect(REGISTRY.newKey).toBe("newValue");
46
- });
47
- it("should not add new keys when params is empty", () => {
48
- const params = {};
49
- const options = { overwrite: true };
50
- define(params, options);
51
- expect(REGISTRY).toEqual(originalRegistry);
52
- });
53
- });
@@ -1,62 +0,0 @@
1
- import { update } from "../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 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 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 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 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 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 update.call(element, {}, options);
60
- expect(element.state.local).toBe("data");
61
- });
62
- });
@@ -1,116 +0,0 @@
1
- import { jest } from "@jest/globals";
2
- describe("create()", () => {
3
- let props;
4
- let parent;
5
- const OLD_ENV = process.env;
6
- beforeEach(() => {
7
- props = {
8
- __ref: { __if: false, path: [], __skipCreate: true },
9
- key: "testKey",
10
- context: {
11
- defaultExtends: {},
12
- define: ["test"]
13
- },
14
- scope: "props",
15
- define: ["test"]
16
- };
17
- parent = {
18
- testKey: "parentTestKey",
19
- key: "parentKey"
20
- };
21
- jest.resetModules();
22
- process.env = { ...OLD_ENV };
23
- });
24
- afterAll(() => {
25
- process.env = OLD_ENV;
26
- });
27
- test("should execute onlyResolveExtends when __skipCreate is true", async () => {
28
- props.__ref.__skipCreate = true;
29
- props.scope = void 0;
30
- const { create } = await import("../create");
31
- await create(props, parent, "passedKey", {
32
- onlyResolveExtends: true,
33
- define: ["test"]
34
- });
35
- expect(parent.__ref).toBeUndefined();
36
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
37
- });
38
- test("should execute onlyResolveExtends when __ref.__if is true", async () => {
39
- props.__ref.__if = true;
40
- props.scope = "state";
41
- const { create } = await import("../create");
42
- await create(props, parent, "passedKey", {
43
- onlyResolveExtends: true,
44
- define: ["test"]
45
- });
46
- expect(parent.__ref).toBeUndefined();
47
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
48
- });
49
- test("should execute onlyResolveExtends when scope is not state", async () => {
50
- process.env.NODE_ENV = "prod";
51
- props.__ref = void 0;
52
- const { create } = await import("../create");
53
- await create(props, parent, "passedKey", { onlyResolveExtends: true });
54
- expect(parent.__ref).toBeUndefined();
55
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
56
- });
57
- test("should execute catch statement when __ref is undefined", async () => {
58
- process.env.NODE_ENV = "prod";
59
- props.__ref = void 0;
60
- const { create } = await import("../create");
61
- await create(props, parent, "passedKey");
62
- expect(parent.__ref).toBeUndefined();
63
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
64
- });
65
- test("should attaches element to parent when ref.__if is false", async () => {
66
- process.env.NODE_ENV = "prod";
67
- const { create } = await import("../create");
68
- await create(props, parent, "passedKey");
69
- expect(parent.__ref).toBeUndefined();
70
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
71
- });
72
- test("should attach element to parent when ref.__if is true", async () => {
73
- process.env.NODE_ENV = "prod";
74
- props.__if = true;
75
- const { create } = await import("../create");
76
- await create(props, parent, "passedKey");
77
- expect(parent.testKey).toBe("parentTestKey");
78
- expect(parent.passedKey).toBe(props.__ref.parent.passedKey);
79
- });
80
- test("skips createNestedChild when __uniqId exists", async () => {
81
- process.env.NODE_ENV = "prod";
82
- props.__ref = { __uniqId: "existing-id", path: [] };
83
- const { create } = await import("../create");
84
- await create(props, {}, "passedKey");
85
- expect(props.__ref.__uniqId).toBeDefined();
86
- });
87
- test("skips createNestedChild when infinite loop detected", async () => {
88
- process.env.NODE_ENV = "prod";
89
- props.__ref = { path: ["loop-path"], __uniqId: void 0 };
90
- const { create } = await import("../create");
91
- await create(props, {}, "passedKey");
92
- expect(props.__ref.__uniqId).toBeDefined();
93
- });
94
- test("should modifies path containing ComponentsGrid", async () => {
95
- process.env.NODE_ENV = "prod";
96
- props.__ref = { path: ["ComponentsGrid", "x", "y", "z"] };
97
- const { create } = await import("../create");
98
- await create(props, {}, ["ComponentsGrid", "x", "y", "z"]);
99
- expect(props.__ref.path).toEqual(["ComponentsGrid,x,y,z"]);
100
- });
101
- test("should modifies path containing demoComponent", async () => {
102
- process.env.NODE_ENV = "prod";
103
- props.__ref = { path: ["demoComponent", "a", "b", "c"] };
104
- const { create } = await import("../create");
105
- await create(props, {}, ["demoComponent", "a", "b", "c"]);
106
- expect(props.__ref.path).toEqual(["demoComponent,a,b,c"]);
107
- });
108
- test("uses element.key when key property is missing", async () => {
109
- process.env.NODE_ENV = "prod";
110
- props.__ref = { __if: false, path: [] };
111
- props.key = "fallbackKey";
112
- const { create } = await import("../create");
113
- await create(props, parent, null);
114
- expect(props.__ref.parent.fallbackKey).toBeDefined();
115
- });
116
- });
@@ -1,35 +0,0 @@
1
- import { resetContent } from "../set";
2
- describe("resetContent", () => {
3
- let element, ref;
4
- beforeEach(() => {
5
- ref = {
6
- contentElementKey: "content"
7
- };
8
- element = {
9
- __ref: ref,
10
- content: { node: document.createElement("div") },
11
- node: document.createElement("div"),
12
- context: {}
13
- };
14
- });
15
- it("should update contentElementKey from options", async () => {
16
- await resetContent({}, element, { contentElementKey: "mainContent" });
17
- expect(ref.contentElementKey).toBe("mainContent");
18
- expect(element.mainContent).toBeDefined();
19
- });
20
- it("should merge options correctly", async () => {
21
- await resetContent({}, element, { customOption: true });
22
- expect(element.content).toEqual(
23
- expect.objectContaining({
24
- // Verify options merging through observable behavior
25
- // (this assertion pattern would need actual create() implementation details)
26
- })
27
- );
28
- });
29
- it("should maintain context through reset", async () => {
30
- const originalContext = element.context;
31
- await resetContent({}, element, {});
32
- expect(element.context).toBe(originalContext);
33
- expect(element.content.context).toBe(originalContext);
34
- });
35
- });