1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Started menu dialog support

This commit is contained in:
Dan Brown
2022-01-14 20:56:05 +00:00
parent c013d7e549
commit 7703face52
11 changed files with 328 additions and 25 deletions

View File

@ -4,10 +4,13 @@ import {
} from "./menu"
import {icons} from "./icons";
import ColorPickerGrid from "./ColorPickerGrid";
import DialogBox from "./DialogBox";
import {toggleMark} from "prosemirror-commands";
import {menuBar} from "./menubar"
import schema from "../schema";
import {removeMarks} from "../commands";
import DialogForm from "./DialogForm";
import DialogInput from "./DialogInput";
function cmdItem(cmd, options) {
@ -161,6 +164,37 @@ const utilities = [
}),
];
function getMarkAttribute(markType, attribute) {
return function(state) {
const marks = state.selection.$head.marks();
for (const mark of marks) {
if (mark.type === markType) {
return mark.attrs[attribute];
}
}
return null;
};
}
let box = new DialogBox([
new DialogForm([
new DialogInput({
label: 'URL',
id: 'url',
value: getMarkAttribute(schema.marks.link, 'href'),
}),
new DialogInput({
label: 'Title',
id: 'title',
value: getMarkAttribute(schema.marks.link, 'title'),
})
], {
canceler: () => box.close(),
action: (data) => console.log('submit', data),
}),
], {label: 'Insert Link', closer: () => {console.log('close')}});
const menu = menuBar({
floating: false,
content: [
@ -172,6 +206,7 @@ const menu = menuBar({
lists,
inserts,
utilities,
[box]
],
});