feature: add a left menu option to add a below block (#232)

* feature: add a left menu to add a below block

* fix: 1.remove extra spaces
2.update hard code to predefined types
This commit is contained in:
Simon Li 2022-08-13 03:18:26 +08:00 committed by GitHub
parent 754b2581cd
commit 2560c7b074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,10 @@
import { useMemo } from 'react';
import { Virgo, PluginHooks } from '@toeverything/framework/virgo';
import { Cascader, CascaderItemProps } from '@toeverything/components/ui';
import { Protocol } from '@toeverything/datasource/db-service';
import { TurnIntoMenu } from './TurnIntoMenu';
import {
AddViewIcon,
DeleteCashBinIcon,
TurnIntoIcon,
UngroupIcon,
@ -45,6 +47,24 @@ export function LeftMenu(props: LeftMenuProps) {
),
icon: <TurnIntoIcon />,
},
{
title: 'Add A Below Block',
icon: <AddViewIcon />,
callback: async () => {
const block = await editor.getBlockById(blockId);
const belowType = [
Protocol.Block.Type.numbered,
Protocol.Block.Type.bullet,
Protocol.Block.Type.todo,
].some(type => type === block.type)
? block.type
: Protocol.Block.Type.text;
editor.commands.blockCommands.createNextBlock(
blockId,
belowType
);
},
},
{
title: 'Divide Here As A New Group',
icon: <UngroupIcon />,