@domql/element 2.31.25 → 2.31.27
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 +107 -8
- package/dist/cjs/create.js +135 -69
- package/dist/cjs/iterate.js +2 -0
- package/dist/cjs/methods/index.js +22 -8
- package/dist/cjs/mixins/content.js +1 -1
- package/dist/cjs/node.js +5 -1
- package/dist/cjs/set.js +0 -19
- package/dist/cjs/update.js +16 -3
- package/dist/esm/create.js +136 -70
- package/dist/esm/extend.js +1 -1
- package/dist/esm/iterate.js +3 -1
- package/dist/esm/methods/index.js +22 -8
- package/dist/esm/mixins/content.js +1 -1
- package/dist/esm/node.js +5 -1
- package/dist/esm/set.js +1 -20
- package/dist/esm/update.js +16 -3
- package/extend.js +1 -1
- package/iterate.js +6 -4
- package/methods/index.js +21 -7
- package/mixins/content.js +2 -2
- package/node.js +6 -1
- package/package.json +6 -6
- package/set.js +27 -25
- package/update.js +27 -4
package/dist/cjs/set.js
CHANGED
|
@@ -33,7 +33,6 @@ var import_event = require("@domql/event");
|
|
|
33
33
|
const resetElement = async (params, element, options) => {
|
|
34
34
|
if (!options.preventRemove) (0, import_content.removeContent)(element, options);
|
|
35
35
|
const { __ref: ref } = element;
|
|
36
|
-
if (params instanceof Promise) console.log(params, params instanceof Promise);
|
|
37
36
|
await (0, import_create.create)(params, element, ref.contentElementKey || "content", {
|
|
38
37
|
ignoreChildExtend: true,
|
|
39
38
|
...import_mixins.registry.defaultOptions,
|
|
@@ -53,32 +52,14 @@ const reset = async (options) => {
|
|
|
53
52
|
const set = async function(params, options = {}, el) {
|
|
54
53
|
var _a, _b, _c;
|
|
55
54
|
const element = el || this;
|
|
56
|
-
const { __ref: ref } = element;
|
|
57
55
|
if (options.preventContentUpdate || options.preventUpdate && ((_b = (_a = options.preventUpdate).includes) == null ? void 0 : _b.call(_a, "content")))
|
|
58
56
|
return;
|
|
59
57
|
if (options.routerContentElement && options.lastElement) {
|
|
60
58
|
if (options.routerContentElement !== options.lastElement.content) return;
|
|
61
59
|
}
|
|
62
|
-
const content = (0, import_utils.setContentKey)(element, options);
|
|
63
|
-
const __contentRef = content && content.__ref;
|
|
64
60
|
const lazyLoad = element.props && element.props.lazyLoad;
|
|
65
61
|
const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
|
|
66
62
|
if (options.preventContentUpdate === true && !hasCollection) return;
|
|
67
|
-
if (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && (0, import_utils.deepContains)(params, content)) {
|
|
68
|
-
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
69
|
-
const beforeUpdateReturns = await (0, import_event.triggerEventOnUpdate)(
|
|
70
|
-
"beforeUpdate",
|
|
71
|
-
params,
|
|
72
|
-
element,
|
|
73
|
-
options
|
|
74
|
-
);
|
|
75
|
-
if (beforeUpdateReturns === false) return element;
|
|
76
|
-
}
|
|
77
|
-
if (content == null ? void 0 : content.update) await content.update();
|
|
78
|
-
if (!options.preventUpdateListener)
|
|
79
|
-
await (0, import_event.triggerEventOn)("update", element, options);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
63
|
if (params) {
|
|
83
64
|
let { childExtend, props } = params;
|
|
84
65
|
if (!props) props = params.props = {};
|
package/dist/cjs/update.js
CHANGED
|
@@ -50,12 +50,24 @@ const update = async function(params = {}, opts) {
|
|
|
50
50
|
(0, import_utils.isObject)(opts) ? (0, import_utils2.deepMerge)(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
|
|
51
51
|
{ exclude: ["calleeElement"] }
|
|
52
52
|
);
|
|
53
|
-
options.calleeElement = calleeElementCache;
|
|
54
53
|
const element = this;
|
|
54
|
+
options.calleeElement = calleeElementCache || this;
|
|
55
55
|
const { parent, node, key } = element;
|
|
56
56
|
const { excludes, preventInheritAtCurrentState } = options;
|
|
57
57
|
let ref = element.__ref;
|
|
58
58
|
if (!ref) ref = element.__ref = {};
|
|
59
|
+
if (this === options.calleeElement && !options.allowStorm) {
|
|
60
|
+
if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
|
|
61
|
+
else ref.__selfCallIteration++;
|
|
62
|
+
if (ref.__selfCallIteration > 100) {
|
|
63
|
+
ref.__selfCallIteration = 0;
|
|
64
|
+
return this.error("Potential self calling loop in update detected", opts);
|
|
65
|
+
}
|
|
66
|
+
const stormTimeout = setTimeout(() => {
|
|
67
|
+
ref.__selfCallIteration = 0;
|
|
68
|
+
clearTimeout(stormTimeout);
|
|
69
|
+
}, 350);
|
|
70
|
+
}
|
|
59
71
|
const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
|
|
60
72
|
element,
|
|
61
73
|
options
|
|
@@ -116,7 +128,8 @@ const update = async function(params = {}, opts) {
|
|
|
116
128
|
options.preventUpdateAfterCount = 1;
|
|
117
129
|
else options.preventUpdateAfterCount++;
|
|
118
130
|
}
|
|
119
|
-
|
|
131
|
+
const keys = Object.keys(element);
|
|
132
|
+
for (const param of keys) {
|
|
120
133
|
const prop = element[param];
|
|
121
134
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
122
135
|
const isInPreventUpdate = (0, import_utils.isArray)(preventUpdate) && preventUpdate.includes(param);
|
|
@@ -272,7 +285,7 @@ const inheritStateUpdates = async (element, options) => {
|
|
|
272
285
|
};
|
|
273
286
|
const createStateUpdate = async (element, parent, options) => {
|
|
274
287
|
const __stateChildren = element.state.__children;
|
|
275
|
-
const newState = await (0, import_state.createState)(element, parent);
|
|
288
|
+
const newState = await (0, import_state.createState)(element, parent, options);
|
|
276
289
|
element.state = newState;
|
|
277
290
|
for (const child in __stateChildren) {
|
|
278
291
|
if (newState[child]) newState.__children[child] = __stateChildren[child];
|
package/dist/esm/create.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { applyAnimationFrame, triggerEventOn } from "@domql/event";
|
|
22
22
|
import { assignNode } from "@domql/render";
|
|
23
23
|
import { createState } from "@domql/state";
|
|
24
|
-
import { isMethod } from "./methods/index.js";
|
|
24
|
+
import { error, isMethod } from "./methods/index.js";
|
|
25
25
|
import { createProps } from "./props/index.js";
|
|
26
26
|
import { applyExtend } from "./extend.js";
|
|
27
27
|
import { REGISTRY, registry } from "./mixins/index.js";
|
|
@@ -34,58 +34,68 @@ import {
|
|
|
34
34
|
createValidDomqlObjectFromSugar
|
|
35
35
|
} from "./utils/component.js";
|
|
36
36
|
import { isNotProduction } from "@domql/utils/env.js";
|
|
37
|
-
const create = async (element,
|
|
37
|
+
const create = async (element, parent2, key, options = OPTIONS.create || {}, attachOptions) => {
|
|
38
|
+
const isValid = validateElement(element, options);
|
|
39
|
+
if (!isValid) {
|
|
40
|
+
error.call(
|
|
41
|
+
element,
|
|
42
|
+
"Error while creating element: Not valid type",
|
|
43
|
+
element,
|
|
44
|
+
options
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
38
48
|
cacheOptions(element, options);
|
|
39
49
|
if (checkIfPrimitive(element)) {
|
|
40
|
-
element = applyValueAsText(element,
|
|
50
|
+
element = applyValueAsText(element, parent2, key);
|
|
41
51
|
}
|
|
42
|
-
element = redefineElement(element,
|
|
43
|
-
|
|
44
|
-
key = createKey(element,
|
|
45
|
-
const ref = addRef(element,
|
|
52
|
+
element = redefineElement(element, parent2, key, options);
|
|
53
|
+
parent2 = redefineParent(element, parent2, key);
|
|
54
|
+
key = createKey(element, parent2, key);
|
|
55
|
+
const ref = addRef(element, parent2, key);
|
|
46
56
|
ref.__initialProps = deepClone(element.props);
|
|
47
|
-
applyContext(element,
|
|
48
|
-
applyComponentFromContext(element,
|
|
57
|
+
applyContext(element, parent2, options);
|
|
58
|
+
applyComponentFromContext(element, parent2, options);
|
|
49
59
|
if (!ref.__skipCreate) {
|
|
50
|
-
applyExtend(element,
|
|
60
|
+
applyExtend(element, parent2, options);
|
|
51
61
|
}
|
|
52
62
|
element.key = key;
|
|
53
63
|
if (options.onlyResolveExtends) {
|
|
54
|
-
return await onlyResolveExtends(element,
|
|
64
|
+
return await onlyResolveExtends(element, parent2, key, options);
|
|
55
65
|
}
|
|
56
66
|
await triggerEventOn("start", element, options);
|
|
57
|
-
switchDefaultOptions(element,
|
|
58
|
-
addCaching(element,
|
|
59
|
-
addMethods(element,
|
|
60
|
-
createScope(element,
|
|
61
|
-
await createState(element,
|
|
67
|
+
switchDefaultOptions(element, parent2, options);
|
|
68
|
+
addCaching(element, parent2, options);
|
|
69
|
+
addMethods(element, parent2, options);
|
|
70
|
+
createScope(element, parent2, options);
|
|
71
|
+
await createState(element, parent2, options);
|
|
62
72
|
if (element.scope === "state") element.scope = element.state;
|
|
63
|
-
createIfConditionFlag(element,
|
|
64
|
-
createProps(element,
|
|
73
|
+
createIfConditionFlag(element, parent2);
|
|
74
|
+
createProps(element, parent2, options);
|
|
65
75
|
if (element.scope === "props" || element.scope === true)
|
|
66
76
|
element.scope = element.props;
|
|
67
|
-
createIfConditionFlag(element,
|
|
77
|
+
createIfConditionFlag(element, parent2);
|
|
68
78
|
if (element.node && ref.__if) {
|
|
69
|
-
return assignNode(element,
|
|
79
|
+
return assignNode(element, parent2, key, attachOptions);
|
|
70
80
|
}
|
|
71
|
-
applyVariant(element,
|
|
72
|
-
addChildrenIfNotInOriginal(element,
|
|
81
|
+
applyVariant(element, parent2);
|
|
82
|
+
addChildrenIfNotInOriginal(element, parent2, key);
|
|
73
83
|
const onInit = await triggerEventOn("init", element, options);
|
|
74
84
|
if (onInit === false) return element;
|
|
75
85
|
await triggerEventOn("beforeClassAssign", element, options);
|
|
76
86
|
assignKeyAsClassname(element);
|
|
77
|
-
await renderElement(element,
|
|
78
|
-
addElementIntoParentChildren(element,
|
|
87
|
+
await renderElement(element, parent2, options, attachOptions);
|
|
88
|
+
addElementIntoParentChildren(element, parent2);
|
|
79
89
|
await triggerEventOn("complete", element, options);
|
|
80
90
|
return element;
|
|
81
91
|
};
|
|
82
|
-
const createBasedOnType = (element,
|
|
92
|
+
const createBasedOnType = (element, parent2, key, options) => {
|
|
83
93
|
if (element === void 0) {
|
|
84
94
|
if (isNotProduction()) {
|
|
85
95
|
console.warn(
|
|
86
96
|
key,
|
|
87
97
|
"element is undefined in",
|
|
88
|
-
|
|
98
|
+
parent2 && parent2.__ref && parent2.__ref.path
|
|
89
99
|
);
|
|
90
100
|
}
|
|
91
101
|
return {};
|
|
@@ -100,30 +110,86 @@ const createBasedOnType = (element, parent, key, options) => {
|
|
|
100
110
|
if (element.__hash) {
|
|
101
111
|
return { extend: element };
|
|
102
112
|
}
|
|
113
|
+
if (typeof Node !== "undefined" && element instanceof Node || typeof DocumentFragment !== "undefined" && element instanceof DocumentFragment)
|
|
114
|
+
return { node: element };
|
|
103
115
|
return element;
|
|
104
116
|
};
|
|
105
|
-
const redefineElement = (element,
|
|
106
|
-
const elementWrapper = createBasedOnType(element,
|
|
107
|
-
if (options.syntaxv3 || element.props && element.props.syntaxv3 ||
|
|
117
|
+
const redefineElement = (element, parent2, key, options) => {
|
|
118
|
+
const elementWrapper = createBasedOnType(element, parent2, key, options);
|
|
119
|
+
if (options.syntaxv3 || element.props && element.props.syntaxv3 || parent2 && parent2.props && parent2.props.syntaxv3) {
|
|
108
120
|
if (element.props) element.props.syntaxv3 = true;
|
|
109
121
|
else element.syntaxv3 = true;
|
|
110
|
-
return createValidDomqlObjectFromSugar(element,
|
|
122
|
+
return createValidDomqlObjectFromSugar(element, parent2, key, options);
|
|
111
123
|
} else if (checkIfKeyIsComponent(key)) {
|
|
112
|
-
return applyKeyComponentAsExtend(elementWrapper,
|
|
124
|
+
return applyKeyComponentAsExtend(elementWrapper, parent2, key);
|
|
113
125
|
}
|
|
114
126
|
if (checkIfMedia(key)) {
|
|
115
|
-
return applyMediaProps(elementWrapper,
|
|
127
|
+
return applyMediaProps(elementWrapper, parent2, key);
|
|
116
128
|
}
|
|
117
129
|
return elementWrapper;
|
|
118
130
|
};
|
|
119
|
-
const redefineParent = (element,
|
|
120
|
-
if (!
|
|
121
|
-
if (isNode(
|
|
122
|
-
const parentNodeWrapper = { key: ":root", node:
|
|
131
|
+
const redefineParent = (element, parent2, key, options) => {
|
|
132
|
+
if (!parent2) return ROOT;
|
|
133
|
+
if (isNode(parent2)) {
|
|
134
|
+
const parentNodeWrapper = { key: ":root", node: parent2 };
|
|
123
135
|
ROOT[`${key}_parent`] = parentNodeWrapper;
|
|
124
136
|
return parentNodeWrapper;
|
|
125
137
|
}
|
|
126
|
-
return
|
|
138
|
+
return parent2;
|
|
139
|
+
};
|
|
140
|
+
const validateElement = (value, options) => {
|
|
141
|
+
if (value == null) return false;
|
|
142
|
+
const t = typeof value;
|
|
143
|
+
if (t === "function" || t === "symbol" || t === "bigint") return false;
|
|
144
|
+
if (Number.isNaN(value) || value === Infinity || value === -Infinity)
|
|
145
|
+
return false;
|
|
146
|
+
const unsafeGlobals = [
|
|
147
|
+
typeof window !== "undefined" && window,
|
|
148
|
+
typeof document !== "undefined" && document,
|
|
149
|
+
typeof globalThis !== "undefined" && globalThis,
|
|
150
|
+
typeof navigator !== "undefined" && navigator,
|
|
151
|
+
typeof location !== "undefined" && location,
|
|
152
|
+
typeof history !== "undefined" && history,
|
|
153
|
+
typeof screen !== "undefined" && screen,
|
|
154
|
+
typeof frames !== "undefined" && frames,
|
|
155
|
+
typeof parent !== "undefined" && parent,
|
|
156
|
+
typeof self !== "undefined" && self,
|
|
157
|
+
typeof top !== "undefined" && top,
|
|
158
|
+
typeof performance !== "undefined" && performance,
|
|
159
|
+
typeof console !== "undefined" && console,
|
|
160
|
+
typeof indexedDB !== "undefined" && indexedDB,
|
|
161
|
+
typeof caches !== "undefined" && caches,
|
|
162
|
+
typeof localStorage !== "undefined" && localStorage,
|
|
163
|
+
typeof sessionStorage !== "undefined" && sessionStorage,
|
|
164
|
+
typeof crypto !== "undefined" && crypto,
|
|
165
|
+
typeof visualViewport !== "undefined" && visualViewport,
|
|
166
|
+
typeof customElements !== "undefined" && customElements
|
|
167
|
+
].filter(Boolean);
|
|
168
|
+
if (unsafeGlobals.includes(value)) return false;
|
|
169
|
+
if (typeof EventTarget !== "undefined" && value instanceof EventTarget)
|
|
170
|
+
return false;
|
|
171
|
+
if (typeof Event !== "undefined" && value instanceof Event) return false;
|
|
172
|
+
if (value === Object.prototype || value === Array.prototype || value === Function.prototype || value === Map.prototype || value === Set.prototype || value === WeakMap.prototype || value === WeakSet.prototype || value === Promise.prototype || value === Symbol.prototype)
|
|
173
|
+
return false;
|
|
174
|
+
const unsafeConstructors = [
|
|
175
|
+
typeof Worker !== "undefined" && Worker,
|
|
176
|
+
typeof SharedWorker !== "undefined" && SharedWorker,
|
|
177
|
+
typeof MessagePort !== "undefined" && MessagePort,
|
|
178
|
+
typeof BroadcastChannel !== "undefined" && BroadcastChannel,
|
|
179
|
+
typeof ReadableStream !== "undefined" && ReadableStream,
|
|
180
|
+
typeof WritableStream !== "undefined" && WritableStream,
|
|
181
|
+
typeof TransformStream !== "undefined" && TransformStream,
|
|
182
|
+
typeof File !== "undefined" && File,
|
|
183
|
+
typeof Blob !== "undefined" && Blob,
|
|
184
|
+
typeof FormData !== "undefined" && FormData,
|
|
185
|
+
typeof XMLHttpRequest !== "undefined" && XMLHttpRequest,
|
|
186
|
+
typeof AbortController !== "undefined" && AbortController,
|
|
187
|
+
typeof AbortSignal !== "undefined" && AbortSignal
|
|
188
|
+
].filter(Boolean);
|
|
189
|
+
for (const Ctor of unsafeConstructors) {
|
|
190
|
+
if (value instanceof Ctor) return false;
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
127
193
|
};
|
|
128
194
|
const cacheOptions = (element, options) => {
|
|
129
195
|
if (options && !OPTIONS.create) {
|
|
@@ -131,26 +197,26 @@ const cacheOptions = (element, options) => {
|
|
|
131
197
|
OPTIONS.create.context = element.context || options.context;
|
|
132
198
|
}
|
|
133
199
|
};
|
|
134
|
-
const createKey = (element,
|
|
200
|
+
const createKey = (element, parent2, key) => {
|
|
135
201
|
return (exec(key, element) || key || element.key || generateKey()).toString();
|
|
136
202
|
};
|
|
137
|
-
const addRef = (element,
|
|
203
|
+
const addRef = (element, parent2) => {
|
|
138
204
|
if (element.__ref) element.__ref.origin = element;
|
|
139
205
|
else element.__ref = { origin: element };
|
|
140
206
|
return element.__ref;
|
|
141
207
|
};
|
|
142
|
-
const switchDefaultOptions = (element,
|
|
208
|
+
const switchDefaultOptions = (element, parent2, options) => {
|
|
143
209
|
if (Object.keys(options).length) {
|
|
144
210
|
registry.defaultOptions = options;
|
|
145
211
|
if (options.ignoreChildExtend) delete options.ignoreChildExtend;
|
|
146
212
|
}
|
|
147
213
|
};
|
|
148
|
-
const addElementIntoParentChildren = (element,
|
|
149
|
-
if (
|
|
150
|
-
|
|
214
|
+
const addElementIntoParentChildren = (element, parent2) => {
|
|
215
|
+
if (parent2.__ref && parent2.__ref.__children)
|
|
216
|
+
parent2.__ref.__children.push(element.key);
|
|
151
217
|
};
|
|
152
218
|
const visitedElements = /* @__PURE__ */ new WeakMap();
|
|
153
|
-
const renderElement = async (element,
|
|
219
|
+
const renderElement = async (element, parent2, options, attachOptions) => {
|
|
154
220
|
var _a, _b, _c, _d;
|
|
155
221
|
if (visitedElements.has(element)) {
|
|
156
222
|
if (isNotProduction())
|
|
@@ -195,10 +261,10 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
195
261
|
}
|
|
196
262
|
}
|
|
197
263
|
if (!ref.__if) {
|
|
198
|
-
|
|
264
|
+
parent2[key || element.key] = element;
|
|
199
265
|
return element;
|
|
200
266
|
}
|
|
201
|
-
assignNode(element,
|
|
267
|
+
assignNode(element, parent2, key, attachOptions);
|
|
202
268
|
applyAnimationFrame(element, options);
|
|
203
269
|
await triggerEventOn("render", element, options);
|
|
204
270
|
await triggerEventOn("renderRouter", element, options);
|
|
@@ -206,35 +272,35 @@ const renderElement = async (element, parent, options, attachOptions) => {
|
|
|
206
272
|
await triggerEventOn("create", element, options);
|
|
207
273
|
};
|
|
208
274
|
const checkIfPrimitive = (element) => is(element)("string", "number");
|
|
209
|
-
const applyValueAsText = (element,
|
|
275
|
+
const applyValueAsText = (element, parent2, key) => {
|
|
210
276
|
const extendTag = element.extend && element.extend.tag;
|
|
211
|
-
const childExtendTag =
|
|
212
|
-
const childPropsTag =
|
|
277
|
+
const childExtendTag = parent2.childExtend && parent2.childExtend.tag;
|
|
278
|
+
const childPropsTag = parent2.props.childProps && parent2.props.childProps.tag;
|
|
213
279
|
const isKeyValidHTMLTag = HTML_TAGS.body.indexOf(key) > -1 && key;
|
|
214
280
|
return {
|
|
215
281
|
text: element,
|
|
216
282
|
tag: extendTag || childExtendTag || childPropsTag || isKeyValidHTMLTag || "string"
|
|
217
283
|
};
|
|
218
284
|
};
|
|
219
|
-
const applyContext = (element,
|
|
285
|
+
const applyContext = (element, parent2, options) => {
|
|
220
286
|
const forcedOptionsContext = options.context && !ROOT.context && !element.context;
|
|
221
287
|
if (forcedOptionsContext) ROOT.context = options.context;
|
|
222
288
|
if (!element.context)
|
|
223
|
-
element.context =
|
|
289
|
+
element.context = parent2.context || options.context || ROOT.context;
|
|
224
290
|
};
|
|
225
|
-
const createScope = (element,
|
|
291
|
+
const createScope = (element, parent2) => {
|
|
226
292
|
const { __ref: ref } = element;
|
|
227
|
-
if (!element.scope) element.scope =
|
|
293
|
+
if (!element.scope) element.scope = parent2.scope || ref.root.scope || {};
|
|
228
294
|
};
|
|
229
|
-
const createIfConditionFlag = (element,
|
|
295
|
+
const createIfConditionFlag = (element, parent2) => {
|
|
230
296
|
const { __ref: ref } = element;
|
|
231
297
|
if (isFunction(element.if) && !element.if(element, element.state, element.context)) {
|
|
232
298
|
delete ref.__if;
|
|
233
299
|
} else ref.__if = true;
|
|
234
300
|
};
|
|
235
|
-
const addCaching = (element,
|
|
301
|
+
const addCaching = (element, parent2) => {
|
|
236
302
|
const { __ref: ref, key } = element;
|
|
237
|
-
let { __ref: parentRef } =
|
|
303
|
+
let { __ref: parentRef } = parent2;
|
|
238
304
|
if (!element.transform) element.transform = {};
|
|
239
305
|
if (!ref.__cached) ref.__cached = {};
|
|
240
306
|
if (!ref.__defineCache) ref.__defineCache = {};
|
|
@@ -247,30 +313,30 @@ const addCaching = (element, parent) => {
|
|
|
247
313
|
if (!ref.__children) ref.__children = [];
|
|
248
314
|
if (checkIfKeyIsComponent(key))
|
|
249
315
|
ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
|
|
250
|
-
const hasRoot =
|
|
316
|
+
const hasRoot = parent2 && parent2.key === ":root";
|
|
251
317
|
if (!ref.root) ref.root = hasRoot ? element : parentRef.root;
|
|
252
|
-
if (!parentRef) parentRef =
|
|
318
|
+
if (!parentRef) parentRef = parent2.ref = {};
|
|
253
319
|
if (!parentRef.path) parentRef.path = [];
|
|
254
320
|
ref.path = parentRef.path.concat(element.key);
|
|
255
321
|
};
|
|
256
|
-
const onlyResolveExtends = async (element,
|
|
322
|
+
const onlyResolveExtends = async (element, parent2, key, options) => {
|
|
257
323
|
const { __ref: ref } = element;
|
|
258
324
|
if (!ref.__skipCreate) {
|
|
259
|
-
addCaching(element,
|
|
260
|
-
addMethods(element,
|
|
261
|
-
createScope(element,
|
|
262
|
-
createState(element,
|
|
325
|
+
addCaching(element, parent2);
|
|
326
|
+
addMethods(element, parent2, options);
|
|
327
|
+
createScope(element, parent2);
|
|
328
|
+
createState(element, parent2, options);
|
|
263
329
|
if (element.scope === "state") element.scope = element.state;
|
|
264
|
-
createIfConditionFlag(element,
|
|
265
|
-
createProps(element,
|
|
330
|
+
createIfConditionFlag(element, parent2);
|
|
331
|
+
createProps(element, parent2, options);
|
|
266
332
|
if (element.scope === "props" || element.scope === true)
|
|
267
333
|
element.scope = element.props;
|
|
268
334
|
if (element.node && ref.__if) {
|
|
269
|
-
|
|
335
|
+
parent2[key || element.key] = element;
|
|
270
336
|
}
|
|
271
337
|
if (!element.props) element.props = {};
|
|
272
|
-
applyVariant(element,
|
|
273
|
-
addElementIntoParentChildren(element,
|
|
338
|
+
applyVariant(element, parent2);
|
|
339
|
+
addElementIntoParentChildren(element, parent2);
|
|
274
340
|
}
|
|
275
341
|
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
276
342
|
await throughInitialDefine(element);
|
|
@@ -288,7 +354,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
|
|
|
288
354
|
}
|
|
289
355
|
}
|
|
290
356
|
}
|
|
291
|
-
|
|
357
|
+
parent2[key || element.key] = element;
|
|
292
358
|
delete element.update;
|
|
293
359
|
delete element.__element;
|
|
294
360
|
if (element.props) {
|
|
@@ -298,7 +364,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
|
|
|
298
364
|
return element;
|
|
299
365
|
};
|
|
300
366
|
const checkIfMedia = (key) => key.slice(0, 1) === "@";
|
|
301
|
-
const applyMediaProps = (element,
|
|
367
|
+
const applyMediaProps = (element, parent2, key) => {
|
|
302
368
|
const { props } = element;
|
|
303
369
|
if (props) {
|
|
304
370
|
props.display = "none";
|
package/dist/esm/extend.js
CHANGED
package/dist/esm/iterate.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isVariant
|
|
10
10
|
} from "@domql/utils";
|
|
11
11
|
import { METHODS_EXL, overwrite } from "./utils/index.js";
|
|
12
|
-
import { isMethod } from "./methods/index.js";
|
|
12
|
+
import { isMethod, warn } from "./methods/index.js";
|
|
13
13
|
const throughInitialExec = async (element, exclude = {}) => {
|
|
14
14
|
const { __ref: ref } = element;
|
|
15
15
|
for (const param in element) {
|
|
@@ -53,6 +53,8 @@ const throughExecProps = (element) => {
|
|
|
53
53
|
const { props } = element;
|
|
54
54
|
for (const k in props) {
|
|
55
55
|
const isDefine = k.startsWith("is") || k.startsWith("has") || k.startsWith("use");
|
|
56
|
+
if (!ref.__execProps)
|
|
57
|
+
return warn.call(element, "Element was not initiated to execute props");
|
|
56
58
|
const cachedExecProp = ref.__execProps[k];
|
|
57
59
|
if (isFunction(cachedExecProp)) {
|
|
58
60
|
props[k] = exec(cachedExecProp, element);
|
|
@@ -58,6 +58,12 @@ function lookdown(param) {
|
|
|
58
58
|
);
|
|
59
59
|
if (v === param) return childElem;
|
|
60
60
|
else if (isFunction(param)) {
|
|
61
|
+
if (!childElem) {
|
|
62
|
+
this.error(
|
|
63
|
+
`"${v}" found in element __children, but content is not defined`
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
61
67
|
const exec = param(childElem, childElem.state, childElem.context);
|
|
62
68
|
if (childElem.state && exec) {
|
|
63
69
|
return childElem;
|
|
@@ -78,6 +84,12 @@ function lookdownAll(param, results = []) {
|
|
|
78
84
|
const childElem = el[v];
|
|
79
85
|
if (v === param) results.push(childElem);
|
|
80
86
|
else if (isFunction(param)) {
|
|
87
|
+
if (!childElem) {
|
|
88
|
+
this.error(
|
|
89
|
+
`"${v}" found in element __children, but content is not defined`
|
|
90
|
+
);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
81
93
|
const exec = param(childElem, childElem.state, childElem.context);
|
|
82
94
|
if (childElem.state && exec) results.push(childElem);
|
|
83
95
|
}
|
|
@@ -97,7 +109,7 @@ function setNodeStyles(params = {}) {
|
|
|
97
109
|
}
|
|
98
110
|
return el;
|
|
99
111
|
}
|
|
100
|
-
async function remove(opts) {
|
|
112
|
+
async function remove(opts = {}) {
|
|
101
113
|
const element = this;
|
|
102
114
|
const beforeRemoveReturns = triggerEventOn("beforeRemove", element, opts);
|
|
103
115
|
if (beforeRemoveReturns === false) return element;
|
|
@@ -118,10 +130,10 @@ function get(param) {
|
|
|
118
130
|
const element = this;
|
|
119
131
|
return element[param];
|
|
120
132
|
}
|
|
121
|
-
function setProps(param,
|
|
133
|
+
function setProps(param, opts = {}) {
|
|
122
134
|
const element = this;
|
|
123
135
|
if (!param || !element.props) return;
|
|
124
|
-
element.update({ props: param },
|
|
136
|
+
element.update({ props: param }, opts);
|
|
125
137
|
return element;
|
|
126
138
|
}
|
|
127
139
|
function getRef(key) {
|
|
@@ -212,9 +224,11 @@ function warn(...params) {
|
|
|
212
224
|
console.warn(...params, this);
|
|
213
225
|
}
|
|
214
226
|
function error(...params) {
|
|
215
|
-
var _a, _b;
|
|
227
|
+
var _a, _b, _c, _d;
|
|
216
228
|
if ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
|
|
217
229
|
if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this, ...params);
|
|
230
|
+
if (isFunction((_c = params[params.length - 1]) == null ? void 0 : _c.onError))
|
|
231
|
+
(_d = params[params.length - 1]) == null ? void 0 : _d.onError.call(this, ...params);
|
|
218
232
|
console.error(...params, this);
|
|
219
233
|
}
|
|
220
234
|
function nextElement() {
|
|
@@ -225,8 +239,8 @@ function nextElement() {
|
|
|
225
239
|
const nextChild = __children[currentIndex + 1];
|
|
226
240
|
return parent[nextChild];
|
|
227
241
|
}
|
|
228
|
-
async function append(el, key) {
|
|
229
|
-
return await create(el, this, key);
|
|
242
|
+
async function append(el, key, opts) {
|
|
243
|
+
return await create(el, this, key, opts);
|
|
230
244
|
}
|
|
231
245
|
function previousElement(el) {
|
|
232
246
|
const element = el || this;
|
|
@@ -277,8 +291,8 @@ function call(fnKey, ...args) {
|
|
|
277
291
|
}
|
|
278
292
|
return result;
|
|
279
293
|
} catch (error2) {
|
|
280
|
-
console.error(`Error calling '${fnKey}'
|
|
281
|
-
throw error2;
|
|
294
|
+
console.error(`Error calling '${fnKey}'`);
|
|
295
|
+
throw new Error(error2);
|
|
282
296
|
}
|
|
283
297
|
}
|
|
284
298
|
const METHODS = [
|
|
@@ -30,7 +30,7 @@ const removeContent = function(el, opts = {}) {
|
|
|
30
30
|
else if (__cached[contentElementKey] && isFunction(__cached[contentElementKey].remove))
|
|
31
31
|
__cached[contentElementKey].remove();
|
|
32
32
|
}
|
|
33
|
-
ref.__children.splice(ref.__children.indexOf(
|
|
33
|
+
ref.__children.splice(ref.__children.indexOf(contentElementKey), 1);
|
|
34
34
|
delete element[contentElementKey];
|
|
35
35
|
}
|
|
36
36
|
};
|
package/dist/esm/node.js
CHANGED
|
@@ -43,11 +43,15 @@ const createNode = async (element, options) => {
|
|
|
43
43
|
applyEventsOnNode(element, options);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
const keys = Object.keys(element);
|
|
47
|
+
for (const param of keys) {
|
|
47
48
|
const value = element[param];
|
|
48
49
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
49
50
|
if (isUndefined(value) || isMethod(param, element) || isVariant(param) || isObject(REGISTRY[param]))
|
|
50
51
|
continue;
|
|
52
|
+
if (param === "onClick") {
|
|
53
|
+
debugger;
|
|
54
|
+
}
|
|
51
55
|
const isElement = await applyParam(param, element, options);
|
|
52
56
|
if (!isElement) continue;
|
|
53
57
|
const { hasDefine, hasContextDefine } = isElement;
|
package/dist/esm/set.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepContains, setContentKey } from "@domql/utils";
|
|
1
|
+
import { deepClone, deepContains, setContentKey } from "@domql/utils";
|
|
2
2
|
import { OPTIONS } from "./cache/options.js";
|
|
3
3
|
import { create } from "./create.js";
|
|
4
4
|
import { registry } from "./mixins/index.js";
|
|
@@ -7,7 +7,6 @@ import { triggerEventOn, triggerEventOnUpdate } from "@domql/event";
|
|
|
7
7
|
const resetElement = async (params, element, options) => {
|
|
8
8
|
if (!options.preventRemove) removeContent(element, options);
|
|
9
9
|
const { __ref: ref } = element;
|
|
10
|
-
if (params instanceof Promise) console.log(params, params instanceof Promise);
|
|
11
10
|
await create(params, element, ref.contentElementKey || "content", {
|
|
12
11
|
ignoreChildExtend: true,
|
|
13
12
|
...registry.defaultOptions,
|
|
@@ -27,32 +26,14 @@ const reset = async (options) => {
|
|
|
27
26
|
const set = async function(params, options = {}, el) {
|
|
28
27
|
var _a, _b, _c;
|
|
29
28
|
const element = el || this;
|
|
30
|
-
const { __ref: ref } = element;
|
|
31
29
|
if (options.preventContentUpdate || options.preventUpdate && ((_b = (_a = options.preventUpdate).includes) == null ? void 0 : _b.call(_a, "content")))
|
|
32
30
|
return;
|
|
33
31
|
if (options.routerContentElement && options.lastElement) {
|
|
34
32
|
if (options.routerContentElement !== options.lastElement.content) return;
|
|
35
33
|
}
|
|
36
|
-
const content = setContentKey(element, options);
|
|
37
|
-
const __contentRef = content && content.__ref;
|
|
38
34
|
const lazyLoad = element.props && element.props.lazyLoad;
|
|
39
35
|
const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
|
|
40
36
|
if (options.preventContentUpdate === true && !hasCollection) return;
|
|
41
|
-
if (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && deepContains(params, content)) {
|
|
42
|
-
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
43
|
-
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
44
|
-
"beforeUpdate",
|
|
45
|
-
params,
|
|
46
|
-
element,
|
|
47
|
-
options
|
|
48
|
-
);
|
|
49
|
-
if (beforeUpdateReturns === false) return element;
|
|
50
|
-
}
|
|
51
|
-
if (content == null ? void 0 : content.update) await content.update();
|
|
52
|
-
if (!options.preventUpdateListener)
|
|
53
|
-
await triggerEventOn("update", element, options);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
37
|
if (params) {
|
|
57
38
|
let { childExtend, props } = params;
|
|
58
39
|
if (!props) props = params.props = {};
|
package/dist/esm/update.js
CHANGED
|
@@ -44,12 +44,24 @@ const update = async function(params = {}, opts) {
|
|
|
44
44
|
isObject(opts) ? deepMerge(opts, UPDATE_DEFAULT_OPTIONS) : UPDATE_DEFAULT_OPTIONS,
|
|
45
45
|
{ exclude: ["calleeElement"] }
|
|
46
46
|
);
|
|
47
|
-
options.calleeElement = calleeElementCache;
|
|
48
47
|
const element = this;
|
|
48
|
+
options.calleeElement = calleeElementCache || this;
|
|
49
49
|
const { parent, node, key } = element;
|
|
50
50
|
const { excludes, preventInheritAtCurrentState } = options;
|
|
51
51
|
let ref = element.__ref;
|
|
52
52
|
if (!ref) ref = element.__ref = {};
|
|
53
|
+
if (this === options.calleeElement && !options.allowStorm) {
|
|
54
|
+
if (ref.__selfCallIteration === void 0) ref.__selfCallIteration = 0;
|
|
55
|
+
else ref.__selfCallIteration++;
|
|
56
|
+
if (ref.__selfCallIteration > 100) {
|
|
57
|
+
ref.__selfCallIteration = 0;
|
|
58
|
+
return this.error("Potential self calling loop in update detected", opts);
|
|
59
|
+
}
|
|
60
|
+
const stormTimeout = setTimeout(() => {
|
|
61
|
+
ref.__selfCallIteration = 0;
|
|
62
|
+
clearTimeout(stormTimeout);
|
|
63
|
+
}, 350);
|
|
64
|
+
}
|
|
53
65
|
const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(
|
|
54
66
|
element,
|
|
55
67
|
options
|
|
@@ -110,7 +122,8 @@ const update = async function(params = {}, opts) {
|
|
|
110
122
|
options.preventUpdateAfterCount = 1;
|
|
111
123
|
else options.preventUpdateAfterCount++;
|
|
112
124
|
}
|
|
113
|
-
|
|
125
|
+
const keys = Object.keys(element);
|
|
126
|
+
for (const param of keys) {
|
|
114
127
|
const prop = element[param];
|
|
115
128
|
if (!Object.hasOwnProperty.call(element, param)) continue;
|
|
116
129
|
const isInPreventUpdate = isArray(preventUpdate) && preventUpdate.includes(param);
|
|
@@ -266,7 +279,7 @@ const inheritStateUpdates = async (element, options) => {
|
|
|
266
279
|
};
|
|
267
280
|
const createStateUpdate = async (element, parent, options) => {
|
|
268
281
|
const __stateChildren = element.state.__children;
|
|
269
|
-
const newState = await createState(element, parent);
|
|
282
|
+
const newState = await createState(element, parent, options);
|
|
270
283
|
element.state = newState;
|
|
271
284
|
for (const child in __stateChildren) {
|
|
272
285
|
if (newState[child]) newState.__children[child] = __stateChildren[child];
|