@blocknote/core 0.33.0 → 0.35.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.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +1822 -1688
- package/dist/blocknote.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +3 -3
- package/src/api/__snapshots__/blocks-indented-changed.json +129 -0
- package/src/api/__snapshots__/blocks-moved-deeper-into-nesting.json +164 -0
- package/src/api/__snapshots__/blocks-moved-multiple-in-same-transaction.json +188 -0
- package/src/api/__snapshots__/blocks-moved-to-different-parent.json +78 -0
- package/src/api/__snapshots__/blocks-moved-to-root-level.json +78 -0
- package/src/api/__snapshots__/blocks-outdented-changed.json +129 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +58 -59
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +12 -1
- package/src/api/nodeUtil.test.ts +228 -1
- package/src/api/nodeUtil.ts +139 -118
- package/src/api/parsers/markdown/detectMarkdown.test.ts +211 -0
- package/src/api/parsers/markdown/detectMarkdown.ts +3 -2
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +2 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +2 -1
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +23 -1
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +2 -0
- package/src/blocks/defaultBlockTypeGuards.ts +30 -0
- package/src/editor/BlockNoteEditor.ts +105 -38
- package/src/editor/BlockNoteExtensions.ts +3 -5
- package/src/exporter/Exporter.ts +2 -0
- package/src/exporter/mapping.ts +1 -0
- package/src/extensions/BlockChange/BlockChangePlugin.ts +66 -0
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +288 -207
- package/src/schema/inlineContent/types.ts +8 -0
- package/types/src/api/nodeUtil.d.ts +19 -21
- package/types/src/api/parsers/markdown/detectMarkdown.test.d.ts +1 -0
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +7 -1
- package/types/src/editor/BlockNoteEditor.d.ts +89 -36
- package/types/src/editor/BlockNoteExtensions.d.ts +0 -1
- package/types/src/exporter/Exporter.d.ts +1 -1
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/BlockChange/BlockChangePlugin.d.ts +15 -0
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +50 -9
- package/types/src/schema/inlineContent/types.d.ts +4 -0
|
@@ -16,31 +16,14 @@ export declare function isNodeBlock(node: Node): boolean;
|
|
|
16
16
|
* This attributes the changes to a specific source.
|
|
17
17
|
*/
|
|
18
18
|
export type BlockChangeSource = {
|
|
19
|
-
/**
|
|
20
|
-
* When an event is triggered by the local user, the source is "local".
|
|
21
|
-
* This is the default source.
|
|
22
|
-
*/
|
|
23
19
|
type: "local";
|
|
24
20
|
} | {
|
|
25
|
-
/**
|
|
26
|
-
* When an event is triggered by a paste operation, the source is "paste".
|
|
27
|
-
*/
|
|
28
21
|
type: "paste";
|
|
29
22
|
} | {
|
|
30
|
-
/**
|
|
31
|
-
* When an event is triggered by a drop operation, the source is "drop".
|
|
32
|
-
*/
|
|
33
23
|
type: "drop";
|
|
34
24
|
} | {
|
|
35
|
-
/**
|
|
36
|
-
* When an event is triggered by an undo or redo operation, the source is "undo" or "redo".
|
|
37
|
-
* @note Y.js undo/redo are not differentiated.
|
|
38
|
-
*/
|
|
39
25
|
type: "undo" | "redo" | "undo-redo";
|
|
40
26
|
} | {
|
|
41
|
-
/**
|
|
42
|
-
* When an event is triggered by a remote user, the source is "remote".
|
|
43
|
-
*/
|
|
44
27
|
type: "yjs-remote";
|
|
45
28
|
};
|
|
46
29
|
export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> = Array<{
|
|
@@ -61,14 +44,29 @@ export type BlocksChanged<BSchema extends BlockSchema = DefaultBlockSchema, ISch
|
|
|
61
44
|
} | {
|
|
62
45
|
type: "update";
|
|
63
46
|
/**
|
|
64
|
-
* The block
|
|
47
|
+
* The previous block.
|
|
48
|
+
*/
|
|
49
|
+
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
50
|
+
} | {
|
|
51
|
+
type: "move";
|
|
52
|
+
/**
|
|
53
|
+
* The affected block.
|
|
54
|
+
*/
|
|
55
|
+
block: Block<BSchema, ISchema, SSchema>;
|
|
56
|
+
/**
|
|
57
|
+
* The block before the move.
|
|
65
58
|
*/
|
|
66
59
|
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
60
|
+
/**
|
|
61
|
+
* The previous parent block (if it existed).
|
|
62
|
+
*/
|
|
63
|
+
prevParent?: Block<BSchema, ISchema, SSchema>;
|
|
64
|
+
/**
|
|
65
|
+
* The current parent block (if it exists).
|
|
66
|
+
*/
|
|
67
|
+
currentParent?: Block<BSchema, ISchema, SSchema>;
|
|
67
68
|
})>;
|
|
68
69
|
/**
|
|
69
70
|
* Get the blocks that were changed by a transaction.
|
|
70
|
-
* @param transaction The transaction to get the changes from.
|
|
71
|
-
* @param editor The editor to get the changes from.
|
|
72
|
-
* @returns The blocks that were changed by the transaction.
|
|
73
71
|
*/
|
|
74
72
|
export declare function getBlocksChangedByTransaction<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(transaction: Transaction, appendedTransactions?: Transaction[]): BlocksChanged<BSchema, ISchema, SSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { CellSelection } from "prosemirror-tables";
|
|
2
2
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
3
|
-
import { BlockFromConfig, BlockSchema, FileBlockConfig, InlineContentSchema, StyleSchema } from "../schema/index.js";
|
|
3
|
+
import { BlockConfig, BlockFromConfig, BlockSchema, FileBlockConfig, InlineContentConfig, InlineContentSchema, StyleSchema } from "../schema/index.js";
|
|
4
4
|
import { Block, DefaultBlockSchema, DefaultInlineContentSchema } from "./defaultBlocks.js";
|
|
5
5
|
import { defaultProps } from "./defaultProps.js";
|
|
6
6
|
import { Selection } from "prosemirror-state";
|
|
7
7
|
export declare function checkDefaultBlockTypeInSchema<BlockType extends keyof DefaultBlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blockType: BlockType, editor: BlockNoteEditor<any, I, S>): editor is BlockNoteEditor<{
|
|
8
8
|
[K in BlockType]: DefaultBlockSchema[BlockType];
|
|
9
9
|
}, I, S>;
|
|
10
|
+
export declare function checkBlockTypeInSchema<BlockType extends string, Config extends BlockConfig>(blockType: BlockType, blockConfig: Config, editor: BlockNoteEditor<any, any, any>): editor is BlockNoteEditor<{
|
|
11
|
+
[T in BlockType]: Config;
|
|
12
|
+
}, any, any>;
|
|
10
13
|
export declare function checkDefaultInlineContentTypeInSchema<InlineContentType extends keyof DefaultInlineContentSchema, B extends BlockSchema, S extends StyleSchema>(inlineContentType: InlineContentType, editor: BlockNoteEditor<B, any, S>): editor is BlockNoteEditor<B, {
|
|
11
14
|
[K in InlineContentType]: DefaultInlineContentSchema[InlineContentType];
|
|
12
15
|
}, S>;
|
|
16
|
+
export declare function checkInlineContentTypeInSchema<InlineContentType extends string, Config extends InlineContentConfig>(inlineContentType: InlineContentType, inlineContentConfig: Config, editor: BlockNoteEditor<any, any, any>): editor is BlockNoteEditor<any, {
|
|
17
|
+
[T in InlineContentType]: Config;
|
|
18
|
+
}, any>;
|
|
13
19
|
export declare function checkBlockIsDefaultType<BlockType extends keyof DefaultBlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blockType: BlockType, block: Block<any, I, S>, editor: BlockNoteEditor<any, I, S>): block is BlockFromConfig<DefaultBlockSchema[BlockType], I, S>;
|
|
14
20
|
export declare function checkBlockIsFileBlock<B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(block: Block<any, I, S>, editor: BlockNoteEditor<B, I, S>): block is BlockFromConfig<FileBlockConfig, I, S>;
|
|
15
21
|
export declare function checkBlockIsFileBlockWithPreview<B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(block: Block<any, I, S>, editor: BlockNoteEditor<B, I, S>): block is BlockFromConfig<FileBlockConfig & {
|
|
@@ -45,8 +45,11 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
45
45
|
animations?: boolean;
|
|
46
46
|
/**
|
|
47
47
|
* When enabled, allows for collaboration between multiple users.
|
|
48
|
+
* See [Real-time Collaboration](https://www.blocknotejs.org/docs/advanced/real-time-collaboration) for more info.
|
|
49
|
+
*
|
|
50
|
+
* @remarks `CollaborationOptions`
|
|
48
51
|
*/
|
|
49
|
-
collaboration
|
|
52
|
+
collaboration?: {
|
|
50
53
|
/**
|
|
51
54
|
* The Yjs XML fragment that's used for collaboration.
|
|
52
55
|
*/
|
|
@@ -78,7 +81,13 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
78
81
|
* Options for code blocks.
|
|
79
82
|
*/
|
|
80
83
|
codeBlock?: CodeBlockOptions;
|
|
81
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for the comments feature, requires a `threadStore`.
|
|
86
|
+
*
|
|
87
|
+
* See [Comments](https://www.blocknotejs.org/docs/features/collaboration/comments) for more info.
|
|
88
|
+
* @remarks `CommentsOptions`
|
|
89
|
+
*/
|
|
90
|
+
comments?: {
|
|
82
91
|
threadStore: ThreadStore;
|
|
83
92
|
};
|
|
84
93
|
/**
|
|
@@ -86,21 +95,34 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
86
95
|
*
|
|
87
96
|
* @default true
|
|
88
97
|
*/
|
|
89
|
-
defaultStyles
|
|
98
|
+
defaultStyles?: boolean;
|
|
90
99
|
/**
|
|
91
100
|
* A dictionary object containing translations for the editor.
|
|
101
|
+
*
|
|
102
|
+
* See [Localization / i18n](https://www.blocknotejs.org/docs/advanced/localization) for more info.
|
|
103
|
+
*
|
|
104
|
+
* @remarks `Dictionary` is a type that contains all the translations for the editor.
|
|
92
105
|
*/
|
|
93
106
|
dictionary?: Dictionary & Record<string, any>;
|
|
94
107
|
/**
|
|
95
108
|
* Disable internal extensions (based on keys / extension name)
|
|
109
|
+
*
|
|
110
|
+
* @note Advanced
|
|
96
111
|
*/
|
|
97
|
-
disableExtensions
|
|
112
|
+
disableExtensions?: string[];
|
|
98
113
|
/**
|
|
99
114
|
* An object containing attributes that should be added to HTML elements of the editor.
|
|
100
115
|
*
|
|
116
|
+
* See [Adding DOM Attributes](https://www.blocknotejs.org/docs/theming#adding-dom-attributes) for more info.
|
|
117
|
+
*
|
|
101
118
|
* @example { editor: { class: "my-editor-class" } }
|
|
119
|
+
* @remarks `Record<string, Record<string, string>>`
|
|
120
|
+
*/
|
|
121
|
+
domAttributes?: Partial<BlockNoteDOMAttributes>;
|
|
122
|
+
/**
|
|
123
|
+
* A replacement indicator to use when dragging and dropping blocks. Uses the [ProseMirror drop cursor](https://github.com/ProseMirror/prosemirror-dropcursor), or a modified version when [Column Blocks](https://www.blocknotejs.org/docs/document-structure#column-blocks) are enabled.
|
|
124
|
+
* @remarks `() => Plugin`
|
|
102
125
|
*/
|
|
103
|
-
domAttributes: Partial<BlockNoteDOMAttributes>;
|
|
104
126
|
dropCursor?: (opts: {
|
|
105
127
|
editor: BlockNoteEditor<NoInfer<BSchema>, NoInfer<ISchema>, NoInfer<SSchema>>;
|
|
106
128
|
color?: string | false;
|
|
@@ -119,15 +141,24 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
119
141
|
levels?: (1 | 2 | 3 | 4 | 5 | 6)[];
|
|
120
142
|
};
|
|
121
143
|
/**
|
|
122
|
-
* The content that should be in the editor when it's created, represented as an array of
|
|
144
|
+
* The content that should be in the editor when it's created, represented as an array of {@link PartialBlock} objects.
|
|
145
|
+
*
|
|
146
|
+
* See [Partial Blocks](https://www.blocknotejs.org/docs/editor-api/manipulating-blocks#partial-blocks) for more info.
|
|
147
|
+
*
|
|
148
|
+
* @remarks `PartialBlock[]`
|
|
123
149
|
*/
|
|
124
|
-
initialContent
|
|
150
|
+
initialContent?: PartialBlock<NoInfer<BSchema>, NoInfer<ISchema>, NoInfer<SSchema>>[];
|
|
125
151
|
/**
|
|
126
152
|
* @deprecated, provide placeholders via dictionary instead
|
|
153
|
+
* @internal
|
|
127
154
|
*/
|
|
128
|
-
placeholders
|
|
155
|
+
placeholders?: Record<string | "default" | "emptyDocument", string | undefined>;
|
|
129
156
|
/**
|
|
130
157
|
* Custom paste handler that can be used to override the default paste behavior.
|
|
158
|
+
*
|
|
159
|
+
* See [Paste Handling](https://www.blocknotejs.org/docs/advanced/paste-handling) for more info.
|
|
160
|
+
*
|
|
161
|
+
* @remarks `PasteHandler`
|
|
131
162
|
* @returns The function should return `true` if the paste event was handled, otherwise it should return `false` if it should be canceled or `undefined` if it should be handled by another handler.
|
|
132
163
|
*
|
|
133
164
|
* @example
|
|
@@ -163,8 +194,19 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
163
194
|
* implementing custom protocols / schemes
|
|
164
195
|
* @returns The URL that's
|
|
165
196
|
*/
|
|
166
|
-
resolveFileUrl
|
|
167
|
-
|
|
197
|
+
resolveFileUrl?: (url: string) => Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* Resolve user information for comments.
|
|
200
|
+
*
|
|
201
|
+
* See [Comments](https://www.blocknotejs.org/docs/features/collaboration/comments) for more info.
|
|
202
|
+
*/
|
|
203
|
+
resolveUsers?: (userIds: string[]) => Promise<User[]>;
|
|
204
|
+
/**
|
|
205
|
+
* The schema of the editor. The schema defines which Blocks, InlineContent, and Styles are available in the editor.
|
|
206
|
+
*
|
|
207
|
+
* See [Custom Schemas](https://www.blocknotejs.org/docs/custom-schemas) for more info.
|
|
208
|
+
* @remarks `BlockNoteSchema`
|
|
209
|
+
*/
|
|
168
210
|
schema: BlockNoteSchema<BSchema, ISchema, SSchema>;
|
|
169
211
|
/**
|
|
170
212
|
* A flag indicating whether to set an HTML ID for every block
|
|
@@ -176,29 +218,18 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
176
218
|
*/
|
|
177
219
|
setIdAttribute?: boolean;
|
|
178
220
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @default "viewport"
|
|
221
|
+
* Determines behavior when pressing Tab (or Shift-Tab) while multiple blocks are selected and a toolbar is open.
|
|
222
|
+
* - `"prefer-navigate-ui"`: Changes focus to the toolbar. User must press Escape to close toolbar before indenting blocks. Better for keyboard accessibility.
|
|
223
|
+
* - `"prefer-indent"`: Always indents selected blocks, regardless of toolbar state. Keyboard navigation of toolbars not possible.
|
|
224
|
+
* @default "prefer-navigate-ui"
|
|
184
225
|
*/
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
Select desired behavior when pressing `Tab` (or `Shift-Tab`). Specifically,
|
|
188
|
-
what should happen when a user has selected multiple blocks while a toolbar
|
|
189
|
-
is open:
|
|
190
|
-
- `"prefer-navigate-ui"`: Change focus to the toolbar. The user needs to
|
|
191
|
-
first press `Escape` to close the toolbar, and can then indent multiple
|
|
192
|
-
blocks. Better for keyboard accessibility.
|
|
193
|
-
- `"prefer-indent"`: Regardless of whether toolbars are open, indent the
|
|
194
|
-
selection of blocks. In this case, it's not possible to navigate toolbars
|
|
195
|
-
with the keyboard.
|
|
196
|
-
|
|
197
|
-
@default "prefer-navigate-ui"
|
|
198
|
-
*/
|
|
199
|
-
tabBehavior: "prefer-navigate-ui" | "prefer-indent";
|
|
226
|
+
tabBehavior?: "prefer-navigate-ui" | "prefer-indent";
|
|
200
227
|
/**
|
|
201
228
|
* Allows enabling / disabling features of tables.
|
|
229
|
+
*
|
|
230
|
+
* See [Tables](https://www.blocknotejs.org/docs/editor-basics/document-structure#tables) for more info.
|
|
231
|
+
*
|
|
232
|
+
* @remarks `TableConfig`
|
|
202
233
|
*/
|
|
203
234
|
tables?: {
|
|
204
235
|
/**
|
|
@@ -226,6 +257,11 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
226
257
|
*/
|
|
227
258
|
headers?: boolean;
|
|
228
259
|
};
|
|
260
|
+
/**
|
|
261
|
+
* An option which user can pass with `false` value to disable the automatic creation of a trailing new block on the next line when the user types or edits any block.
|
|
262
|
+
*
|
|
263
|
+
* @default true
|
|
264
|
+
*/
|
|
229
265
|
trailingBlock?: boolean;
|
|
230
266
|
/**
|
|
231
267
|
* The `uploadFile` method is what the editor uses when files need to be uploaded (for example when selecting an image to upload).
|
|
@@ -235,18 +271,21 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
235
271
|
*
|
|
236
272
|
* @param file The file that should be uploaded.
|
|
237
273
|
* @returns The URL of the uploaded file OR an object containing props that should be set on the file block (such as an id)
|
|
274
|
+
* @remarks `(file: File) => Promise<UploadFileResult>`
|
|
238
275
|
*/
|
|
239
|
-
uploadFile
|
|
276
|
+
uploadFile?: (file: File, blockId?: string) => Promise<string | Record<string, any>>;
|
|
240
277
|
/**
|
|
241
278
|
* additional tiptap options, undocumented
|
|
279
|
+
* @internal
|
|
242
280
|
*/
|
|
243
|
-
_tiptapOptions
|
|
281
|
+
_tiptapOptions?: Partial<EditorOptions>;
|
|
244
282
|
/**
|
|
245
283
|
* (experimental) add extra extensions to the editor
|
|
246
284
|
*
|
|
247
285
|
* @deprecated, should use `extensions` instead
|
|
286
|
+
* @internal
|
|
248
287
|
*/
|
|
249
|
-
_extensions
|
|
288
|
+
_extensions?: Record<string, {
|
|
250
289
|
plugin: Plugin;
|
|
251
290
|
priority?: number;
|
|
252
291
|
} | ((editor: BlockNoteEditor<any, any, any>) => {
|
|
@@ -254,17 +293,20 @@ export type BlockNoteEditorOptions<BSchema extends BlockSchema, ISchema extends
|
|
|
254
293
|
priority?: number;
|
|
255
294
|
})>;
|
|
256
295
|
/**
|
|
257
|
-
* Register
|
|
296
|
+
* Register extensions to the editor.
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
258
299
|
*/
|
|
259
|
-
extensions
|
|
300
|
+
extensions?: Array<BlockNoteExtension | BlockNoteExtensionFactory>;
|
|
260
301
|
/**
|
|
261
302
|
* Boolean indicating whether the editor is in headless mode.
|
|
262
303
|
* Headless mode means we can use features like importing / exporting blocks,
|
|
263
304
|
* but there's no underlying editor (UI) instantiated.
|
|
264
305
|
*
|
|
265
306
|
* You probably don't need to set this manually, but use the `server-util` package instead that uses this option internally
|
|
307
|
+
* @internal
|
|
266
308
|
*/
|
|
267
|
-
_headless
|
|
309
|
+
_headless?: boolean;
|
|
268
310
|
};
|
|
269
311
|
export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> extends EventEmitter<{
|
|
270
312
|
create: void;
|
|
@@ -716,6 +758,17 @@ export declare class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockS
|
|
|
716
758
|
name: string;
|
|
717
759
|
color: string;
|
|
718
760
|
}): void;
|
|
761
|
+
/**
|
|
762
|
+
* Registers a callback which will be called before any change is applied to the editor, allowing you to cancel the change.
|
|
763
|
+
*/
|
|
764
|
+
onBeforeChange(
|
|
765
|
+
/**
|
|
766
|
+
* If the callback returns `false`, the change will be canceled & not applied to the editor.
|
|
767
|
+
*/
|
|
768
|
+
callback: (editor: BlockNoteEditor<BSchema, ISchema, SSchema>, context: {
|
|
769
|
+
getChanges: () => BlocksChanged<BSchema, ISchema, SSchema>;
|
|
770
|
+
tr: Transaction;
|
|
771
|
+
}) => boolean | void): () => void;
|
|
719
772
|
/**
|
|
720
773
|
* A callback function that runs whenever the editor's contents change.
|
|
721
774
|
*
|
|
@@ -28,7 +28,6 @@ type ExtensionOptions<BSchema extends BlockSchema, I extends InlineContentSchema
|
|
|
28
28
|
dropCursor: (opts: any) => Plugin;
|
|
29
29
|
placeholders: Record<string | "default" | "emptyDocument", string | undefined>;
|
|
30
30
|
tabBehavior?: "prefer-navigate-ui" | "prefer-indent";
|
|
31
|
-
sideMenuDetection: "viewport" | "editor";
|
|
32
31
|
comments?: {
|
|
33
32
|
threadStore: ThreadStore;
|
|
34
33
|
};
|
|
@@ -39,5 +39,5 @@ export declare abstract class Exporter<B extends BlockSchema, I extends InlineCo
|
|
|
39
39
|
mapInlineContent(inlineContent: InlineContent<I, S>): RI;
|
|
40
40
|
transformInlineContent(inlineContentArray: InlineContent<I, S>[]): RI[];
|
|
41
41
|
abstract transformStyledText(styledText: StyledText<S>): TS;
|
|
42
|
-
mapBlock(block: BlockFromConfig<B[keyof B], I, S>, nestingLevel: number, numberedListIndex: number): Promise<RB>;
|
|
42
|
+
mapBlock(block: BlockFromConfig<B[keyof B], I, S>, nestingLevel: number, numberedListIndex: number, children?: Array<Awaited<RB>>): Promise<RB>;
|
|
43
43
|
}
|
|
@@ -5,7 +5,7 @@ import type { Exporter } from "./Exporter.js";
|
|
|
5
5
|
* Defines a mapping from all block types with a schema to a result type `R`.
|
|
6
6
|
*/
|
|
7
7
|
export type BlockMapping<B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema, RB, RI> = {
|
|
8
|
-
[K in keyof B]: (block: BlockFromConfigNoChildren<B[K], I, S>, exporter: Exporter<any, any, any, RB, RI, any, any>, nestingLevel: number, numberedListIndex?: number) => RB | Promise<RB>;
|
|
8
|
+
[K in keyof B]: (block: BlockFromConfigNoChildren<B[K], I, S>, exporter: Exporter<any, any, any, RB, RI, any, any>, nestingLevel: number, numberedListIndex?: number, children?: Array<Awaited<RB>>) => RB | Promise<RB>;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Defines a mapping from all inline content types with a schema to a result type R.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transaction } from "prosemirror-state";
|
|
2
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
3
|
+
import { BlocksChanged } from "../../index.js";
|
|
4
|
+
/**
|
|
5
|
+
* This plugin can filter transactions before they are applied to the editor, but with a higher-level API than `filterTransaction` from prosemirror.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BlockChangePlugin extends BlockNoteExtension {
|
|
8
|
+
static key(): string;
|
|
9
|
+
private beforeChangeCallbacks;
|
|
10
|
+
constructor();
|
|
11
|
+
subscribe(callback: (context: {
|
|
12
|
+
getChanges: () => BlocksChanged<any, any, any>;
|
|
13
|
+
tr: Transaction;
|
|
14
|
+
}) => boolean | void): () => void;
|
|
15
|
+
}
|
|
@@ -13,7 +13,6 @@ export type SideMenuState<BSchema extends BlockSchema, I extends InlineContentSc
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class SideMenuView<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> implements PluginView {
|
|
15
15
|
private readonly editor;
|
|
16
|
-
private readonly sideMenuDetection;
|
|
17
16
|
private readonly pmView;
|
|
18
17
|
state?: SideMenuState<BSchema, I, S>;
|
|
19
18
|
readonly emitUpdate: (state: SideMenuState<BSchema, I, S>) => void;
|
|
@@ -21,11 +20,9 @@ export declare class SideMenuView<BSchema extends BlockSchema, I extends InlineC
|
|
|
21
20
|
private hoveredBlock;
|
|
22
21
|
menuFrozen: boolean;
|
|
23
22
|
isDragOrigin: boolean;
|
|
24
|
-
constructor(editor: BlockNoteEditor<BSchema, I, S>,
|
|
23
|
+
constructor(editor: BlockNoteEditor<BSchema, I, S>, pmView: EditorView, emitUpdate: (state: SideMenuState<BSchema, I, S>) => void);
|
|
25
24
|
updateState: (state: SideMenuState<BSchema, I, S>) => void;
|
|
26
25
|
updateStateFromMousePos: () => void;
|
|
27
|
-
onDrop: (event: DragEvent) => void;
|
|
28
|
-
onDragEnd: () => void;
|
|
29
26
|
/**
|
|
30
27
|
* If a block is being dragged, ProseMirror usually gets the context of what's
|
|
31
28
|
* being dragged from `view.dragging`, which is automatically set when a
|
|
@@ -46,14 +43,58 @@ export declare class SideMenuView<BSchema extends BlockSchema, I extends InlineC
|
|
|
46
43
|
*/
|
|
47
44
|
onDragStart: (event: DragEvent) => void;
|
|
48
45
|
/**
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
* Finds the closest editor visually to the given coordinates
|
|
47
|
+
*/
|
|
48
|
+
private findClosestEditorElement;
|
|
49
|
+
/**
|
|
50
|
+
* This dragover event handler listens at the document level,
|
|
51
|
+
* and is trying to handle dragover events for all editors.
|
|
52
|
+
*
|
|
53
|
+
* It specifically is trying to handle the following cases:
|
|
54
|
+
* - If the dragover event is within the bounds of any editor, then it does nothing
|
|
55
|
+
* - If the dragover event is outside the bounds of any editor, but close enough (within DISTANCE_TO_CONSIDER_EDITOR_BOUNDS) to the closest editor,
|
|
56
|
+
* then it dispatches a synthetic dragover event to the closest editor (which will trigger the drop-cursor to be shown on that editor)
|
|
57
|
+
* - If the dragover event is outside the bounds of the current editor, then it will dispatch a synthetic dragleave event to the current editor
|
|
58
|
+
* (which will trigger the drop-cursor to be removed from the current editor)
|
|
59
|
+
*
|
|
60
|
+
* The synthetic event is a necessary evil because we do not control prosemirror-dropcursor to be able to show the drop-cursor within the range we want
|
|
52
61
|
*/
|
|
53
62
|
onDragOver: (event: DragEvent) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Closes the drop-cursor for the current editor
|
|
65
|
+
*/
|
|
66
|
+
private closeDropCursor;
|
|
67
|
+
/**
|
|
68
|
+
* It is surprisingly difficult to determine the information we need to know about a drag event
|
|
69
|
+
*
|
|
70
|
+
* This function is trying to determine the following:
|
|
71
|
+
* - Whether the current editor instance is the drop point
|
|
72
|
+
* - Whether the current editor instance is the drag origin
|
|
73
|
+
* - Whether the drop event is within the bounds of the current editor instance
|
|
74
|
+
*/
|
|
75
|
+
getDragEventContext: (event: DragEvent) => {
|
|
76
|
+
isDropPoint: boolean;
|
|
77
|
+
isDropWithinEditorBounds: boolean;
|
|
78
|
+
isDragOrigin: boolean;
|
|
79
|
+
} | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The drop event handler listens at the document level,
|
|
82
|
+
* and handles drop events for all editors.
|
|
83
|
+
*
|
|
84
|
+
* It specifically handles the following cases:
|
|
85
|
+
* - If we are both the drag origin and drop point:
|
|
86
|
+
* - Let normal drop handling take over
|
|
87
|
+
* - If we are the drop point but not the drag origin:
|
|
88
|
+
* - Collapse selection to prevent PM from deleting unrelated content
|
|
89
|
+
* - If drop event is outside our editor bounds, dispatch synthetic drop event to our editor
|
|
90
|
+
* - If we are the drag origin but not the drop point:
|
|
91
|
+
* - Delete the dragged content from our editor after a delay
|
|
92
|
+
*/
|
|
93
|
+
onDrop: (event: DragEvent) => void;
|
|
94
|
+
onDragEnd: (event: DragEvent) => void;
|
|
54
95
|
onKeyDown: (_event: KeyboardEvent) => void;
|
|
55
96
|
onMouseMove: (event: MouseEvent) => void;
|
|
56
|
-
private
|
|
97
|
+
private dispatchSyntheticEvent;
|
|
57
98
|
onScroll: () => void;
|
|
58
99
|
update(_view: EditorView, prevState: EditorState): void;
|
|
59
100
|
destroy(): void;
|
|
@@ -63,7 +104,7 @@ export declare class SideMenuProsemirrorPlugin<BSchema extends BlockSchema, I ex
|
|
|
63
104
|
private readonly editor;
|
|
64
105
|
static key(): string;
|
|
65
106
|
view: SideMenuView<BSchema, I, S> | undefined;
|
|
66
|
-
constructor(editor: BlockNoteEditor<BSchema, I, S
|
|
107
|
+
constructor(editor: BlockNoteEditor<BSchema, I, S>);
|
|
67
108
|
onUpdate(callback: (state: SideMenuState<BSchema, I, S>) => void): () => void;
|
|
68
109
|
/**
|
|
69
110
|
* Handles drag & drop events for blocks.
|
|
@@ -4,12 +4,16 @@ import { StyleSchema, Styles } from "../styles/types.js";
|
|
|
4
4
|
export type CustomInlineContentConfig = {
|
|
5
5
|
type: string;
|
|
6
6
|
content: "styled" | "none";
|
|
7
|
+
draggable?: boolean;
|
|
7
8
|
readonly propSchema: PropSchema;
|
|
8
9
|
};
|
|
9
10
|
export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
|
|
10
11
|
export type InlineContentImplementation<T extends InlineContentConfig> = T extends "link" | "text" ? undefined : {
|
|
11
12
|
node: Node;
|
|
12
13
|
};
|
|
14
|
+
export type InlineContentSchemaWithInlineContent<IType extends string, C extends InlineContentConfig> = {
|
|
15
|
+
[k in IType]: C;
|
|
16
|
+
};
|
|
13
17
|
export type InlineContentSpec<T extends InlineContentConfig> = {
|
|
14
18
|
config: T;
|
|
15
19
|
implementation: InlineContentImplementation<T>;
|