@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/cjs/methods.js
CHANGED
|
@@ -22,8 +22,14 @@ __export(methods_exports, {
|
|
|
22
22
|
defineSetter: () => defineSetter,
|
|
23
23
|
error: () => error,
|
|
24
24
|
get: () => get,
|
|
25
|
+
getChildren: () => getChildren,
|
|
26
|
+
getContext: () => getContext,
|
|
25
27
|
getPath: () => getPath,
|
|
26
28
|
getRef: () => getRef,
|
|
29
|
+
getRoot: () => getRoot,
|
|
30
|
+
getRootContext: () => getRootContext,
|
|
31
|
+
getRootData: () => getRootData,
|
|
32
|
+
getRootState: () => getRootState,
|
|
27
33
|
isMethod: () => isMethod,
|
|
28
34
|
keys: () => keys,
|
|
29
35
|
log: () => log,
|
|
@@ -43,13 +49,13 @@ __export(methods_exports, {
|
|
|
43
49
|
warn: () => warn
|
|
44
50
|
});
|
|
45
51
|
module.exports = __toCommonJS(methods_exports);
|
|
46
|
-
var
|
|
52
|
+
var import_triggerEvent = require("./triggerEvent.js");
|
|
47
53
|
var import_keys = require("./keys.js");
|
|
48
54
|
var import_types = require("./types.js");
|
|
49
55
|
var import_object = require("./object.js");
|
|
50
56
|
var import_env = require("./env.js");
|
|
51
57
|
var import_array = require("./array.js");
|
|
52
|
-
const ENV =
|
|
58
|
+
const ENV = process.env.NODE_ENV;
|
|
53
59
|
function spotByPath(path) {
|
|
54
60
|
const element = this;
|
|
55
61
|
const { __ref: ref } = element;
|
|
@@ -84,10 +90,10 @@ function lookup(param) {
|
|
|
84
90
|
return parent;
|
|
85
91
|
}
|
|
86
92
|
function lookdown(param) {
|
|
87
|
-
var _a;
|
|
88
93
|
const el = this;
|
|
89
94
|
const { __ref: ref } = el;
|
|
90
|
-
const children = ref
|
|
95
|
+
const children = ref?.__children;
|
|
96
|
+
if (!children) return;
|
|
91
97
|
for (let i = 0; i < children.length; i++) {
|
|
92
98
|
const v = children[i];
|
|
93
99
|
const childElem = el[v];
|
|
@@ -98,15 +104,15 @@ function lookdown(param) {
|
|
|
98
104
|
return childElem;
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
|
-
const lookdown2 =
|
|
107
|
+
const lookdown2 = childElem?.lookdown?.(param);
|
|
102
108
|
if (lookdown2) return lookdown2;
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
111
|
function lookdownAll(param, results = []) {
|
|
106
|
-
var _a;
|
|
107
112
|
const el = this;
|
|
108
113
|
const { __ref: ref } = el;
|
|
109
|
-
const children = ref
|
|
114
|
+
const children = ref?.__children;
|
|
115
|
+
if (!children) return;
|
|
110
116
|
for (let i = 0; i < children.length; i++) {
|
|
111
117
|
const v = children[i];
|
|
112
118
|
const childElem = el[v];
|
|
@@ -115,14 +121,13 @@ function lookdownAll(param, results = []) {
|
|
|
115
121
|
const exec = param(childElem, childElem.state, childElem.context);
|
|
116
122
|
if (childElem.state && exec) results.push(childElem);
|
|
117
123
|
}
|
|
118
|
-
|
|
124
|
+
childElem?.lookdownAll?.(param, results);
|
|
119
125
|
}
|
|
120
126
|
return results.length ? results : void 0;
|
|
121
127
|
}
|
|
122
128
|
function setNodeStyles(params = {}) {
|
|
123
|
-
var _a;
|
|
124
129
|
const el = this;
|
|
125
|
-
if (!
|
|
130
|
+
if (!el.node?.style) return;
|
|
126
131
|
for (const param in params) {
|
|
127
132
|
const value = params[param];
|
|
128
133
|
const childElem = el[param];
|
|
@@ -133,7 +138,7 @@ function setNodeStyles(params = {}) {
|
|
|
133
138
|
}
|
|
134
139
|
function remove(opts) {
|
|
135
140
|
const element = this;
|
|
136
|
-
const beforeRemoveReturns = (0,
|
|
141
|
+
const beforeRemoveReturns = (0, import_triggerEvent.triggerEventOn)("beforeRemove", element, opts);
|
|
137
142
|
if (beforeRemoveReturns === false) return element;
|
|
138
143
|
if ((0, import_types.isFunction)(element.node.remove)) element.node.remove();
|
|
139
144
|
else if (!(0, import_env.isProduction)()) {
|
|
@@ -147,7 +152,7 @@ function remove(opts) {
|
|
|
147
152
|
element.key
|
|
148
153
|
);
|
|
149
154
|
}
|
|
150
|
-
(0,
|
|
155
|
+
(0, import_triggerEvent.triggerEventOn)("remove", element, opts);
|
|
151
156
|
}
|
|
152
157
|
function get(param) {
|
|
153
158
|
const element = this;
|
|
@@ -159,20 +164,59 @@ function setProps(param, options) {
|
|
|
159
164
|
element.update({ props: param }, options);
|
|
160
165
|
return element;
|
|
161
166
|
}
|
|
162
|
-
function getRef() {
|
|
167
|
+
function getRef(key) {
|
|
168
|
+
if (key) return this.__ref && this.__ref[key];
|
|
163
169
|
return this.__ref;
|
|
164
170
|
}
|
|
171
|
+
function getChildren() {
|
|
172
|
+
const __children = this.getRef("__children");
|
|
173
|
+
return __children.map((k) => this[k]);
|
|
174
|
+
}
|
|
165
175
|
function getPath() {
|
|
166
176
|
return this.getRef().path;
|
|
167
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
|
+
}
|
|
168
212
|
const defineSetter = (element, key, get2, set) => Object.defineProperty(element, key, { get: get2, set });
|
|
169
213
|
function keys() {
|
|
170
214
|
const element = this;
|
|
171
215
|
const keys2 = [];
|
|
172
216
|
for (const param in element) {
|
|
173
217
|
if (
|
|
174
|
-
// (REGISTRY[param] && !DOMQ_PROPERTIES.
|
|
175
|
-
!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)
|
|
176
220
|
) {
|
|
177
221
|
continue;
|
|
178
222
|
}
|
|
@@ -182,32 +226,46 @@ function keys() {
|
|
|
182
226
|
}
|
|
183
227
|
function parse(excl = []) {
|
|
184
228
|
const element = this;
|
|
185
|
-
const { __ref: ref } = element;
|
|
186
229
|
const obj = {};
|
|
187
230
|
const keyList = keys.call(element);
|
|
188
|
-
keyList.
|
|
189
|
-
|
|
231
|
+
const hasChildren = keyList.includes("children");
|
|
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;
|
|
190
237
|
const val = element[v];
|
|
191
238
|
if (v === "state") {
|
|
192
|
-
if (
|
|
239
|
+
if (element.__ref && !element.__ref.__hasRootState) continue;
|
|
193
240
|
const parsedVal = (0, import_types.isFunction)(val && val.parse) ? val.parse() : val;
|
|
194
241
|
obj[v] = (0, import_types.isFunction)(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
|
|
195
242
|
} else if (v === "scope") {
|
|
196
|
-
if (
|
|
243
|
+
if (element.__ref && !element.__ref.__hasRootScope) continue;
|
|
197
244
|
obj[v] = JSON.parse(JSON.stringify(val || {}));
|
|
198
|
-
} else if (
|
|
245
|
+
} else if (v === "props") {
|
|
246
|
+
const { __element, update, ...props } = element[v];
|
|
247
|
+
obj[v] = props;
|
|
248
|
+
} else if ((0, import_types.isDefined)(val) && Object.prototype.hasOwnProperty.call(element, v)) {
|
|
199
249
|
obj[v] = val;
|
|
200
250
|
}
|
|
201
|
-
}
|
|
251
|
+
}
|
|
202
252
|
return obj;
|
|
203
253
|
}
|
|
204
|
-
function parseDeep(excl = []) {
|
|
254
|
+
function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
205
255
|
const element = this;
|
|
256
|
+
if (visited.has(element)) return void 0;
|
|
257
|
+
visited.add(element);
|
|
206
258
|
const obj = parse.call(element, excl);
|
|
259
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
207
260
|
for (const v in obj) {
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
261
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
262
|
+
const val = obj[v];
|
|
263
|
+
if (Array.isArray(val)) {
|
|
264
|
+
obj[v] = val.map(
|
|
265
|
+
(item) => (0, import_types.isObjectLike)(item) ? parseDeep.call(item, excl, visited) : item
|
|
266
|
+
);
|
|
267
|
+
} else if ((0, import_types.isObjectLike)(val)) {
|
|
268
|
+
obj[v] = parseDeep.call(val, excl, visited);
|
|
211
269
|
}
|
|
212
270
|
}
|
|
213
271
|
return obj;
|
|
@@ -240,10 +298,9 @@ function warn(...params) {
|
|
|
240
298
|
}
|
|
241
299
|
}
|
|
242
300
|
function error(...params) {
|
|
243
|
-
var _a, _b;
|
|
244
301
|
if (ENV === "test" || ENV === "development") {
|
|
245
|
-
if (
|
|
246
|
-
if (
|
|
302
|
+
if (params[params.length - 1]?.debugger) debugger;
|
|
303
|
+
if (params[params.length - 1]?.verbose) verbose.call(this);
|
|
247
304
|
throw new Error(...params);
|
|
248
305
|
}
|
|
249
306
|
}
|
|
@@ -295,11 +352,9 @@ function variables(obj = {}) {
|
|
|
295
352
|
};
|
|
296
353
|
}
|
|
297
354
|
function call(fnKey, ...args) {
|
|
298
|
-
var _a, _b, _c, _d, _e;
|
|
299
355
|
const context = this.context;
|
|
300
|
-
return (
|
|
356
|
+
return (context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey])?.call(this, ...args);
|
|
301
357
|
}
|
|
302
358
|
function isMethod(param, element) {
|
|
303
|
-
|
|
304
|
-
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]);
|
|
305
360
|
}
|