@domql/element 3.0.7 → 3.1.2
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/__tests__/inheritStateUpdates.test.js +1 -1
- package/__tests__/throughExecProps.test.js +12 -12
- package/__tests__/throughInitialDefine.test.js +16 -16
- package/__tests__/throughInitialExec.test.js +16 -16
- package/__tests__/throughUpdatedDefine.test.js +14 -14
- package/__tests__/update.test.js +11 -8
- package/create.js +1 -10
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/cjs/__tests__/children.test.js +177 -0
- package/dist/cjs/__tests__/define.test.js +75 -0
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/cjs/__tests__/renderElement.test.js +138 -0
- package/dist/cjs/__tests__/resetElement.test.js +35 -0
- package/dist/cjs/__tests__/set.test.js +256 -0
- package/dist/cjs/__tests__/throughExecProps.test.js +62 -0
- package/dist/cjs/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/cjs/__tests__/throughInitialExec.test.js +73 -0
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/cjs/__tests__/tree.test.js +11 -0
- package/dist/cjs/__tests__/update.test.js +222 -0
- package/dist/cjs/create.js +2 -11
- package/dist/cjs/iterate.js +11 -11
- package/dist/cjs/update.js +3 -2
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/esm/__tests__/children.test.js +177 -0
- package/dist/esm/__tests__/define.test.js +53 -0
- package/dist/esm/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/esm/__tests__/renderElement.test.js +116 -0
- package/dist/esm/__tests__/resetElement.test.js +35 -0
- package/dist/esm/__tests__/set.test.js +256 -0
- package/dist/esm/__tests__/throughExecProps.test.js +62 -0
- package/dist/esm/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/esm/__tests__/throughInitialExec.test.js +73 -0
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/esm/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/esm/__tests__/tree.test.js +11 -0
- package/dist/esm/__tests__/update.test.js +222 -0
- package/dist/esm/create.js +2 -11
- package/dist/esm/iterate.js +13 -12
- package/dist/esm/update.js +5 -4
- package/iterate.js +13 -12
- package/package.json +11 -12
- package/update.js +6 -4
- package/dist/cjs/utils/onlyResolveExtends.js +0 -85
- package/dist/esm/utils/onlyResolveExtends.js +0 -72
- package/utils/onlyResolveExtends.js +0 -128
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { throughUpdatedDefine } from "../iterate";
|
|
2
|
+
describe("throughUpdatedDefine", () => {
|
|
3
|
+
let element, ref;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
ref = {
|
|
6
|
+
__exec: {},
|
|
7
|
+
__defineCache: {}
|
|
8
|
+
};
|
|
9
|
+
element = {
|
|
10
|
+
__ref: ref,
|
|
11
|
+
define: {},
|
|
12
|
+
state: { testState: true },
|
|
13
|
+
context: { testContext: true }
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
it("should merge local and global define objects", async () => {
|
|
17
|
+
element.define = { localProp: () => "local" };
|
|
18
|
+
element.context.define = { globalProp: () => "global" };
|
|
19
|
+
await throughUpdatedDefine(element);
|
|
20
|
+
expect(element.localProp).toBe("local");
|
|
21
|
+
expect(element.globalProp).toBe("global");
|
|
22
|
+
});
|
|
23
|
+
it("should update element properties using cached exec functions", async () => {
|
|
24
|
+
ref.__exec.testProp = () => "cached value";
|
|
25
|
+
element.define.testProp = (cached) => `updated ${cached}`;
|
|
26
|
+
await throughUpdatedDefine(element);
|
|
27
|
+
expect(element.testProp).toBe("updated cached value");
|
|
28
|
+
expect(ref.__defineCache.testProp).toBe("cached value");
|
|
29
|
+
});
|
|
30
|
+
it("should handle non-function cached values", async () => {
|
|
31
|
+
ref.__defineCache.testProp = "static value";
|
|
32
|
+
element.define.testProp = (cached) => `updated ${cached}`;
|
|
33
|
+
await throughUpdatedDefine(element);
|
|
34
|
+
expect(element.testProp).toBe("updated static value");
|
|
35
|
+
});
|
|
36
|
+
it("should skip updates for undefined or null results", async () => {
|
|
37
|
+
ref.__exec.testProp = () => "cached value";
|
|
38
|
+
element.define.testProp = () => null;
|
|
39
|
+
element.testProp = "original value";
|
|
40
|
+
await throughUpdatedDefine(element);
|
|
41
|
+
expect(element.testProp).toBe("original value");
|
|
42
|
+
});
|
|
43
|
+
it("should handle empty define objects", async () => {
|
|
44
|
+
const originalElement = { ...element };
|
|
45
|
+
await throughUpdatedDefine(element);
|
|
46
|
+
expect(element).toEqual(originalElement);
|
|
47
|
+
});
|
|
48
|
+
it("should pass correct arguments to define functions", async () => {
|
|
49
|
+
element.define.testProp = (cached, el, state, context) => ({
|
|
50
|
+
cachedMatch: cached === "cached value",
|
|
51
|
+
elMatch: el === element,
|
|
52
|
+
stateMatch: state === element.state,
|
|
53
|
+
contextMatch: context === element.context
|
|
54
|
+
});
|
|
55
|
+
ref.__defineCache.testProp = "cached value";
|
|
56
|
+
await throughUpdatedDefine(element);
|
|
57
|
+
expect(element.testProp).toEqual({
|
|
58
|
+
cachedMatch: true,
|
|
59
|
+
elMatch: true,
|
|
60
|
+
stateMatch: true,
|
|
61
|
+
contextMatch: true
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it("should return an empty changes object", async () => {
|
|
65
|
+
element.define.testProp = () => "updated value";
|
|
66
|
+
const changes = await throughUpdatedDefine(element);
|
|
67
|
+
expect(changes).toEqual({});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { throughUpdatedExec } from "../iterate";
|
|
2
|
+
describe("throughUpdatedExec", () => {
|
|
3
|
+
let element, ref;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
ref = {
|
|
6
|
+
__exec: {},
|
|
7
|
+
__defineCache: {}
|
|
8
|
+
};
|
|
9
|
+
element = {
|
|
10
|
+
__ref: ref,
|
|
11
|
+
state: { testState: true },
|
|
12
|
+
context: { testContext: true }
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
it("should skip execution for params in __defineCache", () => {
|
|
16
|
+
ref.__defineCache.cachedParam = true;
|
|
17
|
+
ref.__exec.cachedParam = () => "should not execute";
|
|
18
|
+
element.cachedParam = "original";
|
|
19
|
+
const changes = throughUpdatedExec(element);
|
|
20
|
+
expect(element.cachedParam).toBe("original");
|
|
21
|
+
expect(changes).toEqual({});
|
|
22
|
+
});
|
|
23
|
+
it("should update element properties when newExec differs from current value", () => {
|
|
24
|
+
ref.__exec.testParam = () => "new value";
|
|
25
|
+
element.testParam = "old value";
|
|
26
|
+
const changes = throughUpdatedExec(element);
|
|
27
|
+
expect(element.testParam).toBe("new value");
|
|
28
|
+
expect(changes).toEqual({ testParam: "old value" });
|
|
29
|
+
});
|
|
30
|
+
it("should overwrite text property for nodes when exec returns string or number", () => {
|
|
31
|
+
const node = { node: true, text: "old text" };
|
|
32
|
+
ref.__exec.testParam = () => "new text";
|
|
33
|
+
element.testParam = node;
|
|
34
|
+
const changes = throughUpdatedExec(element);
|
|
35
|
+
expect(element.testParam.text).toBe("new text");
|
|
36
|
+
expect(changes).toEqual({});
|
|
37
|
+
});
|
|
38
|
+
it("should handle component naming matches and overwrite with context component", () => {
|
|
39
|
+
const contextComponent = { extends: "Component", prop: "value" };
|
|
40
|
+
element.context.components = { TestComponent: contextComponent };
|
|
41
|
+
ref.__exec.TestComponent = () => contextComponent;
|
|
42
|
+
element.TestComponent = { oldProp: "oldValue" };
|
|
43
|
+
const changes = throughUpdatedExec(element);
|
|
44
|
+
expect(element.TestComponent).toEqual({
|
|
45
|
+
oldProp: "oldValue",
|
|
46
|
+
prop: "value"
|
|
47
|
+
});
|
|
48
|
+
expect(changes).toEqual({});
|
|
49
|
+
});
|
|
50
|
+
it("should not update element properties when newExec matches current value", () => {
|
|
51
|
+
ref.__exec.testParam = () => "same value";
|
|
52
|
+
element.testParam = "same value";
|
|
53
|
+
const changes = throughUpdatedExec(element);
|
|
54
|
+
expect(element.testParam).toBe("same value");
|
|
55
|
+
expect(changes).toEqual({});
|
|
56
|
+
});
|
|
57
|
+
it("should handle non-string/non-number exec returns for non-node properties", () => {
|
|
58
|
+
const newValue = { complex: "object" };
|
|
59
|
+
ref.__exec.testParam = () => newValue;
|
|
60
|
+
element.testParam = "old value";
|
|
61
|
+
const changes = throughUpdatedExec(element);
|
|
62
|
+
expect(element.testParam).toBe(newValue);
|
|
63
|
+
expect(changes).toEqual({ testParam: "old value" });
|
|
64
|
+
});
|
|
65
|
+
it("should return an empty changes object when no updates occur", () => {
|
|
66
|
+
ref.__exec.testParam = () => "same value";
|
|
67
|
+
element.testParam = "same value";
|
|
68
|
+
const changes = throughUpdatedExec(element);
|
|
69
|
+
expect(changes).toEqual({});
|
|
70
|
+
});
|
|
71
|
+
it("should handle multiple properties and return correct changes", () => {
|
|
72
|
+
ref.__exec.param1 = () => "new value 1";
|
|
73
|
+
ref.__exec.param2 = () => "new value 2";
|
|
74
|
+
element.param1 = "old value 1";
|
|
75
|
+
element.param2 = "old value 2";
|
|
76
|
+
const changes = throughUpdatedExec(element);
|
|
77
|
+
expect(element.param1).toBe("new value 1");
|
|
78
|
+
expect(element.param2).toBe("new value 2");
|
|
79
|
+
expect(changes).toEqual({
|
|
80
|
+
param1: "old value 1",
|
|
81
|
+
param2: "old value 2"
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ROOT, TREE } from "../tree";
|
|
2
|
+
describe("ROOT/TREE initialization and report()", () => {
|
|
3
|
+
it("initializes ROOT with :root key and document.body node", () => {
|
|
4
|
+
expect(ROOT.key).toBe(":root");
|
|
5
|
+
expect(ROOT.node).toBe(document.body);
|
|
6
|
+
});
|
|
7
|
+
it("assigns TREE to reference ROOT", () => {
|
|
8
|
+
expect(TREE).toBe(ROOT);
|
|
9
|
+
expect(TREE.node).toBe(document.body);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { update } from "../update";
|
|
2
|
+
describe("update()", () => {
|
|
3
|
+
let element, params, opts;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
element = {
|
|
6
|
+
__ref: {
|
|
7
|
+
__if: true,
|
|
8
|
+
__execProps: {},
|
|
9
|
+
__exec: {},
|
|
10
|
+
__defineCache: {},
|
|
11
|
+
__propsStack: [],
|
|
12
|
+
__props: [],
|
|
13
|
+
__state: "state"
|
|
14
|
+
},
|
|
15
|
+
state: "string",
|
|
16
|
+
props: {},
|
|
17
|
+
parent: {
|
|
18
|
+
props: {}
|
|
19
|
+
},
|
|
20
|
+
context: {},
|
|
21
|
+
define: {},
|
|
22
|
+
node: document.createElement("div"),
|
|
23
|
+
key: "testElement",
|
|
24
|
+
on: {},
|
|
25
|
+
update
|
|
26
|
+
};
|
|
27
|
+
opts = {
|
|
28
|
+
preventUpdate: [],
|
|
29
|
+
preventDefineUpdate: [],
|
|
30
|
+
preventBeforeStateUpdateListener: false,
|
|
31
|
+
preventListeners: false,
|
|
32
|
+
preventStateUpdateListener: false
|
|
33
|
+
};
|
|
34
|
+
params = {};
|
|
35
|
+
});
|
|
36
|
+
it("does not modify opts when params and opts are empty", async () => {
|
|
37
|
+
await element.update({}, opts);
|
|
38
|
+
expect(opts).toEqual({
|
|
39
|
+
calleeElement: false,
|
|
40
|
+
cleanExec: true,
|
|
41
|
+
currentSnapshot: false,
|
|
42
|
+
exclude: [],
|
|
43
|
+
preventRecursive: false,
|
|
44
|
+
stackChanges: false,
|
|
45
|
+
preventUpdate: [],
|
|
46
|
+
preventDefineUpdate: [],
|
|
47
|
+
preventBeforeStateUpdateListener: false,
|
|
48
|
+
preventListeners: false,
|
|
49
|
+
preventStateUpdateListener: false
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("initializes options with UPDATE_DEFAULT_OPTIONS when opts is empty", async () => {
|
|
53
|
+
await element.update({}, opts);
|
|
54
|
+
expect(opts.calleeElement).toBe(false);
|
|
55
|
+
expect(element.__ref).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
it("merges opts with UPDATE_DEFAULT_OPTIONS using deepMerge", async () => {
|
|
58
|
+
opts.customOption = true;
|
|
59
|
+
await element.update({}, opts);
|
|
60
|
+
expect(opts.customOption).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
it("converts string params to { text: params }", async () => {
|
|
63
|
+
await element.update("testString", opts);
|
|
64
|
+
expect(element.text).toBe("testString");
|
|
65
|
+
});
|
|
66
|
+
it("converts number params to { text: params }", async () => {
|
|
67
|
+
await element.update(123, opts);
|
|
68
|
+
expect(element.text).toBe(123);
|
|
69
|
+
});
|
|
70
|
+
it("returns early if preventInheritAtCurrentState matches element", async () => {
|
|
71
|
+
opts.preventInheritAtCurrentState = { __element: element };
|
|
72
|
+
await element.update({}, opts);
|
|
73
|
+
expect(element.__ref.__currentSnapshot).toBe(6);
|
|
74
|
+
});
|
|
75
|
+
it("initializes __ref if not present", async () => {
|
|
76
|
+
delete element.__ref;
|
|
77
|
+
await element.update({}, opts);
|
|
78
|
+
expect(element.__ref).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
it("merges options with UPDATE_DEFAULT_OPTIONS when exclude is missing", async () => {
|
|
81
|
+
await element.update({}, opts);
|
|
82
|
+
expect(opts.exclude).toBeDefined();
|
|
83
|
+
});
|
|
84
|
+
it("does not throw or modify opts when params is undefined", async () => {
|
|
85
|
+
await element.update(void 0, opts);
|
|
86
|
+
expect(opts).toEqual({
|
|
87
|
+
calleeElement: false,
|
|
88
|
+
cleanExec: true,
|
|
89
|
+
currentSnapshot: false,
|
|
90
|
+
exclude: [],
|
|
91
|
+
preventRecursive: false,
|
|
92
|
+
preventUpdate: [],
|
|
93
|
+
preventDefineUpdate: [],
|
|
94
|
+
stackChanges: false,
|
|
95
|
+
preventBeforeStateUpdateListener: false,
|
|
96
|
+
preventListeners: false,
|
|
97
|
+
preventStateUpdateListener: false
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it("does not throw when opts is undefined", async () => {
|
|
101
|
+
await element.update({}, void 0);
|
|
102
|
+
expect(element.__ref).toBeDefined();
|
|
103
|
+
});
|
|
104
|
+
it("does not throw when opts is null", async () => {
|
|
105
|
+
await element.update({}, null);
|
|
106
|
+
expect(element.__ref).toBeDefined();
|
|
107
|
+
});
|
|
108
|
+
it("does not modify the params object", async () => {
|
|
109
|
+
params = { key: "value" };
|
|
110
|
+
await element.update(params, opts);
|
|
111
|
+
expect(params).toEqual({ key: "value" });
|
|
112
|
+
});
|
|
113
|
+
it("does modify opts when params is an empty object", async () => {
|
|
114
|
+
await element.update({}, opts);
|
|
115
|
+
expect(opts).toEqual({
|
|
116
|
+
calleeElement: false,
|
|
117
|
+
cleanExec: true,
|
|
118
|
+
currentSnapshot: false,
|
|
119
|
+
exclude: [],
|
|
120
|
+
preventRecursive: false,
|
|
121
|
+
stackChanges: false,
|
|
122
|
+
preventUpdate: [],
|
|
123
|
+
preventDefineUpdate: [],
|
|
124
|
+
preventBeforeStateUpdateListener: false,
|
|
125
|
+
preventListeners: false,
|
|
126
|
+
preventStateUpdateListener: false
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it("moves regular properties to element.props", async () => {
|
|
130
|
+
params = { props: { title: "Test", description: "Content" } };
|
|
131
|
+
await element.update(params, opts);
|
|
132
|
+
expect(element.props).toEqual({
|
|
133
|
+
title: "Test",
|
|
134
|
+
description: "Content"
|
|
135
|
+
});
|
|
136
|
+
expect(element.title).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
it("keeps element-rooted properties", async () => {
|
|
139
|
+
params = { Header: {}, Footer: {}, 0: "index" };
|
|
140
|
+
await element.update(params, opts);
|
|
141
|
+
expect(element.Header).toBeDefined();
|
|
142
|
+
expect(element.Footer).toBeDefined();
|
|
143
|
+
expect(element["0"]).toBe("index");
|
|
144
|
+
expect(element.props).toEqual({});
|
|
145
|
+
});
|
|
146
|
+
it("preserves built-in properties on element", async () => {
|
|
147
|
+
params = { props: { className: "container", hidden: true } };
|
|
148
|
+
await element.update(params, opts);
|
|
149
|
+
expect(element.props.className).toBe("container");
|
|
150
|
+
expect(element.props.hidden).toBe(true);
|
|
151
|
+
expect(element.props).toEqual({ className: "container", hidden: true });
|
|
152
|
+
});
|
|
153
|
+
it("moves element-like properties from props to root", async () => {
|
|
154
|
+
params = { props: { Header: {} } };
|
|
155
|
+
await element.update(params, opts);
|
|
156
|
+
expect(element.Header).toBeDefined();
|
|
157
|
+
expect(element.props.Header).toBeUndefined();
|
|
158
|
+
});
|
|
159
|
+
it("exits early when inheritStateUpdates returns false", async () => {
|
|
160
|
+
element.__ref.__stateBlocked = true;
|
|
161
|
+
await element.update({ props: { shouldChange: true } }, opts);
|
|
162
|
+
expect(element.props.shouldChange).toBe(true);
|
|
163
|
+
expect(element.__ref.__stateBlocked).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
it("exits early when checkIfOnUpdate fails", async () => {
|
|
166
|
+
element.parent.props.ifCondition = false;
|
|
167
|
+
await element.update({ state: { newState: true } }, opts);
|
|
168
|
+
expect(element.state.newState).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
it("updates props from parent key match", async () => {
|
|
171
|
+
element.parent.props.testKey = { inherited: true };
|
|
172
|
+
await element.update({}, opts);
|
|
173
|
+
expect(element.props.inherited).toBeUndefined();
|
|
174
|
+
});
|
|
175
|
+
it("updates props when functions exist in __props", async () => {
|
|
176
|
+
element.__ref.__props.push(() => "dynamic");
|
|
177
|
+
await element.update({}, opts);
|
|
178
|
+
expect(element.props).toEqual(expect.any(Object));
|
|
179
|
+
});
|
|
180
|
+
it("skips props update when preventPropsUpdate=true", async () => {
|
|
181
|
+
opts.preventPropsUpdate = true;
|
|
182
|
+
opts.preventUpdateAfter = true;
|
|
183
|
+
element.parent.props.testKey = { shouldExist: true };
|
|
184
|
+
await element.update({}, opts);
|
|
185
|
+
expect(element.props.shouldExist).toBeUndefined();
|
|
186
|
+
});
|
|
187
|
+
it("should not skips props update when preventPropsUpdate=false", async () => {
|
|
188
|
+
opts.preventPropsUpdate = false;
|
|
189
|
+
opts.lazyLoad = true;
|
|
190
|
+
opts.onEachUpdate = () => {
|
|
191
|
+
return true;
|
|
192
|
+
};
|
|
193
|
+
element.parent.props.testKey = { shouldExist: true };
|
|
194
|
+
element.__ref.__propsStack = [];
|
|
195
|
+
element.__ref.__if = true;
|
|
196
|
+
element.off = { text: "off" };
|
|
197
|
+
await element.update({}, opts);
|
|
198
|
+
expect(element.props.shouldExist).toBeUndefined();
|
|
199
|
+
});
|
|
200
|
+
it("should set preventUpdateAfterCount to 1 when is not a number", async () => {
|
|
201
|
+
opts.preventPropsUpdate = true;
|
|
202
|
+
opts.preventUpdateAfter = 2;
|
|
203
|
+
opts.preventUpdateAfterCount = void 0;
|
|
204
|
+
element.parent.props.testKey = { shouldExist: true };
|
|
205
|
+
await element.update({}, opts);
|
|
206
|
+
expect(element.props.shouldExist).toBeUndefined();
|
|
207
|
+
});
|
|
208
|
+
it("processes parent.childProps", async () => {
|
|
209
|
+
element.parent.props.childProps = { global: true };
|
|
210
|
+
await element.update({}, opts);
|
|
211
|
+
expect(element.props.global).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
it("processes function props", async () => {
|
|
214
|
+
await element.update({ props: { calc: () => 42 } }, opts);
|
|
215
|
+
expect(element.props.calc()).toBe(42);
|
|
216
|
+
});
|
|
217
|
+
it("returns element when beforeUpdate rejects", async () => {
|
|
218
|
+
element.on.beforeUpdate = () => false;
|
|
219
|
+
const result = await element.update({}, opts);
|
|
220
|
+
expect(result).toBe(element);
|
|
221
|
+
});
|
|
222
|
+
});
|
package/dist/esm/create.js
CHANGED
|
@@ -30,7 +30,7 @@ const create = async (props, parentEl, passedKey, options = OPTIONS.create || {}
|
|
|
30
30
|
const { key, parent, __ref: ref } = element;
|
|
31
31
|
createRoot(element, parent);
|
|
32
32
|
applyExtends(element, parent, options);
|
|
33
|
-
propertizeElement(element,
|
|
33
|
+
propertizeElement.call(element, element);
|
|
34
34
|
await triggerEventOn("start", element, options);
|
|
35
35
|
if (options.onlyResolveExtends) {
|
|
36
36
|
return onlyResolveExtends(element, parent, key, options);
|
|
@@ -77,7 +77,7 @@ const addElementIntoParentChildren = (element, parent) => {
|
|
|
77
77
|
};
|
|
78
78
|
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
79
79
|
const renderElement = async (element, parent, options, attachOptions) => {
|
|
80
|
-
var _a, _b, _c
|
|
80
|
+
var _a, _b, _c;
|
|
81
81
|
if (visitedElements.has(element)) {
|
|
82
82
|
if (ENV === "test" || ENV === "development") {
|
|
83
83
|
console.warn("Cyclic rendering detected:", element.__ref.path);
|
|
@@ -114,15 +114,6 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
114
114
|
if ((_c = element.on) == null ? void 0 : _c.error) {
|
|
115
115
|
element.on.error(e, element, element.state, element.context, options);
|
|
116
116
|
}
|
|
117
|
-
if ((_d = element.props) == null ? void 0 : _d.onError) {
|
|
118
|
-
element.props.onError(
|
|
119
|
-
e,
|
|
120
|
-
element,
|
|
121
|
-
element.state,
|
|
122
|
-
element.context,
|
|
123
|
-
options
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
117
|
}
|
|
127
118
|
}
|
|
128
119
|
if (!ref.__if) {
|
package/dist/esm/iterate.js
CHANGED
|
@@ -7,16 +7,17 @@ import {
|
|
|
7
7
|
matchesComponentNaming,
|
|
8
8
|
isContextComponent,
|
|
9
9
|
isMethod,
|
|
10
|
-
overwrite
|
|
10
|
+
overwrite,
|
|
11
|
+
execPromise
|
|
11
12
|
} from "@domql/utils";
|
|
12
|
-
const throughInitialExec = (element, exclude = {}) => {
|
|
13
|
+
const throughInitialExec = async (element, exclude = {}) => {
|
|
13
14
|
const { __ref: ref } = element;
|
|
14
15
|
for (const param in element) {
|
|
15
16
|
if (exclude[param]) continue;
|
|
16
17
|
const prop = element[param];
|
|
17
18
|
if (isFunction(prop) && !isMethod(param, element)) {
|
|
18
19
|
ref.__exec[param] = prop;
|
|
19
|
-
element[param] = prop(element, element.state, element.context);
|
|
20
|
+
element[param] = await prop(element, element.state, element.context);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
};
|
|
@@ -47,23 +48,23 @@ const throughUpdatedExec = (element, options = {}) => {
|
|
|
47
48
|
}
|
|
48
49
|
return changes;
|
|
49
50
|
};
|
|
50
|
-
const throughExecProps = (element) => {
|
|
51
|
+
const throughExecProps = async (element) => {
|
|
51
52
|
const { __ref: ref } = element;
|
|
52
53
|
const { props } = element;
|
|
53
54
|
for (const k in props) {
|
|
54
55
|
const isDefine = k.startsWith("is") || k.startsWith("has") || k.startsWith("use");
|
|
55
56
|
const cachedExecProp = ref.__execProps[k];
|
|
56
57
|
if (isFunction(cachedExecProp)) {
|
|
57
|
-
props[k] =
|
|
58
|
+
props[k] = await execPromise(cachedExecProp, element);
|
|
58
59
|
} else if (isDefine && isFunction(props[k])) {
|
|
59
60
|
ref.__execProps[k] = props[k];
|
|
60
|
-
props[k] =
|
|
61
|
+
props[k] = await execPromise(props[k], element);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
};
|
|
64
65
|
const isPropertyInDefines = (key, element) => {
|
|
65
66
|
};
|
|
66
|
-
const throughInitialDefine = (element) => {
|
|
67
|
+
const throughInitialDefine = async (element) => {
|
|
67
68
|
const { define, context, __ref: ref } = element;
|
|
68
69
|
let defineObj = {};
|
|
69
70
|
const hasGlobalDefine = context && isObject(context.define);
|
|
@@ -73,13 +74,13 @@ const throughInitialDefine = (element) => {
|
|
|
73
74
|
let elementProp = element[param];
|
|
74
75
|
if (isFunction(elementProp) && !isMethod(param, element)) {
|
|
75
76
|
ref.__exec[param] = elementProp;
|
|
76
|
-
const execParam2 = elementProp =
|
|
77
|
+
const execParam2 = elementProp = await execPromise(elementProp, element);
|
|
77
78
|
if (execParam2) {
|
|
78
79
|
elementProp = element[param] = execParam2.parse ? execParam2.parse() : execParam2;
|
|
79
80
|
ref.__defineCache[param] = elementProp;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
const execParam = defineObj[param](
|
|
83
|
+
const execParam = await defineObj[param](
|
|
83
84
|
elementProp,
|
|
84
85
|
element,
|
|
85
86
|
element.state,
|
|
@@ -89,7 +90,7 @@ const throughInitialDefine = (element) => {
|
|
|
89
90
|
}
|
|
90
91
|
return element;
|
|
91
92
|
};
|
|
92
|
-
const throughUpdatedDefine = (element) => {
|
|
93
|
+
const throughUpdatedDefine = async (element) => {
|
|
93
94
|
const { context, define, __ref: ref } = element;
|
|
94
95
|
const changes = {};
|
|
95
96
|
let obj = {};
|
|
@@ -98,13 +99,13 @@ const throughUpdatedDefine = (element) => {
|
|
|
98
99
|
for (const param in obj) {
|
|
99
100
|
const execParam = ref.__exec[param];
|
|
100
101
|
if (execParam) {
|
|
101
|
-
ref.__defineCache[param] = execParam(
|
|
102
|
+
ref.__defineCache[param] = await execParam(
|
|
102
103
|
element,
|
|
103
104
|
element.state,
|
|
104
105
|
element.context
|
|
105
106
|
);
|
|
106
107
|
}
|
|
107
|
-
const cached =
|
|
108
|
+
const cached = await execPromise(ref.__defineCache[param], element);
|
|
108
109
|
const newExecParam = typeof obj[param] === "function" ? obj[param](cached, element, element.state, element.context) : void 0;
|
|
109
110
|
if (newExecParam) element[param] = newExecParam;
|
|
110
111
|
}
|
package/dist/esm/update.js
CHANGED
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
merge,
|
|
11
11
|
overwriteDeep,
|
|
12
12
|
deepClone,
|
|
13
|
-
propertizeElement,
|
|
14
13
|
isMethod,
|
|
15
14
|
findInheritedState,
|
|
16
15
|
deepMerge,
|
|
17
16
|
OPTIONS,
|
|
18
17
|
updateProps,
|
|
19
|
-
captureSnapshot
|
|
18
|
+
captureSnapshot,
|
|
19
|
+
propertizeUpdate
|
|
20
20
|
} from "@domql/utils";
|
|
21
21
|
import { applyEvent, triggerEventOn, triggerEventOnUpdate } from "@domql/event";
|
|
22
22
|
import { createState } from "@domql/state";
|
|
@@ -66,7 +66,7 @@ const update = async function(params = {}, opts) {
|
|
|
66
66
|
if (isString(params) || isNumber(params)) {
|
|
67
67
|
params = { text: params };
|
|
68
68
|
}
|
|
69
|
-
params =
|
|
69
|
+
params = propertizeUpdate.call(element, params);
|
|
70
70
|
const inheritState = await inheritStateUpdates(element, options);
|
|
71
71
|
if (inheritState === false) return;
|
|
72
72
|
const ifFails = await checkIfOnUpdate(element, parent, options);
|
|
@@ -78,10 +78,11 @@ const update = async function(params = {}, opts) {
|
|
|
78
78
|
if (props) updateProps(props, element, parent);
|
|
79
79
|
}
|
|
80
80
|
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
81
|
+
const simulate = { ...params, ...element };
|
|
81
82
|
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
82
83
|
"beforeUpdate",
|
|
83
84
|
params,
|
|
84
|
-
|
|
85
|
+
simulate,
|
|
85
86
|
options
|
|
86
87
|
);
|
|
87
88
|
if (beforeUpdateReturns === false) return element;
|
package/iterate.js
CHANGED
|
@@ -9,17 +9,18 @@ import {
|
|
|
9
9
|
matchesComponentNaming,
|
|
10
10
|
isContextComponent,
|
|
11
11
|
isMethod,
|
|
12
|
-
overwrite
|
|
12
|
+
overwrite,
|
|
13
|
+
execPromise
|
|
13
14
|
} from '@domql/utils'
|
|
14
15
|
|
|
15
|
-
export const throughInitialExec = (element, exclude = {}) => {
|
|
16
|
+
export const throughInitialExec = async (element, exclude = {}) => {
|
|
16
17
|
const { __ref: ref } = element
|
|
17
18
|
for (const param in element) {
|
|
18
19
|
if (exclude[param]) continue
|
|
19
20
|
const prop = element[param]
|
|
20
21
|
if (isFunction(prop) && !isMethod(param, element)) {
|
|
21
22
|
ref.__exec[param] = prop
|
|
22
|
-
element[param] = prop(element, element.state, element.context)
|
|
23
|
+
element[param] = await prop(element, element.state, element.context)
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -57,7 +58,7 @@ export const throughUpdatedExec = (element, options = {}) => {
|
|
|
57
58
|
return changes
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
export const throughExecProps = element => {
|
|
61
|
+
export const throughExecProps = async element => {
|
|
61
62
|
const { __ref: ref } = element
|
|
62
63
|
const { props } = element
|
|
63
64
|
for (const k in props) {
|
|
@@ -65,17 +66,17 @@ export const throughExecProps = element => {
|
|
|
65
66
|
k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
|
|
66
67
|
const cachedExecProp = ref.__execProps[k]
|
|
67
68
|
if (isFunction(cachedExecProp)) {
|
|
68
|
-
props[k] =
|
|
69
|
+
props[k] = await execPromise(cachedExecProp, element)
|
|
69
70
|
} else if (isDefine && isFunction(props[k])) {
|
|
70
71
|
ref.__execProps[k] = props[k]
|
|
71
|
-
props[k] =
|
|
72
|
+
props[k] = await execPromise(props[k], element)
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
export const isPropertyInDefines = (key, element) => {}
|
|
77
78
|
|
|
78
|
-
export const throughInitialDefine = element => {
|
|
79
|
+
export const throughInitialDefine = async element => {
|
|
79
80
|
const { define, context, __ref: ref } = element
|
|
80
81
|
|
|
81
82
|
let defineObj = {}
|
|
@@ -88,7 +89,7 @@ export const throughInitialDefine = element => {
|
|
|
88
89
|
|
|
89
90
|
if (isFunction(elementProp) && !isMethod(param, element)) {
|
|
90
91
|
ref.__exec[param] = elementProp
|
|
91
|
-
const execParam = (elementProp =
|
|
92
|
+
const execParam = (elementProp = await execPromise(elementProp, element))
|
|
92
93
|
|
|
93
94
|
if (execParam) {
|
|
94
95
|
elementProp = element[param] = execParam.parse
|
|
@@ -98,7 +99,7 @@ export const throughInitialDefine = element => {
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
const execParam = defineObj[param](
|
|
102
|
+
const execParam = await defineObj[param](
|
|
102
103
|
elementProp,
|
|
103
104
|
element,
|
|
104
105
|
element.state,
|
|
@@ -109,7 +110,7 @@ export const throughInitialDefine = element => {
|
|
|
109
110
|
return element
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
export const throughUpdatedDefine = element => {
|
|
113
|
+
export const throughUpdatedDefine = async element => {
|
|
113
114
|
const { context, define, __ref: ref } = element
|
|
114
115
|
const changes = {}
|
|
115
116
|
|
|
@@ -120,13 +121,13 @@ export const throughUpdatedDefine = element => {
|
|
|
120
121
|
for (const param in obj) {
|
|
121
122
|
const execParam = ref.__exec[param]
|
|
122
123
|
if (execParam) {
|
|
123
|
-
ref.__defineCache[param] = execParam(
|
|
124
|
+
ref.__defineCache[param] = await execParam(
|
|
124
125
|
element,
|
|
125
126
|
element.state,
|
|
126
127
|
element.context
|
|
127
128
|
)
|
|
128
129
|
}
|
|
129
|
-
const cached =
|
|
130
|
+
const cached = await execPromise(ref.__defineCache[param], element)
|
|
130
131
|
const newExecParam =
|
|
131
132
|
typeof obj[param] === 'function'
|
|
132
133
|
? obj[param](cached, element, element.state, element.context)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,20 +21,19 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
24
|
-
"build:esm": "npx esbuild
|
|
25
|
-
"build:cjs": "npx esbuild
|
|
26
|
-
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
27
|
-
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
24
|
+
"build:esm": "npx esbuild *.js **/*.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
+
"build:cjs": "npx esbuild *.js **/*.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
26
|
+
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
27
|
+
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^3.
|
|
31
|
-
"@domql/render": "^3.
|
|
32
|
-
"@domql/
|
|
33
|
-
"@domql/
|
|
34
|
-
"@domql/utils": "^3.0.7"
|
|
30
|
+
"@domql/event": "^3.1.2",
|
|
31
|
+
"@domql/render": "^3.1.2",
|
|
32
|
+
"@domql/state": "^3.1.2",
|
|
33
|
+
"@domql/utils": "^3.1.2"
|
|
35
34
|
},
|
|
36
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "429b36616aa04c8587a26ce3c129815115e35897",
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "^7.
|
|
37
|
+
"@babel/core": "^7.26.0"
|
|
39
38
|
}
|
|
40
39
|
}
|