Rebuilding code block menus (#5569)

This commit is contained in:
Tom Moor
2023-07-17 21:25:22 -04:00
committed by GitHub
parent 60b456f35a
commit 2427f4747a
42 changed files with 474 additions and 469 deletions

37
app/editor/menus/code.tsx Normal file
View 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,
},
})),
},
];
}