Skip to content

Commit 6011aa9

Browse files
Remove some non null assertion operator (#1057)
* Lgtm * Add prepare script * v0.15.7 * v0.15.8 * Remove prepare script * Revert "v0.15.8" This reverts commit 58b37d5. * Revert version update * Restore package-lock.json --------- Co-authored-by: Kody Liou <[email protected]> Co-authored-by: matthewlipski <[email protected]>
1 parent 68dcdeb commit 6011aa9

File tree

8 files changed

+46
-25
lines changed

8 files changed

+46
-25
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"postpublish": "rm -rf packages/core/README.md && rm -rf packages/react/README.md",
3535
"clean": "lerna run --stream clean"
3636
}
37-
}
37+
}

packages/core/src/extensions/FilePanel/FilePanelPlugin.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
7171
if (this.state?.show) {
7272
const blockElement = this.pmView.root.querySelector(
7373
`[data-node-type="blockContainer"][data-id="${this.state.block.id}"]`
74-
)!;
75-
74+
);
75+
if (!blockElement) {
76+
return;
77+
}
7678
this.state.referencePos = blockElement.getBoundingClientRect();
7779
this.emitUpdate();
7880
}
@@ -86,8 +88,10 @@ export class FilePanelView<I extends InlineContentSchema, S extends StyleSchema>
8688
if (!this.state?.show && pluginState.block && this.editor.isEditable) {
8789
const blockElement = this.pmView.root.querySelector(
8890
`[data-node-type="blockContainer"][data-id="${pluginState.block.id}"]`
89-
)!;
90-
91+
);
92+
if (!blockElement) {
93+
return;
94+
}
9195
this.state = {
9296
show: true,
9397
referencePos: blockElement.getBoundingClientRect(),
@@ -157,7 +161,7 @@ export class FilePanelProsemirrorPlugin<
157161
props: {
158162
handleKeyDown: (_view, event: KeyboardEvent) => {
159163
if (event.key === "Escape" && this.shown) {
160-
this.view!.closeMenu();
164+
this.view?.closeMenu();
161165
return true;
162166
}
163167
return false;
@@ -189,5 +193,5 @@ export class FilePanelProsemirrorPlugin<
189193
return this.on("update", callback);
190194
}
191195

192-
public closeMenu = () => this.view!.closeMenu();
196+
public closeMenu = () => this.view?.closeMenu();
193197
}

packages/core/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ export class FormattingToolbarView implements PluginView {
205205

206206
if (isNodeSelection(selection)) {
207207
const node = this.pmView.nodeDOM(from) as HTMLElement;
208-
209208
if (node) {
210209
return node.getBoundingClientRect();
211210
}

packages/core/src/extensions/SideMenu/SideMenuPlugin.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class SideMenuView<
267267
// When false, the drag handle with be just to the left of the element
268268
// TODO: Is there any case where we want this to be false?
269269
private horizontalPosAnchoredAtRoot: boolean;
270-
private horizontalPosAnchor: number;
270+
private horizontalPosAnchor: number | undefined;
271271

272272
private hoveredBlock: HTMLElement | undefined;
273273

@@ -290,9 +290,12 @@ export class SideMenuView<
290290
};
291291

292292
this.horizontalPosAnchoredAtRoot = true;
293-
this.horizontalPosAnchor = (
294-
this.pmView.dom.firstChild! as HTMLElement
295-
).getBoundingClientRect().x;
293+
294+
if (this.pmView.dom.firstChild) {
295+
this.horizontalPosAnchor = (
296+
this.pmView.dom.firstChild as HTMLElement
297+
).getBoundingClientRect().x;
298+
}
296299

297300
this.pmView.root.addEventListener(
298301
"drop",
@@ -337,8 +340,12 @@ export class SideMenuView<
337340
// size/position, so we get the boundingRect of the first child (i.e. the
338341
// blockGroup that wraps all blocks in the editor) for more accurate side
339342
// menu placement.
343+
if (!this.pmView.dom.firstChild) {
344+
return;
345+
}
346+
340347
const editorBoundingBox = (
341-
this.pmView.dom.firstChild! as HTMLElement
348+
this.pmView.dom.firstChild as HTMLElement
342349
).getBoundingClientRect();
343350

344351
this.horizontalPosAnchor = editorBoundingBox.x;
@@ -441,7 +448,7 @@ export class SideMenuView<
441448
if (!pos || pos.inside === -1) {
442449
const evt = new Event("drop", event) as any;
443450
const editorBoundingBox = (
444-
this.pmView.dom.firstChild! as HTMLElement
451+
this.pmView.dom.firstChild as HTMLElement
445452
).getBoundingClientRect();
446453
evt.clientX =
447454
event.clientX < editorBoundingBox.left ||
@@ -474,10 +481,10 @@ export class SideMenuView<
474481
top: event.clientY,
475482
});
476483

477-
if (!pos || pos.inside === -1) {
484+
if (!pos || (pos.inside === -1 && this.pmView.dom.firstChild)) {
478485
const evt = new Event("dragover", event) as any;
479486
const editorBoundingBox = (
480-
this.pmView.dom.firstChild! as HTMLElement
487+
this.pmView.dom.firstChild as HTMLElement
481488
).getBoundingClientRect();
482489
evt.clientX = editorBoundingBox.left + editorBoundingBox.width / 2;
483490
evt.clientY = event.clientY;
@@ -555,8 +562,8 @@ export class SideMenuView<
555562
};
556563

557564
onScroll = () => {
558-
if (this.state?.show) {
559-
const blockContent = this.hoveredBlock!.firstChild as HTMLElement;
565+
if (this.state?.show && this.hoveredBlock?.firstChild) {
566+
const blockContent = this.hoveredBlock.firstChild as HTMLElement;
560567
const blockContentBoundingBox = blockContent.getBoundingClientRect();
561568

562569
this.state.referencePos = new DOMRect(
@@ -624,7 +631,11 @@ export class SideMenuView<
624631
this.emitUpdate(this.state);
625632
}
626633

627-
const blockContent = this.hoveredBlock!.firstChild! as HTMLElement;
634+
if (!this.hoveredBlock?.firstChild) {
635+
return;
636+
}
637+
638+
const blockContent = this.hoveredBlock.firstChild as HTMLElement;
628639
const blockContentBoundingBox = blockContent.getBoundingClientRect();
629640

630641
const pos = this.pmView.posAtCoords({

packages/core/src/extensions/SuggestionMenu/SuggestionPlugin.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class SuggestionMenuView<
5454
const decorationNode = this.rootEl?.querySelector(
5555
`[data-decoration-id="${this.pluginState!.decorationId}"]`
5656
);
57-
this.state.referencePos = decorationNode!.getBoundingClientRect();
57+
if (!decorationNode) {
58+
return;
59+
}
60+
this.state.referencePos = decorationNode.getBoundingClientRect();
5861
this.emitUpdate(this.pluginState!.triggerCharacter!);
5962
}
6063
};
@@ -89,10 +92,10 @@ class SuggestionMenuView<
8992
`[data-decoration-id="${this.pluginState!.decorationId}"]`
9093
);
9194

92-
if (this.editor.isEditable) {
95+
if (this.editor.isEditable && decorationNode) {
9396
this.state = {
9497
show: true,
95-
referencePos: decorationNode!.getBoundingClientRect(),
98+
referencePos: decorationNode.getBoundingClientRect(),
9699
query: this.pluginState!.query,
97100
};
98101

packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ export class TableHandlesView<
159159
const rowIndex = getChildIndex(target.parentElement!);
160160
const cellRect = target.getBoundingClientRect();
161161
const tableRect =
162-
target.parentElement!.parentElement!.getBoundingClientRect();
162+
target.parentElement?.parentElement?.getBoundingClientRect();
163+
164+
if (!tableRect) {
165+
return;
166+
}
163167

164168
const blockEl = getDraggableBlockFromElement(target, this.pmView);
165169
if (!blockEl) {

packages/dev-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
"../../.eslintrc.js"
3131
]
3232
}
33-
}
33+
}

0 commit comments

Comments
 (0)