chore: Move editor into codebase (#2930)
This commit is contained in:
50
app/editor/components/BlockMenu.tsx
Normal file
50
app/editor/components/BlockMenu.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
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">>;
|
||||
|
||||
class BlockMenu extends React.Component<BlockMenuProps> {
|
||||
get items() {
|
||||
return getMenuItems(this.props.dictionary);
|
||||
}
|
||||
|
||||
clearSearch = () => {
|
||||
const { state, dispatch } = this.props.view;
|
||||
const parent = findParentNode((node) => !!node)(state.selection);
|
||||
|
||||
if (parent) {
|
||||
dispatch(state.tr.insertText("", parent.pos, state.selection.to));
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<CommandMenu
|
||||
{...this.props}
|
||||
filterable={true}
|
||||
onClearSearch={this.clearSearch}
|
||||
renderMenuItem={(item, _index, options) => {
|
||||
return (
|
||||
<BlockMenuItem
|
||||
onClick={options.onClick}
|
||||
selected={options.selected}
|
||||
icon={item.icon}
|
||||
title={item.title}
|
||||
shortcut={item.shortcut}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
items={this.items}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default BlockMenu;
|
||||
Reference in New Issue
Block a user