1 import DialogBox from "./DialogBox";
2 import DialogForm from "./DialogForm";
3 import DialogTextArea from "./DialogTextArea";
5 import {MenuItem} from "./menu";
6 import {icons} from "./icons";
7 import {htmlToDoc, stateToHtml} from "../util";
10 * @param {(function(FormData))} submitter
11 * @param {Function} closer
14 function getLinkDialog(submitter, closer) {
15 return new DialogBox([
30 label: 'View/Edit HTML Source',
36 * @param {FormData} formData
37 * @param {PmEditorState} state
38 * @param {PmDispatchFunction} dispatch
41 function replaceEditorHtml(formData, state, dispatch) {
42 const html = formData.get('source');
47 const newDoc = htmlToDoc(html);
48 tr.replaceWith(0, state.doc.content.size, newDoc.content);
57 * @param {PmEditorState} state
58 * @param {PmDispatchFunction} dispatch
59 * @param {PmView} view
62 function onPress(state, dispatch, view, e) {
63 const dialog = getLinkDialog((data) => {
64 replaceEditorHtml(data, state, dispatch);
70 const {dom, update} = dialog.render(view);
72 document.body.appendChild(dom);
78 function htmlSourceButtonItem() {
80 title: "View HTML Source",
82 enable: state => true,
83 icon: icons.source_code,
87 export default htmlSourceButtonItem;