mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 04:36:13 +08:00
refactor(editor): bookmark slash menu config extension (#10675)
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-model": "workspace:*",
|
"@blocksuite/affine-model": "workspace:*",
|
||||||
"@blocksuite/affine-shared": "workspace:*",
|
"@blocksuite/affine-shared": "workspace:*",
|
||||||
|
"@blocksuite/affine-widget-slash-menu": "workspace:*",
|
||||||
"@blocksuite/block-std": "workspace:*",
|
"@blocksuite/block-std": "workspace:*",
|
||||||
"@blocksuite/global": "workspace:*",
|
"@blocksuite/global": "workspace:*",
|
||||||
"@blocksuite/icons": "^2.2.1",
|
"@blocksuite/icons": "^2.2.1",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { BookmarkBlockSchema } from '@blocksuite/affine-model';
|
import { BookmarkBlockSchema } from '@blocksuite/affine-model';
|
||||||
import { ToolbarModuleExtension } from '@blocksuite/affine-shared/services';
|
import { ToolbarModuleExtension } from '@blocksuite/affine-shared/services';
|
||||||
|
import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
||||||
import {
|
import {
|
||||||
BlockFlavourIdentifier,
|
BlockFlavourIdentifier,
|
||||||
BlockViewExtension,
|
BlockViewExtension,
|
||||||
@@ -9,6 +10,7 @@ import type { ExtensionType } from '@blocksuite/store';
|
|||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { BookmarkBlockAdapterExtensions } from './adapters/extension';
|
import { BookmarkBlockAdapterExtensions } from './adapters/extension';
|
||||||
|
import { bookmarkSlashMenuConfig } from './configs/slash-menu';
|
||||||
import { builtinToolbarConfig } from './configs/toolbar';
|
import { builtinToolbarConfig } from './configs/toolbar';
|
||||||
|
|
||||||
const flavour = BookmarkBlockSchema.model.flavour;
|
const flavour = BookmarkBlockSchema.model.flavour;
|
||||||
@@ -25,4 +27,5 @@ export const BookmarkBlockSpec: ExtensionType[] = [
|
|||||||
id: BlockFlavourIdentifier(flavour),
|
id: BlockFlavourIdentifier(flavour),
|
||||||
config: builtinToolbarConfig,
|
config: builtinToolbarConfig,
|
||||||
}),
|
}),
|
||||||
|
SlashMenuConfigExtension(flavour, bookmarkSlashMenuConfig),
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { toggleEmbedCardCreateModal } from '@blocksuite/affine-components/embed-card-modal';
|
||||||
|
import { type SlashMenuConfig } from '@blocksuite/affine-widget-slash-menu';
|
||||||
|
import { LinkIcon } from '@blocksuite/icons/lit';
|
||||||
|
|
||||||
|
import { LinkTooltip } from './tooltips';
|
||||||
|
|
||||||
|
export const bookmarkSlashMenuConfig: SlashMenuConfig = {
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
name: 'Link',
|
||||||
|
description: 'Add a bookmark for reference.',
|
||||||
|
icon: LinkIcon(),
|
||||||
|
tooltip: {
|
||||||
|
figure: LinkTooltip,
|
||||||
|
caption: 'Link',
|
||||||
|
},
|
||||||
|
group: '4_Content & Media@2',
|
||||||
|
when: ({ model }) =>
|
||||||
|
model.doc.schema.flavourSchemaMap.has('affine:bookmark'),
|
||||||
|
action: ({ std, model }) => {
|
||||||
|
const { host } = std;
|
||||||
|
const parentModel = host.doc.getParent(model);
|
||||||
|
if (!parentModel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const index = parentModel.children.indexOf(model) + 1;
|
||||||
|
toggleEmbedCardCreateModal(
|
||||||
|
host,
|
||||||
|
'Links',
|
||||||
|
'The added link will be displayed as a card view.',
|
||||||
|
{ mode: 'page', parentModel, index }
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
if (model.text?.length === 0) {
|
||||||
|
model.doc.deleteBlock(model);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
{ "path": "../components" },
|
{ "path": "../components" },
|
||||||
{ "path": "../model" },
|
{ "path": "../model" },
|
||||||
{ "path": "../shared" },
|
{ "path": "../shared" },
|
||||||
|
{ "path": "../widget-slash-menu" },
|
||||||
{ "path": "../../framework/block-std" },
|
{ "path": "../../framework/block-std" },
|
||||||
{ "path": "../../framework/global" },
|
{ "path": "../../framework/global" },
|
||||||
{ "path": "../../framework/inline" },
|
{ "path": "../../framework/inline" },
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { Heading5Tooltip } from './heading-5';
|
|||||||
import { Heading6Tooltip } from './heading-6';
|
import { Heading6Tooltip } from './heading-6';
|
||||||
import { ItalicTooltip } from './italic';
|
import { ItalicTooltip } from './italic';
|
||||||
import { LinearTooltip } from './linear';
|
import { LinearTooltip } from './linear';
|
||||||
import { LinkTooltip } from './link';
|
|
||||||
import { LinkDocTooltip } from './link-doc';
|
import { LinkDocTooltip } from './link-doc';
|
||||||
import { MoveDownTooltip } from './move-down';
|
import { MoveDownTooltip } from './move-down';
|
||||||
import { MoveUpTooltip } from './move-up';
|
import { MoveUpTooltip } from './move-up';
|
||||||
@@ -126,11 +125,6 @@ export const slashMenuToolTips: Record<string, SlashMenuTooltip> = {
|
|||||||
caption: 'Link Doc',
|
caption: 'Link Doc',
|
||||||
},
|
},
|
||||||
|
|
||||||
Link: {
|
|
||||||
figure: LinkTooltip,
|
|
||||||
caption: 'Link',
|
|
||||||
},
|
|
||||||
|
|
||||||
Attachment: {
|
Attachment: {
|
||||||
figure: AttachmentTooltip,
|
figure: AttachmentTooltip,
|
||||||
caption: 'Attachment',
|
caption: 'Attachment',
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export const PackageList = [
|
|||||||
'blocksuite/affine/components',
|
'blocksuite/affine/components',
|
||||||
'blocksuite/affine/model',
|
'blocksuite/affine/model',
|
||||||
'blocksuite/affine/shared',
|
'blocksuite/affine/shared',
|
||||||
|
'blocksuite/affine/widget-slash-menu',
|
||||||
'blocksuite/framework/block-std',
|
'blocksuite/framework/block-std',
|
||||||
'blocksuite/framework/global',
|
'blocksuite/framework/global',
|
||||||
'blocksuite/framework/inline',
|
'blocksuite/framework/inline',
|
||||||
|
|||||||
@@ -2248,6 +2248,7 @@ __metadata:
|
|||||||
"@blocksuite/affine-components": "workspace:*"
|
"@blocksuite/affine-components": "workspace:*"
|
||||||
"@blocksuite/affine-model": "workspace:*"
|
"@blocksuite/affine-model": "workspace:*"
|
||||||
"@blocksuite/affine-shared": "workspace:*"
|
"@blocksuite/affine-shared": "workspace:*"
|
||||||
|
"@blocksuite/affine-widget-slash-menu": "workspace:*"
|
||||||
"@blocksuite/block-std": "workspace:*"
|
"@blocksuite/block-std": "workspace:*"
|
||||||
"@blocksuite/global": "workspace:*"
|
"@blocksuite/global": "workspace:*"
|
||||||
"@blocksuite/icons": "npm:^2.2.1"
|
"@blocksuite/icons": "npm:^2.2.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user