@blocknote/core 0.11.1 → 0.12.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/README.md +13 -17
- package/dist/blocknote.js +1611 -1408
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +8 -4
- package/src/api/blockManipulation/blockManipulation.test.ts +19 -15
- package/src/api/blockManipulation/blockManipulation.ts +107 -17
- package/src/api/exporters/html/externalHTMLExporter.ts +3 -7
- package/src/api/exporters/html/htmlConversion.test.ts +6 -3
- package/src/api/exporters/html/internalHTMLSerializer.ts +3 -7
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +3 -3
- package/src/api/exporters/markdown/markdownExporter.test.ts +7 -3
- package/src/api/exporters/markdown/markdownExporter.ts +2 -6
- package/src/api/nodeConversions/nodeConversions.test.ts +14 -7
- package/src/api/nodeConversions/nodeConversions.ts +1 -2
- package/src/api/parsers/html/parseHTML.test.ts +5 -1
- package/src/api/parsers/html/parseHTML.ts +2 -6
- package/src/api/parsers/html/util/nestedLists.ts +11 -1
- package/src/api/parsers/markdown/parseMarkdown.test.ts +3 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +2 -6
- package/src/api/testUtil/cases/customBlocks.ts +18 -16
- package/src/api/testUtil/cases/customInlineContent.ts +12 -13
- package/src/api/testUtil/cases/customStyles.ts +12 -10
- package/src/api/testUtil/index.ts +4 -2
- package/src/api/testUtil/partialBlockTestUtil.ts +2 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +1 -2
- package/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +8 -1
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +13 -0
- package/src/blocks/defaultBlockHelpers.ts +3 -3
- package/src/blocks/defaultBlockTypeGuards.ts +84 -0
- package/src/blocks/defaultBlocks.ts +29 -3
- package/src/editor/Block.css +2 -31
- package/src/editor/BlockNoteEditor.ts +219 -263
- package/src/editor/BlockNoteExtensions.ts +5 -2
- package/src/editor/BlockNoteSchema.ts +98 -0
- package/src/editor/BlockNoteTipTapEditor.ts +162 -0
- package/src/editor/cursorPositionTypes.ts +2 -6
- package/src/editor/editor.css +0 -1
- package/src/editor/selectionTypes.ts +2 -6
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +22 -29
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +26 -27
- package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +45 -51
- package/src/extensions/Placeholder/PlaceholderExtension.ts +81 -88
- package/src/extensions/SideMenu/SideMenuPlugin.ts +55 -56
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +8 -0
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +353 -0
- package/src/extensions/{SlashMenu/defaultSlashMenuItems.ts → SuggestionMenu/getDefaultSlashMenuItems.ts} +119 -89
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +62 -45
- package/src/extensions-shared/UiElementPosition.ts +4 -0
- package/src/index.ts +6 -6
- package/src/pm-nodes/BlockContainer.ts +5 -9
- package/src/schema/blocks/types.ts +15 -15
- package/src/schema/inlineContent/createSpec.ts +2 -2
- package/src/schema/inlineContent/types.ts +1 -1
- package/src/util/browser.ts +6 -4
- package/src/util/typescript.ts +7 -4
- package/types/src/api/blockManipulation/blockManipulation.d.ts +6 -1
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +2 -1
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +2 -1
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +2 -1
- package/types/src/api/nodeConversions/nodeConversions.d.ts +2 -1
- package/types/src/api/parsers/html/parseHTML.d.ts +2 -1
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -1
- package/types/src/api/testUtil/cases/customBlocks.d.ts +72 -13
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +281 -6
- package/types/src/api/testUtil/cases/customStyles.d.ts +247 -13
- package/types/src/api/testUtil/index.d.ts +4 -2
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +2 -1
- package/types/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +6 -1
- package/types/src/blocks/defaultBlockHelpers.d.ts +2 -2
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +24 -0
- package/types/src/blocks/defaultBlocks.d.ts +21 -15
- package/types/src/editor/BlockNoteEditor.d.ts +48 -53
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -0
- package/types/src/editor/BlockNoteSchema.d.ts +34 -0
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +28 -0
- package/types/src/editor/cursorPositionTypes.d.ts +2 -1
- package/types/src/editor/selectionTypes.d.ts +2 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -6
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +2 -2
- package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +15 -14
- package/types/src/extensions/Placeholder/PlaceholderExtension.d.ts +2 -15
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +8 -7
- package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +8 -0
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +31 -0
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +10 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +7 -7
- package/types/src/extensions-shared/UiElementPosition.d.ts +4 -0
- package/types/src/index.d.ts +6 -6
- package/types/src/pm-nodes/BlockContainer.d.ts +3 -2
- package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
- package/types/src/schema/blocks/types.d.ts +15 -15
- package/types/src/schema/inlineContent/types.d.ts +1 -1
- package/types/src/util/browser.d.ts +1 -0
- package/types/src/util/typescript.d.ts +1 -0
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +0 -12
- package/src/extensions/SlashMenu/SlashMenuPlugin.ts +0 -53
- package/src/extensions-shared/BaseUiElementTypes.ts +0 -8
- package/src/extensions-shared/README.md +0 -3
- package/src/extensions-shared/suggestion/SuggestionItem.ts +0 -3
- package/src/extensions-shared/suggestion/SuggestionPlugin.ts +0 -448
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +0 -7
- package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +0 -13
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +0 -3
- package/types/src/extensions-shared/BaseUiElementTypes.d.ts +0 -7
- package/types/src/extensions-shared/suggestion/SuggestionItem.d.ts +0 -3
- package/types/src/extensions-shared/suggestion/SuggestionPlugin.d.ts +0 -36
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-100.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-100.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-200.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-200.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-300.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-300.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-500.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-500.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-600.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-600.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-700.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-700.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-800.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-800.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-900.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-900.woff2 +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-regular.woff +0 -0
- /package/src/{assets → fonts}/inter-v12-latin/inter-v12-latin-regular.woff2 +0 -0
- /package/src/{assets/fonts-inter.css → fonts/inter.css} +0 -0
|
@@ -1,42 +1,20 @@
|
|
|
1
1
|
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
3
|
-
import { EventEmitter } from "../../util/EventEmitter";
|
|
4
3
|
import { nodeToBlock } from "../../api/nodeConversions/nodeConversions";
|
|
5
|
-
import { DefaultBlockSchema } from "../../blocks/defaultBlocks";
|
|
4
|
+
import { Block, DefaultBlockSchema } from "../../blocks/defaultBlocks";
|
|
6
5
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
7
6
|
import {
|
|
8
|
-
Block,
|
|
9
7
|
BlockFromConfigNoChildren,
|
|
10
8
|
BlockSchemaWithBlock,
|
|
11
9
|
InlineContentSchema,
|
|
12
|
-
PartialBlock,
|
|
13
10
|
SpecificBlock,
|
|
14
11
|
StyleSchema,
|
|
15
12
|
} from "../../schema";
|
|
13
|
+
import { EventEmitter } from "../../util/EventEmitter";
|
|
16
14
|
import { getDraggableBlockFromCoords } from "../SideMenu/SideMenuPlugin";
|
|
17
15
|
|
|
18
16
|
let dragImageElement: HTMLElement | undefined;
|
|
19
17
|
|
|
20
|
-
function setHiddenDragImage() {
|
|
21
|
-
if (dragImageElement) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
dragImageElement = document.createElement("div");
|
|
26
|
-
dragImageElement.innerHTML = "_";
|
|
27
|
-
dragImageElement.style.opacity = "0";
|
|
28
|
-
dragImageElement.style.height = "1px";
|
|
29
|
-
dragImageElement.style.width = "1px";
|
|
30
|
-
document.body.appendChild(dragImageElement);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function unsetHiddenDragImage() {
|
|
34
|
-
if (dragImageElement) {
|
|
35
|
-
document.body.removeChild(dragImageElement);
|
|
36
|
-
dragImageElement = undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
18
|
export type TableHandlesState<
|
|
41
19
|
I extends InlineContentSchema,
|
|
42
20
|
S extends StyleSchema
|
|
@@ -58,6 +36,26 @@ export type TableHandlesState<
|
|
|
58
36
|
| undefined;
|
|
59
37
|
};
|
|
60
38
|
|
|
39
|
+
function setHiddenDragImage() {
|
|
40
|
+
if (dragImageElement) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dragImageElement = document.createElement("div");
|
|
45
|
+
dragImageElement.innerHTML = "_";
|
|
46
|
+
dragImageElement.style.opacity = "0";
|
|
47
|
+
dragImageElement.style.height = "1px";
|
|
48
|
+
dragImageElement.style.width = "1px";
|
|
49
|
+
document.body.appendChild(dragImageElement);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function unsetHiddenDragImage() {
|
|
53
|
+
if (dragImageElement) {
|
|
54
|
+
document.body.removeChild(dragImageElement);
|
|
55
|
+
dragImageElement = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
61
59
|
function getChildIndex(node: Element) {
|
|
62
60
|
return Array.prototype.indexOf.call(node.parentElement!.childNodes, node);
|
|
63
61
|
}
|
|
@@ -91,7 +89,7 @@ export class TableHandlesView<
|
|
|
91
89
|
> implements PluginView
|
|
92
90
|
{
|
|
93
91
|
public state?: TableHandlesState<I, S>;
|
|
94
|
-
public
|
|
92
|
+
public emitUpdate: () => void;
|
|
95
93
|
|
|
96
94
|
public tableId: string | undefined;
|
|
97
95
|
public tablePos: number | undefined;
|
|
@@ -101,16 +99,20 @@ export class TableHandlesView<
|
|
|
101
99
|
public prevWasEditable: boolean | null = null;
|
|
102
100
|
|
|
103
101
|
constructor(
|
|
104
|
-
private readonly editor: BlockNoteEditor<
|
|
102
|
+
private readonly editor: BlockNoteEditor<
|
|
103
|
+
BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
104
|
+
I,
|
|
105
|
+
S
|
|
106
|
+
>,
|
|
105
107
|
private readonly pmView: EditorView,
|
|
106
|
-
|
|
108
|
+
emitUpdate: (state: TableHandlesState<I, S>) => void
|
|
107
109
|
) {
|
|
108
|
-
this.
|
|
110
|
+
this.emitUpdate = () => {
|
|
109
111
|
if (!this.state) {
|
|
110
112
|
throw new Error("Attempting to update uninitialized image toolbar");
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
emitUpdate(this.state);
|
|
114
116
|
};
|
|
115
117
|
|
|
116
118
|
pmView.dom.addEventListener("mousemove", this.mouseMoveHandler);
|
|
@@ -131,7 +133,7 @@ export class TableHandlesView<
|
|
|
131
133
|
if (!target || !this.editor.isEditable) {
|
|
132
134
|
if (this.state?.show) {
|
|
133
135
|
this.state.show = false;
|
|
134
|
-
this.
|
|
136
|
+
this.emitUpdate();
|
|
135
137
|
}
|
|
136
138
|
return;
|
|
137
139
|
}
|
|
@@ -175,9 +177,9 @@ export class TableHandlesView<
|
|
|
175
177
|
|
|
176
178
|
block = nodeToBlock(
|
|
177
179
|
node,
|
|
178
|
-
this.editor.blockSchema,
|
|
179
|
-
this.editor.inlineContentSchema,
|
|
180
|
-
this.editor.styleSchema,
|
|
180
|
+
this.editor.schema.blockSchema,
|
|
181
|
+
this.editor.schema.inlineContentSchema,
|
|
182
|
+
this.editor.schema.styleSchema,
|
|
181
183
|
this.editor.blockCache
|
|
182
184
|
);
|
|
183
185
|
this.tablePos = pos + 1;
|
|
@@ -196,7 +198,7 @@ export class TableHandlesView<
|
|
|
196
198
|
|
|
197
199
|
draggingState: undefined,
|
|
198
200
|
};
|
|
199
|
-
this.
|
|
201
|
+
this.emitUpdate();
|
|
200
202
|
|
|
201
203
|
return false;
|
|
202
204
|
};
|
|
@@ -286,7 +288,7 @@ export class TableHandlesView<
|
|
|
286
288
|
|
|
287
289
|
// Emits a state update if any of the fields have changed.
|
|
288
290
|
if (emitStateUpdate) {
|
|
289
|
-
this.
|
|
291
|
+
this.emitUpdate();
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
// Dispatches a dummy transaction to force a decorations update if
|
|
@@ -327,7 +329,7 @@ export class TableHandlesView<
|
|
|
327
329
|
type: "tableContent",
|
|
328
330
|
rows: rows,
|
|
329
331
|
},
|
|
330
|
-
}
|
|
332
|
+
});
|
|
331
333
|
};
|
|
332
334
|
|
|
333
335
|
scrollHandler = () => {
|
|
@@ -343,7 +345,7 @@ export class TableHandlesView<
|
|
|
343
345
|
|
|
344
346
|
this.state.referencePosTable = tableElement.getBoundingClientRect();
|
|
345
347
|
this.state.referencePosCell = cellElement.getBoundingClientRect();
|
|
346
|
-
this.
|
|
348
|
+
this.emitUpdate();
|
|
347
349
|
}
|
|
348
350
|
};
|
|
349
351
|
|
|
@@ -360,14 +362,25 @@ export class TableHandlesView<
|
|
|
360
362
|
export const tableHandlesPluginKey = new PluginKey("TableHandlesPlugin");
|
|
361
363
|
|
|
362
364
|
export class TableHandlesProsemirrorPlugin<
|
|
363
|
-
BSchema extends BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
364
365
|
I extends InlineContentSchema,
|
|
365
366
|
S extends StyleSchema
|
|
366
367
|
> extends EventEmitter<any> {
|
|
367
|
-
private view:
|
|
368
|
+
private view:
|
|
369
|
+
| TableHandlesView<
|
|
370
|
+
BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
371
|
+
I,
|
|
372
|
+
S
|
|
373
|
+
>
|
|
374
|
+
| undefined;
|
|
368
375
|
public readonly plugin: Plugin;
|
|
369
376
|
|
|
370
|
-
constructor(
|
|
377
|
+
constructor(
|
|
378
|
+
private readonly editor: BlockNoteEditor<
|
|
379
|
+
BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
380
|
+
I,
|
|
381
|
+
S
|
|
382
|
+
>
|
|
383
|
+
) {
|
|
371
384
|
super();
|
|
372
385
|
this.plugin = new Plugin({
|
|
373
386
|
key: tableHandlesPluginKey,
|
|
@@ -531,7 +544,7 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
531
544
|
originalIndex: this.view!.state.colIndex,
|
|
532
545
|
mousePos: event.clientX,
|
|
533
546
|
};
|
|
534
|
-
this.view!.
|
|
547
|
+
this.view!.emitUpdate();
|
|
535
548
|
|
|
536
549
|
this.editor._tiptapEditor.view.dispatch(
|
|
537
550
|
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, {
|
|
@@ -567,7 +580,7 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
567
580
|
originalIndex: this.view!.state.rowIndex,
|
|
568
581
|
mousePos: event.clientY,
|
|
569
582
|
};
|
|
570
|
-
this.view!.
|
|
583
|
+
this.view!.emitUpdate();
|
|
571
584
|
|
|
572
585
|
this.editor._tiptapEditor.view.dispatch(
|
|
573
586
|
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, {
|
|
@@ -596,7 +609,7 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
596
609
|
}
|
|
597
610
|
|
|
598
611
|
this.view!.state.draggingState = undefined;
|
|
599
|
-
this.view!.
|
|
612
|
+
this.view!.emitUpdate();
|
|
600
613
|
|
|
601
614
|
this.editor._tiptapEditor.view.dispatch(
|
|
602
615
|
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, null)
|
|
@@ -609,11 +622,15 @@ export class TableHandlesProsemirrorPlugin<
|
|
|
609
622
|
* Freezes the drag handles. When frozen, they will stay attached to the same
|
|
610
623
|
* cell regardless of which cell is hovered by the mouse cursor.
|
|
611
624
|
*/
|
|
612
|
-
freezeHandles = () =>
|
|
625
|
+
freezeHandles = () => {
|
|
626
|
+
this.view!.menuFrozen = true;
|
|
627
|
+
};
|
|
613
628
|
|
|
614
629
|
/**
|
|
615
630
|
* Unfreezes the drag handles. When frozen, they will stay attached to the
|
|
616
631
|
* same cell regardless of which cell is hovered by the mouse cursor.
|
|
617
632
|
*/
|
|
618
|
-
unfreezeHandles = () =>
|
|
633
|
+
unfreezeHandles = () => {
|
|
634
|
+
this.view!.menuFrozen = false;
|
|
635
|
+
};
|
|
619
636
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,21 +2,21 @@ export * from "./api/exporters/html/externalHTMLExporter";
|
|
|
2
2
|
export * from "./api/exporters/html/internalHTMLSerializer";
|
|
3
3
|
export * from "./api/testUtil";
|
|
4
4
|
export * from "./blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY";
|
|
5
|
+
export * from "./blocks/defaultBlockTypeGuards";
|
|
5
6
|
export * from "./blocks/defaultBlocks";
|
|
6
7
|
export * from "./blocks/defaultProps";
|
|
7
8
|
export * from "./editor/BlockNoteEditor";
|
|
8
9
|
export * from "./editor/BlockNoteExtensions";
|
|
10
|
+
export * from "./editor/BlockNoteSchema";
|
|
9
11
|
export * from "./editor/selectionTypes";
|
|
10
|
-
export * from "./extensions-shared/
|
|
11
|
-
export type { SuggestionItem } from "./extensions-shared/suggestion/SuggestionItem";
|
|
12
|
-
export * from "./extensions-shared/suggestion/SuggestionPlugin";
|
|
12
|
+
export * from "./extensions-shared/UiElementPosition";
|
|
13
13
|
export * from "./extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
14
14
|
export * from "./extensions/HyperlinkToolbar/HyperlinkToolbarPlugin";
|
|
15
15
|
export * from "./extensions/ImageToolbar/ImageToolbarPlugin";
|
|
16
16
|
export * from "./extensions/SideMenu/SideMenuPlugin";
|
|
17
|
-
export * from "./extensions/
|
|
18
|
-
export * from "./extensions/
|
|
19
|
-
export
|
|
17
|
+
export * from "./extensions/SuggestionMenu/DefaultSuggestionItem";
|
|
18
|
+
export * from "./extensions/SuggestionMenu/SuggestionPlugin";
|
|
19
|
+
export * from "./extensions/SuggestionMenu/getDefaultSlashMenuItems";
|
|
20
20
|
export * from "./extensions/TableHandles/TableHandlesPlugin";
|
|
21
21
|
export * from "./schema";
|
|
22
22
|
export * from "./util/browser";
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
inlineContentToNodes,
|
|
9
9
|
tableContentToNodes,
|
|
10
10
|
} from "../api/nodeConversions/nodeConversions";
|
|
11
|
+
import { PartialBlock } from "../blocks/defaultBlocks";
|
|
11
12
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor";
|
|
12
13
|
import { NonEditableBlockPlugin } from "../extensions/NonEditableBlocks/NonEditableBlockPlugin";
|
|
13
14
|
import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin";
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
BlockNoteDOMAttributes,
|
|
16
17
|
BlockSchema,
|
|
17
18
|
InlineContentSchema,
|
|
18
|
-
PartialBlock,
|
|
19
19
|
StyleSchema,
|
|
20
20
|
} from "../schema";
|
|
21
21
|
import { mergeCSSClasses } from "../util/browser";
|
|
@@ -109,7 +109,7 @@ export const BlockContainer = Node.create<{
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
const blockHTMLAttributes = {
|
|
112
|
-
...(this.options.domAttributes?.
|
|
112
|
+
...(this.options.domAttributes?.block || {}),
|
|
113
113
|
...HTMLAttributes,
|
|
114
114
|
};
|
|
115
115
|
const block = document.createElement("div");
|
|
@@ -183,7 +183,7 @@ export const BlockContainer = Node.create<{
|
|
|
183
183
|
blockToNode(
|
|
184
184
|
child,
|
|
185
185
|
state.schema,
|
|
186
|
-
this.options.editor.styleSchema
|
|
186
|
+
this.options.editor.schema.styleSchema
|
|
187
187
|
)
|
|
188
188
|
);
|
|
189
189
|
}
|
|
@@ -223,13 +223,13 @@ export const BlockContainer = Node.create<{
|
|
|
223
223
|
content = inlineContentToNodes(
|
|
224
224
|
block.content,
|
|
225
225
|
state.schema,
|
|
226
|
-
this.options.editor.styleSchema
|
|
226
|
+
this.options.editor.schema.styleSchema
|
|
227
227
|
);
|
|
228
228
|
} else if (block.content.type === "tableContent") {
|
|
229
229
|
content = tableContentToNodes(
|
|
230
230
|
block.content,
|
|
231
231
|
state.schema,
|
|
232
|
-
this.options.editor.styleSchema
|
|
232
|
+
this.options.editor.schema.styleSchema
|
|
233
233
|
);
|
|
234
234
|
} else {
|
|
235
235
|
throw new UnreachableCaseError(block.content.type);
|
|
@@ -693,10 +693,6 @@ export const BlockContainer = Node.create<{
|
|
|
693
693
|
this.editor.commands.liftListItem("blockContainer");
|
|
694
694
|
return true;
|
|
695
695
|
},
|
|
696
|
-
"Mod-Alt-0": () =>
|
|
697
|
-
this.editor.commands.BNCreateBlock(
|
|
698
|
-
this.editor.state.selection.anchor + 2
|
|
699
|
-
),
|
|
700
696
|
};
|
|
701
697
|
},
|
|
702
698
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/** Define the main block types **/
|
|
2
|
-
import { Extension, Node } from "@tiptap/core";
|
|
2
|
+
import type { Extension, Node } from "@tiptap/core";
|
|
3
3
|
|
|
4
4
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
6
|
InlineContent,
|
|
7
7
|
InlineContentSchema,
|
|
8
8
|
PartialInlineContent,
|
|
9
9
|
} from "../inlineContent/types";
|
|
10
|
-
import { PropSchema, Props } from "../propTypes";
|
|
11
|
-
import { StyleSchema } from "../styles/types";
|
|
10
|
+
import type { PropSchema, Props } from "../propTypes";
|
|
11
|
+
import type { StyleSchema } from "../styles/types";
|
|
12
12
|
|
|
13
13
|
export type BlockNoteDOMElement =
|
|
14
14
|
| "editor"
|
|
15
|
-
| "
|
|
15
|
+
| "block"
|
|
16
16
|
| "blockGroup"
|
|
17
17
|
| "blockContent"
|
|
18
18
|
| "inlineContent";
|
|
@@ -41,7 +41,7 @@ export type TiptapBlockImplementation<
|
|
|
41
41
|
node: Node;
|
|
42
42
|
toInternalHTML: (
|
|
43
43
|
block: BlockFromConfigNoChildren<T, I, S> & {
|
|
44
|
-
children:
|
|
44
|
+
children: BlockNoDefaults<B, I, S>[];
|
|
45
45
|
},
|
|
46
46
|
editor: BlockNoteEditor<B, I, S>
|
|
47
47
|
) => {
|
|
@@ -50,7 +50,7 @@ export type TiptapBlockImplementation<
|
|
|
50
50
|
};
|
|
51
51
|
toExternalHTML: (
|
|
52
52
|
block: BlockFromConfigNoChildren<T, I, S> & {
|
|
53
|
-
children:
|
|
53
|
+
children: BlockNoDefaults<B, I, S>[];
|
|
54
54
|
},
|
|
55
55
|
editor: BlockNoteEditor<B, I, S>
|
|
56
56
|
) => {
|
|
@@ -142,7 +142,7 @@ export type BlockFromConfig<
|
|
|
142
142
|
I extends InlineContentSchema,
|
|
143
143
|
S extends StyleSchema
|
|
144
144
|
> = BlockFromConfigNoChildren<B, I, S> & {
|
|
145
|
-
children:
|
|
145
|
+
children: BlockNoDefaults<BlockSchema, I, S>[];
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
// Converts each block spec into a Block object without children. We later merge
|
|
@@ -158,12 +158,12 @@ type BlocksWithoutChildren<
|
|
|
158
158
|
|
|
159
159
|
// Converts each block spec into a Block object without children, merges them
|
|
160
160
|
// into a union type, and adds a children property
|
|
161
|
-
export type
|
|
161
|
+
export type BlockNoDefaults<
|
|
162
162
|
BSchema extends BlockSchema,
|
|
163
163
|
I extends InlineContentSchema,
|
|
164
164
|
S extends StyleSchema
|
|
165
165
|
> = BlocksWithoutChildren<BSchema, I, S>[keyof BSchema] & {
|
|
166
|
-
children:
|
|
166
|
+
children: BlockNoDefaults<BSchema, I, S>[];
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
export type SpecificBlock<
|
|
@@ -172,7 +172,7 @@ export type SpecificBlock<
|
|
|
172
172
|
I extends InlineContentSchema,
|
|
173
173
|
S extends StyleSchema
|
|
174
174
|
> = BlocksWithoutChildren<BSchema, I, S>[BType] & {
|
|
175
|
-
children:
|
|
175
|
+
children: BlockNoDefaults<BSchema, I, S>[];
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
/** CODE FOR PARTIAL BLOCKS, analogous to above
|
|
@@ -219,7 +219,7 @@ type PartialBlocksWithoutChildren<
|
|
|
219
219
|
>;
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
-
export type
|
|
222
|
+
export type PartialBlockNoDefaults<
|
|
223
223
|
BSchema extends BlockSchema,
|
|
224
224
|
I extends InlineContentSchema,
|
|
225
225
|
S extends StyleSchema
|
|
@@ -229,7 +229,7 @@ export type PartialBlock<
|
|
|
229
229
|
S
|
|
230
230
|
>[keyof PartialBlocksWithoutChildren<BSchema, I, S>] &
|
|
231
231
|
Partial<{
|
|
232
|
-
children:
|
|
232
|
+
children: PartialBlockNoDefaults<BSchema, I, S>[];
|
|
233
233
|
}>;
|
|
234
234
|
|
|
235
235
|
export type SpecificPartialBlock<
|
|
@@ -238,7 +238,7 @@ export type SpecificPartialBlock<
|
|
|
238
238
|
BType extends keyof BSchema,
|
|
239
239
|
S extends StyleSchema
|
|
240
240
|
> = PartialBlocksWithoutChildren<BSchema, I, S>[BType] & {
|
|
241
|
-
children?:
|
|
241
|
+
children?: BlockNoDefaults<BSchema, I, S>[];
|
|
242
242
|
};
|
|
243
243
|
|
|
244
244
|
export type PartialBlockFromConfig<
|
|
@@ -246,7 +246,7 @@ export type PartialBlockFromConfig<
|
|
|
246
246
|
I extends InlineContentSchema,
|
|
247
247
|
S extends StyleSchema
|
|
248
248
|
> = PartialBlockFromConfigNoChildren<B, I, S> & {
|
|
249
|
-
children?:
|
|
249
|
+
children?: BlockNoDefaults<BlockSchema, I, S>[];
|
|
250
250
|
};
|
|
251
251
|
|
|
252
252
|
export type BlockIdentifier = { id: string } | string;
|
|
@@ -98,8 +98,8 @@ export function createInlineContentSpec<
|
|
|
98
98
|
const output = inlineContentImplementation.render(
|
|
99
99
|
nodeToCustomInlineContent(
|
|
100
100
|
node,
|
|
101
|
-
editor.inlineContentSchema,
|
|
102
|
-
editor.styleSchema
|
|
101
|
+
editor.schema.inlineContentSchema,
|
|
102
|
+
editor.schema.styleSchema
|
|
103
103
|
) as any as InlineContentFromConfig<T, S> // TODO: fix cast
|
|
104
104
|
);
|
|
105
105
|
|
|
@@ -74,7 +74,7 @@ export type PartialCustomInlineContentFromConfig<
|
|
|
74
74
|
> = {
|
|
75
75
|
type: I["type"];
|
|
76
76
|
props?: Props<I["propSchema"]>;
|
|
77
|
-
content
|
|
77
|
+
content?: I["content"] extends "styled"
|
|
78
78
|
? StyledText<S>[] | string
|
|
79
79
|
: I["content"] extends "plain"
|
|
80
80
|
? string
|
package/src/util/browser.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const isAppleOS = () =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
typeof navigator !== "undefined" &&
|
|
3
|
+
(/Mac/.test(navigator.platform) ||
|
|
4
|
+
(/AppleWebKit/.test(navigator.userAgent) &&
|
|
5
|
+
/Mobile\/\w+/.test(navigator.userAgent)));
|
|
6
6
|
|
|
7
7
|
export function formatKeyboardShortcut(shortcut: string) {
|
|
8
8
|
if (isAppleOS()) {
|
|
@@ -16,3 +16,5 @@ export function mergeCSSClasses(...classes: string[]) {
|
|
|
16
16
|
return classes.filter((c) => c).join(" ");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export const isSafari = () =>
|
|
20
|
+
/^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
package/src/util/typescript.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export class UnreachableCaseError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
2
|
+
constructor(val: never) {
|
|
3
|
+
super(`Unreachable case: ${val}`);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// TODO: change for built-in version of typescript 5.4 after upgrade
|
|
8
|
+
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { Block, PartialBlock } from "../../blocks/defaultBlocks";
|
|
1
3
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
2
|
-
import {
|
|
4
|
+
import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
3
5
|
export declare function insertBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocksToInsert: PartialBlock<BSchema, I, S>[], referenceBlock: BlockIdentifier, placement: "before" | "after" | "nested" | undefined, editor: BlockNoteEditor<BSchema, I, S>): Block<BSchema, I, S>[];
|
|
4
6
|
export declare function updateBlock<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>, editor: BlockNoteEditor<BSchema, I, S>): Block<BSchema, I, S>;
|
|
5
7
|
export declare function removeBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocksToRemove: BlockIdentifier[], editor: BlockNoteEditor<BSchema, I, S>): Block<BSchema, I, S>[];
|
|
@@ -7,3 +9,6 @@ export declare function replaceBlocks<BSchema extends BlockSchema, I extends Inl
|
|
|
7
9
|
insertedBlocks: Block<BSchema, I, S>[];
|
|
8
10
|
removedBlocks: Block<BSchema, I, S>[];
|
|
9
11
|
};
|
|
12
|
+
export declare function insertContentAt<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(position: any, nodes: Node[], editor: BlockNoteEditor<BSchema, I, S>, options?: {
|
|
13
|
+
updateSelection: boolean;
|
|
14
|
+
}): boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, Schema } from "prosemirror-model";
|
|
2
|
+
import { PartialBlock } from "../../../blocks/defaultBlocks";
|
|
2
3
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
3
|
-
import { BlockSchema, InlineContentSchema,
|
|
4
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
4
5
|
export interface ExternalHTMLExporter<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> {
|
|
5
6
|
exportBlocks: (blocks: PartialBlock<BSchema, I, S>[]) => string;
|
|
6
7
|
exportProseMirrorFragment: (fragment: Fragment) => string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, Schema } from "prosemirror-model";
|
|
2
|
+
import { PartialBlock } from "../../../blocks/defaultBlocks";
|
|
2
3
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
3
|
-
import { BlockSchema, InlineContentSchema,
|
|
4
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
4
5
|
export interface InternalHTMLSerializer<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> {
|
|
5
6
|
serializeProseMirrorFragment: (fragment: Fragment) => string;
|
|
6
7
|
serializeBlocks: (blocks: PartialBlock<BSchema, I, S>[]) => string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
|
+
import { Block } from "../../../blocks/defaultBlocks";
|
|
2
3
|
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
3
|
-
import {
|
|
4
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
4
5
|
export declare function cleanHTMLToMarkdown(cleanHTMLString: string): string;
|
|
5
6
|
export declare function blocksToMarkdown<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(blocks: Block<BSchema, I, S>[], schema: Schema, editor: BlockNoteEditor<BSchema, I, S>): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node, Schema } from "@tiptap/pm/model";
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockSchema, InlineContent, InlineContentSchema, PartialInlineContent, PartialTableContent, StyleSchema } from "../../schema";
|
|
3
|
+
import type { Block, PartialBlock } from "../../blocks/defaultBlocks";
|
|
3
4
|
/**
|
|
4
5
|
* converts an array of inline content elements to prosemirror nodes
|
|
5
6
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
|
-
import {
|
|
2
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
3
|
+
import { Block } from "../../../blocks/defaultBlocks";
|
|
3
4
|
export declare function HTMLToBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(html: string, blockSchema: BSchema, icSchema: I, styleSchema: S, pmSchema: Schema): Promise<Block<BSchema, I, S>[]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Schema } from "prosemirror-model";
|
|
2
|
-
import { Block
|
|
2
|
+
import { Block } from "../../../blocks/defaultBlocks";
|
|
3
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
|
|
3
4
|
export declare function markdownToBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(markdown: string, blockSchema: BSchema, icSchema: I, styleSchema: S, pmSchema: Schema): Promise<Block<BSchema, I, S>[]>;
|