Merge pull request #368 from toeverything/feat/doublelink220820

Feat/doublelink220820
This commit is contained in:
xiaodong zuo
2022-09-06 16:25:39 +08:00
committed by GitHub
24 changed files with 643 additions and 186 deletions
@@ -5,13 +5,14 @@ import type {
} from '@toeverything/components/common';
import {
BaseRange,
Location,
Node,
Path,
Point,
Selection as SlateSelection,
} from 'slate';
import { Editor } from '../editor';
import { AsyncBlock } from '../block';
import { Editor } from '../editor';
import { SelectBlock } from '../selection';
type TextUtilsFunctions =
@@ -44,6 +45,7 @@ type TextUtilsFunctions =
| 'setSelection'
| 'insertNodes'
| 'getNodeByPath'
| 'wrapLink'
| 'getNodeByRange'
| 'convertLeaf2Html';
@@ -160,7 +162,7 @@ export class BlockHelper {
if (properties.text.value.length === 0) {
return properties;
}
let text_value = properties.text.value;
const text_value = properties.text.value;
const {
text: { value: originTextValue, ...otherTextProperties },
@@ -517,4 +519,13 @@ export class BlockHelper {
console.warn('Could find the block text utils');
return undefined;
}
public wrapLink(blockId: string, url: string, preSelection?: Location) {
const text_utils = this._blockTextUtilsMap[blockId];
if (text_utils) {
return text_utils.wrapLink(url, preSelection);
}
console.warn('Could find the block text utils');
return undefined;
}
}
@@ -13,8 +13,6 @@ import type {
BlockFlavors,
ReturnEditorBlock,
} from '@toeverything/datasource/db-service';
import type { IdList, SelectionInfo, SelectionManager } from './selection';
import { Point } from '@toeverything/utils';
import { Observable } from 'rxjs';
import type { AsyncBlock } from './block';
@@ -23,6 +21,7 @@ import type { BlockCommands } from './commands/block-commands';
import type { DragDropManager } from './drag-drop';
import { MouseManager } from './mouse';
import { ScrollManager } from './scroll';
import type { IdList, SelectionInfo, SelectionManager } from './selection';
// import { BrowserClipboard } from './clipboard/browser-clipboard';
@@ -114,6 +113,7 @@ export interface Virgo {
getGroupBlockByPoint: (point: Point) => Promise<AsyncBlock>;
isEdgeless: boolean;
mouseManager: MouseManager;
getHooks: () => HooksRunner & PluginHooks;
}
export interface Plugin {
@@ -4,7 +4,7 @@ import {
BlockDecoration,
MapOperation,
} from '@toeverything/datasource/jwt';
import type { ComponentType, ReactElement } from 'react';
import { ComponentType, ReactElement } from 'react';
import type { EventData } from '../block';
import { AsyncBlock } from '../block';
import { HTML2BlockResult } from '../clipboard';
@@ -108,7 +108,11 @@ export abstract class BaseView {
// Whether the component is empty
isEmpty(block: AsyncBlock): boolean {
const text = block.getProperty('text');
const result = !text?.value?.[0]?.text;
// const result = !text?.value?.[0]?.text;
const result =
text?.value?.findIndex(
(item: any) => item.text || item.children?.length
) === -1;
// Assert that the text is really empty
if (