@blocknote/core 0.8.2 → 0.8.3
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/README.md +4 -0
- package/dist/blocknote.js +1777 -1849
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +4 -4
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/BlockNoteEditor.ts +89 -39
- package/src/BlockNoteExtensions.ts +1 -58
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
- package/src/api/formatConversions/formatConversions.test.ts +587 -605
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +15 -15
- package/src/api/nodeConversions/nodeConversions.test.ts +90 -94
- package/src/extensions/Blocks/api/blockTypes.ts +3 -2
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +6 -0
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +101 -114
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +184 -149
- package/src/extensions/Placeholder/PlaceholderExtension.ts +2 -2
- package/src/extensions/{DraggableBlocks/DraggableBlocksPlugin.ts → SideMenu/SideMenuPlugin.ts} +181 -164
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -30
- package/src/extensions/SlashMenu/SlashMenuPlugin.ts +51 -0
- package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +109 -0
- package/src/extensions/UniqueID/UniqueID.ts +29 -30
- package/src/index.ts +9 -8
- package/src/node_modules/.vitest/results.json +1 -0
- package/src/shared/BaseUiElementTypes.ts +8 -0
- package/src/shared/EditorElement.ts +0 -16
- package/src/shared/EventEmitter.ts +58 -0
- package/src/shared/plugins/suggestion/SuggestionItem.ts +3 -6
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +341 -403
- package/types/src/BlockNoteEditor.d.ts +18 -11
- package/types/src/BlockNoteExtensions.d.ts +0 -19
- package/types/src/EventEmitter.d.ts +11 -0
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +3 -2
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +0 -17
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +26 -20
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +18 -24
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +0 -12
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +37 -10
- package/types/src/extensions/SideMenu/MultipleNodeSelection.d.ts +24 -0
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +79 -0
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -18
- package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +13 -0
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +1 -69
- package/types/src/extensions/SlashMenu/index.d.ts +2 -3
- package/types/src/index.d.ts +9 -8
- package/types/src/shared/BaseUiElementTypes.d.ts +7 -0
- package/types/src/shared/EditorElement.d.ts +0 -10
- package/types/src/shared/EventEmitter.d.ts +11 -0
- package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +2 -7
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +12 -43
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +0 -29
- package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +0 -37
- package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +0 -37
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +0 -18
- package/src/extensions/HyperlinkToolbar/HyperlinkMark.ts +0 -28
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +0 -19
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +0 -53
- package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +0 -195
- package/src/extensions/SlashMenu/index.ts +0 -5
- package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +0 -21
- package/types/src/CustomBlock.d.ts +0 -15
- package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableCol.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableContent.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/TableContent/TableRow.d.ts +0 -2
- package/types/src/extensions/Placeholder/localisation/index.d.ts +0 -2
- package/types/src/extensions/Placeholder/localisation/translation.d.ts +0 -51
- /package/src/extensions/{DraggableBlocks → SideMenu}/MultipleNodeSelection.ts +0 -0
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* A generic interface used in all suggestion menus (slash menu, mentions, etc)
|
|
3
|
-
*/
|
|
4
|
-
export declare class SuggestionItem {
|
|
1
|
+
export type SuggestionItem = {
|
|
5
2
|
name: string;
|
|
6
|
-
|
|
7
|
-
constructor(name: string, match: (query: string) => boolean);
|
|
8
|
-
}
|
|
3
|
+
};
|
|
@@ -1,44 +1,10 @@
|
|
|
1
|
-
import { Editor, Range } from "@tiptap/core";
|
|
2
1
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
3
|
-
import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
|
|
4
|
-
import { SuggestionItem } from "./SuggestionItem";
|
|
5
2
|
import { BlockNoteEditor } from "../../../BlockNoteEditor";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Used for ensuring that the plugin key is unique when more than one instance of the SuggestionPlugin is used.
|
|
12
|
-
*/
|
|
13
|
-
pluginKey: PluginKey;
|
|
14
|
-
/**
|
|
15
|
-
* The BlockNote editor.
|
|
16
|
-
*/
|
|
17
|
-
editor: BlockNoteEditor<BSchema>;
|
|
18
|
-
/**
|
|
19
|
-
* The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
|
|
20
|
-
*/
|
|
21
|
-
defaultTriggerCharacter: string;
|
|
22
|
-
suggestionsMenuFactory: SuggestionsMenuFactory<T>;
|
|
23
|
-
/**
|
|
24
|
-
* The callback that gets executed when an item is selected by the user.
|
|
25
|
-
*
|
|
26
|
-
* **NOTE:** The command text is not removed automatically from the editor by this plugin,
|
|
27
|
-
* this should be done manually. The `editor` and `range` properties passed
|
|
28
|
-
* to the callback function might come in handy when doing this.
|
|
29
|
-
*/
|
|
30
|
-
onSelectItem?: (props: {
|
|
31
|
-
item: T;
|
|
32
|
-
editor: BlockNoteEditor<BSchema>;
|
|
33
|
-
}) => void;
|
|
34
|
-
/**
|
|
35
|
-
* A function that should supply the plugin with items to suggest, based on a certain query string.
|
|
36
|
-
*/
|
|
37
|
-
items?: (query: string) => T[];
|
|
38
|
-
allow?: (props: {
|
|
39
|
-
editor: Editor;
|
|
40
|
-
range: Range;
|
|
41
|
-
}) => boolean;
|
|
3
|
+
import { BaseUiElementState } from "../../BaseUiElementTypes";
|
|
4
|
+
import { SuggestionItem } from "./SuggestionItem";
|
|
5
|
+
export type SuggestionsMenuState<T extends SuggestionItem> = BaseUiElementState & {
|
|
6
|
+
filteredItems: T[];
|
|
7
|
+
keyboardHoveredItemIndex: number;
|
|
42
8
|
};
|
|
43
9
|
type SuggestionPluginState<T extends SuggestionItem> = {
|
|
44
10
|
active: boolean;
|
|
@@ -58,9 +24,12 @@ type SuggestionPluginState<T extends SuggestionItem> = {
|
|
|
58
24
|
* - This version supports generic items instead of only strings (to allow for more advanced filtering for example)
|
|
59
25
|
* - This version hides some unnecessary complexity from the user of the plugin.
|
|
60
26
|
* - This version handles key events differently
|
|
61
|
-
*
|
|
62
|
-
* @param options options for configuring the plugin
|
|
63
|
-
* @returns the prosemirror plugin
|
|
64
27
|
*/
|
|
65
|
-
export declare
|
|
28
|
+
export declare const setupSuggestionsMenu: <T extends SuggestionItem, BSchema extends Record<string, import("../../../extensions/Blocks/api/blockTypes").BlockSpec<string, import("../../../extensions/Blocks/api/blockTypes").PropSchema>>>(editor: BlockNoteEditor<BSchema>, updateSuggestionsMenu: (suggestionsMenuState: SuggestionsMenuState<T>) => void, pluginKey: PluginKey, defaultTriggerCharacter: string, items?: (query: string) => T[], onSelectItem?: (props: {
|
|
29
|
+
item: T;
|
|
30
|
+
editor: BlockNoteEditor<BSchema>;
|
|
31
|
+
}) => void) => {
|
|
32
|
+
plugin: Plugin<SuggestionPluginState<T>>;
|
|
33
|
+
itemCallback: (item: T) => void;
|
|
34
|
+
};
|
|
66
35
|
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
|
-
import { Block, BlockSchema } from "../Blocks/api/blockTypes";
|
|
4
|
-
|
|
5
|
-
export type BlockSideMenuStaticParams<BSchema extends BlockSchema> = {
|
|
6
|
-
editor: BlockNoteEditor<BSchema>;
|
|
7
|
-
|
|
8
|
-
addBlock: () => void;
|
|
9
|
-
|
|
10
|
-
blockDragStart: (event: DragEvent) => void;
|
|
11
|
-
blockDragEnd: () => void;
|
|
12
|
-
|
|
13
|
-
freezeMenu: () => void;
|
|
14
|
-
unfreezeMenu: () => void;
|
|
15
|
-
|
|
16
|
-
getReferenceRect: () => DOMRect;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type BlockSideMenuDynamicParams<BSchema extends BlockSchema> = {
|
|
20
|
-
block: Block<BSchema>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type BlockSideMenu<BSchema extends BlockSchema> = EditorElement<
|
|
24
|
-
BlockSideMenuDynamicParams<BSchema>
|
|
25
|
-
>;
|
|
26
|
-
export type BlockSideMenuFactory<BSchema extends BlockSchema> = ElementFactory<
|
|
27
|
-
BlockSideMenuStaticParams<BSchema>,
|
|
28
|
-
BlockSideMenuDynamicParams<BSchema>
|
|
29
|
-
>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Editor, Extension } from "@tiptap/core";
|
|
2
|
-
import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
|
|
3
|
-
import { createDraggableBlocksPlugin } from "./DraggableBlocksPlugin";
|
|
4
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
5
|
-
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
6
|
-
|
|
7
|
-
export type DraggableBlocksOptions<BSchema extends BlockSchema> = {
|
|
8
|
-
tiptapEditor: Editor;
|
|
9
|
-
editor: BlockNoteEditor<BSchema>;
|
|
10
|
-
blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This extension adds a menu to the side of blocks which features various BlockNote functions such as adding and
|
|
15
|
-
* removing blocks. More importantly, it adds a drag handle which allows the user to drag and drop blocks.
|
|
16
|
-
*
|
|
17
|
-
* code based on https://github.com/ueberdosis/tiptap/issues/323#issuecomment-506637799
|
|
18
|
-
*/
|
|
19
|
-
export const createDraggableBlocksExtension = <BSchema extends BlockSchema>() =>
|
|
20
|
-
Extension.create<DraggableBlocksOptions<BSchema>>({
|
|
21
|
-
name: "DraggableBlocksExtension",
|
|
22
|
-
priority: 1000, // Need to be high, in order to hide menu when typing slash
|
|
23
|
-
addProseMirrorPlugins() {
|
|
24
|
-
if (!this.options.blockSideMenuFactory) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
"UI Element factory not defined for DraggableBlocksExtension"
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return [
|
|
30
|
-
createDraggableBlocksPlugin({
|
|
31
|
-
tiptapEditor: this.editor,
|
|
32
|
-
editor: this.options.editor,
|
|
33
|
-
blockSideMenuFactory: this.options.blockSideMenuFactory,
|
|
34
|
-
}),
|
|
35
|
-
];
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { PluginKey } from "prosemirror-state";
|
|
3
|
-
import { BlockNoteEditor, BlockSchema } from "../..";
|
|
4
|
-
import { FormattingToolbarFactory } from "./FormattingToolbarFactoryTypes";
|
|
5
|
-
import { createFormattingToolbarPlugin } from "./FormattingToolbarPlugin";
|
|
6
|
-
|
|
7
|
-
export type FormattingToolbarOptions<BSchema extends BlockSchema> = {
|
|
8
|
-
formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
|
|
9
|
-
editor: BlockNoteEditor<BSchema>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The menu that is displayed when selecting a piece of text.
|
|
14
|
-
*/
|
|
15
|
-
export const createFormattingToolbarExtension = <
|
|
16
|
-
BSchema extends BlockSchema
|
|
17
|
-
>() =>
|
|
18
|
-
Extension.create<FormattingToolbarOptions<BSchema>>({
|
|
19
|
-
name: "FormattingToolbarExtension",
|
|
20
|
-
|
|
21
|
-
addProseMirrorPlugins() {
|
|
22
|
-
if (!this.options.formattingToolbarFactory || !this.options.editor) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"required args not defined for FormattingToolbarExtension"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return [
|
|
29
|
-
createFormattingToolbarPlugin({
|
|
30
|
-
tiptapEditor: this.editor,
|
|
31
|
-
editor: this.options.editor,
|
|
32
|
-
formattingToolbarFactory: this.options.formattingToolbarFactory,
|
|
33
|
-
pluginKey: new PluginKey("FormattingToolbarPlugin"),
|
|
34
|
-
}),
|
|
35
|
-
];
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
|
-
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
4
|
-
|
|
5
|
-
export type FormattingToolbarStaticParams<BSchema extends BlockSchema> = {
|
|
6
|
-
editor: BlockNoteEditor<BSchema>;
|
|
7
|
-
|
|
8
|
-
getReferenceRect: () => DOMRect;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type FormattingToolbarDynamicParams = {};
|
|
12
|
-
|
|
13
|
-
export type FormattingToolbar = EditorElement<FormattingToolbarDynamicParams>;
|
|
14
|
-
export type FormattingToolbarFactory<BSchema extends BlockSchema> =
|
|
15
|
-
ElementFactory<
|
|
16
|
-
FormattingToolbarStaticParams<BSchema>,
|
|
17
|
-
FormattingToolbarDynamicParams
|
|
18
|
-
>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Link } from "@tiptap/extension-link";
|
|
2
|
-
import {
|
|
3
|
-
createHyperlinkToolbarPlugin,
|
|
4
|
-
HyperlinkToolbarPluginProps,
|
|
5
|
-
} from "./HyperlinkToolbarPlugin";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This custom link includes a special menu for editing/deleting/opening the link.
|
|
9
|
-
* The menu will be triggered by hovering over the link with the mouse,
|
|
10
|
-
* or by moving the cursor inside the link text
|
|
11
|
-
*/
|
|
12
|
-
const Hyperlink = Link.extend<HyperlinkToolbarPluginProps>({
|
|
13
|
-
priority: 500,
|
|
14
|
-
addProseMirrorPlugins() {
|
|
15
|
-
if (!this.options.hyperlinkToolbarFactory) {
|
|
16
|
-
throw new Error("UI Element factory not defined for HyperlinkMark");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return [
|
|
20
|
-
...(this.parent?.() || []),
|
|
21
|
-
createHyperlinkToolbarPlugin(this.editor, {
|
|
22
|
-
hyperlinkToolbarFactory: this.options.hyperlinkToolbarFactory,
|
|
23
|
-
}),
|
|
24
|
-
];
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export default Hyperlink;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
|
|
3
|
-
export type HyperlinkToolbarStaticParams = {
|
|
4
|
-
editHyperlink: (url: string, text: string) => void;
|
|
5
|
-
deleteHyperlink: () => void;
|
|
6
|
-
|
|
7
|
-
getReferenceRect: () => DOMRect;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type HyperlinkToolbarDynamicParams = {
|
|
11
|
-
url: string;
|
|
12
|
-
text: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type HyperlinkToolbar = EditorElement<HyperlinkToolbarDynamicParams>;
|
|
16
|
-
export type HyperlinkToolbarFactory = ElementFactory<
|
|
17
|
-
HyperlinkToolbarStaticParams,
|
|
18
|
-
HyperlinkToolbarDynamicParams
|
|
19
|
-
>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { PluginKey } from "prosemirror-state";
|
|
3
|
-
import { createSuggestionPlugin } from "../../shared/plugins/suggestion/SuggestionPlugin";
|
|
4
|
-
import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
5
|
-
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
6
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
7
|
-
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
8
|
-
|
|
9
|
-
export type SlashMenuOptions<BSchema extends BlockSchema> = {
|
|
10
|
-
editor: BlockNoteEditor<BSchema> | undefined;
|
|
11
|
-
commands: BaseSlashMenuItem<BSchema>[] | undefined;
|
|
12
|
-
slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const SlashMenuPluginKey = new PluginKey("suggestions-slash-commands");
|
|
16
|
-
|
|
17
|
-
export const createSlashMenuExtension = <BSchema extends BlockSchema>() =>
|
|
18
|
-
Extension.create<SlashMenuOptions<BSchema>>({
|
|
19
|
-
name: "slash-command",
|
|
20
|
-
|
|
21
|
-
addOptions() {
|
|
22
|
-
return {
|
|
23
|
-
editor: undefined,
|
|
24
|
-
commands: undefined,
|
|
25
|
-
slashMenuFactory: undefined,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
addProseMirrorPlugins() {
|
|
30
|
-
if (!this.options.slashMenuFactory || !this.options.commands) {
|
|
31
|
-
throw new Error("required args not defined for SlashMenuExtension");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const commands = this.options.commands;
|
|
35
|
-
|
|
36
|
-
return [
|
|
37
|
-
createSuggestionPlugin<BaseSlashMenuItem<BSchema>, BSchema>({
|
|
38
|
-
pluginKey: SlashMenuPluginKey,
|
|
39
|
-
editor: this.options.editor!,
|
|
40
|
-
defaultTriggerCharacter: "/",
|
|
41
|
-
suggestionsMenuFactory: this.options.slashMenuFactory!,
|
|
42
|
-
items: (query) => {
|
|
43
|
-
return commands.filter((cmd: BaseSlashMenuItem<BSchema>) =>
|
|
44
|
-
cmd.match(query)
|
|
45
|
-
);
|
|
46
|
-
},
|
|
47
|
-
onSelectItem: ({ item, editor }) => {
|
|
48
|
-
item.execute(editor);
|
|
49
|
-
},
|
|
50
|
-
}),
|
|
51
|
-
];
|
|
52
|
-
},
|
|
53
|
-
});
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
2
|
-
import { PartialBlock } from "../Blocks/api/blockTypes";
|
|
3
|
-
import { DefaultBlockSchema } from "../Blocks/api/defaultBlocks";
|
|
4
|
-
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
5
|
-
|
|
6
|
-
function insertOrUpdateBlock<BSchema extends DefaultBlockSchema>(
|
|
7
|
-
editor: BlockNoteEditor<BSchema>,
|
|
8
|
-
block: PartialBlock<BSchema>
|
|
9
|
-
) {
|
|
10
|
-
const currentBlock = editor.getTextCursorPosition().block;
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
(currentBlock.content.length === 1 &&
|
|
14
|
-
currentBlock.content[0].type === "text" &&
|
|
15
|
-
currentBlock.content[0].text === "/") ||
|
|
16
|
-
currentBlock.content.length === 0
|
|
17
|
-
) {
|
|
18
|
-
editor.updateBlock(currentBlock, block);
|
|
19
|
-
} else {
|
|
20
|
-
editor.insertBlocks([block], currentBlock, "after");
|
|
21
|
-
editor.setTextCursorPosition(editor.getTextCursorPosition().nextBlock!);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* An array containing commands for creating all default blocks.
|
|
27
|
-
*/
|
|
28
|
-
export const defaultSlashMenuItems = [
|
|
29
|
-
// Command for creating a level 1 heading
|
|
30
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
31
|
-
"Heading",
|
|
32
|
-
(editor) =>
|
|
33
|
-
insertOrUpdateBlock(editor, {
|
|
34
|
-
type: "heading",
|
|
35
|
-
props: { level: "1" },
|
|
36
|
-
}),
|
|
37
|
-
["h", "heading1", "h1"]
|
|
38
|
-
),
|
|
39
|
-
|
|
40
|
-
// Command for creating a level 2 heading
|
|
41
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
42
|
-
"Heading 2",
|
|
43
|
-
(editor) =>
|
|
44
|
-
insertOrUpdateBlock(editor, {
|
|
45
|
-
type: "heading",
|
|
46
|
-
props: { level: "2" },
|
|
47
|
-
}),
|
|
48
|
-
["h2", "heading2", "subheading"]
|
|
49
|
-
),
|
|
50
|
-
|
|
51
|
-
// Command for creating a level 3 heading
|
|
52
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
53
|
-
"Heading 3",
|
|
54
|
-
(editor) =>
|
|
55
|
-
insertOrUpdateBlock(editor, {
|
|
56
|
-
type: "heading",
|
|
57
|
-
props: { level: "3" },
|
|
58
|
-
}),
|
|
59
|
-
["h3", "heading3", "subheading"]
|
|
60
|
-
),
|
|
61
|
-
|
|
62
|
-
// Command for creating an ordered list
|
|
63
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
64
|
-
"Numbered List",
|
|
65
|
-
(editor) =>
|
|
66
|
-
insertOrUpdateBlock(editor, {
|
|
67
|
-
type: "numberedListItem",
|
|
68
|
-
}),
|
|
69
|
-
["li", "list", "numberedlist", "numbered list"]
|
|
70
|
-
),
|
|
71
|
-
|
|
72
|
-
// Command for creating a bullet list
|
|
73
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
74
|
-
"Bullet List",
|
|
75
|
-
(editor) =>
|
|
76
|
-
insertOrUpdateBlock(editor, {
|
|
77
|
-
type: "bulletListItem",
|
|
78
|
-
}),
|
|
79
|
-
["ul", "list", "bulletlist", "bullet list"]
|
|
80
|
-
),
|
|
81
|
-
|
|
82
|
-
// Command for creating a paragraph (pretty useless)
|
|
83
|
-
new BaseSlashMenuItem<DefaultBlockSchema>(
|
|
84
|
-
"Paragraph",
|
|
85
|
-
(editor) =>
|
|
86
|
-
insertOrUpdateBlock(editor, {
|
|
87
|
-
type: "paragraph",
|
|
88
|
-
}),
|
|
89
|
-
["p"]
|
|
90
|
-
),
|
|
91
|
-
|
|
92
|
-
// replaceRangeWithNode(editor, range, node);
|
|
93
|
-
|
|
94
|
-
// return true;
|
|
95
|
-
// },
|
|
96
|
-
// ["ol", "orderedlist"],
|
|
97
|
-
// OrderedListIcon,
|
|
98
|
-
// "Used to display an ordered (enumerated) list item"
|
|
99
|
-
// ),
|
|
100
|
-
|
|
101
|
-
// Command for creating a blockquote
|
|
102
|
-
// blockquote: new SlashCommand(
|
|
103
|
-
// "Block Quote",
|
|
104
|
-
// CommandGroup.BASIC_BLOCKS,
|
|
105
|
-
// (editor, range) => {
|
|
106
|
-
// const paragraph = editor.schema.node("paragraph");
|
|
107
|
-
// const node = editor.schema.node(
|
|
108
|
-
// "blockquote",
|
|
109
|
-
// { "block-id": uniqueId.generate() },
|
|
110
|
-
// paragraph
|
|
111
|
-
// );
|
|
112
|
-
|
|
113
|
-
// replaceRangeWithNode(editor, range, node);
|
|
114
|
-
|
|
115
|
-
// return true;
|
|
116
|
-
// },
|
|
117
|
-
// ["quote", "blockquote"],
|
|
118
|
-
// QuoteIcon,
|
|
119
|
-
// "Used to make a quote stand out",
|
|
120
|
-
// "Ctrl+Shift+B"
|
|
121
|
-
// ),
|
|
122
|
-
|
|
123
|
-
// Command for creating a horizontal rule
|
|
124
|
-
// horizontalRule: new SlashCommand(
|
|
125
|
-
// "Horizontal Rule",
|
|
126
|
-
// CommandGroup.BASIC_BLOCKS,
|
|
127
|
-
// (editor, range) => {
|
|
128
|
-
// const node = editor.schema.node("horizontalRule", {
|
|
129
|
-
// "block-id": uniqueId.generate(),
|
|
130
|
-
// });
|
|
131
|
-
|
|
132
|
-
// // insert horizontal rule, create a new block after the horizontal rule if applicable
|
|
133
|
-
// // and put the cursor in the block after the horizontal rule.
|
|
134
|
-
// editor
|
|
135
|
-
// .chain()
|
|
136
|
-
// .focus()
|
|
137
|
-
// .replaceRangeAndUpdateSelection(range, node)
|
|
138
|
-
// .command(({ tr, dispatch }) => {
|
|
139
|
-
// if (dispatch) {
|
|
140
|
-
// // the node immediately after the cursor
|
|
141
|
-
// const nodeAfter = tr.selection.$to.nodeAfter;
|
|
142
|
-
|
|
143
|
-
// // the position of the cursor
|
|
144
|
-
// const cursorPos = tr.selection.$to.pos;
|
|
145
|
-
|
|
146
|
-
// // check if there is no node after the cursor (end of document)
|
|
147
|
-
// if (!nodeAfter) {
|
|
148
|
-
// // create a new block of the default type (probably paragraph) after the cursor
|
|
149
|
-
// const { parent } = tr.selection.$to;
|
|
150
|
-
// const node = parent.type.contentMatch.defaultType?.create();
|
|
151
|
-
|
|
152
|
-
// if (node) {
|
|
153
|
-
// tr.insert(cursorPos, node);
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
|
-
// // try to put the cursor at the start of the node directly after the inserted horizontal rule
|
|
158
|
-
// tr.doc.nodesBetween(cursorPos, cursorPos + 1, (node, pos) => {
|
|
159
|
-
// if (node.type.name !== "horizontalRule") {
|
|
160
|
-
// tr.setSelection(TextSelection.create(tr.doc, pos));
|
|
161
|
-
// }
|
|
162
|
-
// });
|
|
163
|
-
// }
|
|
164
|
-
|
|
165
|
-
// return true;
|
|
166
|
-
// })
|
|
167
|
-
// .scrollIntoView()
|
|
168
|
-
// .run();
|
|
169
|
-
// return true;
|
|
170
|
-
// },
|
|
171
|
-
// ["hr", "horizontalrule"],
|
|
172
|
-
// SeparatorIcon,
|
|
173
|
-
// "Used to separate sections with a horizontal line"
|
|
174
|
-
// ),
|
|
175
|
-
|
|
176
|
-
// Command for creating a table
|
|
177
|
-
// table: new SlashCommand(
|
|
178
|
-
// "Table",
|
|
179
|
-
// CommandGroup.BASIC_BLOCKS,
|
|
180
|
-
// (editor, range) => {
|
|
181
|
-
// editor.chain().focus().deleteRange(range).run();
|
|
182
|
-
// // TODO: add blockid, pending https://github.com/ueberdosis/tiptap/pull/1469
|
|
183
|
-
// editor
|
|
184
|
-
// .chain()
|
|
185
|
-
// .focus()
|
|
186
|
-
// .insertTable({ rows: 1, cols: 2, withHeaderRow: false })
|
|
187
|
-
// .scrollIntoView()
|
|
188
|
-
// .run();
|
|
189
|
-
// return true;
|
|
190
|
-
// },
|
|
191
|
-
// ["table", "database"],
|
|
192
|
-
// TableIcon,
|
|
193
|
-
// "Used to create a simple table"
|
|
194
|
-
// ),
|
|
195
|
-
];
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { defaultSlashMenuItems } from "./defaultSlashMenuItems";
|
|
2
|
-
import { createSlashMenuExtension } from "./SlashMenuExtension";
|
|
3
|
-
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
4
|
-
|
|
5
|
-
export { defaultSlashMenuItems, BaseSlashMenuItem, createSlashMenuExtension };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../EditorElement";
|
|
2
|
-
import { SuggestionItem } from "./SuggestionItem";
|
|
3
|
-
|
|
4
|
-
export type SuggestionsMenuStaticParams<T extends SuggestionItem> = {
|
|
5
|
-
itemCallback: (item: T) => void;
|
|
6
|
-
|
|
7
|
-
getReferenceRect: () => DOMRect;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type SuggestionsMenuDynamicParams<T extends SuggestionItem> = {
|
|
11
|
-
items: T[];
|
|
12
|
-
keyboardHoveredItemIndex: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type SuggestionsMenu<T extends SuggestionItem> = EditorElement<
|
|
16
|
-
SuggestionsMenuDynamicParams<T>
|
|
17
|
-
>;
|
|
18
|
-
export type SuggestionsMenuFactory<T extends SuggestionItem> = ElementFactory<
|
|
19
|
-
SuggestionsMenuStaticParams<T>,
|
|
20
|
-
SuggestionsMenuDynamicParams<T>
|
|
21
|
-
>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Node } from "@tiptap/core";
|
|
2
|
-
import { NodeViewRendererProps } from "@tiptap/core";
|
|
3
|
-
export type CustomBlock = {
|
|
4
|
-
name: string;
|
|
5
|
-
priority?: number;
|
|
6
|
-
atom?: boolean;
|
|
7
|
-
selectable?: boolean;
|
|
8
|
-
className?: string;
|
|
9
|
-
props?: Record<string, string>;
|
|
10
|
-
element: (props: NodeViewRendererProps) => {
|
|
11
|
-
element: HTMLElement;
|
|
12
|
-
editable?: HTMLElement;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function createCustomBlock(customBlock: CustomBlock): Node<CustomBlock, any>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export declare const translation: {
|
|
2
|
-
en: {
|
|
3
|
-
translation: {
|
|
4
|
-
placeholder: string;
|
|
5
|
-
heading: string;
|
|
6
|
-
list: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
de: {
|
|
10
|
-
translation: {
|
|
11
|
-
placeholder: string;
|
|
12
|
-
heading: string;
|
|
13
|
-
list: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
it: {
|
|
17
|
-
translation: {
|
|
18
|
-
placeholder: string;
|
|
19
|
-
heading: string;
|
|
20
|
-
list: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
es: {
|
|
24
|
-
translation: {
|
|
25
|
-
placeholder: string;
|
|
26
|
-
heading: string;
|
|
27
|
-
list: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
fr: {
|
|
31
|
-
translation: {
|
|
32
|
-
placeholder: string;
|
|
33
|
-
heading: string;
|
|
34
|
-
list: string;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
fi: {
|
|
38
|
-
translation: {
|
|
39
|
-
placeholder: string;
|
|
40
|
-
heading: string;
|
|
41
|
-
list: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
sv: {
|
|
45
|
-
translation: {
|
|
46
|
-
placeholder: string;
|
|
47
|
-
heading: string;
|
|
48
|
-
list: string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
};
|
|
File without changes
|