mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
refactor(editor): remove dependency of command global types (#9903)
Closes: [BS-2216](https://linear.app/affine-design/issue/BS-2216/remove-global-types-in-command)
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
BlocksUtils,
|
||||
DocModeProvider,
|
||||
EditPropsStore,
|
||||
getSelectedBlocksCommand,
|
||||
NoteDisplayMode,
|
||||
NotificationProvider,
|
||||
RefNodeSlotsProvider,
|
||||
@@ -216,13 +217,10 @@ const REPLACE_SELECTION = {
|
||||
) => {
|
||||
const currentTextSelection = currentSelections.text;
|
||||
const currentBlockSelections = currentSelections.blocks;
|
||||
const [_, data] = host.command
|
||||
.chain()
|
||||
.getSelectedBlocks({
|
||||
currentTextSelection,
|
||||
currentBlockSelections,
|
||||
})
|
||||
.run();
|
||||
const [_, data] = host.command.exec(getSelectedBlocksCommand, {
|
||||
currentTextSelection,
|
||||
currentBlockSelections,
|
||||
});
|
||||
if (!data.selectedBlocks) return false;
|
||||
|
||||
reportResponse('result:replace');
|
||||
@@ -264,14 +262,11 @@ const INSERT_BELOW = {
|
||||
const currentTextSelection = currentSelections.text;
|
||||
const currentBlockSelections = currentSelections.blocks;
|
||||
const currentImageSelections = currentSelections.images;
|
||||
const [_, data] = host.command
|
||||
.chain()
|
||||
.getSelectedBlocks({
|
||||
currentTextSelection,
|
||||
currentBlockSelections,
|
||||
currentImageSelections,
|
||||
})
|
||||
.run();
|
||||
const [_, data] = host.command.exec(getSelectedBlocksCommand, {
|
||||
currentTextSelection,
|
||||
currentBlockSelections,
|
||||
currentImageSelections,
|
||||
});
|
||||
if (!data.selectedBlocks) return false;
|
||||
reportResponse('result:insert');
|
||||
await insertBelow(
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Chain, InitCommandCtx } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
type AIItemGroupConfig,
|
||||
type AISubItemConfig,
|
||||
getSelectedModelsCommand,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
|
||||
@@ -94,7 +95,7 @@ const blockActionTrackerOptions: BlockSuitePresets.TrackerOptions = {
|
||||
|
||||
const textBlockShowWhen = (chain: Chain<InitCommandCtx>) => {
|
||||
const [_, ctx] = chain
|
||||
.getSelectedModels({
|
||||
.pipe(getSelectedModelsCommand, {
|
||||
types: ['block', 'text'],
|
||||
})
|
||||
.run();
|
||||
@@ -108,7 +109,7 @@ const textBlockShowWhen = (chain: Chain<InitCommandCtx>) => {
|
||||
|
||||
const codeBlockShowWhen = (chain: Chain<InitCommandCtx>) => {
|
||||
const [_, ctx] = chain
|
||||
.getSelectedModels({
|
||||
.pipe(getSelectedModelsCommand, {
|
||||
types: ['block', 'text'],
|
||||
})
|
||||
.run();
|
||||
@@ -121,7 +122,7 @@ const codeBlockShowWhen = (chain: Chain<InitCommandCtx>) => {
|
||||
|
||||
const imageBlockShowWhen = (chain: Chain<InitCommandCtx>) => {
|
||||
const [_, ctx] = chain
|
||||
.getSelectedModels({
|
||||
.pipe(getSelectedModelsCommand, {
|
||||
types: ['block'],
|
||||
})
|
||||
.run();
|
||||
@@ -268,7 +269,7 @@ const GenerateWithAIGroup: AIItemGroupConfig = {
|
||||
handler: actionToHandler('createHeadings', AIPenIconWithAnimation),
|
||||
showWhen: chain => {
|
||||
const [_, ctx] = chain
|
||||
.getSelectedModels({
|
||||
.pipe(getSelectedModelsCommand, {
|
||||
types: ['block', 'text'],
|
||||
})
|
||||
.run();
|
||||
|
||||
@@ -6,7 +6,10 @@ import {
|
||||
type TextSelection,
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import type { AffineAIPanelWidget } from '@blocksuite/affine/blocks';
|
||||
import { isInsideEdgelessEditor } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
deleteTextCommand,
|
||||
isInsideEdgelessEditor,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { type BlockModel, Slice } from '@blocksuite/affine/store';
|
||||
|
||||
import {
|
||||
@@ -107,7 +110,7 @@ export const replace = async (
|
||||
);
|
||||
|
||||
if (textSelection) {
|
||||
host.std.command.exec('deleteText', { textSelection });
|
||||
host.std.command.exec(deleteTextCommand, { textSelection });
|
||||
const { snapshot, transformer } = await markdownToSnapshot(content, host);
|
||||
await transformer.snapshotToSlice(
|
||||
snapshot,
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
BlocksUtils,
|
||||
DocModeProvider,
|
||||
embedSyncedDocMiddleware,
|
||||
getImageSelectionsCommand,
|
||||
getSelectedBlocksCommand,
|
||||
type ImageBlockModel,
|
||||
isInsideEdgelessEditor,
|
||||
MarkdownAdapter,
|
||||
@@ -70,8 +72,8 @@ async function extractPageSelected(
|
||||
} else if (!hasText && hasImages && images.length === 1) {
|
||||
host.command
|
||||
.chain()
|
||||
.tryAll(chain => [chain.getImageSelections()])
|
||||
.getSelectedBlocks({
|
||||
.tryAll(chain => [chain.pipe(getImageSelectionsCommand)])
|
||||
.pipe(getSelectedBlocksCommand, {
|
||||
types: ['image'],
|
||||
})
|
||||
.run();
|
||||
|
||||
@@ -5,6 +5,11 @@ import {
|
||||
type CopilotTool,
|
||||
EdgelessRootService,
|
||||
type FrameBlockModel,
|
||||
getBlockSelectionsCommand,
|
||||
getImageSelectionsCommand,
|
||||
getSelectedBlocksCommand,
|
||||
getSelectedModelsCommand,
|
||||
getTextSelectionCommand,
|
||||
ImageBlockModel,
|
||||
type SurfaceBlockComponent,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
@@ -95,12 +100,9 @@ export async function selectedToPng(editor: EditorHost) {
|
||||
}
|
||||
|
||||
export function getSelectedModels(editorHost: EditorHost) {
|
||||
const chain = editorHost.std.command.chain();
|
||||
const [_, ctx] = chain
|
||||
.getSelectedModels({
|
||||
types: ['block', 'text'],
|
||||
})
|
||||
.run();
|
||||
const [_, ctx] = editorHost.std.command.exec(getSelectedModelsCommand, {
|
||||
types: ['block', 'text'],
|
||||
});
|
||||
const { selectedModels } = ctx;
|
||||
return selectedModels;
|
||||
}
|
||||
@@ -246,11 +248,11 @@ export const getSelections = (
|
||||
const [_, data] = host.command
|
||||
.chain()
|
||||
.tryAll(chain => [
|
||||
chain.getTextSelection(),
|
||||
chain.getBlockSelections(),
|
||||
chain.getImageSelections(),
|
||||
chain.pipe(getTextSelectionCommand),
|
||||
chain.pipe(getBlockSelectionsCommand),
|
||||
chain.pipe(getImageSelectionsCommand),
|
||||
])
|
||||
.getSelectedBlocks({ types: ['text', 'block', 'image'], mode })
|
||||
.pipe(getSelectedBlocksCommand, { types: ['text', 'block', 'image'], mode })
|
||||
.run();
|
||||
|
||||
return data;
|
||||
@@ -260,11 +262,11 @@ export const getSelectedImagesAsBlobs = async (host: EditorHost) => {
|
||||
const [_, data] = host.command
|
||||
.chain()
|
||||
.tryAll(chain => [
|
||||
chain.getTextSelection(),
|
||||
chain.getBlockSelections(),
|
||||
chain.getImageSelections(),
|
||||
chain.pipe(getTextSelectionCommand),
|
||||
chain.pipe(getBlockSelectionsCommand),
|
||||
chain.pipe(getImageSelectionsCommand),
|
||||
])
|
||||
.getSelectedBlocks({
|
||||
.pipe(getSelectedBlocksCommand, {
|
||||
types: ['block', 'image'],
|
||||
})
|
||||
.run();
|
||||
|
||||
Reference in New Issue
Block a user