mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +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:
@@ -1,5 +1,5 @@
|
||||
import type { DatabaseBlockModel } from '@blocksuite/affine-model';
|
||||
import type { BlockCommands, Command } from '@blocksuite/block-std';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
@@ -8,12 +8,14 @@ import {
|
||||
} from './data-source';
|
||||
|
||||
export const insertDatabaseBlockCommand: Command<
|
||||
'selectedModels',
|
||||
'insertedDatabaseBlockId',
|
||||
{
|
||||
selectedModels?: BlockModel[];
|
||||
viewType: string;
|
||||
place?: 'after' | 'before';
|
||||
removeEmptyLine?: boolean;
|
||||
},
|
||||
{
|
||||
insertedDatabaseBlockId: string;
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const { selectedModels, viewType, place, removeEmptyLine, std } = ctx;
|
||||
@@ -65,7 +67,3 @@ export const initDatabaseBlock = (
|
||||
doc.addBlock('affine:paragraph', {}, parent.id);
|
||||
}
|
||||
};
|
||||
|
||||
export const commands: BlockCommands = {
|
||||
insertDatabaseBlock: insertDatabaseBlockCommand,
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
ColumnUpdater,
|
||||
DatabaseBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
insertPositionToIndex,
|
||||
@@ -517,12 +518,9 @@ export const databaseViewInitTemplate = (
|
||||
datasource.viewManager.viewAdd(viewType);
|
||||
};
|
||||
export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
||||
const [_, ctx] = host.std.command
|
||||
.chain()
|
||||
.getSelectedModels({
|
||||
types: ['block', 'text'],
|
||||
})
|
||||
.run();
|
||||
const [_, ctx] = host.std.command.exec(getSelectedModelsCommand, {
|
||||
types: ['block', 'text'],
|
||||
});
|
||||
const { selectedModels } = ctx;
|
||||
const firstModel = selectedModels?.[0];
|
||||
if (!firstModel) return;
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import {
|
||||
BlockViewExtension,
|
||||
CommandExtension,
|
||||
FlavourExtension,
|
||||
} from '@blocksuite/block-std';
|
||||
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { DatabaseBlockAdapterExtensions } from './adapters/extension.js';
|
||||
import { commands } from './commands.js';
|
||||
|
||||
export const DatabaseBlockSpec: ExtensionType[] = [
|
||||
FlavourExtension('affine:database'),
|
||||
CommandExtension(commands),
|
||||
BlockViewExtension('affine:database', literal`affine-database`),
|
||||
DatabaseBlockAdapterExtensions,
|
||||
].flat();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { insertDatabaseBlockCommand } from './commands';
|
||||
import { CenterPeek } from './components/layout';
|
||||
import { DatabaseTitle } from './components/title';
|
||||
import type { DatabaseOptionsConfig } from './config';
|
||||
@@ -44,20 +43,5 @@ declare global {
|
||||
interface BlockConfigs {
|
||||
'affine:database': Partial<DatabaseOptionsConfig>;
|
||||
}
|
||||
|
||||
interface CommandContext {
|
||||
insertedDatabaseBlockId?: string;
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
/**
|
||||
* insert a database block after or before the current block selection
|
||||
* @param latex the LaTeX content. A input dialog will be shown if not provided
|
||||
* @param removeEmptyLine remove the current block if it is empty
|
||||
* @param place where to insert the LaTeX block
|
||||
* @returns the id of the inserted LaTeX block
|
||||
*/
|
||||
insertDatabaseBlock: typeof insertDatabaseBlockCommand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type * as CommandType from '@blocksuite/affine-shared/commands';
|
||||
|
||||
declare type _GLOBAL_ = typeof CommandType;
|
||||
|
||||
export * from './adapters';
|
||||
export * from './commands';
|
||||
export type { DatabaseOptionsConfig } from './config';
|
||||
export * from './data-source';
|
||||
export * from './database-block';
|
||||
|
||||
@@ -65,12 +65,4 @@ export class DatabaseSelection extends BaseSelection {
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface Selection {
|
||||
database: typeof DatabaseSelection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const DatabaseSelectionExtension = SelectionExtension(DatabaseSelection);
|
||||
|
||||
Reference in New Issue
Block a user