@domql/utils 3.1.2 → 3.2.7
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 +6 -6
- package/dist/cjs/env.js +1 -1
- package/dist/cjs/events.js +3 -3
- package/dist/cjs/extends.js +44 -28
- 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 +29 -15
- package/dist/cjs/methods.js +88 -33
- package/dist/cjs/object.js +154 -141
- package/dist/cjs/props.js +43 -34
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +12 -11
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +71 -16
- 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 +9 -27
- package/dist/esm/env.js +1 -1
- package/dist/esm/events.js +3 -3
- package/dist/esm/extends.js +48 -50
- 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 +29 -15
- package/dist/esm/methods.js +86 -31
- package/dist/esm/object.js +158 -165
- package/dist/esm/props.js +43 -50
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +21 -38
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +71 -16
- 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/events.js +3 -3
- package/extends.js +28 -17
- package/function.js +10 -9
- package/index.js +1 -0
- package/keys.js +25 -15
- package/log.js +0 -1
- package/methods.js +99 -24
- package/object.js +155 -215
- package/package.json +34 -13
- package/props.js +44 -27
- package/state.js +12 -12
- package/string.js +20 -38
- package/tags.js +45 -16
- package/triggerEvent.js +76 -0
- package/types.js +8 -25
- package/dist/cjs/package.json +0 -4
package/dist/esm/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { triggerEventOn } from "
|
|
1
|
+
import { triggerEventOn } from "./triggerEvent.js";
|
|
2
2
|
import { DOMQ_PROPERTIES, METHODS, PARSED_DOMQ_PROPERTIES } from "./keys.js";
|
|
3
3
|
import { isDefined, isFunction, isObject, isObjectLike } from "./types.js";
|
|
4
4
|
import { deepClone } from "./object.js";
|
|
5
5
|
import { isProduction } from "./env.js";
|
|
6
6
|
import { removeValueFromArray } from "./array.js";
|
|
7
|
-
const ENV =
|
|
7
|
+
const ENV = process.env.NODE_ENV;
|
|
8
8
|
function spotByPath(path) {
|
|
9
9
|
const element = this;
|
|
10
10
|
const { __ref: ref } = element;
|
|
@@ -39,10 +39,10 @@ function lookup(param) {
|
|
|
39
39
|
return parent;
|
|
40
40
|
}
|
|
41
41
|
function lookdown(param) {
|
|
42
|
-
var _a;
|
|
43
42
|
const el = this;
|
|
44
43
|
const { __ref: ref } = el;
|
|
45
|
-
const children = ref
|
|
44
|
+
const children = ref?.__children;
|
|
45
|
+
if (!children) return;
|
|
46
46
|
for (let i = 0; i < children.length; i++) {
|
|
47
47
|
const v = children[i];
|
|
48
48
|
const childElem = el[v];
|
|
@@ -53,15 +53,15 @@ function lookdown(param) {
|
|
|
53
53
|
return childElem;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
const lookdown2 =
|
|
56
|
+
const lookdown2 = childElem?.lookdown?.(param);
|
|
57
57
|
if (lookdown2) return lookdown2;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
function lookdownAll(param, results = []) {
|
|
61
|
-
var _a;
|
|
62
61
|
const el = this;
|
|
63
62
|
const { __ref: ref } = el;
|
|
64
|
-
const children = ref
|
|
63
|
+
const children = ref?.__children;
|
|
64
|
+
if (!children) return;
|
|
65
65
|
for (let i = 0; i < children.length; i++) {
|
|
66
66
|
const v = children[i];
|
|
67
67
|
const childElem = el[v];
|
|
@@ -70,14 +70,13 @@ function lookdownAll(param, results = []) {
|
|
|
70
70
|
const exec = param(childElem, childElem.state, childElem.context);
|
|
71
71
|
if (childElem.state && exec) results.push(childElem);
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
childElem?.lookdownAll?.(param, results);
|
|
74
74
|
}
|
|
75
75
|
return results.length ? results : void 0;
|
|
76
76
|
}
|
|
77
77
|
function setNodeStyles(params = {}) {
|
|
78
|
-
var _a;
|
|
79
78
|
const el = this;
|
|
80
|
-
if (!
|
|
79
|
+
if (!el.node?.style) return;
|
|
81
80
|
for (const param in params) {
|
|
82
81
|
const value = params[param];
|
|
83
82
|
const childElem = el[param];
|
|
@@ -114,20 +113,59 @@ function setProps(param, options) {
|
|
|
114
113
|
element.update({ props: param }, options);
|
|
115
114
|
return element;
|
|
116
115
|
}
|
|
117
|
-
function getRef() {
|
|
116
|
+
function getRef(key) {
|
|
117
|
+
if (key) return this.__ref && this.__ref[key];
|
|
118
118
|
return this.__ref;
|
|
119
119
|
}
|
|
120
|
+
function getChildren() {
|
|
121
|
+
const __children = this.getRef("__children");
|
|
122
|
+
return __children.map((k) => this[k]);
|
|
123
|
+
}
|
|
120
124
|
function getPath() {
|
|
121
125
|
return this.getRef().path;
|
|
122
126
|
}
|
|
127
|
+
function getRootState(param) {
|
|
128
|
+
let state = null;
|
|
129
|
+
const hasRootState = (obj) => obj.__element && obj.root?.isRootState;
|
|
130
|
+
if (!this) {
|
|
131
|
+
state = window.platformState || window.smblsApp?.state;
|
|
132
|
+
} else if (hasRootState(this)) {
|
|
133
|
+
state = this.root;
|
|
134
|
+
} else if (this.__ref && this.__ref.path) {
|
|
135
|
+
const hasPlatformState = this.state && hasRootState(this.state);
|
|
136
|
+
const hasPlatformStateOnParent = isFunction(this.state) && this.parent.state && hasRootState(this.parent.state);
|
|
137
|
+
if (hasPlatformState || hasPlatformStateOnParent) {
|
|
138
|
+
state = this.state.root || this.parent.state.root;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!state) {
|
|
142
|
+
state = window.platformState || window.smblsApp?.state;
|
|
143
|
+
}
|
|
144
|
+
return param ? state?.[param] : state;
|
|
145
|
+
}
|
|
146
|
+
function getRoot(key) {
|
|
147
|
+
const rootElem = this.getRootState()?.__element;
|
|
148
|
+
return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
|
|
149
|
+
}
|
|
150
|
+
function getRootData(key) {
|
|
151
|
+
return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
|
|
152
|
+
}
|
|
153
|
+
function getRootContext(key) {
|
|
154
|
+
const ctx = this.getRoot()?.context;
|
|
155
|
+
return key ? ctx[key] : ctx;
|
|
156
|
+
}
|
|
157
|
+
function getContext(key) {
|
|
158
|
+
const ctx = this.context;
|
|
159
|
+
return key ? ctx[key] : ctx;
|
|
160
|
+
}
|
|
123
161
|
const defineSetter = (element, key, get2, set) => Object.defineProperty(element, key, { get: get2, set });
|
|
124
162
|
function keys() {
|
|
125
163
|
const element = this;
|
|
126
164
|
const keys2 = [];
|
|
127
165
|
for (const param in element) {
|
|
128
166
|
if (
|
|
129
|
-
// (REGISTRY[param] && !DOMQ_PROPERTIES.
|
|
130
|
-
!Object.hasOwnProperty.call(element, param) || DOMQ_PROPERTIES.
|
|
167
|
+
// (REGISTRY[param] && !DOMQ_PROPERTIES.has(param)) ||
|
|
168
|
+
!Object.prototype.hasOwnProperty.call(element, param) || DOMQ_PROPERTIES.has(param) && !PARSED_DOMQ_PROPERTIES.has(param)
|
|
131
169
|
) {
|
|
132
170
|
continue;
|
|
133
171
|
}
|
|
@@ -137,32 +175,46 @@ function keys() {
|
|
|
137
175
|
}
|
|
138
176
|
function parse(excl = []) {
|
|
139
177
|
const element = this;
|
|
140
|
-
const { __ref: ref } = element;
|
|
141
178
|
const obj = {};
|
|
142
179
|
const keyList = keys.call(element);
|
|
143
|
-
keyList.
|
|
144
|
-
|
|
180
|
+
const hasChildren = keyList.includes("children");
|
|
181
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
182
|
+
for (let i = 0; i < keyList.length; i++) {
|
|
183
|
+
const v = keyList[i];
|
|
184
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
185
|
+
if (hasChildren && v === "content") continue;
|
|
145
186
|
const val = element[v];
|
|
146
187
|
if (v === "state") {
|
|
147
|
-
if (
|
|
188
|
+
if (element.__ref && !element.__ref.__hasRootState) continue;
|
|
148
189
|
const parsedVal = isFunction(val && val.parse) ? val.parse() : val;
|
|
149
190
|
obj[v] = isFunction(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
|
|
150
191
|
} else if (v === "scope") {
|
|
151
|
-
if (
|
|
192
|
+
if (element.__ref && !element.__ref.__hasRootScope) continue;
|
|
152
193
|
obj[v] = JSON.parse(JSON.stringify(val || {}));
|
|
153
|
-
} else if (
|
|
194
|
+
} else if (v === "props") {
|
|
195
|
+
const { __element, update, ...props } = element[v];
|
|
196
|
+
obj[v] = props;
|
|
197
|
+
} else if (isDefined(val) && Object.prototype.hasOwnProperty.call(element, v)) {
|
|
154
198
|
obj[v] = val;
|
|
155
199
|
}
|
|
156
|
-
}
|
|
200
|
+
}
|
|
157
201
|
return obj;
|
|
158
202
|
}
|
|
159
|
-
function parseDeep(excl = []) {
|
|
203
|
+
function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
160
204
|
const element = this;
|
|
205
|
+
if (visited.has(element)) return void 0;
|
|
206
|
+
visited.add(element);
|
|
161
207
|
const obj = parse.call(element, excl);
|
|
208
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
162
209
|
for (const v in obj) {
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
210
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
211
|
+
const val = obj[v];
|
|
212
|
+
if (Array.isArray(val)) {
|
|
213
|
+
obj[v] = val.map(
|
|
214
|
+
(item) => isObjectLike(item) ? parseDeep.call(item, excl, visited) : item
|
|
215
|
+
);
|
|
216
|
+
} else if (isObjectLike(val)) {
|
|
217
|
+
obj[v] = parseDeep.call(val, excl, visited);
|
|
166
218
|
}
|
|
167
219
|
}
|
|
168
220
|
return obj;
|
|
@@ -195,10 +247,9 @@ function warn(...params) {
|
|
|
195
247
|
}
|
|
196
248
|
}
|
|
197
249
|
function error(...params) {
|
|
198
|
-
var _a, _b;
|
|
199
250
|
if (ENV === "test" || ENV === "development") {
|
|
200
|
-
if (
|
|
201
|
-
if (
|
|
251
|
+
if (params[params.length - 1]?.debugger) debugger;
|
|
252
|
+
if (params[params.length - 1]?.verbose) verbose.call(this);
|
|
202
253
|
throw new Error(...params);
|
|
203
254
|
}
|
|
204
255
|
}
|
|
@@ -250,21 +301,25 @@ function variables(obj = {}) {
|
|
|
250
301
|
};
|
|
251
302
|
}
|
|
252
303
|
function call(fnKey, ...args) {
|
|
253
|
-
var _a, _b, _c, _d, _e;
|
|
254
304
|
const context = this.context;
|
|
255
|
-
return (
|
|
305
|
+
return (context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey])?.call(this, ...args);
|
|
256
306
|
}
|
|
257
307
|
function isMethod(param, element) {
|
|
258
|
-
|
|
259
|
-
return Boolean(METHODS.includes(param) || ((_b = (_a = element == null ? void 0 : element.context) == null ? void 0 : _a.methods) == null ? void 0 : _b[param]));
|
|
308
|
+
return Boolean(METHODS.has(param) || element?.context?.methods?.[param]);
|
|
260
309
|
}
|
|
261
310
|
export {
|
|
262
311
|
call,
|
|
263
312
|
defineSetter,
|
|
264
313
|
error,
|
|
265
314
|
get,
|
|
315
|
+
getChildren,
|
|
316
|
+
getContext,
|
|
266
317
|
getPath,
|
|
267
318
|
getRef,
|
|
319
|
+
getRoot,
|
|
320
|
+
getRootContext,
|
|
321
|
+
getRootData,
|
|
322
|
+
getRootState,
|
|
268
323
|
isMethod,
|
|
269
324
|
keys,
|
|
270
325
|
log,
|