@domql/utils 2.5.187 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +30 -16
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +16 -226
- package/dist/cjs/cookie.js +19 -24
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/function.js +2 -4
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +25 -15
- package/dist/cjs/key.js +6 -1
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/log.js +1 -2
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +89 -237
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -16
- package/dist/cjs/types.js +2 -4
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +30 -16
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +17 -245
- package/dist/esm/cookie.js +19 -24
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/function.js +2 -4
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +6 -1
- package/dist/esm/keys.js +158 -0
- package/dist/esm/log.js +1 -2
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +90 -239
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -16
- package/dist/esm/types.js +2 -4
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +121 -235
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/dist/esm/component.js
CHANGED
|
@@ -1,255 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { joinArrays } from "./array.js";
|
|
21
|
-
import { deepClone, exec } from "./object.js";
|
|
22
|
-
import { isArray, isFunction, isObject, isString } from "./types.js";
|
|
23
|
-
const ENV = "development";
|
|
24
|
-
const checkIfKeyIsComponent = (key) => {
|
|
1
|
+
import { createExtendsFromKeys } from "./extends.js";
|
|
2
|
+
import { isString } from "./types.js";
|
|
3
|
+
const matchesComponentNaming = (key) => {
|
|
25
4
|
const isFirstKeyString = isString(key);
|
|
26
|
-
if (!isFirstKeyString)
|
|
27
|
-
return;
|
|
5
|
+
if (!isFirstKeyString) return;
|
|
28
6
|
const firstCharKey = key.slice(0, 1);
|
|
29
7
|
return /^[A-Z]*$/.test(firstCharKey);
|
|
30
8
|
};
|
|
31
|
-
const checkIfKeyIsProperty = (key) => {
|
|
32
|
-
const isFirstKeyString = isString(key);
|
|
33
|
-
if (!isFirstKeyString)
|
|
34
|
-
return;
|
|
35
|
-
const firstCharKey = key.slice(0, 1);
|
|
36
|
-
return /^[a-z]*$/.test(firstCharKey);
|
|
37
|
-
};
|
|
38
|
-
const addAdditionalExtend = (newExtend, element) => {
|
|
39
|
-
if (!newExtend)
|
|
40
|
-
return element;
|
|
41
|
-
const { extend: elementExtend } = element;
|
|
42
|
-
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend];
|
|
43
|
-
const receivedArray = isArray(newExtend) ? newExtend : [newExtend];
|
|
44
|
-
const extend = joinArrays(receivedArray, originalArray);
|
|
45
|
-
return __spreadProps(__spreadValues({}, element), { extend });
|
|
46
|
-
};
|
|
47
|
-
const checkIfSugar = (element, parent, key) => {
|
|
48
|
-
var _a;
|
|
49
|
-
const {
|
|
50
|
-
extend,
|
|
51
|
-
props,
|
|
52
|
-
childExtend,
|
|
53
|
-
extends: extendProps,
|
|
54
|
-
childExtends,
|
|
55
|
-
childProps,
|
|
56
|
-
children,
|
|
57
|
-
on,
|
|
58
|
-
$collection,
|
|
59
|
-
$stateCollection,
|
|
60
|
-
$propsCollection
|
|
61
|
-
} = element;
|
|
62
|
-
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
|
|
63
|
-
if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
|
|
64
|
-
const logErr = (_a = parent || element) == null ? void 0 : _a.error;
|
|
65
|
-
if (logErr)
|
|
66
|
-
logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
|
|
67
|
-
}
|
|
68
|
-
return !hasComponentAttrs || childProps || extendProps || children || childExtends;
|
|
69
|
-
};
|
|
70
|
-
const extractComponentKeyFromKey = (key) => {
|
|
71
|
-
return key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
|
|
72
|
-
};
|
|
73
|
-
const extendizeByKey = (element, parent, key) => {
|
|
74
|
-
const { context } = parent;
|
|
75
|
-
const { tag, extend, childExtends } = element;
|
|
76
|
-
const isSugar = checkIfSugar(element, parent, key);
|
|
77
|
-
const extendFromKey = extractComponentKeyFromKey(key);
|
|
78
|
-
const isExtendKeyComponent = context && context.components[extendFromKey];
|
|
79
|
-
if (element === isExtendKeyComponent)
|
|
80
|
-
return element;
|
|
81
|
-
else if (isSugar) {
|
|
82
|
-
const newElem = addAdditionalExtend(element.extends, {
|
|
83
|
-
extend: extendFromKey,
|
|
84
|
-
tag,
|
|
85
|
-
props: __spreadValues({}, element)
|
|
86
|
-
});
|
|
87
|
-
if (newElem.props.data) {
|
|
88
|
-
newElem.data = newElem.props.data;
|
|
89
|
-
delete newElem.props.data;
|
|
90
|
-
}
|
|
91
|
-
if (newElem.props.state) {
|
|
92
|
-
newElem.state = newElem.props.state;
|
|
93
|
-
delete newElem.props.state;
|
|
94
|
-
}
|
|
95
|
-
if (newElem.props.attr) {
|
|
96
|
-
newElem.attr = newElem.props.attr;
|
|
97
|
-
delete newElem.props.attr;
|
|
98
|
-
}
|
|
99
|
-
if (newElem.props.if) {
|
|
100
|
-
newElem.if = newElem.props.if;
|
|
101
|
-
delete newElem.props.if;
|
|
102
|
-
}
|
|
103
|
-
if (childExtends)
|
|
104
|
-
newElem.childExtend = childExtends;
|
|
105
|
-
return newElem;
|
|
106
|
-
} else if (!extend || extend === true) {
|
|
107
|
-
return __spreadProps(__spreadValues({}, element), {
|
|
108
|
-
tag,
|
|
109
|
-
extend: extendFromKey
|
|
110
|
-
});
|
|
111
|
-
} else if (extend) {
|
|
112
|
-
return addAdditionalExtend(extendFromKey, element);
|
|
113
|
-
} else if (isFunction(element)) {
|
|
114
|
-
return {
|
|
115
|
-
extend: extendFromKey,
|
|
116
|
-
tag,
|
|
117
|
-
props: __spreadValues({}, exec(element, parent))
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
9
|
function getCapitalCaseKeys(obj) {
|
|
122
10
|
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
123
11
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
delete element.props[childKey];
|
|
135
|
-
};
|
|
136
|
-
if (newChild == null ? void 0 : newChild.ignoreExtend)
|
|
137
|
-
continue;
|
|
138
|
-
if (newChild === null)
|
|
139
|
-
assignChild(null);
|
|
140
|
-
else if (!childElem)
|
|
141
|
-
assignChild(deepClone(newChild));
|
|
142
|
-
else {
|
|
143
|
-
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
144
|
-
if (isSugarChildElem)
|
|
145
|
-
continue;
|
|
146
|
-
assignChild({
|
|
147
|
-
extend: element[childKey],
|
|
148
|
-
props: newChild
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
154
|
-
return extendizeByKey(element, parent, key) || element;
|
|
155
|
-
};
|
|
156
|
-
const applyComponentFromContext = (element, parent, options) => {
|
|
157
|
-
const { context } = element;
|
|
158
|
-
if (!context || !context.components)
|
|
159
|
-
return;
|
|
160
|
-
const { components } = context;
|
|
161
|
-
const { extend } = element;
|
|
162
|
-
const execExtend = exec(extend, element);
|
|
163
|
-
if (isString(execExtend)) {
|
|
164
|
-
const componentExists = components[execExtend] || components["smbls." + execExtend];
|
|
165
|
-
if (componentExists)
|
|
166
|
-
element.extend = componentExists;
|
|
167
|
-
else {
|
|
168
|
-
if ((ENV === "test" || ENV === "development") && options.verbose) {
|
|
169
|
-
console.warn(execExtend, "is not in library", components, element);
|
|
170
|
-
console.warn("replacing with ", {});
|
|
171
|
-
}
|
|
172
|
-
element.extend = {};
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
const isVariant = (param) => {
|
|
177
|
-
if (!isString(param))
|
|
178
|
-
return;
|
|
179
|
-
const firstCharKey = param.slice(0, 1);
|
|
180
|
-
return firstCharKey === ".";
|
|
181
|
-
};
|
|
182
|
-
const hasVariantProp = (element) => {
|
|
183
|
-
const { props } = element;
|
|
184
|
-
if (isObject(props) && isString(props.variant))
|
|
185
|
-
return true;
|
|
186
|
-
};
|
|
187
|
-
const getChildrenComponentsByKey = (key, el) => {
|
|
188
|
-
if (key === el.key || el.__ref.__componentKey === key) {
|
|
189
|
-
return el;
|
|
190
|
-
}
|
|
191
|
-
if (el.extend) {
|
|
192
|
-
const foundString = isString(el.extend) && el.extend === key;
|
|
193
|
-
const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length;
|
|
194
|
-
if (foundString || foundInArray)
|
|
195
|
-
return el;
|
|
196
|
-
}
|
|
197
|
-
if (el.parent && el.parent.childExtend) {
|
|
198
|
-
const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key;
|
|
199
|
-
const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
|
|
200
|
-
if (foundString || foundInArray)
|
|
201
|
-
return el;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
const getExtendsInElement = (obj) => {
|
|
205
|
-
let result = [];
|
|
206
|
-
function traverse(o) {
|
|
207
|
-
for (const key in o) {
|
|
208
|
-
if (Object.hasOwnProperty.call(o, key)) {
|
|
209
|
-
if (checkIfKeyIsComponent(key)) {
|
|
210
|
-
result.push(key);
|
|
211
|
-
}
|
|
212
|
-
if (key === "extend" || key === "extends") {
|
|
213
|
-
if (typeof o[key] === "string") {
|
|
214
|
-
result.push(o[key]);
|
|
215
|
-
} else if (Array.isArray(o[key])) {
|
|
216
|
-
result = result.concat(o[key]);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (typeof o[key] === "object" && o[key] !== null) {
|
|
220
|
-
traverse(o[key]);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
traverse(obj);
|
|
226
|
-
return result;
|
|
227
|
-
};
|
|
228
|
-
const setContentKey = (el, opts = {}) => {
|
|
229
|
-
const { __ref: ref } = el;
|
|
230
|
-
const contentElementKey = opts.contentElementKey;
|
|
231
|
-
if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
|
|
232
|
-
ref.contentElementKey = contentElementKey || "content";
|
|
233
|
-
} else
|
|
234
|
-
ref.contentElementKey = "content";
|
|
235
|
-
if (contentElementKey !== "content")
|
|
236
|
-
opts.contentElementKey = "content";
|
|
237
|
-
return ref.contentElementKey;
|
|
238
|
-
};
|
|
12
|
+
function getSpreadChildren(obj) {
|
|
13
|
+
return Object.keys(obj).filter((key) => /^\d+$/.test(key));
|
|
14
|
+
}
|
|
15
|
+
function isContextComponent(element, parent, passedKey) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const { context } = parent || {};
|
|
18
|
+
const [extendsKey] = createExtendsFromKeys(passedKey);
|
|
19
|
+
const key = passedKey || extendsKey;
|
|
20
|
+
return ((_a = context == null ? void 0 : context.components) == null ? void 0 : _a[key]) || ((_b = context == null ? void 0 : context.pages) == null ? void 0 : _b[key]);
|
|
21
|
+
}
|
|
239
22
|
export {
|
|
240
|
-
addAdditionalExtend,
|
|
241
|
-
addChildrenIfNotInOriginal,
|
|
242
|
-
applyComponentFromContext,
|
|
243
|
-
applyKeyComponentAsExtend,
|
|
244
|
-
checkIfKeyIsComponent,
|
|
245
|
-
checkIfKeyIsProperty,
|
|
246
|
-
checkIfSugar,
|
|
247
|
-
extendizeByKey,
|
|
248
|
-
extractComponentKeyFromKey,
|
|
249
23
|
getCapitalCaseKeys,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
isVariant,
|
|
254
|
-
setContentKey
|
|
24
|
+
getSpreadChildren,
|
|
25
|
+
isContextComponent,
|
|
26
|
+
matchesComponentNaming
|
|
255
27
|
};
|
package/dist/esm/cookie.js
CHANGED
|
@@ -2,53 +2,48 @@ import { isUndefined } from "./types.js";
|
|
|
2
2
|
import { document } from "./globals.js";
|
|
3
3
|
const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
|
|
4
4
|
const setCookie = (cname, cvalue, exdays = 365) => {
|
|
5
|
-
if (isUndefined(document) || isUndefined(document.cookie))
|
|
6
|
-
return;
|
|
5
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
7
6
|
const d = /* @__PURE__ */ new Date();
|
|
8
7
|
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
|
|
9
8
|
const expires = `expires=${d.toUTCString()}`;
|
|
10
9
|
document.cookie = `${cname}=${cvalue};${expires};path=/`;
|
|
11
10
|
};
|
|
12
11
|
const getCookie = (cname) => {
|
|
13
|
-
if (isUndefined(document) || isUndefined(document.cookie))
|
|
14
|
-
return;
|
|
12
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
15
13
|
const name = `${cname}=`;
|
|
16
14
|
const decodedCookie = decodeURIComponent(document.cookie);
|
|
17
15
|
const ca = decodedCookie.split(";");
|
|
18
16
|
for (let i = 0; i < ca.length; i++) {
|
|
19
17
|
let c = ca[i];
|
|
20
|
-
while (c.charAt(0) === " ")
|
|
21
|
-
|
|
22
|
-
if (c.indexOf(name) === 0)
|
|
23
|
-
return c.substring(name.length, c.length);
|
|
18
|
+
while (c.charAt(0) === " ") c = c.substring(1);
|
|
19
|
+
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
|
|
24
20
|
}
|
|
25
21
|
return "";
|
|
26
22
|
};
|
|
27
23
|
const removeCookie = (cname) => {
|
|
28
|
-
if (isUndefined(document) || isUndefined(document.cookie))
|
|
29
|
-
return;
|
|
24
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
30
25
|
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
31
26
|
};
|
|
32
27
|
function getLocalStorage(key) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
savedJSON = JSON.parse(window.localStorage.getItem(key));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
}
|
|
28
|
+
if (!window.localStorage) {
|
|
29
|
+
return void 0;
|
|
39
30
|
}
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
const item = window.localStorage.getItem(key);
|
|
32
|
+
if (item === null) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(item);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return void 0;
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
function setLocalStorage(key, data) {
|
|
45
|
-
if (data
|
|
46
|
-
|
|
47
|
-
window.localStorage.setItem(key, JSON.stringify(data));
|
|
48
|
-
} else {
|
|
49
|
-
window.localStorage.setItem(key, data);
|
|
50
|
-
}
|
|
42
|
+
if (!window.localStorage || data === void 0 || data === null) {
|
|
43
|
+
return;
|
|
51
44
|
}
|
|
45
|
+
const value = typeof data === "object" ? JSON.stringify(data) : data;
|
|
46
|
+
window.localStorage.setItem(key, value);
|
|
52
47
|
}
|
|
53
48
|
export {
|
|
54
49
|
getCookie,
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { createExtends } from "./extends.js";
|
|
21
|
+
import { createKey } from "./key.js";
|
|
22
|
+
import { isNode } from "./node.js";
|
|
23
|
+
import { createProps } from "./props.js";
|
|
24
|
+
import { HTML_TAGS } from "./tags.js";
|
|
25
|
+
import { is, isFunction } from "./types.js";
|
|
26
|
+
const ENV = "development";
|
|
27
|
+
const returnValueAsText = (element, parent, key) => {
|
|
28
|
+
const childExtendsTag = parent.childExtends && parent.childExtends.tag;
|
|
29
|
+
const childPropsTag = parent.props.childProps && parent.props.childProps.tag;
|
|
30
|
+
const isKeyValidHTMLTag = HTML_TAGS.body.indexOf(key) > -1 && key;
|
|
31
|
+
return {
|
|
32
|
+
text: element,
|
|
33
|
+
tag: childExtendsTag || childPropsTag || isKeyValidHTMLTag || "string"
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const createBasedOnType = (element, parent, key) => {
|
|
37
|
+
if (element === void 0) {
|
|
38
|
+
if (ENV === "test" || ENV === "development") {
|
|
39
|
+
console.warn(
|
|
40
|
+
key,
|
|
41
|
+
"element is undefined in",
|
|
42
|
+
parent && parent.__ref && parent.__ref.path
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
if (element === null) return;
|
|
48
|
+
if (element === true) return {};
|
|
49
|
+
if (is(element)("string", "number")) {
|
|
50
|
+
return returnValueAsText(element, parent, key);
|
|
51
|
+
}
|
|
52
|
+
if (isFunction(element)) {
|
|
53
|
+
return { props: element };
|
|
54
|
+
}
|
|
55
|
+
return element;
|
|
56
|
+
};
|
|
57
|
+
const addRef = (element, parent) => {
|
|
58
|
+
const ref = {};
|
|
59
|
+
ref.origin = element;
|
|
60
|
+
ref.parent = parent;
|
|
61
|
+
return ref;
|
|
62
|
+
};
|
|
63
|
+
const createParent = (element, parent, key, options, root) => {
|
|
64
|
+
if (!parent) return root;
|
|
65
|
+
if (isNode(parent)) {
|
|
66
|
+
const parentNodeWrapper = { key: ":root", node: parent };
|
|
67
|
+
root[`${key}_parent`] = parentNodeWrapper;
|
|
68
|
+
return parentNodeWrapper;
|
|
69
|
+
}
|
|
70
|
+
return parent;
|
|
71
|
+
};
|
|
72
|
+
const createRoot = (element, parent) => {
|
|
73
|
+
const { __ref: ref } = element;
|
|
74
|
+
const { __ref: parentRef } = parent;
|
|
75
|
+
const hasRoot = parent && parent.key === ":root";
|
|
76
|
+
if (!(ref == null ? void 0 : ref.root)) {
|
|
77
|
+
return hasRoot ? element : parentRef == null ? void 0 : parentRef.root;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const createPath = (element, parent, key) => {
|
|
81
|
+
let { __ref: parentRef } = parent;
|
|
82
|
+
if (!parentRef) parentRef = parent.ref = {};
|
|
83
|
+
if (!parentRef.path) parentRef.path = [];
|
|
84
|
+
return parentRef.path.concat(key);
|
|
85
|
+
};
|
|
86
|
+
const addContext = (element, parent, key, options, root) => {
|
|
87
|
+
const forcedOptionsContext = options.context && !root.context && !element.context;
|
|
88
|
+
if (forcedOptionsContext) root.context = options.context;
|
|
89
|
+
return options.context || parent.context || root.context || element.context;
|
|
90
|
+
};
|
|
91
|
+
const addCaching = (element, parent, key) => {
|
|
92
|
+
const ref = addRef(element, parent);
|
|
93
|
+
element.__ref = ref;
|
|
94
|
+
if (!ref.__defineCache) ref.__defineCache = {};
|
|
95
|
+
if (!ref.__exec) ref.__exec = {};
|
|
96
|
+
if (!ref.__execProps) ref.__execProps = {};
|
|
97
|
+
if (!ref.__class) ref.__class = {};
|
|
98
|
+
if (!ref.__classNames) ref.__classNames = {};
|
|
99
|
+
if (!ref.__attr) ref.__attr = {};
|
|
100
|
+
if (!ref.__changes) ref.__changes = [];
|
|
101
|
+
if (!ref.__children) ref.__children = [];
|
|
102
|
+
ref.__extends = createExtends(element, parent, key);
|
|
103
|
+
ref.path = createPath(element, parent, key);
|
|
104
|
+
ref.root = createRoot(element, parent);
|
|
105
|
+
return ref;
|
|
106
|
+
};
|
|
107
|
+
const createElement = (passedProps, parentEl, passedKey, opts, root) => {
|
|
108
|
+
const hashed = passedProps == null ? void 0 : passedProps.__hash;
|
|
109
|
+
const element = hashed ? { extends: [passedProps] } : createBasedOnType(passedProps, parentEl, passedKey);
|
|
110
|
+
if (!element) return;
|
|
111
|
+
const parent = createParent(element, parentEl, passedKey, opts, root);
|
|
112
|
+
const key = createKey(element, parent, passedKey);
|
|
113
|
+
addCaching(element, parent, key);
|
|
114
|
+
const props = createProps(element, parent, key);
|
|
115
|
+
const context = addContext(element, parent, key, opts, root);
|
|
116
|
+
const on = element.on || {};
|
|
117
|
+
return __spreadProps(__spreadValues({}, element), {
|
|
118
|
+
key,
|
|
119
|
+
props,
|
|
120
|
+
parent,
|
|
121
|
+
context,
|
|
122
|
+
on
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
export {
|
|
126
|
+
addCaching,
|
|
127
|
+
addContext,
|
|
128
|
+
addRef,
|
|
129
|
+
createBasedOnType,
|
|
130
|
+
createElement,
|
|
131
|
+
createParent,
|
|
132
|
+
createPath,
|
|
133
|
+
createRoot,
|
|
134
|
+
returnValueAsText
|
|
135
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { lowercaseFirstLetter } from "./string.js";
|
|
2
|
+
import { isFunction } from "./types.js";
|
|
3
|
+
const addEventFromProps = (key, element) => {
|
|
4
|
+
const { props, on } = element;
|
|
5
|
+
const eventName = lowercaseFirstLetter(key.split("on")[1]);
|
|
6
|
+
const origEvent = on[eventName];
|
|
7
|
+
const funcFromProps = props[key];
|
|
8
|
+
if (isFunction(origEvent)) {
|
|
9
|
+
on[eventName] = (...args) => {
|
|
10
|
+
const originalEventRetunrs = origEvent(...args);
|
|
11
|
+
if (originalEventRetunrs !== false) funcFromProps(...args);
|
|
12
|
+
};
|
|
13
|
+
} else on[eventName] = funcFromProps;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
addEventFromProps
|
|
17
|
+
};
|