domql 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.
Files changed (2) hide show
  1. package/dist/iife/index.js +163 -10
  2. package/package.json +4 -4
@@ -352,6 +352,17 @@ var Domql = (() => {
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 Domql = (() => {
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 Domql = (() => {
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 Domql = (() => {
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 Domql = (() => {
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) => {
@@ -6435,7 +6462,18 @@ ${element}` : "";
6435
6462
  "onfullscreenchange",
6436
6463
  "onfullscreenerror"
6437
6464
  ];
6465
+ var camelToAttr = (key) => {
6466
+ if (key.startsWith("aria") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6467
+ return "aria-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6468
+ }
6469
+ if (key.startsWith("data") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6470
+ return "data-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6471
+ }
6472
+ return null;
6473
+ };
6438
6474
  var checkAttributeByTagName = (tag, attribute) => {
6475
+ if (attribute.startsWith("aria-") || attribute.startsWith("data-")) return true;
6476
+ if (camelToAttr(attribute)) return true;
6439
6477
  if (Object.prototype.hasOwnProperty.call(HTML_ATTRIBUTES, tag)) {
6440
6478
  const attributes = HTML_ATTRIBUTES[tag];
6441
6479
  return attributes.includes(attribute) || attributes.includes("default");
@@ -6454,25 +6492,139 @@ ${element}` : "";
6454
6492
  for (const key in props) {
6455
6493
  if (Object.prototype.hasOwnProperty.call(props, key)) {
6456
6494
  if (cssProps && key in cssProps) continue;
6495
+ if (key === "aria" && props[key] && typeof props[key] === "object") {
6496
+ for (const ariaKey in props[key]) {
6497
+ if (isDefined(props[key][ariaKey])) {
6498
+ filteredObject["aria-" + ariaKey] = props[key][ariaKey];
6499
+ }
6500
+ }
6501
+ continue;
6502
+ }
6503
+ if (key === "data" && props[key] && typeof props[key] === "object") {
6504
+ for (const dataKey in props[key]) {
6505
+ if (isDefined(props[key][dataKey])) {
6506
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6507
+ filteredObject["data-" + kebab] = props[key][dataKey];
6508
+ }
6509
+ }
6510
+ continue;
6511
+ }
6457
6512
  const isAttribute = checkAttributeByTagName(tag, key);
6458
6513
  const isEvent = checkEventFunctions(key);
6459
6514
  if (isDefined(props[key]) && (isAttribute || isEvent)) {
6460
- filteredObject[key] = props[key];
6515
+ const attrName = camelToAttr(key) || key;
6516
+ filteredObject[attrName] = props[key];
6461
6517
  }
6462
6518
  }
6463
6519
  }
6464
6520
  return filteredObject;
6465
6521
  };
6522
+ var resolvePropValue = (el, value) => {
6523
+ let resolved = el.call("exec", value, el);
6524
+ if (!resolved) return;
6525
+ if (isString(resolved) && resolved.includes("{{")) {
6526
+ resolved = el.call("replaceLiteralsWithObjectFields", resolved);
6527
+ }
6528
+ return resolved;
6529
+ };
6530
+ var resolveFileSource = (el, value) => {
6531
+ let src = (el.props.preSrc || "") + (resolvePropValue(el, value) || "");
6532
+ if (!src) return;
6533
+ try {
6534
+ new URL(src);
6535
+ return src;
6536
+ } catch (e) {
6537
+ }
6538
+ const { context } = el;
6539
+ if (!context.files) return src;
6540
+ const fileSrc = src.startsWith("/files/") ? src.slice(7) : src;
6541
+ const file = context.files[src] || context.files[fileSrc];
6542
+ if (file && file.content) return file.content.src;
6543
+ return src;
6544
+ };
6545
+ var ATTR_TRANSFORMS = {
6546
+ src: (el) => resolveFileSource(el, el.props.src),
6547
+ href: (el) => resolvePropValue(el, el.props.href),
6548
+ action: (el) => resolvePropValue(el, el.props.action),
6549
+ poster: (el) => resolveFileSource(el, el.props.poster),
6550
+ data: (el) => resolvePropValue(el, el.props.data)
6551
+ };
6552
+ var resolveCase = (caseKey, element) => {
6553
+ const caseFn = element.context?.cases?.[caseKey];
6554
+ if (caseFn === void 0) return void 0;
6555
+ if (isFunction(caseFn)) return caseFn.call(element, element);
6556
+ return !!caseFn;
6557
+ };
6558
+ var evaluateCondition = (prefix, caseKey, element) => {
6559
+ if (prefix === "$") {
6560
+ let result = resolveCase(caseKey, element);
6561
+ if (result === void 0) result = !!element.props?.[caseKey];
6562
+ return result;
6563
+ }
6564
+ let isTruthy = element.props[caseKey] === true || element.state[caseKey] || element[caseKey];
6565
+ if (!isTruthy) {
6566
+ const caseResult = resolveCase(caseKey, element);
6567
+ if (caseResult !== void 0) isTruthy = caseResult;
6568
+ }
6569
+ return prefix === "." ? !!isTruthy : !isTruthy;
6570
+ };
6571
+ var CONDITIONAL_PREFIXES = /* @__PURE__ */ new Set(["$", ".", "!"]);
6572
+ var extractConditionalAttrs = (props, tag, cssProps) => {
6573
+ const result = {};
6574
+ const addConditionalAttr = (attrName, attrVal, prefix, caseKey) => {
6575
+ const capturedVal = attrVal;
6576
+ result[attrName] = (el) => {
6577
+ if (!evaluateCondition(prefix, caseKey, el)) return void 0;
6578
+ return isFunction(capturedVal) ? capturedVal(el) : capturedVal;
6579
+ };
6580
+ };
6581
+ for (const key in props) {
6582
+ const prefix = key.charAt(0);
6583
+ if (!CONDITIONAL_PREFIXES.has(prefix)) continue;
6584
+ const block = props[key];
6585
+ if (!block || typeof block !== "object") continue;
6586
+ const caseKey = key.slice(1);
6587
+ for (const attrKey in block) {
6588
+ if (cssProps && attrKey in cssProps) continue;
6589
+ if (attrKey === "aria" && block[attrKey] && typeof block[attrKey] === "object") {
6590
+ for (const ariaKey in block[attrKey]) {
6591
+ addConditionalAttr("aria-" + ariaKey, block[attrKey][ariaKey], prefix, caseKey);
6592
+ }
6593
+ continue;
6594
+ }
6595
+ if (attrKey === "data" && block[attrKey] && typeof block[attrKey] === "object") {
6596
+ for (const dataKey in block[attrKey]) {
6597
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6598
+ addConditionalAttr("data-" + kebab, block[attrKey][dataKey], prefix, caseKey);
6599
+ }
6600
+ continue;
6601
+ }
6602
+ const isAttribute = checkAttributeByTagName(tag, attrKey);
6603
+ const isEvent = checkEventFunctions(attrKey);
6604
+ if (!isAttribute && !isEvent) continue;
6605
+ const attrName = camelToAttr(attrKey) || attrKey;
6606
+ addConditionalAttr(attrName, block[attrKey], prefix, caseKey);
6607
+ }
6608
+ }
6609
+ return result;
6610
+ };
6466
6611
 
6467
6612
  // ../element/dist/esm/create.js
6468
6613
  var EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
6469
6614
  var applyPropsAsAttrs = (element) => {
6470
6615
  const { tag, props, context } = element;
6471
6616
  if (!tag || !props) return;
6472
- const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry);
6617
+ const cssProps = context?.cssPropsRegistry;
6618
+ const autoAttrs = filterAttributesByTagName(tag, props, cssProps);
6619
+ const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps);
6473
6620
  const filtered = {};
6474
6621
  for (const key in autoAttrs) {
6475
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
6622
+ if (!EXCLUDED_ATTRS.has(key)) {
6623
+ filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key];
6624
+ }
6625
+ }
6626
+ for (const key in conditionalAttrs) {
6627
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
6476
6628
  }
6477
6629
  let hasFiltered = false;
6478
6630
  for (const _k in filtered) {
@@ -6581,7 +6733,8 @@ ${element}` : "";
6581
6733
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
6582
6734
  );
6583
6735
  element.verbose();
6584
- console.error("[DOMQL] Render error:", e);
6736
+ if (e instanceof ReferenceError) console.warn("[DOMQL] Render warning:", e.message);
6737
+ else console.error("[DOMQL] Render error:", e);
6585
6738
  if (element.on?.error) {
6586
6739
  element.on.error(e, element, element.state, element.context, options);
6587
6740
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domql",
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",
@@ -25,9 +25,9 @@
25
25
  "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=Domql --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
26
26
  },
27
27
  "dependencies": {
28
- "@domql/element": "^3.8.0",
29
- "@domql/state": "^3.8.0",
30
- "@domql/utils": "^3.8.0"
28
+ "@domql/element": "^3.8.6",
29
+ "@domql/state": "^3.8.6",
30
+ "@domql/utils": "^3.8.6"
31
31
  },
32
32
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
33
33
  "browser": "./dist/esm/index.js",