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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"postpublish": "rm -rf packages/core/README.md && rm -rf packages/react/README.md",
"clean": "lerna run --stream clean"
}
}
}
16 changes: 10 additions & 6 deletions packages/core/src/extensions/FilePanel/FilePanelPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
if (this.state?.show) {
const blockElement = this.pmView.root.querySelector(
`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`
)!;

);
if (!blockElement) {
return;
}
this.state.referencePos = blockElement.getBoundingClientRect();
this.emitUpdate();
}
Expand All @@ -86,8 +88,10 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
if (!this.state?.show && pluginState.block && this.editor.isEditable) {
const blockElement = this.pmView.root.querySelector(
`[data-node-type="blockContainer"][data-id="${pluginState.block.id}"]`
)!;

);
if (!blockElement) {
return;
}
this.state = {
show: true,
referencePos: blockElement.getBoundingClientRect(),
Expand Down Expand Up @@ -157,7 +161,7 @@ export class FilePanelProsemirrorPlugin<
props: {
handleKeyDown: (_view, event: KeyboardEvent) => {
if (event.key === "Escape" && this.shown) {
this.view!.closeMenu();
this.view?.closeMenu();
return true;
}
return false;
Expand Down Expand Up @@ -189,5 +193,5 @@ export class FilePanelProsemirrorPlugin<
return this.on("update", callback);
}

public closeMenu = () => this.view!.closeMenu();
public closeMenu = () => this.view?.closeMenu();
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export class FormattingToolbarView implements PluginView {

if (isNodeSelection(selection)) {
const node = this.pmView.nodeDOM(from) as HTMLElement;

if (node) {
return node.getBoundingClientRect();
}
Expand Down
33 changes: 22 additions & 11 deletions packages/core/src/extensions/SideMenu/SideMenuPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class SideMenuView<
// When false, the drag handle with be just to the left of the element
// TODO: Is there any case where we want this to be false?
private horizontalPosAnchoredAtRoot: boolean;
private horizontalPosAnchor: number;
private horizontalPosAnchor: number | undefined;

private hoveredBlock: HTMLElement | undefined;

Expand All @@ -290,9 +290,12 @@ export class SideMenuView<
};

this.horizontalPosAnchoredAtRoot = true;
this.horizontalPosAnchor = (
this.pmView.dom.firstChild! as HTMLElement
).getBoundingClientRect().x;

if (this.pmView.dom.firstChild) {
this.horizontalPosAnchor = (
this.pmView.dom.firstChild as HTMLElement
).getBoundingClientRect().x;
}

this.pmView.root.addEventListener(
"drop",
Expand Down Expand Up @@ -337,8 +340,12 @@ export class SideMenuView<
// size/position, so we get the boundingRect of the first child (i.e. the
// blockGroup that wraps all blocks in the editor) for more accurate side
// menu placement.
if (!this.pmView.dom.firstChild) {
return;
}

const editorBoundingBox = (
this.pmView.dom.firstChild! as HTMLElement
this.pmView.dom.firstChild as HTMLElement
).getBoundingClientRect();

this.horizontalPosAnchor = editorBoundingBox.x;
Expand Down Expand Up @@ -441,7 +448,7 @@ export class SideMenuView<
if (!pos || pos.inside === -1) {
const evt = new Event("drop", event) as any;
const editorBoundingBox = (
this.pmView.dom.firstChild! as HTMLElement
this.pmView.dom.firstChild as HTMLElement
).getBoundingClientRect();
evt.clientX =
event.clientX < editorBoundingBox.left ||
Expand Down Expand Up @@ -474,10 +481,10 @@ export class SideMenuView<
top: event.clientY,
});

if (!pos || pos.inside === -1) {
if (!pos || (pos.inside === -1 && this.pmView.dom.firstChild)) {
const evt = new Event("dragover", event) as any;
const editorBoundingBox = (
this.pmView.dom.firstChild! as HTMLElement
this.pmView.dom.firstChild as HTMLElement
).getBoundingClientRect();
evt.clientX = editorBoundingBox.left + editorBoundingBox.width / 2;
evt.clientY = event.clientY;
Expand Down Expand Up @@ -555,8 +562,8 @@ export class SideMenuView<
};

onScroll = () => {
if (this.state?.show) {
const blockContent = this.hoveredBlock!.firstChild as HTMLElement;
if (this.state?.show && this.hoveredBlock?.firstChild) {
const blockContent = this.hoveredBlock.firstChild as HTMLElement;
const blockContentBoundingBox = blockContent.getBoundingClientRect();

this.state.referencePos = new DOMRect(
Expand Down Expand Up @@ -624,7 +631,11 @@ export class SideMenuView<
this.emitUpdate(this.state);
}

const blockContent = this.hoveredBlock!.firstChild! as HTMLElement;
if (!this.hoveredBlock?.firstChild) {
return;
}

const blockContent = this.hoveredBlock.firstChild as HTMLElement;
const blockContentBoundingBox = blockContent.getBoundingClientRect();

const pos = this.pmView.posAtCoords({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class SuggestionMenuView<
const decorationNode = this.rootEl?.querySelector(
`[data-decoration-id="${this.pluginState!.decorationId}"]`
);
this.state.referencePos = decorationNode!.getBoundingClientRect();
if (!decorationNode) {
return;
}
this.state.referencePos = decorationNode.getBoundingClientRect();
this.emitUpdate(this.pluginState!.triggerCharacter!);
}
};
Expand Down Expand Up @@ -89,10 +92,10 @@ class SuggestionMenuView<
`[data-decoration-id="${this.pluginState!.decorationId}"]`
);

if (this.editor.isEditable) {
if (this.editor.isEditable && decorationNode) {
this.state = {
show: true,
referencePos: decorationNode!.getBoundingClientRect(),
referencePos: decorationNode.getBoundingClientRect(),
query: this.pluginState!.query,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ export class TableHandlesView<
const rowIndex = getChildIndex(target.parentElement!);
const cellRect = target.getBoundingClientRect();
const tableRect =
target.parentElement!.parentElement!.getBoundingClientRect();
target.parentElement?.parentElement?.getBoundingClientRect();

if (!tableRect) {
return;
}

const blockEl = getDraggableBlockFromElement(target, this.pmView);
if (!blockEl) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"../../.eslintrc.js"
]
}
}
}
Loading