@blocknote/core 0.2.3 → 0.2.4-alpha.7

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.
Files changed (44) hide show
  1. package/dist/blocknote.js +753 -633
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +1 -1
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +19 -28
  7. package/src/BlockNoteExtensions.ts +10 -0
  8. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +61 -0
  9. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +62 -0
  10. package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +107 -97
  11. package/src/extensions/Blocks/nodes/Block.module.css +91 -6
  12. package/src/extensions/Blocks/nodes/BlockContainer.ts +39 -26
  13. package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
  14. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +8 -0
  15. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +80 -35
  16. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +16 -0
  17. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +34 -3
  18. package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -1
  19. package/src/extensions/SlashMenu/SlashMenuExtension.ts +1 -1
  20. package/src/extensions/SlashMenu/SlashMenuItem.ts +3 -28
  21. package/src/extensions/SlashMenu/defaultCommands.tsx +14 -32
  22. package/src/extensions/SlashMenu/index.ts +1 -6
  23. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +75 -0
  24. package/src/extensions/TextColor/TextColorExtension.ts +54 -0
  25. package/src/extensions/TextColor/TextColorMark.ts +62 -0
  26. package/src/shared/plugins/suggestion/SuggestionItem.ts +0 -9
  27. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +191 -228
  28. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +1 -1
  29. package/types/src/api/Document.d.ts +5 -0
  30. package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +9 -0
  31. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +9 -0
  32. package/types/src/extensions/Blocks/PreviousBlockTypePlugin.d.ts +3 -2
  33. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -0
  34. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +4 -9
  35. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +10 -0
  36. package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +2 -19
  37. package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +5 -0
  38. package/types/src/extensions/SlashMenu/index.d.ts +1 -2
  39. package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +9 -0
  40. package/types/src/extensions/TextColor/TextColorExtension.d.ts +9 -0
  41. package/types/src/extensions/TextColor/TextColorMark.d.ts +9 -0
  42. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +0 -6
  43. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +9 -23
  44. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +1 -1
@@ -1,14 +1,5 @@
1
1
  import { Editor, Range } from "@tiptap/core";
2
2
  import { SuggestionItem } from "../../shared/plugins/suggestion/SuggestionItem";
3
- export type SlashMenuCallback = (editor: Editor, range: Range) => boolean;
4
- export declare enum SlashMenuGroups {
5
- HEADINGS = "Headings",
6
- BASIC_BLOCKS = "Basic Blocks",
7
- CODE = "Code Blocks",
8
- INLINE = "Inline",
9
- EMBED = "Embed",
10
- PLUGIN = "Plugin"
11
- }
12
3
  /**
13
4
  * A class that defines a slash command (/<command>).
14
5
  *
@@ -16,23 +7,15 @@ export declare enum SlashMenuGroups {
16
7
  */
17
8
  export declare class SlashMenuItem implements SuggestionItem {
18
9
  readonly name: string;
19
- readonly group: SlashMenuGroups;
20
- readonly execute: SlashMenuCallback;
10
+ readonly execute: (editor: Editor, range: Range) => void;
21
11
  readonly aliases: string[];
22
- readonly hint?: string | undefined;
23
- readonly shortcut?: string | undefined;
24
- groupName: string;
25
12
  /**
26
13
  * Constructs a new slash-command.
27
14
  *
28
15
  * @param name The name of the command
29
- * @param group Used to organize the menu
30
16
  * @param execute The callback for creating a new node
31
17
  * @param aliases Aliases for this command
32
- * @param icon To be shown next to the name in the menu
33
- * @param hint Short description of command
34
- * @param shortcut Info about keyboard shortcut that would activate this command
35
18
  */
36
- constructor(name: string, group: SlashMenuGroups, execute: SlashMenuCallback, aliases?: string[], hint?: string | undefined, shortcut?: string | undefined);
19
+ constructor(name: string, execute: (editor: Editor, range: Range) => void, aliases?: string[]);
37
20
  match(query: string): boolean;
38
21
  }
@@ -0,0 +1,5 @@
1
+ import { SlashMenuItem } from "./SlashMenuItem";
2
+ /**
3
+ * An array containing commands for creating all default blocks.
4
+ */
5
+ export declare const defaultSlashCommands: SlashMenuItem[];
@@ -1,5 +1,4 @@
1
1
  import { SlashMenuExtension } from "./SlashMenuExtension";
2
2
  import defaultCommands from "./defaultCommands";
3
- import { SlashMenuGroups, SlashMenuItem } from "./SlashMenuItem";
4
- export { defaultCommands, SlashMenuItem as SlashCommand, SlashMenuGroups as CommandGroup, };
3
+ export { defaultCommands };
5
4
  export default SlashMenuExtension;
@@ -0,0 +1,9 @@
1
+ import { Extension } from "@tiptap/core";
2
+ declare module "@tiptap/core" {
3
+ interface Commands<ReturnType> {
4
+ textAlignment: {
5
+ setTextAlignment: (textAlignment: "left" | "center" | "right" | "justify") => ReturnType;
6
+ };
7
+ }
8
+ }
9
+ export declare const TextAlignmentExtension: Extension<any, any>;
@@ -0,0 +1,9 @@
1
+ import { Extension } from "@tiptap/core";
2
+ declare module "@tiptap/core" {
3
+ interface Commands<ReturnType> {
4
+ blockTextColor: {
5
+ setBlockTextColor: (posInBlock: number, color: string) => ReturnType;
6
+ };
7
+ }
8
+ }
9
+ export declare const TextColorExtension: Extension<any, any>;
@@ -0,0 +1,9 @@
1
+ import { Mark } from "@tiptap/core";
2
+ declare module "@tiptap/core" {
3
+ interface Commands<ReturnType> {
4
+ textColor: {
5
+ setTextColor: (color: string) => ReturnType;
6
+ };
7
+ }
8
+ }
9
+ export declare const TextColorMark: Mark<any, any>;
@@ -6,12 +6,6 @@ export interface SuggestionItem {
6
6
  * The name of the item
7
7
  */
8
8
  name: string;
9
- /**
10
- * The name of the group to which this item belongs
11
- */
12
- groupName: string;
13
- hint?: string;
14
- shortcut?: string;
15
9
  /**
16
10
  * This function matches this item against a query string, the function should return **true** if the item
17
11
  * matches the query or **false** otherwise.
@@ -1,5 +1,5 @@
1
1
  import { Editor, Range } from "@tiptap/core";
2
- import { Plugin, PluginKey, Selection } from "prosemirror-state";
2
+ import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { SuggestionsMenuFactory } from "./SuggestionsMenuFactoryTypes";
4
4
  import { SuggestionItem } from "./SuggestionItem";
5
5
  export type SuggestionPluginOptions<T extends SuggestionItem> = {
@@ -14,9 +14,9 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
14
14
  */
15
15
  editor: Editor;
16
16
  /**
17
- * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands)
17
+ * The character that should trigger the suggestion menu to pop up (e.g. a '/' for commands), when typed by the user.
18
18
  */
19
- char: string;
19
+ defaultTriggerCharacter: string;
20
20
  suggestionsMenuFactory: SuggestionsMenuFactory<T>;
21
21
  /**
22
22
  * The callback that gets executed when an item is selected by the user.
@@ -41,27 +41,13 @@ export type SuggestionPluginOptions<T extends SuggestionItem> = {
41
41
  };
42
42
  type SuggestionPluginState<T extends SuggestionItem> = {
43
43
  active: boolean;
44
- range: Range | null;
45
- query: string | null;
46
- notFoundCount: number;
44
+ triggerCharacter: string | undefined;
45
+ queryStartPos: number | undefined;
47
46
  items: T[];
48
- selectedItemIndex: number;
49
- type: string;
50
- decorationId: string | null;
47
+ keyboardHoveredItemIndex: number | undefined;
48
+ notFoundCount: number | undefined;
49
+ decorationId: string | undefined;
51
50
  };
52
- export type MenuType = "slash" | "drag";
53
- /**
54
- * Finds a command: a specified character (e.g. '/') followed by a string of characters (all characters except the specified character are allowed).
55
- * Returns the string following the specified character or undefined if no command was found.
56
- *
57
- * @param char the character that indicates the start of a command
58
- * @param selection the selection (only works if the selection is empty; i.e. is a blinking cursor).
59
- * @returns an object containing the matching word (excluding the specified character) and the range of the match (including the specified character) or undefined if there is no match.
60
- */
61
- export declare function findCommandBeforeCursor(char: string, selection: Selection): {
62
- range: Range;
63
- query: string;
64
- } | undefined;
65
51
  /**
66
52
  * A ProseMirror plugin for suggestions, designed to make '/'-commands possible as well as mentions.
67
53
  *
@@ -75,5 +61,5 @@ export declare function findCommandBeforeCursor(char: string, selection: Selecti
75
61
  * @param options options for configuring the plugin
76
62
  * @returns the prosemirror plugin
77
63
  */
78
- export declare function createSuggestionPlugin<T extends SuggestionItem>({ pluginKey, editor, char, suggestionsMenuFactory, onSelectItem: selectItemCallback, items, }: SuggestionPluginOptions<T>): Plugin<SuggestionPluginState<T>>;
64
+ export declare function createSuggestionPlugin<T extends SuggestionItem>({ pluginKey, editor, defaultTriggerCharacter, suggestionsMenuFactory, onSelectItem: selectItemCallback, items, }: SuggestionPluginOptions<T>): Plugin<SuggestionPluginState<T>>;
79
65
  export {};
@@ -5,7 +5,7 @@ export type SuggestionsMenuStaticParams<T extends SuggestionItem> = {
5
5
  };
6
6
  export type SuggestionsMenuDynamicParams<T extends SuggestionItem> = {
7
7
  items: T[];
8
- selectedItemIndex: number;
8
+ keyboardHoveredItemIndex: number;
9
9
  referenceRect: DOMRect;
10
10
  };
11
11
  export type SuggestionsMenu<T extends SuggestionItem> = EditorElement<SuggestionsMenuDynamicParams<T>>;