@domql/element 3.8.0 → 3.8.1
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 +12 -3
- package/dist/cjs/create.js +9 -2
- package/dist/esm/create.js +10 -3
- package/dist/iife/index.js +130 -4
- package/package.json +5 -5
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
|
|
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))
|
|
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
|
package/dist/cjs/create.js
CHANGED
|
@@ -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
|
|
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))
|
|
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) {
|
package/dist/esm/create.js
CHANGED
|
@@ -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
|
|
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))
|
|
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) {
|
package/dist/iife/index.js
CHANGED
|
@@ -1335,7 +1335,7 @@ var DomqlElement = (() => {
|
|
|
1335
1335
|
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
1336
1336
|
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
1337
1337
|
if (!isElement && !isBuiltin) {
|
|
1338
|
-
obj.props[key] = value;
|
|
1338
|
+
if (!(key in obj.props)) obj.props[key] = value;
|
|
1339
1339
|
delete obj[key];
|
|
1340
1340
|
cachedKeys.push(key);
|
|
1341
1341
|
}
|
|
@@ -2605,6 +2605,7 @@ var DomqlElement = (() => {
|
|
|
2605
2605
|
const session = await adapter.getSession();
|
|
2606
2606
|
updateAuth(session?.user || null, session);
|
|
2607
2607
|
} catch (e) {
|
|
2608
|
+
console.warn("[fetch] Failed to restore auth session:", e.message);
|
|
2608
2609
|
}
|
|
2609
2610
|
if (adapter.onAuthStateChange) {
|
|
2610
2611
|
adapter.onAuthStateChange((event, session) => {
|
|
@@ -6464,7 +6465,18 @@ ${element}` : "";
|
|
|
6464
6465
|
"onfullscreenchange",
|
|
6465
6466
|
"onfullscreenerror"
|
|
6466
6467
|
];
|
|
6468
|
+
var camelToAttr = (key) => {
|
|
6469
|
+
if (key.startsWith("aria") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
|
|
6470
|
+
return "aria-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
|
|
6471
|
+
}
|
|
6472
|
+
if (key.startsWith("data") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
|
|
6473
|
+
return "data-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
|
|
6474
|
+
}
|
|
6475
|
+
return null;
|
|
6476
|
+
};
|
|
6467
6477
|
var checkAttributeByTagName = (tag, attribute) => {
|
|
6478
|
+
if (attribute.startsWith("aria-") || attribute.startsWith("data-")) return true;
|
|
6479
|
+
if (camelToAttr(attribute)) return true;
|
|
6468
6480
|
if (Object.prototype.hasOwnProperty.call(HTML_ATTRIBUTES, tag)) {
|
|
6469
6481
|
const attributes = HTML_ATTRIBUTES[tag];
|
|
6470
6482
|
return attributes.includes(attribute) || attributes.includes("default");
|
|
@@ -6483,25 +6495,139 @@ ${element}` : "";
|
|
|
6483
6495
|
for (const key in props) {
|
|
6484
6496
|
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
6485
6497
|
if (cssProps && key in cssProps) continue;
|
|
6498
|
+
if (key === "aria" && props[key] && typeof props[key] === "object") {
|
|
6499
|
+
for (const ariaKey in props[key]) {
|
|
6500
|
+
if (isDefined(props[key][ariaKey])) {
|
|
6501
|
+
filteredObject["aria-" + ariaKey] = props[key][ariaKey];
|
|
6502
|
+
}
|
|
6503
|
+
}
|
|
6504
|
+
continue;
|
|
6505
|
+
}
|
|
6506
|
+
if (key === "data" && props[key] && typeof props[key] === "object") {
|
|
6507
|
+
for (const dataKey in props[key]) {
|
|
6508
|
+
if (isDefined(props[key][dataKey])) {
|
|
6509
|
+
const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
|
|
6510
|
+
filteredObject["data-" + kebab] = props[key][dataKey];
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
continue;
|
|
6514
|
+
}
|
|
6486
6515
|
const isAttribute = checkAttributeByTagName(tag, key);
|
|
6487
6516
|
const isEvent = checkEventFunctions(key);
|
|
6488
6517
|
if (isDefined(props[key]) && (isAttribute || isEvent)) {
|
|
6489
|
-
|
|
6518
|
+
const attrName = camelToAttr(key) || key;
|
|
6519
|
+
filteredObject[attrName] = props[key];
|
|
6490
6520
|
}
|
|
6491
6521
|
}
|
|
6492
6522
|
}
|
|
6493
6523
|
return filteredObject;
|
|
6494
6524
|
};
|
|
6525
|
+
var resolvePropValue = (el, value) => {
|
|
6526
|
+
let resolved = el.call("exec", value, el);
|
|
6527
|
+
if (!resolved) return;
|
|
6528
|
+
if (isString(resolved) && resolved.includes("{{")) {
|
|
6529
|
+
resolved = el.call("replaceLiteralsWithObjectFields", resolved);
|
|
6530
|
+
}
|
|
6531
|
+
return resolved;
|
|
6532
|
+
};
|
|
6533
|
+
var resolveFileSource = (el, value) => {
|
|
6534
|
+
let src = (el.props.preSrc || "") + (resolvePropValue(el, value) || "");
|
|
6535
|
+
if (!src) return;
|
|
6536
|
+
try {
|
|
6537
|
+
new URL(src);
|
|
6538
|
+
return src;
|
|
6539
|
+
} catch (e) {
|
|
6540
|
+
}
|
|
6541
|
+
const { context } = el;
|
|
6542
|
+
if (!context.files) return src;
|
|
6543
|
+
const fileSrc = src.startsWith("/files/") ? src.slice(7) : src;
|
|
6544
|
+
const file = context.files[src] || context.files[fileSrc];
|
|
6545
|
+
if (file && file.content) return file.content.src;
|
|
6546
|
+
return src;
|
|
6547
|
+
};
|
|
6548
|
+
var ATTR_TRANSFORMS = {
|
|
6549
|
+
src: (el) => resolveFileSource(el, el.props.src),
|
|
6550
|
+
href: (el) => resolvePropValue(el, el.props.href),
|
|
6551
|
+
action: (el) => resolvePropValue(el, el.props.action),
|
|
6552
|
+
poster: (el) => resolveFileSource(el, el.props.poster),
|
|
6553
|
+
data: (el) => resolvePropValue(el, el.props.data)
|
|
6554
|
+
};
|
|
6555
|
+
var resolveCase = (caseKey, element) => {
|
|
6556
|
+
const caseFn = element.context?.cases?.[caseKey];
|
|
6557
|
+
if (caseFn === void 0) return void 0;
|
|
6558
|
+
if (isFunction(caseFn)) return caseFn.call(element, element);
|
|
6559
|
+
return !!caseFn;
|
|
6560
|
+
};
|
|
6561
|
+
var evaluateCondition = (prefix, caseKey, element) => {
|
|
6562
|
+
if (prefix === "$") {
|
|
6563
|
+
let result = resolveCase(caseKey, element);
|
|
6564
|
+
if (result === void 0) result = !!element.props?.[caseKey];
|
|
6565
|
+
return result;
|
|
6566
|
+
}
|
|
6567
|
+
let isTruthy = element.props[caseKey] === true || element.state[caseKey] || element[caseKey];
|
|
6568
|
+
if (!isTruthy) {
|
|
6569
|
+
const caseResult = resolveCase(caseKey, element);
|
|
6570
|
+
if (caseResult !== void 0) isTruthy = caseResult;
|
|
6571
|
+
}
|
|
6572
|
+
return prefix === "." ? !!isTruthy : !isTruthy;
|
|
6573
|
+
};
|
|
6574
|
+
var CONDITIONAL_PREFIXES = /* @__PURE__ */ new Set(["$", ".", "!"]);
|
|
6575
|
+
var extractConditionalAttrs = (props, tag, cssProps) => {
|
|
6576
|
+
const result = {};
|
|
6577
|
+
const addConditionalAttr = (attrName, attrVal, prefix, caseKey) => {
|
|
6578
|
+
const capturedVal = attrVal;
|
|
6579
|
+
result[attrName] = (el) => {
|
|
6580
|
+
if (!evaluateCondition(prefix, caseKey, el)) return void 0;
|
|
6581
|
+
return isFunction(capturedVal) ? capturedVal(el) : capturedVal;
|
|
6582
|
+
};
|
|
6583
|
+
};
|
|
6584
|
+
for (const key in props) {
|
|
6585
|
+
const prefix = key.charAt(0);
|
|
6586
|
+
if (!CONDITIONAL_PREFIXES.has(prefix)) continue;
|
|
6587
|
+
const block = props[key];
|
|
6588
|
+
if (!block || typeof block !== "object") continue;
|
|
6589
|
+
const caseKey = key.slice(1);
|
|
6590
|
+
for (const attrKey in block) {
|
|
6591
|
+
if (cssProps && attrKey in cssProps) continue;
|
|
6592
|
+
if (attrKey === "aria" && block[attrKey] && typeof block[attrKey] === "object") {
|
|
6593
|
+
for (const ariaKey in block[attrKey]) {
|
|
6594
|
+
addConditionalAttr("aria-" + ariaKey, block[attrKey][ariaKey], prefix, caseKey);
|
|
6595
|
+
}
|
|
6596
|
+
continue;
|
|
6597
|
+
}
|
|
6598
|
+
if (attrKey === "data" && block[attrKey] && typeof block[attrKey] === "object") {
|
|
6599
|
+
for (const dataKey in block[attrKey]) {
|
|
6600
|
+
const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
|
|
6601
|
+
addConditionalAttr("data-" + kebab, block[attrKey][dataKey], prefix, caseKey);
|
|
6602
|
+
}
|
|
6603
|
+
continue;
|
|
6604
|
+
}
|
|
6605
|
+
const isAttribute = checkAttributeByTagName(tag, attrKey);
|
|
6606
|
+
const isEvent = checkEventFunctions(attrKey);
|
|
6607
|
+
if (!isAttribute && !isEvent) continue;
|
|
6608
|
+
const attrName = camelToAttr(attrKey) || attrKey;
|
|
6609
|
+
addConditionalAttr(attrName, block[attrKey], prefix, caseKey);
|
|
6610
|
+
}
|
|
6611
|
+
}
|
|
6612
|
+
return result;
|
|
6613
|
+
};
|
|
6495
6614
|
|
|
6496
6615
|
// create.js
|
|
6497
6616
|
var EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
|
|
6498
6617
|
var applyPropsAsAttrs = (element) => {
|
|
6499
6618
|
const { tag, props, context } = element;
|
|
6500
6619
|
if (!tag || !props) return;
|
|
6501
|
-
const
|
|
6620
|
+
const cssProps = context?.cssPropsRegistry;
|
|
6621
|
+
const autoAttrs = filterAttributesByTagName(tag, props, cssProps);
|
|
6622
|
+
const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps);
|
|
6502
6623
|
const filtered = {};
|
|
6503
6624
|
for (const key in autoAttrs) {
|
|
6504
|
-
if (!EXCLUDED_ATTRS.has(key))
|
|
6625
|
+
if (!EXCLUDED_ATTRS.has(key)) {
|
|
6626
|
+
filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key];
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
for (const key in conditionalAttrs) {
|
|
6630
|
+
if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
|
|
6505
6631
|
}
|
|
6506
6632
|
let hasFiltered = false;
|
|
6507
6633
|
for (const _k in filtered) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
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.
|
|
50
|
-
"@domql/state": "^3.8.
|
|
51
|
-
"@domql/utils": "^3.8.
|
|
52
|
-
"attrs-in-props": "^3.8.
|
|
49
|
+
"@domql/report": "^3.8.1",
|
|
50
|
+
"@domql/state": "^3.8.1",
|
|
51
|
+
"@domql/utils": "^3.8.1",
|
|
52
|
+
"attrs-in-props": "^3.8.1"
|
|
53
53
|
},
|
|
54
54
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
55
55
|
"devDependencies": {
|