mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-22 18:11:32 +03:00
fix: workaround dom not found
This commit is contained in:
parent
1b3ef42ef6
commit
52819e2f81
@ -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
|
||||
|
@ -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)
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { HookType, BlockDropPlacement } from '@toeverything/framework/virgo';
|
||||
import { StrictMode } from 'react';
|
||||
import { BasePlugin } from '../../base-plugin';
|
||||
import { ignoreBlockTypes } from './menu-config';
|
||||
import {
|
||||
LineInfoSubject,
|
||||
LeftMenuDraggable,
|
||||
BlockDomInfo,
|
||||
} from './LeftMenuDraggable';
|
||||
import { PluginRenderRoot } from '../../utils';
|
||||
import { Subject, throttleTime } from 'rxjs';
|
||||
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 { PluginRenderRoot } from '../../utils';
|
||||
import {
|
||||
BlockDomInfo,
|
||||
LeftMenuDraggable,
|
||||
LineInfoSubject,
|
||||
} from './LeftMenuDraggable';
|
||||
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: {
|
||||
|
Loading…
Reference in New Issue
Block a user