Rebuilding code block menus (#5569)
This commit is contained in:
37
app/editor/menus/code.tsx
Normal file
37
app/editor/menus/code.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { CopyIcon, ExpandedIcon } from "outline-icons";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
import * as React from "react";
|
||||
import { LANGUAGES } from "@shared/editor/extensions/Prism";
|
||||
import { MenuItem } from "@shared/editor/types";
|
||||
import { Dictionary } from "~/hooks/useDictionary";
|
||||
|
||||
export default function codeMenuItems(
|
||||
state: EditorState,
|
||||
dictionary: Dictionary
|
||||
): MenuItem[] {
|
||||
const node = state.selection.$from.node();
|
||||
|
||||
return [
|
||||
{
|
||||
name: "copyToClipboard",
|
||||
icon: <CopyIcon />,
|
||||
tooltip: dictionary.copy,
|
||||
},
|
||||
{
|
||||
name: "separator",
|
||||
},
|
||||
{
|
||||
name: "code_block",
|
||||
icon: <ExpandedIcon />,
|
||||
label: LANGUAGES[node.attrs.language ?? "none"],
|
||||
children: Object.entries(LANGUAGES).map(([value, label]) => ({
|
||||
name: "code_block",
|
||||
label,
|
||||
active: () => node.attrs.language === value,
|
||||
attrs: {
|
||||
language: value,
|
||||
},
|
||||
})),
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user