@domql/element 3.7.4 → 3.7.6

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/README.md CHANGED
@@ -55,6 +55,20 @@ variables, on, component, context
55
55
 
56
56
  Plus mixin handlers: `attr`, `style`, `text`, `html`, `data`, `classlist`, `state`, `scope`, `deps`.
57
57
 
58
+ ## Scope and globalScope
59
+
60
+ During `create()`, `createScope(element, parent)` establishes a prototype chain:
61
+
62
+ ```
63
+ el.scope → parent.scope → ... → root.scope → context.globalScope
64
+ ```
65
+
66
+ - Elements without a `scope` property inherit their parent's scope (same reference)
67
+ - Elements with `scope: { ... }` get their own scope with parent's scope as prototype
68
+ - `context.globalScope` is auto-initialized as `{}` and sits at the chain's root
69
+
70
+ This enables serialized functions to access module-scoped values (constants, helpers) via `el.scope.X` without closures or imports — the values are placed in `globalScope` by the serialization pipeline and are accessible through prototype lookup.
71
+
58
72
  > **v3 note:** `childExtend` (singular) is deprecated v2 syntax — use `childExtends` (plural) in new code. The singular forms remain in REGISTRY for backwards compatibility with older projects. If a key is missing from REGISTRY, it gets interpreted as a child element name, causing silent rendering failures.
59
73
 
60
74
  ## set.js — Content Setting
package/create.js CHANGED
@@ -91,7 +91,6 @@ export const create = (
91
91
  createScope(element, parent)
92
92
 
93
93
  createState(element, parent)
94
- if (element.scope === 'state') element.scope = element.state
95
94
 
96
95
  createIfConditionFlag(element, parent)
97
96
 
@@ -103,9 +102,6 @@ export const create = (
103
102
  if (!element.tag) element.tag = detectTag(element)
104
103
  // Populate element.attr from props matching the tag's HTML spec
105
104
  applyPropsAsAttrs(element)
106
- if (element.scope === 'props' || element.scope === true) {
107
- element.scope = element.props
108
- }
109
105
 
110
106
  // recatch if it passess props again
111
107
  createIfConditionFlag(element, parent)
@@ -240,7 +236,6 @@ const onlyResolveExtends = (element, parent, key, options) => {
240
236
  createScope(element, parent)
241
237
 
242
238
  createState(element, parent)
243
- if (element.scope === 'state') element.scope = element.state
244
239
 
245
240
  createIfConditionFlag(element, parent)
246
241
 
@@ -248,9 +243,6 @@ const onlyResolveExtends = (element, parent, key, options) => {
248
243
  initProps(element, parent, options)
249
244
  // Re-pickup component-named properties that entered props via childProps/inheritParentProps
250
245
  pickupElementFromProps.call(element, element, { cachedKeys: [] })
251
- if (element.scope === 'props' || element.scope === true) {
252
- element.scope = element.props
253
- }
254
246
 
255
247
  if (element.node && ref.__if) {
256
248
  parent[key || element.key] = element
@@ -286,7 +278,11 @@ const onlyResolveExtends = (element, parent, key, options) => {
286
278
  !optionsHasDefine &&
287
279
  !contextHasDefine
288
280
  ) {
289
- create(exec(element[k], element), element, k, options)
281
+ try {
282
+ create(exec(element[k], element), element, k, options)
283
+ } catch (e) {
284
+ console.warn('[DOMQL] onlyResolveExtends child error in', k, ':', e?.message || e)
285
+ }
290
286
  }
291
287
  }
292
288
  }
@@ -72,15 +72,11 @@ const create = (props, parentEl, passedKey, options = import_utils.OPTIONS.creat
72
72
  (0, import_set.addMethods)(element, parent, options);
73
73
  (0, import_utils.createScope)(element, parent);
74
74
  (0, import_state.createState)(element, parent);
75
- if (element.scope === "state") element.scope = element.state;
76
75
  (0, import_utils.createIfConditionFlag)(element, parent);
77
76
  (0, import_utils.initProps)(element, parent, options);
78
77
  import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
79
78
  if (!element.tag) element.tag = (0, import_cache.detectTag)(element);
80
79
  applyPropsAsAttrs(element);
81
- if (element.scope === "props" || element.scope === true) {
82
- element.scope = element.props;
83
- }
84
80
  (0, import_utils.createIfConditionFlag)(element, parent);
85
81
  if (element.node) {
86
82
  if (ref.__if) return (0, import_render.assignNode)(element, parent, key, attachOptions);
@@ -176,13 +172,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
176
172
  (0, import_set.addMethods)(element, parent, options);
177
173
  (0, import_utils.createScope)(element, parent);
178
174
  (0, import_state.createState)(element, parent);
179
- if (element.scope === "state") element.scope = element.state;
180
175
  (0, import_utils.createIfConditionFlag)(element, parent);
181
176
  (0, import_utils.initProps)(element, parent, options);
182
177
  import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
183
- if (element.scope === "props" || element.scope === true) {
184
- element.scope = element.props;
185
- }
186
178
  if (element.node && ref.__if) {
187
179
  parent[key || element.key] = element;
188
180
  }
@@ -201,7 +193,11 @@ const onlyResolveExtends = (element, parent, key, options) => {
201
193
  if (!ref.__skipCreate && import_mixins.REGISTRY[k] && !optionsHasDefine) {
202
194
  continue;
203
195
  } else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
204
- create((0, import_utils.exec)(element[k], element), element, k, options);
196
+ try {
197
+ create((0, import_utils.exec)(element[k], element), element, k, options);
198
+ } catch (e) {
199
+ console.warn("[DOMQL] onlyResolveExtends child error in", k, ":", e?.message || e);
200
+ }
205
201
  }
206
202
  }
207
203
  }
@@ -33,13 +33,19 @@ const throughInitialExec = (element, exclude = {}) => {
33
33
  const prop = element[param];
34
34
  if ((0, import_utils.isFunction)(prop) && !(0, import_utils.isMethod)(param, element)) {
35
35
  ref.__exec[param] = prop;
36
- const result = prop(element, element.state, element.context);
37
- if (result && typeof result.then === "function") {
38
- result.then((resolved) => {
39
- element[param] = resolved;
40
- });
41
- } else {
42
- element[param] = result;
36
+ try {
37
+ const result = prop(element, element.state, element.context);
38
+ if (result && typeof result.then === "function") {
39
+ result.then((resolved) => {
40
+ element[param] = resolved;
41
+ }).catch((e) => {
42
+ console.warn("[DOMQL] Async exec error in", param, ":", e?.message || e);
43
+ });
44
+ } else {
45
+ element[param] = result;
46
+ }
47
+ } catch (e) {
48
+ console.warn("[DOMQL] Exec error in", param, ":", e?.message || e);
43
49
  }
44
50
  }
45
51
  }
@@ -24,10 +24,7 @@ __export(html_exports, {
24
24
  module.exports = __toCommonJS(html_exports);
25
25
  var import_utils = require("@domql/utils");
26
26
  function html(param, element, node) {
27
- let prop = (0, import_utils.exec)(param ?? element?.props?.html, element);
28
- if ((0, import_utils.isString)(prop) && prop.includes("{{") && element.call) {
29
- prop = element.call("replaceLiteralsWithObjectFields", prop, element.state);
30
- }
27
+ const prop = (0, import_utils.exec)(param ?? element?.props?.html, element);
31
28
  const { __ref } = element;
32
29
  if (prop !== __ref.__html) {
33
30
  if (node.nodeName === "SVG") node.textContent = prop;
@@ -63,15 +63,11 @@ const create = (props, parentEl, passedKey, options = OPTIONS.create || {}, atta
63
63
  addMethods(element, parent, options);
64
64
  createScope(element, parent);
65
65
  createState(element, parent);
66
- if (element.scope === "state") element.scope = element.state;
67
66
  createIfConditionFlag(element, parent);
68
67
  initProps(element, parent, options);
69
68
  pickupElementFromProps.call(element, element, { cachedKeys: [] });
70
69
  if (!element.tag) element.tag = detectTag(element);
71
70
  applyPropsAsAttrs(element);
72
- if (element.scope === "props" || element.scope === true) {
73
- element.scope = element.props;
74
- }
75
71
  createIfConditionFlag(element, parent);
76
72
  if (element.node) {
77
73
  if (ref.__if) return assignNode(element, parent, key, attachOptions);
@@ -167,13 +163,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
167
163
  addMethods(element, parent, options);
168
164
  createScope(element, parent);
169
165
  createState(element, parent);
170
- if (element.scope === "state") element.scope = element.state;
171
166
  createIfConditionFlag(element, parent);
172
167
  initProps(element, parent, options);
173
168
  pickupElementFromProps.call(element, element, { cachedKeys: [] });
174
- if (element.scope === "props" || element.scope === true) {
175
- element.scope = element.props;
176
- }
177
169
  if (element.node && ref.__if) {
178
170
  parent[key || element.key] = element;
179
171
  }
@@ -192,7 +184,11 @@ const onlyResolveExtends = (element, parent, key, options) => {
192
184
  if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
193
185
  continue;
194
186
  } else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
195
- create(exec(element[k], element), element, k, options);
187
+ try {
188
+ create(exec(element[k], element), element, k, options);
189
+ } catch (e) {
190
+ console.warn("[DOMQL] onlyResolveExtends child error in", k, ":", e?.message || e);
191
+ }
196
192
  }
197
193
  }
198
194
  }
@@ -16,13 +16,19 @@ const throughInitialExec = (element, exclude = {}) => {
16
16
  const prop = element[param];
17
17
  if (isFunction(prop) && !isMethod(param, element)) {
18
18
  ref.__exec[param] = prop;
19
- const result = prop(element, element.state, element.context);
20
- if (result && typeof result.then === "function") {
21
- result.then((resolved) => {
22
- element[param] = resolved;
23
- });
24
- } else {
25
- element[param] = result;
19
+ try {
20
+ const result = prop(element, element.state, element.context);
21
+ if (result && typeof result.then === "function") {
22
+ result.then((resolved) => {
23
+ element[param] = resolved;
24
+ }).catch((e) => {
25
+ console.warn("[DOMQL] Async exec error in", param, ":", e?.message || e);
26
+ });
27
+ } else {
28
+ element[param] = result;
29
+ }
30
+ } catch (e) {
31
+ console.warn("[DOMQL] Exec error in", param, ":", e?.message || e);
26
32
  }
27
33
  }
28
34
  }
@@ -1,9 +1,6 @@
1
- import { exec, isString } from "@domql/utils";
1
+ import { exec } from "@domql/utils";
2
2
  function html(param, element, node) {
3
- let prop = exec(param ?? element?.props?.html, element);
4
- if (isString(prop) && prop.includes("{{") && element.call) {
5
- prop = element.call("replaceLiteralsWithObjectFields", prop, element.state);
6
- }
3
+ const prop = exec(param ?? element?.props?.html, element);
7
4
  const { __ref } = element;
8
5
  if (prop !== __ref.__html) {
9
6
  if (node.nodeName === "SVG") node.textContent = prop;
@@ -1813,7 +1813,24 @@ var DomqlElement = (() => {
1813
1813
  "../utils/dist/esm/scope.js"() {
1814
1814
  createScope = (element, parent) => {
1815
1815
  const { __ref: ref } = element;
1816
- if (!element.scope) element.scope = parent.scope || ref.root?.scope || {};
1816
+ const context = element.context || parent.context || ref.root?.context;
1817
+ if (context && !context.globalScope) context.globalScope = {};
1818
+ const parentScope = parent.scope || ref.root?.scope;
1819
+ const globalScope = context?.globalScope;
1820
+ if (!element.scope) {
1821
+ if (parentScope) {
1822
+ element.scope = parentScope;
1823
+ } else if (globalScope) {
1824
+ element.scope = Object.create(globalScope);
1825
+ } else {
1826
+ element.scope = {};
1827
+ }
1828
+ } else if (typeof element.scope === "object" && element.scope !== null) {
1829
+ if (Object.getPrototypeOf(element.scope) === Object.prototype) {
1830
+ const proto = parentScope || globalScope;
1831
+ if (proto) Object.setPrototypeOf(element.scope, proto);
1832
+ }
1833
+ }
1817
1834
  };
1818
1835
  }
1819
1836
  });
@@ -1941,7 +1958,9 @@ var DomqlElement = (() => {
1941
1958
  );
1942
1959
  createClient = mod.createClient;
1943
1960
  }
1944
- return supabaseAdapter(createClient(supabaseUrl, key, options));
1961
+ const client = createClient(supabaseUrl, key, options);
1962
+ if (!client || !client.auth) return null;
1963
+ return supabaseAdapter(client);
1945
1964
  };
1946
1965
  applyFilters = (query, params) => {
1947
1966
  if (!params) return query;
@@ -2573,7 +2592,7 @@ var DomqlElement = (() => {
2573
2592
  return resolved;
2574
2593
  };
2575
2594
  initAdapterAuth = async (adapter, context) => {
2576
- if (adapter.__authInitialized) return;
2595
+ if (!adapter || adapter.__authInitialized) return;
2577
2596
  adapter.__authInitialized = true;
2578
2597
  if (!adapter.getSession) return;
2579
2598
  const updateAuth = (user, session) => {
@@ -2605,9 +2624,10 @@ var DomqlElement = (() => {
2605
2624
  if (db.__resolving) return db.__resolving;
2606
2625
  db.__resolving = resolveDb(db);
2607
2626
  const resolved = await db.__resolving;
2627
+ delete db.__resolving;
2628
+ if (!resolved) return null;
2608
2629
  db.__resolved = resolved;
2609
2630
  context.fetch = resolved;
2610
- delete db.__resolving;
2611
2631
  if (db.auth !== false) await initAdapterAuth(resolved, context);
2612
2632
  return resolved;
2613
2633
  };
@@ -4140,13 +4160,19 @@ ${element}` : "";
4140
4160
  const prop = element[param];
4141
4161
  if (isFunction(prop) && !isMethod(param, element)) {
4142
4162
  ref.__exec[param] = prop;
4143
- const result = prop(element, element.state, element.context);
4144
- if (result && typeof result.then === "function") {
4145
- result.then((resolved) => {
4146
- element[param] = resolved;
4147
- });
4148
- } else {
4149
- element[param] = result;
4163
+ try {
4164
+ const result = prop(element, element.state, element.context);
4165
+ if (result && typeof result.then === "function") {
4166
+ result.then((resolved) => {
4167
+ element[param] = resolved;
4168
+ }).catch((e) => {
4169
+ console.warn("[DOMQL] Async exec error in", param, ":", e?.message || e);
4170
+ });
4171
+ } else {
4172
+ element[param] = result;
4173
+ }
4174
+ } catch (e) {
4175
+ console.warn("[DOMQL] Exec error in", param, ":", e?.message || e);
4150
4176
  }
4151
4177
  }
4152
4178
  }
@@ -4366,10 +4392,7 @@ ${element}` : "";
4366
4392
  // mixins/html.js
4367
4393
  init_esm();
4368
4394
  function html(param, element, node) {
4369
- let prop = exec(param ?? element?.props?.html, element);
4370
- if (isString(prop) && prop.includes("{{") && element.call) {
4371
- prop = element.call("replaceLiteralsWithObjectFields", prop, element.state);
4372
- }
4395
+ const prop = exec(param ?? element?.props?.html, element);
4373
4396
  const { __ref } = element;
4374
4397
  if (prop !== __ref.__html) {
4375
4398
  if (node.nodeName === "SVG") node.textContent = prop;
@@ -6508,15 +6531,11 @@ ${element}` : "";
6508
6531
  addMethods(element, parent, options);
6509
6532
  createScope(element, parent);
6510
6533
  createState(element, parent);
6511
- if (element.scope === "state") element.scope = element.state;
6512
6534
  createIfConditionFlag(element, parent);
6513
6535
  initProps(element, parent, options);
6514
6536
  pickupElementFromProps.call(element, element, { cachedKeys: [] });
6515
6537
  if (!element.tag) element.tag = detectTag(element);
6516
6538
  applyPropsAsAttrs(element);
6517
- if (element.scope === "props" || element.scope === true) {
6518
- element.scope = element.props;
6519
- }
6520
6539
  createIfConditionFlag(element, parent);
6521
6540
  if (element.node) {
6522
6541
  if (ref.__if) return assignNode(element, parent, key, attachOptions);
@@ -6612,13 +6631,9 @@ ${element}` : "";
6612
6631
  addMethods(element, parent, options);
6613
6632
  createScope(element, parent);
6614
6633
  createState(element, parent);
6615
- if (element.scope === "state") element.scope = element.state;
6616
6634
  createIfConditionFlag(element, parent);
6617
6635
  initProps(element, parent, options);
6618
6636
  pickupElementFromProps.call(element, element, { cachedKeys: [] });
6619
- if (element.scope === "props" || element.scope === true) {
6620
- element.scope = element.props;
6621
- }
6622
6637
  if (element.node && ref.__if) {
6623
6638
  parent[key || element.key] = element;
6624
6639
  }
@@ -6637,7 +6652,11 @@ ${element}` : "";
6637
6652
  if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
6638
6653
  continue;
6639
6654
  } else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
6640
- create(exec(element[k], element), element, k, options);
6655
+ try {
6656
+ create(exec(element[k], element), element, k, options);
6657
+ } catch (e) {
6658
+ console.warn("[DOMQL] onlyResolveExtends child error in", k, ":", e?.message || e);
6659
+ }
6641
6660
  }
6642
6661
  }
6643
6662
  }
package/iterate.js CHANGED
@@ -19,13 +19,19 @@ export const throughInitialExec = (element, exclude = {}) => {
19
19
  const prop = element[param]
20
20
  if (isFunction(prop) && !isMethod(param, element)) {
21
21
  ref.__exec[param] = prop
22
- const result = prop(element, element.state, element.context)
23
- if (result && typeof result.then === 'function') {
24
- result.then(resolved => {
25
- element[param] = resolved
26
- })
27
- } else {
28
- element[param] = result
22
+ try {
23
+ const result = prop(element, element.state, element.context)
24
+ if (result && typeof result.then === 'function') {
25
+ result.then(resolved => {
26
+ element[param] = resolved
27
+ }).catch(e => {
28
+ console.warn('[DOMQL] Async exec error in', param, ':', e?.message || e)
29
+ })
30
+ } else {
31
+ element[param] = result
32
+ }
33
+ } catch (e) {
34
+ console.warn('[DOMQL] Exec error in', param, ':', e?.message || e)
29
35
  }
30
36
  }
31
37
  }
package/mixins/html.js CHANGED
@@ -1,16 +1,13 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isString } from '@domql/utils'
3
+ import { exec } from '@domql/utils'
4
4
 
5
5
  /**
6
6
  * Appends raw HTML as content
7
7
  * an original one as a child
8
8
  */
9
9
  export function html (param, element, node) {
10
- let prop = exec(param ?? element?.props?.html, element)
11
- if (isString(prop) && prop.includes('{{') && element.call) {
12
- prop = element.call('replaceLiteralsWithObjectFields', prop, element.state)
13
- }
10
+ const prop = exec(param ?? element?.props?.html, element)
14
11
  const { __ref } = element
15
12
  if (prop !== __ref.__html) {
16
13
  if (node.nodeName === 'SVG') node.textContent = prop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "3.7.4",
3
+ "version": "3.7.6",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -46,10 +46,10 @@
46
46
  "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=DomqlElement --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
47
47
  },
48
48
  "dependencies": {
49
- "@domql/report": "^3.7.4",
50
- "@domql/state": "^3.7.4",
51
- "@domql/utils": "^3.7.4",
52
- "attrs-in-props": "^3.7.4"
49
+ "@domql/report": "^3.7.6",
50
+ "@domql/state": "^3.7.6",
51
+ "@domql/utils": "^3.7.6",
52
+ "attrs-in-props": "^3.7.6"
53
53
  },
54
54
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
55
55
  "devDependencies": {