mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 13:22:38 +10:00
refactor page editor
This commit is contained in:
@ -1,15 +1,15 @@
|
|||||||
@media (max-width: 992px) {
|
|
||||||
.header,
|
.header,
|
||||||
.footer {
|
.footer {
|
||||||
|
@media (max-width: 992px) {
|
||||||
[data-layout='alt'] & {
|
[data-layout='alt'] & {
|
||||||
--_section-right: var(--app-shell-aside-offset, 0px);
|
--_section-right: var(--app-shell-aside-offset, 0px);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 993px) {
|
}
|
||||||
|
|
||||||
.aside {
|
.aside {
|
||||||
|
@media (min-width: 993px) {
|
||||||
background: var(--mantine-color-gray-light);
|
background: var(--mantine-color-gray-light);
|
||||||
|
|
||||||
[data-layout='alt'] & {
|
[data-layout='alt'] & {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import classes from './comment.module.css';
|
|||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { timeAgo } from '@/lib/time';
|
import { timeAgo } from '@/lib/time';
|
||||||
import CommentEditor from '@/features/comment/components/comment-editor';
|
import CommentEditor from '@/features/comment/components/comment-editor';
|
||||||
import { editorAtom } from '@/features/editor/atoms/editorAtom';
|
import { editorAtoms } from '@/features/editor/atoms/editor-atoms';
|
||||||
import CommentActions from '@/features/comment/components/comment-actions';
|
import CommentActions from '@/features/comment/components/comment-actions';
|
||||||
import CommentMenu from '@/features/comment/components/comment-menu';
|
import CommentMenu from '@/features/comment/components/comment-menu';
|
||||||
import { useHover } from '@mantine/hooks';
|
import { useHover } from '@mantine/hooks';
|
||||||
@ -22,7 +22,7 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const editor = useAtomValue(editorAtom);
|
const editor = useAtomValue(editorAtoms);
|
||||||
const [content, setContent] = useState(comment.content);
|
const [content, setContent] = useState(comment.content);
|
||||||
const updateCommentMutation = useUpdateCommentMutation();
|
const updateCommentMutation = useUpdateCommentMutation();
|
||||||
const deleteCommentMutation = useDeleteCommentMutation(comment.pageId);
|
const deleteCommentMutation = useDeleteCommentMutation(comment.pageId);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { atom } from 'jotai';
|
import { atom } from 'jotai';
|
||||||
import { Editor } from '@tiptap/core';
|
import { Editor } from '@tiptap/core';
|
||||||
|
|
||||||
export const editorAtom = atom<Editor | null>(null);
|
export const editorAtoms = atom<Editor | null>(null);
|
||||||
|
|
||||||
export const titleEditorAtom = atom<Editor | null>(null);
|
export const titleEditorAtom = atom<Editor | null>(null);
|
||||||
39
client/src/features/editor/components/editor-skeleton.tsx
Normal file
39
client/src/features/editor/components/editor-skeleton.tsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Skeleton } from '@mantine/core';
|
||||||
|
|
||||||
|
function EditorSkeleton() {
|
||||||
|
const [showSkeleton, setShowSkeleton] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => setShowSkeleton(true), 100);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!showSkeleton) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
<Skeleton height={12} mt={6} radius="xl" />
|
||||||
|
</>
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default EditorSkeleton;
|
||||||
@ -17,7 +17,7 @@ import SlashCommand from '@/features/editor/extensions/slash-command';
|
|||||||
import { Collaboration } from '@tiptap/extension-collaboration';
|
import { Collaboration } from '@tiptap/extension-collaboration';
|
||||||
import { CollaborationCursor } from '@tiptap/extension-collaboration-cursor';
|
import { CollaborationCursor } from '@tiptap/extension-collaboration-cursor';
|
||||||
import { Comment } from '@/features/editor/extensions/comment/comment';
|
import { Comment } from '@/features/editor/extensions/comment/comment';
|
||||||
import * as Y from 'yjs';
|
import { HocuspocusProvider } from '@hocuspocus/provider';
|
||||||
|
|
||||||
export const mainExtensions = [
|
export const mainExtensions = [
|
||||||
StarterKit.configure({
|
StarterKit.configure({
|
||||||
@ -55,11 +55,11 @@ export const mainExtensions = [
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
type CollabExtensions = (ydoc: Y.Doc, provider: any) => any[];
|
type CollabExtensions = (provider: HocuspocusProvider) => any[];
|
||||||
|
|
||||||
export const collabExtensions: CollabExtensions = (ydoc, provider) => [
|
export const collabExtensions: CollabExtensions = (provider) => [
|
||||||
Collaboration.configure({
|
Collaboration.configure({
|
||||||
document: ydoc,
|
document: provider.document,
|
||||||
}),
|
}),
|
||||||
CollaborationCursor.configure({
|
CollaborationCursor.configure({
|
||||||
provider,
|
provider,
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import classes from '@/features/editor/styles/editor.module.css';
|
import classes from '@/features/editor/styles/editor.module.css';
|
||||||
import Editor from '@/features/editor/editor';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { TitleEditor } from '@/features/editor/title-editor';
|
import { TitleEditor } from '@/features/editor/title-editor';
|
||||||
|
import PageEditor from '@/features/editor/page-editor';
|
||||||
|
|
||||||
export interface FullEditorProps {
|
export interface FullEditorProps {
|
||||||
pageId: string;
|
pageId: string;
|
||||||
@ -13,7 +13,7 @@ export function FullEditor({ pageId, title }: FullEditorProps) {
|
|||||||
return (
|
return (
|
||||||
<div className={classes.editor}>
|
<div className={classes.editor}>
|
||||||
<TitleEditor pageId={pageId} title={title} />
|
<TitleEditor pageId={pageId} title={title} />
|
||||||
<Editor pageId={pageId} />
|
<PageEditor pageId={pageId} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,102 +1,99 @@
|
|||||||
import '@/features/editor/styles/index.css';
|
import '@/features/editor/styles/index.css';
|
||||||
|
import React, {
|
||||||
import { HocuspocusProvider } from '@hocuspocus/provider';
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import { IndexeddbPersistence } from 'y-indexeddb';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
import { HocuspocusProvider } from '@hocuspocus/provider';
|
||||||
import { EditorContent, useEditor } from '@tiptap/react';
|
import { EditorContent, useEditor } from '@tiptap/react';
|
||||||
import React, { useEffect, useState } from 'react';
|
import { collabExtensions, mainExtensions } from '@/features/editor/extensions/extensions';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { currentUserAtom } from '@/features/user/atoms/current-user-atom';
|
|
||||||
import { authTokensAtom } from '@/features/auth/atoms/auth-tokens-atom';
|
import { authTokensAtom } from '@/features/auth/atoms/auth-tokens-atom';
|
||||||
import useCollaborationUrl from '@/features/editor/hooks/use-collaboration-url';
|
import useCollaborationUrl from '@/features/editor/hooks/use-collaboration-url';
|
||||||
import { IndexeddbPersistence } from 'y-indexeddb';
|
import { currentUserAtom } from '@/features/user/atoms/current-user-atom';
|
||||||
import { EditorBubbleMenu } from '@/features/editor/components/bubble-menu/bubble-menu';
|
import { editorAtoms } from '@/features/editor/atoms/editor-atoms';
|
||||||
import { asideStateAtom } from '@/components/navbar/atoms/sidebar-atom';
|
import { asideStateAtom } from '@/components/navbar/atoms/sidebar-atom';
|
||||||
import { activeCommentIdAtom, showCommentPopupAtom } from '@/features/comment/atoms/comment-atom';
|
import { activeCommentIdAtom, showCommentPopupAtom } from '@/features/comment/atoms/comment-atom';
|
||||||
import CommentDialog from '@/features/comment/components/comment-dialog';
|
import CommentDialog from '@/features/comment/components/comment-dialog';
|
||||||
import { editorAtom, titleEditorAtom } from '@/features/editor/atoms/editorAtom';
|
import EditorSkeleton from '@/features/editor/components/editor-skeleton';
|
||||||
import { collabExtensions, mainExtensions } from '@/features/editor/extensions';
|
import { EditorBubbleMenu } from '@/features/editor/components/bubble-menu/bubble-menu';
|
||||||
|
|
||||||
interface EditorProps {
|
|
||||||
pageId: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
const colors = ['#958DF1', '#F98181', '#FBBC88', '#FAF594', '#70CFF8', '#94FADB', '#B9F18D'];
|
const colors = ['#958DF1', '#F98181', '#FBBC88', '#FAF594', '#70CFF8', '#94FADB', '#B9F18D'];
|
||||||
const getRandomElement = list => list[Math.floor(Math.random() * list.length)];
|
const getRandomElement = list => list[Math.floor(Math.random() * list.length)];
|
||||||
const getRandomColor = () => getRandomElement(colors);
|
const getRandomColor = () => getRandomElement(colors);
|
||||||
|
|
||||||
export default function Editor({ pageId }: EditorProps) {
|
interface PageEditorProps {
|
||||||
|
pageId: string;
|
||||||
|
editable?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PageEditor({ pageId, editable = true }: PageEditorProps) {
|
||||||
const [token] = useAtom(authTokensAtom);
|
const [token] = useAtom(authTokensAtom);
|
||||||
const collaborationURL = useCollaborationUrl();
|
const collaborationURL = useCollaborationUrl();
|
||||||
const [provider, setProvider] = useState<any>();
|
|
||||||
const [yDoc] = useState(() => new Y.Doc());
|
|
||||||
const [isLocalSynced, setLocalSynced] = useState(false);
|
|
||||||
const [isRemoteSynced, setRemoteSynced] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (token) {
|
|
||||||
const indexeddbProvider = new IndexeddbPersistence(pageId, yDoc);
|
|
||||||
|
|
||||||
const provider = new HocuspocusProvider({
|
|
||||||
url: collaborationURL,
|
|
||||||
name: pageId,
|
|
||||||
document: yDoc,
|
|
||||||
token: token.accessToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
indexeddbProvider.on('synced', () => {
|
|
||||||
console.log('index synced');
|
|
||||||
setLocalSynced(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
provider.on('synced', () => {
|
|
||||||
console.log('remote synced');
|
|
||||||
setRemoteSynced(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
setProvider(provider);
|
|
||||||
return () => {
|
|
||||||
setProvider(null);
|
|
||||||
provider.destroy();
|
|
||||||
indexeddbProvider.destroy();
|
|
||||||
setRemoteSynced(false);
|
|
||||||
setLocalSynced(false);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [pageId, token]);
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSynced = isLocalSynced || isRemoteSynced;
|
|
||||||
if (isSynced){
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
}
|
|
||||||
return (isSynced && <TiptapEditor ydoc={yDoc} provider={provider} pageId={pageId} />);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TiptapEditorProps {
|
|
||||||
ydoc: Y.Doc,
|
|
||||||
provider: HocuspocusProvider,
|
|
||||||
pageId: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
function TiptapEditor({ ydoc, provider, pageId }: TiptapEditorProps) {
|
|
||||||
const [currentUser] = useAtom(currentUserAtom);
|
const [currentUser] = useAtom(currentUserAtom);
|
||||||
const [, setEditor] = useAtom(editorAtom);
|
const [, setEditor] = useAtom(editorAtoms);
|
||||||
const [titleEditor] = useAtom(titleEditorAtom);
|
const [, setAsideState] = useAtom(asideStateAtom);
|
||||||
const [asideState, setAsideState] = useAtom(asideStateAtom);
|
|
||||||
const [, setActiveCommentId] = useAtom(activeCommentIdAtom);
|
const [, setActiveCommentId] = useAtom(activeCommentIdAtom);
|
||||||
const [showCommentPopup, setShowCommentPopup] = useAtom(showCommentPopupAtom);
|
const [showCommentPopup, setShowCommentPopup] = useAtom(showCommentPopupAtom);
|
||||||
|
|
||||||
|
const ydoc = useMemo(() => new Y.Doc(), [pageId]);
|
||||||
|
|
||||||
|
const [isLocalSynced, setLocalSynced] = useState(false);
|
||||||
|
const [isRemoteSynced, setRemoteSynced] = useState(false);
|
||||||
|
|
||||||
|
const localProvider = useMemo(() => {
|
||||||
|
const provider = new IndexeddbPersistence(
|
||||||
|
pageId,
|
||||||
|
ydoc,
|
||||||
|
);
|
||||||
|
|
||||||
|
provider.on('synced', () => {
|
||||||
|
setLocalSynced(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return provider;
|
||||||
|
}, [pageId, ydoc]);
|
||||||
|
|
||||||
|
const remoteProvider = useMemo(() => {
|
||||||
|
const provider = new HocuspocusProvider({
|
||||||
|
name: pageId,
|
||||||
|
url: collaborationURL,
|
||||||
|
document: ydoc,
|
||||||
|
token: token?.accessToken,
|
||||||
|
connect: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
provider.on('synced', () => {
|
||||||
|
setRemoteSynced(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return provider;
|
||||||
|
}, [ydoc, pageId, token?.accessToken]);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
remoteProvider.connect();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
setRemoteSynced(false);
|
||||||
|
setLocalSynced(false);
|
||||||
|
remoteProvider.destroy();
|
||||||
|
localProvider.destroy();
|
||||||
|
};
|
||||||
|
}, [remoteProvider, localProvider]);
|
||||||
|
|
||||||
const extensions = [
|
const extensions = [
|
||||||
...mainExtensions,
|
...mainExtensions,
|
||||||
...collabExtensions(ydoc, provider),
|
...collabExtensions(remoteProvider),
|
||||||
];
|
];
|
||||||
|
|
||||||
const editor = useEditor({
|
const editor = useEditor(
|
||||||
extensions: extensions,
|
{
|
||||||
autofocus: 0,
|
extensions,
|
||||||
|
editable,
|
||||||
editorProps: {
|
editorProps: {
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
keydown: (_view, event) => {
|
keydown: (_view, event) => {
|
||||||
@ -115,26 +112,9 @@ function TiptapEditor({ ydoc, provider, pageId }: TiptapEditorProps) {
|
|||||||
setEditor(editor);
|
setEditor(editor);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUpdate({ editor }) {
|
|
||||||
const { selection } = editor.state;
|
|
||||||
if (!selection.empty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const viewportCoords = editor.view.coordsAtPos(selection.from);
|
|
||||||
const absoluteOffset = window.scrollY + viewportCoords.top;
|
|
||||||
window.scrollTo(
|
|
||||||
window.scrollX,
|
|
||||||
absoluteOffset - (window.innerHeight / 2),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
[pageId, editable, remoteProvider],
|
||||||
|
);
|
||||||
useEffect(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
titleEditor?.commands.focus('end');
|
|
||||||
}, 200);
|
|
||||||
}, [editor]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editor && currentUser.user) {
|
if (editor && currentUser.user) {
|
||||||
@ -165,18 +145,26 @@ function TiptapEditor({ ydoc, provider, pageId }: TiptapEditorProps) {
|
|||||||
setAsideState({ tab: '', isAsideOpen: false });
|
setAsideState({ tab: '', isAsideOpen: false });
|
||||||
}, [pageId]);
|
}, [pageId]);
|
||||||
|
|
||||||
return (
|
const isSynced = isLocalSynced || isRemoteSynced;
|
||||||
|
|
||||||
|
return isSynced ? (
|
||||||
|
<div>
|
||||||
|
{isSynced && (
|
||||||
<div>
|
<div>
|
||||||
{editor &&
|
|
||||||
(<div>
|
|
||||||
<EditorBubbleMenu editor={editor} />
|
|
||||||
<EditorContent editor={editor} />
|
<EditorContent editor={editor} />
|
||||||
|
|
||||||
|
{editor && editor.isEditable && (
|
||||||
|
<div>
|
||||||
|
<EditorBubbleMenu editor={editor} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{showCommentPopup && (
|
{showCommentPopup && (
|
||||||
<CommentDialog editor={editor} pageId={pageId} />
|
<CommentDialog editor={editor} pageId={pageId} />
|
||||||
)}
|
)}
|
||||||
</div>)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
)}
|
||||||
}
|
</div>
|
||||||
|
) : <EditorSkeleton />;
|
||||||
|
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@ import { Heading } from '@tiptap/extension-heading';
|
|||||||
import { Text } from '@tiptap/extension-text';
|
import { Text } from '@tiptap/extension-text';
|
||||||
import { Placeholder } from '@tiptap/extension-placeholder';
|
import { Placeholder } from '@tiptap/extension-placeholder';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { editorAtom, titleEditorAtom } from '@/features/editor/atoms/editorAtom';
|
import { editorAtoms, titleEditorAtom } from '@/features/editor/atoms/editor-atoms';
|
||||||
import { useUpdatePageMutation } from '@/features/page/queries/page-query';
|
import { useUpdatePageMutation } from '@/features/page/queries/page-query';
|
||||||
import { useDebouncedValue } from '@mantine/hooks';
|
import { useDebouncedValue } from '@mantine/hooks';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
@ -22,7 +22,7 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
|||||||
const [debouncedTitleState, setDebouncedTitleState] = useState('');
|
const [debouncedTitleState, setDebouncedTitleState] = useState('');
|
||||||
const [debouncedTitle] = useDebouncedValue(debouncedTitleState, 1000);
|
const [debouncedTitle] = useDebouncedValue(debouncedTitleState, 1000);
|
||||||
const updatePageMutation = useUpdatePageMutation();
|
const updatePageMutation = useUpdatePageMutation();
|
||||||
const contentEditor = useAtomValue(editorAtom);
|
const pageEditor = useAtomValue(editorAtoms);
|
||||||
const [, setTitleEditor] = useAtom(titleEditorAtom);
|
const [, setTitleEditor] = useAtom(titleEditorAtom);
|
||||||
const [treeData, setTreeData] = useAtom(treeDataAtom);
|
const [treeData, setTreeData] = useAtom(treeDataAtom);
|
||||||
|
|
||||||
@ -58,7 +58,6 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
|||||||
|
|
||||||
const newTreeData = updateTreeNodeName(treeData, pageId, debouncedTitle);
|
const newTreeData = updateTreeNodeName(treeData, pageId, debouncedTitle);
|
||||||
setTreeData(newTreeData);
|
setTreeData(newTreeData);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, [debouncedTitle]);
|
}, [debouncedTitle]);
|
||||||
|
|
||||||
@ -66,10 +65,16 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
|||||||
if (titleEditor && title !== titleEditor.getText()) {
|
if (titleEditor && title !== titleEditor.getText()) {
|
||||||
titleEditor.commands.setContent(title);
|
titleEditor.commands.setContent(title);
|
||||||
}
|
}
|
||||||
}, [title, titleEditor]);
|
}, [pageId, title, titleEditor]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
titleEditor?.commands.focus('end');
|
||||||
|
}, 500);
|
||||||
|
}, [titleEditor]);
|
||||||
|
|
||||||
function handleTitleKeyDown(event) {
|
function handleTitleKeyDown(event) {
|
||||||
if (!titleEditor || !contentEditor || event.shiftKey) return;
|
if (!titleEditor || !pageEditor || event.shiftKey) return;
|
||||||
|
|
||||||
const { key } = event;
|
const { key } = event;
|
||||||
const { $head } = titleEditor.state.selection;
|
const { $head } = titleEditor.state.selection;
|
||||||
@ -78,7 +83,7 @@ export function TitleEditor({ pageId, title }: TitleEditorProps) {
|
|||||||
(key === 'ArrowRight' && !$head.nodeAfter);
|
(key === 'ArrowRight' && !$head.nodeAfter);
|
||||||
|
|
||||||
if (shouldFocusEditor) {
|
if (shouldFocusEditor) {
|
||||||
contentEditor.commands.focus('start');
|
pageEditor.commands.focus('start');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import '@/features/editor/styles/index.css';
|
import '@/features/editor/styles/index.css';
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { EditorContent, useEditor } from '@tiptap/react';
|
import { EditorContent, useEditor } from '@tiptap/react';
|
||||||
import { mainExtensions } from '@/features/editor/extensions';
|
import { mainExtensions } from '@/features/editor/extensions/extensions';
|
||||||
import { Title } from '@mantine/core';
|
import { Title } from '@mantine/core';
|
||||||
|
|
||||||
export interface HistoryEditorProps {
|
export interface HistoryEditorProps {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { activeHistoryIdAtom, historyAtoms } from '@/features/page-history/atoms
|
|||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { Button, ScrollArea, Group, Divider, Text } from '@mantine/core';
|
import { Button, ScrollArea, Group, Divider, Text } from '@mantine/core';
|
||||||
import { editorAtom, titleEditorAtom } from '@/features/editor/atoms/editorAtom';
|
import { editorAtoms, titleEditorAtom } from '@/features/editor/atoms/editor-atoms';
|
||||||
import { modals } from '@mantine/modals';
|
import { modals } from '@mantine/modals';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ function HistoryList() {
|
|||||||
const { data, isLoading, isError } = usePageHistoryListQuery(pageId);
|
const { data, isLoading, isError } = usePageHistoryListQuery(pageId);
|
||||||
const { data: activeHistoryData } = usePageHistoryQuery(activeHistoryId);
|
const { data: activeHistoryData } = usePageHistoryQuery(activeHistoryId);
|
||||||
|
|
||||||
const [mainEditor] = useAtom(editorAtom);
|
const [mainEditor] = useAtom(editorAtoms);
|
||||||
const [mainEditorTitle] = useAtom(titleEditorAtom);
|
const [mainEditorTitle] = useAtom(titleEditorAtom);
|
||||||
const [, setHistoryModalOpen] = useAtom(historyAtoms);
|
const [, setHistoryModalOpen] = useAtom(historyAtoms);
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export default function Page() {
|
|||||||
return (
|
return (
|
||||||
data && (
|
data && (
|
||||||
<div>
|
<div>
|
||||||
<FullEditor key={pageId} pageId={pageId} title={data.title} />
|
<FullEditor pageId={pageId} title={data.title} />
|
||||||
<HistoryModal />
|
<HistoryModal />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user