Skip to content

Commit

Permalink
feat(editor): add toolbar registry extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Jan 16, 2025
1 parent 2ccb27a commit 3558eb3
Show file tree
Hide file tree
Showing 35 changed files with 1,231 additions and 31 deletions.
24 changes: 18 additions & 6 deletions blocksuite/affine/block-attachment/src/attachment-spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std';
import { ToolbarModuleExtension } from '@blocksuite/affine-shared/services';
import {
BlockFlavourIdentifier,
BlockViewExtension,
FlavourExtension,
} from '@blocksuite/block-std';
import type { ExtensionType } from '@blocksuite/store';
import { literal } from 'lit/static-html.js';

import { AttachmentBlockNotionHtmlAdapterExtension } from './adapters/notion-html.js';
import { AttachmentBlockNotionHtmlAdapterExtension } from './adapters/notion-html';
import {
AttachmentBlockService,
AttachmentDropOption,
} from './attachment-service.js';
} from './attachment-service';
import { builtinToolbarConfig } from './configs/toolbar';
import {
AttachmentEmbedConfigExtension,
AttachmentEmbedService,
} from './embed.js';
} from './embed';

const Flavour = 'affine:attachment';

export const AttachmentBlockSpec: ExtensionType[] = [
FlavourExtension('affine:attachment'),
FlavourExtension(Flavour),
AttachmentBlockService,
BlockViewExtension('affine:attachment', model => {
BlockViewExtension(Flavour, model => {
return model.parent?.flavour === 'affine:surface'
? literal`affine-edgeless-attachment`
: literal`affine-attachment`;
Expand All @@ -24,4 +32,8 @@ export const AttachmentBlockSpec: ExtensionType[] = [
AttachmentEmbedConfigExtension(),
AttachmentEmbedService,
AttachmentBlockNotionHtmlAdapterExtension,
ToolbarModuleExtension({
id: BlockFlavourIdentifier(Flavour),
config: builtinToolbarConfig,
}),
];
81 changes: 81 additions & 0 deletions blocksuite/affine/block-attachment/src/configs/toolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type {
ToolbarActionGroup,
ToolbarModuleConfig,
} from '@blocksuite/affine-shared/services';

export const builtinToolbarConfig = {
actions: [
{
id: 'rename',
tooltip: 'Rename',
run(_cx) {},
},
{
id: 'conversions',
actions: [
{
id: 'card-view',
label: 'Card view',
run(_cx) {},
},
{
id: 'embed-view',
label: 'Embed view',
run(_cx) {},
},
],
content(_cx) {
this.actions;
return null;
},
} satisfies ToolbarActionGroup,
{
id: 'download',
tooltip: 'Download',
run(_cx) {},
},
{
id: 'caption',
tooltip: 'Caption',
run(_cx) {},
},
{
id: 'clipboard',
placement: 'more',
actions: [
{
id: 'copy',
label: 'Copy',
run(_cx) {},
},
{
id: 'duplicate',
label: 'Duplicate',
run(_cx) {},
},
],
},
{
id: 'refresh',
placement: 'more',
actions: [
{
id: 'reload',
label: 'Reload',
run(_cx) {},
},
],
},
{
id: 'delete',
placement: 'more',
actions: [
{
id: 'delete',
label: 'Delete',
run(_cx) {},
},
],
},
],
} as const satisfies ToolbarModuleConfig;
19 changes: 14 additions & 5 deletions blocksuite/affine/block-bookmark/src/bookmark-spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { ToolbarModuleExtension } from '@blocksuite/affine-shared/services';
import {
BlockFlavourIdentifier,
BlockViewExtension,
CommandExtension,
FlavourExtension,
} from '@blocksuite/block-std';
import type { ExtensionType } from '@blocksuite/store';
import { literal } from 'lit/static-html.js';

import { BookmarkBlockAdapterExtensions } from './adapters/extension.js';
import { BookmarkBlockService } from './bookmark-service.js';
import { commands } from './commands/index.js';
import { BookmarkBlockAdapterExtensions } from './adapters/extension';
import { BookmarkBlockService } from './bookmark-service';
import { commands } from './commands/index';
import { builtinToolbarConfig } from './configs/toolbar';

const Flavour = 'affine:bookmark';

export const BookmarkBlockSpec: ExtensionType[] = [
FlavourExtension('affine:bookmark'),
FlavourExtension(Flavour),
BookmarkBlockService,
CommandExtension(commands),
BlockViewExtension('affine:bookmark', model => {
BlockViewExtension(Flavour, model => {
return model.parent?.flavour === 'affine:surface'
? literal`affine-edgeless-bookmark`
: literal`affine-bookmark`;
}),
BookmarkBlockAdapterExtensions,
ToolbarModuleExtension({
id: BlockFlavourIdentifier(Flavour),
config: builtinToolbarConfig,
}),
].flat();
76 changes: 76 additions & 0 deletions blocksuite/affine/block-bookmark/src/configs/toolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type {
ToolbarActionGroup,
ToolbarModuleConfig,
} from '@blocksuite/affine-shared/services';

export const builtinToolbarConfig = {
actions: [
{
id: 'conversions',
actions: [
{
id: 'inline-view',
label: 'Inline view',
run(_cx) {},
},
{
id: 'card-view',
label: 'Card view',
run(_cx) {},
},
],
content(_cx) {
this.actions;
return null;
},
} satisfies ToolbarActionGroup,
{
id: 'style',
tooltip: 'Card style',
run(_cx) {},
},
{
id: 'caption',
tooltip: 'Caption',
run(_cx) {},
},
{
id: 'clipboard',
placement: 'more',
actions: [
{
id: 'copy',
label: 'Copy',
run(_cx) {},
},
{
id: 'duplicate',
label: 'Duplicate',
run(_cx) {},
},
],
},
{
id: 'refresh',
placement: 'more',
actions: [
{
id: 'reload',
label: 'Reload',
run(_cx) {},
},
],
},
{
id: 'delete',
placement: 'more',
actions: [
{
id: 'delete',
label: 'Delete',
run(_cx) {},
},
],
},
],
} as const satisfies ToolbarModuleConfig;
Loading

0 comments on commit 3558eb3

Please sign in to comment.