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

set transaction

parent 6183a36b
No related branches found
No related tags found
1 merge request!396add inputs
......@@ -144,8 +144,9 @@ const ContainerEditor = ({ node, view, getPos }) => {
for (let j = 0; j < steps.length; j++)
outerTr.step(steps[j].map(offsetMap));
}
if (outerTr.docChanged)
if (outerTr.docChanged && !tr.getMeta('reject')) {
view.dispatch(outerTr.setMeta('outsideView', questionId));
}
}
};
......
......@@ -11,7 +11,7 @@ import { DocumentHelpers } from 'wax-prosemirror-utilities';
import { v4 as uuidv4 } from 'uuid';
import styled from 'styled-components';
import { Icon } from 'wax-prosemirror-components';
import { NodeSelection } from 'prosemirror-state';
const TriangleTop = styled.div`
width: 0;
height: 0;
......@@ -90,6 +90,8 @@ const IconRemove = styled(Icon)`
width: 10px;
`;
let PreviousNode = '';
export default ({ setPosition, position }) => {
const context = useContext(WaxContext);
const {
......@@ -103,9 +105,8 @@ export default ({ setPosition, position }) => {
return editable;
});
const currentOptions = activeView.state.selection.node
? activeView.state.selection.node.attrs.options
: [];
const currentNode = position.node;
const currentOptions = currentNode.node.attrs.options;
const readOnly = !isEditable;
......@@ -126,17 +127,16 @@ export default ({ setPosition, position }) => {
useEffect(() => {
if (addOptionRef.current) addOptionRef.current.focus();
const allNodes = getNodes(main);
if (!activeView.state.selection.node) return;
allNodes.forEach(singleNode => {
if (
singleNode.node.attrs.id === activeView.state.selection.node.attrs.id
) {
activeView.state.selection.node.attrs.options = options;
}
const { tr } = activeView.state;
tr.setNodeMarkup(position.from, undefined, {
...currentNode.node.attrs,
options,
});
}, [options]);
const resolvedPos = tr.doc.resolve(position.from);
tr.setSelection(new NodeSelection(resolvedPos));
activeView.dispatch(tr.setMeta('reject', true));
}, [position.from]);
const updateOptionText = () => {
setOptionText(addOptionRef.current.value);
......@@ -152,19 +152,13 @@ export default ({ setPosition, position }) => {
if (addOptionRef.current.value.trim() === '') return;
const obj = { label: addOptionRef.current.value, value: uuidv4() };
setOptions(prevOptions => [...prevOptions, obj]);
setOptionText(' ');
setTimeout(() => {
setOptionText('');
});
setOptionText('');
addOptionRef.current.focus();
};
const removeOption = id => {
setOptions(options.filter(option => option.value !== id));
setOptionText(' ');
setTimeout(() => {
setOptionText('');
});
setOptionText('');
};
return (
......@@ -204,14 +198,3 @@ export default ({ setPosition, position }) => {
</>
);
};
const getNodes = view => {
const allNodes = DocumentHelpers.findInlineNodes(view.state.doc);
const multipleDropDownNodes = [];
allNodes.forEach(node => {
if (node.node.type.name === 'multiple_drop_down_option') {
multipleDropDownNodes.push(node);
}
});
return multipleDropDownNodes;
};
......@@ -68,6 +68,7 @@ export default options => {
top,
from,
to,
node,
};
};
......
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