Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Merge requests
!348
Multiple single
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Multiple single
multiple-single
into
master
Overview
0
Commits
32
Pipelines
0
Changes
48
Merged
Christos
requested to merge
multiple-single
into
master
3 years ago
Overview
0
Commits
32
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
version 17
version 21
81150edd
3 years ago
version 20
40cd8ccb
3 years ago
version 19
a20748f6
3 years ago
version 18
42f4030c
3 years ago
version 17
1fd76927
3 years ago
version 16
95d8042f
3 years ago
version 15
ae8d8572
3 years ago
version 14
a23c2d55
3 years ago
version 13
ca3cc28a
3 years ago
version 12
1e8127d2
3 years ago
version 11
4a76c6a5
3 years ago
version 10
f7a3b5e3
3 years ago
version 9
bebec1ef
3 years ago
version 8
6c4231f8
3 years ago
version 7
c3a5da2d
3 years ago
version 6
98768714
3 years ago
version 5
0cff119e
3 years ago
version 4
fba70579
3 years ago
version 3
bdccaabf
3 years ago
version 2
2036fb52
3 years ago
version 1
091758ba
3 years ago
master (base)
and
version 18
latest version
acf344ae
32 commits,
3 years ago
version 21
81150edd
31 commits,
3 years ago
version 20
40cd8ccb
30 commits,
3 years ago
version 19
a20748f6
29 commits,
3 years ago
version 18
42f4030c
27 commits,
3 years ago
version 17
1fd76927
26 commits,
3 years ago
version 16
95d8042f
24 commits,
3 years ago
version 15
ae8d8572
23 commits,
3 years ago
version 14
a23c2d55
21 commits,
3 years ago
version 13
ca3cc28a
20 commits,
3 years ago
version 12
1e8127d2
19 commits,
3 years ago
version 11
4a76c6a5
17 commits,
3 years ago
version 10
f7a3b5e3
15 commits,
3 years ago
version 9
bebec1ef
14 commits,
3 years ago
version 8
6c4231f8
11 commits,
3 years ago
version 7
c3a5da2d
10 commits,
3 years ago
version 6
98768714
9 commits,
3 years ago
version 5
0cff119e
8 commits,
3 years ago
version 4
fba70579
7 commits,
3 years ago
version 3
bdccaabf
6 commits,
3 years ago
version 2
2036fb52
5 commits,
3 years ago
version 1
091758ba
4 commits,
3 years ago
Show latest version
1 file
+
51
−
20
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
wax-prosemirror-services/src/MultipleChoiceQuestionService/MultipleChoiceSingleCorrectQuestionService/components/SwitchComponent.js
+
51
−
20
Options
@@ -5,6 +5,7 @@ import { WaxContext } from 'wax-prosemirror-core';
import
{
DocumentHelpers
}
from
'
wax-prosemirror-utilities
'
;
import
styled
from
'
styled-components
'
;
import
Switch
from
'
../../components/Switch
'
;
import
{
NodeSelection
}
from
'
prosemirror-state
'
;
const
StyledSwitch
=
styled
(
Switch
)
`
display: flex;
@@ -33,30 +34,48 @@ const CustomSwitch = ({ node, getPos }) => {
const
handleChange
=
()
=>
{
setChecked
(
!
checked
);
const
{
tr
}
=
main
.
state
;
main
.
dispatch
(
main
.
state
.
tr
.
setSelection
(
NodeSelection
.
create
(
main
.
state
.
doc
,
getPos
()),
),
);
const
parentContainer
=
findParentOfType
(
main
.
state
,
main
.
state
.
config
.
schema
.
nodes
.
multiple_choice_single_correct_container
,
);
let
parentPosition
=
0
;
main
.
state
.
doc
.
descendants
((
parentNode
,
parentPos
)
=>
{
if
(
parentNode
.
type
.
name
===
'
multiple_choice_single_correct_container
'
)
{
parentNode
.
descendants
((
element
,
position
)
=>
{
if
(
element
.
type
.
name
===
'
multiple_choice_single_correct
'
&&
element
.
attrs
.
id
===
node
.
attrs
.
id
)
{
tr
.
setNodeMarkup
(
getPos
(),
undefined
,
{
...
element
.
attrs
,
correct
:
!
checked
,
});
}
else
if
(
element
.
type
.
name
===
'
multiple_choice_single_correct
'
&&
element
.
attrs
.
correct
)
{
tr
.
setNodeMarkup
(
parentPos
+
position
+
1
,
undefined
,
{
...
element
.
attrs
,
correct
:
false
,
});
}
if
(
parentNode
.
type
.
name
===
'
multiple_choice_single_correct_container
'
&&
parentNode
.
attrs
.
id
===
parentContainer
.
attrs
.
id
)
{
parentPosition
=
parentPos
;
}
});
const
{
tr
}
=
main
.
state
;
parentContainer
.
descendants
((
element
,
position
)
=>
{
if
(
element
.
type
.
name
===
'
multiple_choice_single_correct
'
&&
element
.
attrs
.
id
===
node
.
attrs
.
id
)
{
tr
.
setNodeMarkup
(
getPos
(),
undefined
,
{
...
element
.
attrs
,
correct
:
!
checked
,
});
}
else
if
(
element
.
type
.
name
===
'
multiple_choice_single_correct
'
&&
element
.
attrs
.
correct
)
{
tr
.
setNodeMarkup
(
parentPosition
+
position
+
1
,
undefined
,
{
...
element
.
attrs
,
correct
:
false
,
});
}
});
main
.
dispatch
(
tr
);
};
@@ -84,3 +103,15 @@ const getNodes = view => {
};
export
default
CustomSwitch
;
const
findParentOfType
=
(
state
,
nodeType
)
=>
{
let
nodeFound
=
''
;
const
predicate
=
node
=>
node
.
type
===
nodeType
;
for
(
let
i
=
state
.
selection
.
$from
.
depth
;
i
>
0
;
i
-=
1
)
{
const
node
=
state
.
selection
.
$from
.
node
(
i
);
if
(
predicate
(
node
))
{
nodeFound
=
node
;
}
}
return
nodeFound
;
};