@jay-framework/compiler-jay-html 0.24.7 → 0.25.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/dist/index.js +31 -4
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -5777,6 +5777,7 @@ parse$1.TextNode = text_1.default;
|
|
|
5777
5777
|
parse$1.NodeType = type_1.default;
|
|
5778
5778
|
const COORD_ATTR$1 = "jay-coordinate-base";
|
|
5779
5779
|
const SCOPE_ATTR = "jay-scope";
|
|
5780
|
+
const AUTO_REF_PATTERN = /^AR\d+$/;
|
|
5780
5781
|
function assignCoordinatesToJayHtml(jayHtml, headlessContractNames) {
|
|
5781
5782
|
const root = parse_2(jayHtml, {
|
|
5782
5783
|
comment: true,
|
|
@@ -5790,6 +5791,12 @@ function assignCoordinatesToJayHtml(jayHtml, headlessContractNames) {
|
|
|
5790
5791
|
function nextScopeId(counter) {
|
|
5791
5792
|
return `S${counter.next++}`;
|
|
5792
5793
|
}
|
|
5794
|
+
function isScopeAnchorDiv(node2) {
|
|
5795
|
+
if (node2.nodeType !== NodeType.ELEMENT_NODE) return false;
|
|
5796
|
+
const el = node2;
|
|
5797
|
+
if (el.tagName?.toLowerCase() !== "div") return false;
|
|
5798
|
+
return (el.getAttribute("style") ?? "").replace(/\s+/g, "").includes("display:contents");
|
|
5799
|
+
}
|
|
5793
5800
|
function assignCoordinates(body, options) {
|
|
5794
5801
|
if (!options._refCounters) options._refCounters = /* @__PURE__ */ new Map();
|
|
5795
5802
|
const rootChildren = body.childNodes.filter(
|
|
@@ -5814,13 +5821,22 @@ function walkChildren(parent, parentCoord, scopeId, options, counter) {
|
|
|
5814
5821
|
const contractName = tagName.substring(4);
|
|
5815
5822
|
if (options.headlessContractNames.has(contractName)) {
|
|
5816
5823
|
let ref = element.getAttribute("ref");
|
|
5824
|
+
const explicitRef = !!ref && !AUTO_REF_PATTERN.test(ref);
|
|
5817
5825
|
if (!ref) {
|
|
5818
5826
|
const idx = options._refCounters.get(contractName) ?? 0;
|
|
5819
5827
|
options._refCounters.set(contractName, idx + 1);
|
|
5820
5828
|
ref = `AR${idx}`;
|
|
5821
5829
|
element.setAttribute("ref", ref);
|
|
5822
5830
|
}
|
|
5823
|
-
assignHeadlessInstance(
|
|
5831
|
+
assignHeadlessInstance(
|
|
5832
|
+
element,
|
|
5833
|
+
contractName,
|
|
5834
|
+
ref,
|
|
5835
|
+
parentCoord,
|
|
5836
|
+
options,
|
|
5837
|
+
counter,
|
|
5838
|
+
explicitRef
|
|
5839
|
+
);
|
|
5824
5840
|
continue;
|
|
5825
5841
|
}
|
|
5826
5842
|
}
|
|
@@ -5843,7 +5859,7 @@ function walkChildren(parent, parentCoord, scopeId, options, counter) {
|
|
|
5843
5859
|
walkChildren(element, coord, scopeId, options, counter);
|
|
5844
5860
|
}
|
|
5845
5861
|
}
|
|
5846
|
-
function assignHeadlessInstance(element, contractName, ref, parentCoord, options, counter) {
|
|
5862
|
+
function assignHeadlessInstance(element, contractName, ref, parentCoord, options, counter, explicitRef) {
|
|
5847
5863
|
const instanceCoord = `${parentCoord}/${contractName}:${ref}`;
|
|
5848
5864
|
element.setAttribute(COORD_ATTR$1, instanceCoord);
|
|
5849
5865
|
const childScopeId = nextScopeId(counter);
|
|
@@ -5851,8 +5867,10 @@ function assignHeadlessInstance(element, contractName, ref, parentCoord, options
|
|
|
5851
5867
|
const significantTemplateChildren = element.childNodes.filter(
|
|
5852
5868
|
(n) => n.nodeType === NodeType.ELEMENT_NODE || n.nodeType === NodeType.TEXT_NODE && (n.innerText || "").trim() !== ""
|
|
5853
5869
|
);
|
|
5854
|
-
|
|
5870
|
+
const alreadyWrapped = significantTemplateChildren.length === 1 && isScopeAnchorDiv(significantTemplateChildren[0]);
|
|
5871
|
+
if (!alreadyWrapped && (explicitRef || significantTemplateChildren.length > 1)) {
|
|
5855
5872
|
const wrapper = parse_2("<div></div>").querySelector("div");
|
|
5873
|
+
if (explicitRef) wrapper.setAttribute("class", ref);
|
|
5856
5874
|
wrapper.setAttribute("style", "display: contents");
|
|
5857
5875
|
const children = element.childNodes;
|
|
5858
5876
|
element.innerHTML = "";
|
|
@@ -5871,6 +5889,7 @@ function walkForEachChildren(parent, itemScopeId, options, counter) {
|
|
|
5871
5889
|
const contractName = tagName.substring(4);
|
|
5872
5890
|
if (options.headlessContractNames.has(contractName)) {
|
|
5873
5891
|
let ref = element.getAttribute("ref");
|
|
5892
|
+
const explicitRef = !!ref && !AUTO_REF_PATTERN.test(ref);
|
|
5874
5893
|
if (!ref) {
|
|
5875
5894
|
const counterKey = `forEach/${contractName}`;
|
|
5876
5895
|
const idx = options._refCounters.get(counterKey) ?? 0;
|
|
@@ -5878,7 +5897,15 @@ function walkForEachChildren(parent, itemScopeId, options, counter) {
|
|
|
5878
5897
|
ref = `AR${idx}`;
|
|
5879
5898
|
element.setAttribute("ref", ref);
|
|
5880
5899
|
}
|
|
5881
|
-
assignHeadlessInstance(
|
|
5900
|
+
assignHeadlessInstance(
|
|
5901
|
+
element,
|
|
5902
|
+
contractName,
|
|
5903
|
+
ref,
|
|
5904
|
+
itemScopeId,
|
|
5905
|
+
options,
|
|
5906
|
+
counter,
|
|
5907
|
+
explicitRef
|
|
5908
|
+
);
|
|
5882
5909
|
continue;
|
|
5883
5910
|
}
|
|
5884
5911
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/compiler-jay-html",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
},
|
|
35
35
|
"author": "",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@jay-framework/compiler-analyze-exported-types": "^0.
|
|
38
|
-
"@jay-framework/compiler-shared": "^0.
|
|
39
|
-
"@jay-framework/component": "^0.
|
|
40
|
-
"@jay-framework/logger": "^0.
|
|
41
|
-
"@jay-framework/runtime": "^0.
|
|
42
|
-
"@jay-framework/secure": "^0.
|
|
37
|
+
"@jay-framework/compiler-analyze-exported-types": "^0.25.1",
|
|
38
|
+
"@jay-framework/compiler-shared": "^0.25.1",
|
|
39
|
+
"@jay-framework/component": "^0.25.1",
|
|
40
|
+
"@jay-framework/logger": "^0.25.1",
|
|
41
|
+
"@jay-framework/runtime": "^0.25.1",
|
|
42
|
+
"@jay-framework/secure": "^0.25.1",
|
|
43
43
|
"@types/js-yaml": "^4.0.9",
|
|
44
44
|
"change-case": "^4.1.2",
|
|
45
45
|
"he": "^1.2.0",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@caiogondim/strip-margin": "^1.0.0",
|
|
55
|
-
"@jay-framework/4-react": "^0.
|
|
56
|
-
"@jay-framework/dev-environment": "^0.
|
|
55
|
+
"@jay-framework/4-react": "^0.25.1",
|
|
56
|
+
"@jay-framework/dev-environment": "^0.25.1",
|
|
57
57
|
"@testing-library/jest-dom": "^6.2.0",
|
|
58
58
|
"@types/js-beautify": "^1",
|
|
59
59
|
"@types/node": "^20.11.5",
|