Skip to content
Snippets Groups Projects

Pm node views portals

Merged Christos requested to merge pm-node-views-portals into master
3 files
+ 25
6
Compare changes
  • Side-by-side
  • Inline
Files
3
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useContext, useRef, useState, useEffect } from 'react';
import styled from 'styled-components';
import { EditorView } from 'prosemirror-view';
import { EditorState, TextSelection } from 'prosemirror-state';
import { EditorState } from 'prosemirror-state';
import { StepMap } from 'prosemirror-transform';
import { keymap } from 'prosemirror-keymap';
import { baseKeymap } from 'prosemirror-commands';
import { undo, redo } from 'prosemirror-history';
import { WaxContext } from 'wax-prosemirror-core';
import styled from 'styled-components';
const QuestionWrapper = styled.div`
border: 1px solid black;
display: flex;
@@ -46,6 +48,7 @@ export default ({ node, view, getPos }) => {
{
state: EditorState.create({
doc: node,
plugins: [keymap(createKeyBindings()), ...context.app.getPlugins()],
}),
// This is the magic part
dispatchTransaction,
@@ -100,6 +103,21 @@ export default ({ node, view, getPos }) => {
// view.dispatch(view.state.tr);
};
const createKeyBindings = () => {
const keys = getKeys();
Object.keys(baseKeymap).forEach(key => {
keys[key] = baseKeymap[key];
});
return keys;
};
const getKeys = () => {
return {
'Mod-z': () => undo(view.state, view.dispatch),
'Mod-y': () => redo(view.state, view.dispatch),
};
};
return (
<QuestionWrapper>
<Question>