A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: fix editor toolbar is not sticky
Abdullah Atta1487bf027abe
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 3e1394511..064dd0f88 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -51,9 +51,7 @@ import { useEditorManager } from "./manager";import { saveAttachment, downloadAttachment } from "../../common/attachments";import { EV, EVENTS } from "@notesnook/core/dist/common";import { db } from "../../common/db";-import useMobile from "../../hooks/use-mobile";import Titlebox from "./title-box";-import useTablet from "../../hooks/use-tablet";import Config from "../../utils/config";import { ScopedThemeProvider } from "../theme-provider";import { Lightbox } from "../lightbox";@@ -160,9 +158,6 @@ function EditorView({const isFocusMode = useAppStore((store) => store.isFocusMode);const editor = useEditorManager((store) => store.editors[session.id]?.editor);- const isMobile = useMobile();- const isTablet = useTablet();-useEffect(() => {const event = db.eventManager.subscribe(EVENTS.syncItemMerged,@@ -255,8 +250,7 @@ function EditorView({readonly:session?.type === "readonly" || session?.type === "deleted",onRequestFocus: () => toggleProperties(false),- focusMode: isFocusMode,- isMobile: isMobile || isTablet+ focusMode: isFocusMode}}/>{editor && <DropZone editor={editor} overlayRef={overlayRef} />}@@ -350,7 +344,6 @@ function DownloadAttachmentProgress(props: DownloadAttachmentProgressProps) {}type EditorOptions = {- isMobile?: boolean;headless?: boolean;readonly?: boolean;focusMode?: boolean;@@ -379,11 +372,10 @@ export function Editor(props: EditorProps) {onContentChange,onPreviewDocument} = props;- const { readonly, headless, isMobile } = options || {+ const { readonly, headless } = options || {headless: false,readonly: false,- focusMode: false,- isMobile: false+ focusMode: false};const [isLoading, setIsLoading] = useState(true);useScrollToBlock(session);@@ -408,7 +400,6 @@ export function Editor(props: EditorProps) {<EditorChrome isLoading={isLoading} {...props}><Tiptapid={id}- isMobile={isMobile}nonce={nonce}readonly={readonly}content={content}@@ -499,11 +490,10 @@ function EditorChrome(props: PropsWithChildren<EditorProps & { isLoading: boolean }>) {const { id, options, children } = props;- const { focusMode, headless, onRequestFocus, isMobile } = options || {+ const { focusMode, headless, onRequestFocus } = options || {headless: false,readonly: false,- focusMode: false,- isMobile: false+ focusMode: false};const editorMargins = useEditorStore((store) => store.editorMargins);const editorContainerRef = useRef<HTMLElement>(null);@@ -543,24 +533,6 @@ function EditorChrome(return (<>- {/* {isLoading ? (- <AnimatedFlex- sx={{- position: "absolute",- overflow: "hidden",- flex: 1,- flexDirection: "column",- width: "100%",- height: "100%",- zIndex: 999,- bg: "background"- }}- >- <EditorLoader />- </AnimatedFlex>- ) : null} */}-- {/* <Toolbar /> */}<FlexScrollContainerid={`editorScroll_${id}`}scrollRef={editorScrollRef}@@ -590,46 +562,9 @@ function EditorChrome(pr={6}onClick={onRequestFocus}>- {/* {!isMobile && (-- )} */}- {/* <Box- id={`${id}_toolbar`}- sx={{- minHeight: 34,- display: readonly ? "none" : "flex",- bg: "background",- position: "sticky",- top: 0,- mb: 1,- zIndex: 2- }}- /> */}-- {/* <AnimatedFlex- initial={{ opacity: 0 }}- animate={{ opacity: isLoading ? 0 : 1 }}- transition={{ duration: 0.3, ease: "easeInOut" }}- sx={{ flex: 1 }}- > */}{children}- {/* </AnimatedFlex> */}</Flex></FlexScrollContainer>- {isMobile && (- <Box- id={`${id}_toolbar`}- sx={{- display: "flex",- bg: "background",- position: "sticky",- top: 0,- mb: 1,- zIndex: 2,- px: [2, 2, 35]- }}- />- )}</>);}diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 1c809ebb1..3fe9da51d 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -74,7 +74,11 @@ type TipTapProps = {onInsertAttachment?: (type: AttachmentType) => void;onDownloadAttachment?: (attachment: Attachment) => void;onPreviewAttachment?: (attachment: Attachment) => void;- onGetAttachmentData?: (attachment: Attachment) => Promise<string | undefined>;+ onGetAttachmentData?:+ | ((+ attachment: Pick<Attachment, "hash" | "type">+ ) => Promise<string | undefined>)+ | undefined;onAttachFiles?: (files: File[]) => void;onInsertInternalLink?: (attributes?: LinkAttributes@@ -179,7 +183,6 @@ function TipTap(props: TipTapProps) {doubleSpacedLines,dateFormat,timeFormat,- isMobile: isMobile || false,element: editorContainer(),editable: !readonly,content: content?.(),@@ -297,35 +300,45 @@ function TipTap(props: TipTapProps) {[tiptapOptions]);- // useEffect(() => {- // if (!editorContainer) return;- // const currentEditor = editor;- // function onClick(e: MouseEvent) {- // if (e.target !== editorContainer || !currentEditor?.state.selection.empty)- // return;+ useEffect(() => {+ const container = editorContainer();+ if (!container) return;+ const currentEditor = editor;+ function onClick(e: MouseEvent) {+ if (e.target !== container || !currentEditor?.state.selection.empty)+ return;- // const lastNode = currentEditor?.state.doc.lastChild;- // const isLastNodeParagraph = lastNode?.type.name === "paragraph";- // const isEmpty = lastNode?.nodeSize === 2;- // if (isLastNodeParagraph && isEmpty) currentEditor?.commands.focus("end");- // else {- // currentEditor- // ?.chain()- // .insertContentAt(currentEditor?.state.doc.nodeSize - 2, "<p></p>")- // .focus("end")- // .run();- // }- // }- // editorContainer.addEventListener("click", onClick);- // return () => {- // editorContainer.removeEventListener("click", onClick);- // };- // }, [editor, editorContainer]);+ const lastNode = currentEditor?.state.doc.lastChild;+ const isLastNodeParagraph = lastNode?.type.name === "paragraph";+ const isEmpty = lastNode?.nodeSize === 2;+ if (isLastNodeParagraph && isEmpty) currentEditor?.commands.focus("end");+ else {+ currentEditor+ ?.chain()+ .insertContentAt(currentEditor?.state.doc.nodeSize - 2, "<p></p>")+ .focus("end")+ .run();+ }+ }+ container.addEventListener("click", onClick);+ return () => {+ container.removeEventListener("click", onClick);+ };+ }, [editor, editorContainer]);if (readonly) return null;return (<>- <ScopedThemeProvider scope="editorToolbar" sx={{ width: "100%" }}>+ <ScopedThemeProvider+ scope="editorToolbar"+ sx={{+ width: "100%",+ position: "sticky",+ top: 0,+ bg: "background",+ zIndex: 2+ }}+ ><Toolbareditor={editor}location={isMobile ? "bottom" : "top"}