@domql/element 2.5.200 → 3.0.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.
- package/README.md +1 -1
- package/__tests__/checkIfOnUpdate.test.js +103 -0
- package/__tests__/children.test.js +213 -0
- package/__tests__/define.test.js +75 -0
- package/__tests__/inheritStateUpdates.test.js +79 -0
- package/__tests__/renderElement.test.js +131 -0
- package/__tests__/resetElement.test.js +44 -0
- package/__tests__/set.test.js +316 -0
- package/__tests__/throughExecProps.test.js +86 -0
- package/__tests__/throughInitialDefine.test.js +104 -0
- package/__tests__/throughInitialExec.test.js +92 -0
- package/__tests__/throughUpdatedDefine.test.js +92 -0
- package/__tests__/throughUpdatedExec.test.js +110 -0
- package/__tests__/tree.test.js +15 -0
- package/__tests__/update.test.js +253 -0
- package/children.js +105 -0
- package/create.js +125 -252
- 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 +219 -0
- package/dist/cjs/children.js +87 -0
- package/dist/cjs/create.js +79 -177
- package/dist/cjs/iterate.js +29 -13
- package/dist/cjs/methods/set.js +27 -25
- package/dist/cjs/methods/v2.js +1 -5
- package/dist/cjs/mixins/attr.js +7 -6
- package/dist/cjs/mixins/index.js +0 -4
- package/dist/cjs/mixins/registry.js +7 -67
- package/dist/cjs/mixins/scope.js +1 -1
- package/dist/cjs/mixins/state.js +3 -4
- package/dist/cjs/mixins/text.js +3 -3
- package/dist/cjs/node.js +32 -22
- package/dist/cjs/set.js +112 -40
- package/dist/cjs/update.js +119 -64
- package/dist/cjs/utils/applyParam.js +2 -2
- package/dist/cjs/utils/index.js +8 -4
- package/dist/cjs/utils/onlyResolveExtends.js +4 -7
- 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 +219 -0
- package/dist/esm/children.js +81 -0
- package/dist/esm/create.js +85 -188
- package/dist/esm/iterate.js +33 -16
- package/dist/esm/methods/set.js +6 -4
- package/dist/esm/methods/v2.js +1 -5
- package/dist/esm/mixins/attr.js +8 -7
- package/dist/esm/mixins/data.js +1 -1
- package/dist/esm/mixins/index.js +0 -4
- package/dist/esm/mixins/registry.js +7 -67
- package/dist/esm/mixins/scope.js +1 -1
- package/dist/esm/mixins/state.js +4 -5
- package/dist/esm/mixins/text.js +4 -7
- package/dist/esm/node.js +23 -23
- package/dist/esm/set.js +112 -40
- package/dist/esm/update.js +122 -68
- package/dist/esm/utils/applyParam.js +2 -2
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/onlyResolveExtends.js +12 -8
- package/iterate.js +44 -26
- package/methods/set.js +5 -4
- package/methods/v2.js +5 -4
- package/mixins/attr.js +13 -7
- package/mixins/classList.js +7 -2
- package/mixins/data.js +1 -1
- package/mixins/index.js +1 -6
- package/mixins/registry.js +6 -53
- package/mixins/scope.js +1 -1
- package/mixins/state.js +4 -5
- package/mixins/text.js +4 -7
- package/node.js +31 -28
- package/package.json +7 -6
- package/set.js +129 -41
- package/update.js +169 -89
- package/utils/applyParam.js +7 -4
- package/utils/index.js +1 -3
- package/utils/onlyResolveExtends.js +27 -16
- package/cache/index.js +0 -3
- package/cache/options.js +0 -4
- package/dist/cjs/cache/index.js +0 -24
- package/dist/cjs/cache/options.js +0 -26
- package/dist/cjs/extend.js +0 -81
- package/dist/cjs/methods/index.js +0 -320
- package/dist/cjs/mixins/content.js +0 -67
- package/dist/cjs/props/create.js +0 -92
- package/dist/cjs/props/ignore.js +0 -24
- package/dist/cjs/props/index.js +0 -21
- package/dist/cjs/props/inherit.js +0 -51
- package/dist/cjs/props/update.js +0 -34
- package/dist/cjs/utils/component.js +0 -74
- package/dist/cjs/utils/extendUtils.js +0 -133
- package/dist/cjs/utils/object.js +0 -171
- package/dist/cjs/utils/propEvents.js +0 -39
- package/dist/esm/cache/index.js +0 -4
- package/dist/esm/cache/options.js +0 -6
- package/dist/esm/extend.js +0 -67
- package/dist/esm/methods/index.js +0 -300
- package/dist/esm/mixins/content.js +0 -47
- package/dist/esm/props/create.js +0 -72
- package/dist/esm/props/ignore.js +0 -4
- package/dist/esm/props/index.js +0 -4
- package/dist/esm/props/inherit.js +0 -31
- package/dist/esm/props/update.js +0 -14
- package/dist/esm/utils/component.js +0 -62
- package/dist/esm/utils/extendUtils.js +0 -113
- package/dist/esm/utils/object.js +0 -151
- package/dist/esm/utils/propEvents.js +0 -19
- package/extend.js +0 -90
- package/methods/index.js +0 -317
- package/mixins/content.js +0 -55
- package/props/create.js +0 -87
- package/props/ignore.js +0 -3
- package/props/index.js +0 -6
- package/props/inherit.js +0 -35
- package/props/update.js +0 -17
- package/utils/component.js +0 -68
- package/utils/extendUtils.js +0 -134
- package/utils/object.js +0 -172
- package/utils/propEvents.js +0 -19
package/dist/esm/update.js
CHANGED
|
@@ -8,69 +8,90 @@ import {
|
|
|
8
8
|
isString,
|
|
9
9
|
isUndefined,
|
|
10
10
|
merge,
|
|
11
|
-
isVariant,
|
|
12
11
|
overwriteDeep,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
deepClone,
|
|
13
|
+
propertizeElement,
|
|
14
|
+
isMethod,
|
|
15
|
+
findInheritedState,
|
|
16
|
+
deepMerge,
|
|
17
|
+
OPTIONS,
|
|
18
|
+
updateProps,
|
|
19
|
+
captureSnapshot
|
|
15
20
|
} from "@domql/utils";
|
|
16
21
|
import { applyEvent, triggerEventOn, triggerEventOnUpdate } from "@domql/event";
|
|
17
|
-
import {
|
|
18
|
-
import { updateProps } from "./props/index.js";
|
|
19
|
-
import { createState, findInheritedState } from "@domql/state";
|
|
22
|
+
import { createState } from "@domql/state";
|
|
20
23
|
import { create } from "./create.js";
|
|
21
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
throughExecProps,
|
|
26
|
+
throughUpdatedDefine,
|
|
27
|
+
throughUpdatedExec
|
|
28
|
+
} from "./iterate.js";
|
|
22
29
|
import { REGISTRY } from "./mixins/index.js";
|
|
23
30
|
import { applyParam } from "./utils/applyParam.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
snapshotId: createSnapshotId
|
|
28
|
-
};
|
|
31
|
+
import { METHODS_EXL } from "./utils/index.js";
|
|
32
|
+
import { setContent } from "./set.js";
|
|
33
|
+
import setChildren from "./children.js";
|
|
29
34
|
const UPDATE_DEFAULT_OPTIONS = {
|
|
30
35
|
stackChanges: false,
|
|
31
36
|
cleanExec: true,
|
|
32
37
|
preventRecursive: false,
|
|
33
38
|
currentSnapshot: false,
|
|
34
39
|
calleeElement: false,
|
|
35
|
-
|
|
40
|
+
exclude: METHODS_EXL
|
|
36
41
|
};
|
|
37
42
|
const update = async function(params = {}, opts) {
|
|
38
43
|
const calleeElementCache = opts == null ? void 0 : opts.calleeElement;
|
|
39
|
-
const options = deepClone(
|
|
44
|
+
const options = deepClone(
|
|
45
|
+
isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
|
|
46
|
+
{ exclude: ["calleeElement"] }
|
|
47
|
+
);
|
|
40
48
|
options.calleeElement = calleeElementCache;
|
|
41
49
|
const element = this;
|
|
42
|
-
const { parent, node, key } = element;
|
|
43
|
-
const { excludes, preventInheritAtCurrentState } = options;
|
|
44
50
|
let ref = element.__ref;
|
|
45
51
|
if (!ref) ref = element.__ref = {};
|
|
46
|
-
const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
|
|
52
|
+
const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
|
|
53
|
+
element,
|
|
54
|
+
options
|
|
55
|
+
);
|
|
47
56
|
if (snapshotHasUpdated) return;
|
|
48
|
-
if (!options.preventListeners)
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
if (!options.preventListeners) {
|
|
58
|
+
await triggerEventOnUpdate("startUpdate", params, element, options);
|
|
59
|
+
}
|
|
60
|
+
const { parent, node, key } = element;
|
|
61
|
+
const { exclude, preventInheritAtCurrentState } = options;
|
|
62
|
+
if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!exclude) merge(options, UPDATE_DEFAULT_OPTIONS);
|
|
51
66
|
if (isString(params) || isNumber(params)) {
|
|
52
67
|
params = { text: params };
|
|
53
68
|
}
|
|
69
|
+
params = propertizeElement(params);
|
|
54
70
|
const inheritState = await inheritStateUpdates(element, options);
|
|
55
71
|
if (inheritState === false) return;
|
|
56
|
-
const ifFails = checkIfOnUpdate(element, parent, options);
|
|
72
|
+
const ifFails = await checkIfOnUpdate(element, parent, options);
|
|
57
73
|
if (ifFails) return;
|
|
58
74
|
if (ref.__if && !options.preventPropsUpdate) {
|
|
59
75
|
const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
|
|
60
|
-
const hasFunctionInProps = ref.
|
|
76
|
+
const hasFunctionInProps = ref.__propsStack.filter((v) => isFunction(v));
|
|
61
77
|
const props = params.props || hasParentProps || hasFunctionInProps.length;
|
|
62
78
|
if (props) updateProps(props, element, parent);
|
|
63
79
|
}
|
|
64
80
|
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
65
|
-
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
81
|
+
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
82
|
+
"beforeUpdate",
|
|
83
|
+
params,
|
|
84
|
+
element,
|
|
85
|
+
options
|
|
86
|
+
);
|
|
66
87
|
if (beforeUpdateReturns === false) return element;
|
|
67
88
|
}
|
|
68
|
-
overwriteDeep(element, params
|
|
89
|
+
overwriteDeep(element, params);
|
|
69
90
|
throughExecProps(element);
|
|
70
91
|
throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS });
|
|
71
92
|
throughUpdatedDefine(element);
|
|
72
93
|
if (!options.isForced && !options.preventListeners) {
|
|
73
|
-
triggerEventOn("beforeClassAssign", element, options);
|
|
94
|
+
await triggerEventOn("beforeClassAssign", element, options);
|
|
74
95
|
}
|
|
75
96
|
if (!ref.__if) return false;
|
|
76
97
|
if (!node) {
|
|
@@ -87,19 +108,22 @@ const update = async function(params = {}, opts) {
|
|
|
87
108
|
preventUpdateAfterCount
|
|
88
109
|
} = options;
|
|
89
110
|
if (preventUpdateAfter) {
|
|
90
|
-
if (isNumber(preventUpdateAfterCount) && preventUpdateAfter <= preventUpdateAfterCount)
|
|
91
|
-
|
|
92
|
-
else options.preventUpdateAfterCount
|
|
111
|
+
if (isNumber(preventUpdateAfterCount) && preventUpdateAfter <= preventUpdateAfterCount) {
|
|
112
|
+
return;
|
|
113
|
+
} else if (options.preventUpdateAfterCount === void 0) {
|
|
114
|
+
options.preventUpdateAfterCount = 1;
|
|
115
|
+
} else options.preventUpdateAfterCount++;
|
|
93
116
|
}
|
|
94
117
|
for (const param in element) {
|
|
95
118
|
const prop = element[param];
|
|
96
119
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
97
120
|
const isInPreventUpdate = isArray(preventUpdate) && preventUpdate.includes(param);
|
|
98
121
|
const isInPreventDefineUpdate = isArray(preventDefineUpdate) && preventDefineUpdate.includes(param);
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
if (isUndefined(prop) || isInPreventUpdate || isInPreventDefineUpdate || preventDefineUpdate === true || preventDefineUpdate === param || (preventStateUpdate && param) === "state" || isMethod(param, element) || isObject(REGISTRY[param])) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
101
125
|
if (preventStateUpdate === "once") options.preventStateUpdate = false;
|
|
102
|
-
const isElement = applyParam(param, element, options);
|
|
126
|
+
const isElement = await applyParam(param, element, options);
|
|
103
127
|
if (isElement) {
|
|
104
128
|
const { hasDefine, hasContextDefine } = isElement;
|
|
105
129
|
const canUpdate = isObject(prop) && !hasDefine && !hasContextDefine && !preventRecursive;
|
|
@@ -108,48 +132,51 @@ const update = async function(params = {}, opts) {
|
|
|
108
132
|
if (options.onEachUpdate) {
|
|
109
133
|
options.onEachUpdate(param, element, element.state, element.context);
|
|
110
134
|
}
|
|
111
|
-
const childUpdateCall = () => update.call(prop, params[prop], {
|
|
135
|
+
const childUpdateCall = async () => await update.call(prop, params[prop], {
|
|
112
136
|
...options,
|
|
113
137
|
currentSnapshot: snapshotOnCallee,
|
|
114
138
|
calleeElement
|
|
115
139
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
if (lazyLoad) {
|
|
141
|
+
window.requestAnimationFrame(async () => {
|
|
142
|
+
await childUpdateCall();
|
|
143
|
+
if (!options.preventUpdateListener) {
|
|
144
|
+
await triggerEventOn("lazyLoad", element, options);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
} else await childUpdateCall();
|
|
122
148
|
}
|
|
123
149
|
}
|
|
124
|
-
if (!
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
|
|
136
|
-
if (currentSnapshot < snapshotOnCallee) {
|
|
137
|
-
return [snapshotOnCallee, calleeElement, true];
|
|
138
|
-
}
|
|
139
|
-
return [snapshotOnCallee, calleeElement];
|
|
150
|
+
if (!preventContentUpdate) {
|
|
151
|
+
const children = params.children || element.children;
|
|
152
|
+
const content = children ? await setChildren(children, element, opts) : element.children || params.content;
|
|
153
|
+
if (content) {
|
|
154
|
+
await setContent(content, element, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!preventUpdateListener) {
|
|
158
|
+
await triggerEventOn("update", element, options);
|
|
159
|
+
}
|
|
140
160
|
};
|
|
141
|
-
const checkIfOnUpdate = (element, parent, options) => {
|
|
161
|
+
const checkIfOnUpdate = async (element, parent, options) => {
|
|
142
162
|
var _a, _b, _c;
|
|
143
|
-
if (!isFunction(element.if) && !isFunction((_a = element.props) == null ? void 0 : _a.if) || !parent)
|
|
163
|
+
if (!isFunction(element.if) && !isFunction((_a = element.props) == null ? void 0 : _a.if) || !parent) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
144
166
|
const ref = element.__ref;
|
|
145
|
-
const ifPassed = (element.if || ((_b = element.props) == null ? void 0 : _b.if))(
|
|
167
|
+
const ifPassed = (element.if || ((_b = element.props) == null ? void 0 : _b.if))(
|
|
168
|
+
element,
|
|
169
|
+
element.state,
|
|
170
|
+
element.context,
|
|
171
|
+
options
|
|
172
|
+
);
|
|
146
173
|
const itWasFalse = ref.__if !== true;
|
|
147
174
|
if (ifPassed) {
|
|
148
175
|
ref.__if = true;
|
|
149
176
|
if (itWasFalse) {
|
|
150
177
|
delete element.__hash;
|
|
151
178
|
delete element.__text;
|
|
152
|
-
delete element.
|
|
179
|
+
delete element.extends;
|
|
153
180
|
if (!ref.__hasRootState) {
|
|
154
181
|
delete element.state;
|
|
155
182
|
}
|
|
@@ -163,9 +190,11 @@ const checkIfOnUpdate = (element, parent, options) => {
|
|
|
163
190
|
delete element.node;
|
|
164
191
|
}
|
|
165
192
|
const contentKey = ref.contentElementKey;
|
|
166
|
-
if (element
|
|
193
|
+
if (element.children) {
|
|
167
194
|
element.removeContent();
|
|
168
|
-
} else if ((_c = element[contentKey]) == null ? void 0 : _c.parseDeep)
|
|
195
|
+
} else if ((_c = element[contentKey]) == null ? void 0 : _c.parseDeep) {
|
|
196
|
+
element[contentKey] = element[contentKey].parseDeep();
|
|
197
|
+
}
|
|
169
198
|
const previousElement = element.previousElement();
|
|
170
199
|
const previousNode = previousElement == null ? void 0 : previousElement.node;
|
|
171
200
|
const hasPrevious = previousNode == null ? void 0 : previousNode.parentNode;
|
|
@@ -178,9 +207,19 @@ const checkIfOnUpdate = (element, parent, options) => {
|
|
|
178
207
|
};
|
|
179
208
|
delete element.__ref;
|
|
180
209
|
delete element.parent;
|
|
181
|
-
const createdElement = create(
|
|
210
|
+
const createdElement = await create(
|
|
211
|
+
element,
|
|
212
|
+
parent,
|
|
213
|
+
element.key,
|
|
214
|
+
OPTIONS.create,
|
|
215
|
+
attachOptions
|
|
216
|
+
);
|
|
182
217
|
if (options.preventUpdate !== true && element.on && isFunction(element.on.update)) {
|
|
183
|
-
applyEvent(
|
|
218
|
+
await applyEvent(
|
|
219
|
+
element.on.update,
|
|
220
|
+
createdElement,
|
|
221
|
+
createdElement.state
|
|
222
|
+
);
|
|
184
223
|
}
|
|
185
224
|
return createdElement;
|
|
186
225
|
}
|
|
@@ -202,23 +241,38 @@ const inheritStateUpdates = async (element, options) => {
|
|
|
202
241
|
const shouldForceFunctionState = isFunction(stateKey) && !isHoisted && execStateFunction;
|
|
203
242
|
if (shouldForceFunctionState) {
|
|
204
243
|
const execState = exec(stateKey, element);
|
|
205
|
-
state.set(execState, {
|
|
244
|
+
state.set(execState, {
|
|
245
|
+
...options,
|
|
246
|
+
preventUpdate: true,
|
|
247
|
+
preventStateUpdateListener: false,
|
|
248
|
+
updatedByStateFunction: true
|
|
249
|
+
});
|
|
206
250
|
return;
|
|
207
251
|
}
|
|
208
252
|
const keyInParentState = findInheritedState(element, element.parent);
|
|
209
253
|
if (!keyInParentState || options.preventInheritedStateUpdate) return;
|
|
210
254
|
if (!options.preventBeforeStateUpdateListener && !options.preventListeners) {
|
|
211
|
-
const initStateReturns = await triggerEventOnUpdate(
|
|
255
|
+
const initStateReturns = await triggerEventOnUpdate(
|
|
256
|
+
"beforeStateUpdate",
|
|
257
|
+
keyInParentState,
|
|
258
|
+
element,
|
|
259
|
+
options
|
|
260
|
+
);
|
|
212
261
|
if (initStateReturns === false) return element;
|
|
213
262
|
}
|
|
214
|
-
const newState = createStateUpdate(element, parent, options);
|
|
263
|
+
const newState = await createStateUpdate(element, parent, options);
|
|
215
264
|
if (!options.preventStateUpdateListener && !options.preventListeners) {
|
|
216
|
-
await triggerEventOnUpdate(
|
|
265
|
+
await triggerEventOnUpdate(
|
|
266
|
+
"stateUpdate",
|
|
267
|
+
newState.parse(),
|
|
268
|
+
element,
|
|
269
|
+
options
|
|
270
|
+
);
|
|
217
271
|
}
|
|
218
272
|
};
|
|
219
|
-
const createStateUpdate = (element, parent, options) => {
|
|
273
|
+
const createStateUpdate = async (element, parent, options) => {
|
|
220
274
|
const __stateChildren = element.state.__children;
|
|
221
|
-
const newState = createState(element, parent);
|
|
275
|
+
const newState = await createState(element, parent);
|
|
222
276
|
element.state = newState;
|
|
223
277
|
for (const child in __stateChildren) {
|
|
224
278
|
if (newState[child]) newState.__children[child] = __stateChildren[child];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isFunction } from "@domql/utils";
|
|
2
2
|
import { REGISTRY } from "../mixins/index.js";
|
|
3
|
-
const applyParam = (param, element, options) => {
|
|
3
|
+
const applyParam = async (param, element, options) => {
|
|
4
4
|
const { node, context, __ref: ref } = element;
|
|
5
5
|
const prop = element[param];
|
|
6
6
|
const { onlyUpdate } = options;
|
|
@@ -13,7 +13,7 @@ const applyParam = (param, element, options) => {
|
|
|
13
13
|
const hasOnlyUpdate = onlyUpdate ? onlyUpdate === param || element.lookup(onlyUpdate) : true;
|
|
14
14
|
if (isGlobalTransformer && !hasContextDefine && hasOnlyUpdate) {
|
|
15
15
|
if (isFunction(isGlobalTransformer)) {
|
|
16
|
-
isGlobalTransformer(prop, element, node, options);
|
|
16
|
+
await isGlobalTransformer(prop, element, node, options);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
const METHODS_EXL = [];
|
|
2
|
+
export {
|
|
3
|
+
METHODS_EXL
|
|
4
|
+
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
exec,
|
|
3
|
+
initProps,
|
|
4
|
+
isFunction,
|
|
5
|
+
isMethod,
|
|
6
|
+
isObject,
|
|
7
|
+
isUndefined
|
|
8
|
+
} from "@domql/utils";
|
|
2
9
|
import { create } from "..";
|
|
3
10
|
import { REGISTRY } from "../mixins/index.js";
|
|
4
|
-
import { applyVariant, isVariant } from ".";
|
|
5
|
-
import { isMethod } from "../methods";
|
|
6
11
|
import { addMethods } from "../methods/set";
|
|
7
12
|
import { createState } from "@domql/state";
|
|
8
13
|
import { detectTag } from "@domql/render";
|
|
9
|
-
import { createProps } from "../props";
|
|
10
14
|
import { throughInitialDefine, throughInitialExec } from "../iterate";
|
|
11
15
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
12
16
|
const { __ref } = element;
|
|
13
17
|
element.tag = detectTag(element);
|
|
14
18
|
{
|
|
15
19
|
const { __ref: ref2 } = element;
|
|
16
|
-
if (!ref2.__cached) ref2.__cached = {};
|
|
17
20
|
if (!ref2.__defineCache) ref2.__defineCache = {};
|
|
18
21
|
if (!ref2.__exec) ref2.__exec = {};
|
|
19
22
|
if (!ref2.__execProps) ref2.__execProps = {};
|
|
@@ -35,14 +38,15 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
35
38
|
if (element.node && ref.__if) {
|
|
36
39
|
parent[key || element.key] = element;
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
applyVariant(element, parent);
|
|
41
|
+
initProps(element, parent, options);
|
|
40
42
|
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
41
43
|
throughInitialDefine(element);
|
|
42
44
|
throughInitialExec(element);
|
|
43
45
|
for (const param in element) {
|
|
44
46
|
const prop = element[param];
|
|
45
|
-
if (isUndefined(prop) || isMethod(param, element) || isObject(REGISTRY[param])
|
|
47
|
+
if (isUndefined(prop) || isMethod(param, element) || isObject(REGISTRY[param])) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
46
50
|
const hasDefine = element.define && element.define[param];
|
|
47
51
|
const contextHasDefine = element.context && element.context.define && element.context.define[param];
|
|
48
52
|
const optionsHasDefine = options.define && options.define[param];
|
package/iterate.js
CHANGED
|
@@ -6,28 +6,25 @@ import {
|
|
|
6
6
|
isFunction,
|
|
7
7
|
isNumber,
|
|
8
8
|
isString,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
matchesComponentNaming,
|
|
10
|
+
isContextComponent,
|
|
11
|
+
isMethod,
|
|
12
|
+
overwrite
|
|
12
13
|
} from '@domql/utils'
|
|
13
14
|
|
|
14
|
-
import { METHODS_EXL, overwrite } from './utils/index.js'
|
|
15
|
-
import { isMethod } from './methods/index.js'
|
|
16
|
-
|
|
17
15
|
export const throughInitialExec = (element, exclude = {}) => {
|
|
18
16
|
const { __ref: ref } = element
|
|
19
17
|
for (const param in element) {
|
|
20
18
|
if (exclude[param]) continue
|
|
21
19
|
const prop = element[param]
|
|
22
|
-
if (isFunction(prop) && !isMethod(param, element)
|
|
20
|
+
if (isFunction(prop) && !isMethod(param, element)) {
|
|
23
21
|
ref.__exec[param] = prop
|
|
24
22
|
element[param] = prop(element, element.state, element.context)
|
|
25
|
-
// if (isComponent)
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
export const throughUpdatedExec = (element, options = {
|
|
27
|
+
export const throughUpdatedExec = (element, options = {}) => {
|
|
31
28
|
const { __ref: ref } = element
|
|
32
29
|
const changes = {}
|
|
33
30
|
|
|
@@ -41,15 +38,17 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
|
|
|
41
38
|
const execReturnsString = isString(newExec) || isNumber(newExec)
|
|
42
39
|
// if (prop && prop.node && execReturnsString) {
|
|
43
40
|
if (prop && prop.node && execReturnsString) {
|
|
44
|
-
overwrite(prop, { text: newExec }
|
|
41
|
+
overwrite(prop, { text: newExec })
|
|
45
42
|
} else if (newExec !== prop) {
|
|
46
|
-
if (
|
|
47
|
-
const { extend, ...newElem } =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
if (matchesComponentNaming(param)) {
|
|
44
|
+
const { extends: extend, ...newElem } = isContextComponent(
|
|
45
|
+
newExec,
|
|
46
|
+
element,
|
|
47
|
+
param
|
|
48
|
+
)
|
|
49
|
+
overwrite(prop, newElem)
|
|
51
50
|
} else {
|
|
52
|
-
|
|
51
|
+
changes[param] = prop
|
|
53
52
|
element[param] = newExec
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -58,11 +57,12 @@ export const throughUpdatedExec = (element, options = { excludes: METHODS_EXL })
|
|
|
58
57
|
return changes
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export const throughExecProps =
|
|
60
|
+
export const throughExecProps = element => {
|
|
62
61
|
const { __ref: ref } = element
|
|
63
62
|
const { props } = element
|
|
64
63
|
for (const k in props) {
|
|
65
|
-
const isDefine =
|
|
64
|
+
const isDefine =
|
|
65
|
+
k.startsWith('is') || k.startsWith('has') || k.startsWith('use')
|
|
66
66
|
const cachedExecProp = ref.__execProps[k]
|
|
67
67
|
if (isFunction(cachedExecProp)) {
|
|
68
68
|
props[k] = exec(cachedExecProp, element)
|
|
@@ -73,7 +73,9 @@ export const throughExecProps = (element) => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export const
|
|
76
|
+
export const isPropertyInDefines = (key, element) => {}
|
|
77
|
+
|
|
78
|
+
export const throughInitialDefine = element => {
|
|
77
79
|
const { define, context, __ref: ref } = element
|
|
78
80
|
|
|
79
81
|
let defineObj = {}
|
|
@@ -84,23 +86,30 @@ export const throughInitialDefine = (element) => {
|
|
|
84
86
|
for (const param in defineObj) {
|
|
85
87
|
let elementProp = element[param]
|
|
86
88
|
|
|
87
|
-
if (isFunction(elementProp) && !isMethod(param, element)
|
|
89
|
+
if (isFunction(elementProp) && !isMethod(param, element)) {
|
|
88
90
|
ref.__exec[param] = elementProp
|
|
89
|
-
const execParam = elementProp = exec(elementProp, element)
|
|
91
|
+
const execParam = (elementProp = exec(elementProp, element))
|
|
90
92
|
|
|
91
93
|
if (execParam) {
|
|
92
|
-
elementProp = element[param] = execParam.parse
|
|
94
|
+
elementProp = element[param] = execParam.parse
|
|
95
|
+
? execParam.parse()
|
|
96
|
+
: execParam
|
|
93
97
|
ref.__defineCache[param] = elementProp
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
const execParam = defineObj[param](
|
|
101
|
+
const execParam = defineObj[param](
|
|
102
|
+
elementProp,
|
|
103
|
+
element,
|
|
104
|
+
element.state,
|
|
105
|
+
element.context
|
|
106
|
+
)
|
|
98
107
|
if (execParam) element[param] = execParam
|
|
99
108
|
}
|
|
100
109
|
return element
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
export const throughUpdatedDefine =
|
|
112
|
+
export const throughUpdatedDefine = element => {
|
|
104
113
|
const { context, define, __ref: ref } = element
|
|
105
114
|
const changes = {}
|
|
106
115
|
|
|
@@ -110,9 +119,18 @@ export const throughUpdatedDefine = (element) => {
|
|
|
110
119
|
|
|
111
120
|
for (const param in obj) {
|
|
112
121
|
const execParam = ref.__exec[param]
|
|
113
|
-
if (execParam)
|
|
122
|
+
if (execParam) {
|
|
123
|
+
ref.__defineCache[param] = execParam(
|
|
124
|
+
element,
|
|
125
|
+
element.state,
|
|
126
|
+
element.context
|
|
127
|
+
)
|
|
128
|
+
}
|
|
114
129
|
const cached = exec(ref.__defineCache[param], element)
|
|
115
|
-
const newExecParam =
|
|
130
|
+
const newExecParam =
|
|
131
|
+
typeof obj[param] === 'function'
|
|
132
|
+
? obj[param](cached, element, element.state, element.context)
|
|
133
|
+
: undefined
|
|
116
134
|
if (newExecParam) element[param] = newExecParam
|
|
117
135
|
}
|
|
118
136
|
return changes
|
package/methods/set.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { merge, overwrite } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
import { set, reset } from '../set.js'
|
|
5
|
+
import { set, reset, updateContent, removeContent } from '../set.js'
|
|
6
6
|
import { update } from '../update.js'
|
|
7
7
|
|
|
8
|
-
import { removeContent, updateContent } from '../mixins/content.js'
|
|
9
8
|
import {
|
|
10
9
|
call,
|
|
11
10
|
error,
|
|
@@ -27,7 +26,7 @@ import {
|
|
|
27
26
|
variables,
|
|
28
27
|
verbose,
|
|
29
28
|
warn
|
|
30
|
-
} from '
|
|
29
|
+
} from '@domql/utils/methods'
|
|
31
30
|
|
|
32
31
|
export const addMethods = (element, parent, options = {}) => {
|
|
33
32
|
const proto = {
|
|
@@ -57,6 +56,8 @@ export const addMethods = (element, parent, options = {}) => {
|
|
|
57
56
|
error,
|
|
58
57
|
call
|
|
59
58
|
}
|
|
60
|
-
if (element.context.methods)
|
|
59
|
+
if (element.context.methods) {
|
|
60
|
+
;(options.strict ? merge : overwrite)(proto, element.context.methods)
|
|
61
|
+
}
|
|
61
62
|
Object.setPrototypeOf(element, proto)
|
|
62
63
|
}
|
package/methods/v2.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isDefined, isFunction, isObjectLike } from '@domql/utils'
|
|
4
|
-
import { parseFilters, REGISTRY } from '../mixins/index.js'
|
|
5
4
|
|
|
6
5
|
export const defineSetter = (element, key, get, set) =>
|
|
7
6
|
Object.defineProperty(element, key, { get, set })
|
|
@@ -10,7 +9,7 @@ export const keys = function () {
|
|
|
10
9
|
const element = this
|
|
11
10
|
const keys = []
|
|
12
11
|
for (const param in element) {
|
|
13
|
-
if (REGISTRY[param] && !parseFilters.elementKeys.includes(param)) { continue }
|
|
12
|
+
// if (REGISTRY[param] && !parseFilters.elementKeys.includes(param)) { continue }
|
|
14
13
|
keys.push(param)
|
|
15
14
|
}
|
|
16
15
|
return keys
|
|
@@ -39,7 +38,9 @@ export const parseDeep = function (excl = []) {
|
|
|
39
38
|
const obj = parse.call(element, excl)
|
|
40
39
|
for (const v in obj) {
|
|
41
40
|
if (excl.includes(v)) return
|
|
42
|
-
if (isObjectLike(obj[v])) {
|
|
41
|
+
if (isObjectLike(obj[v])) {
|
|
42
|
+
obj[v] = parseDeep.call(obj[v], excl)
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
return obj
|
|
45
46
|
}
|
|
@@ -51,7 +52,7 @@ export const log = function (...args) {
|
|
|
51
52
|
if (args.length) {
|
|
52
53
|
args.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
53
54
|
} else {
|
|
54
|
-
console.log(__ref
|
|
55
|
+
console.log(__ref?.path)
|
|
55
56
|
const keys = element.keys()
|
|
56
57
|
keys.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
57
58
|
}
|
package/mixins/attr.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { exec, isNot, isNull, isUndefined } from '@domql/utils'
|
|
3
|
+
import { deepMerge, exec, isNot, isNull, isUndefined } from '@domql/utils'
|
|
4
4
|
import { report } from '@domql/report'
|
|
5
|
-
import { deepMerge } from '../utils/index.js'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Recursively add attributes to a DOM node
|
|
@@ -12,12 +11,19 @@ export function attr (params, element, node) {
|
|
|
12
11
|
const { __attr } = ref
|
|
13
12
|
if (isNot('object')) report('HTMLInvalidAttr', params)
|
|
14
13
|
if (params) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const attrs = exec(params, element)
|
|
15
|
+
if (props.attr) deepMerge(attrs, props.attr)
|
|
16
|
+
for (const attr in attrs) {
|
|
17
|
+
const val = exec(attrs[attr], element)
|
|
18
18
|
// if (__attr[attr] === val) return
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
if (
|
|
20
|
+
val !== false &&
|
|
21
|
+
!isUndefined(val) &&
|
|
22
|
+
!isNull(val) &&
|
|
23
|
+
node.setAttribute
|
|
24
|
+
) {
|
|
25
|
+
node.setAttribute(attr, val)
|
|
26
|
+
} else if (node.removeAttribute) node.removeAttribute(attr)
|
|
21
27
|
__attr[attr] = val
|
|
22
28
|
}
|
|
23
29
|
}
|
package/mixins/classList.js
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { exec, isObject, isString } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
export const assignKeyAsClassname =
|
|
5
|
+
export const assignKeyAsClassname = element => {
|
|
6
6
|
const { key } = element
|
|
7
7
|
if (element.class === true) element.class = key
|
|
8
|
-
else if (
|
|
8
|
+
else if (
|
|
9
|
+
!element.class &&
|
|
10
|
+
typeof key === 'string' &&
|
|
11
|
+
key.charAt(0) === '_' &&
|
|
12
|
+
key.charAt(1) !== '_'
|
|
13
|
+
) {
|
|
9
14
|
element.class = key.slice(1)
|
|
10
15
|
}
|
|
11
16
|
}
|