@blocknote/core 0.30.0 → 0.31.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 +2771 -2245
- package/dist/blocknote.js.map +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js.map +1 -1
- package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
- package/dist/en-BXVKCwYt.cjs.map +1 -0
- package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
- package/dist/en-qGo6sk9V.js.map +1 -0
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +20 -39
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +8 -7
- package/src/api/README.md +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
- package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
- package/src/api/blockManipulation/insertContentAt.ts +1 -1
- package/src/api/blockManipulation/selections/selection.ts +59 -12
- package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
- package/src/api/blockManipulation/tables/tables.test.ts +106 -106
- package/src/api/blockManipulation/tables/tables.ts +35 -35
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
- package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
- package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
- package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
- package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
- package/src/api/exporters/markdown/markdownExporter.ts +3 -3
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
- package/src/api/getBlockInfoFromPos.ts +6 -6
- package/src/api/nodeConversions/blockToNode.ts +31 -28
- package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
- package/src/api/nodeConversions/nodeToBlock.ts +240 -41
- package/src/api/nodeUtil.test.ts +16 -16
- package/src/api/nodeUtil.ts +10 -10
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.ts +2 -2
- package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
- package/src/api/pmUtil.ts +7 -7
- package/src/api/positionMapping.test.ts +3 -3
- package/src/api/positionMapping.ts +5 -5
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
- package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
- package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
- package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
- package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
- package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
- package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
- package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
- package/src/blocks/README.md +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
- package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
- package/src/blocks/defaultBlockHelpers.ts +8 -8
- package/src/blocks/defaultBlockTypeGuards.ts +16 -16
- package/src/blocks/defaultBlocks.ts +3 -3
- package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
- package/src/comments/threadstore/ThreadStore.ts +1 -1
- package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
- package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
- package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
- package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
- package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
- package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
- package/src/editor/Block.css +35 -1
- package/src/editor/BlockNoteEditor.test.ts +10 -3
- package/src/editor/BlockNoteEditor.ts +95 -38
- package/src/editor/BlockNoteExtension.ts +26 -0
- package/src/editor/BlockNoteExtensions.ts +38 -22
- package/src/editor/BlockNoteSchema.ts +4 -4
- package/src/editor/BlockNoteTipTapEditor.ts +33 -12
- package/src/editor/README.md +1 -1
- package/src/editor/cursorPositionTypes.ts +1 -1
- package/src/editor/editor.css +15 -3
- package/src/editor/selectionTypes.ts +1 -1
- package/src/editor/transformPasted.ts +2 -2
- package/src/exporter/Exporter.ts +5 -5
- package/src/exporter/mapping.ts +7 -7
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
- package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
- package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
- package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
- package/src/extensions/Comments/CommentsPlugin.ts +80 -75
- package/src/extensions/Comments/userstore/UserStore.ts +2 -2
- package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
- package/src/extensions/README.md +1 -1
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
- package/src/extensions/SideMenu/dragging.ts +8 -8
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
- package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
- package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
- package/src/extensions/UniqueID/UniqueID.ts +6 -6
- package/src/extensions/getDraggableBlockFromElement.ts +1 -1
- package/src/fonts/inter.css +18 -9
- package/src/i18n/locales/ar.ts +0 -1
- package/src/i18n/locales/de.ts +0 -1
- package/src/i18n/locales/en.ts +0 -1
- package/src/i18n/locales/es.ts +0 -1
- package/src/i18n/locales/fr.ts +0 -1
- package/src/i18n/locales/hr.ts +0 -1
- package/src/i18n/locales/is.ts +0 -1
- package/src/i18n/locales/it.ts +0 -1
- package/src/i18n/locales/ja.ts +0 -1
- package/src/i18n/locales/ko.ts +0 -1
- package/src/i18n/locales/nl.ts +0 -1
- package/src/i18n/locales/no.ts +0 -1
- package/src/i18n/locales/pl.ts +0 -1
- package/src/i18n/locales/pt.ts +0 -1
- package/src/i18n/locales/ru.ts +0 -1
- package/src/i18n/locales/sk.ts +0 -1
- package/src/i18n/locales/uk.ts +0 -1
- package/src/i18n/locales/vi.ts +0 -1
- package/src/i18n/locales/zh-tw.ts +0 -1
- package/src/i18n/locales/zh.ts +0 -1
- package/src/index.ts +18 -8
- package/src/locales.ts +1 -1
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/Doc.ts +5 -4
- package/src/schema/README.md +1 -1
- package/src/schema/blocks/createSpec.ts +14 -14
- package/src/schema/blocks/internal.ts +17 -17
- package/src/schema/blocks/types.ts +25 -25
- package/src/schema/inlineContent/createSpec.ts +16 -20
- package/src/schema/inlineContent/internal.ts +9 -9
- package/src/schema/inlineContent/types.ts +26 -26
- package/src/schema/propTypes.ts +8 -8
- package/src/schema/styles/createSpec.ts +2 -2
- package/src/schema/styles/internal.ts +7 -7
- package/src/schema/styles/types.ts +2 -2
- package/src/util/EventEmitter.ts +4 -4
- package/src/util/README.md +1 -1
- package/src/util/combineByGroup.ts +1 -1
- package/src/util/table.ts +33 -30
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
- package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
- package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
- package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
- package/types/src/api/clipboard/testUtil.d.ts +541 -0
- package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
- package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
- package/types/src/api/pmUtil.d.ts +3 -3
- package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
- package/types/src/api/testUtil/index.d.ts +14 -0
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
- package/types/src/api/testUtil/paste.d.ts +2 -0
- package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
- package/types/src/editor/BlockNoteEditor.d.ts +58 -10
- package/types/src/editor/BlockNoteExtension.d.ts +9 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
- package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
- package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
- package/types/src/i18n/locales/en.d.ts +0 -1
- package/types/src/i18n/locales/sk.d.ts +0 -1
- package/types/src/index.d.ts +15 -8
- package/dist/en-B7ycW7c8.js.map +0 -1
- package/dist/en-D4taoCs4.cjs.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
- package/src/api/blockManipulation/selections/selection.test.ts +0 -72
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Plugin, PluginKey, TextSelection } from "prosemirror-state";
|
|
2
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
2
3
|
|
|
3
4
|
const PLUGIN_KEY = new PluginKey("node-selection-keyboard");
|
|
4
5
|
// By default, typing with a node selection active will cause ProseMirror to
|
|
@@ -15,54 +16,56 @@ const PLUGIN_KEY = new PluginKey("node-selection-keyboard");
|
|
|
15
16
|
// While a more elegant solution would probably process transactions instead of
|
|
16
17
|
// keystrokes, this brings us most of the way to Notion's UX without much added
|
|
17
18
|
// complexity.
|
|
18
|
-
export class NodeSelectionKeyboardPlugin {
|
|
19
|
-
public readonly plugin: Plugin;
|
|
19
|
+
export class NodeSelectionKeyboardPlugin extends BlockNoteExtension {
|
|
20
20
|
constructor() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Checks
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
super();
|
|
22
|
+
this.addProsemirrorPlugin(
|
|
23
|
+
new Plugin({
|
|
24
|
+
key: PLUGIN_KEY,
|
|
25
|
+
props: {
|
|
26
|
+
handleKeyDown: (view, event) => {
|
|
27
|
+
// Checks for node selection
|
|
28
|
+
if ("node" in view.state.selection) {
|
|
29
|
+
// Checks if key press uses ctrl/meta modifier
|
|
30
|
+
if (event.ctrlKey || event.metaKey) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Checks if key press is alphanumeric
|
|
34
|
+
if (event.key.length === 1) {
|
|
35
|
+
event.preventDefault();
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
52
|
-
.setSelection(
|
|
53
|
-
new TextSelection(
|
|
54
|
-
tr.doc.resolve(view.state.tr.selection.$to.after() + 1)
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
// Checks if key press is Enter
|
|
40
|
+
if (
|
|
41
|
+
event.key === "Enter" &&
|
|
42
|
+
!event.shiftKey &&
|
|
43
|
+
!event.altKey &&
|
|
44
|
+
!event.ctrlKey &&
|
|
45
|
+
!event.metaKey
|
|
46
|
+
) {
|
|
47
|
+
const tr = view.state.tr;
|
|
48
|
+
view.dispatch(
|
|
49
|
+
tr
|
|
50
|
+
.insert(
|
|
51
|
+
view.state.tr.selection.$to.after(),
|
|
52
|
+
view.state.schema.nodes["paragraph"].createChecked(),
|
|
55
53
|
)
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
.setSelection(
|
|
55
|
+
new TextSelection(
|
|
56
|
+
tr.doc.resolve(view.state.tr.selection.$to.after() + 1),
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
);
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
}
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
return false;
|
|
66
|
+
},
|
|
64
67
|
},
|
|
65
|
-
},
|
|
66
|
-
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -2,139 +2,142 @@ import { Plugin, PluginKey } from "prosemirror-state";
|
|
|
2
2
|
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
4
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
5
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
5
6
|
|
|
6
7
|
const PLUGIN_KEY = new PluginKey(`blocknote-placeholder`);
|
|
7
8
|
|
|
8
|
-
export class PlaceholderPlugin {
|
|
9
|
-
public readonly plugin: Plugin;
|
|
9
|
+
export class PlaceholderPlugin extends BlockNoteExtension {
|
|
10
10
|
constructor(
|
|
11
11
|
editor: BlockNoteEditor<any, any, any>,
|
|
12
12
|
placeholders: Record<
|
|
13
13
|
string | "default" | "emptyDocument",
|
|
14
14
|
string | undefined
|
|
15
|
-
|
|
15
|
+
>,
|
|
16
16
|
) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
view
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`.${uniqueEditorSelector} .bn-block-content${additionalSelectors} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
// FIXME: the names "default" and "emptyDocument" are hardcoded
|
|
42
|
-
const {
|
|
43
|
-
default: defaultPlaceholder,
|
|
44
|
-
emptyDocument: emptyPlaceholder,
|
|
45
|
-
...rest
|
|
46
|
-
} = placeholders;
|
|
47
|
-
|
|
48
|
-
// add block specific placeholders
|
|
49
|
-
for (const [blockType, placeholder] of Object.entries(rest)) {
|
|
50
|
-
const blockTypeSelector = `[data-content-type="${blockType}"]`;
|
|
17
|
+
super();
|
|
18
|
+
this.addProsemirrorPlugin(
|
|
19
|
+
new Plugin({
|
|
20
|
+
key: PLUGIN_KEY,
|
|
21
|
+
view: (view) => {
|
|
22
|
+
const uniqueEditorSelector = `placeholder-selector-${v4()}`;
|
|
23
|
+
view.dom.classList.add(uniqueEditorSelector);
|
|
24
|
+
const styleEl = document.createElement("style");
|
|
25
|
+
|
|
26
|
+
const nonce = editor._tiptapEditor.options.injectNonce;
|
|
27
|
+
if (nonce) {
|
|
28
|
+
styleEl.setAttribute("nonce", nonce);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (editor.prosemirrorView?.root instanceof ShadowRoot) {
|
|
32
|
+
editor.prosemirrorView.root.append(styleEl);
|
|
33
|
+
} else {
|
|
34
|
+
editor.prosemirrorView?.root.head.appendChild(styleEl);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const styleSheet = styleEl.sheet!;
|
|
51
38
|
|
|
39
|
+
const getSelector = (additionalSelectors = "") =>
|
|
40
|
+
`.${uniqueEditorSelector} .bn-block-content${additionalSelectors} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// FIXME: the names "default" and "emptyDocument" are hardcoded
|
|
44
|
+
const {
|
|
45
|
+
default: defaultPlaceholder,
|
|
46
|
+
emptyDocument: emptyPlaceholder,
|
|
47
|
+
...rest
|
|
48
|
+
} = placeholders;
|
|
49
|
+
|
|
50
|
+
// add block specific placeholders
|
|
51
|
+
for (const [blockType, placeholder] of Object.entries(rest)) {
|
|
52
|
+
const blockTypeSelector = `[data-content-type="${blockType}"]`;
|
|
53
|
+
|
|
54
|
+
styleSheet.insertRule(
|
|
55
|
+
`${getSelector(blockTypeSelector)} { content: ${JSON.stringify(
|
|
56
|
+
placeholder,
|
|
57
|
+
)}; }`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const onlyBlockSelector = `[data-is-only-empty-block]`;
|
|
62
|
+
const mustBeFocusedSelector = `[data-is-empty-and-focused]`;
|
|
63
|
+
|
|
64
|
+
// placeholder for when there's only one empty block
|
|
52
65
|
styleSheet.insertRule(
|
|
53
|
-
`${getSelector(
|
|
54
|
-
|
|
55
|
-
)}; }
|
|
66
|
+
`${getSelector(onlyBlockSelector)} { content: ${JSON.stringify(
|
|
67
|
+
emptyPlaceholder,
|
|
68
|
+
)}; }`,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// placeholder for default blocks, only when the cursor is in the block (mustBeFocused)
|
|
72
|
+
styleSheet.insertRule(
|
|
73
|
+
`${getSelector(mustBeFocusedSelector)} { content: ${JSON.stringify(
|
|
74
|
+
defaultPlaceholder,
|
|
75
|
+
)}; }`,
|
|
76
|
+
);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.warn(
|
|
80
|
+
`Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)`,
|
|
81
|
+
e,
|
|
56
82
|
);
|
|
57
83
|
}
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
} catch (e) {
|
|
76
|
-
// eslint-disable-next-line no-console
|
|
77
|
-
console.warn(
|
|
78
|
-
`Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)`,
|
|
79
|
-
e
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
destroy: () => {
|
|
85
|
-
if (editor.prosemirrorView?.root instanceof ShadowRoot) {
|
|
86
|
-
editor.prosemirrorView.root.removeChild(styleEl);
|
|
87
|
-
} else {
|
|
88
|
-
editor.prosemirrorView?.root.head.removeChild(styleEl);
|
|
85
|
+
return {
|
|
86
|
+
destroy: () => {
|
|
87
|
+
if (editor.prosemirrorView?.root instanceof ShadowRoot) {
|
|
88
|
+
editor.prosemirrorView.root.removeChild(styleEl);
|
|
89
|
+
} else {
|
|
90
|
+
editor.prosemirrorView?.root.head.removeChild(styleEl);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
props: {
|
|
96
|
+
decorations: (state) => {
|
|
97
|
+
const { doc, selection } = state;
|
|
98
|
+
|
|
99
|
+
if (!editor.isEditable) {
|
|
100
|
+
return;
|
|
89
101
|
}
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
props: {
|
|
94
|
-
decorations: (state) => {
|
|
95
|
-
const { doc, selection } = state;
|
|
96
|
-
|
|
97
|
-
if (!editor.isEditable) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
if (!selection.empty) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
104
106
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
// Don't show placeholder when the cursor is inside a code block
|
|
108
|
+
if (selection.$from.parent.type.spec.code) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
const decs = [];
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
// decoration for when there's only one empty block
|
|
115
|
+
// positions are hardcoded for now
|
|
116
|
+
if (state.doc.content.size === 6) {
|
|
117
|
+
decs.push(
|
|
118
|
+
Decoration.node(2, 4, {
|
|
119
|
+
"data-is-only-empty-block": "true",
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
const $pos = selection.$anchor;
|
|
125
|
+
const node = $pos.parent;
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
if (node.content.size === 0) {
|
|
128
|
+
const before = $pos.before();
|
|
127
129
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
decs.push(
|
|
131
|
+
Decoration.node(before, before + node.nodeSize, {
|
|
132
|
+
"data-is-empty-and-focused": "true",
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
134
136
|
|
|
135
|
-
|
|
137
|
+
return DecorationSet.create(doc, decs);
|
|
138
|
+
},
|
|
136
139
|
},
|
|
137
|
-
},
|
|
138
|
-
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
139
142
|
}
|
|
140
143
|
}
|