@blocknote/core 0.40.0 → 0.41.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.
Files changed (102) hide show
  1. package/dist/BlockNoteSchema-COA0fsXW.cjs +11 -0
  2. package/dist/BlockNoteSchema-COA0fsXW.cjs.map +1 -0
  3. package/dist/{BlockNoteSchema-oR047ACf.js → BlockNoteSchema-CYRHak18.js} +681 -581
  4. package/dist/BlockNoteSchema-CYRHak18.js.map +1 -0
  5. package/dist/blocknote.cjs +4 -4
  6. package/dist/blocknote.cjs.map +1 -1
  7. package/dist/blocknote.js +3663 -2817
  8. package/dist/blocknote.js.map +1 -1
  9. package/dist/blocks.cjs +1 -1
  10. package/dist/blocks.js +51 -49
  11. package/dist/en-Cl87Uuyf.cjs +2 -0
  12. package/dist/en-Cl87Uuyf.cjs.map +1 -0
  13. package/dist/{en-Bq3Es3Np.js → en-njEqD7AG.js} +9 -3
  14. package/dist/en-njEqD7AG.js.map +1 -0
  15. package/dist/locales.cjs +1 -1
  16. package/dist/locales.cjs.map +1 -1
  17. package/dist/locales.js +122 -2
  18. package/dist/locales.js.map +1 -1
  19. package/dist/style.css +1 -1
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/dist/webpack-stats.json +1 -1
  22. package/package.json +4 -3
  23. package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
  24. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +2 -1
  25. package/src/api/exporters/markdown/markdownExporter.ts +3 -1
  26. package/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.ts +19 -0
  27. package/src/api/parsers/markdown/parseMarkdown.ts +31 -0
  28. package/src/blocks/Code/block.ts +14 -14
  29. package/src/blocks/Divider/block.ts +49 -0
  30. package/src/blocks/ListItem/BulletListItem/block.ts +9 -1
  31. package/src/blocks/ListItem/CheckListItem/block.ts +1 -0
  32. package/src/blocks/ListItem/NumberedListItem/block.ts +9 -1
  33. package/src/blocks/Table/block.ts +56 -1
  34. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  35. package/src/blocks/defaultBlocks.ts +16 -14
  36. package/src/blocks/index.ts +1 -0
  37. package/src/editor/Block.css +14 -20
  38. package/src/editor/BlockNoteEditor.test.ts +40 -0
  39. package/src/editor/BlockNoteEditor.ts +248 -465
  40. package/src/editor/BlockNoteExtensions.ts +3 -1
  41. package/src/editor/managers/BlockManager.ts +251 -0
  42. package/src/editor/managers/CollaborationManager.ts +212 -0
  43. package/src/editor/managers/EventManager.ts +134 -0
  44. package/src/editor/managers/ExportManager.ts +137 -0
  45. package/src/editor/managers/ExtensionManager.ts +130 -0
  46. package/src/editor/managers/SelectionManager.ts +114 -0
  47. package/src/editor/managers/StateManager.ts +238 -0
  48. package/src/editor/managers/StyleManager.ts +182 -0
  49. package/src/editor/managers/index.ts +11 -0
  50. package/src/extensions/Comments/CommentsPlugin.ts +7 -4
  51. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +10 -0
  52. package/src/i18n/locales/ar.ts +6 -0
  53. package/src/i18n/locales/de.ts +6 -0
  54. package/src/i18n/locales/en.ts +6 -0
  55. package/src/i18n/locales/es.ts +6 -0
  56. package/src/i18n/locales/fr.ts +6 -0
  57. package/src/i18n/locales/he.ts +6 -0
  58. package/src/i18n/locales/hr.ts +6 -0
  59. package/src/i18n/locales/is.ts +6 -0
  60. package/src/i18n/locales/it.ts +6 -0
  61. package/src/i18n/locales/ja.ts +6 -0
  62. package/src/i18n/locales/ko.ts +6 -0
  63. package/src/i18n/locales/nl.ts +6 -0
  64. package/src/i18n/locales/no.ts +6 -0
  65. package/src/i18n/locales/pl.ts +6 -0
  66. package/src/i18n/locales/pt.ts +6 -0
  67. package/src/i18n/locales/ru.ts +6 -0
  68. package/src/i18n/locales/sk.ts +6 -0
  69. package/src/i18n/locales/uk.ts +6 -0
  70. package/src/i18n/locales/vi.ts +6 -0
  71. package/src/i18n/locales/zh-tw.ts +6 -0
  72. package/src/i18n/locales/zh.ts +6 -0
  73. package/src/schema/blocks/createSpec.ts +1 -0
  74. package/src/util/string.ts +21 -0
  75. package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +2 -0
  76. package/types/src/blocks/Divider/block.d.ts +3 -0
  77. package/types/src/blocks/Heading/block.d.ts +3 -3
  78. package/types/src/blocks/defaultBlocks.d.ts +2 -1
  79. package/types/src/blocks/index.d.ts +1 -0
  80. package/types/src/editor/BlockNoteEditor.d.ts +68 -47
  81. package/types/src/editor/BlockNoteExtensions.d.ts +2 -1
  82. package/types/src/editor/managers/BlockManager.d.ts +114 -0
  83. package/types/src/editor/managers/CollaborationManager.d.ts +115 -0
  84. package/types/src/editor/managers/EventManager.d.ts +58 -0
  85. package/types/src/editor/managers/ExportManager.d.ts +64 -0
  86. package/types/src/editor/managers/ExtensionManager.d.ts +68 -0
  87. package/types/src/editor/managers/SelectionManager.d.ts +54 -0
  88. package/types/src/editor/managers/StateManager.d.ts +115 -0
  89. package/types/src/editor/managers/StyleManager.d.ts +48 -0
  90. package/types/src/editor/managers/index.d.ts +8 -0
  91. package/types/src/extensions/Comments/CommentsPlugin.d.ts +4 -3
  92. package/types/src/i18n/locales/en.d.ts +6 -0
  93. package/types/src/i18n/locales/sk.d.ts +6 -0
  94. package/types/src/util/string.d.ts +1 -0
  95. package/dist/BlockNoteSchema-DmZ6UQfY.cjs +0 -11
  96. package/dist/BlockNoteSchema-DmZ6UQfY.cjs.map +0 -1
  97. package/dist/BlockNoteSchema-oR047ACf.js.map +0 -1
  98. package/dist/en-Bq3Es3Np.js.map +0 -1
  99. package/dist/en-D3B48eJ7.cjs +0 -2
  100. package/dist/en-D3B48eJ7.cjs.map +0 -1
  101. /package/src/api/exporters/markdown/{removeUnderlinesRehypePlugin.ts → util/removeUnderlinesRehypePlugin.ts} +0 -0
  102. /package/types/src/api/exporters/markdown/{removeUnderlinesRehypePlugin.d.ts → util/removeUnderlinesRehypePlugin.d.ts} +0 -0
@@ -2,25 +2,24 @@ import { AnyExtension, EditorOptions, FocusPosition, Editor as TiptapEditor } fr
2
2
  import { type Command, type Plugin, type Transaction } from "@tiptap/pm/state";
3
3
  import { Node, Schema } from "prosemirror-model";
4
4
  import * as Y from "yjs";
5
- import { BlocksChanged } from "../api/getBlocksChangedByTransaction.js";
5
+ import type { BlocksChanged } from "../api/getBlocksChangedByTransaction.js";
6
+ import { Block, BlockNoteSchema, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, PartialBlock } from "../blocks/index.js";
6
7
  import type { ThreadStore, User } from "../comments/index.js";
7
- import type { ForkYDocPlugin } from "../extensions/Collaboration/ForkYDocPlugin.js";
8
8
  import type { CommentsPlugin } from "../extensions/Comments/CommentsPlugin.js";
9
- import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin.js";
10
- import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
11
- import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin.js";
12
- import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin.js";
13
- import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin.js";
14
- import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin.js";
15
- import { Dictionary } from "../i18n/dictionary.js";
16
- import { BlockIdentifier, BlockNoteDOMAttributes, BlockSchema, BlockSpecs, CustomBlockNoteSchema, InlineContentSchema, InlineContentSpecs, PartialInlineContent, Styles, StyleSchema, StyleSpecs } from "../schema/index.js";
17
- import "../style.css";
9
+ import type { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin.js";
10
+ import type { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
11
+ import type { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin.js";
12
+ import type { ShowSelectionPlugin } from "../extensions/ShowSelection/ShowSelectionPlugin.js";
13
+ import type { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin.js";
14
+ import type { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin.js";
15
+ import type { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin.js";
16
+ import type { Dictionary } from "../i18n/dictionary.js";
17
+ import type { BlockIdentifier, BlockNoteDOMAttributes, BlockSchema, BlockSpecs, CustomBlockNoteSchema, InlineContentSchema, InlineContentSpecs, PartialInlineContent, Styles, StyleSchema, StyleSpecs } from "../schema/index.js";
18
18
  import { EventEmitter } from "../util/EventEmitter.js";
19
- import { NoInfer } from "../util/typescript.js";
19
+ import type { NoInfer } from "../util/typescript.js";
20
20
  import { BlockNoteExtension } from "./BlockNoteExtension.js";
21
- import { TextCursorPosition } from "./cursorPositionTypes.js";
22
- import { Selection } from "./selectionTypes.js";
23
- import { Block, BlockNoteSchema, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, PartialBlock } from "../blocks/index.js";
21
+ import type { TextCursorPosition } from "./cursorPositionTypes.js";
22
+ import type { Selection } from "./selectionTypes.js";
24
23
  import "../style.css";
25
24
  /**
26
25
  * A factory function that returns a BlockNoteExtension
@@ -323,22 +322,22 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
323
322
  /**
324
323
  * The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
325
324
  */
326
- readonly schema: CustomBlockNoteSchema<BSchema, ISchema, SSchema>;
325
+ readonly schema: BlockNoteSchema<BSchema, ISchema, SSchema>;
327
326
  readonly blockImplementations: BlockSpecs;
328
327
  readonly inlineContentImplementations: InlineContentSpecs;
329
328
  readonly styleImplementations: StyleSpecs;
330
- readonly formattingToolbar: FormattingToolbarProsemirrorPlugin;
331
- readonly linkToolbar: LinkToolbarProsemirrorPlugin<BSchema, ISchema, SSchema>;
332
- readonly sideMenu: SideMenuProsemirrorPlugin<BSchema, ISchema, SSchema>;
333
- readonly suggestionMenus: SuggestionMenuProseMirrorPlugin<BSchema, ISchema, SSchema>;
334
- readonly filePanel?: FilePanelProsemirrorPlugin<ISchema, SSchema>;
335
- readonly tableHandles?: TableHandlesProsemirrorPlugin<ISchema, SSchema>;
336
- readonly comments?: CommentsPlugin;
337
- private readonly showSelectionPlugin;
329
+ get formattingToolbar(): FormattingToolbarProsemirrorPlugin;
330
+ get linkToolbar(): LinkToolbarProsemirrorPlugin<BSchema, ISchema, SSchema>;
331
+ get sideMenu(): SideMenuProsemirrorPlugin<BSchema, ISchema, SSchema>;
332
+ get suggestionMenus(): SuggestionMenuProseMirrorPlugin<BSchema, ISchema, SSchema>;
333
+ get filePanel(): FilePanelProsemirrorPlugin<ISchema, SSchema> | undefined;
334
+ get tableHandles(): TableHandlesProsemirrorPlugin<ISchema, SSchema> | undefined;
335
+ get comments(): CommentsPlugin | undefined;
336
+ get showSelectionPlugin(): ShowSelectionPlugin;
338
337
  /**
339
338
  * The plugin for forking a document, only defined if in collaboration mode
340
339
  */
341
- readonly forkYDocPlugin?: ForkYDocPlugin;
340
+ get forkYDocPlugin(): import("../extensions/Collaboration/ForkYDocPlugin.js").ForkYDocPlugin | undefined;
342
341
  /**
343
342
  * The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
344
343
  * This method should set when creating the editor as this is application-specific.
@@ -368,10 +367,14 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
368
367
  schema: CustomBlockNoteSchema<infer BSchema, infer ISchema, infer SSchema>;
369
368
  } ? BlockNoteEditor<BSchema, ISchema, SSchema> : BlockNoteEditor<DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema>;
370
369
  protected constructor(options: Partial<BlockNoteEditorOptions<BSchema, ISchema, SSchema>>);
371
- /**
372
- * Stores the currently active transaction, which is the accumulated transaction from all {@link dispatch} calls during a {@link transact} calls
373
- */
374
- private activeTransaction;
370
+ private readonly _blockManager;
371
+ private readonly _collaborationManager?;
372
+ private readonly _eventManager;
373
+ private readonly _exportManager;
374
+ private readonly _extensionManager;
375
+ private readonly _selectionManager;
376
+ private readonly _stateManager;
377
+ private readonly _styleManager;
375
378
  /**
376
379
  * Execute a prosemirror command. This is mostly for backwards compatibility with older code.
377
380
  *
@@ -584,7 +587,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
584
587
  * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
585
588
  * `referenceBlock`.
586
589
  */
587
- insertBlocks(blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after"): Block<BSchema, ISchema, SSchema>[];
590
+ insertBlocks(blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after"): Block<any, any, any>[];
588
591
  /**
589
592
  * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
590
593
  * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
@@ -592,7 +595,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
592
595
  * @param blockToUpdate The block that should be updated.
593
596
  * @param update A partial block which defines how the existing block should be changed.
594
597
  */
595
- updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, ISchema, SSchema>): Block<BSchema, ISchema, SSchema>;
598
+ updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, ISchema, SSchema>): Block<any, any, any>;
596
599
  /**
597
600
  * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
598
601
  * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
@@ -606,8 +609,8 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
606
609
  * @param blocksToInsert An array of partial blocks to replace the old ones with.
607
610
  */
608
611
  replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]): {
609
- insertedBlocks: Block<BSchema, ISchema, SSchema>[];
610
- removedBlocks: Block<BSchema, ISchema, SSchema>[];
612
+ insertedBlocks: Block<any, any, any>[];
613
+ removedBlocks: Block<any, any, any>[];
611
614
  };
612
615
  /**
613
616
  * Undo the last action.
@@ -726,7 +729,7 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
726
729
  * @param markdown The Markdown string to parse blocks from.
727
730
  * @returns The blocks parsed from the Markdown string.
728
731
  */
729
- tryParseMarkdownToBlocks(markdown: string): Promise<Block<BSchema, ISchema, SSchema>[]>;
732
+ tryParseMarkdownToBlocks(markdown: string): Block<BSchema, ISchema, SSchema>[];
730
733
  /**
731
734
  * Updates the user info for the current user that's shown to other collaborators.
732
735
  */
@@ -734,17 +737,6 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
734
737
  name: string;
735
738
  color: string;
736
739
  }): void;
737
- /**
738
- * Registers a callback which will be called before any change is applied to the editor, allowing you to cancel the change.
739
- */
740
- onBeforeChange(
741
- /**
742
- * If the callback returns `false`, the change will be canceled & not applied to the editor.
743
- */
744
- callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>, context: {
745
- getChanges: () => BlocksChanged<BSchema, ISchema, SSchema>;
746
- tr: Transaction;
747
- }) => boolean | void): () => void;
748
740
  /**
749
741
  * A callback function that runs whenever the editor's contents change.
750
742
  *
@@ -756,20 +748,49 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
756
748
  * Returns the blocks that were inserted, updated, or deleted by the change that occurred.
757
749
  */
758
750
  getChanges(): BlocksChanged<BSchema, ISchema, SSchema>;
759
- }) => void): () => void;
751
+ }) => void): import("./managers/EventManager.js").Unsubscribe;
760
752
  /**
761
753
  * A callback function that runs whenever the text cursor position or selection changes.
762
754
  *
763
755
  * @param callback The callback to execute.
764
756
  * @returns A function to remove the callback.
765
757
  */
766
- onSelectionChange(callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>) => void, includeSelectionChangedByRemote?: boolean): () => void;
758
+ onSelectionChange(callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>) => void, includeSelectionChangedByRemote?: boolean): import("./managers/EventManager.js").Unsubscribe;
767
759
  /**
768
760
  * A callback function that runs when the editor has been initialized.
769
761
  *
770
762
  * This can be useful for plugins to initialize themselves after the editor has been initialized.
763
+ *
764
+ * @param callback The callback to execute.
765
+ * @returns A function to remove the callback.
771
766
  */
772
767
  onCreate(callback: () => void): () => void;
768
+ /**
769
+ * A callback function that runs when the editor has been mounted.
770
+ *
771
+ * This can be useful for plugins to initialize themselves after the editor has been mounted.
772
+ *
773
+ * @param callback The callback to execute.
774
+ * @returns A function to remove the callback.
775
+ */
776
+ onMount(callback: (ctx: {
777
+ editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
778
+ }) => void): void;
779
+ /**
780
+ * A callback function that runs when the editor has been unmounted.
781
+ *
782
+ * This can be useful for plugins to clean up themselves after the editor has been unmounted.
783
+ *
784
+ * @param callback The callback to execute.
785
+ * @returns A function to remove the callback.
786
+ */
787
+ onUnmount(callback: (ctx: {
788
+ editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
789
+ }) => void): void;
790
+ /**
791
+ * Gets the bounding box of the current selection.
792
+ * @returns The bounding box of the current selection.
793
+ */
773
794
  getSelectionBoundingBox(): DOMRect | undefined;
774
795
  get isEmpty(): boolean;
775
796
  openSuggestionMenu(triggerCharacter: string, pluginState?: {
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from "prosemirror-state";
2
2
  import * as Y from "yjs";
3
- import type { ThreadStore } from "../comments/index.js";
3
+ import type { ThreadStore, User } from "../comments/index.js";
4
4
  import { BlockNoteDOMAttributes, BlockSchema, BlockSpecs, InlineContentSchema, InlineContentSpecs, StyleSchema, StyleSpecs } from "../schema/index.js";
5
5
  import type { BlockNoteEditor, BlockNoteEditorOptions, SupportedExtension } from "./BlockNoteEditor.js";
6
6
  import { BlockNoteSchema } from "../blocks/BlockNoteSchema.js";
@@ -32,6 +32,7 @@ type ExtensionOptions<BSchema extends BlockSchema, I extends InlineContentSchema
32
32
  comments?: {
33
33
  schema?: BlockNoteSchema<any, any, any>;
34
34
  threadStore: ThreadStore;
35
+ resolveUsers?: (userIds: string[]) => Promise<User[]>;
35
36
  };
36
37
  pasteHandler: BlockNoteEditorOptions<any, any, any>["pasteHandler"];
37
38
  };
@@ -0,0 +1,114 @@
1
+ import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, PartialBlock } from "../../blocks/defaultBlocks.js";
2
+ import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../schema/index.js";
3
+ import { BlockNoteEditor } from "../BlockNoteEditor.js";
4
+ export declare class BlockManager<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> {
5
+ private editor;
6
+ constructor(editor: BlockNoteEditor<BSchema, ISchema, SSchema>);
7
+ /**
8
+ * Gets a snapshot of all top-level (non-nested) blocks in the editor.
9
+ * @returns A snapshot of all top-level (non-nested) blocks in the editor.
10
+ */
11
+ get document(): Block<BSchema, ISchema, SSchema>[];
12
+ /**
13
+ * Gets a snapshot of an existing block from the editor.
14
+ * @param blockIdentifier The identifier of an existing block that should be
15
+ * retrieved.
16
+ * @returns The block that matches the identifier, or `undefined` if no
17
+ * matching block was found.
18
+ */
19
+ getBlock(blockIdentifier: BlockIdentifier): Block<BSchema, ISchema, SSchema> | undefined;
20
+ /**
21
+ * Gets a snapshot of the previous sibling of an existing block from the
22
+ * editor.
23
+ * @param blockIdentifier The identifier of an existing block for which the
24
+ * previous sibling should be retrieved.
25
+ * @returns The previous sibling of the block that matches the identifier.
26
+ * `undefined` if no matching block was found, or it's the first child/block
27
+ * in the document.
28
+ */
29
+ getPrevBlock(blockIdentifier: BlockIdentifier): Block<BSchema, ISchema, SSchema> | undefined;
30
+ /**
31
+ * Gets a snapshot of the next sibling of an existing block from the editor.
32
+ * @param blockIdentifier The identifier of an existing block for which the
33
+ * next sibling should be retrieved.
34
+ * @returns The next sibling of the block that matches the identifier.
35
+ * `undefined` if no matching block was found, or it's the last child/block in
36
+ * the document.
37
+ */
38
+ getNextBlock(blockIdentifier: BlockIdentifier): Block<BSchema, ISchema, SSchema> | undefined;
39
+ /**
40
+ * Gets a snapshot of the parent of an existing block from the editor.
41
+ * @param blockIdentifier The identifier of an existing block for which the
42
+ * parent should be retrieved.
43
+ * @returns The parent of the block that matches the identifier. `undefined`
44
+ * if no matching block was found, or the block isn't nested.
45
+ */
46
+ getParentBlock(blockIdentifier: BlockIdentifier): Block<BSchema, ISchema, SSchema> | undefined;
47
+ /**
48
+ * Traverses all blocks in the editor depth-first, and executes a callback for each.
49
+ * @param callback The callback to execute for each block. Returning `false` stops the traversal.
50
+ * @param reverse Whether the blocks should be traversed in reverse order.
51
+ */
52
+ forEachBlock(callback: (block: Block<BSchema, ISchema, SSchema>) => boolean, reverse?: boolean): void;
53
+ /**
54
+ * Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
55
+ * error if the reference block could not be found.
56
+ * @param blocksToInsert An array of partial blocks that should be inserted.
57
+ * @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
58
+ * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
59
+ * `referenceBlock`.
60
+ */
61
+ insertBlocks(blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[], referenceBlock: BlockIdentifier, placement?: "before" | "after"): Block<BSchema, ISchema, SSchema>[];
62
+ /**
63
+ * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
64
+ * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
65
+ * not be found.
66
+ * @param blockToUpdate The block that should be updated.
67
+ * @param update A partial block which defines how the existing block should be changed.
68
+ */
69
+ updateBlock(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, ISchema, SSchema>): Block<BSchema, ISchema, SSchema>;
70
+ /**
71
+ * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
72
+ * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
73
+ */
74
+ removeBlocks(blocksToRemove: BlockIdentifier[]): Block<Record<string, import("../../index.js").BlockConfig<string, import("../../index.js").PropSchema, "inline" | "none" | "table">>, InlineContentSchema, StyleSchema>[];
75
+ /**
76
+ * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
77
+ * are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
78
+ * `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
79
+ * @param blocksToRemove An array of blocks that should be replaced.
80
+ * @param blocksToInsert An array of partial blocks to replace the old ones with.
81
+ */
82
+ replaceBlocks(blocksToRemove: BlockIdentifier[], blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]): {
83
+ insertedBlocks: Block<BSchema, ISchema, SSchema>[];
84
+ removedBlocks: Block<BSchema, ISchema, SSchema>[];
85
+ };
86
+ /**
87
+ * Checks if the block containing the text cursor can be nested.
88
+ */
89
+ canNestBlock(): boolean;
90
+ /**
91
+ * Nests the block containing the text cursor into the block above it.
92
+ */
93
+ nestBlock(): void;
94
+ /**
95
+ * Checks if the block containing the text cursor is nested.
96
+ */
97
+ canUnnestBlock(): boolean;
98
+ /**
99
+ * Lifts the block containing the text cursor out of its parent.
100
+ */
101
+ unnestBlock(): void;
102
+ /**
103
+ * Moves the selected blocks up. If the previous block has children, moves
104
+ * them to the end of its children. If there is no previous block, but the
105
+ * current blocks share a common parent, moves them out of & before it.
106
+ */
107
+ moveBlocksUp(): void;
108
+ /**
109
+ * Moves the selected blocks down. If the next block has children, moves
110
+ * them to the start of its children. If there is no next block, but the
111
+ * current blocks share a common parent, moves them out of & after it.
112
+ */
113
+ moveBlocksDown(): void;
114
+ }
@@ -0,0 +1,115 @@
1
+ import * as Y from "yjs";
2
+ import { CommentsPlugin } from "../../extensions/Comments/CommentsPlugin.js";
3
+ import { ForkYDocPlugin } from "../../extensions/Collaboration/ForkYDocPlugin.js";
4
+ import { SyncPlugin } from "../../extensions/Collaboration/SyncPlugin.js";
5
+ import { UndoPlugin } from "../../extensions/Collaboration/UndoPlugin.js";
6
+ import { CursorPlugin } from "../../extensions/Collaboration/CursorPlugin.js";
7
+ import type { ThreadStore, User } from "../../comments/index.js";
8
+ import type { BlockNoteEditor } from "../BlockNoteEditor.js";
9
+ import { CustomBlockNoteSchema } from "../../schema/schema.js";
10
+ export interface CollaborationOptions {
11
+ /**
12
+ * The Yjs XML fragment that's used for collaboration.
13
+ */
14
+ fragment: Y.XmlFragment;
15
+ /**
16
+ * The user info for the current user that's shown to other collaborators.
17
+ */
18
+ user: {
19
+ name: string;
20
+ color: string;
21
+ };
22
+ /**
23
+ * A Yjs provider (used for awareness / cursor information)
24
+ * Can be null for comments-only mode
25
+ */
26
+ provider: any;
27
+ /**
28
+ * Optional function to customize how cursors of users are rendered
29
+ */
30
+ renderCursor?: (user: any) => HTMLElement;
31
+ /**
32
+ * Optional flag to set when the user label should be shown with the default
33
+ * collaboration cursor. Setting to "always" will always show the label,
34
+ * while "activity" will only show the label when the user moves the cursor
35
+ * or types. Defaults to "activity".
36
+ */
37
+ showCursorLabels?: "always" | "activity";
38
+ /**
39
+ * Comments configuration - can be used with or without collaboration
40
+ */
41
+ comments?: {
42
+ schema?: CustomBlockNoteSchema<any, any, any>;
43
+ threadStore: ThreadStore;
44
+ };
45
+ /**
46
+ * Function to resolve user IDs to user objects - required for comments
47
+ */
48
+ resolveUsers?: (userIds: string[]) => Promise<User[]>;
49
+ }
50
+ /**
51
+ * CollaborationManager handles all collaboration-related functionality
52
+ * This manager is completely optional and can be tree-shaken if not used
53
+ */
54
+ export declare class CollaborationManager {
55
+ private editor;
56
+ private options;
57
+ private _commentsPlugin?;
58
+ private _forkYDocPlugin?;
59
+ private _syncPlugin?;
60
+ private _undoPlugin?;
61
+ private _cursorPlugin?;
62
+ constructor(editor: BlockNoteEditor, options: CollaborationOptions);
63
+ /**
64
+ * Get the sync plugin instance
65
+ */
66
+ get syncPlugin(): SyncPlugin | undefined;
67
+ /**
68
+ * Get the undo plugin instance
69
+ */
70
+ get undoPlugin(): UndoPlugin | undefined;
71
+ /**
72
+ * Get the cursor plugin instance
73
+ */
74
+ get cursorPlugin(): CursorPlugin | undefined;
75
+ /**
76
+ * Get the fork YDoc plugin instance
77
+ */
78
+ get forkYDocPlugin(): ForkYDocPlugin | undefined;
79
+ initExtensions(): Record<string, unknown>;
80
+ /**
81
+ * Update the user info for the current user that's shown to other collaborators
82
+ */
83
+ updateUserInfo(user: {
84
+ name: string;
85
+ color: string;
86
+ }): void;
87
+ /**
88
+ * Get the collaboration undo command
89
+ */
90
+ getUndoCommand(): import("prosemirror-state").Command;
91
+ /**
92
+ * Get the collaboration redo command
93
+ */
94
+ getRedoCommand(): import("prosemirror-state").Command;
95
+ /**
96
+ * Check if initial content should be avoided due to collaboration
97
+ */
98
+ shouldAvoidInitialContent(): boolean;
99
+ /**
100
+ * Get the collaboration options
101
+ */
102
+ getOptions(): CollaborationOptions;
103
+ /**
104
+ * Get the comments plugin if available
105
+ */
106
+ get comments(): CommentsPlugin | undefined;
107
+ /**
108
+ * Check if comments are enabled
109
+ */
110
+ get hasComments(): boolean;
111
+ /**
112
+ * Get the resolveUsers function
113
+ */
114
+ get resolveUsers(): ((userIds: string[]) => Promise<User[]>) | undefined;
115
+ }
@@ -0,0 +1,58 @@
1
+ import type { BlockNoteEditor } from "../BlockNoteEditor.js";
2
+ import { type BlocksChanged } from "../../api/getBlocksChangedByTransaction.js";
3
+ import { Transaction } from "prosemirror-state";
4
+ import { EventEmitter } from "../../util/EventEmitter.js";
5
+ /**
6
+ * A function that can be used to unsubscribe from an event.
7
+ */
8
+ export type Unsubscribe = () => void;
9
+ /**
10
+ * EventManager is a class which manages the events of the editor
11
+ */
12
+ export declare class EventManager<Editor extends BlockNoteEditor> extends EventEmitter<{
13
+ onChange: [
14
+ editor: Editor,
15
+ ctx: {
16
+ getChanges(): BlocksChanged<Editor["schema"]["blockSchema"], Editor["schema"]["inlineContentSchema"], Editor["schema"]["styleSchema"]>;
17
+ }
18
+ ];
19
+ onSelectionChange: [ctx: {
20
+ editor: Editor;
21
+ transaction: Transaction;
22
+ }];
23
+ onMount: [ctx: {
24
+ editor: Editor;
25
+ }];
26
+ onUnmount: [ctx: {
27
+ editor: Editor;
28
+ }];
29
+ }> {
30
+ private editor;
31
+ constructor(editor: Editor);
32
+ /**
33
+ * Register a callback that will be called when the editor changes.
34
+ */
35
+ onChange(callback: (editor: Editor, ctx: {
36
+ getChanges(): BlocksChanged<Editor["schema"]["blockSchema"], Editor["schema"]["inlineContentSchema"], Editor["schema"]["styleSchema"]>;
37
+ }) => void): Unsubscribe;
38
+ /**
39
+ * Register a callback that will be called when the selection changes.
40
+ */
41
+ onSelectionChange(callback: (editor: Editor) => void,
42
+ /**
43
+ * If true, the callback will be triggered when the selection changes due to a yjs sync (i.e.: other user was typing)
44
+ */
45
+ includeSelectionChangedByRemote?: boolean): Unsubscribe;
46
+ /**
47
+ * Register a callback that will be called when the editor is mounted.
48
+ */
49
+ onMount(callback: (ctx: {
50
+ editor: Editor;
51
+ }) => void): Unsubscribe;
52
+ /**
53
+ * Register a callback that will be called when the editor is unmounted.
54
+ */
55
+ onUnmount(callback: (ctx: {
56
+ editor: Editor;
57
+ }) => void): Unsubscribe;
58
+ }
@@ -0,0 +1,64 @@
1
+ import { Block, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, PartialBlock } from "../../blocks/defaultBlocks.js";
2
+ import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema/index.js";
3
+ import { BlockNoteEditor } from "../BlockNoteEditor.js";
4
+ export declare class ExportManager<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> {
5
+ private editor;
6
+ constructor(editor: BlockNoteEditor<BSchema, ISchema, SSchema>);
7
+ /**
8
+ * Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
9
+ * items are un-nested in the output HTML.
10
+ *
11
+ * @param blocks An array of blocks that should be serialized into HTML.
12
+ * @returns The blocks, serialized as an HTML string.
13
+ */
14
+ blocksToHTMLLossy(blocks?: PartialBlock<BSchema, ISchema, SSchema>[]): string;
15
+ /**
16
+ * Serializes blocks into an HTML string in the format that would normally be rendered by the editor.
17
+ *
18
+ * Use this method if you want to server-side render HTML (for example, a blog post that has been edited in BlockNote)
19
+ * and serve it to users without loading the editor on the client (i.e.: displaying the blog post)
20
+ *
21
+ * @param blocks An array of blocks that should be serialized into HTML.
22
+ * @returns The blocks, serialized as an HTML string.
23
+ */
24
+ blocksToFullHTML(blocks: PartialBlock<BSchema, ISchema, SSchema>[]): string;
25
+ /**
26
+ * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
27
+ * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
28
+ * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
29
+ * @param html The HTML string to parse blocks from.
30
+ * @returns The blocks parsed from the HTML string.
31
+ */
32
+ tryParseHTMLToBlocks(html: string): Block<BSchema, ISchema, SSchema>[];
33
+ /**
34
+ * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
35
+ * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
36
+ * @param blocks An array of blocks that should be serialized into Markdown.
37
+ * @returns The blocks, serialized as a Markdown string.
38
+ */
39
+ blocksToMarkdownLossy(blocks?: PartialBlock<BSchema, ISchema, SSchema>[]): string;
40
+ /**
41
+ * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
42
+ * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
43
+ * as text.
44
+ * @param markdown The Markdown string to parse blocks from.
45
+ * @returns The blocks parsed from the Markdown string.
46
+ */
47
+ tryParseMarkdownToBlocks(markdown: string): Block<BSchema, ISchema, SSchema>[];
48
+ /**
49
+ * Paste HTML into the editor. Defaults to converting HTML to BlockNote HTML.
50
+ * @param html The HTML to paste.
51
+ * @param raw Whether to paste the HTML as is, or to convert it to BlockNote HTML.
52
+ */
53
+ pasteHTML(html: string, raw?: boolean): void;
54
+ /**
55
+ * Paste text into the editor. Defaults to interpreting text as markdown.
56
+ * @param text The text to paste.
57
+ */
58
+ pasteText(text: string): boolean;
59
+ /**
60
+ * Paste markdown into the editor.
61
+ * @param markdown The markdown to paste.
62
+ */
63
+ pasteMarkdown(markdown: string): void;
64
+ }
@@ -0,0 +1,68 @@
1
+ import { FilePanelProsemirrorPlugin } from "../../extensions/FilePanel/FilePanelPlugin.js";
2
+ import { FormattingToolbarProsemirrorPlugin } from "../../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
3
+ import { LinkToolbarProsemirrorPlugin } from "../../extensions/LinkToolbar/LinkToolbarPlugin.js";
4
+ import { ShowSelectionPlugin } from "../../extensions/ShowSelection/ShowSelectionPlugin.js";
5
+ import { SideMenuProsemirrorPlugin } from "../../extensions/SideMenu/SideMenuPlugin.js";
6
+ import { SuggestionMenuProseMirrorPlugin } from "../../extensions/SuggestionMenu/SuggestionPlugin.js";
7
+ import { TableHandlesProsemirrorPlugin } from "../../extensions/TableHandles/TableHandlesPlugin.js";
8
+ import { BlockNoteExtension } from "../BlockNoteExtension.js";
9
+ import { BlockNoteEditor } from "../BlockNoteEditor.js";
10
+ export declare class ExtensionManager {
11
+ private editor;
12
+ constructor(editor: BlockNoteEditor);
13
+ /**
14
+ * Shorthand to get a typed extension from the editor, by
15
+ * just passing in the extension class.
16
+ *
17
+ * @param ext - The extension class to get
18
+ * @param key - optional, the key of the extension in the extensions object (defaults to the extension name)
19
+ * @returns The extension instance
20
+ */
21
+ extension<T extends BlockNoteExtension>(ext: {
22
+ new (...args: any[]): T;
23
+ } & typeof BlockNoteExtension, key?: string): T;
24
+ /**
25
+ * Get all extensions
26
+ */
27
+ getExtensions(): Record<string, import("../BlockNoteEditor.js").SupportedExtension>;
28
+ /**
29
+ * Get a specific extension by key
30
+ */
31
+ getExtension(key: string): import("../BlockNoteEditor.js").SupportedExtension;
32
+ /**
33
+ * Check if an extension exists
34
+ */
35
+ hasExtension(key: string): boolean;
36
+ /**
37
+ * Get the formatting toolbar plugin
38
+ */
39
+ get formattingToolbar(): FormattingToolbarProsemirrorPlugin;
40
+ /**
41
+ * Get the link toolbar plugin
42
+ */
43
+ get linkToolbar(): LinkToolbarProsemirrorPlugin<any, any, any>;
44
+ /**
45
+ * Get the side menu plugin
46
+ */
47
+ get sideMenu(): SideMenuProsemirrorPlugin<any, any, any>;
48
+ /**
49
+ * Get the suggestion menus plugin
50
+ */
51
+ get suggestionMenus(): SuggestionMenuProseMirrorPlugin<any, any, any>;
52
+ /**
53
+ * Get the file panel plugin (if available)
54
+ */
55
+ get filePanel(): FilePanelProsemirrorPlugin<any, any> | undefined;
56
+ /**
57
+ * Get the table handles plugin (if available)
58
+ */
59
+ get tableHandles(): TableHandlesProsemirrorPlugin<any, any> | undefined;
60
+ /**
61
+ * Get the show selection plugin
62
+ */
63
+ get showSelectionPlugin(): ShowSelectionPlugin;
64
+ /**
65
+ * Check if collaboration is enabled (Yjs or Liveblocks)
66
+ */
67
+ get isCollaborationEnabled(): boolean;
68
+ }