|
1 | 1 | import { BlockNoteEditor, BlockNoteEditorOptions } from "@blocknote/core"; |
2 | 2 | import { DependencyList, FC, useEffect, useState } from "react"; |
| 3 | +import { getBlockNoteTheme } from "../BlockNoteTheme"; |
3 | 4 | import { createReactBlockSideMenuFactory } from "../BlockSideMenu/BlockSideMenuFactory"; |
| 5 | +import { DragHandleMenuProps } from "../BlockSideMenu/components/DragHandleMenu"; |
4 | 6 | import { createReactFormattingToolbarFactory } from "../FormattingToolbar/FormattingToolbarFactory"; |
5 | 7 | import { createReactHyperlinkToolbarFactory } from "../HyperlinkToolbar/HyperlinkToolbarFactory"; |
6 | | -import { createReactSlashMenuFactory } from "../SlashMenu/SlashMenuFactory"; |
7 | 8 | import { defaultReactSlashMenuItems } from "../SlashMenu/defaultReactSlashMenuItems"; |
8 | | -import { getBlockNoteTheme } from "../BlockNoteTheme"; |
9 | | -import { DragHandleMenuProps } from "../BlockSideMenu/components/DragHandleMenu"; |
| 9 | +import { createReactSlashMenuFactory } from "../SlashMenu/SlashMenuFactory"; |
10 | 10 |
|
11 | 11 | //based on https://github.com/ueberdosis/tiptap/blob/main/packages/react/src/useEditor.ts |
12 | 12 |
|
@@ -45,38 +45,33 @@ export const useBlockNote = ( |
45 | 45 | ...options, |
46 | 46 | }; |
47 | 47 |
|
48 | | - let uiFactories: any; |
49 | | - |
50 | 48 | if (newOptions.customElements && newOptions.uiFactories) { |
51 | 49 | console.warn( |
52 | 50 | "BlockNote editor initialized with both `customElements` and `uiFactories` options, prioritizing `uiFactories`." |
53 | 51 | ); |
54 | 52 | } |
55 | 53 |
|
56 | | - if (newOptions.uiFactories) { |
57 | | - uiFactories = newOptions.uiFactories; |
58 | | - } else { |
59 | | - uiFactories = { |
60 | | - formattingToolbarFactory: createReactFormattingToolbarFactory( |
61 | | - getBlockNoteTheme(newOptions.theme === "dark"), |
62 | | - newOptions.customElements?.formattingToolbar |
63 | | - ), |
64 | | - hyperlinkToolbarFactory: createReactHyperlinkToolbarFactory( |
65 | | - getBlockNoteTheme(newOptions.theme === "dark") |
66 | | - ), |
67 | | - slashMenuFactory: createReactSlashMenuFactory( |
68 | | - getBlockNoteTheme(newOptions.theme === "dark") |
69 | | - ), |
70 | | - blockSideMenuFactory: createReactBlockSideMenuFactory( |
71 | | - getBlockNoteTheme(newOptions.theme === "dark"), |
72 | | - newOptions.customElements?.dragHandleMenu |
73 | | - ), |
74 | | - }; |
75 | | - } |
| 54 | + let uiFactories = { |
| 55 | + formattingToolbarFactory: createReactFormattingToolbarFactory( |
| 56 | + getBlockNoteTheme(newOptions.theme === "dark"), |
| 57 | + newOptions.customElements?.formattingToolbar |
| 58 | + ), |
| 59 | + hyperlinkToolbarFactory: createReactHyperlinkToolbarFactory( |
| 60 | + getBlockNoteTheme(newOptions.theme === "dark") |
| 61 | + ), |
| 62 | + slashMenuFactory: createReactSlashMenuFactory( |
| 63 | + getBlockNoteTheme(newOptions.theme === "dark") |
| 64 | + ), |
| 65 | + blockSideMenuFactory: createReactBlockSideMenuFactory( |
| 66 | + getBlockNoteTheme(newOptions.theme === "dark"), |
| 67 | + newOptions.customElements?.dragHandleMenu |
| 68 | + ), |
| 69 | + ...newOptions.uiFactories, |
| 70 | + }; |
76 | 71 |
|
77 | 72 | newOptions = { |
78 | 73 | ...newOptions, |
79 | | - uiFactories: uiFactories, |
| 74 | + uiFactories, |
80 | 75 | }; |
81 | 76 |
|
82 | 77 | console.log("create new blocknote instance"); |
|
0 commit comments