Skip to content
Snippets Groups Projects
Commit be700e1e authored by chris's avatar chris
Browse files

disable if from eq to

parent 669373b3
No related branches found
No related tags found
1 merge request!143Track changes
import React, { useContext } from "react"; import React, { useContext } from 'react';
import styled from "styled-components"; import styled from 'styled-components';
import { ButtonStyles } from "wax-prosemirror-themes"; import { ButtonStyles } from 'wax-prosemirror-themes';
import { WaxContext } from "wax-prosemirror-core"; import { WaxContext } from 'wax-prosemirror-core';
const ButtonStyled = styled.button` const ButtonStyled = styled.button`
${ButtonStyles}; ${ButtonStyles};
opacity: ${props => (props.select ? 1 : 0.4)}; opacity: ${props => (props.select ? 1 : 0.4)};
pointer-events: ${props => (props.select ? "default" : "none")}; pointer-events: ${props => (props.select ? 'default' : 'none')};
color: ${props => (props.isActive ? "white" : props.theme.colorButton)}; color: ${props => (props.isActive ? 'white' : props.theme.colorButton)};
background-color: ${props => background-color: ${props =>
props.isActive ? props.theme.colorPrimary : "transparent"}; props.isActive ? props.theme.colorPrimary : 'transparent'};
&:hover { &:hover {
background-color: ${props => background-color: ${props =>
props.isActive ? props.theme.colorPrimary : "transparent"}; props.isActive ? props.theme.colorPrimary : 'transparent'};
} }
`; `;
const Button = ({ view = {}, item }) => { const Button = ({ view = {}, item }) => {
if (item.onlyOnMain) { if (item.onlyOnMain) {
const { view: { main } } = useContext(WaxContext); const {
view: { main },
} = useContext(WaxContext);
view = main; view = main;
} }
......
...@@ -15,8 +15,9 @@ export default ({ node, view }) => { ...@@ -15,8 +15,9 @@ export default ({ node, view }) => {
const editorRef = useRef(); const editorRef = useRef();
const context = useContext(WaxContext); const context = useContext(WaxContext);
const noteId = node.attrs.id; const noteId = node.attrs.id;
let noteView;
useEffect(() => { useEffect(() => {
const noteView = new EditorView( noteView = new EditorView(
{ mount: editorRef.current }, { mount: editorRef.current },
{ {
state: EditorState.create({ state: EditorState.create({
...@@ -24,38 +25,7 @@ export default ({ node, view }) => { ...@@ -24,38 +25,7 @@ export default ({ node, view }) => {
plugins: [keymap(createKeyBindings()), ...context.app.getPlugins()], plugins: [keymap(createKeyBindings()), ...context.app.getPlugins()],
}), }),
// This is the magic part // This is the magic part
dispatchTransaction: tr => { dispatchTransaction,
let { state, transactions } = noteView.state.applyTransaction(tr);
noteView.updateState(state);
const allNotes = DocumentHelpers.findChildrenByType(
view.state.doc,
view.state.schema.nodes.footnote,
true,
);
const noteFound = filter(allNotes, {
node: { attrs: { id: noteId } },
});
// TODO Remove timeout and use state to check if noteView has changed
setTimeout(() => {
context.updateView({}, noteId);
}, 20);
if (!tr.getMeta('fromOutside')) {
let outerTr = view.state.tr,
offsetMap = StepMap.offset(noteFound[0].pos + 1);
for (let i = 0; i < transactions.length; i++) {
let steps = transactions[i].steps;
for (let j = 0; j < steps.length; j++)
outerTr.step(steps[j].map(offsetMap));
}
if (outerTr.docChanged)
view.dispatch(outerTr.setMeta('outsideView', 'notes'));
}
},
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
context.updateView({}, noteId); context.updateView({}, noteId);
...@@ -84,6 +54,39 @@ export default ({ node, view }) => { ...@@ -84,6 +54,39 @@ export default ({ node, view }) => {
} }
}, []); }, []);
const dispatchTransaction = tr => {
const { state, transactions } = noteView.state.applyTransaction(tr);
noteView.updateState(state);
const allNotes = DocumentHelpers.findChildrenByType(
view.state.doc,
view.state.schema.nodes.footnote,
true,
);
const noteFound = filter(allNotes, {
node: { attrs: { id: noteId } },
});
// TODO Remove timeout and use state to check if noteView has changed
setTimeout(() => {
context.updateView({}, noteId);
}, 20);
if (!tr.getMeta('fromOutside')) {
let outerTr = view.state.tr,
offsetMap = StepMap.offset(noteFound[0].pos + 1);
for (let i = 0; i < transactions.length; i++) {
let steps = transactions[i].steps;
for (let j = 0; j < steps.length; j++)
outerTr.step(steps[j].map(offsetMap));
}
if (outerTr.docChanged)
view.dispatch(outerTr.setMeta('outsideView', 'notes'));
}
};
const createKeyBindings = () => { const createKeyBindings = () => {
const keys = getKeys(); const keys = getKeys();
Object.keys(baseKeymap).forEach(key => { Object.keys(baseKeymap).forEach(key => {
......
...@@ -67,6 +67,14 @@ class AcceptTrackChange extends Tools { ...@@ -67,6 +67,14 @@ class AcceptTrackChange extends Tools {
}; };
} }
select = state => {
const {
selection: { from, to },
} = state;
if (from === to) return false;
return true;
};
get active() { get active() {
return state => {}; return state => {};
} }
......
...@@ -88,6 +88,14 @@ class RejectTrackChange extends Tools { ...@@ -88,6 +88,14 @@ class RejectTrackChange extends Tools {
}; };
} }
select = state => {
const {
selection: { from, to },
} = state;
if (from === to) return false;
return true;
};
get active() { get active() {
return state => {}; return state => {};
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment