mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 16:19:43 +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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user