@domql/element 2.5.185 → 2.5.187
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/create.js +11 -11
- package/dist/cjs/create.js +11 -11
- package/dist/cjs/extend.js +1 -1
- package/dist/cjs/iterate.js +2 -2
- package/dist/cjs/methods/index.js +1 -1
- package/dist/cjs/methods/set.js +24 -24
- package/dist/cjs/mixins/attr.js +1 -1
- package/dist/cjs/mixins/content.js +1 -1
- package/dist/cjs/mixins/index.js +11 -11
- package/dist/cjs/mixins/registry.js +9 -9
- package/dist/cjs/mixins/text.js +1 -1
- package/dist/cjs/node.js +6 -6
- package/dist/cjs/props/create.js +2 -2
- package/dist/cjs/props/index.js +4 -4
- package/dist/cjs/props/update.js +2 -2
- package/dist/cjs/set.js +4 -4
- package/dist/cjs/update.js +8 -8
- package/dist/cjs/utils/component.js +1 -1
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/object.js +1 -1
- package/dist/esm/cache/index.js +4 -0
- package/dist/esm/cache/options.js +6 -0
- package/dist/esm/create.js +334 -0
- package/dist/esm/define.js +14 -0
- package/dist/esm/extend.js +71 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/iterate.js +112 -0
- package/dist/esm/methods/index.js +333 -0
- package/dist/esm/methods/set.js +61 -0
- package/dist/esm/methods/v2.js +89 -0
- package/dist/esm/mixins/attr.js +26 -0
- package/dist/esm/mixins/classList.js +55 -0
- package/dist/esm/mixins/content.js +54 -0
- package/dist/esm/mixins/data.js +22 -0
- package/dist/esm/mixins/html.js +18 -0
- package/dist/esm/mixins/index.js +23 -0
- package/dist/esm/mixins/registry.js +105 -0
- package/dist/esm/mixins/scope.js +18 -0
- package/dist/esm/mixins/state.js +19 -0
- package/dist/esm/mixins/style.js +15 -0
- package/dist/esm/mixins/text.js +28 -0
- package/dist/esm/node.js +69 -0
- package/dist/esm/props/create.js +78 -0
- package/dist/esm/props/ignore.js +4 -0
- package/dist/esm/props/index.js +4 -0
- package/dist/esm/props/inherit.js +33 -0
- package/dist/esm/props/update.js +17 -0
- package/dist/esm/set.js +73 -0
- package/dist/esm/tree.js +11 -0
- package/dist/esm/update.js +255 -0
- package/dist/esm/utils/applyParam.js +25 -0
- package/dist/esm/utils/component.js +65 -0
- package/dist/esm/utils/extendUtils.js +122 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/object.js +159 -0
- package/dist/esm/utils/onlyResolveExtends.js +81 -0
- package/dist/esm/utils/propEvents.js +21 -0
- package/extend.js +1 -1
- package/iterate.js +2 -2
- package/methods/index.js +1 -1
- package/methods/set.js +18 -19
- package/mixins/attr.js +1 -1
- package/mixins/content.js +1 -1
- package/mixins/index.js +11 -11
- package/mixins/registry.js +9 -9
- package/mixins/text.js +1 -1
- package/node.js +6 -6
- package/package.json +7 -7
- package/props/create.js +2 -2
- package/props/index.js +4 -4
- package/props/update.js +2 -2
- package/set.js +4 -4
- package/update.js +8 -8
- package/utils/component.js +1 -1
- package/utils/index.js +3 -3
- package/utils/object.js +1 -1
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import createNode from "./node.js";
|
|
2
|
+
import { ROOT } from "./tree.js";
|
|
3
|
+
import {
|
|
4
|
+
HTML_TAGS,
|
|
5
|
+
isObject,
|
|
6
|
+
isFunction,
|
|
7
|
+
isString,
|
|
8
|
+
exec,
|
|
9
|
+
is,
|
|
10
|
+
isNode,
|
|
11
|
+
isUndefined,
|
|
12
|
+
generateKey,
|
|
13
|
+
checkIfKeyIsComponent,
|
|
14
|
+
deepClone,
|
|
15
|
+
applyComponentFromContext,
|
|
16
|
+
applyKeyComponentAsExtend,
|
|
17
|
+
isVariant,
|
|
18
|
+
detectInfiniteLoop,
|
|
19
|
+
addChildrenIfNotInOriginal
|
|
20
|
+
} from "@domql/utils";
|
|
21
|
+
import { triggerEventOn } from "@domql/event";
|
|
22
|
+
import { assignNode } from "@domql/render";
|
|
23
|
+
import { createState } from "@domql/state";
|
|
24
|
+
import { isMethod } from "./methods/index.js";
|
|
25
|
+
import { createProps } from "./props/index.js";
|
|
26
|
+
import { applyExtend } from "./extend.js";
|
|
27
|
+
import { REGISTRY, registry } from "./mixins/index.js";
|
|
28
|
+
import { addMethods } from "./methods/set.js";
|
|
29
|
+
import { assignKeyAsClassname } from "./mixins/classList.js";
|
|
30
|
+
import { throughInitialExec, throughInitialDefine } from "./iterate.js";
|
|
31
|
+
import { OPTIONS } from "./cache/options.js";
|
|
32
|
+
import {
|
|
33
|
+
applyVariant,
|
|
34
|
+
createValidDomqlObjectFromSugar
|
|
35
|
+
} from "./utils/component.js";
|
|
36
|
+
const ENV = "development";
|
|
37
|
+
const create = async (element, parent, key, options = OPTIONS.create || {}, attachOptions) => {
|
|
38
|
+
cacheOptions(element, options);
|
|
39
|
+
if (checkIfPrimitive(element)) {
|
|
40
|
+
element = applyValueAsText(element, parent, key);
|
|
41
|
+
}
|
|
42
|
+
element = redefineElement(element, parent, key, options);
|
|
43
|
+
parent = redefineParent(element, parent, key);
|
|
44
|
+
key = createKey(element, parent, key);
|
|
45
|
+
const ref = addRef(element, parent, key);
|
|
46
|
+
ref.__initialProps = deepClone(element.props);
|
|
47
|
+
applyContext(element, parent, options);
|
|
48
|
+
applyComponentFromContext(element, parent, options);
|
|
49
|
+
if (!ref.__skipCreate) {
|
|
50
|
+
applyExtend(element, parent, options);
|
|
51
|
+
}
|
|
52
|
+
element.key = key;
|
|
53
|
+
if (options.onlyResolveExtends) {
|
|
54
|
+
return onlyResolveExtends(element, parent, key, options);
|
|
55
|
+
}
|
|
56
|
+
await triggerEventOn("start", element, options);
|
|
57
|
+
switchDefaultOptions(element, parent, options);
|
|
58
|
+
addCaching(element, parent);
|
|
59
|
+
addMethods(element, parent, options);
|
|
60
|
+
createScope(element, parent);
|
|
61
|
+
await createState(element, parent);
|
|
62
|
+
if (element.scope === "state")
|
|
63
|
+
element.scope = element.state;
|
|
64
|
+
createIfConditionFlag(element, parent);
|
|
65
|
+
createProps(element, parent, options);
|
|
66
|
+
if (element.scope === "props" || element.scope === true)
|
|
67
|
+
element.scope = element.props;
|
|
68
|
+
createIfConditionFlag(element, parent);
|
|
69
|
+
if (element.node && ref.__if) {
|
|
70
|
+
return assignNode(element, parent, key, attachOptions);
|
|
71
|
+
}
|
|
72
|
+
applyVariant(element, parent);
|
|
73
|
+
const onInit = await triggerEventOn("init", element, options);
|
|
74
|
+
if (onInit === false)
|
|
75
|
+
return element;
|
|
76
|
+
triggerEventOn("beforeClassAssign", element, options);
|
|
77
|
+
assignKeyAsClassname(element);
|
|
78
|
+
addChildrenIfNotInOriginal(element, parent, key);
|
|
79
|
+
await renderElement(element, parent, options, attachOptions);
|
|
80
|
+
addElementIntoParentChildren(element, parent);
|
|
81
|
+
await triggerEventOn("complete", element, options);
|
|
82
|
+
return element;
|
|
83
|
+
};
|
|
84
|
+
const createBasedOnType = (element, parent, key, options) => {
|
|
85
|
+
if (element === void 0) {
|
|
86
|
+
if (ENV === "test" || ENV === "development") {
|
|
87
|
+
console.warn(key, "element is undefined in", parent && parent.__ref && parent.__ref.path);
|
|
88
|
+
}
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
if (isString(key) && key.slice(0, 2 === "__")) {
|
|
92
|
+
if (ENV === "test" || ENV === "development") {
|
|
93
|
+
console.warn(key, "seems like to be in __ref");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (element === null)
|
|
97
|
+
return;
|
|
98
|
+
if (element === true)
|
|
99
|
+
return { text: true };
|
|
100
|
+
if (element.__hash) {
|
|
101
|
+
return { extend: element };
|
|
102
|
+
}
|
|
103
|
+
return element;
|
|
104
|
+
};
|
|
105
|
+
const redefineElement = (element, parent, key, options) => {
|
|
106
|
+
const elementWrapper = createBasedOnType(element, parent, key, options);
|
|
107
|
+
if (options.syntaxv3 || element.props && element.props.syntaxv3 || parent && parent.props && parent.props.syntaxv3) {
|
|
108
|
+
if (element.props)
|
|
109
|
+
element.props.syntaxv3 = true;
|
|
110
|
+
else
|
|
111
|
+
element.syntaxv3 = true;
|
|
112
|
+
return createValidDomqlObjectFromSugar(element, parent, key, options);
|
|
113
|
+
} else if (checkIfKeyIsComponent(key)) {
|
|
114
|
+
return applyKeyComponentAsExtend(elementWrapper, parent, key);
|
|
115
|
+
}
|
|
116
|
+
if (checkIfMedia(key)) {
|
|
117
|
+
return applyMediaProps(elementWrapper, parent, key);
|
|
118
|
+
}
|
|
119
|
+
return elementWrapper;
|
|
120
|
+
};
|
|
121
|
+
const redefineParent = (element, parent, key, options) => {
|
|
122
|
+
if (!parent)
|
|
123
|
+
return ROOT;
|
|
124
|
+
if (isNode(parent)) {
|
|
125
|
+
const parentNodeWrapper = { key: ":root", node: parent };
|
|
126
|
+
ROOT[`${key}_parent`] = parentNodeWrapper;
|
|
127
|
+
return parentNodeWrapper;
|
|
128
|
+
}
|
|
129
|
+
return parent;
|
|
130
|
+
};
|
|
131
|
+
const cacheOptions = (element, options) => {
|
|
132
|
+
if (options && !OPTIONS.create) {
|
|
133
|
+
OPTIONS.create = options;
|
|
134
|
+
OPTIONS.create.context = element.context || options.context;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const createKey = (element, parent, key) => {
|
|
138
|
+
return (exec(key, element) || key || element.key || generateKey()).toString();
|
|
139
|
+
};
|
|
140
|
+
const addRef = (element, parent) => {
|
|
141
|
+
if (element.__ref)
|
|
142
|
+
element.__ref.origin = element;
|
|
143
|
+
else
|
|
144
|
+
element.__ref = { origin: element };
|
|
145
|
+
return element.__ref;
|
|
146
|
+
};
|
|
147
|
+
const switchDefaultOptions = (element, parent, options) => {
|
|
148
|
+
if (Object.keys(options).length) {
|
|
149
|
+
registry.defaultOptions = options;
|
|
150
|
+
if (options.ignoreChildExtend)
|
|
151
|
+
delete options.ignoreChildExtend;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const addElementIntoParentChildren = (element, parent) => {
|
|
155
|
+
if (parent.__ref && parent.__ref.__children)
|
|
156
|
+
parent.__ref.__children.push(element.key);
|
|
157
|
+
};
|
|
158
|
+
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
159
|
+
const renderElement = async (element, parent, options, attachOptions) => {
|
|
160
|
+
var _a, _b, _c, _d;
|
|
161
|
+
if (visitedElements.has(element)) {
|
|
162
|
+
if (ENV === "test" || ENV === "development")
|
|
163
|
+
console.warn("Cyclic rendering detected:", element.__ref.path);
|
|
164
|
+
}
|
|
165
|
+
visitedElements.set(element, true);
|
|
166
|
+
const { __ref: ref, key } = element;
|
|
167
|
+
try {
|
|
168
|
+
const isInfiniteLoopDetected = detectInfiniteLoop(ref.path);
|
|
169
|
+
if (ref.__uniqId || isInfiniteLoopDetected)
|
|
170
|
+
return;
|
|
171
|
+
await createNode(element, options);
|
|
172
|
+
ref.__uniqId = Math.random();
|
|
173
|
+
} catch (e) {
|
|
174
|
+
if (ENV === "test" || ENV === "development") {
|
|
175
|
+
const path = ref.path;
|
|
176
|
+
if (path.includes("ComponentsGrid"))
|
|
177
|
+
path.splice(0, path.indexOf("ComponentsGrid") + 2);
|
|
178
|
+
if (path.includes("demoComponent"))
|
|
179
|
+
path.splice(0, path.indexOf("demoComponent") + 1);
|
|
180
|
+
const isDemoComponent = (_b = (_a = element.lookup((el) => el.state.key)) == null ? void 0 : _a.state) == null ? void 0 : _b.key;
|
|
181
|
+
element.warn("Error happened in:", isDemoComponent ? isDemoComponent + " " : "" + path.join("."));
|
|
182
|
+
element.verbose();
|
|
183
|
+
element.error(e, options);
|
|
184
|
+
if ((_c = element.on) == null ? void 0 : _c.error)
|
|
185
|
+
element.on.error(e, element, element.state, element.context, options);
|
|
186
|
+
if ((_d = element.props) == null ? void 0 : _d.onError)
|
|
187
|
+
element.props.onError(e, element, element.state, element.context, options);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!ref.__if) {
|
|
191
|
+
parent[key || element.key] = element;
|
|
192
|
+
return element;
|
|
193
|
+
}
|
|
194
|
+
assignNode(element, parent, key, attachOptions);
|
|
195
|
+
await triggerEventOn("renderRouter", element, options);
|
|
196
|
+
await triggerEventOn("render", element, options);
|
|
197
|
+
await triggerEventOn("done", element, options);
|
|
198
|
+
await triggerEventOn("create", element, options);
|
|
199
|
+
};
|
|
200
|
+
const checkIfPrimitive = (element) => is(element)("string", "number");
|
|
201
|
+
const applyValueAsText = (element, parent, key) => {
|
|
202
|
+
const extendTag = element.extend && element.extend.tag;
|
|
203
|
+
const childExtendTag = parent.childExtend && parent.childExtend.tag;
|
|
204
|
+
const childPropsTag = parent.props.childProps && parent.props.childProps.tag;
|
|
205
|
+
const isKeyValidHTMLTag = HTML_TAGS.body.indexOf(key) > -1 && key;
|
|
206
|
+
return {
|
|
207
|
+
text: element,
|
|
208
|
+
tag: extendTag || childExtendTag || childPropsTag || isKeyValidHTMLTag || "string"
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
const applyContext = (element, parent, options) => {
|
|
212
|
+
const forcedOptionsContext = options.context && !ROOT.context && !element.context;
|
|
213
|
+
if (forcedOptionsContext)
|
|
214
|
+
ROOT.context = options.context;
|
|
215
|
+
if (!element.context)
|
|
216
|
+
element.context = parent.context || options.context || ROOT.context;
|
|
217
|
+
};
|
|
218
|
+
const createScope = (element, parent) => {
|
|
219
|
+
const { __ref: ref } = element;
|
|
220
|
+
if (!element.scope)
|
|
221
|
+
element.scope = parent.scope || ref.root.scope || {};
|
|
222
|
+
};
|
|
223
|
+
const createIfConditionFlag = (element, parent) => {
|
|
224
|
+
const { __ref: ref } = element;
|
|
225
|
+
if (isFunction(element.if) && !element.if(element, element.state, element.context)) {
|
|
226
|
+
delete ref.__if;
|
|
227
|
+
} else
|
|
228
|
+
ref.__if = true;
|
|
229
|
+
};
|
|
230
|
+
const addCaching = (element, parent) => {
|
|
231
|
+
const { __ref: ref, key } = element;
|
|
232
|
+
let { __ref: parentRef } = parent;
|
|
233
|
+
if (!element.transform)
|
|
234
|
+
element.transform = {};
|
|
235
|
+
if (!ref.__cached)
|
|
236
|
+
ref.__cached = {};
|
|
237
|
+
if (!ref.__defineCache)
|
|
238
|
+
ref.__defineCache = {};
|
|
239
|
+
if (!ref.__exec)
|
|
240
|
+
ref.__exec = {};
|
|
241
|
+
if (!ref.__execProps)
|
|
242
|
+
ref.__execProps = {};
|
|
243
|
+
if (!ref.__class)
|
|
244
|
+
ref.__class = {};
|
|
245
|
+
if (!ref.__classNames)
|
|
246
|
+
ref.__classNames = {};
|
|
247
|
+
if (!ref.__attr)
|
|
248
|
+
ref.__attr = {};
|
|
249
|
+
if (!ref.__changes)
|
|
250
|
+
ref.__changes = [];
|
|
251
|
+
if (!ref.__children)
|
|
252
|
+
ref.__children = [];
|
|
253
|
+
if (checkIfKeyIsComponent(key))
|
|
254
|
+
ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
|
|
255
|
+
const hasRoot = parent && parent.key === ":root";
|
|
256
|
+
if (!ref.root)
|
|
257
|
+
ref.root = hasRoot ? element : parentRef.root;
|
|
258
|
+
if (!parentRef)
|
|
259
|
+
parentRef = parent.ref = {};
|
|
260
|
+
if (!parentRef.path)
|
|
261
|
+
parentRef.path = [];
|
|
262
|
+
ref.path = parentRef.path.concat(element.key);
|
|
263
|
+
};
|
|
264
|
+
const onlyResolveExtends = (element, parent, key, options) => {
|
|
265
|
+
const { __ref: ref } = element;
|
|
266
|
+
if (!ref.__skipCreate) {
|
|
267
|
+
addCaching(element, parent);
|
|
268
|
+
addMethods(element, parent, options);
|
|
269
|
+
createScope(element, parent);
|
|
270
|
+
createState(element, parent);
|
|
271
|
+
if (element.scope === "state")
|
|
272
|
+
element.scope = element.state;
|
|
273
|
+
createIfConditionFlag(element, parent);
|
|
274
|
+
createProps(element, parent, options);
|
|
275
|
+
if (element.scope === "props" || element.scope === true)
|
|
276
|
+
element.scope = element.props;
|
|
277
|
+
if (element.node && ref.__if) {
|
|
278
|
+
parent[key || element.key] = element;
|
|
279
|
+
}
|
|
280
|
+
if (!element.props)
|
|
281
|
+
element.props = {};
|
|
282
|
+
applyVariant(element, parent);
|
|
283
|
+
addElementIntoParentChildren(element, parent);
|
|
284
|
+
}
|
|
285
|
+
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
286
|
+
throughInitialDefine(element);
|
|
287
|
+
throughInitialExec(element);
|
|
288
|
+
for (const k in element) {
|
|
289
|
+
if (isUndefined(element[k]) || isMethod(k, element) || isObject((registry.default || registry)[k]) || isVariant(k))
|
|
290
|
+
continue;
|
|
291
|
+
const hasDefine = element.define && element.define[k];
|
|
292
|
+
const contextHasDefine = element.context && element.context.define && element.context.define[k];
|
|
293
|
+
const optionsHasDefine = options.define && options.define[k];
|
|
294
|
+
if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
|
|
295
|
+
continue;
|
|
296
|
+
} else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
|
|
297
|
+
create(exec(element[k], element), element, k, options);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
parent[key || element.key] = element;
|
|
302
|
+
delete element.update;
|
|
303
|
+
delete element.__element;
|
|
304
|
+
if (element.props) {
|
|
305
|
+
delete element.props.update;
|
|
306
|
+
delete element.props.__element;
|
|
307
|
+
}
|
|
308
|
+
return element;
|
|
309
|
+
};
|
|
310
|
+
const checkIfMedia = (key) => key.slice(0, 1) === "@";
|
|
311
|
+
const applyMediaProps = (element, parent, key) => {
|
|
312
|
+
const { props } = element;
|
|
313
|
+
if (props) {
|
|
314
|
+
props.display = "none";
|
|
315
|
+
if (props[key])
|
|
316
|
+
props[key].display = props.display;
|
|
317
|
+
else
|
|
318
|
+
props[key] = { display: props.display || "block" };
|
|
319
|
+
return element;
|
|
320
|
+
} else {
|
|
321
|
+
return {
|
|
322
|
+
...element,
|
|
323
|
+
props: {
|
|
324
|
+
display: "none",
|
|
325
|
+
[key]: { display: "block" }
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var create_default = create;
|
|
331
|
+
export {
|
|
332
|
+
create,
|
|
333
|
+
create_default as default
|
|
334
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { report } from "@domql/report";
|
|
2
|
+
import { REGISTRY } from "./mixins";
|
|
3
|
+
var define_default = (params, options = {}) => {
|
|
4
|
+
const { overwrite } = options;
|
|
5
|
+
for (const param in params) {
|
|
6
|
+
if (REGISTRY[param] && !overwrite) {
|
|
7
|
+
report("OverwriteToBuiltin", param);
|
|
8
|
+
} else
|
|
9
|
+
REGISTRY[param] = params[param];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
define_default as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isFunction, exec } from "@domql/utils";
|
|
2
|
+
import {
|
|
3
|
+
getExtendStack,
|
|
4
|
+
jointStacks,
|
|
5
|
+
cloneAndMergeArrayExtend,
|
|
6
|
+
deepMergeExtend,
|
|
7
|
+
fallbackStringExtend
|
|
8
|
+
} from "./utils/index.js";
|
|
9
|
+
const ENV = "development";
|
|
10
|
+
let mainExtend;
|
|
11
|
+
const applyExtend = (element, parent, options = {}) => {
|
|
12
|
+
if (isFunction(element))
|
|
13
|
+
element = exec(element, parent);
|
|
14
|
+
const { props, __ref } = element;
|
|
15
|
+
let extend = (props == null ? void 0 : props.extends) || element.extends || element.extend;
|
|
16
|
+
const variant = props == null ? void 0 : props.variant;
|
|
17
|
+
const context = element.context || parent.context;
|
|
18
|
+
extend = fallbackStringExtend(extend, context, options, variant);
|
|
19
|
+
const extendStack = getExtendStack(extend, context);
|
|
20
|
+
if (ENV !== "test" || ENV !== "development")
|
|
21
|
+
delete element.extend;
|
|
22
|
+
let childExtendStack = [];
|
|
23
|
+
if (parent) {
|
|
24
|
+
element.parent = parent;
|
|
25
|
+
if (!options.ignoreChildExtend && !(props && props.ignoreChildExtend)) {
|
|
26
|
+
childExtendStack = getExtendStack(parent.childExtend, context);
|
|
27
|
+
const ignoreChildExtendRecursive = props && props.ignoreChildExtendRecursive;
|
|
28
|
+
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
29
|
+
const canExtendRecursive = element.key !== "__text";
|
|
30
|
+
if (canExtendRecursive) {
|
|
31
|
+
const childExtendRecursiveStack = getExtendStack(parent.childExtendRecursive, context);
|
|
32
|
+
childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
|
|
33
|
+
element.childExtendRecursive = parent.childExtendRecursive;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const extendLength = extendStack.length;
|
|
39
|
+
const childExtendLength = childExtendStack.length;
|
|
40
|
+
let stack = [];
|
|
41
|
+
if (extendLength && childExtendLength) {
|
|
42
|
+
stack = jointStacks(extendStack, childExtendStack);
|
|
43
|
+
} else if (extendLength) {
|
|
44
|
+
stack = extendStack;
|
|
45
|
+
} else if (childExtendLength) {
|
|
46
|
+
stack = childExtendStack;
|
|
47
|
+
} else if (!context.defaultExtends)
|
|
48
|
+
return element;
|
|
49
|
+
if (context.defaultExtends) {
|
|
50
|
+
if (!mainExtend) {
|
|
51
|
+
const defaultOptionsExtend = getExtendStack(context.defaultExtends, context);
|
|
52
|
+
mainExtend = cloneAndMergeArrayExtend(defaultOptionsExtend);
|
|
53
|
+
delete mainExtend.extend;
|
|
54
|
+
}
|
|
55
|
+
stack = [].concat(stack, mainExtend);
|
|
56
|
+
}
|
|
57
|
+
if (__ref)
|
|
58
|
+
__ref.__extend = stack;
|
|
59
|
+
let mergedExtend = cloneAndMergeArrayExtend(stack);
|
|
60
|
+
const COMPONENTS = context && context.components || options.components;
|
|
61
|
+
const component = exec(element.component || mergedExtend.component, element);
|
|
62
|
+
if (component && COMPONENTS && COMPONENTS[component]) {
|
|
63
|
+
const componentExtend = cloneAndMergeArrayExtend(getExtendStack(COMPONENTS[component]));
|
|
64
|
+
mergedExtend = deepMergeExtend(componentExtend, mergedExtend);
|
|
65
|
+
}
|
|
66
|
+
const merged = deepMergeExtend(element, mergedExtend);
|
|
67
|
+
return merged;
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
applyExtend
|
|
71
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TREE } from "./tree";
|
|
2
|
+
import create from "./create";
|
|
3
|
+
import createNode from "./node";
|
|
4
|
+
import define from "./define";
|
|
5
|
+
import update from "./update";
|
|
6
|
+
import set from "./set";
|
|
7
|
+
export {
|
|
8
|
+
TREE,
|
|
9
|
+
create,
|
|
10
|
+
createNode,
|
|
11
|
+
define,
|
|
12
|
+
set,
|
|
13
|
+
update
|
|
14
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject,
|
|
3
|
+
exec,
|
|
4
|
+
isFunction,
|
|
5
|
+
isNumber,
|
|
6
|
+
isString,
|
|
7
|
+
checkIfKeyIsComponent,
|
|
8
|
+
extendizeByKey,
|
|
9
|
+
isVariant
|
|
10
|
+
} from "@domql/utils";
|
|
11
|
+
import { METHODS_EXL, overwrite } from "./utils/index.js";
|
|
12
|
+
import { isMethod } from "./methods/index.js";
|
|
13
|
+
const throughInitialExec = (element, exclude = {}) => {
|
|
14
|
+
const { __ref: ref } = element;
|
|
15
|
+
for (const param in element) {
|
|
16
|
+
if (exclude[param])
|
|
17
|
+
continue;
|
|
18
|
+
const prop = element[param];
|
|
19
|
+
if (isFunction(prop) && !isMethod(param, element) && !isVariant(param)) {
|
|
20
|
+
ref.__exec[param] = prop;
|
|
21
|
+
element[param] = prop(element, element.state, element.context);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const throughUpdatedExec = (element, options = { excludes: METHODS_EXL }) => {
|
|
26
|
+
const { __ref: ref } = element;
|
|
27
|
+
const changes = {};
|
|
28
|
+
for (const param in ref.__exec) {
|
|
29
|
+
const prop = element[param];
|
|
30
|
+
const isDefinedParam = ref.__defineCache[param];
|
|
31
|
+
if (isDefinedParam)
|
|
32
|
+
continue;
|
|
33
|
+
const newExec = ref.__exec[param](element, element.state, element.context);
|
|
34
|
+
const execReturnsString = isString(newExec) || isNumber(newExec);
|
|
35
|
+
if (prop && prop.node && execReturnsString) {
|
|
36
|
+
overwrite(prop, { text: newExec }, options);
|
|
37
|
+
} else if (newExec !== prop) {
|
|
38
|
+
if (checkIfKeyIsComponent(param)) {
|
|
39
|
+
const { extend, ...newElem } = extendizeByKey(newExec, element, param);
|
|
40
|
+
overwrite(prop, newElem, options);
|
|
41
|
+
} else {
|
|
42
|
+
ref.__cached[param] = changes[param] = prop;
|
|
43
|
+
element[param] = newExec;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return changes;
|
|
48
|
+
};
|
|
49
|
+
const throughExecProps = (element) => {
|
|
50
|
+
const { __ref: ref } = element;
|
|
51
|
+
const { props } = element;
|
|
52
|
+
for (const k in props) {
|
|
53
|
+
const isDefine = k.startsWith("is") || k.startsWith("has") || k.startsWith("use");
|
|
54
|
+
const cachedExecProp = ref.__execProps[k];
|
|
55
|
+
if (isFunction(cachedExecProp)) {
|
|
56
|
+
props[k] = exec(cachedExecProp, element);
|
|
57
|
+
} else if (isDefine && isFunction(props[k])) {
|
|
58
|
+
ref.__execProps[k] = props[k];
|
|
59
|
+
props[k] = exec(props[k], element);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const throughInitialDefine = (element) => {
|
|
64
|
+
const { define, context, __ref: ref } = element;
|
|
65
|
+
let defineObj = {};
|
|
66
|
+
const hasGlobalDefine = context && isObject(context.define);
|
|
67
|
+
if (isObject(define))
|
|
68
|
+
defineObj = { ...define };
|
|
69
|
+
if (hasGlobalDefine)
|
|
70
|
+
defineObj = { ...defineObj, ...context.define };
|
|
71
|
+
for (const param in defineObj) {
|
|
72
|
+
let elementProp = element[param];
|
|
73
|
+
if (isFunction(elementProp) && !isMethod(param, element) && !isVariant(param)) {
|
|
74
|
+
ref.__exec[param] = elementProp;
|
|
75
|
+
const execParam2 = elementProp = exec(elementProp, element);
|
|
76
|
+
if (execParam2) {
|
|
77
|
+
elementProp = element[param] = execParam2.parse ? execParam2.parse() : execParam2;
|
|
78
|
+
ref.__defineCache[param] = elementProp;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const execParam = defineObj[param](elementProp, element, element.state, element.context);
|
|
82
|
+
if (execParam)
|
|
83
|
+
element[param] = execParam;
|
|
84
|
+
}
|
|
85
|
+
return element;
|
|
86
|
+
};
|
|
87
|
+
const throughUpdatedDefine = (element) => {
|
|
88
|
+
const { context, define, __ref: ref } = element;
|
|
89
|
+
const changes = {};
|
|
90
|
+
let obj = {};
|
|
91
|
+
if (isObject(define))
|
|
92
|
+
obj = { ...define };
|
|
93
|
+
if (isObject(context && context.define))
|
|
94
|
+
obj = { ...obj, ...context.define };
|
|
95
|
+
for (const param in obj) {
|
|
96
|
+
const execParam = ref.__exec[param];
|
|
97
|
+
if (execParam)
|
|
98
|
+
ref.__defineCache[param] = execParam(element, element.state, element.context);
|
|
99
|
+
const cached = exec(ref.__defineCache[param], element);
|
|
100
|
+
const newExecParam = obj[param](cached, element, element.state, element.context);
|
|
101
|
+
if (newExecParam)
|
|
102
|
+
element[param] = newExecParam;
|
|
103
|
+
}
|
|
104
|
+
return changes;
|
|
105
|
+
};
|
|
106
|
+
export {
|
|
107
|
+
throughExecProps,
|
|
108
|
+
throughInitialDefine,
|
|
109
|
+
throughInitialExec,
|
|
110
|
+
throughUpdatedDefine,
|
|
111
|
+
throughUpdatedExec
|
|
112
|
+
};
|