mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 15:26:59 +08:00
feat(editor): insert a blank frame slash menu action (#10899)
Close [BS-2517](https://linear.app/affine-design/issue/BS-2517/%E6%B7%BB%E5%8A%A0frame%E5%85%A5%E5%8F%A3) ### What changes: - add a insert blank frame action to slash menu - move `EdgelessFrameManager` and `FrameOverlay` extensions to `FrameBlockSpec` - make `FrameBlockSpec` as a part of `CommonBlockSpecs` such that we can use `EdgelessFrameManager` to create a frame more easily https://github.com/user-attachments/assets/ddff5866-8933-4ce5-aaf4-873661407ee4
This commit is contained in:
@@ -57,6 +57,7 @@ export const CommonBlockSpecs: ExtensionType[] = [
|
|||||||
DefaultOpenDocExtension,
|
DefaultOpenDocExtension,
|
||||||
FontLoaderService,
|
FontLoaderService,
|
||||||
CalloutBlockSpec,
|
CalloutBlockSpec,
|
||||||
|
FrameBlockSpec,
|
||||||
].flat();
|
].flat();
|
||||||
|
|
||||||
export const PageFirstPartyBlockSpecs: ExtensionType[] = [
|
export const PageFirstPartyBlockSpecs: ExtensionType[] = [
|
||||||
@@ -72,6 +73,5 @@ export const EdgelessFirstPartyBlockSpecs: ExtensionType[] = [
|
|||||||
EdgelessNoteBlockSpec,
|
EdgelessNoteBlockSpec,
|
||||||
EdgelessSurfaceBlockSpec,
|
EdgelessSurfaceBlockSpec,
|
||||||
EdgelessSurfaceRefBlockSpec,
|
EdgelessSurfaceRefBlockSpec,
|
||||||
FrameBlockSpec,
|
|
||||||
EdgelessTextBlockSpec,
|
EdgelessTextBlockSpec,
|
||||||
].flat();
|
].flat();
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ import { BlockViewExtension } from '@blocksuite/block-std';
|
|||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
|
import { EdgelessFrameManager, FrameOverlay } from './frame-manager';
|
||||||
|
|
||||||
export const FrameBlockSpec: ExtensionType[] = [
|
export const FrameBlockSpec: ExtensionType[] = [
|
||||||
BlockViewExtension('affine:frame', literal`affine-frame`),
|
BlockViewExtension('affine:frame', literal`affine-frame`),
|
||||||
|
FrameOverlay,
|
||||||
|
EdgelessFrameManager,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { PresentTool } from '@blocksuite/affine-block-frame';
|
||||||
EdgelessFrameManager,
|
|
||||||
FrameOverlay,
|
|
||||||
PresentTool,
|
|
||||||
} from '@blocksuite/affine-block-frame';
|
|
||||||
import { ConnectionOverlay } from '@blocksuite/affine-block-surface';
|
import { ConnectionOverlay } from '@blocksuite/affine-block-surface';
|
||||||
import { TextTool } from '@blocksuite/affine-gfx-text';
|
import { TextTool } from '@blocksuite/affine-gfx-text';
|
||||||
import type { ExtensionType } from '@blocksuite/store';
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
@@ -41,10 +37,8 @@ export const EdgelessToolExtension: ExtensionType[] = [
|
|||||||
|
|
||||||
export const EdgelessBuiltInManager: ExtensionType[] = [
|
export const EdgelessBuiltInManager: ExtensionType[] = [
|
||||||
ConnectionOverlay,
|
ConnectionOverlay,
|
||||||
FrameOverlay,
|
|
||||||
MindMapIndicatorOverlay,
|
MindMapIndicatorOverlay,
|
||||||
SnapManager,
|
SnapManager,
|
||||||
EdgelessFrameManager,
|
|
||||||
EditPropsMiddlewareBuilder,
|
EditPropsMiddlewareBuilder,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"author": "toeverything",
|
"author": "toeverything",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@blocksuite/affine-block-frame": "workspace:*",
|
||||||
"@blocksuite/affine-block-surface": "workspace:*",
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-model": "workspace:*",
|
"@blocksuite/affine-model": "workspace:*",
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
|
import { EdgelessFrameManagerIdentifier } from '@blocksuite/affine-block-frame';
|
||||||
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
|
||||||
import type { FrameBlockModel } from '@blocksuite/affine-model';
|
import { type FrameBlockModel, NoteBlockModel } from '@blocksuite/affine-model';
|
||||||
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
||||||
|
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||||
import {
|
import {
|
||||||
type SlashMenuActionItem,
|
type SlashMenuActionItem,
|
||||||
type SlashMenuConfig,
|
type SlashMenuConfig,
|
||||||
SlashMenuConfigExtension,
|
SlashMenuConfigExtension,
|
||||||
|
type SlashMenuItem,
|
||||||
} from '@blocksuite/affine-widget-slash-menu';
|
} from '@blocksuite/affine-widget-slash-menu';
|
||||||
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
|
import { Bound } from '@blocksuite/global/gfx';
|
||||||
import { FrameIcon, GroupingIcon } from '@blocksuite/icons/lit';
|
import { FrameIcon, GroupingIcon } from '@blocksuite/icons/lit';
|
||||||
|
|
||||||
import { insertSurfaceRefBlockCommand } from '../commands';
|
import { insertSurfaceRefBlockCommand } from '../commands';
|
||||||
@@ -15,6 +20,54 @@ const surfaceRefSlashMenuConfig: SlashMenuConfig = {
|
|||||||
items: ({ std }) => {
|
items: ({ std }) => {
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
|
const insertBlankFrameItem: SlashMenuItem = {
|
||||||
|
name: 'Frame',
|
||||||
|
description: 'Insert a blank frame',
|
||||||
|
icon: FrameIcon(),
|
||||||
|
tooltip: {
|
||||||
|
figure: EdgelessTooltip,
|
||||||
|
caption: 'Edgeless',
|
||||||
|
},
|
||||||
|
group: `5_Edgeless Element@${index++}`,
|
||||||
|
action: ({ std, model }) => {
|
||||||
|
const { root } = std.store;
|
||||||
|
if (!root) return;
|
||||||
|
|
||||||
|
const pageBlock = root.children.find(
|
||||||
|
(model): model is NoteBlockModel =>
|
||||||
|
matchModels(model, [NoteBlockModel]) && model.isPageBlock()
|
||||||
|
);
|
||||||
|
if (!pageBlock) return;
|
||||||
|
|
||||||
|
const top = pageBlock.x;
|
||||||
|
const right = pageBlock.x + pageBlock.w;
|
||||||
|
const padding = 20;
|
||||||
|
|
||||||
|
let frameBound = Bound.fromXYWH([right + padding, top, 1600, 900]);
|
||||||
|
const gfx = std.get(GfxControllerIdentifier);
|
||||||
|
|
||||||
|
// Find a space to insert the frame
|
||||||
|
let elementInFrameBound = gfx.grid.search(frameBound);
|
||||||
|
while (elementInFrameBound.length > 0) {
|
||||||
|
const rightElement = elementInFrameBound.reduce((a, b) => {
|
||||||
|
return a.x + a.w > b.x + b.w ? a : b;
|
||||||
|
});
|
||||||
|
frameBound.x = rightElement.x + rightElement.w + padding;
|
||||||
|
elementInFrameBound = gfx.grid.search(frameBound);
|
||||||
|
}
|
||||||
|
|
||||||
|
const frameMgr = std.get(EdgelessFrameManagerIdentifier);
|
||||||
|
const frame = frameMgr.createFrameOnBound(frameBound);
|
||||||
|
|
||||||
|
std.command.exec(insertSurfaceRefBlockCommand, {
|
||||||
|
reference: frame.id,
|
||||||
|
place: 'after',
|
||||||
|
removeEmptyLine: true,
|
||||||
|
selectedModels: [model],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const surfaceModel = getSurfaceBlock(std.store);
|
const surfaceModel = getSurfaceBlock(std.store);
|
||||||
if (!surfaceModel) return [];
|
if (!surfaceModel) return [];
|
||||||
|
|
||||||
@@ -25,7 +78,7 @@ const surfaceRefSlashMenuConfig: SlashMenuConfig = {
|
|||||||
const frameItems = frameModels.map<SlashMenuActionItem>(frameModel => ({
|
const frameItems = frameModels.map<SlashMenuActionItem>(frameModel => ({
|
||||||
name: 'Frame: ' + frameModel.props.title,
|
name: 'Frame: ' + frameModel.props.title,
|
||||||
icon: FrameIcon(),
|
icon: FrameIcon(),
|
||||||
group: `5_Document Group & Frame@${index++}`,
|
group: `5_Edgeless Element@${index++}`,
|
||||||
tooltip: {
|
tooltip: {
|
||||||
figure: EdgelessTooltip,
|
figure: EdgelessTooltip,
|
||||||
caption: 'Edgeless',
|
caption: 'Edgeless',
|
||||||
@@ -47,7 +100,7 @@ const surfaceRefSlashMenuConfig: SlashMenuConfig = {
|
|||||||
const groupItems = groupElements.map<SlashMenuActionItem>(group => ({
|
const groupItems = groupElements.map<SlashMenuActionItem>(group => ({
|
||||||
name: 'Group: ' + group.title.toString(),
|
name: 'Group: ' + group.title.toString(),
|
||||||
icon: GroupingIcon(),
|
icon: GroupingIcon(),
|
||||||
group: `5_Document Group & Frame@${index++}`,
|
group: `5_Edgeless Element@${index++}`,
|
||||||
tooltip: {
|
tooltip: {
|
||||||
figure: EdgelessTooltip,
|
figure: EdgelessTooltip,
|
||||||
caption: 'Edgeless',
|
caption: 'Edgeless',
|
||||||
@@ -65,7 +118,7 @@ const surfaceRefSlashMenuConfig: SlashMenuConfig = {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return [...frameItems, ...groupItems];
|
return [insertBlankFrameItem, ...frameItems, ...groupItems];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"include": ["./src"],
|
"include": ["./src"],
|
||||||
"references": [
|
"references": [
|
||||||
|
{ "path": "../block-frame" },
|
||||||
{ "path": "../block-surface" },
|
{ "path": "../block-surface" },
|
||||||
{ "path": "../../components" },
|
{ "path": "../../components" },
|
||||||
{ "path": "../../model" },
|
{ "path": "../../model" },
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ export const PackageList = [
|
|||||||
location: 'blocksuite/affine/blocks/block-surface-ref',
|
location: 'blocksuite/affine/blocks/block-surface-ref',
|
||||||
name: '@blocksuite/affine-block-surface-ref',
|
name: '@blocksuite/affine-block-surface-ref',
|
||||||
workspaceDependencies: [
|
workspaceDependencies: [
|
||||||
|
'blocksuite/affine/blocks/block-frame',
|
||||||
'blocksuite/affine/blocks/block-surface',
|
'blocksuite/affine/blocks/block-surface',
|
||||||
'blocksuite/affine/components',
|
'blocksuite/affine/components',
|
||||||
'blocksuite/affine/model',
|
'blocksuite/affine/model',
|
||||||
|
|||||||
@@ -2692,6 +2692,7 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@blocksuite/affine-block-surface-ref@workspace:blocksuite/affine/blocks/block-surface-ref"
|
resolution: "@blocksuite/affine-block-surface-ref@workspace:blocksuite/affine/blocks/block-surface-ref"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
"@blocksuite/affine-block-frame": "workspace:*"
|
||||||
"@blocksuite/affine-block-surface": "workspace:*"
|
"@blocksuite/affine-block-surface": "workspace:*"
|
||||||
"@blocksuite/affine-components": "workspace:*"
|
"@blocksuite/affine-components": "workspace:*"
|
||||||
"@blocksuite/affine-model": "workspace:*"
|
"@blocksuite/affine-model": "workspace:*"
|
||||||
|
|||||||
Reference in New Issue
Block a user