From 911d770bceaaadb6921bb302f6b7a70abed33062 Mon Sep 17 00:00:00 2001 From: southclaws Date: Sat, 12 Oct 2024 16:18:26 +0100 Subject: [PATCH 1/3] apply a unique ID to some rich text components to fix issues with images being uploaded to the wrong editor instance --- .../content/ContentComposer/ContentComposer.tsx | 10 +++++----- .../content/ContentComposer/useContentComposer.ts | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/web/src/components/content/ContentComposer/ContentComposer.tsx b/web/src/components/content/ContentComposer/ContentComposer.tsx index 7eee1e71f..4e19ebe8f 100644 --- a/web/src/components/content/ContentComposer/ContentComposer.tsx +++ b/web/src/components/content/ContentComposer/ContentComposer.tsx @@ -32,12 +32,12 @@ import { FloatingMenu } from "./plugins/MenuPlugin"; import { ContentComposerProps, useContentComposer } from "./useContentComposer"; export function ContentComposer(props: ContentComposerProps) { - const { editor, initialValueHTML, handlers, format } = + const { editor, initialValueHTML, uniqueID, handlers, format } = useContentComposer(props); return ( Date: Sat, 12 Oct 2024 16:37:03 +0100 Subject: [PATCH 2/3] fix editor floating menu positioning --- .../ContentComposer/ContentComposer.tsx | 2 ++ .../ContentComposer/plugins/MenuPlugin.tsx | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/web/src/components/content/ContentComposer/ContentComposer.tsx b/web/src/components/content/ContentComposer/ContentComposer.tsx index 4e19ebe8f..ac6fd4b4e 100644 --- a/web/src/components/content/ContentComposer/ContentComposer.tsx +++ b/web/src/components/content/ContentComposer/ContentComposer.tsx @@ -40,6 +40,8 @@ export function ContentComposer(props: ContentComposerProps) { id={`rich-text-editor-${uniqueID}`} containerType="inline-size" className="typography" + // NOTE: Relative positioning is for the floating menu to work. + position="relative" w="full" h="full" gap="1" diff --git a/web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx b/web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx index 048418bc1..4fdbf0364 100644 --- a/web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx +++ b/web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx @@ -103,7 +103,7 @@ export class FloatingMenuView { const { state } = view; const { doc, selection } = state; - const { from, to } = selection; + const isSame = oldState && oldState.doc.eq(doc) && oldState.selection.eq(selection); @@ -111,16 +111,32 @@ export class FloatingMenuView { return; } + const { offsetX, offsetY } = this.getMenuOffset(view); + + this.element.setAttribute( + "style", + `top: ${offsetY}px; left: ${offsetX - 1}px;`, + ); + } + + hide() { + const style = this.element.getAttribute("style"); + this.element.setAttribute("style", `${style} visibility: hidden;`); + } + + getMenuOffset(view: EditorView) { + const { state } = view; + const { selection } = state; + const { from, to } = selection; + const { top: containerTop } = view.dom.getBoundingClientRect(); const { bottom: caretY } = posToDOMRect(view, from, to); - const offsetY = caretY - containerTop + 16; // NOTE: Left is -1px for optical alignment due to the border radius. - this.element.setAttribute("style", `top: ${offsetY}px; left: -1px;`); - } + const offsetX = -1; + const offsetY = caretY - containerTop + 8; - hide() { - this.element.setAttribute("style", "visibility: hidden;"); + return { offsetX, offsetY }; } } From 3429a4e09a771c1d146b618514713d693eab2727 Mon Sep 17 00:00:00 2001 From: southclaws Date: Sat, 12 Oct 2024 16:38:17 +0100 Subject: [PATCH 3/3] tighten paragraph spacing --- web/src/app/global.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/app/global.css b/web/src/app/global.css index 3c41d4308..fb49450d2 100644 --- a/web/src/app/global.css +++ b/web/src/app/global.css @@ -89,7 +89,7 @@ body { /* BLOCK ELEMENTS */ p { - margin-bottom: 1rem; + margin-bottom: 0.5rem; } a { @@ -103,6 +103,10 @@ body { color: var(--colors-blue-11); } + img { + margin-bottom: 0.5rem; + } + h1, h2, h3,