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.

Markdown bugs (#1168)

Oleg Isonend5db7a38b421
diff --git a/apps/builder/app/shared/copy-paste/init-copy-paste.ts b/apps/builder/app/shared/copy-paste/init-copy-paste.ts
index 406b7b61e8..bcde3f634d 100644
--- a/apps/builder/app/shared/copy-paste/init-copy-paste.ts
+++ b/apps/builder/app/shared/copy-paste/init-copy-paste.ts
@@ -102,7 +102,9 @@ export const initCopyPaste = (options: Options) => {
document.addEventListener("cut", handleCut);
}
if (onPaste) {
- document.addEventListener("paste", handlePaste);
+ // Capture is required so we get the element before content-editable removes it
+ // This way we can detect when we are inside content-editable and ignore the event
+ document.addEventListener("paste", handlePaste, { capture: true });
}
return () => {
@@ -113,7 +115,7 @@ export const initCopyPaste = (options: Options) => {
document.removeEventListener("cut", handleCut);
}
if (onPaste) {
- document.removeEventListener("paste", handlePaste);
+ document.removeEventListener("paste", handlePaste, { capture: true });
}
};
};
diff --git a/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts b/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts
index 4a1438ef56..813ad600c4 100644
--- a/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-markdown.test.ts
@@ -236,7 +236,7 @@ describe("Plugin Markdown", () => {
"value": "link",
},
],
- "component": "Link",
+ "component": "RichTextLink",
"id": "123",
"type": "instance",
},
diff --git a/apps/builder/app/shared/copy-paste/plugin-markdown.ts b/apps/builder/app/shared/copy-paste/plugin-markdown.ts
index b1c9454304..8d5aa33ba6 100644
--- a/apps/builder/app/shared/copy-paste/plugin-markdown.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-markdown.ts
@@ -29,10 +29,13 @@ const astTypeComponentMap: Record<string, Instance["component"]> = {
heading: "Heading",
strong: "Bold",
emphasis: "Italic",
- link: "Link",
+ link: "RichTextLink",
+ // @todo image should not be rendered inside paragraph
+ // we need to either have RichTextImage or support Image inside RichText
image: "Image",
blockquote: "Blockquote",
code: "Code",
+ // @todo same problem as with image
inlineCode: "Code",
list: "List",
listItem: "ListItem",
diff --git a/apps/builder/app/shared/nano-states/nano-states.ts b/apps/builder/app/shared/nano-states/nano-states.ts
index 133a6321c7..e2c2ca1b48 100644
--- a/apps/builder/app/shared/nano-states/nano-states.ts
+++ b/apps/builder/app/shared/nano-states/nano-states.ts
@@ -423,9 +423,9 @@ const isScrollingContainer = atom<boolean>(false);
export const useIsScrolling = () => useValue(isScrollingContainer);
// We are editing the text of that instance in text editor.
-const textEditingInstanceIdContainer = atom<Instance["id"] | undefined>();
+export const textEditingInstanceIdStore = atom<Instance["id"] | undefined>();
export const useTextEditingInstanceId = () =>
- useValue(textEditingInstanceIdContainer);
+ useValue(textEditingInstanceIdStore);
export type DragAndDropState = {
isDragging: boolean;
diff --git a/packages/react-sdk/src/components/rich-text-link.tsx b/packages/react-sdk/src/components/rich-text-link.tsx
index 68371a3ad9..cc407ec38f 100644
--- a/packages/react-sdk/src/components/rich-text-link.tsx
+++ b/packages/react-sdk/src/components/rich-text-link.tsx
@@ -1,9 +1,7 @@
-import { forwardRef, type ElementRef, type ComponentProps } from "react";
+import { forwardRef } from "react";
import { Link } from "./link";
-type Props = ComponentProps<typeof Link>;
-
-export const RichTextLink = forwardRef<ElementRef<"a">, Props>((props, ref) => (
+export const RichTextLink: typeof Link = forwardRef((props, ref) => (
<Link {...props} ref={ref} />
));
diff --git a/packages/react-sdk/src/components/rich-text-link.ws.tsx b/packages/react-sdk/src/components/rich-text-link.ws.tsx
index a9cb055e01..96c01c802d 100644
--- a/packages/react-sdk/src/components/rich-text-link.ws.tsx
+++ b/packages/react-sdk/src/components/rich-text-link.ws.tsx
@@ -1,13 +1,14 @@
-import { Link2Icon } from "@webstudio-is/icons";
import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
import { props } from "./__generated__/rich-text-link.props";
+import { meta as linkMeta, propsMeta as propsLinkMeta } from "./link.ws";
export const meta: WsComponentMeta = {
+ ...linkMeta,
type: "rich-text-child",
- label: "Link",
- Icon: Link2Icon,
+ children: [],
};
export const propsMeta: WsComponentPropsMeta = {
+ ...propsLinkMeta,
props,
};