Rebuilding code block menus (#5569)
This commit is contained in:
@@ -2,9 +2,10 @@ import { PluginSimple } from "markdown-it";
|
||||
import { InputRule } from "prosemirror-inputrules";
|
||||
import { NodeType, MarkType, Schema } from "prosemirror-model";
|
||||
import { Command, Plugin } from "prosemirror-state";
|
||||
import { Primitive } from "utility-types";
|
||||
import { Editor } from "../../../app/editor";
|
||||
|
||||
export type CommandFactory = (attrs?: Record<string, any>) => Command;
|
||||
export type CommandFactory = (attrs?: Record<string, Primitive>) => Command;
|
||||
|
||||
export default class Extension {
|
||||
options: any;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { keymap } from "prosemirror-keymap";
|
||||
import { MarkdownParser } from "prosemirror-markdown";
|
||||
import { Schema } from "prosemirror-model";
|
||||
import { EditorView } from "prosemirror-view";
|
||||
import { Primitive } from "utility-types";
|
||||
import { Editor } from "~/editor";
|
||||
import Mark from "../marks/Mark";
|
||||
import Node from "../nodes/Node";
|
||||
@@ -203,7 +204,7 @@ export default class ExtensionManager {
|
||||
|
||||
const apply = (
|
||||
callback: CommandFactory,
|
||||
attrs: Record<string, any>
|
||||
attrs: Record<string, Primitive>
|
||||
) => {
|
||||
if (!view.editable && !extension.allowInReadOnly) {
|
||||
return false;
|
||||
@@ -214,10 +215,10 @@ export default class ExtensionManager {
|
||||
|
||||
const handle = (_name: string, _value: CommandFactory) => {
|
||||
if (Array.isArray(_value)) {
|
||||
commands[_name] = (attrs: Record<string, any>) =>
|
||||
commands[_name] = (attrs: Record<string, Primitive>) =>
|
||||
_value.forEach((callback) => apply(callback, attrs));
|
||||
} else if (typeof _value === "function") {
|
||||
commands[_name] = (attrs: Record<string, any>) =>
|
||||
commands[_name] = (attrs: Record<string, Primitive>) =>
|
||||
apply(_value, attrs);
|
||||
}
|
||||
};
|
||||
|
||||
5
shared/editor/lib/isCode.ts
Normal file
5
shared/editor/lib/isCode.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Node } from "prosemirror-model";
|
||||
|
||||
export function isCode(node: Node) {
|
||||
return node.type.name === "code_block" || node.type.name === "code_fence";
|
||||
}
|
||||
Reference in New Issue
Block a user