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
Fix code text component (#2120)
Bogdan Chadkine665a996ee92
diff --git a/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts b/apps/builder/app/shared/copy-paste/plugin-markdown.test.tsindex 8236e273ae..c19f84da00 100644--- a/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts+++ b/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts@@ -1,745 +1,788 @@import { describe, test, expect } from "@jest/globals";-import { Instance, Prop } from "@webstudio-is/project-build";import { parse } from "./plugin-markdown";--const parseInstanceData = (data?: ReturnType<typeof parse>) => {- if (data === undefined) {- return;- }- const { children, instances, props } = data;- for (const instance of instances) {- Instance.parse(instance);- }- for (const prop of props) {- Prop.parse(prop);- }- return { children, instances, props };-};+import { breakpointsStore } from "../nano-states";const options = { generateId: () => "123" };+breakpointsStore.set(new Map([["0", { id: "0", label: "base" }]]));+describe("Plugin Markdown", () => {test("paragraph", () => {- expect(parseInstanceData(parse("xyz", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "xyz",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("xyz", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "xyz",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("h1", () => {- expect(parseInstanceData(parse("# heading", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "heading",- },- ],- "component": "Heading",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "tag",- "type": "string",- "value": "h1",- },- ],- }- `);+ expect(parse("# heading", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "heading",+ },+ ],+ "component": "Heading",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "tag",+ "type": "string",+ "value": "h1",+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("h6", () => {- expect(parseInstanceData(parse("###### heading", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "heading",- },- ],- "component": "Heading",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "tag",- "type": "string",- "value": "h6",- },- ],- }- `);+ expect(parse("###### heading", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "heading",+ },+ ],+ "component": "Heading",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "tag",+ "type": "string",+ "value": "h6",+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("bold 1", () => {- expect(parseInstanceData(parse("__bold__", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "bold",- },- ],- "component": "Bold",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("__bold__", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "bold",+ },+ ],+ "component": "Bold",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("bold 2", () => {- expect(parseInstanceData(parse("**bold**", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "bold",- },- ],- "component": "Bold",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("**bold**", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "bold",+ },+ ],+ "component": "Bold",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("italic 1", () => {- expect(parseInstanceData(parse("_italic_", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "italic",- },- ],- "component": "Italic",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("_italic_", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "italic",+ },+ ],+ "component": "Italic",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("italic 2", () => {- expect(parseInstanceData(parse("*italic*", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "italic",- },- ],- "component": "Italic",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("*italic*", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "italic",+ },+ ],+ "component": "Italic",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("link", () => {- expect(parseInstanceData(parse('[link](/uri "Title")', options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "link",- },- ],- "component": "RichTextLink",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "href",- "type": "string",- "value": "/uri",- },- {- "id": "123",- "instanceId": "123",- "name": "title",- "type": "string",- "value": "Title",- },- ],- }- `);+ expect(parse('[link](/uri "Title")', options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "link",+ },+ ],+ "component": "RichTextLink",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "href",+ "type": "string",+ "value": "/uri",+ },+ {+ "id": "123",+ "instanceId": "123",+ "name": "title",+ "type": "string",+ "value": "Title",+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("image", () => {- expect(parseInstanceData(parse('', options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [],- "component": "Image",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "src",- "type": "string",- "value": "/url",- },- {- "id": "123",- "instanceId": "123",- "name": "title",- "type": "string",- "value": "title",- },- {- "id": "123",- "instanceId": "123",- "name": "alt",- "type": "string",- "value": "foo",- },- ],- }- `);+ expect(parse('', options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [],+ "component": "Image",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "src",+ "type": "string",+ "value": "/url",+ },+ {+ "id": "123",+ "instanceId": "123",+ "name": "title",+ "type": "string",+ "value": "title",+ },+ {+ "id": "123",+ "instanceId": "123",+ "name": "alt",+ "type": "string",+ "value": "foo",+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("hard line break", () => {expect(- parseInstanceData(- parse(- `foo+ parse(+ `foobaz`,- options- )+ options)).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "foo",- },- {- "type": "text",- "value": "baz",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "foo",+ },+ {+ "type": "text",+ "value": "baz",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("soft line break", () => {expect(- parseInstanceData(- parse(- `foo+ parse(+ `foobaz`,- options- )+ options)).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "foo- baz",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "foo+baz",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("blockquote", () => {- expect(parseInstanceData(parse("> bar", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "bar",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Blockquote",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("> bar", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "bar",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Blockquote",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("inline code", () => {- expect(parseInstanceData(parse("`foo`", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "foo",- },- ],- "component": "Code",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "inline",- "type": "boolean",- "value": true,- },- ],- }- `);+ expect(parse("`foo`", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "foo",+ },+ ],+ "component": "CodeText",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [+ {+ "instanceId": "123",+ "values": [+ "123",+ ],+ },+ ],+ "styleSources": [+ {+ "id": "123",+ "type": "local",+ },+ ],+ "styles": [+ {+ "breakpointId": "0",+ "property": "display",+ "styleSourceId": "123",+ "value": {+ "type": "keyword",+ "value": "inline-block",+ },+ },+ ],+}+`);});test("code", () => {- expect(parseInstanceData(parse("```js meta\nfoo\n```", options)))- .toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "foo",- },- ],- "component": "Code",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "inline",- "type": "boolean",- "value": false,- },- {- "id": "123",- "instanceId": "123",- "name": "lang",- "type": "string",- "value": "js",- },- {- "id": "123",- "instanceId": "123",- "name": "meta",- "type": "string",- "value": "meta",- },- ],- }- `);+ expect(parse("```js meta\nfoo\n```", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "foo",+ },+ ],+ "component": "CodeText",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "lang",+ "type": "string",+ "value": "js",+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("list unordered", () => {- expect(parseInstanceData(parse("- one", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "one",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "ListItem",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "List",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "ordered",- "type": "boolean",- "value": false,- },- ],- }- `);+ expect(parse("- one", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "one",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "ListItem",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "List",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "ordered",+ "type": "boolean",+ "value": false,+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("list ordered", () => {- expect(parseInstanceData(parse("3. one", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [- {- "type": "text",- "value": "one",- },- ],- "component": "Paragraph",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "ListItem",- "id": "123",- "type": "instance",- },- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "component": "List",- "id": "123",- "type": "instance",- },- ],- "props": [- {- "id": "123",- "instanceId": "123",- "name": "ordered",- "type": "boolean",- "value": true,- },- {- "id": "123",- "instanceId": "123",- "name": "start",- "type": "number",- "value": 3,- },- ],- }- `);+ expect(parse("3. one", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [+ {+ "type": "text",+ "value": "one",+ },+ ],+ "component": "Paragraph",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "ListItem",+ "id": "123",+ "type": "instance",+ },+ {+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "component": "List",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [+ {+ "id": "123",+ "instanceId": "123",+ "name": "ordered",+ "type": "boolean",+ "value": true,+ },+ {+ "id": "123",+ "instanceId": "123",+ "name": "start",+ "type": "number",+ "value": 3,+ },+ ],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});test("thematic break | separator", () => {- expect(parseInstanceData(parse("---", options))).toMatchInlineSnapshot(`- {- "children": [- {- "type": "id",- "value": "123",- },- ],- "instances": [- {- "children": [],- "component": "Separator",- "id": "123",- "type": "instance",- },- ],- "props": [],- }- `);+ expect(parse("---", options)).toMatchInlineSnapshot(`+{+ "children": [+ {+ "type": "id",+ "value": "123",+ },+ ],+ "dataSources": [],+ "instances": [+ {+ "children": [],+ "component": "Separator",+ "id": "123",+ "type": "instance",+ },+ ],+ "props": [],+ "styleSourceSelections": [],+ "styleSources": [],+ "styles": [],+}+`);});// @todo For some reason doesn't worktest.skip("strikethrough", () => {expect(- parseInstanceData(parse("~One~ ~~two~~ ~~~three~~~.", options))+ parse("~One~ ~~two~~ ~~~three~~~.", options)).toMatchInlineSnapshot();});});diff --git a/apps/builder/app/shared/copy-paste/plugin-markdown.ts b/apps/builder/app/shared/copy-paste/plugin-markdown.tsindex b6a71ac075..9d244b0743 100644--- a/apps/builder/app/shared/copy-paste/plugin-markdown.ts+++ b/apps/builder/app/shared/copy-paste/plugin-markdown.ts@@ -1,21 +1,22 @@-import store from "immerhin";+import { nanoid } from "nanoid";import { fromMarkdown } from "mdast-util-from-markdown";import { gfmFromMarkdown } from "mdast-util-gfm";import { gfm } from "micromark-extension-gfm";-import type { Instance, Prop } from "@webstudio-is/project-build";-import { nanoid } from "nanoid";-import { insertInstancesMutable } from "../tree-utils";+import type { Breakpoint, Instance } from "@webstudio-is/project-build";+import type { EmbedTemplateData } from "@webstudio-is/react-sdk";import {computeInstancesConstraints,findClosestDroppableTarget,+ insertTemplateData,} from "../instance-utils";import {+ breakpointsStore,instancesStore,- propsStore,registeredComponentMetasStore,selectedInstanceSelectorStore,selectedPageStore,} from "../nano-states";+import { isBaseBreakpoint } from "../breakpoints";const micromarkOptions = {extensions: [gfm()],@@ -35,9 +36,9 @@ const astTypeComponentMap: Record<string, Instance["component"]> = {// we need to either have RichTextImage or support Image inside RichTextimage: "Image",blockquote: "Blockquote",- code: "Code",+ code: "CodeText",// @todo same problem as with image- inlineCode: "Code",+ inlineCode: "CodeText",list: "List",listItem: "ListItem",thematicBreak: "Separator",@@ -48,11 +49,13 @@ type Options = { generateId?: typeof nanoid };type Root = ReturnType<typeof fromMarkdown>;const toInstanceData = (- instances: Instance[],- props: Prop[],+ data: EmbedTemplateData,+ breakpointId: Breakpoint["id"],ast: { children: Root["children"] },options: Options = {}): Instance["children"] => {+ const { instances, props, styleSources, styleSourceSelections, styles } =+ data;const { generateId = nanoid } = options;const children: Instance["children"] = [];@@ -66,24 +69,25 @@ const toInstanceData = (if (component === undefined) {continue;}+ const instanceId = generateId();const instance: Instance = {type: "instance",- id: generateId(),+ id: instanceId,component,children:"children" in child- ? toInstanceData(instances, props, child, options)+ ? toInstanceData(data, breakpointId, child, options): [],};instances.push(instance);- children.push({ type: "id", value: instance.id });+ children.push({ type: "id", value: instanceId });if (child.type === "heading") {props.push({id: generateId(),type: "string",name: "tag",- instanceId: instance.id,+ instanceId,value: `h${child.depth}`,});}@@ -92,7 +96,7 @@ const toInstanceData = (id: generateId(),type: "string",name: "href",- instanceId: instance.id,+ instanceId,value: child.url,});}@@ -101,7 +105,7 @@ const toInstanceData = (id: generateId(),type: "string",name: "src",- instanceId: instance.id,+ instanceId,value: child.url,});}@@ -110,12 +114,14 @@ const toInstanceData = (type: "text",value: child.value,});- props.push({- id: generateId(),- type: "boolean",- name: "inline",- instanceId: instance.id,- value: true,+ const styleSourceId = generateId();+ styleSources.push({ type: "local", id: styleSourceId });+ styleSourceSelections.push({ instanceId, values: [styleSourceId] });+ styles.push({+ breakpointId,+ styleSourceId,+ property: "display",+ value: { type: "keyword", value: "inline-block" },});}if (child.type === "code") {@@ -123,31 +129,15 @@ const toInstanceData = (type: "text",value: child.value,});- props.push({- id: generateId(),- type: "boolean",- name: "inline",- instanceId: instance.id,- value: false,- });if (child.lang) {props.push({id: generateId(),type: "string",name: "lang",- instanceId: instance.id,+ instanceId,value: child.lang,});}- if (child.meta) {- props.push({- id: generateId(),- type: "string",- name: "meta",- instanceId: instance.id,- value: child.meta,- });- }}if (child.type === "list") {if (typeof child.ordered === "boolean") {@@ -155,7 +145,7 @@ const toInstanceData = (id: generateId(),type: "boolean",name: "ordered",- instanceId: instance.id,+ instanceId,value: child.ordered,});}@@ -164,7 +154,7 @@ const toInstanceData = (id: generateId(),type: "number",name: "start",- instanceId: instance.id,+ instanceId,value: child.start,});}@@ -175,7 +165,7 @@ const toInstanceData = (id: generateId(),type: "string",name: "title",- instanceId: instance.id,+ instanceId,value: child.title,});}@@ -184,7 +174,7 @@ const toInstanceData = (id: generateId(),type: "string",name: "alt",- instanceId: instance.id,+ instanceId,value: child.alt,});}@@ -198,10 +188,23 @@ export const parse = (clipboardData: string, options?: Options) => {if (ast.children.length === 0) {return;}- const instances: Instance[] = [];- const props: Prop[] = [];- const children = toInstanceData(instances, props, ast, options);- return { props, instances, children };+ const breakpoints = breakpointsStore.get();+ const breakpointValues = Array.from(breakpoints.values());+ const baseBreakpoint = breakpointValues.find(isBaseBreakpoint);+ if (baseBreakpoint === undefined) {+ return;+ }+ const data: EmbedTemplateData = {+ children: [],+ instances: [],+ props: [],+ styles: [],+ styleSources: [],+ styleSourceSelections: [],+ dataSources: [],+ };+ data.children = toInstanceData(data, baseBreakpoint.id, ast, options);+ return data;};export const onPaste = (clipboardData: string): boolean => {@@ -230,18 +233,6 @@ export const onPaste = (clipboardData: string): boolean => {if (dropTarget === undefined) {return false;}- store.createTransaction([instancesStore, propsStore], (instances, props) => {- insertInstancesMutable(- instances,- props,- registeredComponentMetasStore.get(),- data.instances,- data.children,- dropTarget- );- for (const prop of data.props) {- props.set(prop.id, prop);- }- });+ insertTemplateData(data, dropTarget);return true;};diff --git a/packages/sdk-components-react/src/__generated__/checkbox.props.ts b/packages/sdk-components-react/src/__generated__/checkbox.props.tsindex ba9b1032eb..9b319481cf 100644--- a/packages/sdk-components-react/src/__generated__/checkbox.props.ts+++ b/packages/sdk-components-react/src/__generated__/checkbox.props.ts@@ -394,12 +394,6 @@ export const props: Record<string, PropMeta> = {color: { required: false, control: "color", type: "string" },content: { required: false, control: "text", type: "string" },contextMenu: { required: false, control: "text", type: "string" },- crossOrigin: {- required: false,- control: "radio",- type: "string",- options: ["", "anonymous", "use-credentials"],- },datatype: { required: false, control: "text", type: "string" },defaultChecked: { required: false, control: "boolean", type: "boolean" },dir: { required: false, control: "text", type: "string" },diff --git a/packages/sdk-components-react/src/__generated__/code-text.props.ts b/packages/sdk-components-react/src/__generated__/code-text.props.tsindex 2b35c97ea0..0a1fafa1e6 100644--- a/packages/sdk-components-react/src/__generated__/code-text.props.ts+++ b/packages/sdk-components-react/src/__generated__/code-text.props.ts@@ -23,7 +23,7 @@ export const props: Record<string, PropMeta> = {required: false,control: "select",type: "string",- options: ["inline", "list", "none", "both"],+ options: ["list", "none", "inline", "both"],},"aria-braillelabel": {description:@@ -396,12 +396,6 @@ export const props: Record<string, PropMeta> = {draggable: { required: false, control: "boolean", type: "boolean" },hidden: { required: false, control: "boolean", type: "boolean" },id: { required: false, control: "text", type: "string" },- inline: {- required: false,- control: "boolean",- type: "boolean",- defaultValue: false,- },inputMode: {description:"Hints at the type of data that might be entered by the user while editing the element or its contents\n@see https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute",@@ -432,7 +426,6 @@ export const props: Record<string, PropMeta> = {itemScope: { required: false, control: "boolean", type: "boolean" },itemType: { required: false, control: "text", type: "string" },lang: { required: false, control: "text", type: "string" },- meta: { required: false, control: "text", type: "string" },nonce: { required: false, control: "text", type: "string" },placeholder: { required: false, control: "text", type: "string" },prefix: { required: false, control: "text", type: "string" },diff --git a/packages/sdk-components-react/src/__generated__/input.props.ts b/packages/sdk-components-react/src/__generated__/input.props.tsindex bee987046d..d033ad83c5 100644--- a/packages/sdk-components-react/src/__generated__/input.props.ts+++ b/packages/sdk-components-react/src/__generated__/input.props.ts@@ -394,12 +394,6 @@ export const props: Record<string, PropMeta> = {color: { required: false, control: "color", type: "string" },content: { required: false, control: "text", type: "string" },contextMenu: { required: false, control: "text", type: "string" },- crossOrigin: {- required: false,- control: "radio",- type: "string",- options: ["", "anonymous", "use-credentials"],- },datatype: { required: false, control: "text", type: "string" },defaultChecked: { required: false, control: "boolean", type: "boolean" },dir: { required: false, control: "text", type: "string" },diff --git a/packages/sdk-components-react/src/__generated__/radio-button.props.ts b/packages/sdk-components-react/src/__generated__/radio-button.props.tsindex ba9b1032eb..9b319481cf 100644--- a/packages/sdk-components-react/src/__generated__/radio-button.props.ts+++ b/packages/sdk-components-react/src/__generated__/radio-button.props.ts@@ -394,12 +394,6 @@ export const props: Record<string, PropMeta> = {color: { required: false, control: "color", type: "string" },content: { required: false, control: "text", type: "string" },contextMenu: { required: false, control: "text", type: "string" },- crossOrigin: {- required: false,- control: "radio",- type: "string",- options: ["", "anonymous", "use-credentials"],- },datatype: { required: false, control: "text", type: "string" },defaultChecked: { required: false, control: "boolean", type: "boolean" },dir: { required: false, control: "text", type: "string" },diff --git a/packages/sdk-components-react/src/code-text.tsx b/packages/sdk-components-react/src/code-text.tsxindex c091c76dfa..632ecdc983 100644--- a/packages/sdk-components-react/src/code-text.tsx+++ b/packages/sdk-components-react/src/code-text.tsx@@ -1,31 +1,17 @@import {- forwardRef,- createElement,type ElementRef,type ComponentProps,+ forwardRef,+ createElement,} from "react";-import { cssVars } from "@webstudio-is/css-vars";export const defaultTag = "code";-export const displayVarNamespace = cssVars.define("code-display");--const blockStyle = {- [cssVars.define(displayVarNamespace)]: "block",-};--type Props = Omit<ComponentProps<typeof defaultTag>, "inline"> & {- inline?: boolean;- meta?: string;-};--export const CodeText = forwardRef<ElementRef<typeof defaultTag>, Props>(- ({ inline = false, ...props }, ref) => {- // @todo in the future we should expose the inline prop a an attribute- // and define the display style in `presetStyle` in meta.- const style = inline ? undefined : blockStyle;- return createElement(defaultTag, { ...props, style, ref });- }-);+export const CodeText = forwardRef<+ ElementRef<typeof defaultTag>,+ ComponentProps<typeof defaultTag>+>((props, ref) => {+ return createElement(defaultTag, { ...props, ref });+});CodeText.displayName = "CodeText";diff --git a/packages/sdk-components-react/src/code-text.ws.tsx b/packages/sdk-components-react/src/code-text.ws.tsxindex ab36912dfe..5108e51fc2 100644--- a/packages/sdk-components-react/src/code-text.ws.tsx+++ b/packages/sdk-components-react/src/code-text.ws.tsx@@ -6,7 +6,7 @@ import {type WsComponentPropsMeta,} from "@webstudio-is/react-sdk";import { code } from "@webstudio-is/react-sdk/css-normalize";-import { type defaultTag, displayVarNamespace } from "./code-text";+import type { defaultTag } from "./code-text";import { props } from "./__generated__/code-text.props";const presetStyle = {@@ -14,11 +14,11 @@ const presetStyle = {...code,{property: "display",- value: {- type: "var",- value: displayVarNamespace,- fallbacks: [{ type: "keyword", value: "inline-block" }],- },+ value: { type: "keyword", value: "block" },+ },+ {+ property: "whiteSpace",+ value: { type: "keyword", value: "pre-wrap" },},{property: "paddingLeft",@@ -54,5 +54,5 @@ export const meta: WsComponentMeta = {export const propsMeta: WsComponentPropsMeta = {props,- initialProps: ["id", "inline", "lang", "meta"],+ initialProps: ["id", "lang"],};