@domql/element 2.5.198 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +1 -1
  2. package/__tests__/checkIfOnUpdate.test.js +103 -0
  3. package/__tests__/children.test.js +213 -0
  4. package/__tests__/define.test.js +75 -0
  5. package/__tests__/inheritStateUpdates.test.js +79 -0
  6. package/__tests__/renderElement.test.js +131 -0
  7. package/__tests__/resetElement.test.js +44 -0
  8. package/__tests__/set.test.js +316 -0
  9. package/__tests__/throughExecProps.test.js +86 -0
  10. package/__tests__/throughInitialDefine.test.js +104 -0
  11. package/__tests__/throughInitialExec.test.js +92 -0
  12. package/__tests__/throughUpdatedDefine.test.js +92 -0
  13. package/__tests__/throughUpdatedExec.test.js +110 -0
  14. package/__tests__/tree.test.js +15 -0
  15. package/__tests__/update.test.js +253 -0
  16. package/children.js +105 -0
  17. package/create.js +125 -255
  18. package/dist/cjs/__tests__/checkIfOnUpdate.test.js +73 -0
  19. package/dist/cjs/__tests__/children.test.js +177 -0
  20. package/dist/cjs/__tests__/define.test.js +75 -0
  21. package/dist/cjs/__tests__/inheritStateUpdates.test.js +62 -0
  22. package/dist/cjs/__tests__/renderElement.test.js +138 -0
  23. package/dist/cjs/__tests__/resetElement.test.js +35 -0
  24. package/dist/cjs/__tests__/set.test.js +256 -0
  25. package/dist/cjs/__tests__/throughExecProps.test.js +62 -0
  26. package/dist/cjs/__tests__/throughInitialDefine.test.js +79 -0
  27. package/dist/cjs/__tests__/throughInitialExec.test.js +73 -0
  28. package/dist/cjs/__tests__/throughUpdatedDefine.test.js +69 -0
  29. package/dist/cjs/__tests__/throughUpdatedExec.test.js +84 -0
  30. package/dist/cjs/__tests__/tree.test.js +11 -0
  31. package/dist/cjs/__tests__/update.test.js +219 -0
  32. package/dist/cjs/children.js +87 -0
  33. package/dist/cjs/create.js +74 -215
  34. package/dist/cjs/define.js +1 -2
  35. package/dist/cjs/index.js +3 -3
  36. package/dist/cjs/iterate.js +37 -30
  37. package/dist/cjs/methods/set.js +26 -25
  38. package/dist/cjs/methods/v2.js +7 -17
  39. package/dist/cjs/mixins/attr.js +7 -10
  40. package/dist/cjs/mixins/classList.js +8 -16
  41. package/dist/cjs/mixins/data.js +2 -4
  42. package/dist/cjs/mixins/html.js +2 -4
  43. package/dist/cjs/mixins/index.js +0 -4
  44. package/dist/cjs/mixins/registry.js +7 -67
  45. package/dist/cjs/mixins/scope.js +2 -3
  46. package/dist/cjs/mixins/state.js +4 -7
  47. package/dist/cjs/mixins/style.js +2 -4
  48. package/dist/cjs/mixins/text.js +5 -8
  49. package/dist/cjs/node.js +34 -30
  50. package/dist/cjs/set.js +112 -47
  51. package/dist/cjs/update.js +123 -92
  52. package/dist/cjs/utils/applyParam.js +3 -4
  53. package/dist/cjs/utils/index.js +8 -4
  54. package/dist/cjs/utils/onlyResolveExtends.js +14 -30
  55. package/dist/esm/__tests__/checkIfOnUpdate.test.js +73 -0
  56. package/dist/esm/__tests__/children.test.js +177 -0
  57. package/dist/esm/__tests__/define.test.js +53 -0
  58. package/dist/esm/__tests__/inheritStateUpdates.test.js +62 -0
  59. package/dist/esm/__tests__/renderElement.test.js +116 -0
  60. package/dist/esm/__tests__/resetElement.test.js +35 -0
  61. package/dist/esm/__tests__/set.test.js +256 -0
  62. package/dist/esm/__tests__/throughExecProps.test.js +62 -0
  63. package/dist/esm/__tests__/throughInitialDefine.test.js +79 -0
  64. package/dist/esm/__tests__/throughInitialExec.test.js +73 -0
  65. package/dist/esm/__tests__/throughUpdatedDefine.test.js +69 -0
  66. package/dist/esm/__tests__/throughUpdatedExec.test.js +84 -0
  67. package/dist/esm/__tests__/tree.test.js +11 -0
  68. package/dist/esm/__tests__/update.test.js +219 -0
  69. package/dist/esm/children.js +81 -0
  70. package/dist/esm/create.js +79 -226
  71. package/dist/esm/define.js +1 -2
  72. package/dist/esm/iterate.js +41 -33
  73. package/dist/esm/methods/set.js +5 -4
  74. package/dist/esm/methods/v2.js +7 -17
  75. package/dist/esm/mixins/attr.js +8 -11
  76. package/dist/esm/mixins/classList.js +8 -16
  77. package/dist/esm/mixins/data.js +3 -5
  78. package/dist/esm/mixins/html.js +2 -4
  79. package/dist/esm/mixins/index.js +0 -4
  80. package/dist/esm/mixins/registry.js +7 -67
  81. package/dist/esm/mixins/scope.js +2 -3
  82. package/dist/esm/mixins/state.js +5 -8
  83. package/dist/esm/mixins/style.js +2 -4
  84. package/dist/esm/mixins/text.js +6 -12
  85. package/dist/esm/node.js +25 -31
  86. package/dist/esm/set.js +112 -47
  87. package/dist/esm/update.js +127 -97
  88. package/dist/esm/utils/applyParam.js +3 -4
  89. package/dist/esm/utils/index.js +4 -3
  90. package/dist/esm/utils/onlyResolveExtends.js +22 -31
  91. package/iterate.js +44 -26
  92. package/methods/set.js +5 -4
  93. package/methods/v2.js +5 -4
  94. package/mixins/attr.js +13 -7
  95. package/mixins/classList.js +7 -2
  96. package/mixins/data.js +1 -1
  97. package/mixins/index.js +1 -6
  98. package/mixins/registry.js +6 -53
  99. package/mixins/scope.js +1 -1
  100. package/mixins/state.js +4 -5
  101. package/mixins/text.js +4 -7
  102. package/node.js +31 -28
  103. package/package.json +7 -6
  104. package/set.js +129 -41
  105. package/update.js +169 -89
  106. package/utils/applyParam.js +7 -4
  107. package/utils/index.js +1 -3
  108. package/utils/onlyResolveExtends.js +27 -16
  109. package/cache/index.js +0 -3
  110. package/cache/options.js +0 -4
  111. package/dist/cjs/cache/index.js +0 -24
  112. package/dist/cjs/cache/options.js +0 -26
  113. package/dist/cjs/extend.js +0 -85
  114. package/dist/cjs/methods/index.js +0 -353
  115. package/dist/cjs/mixins/content.js +0 -74
  116. package/dist/cjs/props/create.js +0 -98
  117. package/dist/cjs/props/ignore.js +0 -24
  118. package/dist/cjs/props/index.js +0 -21
  119. package/dist/cjs/props/inherit.js +0 -53
  120. package/dist/cjs/props/update.js +0 -37
  121. package/dist/cjs/utils/component.js +0 -77
  122. package/dist/cjs/utils/extendUtils.js +0 -142
  123. package/dist/cjs/utils/object.js +0 -179
  124. package/dist/cjs/utils/propEvents.js +0 -41
  125. package/dist/esm/cache/index.js +0 -4
  126. package/dist/esm/cache/options.js +0 -6
  127. package/dist/esm/extend.js +0 -71
  128. package/dist/esm/methods/index.js +0 -333
  129. package/dist/esm/mixins/content.js +0 -54
  130. package/dist/esm/props/create.js +0 -78
  131. package/dist/esm/props/ignore.js +0 -4
  132. package/dist/esm/props/index.js +0 -4
  133. package/dist/esm/props/inherit.js +0 -33
  134. package/dist/esm/props/update.js +0 -17
  135. package/dist/esm/utils/component.js +0 -65
  136. package/dist/esm/utils/extendUtils.js +0 -122
  137. package/dist/esm/utils/object.js +0 -159
  138. package/dist/esm/utils/propEvents.js +0 -21
  139. package/extend.js +0 -90
  140. package/methods/index.js +0 -317
  141. package/mixins/content.js +0 -55
  142. package/props/create.js +0 -87
  143. package/props/ignore.js +0 -3
  144. package/props/index.js +0 -6
  145. package/props/inherit.js +0 -35
  146. package/props/update.js +0 -17
  147. package/utils/component.js +0 -68
  148. package/utils/extendUtils.js +0 -134
  149. package/utils/object.js +0 -172
  150. package/utils/propEvents.js +0 -19
@@ -23,7 +23,7 @@ __export(applyParam_exports, {
23
23
  module.exports = __toCommonJS(applyParam_exports);
24
24
  var import_utils = require("@domql/utils");
25
25
  var import_mixins = require("../mixins/index.js");
26
- const applyParam = (param, element, options) => {
26
+ const applyParam = async (param, element, options) => {
27
27
  const { node, context, __ref: ref } = element;
28
28
  const prop = element[param];
29
29
  const { onlyUpdate } = options;
@@ -32,12 +32,11 @@ const applyParam = (param, element, options) => {
32
32
  const isGlobalTransformer = DOMQLPropertyFromContext || DOMQLProperty;
33
33
  const hasDefine = element.define && element.define[param];
34
34
  const hasContextDefine = context && context.define && context.define[param];
35
- if (!ref.__if)
36
- return;
35
+ if (!ref.__if) return;
37
36
  const hasOnlyUpdate = onlyUpdate ? onlyUpdate === param || element.lookup(onlyUpdate) : true;
38
37
  if (isGlobalTransformer && !hasContextDefine && hasOnlyUpdate) {
39
38
  if ((0, import_utils.isFunction)(isGlobalTransformer)) {
40
- isGlobalTransformer(prop, element, node, options);
39
+ await isGlobalTransformer(prop, element, node, options);
41
40
  return;
42
41
  }
43
42
  }
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -11,10 +15,10 @@ var __copyProps = (to, from, except, desc) => {
11
15
  }
12
16
  return to;
13
17
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
19
  var utils_exports = {};
20
+ __export(utils_exports, {
21
+ METHODS_EXL: () => METHODS_EXL
22
+ });
17
23
  module.exports = __toCommonJS(utils_exports);
18
- __reExport(utils_exports, require("./object.js"), module.exports);
19
- __reExport(utils_exports, require("./extendUtils.js"), module.exports);
20
- __reExport(utils_exports, require("./component.js"), module.exports);
24
+ const METHODS_EXL = [];
@@ -24,36 +24,23 @@ module.exports = __toCommonJS(onlyResolveExtends_exports);
24
24
  var import_utils = require("@domql/utils");
25
25
  var import__ = require("..");
26
26
  var import_mixins = require("../mixins/index.js");
27
- var import__2 = require(".");
28
- var import_methods = require("../methods");
29
27
  var import_set = require("../methods/set");
30
28
  var import_state = require("@domql/state");
31
29
  var import_render = require("@domql/render");
32
- var import_props = require("../props");
33
30
  var import_iterate = require("../iterate");
34
31
  const onlyResolveExtends = (element, parent, key, options) => {
35
32
  const { __ref } = element;
36
33
  element.tag = (0, import_render.detectTag)(element);
37
34
  {
38
35
  const { __ref: ref2 } = element;
39
- if (!ref2.__cached)
40
- ref2.__cached = {};
41
- if (!ref2.__defineCache)
42
- ref2.__defineCache = {};
43
- if (!ref2.__exec)
44
- ref2.__exec = {};
45
- if (!ref2.__execProps)
46
- ref2.__execProps = {};
47
- if (!ref2.__class)
48
- ref2.__class = {};
49
- if (!ref2.__classNames)
50
- ref2.__classNames = {};
51
- if (!ref2.__attr)
52
- ref2.__attr = {};
53
- if (!ref2.__changes)
54
- ref2.__changes = [];
55
- if (!ref2.__children)
56
- ref2.__children = [];
36
+ if (!ref2.__defineCache) ref2.__defineCache = {};
37
+ if (!ref2.__exec) ref2.__exec = {};
38
+ if (!ref2.__execProps) ref2.__execProps = {};
39
+ if (!ref2.__class) ref2.__class = {};
40
+ if (!ref2.__classNames) ref2.__classNames = {};
41
+ if (!ref2.__attr) ref2.__attr = {};
42
+ if (!ref2.__changes) ref2.__changes = [];
43
+ if (!ref2.__children) ref2.__children = [];
57
44
  }
58
45
  (0, import_set.addMethods)(element, parent, options);
59
46
  (0, import_state.createState)(element, parent);
@@ -62,22 +49,20 @@ const onlyResolveExtends = (element, parent, key, options) => {
62
49
  const ifPassed = element.if(element, element.state, element.context);
63
50
  if (!ifPassed) {
64
51
  delete ref.__if;
65
- } else
66
- ref.__if = true;
67
- } else
68
- ref.__if = true;
52
+ } else ref.__if = true;
53
+ } else ref.__if = true;
69
54
  if (element.node && ref.__if) {
70
55
  parent[key || element.key] = element;
71
56
  }
72
- (0, import_props.createProps)(element, parent, options);
73
- (0, import__2.applyVariant)(element, parent);
57
+ (0, import_utils.initProps)(element, parent, options);
74
58
  if (element.tag !== "string" && element.tag !== "fragment") {
75
59
  (0, import_iterate.throughInitialDefine)(element);
76
60
  (0, import_iterate.throughInitialExec)(element);
77
61
  for (const param in element) {
78
62
  const prop = element[param];
79
- if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param, element) || (0, import_utils.isObject)(import_mixins.REGISTRY[param]) || (0, import__2.isVariant)(param))
63
+ if ((0, import_utils.isUndefined)(prop) || (0, import_utils.isMethod)(param, element) || (0, import_utils.isObject)(import_mixins.REGISTRY[param])) {
80
64
  continue;
65
+ }
81
66
  const hasDefine = element.define && element.define[param];
82
67
  const contextHasDefine = element.context && element.context.define && element.context.define[param];
83
68
  const optionsHasDefine = options.define && options.define[param];
@@ -95,7 +80,6 @@ const onlyResolveExtends = (element, parent, key, options) => {
95
80
  delete element.props.update;
96
81
  delete element.props.__element;
97
82
  }
98
- if (!options.keepRef)
99
- delete element.__ref;
83
+ if (!options.keepRef) delete element.__ref;
100
84
  return element;
101
85
  };
@@ -0,0 +1,73 @@
1
+ import { update } from "../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 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 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 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 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
+ });
@@ -0,0 +1,177 @@
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
+ });
@@ -0,0 +1,53 @@
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
+ });
@@ -0,0 +1,62 @@
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.props.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
+ });
@@ -0,0 +1,116 @@
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
+ });
@@ -0,0 +1,35 @@
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
+ });