Rebuilding code block menus (#5569)
This commit is contained in:
@@ -4,21 +4,13 @@ import { wrappingInputRule } from "prosemirror-inputrules";
|
||||
import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model";
|
||||
import * as React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Primitive } from "utility-types";
|
||||
import toggleWrap from "../commands/toggleWrap";
|
||||
import { MarkdownSerializerState } from "../lib/markdown/serializer";
|
||||
import noticesRule from "../rules/notices";
|
||||
import Node from "./Node";
|
||||
|
||||
export default class Notice extends Node {
|
||||
get styleOptions() {
|
||||
return Object.entries({
|
||||
info: this.options.dictionary.info,
|
||||
warning: this.options.dictionary.warning,
|
||||
success: this.options.dictionary.success,
|
||||
tip: this.options.dictionary.tip,
|
||||
});
|
||||
}
|
||||
|
||||
get name() {
|
||||
return "container_notice";
|
||||
}
|
||||
@@ -90,23 +82,8 @@ export default class Notice extends Node {
|
||||
},
|
||||
],
|
||||
toDOM: (node) => {
|
||||
let icon, actions;
|
||||
let icon;
|
||||
if (typeof document !== "undefined") {
|
||||
const select = document.createElement("select");
|
||||
select.addEventListener("change", this.handleStyleChange);
|
||||
|
||||
this.styleOptions.forEach(([key, label]) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = key;
|
||||
option.innerText = label;
|
||||
option.selected = node.attrs.style === key;
|
||||
select.appendChild(option);
|
||||
});
|
||||
|
||||
actions = document.createElement("div");
|
||||
actions.className = "notice-actions";
|
||||
actions.appendChild(select);
|
||||
|
||||
let component;
|
||||
|
||||
if (node.attrs.style === "tip") {
|
||||
@@ -128,7 +105,6 @@ export default class Notice extends Node {
|
||||
"div",
|
||||
{ class: `notice-block ${node.attrs.style}` },
|
||||
...(icon ? [icon] : []),
|
||||
["div", { contentEditable: "false" }, ...(actions ? [actions] : [])],
|
||||
["div", { class: "content" }, 0],
|
||||
];
|
||||
},
|
||||
@@ -136,7 +112,7 @@ export default class Notice extends Node {
|
||||
}
|
||||
|
||||
commands({ type }: { type: NodeType }) {
|
||||
return (attrs: Record<string, any>) => toggleWrap(type, attrs);
|
||||
return (attrs: Record<string, Primitive>) => toggleWrap(type, attrs);
|
||||
}
|
||||
|
||||
handleStyleChange = (event: InputEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user