@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,28 +1,25 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
|
|
3
3
|
import * as Y from "yjs";
|
|
4
|
-
import { UiFactories } from "./BlockNoteExtensions";
|
|
5
4
|
import { Block, BlockIdentifier, BlockSchema, PartialBlock } from "./extensions/Blocks/api/blockTypes";
|
|
6
5
|
import { TextCursorPosition } from "./extensions/Blocks/api/cursorPositionTypes";
|
|
7
6
|
import { DefaultBlockSchema } from "./extensions/Blocks/api/defaultBlocks";
|
|
8
7
|
import { Styles } from "./extensions/Blocks/api/inlineContentTypes";
|
|
9
8
|
import { Selection } from "./extensions/Blocks/api/selectionTypes";
|
|
10
|
-
import {
|
|
9
|
+
import { FormattingToolbarProsemirrorPlugin } from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
10
|
+
import { HyperlinkToolbarProsemirrorPlugin } from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
|
|
11
|
+
import { SideMenuProsemirrorPlugin } from "./extensions/SideMenu/SideMenuPlugin";
|
|
12
|
+
import { BaseSlashMenuItem } from "./extensions/SlashMenu/BaseSlashMenuItem";
|
|
13
|
+
import { SlashMenuProsemirrorPlugin } from "./extensions/SlashMenu/SlashMenuPlugin";
|
|
11
14
|
export type BlockNoteEditorOptions<BSchema extends BlockSchema> = {
|
|
12
15
|
enableBlockNoteExtensions: boolean;
|
|
13
16
|
/**
|
|
14
|
-
* UI element factories for creating a custom UI, including custom positioning
|
|
15
|
-
* & rendering.
|
|
16
|
-
*/
|
|
17
|
-
uiFactories: UiFactories<BSchema>;
|
|
18
|
-
/**
|
|
19
|
-
* TODO: why is this called slashCommands and not slashMenuItems?
|
|
20
17
|
*
|
|
21
18
|
* (couldn't fix any type, see https://github.com/TypeCellOS/BlockNote/pull/191#discussion_r1210708771)
|
|
22
19
|
*
|
|
23
20
|
* @default defaultSlashMenuItems from `./extensions/SlashMenu`
|
|
24
21
|
*/
|
|
25
|
-
|
|
22
|
+
slashMenuItems: BaseSlashMenuItem<any>[];
|
|
26
23
|
/**
|
|
27
24
|
* The HTML element that should be used as the parent element for the editor.
|
|
28
25
|
*
|
|
@@ -104,11 +101,16 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
104
101
|
};
|
|
105
102
|
blockCache: WeakMap<Node, Block<BSchema>>;
|
|
106
103
|
readonly schema: BSchema;
|
|
107
|
-
|
|
104
|
+
ready: boolean;
|
|
105
|
+
readonly sideMenu: SideMenuProsemirrorPlugin<BSchema>;
|
|
106
|
+
readonly formattingToolbar: FormattingToolbarProsemirrorPlugin<BSchema>;
|
|
107
|
+
readonly slashMenu: SlashMenuProsemirrorPlugin<BSchema, any>;
|
|
108
|
+
readonly hyperlinkToolbar: HyperlinkToolbarProsemirrorPlugin<BSchema>;
|
|
109
|
+
constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
|
|
110
|
+
get prosemirrorView(): import("prosemirror-view").EditorView;
|
|
108
111
|
get domElement(): HTMLDivElement;
|
|
109
112
|
isFocused(): boolean;
|
|
110
113
|
focus(): void;
|
|
111
|
-
constructor(options?: Partial<BlockNoteEditorOptions<BSchema>>);
|
|
112
114
|
/**
|
|
113
115
|
* Gets a snapshot of all top-level (non-nested) blocks in the editor.
|
|
114
116
|
* @returns A snapshot of all top-level (non-nested) blocks in the editor.
|
|
@@ -131,6 +133,11 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
131
133
|
* @param callback The callback to execute.
|
|
132
134
|
*/
|
|
133
135
|
onEditorContentChange(callback: () => void): void;
|
|
136
|
+
/**
|
|
137
|
+
* Executes a callback whenever the editor's selection changes.
|
|
138
|
+
* @param callback The callback to execute.
|
|
139
|
+
*/
|
|
140
|
+
onEditorSelectionChange(callback: () => void): void;
|
|
134
141
|
/**
|
|
135
142
|
* Gets a snapshot of the current text cursor position.
|
|
136
143
|
* @returns A snapshot of the current text cursor position.
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { Extensions } from "@tiptap/core";
|
|
2
2
|
import { BlockNoteEditor } from "./BlockNoteEditor";
|
|
3
3
|
import * as Y from "yjs";
|
|
4
|
-
import { BlockSchema } from "./extensions/Blocks/api/blockTypes";
|
|
5
|
-
import { BlockSideMenuFactory } from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
6
|
-
import { FormattingToolbarFactory } from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
7
|
-
import { HyperlinkToolbarFactory } from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
8
|
-
import { BaseSlashMenuItem } from "./extensions/SlashMenu";
|
|
9
|
-
import { SuggestionsMenuFactory } from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
10
|
-
export type UiFactories<BSchema extends BlockSchema> = Partial<{
|
|
11
|
-
formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
|
|
12
|
-
hyperlinkToolbarFactory: HyperlinkToolbarFactory;
|
|
13
|
-
slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem<BSchema>>;
|
|
14
|
-
blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
|
|
15
|
-
}>;
|
|
16
4
|
/**
|
|
17
5
|
* Get all the Tiptap extensions BlockNote is configured with by default
|
|
18
6
|
*/
|
|
19
7
|
export declare const getBlockNoteExtensions: <BSchema extends Record<string, import("./extensions/Blocks/api/blockTypes").BlockSpec<string, import("./extensions/Blocks/api/blockTypes").PropSchema>>>(opts: {
|
|
20
8
|
editor: BlockNoteEditor<BSchema>;
|
|
21
|
-
uiFactories: Partial<{
|
|
22
|
-
formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
|
|
23
|
-
hyperlinkToolbarFactory: HyperlinkToolbarFactory;
|
|
24
|
-
slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem<BSchema>>;
|
|
25
|
-
blockSideMenuFactory: BlockSideMenuFactory<BSchema>;
|
|
26
|
-
}>;
|
|
27
|
-
slashCommands: BaseSlashMenuItem<any>[];
|
|
28
9
|
blockSchema: BSchema;
|
|
29
10
|
collaboration?: {
|
|
30
11
|
fragment: Y.XmlFragment;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
2
|
+
type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
|
|
3
|
+
type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
|
|
4
|
+
export declare class EventEmitter<T extends Record<string, any>> {
|
|
5
|
+
private callbacks;
|
|
6
|
+
on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): this;
|
|
7
|
+
protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): this;
|
|
8
|
+
off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): this;
|
|
9
|
+
protected removeAllListeners(): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Node, NodeConfig } from "@tiptap/core";
|
|
3
3
|
import { BlockNoteEditor } from "../../../BlockNoteEditor";
|
|
4
4
|
import { InlineContent, PartialInlineContent } from "./inlineContentTypes";
|
|
5
|
+
import { DefaultBlockSchema } from "./defaultBlocks";
|
|
5
6
|
export type TipTapNodeConfig<Name extends string, Options = any, Storage = any> = {
|
|
6
7
|
[K in keyof NodeConfig<Options, Storage>]: K extends "name" ? Name : K extends "group" ? never : NodeConfig<Options, Storage>[K];
|
|
7
8
|
};
|
|
@@ -58,7 +59,7 @@ type BlocksWithoutChildren<BSchema extends BlockSchema> = {
|
|
|
58
59
|
content: InlineContent[];
|
|
59
60
|
};
|
|
60
61
|
};
|
|
61
|
-
export type Block<BSchema extends BlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
|
|
62
|
+
export type Block<BSchema extends BlockSchema = DefaultBlockSchema> = BlocksWithoutChildren<BSchema>[keyof BlocksWithoutChildren<BSchema>] & {
|
|
62
63
|
children: Block<BSchema>[];
|
|
63
64
|
};
|
|
64
65
|
export type SpecificBlock<BSchema extends BlockSchema, BlockType extends keyof BSchema> = BlocksWithoutChildren<BSchema>[BlockType] & {
|
|
@@ -72,7 +73,7 @@ type PartialBlocksWithoutChildren<BSchema extends BlockSchema> = {
|
|
|
72
73
|
content: PartialInlineContent[] | string;
|
|
73
74
|
}>;
|
|
74
75
|
};
|
|
75
|
-
export type PartialBlock<BSchema extends BlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
|
|
76
|
+
export type PartialBlock<BSchema extends BlockSchema = DefaultBlockSchema> = PartialBlocksWithoutChildren<BSchema>[keyof PartialBlocksWithoutChildren<BSchema>] & Partial<{
|
|
76
77
|
children: PartialBlock<BSchema>[];
|
|
77
78
|
}>;
|
|
78
79
|
export type BlockIdentifier = {
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
|
-
import { Block, BlockSchema } from "../Blocks/api/blockTypes";
|
|
4
|
-
export type BlockSideMenuStaticParams<BSchema extends BlockSchema> = {
|
|
5
|
-
editor: BlockNoteEditor<BSchema>;
|
|
6
|
-
addBlock: () => void;
|
|
7
|
-
blockDragStart: (event: DragEvent) => void;
|
|
8
|
-
blockDragEnd: () => void;
|
|
9
|
-
freezeMenu: () => void;
|
|
10
|
-
unfreezeMenu: () => void;
|
|
11
|
-
getReferenceRect: () => DOMRect;
|
|
12
|
-
};
|
|
13
|
-
export type BlockSideMenuDynamicParams<BSchema extends BlockSchema> = {
|
|
14
|
-
block: Block<BSchema>;
|
|
15
|
-
};
|
|
16
|
-
export type BlockSideMenu<BSchema extends BlockSchema> = EditorElement<BlockSideMenuDynamicParams<BSchema>>;
|
|
17
|
-
export type BlockSideMenuFactory<BSchema extends BlockSchema> = ElementFactory<BlockSideMenuStaticParams<BSchema>, BlockSideMenuDynamicParams<BSchema>>;
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from "prosemirror-state";
|
|
3
|
-
import { BlockSideMenu, BlockSideMenuDynamicParams, BlockSideMenuFactory, BlockSideMenuStaticParams } from "./BlockSideMenuFactoryTypes";
|
|
4
|
-
import { DraggableBlocksOptions } from "./DraggableBlocksExtension";
|
|
1
|
+
import { PluginView } from "@tiptap/pm/state";
|
|
2
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
5
3
|
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { BaseUiElementCallbacks, BaseUiElementState } from "../../shared/BaseUiElementTypes";
|
|
5
|
+
import { Block, BlockSchema } from "../Blocks/api/blockTypes";
|
|
6
|
+
import { Editor } from "@tiptap/core";
|
|
7
|
+
export type SideMenuCallbacks = BaseUiElementCallbacks & {
|
|
8
|
+
addBlock: () => void;
|
|
9
|
+
freezeMenu: () => void;
|
|
10
|
+
unfreezeMenu: () => void;
|
|
11
|
+
blockDragStart: (event: DragEvent) => void;
|
|
12
|
+
blockDragEnd: () => void;
|
|
13
|
+
};
|
|
14
|
+
export type SideMenuState<BSchema extends BlockSchema> = BaseUiElementState & {
|
|
15
|
+
block: Block<BSchema>;
|
|
12
16
|
};
|
|
13
|
-
export declare class
|
|
17
|
+
export declare class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
14
18
|
editor: BlockNoteEditor<BSchema>;
|
|
15
|
-
|
|
19
|
+
ttEditor: Editor;
|
|
20
|
+
private sideMenuState?;
|
|
21
|
+
updateSideMenu: () => void;
|
|
16
22
|
horizontalPosAnchoredAtRoot: boolean;
|
|
17
23
|
horizontalPosAnchor: number;
|
|
18
|
-
blockMenu: BlockSideMenu<BSchema>;
|
|
19
24
|
hoveredBlock: HTMLElement | undefined;
|
|
20
25
|
isDragging: boolean;
|
|
21
|
-
menuOpen: boolean;
|
|
22
26
|
menuFrozen: boolean;
|
|
23
|
-
|
|
24
|
-
constructor({ tiptapEditor, editor, blockMenuFactory, horizontalPosAnchoredAtRoot, }: BlockMenuViewProps<BSchema>);
|
|
27
|
+
constructor(editor: BlockNoteEditor<BSchema>, tiptapEditor: Editor, updateSideMenu: (sideMenuState: SideMenuState<BSchema>) => void);
|
|
25
28
|
/**
|
|
26
29
|
* Sets isDragging when dragging text.
|
|
27
30
|
*/
|
|
@@ -39,11 +42,14 @@ export declare class BlockMenuView<BSchema extends BlockSchema> {
|
|
|
39
42
|
*/
|
|
40
43
|
onDragOver: (event: DragEvent) => void;
|
|
41
44
|
onKeyDown: (_event: KeyboardEvent) => void;
|
|
42
|
-
onMouseDown: (
|
|
45
|
+
onMouseDown: (_event: MouseEvent) => void;
|
|
43
46
|
onMouseMove: (event: MouseEvent) => void;
|
|
47
|
+
onScroll: () => void;
|
|
44
48
|
destroy(): void;
|
|
45
49
|
addBlock(): void;
|
|
46
|
-
getStaticParams(): BlockSideMenuStaticParams<BSchema>;
|
|
47
|
-
getDynamicParams(): BlockSideMenuDynamicParams<BSchema>;
|
|
48
50
|
}
|
|
49
|
-
export declare const
|
|
51
|
+
export declare const sideMenuPluginKey: PluginKey<any>;
|
|
52
|
+
export declare function setupSideMenu<BSchema extends BlockSchema>(editor: BlockNoteEditor<BSchema>, tiptapEditor: Editor, updateSideMenu: (sideMenuState: SideMenuState<BSchema>) => void): {
|
|
53
|
+
plugin: Plugin;
|
|
54
|
+
callbacks: Omit<SideMenuCallbacks, "destroy">;
|
|
55
|
+
};
|
|
@@ -1,44 +1,38 @@
|
|
|
1
|
-
import { Editor } from "@tiptap/core";
|
|
2
1
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
3
2
|
import { EditorView } from "prosemirror-view";
|
|
4
|
-
import { BlockNoteEditor, BlockSchema } from "../..";
|
|
5
|
-
import {
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
tiptapEditor: Editor;
|
|
9
|
-
editor: BlockNoteEditor<BSchema>;
|
|
10
|
-
formattingToolbarFactory: FormattingToolbarFactory<BSchema>;
|
|
11
|
-
}
|
|
12
|
-
export type FormattingToolbarViewProps<BSchema extends BlockSchema> = FormattingToolbarPluginProps<BSchema> & {
|
|
13
|
-
view: EditorView;
|
|
14
|
-
};
|
|
3
|
+
import { BaseUiElementCallbacks, BaseUiElementState, BlockNoteEditor, BlockSchema } from "../..";
|
|
4
|
+
import { EventEmitter } from "../../shared/EventEmitter";
|
|
5
|
+
export type FormattingToolbarCallbacks = BaseUiElementCallbacks;
|
|
6
|
+
export type FormattingToolbarState = BaseUiElementState;
|
|
15
7
|
export declare class FormattingToolbarView<BSchema extends BlockSchema> {
|
|
16
|
-
editor
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
private readonly editor;
|
|
9
|
+
private readonly pmView;
|
|
10
|
+
private formattingToolbarState?;
|
|
11
|
+
updateFormattingToolbar: () => void;
|
|
20
12
|
preventHide: boolean;
|
|
21
13
|
preventShow: boolean;
|
|
22
|
-
toolbarIsOpen: boolean;
|
|
23
14
|
prevWasEditable: boolean | null;
|
|
24
|
-
private lastPosition;
|
|
25
15
|
shouldShow: (props: {
|
|
26
16
|
view: EditorView;
|
|
27
17
|
state: EditorState;
|
|
28
18
|
from: number;
|
|
29
19
|
to: number;
|
|
30
20
|
}) => boolean;
|
|
31
|
-
constructor(
|
|
21
|
+
constructor(editor: BlockNoteEditor<BSchema>, pmView: EditorView, updateFormattingToolbar: (formattingToolbarState: FormattingToolbarState) => void);
|
|
32
22
|
viewMousedownHandler: () => void;
|
|
33
23
|
viewMouseupHandler: () => void;
|
|
34
24
|
dragstartHandler: () => void;
|
|
35
25
|
focusHandler: () => void;
|
|
36
|
-
blurHandler: (
|
|
37
|
-
|
|
38
|
-
}) => void;
|
|
26
|
+
blurHandler: (event: FocusEvent) => void;
|
|
27
|
+
scrollHandler: () => void;
|
|
39
28
|
update(view: EditorView, oldState?: EditorState): void;
|
|
40
29
|
destroy(): void;
|
|
41
30
|
getSelectionBoundingBox(): DOMRect;
|
|
42
|
-
getStaticParams(): FormattingToolbarStaticParams<BSchema>;
|
|
43
31
|
}
|
|
44
|
-
export declare const
|
|
32
|
+
export declare const formattingToolbarPluginKey: PluginKey<any>;
|
|
33
|
+
export declare class FormattingToolbarProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
|
|
34
|
+
private view;
|
|
35
|
+
readonly plugin: Plugin;
|
|
36
|
+
constructor(editor: BlockNoteEditor<BSchema>);
|
|
37
|
+
onUpdate(callback: (state: FormattingToolbarState) => void): () => void;
|
|
38
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
export type HyperlinkToolbarStaticParams = {
|
|
3
|
-
editHyperlink: (url: string, text: string) => void;
|
|
4
|
-
deleteHyperlink: () => void;
|
|
5
|
-
getReferenceRect: () => DOMRect;
|
|
6
|
-
};
|
|
7
|
-
export type HyperlinkToolbarDynamicParams = {
|
|
8
|
-
url: string;
|
|
9
|
-
text: string;
|
|
10
|
-
};
|
|
11
|
-
export type HyperlinkToolbar = EditorElement<HyperlinkToolbarDynamicParams>;
|
|
12
|
-
export type HyperlinkToolbarFactory = ElementFactory<HyperlinkToolbarStaticParams, HyperlinkToolbarDynamicParams>;
|
|
@@ -1,11 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
+
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
|
+
import { BaseUiElementState } from "../../shared/BaseUiElementTypes";
|
|
4
|
+
import { EventEmitter } from "../../shared/EventEmitter";
|
|
5
|
+
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
6
|
+
export type HyperlinkToolbarState = BaseUiElementState & {
|
|
7
|
+
url: string;
|
|
8
|
+
text: string;
|
|
6
9
|
};
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export declare const hyperlinkToolbarPluginKey: PluginKey<any>;
|
|
11
|
+
export declare class HyperlinkToolbarProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
|
|
12
|
+
private view;
|
|
13
|
+
readonly plugin: Plugin;
|
|
14
|
+
constructor(editor: BlockNoteEditor<BSchema>);
|
|
15
|
+
onUpdate(callback: (state: HyperlinkToolbarState) => void): () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Edit the currently hovered hyperlink.
|
|
18
|
+
*/
|
|
19
|
+
editHyperlink: (url: string, text: string) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Delete the currently hovered hyperlink.
|
|
22
|
+
*/
|
|
23
|
+
deleteHyperlink: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* When hovering on/off hyperlinks using the mouse cursor, the hyperlink
|
|
26
|
+
* toolbar will open & close with a delay.
|
|
27
|
+
*
|
|
28
|
+
* This function starts the delay timer, and should be used for when the mouse cursor enters the hyperlink toolbar.
|
|
29
|
+
*/
|
|
30
|
+
startHideTimer: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* When hovering on/off hyperlinks using the mouse cursor, the hyperlink
|
|
33
|
+
* toolbar will open & close with a delay.
|
|
34
|
+
*
|
|
35
|
+
* This function stops the delay timer, and should be used for when the mouse cursor exits the hyperlink toolbar.
|
|
36
|
+
*/
|
|
37
|
+
stopHideTimer: () => void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Selection } from "prosemirror-state";
|
|
2
|
+
import { Node, ResolvedPos, Slice } from "prosemirror-model";
|
|
3
|
+
import { Mappable } from "prosemirror-transform";
|
|
4
|
+
/**
|
|
5
|
+
* This class represents an editor selection which spans multiple nodes/blocks. It's currently only used to allow users
|
|
6
|
+
* to drag multiple blocks at the same time. Expects the selection anchor and head to be between nodes, i.e. just before
|
|
7
|
+
* the first target node and just after the last, and that anchor and head are at the same nesting level.
|
|
8
|
+
*
|
|
9
|
+
* Partially based on ProseMirror's NodeSelection implementation:
|
|
10
|
+
* (https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.ts)
|
|
11
|
+
* MultipleNodeSelection differs from NodeSelection in the following ways:
|
|
12
|
+
* 1. Stores which nodes are included in the selection instead of just a single node.
|
|
13
|
+
* 2. Already expects the selection to start just before the first target node and ends just after the last, while a
|
|
14
|
+
* NodeSelection automatically sets both anchor and head to just before the single target node.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MultipleNodeSelection extends Selection {
|
|
17
|
+
nodes: Array<Node>;
|
|
18
|
+
constructor($anchor: ResolvedPos, $head: ResolvedPos);
|
|
19
|
+
static create(doc: Node, from: number, to?: number): MultipleNodeSelection;
|
|
20
|
+
content(): Slice;
|
|
21
|
+
eq(selection: Selection): boolean;
|
|
22
|
+
map(doc: Node, mapping: Mappable): Selection;
|
|
23
|
+
toJSON(): any;
|
|
24
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { PluginView } from "@tiptap/pm/state";
|
|
2
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
3
|
+
import { EditorView } from "prosemirror-view";
|
|
4
|
+
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
5
|
+
import { BaseUiElementState } from "../../shared/BaseUiElementTypes";
|
|
6
|
+
import { EventEmitter } from "../../shared/EventEmitter";
|
|
7
|
+
import { Block, BlockSchema } from "../Blocks/api/blockTypes";
|
|
8
|
+
export type SideMenuState<BSchema extends BlockSchema> = BaseUiElementState & {
|
|
9
|
+
block: Block<BSchema>;
|
|
10
|
+
};
|
|
11
|
+
export declare class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
12
|
+
private readonly editor;
|
|
13
|
+
private readonly pmView;
|
|
14
|
+
private readonly updateSideMenu;
|
|
15
|
+
private sideMenuState?;
|
|
16
|
+
private horizontalPosAnchoredAtRoot;
|
|
17
|
+
private horizontalPosAnchor;
|
|
18
|
+
private hoveredBlock;
|
|
19
|
+
isDragging: boolean;
|
|
20
|
+
menuFrozen: boolean;
|
|
21
|
+
constructor(editor: BlockNoteEditor<BSchema>, pmView: EditorView, updateSideMenu: (sideMenuState: SideMenuState<BSchema>) => void);
|
|
22
|
+
/**
|
|
23
|
+
* Sets isDragging when dragging text.
|
|
24
|
+
*/
|
|
25
|
+
onDragStart: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* If the event is outside the editor contents,
|
|
28
|
+
* we dispatch a fake event, so that we can still drop the content
|
|
29
|
+
* when dragging / dropping to the side of the editor
|
|
30
|
+
*/
|
|
31
|
+
onDrop: (event: DragEvent) => void;
|
|
32
|
+
/**
|
|
33
|
+
* If the event is outside the editor contents,
|
|
34
|
+
* we dispatch a fake event, so that we can still drop the content
|
|
35
|
+
* when dragging / dropping to the side of the editor
|
|
36
|
+
*/
|
|
37
|
+
onDragOver: (event: DragEvent) => void;
|
|
38
|
+
onKeyDown: (_event: KeyboardEvent) => void;
|
|
39
|
+
onMouseMove: (event: MouseEvent) => void;
|
|
40
|
+
onScroll: () => void;
|
|
41
|
+
destroy(): void;
|
|
42
|
+
addBlock(): void;
|
|
43
|
+
}
|
|
44
|
+
export declare const sideMenuPluginKey: PluginKey<any>;
|
|
45
|
+
export declare class SideMenuProsemirrorPlugin<BSchema extends BlockSchema> extends EventEmitter<any> {
|
|
46
|
+
private readonly editor;
|
|
47
|
+
private sideMenuView;
|
|
48
|
+
readonly plugin: Plugin;
|
|
49
|
+
constructor(editor: BlockNoteEditor<BSchema>);
|
|
50
|
+
onUpdate(callback: (state: SideMenuState<BSchema>) => void): () => void;
|
|
51
|
+
/**
|
|
52
|
+
* If the block is empty, opens the slash menu. If the block has content,
|
|
53
|
+
* creates a new block below and opens the slash menu in it.
|
|
54
|
+
*/
|
|
55
|
+
addBlock: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Handles drag & drop events for blocks.
|
|
58
|
+
*/
|
|
59
|
+
blockDragStart: (event: {
|
|
60
|
+
dataTransfer: DataTransfer | null;
|
|
61
|
+
clientY: number;
|
|
62
|
+
}) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Handles drag & drop events for blocks.
|
|
65
|
+
*/
|
|
66
|
+
blockDragEnd: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Freezes the side menu. When frozen, the side menu will stay
|
|
69
|
+
* attached to the same block regardless of which block is hovered by the
|
|
70
|
+
* mouse cursor.
|
|
71
|
+
*/
|
|
72
|
+
freezeMenu: () => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Unfreezes the side menu. When frozen, the side menu will stay
|
|
75
|
+
* attached to the same block regardless of which block is hovered by the
|
|
76
|
+
* mouse cursor.
|
|
77
|
+
*/
|
|
78
|
+
unfreezeMenu: () => boolean;
|
|
79
|
+
}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
|
|
2
2
|
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
3
|
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare class BaseSlashMenuItem<BSchema extends BlockSchema> extends SuggestionItem {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly execute: (editor: BlockNoteEditor<BSchema>) => void;
|
|
12
|
-
readonly aliases: string[];
|
|
13
|
-
/**
|
|
14
|
-
* Constructs a new slash-command.
|
|
15
|
-
*
|
|
16
|
-
* @param name The name of the command
|
|
17
|
-
* @param execute The callback for creating a new node
|
|
18
|
-
* @param aliases Aliases for this command
|
|
19
|
-
*/
|
|
20
|
-
constructor(name: string, execute: (editor: BlockNoteEditor<BSchema>) => void, aliases?: string[]);
|
|
21
|
-
}
|
|
4
|
+
import { DefaultBlockSchema } from "../Blocks/api/defaultBlocks";
|
|
5
|
+
export type BaseSlashMenuItem<BSchema extends BlockSchema = DefaultBlockSchema> = SuggestionItem & {
|
|
6
|
+
execute: (editor: BlockNoteEditor<BSchema>) => void;
|
|
7
|
+
aliases?: string[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
+
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
3
|
+
import { EventEmitter } from "../../shared/EventEmitter";
|
|
4
|
+
import { SuggestionsMenuState } from "../../shared/plugins/suggestion/SuggestionPlugin";
|
|
5
|
+
import { BlockSchema } from "../Blocks/api/blockTypes";
|
|
6
|
+
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
7
|
+
export declare const slashMenuPluginKey: PluginKey<any>;
|
|
8
|
+
export declare class SlashMenuProsemirrorPlugin<BSchema extends BlockSchema, SlashMenuItem extends BaseSlashMenuItem<BSchema>> extends EventEmitter<any> {
|
|
9
|
+
readonly plugin: Plugin;
|
|
10
|
+
readonly itemCallback: (item: SlashMenuItem) => void;
|
|
11
|
+
constructor(editor: BlockNoteEditor<BSchema>, items: SlashMenuItem[]);
|
|
12
|
+
onUpdate(callback: (state: SuggestionsMenuState<SlashMenuItem>) => void): () => void;
|
|
13
|
+
}
|
|
@@ -1,70 +1,2 @@
|
|
|
1
1
|
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
2
|
-
|
|
3
|
-
* An array containing commands for creating all default blocks.
|
|
4
|
-
*/
|
|
5
|
-
export declare const defaultSlashMenuItems: BaseSlashMenuItem<{
|
|
6
|
-
readonly paragraph: {
|
|
7
|
-
readonly propSchema: {
|
|
8
|
-
backgroundColor: {
|
|
9
|
-
default: "transparent";
|
|
10
|
-
};
|
|
11
|
-
textColor: {
|
|
12
|
-
default: "black";
|
|
13
|
-
};
|
|
14
|
-
textAlignment: {
|
|
15
|
-
default: "left";
|
|
16
|
-
values: readonly ["left", "center", "right", "justify"];
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
readonly node: import("../Blocks/api/blockTypes").TipTapNode<"paragraph">;
|
|
20
|
-
};
|
|
21
|
-
readonly heading: {
|
|
22
|
-
readonly propSchema: {
|
|
23
|
-
readonly level: {
|
|
24
|
-
readonly default: "1";
|
|
25
|
-
readonly values: readonly ["1", "2", "3"];
|
|
26
|
-
};
|
|
27
|
-
readonly backgroundColor: {
|
|
28
|
-
default: "transparent";
|
|
29
|
-
};
|
|
30
|
-
readonly textColor: {
|
|
31
|
-
default: "black";
|
|
32
|
-
};
|
|
33
|
-
readonly textAlignment: {
|
|
34
|
-
default: "left";
|
|
35
|
-
values: readonly ["left", "center", "right", "justify"];
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
readonly node: import("../Blocks/api/blockTypes").TipTapNode<"heading">;
|
|
39
|
-
};
|
|
40
|
-
readonly bulletListItem: {
|
|
41
|
-
readonly propSchema: {
|
|
42
|
-
backgroundColor: {
|
|
43
|
-
default: "transparent";
|
|
44
|
-
};
|
|
45
|
-
textColor: {
|
|
46
|
-
default: "black";
|
|
47
|
-
};
|
|
48
|
-
textAlignment: {
|
|
49
|
-
default: "left";
|
|
50
|
-
values: readonly ["left", "center", "right", "justify"];
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
readonly node: import("../Blocks/api/blockTypes").TipTapNode<"bulletListItem">;
|
|
54
|
-
};
|
|
55
|
-
readonly numberedListItem: {
|
|
56
|
-
readonly propSchema: {
|
|
57
|
-
backgroundColor: {
|
|
58
|
-
default: "transparent";
|
|
59
|
-
};
|
|
60
|
-
textColor: {
|
|
61
|
-
default: "black";
|
|
62
|
-
};
|
|
63
|
-
textAlignment: {
|
|
64
|
-
default: "left";
|
|
65
|
-
values: readonly ["left", "center", "right", "justify"];
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
readonly node: import("../Blocks/api/blockTypes").TipTapNode<"numberedListItem">;
|
|
69
|
-
};
|
|
70
|
-
}>[];
|
|
2
|
+
export declare const getDefaultSlashMenuItems: <BSchema extends Record<string, import("../Blocks/api/blockTypes").BlockSpec<string, import("../Blocks/api/blockTypes").PropSchema>>>(schema?: BSchema) => BaseSlashMenuItem<BSchema>[];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createSlashMenuExtension } from "./SlashMenuExtension";
|
|
1
|
+
import { getDefaultSlashMenuItems } from "./defaultSlashMenuItems";
|
|
3
2
|
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
4
|
-
export {
|
|
3
|
+
export { getDefaultSlashMenuItems, BaseSlashMenuItem };
|
package/types/src/index.d.ts
CHANGED
|
@@ -3,14 +3,15 @@ export * from "./BlockNoteExtensions";
|
|
|
3
3
|
export * from "./extensions/Blocks/api/block";
|
|
4
4
|
export * from "./extensions/Blocks/api/blockTypes";
|
|
5
5
|
export * from "./extensions/Blocks/api/defaultBlocks";
|
|
6
|
-
export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
7
|
-
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
8
|
-
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
9
|
-
export { defaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMenuItems";
|
|
10
|
-
export * from "./extensions/SlashMenu/BaseSlashMenuItem";
|
|
11
|
-
export * from "./shared/EditorElement";
|
|
12
|
-
export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
|
|
13
|
-
export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
14
6
|
export * from "./extensions/Blocks/api/inlineContentTypes";
|
|
15
7
|
export * from "./extensions/Blocks/api/serialization";
|
|
16
8
|
export * as blockStyles from "./extensions/Blocks/nodes/Block.module.css";
|
|
9
|
+
export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
10
|
+
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
|
|
11
|
+
export * from "./extensions/SideMenu/SideMenuPlugin";
|
|
12
|
+
export * from "./extensions/SlashMenu/BaseSlashMenuItem";
|
|
13
|
+
export * from "./extensions/SlashMenu/SlashMenuPlugin";
|
|
14
|
+
export { getDefaultSlashMenuItems } from "./extensions/SlashMenu/defaultSlashMenuItems";
|
|
15
|
+
export * from "./shared/BaseUiElementTypes";
|
|
16
|
+
export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
|
|
17
|
+
export * from "./shared/plugins/suggestion/SuggestionPlugin";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type RequiredStaticParams = Record<string, any> & {
|
|
2
|
-
getReferenceRect: () => DOMRect;
|
|
3
|
-
};
|
|
4
|
-
export type RequiredDynamicParams = Record<string, any> & {};
|
|
5
|
-
export type EditorElement<ElementDynamicParams extends RequiredDynamicParams> = {
|
|
6
|
-
element: HTMLElement | undefined;
|
|
7
|
-
render: (params: ElementDynamicParams, isHidden: boolean) => void;
|
|
8
|
-
hide: () => void;
|
|
9
|
-
};
|
|
10
|
-
export type ElementFactory<ElementStaticParams extends RequiredStaticParams, ElementDynamicParams extends RequiredDynamicParams> = (staticParams: ElementStaticParams) => EditorElement<ElementDynamicParams>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
2
|
+
type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
|
|
3
|
+
type CallbackFunction<T extends Record<string, any>, EventName extends StringKeyOf<T>> = (...props: CallbackType<T, EventName>) => any;
|
|
4
|
+
export declare class EventEmitter<T extends Record<string, any>> {
|
|
5
|
+
private callbacks;
|
|
6
|
+
on<EventName extends StringKeyOf<T>>(event: EventName, fn: CallbackFunction<T, EventName>): () => void;
|
|
7
|
+
protected emit<EventName extends StringKeyOf<T>>(event: EventName, ...args: CallbackType<T, EventName>): void;
|
|
8
|
+
off<EventName extends StringKeyOf<T>>(event: EventName, fn?: CallbackFunction<T, EventName>): void;
|
|
9
|
+
protected removeAllListeners(): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|