@domql/element 2.34.25 → 2.34.27

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.
@@ -48,6 +48,7 @@ __export(methods_exports, {
48
48
  warn: () => warn
49
49
  });
50
50
  module.exports = __toCommonJS(methods_exports);
51
+ var import_root = require("./root.js");
51
52
  var import_event = require("@domql/event");
52
53
  var import_utils = require("@domql/utils");
53
54
  var import_tree = require("../tree.js");
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var root_exports = {};
19
+ __export(root_exports, {
20
+ getChildren: () => getChildren,
21
+ getContext: () => getContext,
22
+ getRef: () => getRef,
23
+ getRoot: () => getRoot,
24
+ getRootContext: () => getRootContext,
25
+ getRootData: () => getRootData,
26
+ getRootState: () => getRootState
27
+ });
28
+ module.exports = __toCommonJS(root_exports);
29
+ function getRootState(param) {
30
+ var _a, _b;
31
+ let state = null;
32
+ const hasRootState = (obj) => {
33
+ var _a2;
34
+ return obj.__element && ((_a2 = obj.root) == null ? void 0 : _a2.isRootState);
35
+ };
36
+ if (!this) {
37
+ state = window.platformState || ((_a = window.smblsApp) == null ? void 0 : _a.state);
38
+ } else if (hasRootState(this)) {
39
+ state = this.root;
40
+ } else if (this.__ref && this.__ref.path) {
41
+ const hasPlatformState = this.state && hasRootState(this.state);
42
+ const hasPlatformStateOnParent = this.call("isFunction", this.state) && this.parent.state && hasRootState(this.parent.state);
43
+ if (hasPlatformState || hasPlatformStateOnParent) {
44
+ state = this.state.root || this.parent.state.root;
45
+ }
46
+ }
47
+ if (!state) {
48
+ state = window.platformState || ((_b = window.smblsApp) == null ? void 0 : _b.state);
49
+ }
50
+ return param ? state[param] : state;
51
+ }
52
+ function getRef(key) {
53
+ if (key) {
54
+ return this.__ref && this.__ref[key];
55
+ }
56
+ return this.__ref;
57
+ }
58
+ function getChildren() {
59
+ const __children = this.getRef("__children");
60
+ return __children == null ? void 0 : __children.map((k) => this[k]);
61
+ }
62
+ function getRoot(key) {
63
+ var _a;
64
+ const rootElem = (_a = this.getRootState()) == null ? void 0 : _a.__element;
65
+ return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
66
+ }
67
+ function getRootData(key) {
68
+ return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
69
+ }
70
+ function getRootContext(key) {
71
+ var _a;
72
+ const ctx = (_a = this.getRoot()) == null ? void 0 : _a.context;
73
+ return key ? ctx[key] : ctx;
74
+ }
75
+ function getContext(key) {
76
+ const ctx = this.context;
77
+ return key ? ctx[key] : ctx;
78
+ }
@@ -1,3 +1,4 @@
1
+ import "./root.js";
1
2
  import { triggerEventOn } from "@domql/event";
2
3
  import {
3
4
  isDefined,
@@ -0,0 +1,59 @@
1
+ function getRootState(param) {
2
+ var _a, _b;
3
+ let state = null;
4
+ const hasRootState = (obj) => {
5
+ var _a2;
6
+ return obj.__element && ((_a2 = obj.root) == null ? void 0 : _a2.isRootState);
7
+ };
8
+ if (!this) {
9
+ state = window.platformState || ((_a = window.smblsApp) == null ? void 0 : _a.state);
10
+ } else if (hasRootState(this)) {
11
+ state = this.root;
12
+ } else if (this.__ref && this.__ref.path) {
13
+ const hasPlatformState = this.state && hasRootState(this.state);
14
+ const hasPlatformStateOnParent = this.call("isFunction", this.state) && this.parent.state && hasRootState(this.parent.state);
15
+ if (hasPlatformState || hasPlatformStateOnParent) {
16
+ state = this.state.root || this.parent.state.root;
17
+ }
18
+ }
19
+ if (!state) {
20
+ state = window.platformState || ((_b = window.smblsApp) == null ? void 0 : _b.state);
21
+ }
22
+ return param ? state[param] : state;
23
+ }
24
+ function getRef(key) {
25
+ if (key) {
26
+ return this.__ref && this.__ref[key];
27
+ }
28
+ return this.__ref;
29
+ }
30
+ function getChildren() {
31
+ const __children = this.getRef("__children");
32
+ return __children == null ? void 0 : __children.map((k) => this[k]);
33
+ }
34
+ function getRoot(key) {
35
+ var _a;
36
+ const rootElem = (_a = this.getRootState()) == null ? void 0 : _a.__element;
37
+ return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
38
+ }
39
+ function getRootData(key) {
40
+ return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
41
+ }
42
+ function getRootContext(key) {
43
+ var _a;
44
+ const ctx = (_a = this.getRoot()) == null ? void 0 : _a.context;
45
+ return key ? ctx[key] : ctx;
46
+ }
47
+ function getContext(key) {
48
+ const ctx = this.context;
49
+ return key ? ctx[key] : ctx;
50
+ }
51
+ export {
52
+ getChildren,
53
+ getContext,
54
+ getRef,
55
+ getRoot,
56
+ getRootContext,
57
+ getRootData,
58
+ getRootState
59
+ };
package/methods/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ import './root.js'
3
4
  import { triggerEventOn } from '@domql/event'
4
5
  import {
5
6
  isDefined,
@@ -0,0 +1,59 @@
1
+ export function getRootState(param) {
2
+ let state = null
3
+ const hasRootState = (obj) => obj.__element && obj.root?.isRootState
4
+ if (!this) {
5
+ state = window.platformState || window.smblsApp?.state
6
+ } else if (hasRootState(this)) {
7
+ state = this.root
8
+ } else if (this.__ref && this.__ref.path) {
9
+ const hasPlatformState = this.state && hasRootState(this.state)
10
+ const hasPlatformStateOnParent =
11
+ this.call('isFunction', this.state) &&
12
+ this.parent.state &&
13
+ hasRootState(this.parent.state)
14
+ if (hasPlatformState || hasPlatformStateOnParent) {
15
+ state = this.state.root || this.parent.state.root
16
+ }
17
+ }
18
+ if (!state) {
19
+ state = window.platformState || window.smblsApp?.state
20
+ }
21
+ return param ? state[param] : state
22
+ }
23
+
24
+ export function getRef(key) {
25
+ if (key) {
26
+ return this.__ref && this.__ref[key]
27
+ }
28
+ return this.__ref
29
+ }
30
+
31
+ export function getChildren() {
32
+ const __children = this.getRef('__children')
33
+ return __children?.map((k) => this[k])
34
+ }
35
+
36
+ export function getRoot(key) {
37
+ const rootElem = this.getRootState()?.__element
38
+ return rootElem && Object.keys(rootElem).length > 0 && key
39
+ ? rootElem[key]
40
+ : rootElem
41
+ }
42
+
43
+ export function getRootData(key) {
44
+ return this.getRoot('data') &&
45
+ Object.keys(this.getRoot('data')).length > 0 &&
46
+ key
47
+ ? this.getRoot('data')[key]
48
+ : this.getRoot('data')
49
+ }
50
+
51
+ export function getRootContext(key) {
52
+ const ctx = this.getRoot()?.context
53
+ return key ? ctx[key] : ctx
54
+ }
55
+
56
+ export function getContext(key) {
57
+ const ctx = this.context
58
+ return key ? ctx[key] : ctx
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.34.25",
3
+ "version": "2.34.27",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -28,12 +28,12 @@
28
28
  "prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
29
29
  },
30
30
  "dependencies": {
31
- "@domql/event": "^2.34.25",
32
- "@domql/render": "^2.34.25",
33
- "@domql/state": "^2.34.25",
34
- "@domql/utils": "^2.34.25"
31
+ "@domql/event": "^2.34.27",
32
+ "@domql/render": "^2.34.27",
33
+ "@domql/state": "^2.34.27",
34
+ "@domql/utils": "^2.34.27"
35
35
  },
36
- "gitHead": "d5d0fa6c595ec8b35ddb5520084a06b7689ecf42",
36
+ "gitHead": "1994ef5ac77cba0564a416c60e9d0a984543d9af",
37
37
  "devDependencies": {
38
38
  "@babel/core": "^7.27.1"
39
39
  }