@domql/utils 3.2.3 → 3.2.10
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 +11 -5
- package/cache.js +3 -0
- package/component.js +3 -4
- package/dist/cjs/array.js +11 -5
- package/dist/cjs/component.js +4 -6
- package/dist/cjs/element.js +5 -5
- package/dist/cjs/extends.js +43 -27
- package/dist/cjs/function.js +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/key.js +2 -2
- package/dist/cjs/keys.js +30 -16
- package/dist/cjs/methods.js +64 -28
- package/dist/cjs/object.js +141 -125
- package/dist/cjs/props.js +41 -32
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +9 -8
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +69 -4
- package/dist/cjs/triggerEvent.js +90 -0
- package/dist/cjs/types.js +4 -12
- package/dist/esm/array.js +11 -5
- package/dist/esm/component.js +4 -6
- package/dist/esm/element.js +8 -26
- package/dist/esm/extends.js +47 -49
- package/dist/esm/function.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +2 -2
- package/dist/esm/keys.js +30 -16
- package/dist/esm/methods.js +63 -42
- package/dist/esm/object.js +145 -149
- package/dist/esm/props.js +41 -48
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +17 -34
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +69 -4
- package/dist/esm/triggerEvent.js +70 -0
- package/dist/esm/types.js +4 -12
- package/dist/iife/index.js +2779 -0
- package/element.js +2 -2
- package/extends.js +28 -17
- package/function.js +4 -6
- package/index.js +1 -0
- package/keys.js +26 -16
- package/methods.js +63 -18
- package/object.js +142 -200
- package/package.json +33 -12
- package/props.js +42 -25
- package/state.js +7 -7
- package/string.js +20 -38
- package/tags.js +43 -4
- package/triggerEvent.js +76 -0
- package/types.js +4 -23
- package/dist/cjs/package.json +0 -4
package/dist/cjs/methods.js
CHANGED
|
@@ -23,8 +23,13 @@ __export(methods_exports, {
|
|
|
23
23
|
error: () => error,
|
|
24
24
|
get: () => get,
|
|
25
25
|
getChildren: () => getChildren,
|
|
26
|
+
getContext: () => getContext,
|
|
26
27
|
getPath: () => getPath,
|
|
27
28
|
getRef: () => getRef,
|
|
29
|
+
getRoot: () => getRoot,
|
|
30
|
+
getRootContext: () => getRootContext,
|
|
31
|
+
getRootData: () => getRootData,
|
|
32
|
+
getRootState: () => getRootState,
|
|
28
33
|
isMethod: () => isMethod,
|
|
29
34
|
keys: () => keys,
|
|
30
35
|
log: () => log,
|
|
@@ -44,7 +49,7 @@ __export(methods_exports, {
|
|
|
44
49
|
warn: () => warn
|
|
45
50
|
});
|
|
46
51
|
module.exports = __toCommonJS(methods_exports);
|
|
47
|
-
var
|
|
52
|
+
var import_triggerEvent = require("./triggerEvent.js");
|
|
48
53
|
var import_keys = require("./keys.js");
|
|
49
54
|
var import_types = require("./types.js");
|
|
50
55
|
var import_object = require("./object.js");
|
|
@@ -85,10 +90,9 @@ function lookup(param) {
|
|
|
85
90
|
return parent;
|
|
86
91
|
}
|
|
87
92
|
function lookdown(param) {
|
|
88
|
-
var _a;
|
|
89
93
|
const el = this;
|
|
90
94
|
const { __ref: ref } = el;
|
|
91
|
-
const children = ref
|
|
95
|
+
const children = ref?.__children;
|
|
92
96
|
if (!children) return;
|
|
93
97
|
for (let i = 0; i < children.length; i++) {
|
|
94
98
|
const v = children[i];
|
|
@@ -100,15 +104,14 @@ function lookdown(param) {
|
|
|
100
104
|
return childElem;
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
|
-
const lookdown2 =
|
|
107
|
+
const lookdown2 = childElem?.lookdown?.(param);
|
|
104
108
|
if (lookdown2) return lookdown2;
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
function lookdownAll(param, results = []) {
|
|
108
|
-
var _a;
|
|
109
112
|
const el = this;
|
|
110
113
|
const { __ref: ref } = el;
|
|
111
|
-
const children = ref
|
|
114
|
+
const children = ref?.__children;
|
|
112
115
|
if (!children) return;
|
|
113
116
|
for (let i = 0; i < children.length; i++) {
|
|
114
117
|
const v = children[i];
|
|
@@ -118,14 +121,13 @@ function lookdownAll(param, results = []) {
|
|
|
118
121
|
const exec = param(childElem, childElem.state, childElem.context);
|
|
119
122
|
if (childElem.state && exec) results.push(childElem);
|
|
120
123
|
}
|
|
121
|
-
|
|
124
|
+
childElem?.lookdownAll?.(param, results);
|
|
122
125
|
}
|
|
123
126
|
return results.length ? results : void 0;
|
|
124
127
|
}
|
|
125
128
|
function setNodeStyles(params = {}) {
|
|
126
|
-
var _a;
|
|
127
129
|
const el = this;
|
|
128
|
-
if (!
|
|
130
|
+
if (!el.node?.style) return;
|
|
129
131
|
for (const param in params) {
|
|
130
132
|
const value = params[param];
|
|
131
133
|
const childElem = el[param];
|
|
@@ -136,7 +138,7 @@ function setNodeStyles(params = {}) {
|
|
|
136
138
|
}
|
|
137
139
|
function remove(opts) {
|
|
138
140
|
const element = this;
|
|
139
|
-
const beforeRemoveReturns = (0,
|
|
141
|
+
const beforeRemoveReturns = (0, import_triggerEvent.triggerEventOn)("beforeRemove", element, opts);
|
|
140
142
|
if (beforeRemoveReturns === false) return element;
|
|
141
143
|
if ((0, import_types.isFunction)(element.node.remove)) element.node.remove();
|
|
142
144
|
else if (!(0, import_env.isProduction)()) {
|
|
@@ -150,7 +152,7 @@ function remove(opts) {
|
|
|
150
152
|
element.key
|
|
151
153
|
);
|
|
152
154
|
}
|
|
153
|
-
(0,
|
|
155
|
+
(0, import_triggerEvent.triggerEventOn)("remove", element, opts);
|
|
154
156
|
}
|
|
155
157
|
function get(param) {
|
|
156
158
|
const element = this;
|
|
@@ -173,14 +175,48 @@ function getChildren() {
|
|
|
173
175
|
function getPath() {
|
|
174
176
|
return this.getRef().path;
|
|
175
177
|
}
|
|
178
|
+
function getRootState(param) {
|
|
179
|
+
let state = null;
|
|
180
|
+
const hasRootState = (obj) => obj.__element && obj.root?.isRootState;
|
|
181
|
+
if (!this) {
|
|
182
|
+
state = window.platformState || window.smblsApp?.state;
|
|
183
|
+
} else if (hasRootState(this)) {
|
|
184
|
+
state = this.root;
|
|
185
|
+
} else if (this.__ref && this.__ref.path) {
|
|
186
|
+
const hasPlatformState = this.state && hasRootState(this.state);
|
|
187
|
+
const hasPlatformStateOnParent = (0, import_types.isFunction)(this.state) && this.parent.state && hasRootState(this.parent.state);
|
|
188
|
+
if (hasPlatformState || hasPlatformStateOnParent) {
|
|
189
|
+
state = this.state.root || this.parent.state.root;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!state) {
|
|
193
|
+
state = window.platformState || window.smblsApp?.state;
|
|
194
|
+
}
|
|
195
|
+
return param ? state?.[param] : state;
|
|
196
|
+
}
|
|
197
|
+
function getRoot(key) {
|
|
198
|
+
const rootElem = this.getRootState()?.__element;
|
|
199
|
+
return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
|
|
200
|
+
}
|
|
201
|
+
function getRootData(key) {
|
|
202
|
+
return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
|
|
203
|
+
}
|
|
204
|
+
function getRootContext(key) {
|
|
205
|
+
const ctx = this.getRoot()?.context;
|
|
206
|
+
return key ? ctx[key] : ctx;
|
|
207
|
+
}
|
|
208
|
+
function getContext(key) {
|
|
209
|
+
const ctx = this.context;
|
|
210
|
+
return key ? ctx[key] : ctx;
|
|
211
|
+
}
|
|
176
212
|
const defineSetter = (element, key, get2, set) => Object.defineProperty(element, key, { get: get2, set });
|
|
177
213
|
function keys() {
|
|
178
214
|
const element = this;
|
|
179
215
|
const keys2 = [];
|
|
180
216
|
for (const param in element) {
|
|
181
217
|
if (
|
|
182
|
-
// (REGISTRY[param] && !DOMQ_PROPERTIES.
|
|
183
|
-
!Object.hasOwnProperty.call(element, param) || import_keys.DOMQ_PROPERTIES.
|
|
218
|
+
// (REGISTRY[param] && !DOMQ_PROPERTIES.has(param)) ||
|
|
219
|
+
!Object.prototype.hasOwnProperty.call(element, param) || import_keys.DOMQ_PROPERTIES.has(param) && !import_keys.PARSED_DOMQ_PROPERTIES.has(param)
|
|
184
220
|
) {
|
|
185
221
|
continue;
|
|
186
222
|
}
|
|
@@ -193,24 +229,26 @@ function parse(excl = []) {
|
|
|
193
229
|
const obj = {};
|
|
194
230
|
const keyList = keys.call(element);
|
|
195
231
|
const hasChildren = keyList.includes("children");
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
233
|
+
for (let i = 0; i < keyList.length; i++) {
|
|
234
|
+
const v = keyList[i];
|
|
235
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
236
|
+
if (hasChildren && v === "content") continue;
|
|
199
237
|
const val = element[v];
|
|
200
238
|
if (v === "state") {
|
|
201
|
-
if (element.__ref && !element.__ref.__hasRootState)
|
|
239
|
+
if (element.__ref && !element.__ref.__hasRootState) continue;
|
|
202
240
|
const parsedVal = (0, import_types.isFunction)(val && val.parse) ? val.parse() : val;
|
|
203
241
|
obj[v] = (0, import_types.isFunction)(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
|
|
204
242
|
} else if (v === "scope") {
|
|
205
|
-
if (element.__ref && !element.__ref.__hasRootScope)
|
|
243
|
+
if (element.__ref && !element.__ref.__hasRootScope) continue;
|
|
206
244
|
obj[v] = JSON.parse(JSON.stringify(val || {}));
|
|
207
245
|
} else if (v === "props") {
|
|
208
246
|
const { __element, update, ...props } = element[v];
|
|
209
247
|
obj[v] = props;
|
|
210
|
-
} else if ((0, import_types.isDefined)(val) && Object.hasOwnProperty.call(element, v)) {
|
|
248
|
+
} else if ((0, import_types.isDefined)(val) && Object.prototype.hasOwnProperty.call(element, v)) {
|
|
211
249
|
obj[v] = val;
|
|
212
250
|
}
|
|
213
|
-
}
|
|
251
|
+
}
|
|
214
252
|
return obj;
|
|
215
253
|
}
|
|
216
254
|
function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
@@ -218,8 +256,9 @@ function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
218
256
|
if (visited.has(element)) return void 0;
|
|
219
257
|
visited.add(element);
|
|
220
258
|
const obj = parse.call(element, excl);
|
|
259
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
221
260
|
for (const v in obj) {
|
|
222
|
-
if (
|
|
261
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
223
262
|
const val = obj[v];
|
|
224
263
|
if (Array.isArray(val)) {
|
|
225
264
|
obj[v] = val.map(
|
|
@@ -259,10 +298,9 @@ function warn(...params) {
|
|
|
259
298
|
}
|
|
260
299
|
}
|
|
261
300
|
function error(...params) {
|
|
262
|
-
var _a, _b;
|
|
263
301
|
if (ENV === "test" || ENV === "development") {
|
|
264
|
-
if (
|
|
265
|
-
if (
|
|
302
|
+
if (params[params.length - 1]?.debugger) debugger;
|
|
303
|
+
if (params[params.length - 1]?.verbose) verbose.call(this);
|
|
266
304
|
throw new Error(...params);
|
|
267
305
|
}
|
|
268
306
|
}
|
|
@@ -314,11 +352,9 @@ function variables(obj = {}) {
|
|
|
314
352
|
};
|
|
315
353
|
}
|
|
316
354
|
function call(fnKey, ...args) {
|
|
317
|
-
var _a, _b, _c, _d, _e;
|
|
318
355
|
const context = this.context;
|
|
319
|
-
return (
|
|
356
|
+
return (context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey])?.call(this, ...args);
|
|
320
357
|
}
|
|
321
358
|
function isMethod(param, element) {
|
|
322
|
-
|
|
323
|
-
return Boolean(import_keys.METHODS.includes(param) || ((_b = (_a = element == null ? void 0 : element.context) == null ? void 0 : _a.methods) == null ? void 0 : _b[param]));
|
|
359
|
+
return Boolean(import_keys.METHODS.has(param) || element?.context?.methods?.[param]);
|
|
324
360
|
}
|