[WEB-2050] dev: added new information panels to a page (#5409)
* dev: added new information panels to pages * refactor: update function name
This commit is contained in:
parent
fb2a04dc14
commit
7efda1c392
13 changed files with 173 additions and 65 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import CharacterCount from "@tiptap/extension-character-count";
|
||||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import TaskItem from "@tiptap/extension-task-item";
|
||||
import TaskList from "@tiptap/extension-task-list";
|
||||
|
|
@ -157,4 +158,5 @@ export const CoreEditorExtensions = ({
|
|||
},
|
||||
includeChildren: true,
|
||||
}),
|
||||
CharacterCount,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import { Extensions, generateJSON, getSchema } from "@tiptap/core";
|
||||
import { Selection } from "@tiptap/pm/state";
|
||||
import { EditorState, Selection } from "@tiptap/pm/state";
|
||||
import { clsx, type ClassValue } from "clsx";
|
||||
import { CoreEditorExtensionsWithoutProps } from "src/core/extensions/core-without-props";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
interface EditorClassNames {
|
||||
|
|
@ -61,3 +59,12 @@ export const isValidHttpUrl = (string: string): boolean => {
|
|||
|
||||
return url.protocol === "http:" || url.protocol === "https:";
|
||||
};
|
||||
|
||||
export const getParagraphCount = (editorState: EditorState | undefined) => {
|
||||
if (!editorState) return 0;
|
||||
let paragraphCount = 0;
|
||||
editorState.doc.descendants((node) => {
|
||||
if (node.type.name === "paragraph" && node.content.size > 0) paragraphCount++;
|
||||
});
|
||||
return paragraphCount;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { getEditorMenuItems } from "@/components/menus";
|
|||
// extensions
|
||||
import { CoreEditorExtensions } from "@/extensions";
|
||||
// helpers
|
||||
import { getParagraphCount } from "@/helpers/common";
|
||||
import { insertContentAtSavedSelection } from "@/helpers/insert-content-at-cursor-position";
|
||||
import { IMarking, scrollSummary } from "@/helpers/scroll-to-node";
|
||||
// plane editor providers
|
||||
|
|
@ -249,6 +250,11 @@ export const useEditor = (props: CustomEditorProps) => {
|
|||
editor.chain().focus().deleteRange({ from, to }).insertContent(contentHTML).run();
|
||||
}
|
||||
},
|
||||
documentInfo: {
|
||||
characters: editorRef.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef.current?.state),
|
||||
words: editorRef.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
},
|
||||
}),
|
||||
[editorRef, savedSelection, fileHandler.upload]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { useEditor as useCustomEditor, Editor } from "@tiptap/react";
|
|||
// extensions
|
||||
import { CoreReadOnlyEditorExtensions } from "@/extensions";
|
||||
// helpers
|
||||
import { getParagraphCount } from "@/helpers/common";
|
||||
import { IMarking, scrollSummary } from "@/helpers/scroll-to-node";
|
||||
// props
|
||||
import { CoreReadOnlyEditorProps } from "@/props";
|
||||
|
|
@ -81,6 +82,11 @@ export const useReadOnlyEditor = ({
|
|||
if (!editorRef.current) return;
|
||||
scrollSummary(editorRef.current, marking);
|
||||
},
|
||||
documentInfo: {
|
||||
characters: editorRef.current?.storage?.characterCount?.characters?.() ?? 0,
|
||||
paragraphs: getParagraphCount(editorRef.current?.state),
|
||||
words: editorRef.current?.storage?.characterCount?.words?.() ?? 0,
|
||||
},
|
||||
}));
|
||||
|
||||
if (!editor) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ export type EditorReadOnlyRefApi = {
|
|||
clearEditor: (emitUpdate?: boolean) => void;
|
||||
setEditorValue: (content: string) => void;
|
||||
scrollSummary: (marking: IMarking) => void;
|
||||
documentInfo: {
|
||||
characters: number;
|
||||
paragraphs: number;
|
||||
words: number;
|
||||
};
|
||||
};
|
||||
|
||||
export interface EditorRefApi extends EditorReadOnlyRefApi {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue