mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-03 23:22:53 +03:00
fix: workaround dom not found
This commit is contained in:
parent
1b3ef42ef6
commit
52819e2f81
@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
import { Protocol } from '@toeverything/datasource/db-service';
|
||||||
import { domToRect, Point } from '@toeverything/utils';
|
import { domToRect, Point } from '@toeverything/utils';
|
||||||
import { AsyncBlock } from '../..';
|
import { AsyncBlock } from '../..';
|
||||||
import { GridDropType } from '../commands/types';
|
import { GridDropType } from '../commands/types';
|
||||||
@ -6,7 +7,6 @@ import { Editor } from '../editor';
|
|||||||
import { BlockDropPlacement, GroupDirection } from '../types';
|
import { BlockDropPlacement, GroupDirection } from '../types';
|
||||||
// TODO: Evaluate implementing custom events with Rxjs
|
// TODO: Evaluate implementing custom events with Rxjs
|
||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
import { Protocol } from '@toeverything/datasource/db-service';
|
|
||||||
|
|
||||||
enum DragType {
|
enum DragType {
|
||||||
dragBlock = 'dragBlock',
|
dragBlock = 'dragBlock',
|
||||||
@ -281,6 +281,10 @@ export class DragDropManager {
|
|||||||
this._editor.getRootBlockId()
|
this._editor.getRootBlockId()
|
||||||
);
|
);
|
||||||
let direction = BlockDropPlacement.none;
|
let direction = BlockDropPlacement.none;
|
||||||
|
if (!rootBlock || !rootBlock.dom) {
|
||||||
|
console.warn('Can not find dom bind with block', rootBlock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const rootBlockRect = domToRect(rootBlock.dom);
|
const rootBlockRect = domToRect(rootBlock.dom);
|
||||||
let targetBlock: AsyncBlock | undefined;
|
let targetBlock: AsyncBlock | undefined;
|
||||||
let typesInfo = {
|
let typesInfo = {
|
||||||
@ -303,6 +307,10 @@ export class DragDropManager {
|
|||||||
if (direction !== BlockDropPlacement.none) {
|
if (direction !== BlockDropPlacement.none) {
|
||||||
const blockList = await this._editor.getBlockListByLevelOrder();
|
const blockList = await this._editor.getBlockListByLevelOrder();
|
||||||
targetBlock = blockList.find(block => {
|
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 domRect = domToRect(block.dom);
|
||||||
const pointChecker =
|
const pointChecker =
|
||||||
direction === BlockDropPlacement.outerLeft
|
direction === BlockDropPlacement.outerLeft
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
import {
|
import {
|
||||||
|
debounce,
|
||||||
domToRect,
|
domToRect,
|
||||||
|
getBlockIdByDom,
|
||||||
|
last,
|
||||||
Point,
|
Point,
|
||||||
Rect,
|
Rect,
|
||||||
last,
|
|
||||||
without,
|
without,
|
||||||
debounce,
|
|
||||||
getBlockIdByDom,
|
|
||||||
} from '@toeverything/utils';
|
} from '@toeverything/utils';
|
||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
|
|
||||||
|
import { Protocol } from '@toeverything/datasource/db-service';
|
||||||
import { BlockEditor } from '../..';
|
import { BlockEditor } from '../..';
|
||||||
import { AsyncBlock } from '../block';
|
import { AsyncBlock } from '../block';
|
||||||
import { VirgoSelection } from '../types';
|
import { VirgoSelection } from '../types';
|
||||||
@ -18,19 +19,17 @@ import {
|
|||||||
changeEventName,
|
changeEventName,
|
||||||
CursorTypes,
|
CursorTypes,
|
||||||
IdList,
|
IdList,
|
||||||
|
SelectBlock,
|
||||||
selectEndEventName,
|
selectEndEventName,
|
||||||
SelectEventCallbackTypes,
|
SelectEventCallbackTypes,
|
||||||
SelectEventTypes,
|
SelectEventTypes,
|
||||||
|
SelectInfo,
|
||||||
SelectionSettings,
|
SelectionSettings,
|
||||||
SelectionSettingsMap,
|
SelectionSettingsMap,
|
||||||
SelectionTypes,
|
SelectionTypes,
|
||||||
SelectPosition,
|
SelectPosition,
|
||||||
SelectBlock,
|
|
||||||
SelectInfo,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
import { isLikeBlockListIds } from './utils';
|
import { isLikeBlockListIds } from './utils';
|
||||||
import { Protocol } from '@toeverything/datasource/db-service';
|
|
||||||
import { Editor } from 'slate';
|
|
||||||
// IMP: maybe merge active and select into single function
|
// IMP: maybe merge active and select into single function
|
||||||
|
|
||||||
export type SelectionInfo = InstanceType<
|
export type SelectionInfo = InstanceType<
|
||||||
@ -336,12 +335,12 @@ export class SelectionManager implements VirgoSelection {
|
|||||||
});
|
});
|
||||||
for await (const childBlock of selectableChildren) {
|
for await (const childBlock of selectableChildren) {
|
||||||
const { dom } = childBlock;
|
const { dom } = childBlock;
|
||||||
if (dom && selectionRect.isIntersect(domToRect(dom))) {
|
|
||||||
selectedNodes.push(childBlock);
|
|
||||||
}
|
|
||||||
if (!dom) {
|
if (!dom) {
|
||||||
console.warn('can not find dom bind with block');
|
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 just only has one selected maybe select the children
|
||||||
if (selectedNodes.length === 1) {
|
if (selectedNodes.length === 1) {
|
||||||
@ -1063,10 +1062,10 @@ export class SelectionManager implements VirgoSelection {
|
|||||||
index: number,
|
index: number,
|
||||||
blockId: string
|
blockId: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let preRang = document.createRange();
|
const preRang = document.createRange();
|
||||||
preRang.setStart(nowRange.startContainer, index);
|
preRang.setStart(nowRange.startContainer, index);
|
||||||
preRang.setEnd(nowRange.endContainer, index);
|
preRang.setEnd(nowRange.endContainer, index);
|
||||||
let prePosition = preRang.getClientRects().item(0);
|
const prePosition = preRang.getClientRects().item(0);
|
||||||
this.activeNodeByNodeId(
|
this.activeNodeByNodeId(
|
||||||
blockId,
|
blockId,
|
||||||
new Point(prePosition.left, prePosition.bottom)
|
new Point(prePosition.left, prePosition.bottom)
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { HookType, BlockDropPlacement } from '@toeverything/framework/virgo';
|
import { BlockDropPlacement, HookType } 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 { domToRect, last, Point } from '@toeverything/utils';
|
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;
|
const DRAG_THROTTLE_DELAY = 60;
|
||||||
export class LeftMenuPlugin extends BasePlugin {
|
export class LeftMenuPlugin extends BasePlugin {
|
||||||
private _mousedown?: boolean;
|
private _mousedown?: boolean;
|
||||||
@ -111,6 +111,10 @@ export class LeftMenuPlugin extends BasePlugin {
|
|||||||
block.dom,
|
block.dom,
|
||||||
block.id
|
block.id
|
||||||
);
|
);
|
||||||
|
if (!targetBlock.dom) {
|
||||||
|
console.warn('Can not find dom bind with block', targetBlock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._lineInfo.next({
|
this._lineInfo.next({
|
||||||
direction,
|
direction,
|
||||||
blockInfo: {
|
blockInfo: {
|
||||||
|
Loading…
Reference in New Issue
Block a user