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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: enforce html content model (#5074)
Bogdan Chadkind5bc0f976010
diff --git a/apps/builder/app/builder/features/navigator/navigator-tree.tsx b/apps/builder/app/builder/features/navigator/navigator-tree.tsxindex 9f32bf7861..23918326f0 100644--- a/apps/builder/app/builder/features/navigator/navigator-tree.tsx+++ b/apps/builder/app/builder/features/navigator/navigator-tree.tsx@@ -67,6 +67,7 @@ import {selectInstance,} from "~/shared/awareness";import { findClosestContainer, isTreeMatching } from "~/shared/matcher";+import { isTreeSatisfyingContentModel } from "~/shared/content-model";type TreeItemAncestor =| undefined@@ -529,6 +530,7 @@ const canDrop = () => {const dropSelector = dropTarget.itemSelector;const instances = $instances.get();+ const props = $props.get();const metas = $registeredComponentMetas.get();// in content mode allow drop only within same blockif ($isContentMode.get()) {@@ -550,15 +552,23 @@ const canDrop = (if (closestContainerIndex !== 0) {return false;}- return isTreeMatching({+ // make sure dragging tree can be put inside of drop instance+ const containerInstanceSelector = [+ dragSelector[0],+ ...dropSelector.slice(closestContainerIndex),+ ];+ let matches = isTreeMatching({instances,metas,- // make sure dragging tree can be put inside of drop instance- instanceSelector: [- dragSelector[0],- ...dropSelector.slice(closestContainerIndex),- ],+ instanceSelector: containerInstanceSelector,});+ matches &&= isTreeSatisfyingContentModel({+ instances,+ metas,+ props,+ instanceSelector: containerInstanceSelector,+ });+ return matches;};export const NavigatorTree = () => {diff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.tsindex b6dae30e00..a058765508 100644--- a/apps/builder/app/builder/shared/commands.ts+++ b/apps/builder/app/builder/shared/commands.ts@@ -44,6 +44,7 @@ import {import { getSetting, setSetting } from "./client-settings";import { findAvailableVariables } from "~/shared/data-variables";import { atom } from "nanostores";+import { isTreeSatisfyingContentModel } from "~/shared/content-model";export const $styleSourceInputElement = atom<HTMLInputElement | undefined>();@@ -174,11 +175,17 @@ export const wrapIn = (component: string) => {}}}- const matches = isTreeMatching({+ let matches = isTreeMatching({metas,instances: data.instances,instanceSelector: newInstanceSelector,});+ matches &&= isTreeSatisfyingContentModel({+ instances: data.instances,+ props: data.props,+ metas,+ instanceSelector: newInstanceSelector,+ });if (matches === false) {toast.error(`Cannot wrap in "${component}"`);throw Error("Abort transaction");@@ -218,11 +225,17 @@ export const unwrap = () => {);parentInstance.children.splice(index, 1, ...selectedInstance.children);}- const matches = isTreeMatching({+ let matches = isTreeMatching({metas: $registeredComponentMetas.get(),instances: data.instances,instanceSelector: parentItem.instanceSelector,});+ matches &&= isTreeSatisfyingContentModel({+ instances: data.instances,+ props: data.props,+ metas: $registeredComponentMetas.get(),+ instanceSelector: parentItem.instanceSelector,+ });if (matches === false) {toast.error(`Cannot unwrap instance`);throw Error("Abort transaction");diff --git a/apps/builder/app/canvas/shared/use-drag-drop.ts b/apps/builder/app/canvas/shared/use-drag-drop.tsindex 17617a50b1..61d21adf5a 100644--- a/apps/builder/app/canvas/shared/use-drag-drop.ts+++ b/apps/builder/app/canvas/shared/use-drag-drop.ts@@ -10,6 +10,7 @@ import {import {$dragAndDropState,$instances,+ $props,$registeredComponentMetas,type ItemDropTarget,} from "~/shared/nano-states";@@ -34,6 +35,7 @@ import {findClosestInstanceMatchingFragment,isTreeMatching,} from "~/shared/matcher";+import { isTreeSatisfyingContentModel } from "~/shared/content-model";declare module "~/shared/pubsub" {export interface PubsubMap {@@ -66,6 +68,7 @@ const findClosestDroppableInstanceSelector = (dragPayload: DragStartPayload) => {const instances = $instances.get();+ const props = $props.get();const metas = $registeredComponentMetas.get();// prevent dropping anything into non containers like image@@ -83,6 +86,7 @@ const findClosestDroppableInstanceSelector = (if (fragment) {droppableIndex = findClosestInstanceMatchingFragment({instances,+ props,metas,instanceSelector,fragment,@@ -90,13 +94,20 @@ const findClosestDroppableInstanceSelector = (}}if (dragPayload?.type === "reparent") {- const matches = isTreeMatching({+ const dropInstanceSelector = [+ dragPayload.dragInstanceSelector[0],+ ...instanceSelector,+ ];+ let matches = isTreeMatching({instances,metas,- instanceSelector: [- dragPayload.dragInstanceSelector[0],- ...instanceSelector,- ],+ instanceSelector: dropInstanceSelector,+ });+ matches &&= isTreeSatisfyingContentModel({+ instances,+ props,+ metas,+ instanceSelector: dropInstanceSelector,});droppableIndex = matches ? 0 : -1;}diff --git a/apps/builder/app/shared/content-model.test.tsx b/apps/builder/app/shared/content-model.test.tsxnew file mode 100644index 0000000000..d594171c29--- /dev/null+++ b/apps/builder/app/shared/content-model.test.tsx@@ -0,0 +1,387 @@+import { expect, test } from "vitest";+import { coreMetas } from "@webstudio-is/sdk";+import * as baseComponentMetas from "@webstudio-is/sdk-components-react/metas";+import { $, renderData, ws } from "@webstudio-is/template";+import { isTreeSatisfyingContentModel } from "./content-model";++const defaultMetas = new Map(+ Object.entries({ ...coreMetas, ...baseComponentMetas })+);++test("flow accepts flow", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="divId"></$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+});++test("none category accepted by parent by tag", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.List ws:id="listId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </$.List>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["listId"],+ })+ ).toBeTruthy();+});++test("none category prevents unacceptable parent 1", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("none category prevents unacceptable parent 2", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.List ws:id="listId">+ <$.Box ws:id="divId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </$.Box>+ </$.List>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("slot without tag accepts transparent category", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.List ws:id="listId">+ <$.Slot ws:id="slotId">+ <$.Fragment ws:id="fragmentId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </$.Fragment>+ </$.Slot>+ </$.List>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+});++test("collection without tag accepts transparent category", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.List ws:id="listId">+ <ws.collection ws:id="collectionId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </ws.collection>+ </$.List>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+});++test("transparent category accepts flow", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Link ws:id="linkId">+ <$.Box ws:id="divId"></$.Box>+ </$.Link>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+});++test("phrasing category accepts element with transparent children", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="spanId" tag="span">+ <$.Link ws:id="linkId"></$.Link>+ </$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+});++test("transparent category should pass through phrasing category and forbid flow inside", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="spanId" tag="span">+ <$.Link ws:id="linkId">+ <$.Box ws:id="anotherSpanId" tag="span"></$.Box>+ </$.Link>+ </$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="spanId" tag="span">+ <$.Link ws:id="linkId">+ <$.Box ws:id="divId"></$.Box>+ </$.Link>+ </$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("transparent category should not pass through invalid parent", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.List ws:id="listId">+ <$.Link ws:id="linkId">+ <$.ListItem ws:id="itemId"></$.ListItem>+ </$.Link>+ </$.List>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("transparent category should pass through category when check deep in the tree", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="spanId" tag="span">+ <$.Link ws:id="linkId">+ <$.Bold ws:id="boldId"></$.Bold>+ </$.Link>+ </$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["linkId", "spanId", "bodyId"],+ })+ ).toBeTruthy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Box ws:id="spanId" tag="span">+ <$.Link ws:id="linkId">+ <$.Box ws:id="divId"></$.Box>+ </$.Link>+ </$.Box>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["linkId", "spanId", "bodyId"],+ })+ ).toBeFalsy();+});++test("restrict empty category", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Separator ws:id="separatorId" />+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Separator ws:id="separatorId">+ <$.Box ws:id="spanId" tag="span"></$.Box>+ </$.Separator>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("prevent nesting interactive instances", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Button>+ <$.Button></$.Button>+ </$.Button>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Button>+ <$.Box tag="span">+ <$.Link></$.Link>+ </$.Box>+ </$.Button>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("prevent nesting interactive instances with slots in between", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Button>+ <$.Slot>+ <$.Fragment>+ <$.Textarea></$.Textarea>+ </$.Fragment>+ </$.Slot>+ </$.Button>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});++test("prevent nesting interactive instances when check deep in the tree", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Button ws:id="buttonId">+ <$.Box ws:id="divId">+ <$.Link ws:id="linkId"></$.Link>+ </$.Box>+ </$.Button>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["linkId", "divId", "buttonId", "bodyId"],+ })+ ).toBeFalsy();+});++test("prevent nesting forms", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Form>+ <$.Button></$.Button>+ </$.Form>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Form ws:id="formId">+ <$.Box ws:id="divId">+ <$.Form ws:id="anotherFormId">+ <$.Button ws:id="buttonId"></$.Button>+ </$.Form>+ </$.Box>+ </$.Form>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["anotherFormId", "divId", "formId", "bodyId"],+ })+ ).toBeFalsy();+});++test("edge case: allow wrapping input with label", () => {+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Label>+ <$.Box tag="span">+ <$.Input />+ </$.Box>+ </$.Label>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeTruthy();+ expect(+ isTreeSatisfyingContentModel({+ ...renderData(+ <$.Body ws:id="bodyId">+ <$.Label>+ <$.Box tag="span">+ <$.Button />+ </$.Box>+ </$.Label>+ </$.Body>+ ),+ metas: defaultMetas,+ instanceSelector: ["bodyId"],+ })+ ).toBeFalsy();+});diff --git a/apps/builder/app/shared/content-model.ts b/apps/builder/app/shared/content-model.tsnew file mode 100644index 0000000000..dfebad05fc--- /dev/null+++ b/apps/builder/app/shared/content-model.ts@@ -0,0 +1,234 @@+import {+ categoriesByTag,+ childrenCategoriesByTag,+} from "@webstudio-is/html-data";+import type {+ Instance,+ Instances,+ Props,+ WsComponentMeta,+} from "@webstudio-is/sdk";+import type { InstanceSelector } from "./tree-utils";++const tagByInstanceIdCache = new WeakMap<Props, Map<Instance["id"], string>>();++const getTagByInstanceId = (props: Props) => {+ let tagByInstanceId = tagByInstanceIdCache.get(props);+ if (tagByInstanceId === undefined) {+ tagByInstanceId = new Map<Instance["id"], string>();+ for (const prop of props.values()) {+ if (prop.type === "string" && prop.name === "tag") {+ tagByInstanceId.set(prop.instanceId, prop.value);+ }+ }+ tagByInstanceIdCache.set(props, tagByInstanceId);+ }+ return tagByInstanceId;+};++const getMetaTag = (meta: undefined | WsComponentMeta) => {+ return Object.keys(meta?.presetStyle ?? {}).at(0);+};++const isIntersected = (arrayA: string[], arrayB: string[]) => {+ return arrayA.some((item) => arrayB.includes(item));+};++const isTagSatisfyingContentModel = ({+ tag,+ allowedCategories,+}: {+ tag: undefined | string;+ allowedCategories: undefined | string[];+}) => {+ // slot or collection does not have tag and should pass through allowed categories+ if (tag === undefined) {+ return true;+ }+ // body does not have parent+ if (allowedCategories === undefined) {+ return true;+ }+ // for example ul has "li" as children category+ if (allowedCategories.includes(tag)) {+ return true;+ }+ // instance does not match parent constraints+ if (isIntersected(allowedCategories, categoriesByTag[tag]) === false) {+ return false;+ }+ // prevent nesting interactive elements+ // like button > button or a > input+ if (+ allowedCategories.includes("non-interactive") &&+ categoriesByTag[tag].includes("interactive")+ ) {+ // interactive exception, label > input is not recommended but a popular case+ // to automatically focus input when click on label text without using id+ if (allowedCategories.includes("label-content") && tag === "input") {+ return true;+ }+ return false;+ }+ // prevent nesting form elements+ // like form > div > form+ if (allowedCategories.includes("non-form") && tag === "form") {+ return false;+ }+ return true;+};++/**+ * compute possible categories for tag children+ */+const getTagChildrenCategories = (+ tag: undefined | string,+ allowedCategories: undefined | string[]+) => {+ // components without tag behave like transparent category+ // and pass through parent constraints+ let childrenCategories: string[] =+ tag === undefined ? ["transparent"] : childrenCategoriesByTag[tag];+ if (childrenCategories.includes("transparent") && allowedCategories) {+ childrenCategories = allowedCategories;+ }+ // introduce custom non-interactive category to restrict nesting interactive elements+ // like button > button or a > input+ if (+ tag &&+ (categoriesByTag[tag].includes("interactive") ||+ allowedCategories?.includes("non-interactive"))+ ) {+ childrenCategories = [...childrenCategories, "non-interactive"];+ }+ // interactive exception, label > input is not recommended but a popular case+ // to automatically focus input when click on label text without using id+ if (tag === "label" || allowedCategories?.includes("label-content")) {+ childrenCategories = [...childrenCategories, "label-content"];+ }+ // introduce custom non-form category to restrict nesting form elements+ // like form > div > form+ if (tag === "form" || allowedCategories?.includes("non-form")) {+ childrenCategories = [...childrenCategories, "non-form"];+ }+ return childrenCategories;+};++/**+ * compute allowed categories from all ancestors+ * considering inherited (transparent) categories+ * and other ancestor specific behaviors+ */+const computeAllowedCategories = ({+ instances,+ props,+ metas,+ instanceSelector,+}: {+ instances: Instances;+ props: Props;+ metas: Map<Instance["component"], WsComponentMeta>;+ instanceSelector: InstanceSelector;+}) => {+ let instance: undefined | Instance;+ let allowedCategories: undefined | string[];+ // skip selected instance for which these constraints are computed+ for (const instanceId of instanceSelector.slice(1).reverse()) {+ instance = instances.get(instanceId);+ // collection item can be undefined+ if (instance === undefined) {+ continue;+ }+ const tagByInstanceId = getTagByInstanceId(props);+ const meta = metas.get(instance.component);+ const tag = tagByInstanceId.get(instance.id) ?? getMetaTag(meta);+ allowedCategories = getTagChildrenCategories(tag, allowedCategories);+ }+ return allowedCategories;+};++/**+ * Check all tags starting with specified instance select+ * for example+ *+ * Most rules are described by categoriesByTag and childrenCategoriesByTag+ * from html-data package. Basically all elements enforce children categories+ * and all elements has own categories. We check intersections to match them.+ *+ * See https://html.spec.whatwg.org/multipage/indices.html#elements-3+ *+ * div > span = true+ * where div is flow category+ * and requires flow or phrasing category in children+ * span is flow and phrasing category+ * and requires phrasing in children+ *+ * span > div = false+ * because span requires phrasing category in children+ *+ * p > div = false+ * because paragraph also requires phrasing category in children+ *+ * Interactive categories and form elements are exception+ * because button requires phrasing children+ * and does not prevent nesting interactive elements by content model+ * They pass through negative categories+ *+ * [categories] [children]+ * interactive non-interactive+ *+ * exampeles+ * button > input = false+ * form > div > form = false+ *+ */+export const isTreeSatisfyingContentModel = ({+ instances,+ props,+ metas,+ instanceSelector,+ _allowedCategories: allowedCategories,+}: {+ instances: Instances;+ props: Props;+ metas: Map<Instance["component"], WsComponentMeta>;+ instanceSelector: InstanceSelector;+ _allowedCategories?: string[];+}): boolean => {+ // compute constraints only when not passed from parent+ allowedCategories ??= computeAllowedCategories({+ instanceSelector,+ instances,+ props,+ metas,+ });+ const [instanceId] = instanceSelector;+ const instance = instances.get(instanceId);+ // collection item can be undefined+ if (instance === undefined) {+ return true;+ }+ const tagByInstanceId = getTagByInstanceId(props);+ const meta = metas.get(instance.component);+ const tag = tagByInstanceId.get(instance.id) ?? getMetaTag(meta);+ let isSatisfying = isTagSatisfyingContentModel({+ tag,+ allowedCategories,+ });+ const childrenCategories: string[] = getTagChildrenCategories(+ tag,+ allowedCategories+ );+ for (const child of instance.children) {+ if (child.type === "id") {+ isSatisfying &&= isTreeSatisfyingContentModel({+ instances,+ props,+ metas,+ instanceSelector: [child.value, ...instanceSelector],+ _allowedCategories: childrenCategories,+ });+ }+ }+ return isSatisfying;+};diff --git a/apps/builder/app/shared/instance-utils.test.tsx b/apps/builder/app/shared/instance-utils.test.tsxindex c576598ce8..1fe0229ef1 100644--- a/apps/builder/app/shared/instance-utils.test.tsx+++ b/apps/builder/app/shared/instance-utils.test.tsx@@ -1472,7 +1472,9 @@ describe("find closest insertable", () => {);$instances.set(instances);selectInstance(["boxId", "paragraphId", "bodyId"]);- expect(findClosestInsertable(newBoxFragment)).toEqual({+ expect(+ findClosestInsertable(renderTemplate(<$.Box tag="span"></$.Box>))+ ).toEqual({parentSelector: ["paragraphId", "bodyId"],position: 0,});diff --git a/apps/builder/app/shared/instance-utils.ts b/apps/builder/app/shared/instance-utils.tsindex 859ab0fdee..aeb8080da9 100644--- a/apps/builder/app/shared/instance-utils.ts+++ b/apps/builder/app/shared/instance-utils.ts@@ -28,6 +28,7 @@ import {portalComponent,collectionComponent,Prop,+ parseComponentName,} from "@webstudio-is/sdk";import {$props,@@ -1298,6 +1299,7 @@ export const findClosestInsertable = (}const metas = $registeredComponentMetas.get();const instances = $instances.get();+ const props = $props.get();const closestContainerIndex = findClosestNonTextualContainer({metas,instances,@@ -1309,14 +1311,16 @@ export const findClosestInsertable = (let insertableIndex = findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: instanceSelector.slice(closestContainerIndex),fragment,- onError: (message) =>- toast.error(- message === ""- ? "findClosestInstanceMatchingFragment encountered an unknown error"- : message- ),+ onError: (message) => {+ const [_namespace, componentName] = parseComponentName(+ fragment.instances[0].component+ );+ const label = humanizeString(componentName);+ toast.error(message || `Cannot insert "${label}"`);+ },});if (insertableIndex === -1) {return;diff --git a/apps/builder/app/shared/matcher.test.tsx b/apps/builder/app/shared/matcher.test.tsxindex 7ab255c947..575fdd3657 100644--- a/apps/builder/app/shared/matcher.test.tsx+++ b/apps/builder/app/shared/matcher.test.tsx@@ -853,7 +853,7 @@ describe("is instance detachable", () => {describe("find closest instance matching fragment", () => {test("finds closest list with list item fragment", () => {- const { instances } = renderData(+ const { instances, props } = renderData(<$.Body ws:id="body"><$.List ws:id="list"><$.ListItem ws:id="listitem"></$.ListItem>@@ -865,6 +865,7 @@ describe("find closest instance matching fragment", () => {findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: ["list", "body"],fragment,})@@ -873,6 +874,7 @@ describe("find closest instance matching fragment", () => {findClosestInstanceMatchingFragment({metas,instances,+ props,// looks up until list parent is reachedinstanceSelector: ["listitem", "list", "body"],fragment,@@ -882,6 +884,7 @@ describe("find closest instance matching fragment", () => {findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: ["body"],fragment,})@@ -889,7 +892,7 @@ describe("find closest instance matching fragment", () => {});test("finds button parent with button fragment", () => {- const { instances } = renderData(+ const { instances, props } = renderData(<$.Body ws:id="body"><$.Button ws:id="button"></$.Button></$.Body>@@ -899,6 +902,7 @@ describe("find closest instance matching fragment", () => {findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: ["button", "body"],fragment,})@@ -906,7 +910,7 @@ describe("find closest instance matching fragment", () => {});test("finds button parent with button+span fragment", () => {- const { instances } = renderData(+ const { instances, props } = renderData(<$.Body ws:id="body"><$.Button ws:id="button"></$.Button></$.Body>@@ -921,6 +925,7 @@ describe("find closest instance matching fragment", () => {findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: ["button", "body"],fragment,})@@ -929,11 +934,12 @@ describe("find closest instance matching fragment", () => {test("report first error", () => {const onError = vi.fn();- const { instances } = renderData(<$.Body ws:id="body"></$.Body>);+ const { instances, props } = renderData(<$.Body ws:id="body"></$.Body>);const fragment = renderTemplate(<$.ListItem ws:id="listitem"></$.ListItem>);findClosestInstanceMatchingFragment({metas,instances,+ props,instanceSelector: ["body"],fragment,onError,diff --git a/apps/builder/app/shared/matcher.ts b/apps/builder/app/shared/matcher.tsindex aab271ae78..de96316c1d 100644--- a/apps/builder/app/shared/matcher.ts+++ b/apps/builder/app/shared/matcher.ts@@ -1,5 +1,6 @@import {parseComponentName,+ Props,type Instance,type Instances,type Matcher,@@ -9,6 +10,7 @@ import {type WsComponentMeta,} from "@webstudio-is/sdk";import type { InstanceSelector } from "./tree-utils";+import { isTreeSatisfyingContentModel } from "./content-model";const isNegated = (operation?: MatcherOperation) => {return operation?.$neq !== undefined || operation?.$nin !== undefined;@@ -304,22 +306,28 @@ export const isInstanceDetachable = ({export const findClosestInstanceMatchingFragment = ({instances,+ props,metas,instanceSelector,fragment,onError,}: {instances: Instances;+ props: Props;metas: Map<string, WsComponentMeta>;instanceSelector: InstanceSelector;// require only subset of fragment- fragment: Pick<WebstudioFragment, "children" | "instances">;+ fragment: Pick<WebstudioFragment, "children" | "instances" | "props">;onError?: (message: string) => void;}) => {const mergedInstances = new Map(instances);for (const instance of fragment.instances) {mergedInstances.set(instance.id, instance);}+ const mergedProps = new Map(props);+ for (const prop of fragment.props) {+ mergedProps.set(prop.id, prop);+ }let firstError = "";for (let index = 0; index < instanceSelector.length; index += 1) {const instanceId = instanceSelector[index];@@ -335,16 +343,26 @@ export const findClosestInstanceMatchingFragment = ({let matches = true;for (const child of fragment.children) {if (child.type === "id") {+ const childInstanceSelector = [+ child.value,+ ...instanceSelector.slice(index),+ ];matches &&= isTreeMatching({instances: mergedInstances,metas,- instanceSelector: [child.value, ...instanceSelector.slice(index)],+ instanceSelector: childInstanceSelector,onError: (message) => {if (firstError === "") {firstError = message;}},});+ matches &&= isTreeSatisfyingContentModel({+ instances: mergedInstances,+ props: mergedProps,+ metas,+ instanceSelector: childInstanceSelector,+ });}}if (matches) {diff --git a/apps/builder/package.json b/apps/builder/package.jsonindex 193e95f137..ca03c13d3a 100644--- a/apps/builder/package.json+++ b/apps/builder/package.json@@ -65,6 +65,7 @@"@webstudio-is/domain": "workspace:*","@webstudio-is/feature-flags": "workspace:*","@webstudio-is/fonts": "workspace:*",+ "@webstudio-is/html-data": "workspace:*","@webstudio-is/http-client": "workspace:*","@webstudio-is/icons": "workspace:*","@webstudio-is/image": "workspace:*",diff --git a/packages/html-data/bin/crawler.ts b/packages/html-data/bin/crawler.tsnew file mode 100644index 0000000000..d7dc33475b--- /dev/null+++ b/packages/html-data/bin/crawler.ts@@ -0,0 +1,53 @@+import { Parser, defaultTreeAdapter, type DefaultTreeAdapterMap } from "parse5";++type Document = DefaultTreeAdapterMap["document"];++type ChildNode = DefaultTreeAdapterMap["childNode"];++type Node = DefaultTreeAdapterMap["node"];++type NodeWithChildren = Extract<ChildNode, { childNodes: ChildNode[] }>;++type Element = DefaultTreeAdapterMap["element"];++type Attribute = Element["attrs"][number];++export const findTags = (+ node: undefined | Node,+ tagName: string,+ result: NodeWithChildren[] = []+): NodeWithChildren[] => {+ if (node && "childNodes" in node) {+ if ("tagName" in node && node.tagName === tagName) {+ result.push(node);+ }+ for (const child of node.childNodes) {+ findTags(child, tagName, result);+ }+ }+ return result;+};++export const getAttr = (+ node: NodeWithChildren,+ name: string+): undefined | Attribute => {+ return node.attrs.find((attr) => attr.name === name);+};++export const getTextContent = (node: ChildNode) => {+ if ("value" in node) {+ return node.value;+ }+ let result = "";+ if ("childNodes" in node) {+ for (const child of node.childNodes) {+ result += getTextContent(child);+ }+ }+ return result;+};++export const parseHtml = (html: string): Document => {+ return Parser.parse(html, { treeAdapter: defaultTreeAdapter });+};diff --git a/packages/html-data/bin/html-crawler.ts b/packages/html-data/bin/html-crawler.tsnew file mode 100644index 0000000000..339621b0ce--- /dev/null+++ b/packages/html-data/bin/html-crawler.ts@@ -0,0 +1,63 @@+import { dirname } from "node:path";+import { mkdir, readFile, writeFile } from "node:fs/promises";+import { findTags, getTextContent, parseHtml } from "./crawler";++// Crawl WHATWG HTML.++// prefer cached file to avoid too many requests on debug+const cachedFile = "./node_modules/.cache/html-spec-indices.html";+let text;+try {+ text = await readFile(cachedFile, "utf-8");+} catch {+ const response = await fetch(+ "https://html.spec.whatwg.org/multipage/indices.html"+ );+ text = await response.text();+ await writeFile(cachedFile, text);+}++const document = parseHtml(text);++const categoriesByTag: Record<string, string[]> = {};+const childrenCategoriesByTag: Record<string, string[]> = {};++/**+ * scrape elements table with content model+ */+{+ const table = findTags(document, "table").find((table) => {+ const [caption] = findTags(table, "caption");+ return getTextContent(caption).toLowerCase().includes("list of elements");+ });+ const [tbody] = findTags(table, "tbody");+ const rows = findTags(tbody, "tr");+ const parseList = (text: string) => {+ return text+ .trim()+ .split(/\s*;\s*/)+ .map((item) => (item.endsWith("*") ? item.slice(0, -1) : item));+ };+ for (const row of rows) {+ const elements = getTextContent(row.childNodes[0])+ .trim()+ .split(/\s*,\s*/)+ .filter((tag) => {+ // skip "SVG svg" amd "MathML math"+ return !tag.includes(" ");+ });+ const categories = parseList(getTextContent(row.childNodes[2]));+ const children = parseList(getTextContent(row.childNodes[4]));+ for (const tag of elements) {+ categoriesByTag[tag] = categories;+ childrenCategoriesByTag[tag] = children;+ }+ }+}++let contentModel = ``;+contentModel += `export const categoriesByTag: Record<string, string[]> = ${JSON.stringify(categoriesByTag, null, 2)};\n`;+contentModel += `export const childrenCategoriesByTag: Record<string, string[]> = ${JSON.stringify(childrenCategoriesByTag, null, 2)};\n`;+const contentModelFile = "./src/__generated__/content-model.ts";+await mkdir(dirname(contentModelFile), { recursive: true });+await writeFile(contentModelFile, contentModel);diff --git a/packages/html-data/package.json b/packages/html-data/package.jsonindex eef2f97176..a975a41ab1 100644--- a/packages/html-data/package.json+++ b/packages/html-data/package.json@@ -6,17 +6,17 @@"homepage": "https://webstudio.is","type": "module","scripts": {- "typecheck": "tsc"+ "typecheck": "tsc",+ "build:spec": "tsx --conditions=webstudio ./bin/html-crawler.ts"},"devDependencies": {- "@webstudio-is/tsconfig": "workspace:*"+ "@webstudio-is/tsconfig": "workspace:*",+ "parse5": "7.2.1"},- "peerDependencies": {},"exports": {"webstudio": "./src/index.ts"},"license": "AGPL-3.0-or-later","private": true,- "sideEffects": false,- "dependencies": {}+ "sideEffects": false}diff --git a/packages/html-data/src/__generated__/content-model.ts b/packages/html-data/src/__generated__/content-model.tsnew file mode 100644index 0000000000..43ec62ee5a--- /dev/null+++ b/packages/html-data/src/__generated__/content-model.ts@@ -0,0 +1,298 @@+export const categoriesByTag: Record<string, string[]> = {+ a: ["flow", "phrasing", "interactive", "palpable"],+ abbr: ["flow", "phrasing", "palpable"],+ address: ["flow", "palpable"],+ area: ["flow", "phrasing"],+ article: ["flow", "sectioning", "palpable"],+ aside: ["flow", "sectioning", "palpable"],+ audio: ["flow", "phrasing", "embedded", "interactive", "palpable"],+ b: ["flow", "phrasing", "palpable"],+ base: ["metadata"],+ bdi: ["flow", "phrasing", "palpable"],+ bdo: ["flow", "phrasing", "palpable"],+ blockquote: ["flow", "palpable"],+ body: ["none"],+ br: ["flow", "phrasing"],+ button: [+ "flow",+ "phrasing",+ "interactive",+ "listed",+ "labelable",+ "submittable",+ "form-associated",+ "palpable",+ ],+ canvas: ["flow", "phrasing", "embedded", "palpable"],+ caption: ["none"],+ cite: ["flow", "phrasing", "palpable"],+ code: ["flow", "phrasing", "palpable"],+ col: ["none"],+ colgroup: ["none"],+ data: ["flow", "phrasing", "palpable"],+ datalist: ["flow", "phrasing"],+ dd: ["none"],+ del: ["flow", "phrasing", "palpable"],+ details: ["flow", "interactive", "palpable"],+ dfn: ["flow", "phrasing", "palpable"],+ dialog: ["flow"],+ div: ["flow", "palpable"],+ dl: ["flow", "palpable"],+ dt: ["none"],+ em: ["flow", "phrasing", "palpable"],+ embed: ["flow", "phrasing", "embedded", "interactive", "palpable"],+ fieldset: ["flow", "listed", "form-associated", "palpable"],+ figcaption: ["none"],+ figure: ["flow", "palpable"],+ footer: ["flow", "palpable"],+ form: ["flow", "palpable"],+ h1: ["flow", "heading", "palpable"],+ h2: ["flow", "heading", "palpable"],+ h3: ["flow", "heading", "palpable"],+ h4: ["flow", "heading", "palpable"],+ h5: ["flow", "heading", "palpable"],+ h6: ["flow", "heading", "palpable"],+ head: ["none"],+ header: ["flow", "palpable"],+ hgroup: ["flow", "palpable"],+ hr: ["flow"],+ html: ["none"],+ i: ["flow", "phrasing", "palpable"],+ iframe: ["flow", "phrasing", "embedded", "interactive", "palpable"],+ img: [+ "flow",+ "phrasing",+ "embedded",+ "interactive",+ "form-associated",+ "palpable",+ ],+ input: [+ "flow",+ "phrasing",+ "interactive",+ "listed",+ "labelable",+ "submittable",+ "resettable",+ "form-associated",+ "palpable",+ ],+ ins: ["flow", "phrasing", "palpable"],+ kbd: ["flow", "phrasing", "palpable"],+ label: ["flow", "phrasing", "interactive", "palpable"],+ legend: ["none"],+ li: ["none"],+ link: ["metadata", "flow", "phrasing"],+ main: ["flow", "palpable"],+ map: ["flow", "phrasing", "palpable"],+ mark: ["flow", "phrasing", "palpable"],+ menu: ["flow", "palpable"],+ meta: ["metadata", "flow", "phrasing"],+ meter: ["flow", "phrasing", "labelable", "palpable"],+ nav: ["flow", "sectioning", "palpable"],+ noscript: ["metadata", "flow", "phrasing"],+ object: [+ "flow",+ "phrasing",+ "embedded",+ "interactive",+ "listed",+ "form-associated",+ "palpable",+ ],+ ol: ["flow", "palpable"],+ optgroup: ["none"],+ option: ["none"],+ output: [+ "flow",+ "phrasing",+ "listed",+ "labelable",+ "resettable",+ "form-associated",+ "palpable",+ ],+ p: ["flow", "palpable"],+ picture: ["flow", "phrasing", "embedded", "palpable"],+ pre: ["flow", "palpable"],+ progress: ["flow", "phrasing", "labelable", "palpable"],+ q: ["flow", "phrasing", "palpable"],+ rp: ["none"],+ rt: ["none"],+ ruby: ["flow", "phrasing", "palpable"],+ s: ["flow", "phrasing", "palpable"],+ samp: ["flow", "phrasing", "palpable"],+ script: ["metadata", "flow", "phrasing", "script-supporting"],+ search: ["flow", "palpable"],+ section: ["flow", "sectioning", "palpable"],+ select: [+ "flow",+ "phrasing",+ "interactive",+ "listed",+ "labelable",+ "submittable",+ "resettable",+ "form-associated",+ "palpable",+ ],+ slot: ["flow", "phrasing"],+ small: ["flow", "phrasing", "palpable"],+ source: ["none"],+ span: ["flow", "phrasing", "palpable"],+ strong: ["flow", "phrasing", "palpable"],+ style: ["metadata"],+ sub: ["flow", "phrasing", "palpable"],+ summary: ["none"],+ sup: ["flow", "phrasing", "palpable"],+ table: ["flow", "palpable"],+ tbody: ["none"],+ td: ["none"],+ template: ["metadata", "flow", "phrasing", "script-supporting"],+ textarea: [+ "flow",+ "phrasing",+ "interactive",+ "listed",+ "labelable",+ "submittable",+ "resettable",+ "form-associated",+ "palpable",+ ],+ tfoot: ["none"],+ th: ["interactive"],+ thead: ["none"],+ time: ["flow", "phrasing", "palpable"],+ title: ["metadata"],+ tr: ["none"],+ track: ["none"],+ u: ["flow", "phrasing", "palpable"],+ ul: ["flow", "palpable"],+ var: ["flow", "phrasing", "palpable"],+ video: ["flow", "phrasing", "embedded", "interactive", "palpable"],+ wbr: ["flow", "phrasing"],+};+export const childrenCategoriesByTag: Record<string, string[]> = {+ a: ["transparent"],+ abbr: ["phrasing"],+ address: ["flow"],+ area: ["empty"],+ article: ["flow"],+ aside: ["flow"],+ audio: ["source", "track", "transparent"],+ b: ["phrasing"],+ base: ["empty"],+ bdi: ["phrasing"],+ bdo: ["phrasing"],+ blockquote: ["flow"],+ body: ["flow"],+ br: ["empty"],+ button: ["phrasing"],+ canvas: ["transparent"],+ caption: ["flow"],+ cite: ["phrasing"],+ code: ["phrasing"],+ col: ["empty"],+ colgroup: ["col", "template"],+ data: ["phrasing"],+ datalist: ["phrasing", "option", "script-supporting elements"],+ dd: ["flow"],+ del: ["transparent"],+ details: ["summary", "flow"],+ dfn: ["phrasing"],+ dialog: ["flow"],+ div: ["flow"],+ dl: ["dt", "dd", "div", "script-supporting elements"],+ dt: ["flow"],+ em: ["phrasing"],+ embed: ["empty"],+ fieldset: ["legend", "flow"],+ figcaption: ["flow"],+ figure: ["figcaption", "flow"],+ footer: ["flow"],+ form: ["flow"],+ h1: ["phrasing"],+ h2: ["phrasing"],+ h3: ["phrasing"],+ h4: ["phrasing"],+ h5: ["phrasing"],+ h6: ["phrasing"],+ head: ["metadata content"],+ header: ["flow"],+ hgroup: ["h1", "h2", "h3", "h4", "h5", "h6", "script-supporting elements"],+ hr: ["empty"],+ html: ["head", "body"],+ i: ["phrasing"],+ iframe: ["empty"],+ img: ["empty"],+ input: ["empty"],+ ins: ["transparent"],+ kbd: ["phrasing"],+ label: ["phrasing"],+ legend: ["phrasing", "heading content"],+ li: ["flow"],+ link: ["empty"],+ main: ["flow"],+ map: ["transparent", "area"],+ mark: ["phrasing"],+ menu: ["li", "script-supporting elements"],+ meta: ["empty"],+ meter: ["phrasing"],+ nav: ["flow"],+ noscript: ["varies"],+ object: ["transparent"],+ ol: ["li", "script-supporting elements"],+ optgroup: ["option", "script-supporting elements"],+ option: ["text"],+ output: ["phrasing"],+ p: ["phrasing"],+ picture: ["source", "one img", "script-supporting elements"],+ pre: ["phrasing"],+ progress: ["phrasing"],+ q: ["phrasing"],+ rp: ["text"],+ rt: ["phrasing"],+ ruby: ["phrasing", "rt", "rp"],+ s: ["phrasing"],+ samp: ["phrasing"],+ script: ["script, data, or script documentation"],+ search: ["flow"],+ section: ["flow"],+ select: ["option", "optgroup", "script-supporting elements"],+ slot: ["transparent"],+ small: ["phrasing"],+ source: ["empty"],+ span: ["phrasing"],+ strong: ["phrasing"],+ style: ["text"],+ sub: ["phrasing"],+ summary: ["phrasing", "heading content"],+ sup: ["phrasing"],+ table: [+ "caption",+ "colgroup",+ "thead",+ "tbody",+ "tfoot",+ "tr",+ "script-supporting elements",+ ],+ tbody: ["tr", "script-supporting elements"],+ td: ["flow"],+ template: ["empty"],+ textarea: ["text"],+ tfoot: ["tr", "script-supporting elements"],+ th: ["flow"],+ thead: ["tr", "script-supporting elements"],+ time: ["phrasing"],+ title: ["text"],+ tr: ["th", "td", "script-supporting elements"],+ track: ["empty"],+ u: ["phrasing"],+ ul: ["li", "script-supporting elements"],+ var: ["phrasing"],+ video: ["source", "track", "transparent"],+ wbr: ["empty"],+};diff --git a/packages/html-data/src/index.ts b/packages/html-data/src/index.tsindex cc0564a2ed..a0aca455c0 100644--- a/packages/html-data/src/index.ts+++ b/packages/html-data/src/index.ts@@ -1,2 +1,3 @@+export * from "./__generated__/content-model";export * from "./descriptions";export * from "./dom-attributes-react-mappings";diff --git a/packages/sdk-components-react/src/button.ws.ts b/packages/sdk-components-react/src/button.ws.tsindex ef3573f94b..d39135ce62 100644--- a/packages/sdk-components-react/src/button.ws.ts+++ b/packages/sdk-components-react/src/button.ws.ts@@ -16,10 +16,6 @@ const presetStyle = {export const meta: WsComponentMeta = {icon: ButtonElementIcon,type: "container",- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },presetStyle,states: [...defaultStates,diff --git a/packages/sdk-components-react/src/checkbox.ws.ts b/packages/sdk-components-react/src/checkbox.ws.tsindex 0d420a0cdd..805574e877 100644--- a/packages/sdk-components-react/src/checkbox.ws.ts+++ b/packages/sdk-components-react/src/checkbox.ws.ts@@ -20,10 +20,6 @@ const presetStyle = {} satisfies PresetStyle<typeof defaultTag>;export const meta: WsComponentMeta = {- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },type: "control",icon: CheckboxCheckedIcon,presetStyle,diff --git a/packages/sdk-components-react/src/code-text.ws.ts b/packages/sdk-components-react/src/code-text.ws.tsindex b8cc99d4f2..848348d9c1 100644--- a/packages/sdk-components-react/src/code-text.ws.ts+++ b/packages/sdk-components-react/src/code-text.ws.ts@@ -45,10 +45,6 @@ export const meta: WsComponentMeta = {description:"Use this component when you want to display code as text on the page.",icon: BracesIcon,- constraints: {- relation: "ancestor",- component: { $neq: "CodeText" },- },states: defaultStates,presetStyle,order: 5,diff --git a/packages/sdk-components-react/src/form.ws.ts b/packages/sdk-components-react/src/form.ws.tsindex bdab8deb40..64680f9cd3 100644--- a/packages/sdk-components-react/src/form.ws.ts+++ b/packages/sdk-components-react/src/form.ws.ts@@ -20,10 +20,6 @@ export const meta: WsComponentMeta = {category: "forms",type: "container",label: "Form",- constraints: {- relation: "ancestor",- component: { $nin: ["Form", "Button", "Link"] },- },description: "Create filters, surveys, searches and more.",icon: FormIcon,states: defaultStates,diff --git a/packages/sdk-components-react/src/heading.ws.ts b/packages/sdk-components-react/src/heading.ws.tsindex 34965c9624..0a4ba6be34 100644--- a/packages/sdk-components-react/src/heading.ws.ts+++ b/packages/sdk-components-react/src/heading.ws.ts@@ -25,10 +25,6 @@ export const meta: WsComponentMeta = {type: "container",placeholder: "Heading",icon: HeadingIcon,- constraints: {- relation: "ancestor",- component: { $neq: "Heading" },- },states: defaultStates,presetStyle,};diff --git a/packages/sdk-components-react/src/input.ws.ts b/packages/sdk-components-react/src/input.ws.tsindex ec45b00d83..cbf24aaaa6 100644--- a/packages/sdk-components-react/src/input.ws.ts+++ b/packages/sdk-components-react/src/input.ws.ts@@ -21,10 +21,6 @@ const presetStyle = {export const meta: WsComponentMeta = {category: "forms",- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },type: "control",label: "Text Input",description:diff --git a/packages/sdk-components-react/src/label.ws.ts b/packages/sdk-components-react/src/label.ws.tsindex 41937f3af8..d14e241e8e 100644--- a/packages/sdk-components-react/src/label.ws.ts+++ b/packages/sdk-components-react/src/label.ws.ts@@ -17,10 +17,6 @@ const presetStyle = {} satisfies PresetStyle<typeof defaultTag>;export const meta: WsComponentMeta = {- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },type: "container",label: "Input Label",icon: LabelIcon,diff --git a/packages/sdk-components-react/src/link.ws.ts b/packages/sdk-components-react/src/link.ws.tsindex a50f51a6e8..930f20eb3a 100644--- a/packages/sdk-components-react/src/link.ws.ts+++ b/packages/sdk-components-react/src/link.ws.ts@@ -23,10 +23,6 @@ export const meta: WsComponentMeta = {type: "container",placeholder: "Link",icon: LinkIcon,- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },presetStyle,states: [...defaultStates,diff --git a/packages/sdk-components-react/src/list-item.ws.ts b/packages/sdk-components-react/src/list-item.ws.tsindex 63fcbd90a7..b7c8b91b49 100644--- a/packages/sdk-components-react/src/list-item.ws.ts+++ b/packages/sdk-components-react/src/list-item.ws.ts@@ -1,31 +1,20 @@import { ListItemIcon } from "@webstudio-is/icons/svg";import {defaultStates,- type PresetStyle,type WsComponentMeta,type WsComponentPropsMeta,} from "@webstudio-is/sdk";import { li } from "@webstudio-is/sdk/normalize.css";-import type { defaultTag } from "./list-item";import { props } from "./__generated__/list-item.props";-const presetStyle = {- li,-} satisfies PresetStyle<typeof defaultTag>;-export const meta: WsComponentMeta = {type: "container",placeholder: "List item",- constraints: {- // cannot use parent relation here- // because list item can be put inside of collection or slot- // perhaps can be eventually fixed with tag matchers- relation: "ancestor",- component: { $eq: "List" },- },icon: ListItemIcon,states: defaultStates,- presetStyle,+ presetStyle: {+ li,+ },};export const propsMeta: WsComponentPropsMeta = {diff --git a/packages/sdk-components-react/src/option.ws.ts b/packages/sdk-components-react/src/option.ws.tsindex 82be10352f..3f7101c86e 100644--- a/packages/sdk-components-react/src/option.ws.ts+++ b/packages/sdk-components-react/src/option.ws.ts@@ -26,10 +26,6 @@ const presetStyle = {export const meta: WsComponentMeta = {category: "hidden",- constraints: {- relation: "parent",- component: { $eq: "Select" },- },type: "control",description:"An item within a drop-down menu that users can select as their chosen value.",diff --git a/packages/sdk-components-react/src/paragraph.ws.ts b/packages/sdk-components-react/src/paragraph.ws.tsindex d81e8c2abc..8147d73900 100644--- a/packages/sdk-components-react/src/paragraph.ws.ts+++ b/packages/sdk-components-react/src/paragraph.ws.ts@@ -17,10 +17,6 @@ export const meta: WsComponentMeta = {type: "container",placeholder: "Paragraph",icon: TextAlignLeftIcon,- constraints: {- relation: "ancestor",- component: { $neq: "Paragraph" },- },states: defaultStates,presetStyle,};diff --git a/packages/sdk-components-react/src/radio-button.ws.ts b/packages/sdk-components-react/src/radio-button.ws.tsindex 3ec8fb4ae0..486e965e00 100644--- a/packages/sdk-components-react/src/radio-button.ws.ts+++ b/packages/sdk-components-react/src/radio-button.ws.ts@@ -20,10 +20,6 @@ const presetStyle = {} satisfies PresetStyle<typeof defaultTag>;export const meta: WsComponentMeta = {- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },type: "control",label: "Radio",icon: RadioCheckedIcon,diff --git a/packages/sdk-components-react/src/select.ws.ts b/packages/sdk-components-react/src/select.ws.tsindex cfa716aa7b..2609905924 100644--- a/packages/sdk-components-react/src/select.ws.ts+++ b/packages/sdk-components-react/src/select.ws.ts@@ -20,10 +20,6 @@ const presetStyle = {} satisfies PresetStyle<typeof defaultTag>;export const meta: WsComponentMeta = {- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },type: "container",icon: SelectIcon,presetStyle,diff --git a/packages/sdk-components-react/src/textarea.ws.ts b/packages/sdk-components-react/src/textarea.ws.tsindex ccf09ae90d..a46cb9bd31 100644--- a/packages/sdk-components-react/src/textarea.ws.ts+++ b/packages/sdk-components-react/src/textarea.ws.ts@@ -30,10 +30,6 @@ export const meta: WsComponentMeta = {icon: FormTextAreaIcon,presetStyle,order: 4,- constraints: {- relation: "ancestor",- component: { $nin: ["Button", "Link"] },- },states: [...defaultStates,{ selector: "::placeholder", label: "Placeholder" },diff --git a/packages/sdk-components-react/src/webhook-form.ws.ts b/packages/sdk-components-react/src/webhook-form.ws.tsindex 4619b40fa7..e9313a6e7f 100644--- a/packages/sdk-components-react/src/webhook-form.ws.ts+++ b/packages/sdk-components-react/src/webhook-form.ws.ts@@ -7,10 +7,6 @@ export const meta: WsComponentMeta = {label: "Webhook Form",icon: WebhookFormIcon,type: "container",- constraints: {- relation: "ancestor",- component: { $nin: ["Form", "Button", "Link"] },- },presetStyle: {form,},diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex c53e906248..60c88242a0 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -259,6 +259,9 @@ importers:'@webstudio-is/fonts':specifier: workspace:*version: link:../../packages/fonts+ '@webstudio-is/html-data':+ specifier: workspace:*+ version: link:../../packages/html-data'@webstudio-is/http-client':specifier: workspace:*version: link:../../packages/http-client@@ -1534,6 +1537,9 @@ importers:'@webstudio-is/tsconfig':specifier: workspace:*version: link:../tsconfig+ parse5:+ specifier: 7.2.1+ version: 7.2.1packages/http-client:dependencies:@@ -3748,6 +3754,7 @@ packages:'@miniflare/[email protected]':resolution: {integrity: sha512-GB/vZn7oLbnhw+815SGF+HU5EZqSxbhIa3mu2L5MzZ2q5VOD5NHC833qG8c2GzDPhIaZ99ITY+ZJmbR4d+4aNQ==}engines: {node: '>=16.13'}+ deprecated: Miniflare v2 is no longer supported. Please upgrade to Miniflare v4'@miniflare/[email protected]':resolution: {integrity: sha512-aXQ5Ik8Iq1KGMBzGenmd6Js/jJgqyYvjom95/N9GptCGpiVWE5F0XqC1SL5rCwURbHN+aWY191o8XOFyY2nCUA==}@@ -6147,10 +6154,6 @@ packages:resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==}- resolution: {integrity: sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==}- engines: {node: '>=0.12'}-resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==}engines: {node: '>=0.12'}@@ -13304,7 +13307,7 @@ snapshots:dependencies:domelementtype: 2.3.0domhandler: 5.0.3- entities: 4.4.0+ entities: 4.5.0@@ -13363,8 +13366,6 @@ snapshots:dependencies:once: 1.4.0- [email protected]: {}-