Files
outline/app/editor/components/BlockMenu.tsx
Tom Moor 6f2a4488e8 chore: Editor refactor (#3286)
* cleanup

* add context

* EventEmitter allows removal of toolbar props from extensions

* Move to 'packages' of extensions
Remove EmojiTrigger extension

* types

* iteration

* fix render flashing

* fix: Missing nodes in collection descriptions
2022-03-30 19:10:34 -07:00

43 lines
1.1 KiB
TypeScript

import { findParentNode } from "prosemirror-utils";
import React from "react";
import getMenuItems from "../menus/block";
import BlockMenuItem from "./BlockMenuItem";
import CommandMenu, { Props } from "./CommandMenu";
type BlockMenuProps = Omit<
Props,
"renderMenuItem" | "items" | "onClearSearch"
> &
Required<Pick<Props, "onLinkToolbarOpen" | "embeds">>;
function BlockMenu(props: BlockMenuProps) {
const clearSearch = () => {
const { state, dispatch } = props.view;
const parent = findParentNode((node) => !!node)(state.selection);
if (parent) {
dispatch(state.tr.insertText("", parent.pos, state.selection.to));
}
};
return (
<CommandMenu
{...props}
filterable={true}
onClearSearch={clearSearch}
renderMenuItem={(item, _index, options) => (
<BlockMenuItem
onClick={options.onClick}
selected={options.selected}
icon={item.icon}
title={item.title}
shortcut={item.shortcut}
/>
)}
items={getMenuItems(props.dictionary)}
/>
);
}
export default BlockMenu;