mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 06:16:59 +08:00
refactor(editor): remove global types in config (#10143)
Closes: [BS-2554](https://linear.app/affine-design/issue/BS-2554/remove-global-types-in-block-config)
This commit is contained in:
@@ -50,13 +50,3 @@ export const HeadingBlockSchema = defineBlockSchema({
|
||||
export class HeadingBlockModel extends BlockModel<
|
||||
ReturnType<(typeof HeadingBlockSchema)['model']['props']>
|
||||
> {}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'test:page': RootBlockModel;
|
||||
'test:note': NoteBlockModel;
|
||||
'test:heading': HeadingBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ServiceIdentifier } from '@blocksuite/global/di';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
|
||||
import { ConfigIdentifier } from '../identifier.js';
|
||||
@@ -15,17 +16,25 @@ import { ConfigIdentifier } from '../identifier.js';
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { ConfigExtension } from '@blocksuite/block-std';
|
||||
* const MyConfigExtension = ConfigExtension('my-flavour', config);
|
||||
* import { ConfigExtensionFactory } from '@blocksuite/block-std';
|
||||
* const MyConfigExtensionFactory = ConfigExtensionFactory<ConfigType>('my-flavour');
|
||||
* const MyConfigExtension = MyConfigExtensionFactory({
|
||||
* option1: 'value1',
|
||||
* option2: 'value2',
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function ConfigExtension(
|
||||
flavor: string,
|
||||
config: Record<string, unknown>
|
||||
): ExtensionType {
|
||||
return {
|
||||
export function ConfigExtensionFactory<Config extends Record<string, any>>(
|
||||
flavor: string
|
||||
): ((config: Config) => ExtensionType) & {
|
||||
identifier: ServiceIdentifier<Config>;
|
||||
} {
|
||||
const identifier = ConfigIdentifier(flavor) as ServiceIdentifier<Config>;
|
||||
const extensionFactory = (config: Config): ExtensionType => ({
|
||||
setup: di => {
|
||||
di.addImpl(ConfigIdentifier(flavor), () => config);
|
||||
},
|
||||
};
|
||||
});
|
||||
extensionFactory.identifier = identifier;
|
||||
return extensionFactory;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import { SurfaceMiddlewareExtension } from '../gfx/surface-middleware.js';
|
||||
import { ViewManager } from '../gfx/view/view-manager.js';
|
||||
import {
|
||||
BlockViewIdentifier,
|
||||
ConfigIdentifier,
|
||||
LifeCycleWatcherIdentifier,
|
||||
StdIdentifier,
|
||||
} from '../identifier.js';
|
||||
@@ -137,19 +136,6 @@ export class BlockStdScope {
|
||||
});
|
||||
}
|
||||
|
||||
getConfig<Key extends BlockSuite.ConfigKeys>(
|
||||
flavour: Key
|
||||
): BlockSuite.BlockConfigs[Key] | null;
|
||||
|
||||
getConfig(flavour: string) {
|
||||
const config = this.provider.getOptional(ConfigIdentifier(flavour));
|
||||
if (!config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
getView(flavour: string) {
|
||||
return this.getOptional(BlockViewIdentifier(flavour));
|
||||
}
|
||||
@@ -191,11 +177,3 @@ export class BlockStdScope {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockConfigs {}
|
||||
|
||||
type ConfigKeys = string & keyof BlockConfigs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user