@domql/element 3.8.0 → 3.8.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/create.js CHANGED
@@ -29,7 +29,7 @@ import { REGISTRY } from './mixins/index.js'
29
29
  import { addMethods } from './methods/set.js'
30
30
  import { assignKeyAsClassname } from './mixins/classList.js'
31
31
  import { throughInitialExec, throughInitialDefine } from './iterate.js'
32
- import { filterAttributesByTagName } from 'attrs-in-props'
32
+ import { filterAttributesByTagName, extractConditionalAttrs, ATTR_TRANSFORMS } from 'attrs-in-props'
33
33
 
34
34
  const EXCLUDED_ATTRS = new Set(['class', 'style'])
35
35
 
@@ -37,11 +37,20 @@ const applyPropsAsAttrs = (element) => {
37
37
  const { tag, props, context } = element
38
38
  if (!tag || !props) return
39
39
 
40
- const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry)
40
+ const cssProps = context?.cssPropsRegistry
41
+ const autoAttrs = filterAttributesByTagName(tag, props, cssProps)
42
+ const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps)
43
+
41
44
  const filtered = {}
42
45
  for (const key in autoAttrs) {
43
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key]
46
+ if (!EXCLUDED_ATTRS.has(key)) {
47
+ filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key]
48
+ }
44
49
  }
50
+ for (const key in conditionalAttrs) {
51
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key]
52
+ }
53
+
45
54
  let hasFiltered = false
46
55
  for (const _k in filtered) { hasFiltered = true; break } // eslint-disable-line
47
56
  if (!hasFiltered) return
@@ -196,7 +205,8 @@ const renderElement = (element, parent, options, attachOptions) => {
196
205
  isDemoComponent ? isDemoComponent + ' ' : '' + path.join('.')
197
206
  )
198
207
  element.verbose()
199
- console.error('[DOMQL] Render error:', e)
208
+ if (e instanceof ReferenceError) console.warn('[DOMQL] Render warning:', e.message)
209
+ else console.error('[DOMQL] Render error:', e)
200
210
  if (element.on?.error) {
201
211
  element.on.error(e, element, element.state, element.context, options)
202
212
  }
@@ -38,10 +38,17 @@ const EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
38
38
  const applyPropsAsAttrs = (element) => {
39
39
  const { tag, props, context } = element;
40
40
  if (!tag || !props) return;
41
- const autoAttrs = (0, import_attrs_in_props.filterAttributesByTagName)(tag, props, context?.cssPropsRegistry);
41
+ const cssProps = context?.cssPropsRegistry;
42
+ const autoAttrs = (0, import_attrs_in_props.filterAttributesByTagName)(tag, props, cssProps);
43
+ const conditionalAttrs = (0, import_attrs_in_props.extractConditionalAttrs)(props, tag, cssProps);
42
44
  const filtered = {};
43
45
  for (const key in autoAttrs) {
44
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
46
+ if (!EXCLUDED_ATTRS.has(key)) {
47
+ filtered[key] = import_attrs_in_props.ATTR_TRANSFORMS[key] ? import_attrs_in_props.ATTR_TRANSFORMS[key] : autoAttrs[key];
48
+ }
49
+ }
50
+ for (const key in conditionalAttrs) {
51
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
45
52
  }
46
53
  let hasFiltered = false;
47
54
  for (const _k in filtered) {
@@ -150,7 +157,8 @@ const renderElement = (element, parent, options, attachOptions) => {
150
157
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
151
158
  );
152
159
  element.verbose();
153
- console.error("[DOMQL] Render error:", e);
160
+ if (e instanceof ReferenceError) console.warn("[DOMQL] Render warning:", e.message);
161
+ else console.error("[DOMQL] Render error:", e);
154
162
  if (element.on?.error) {
155
163
  element.on.error(e, element, element.state, element.context, options);
156
164
  }
@@ -24,15 +24,22 @@ import { REGISTRY } from "./mixins/index.js";
24
24
  import { addMethods } from "./methods/set.js";
25
25
  import { assignKeyAsClassname } from "./mixins/classList.js";
26
26
  import { throughInitialExec, throughInitialDefine } from "./iterate.js";
27
- import { filterAttributesByTagName } from "attrs-in-props";
27
+ import { filterAttributesByTagName, extractConditionalAttrs, ATTR_TRANSFORMS } from "attrs-in-props";
28
28
  const EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
29
29
  const applyPropsAsAttrs = (element) => {
30
30
  const { tag, props, context } = element;
31
31
  if (!tag || !props) return;
32
- const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry);
32
+ const cssProps = context?.cssPropsRegistry;
33
+ const autoAttrs = filterAttributesByTagName(tag, props, cssProps);
34
+ const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps);
33
35
  const filtered = {};
34
36
  for (const key in autoAttrs) {
35
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
37
+ if (!EXCLUDED_ATTRS.has(key)) {
38
+ filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key];
39
+ }
40
+ }
41
+ for (const key in conditionalAttrs) {
42
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
36
43
  }
37
44
  let hasFiltered = false;
38
45
  for (const _k in filtered) {
@@ -141,7 +148,8 @@ const renderElement = (element, parent, options, attachOptions) => {
141
148
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
142
149
  );
143
150
  element.verbose();
144
- console.error("[DOMQL] Render error:", e);
151
+ if (e instanceof ReferenceError) console.warn("[DOMQL] Render warning:", e.message);
152
+ else console.error("[DOMQL] Render error:", e);
145
153
  if (element.on?.error) {
146
154
  element.on.error(e, element, element.state, element.context, options);
147
155
  }
@@ -352,6 +352,17 @@ var DomqlElement = (() => {
352
352
  }
353
353
  return result;
354
354
  }
355
+ if (param != null && element?.context?.plugins && (isArray(param) || isObject(param) && !isDOMNode(param))) {
356
+ const plugins = element.context.plugins;
357
+ for (const plugin of plugins) {
358
+ if (plugin.resolveHandler) {
359
+ const resolved = plugin.resolveHandler(param, element);
360
+ if (typeof resolved === "function") {
361
+ return exec(resolved, element, state2, context);
362
+ }
363
+ }
364
+ }
365
+ }
355
366
  return param;
356
367
  };
357
368
  merge = (element, obj, excludeFrom = []) => {
@@ -671,11 +682,21 @@ var DomqlElement = (() => {
671
682
  var init_if = __esm({
672
683
  "../utils/dist/esm/if.js"() {
673
684
  init_types();
685
+ init_object();
674
686
  createIfConditionFlag = (element, parent) => {
675
687
  const { __ref: ref } = element;
676
- if (isFunction(element.if) && !element.if(element, element.state, element.context)) {
677
- delete ref.__if;
678
- } else ref.__if = true;
688
+ const ifVal = element.if;
689
+ if (isFunction(ifVal)) {
690
+ if (!ifVal(element, element.state, element.context)) {
691
+ delete ref.__if;
692
+ } else ref.__if = true;
693
+ } else if (ifVal != null && typeof ifVal === "object") {
694
+ const result = exec(ifVal, element);
695
+ if (!result) delete ref.__if;
696
+ else ref.__if = true;
697
+ } else {
698
+ ref.__if = true;
699
+ }
679
700
  };
680
701
  }
681
702
  });
@@ -1335,7 +1356,7 @@ var DomqlElement = (() => {
1335
1356
  const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
1336
1357
  const isBuiltin = DOMQ_PROPERTIES.has(key);
1337
1358
  if (!isElement && !isBuiltin) {
1338
- obj.props[key] = value;
1359
+ if (!(key in obj.props)) obj.props[key] = value;
1339
1360
  delete obj[key];
1340
1361
  cachedKeys.push(key);
1341
1362
  }
@@ -1863,13 +1884,18 @@ var DomqlElement = (() => {
1863
1884
  if (result && typeof result.then === "function") {
1864
1885
  result.catch((err) => {
1865
1886
  element.error = err;
1866
- console.error("[DOMQL] Async event error:", err);
1887
+ if (err instanceof ReferenceError) console.warn("[DOMQL] Async event warning:", err.message);
1888
+ else console.error("[DOMQL] Async event error:", err);
1867
1889
  });
1868
1890
  }
1869
1891
  return result;
1870
1892
  } catch (err) {
1871
1893
  element.error = err;
1872
- console.error("[DOMQL] Event handler error:", err);
1894
+ if (err instanceof ReferenceError) {
1895
+ console.warn("[DOMQL] Event handler warning:", err.message);
1896
+ } else {
1897
+ console.error("[DOMQL] Event handler error:", err);
1898
+ }
1873
1899
  if (element.context?.strictMode) throw err;
1874
1900
  }
1875
1901
  };
@@ -2605,6 +2631,7 @@ var DomqlElement = (() => {
2605
2631
  const session = await adapter.getSession();
2606
2632
  updateAuth(session?.user || null, session);
2607
2633
  } catch (e) {
2634
+ console.warn("[fetch] Failed to restore auth session:", e.message);
2608
2635
  }
2609
2636
  if (adapter.onAuthStateChange) {
2610
2637
  adapter.onAuthStateChange((event, session) => {
@@ -6464,7 +6491,18 @@ ${element}` : "";
6464
6491
  "onfullscreenchange",
6465
6492
  "onfullscreenerror"
6466
6493
  ];
6494
+ var camelToAttr = (key) => {
6495
+ if (key.startsWith("aria") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6496
+ return "aria-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6497
+ }
6498
+ if (key.startsWith("data") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6499
+ return "data-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6500
+ }
6501
+ return null;
6502
+ };
6467
6503
  var checkAttributeByTagName = (tag, attribute) => {
6504
+ if (attribute.startsWith("aria-") || attribute.startsWith("data-")) return true;
6505
+ if (camelToAttr(attribute)) return true;
6468
6506
  if (Object.prototype.hasOwnProperty.call(HTML_ATTRIBUTES, tag)) {
6469
6507
  const attributes = HTML_ATTRIBUTES[tag];
6470
6508
  return attributes.includes(attribute) || attributes.includes("default");
@@ -6483,25 +6521,139 @@ ${element}` : "";
6483
6521
  for (const key in props) {
6484
6522
  if (Object.prototype.hasOwnProperty.call(props, key)) {
6485
6523
  if (cssProps && key in cssProps) continue;
6524
+ if (key === "aria" && props[key] && typeof props[key] === "object") {
6525
+ for (const ariaKey in props[key]) {
6526
+ if (isDefined(props[key][ariaKey])) {
6527
+ filteredObject["aria-" + ariaKey] = props[key][ariaKey];
6528
+ }
6529
+ }
6530
+ continue;
6531
+ }
6532
+ if (key === "data" && props[key] && typeof props[key] === "object") {
6533
+ for (const dataKey in props[key]) {
6534
+ if (isDefined(props[key][dataKey])) {
6535
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6536
+ filteredObject["data-" + kebab] = props[key][dataKey];
6537
+ }
6538
+ }
6539
+ continue;
6540
+ }
6486
6541
  const isAttribute = checkAttributeByTagName(tag, key);
6487
6542
  const isEvent = checkEventFunctions(key);
6488
6543
  if (isDefined(props[key]) && (isAttribute || isEvent)) {
6489
- filteredObject[key] = props[key];
6544
+ const attrName = camelToAttr(key) || key;
6545
+ filteredObject[attrName] = props[key];
6490
6546
  }
6491
6547
  }
6492
6548
  }
6493
6549
  return filteredObject;
6494
6550
  };
6551
+ var resolvePropValue = (el, value) => {
6552
+ let resolved = el.call("exec", value, el);
6553
+ if (!resolved) return;
6554
+ if (isString(resolved) && resolved.includes("{{")) {
6555
+ resolved = el.call("replaceLiteralsWithObjectFields", resolved);
6556
+ }
6557
+ return resolved;
6558
+ };
6559
+ var resolveFileSource = (el, value) => {
6560
+ let src = (el.props.preSrc || "") + (resolvePropValue(el, value) || "");
6561
+ if (!src) return;
6562
+ try {
6563
+ new URL(src);
6564
+ return src;
6565
+ } catch (e) {
6566
+ }
6567
+ const { context } = el;
6568
+ if (!context.files) return src;
6569
+ const fileSrc = src.startsWith("/files/") ? src.slice(7) : src;
6570
+ const file = context.files[src] || context.files[fileSrc];
6571
+ if (file && file.content) return file.content.src;
6572
+ return src;
6573
+ };
6574
+ var ATTR_TRANSFORMS = {
6575
+ src: (el) => resolveFileSource(el, el.props.src),
6576
+ href: (el) => resolvePropValue(el, el.props.href),
6577
+ action: (el) => resolvePropValue(el, el.props.action),
6578
+ poster: (el) => resolveFileSource(el, el.props.poster),
6579
+ data: (el) => resolvePropValue(el, el.props.data)
6580
+ };
6581
+ var resolveCase = (caseKey, element) => {
6582
+ const caseFn = element.context?.cases?.[caseKey];
6583
+ if (caseFn === void 0) return void 0;
6584
+ if (isFunction(caseFn)) return caseFn.call(element, element);
6585
+ return !!caseFn;
6586
+ };
6587
+ var evaluateCondition = (prefix, caseKey, element) => {
6588
+ if (prefix === "$") {
6589
+ let result = resolveCase(caseKey, element);
6590
+ if (result === void 0) result = !!element.props?.[caseKey];
6591
+ return result;
6592
+ }
6593
+ let isTruthy = element.props[caseKey] === true || element.state[caseKey] || element[caseKey];
6594
+ if (!isTruthy) {
6595
+ const caseResult = resolveCase(caseKey, element);
6596
+ if (caseResult !== void 0) isTruthy = caseResult;
6597
+ }
6598
+ return prefix === "." ? !!isTruthy : !isTruthy;
6599
+ };
6600
+ var CONDITIONAL_PREFIXES = /* @__PURE__ */ new Set(["$", ".", "!"]);
6601
+ var extractConditionalAttrs = (props, tag, cssProps) => {
6602
+ const result = {};
6603
+ const addConditionalAttr = (attrName, attrVal, prefix, caseKey) => {
6604
+ const capturedVal = attrVal;
6605
+ result[attrName] = (el) => {
6606
+ if (!evaluateCondition(prefix, caseKey, el)) return void 0;
6607
+ return isFunction(capturedVal) ? capturedVal(el) : capturedVal;
6608
+ };
6609
+ };
6610
+ for (const key in props) {
6611
+ const prefix = key.charAt(0);
6612
+ if (!CONDITIONAL_PREFIXES.has(prefix)) continue;
6613
+ const block = props[key];
6614
+ if (!block || typeof block !== "object") continue;
6615
+ const caseKey = key.slice(1);
6616
+ for (const attrKey in block) {
6617
+ if (cssProps && attrKey in cssProps) continue;
6618
+ if (attrKey === "aria" && block[attrKey] && typeof block[attrKey] === "object") {
6619
+ for (const ariaKey in block[attrKey]) {
6620
+ addConditionalAttr("aria-" + ariaKey, block[attrKey][ariaKey], prefix, caseKey);
6621
+ }
6622
+ continue;
6623
+ }
6624
+ if (attrKey === "data" && block[attrKey] && typeof block[attrKey] === "object") {
6625
+ for (const dataKey in block[attrKey]) {
6626
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6627
+ addConditionalAttr("data-" + kebab, block[attrKey][dataKey], prefix, caseKey);
6628
+ }
6629
+ continue;
6630
+ }
6631
+ const isAttribute = checkAttributeByTagName(tag, attrKey);
6632
+ const isEvent = checkEventFunctions(attrKey);
6633
+ if (!isAttribute && !isEvent) continue;
6634
+ const attrName = camelToAttr(attrKey) || attrKey;
6635
+ addConditionalAttr(attrName, block[attrKey], prefix, caseKey);
6636
+ }
6637
+ }
6638
+ return result;
6639
+ };
6495
6640
 
6496
6641
  // create.js
6497
6642
  var EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
6498
6643
  var applyPropsAsAttrs = (element) => {
6499
6644
  const { tag, props, context } = element;
6500
6645
  if (!tag || !props) return;
6501
- const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry);
6646
+ const cssProps = context?.cssPropsRegistry;
6647
+ const autoAttrs = filterAttributesByTagName(tag, props, cssProps);
6648
+ const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps);
6502
6649
  const filtered = {};
6503
6650
  for (const key in autoAttrs) {
6504
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
6651
+ if (!EXCLUDED_ATTRS.has(key)) {
6652
+ filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key];
6653
+ }
6654
+ }
6655
+ for (const key in conditionalAttrs) {
6656
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
6505
6657
  }
6506
6658
  let hasFiltered = false;
6507
6659
  for (const _k in filtered) {
@@ -6610,7 +6762,8 @@ ${element}` : "";
6610
6762
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
6611
6763
  );
6612
6764
  element.verbose();
6613
- console.error("[DOMQL] Render error:", e);
6765
+ if (e instanceof ReferenceError) console.warn("[DOMQL] Render warning:", e.message);
6766
+ else console.error("[DOMQL] Render error:", e);
6614
6767
  if (element.on?.error) {
6615
6768
  element.on.error(e, element, element.state, element.context, options);
6616
6769
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "3.8.0",
3
+ "version": "3.8.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.8.0",
50
- "@domql/state": "^3.8.0",
51
- "@domql/utils": "^3.8.0",
52
- "attrs-in-props": "^3.8.0"
49
+ "@domql/report": "^3.8.6",
50
+ "@domql/state": "^3.8.6",
51
+ "@domql/utils": "^3.8.6",
52
+ "attrs-in-props": "^3.8.6"
53
53
  },
54
54
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
55
55
  "devDependencies": {