refactor(editor): remove block models global type (#10086)

This commit is contained in:
Saul-Mirone
2025-02-11 11:00:57 +00:00
parent a725df6ebe
commit 39eb8625d6
157 changed files with 402 additions and 621 deletions

View File

@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
import type { Command } from '../command/index.js';
import { CommandManager } from '../command/index.js';
import type { BlockStdScope } from '../scope/block-std-scope.js';
type Command1 = Command<
{
@@ -15,7 +16,7 @@ type Command1 = Command<
type Command2 = Command<{ commandData1: string }, { commandData2: string }>;
describe('CommandManager', () => {
let std: BlockSuite.Std;
let std: BlockStdScope;
let commandManager: CommandManager;
beforeEach(() => {

View File

@@ -8,7 +8,7 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* Commands are functions that take a context and a next function as arguments
*
* ```ts
* const myCommand: Command<'count', 'count'> = (ctx, next) => {
* const myCommand: Command<input, output> = (ctx, next) => {
* const count = ctx.count || 0;
*
* const success = someOperation();
@@ -19,40 +19,17 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* return;
* ```
*
* You should always add the command to the global interface `BlockSuite.Commands`
* ```ts
* declare global {
* namespace BlockSuite {
* interface Commands {
* 'myCommand': typeof myCommand
* }
* }
* }
* ```
*
* Command input and output data can be defined in the `Command` type
*
* ```ts
* // input: ctx.firstName, ctx.lastName
* // output: ctx.fullName
* const myCommand: Command<'firstName' | 'lastName', 'fullName'> = (ctx, next) => {
* const myCommand: Command<{ firstName: string; lastName: string }, { fullName: string }> = (ctx, next) => {
* const { firstName, lastName } = ctx;
* const fullName = `${firstName} ${lastName}`;
* return next({ fullName });
* }
*
* declare global {
* namespace BlockSuite {
* interface CommandContext {
* // All command input and output data should be defined here
* // The keys should be optional
* firstName?: string;
* lastName?: string;
* fullName?: string;
* }
* }
* }
*
* ```
*
*
@@ -63,7 +40,7 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* 1. Using `exec` method
* `exec` is used to run a single command
* ```ts
* const { success, ...data } = commandManager.exec('myCommand', payload);
* const [result, data] = commandManager.exec(myCommand, payload);
* ```
*
* 2. Using `chain` method
@@ -71,8 +48,8 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* ```ts
* const chain = commandManager.chain();
* const [result, data] = chain
* .myCommand1()
* .myCommand2(payload)
* .pipe(myCommand1)
* .pipe(myCommand2, payload)
* .run();
* ```
*
@@ -83,8 +60,8 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* ```ts
* const chain = commandManager.chain();
* const [result, data] = chain
* .myCommand1() <-- if this fail
* .myCommand2(payload) <- this won't run
* .chain(myCommand1) <-- if this fail
* .chain(myCommand2, payload) <- this won't run
* .run();
*
* result <- result will be `false`
@@ -95,9 +72,9 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* const chain = commandManager.chain();
* const [result, data] = chain
* .try(chain => [
* chain.myCommand1(), <- if this fail
* chain.myCommand2(), <- this will run, if this success
* chain.myCommand3(), <- this won't run
* chain.pipe(myCommand1), <- if this fail
* chain.pipe(myCommand2, payload), <- this will run, if this success
* chain.pipe(myCommand3), <- this won't run
* ])
* .run();
* ```
@@ -107,9 +84,9 @@ import type { Chain, Command, InitCommandCtx } from './types.js';
* const chain = commandManager.chain();
* const [result, data] = chain
* .try(chain => [
* chain.myCommand1(), <- if this success
* chain.myCommand2(), <- this will also run
* chain.myCommand3(), <- so will this
* chain.pipe(myCommand1), <- if this success
* chain.pipe(myCommand2), <- this will also run
* chain.pipe(myCommand3), <- so will this
* ])
* .run();
* ```

View File

@@ -3,6 +3,7 @@ import { DisposableGroup } from '@blocksuite/global/utils';
import { LifeCycleWatcher } from '../extension/index.js';
import { KeymapIdentifier } from '../identifier.js';
import type { BlockStdScope } from '../scope/index.js';
import { type BlockComponent, EditorHost } from '../view/index.js';
import {
type UIEventHandler,
@@ -111,7 +112,7 @@ export class UIEventDispatcher extends LifeCycleWatcher {
return this.std.host;
}
constructor(std: BlockSuite.Std) {
constructor(std: BlockStdScope) {
super(std);
this._pointerControl = new PointerControl(this);
this._keyboardControl = new KeyboardControl(this);

View File

@@ -22,7 +22,7 @@ import type { BlockViewType } from '../spec/type.js';
* ```
*/
export function BlockViewExtension(
flavour: BlockSuite.Flavour,
flavour: string,
view: BlockViewType
): ExtensionType {
return {

View File

@@ -20,7 +20,7 @@ import { ConfigIdentifier } from '../identifier.js';
* ```
*/
export function ConfigExtension(
flavor: BlockSuite.Flavour,
flavor: string,
config: Record<string, unknown>
): ExtensionType {
return {

View File

@@ -21,7 +21,7 @@ import type { WidgetViewMapType } from '../spec/type.js';
* });
*/
export function WidgetViewMapExtension(
flavour: BlockSuite.Flavour,
flavour: string,
widgetViewMap: WidgetViewMapType
): ExtensionType {
return {

View File

@@ -213,7 +213,5 @@ declare global {
type ServiceKeys = string & keyof BlockServices;
type ConfigKeys = string & keyof BlockConfigs;
type Std = BlockStdScope;
}
}

View File

@@ -185,7 +185,7 @@ export class EditorHost extends SignalWatcher(
@provide({ context: stdContext })
@property({ attribute: false })
accessor std!: BlockSuite.Std;
accessor std!: BlockStdScope;
}
declare global {