@domql/utils 3.2.3 → 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.
Files changed (53) hide show
  1. package/array.js +11 -5
  2. package/cache.js +3 -0
  3. package/component.js +3 -4
  4. package/dist/cjs/array.js +11 -5
  5. package/dist/cjs/component.js +4 -6
  6. package/dist/cjs/element.js +5 -5
  7. package/dist/cjs/extends.js +43 -27
  8. package/dist/cjs/function.js +3 -3
  9. package/dist/cjs/index.js +1 -0
  10. package/dist/cjs/key.js +2 -2
  11. package/dist/cjs/keys.js +30 -16
  12. package/dist/cjs/methods.js +64 -28
  13. package/dist/cjs/object.js +141 -125
  14. package/dist/cjs/props.js +41 -32
  15. package/dist/cjs/scope.js +1 -2
  16. package/dist/cjs/state.js +9 -8
  17. package/dist/cjs/string.js +15 -20
  18. package/dist/cjs/tags.js +69 -4
  19. package/dist/cjs/triggerEvent.js +90 -0
  20. package/dist/cjs/types.js +4 -12
  21. package/dist/esm/array.js +11 -5
  22. package/dist/esm/component.js +4 -6
  23. package/dist/esm/element.js +8 -26
  24. package/dist/esm/extends.js +47 -49
  25. package/dist/esm/function.js +3 -3
  26. package/dist/esm/index.js +1 -0
  27. package/dist/esm/key.js +2 -2
  28. package/dist/esm/keys.js +30 -16
  29. package/dist/esm/methods.js +63 -42
  30. package/dist/esm/object.js +145 -149
  31. package/dist/esm/props.js +41 -48
  32. package/dist/esm/scope.js +1 -2
  33. package/dist/esm/state.js +17 -34
  34. package/dist/esm/string.js +15 -20
  35. package/dist/esm/tags.js +69 -4
  36. package/dist/esm/triggerEvent.js +70 -0
  37. package/dist/esm/types.js +4 -12
  38. package/dist/iife/index.js +2779 -0
  39. package/element.js +2 -2
  40. package/extends.js +28 -17
  41. package/function.js +4 -6
  42. package/index.js +1 -0
  43. package/keys.js +26 -16
  44. package/methods.js +63 -18
  45. package/object.js +142 -200
  46. package/package.json +33 -12
  47. package/props.js +42 -25
  48. package/state.js +7 -7
  49. package/string.js +20 -38
  50. package/tags.js +43 -4
  51. package/triggerEvent.js +76 -0
  52. package/types.js +4 -23
  53. package/dist/cjs/package.json +0 -4
@@ -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 import_event = require("@domql/event");
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 == null ? void 0 : ref.__children;
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 = (_a = childElem == null ? void 0 : childElem.lookdown) == null ? void 0 : _a.call(childElem, param);
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 == null ? void 0 : ref.__children;
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
- (_a = childElem == null ? void 0 : childElem.lookdownAll) == null ? void 0 : _a.call(childElem, param, results);
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 (!((_a = el.node) == null ? void 0 : _a.style)) return;
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, import_event.triggerEventOn)("beforeRemove", element, opts);
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, import_event.triggerEventOn)("remove", element, opts);
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.includes(param)) ||
183
- !Object.hasOwnProperty.call(element, param) || import_keys.DOMQ_PROPERTIES.includes(param) && !import_keys.PARSED_DOMQ_PROPERTIES.includes(param)
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
- keyList.forEach((v) => {
197
- if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) return;
198
- if (hasChildren && v === "content") return;
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) return;
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) return;
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 (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) continue;
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 ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
265
- if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this);
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 (_e = ((_a = context.utils) == null ? void 0 : _a[fnKey]) || ((_b = context.functions) == null ? void 0 : _b[fnKey]) || ((_c = context.methods) == null ? void 0 : _c[fnKey]) || ((_d = context.snippets) == null ? void 0 : _d[fnKey])) == null ? void 0 : _e.call(this, ...args);
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
- var _a, _b;
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
  }