Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ export async function handleFileInsertion<
top: (event as DragEvent).clientY,
};

const pos = editor.prosemirrorView?.posAtCoords(coords);
const pos = editor.prosemirrorView.posAtCoords(coords);

if (!pos) {
return;
}

insertedBlockId = editor.transact((tr) => {
const posInfo = getNearestBlockPos(tr.doc, pos.pos);
const blockElement = editor.prosemirrorView?.dom.querySelector(
const blockElement = editor.prosemirrorView.dom.querySelector(
`[data-id="${posInfo.node.attrs.id}"]`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function defaultPasteHandler({
}

if (format === "vscode-editor-data") {
handleVSCodePaste(event, editor.prosemirrorView!);
handleVSCodePaste(event, editor.prosemirrorView);
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/extensions/Placeholder/PlaceholderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class PlaceholderPlugin extends BlockNoteExtension {
styleEl.setAttribute("nonce", nonce);
}

if (editor.prosemirrorView?.root instanceof window.ShadowRoot) {
editor.prosemirrorView.root.append(styleEl);
if (view.root instanceof window.ShadowRoot) {
view.root.append(styleEl);
} else {
editor.prosemirrorView?.root.head.appendChild(styleEl);
view.root.head.appendChild(styleEl);
}

const styleSheet = styleEl.sheet!;
Expand Down Expand Up @@ -88,10 +88,10 @@ export class PlaceholderPlugin extends BlockNoteExtension {

return {
destroy: () => {
if (editor.prosemirrorView?.root instanceof window.ShadowRoot) {
editor.prosemirrorView.root.removeChild(styleEl);
if (view.root instanceof window.ShadowRoot) {
view.root.removeChild(styleEl);
} else {
editor.prosemirrorView?.root.head.removeChild(styleEl);
view.root.head.removeChild(styleEl);
}
},
};
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/extensions/SideMenu/SideMenuPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,7 @@ export class SideMenuProsemirrorPlugin<
* Handles drag & drop events for blocks.
*/
blockDragEnd = () => {
if (this.editor.prosemirrorView) {
unsetDragImage(this.editor.prosemirrorView.root);
}
unsetDragImage(this.editor.prosemirrorView.root);

if (this.view) {
this.view.isDragOrigin = false;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/extensions/SideMenu/dragging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ export function dragStart<
return;
}

const view = editor.prosemirrorView;
if (!view) {
if (editor.headless) {
return;
}
const view = editor.prosemirrorView;

const posInfo = getNodeById(block.id, view.state.doc);
if (!posInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SuggestionMenuView<
constructor(
private readonly editor: BlockNoteEditor<BSchema, I, S>,
emitUpdate: (menuName: string, state: SuggestionMenuState) => void,
view: EditorView,
) {
this.pluginState = undefined;

Expand All @@ -46,7 +47,7 @@ class SuggestionMenuView<
});
};

this.rootEl = this.editor.prosemirrorView?.root;
this.rootEl = view.root;

// Setting capture=true ensures that any parent container of the editor that
// gets scrolled will trigger the scroll event. Scroll events do not bubble
Expand Down Expand Up @@ -181,12 +182,13 @@ export class SuggestionMenuProseMirrorPlugin<
new Plugin({
key: suggestionMenuPluginKey,

view: () => {
view: (view) => {
this.view = new SuggestionMenuView<BSchema, I, S>(
editor,
(triggerCharacter, state) => {
this.emit(`update ${triggerCharacter}`, state);
},
view,
);
return this.view;
},
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,8 @@ export class TableHandlesProsemirrorPlugin<
}),
);

if (!this.editor.prosemirrorView) {
throw new Error("Editor view not initialized.");
if (this.editor.headless) {
return;
}

setHiddenDragImage(this.editor.prosemirrorView.root);
Expand Down Expand Up @@ -872,8 +872,8 @@ export class TableHandlesProsemirrorPlugin<
}),
);

if (!this.editor.prosemirrorView) {
throw new Error("Editor view not initialized.");
if (this.editor.headless) {
return;
}

setHiddenDragImage(this.editor.prosemirrorView.root);
Expand All @@ -897,8 +897,8 @@ export class TableHandlesProsemirrorPlugin<

this.editor.transact((tr) => tr.setMeta(tableHandlesPluginKey, null));

if (!this.editor.prosemirrorView) {
throw new Error("Editor view not initialized.");
if (this.editor.headless) {
return;
}

unsetHiddenDragImage(this.editor.prosemirrorView.root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ export const CreateLinkButton = () => {
}
};

editor.prosemirrorView?.dom.addEventListener("keydown", callback);
if (editor.headless) {
return;
}

editor.prosemirrorView.dom.addEventListener("keydown", callback);

return () => {
editor.prosemirrorView?.dom.removeEventListener("keydown", callback);
editor.prosemirrorView.dom.removeEventListener("keydown", callback);
};
}, [editor.prosemirrorView?.dom]);
}, [editor.prosemirrorView, editor.headless]);

const update = useCallback(
(url: string) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/src/unit/shared/clipboard/copy/copyTestExecutors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const testCopyBlockNoteHTML = async <
initTestEditor(editor, testCase.document, testCase.getCopySelection);

const { clipboardHTML } = selectedFragmentToHTML(
editor.prosemirrorView!,
editor.prosemirrorView,
editor,
);

Expand All @@ -42,7 +42,7 @@ export const testCopyHTML = async <
initTestEditor(editor, testCase.document, testCase.getCopySelection);

const { externalHTML } = selectedFragmentToHTML(
editor.prosemirrorView!,
editor.prosemirrorView,
editor,
);

Expand All @@ -61,7 +61,7 @@ export const testCopyMarkdown = async <
) => {
initTestEditor(editor, testCase.document, testCase.getCopySelection);

const { markdown } = selectedFragmentToHTML(editor.prosemirrorView!, editor);
const { markdown } = selectedFragmentToHTML(editor.prosemirrorView, editor);

await expect(markdown).toMatchFileSnapshot(
`./__snapshots__/text/plain/${testCase.name}.md`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export const testCopyPaste = async <
initTestEditor(editor, testCase.document, testCase.getCopySelection);

const { clipboardHTML } = selectedFragmentToHTML(
editor.prosemirrorView!,
editor.prosemirrorView,
editor,
);

editor.transact((tr) => tr.setSelection(testCase.getPasteSelection(tr.doc)));

doPaste(
editor.prosemirrorView!,
editor.prosemirrorView,
"text",
clipboardHTML,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const testCopyPasteEquality = async <
initTestEditor(editor, testCase.document, testCase.getCopyAndPasteSelection);

const { clipboardHTML } = selectedFragmentToHTML(
editor.prosemirrorView!,
editor.prosemirrorView,
editor,
);

const originalDocument = editor.document;
doPaste(
editor.prosemirrorView!,
editor.prosemirrorView,
"text",
clipboardHTML,
false,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/unit/shared/clipboard/paste/pasteTestExecutors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const testPasteHTML = async <
initTestEditor(editor, testCase.document, testCase.getPasteSelection);

doPaste(
editor.prosemirrorView!,
editor.prosemirrorView,
"",
testCase.content,
false,
Expand All @@ -44,7 +44,7 @@ export const testPasteMarkdown = async <
initTestEditor(editor, testCase.document, testCase.getPasteSelection);

doPaste(
editor.prosemirrorView!,
editor.prosemirrorView,
testCase.content,
"",
true,
Expand Down
4 changes: 0 additions & 4 deletions tests/src/unit/shared/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export const initTestEditor = <
document?: PartialBlock<B, I, S>[],
getSelection?: (pmDoc: Node) => Selection,
) => {
if (!editor.prosemirrorView) {
throw new Error("Editor view not initialized.");
}

(window as any).__TEST_OPTIONS.mockID = 0;

if (document) {
Expand Down
Loading