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

enable lists

parent 0e6594dc
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,15 @@ ...@@ -3,10 +3,15 @@
import React, { useContext, useRef, useEffect } from 'react'; import React, { useContext, useRef, useEffect } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { EditorView } from 'prosemirror-view'; import { EditorView } from 'prosemirror-view';
import { EditorState, TextSelection } from 'prosemirror-state'; import { EditorState, TextSelection, NodeSelection } from 'prosemirror-state';
import { StepMap } from 'prosemirror-transform'; import { StepMap } from 'prosemirror-transform';
import {
splitListItem,
liftListItem,
sinkListItem,
} from 'prosemirror-schema-list';
import { keymap } from 'prosemirror-keymap'; import { keymap } from 'prosemirror-keymap';
import { baseKeymap } 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';
...@@ -55,15 +60,46 @@ const ContainerEditor = ({ node, view, getPos }) => { ...@@ -55,15 +60,46 @@ const ContainerEditor = ({ node, view, getPos }) => {
const createKeyBindings = () => { const createKeyBindings = () => {
const keys = getKeys(); const keys = getKeys();
Object.keys(baseKeymap).forEach(key => { Object.keys(baseKeymap).forEach(key => {
keys[key] = baseKeymap[key]; if (keys[key]) {
keys[key] = chainCommands(keys[key], baseKeymap[key]);
} else {
keys[key] = baseKeymap[key];
}
}); });
return keys; return keys;
}; };
const pressEnter = (state, dispatch) => {
if (state.selection.node && state.selection.node.type.name === 'image') {
const { $from, to } = state.selection;
const same = $from.sharedDepth(to);
const pos = $from.before(same);
dispatch(state.tr.setSelection(NodeSelection.create(state.doc, pos)));
return true;
}
// LISTS
if (splitListItem(state.schema.nodes.list_item)(state)) {
splitListItem(state.schema.nodes.list_item)(state, dispatch);
return true;
}
return false;
};
const getKeys = () => { const getKeys = () => {
return { return {
'Mod-z': () => undo(view.state, view.dispatch), 'Mod-z': () => undo(view.state, view.dispatch),
'Mod-y': () => redo(view.state, view.dispatch), 'Mod-y': () => redo(view.state, view.dispatch),
'Mod-[': liftListItem(view.state.schema.nodes.list_item),
'Mod-]': sinkListItem(view.state.schema.nodes.list_item),
// Enter: () =>
// splitListItem(questionView.state.schema.nodes.list_item)(
// questionView.state,
// questionView.dispatch,
// ),
Enter: pressEnter,
}; };
}; };
......
...@@ -8,6 +8,7 @@ const multipleDropDownContainerNode = { ...@@ -8,6 +8,7 @@ const multipleDropDownContainerNode = {
atom: true, atom: true,
selectable: false, selectable: false,
draggable: false, draggable: false,
defining: true,
content: 'block*', content: 'block*',
parseDOM: [ parseDOM: [
{ {
......
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