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

new plugin

parent 0ce105e8
No related branches found
No related tags found
1 merge request!458Hhmi accessibility
...@@ -12,6 +12,7 @@ import { keymap } from 'prosemirror-keymap'; ...@@ -12,6 +12,7 @@ import { keymap } from 'prosemirror-keymap';
import { baseKeymap, chainCommands } from 'prosemirror-commands'; import { baseKeymap, chainCommands } from 'prosemirror-commands';
import { undo, redo } from 'prosemirror-history'; import { undo, redo } from 'prosemirror-history';
import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core'; import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core';
import FakeCursorPlugin from '../plugins/FakeCursorPlugin';
const EditorWrapper = styled.div` const EditorWrapper = styled.div`
position: relative; position: relative;
...@@ -53,7 +54,7 @@ const ContainerEditor = ({ node, view, getPos }) => { ...@@ -53,7 +54,7 @@ const ContainerEditor = ({ node, view, getPos }) => {
return editable; return editable;
}); });
let finalPlugins = []; let finalPlugins = [FakeCursorPlugin()];
const createKeyBindings = () => { const createKeyBindings = () => {
const keys = getKeys(); const keys = getKeys();
......
/* eslint-disable */
import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import { Commands } from 'wax-prosemirror-core';
const fakeCursorPluginMultiple = new PluginKey('fakeCursorPluginMultiple');
export default props => {
return new Plugin({
key: fakeCursorPluginMultiple,
state: {
init: (_, state) => {},
apply(tr, prev, _, newState) {
let createDecoration;
if (
newState.selection.from === newState.selection.to &&
Commands.isInTable(newState)
) {
const widget = document.createElement('fakecursor');
createDecoration = DecorationSet.create(newState.doc, [
Decoration.widget(newState.selection.from, widget, {
key: 'fakecursor',
}),
]);
}
return {
createDecoration,
};
},
},
props: {
decorations: state => {
const fakeCursorPluginMultipleState =
state && fakeCursorPluginMultiple.getState(state);
if (fakeCursorPluginMultipleState)
return fakeCursorPluginMultipleState.createDecoration;
},
handleDOMEvents: {
focus: (view, event) => {
event.preventDefault();
const fakeCursor = document.getElementsByTagName('fakecursor');
if (fakeCursor && fakeCursor[0]) {
for (let i = 0; i < fakeCursor.length; i++) {
fakeCursor[i].style.visibility = 'hidden';
}
}
},
blur: (view, event) => {
event.preventDefault();
if (view && event.relatedTarget === null) {
view.focus();
} else {
const fakeCursor = document.getElementsByTagName('fakecursor');
if (fakeCursor && fakeCursor[0]) {
for (let i = 0; i < fakeCursor.length; i++) {
fakeCursor[i].style.visibility = 'visible';
}
}
}
},
},
},
});
};
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