payload-richtext-tiptap 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.d.ts +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.js +3 -2
- package/dist/src/fields/TiptapEditor/features/BlockEditor/BlockEditor.js.map +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/types.d.ts +3 -2
- package/dist/src/fields/TiptapEditor/features/BlockEditor/types.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/features/BlockEditor/types.js.map +1 -1
- package/dist/src/fields/TiptapEditor/hooks/useBlockEditor.d.ts +2 -1
- package/dist/src/fields/TiptapEditor/hooks/useBlockEditor.d.ts.map +1 -1
- package/dist/src/fields/TiptapEditor/hooks/useBlockEditor.js +2 -1
- package/dist/src/fields/TiptapEditor/hooks/useBlockEditor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TiptapProps } from "./types.js";
|
|
2
|
-
export declare const BlockEditor: ({ handleChange, content }: TiptapProps) => import("react").JSX.Element;
|
|
2
|
+
export declare const BlockEditor: ({ handleChange, content, handleChangeMarkdown, }: TiptapProps) => import("react").JSX.Element;
|
|
3
3
|
export default BlockEditor;
|
|
4
4
|
//# sourceMappingURL=BlockEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockEditor.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"BlockEditor.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,eAAO,MAAM,WAAW,qDAIrB,WAAW,gCA0Fb,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -16,12 +16,13 @@ import { Sidebar } from "../Sidebar/Sidebar.js";
|
|
|
16
16
|
import { ContentItemMenu } from "../menus/ContentItemMenu/ContentItemMenu.js";
|
|
17
17
|
import { TextMenu } from "../menus/TextMenu/TextMenu.js";
|
|
18
18
|
import { LinkMenu } from "../menus/index.js";
|
|
19
|
-
export const BlockEditor = ({ handleChange, content })=>{
|
|
19
|
+
export const BlockEditor = ({ handleChange, content, handleChangeMarkdown })=>{
|
|
20
20
|
const menuContainerRef = useRef(null);
|
|
21
21
|
const editorRef = useRef(null);
|
|
22
22
|
const { editor, users, characterCount, leftSidebar } = useBlockEditor({
|
|
23
23
|
content: content,
|
|
24
|
-
handleChange: handleChange
|
|
24
|
+
handleChange: handleChange,
|
|
25
|
+
handleChangeMarkdown
|
|
25
26
|
});
|
|
26
27
|
const { code } = useLocale();
|
|
27
28
|
const displayedUsers = users.slice(0, 3);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"sourcesContent":["\"use client\";\nimport { EditorContent } from \"@tiptap/react\";\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { useLocale } from \"@payloadcms/ui/providers/Locale\";\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\nimport { EditorContext } from \"../../context/EditorContext.js\";\nimport { IframeMenu } from \"../../extensions/Iframe/menus/index.js\";\nimport ImageBlockMenu from \"../../extensions/ImageBlock/components/ImageBlockMenu.js\";\nimport { InsideLinksMenu } from \"../../extensions/InsideLinks/menus/index.js\";\nimport { ColumnsMenu } from \"../../extensions/MultiColumn/menus/ColumnsMenu.js\";\nimport { SocialMediaMenu } from \"../../extensions/SocialMedia/menus/index.js\";\nimport {\n TableColumnMenu,\n TableRowMenu,\n} from \"../../extensions/Table/menus/index.js\";\nimport { useBlockEditor } from \"../../hooks/useBlockEditor.js\";\nimport { Sidebar } from \"../Sidebar/Sidebar.js\";\nimport { ContentItemMenu } from \"../menus/ContentItemMenu/ContentItemMenu.js\";\nimport { TextMenu } from \"../menus/TextMenu/TextMenu.js\";\nimport { LinkMenu } from \"../menus/index.js\";\nimport { TiptapProps } from \"./types.js\";\n\nexport const BlockEditor = ({
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/BlockEditor.tsx"],"sourcesContent":["\"use client\";\nimport { EditorContent } from \"@tiptap/react\";\nimport { useEffect, useMemo, useRef } from \"react\";\n\nimport { useLocale } from \"@payloadcms/ui/providers/Locale\";\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\nimport { EditorContext } from \"../../context/EditorContext.js\";\nimport { IframeMenu } from \"../../extensions/Iframe/menus/index.js\";\nimport ImageBlockMenu from \"../../extensions/ImageBlock/components/ImageBlockMenu.js\";\nimport { InsideLinksMenu } from \"../../extensions/InsideLinks/menus/index.js\";\nimport { ColumnsMenu } from \"../../extensions/MultiColumn/menus/ColumnsMenu.js\";\nimport { SocialMediaMenu } from \"../../extensions/SocialMedia/menus/index.js\";\nimport {\n TableColumnMenu,\n TableRowMenu,\n} from \"../../extensions/Table/menus/index.js\";\nimport { useBlockEditor } from \"../../hooks/useBlockEditor.js\";\nimport { Sidebar } from \"../Sidebar/Sidebar.js\";\nimport { ContentItemMenu } from \"../menus/ContentItemMenu/ContentItemMenu.js\";\nimport { TextMenu } from \"../menus/TextMenu/TextMenu.js\";\nimport { LinkMenu } from \"../menus/index.js\";\nimport { TiptapProps } from \"./types.js\";\n\nexport const BlockEditor = ({\n handleChange,\n content,\n handleChangeMarkdown,\n}: TiptapProps) => {\n const menuContainerRef = useRef(null);\n const editorRef = useRef<HTMLDivElement>(null);\n\n const { editor, users, characterCount, leftSidebar } = useBlockEditor({\n content: content,\n handleChange: handleChange,\n handleChangeMarkdown,\n });\n\n const { code } = useLocale();\n\n const displayedUsers = users.slice(0, 3);\n\n const providerValue = useMemo(() => {\n return {};\n }, []);\n\n useEffect(() => {\n if (code === \"ar\" || code === \"fa\") {\n editor?.commands?.setTextDirection(\"rtl\");\n editor?.commands?.setContent(\"dwa\");\n }\n }, [code]);\n\n if (!editor) {\n return null;\n }\n const { i18n } = useTranslation();\n\n // Define the content for different languages\n const contentEn = \"للكتابة...\"; // Content for English or default language\n const contentAr = \"انقر هنا للكتابة...\"; // Content for Arabic language\n const contentFa = \"اینجا کلیک کنید تا شروع به نوشتن کنید...\";\n\n /*switch (i18n.language) {\n case 'ar':\n editor.commands.setContent(contentAr)\n break\n case 'fa':\n editor.commands.setContent(contentFa)\n break\n default:\n editor.commands.setContent(contentEn)\n }*/\n\n return (\n <EditorContext.Provider value={providerValue}>\n <div\n lang={i18n.language}\n className=\"flex h-full overflow-visible\"\n ref={menuContainerRef}\n >\n <Sidebar\n isOpen={leftSidebar.isOpen}\n onClose={leftSidebar.close}\n editor={editor}\n />\n <div className=\"relative flex flex-col flex-1 h-full justify-center items-center \">\n {/* <EditorHeader\n characters={characterCount.characters()}\n users={displayedUsers}\n words={characterCount.words()}\n isSidebarOpen={leftSidebar.isOpen}\n toggleSidebar={leftSidebar.toggle}\n /> */}\n <EditorContent\n editor={editor}\n ref={editorRef}\n lang={i18n.language}\n className=\"flex-1 overflow-y-visible w-full h-full outline-none outline-offset-0\"\n style={{\n outline: \"none\",\n }}\n />\n <ContentItemMenu editor={editor} />\n <LinkMenu editor={editor} appendTo={menuContainerRef} />\n\n <TextMenu editor={editor} />\n <IframeMenu editor={editor} appendTo={menuContainerRef} />\n <SocialMediaMenu editor={editor} appendTo={menuContainerRef} />\n <InsideLinksMenu editor={editor} appendTo={menuContainerRef} />\n <ColumnsMenu editor={editor} appendTo={menuContainerRef} />\n <TableRowMenu editor={editor} appendTo={menuContainerRef} />\n <TableColumnMenu editor={editor} appendTo={menuContainerRef} />\n <ImageBlockMenu editor={editor} appendTo={menuContainerRef} />\n </div>\n </div>\n </EditorContext.Provider>\n );\n};\n\nexport default BlockEditor;\n"],"names":["EditorContent","useEffect","useMemo","useRef","useLocale","useTranslation","EditorContext","IframeMenu","ImageBlockMenu","InsideLinksMenu","ColumnsMenu","SocialMediaMenu","TableColumnMenu","TableRowMenu","useBlockEditor","Sidebar","ContentItemMenu","TextMenu","LinkMenu","BlockEditor","handleChange","content","handleChangeMarkdown","menuContainerRef","editorRef","editor","users","characterCount","leftSidebar","code","displayedUsers","slice","providerValue","commands","setTextDirection","setContent","i18n","contentEn","contentAr","contentFa","Provider","value","div","lang","language","className","ref","isOpen","onClose","close","style","outline","appendTo"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;AACA,SAASA,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAEnD,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,cAAc,QAAQ,uCAAuC;AACtE,SAASC,aAAa,QAAQ,iCAAiC;AAC/D,SAASC,UAAU,QAAQ,yCAAyC;AACpE,OAAOC,oBAAoB,2DAA2D;AACtF,SAASC,eAAe,QAAQ,8CAA8C;AAC9E,SAASC,WAAW,QAAQ,oDAAoD;AAChF,SAASC,eAAe,QAAQ,8CAA8C;AAC9E,SACEC,eAAe,EACfC,YAAY,QACP,wCAAwC;AAC/C,SAASC,cAAc,QAAQ,gCAAgC;AAC/D,SAASC,OAAO,QAAQ,wBAAwB;AAChD,SAASC,eAAe,QAAQ,8CAA8C;AAC9E,SAASC,QAAQ,QAAQ,gC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ACP;4BAASO,QAAQA;4BAAQ2B,UAAU7B;;sCAEpC,KAACN;4BAASQ,QAAQA;;sCAClB,KAAClB;4BAAWkB,QAAQA;4BAAQ2B,UAAU7B;;sCACtC,KAACZ;4BAAgBc,QAAQA;4BAAQ2B,UAAU7B;;sCAC3C,KAACd;4BAAgBgB,QAAQA;4BAAQ2B,UAAU7B;;sCAC3C,KAACb;4BAAYe,QAAQA;4BAAQ2B,UAAU7B;;sCACvC,KAACV;4BAAaY,QAAQA;4BAAQ2B,UAAU7B;;sCACxC,KAACX;4BAAgBa,QAAQA;4BAAQ2B,UAAU7B;;sCAC3C,KAACf;4BAAeiB,QAAQA;4BAAQ2B,UAAU7B;;;;;;;AAKpD,EAAE;AAEF,eAAeJ,YAAY"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface TiptapProps {
|
|
2
2
|
hasCollab: boolean;
|
|
3
3
|
handleChange: (value: any) => void;
|
|
4
|
+
handleChangeMarkdown?: (value: any) => void;
|
|
4
5
|
content: {
|
|
5
6
|
html: string;
|
|
6
7
|
json: any;
|
|
@@ -17,8 +18,8 @@ export type EditorUser = {
|
|
|
17
18
|
color: string;
|
|
18
19
|
initials?: string;
|
|
19
20
|
};
|
|
20
|
-
export type AiTone =
|
|
21
|
-
export type AiPromptType =
|
|
21
|
+
export type AiTone = "academic" | "business" | "casual" | "childfriendly" | "conversational" | "emotional" | "humorous" | "informative" | "inspirational" | string;
|
|
22
|
+
export type AiPromptType = "SHORTEN" | "EXTEND" | "SIMPLIFY" | "TONE";
|
|
22
23
|
export type AiToneOption = {
|
|
23
24
|
name: string;
|
|
24
25
|
label: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/types.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/types.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC;CACtC;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,MAAM,GACd,UAAU,GACV,UAAU,GACV,QAAQ,GACR,eAAe,GACf,gBAAgB,GAChB,WAAW,GACX,UAAU,GACV,aAAa,GACb,eAAe,GACf,MAAM,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/types.tsx"],"sourcesContent":["export interface TiptapProps {\n hasCollab: boolean
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/fields/TiptapEditor/features/BlockEditor/types.tsx"],"sourcesContent":["export interface TiptapProps {\n hasCollab: boolean;\n handleChange: (value: any) => void;\n handleChangeMarkdown?: (value: any) => void;\n content: { html: string; json: any };\n}\n\nexport type LanguageOption = {\n name: string;\n label: string;\n value: any;\n};\nexport type EditorUser = {\n clientId: string;\n name: string;\n color: string;\n initials?: string;\n};\n\nexport type AiTone =\n | \"academic\"\n | \"business\"\n | \"casual\"\n | \"childfriendly\"\n | \"conversational\"\n | \"emotional\"\n | \"humorous\"\n | \"informative\"\n | \"inspirational\"\n | string;\n\nexport type AiPromptType = \"SHORTEN\" | \"EXTEND\" | \"SIMPLIFY\" | \"TONE\";\n\nexport type AiToneOption = {\n name: string;\n label: string;\n value: AiTone;\n};\n\nexport type AiImageStyle = {\n name: string;\n label: string;\n value: string;\n};\n"],"names":[],"rangeMappings":"","mappings":"AAuCA,WAIE"}
|
|
@@ -4,12 +4,13 @@ declare global {
|
|
|
4
4
|
editor: Editor | null;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
export declare const useBlockEditor: ({ content, handleChange, }: {
|
|
7
|
+
export declare const useBlockEditor: ({ content, handleChange, handleChangeMarkdown, }: {
|
|
8
8
|
content: {
|
|
9
9
|
html: string;
|
|
10
10
|
json: any;
|
|
11
11
|
};
|
|
12
12
|
handleChange: (data: any) => void;
|
|
13
|
+
handleChangeMarkdown: (data: any) => void;
|
|
13
14
|
}) => {
|
|
14
15
|
editor: Editor;
|
|
15
16
|
users: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockEditor.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/hooks/useBlockEditor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AASlD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB;CACF;AAED,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"useBlockEditor.d.ts","sourceRoot":"","sources":["../../../../../src/fields/TiptapEditor/hooks/useBlockEditor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAa,MAAM,eAAe,CAAC;AASlD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB;CACF;AAED,eAAO,MAAM,cAAc,qDAIxB;IACD,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC;IACrC,YAAY,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,oBAAoB,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CAC3C;;;;;CAqFA,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { useSidebar } from "./useSidebar.js";
|
|
|
6
6
|
import TurndownService from "turndown";
|
|
7
7
|
import { gfm } from "turndown-plugin-gfm";
|
|
8
8
|
import { useTranslation } from "@payloadcms/ui/providers/Translation";
|
|
9
|
-
export const useBlockEditor = ({ content, handleChange })=>{
|
|
9
|
+
export const useBlockEditor = ({ content, handleChange, handleChangeMarkdown })=>{
|
|
10
10
|
const leftSidebar = useSidebar();
|
|
11
11
|
const turndownService = new TurndownService({});
|
|
12
12
|
// Use the gfm plugin
|
|
@@ -43,6 +43,7 @@ export const useBlockEditor = ({ content, handleChange })=>{
|
|
|
43
43
|
},
|
|
44
44
|
onUpdate: ({ editor })=>{
|
|
45
45
|
handleChange(editor?.getJSON() ?? {});
|
|
46
|
+
handleChangeMarkdown(editor?.storage?.markdown?.getMarkdown() ?? "");
|
|
46
47
|
}
|
|
47
48
|
}, []);
|
|
48
49
|
const users = useMemo(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/fields/TiptapEditor/hooks/useBlockEditor.ts"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\n\nimport { Editor, useEditor } from \"@tiptap/react\";\n\nimport ExtensionKit from \"../extensions/extension-kit.js\";\nimport { EditorUser } from \"../features/BlockEditor/types.js\";\nimport { useSidebar } from \"./useSidebar.js\";\n\nimport TurndownService from \"turndown\";\nimport { gfm } from \"turndown-plugin-gfm\";\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\ndeclare global {\n interface Window {\n editor: Editor | null;\n }\n}\n\nexport const useBlockEditor = ({\n content,\n handleChange,\n}: {\n content: { html: string; json: any };\n handleChange: (data: any) => void;\n}) => {\n const leftSidebar = useSidebar();\n\n const turndownService = new TurndownService({});\n // Use the gfm plugin\n turndownService.use(gfm);\n turndownService.addRule(\"twitter\", {\n filter: \"div\",\n replacement: function (content) {\n return \"\\n\\n\" + content + \"\\n\\n\";\n },\n });\n const { t, i18n } = useTranslation();\n\n const editor = useEditor(\n {\n content: content?.json ?? content ?? {},\n autofocus: true,\n onCreate: ({ editor }) => {\n // provider?.on('synced', () => {\n // if (editor.isEmpty) {\n // editor.commands.setContent(initialContent)\n // }\n // })\n },\n extensions: [\n ...ExtensionKit({\n // provider,\n }),\n // Collaboration.configure({\n // document: ydoc,\n // }),\n // CollaborationCursor.configure({\n // provider,\n // user: {\n // name: randomElement(userNames),\n // color: randomElement(userColors),\n // },\n // }),\n ],\n editorProps: {\n attributes: {\n languages: i18n.language,\n autocomplete: \"off\",\n autocorrect: \"off\",\n autocapitalize: \"off\",\n class: \"min-h-full\",\n },\n },\n onUpdate: ({ editor }) => {\n handleChange(editor?.getJSON() ?? {});\n },\n },\n []\n );\n const users = useMemo(() => {\n if (!editor?.storage.collaborationCursor?.users) {\n return [];\n }\n\n return editor.storage.collaborationCursor?.users.map((user: EditorUser) => {\n const names = user.name?.split(\" \");\n const firstName = names?.[0];\n const lastName = names?.[names.length - 1];\n const initials = `${firstName?.[0] || \"?\"}${lastName?.[0] || \"?\"}`;\n\n return { ...user, initials: initials.length ? initials : \"?\" };\n });\n }, [editor?.storage.collaborationCursor?.users]);\n\n const characterCount = editor?.storage.characterCount || {\n characters: () => 0,\n words: () => 0,\n };\n\n // useEffect(() => {\n // provider?.on('status', (event: { status: WebSocketStatus }) => {\n // setCollabState(event.status)\n // })\n // }, [provider])\n\n if (window) window.editor = editor;\n\n return { editor, users, characterCount, leftSidebar };\n};\n"],"names":["useMemo","useEditor","ExtensionKit","useSidebar","TurndownService","gfm","useTranslation","useBlockEditor","content","handleChange","leftSidebar","turndownService","use","addRule","filter","replacement","t","i18n","editor","json","autofocus","onCreate","extensions","editorProps","attributes","languages","language","autocomplete","autocorrect","autocapitalize","class","onUpdate","getJSON","
|
|
1
|
+
{"version":3,"sources":["../../../../../src/fields/TiptapEditor/hooks/useBlockEditor.ts"],"sourcesContent":["\"use client\";\nimport { useMemo } from \"react\";\n\nimport { Editor, useEditor } from \"@tiptap/react\";\n\nimport ExtensionKit from \"../extensions/extension-kit.js\";\nimport { EditorUser } from \"../features/BlockEditor/types.js\";\nimport { useSidebar } from \"./useSidebar.js\";\n\nimport TurndownService from \"turndown\";\nimport { gfm } from \"turndown-plugin-gfm\";\nimport { useTranslation } from \"@payloadcms/ui/providers/Translation\";\ndeclare global {\n interface Window {\n editor: Editor | null;\n }\n}\n\nexport const useBlockEditor = ({\n content,\n handleChange,\n handleChangeMarkdown,\n}: {\n content: { html: string; json: any };\n handleChange: (data: any) => void;\n handleChangeMarkdown: (data: any) => void;\n}) => {\n const leftSidebar = useSidebar();\n\n const turndownService = new TurndownService({});\n // Use the gfm plugin\n turndownService.use(gfm);\n turndownService.addRule(\"twitter\", {\n filter: \"div\",\n replacement: function (content) {\n return \"\\n\\n\" + content + \"\\n\\n\";\n },\n });\n const { t, i18n } = useTranslation();\n\n const editor = useEditor(\n {\n content: content?.json ?? content ?? {},\n autofocus: true,\n onCreate: ({ editor }) => {\n // provider?.on('synced', () => {\n // if (editor.isEmpty) {\n // editor.commands.setContent(initialContent)\n // }\n // })\n },\n extensions: [\n ...ExtensionKit({\n // provider,\n }),\n // Collaboration.configure({\n // document: ydoc,\n // }),\n // CollaborationCursor.configure({\n // provider,\n // user: {\n // name: randomElement(userNames),\n // color: randomElement(userColors),\n // },\n // }),\n ],\n editorProps: {\n attributes: {\n languages: i18n.language,\n autocomplete: \"off\",\n autocorrect: \"off\",\n autocapitalize: \"off\",\n class: \"min-h-full\",\n },\n },\n onUpdate: ({ editor }) => {\n handleChange(editor?.getJSON() ?? {});\n handleChangeMarkdown(editor?.storage?.markdown?.getMarkdown() ?? \"\");\n },\n },\n []\n );\n const users = useMemo(() => {\n if (!editor?.storage.collaborationCursor?.users) {\n return [];\n }\n\n return editor.storage.collaborationCursor?.users.map((user: EditorUser) => {\n const names = user.name?.split(\" \");\n const firstName = names?.[0];\n const lastName = names?.[names.length - 1];\n const initials = `${firstName?.[0] || \"?\"}${lastName?.[0] || \"?\"}`;\n\n return { ...user, initials: initials.length ? initials : \"?\" };\n });\n }, [editor?.storage.collaborationCursor?.users]);\n\n const characterCount = editor?.storage.characterCount || {\n characters: () => 0,\n words: () => 0,\n };\n\n // useEffect(() => {\n // provider?.on('status', (event: { status: WebSocketStatus }) => {\n // setCollabState(event.status)\n // })\n // }, [provider])\n\n if (window) window.editor = editor;\n\n return { editor, users, characterCount, leftSidebar };\n};\n"],"names":["useMemo","useEditor","ExtensionKit","useSidebar","TurndownService","gfm","useTranslation","useBlockEditor","content","handleChange","handleChangeMarkdown","leftSidebar","turndownService","use","addRule","filter","replacement","t","i18n","editor","json","autofocus","onCreate","extensions","editorProps","attributes","languages","language","autocomplete","autocorrect","autocapitalize","class","onUpdate","getJSON","storage","markdown","getMarkdown","users","collaborationCursor","map","user","names","name","split","firstName","lastName","length","initials","characterCount","characters","words","window"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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