-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): add toolbar registry extension
- Loading branch information
Showing
10 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
blocksuite/affine/shared/src/services/toolbar-service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './module'; | ||
export * from './registry'; |
5 changes: 5 additions & 0 deletions
5
blocksuite/affine/shared/src/services/toolbar-service/module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { BlockFlavourIdentifier } from '@blocksuite/block-std'; | ||
|
||
export abstract class ToolbarModule { | ||
constructor(public readonly id: ReturnType<typeof BlockFlavourIdentifier>) {} | ||
} |
59 changes: 59 additions & 0 deletions
59
blocksuite/affine/shared/src/services/toolbar-service/registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
type BlockStdScope, | ||
LifeCycleWatcher, | ||
StdIdentifier, | ||
} from '@blocksuite/block-std'; | ||
import { | ||
type Container, | ||
createIdentifier, | ||
createScope, | ||
} from '@blocksuite/global/di'; | ||
import type { ExtensionType } from '@blocksuite/store'; | ||
|
||
import type { ToolbarModule } from './module'; | ||
|
||
export const ToolbarModuleIdentifier = createIdentifier<ToolbarModule>( | ||
'AffineToolbarModuleIdentifier' | ||
); | ||
|
||
export const ToolbarModulesIdentifier = createIdentifier< | ||
Map<string, ToolbarModule> | ||
>('AffineToolbarModulesIdentifier'); | ||
|
||
export const ToolbarRegistryScope = createScope('AffineToolbarRegistryScope'); | ||
|
||
export const ToolbarRegistryIdentifier = | ||
createIdentifier<ToolbarRegistryExtension>('AffineToolbarRegistryIdentifier'); | ||
|
||
export function ToolbarModuleExtension(module: ToolbarModule): ExtensionType { | ||
return { | ||
setup: di => { | ||
di.scope(ToolbarRegistryScope).addImpl( | ||
ToolbarModuleIdentifier(module.id.variant), | ||
module | ||
); | ||
}, | ||
}; | ||
} | ||
|
||
export class ToolbarRegistryExtension extends LifeCycleWatcher { | ||
constructor( | ||
std: BlockStdScope, | ||
readonly modules: Map<string, ToolbarModule> | ||
) { | ||
super(std); | ||
} | ||
|
||
static override readonly key = 'toolbar-registry'; | ||
|
||
static override setup(di: Container) { | ||
di.scope(ToolbarRegistryScope) | ||
.addImpl(ToolbarModulesIdentifier, provider => | ||
provider.getAll(ToolbarModuleIdentifier) | ||
) | ||
.addImpl(ToolbarRegistryIdentifier, this, [ | ||
StdIdentifier, | ||
ToolbarModulesIdentifier, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
import { | ||
ToolbarRegistryIdentifier, | ||
ToolbarRegistryScope, | ||
} from '@blocksuite/affine-shared/services'; | ||
import { WidgetComponent } from '@blocksuite/block-std'; | ||
|
||
export const AFFINE_TOOLBAR_WIDGET = 'affine-toolbar-widget'; | ||
|
||
export class AffineToolbarWidget extends WidgetComponent {} | ||
export class AffineToolbarWidget extends WidgetComponent { | ||
override connectedCallback() { | ||
super.connectedCallback(); | ||
|
||
const toolbarRegistry = this.std.container | ||
.provider(ToolbarRegistryScope, this.std.provider) | ||
.get(ToolbarRegistryIdentifier); | ||
console.log(toolbarRegistry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters