|
@@ -3,33 +3,6 @@ import {Plugin} from "prosemirror-state"
|
|
|
import {toggleMark, setBlockType, wrapIn} from "prosemirror-commands"
|
|
|
import {schema} from "prosemirror-schema-basic"
|
|
|
|
|
|
-// 自定义 MenuBarView 类
|
|
|
-class MenuBarView {
|
|
|
- constructor(editorView, options) {
|
|
|
- this.editorView = editorView;
|
|
|
- this.options = options;
|
|
|
- this.menuItems = []; // 存储所有的 MenuView 实例
|
|
|
- }
|
|
|
-
|
|
|
- addMenuItem(menuItem) {
|
|
|
- this.menuItems.push(menuItem);
|
|
|
- }
|
|
|
-
|
|
|
- render() {
|
|
|
- const element = document.createElement('div');
|
|
|
- element.classList.add('menu-bar');
|
|
|
- for (const menuItem of this.menuItems) {
|
|
|
- const menuElement = menuItem.render();
|
|
|
- element.appendChild(menuElement);
|
|
|
- }
|
|
|
- return element;
|
|
|
- }
|
|
|
-
|
|
|
- mount() {
|
|
|
- const dom = this.render();
|
|
|
- this.editorView.dom.parentNode.insertBefore(dom, this.editorView.dom);
|
|
|
- }
|
|
|
-}
|
|
|
export class MenuView {
|
|
|
constructor(items, editorView) {
|
|
|
this.items = items
|
|
@@ -102,25 +75,11 @@ export function icon(text, name) {
|
|
|
|
|
|
}
|
|
|
export function addMenu(editorView){
|
|
|
- const menuBarView = new MenuBarView(editorView, { /* options */ });
|
|
|
- // const menuItem1 = new MenuView({ label: 'Item 1' });
|
|
|
- // const menuItem2 = new MenuView({ label: 'Item 2' });
|
|
|
- // menuBarView.addMenuItem(menuItem1);
|
|
|
- // menuBarView.addMenuItem(menuItem2);
|
|
|
- var menu = menuPlugin([
|
|
|
+ let menu = menuPlugin([
|
|
|
{command: toggleMark(schema.marks.strong), dom: icon("B", "strong")},
|
|
|
{command: toggleMark(schema.marks.em), dom: icon("i", "em")},
|
|
|
{command: setBlockType(schema.nodes.paragraph), dom: icon("p", "paragraph")},
|
|
|
heading(1), heading(2), heading(3),
|
|
|
{command: wrapIn(schema.nodes.blockquote), dom: icon(">", "blockquote")}
|
|
|
- ],editorView)
|
|
|
- console.log(menu)
|
|
|
- menuBarView.addMenuItem(menu);
|
|
|
- for(var i =0;i<menu.length;i++){
|
|
|
- console.log(1)
|
|
|
- menuBarView.addMenuItem(menu[i]);
|
|
|
- }
|
|
|
-
|
|
|
- // 将 MenuBarView 挂载到编辑器视图的上方
|
|
|
- menuBarView.mount();
|
|
|
+ ])
|
|
|
}
|