akumatus
2024-07-23 15:24:57 +00:00
parent 0dbed968a0
commit f89945e730
19 changed files with 123 additions and 128 deletions
@@ -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';
@@ -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 {
@@ -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';
@@ -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 }),
]);
@@ -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 }),
]);
@@ -1,4 +1,4 @@
import { Bound } from '@blocksuite/blocks';
import { Bound } from '@blocksuite/global/utils';
import { nanoid } from '@blocksuite/store';
import { AIProvider } from '../provider';
@@ -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;
}
@@ -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
);