akumatus
2024-07-23 15:24:57 +00:00
parent 0dbed968a0
commit f89945e730
19 changed files with 123 additions and 128 deletions

View File

@@ -10,7 +10,6 @@ import type {
SurfaceBlockModel,
} from '@blocksuite/blocks';
import {
Bound,
DeleteIcon,
EDGELESS_ELEMENT_TOOLBAR_WIDGET,
EDGELESS_TEXT_BLOCK_MIN_HEIGHT,
@@ -23,7 +22,7 @@ import {
NoteDisplayMode,
ResetIcon,
} from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import { assertExists, Bound } from '@blocksuite/global/utils';
import type { TemplateResult } from 'lit';
import { AIPenIcon, ChatWithAIIcon } from '../_common/icons';

View File

@@ -4,13 +4,12 @@ import {
AffineAIPanelWidget,
type AffineAIPanelWidgetConfig,
type AIItemConfig,
Bound,
ImageBlockModel,
isInsideEdgelessEditor,
matchFlavours,
NoteDisplayMode,
} from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import { assertExists, Bound } from '@blocksuite/global/utils';
import type { TemplateResult } from 'lit';
import {

View File

@@ -3,17 +3,14 @@ import type {
EditorHost,
TextSelection,
} from '@blocksuite/block-std';
import type {
EdgelessRootService,
ImageSelection,
SerializedXYWH,
} from '@blocksuite/blocks';
import type { EdgelessRootService, ImageSelection } from '@blocksuite/blocks';
import {
BlocksUtils,
Bound,
getElementsBound,
NoteDisplayMode,
} from '@blocksuite/blocks';
import type { SerializedXYWH } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils';
import { CreateIcon, InsertBelowIcon, ReplaceIcon } from '../../_common/icons';
import { reportResponse } from '../../utils/action-reporter';

View File

@@ -20,7 +20,7 @@ export function setupCodeToolbarEntry(codeToolbar: AffineCodeToolbarWidget) {
const onAskAIClick = () => {
const { host } = codeToolbar;
const { selection } = host;
const codeBlock = codeToolbar.blockElement;
const codeBlock = codeToolbar.block;
selection.setGroup('note', [
selection.create('block', { blockId: codeBlock.blockId }),
]);

View File

@@ -20,7 +20,7 @@ export function setupImageToolbarEntry(imageToolbar: AffineImageToolbarWidget) {
const onAskAIClick = () => {
const { host } = imageToolbar;
const { selection } = host;
const imageBlock = imageToolbar.blockElement;
const imageBlock = imageToolbar.block;
selection.setGroup('note', [
selection.create('image', { blockId: imageBlock.blockId }),
]);

View File

@@ -1,4 +1,4 @@
import { Bound } from '@blocksuite/blocks';
import { Bound } from '@blocksuite/global/utils';
import { nanoid } from '@blocksuite/store';
import { AIProvider } from '../provider';

View File

@@ -1,4 +1,4 @@
import type { BlockElement, EditorHost } from '@blocksuite/block-std';
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
import {
AFFINE_EDGELESS_COPILOT_WIDGET,
type EdgelessCopilotWidget,
@@ -59,7 +59,7 @@ export function getEdgelessCopilotWidget(
return copilotWidget;
}
export function findNoteBlockModel(blockElement: BlockElement) {
export function findNoteBlockModel(blockElement: BlockComponent) {
let curBlock = blockElement;
while (curBlock) {
if (matchFlavours(curBlock.model, ['affine:note'])) {
@@ -68,7 +68,7 @@ export function findNoteBlockModel(blockElement: BlockElement) {
if (matchFlavours(curBlock.model, ['affine:page', 'affine:surface'])) {
return null;
}
curBlock = curBlock.parentBlockElement;
curBlock = curBlock.parentBlock;
}
return null;
}

View File

@@ -1,5 +1,5 @@
import type {
BlockElement,
BlockComponent,
EditorHost,
TextSelection,
} from '@blocksuite/block-std';
@@ -13,10 +13,10 @@ import {
markdownToSnapshot,
} from './markdown-utils';
const getNoteId = (blockElement: BlockElement) => {
const getNoteId = (blockElement: BlockComponent) => {
let element = blockElement;
while (element && element.flavour !== 'affine:note') {
element = element.parentBlockElement;
while (element.flavour !== 'affine:note') {
element = element.parentBlock;
}
return element.model.id;
@@ -24,7 +24,7 @@ const getNoteId = (blockElement: BlockElement) => {
const setBlockSelection = (
host: EditorHost,
parent: BlockElement,
parent: BlockComponent,
models: BlockModel[]
) => {
const selections = models
@@ -50,10 +50,10 @@ const setBlockSelection = (
export const insert = async (
host: EditorHost,
content: string,
selectBlock: BlockElement,
selectBlock: BlockComponent,
below: boolean = true
) => {
const blockParent = selectBlock.parentBlockElement;
const blockParent = selectBlock.parentBlock;
const index = blockParent.model.children.findIndex(
model => model.id === selectBlock.model.id
);
@@ -72,7 +72,7 @@ export const insert = async (
export const insertBelow = async (
host: EditorHost,
content: string,
selectBlock: BlockElement
selectBlock: BlockComponent
) => {
await insert(host, content, selectBlock, true);
};
@@ -80,7 +80,7 @@ export const insertBelow = async (
export const insertAbove = async (
host: EditorHost,
content: string,
selectBlock: BlockElement
selectBlock: BlockComponent
) => {
await insert(host, content, selectBlock, false);
};
@@ -88,11 +88,11 @@ export const insertAbove = async (
export const replace = async (
host: EditorHost,
content: string,
firstBlock: BlockElement,
firstBlock: BlockComponent,
selectedModels: BlockModel[],
textSelection?: TextSelection
) => {
const firstBlockParent = firstBlock.parentBlockElement;
const firstBlockParent = firstBlock.parentBlock;
const firstIndex = firstBlockParent.model.children.findIndex(
model => model.id === firstBlock.model.id
);

View File

@@ -1,4 +1,4 @@
import type { BlockElement } from '@blocksuite/block-std';
import type { BlockComponent } from '@blocksuite/block-std';
import type {
AffineEditorContainer,
EdgelessEditor,
@@ -56,7 +56,7 @@ type BlocksuiteEditorContainerRef = Pick<
function findBlockElementById(container: HTMLElement, blockId: string) {
const element = container.querySelector(
`[data-block-id="${blockId}"]`
) as BlockElement | null;
) as BlockComponent | null;
return element;
}
@@ -67,7 +67,7 @@ const useBlockElementById = (
blockId: string | undefined,
timeout = 1000
) => {
const [blockElement, setBlockElement] = useState<BlockElement | null>(null);
const [blockElement, setBlockElement] = useState<BlockComponent | null>(null);
useEffect(() => {
if (!blockId) {
return;
@@ -210,7 +210,7 @@ export const BlocksuiteEditorContainer = forwardRef<
useEffect(() => {
let canceled = false;
const handleScrollToBlock = (blockElement: BlockElement) => {
const handleScrollToBlock = (blockElement: BlockComponent) => {
if (!mode || !blockElement) {
return;
}

View File

@@ -1,4 +1,4 @@
import type { BlockElement } from '@blocksuite/block-std';
import type { BlockComponent } from '@blocksuite/block-std';
import {
AffineReference,
type EmbedLinkedDocModel,
@@ -17,7 +17,7 @@ import type { WorkbenchService } from '../../workbench';
export type PeekViewTarget =
| HTMLElement
| BlockElement
| BlockComponent
| AffineReference
| HTMLAnchorElement
| { docId: string; blockId?: string };

View File

@@ -6,8 +6,8 @@ import { BlockSuiteEditor } from '@affine/core/components/blocksuite/block-suite
import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
import { PageNotFound } from '@affine/core/pages/404';
import { DebugLogger } from '@affine/debug';
import { Bound, type EdgelessRootService } from '@blocksuite/blocks';
import { DisposableGroup } from '@blocksuite/global/utils';
import { type EdgelessRootService } from '@blocksuite/blocks';
import { Bound, DisposableGroup } from '@blocksuite/global/utils';
import type { AffineEditorContainer } from '@blocksuite/presets';
import type { DocMode } from '@toeverything/infra';
import { DocsService, FrameworkScope, useService } from '@toeverything/infra';

View File

@@ -1,5 +1,5 @@
import { toReactNode } from '@affine/component';
import { BlockElement } from '@blocksuite/block-std';
import { BlockComponent } from '@blocksuite/block-std';
import { useLiveData, useService } from '@toeverything/infra';
import { useEffect, useMemo } from 'react';
@@ -91,7 +91,7 @@ export const PeekViewManagerModal = () => {
useEffect(() => {
const subscription = peekViewEntity.show$.subscribe(() => {
if (activePeekView?.target instanceof BlockElement) {
if (activePeekView?.target instanceof BlockComponent) {
activePeekView.target.requestUpdate();
}
});