Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: workaround dom not found

lawvs52819e2f81a9
diff --git a/libs/components/editor-core/src/editor/drag-drop/drag-drop.ts b/libs/components/editor-core/src/editor/drag-drop/drag-drop.ts
index 9da0ed55ee..a96de8eb93 100644
--- a/libs/components/editor-core/src/editor/drag-drop/drag-drop.ts
+++ b/libs/components/editor-core/src/editor/drag-drop/drag-drop.ts
@@ -1,4 +1,5 @@
/* eslint-disable max-lines */
+import { Protocol } from '@toeverything/datasource/db-service';
import { domToRect, Point } from '@toeverything/utils';
import { AsyncBlock } from '../..';
import { GridDropType } from '../commands/types';
@@ -6,7 +7,6 @@ import { Editor } from '../editor';
import { BlockDropPlacement, GroupDirection } from '../types';
// TODO: Evaluate implementing custom events with Rxjs
import EventEmitter from 'eventemitter3';
-import { Protocol } from '@toeverything/datasource/db-service';
enum DragType {
dragBlock = 'dragBlock',
@@ -281,6 +281,10 @@ export class DragDropManager {
this._editor.getRootBlockId()
);
let direction = BlockDropPlacement.none;
+ if (!rootBlock || !rootBlock.dom) {
+ console.warn('Can not find dom bind with block', rootBlock);
+ return;
+ }
const rootBlockRect = domToRect(rootBlock.dom);
let targetBlock: AsyncBlock | undefined;
let typesInfo = {
@@ -303,6 +307,10 @@ export class DragDropManager {
if (direction !== BlockDropPlacement.none) {
const blockList = await this._editor.getBlockListByLevelOrder();
targetBlock = blockList.find(block => {
+ if (!block.dom) {
+ console.warn('Can not find dom bind with block', block);
+ return false;
+ }
const domRect = domToRect(block.dom);
const pointChecker =
direction === BlockDropPlacement.outerLeft
diff --git a/libs/components/editor-core/src/editor/selection/selection.ts b/libs/components/editor-core/src/editor/selection/selection.ts
index 406f9adecb..e6c1f94c83 100644
--- a/libs/components/editor-core/src/editor/selection/selection.ts
+++ b/libs/components/editor-core/src/editor/selection/selection.ts
@@ -1,15 +1,16 @@
/* eslint-disable max-lines */
import {
+ debounce,
domToRect,
+ getBlockIdByDom,
+ last,
Point,
Rect,
- last,
without,
- debounce,
- getBlockIdByDom,
} from '@toeverything/utils';
import EventEmitter from 'eventemitter3';
+import { Protocol } from '@toeverything/datasource/db-service';
import { BlockEditor } from '../..';
import { AsyncBlock } from '../block';
import { VirgoSelection } from '../types';
@@ -18,19 +19,17 @@ import {
changeEventName,
CursorTypes,
IdList,
+ SelectBlock,
selectEndEventName,
SelectEventCallbackTypes,
SelectEventTypes,
+ SelectInfo,
SelectionSettings,
SelectionSettingsMap,
SelectionTypes,
SelectPosition,
- SelectBlock,
- SelectInfo,
} from './types';
import { isLikeBlockListIds } from './utils';
-import { Protocol } from '@toeverything/datasource/db-service';
-import { Editor } from 'slate';
// IMP: maybe merge active and select into single function
export type SelectionInfo = InstanceType<
@@ -336,12 +335,12 @@ export class SelectionManager implements VirgoSelection {
});
for await (const childBlock of selectableChildren) {
const { dom } = childBlock;
- if (dom && selectionRect.isIntersect(domToRect(dom))) {
- selectedNodes.push(childBlock);
- }
if (!dom) {
console.warn('can not find dom bind with block');
}
+ if (dom && selectionRect.isIntersect(domToRect(dom))) {
+ selectedNodes.push(childBlock);
+ }
}
// if just only has one selected maybe select the children
if (selectedNodes.length === 1) {
@@ -1063,10 +1062,10 @@ export class SelectionManager implements VirgoSelection {
index: number,
blockId: string
): Promise<void> {
- let preRang = document.createRange();
+ const preRang = document.createRange();
preRang.setStart(nowRange.startContainer, index);
preRang.setEnd(nowRange.endContainer, index);
- let prePosition = preRang.getClientRects().item(0);
+ const prePosition = preRang.getClientRects().item(0);
this.activeNodeByNodeId(
blockId,
new Point(prePosition.left, prePosition.bottom)
diff --git a/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx b/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx
index 3b432167ee..9c339e8630 100644
--- a/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx
+++ b/libs/components/editor-plugins/src/menu/left-menu/LeftMenuPlugin.tsx
@@ -1,15 +1,15 @@
-import { HookType, BlockDropPlacement } from '@toeverything/framework/virgo';
+import { BlockDropPlacement, HookType } from '@toeverything/framework/virgo';
+import { domToRect, last, Point } from '@toeverything/utils';
import { StrictMode } from 'react';
+import { Subject, throttleTime } from 'rxjs';
import { BasePlugin } from '../../base-plugin';
-import { ignoreBlockTypes } from './menu-config';
+import { PluginRenderRoot } from '../../utils';
import {
- LineInfoSubject,
- LeftMenuDraggable,
BlockDomInfo,
+ LeftMenuDraggable,
+ LineInfoSubject,
} from './LeftMenuDraggable';
-import { PluginRenderRoot } from '../../utils';
-import { Subject, throttleTime } from 'rxjs';
-import { domToRect, last, Point } from '@toeverything/utils';
+import { ignoreBlockTypes } from './menu-config';
const DRAG_THROTTLE_DELAY = 60;
export class LeftMenuPlugin extends BasePlugin {
private _mousedown?: boolean;
@@ -111,6 +111,10 @@ export class LeftMenuPlugin extends BasePlugin {
block.dom,
block.id
);
+ if (!targetBlock.dom) {
+ console.warn('Can not find dom bind with block', targetBlock);
+ return;
+ }
this._lineInfo.next({
direction,
blockInfo: {