diff --git a/wax-prosemirror-components/src/components/Button.js b/wax-prosemirror-components/src/components/Button.js index ad3c1ec9a820d2ba1ee9a3060767ae10b2200092..e0520eddca2692c09197a44c3ff6f03a1c9d7311 100644 --- a/wax-prosemirror-components/src/components/Button.js +++ b/wax-prosemirror-components/src/components/Button.js @@ -1,6 +1,7 @@ -import React from "react"; +import React, { useContext } from "react"; import styled from "styled-components"; import { ButtonStyles } from "wax-prosemirror-themes"; +import { WaxContext } from "wax-prosemirror-core/src/ioc-react"; const ButtonStyled = styled.button` ${ButtonStyles}; @@ -16,6 +17,11 @@ const ButtonStyled = styled.button` `; const Button = ({ view = {}, item }) => { + if (item.onlyOnMain) { + const { view: { main } } = useContext(WaxContext); + view = main; + } + return ( <ButtonStyled type="button" diff --git a/wax-prosemirror-components/src/components/link/LinkComponent.js b/wax-prosemirror-components/src/components/link/LinkComponent.js index 20ee3b09dd300807726c63dc9d43c1829c18110c..2d2e91357bc2f1464ac938b6e2e67d2a1d57f2d2 100644 --- a/wax-prosemirror-components/src/components/link/LinkComponent.js +++ b/wax-prosemirror-components/src/components/link/LinkComponent.js @@ -21,8 +21,8 @@ const Button = styled.button` const LinkComponent = ({ mark, setPosition, position }) => { const href = mark ? mark.attrs.href : null, linkMark = mark ? mark : null, - { view: { main } } = useContext(WaxContext), - { state, dispatch } = main, + { view: { main }, activeView } = useContext(WaxContext), + { state, dispatch } = activeView, ref = useRef(null), linkInput = useRef(null), [addButtonText, setButtonText] = useState("Create"), @@ -46,12 +46,12 @@ const LinkComponent = ({ mark, setPosition, position }) => { .removeMark(mark.from, mark.to, state.schema.marks.link) .addMark(mark.from, mark.to, state.schema.marks.link.create({ href })) ); - main.focus(); + activeView.focus(); }; const removeLink = () => { dispatch(state.tr.removeMark(mark.from, mark.to, state.schema.marks.link)); - main.focus(); + activeView.focus(); }; const handleKeyDown = event => { diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 12bdaccab8bc6c176c51a42829118ee3211b2f69..42abd65fdb3999de4bdb00477abaac0da8006113 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -39,7 +39,11 @@ export default props => { } } ); - context.updateView({ main: view }); + context.updateView({ + main: view, + activeViewId: "main", + activeView: view + }); if (debug) applyDevTools(view); if (autoFocus) view.focus(); }, []); @@ -55,7 +59,7 @@ export default props => { context.updateView({ main: view, - activeViewId: context.activeViewId, + activeViewId: "main", activeView: view }); diff --git a/wax-prosemirror-services/src/BaseService/RedoService/Redo.js b/wax-prosemirror-services/src/BaseService/RedoService/Redo.js index bc9ddc249c9c31184d3b2b97f56dfd70ef2d9053..f01a0aa71d69d3490e7e5a0c80ab390c904bccaf 100644 --- a/wax-prosemirror-services/src/BaseService/RedoService/Redo.js +++ b/wax-prosemirror-services/src/BaseService/RedoService/Redo.js @@ -7,6 +7,7 @@ import { icons } from "wax-prosemirror-components"; export default class Redo extends Tools { title = "Redo last undone change"; content = icons.redo; + onlyOnMain = true; get run() { return redo; diff --git a/wax-prosemirror-services/src/BaseService/UndoService/Undo.js b/wax-prosemirror-services/src/BaseService/UndoService/Undo.js index 27027af0f0a729af09457f8c6a1c5141d58526d5..2d234e1d840dd1c48db434cdb8322694b20366e8 100644 --- a/wax-prosemirror-services/src/BaseService/UndoService/Undo.js +++ b/wax-prosemirror-services/src/BaseService/UndoService/Undo.js @@ -7,6 +7,7 @@ import { icons } from "wax-prosemirror-components"; export default class Undo extends Tools { title = "Undo last change"; content = icons.undo; + onlyOnMain = true; get run() { return undo; diff --git a/wax-prosemirror-services/src/MenuService/Menu.js b/wax-prosemirror-services/src/MenuService/Menu.js index f08b30ea9e19f5d8ae355fd8b33a1238afad6678..3641e149322f24063ea862b852e11cab06a1c086 100644 --- a/wax-prosemirror-services/src/MenuService/Menu.js +++ b/wax-prosemirror-services/src/MenuService/Menu.js @@ -27,11 +27,9 @@ export default class Menu { render() { return () => { - const { - view: { main } - } = useContext(WaxContext); + const { view: { main }, activeView } = useContext(WaxContext); const Bar = useMemo(() => ( - <MenuWrapper items={this.toolGroups} view={main || {}} /> + <MenuWrapper items={this.toolGroups} view={activeView || {}} /> )); return <>{Bar}</>; }; diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index 54885fd028f798a3475b0f06ee5f6a9492625d12..9d2f4a0108f6f89eee1bc6254cf8d8e78d3b0ee4 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -59,6 +59,11 @@ export default ({ node, view }) => { }, handleDOMEvents: { mousedown: () => { + context.updateActiveView({ + activeView: context.view[noteId], + activeViewId: noteId + }); + // Kludge to prevent issues due to the fact that the whole // footnote is node-selected (and thus DOM-selected) when // the parent editor is focused. diff --git a/wax-prosemirror-services/src/NoteService/Note.js b/wax-prosemirror-services/src/NoteService/Note.js index 3d948d20f3f36eb2c41c653b212bbf300402f640..44743d9429f2dd6b4c5418901b56aa8268e35c1d 100644 --- a/wax-prosemirror-services/src/NoteService/Note.js +++ b/wax-prosemirror-services/src/NoteService/Note.js @@ -26,5 +26,9 @@ export default class Note extends Tools { }; } - get enable() {} + get enable() { + return state => { + // TODO disable on notes editor + }; + } } diff --git a/wax-prosemirror-services/src/lib/Tools.js b/wax-prosemirror-services/src/lib/Tools.js index a81c082477af0cd2a7e7008b9d0e1618d1993510..d203e25720def225c877048c18f6f285553268b4 100644 --- a/wax-prosemirror-services/src/lib/Tools.js +++ b/wax-prosemirror-services/src/lib/Tools.js @@ -10,6 +10,7 @@ export default class Tools { content = "content"; _isDisplayed = true; hideOnToolbar = false; + onlyOnMain = false; config = {}; pmplugins = {}; @@ -41,7 +42,8 @@ export default class Tools { active: this.active, run: this.run, enable: this.enable, - select: this.select + select: this.select, + onlyOnMain: this.onlyOnMain }; }