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

execute command

parent ad13f700
No related branches found
No related tags found
1 merge request!458Hhmi accessibility
...@@ -258,6 +258,7 @@ const isParentOfType = (state, nodeType) => { ...@@ -258,6 +258,7 @@ const isParentOfType = (state, nodeType) => {
const predicate = node => node.type === nodeType; const predicate = node => node.type === nodeType;
for (let i = state.selection.$from.depth; i > 0; i -= 1) { for (let i = state.selection.$from.depth; i > 0; i -= 1) {
const node = state.selection.$from.node(i); const node = state.selection.$from.node(i);
console.log(node);
if (predicate(node)) { if (predicate(node)) {
status = true; status = true;
} }
......
...@@ -54,6 +54,10 @@ class MatchingQuestion extends Tools { ...@@ -54,6 +54,10 @@ class MatchingQuestion extends Tools {
Commands.isParentOfType( Commands.isParentOfType(
state, state,
state.config.schema.nodes.matching_container, state.config.schema.nodes.matching_container,
) ||
Commands.isParentOfType(
state,
state.config.schema.nodes.matching_option,
) )
) { ) {
return true; return true;
......
...@@ -125,9 +125,7 @@ const EditorComponent = ({ node, view, getPos }) => { ...@@ -125,9 +125,7 @@ const EditorComponent = ({ node, view, getPos }) => {
.setSelection( .setSelection(
new TextSelection( new TextSelection(
main.state.tr.doc.resolve( main.state.tr.doc.resolve(
getPos() + getPos() + context.pmViews[questionId].state.selection.to,
2 +
context.pmViews[questionId].state.selection.to,
), ),
), ),
), ),
......
...@@ -28,6 +28,10 @@ class MultipleChoiceSingleCorrectQuestion extends Tools { ...@@ -28,6 +28,10 @@ class MultipleChoiceSingleCorrectQuestion extends Tools {
get active() { get active() {
return state => { return state => {
if ( if (
Commands.isParentOfType(
state,
state.config.schema.nodes.multiple_choice_single_correct_container,
) ||
Commands.isParentOfType( Commands.isParentOfType(
state, state,
state.config.schema.nodes.multiple_choice_single_correct, state.config.schema.nodes.multiple_choice_single_correct,
......
...@@ -32,7 +32,7 @@ class CreateDropDown extends Tools { ...@@ -32,7 +32,7 @@ class CreateDropDown extends Tools {
select = (state, activeViewId, activeView) => { select = (state, activeViewId, activeView) => {
if ( if (
activeView.props.type && activeView.props.type &&
activeView.props.type === 'MultipleDropDownContaier' activeView.props.type === 'MultipleDropDownContainer'
) )
return true; return true;
......
...@@ -120,7 +120,7 @@ const ContainerEditor = ({ node, view, getPos }) => { ...@@ -120,7 +120,7 @@ const ContainerEditor = ({ node, view, getPos }) => {
}), }),
dispatchTransaction, dispatchTransaction,
disallowedTools: ['Images', 'FillTheGap', 'MultipleChoice'], disallowedTools: ['Images', 'FillTheGap', 'MultipleChoice'],
type: 'MultipleDropDownContaier', type: 'MultipleDropDownContainer',
handleDOMEvents: { handleDOMEvents: {
mousedown: () => { mousedown: () => {
main.dispatch( main.dispatch(
......
...@@ -123,7 +123,7 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -123,7 +123,7 @@ const DropDownComponent = ({ view, tools }) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
useOnClickOutside(wrapperRef, () => setIsOpen(false)); useOnClickOutside(wrapperRef, () => setIsOpen(false));
const [label, setLabel] = useState(null); const [label, setLabel] = useState('Question Type');
const isEditable = main.props.editable(editable => { const isEditable = main.props.editable(editable => {
return editable; return editable;
}); });
...@@ -132,9 +132,8 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -132,9 +132,8 @@ const DropDownComponent = ({ view, tools }) => {
setLabel('Question Type'); setLabel('Question Type');
dropDownOptions.forEach(option => { dropDownOptions.forEach(option => {
if (option.item.active(main.state)) { if (option.item.active(main.state)) {
setTimeout(() => { setLabel(option.label);
setLabel(option.label); setTimeout(() => {});
});
} }
}); });
}, [activeViewId]); }, [activeViewId]);
...@@ -186,6 +185,11 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -186,6 +185,11 @@ const DropDownComponent = ({ view, tools }) => {
} }
}; };
const onChange = option => {
tools[option.value].run(main, context);
openCloseMenu();
};
const MultipleDropDown = useMemo( const MultipleDropDown = useMemo(
() => ( () => (
<Wrapper disabled={isDisabled} ref={wrapperRef}> <Wrapper disabled={isDisabled} ref={wrapperRef}>
...@@ -202,7 +206,7 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -202,7 +206,7 @@ const DropDownComponent = ({ view, tools }) => {
tabIndex="0" tabIndex="0"
type="button" type="button"
> >
<span>Question type</span> <StyledIcon name="expand" /> <span>{label}</span> <StyledIcon name="expand" />
</DropDownButton> </DropDownButton>
<DropDownMenu isOpen={isOpen} role="menu"> <DropDownMenu isOpen={isOpen} role="menu">
{dropDownOptions.map((option, index) => { {dropDownOptions.map((option, index) => {
...@@ -210,9 +214,7 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -210,9 +214,7 @@ const DropDownComponent = ({ view, tools }) => {
return ( return (
<span <span
key={option.value} key={option.value}
onClick={() => { onClick={() => onChange(option)}
openCloseMenu();
}}
onKeyDown={e => onKeyDown(e, index)} onKeyDown={e => onKeyDown(e, index)}
ref={itemRefs.current[index]} ref={itemRefs.current[index]}
role="menuitem" role="menuitem"
...@@ -225,7 +227,7 @@ const DropDownComponent = ({ view, tools }) => { ...@@ -225,7 +227,7 @@ const DropDownComponent = ({ view, tools }) => {
</DropDownMenu> </DropDownMenu>
</Wrapper> </Wrapper>
), ),
[isDisabled, isOpen], [isDisabled, isOpen, label],
); );
return MultipleDropDown; return MultipleDropDown;
......
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