mirror of
https://github.com/docmost/docmost.git
synced 2026-07-14 02:46:45 +10:00
657fdf8cb7
* Tiptap3 migration - WIP * fix collaboration * remove unused code * fix flicker * disable duplicate extensions * update tiptap version * Switch to useEditorState - Set shouldRerenderOnTransaction to false * fix editable state * add tippyoptions for reference * merge main * tiptap 3.6.1 * fix bubble menu * fix converter * fix menus * fix collaboration caret css * fix: Set `isInitialized` to force immediate react node view rendering * feat: Migrate tippy.js menus to Floating UI * feat: Update collaboration connection for HocusPocus v3 * fix: Connect/disconnect websocketProvider * cleanup * cleanup * feat: Improved placeholder and upload handling for images * feat: Improved placeholder and upload handling for videos * refactor: Image node and view clean-up * feat: Improved placeholder and upload handling for attachments * fix: Video view styles * fix: Transaction handling on asset upload * fix: Use imageDimensionsFromStream * feat: Multiple file upload, improved placeholders, local previews * fix: Drag & drop, paste upload * fix: Allow media as attachment * * add skeleton pulse animation * add translation strings * fix attachment view responsiveness * fix collab connection status display * Tiptap v3.17.0 * fix suggestion menu exit bug * fix search shortcut * fix history editor css * tiptap 3.17.1 --------- Co-authored-by: Arek Nawo <areknawo@areknawo.com>
99 lines
2.6 KiB
TypeScript
99 lines
2.6 KiB
TypeScript
import "@/features/editor/styles/index.css";
|
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
import { EditorProvider } from "@tiptap/react";
|
|
import { mainExtensions } from "@/features/editor/extensions/extensions";
|
|
import { Document } from "@tiptap/extension-document";
|
|
import { Heading, generateNodeId, UniqueID } from "@docmost/editor-ext";
|
|
import { Text } from "@tiptap/extension-text";
|
|
import { Placeholder } from "@tiptap/extension-placeholder";
|
|
import { useAtom } from "jotai";
|
|
import { readOnlyEditorAtom } from "@/features/editor/atoms/editor-atoms.ts";
|
|
import { useEditorScroll } from "./hooks/use-editor-scroll";
|
|
|
|
interface PageEditorProps {
|
|
title: string;
|
|
content: any;
|
|
pageId?: string;
|
|
}
|
|
|
|
export default function ReadonlyPageEditor({
|
|
title,
|
|
content,
|
|
pageId,
|
|
}: PageEditorProps) {
|
|
const [, setReadOnlyEditor] = useAtom(readOnlyEditorAtom);
|
|
const isComponentMounted = useRef(false);
|
|
const editorCreated = useRef(false);
|
|
|
|
const canScroll = useCallback(
|
|
() => isComponentMounted.current && editorCreated.current,
|
|
[isComponentMounted, editorCreated],
|
|
);
|
|
const initialScrollTo = window.location.hash
|
|
? window.location.hash.slice(1)
|
|
: "";
|
|
const { handleScrollTo } = useEditorScroll({ canScroll, initialScrollTo });
|
|
|
|
useEffect(() => {
|
|
isComponentMounted.current = true;
|
|
}, []);
|
|
|
|
const extensions = useMemo(() => {
|
|
const filteredExtensions = mainExtensions.filter(
|
|
(ext) => ext.name !== "uniqueID",
|
|
);
|
|
|
|
return [
|
|
...filteredExtensions,
|
|
UniqueID.configure({
|
|
types: ["heading", "paragraph"],
|
|
updateDocument: false,
|
|
}),
|
|
];
|
|
}, []);
|
|
|
|
const titleExtensions = [
|
|
Document.extend({
|
|
content: "heading",
|
|
}),
|
|
Heading,
|
|
Text,
|
|
Placeholder.configure({
|
|
placeholder: "Untitled",
|
|
showOnlyWhenEditable: false,
|
|
}),
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<EditorProvider
|
|
editable={false}
|
|
immediatelyRender={true}
|
|
extensions={titleExtensions}
|
|
content={title}
|
|
></EditorProvider>
|
|
|
|
<EditorProvider
|
|
editable={false}
|
|
immediatelyRender={true}
|
|
extensions={extensions}
|
|
content={content}
|
|
onCreate={({ editor }) => {
|
|
if (editor) {
|
|
if (pageId) {
|
|
// @ts-ignore
|
|
editor.storage.pageId = pageId;
|
|
}
|
|
// @ts-ignore
|
|
setReadOnlyEditor(editor);
|
|
|
|
handleScrollTo(editor);
|
|
editorCreated.current = true;
|
|
}
|
|
}}
|
|
></EditorProvider>
|
|
<div style={{ paddingBottom: "20vh" }}></div>
|
|
</>
|
|
);
|
|
}
|