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

fix updating context

parent ed33ea95
No related branches found
No related tags found
No related merge requests found
Pipeline #61478 passed with stages
in 2 minutes and 11 seconds
...@@ -56,13 +56,14 @@ const Wax = forwardRef((props, innerViewRef) => { ...@@ -56,13 +56,14 @@ const Wax = forwardRef((props, innerViewRef) => {
const [application, setApplication] = useState(); const [application, setApplication] = useState();
const [WaxLayout, setWaxLayout] = useState(null); const [WaxLayout, setWaxLayout] = useState(null);
const configHash = createConfigWithHash(config); const configHash = createConfigWithHash(config);
console.log(configHash);
useEffect(() => { useEffect(() => {
const newApplication = createApplication(props); const newApplication = createApplication(props);
setApplication(newApplication); setApplication(newApplication);
const Layout = newApplication.container.get('Layout'); const Layout = newApplication.container.get('Layout');
if (layout) Layout.setLayout(layout); if (layout) Layout.setLayout(layout);
setWaxLayout(Layout.layoutComponent); setWaxLayout(Layout.layoutComponent);
setTimeout(() => {}, 100);
}, [configHash]); }, [configHash]);
const finalOnChange = content => { const finalOnChange = content => {
...@@ -78,6 +79,7 @@ const Wax = forwardRef((props, innerViewRef) => { ...@@ -78,6 +79,7 @@ const Wax = forwardRef((props, innerViewRef) => {
autoFocus={autoFocus} autoFocus={autoFocus}
browserSpellCheck={browserSpellCheck} browserSpellCheck={browserSpellCheck}
className={className} className={className}
configHash={configHash}
customValues={customValues} customValues={customValues}
fileUpload={fileUpload} fileUpload={fileUpload}
innerViewRef={innerViewRef} innerViewRef={innerViewRef}
......
...@@ -9,6 +9,7 @@ import helpers from './helpers/helpers'; ...@@ -9,6 +9,7 @@ import helpers from './helpers/helpers';
import './styles/styles.css'; import './styles/styles.css';
let previousDoc; let previousDoc;
let currentCofingHash;
const useWaxView = props => { const useWaxView = props => {
const { const {
...@@ -18,6 +19,7 @@ const useWaxView = props => { ...@@ -18,6 +19,7 @@ const useWaxView = props => {
autoFocus, autoFocus,
user, user,
innerViewRef, innerViewRef,
configHash,
targetFormat, targetFormat,
serializer, serializer,
scrollMargin, scrollMargin,
...@@ -58,17 +60,6 @@ const useWaxView = props => { ...@@ -58,17 +60,6 @@ const useWaxView = props => {
attributes: { attributes: {
spellcheck: browserSpellCheck ? 'true' : 'false', spellcheck: browserSpellCheck ? 'true' : 'false',
}, },
handleDOMEvents: {
focus() {
// return udpateEditorContext(view);
},
mousedown: () => {
return udpateEditorContext(view);
},
},
handleKeyDown: () => {
return udpateEditorContext(view);
},
}); });
setWaxView(view); setWaxView(view);
...@@ -90,17 +81,6 @@ const useWaxView = props => { ...@@ -90,17 +81,6 @@ const useWaxView = props => {
return () => (view = null); return () => (view = null);
}, []); }, []);
const udpateEditorContext = editorView => {
setTimeout(() => {
context.updateView(
{
main: editorView,
},
'main',
);
}, 50);
};
useImperativeHandle(innerViewRef, () => ({ useImperativeHandle(innerViewRef, () => ({
getContent() { getContent() {
return helpers.getDocContent(schema, serializer, targetFormat, context); return helpers.getDocContent(schema, serializer, targetFormat, context);
...@@ -108,24 +88,36 @@ const useWaxView = props => { ...@@ -108,24 +88,36 @@ const useWaxView = props => {
})); }));
const dispatchTransaction = transaction => { const dispatchTransaction = transaction => {
const { TrackChange } = props; if (currentCofingHash === configHash) {
const tr = const { TrackChange } = props;
TrackChange && TrackChange.enabled const tr =
? trackedTransaction(transaction, view.state, user, context) TrackChange && TrackChange.enabled
: transaction; ? trackedTransaction(transaction, view.state, user, context)
: transaction;
if (!view) return; if (!view) return;
previousDoc = view.state.doc; previousDoc = view.state.doc;
const state = view.state.apply(tr); const state = view.state.apply(tr);
view.updateState(state); view.updateState(state);
context.setTransaction(transaction); context.setTransaction(transaction);
const docContent = context.updateView(
targetFormat === 'JSON' ? state.doc.toJSON() : state.doc.content; {
if (!previousDoc.eq(view.state.doc) || tr.getMeta('forceUpdate')) main: view,
onChange(docContent); },
'main',
);
const docContent =
targetFormat === 'JSON' ? state.doc.toJSON() : state.doc.content;
if (!previousDoc.eq(view.state.doc) || tr.getMeta('forceUpdate'))
onChange(docContent);
}
setTimeout(() => {
currentCofingHash = configHash;
}, 100);
}; };
return WaxView; return WaxView;
......
...@@ -15,7 +15,6 @@ const FullScreenButton = ({ view = {}, item }) => { ...@@ -15,7 +15,6 @@ const FullScreenButton = ({ view = {}, item }) => {
const { state } = view; const { state } = view;
const handleMouseDown = e => { const handleMouseDown = e => {
context.updateView({}, 'main');
e.preventDefault(); e.preventDefault();
Object.assign(options, { fullScreen: !options.fullScreen }); Object.assign(options, { fullScreen: !options.fullScreen });
activeView.dispatch( activeView.dispatch(
......
...@@ -140,7 +140,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => { ...@@ -140,7 +140,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => {
const onKeyDown = (e, index) => { const onKeyDown = (e, index) => {
e.preventDefault(); e.preventDefault();
updateWaxView();
// arrow down // arrow down
if (e.keyCode === 40) { if (e.keyCode === 40) {
if (index === itemRefs.current.length - 1) { if (index === itemRefs.current.length - 1) {
...@@ -192,7 +191,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => { ...@@ -192,7 +191,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => {
}; };
const onChange = option => { const onChange = option => {
updateWaxView();
context.setOption({ [node.attrs.id]: { numericalAnswer: option.value } }); context.setOption({ [node.attrs.id]: { numericalAnswer: option.value } });
setLabel(option.label); setLabel(option.label);
openCloseMenu(); openCloseMenu();
...@@ -200,15 +198,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => { ...@@ -200,15 +198,6 @@ const NumericalAnswerDropDownCompontent = ({ node }) => {
activeView.focus(); activeView.focus();
}; };
const updateWaxView = () => {
context.updateView(
{
main: context.pmViews.main,
},
'main',
);
};
const NumericalAnswerDropDown = useMemo( const NumericalAnswerDropDown = useMemo(
() => ( () => (
<Wrapper disabled={isDisabled} ref={wrapperRef}> <Wrapper disabled={isDisabled} ref={wrapperRef}>
......
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