@blocknote/core 0.3.0 → 0.4.0
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/blocknote.js +12508 -1276
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +50 -1
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +16 -5
- package/src/BlockNoteEditor.test.ts +12 -0
- package/src/BlockNoteEditor.ts +38 -15
- package/src/BlockNoteExtensions.ts +25 -21
- package/src/api/Editor.ts +142 -0
- package/src/api/blockManipulation/blockManipulation.ts +114 -0
- package/src/api/formatConversions/formatConversions.ts +86 -0
- package/src/api/formatConversions/removeUnderlinesRehypePlugin.ts +39 -0
- package/src/api/formatConversions/simplifyBlocksRehypePlugin.ts +125 -0
- package/src/api/nodeConversions/nodeConversions.ts +170 -0
- package/src/editor.module.css +7 -1
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +7 -1
- package/src/extensions/Blocks/api/blockTypes.ts +85 -0
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -0
- package/src/extensions/Blocks/api/inlineContentTypes.ts +44 -0
- package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +4 -4
- package/src/extensions/Blocks/nodes/BlockContainer.ts +75 -25
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +23 -5
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +28 -6
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -2
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +3 -3
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +7 -12
- package/src/extensions/SlashMenu/SlashMenuItem.ts +4 -1
- package/src/extensions/SlashMenu/{defaultCommands.tsx → defaultSlashCommands.tsx} +34 -17
- package/src/extensions/SlashMenu/index.ts +7 -4
- package/src/extensions/UniqueID/UniqueID.ts +1 -1
- package/src/index.ts +4 -2
- package/types/src/BlockNoteEditor.d.ts +13 -4
- package/types/src/BlockNoteEditor.test.d.ts +1 -0
- package/types/src/BlockNoteExtensions.d.ts +7 -3
- package/types/src/api/Editor.d.ts +73 -0
- package/types/src/api/blockManipulation/blockManipulation.d.ts +6 -0
- package/types/src/api/formatConversions/formatConversions.d.ts +6 -0
- package/types/src/api/formatConversions/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/formatConversions/simplifyBlocksRehypePlugin.d.ts +16 -0
- package/types/src/api/nodeConversions/nodeConversions.d.ts +8 -0
- package/types/src/api/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/simplifyBlocksRehypePlugin.d.ts +16 -0
- package/types/src/extensions/Blocks/api/apiTypes.d.ts +18 -0
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +36 -0
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +4 -0
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +23 -0
- package/types/src/extensions/Blocks/api/styleTypes.d.ts +22 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -2
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +1 -3
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +4 -1
- package/types/src/extensions/SlashMenu/index.d.ts +3 -3
- package/types/src/index.d.ts +4 -2
- package/src/extensions/Blocks/apiTypes.ts +0 -48
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type StyleTemplate<Type extends string, Props extends Record<string, string>> = {
|
|
2
|
+
type: Type;
|
|
3
|
+
props: Props;
|
|
4
|
+
};
|
|
5
|
+
export type Bold = StyleTemplate<"bold", {}>;
|
|
6
|
+
export type Italic = StyleTemplate<"italic", {}>;
|
|
7
|
+
export type Underline = StyleTemplate<"underline", {}>;
|
|
8
|
+
export type Strikethrough = StyleTemplate<"strike", {}>;
|
|
9
|
+
export type TextColor = StyleTemplate<"textColor", {
|
|
10
|
+
color: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type BackgroundColor = StyleTemplate<"backgroundColor", {
|
|
13
|
+
color: string;
|
|
14
|
+
}>;
|
|
15
|
+
export type Link = StyleTemplate<"link", {
|
|
16
|
+
href: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type Style = Bold | Italic | Underline | Strikethrough | TextColor | BackgroundColor | Link;
|
|
19
|
+
export type StyledText = {
|
|
20
|
+
text: string;
|
|
21
|
+
styles: Style[];
|
|
22
|
+
};
|
|
23
|
+
export type InlineContent = StyledText;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type StyleTemplate<Type extends string, Props extends Record<string, string>> = {
|
|
2
|
+
type: Type;
|
|
3
|
+
props: Props;
|
|
4
|
+
};
|
|
5
|
+
export type Bold = StyleTemplate<"bold", {}>;
|
|
6
|
+
export type Italic = StyleTemplate<"italic", {}>;
|
|
7
|
+
export type Underline = StyleTemplate<"underline", {}>;
|
|
8
|
+
export type Strikethrough = StyleTemplate<"strike", {}>;
|
|
9
|
+
export type TextColor = StyleTemplate<"textColor", {
|
|
10
|
+
color: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type BackgroundColor = StyleTemplate<"backgroundColor", {
|
|
13
|
+
color: string;
|
|
14
|
+
}>;
|
|
15
|
+
export type Link = StyleTemplate<"link", {
|
|
16
|
+
href: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type Style = Bold | Italic | Underline | Strikethrough | TextColor | BackgroundColor | Link;
|
|
19
|
+
export type StyledText = {
|
|
20
|
+
text: string;
|
|
21
|
+
styles: Style[];
|
|
22
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from "@tiptap/core";
|
|
2
|
-
import {
|
|
2
|
+
import { PartialBlock } from "../api/blockTypes";
|
|
3
3
|
export interface IBlock {
|
|
4
4
|
HTMLAttributes: Record<string, any>;
|
|
5
5
|
}
|
|
@@ -10,8 +10,8 @@ declare module "@tiptap/core" {
|
|
|
10
10
|
BNDeleteBlock: (posInBlock: number) => ReturnType;
|
|
11
11
|
BNMergeBlocks: (posBetweenBlocks: number) => ReturnType;
|
|
12
12
|
BNSplitBlock: (posInBlock: number, keepType: boolean) => ReturnType;
|
|
13
|
-
BNUpdateBlock: (posInBlock: number,
|
|
14
|
-
BNCreateOrUpdateBlock: (posInBlock: number,
|
|
13
|
+
BNUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
|
|
14
|
+
BNCreateOrUpdateBlock: (posInBlock: number, block: PartialBlock) => ReturnType;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EditorElement, ElementFactory } from "../../shared/EditorElement";
|
|
2
|
-
import { Block,
|
|
2
|
+
import { Block, PartialBlock } from "../Blocks/api/blockTypes";
|
|
3
3
|
export type FormattingToolbarStaticParams = {
|
|
4
4
|
toggleBold: () => void;
|
|
5
5
|
toggleItalic: () => void;
|
|
@@ -11,7 +11,7 @@ export type FormattingToolbarStaticParams = {
|
|
|
11
11
|
setTextAlignment: (textAlignment: "left" | "center" | "right" | "justify") => void;
|
|
12
12
|
increaseBlockIndent: () => void;
|
|
13
13
|
decreaseBlockIndent: () => void;
|
|
14
|
-
updateBlock: (
|
|
14
|
+
updateBlock: (updatedBlock: PartialBlock) => void;
|
|
15
15
|
};
|
|
16
16
|
export type FormattingToolbarDynamicParams = {
|
|
17
17
|
boldIsActive: boolean;
|
|
@@ -3,9 +3,7 @@ import { PluginKey } from "prosemirror-state";
|
|
|
3
3
|
import { SuggestionsMenuFactory } from "../../shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
4
4
|
import { SlashMenuItem } from "./SlashMenuItem";
|
|
5
5
|
export type SlashMenuOptions = {
|
|
6
|
-
commands:
|
|
7
|
-
[key: string]: SlashMenuItem;
|
|
8
|
-
};
|
|
6
|
+
commands: SlashMenuItem[] | undefined;
|
|
9
7
|
slashMenuFactory: SuggestionsMenuFactory<any> | undefined;
|
|
10
8
|
};
|
|
11
9
|
export declare const SlashMenuPluginKey: PluginKey<any>;
|
|
@@ -9,6 +9,9 @@ export declare class SlashMenuItem implements SuggestionItem {
|
|
|
9
9
|
readonly name: string;
|
|
10
10
|
readonly execute: (editor: Editor, range: Range) => void;
|
|
11
11
|
readonly aliases: string[];
|
|
12
|
+
readonly group: string;
|
|
13
|
+
readonly hint?: string | undefined;
|
|
14
|
+
readonly shortcut?: string | undefined;
|
|
12
15
|
/**
|
|
13
16
|
* Constructs a new slash-command.
|
|
14
17
|
*
|
|
@@ -16,6 +19,6 @@ export declare class SlashMenuItem implements SuggestionItem {
|
|
|
16
19
|
* @param execute The callback for creating a new node
|
|
17
20
|
* @param aliases Aliases for this command
|
|
18
21
|
*/
|
|
19
|
-
constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases
|
|
22
|
+
constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases: string[], group: string, hint?: string | undefined, shortcut?: string | undefined);
|
|
20
23
|
match(query: string): boolean;
|
|
21
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { defaultSlashCommands } from "./defaultSlashCommands";
|
|
1
2
|
import { SlashMenuExtension } from "./SlashMenuExtension";
|
|
2
|
-
import
|
|
3
|
-
export {
|
|
4
|
-
export default SlashMenuExtension;
|
|
3
|
+
import { SlashMenuItem } from "./SlashMenuItem";
|
|
4
|
+
export { defaultSlashCommands, SlashMenuItem as SlashCommand, SlashMenuExtension, };
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from "./BlockNoteEditor";
|
|
2
2
|
export * from "./BlockNoteExtensions";
|
|
3
|
-
export
|
|
4
|
-
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
3
|
+
export * from "./extensions/Blocks/api/blockTypes";
|
|
5
4
|
export * from "./extensions/DraggableBlocks/BlockSideMenuFactoryTypes";
|
|
5
|
+
export * from "./extensions/FormattingToolbar/FormattingToolbarFactoryTypes";
|
|
6
6
|
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes";
|
|
7
|
+
export { defaultSlashCommands } from "./extensions/SlashMenu/defaultSlashCommands";
|
|
7
8
|
export * from "./extensions/SlashMenu/SlashMenuItem";
|
|
8
9
|
export * from "./shared/EditorElement";
|
|
9
10
|
export type { SuggestionItem } from "./shared/plugins/suggestion/SuggestionItem";
|
|
10
11
|
export * from "./shared/plugins/suggestion/SuggestionsMenuFactoryTypes";
|
|
12
|
+
export * from "../src/api/Editor";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type BlockSpec<
|
|
2
|
-
// Type of the block.
|
|
3
|
-
// Examples might include: "paragraph", "heading", or "bulletListItem".
|
|
4
|
-
Type extends string,
|
|
5
|
-
// Changeable props which affect the block's behaviour or appearance.
|
|
6
|
-
// An example might be: { textAlignment: "left" | "right" | "center" | "justify" } for a paragraph block.
|
|
7
|
-
Props extends Record<string, string>
|
|
8
|
-
> = {
|
|
9
|
-
type: Type;
|
|
10
|
-
props: Props;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type BlockSpecUpdate<Spec> = Spec extends BlockSpec<
|
|
14
|
-
infer Type,
|
|
15
|
-
infer Props
|
|
16
|
-
>
|
|
17
|
-
? {
|
|
18
|
-
type: Type;
|
|
19
|
-
props?: Partial<Props>;
|
|
20
|
-
}
|
|
21
|
-
: never;
|
|
22
|
-
|
|
23
|
-
export type NumberedListItemBlock = BlockSpec<"numberedListItem", {}>;
|
|
24
|
-
|
|
25
|
-
export type BulletListItemBlock = BlockSpec<"bulletListItem", {}>;
|
|
26
|
-
|
|
27
|
-
export type HeadingBlock = BlockSpec<
|
|
28
|
-
"heading",
|
|
29
|
-
{
|
|
30
|
-
level: "1" | "2" | "3";
|
|
31
|
-
}
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export type ParagraphBlock = BlockSpec<"paragraph", {}>;
|
|
35
|
-
|
|
36
|
-
export type Block =
|
|
37
|
-
| ParagraphBlock
|
|
38
|
-
| HeadingBlock
|
|
39
|
-
| BulletListItemBlock
|
|
40
|
-
| NumberedListItemBlock;
|
|
41
|
-
|
|
42
|
-
export type BlockUpdate = BlockSpecUpdate<Block>;
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
TODO:
|
|
46
|
-
1) guard read / writes (now we just pass on internal node attrs)
|
|
47
|
-
2) where to locate this code / types
|
|
48
|
-
*/
|