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

create option editor

parent a7072549
No related branches found
No related tags found
1 merge request!396add inputs
...@@ -70,7 +70,7 @@ const Editors = () => { ...@@ -70,7 +70,7 @@ const Editors = () => {
case 'ncbi': case 'ncbi':
return <NCBI />; return <NCBI />;
default: default:
return <Editoria />; return <HHMI />;
} }
}; };
......
...@@ -31,7 +31,7 @@ const EditorWrapper = styled.div` ...@@ -31,7 +31,7 @@ const EditorWrapper = styled.div`
} }
`; `;
const EditorComponent = ({ node, view, getPos }) => { const ContainerEditor = ({ node, view, getPos }) => {
const editorRef = useRef(); const editorRef = useRef();
const context = useContext(WaxContext); const context = useContext(WaxContext);
...@@ -148,4 +148,4 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -148,4 +148,4 @@ const EditorComponent = ({ node, view, getPos }) => {
); );
}; };
export default EditorComponent; export default ContainerEditor;
import { injectable } from 'inversify'; import { injectable } from 'inversify';
import { wrapIn } from 'prosemirror-commands'; import { wrapIn } from 'prosemirror-commands';
import { Fragment } from 'prosemirror-model';
import { findWrapping } from 'prosemirror-transform';
import { TextSelection } from 'prosemirror-state';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import Tools from '../lib/Tools'; import Tools from '../lib/Tools';
...@@ -11,9 +14,33 @@ class MatchingQuestion extends Tools { ...@@ -11,9 +14,33 @@ class MatchingQuestion extends Tools {
get run() { get run() {
return (state, dispatch) => { return (state, dispatch) => {
wrapIn(state.config.schema.nodes.matching_container, { /* Create Wrapping */
id: uuidv4(), const { $from, $to } = state.selection;
})(state, dispatch); const range = $from.blockRange($to);
const { tr } = state;
const wrapping =
range &&
findWrapping(range, state.config.schema.nodes.matching_container, {
id: uuidv4(),
});
if (!wrapping) return false;
tr.wrap(range, wrapping);
const map = tr.mapping.maps[0];
let newPos = 0;
map.forEach((_from, _to, _newFrom, newTo) => {
newPos = newTo;
});
tr.setSelection(TextSelection.create(tr.doc, range.$to.pos));
const option = state.config.schema.nodes.matching_option.create(
{ id: uuidv4() },
Fragment.empty,
);
tr.replaceSelectionWith(option);
dispatch(tr);
}; };
} }
......
...@@ -5,7 +5,7 @@ import matchingOptionNode from './schema/matchingOptionNode'; ...@@ -5,7 +5,7 @@ import matchingOptionNode from './schema/matchingOptionNode';
import MatchingContainerNodeView from './MatchingContainerNodeView'; import MatchingContainerNodeView from './MatchingContainerNodeView';
import MatchingOptionNodeView from './MatchingOptionNodeView'; import MatchingOptionNodeView from './MatchingOptionNodeView';
import MatchingContainerComponent from './components/MatchingContainerComponent'; import MatchingContainerComponent from './components/MatchingContainerComponent';
import MatchingOptionComponent from './MatchingOptionComponent'; import MatchingOptionComponent from './components/MatchingOptionComponent';
class MatchingService extends Service { class MatchingService extends Service {
name = 'MatchingService'; name = 'MatchingService';
......
...@@ -4,6 +4,7 @@ import { WaxContext } from 'wax-prosemirror-core'; ...@@ -4,6 +4,7 @@ import { WaxContext } from 'wax-prosemirror-core';
import { Icon } from 'wax-prosemirror-components'; import { Icon } from 'wax-prosemirror-components';
import styled from 'styled-components'; import styled from 'styled-components';
import FeedbackComponent from './FeedbackComponent'; import FeedbackComponent from './FeedbackComponent';
import ContainerEditor from './ContainerEditor';
const MatchingContainer = styled.div` const MatchingContainer = styled.div`
border: 3px solid #f5f5f7; border: 3px solid #f5f5f7;
...@@ -108,7 +109,7 @@ export default ({ node, view, getPos }) => { ...@@ -108,7 +109,7 @@ export default ({ node, view, getPos }) => {
<LeftArea> <LeftArea>
<InputsContainer> <InputsContainer>
<FirstOption> <FirstOption>
{Input()} <ContainerEditor getPos={getPos} node={node} view={view} />
{!readOnly && ( {!readOnly && (
<ActionButton <ActionButton
onClick={() => addOption(node.attrs.id)} onClick={() => addOption(node.attrs.id)}
......
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