Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: properly support details and summary elements (#5285)

Bogdan Chadkin7c05003cc545
diff --git a/apps/builder/app/shared/content-model.test.tsx b/apps/builder/app/shared/content-model.test.tsx
index 8f6ec62bce..a0d4d09453 100644
--- a/apps/builder/app/shared/content-model.test.tsx
+++ b/apps/builder/app/shared/content-model.test.tsx
@@ -521,6 +521,40 @@ test("support xml node with tags", () => {
).toBeTruthy();
});
+test("support headings inside of summary", () => {
+ expect(
+ isTreeSatisfyingContentModel({
+ ...renderData(
+ <ws.element ws:tag="body" ws:id="bodyId">
+ <ws.element ws:tag="details">
+ <ws.element ws:tag="summary">
+ <ws.element ws:tag="h3"></ws.element>
+ </ws.element>
+ </ws.element>
+ </ws.element>
+ ),
+ metas: defaultMetas,
+ instanceSelector: ["bodyId"],
+ })
+ ).toBeTruthy();
+});
+
+test("support links inside of details", () => {
+ expect(
+ isTreeSatisfyingContentModel({
+ ...renderData(
+ <ws.element ws:tag="body" ws:id="bodyId">
+ <ws.element ws:tag="details">
+ <ws.element ws:tag="a"></ws.element>
+ </ws.element>
+ </ws.element>
+ ),
+ metas: defaultMetas,
+ instanceSelector: ["bodyId"],
+ })
+ ).toBeTruthy();
+});
+
describe("component content model", () => {
test("restrict children with specific component", () => {
expect(
diff --git a/packages/html-data/bin/elements.ts b/packages/html-data/bin/elements.ts
index f04ac57fc1..972ff0acc4 100644
--- a/packages/html-data/bin/elements.ts
+++ b/packages/html-data/bin/elements.ts
@@ -45,7 +45,15 @@ const elementsByTag: Record<string, Element> = {};
return !tag.includes(" ");
});
const description = getTextContent(row.childNodes[1]);
- const categories = parseList(getTextContent(row.childNodes[2]));
+ let categories = parseList(getTextContent(row.childNodes[2])).map(
+ (item) => {
+ if (item === "heading") {
+ // legend and summary refer to it as heading content
+ return "heading content";
+ }
+ return item;
+ }
+ );
let children = parseList(getTextContent(row.childNodes[4]));
for (const tag of elements) {
// textarea does not have value attribute and text content is used as initial value
@@ -53,6 +61,14 @@ const elementsByTag: Record<string, Element> = {};
if (tag === "textarea") {
children = [];
}
+ // move interactive category from details to summary
+ // so details content could accept other interactive elements
+ if (tag === "details") {
+ categories = categories.filter((item) => item !== "interactive");
+ }
+ if (tag === "summary") {
+ categories.push("interactive");
+ }
elementsByTag[tag] = {
description,
categories,
diff --git a/packages/html-data/src/__generated__/elements.ts b/packages/html-data/src/__generated__/elements.ts
index be27fde097..14daffa58d 100644
--- a/packages/html-data/src/__generated__/elements.ts
+++ b/packages/html-data/src/__generated__/elements.ts
@@ -142,7 +142,7 @@ export const elementsByTag: Record<string, Element> = {
},
details: {
description: "Disclosure control for hiding details",
- categories: ["flow", "interactive", "palpable"],
+ categories: ["flow", "palpable"],
children: ["summary", "flow"],
},
dfn: {
@@ -209,32 +209,32 @@ export const elementsByTag: Record<string, Element> = {
},
h1: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
h2: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
h3: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
h4: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
h5: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
h6: {
description: "Heading",
- categories: ["flow", "heading", "palpable"],
+ categories: ["flow", "heading content", "palpable"],
children: ["phrasing"],
},
head: {
@@ -535,7 +535,7 @@ export const elementsByTag: Record<string, Element> = {
},
summary: {
description: "Caption for details",
- categories: ["none"],
+ categories: ["none", "interactive"],
children: ["phrasing", "heading content"],
},
sup: {