@blocknote/core 0.4.3 → 0.4.4

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.
@@ -1,4 +1,4 @@
1
- import { Block, PartialBlock } from "./extensions/Blocks/api/blockTypes";
1
+ import { Block, BlockIdentifier, PartialBlock } from "./extensions/Blocks/api/blockTypes";
2
2
  import { UiFactories } from "./BlockNoteExtensions";
3
3
  import { BaseSlashMenuItem } from "./extensions/SlashMenu";
4
4
  import { Editor as TiptapEditor } from "@tiptap/core/dist/packages/core/src/Editor";
@@ -10,8 +10,9 @@ export type BlockNoteEditorOptions = {
10
10
  slashCommands: BaseSlashMenuItem[];
11
11
  parentElement: HTMLElement;
12
12
  editorDOMAttributes: Record<string, string>;
13
- onUpdate: (editor: BlockNoteEditor) => void;
14
- onCreate: (editor: BlockNoteEditor) => void;
13
+ onEditorCreate: (editor: BlockNoteEditor) => void;
14
+ onEditorContentChange: (editor: BlockNoteEditor) => void;
15
+ onTextCursorPositionChange: (editor: BlockNoteEditor) => void;
15
16
  _tiptapOptions: any;
16
17
  };
17
18
  export declare class BlockNoteEditor {
@@ -22,75 +23,92 @@ export declare class BlockNoteEditor {
22
23
  get domElement(): HTMLDivElement;
23
24
  constructor(options?: Partial<BlockNoteEditorOptions>);
24
25
  /**
25
- * Gets a list of all top-level blocks that are in the editor.
26
+ * Gets a snapshot of all top-level (non-nested) blocks in the editor.
27
+ * @returns A snapshot of all top-level (non-nested) blocks in the editor.
26
28
  */
27
29
  get topLevelBlocks(): Block[];
28
30
  /**
29
- * Traverses all blocks in the editor, including all nested blocks, and executes a callback for each. The traversal is
30
- * depth-first, which is the same order as blocks appear in the editor by y-coordinate.
31
- * @param callback The callback to execute for each block.
31
+ * Gets a snapshot of an existing block from the editor.
32
+ * @param blockIdentifier The identifier of an existing block that should be retrieved.
33
+ * @returns The block that matches the identifier, or `undefined` if no matching block was found.
34
+ */
35
+ getBlock(blockIdentifier: BlockIdentifier): Block | undefined;
36
+ /**
37
+ * Traverses all blocks in the editor depth-first, and executes a callback for each.
38
+ * @param callback The callback to execute for each block. Returning `false` stops the traversal.
32
39
  * @param reverse Whether the blocks should be traversed in reverse order.
33
40
  */
34
- allBlocks(callback: (block: Block) => void, reverse?: boolean): void;
41
+ forEachBlock(callback: (block: Block) => void, reverse?: boolean): void;
35
42
  /**
36
- * Gets information regarding the position of the text cursor in the editor.
43
+ * Gets a snapshot of the current text cursor position.
44
+ * @returns A snapshot of the current text cursor position.
37
45
  */
38
46
  getTextCursorPosition(): TextCursorPosition;
39
- setTextCursorPosition(block: Block, placement?: "start" | "end"): void;
40
47
  /**
41
- * Inserts multiple blocks before, after, or nested inside an existing block in the editor.
42
- * @param blocksToInsert An array of blocks to insert.
43
- * @param blockToInsertAt An existing block, marking where the new blocks should be inserted at.
44
- * @param placement Determines whether the blocks should be inserted just before, just after, or nested inside the
45
- * existing block.
48
+ * Sets the text cursor position to the start or end of an existing block. Throws an error if the target block could
49
+ * not be found.
50
+ * @param targetBlock The identifier of an existing block that the text cursor should be moved to.
51
+ * @param placement Whether the text cursor should be placed at the start or end of the block.
52
+ */
53
+ setTextCursorPosition(targetBlock: BlockIdentifier, placement?: "start" | "end"): void;
54
+ /**
55
+ * Inserts new blocks into the editor. If a block's `id` is undefined, BlockNote generates one automatically. Throws an
56
+ * error if the reference block could not be found.
57
+ * @param blocksToInsert An array of partial blocks that should be inserted.
58
+ * @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
59
+ * @param placement Whether the blocks should be inserted just before, just after, or nested inside the
60
+ * `referenceBlock`. Inserts the blocks at the start of the existing block's children if "nested" is used.
46
61
  */
47
- insertBlocks(blocksToInsert: PartialBlock[], blockToInsertAt: Block, placement?: "before" | "after" | "nested"): void;
62
+ insertBlocks(blocksToInsert: PartialBlock[], referenceBlock: BlockIdentifier, placement?: "before" | "after" | "nested"): void;
48
63
  /**
49
- * Updates a block in the editor to the given specification.
64
+ * Updates an existing block in the editor. Since updatedBlock is a PartialBlock object, some fields might not be
65
+ * defined. These undefined fields are kept as-is from the existing block. Throws an error if the block to update could
66
+ * not be found.
50
67
  * @param blockToUpdate The block that should be updated.
51
- * @param updatedBlock The specification that the block should be updated to.
68
+ * @param update A partial block which defines how the existing block should be changed.
52
69
  */
53
- updateBlock(blockToUpdate: Block, updatedBlock: PartialBlock): void;
70
+ updateBlock(blockToUpdate: Block, update: PartialBlock): void;
54
71
  /**
55
- * Removes multiple blocks from the editor. Throws an error if any of the blocks could not be found.
56
- * @param blocksToRemove An array of blocks that should be removed.
72
+ * Removes existing blocks from the editor. Throws an error if any of the blocks could not be found.
73
+ * @param blocksToRemove An array of identifiers for existing blocks that should be removed.
57
74
  */
58
75
  removeBlocks(blocksToRemove: Block[]): void;
59
76
  /**
60
- * Replaces multiple blocks in the editor with several other blocks. If the provided blocks to remove are not adjacent
61
- * to each other, the new blocks are inserted at the position of the first block in the array. Throws an error if any
62
- * of the blocks could not be found.
77
+ * Replaces existing blocks in the editor with new blocks. If the blocks that should be removed are not adjacent or
78
+ * are at different nesting levels, `blocksToInsert` will be inserted at the position of the first block in
79
+ * `blocksToRemove`. Throws an error if any of the blocks to remove could not be found.
63
80
  * @param blocksToRemove An array of blocks that should be replaced.
64
- * @param blocksToInsert An array of blocks to replace the old ones with.
81
+ * @param blocksToInsert An array of partial blocks to replace the old ones with.
65
82
  */
66
83
  replaceBlocks(blocksToRemove: Block[], blocksToInsert: PartialBlock[]): void;
67
84
  /**
68
- * Executes a callback function whenever the editor's content changes.
69
- * @param callback The callback function to execute.
70
- */
71
- onContentChange(callback: () => void): void;
72
- /**
73
- * Serializes a list of blocks into an HTML string. The output is not the same as what's rendered by the editor, and
74
- * is simplified in order to better conform to HTML standards. Block structuring elements are removed, children of
75
- * blocks which aren't list items are lifted out of them, and list items blocks are wrapped in `ul`/`ol` tags.
76
- * @param blocks The list of blocks to serialize into HTML.
85
+ * Serializes blocks into an HTML string. To better conform to HTML standards, children of blocks which aren't list
86
+ * items are un-nested in the output HTML.
87
+ * @param blocks An array of blocks that should be serialized into HTML.
88
+ * @returns The blocks, serialized as an HTML string.
77
89
  */
78
90
  blocksToHTML(blocks: Block[]): Promise<string>;
79
91
  /**
80
- * Creates a list of blocks from an HTML string.
81
- * @param htmlString The HTML string to create a list of blocks from.
92
+ * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
93
+ * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
94
+ * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
95
+ * @param html The HTML string to parse blocks from.
96
+ * @returns The blocks parsed from the HTML string.
82
97
  */
83
- HTMLToBlocks(htmlString: string): Promise<Block[]>;
98
+ HTMLToBlocks(html: string): Promise<Block[]>;
84
99
  /**
85
- * Serializes a list of blocks into a Markdown string. The output is simplified as Markdown does not support all
86
- * features of BlockNote. Block structuring elements are removed, children of blocks which aren't list items are
87
- * lifted out of them, and certain styles are removed.
88
- * @param blocks The list of blocks to serialize into Markdown.
100
+ * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
101
+ * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
102
+ * @param blocks An array of blocks that should be serialized into Markdown.
103
+ * @returns The blocks, serialized as a Markdown string.
89
104
  */
90
105
  blocksToMarkdown(blocks: Block[]): Promise<string>;
91
106
  /**
92
- * Creates a list of blocks from a Markdown string.
93
- * @param markdownString The Markdown string to create a list of blocks from.
107
+ * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
108
+ * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
109
+ * as text.
110
+ * @param markdown The Markdown string to parse blocks from.
111
+ * @returns The blocks parsed from the Markdown string.
94
112
  */
95
- markdownToBlocks(markdownString: string): Promise<Block[]>;
113
+ markdownToBlocks(markdown: string): Promise<Block[]>;
96
114
  }
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "prosemirror-model";
2
2
  import { Block } from "../../extensions/Blocks/api/blockTypes";
3
3
  export declare function blocksToHTML(blocks: Block[], schema: Schema): Promise<string>;
4
- export declare function HTMLToBlocks(htmlString: string, schema: Schema): Promise<Block[]>;
4
+ export declare function HTMLToBlocks(html: string, schema: Schema): Promise<Block[]>;
5
5
  export declare function blocksToMarkdown(blocks: Block[], schema: Schema): Promise<string>;
6
- export declare function markdownToBlocks(markdownString: string, schema: Schema): Promise<Block[]>;
6
+ export declare function markdownToBlocks(markdown: string, schema: Schema): Promise<Block[]>;