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
!289
Pm node views portals
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Pm node views portals
pm-node-views-portals
into
master
Overview
0
Commits
55
Pipelines
0
Changes
78
Merged
Christos
requested to merge
pm-node-views-portals
into
master
3 years ago
Overview
0
Commits
55
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
5a3087f5
Prev
Next
Show latest version
2 files
+
64
−
52
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
5a3087f5
sync history inside nodeView
· 5a3087f5
chris
authored
3 years ago
editors/demo/src/HHMI/MultipleChoiceQuestionService/components/TestComponent.js
+
61
−
1
Options
/* eslint-disable react-hooks/exhaustive-deps */
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
useContext
,
useRef
,
useState
,
useEffect
}
from
'
react
'
;
import
{
EditorView
}
from
'
prosemirror-view
'
;
import
{
EditorState
,
TextSelection
}
from
'
prosemirror-state
'
;
import
{
StepMap
}
from
'
prosemirror-transform
'
;
import
{
WaxContext
}
from
'
wax-prosemirror-core
'
;
import
styled
from
'
styled-components
'
;
export
default
({
node
,
view
,
getPos
})
=>
{
const
[
showExplanation
,
setShowExplanation
]
=
useState
(
false
);
const
context
=
useContext
(
WaxContext
);
const
editorRef
=
useRef
();
let
questionView
;
const
questionId
=
node
.
attrs
.
id
;
useEffect
(()
=>
{
questionView
=
new
EditorView
(
{
mount
:
editorRef
.
current
},
{
state
:
EditorState
.
create
({
doc
:
node
,
}),
// This is the magic part
dispatchTransaction
,
handleDOMEvents
:
{
mousedown
:
()
=>
{
context
.
updateView
({},
questionId
);
// Kludge to prevent issues due to the fact that the whole
// footnote is node-selected (and thus DOM-selected) when
// the parent editor is focused.
if
(
questionView
.
hasFocus
())
questionView
.
focus
();
},
},
attributes
:
{
spellcheck
:
'
false
'
,
},
},
);
//Set Each note into Wax's Context
context
.
updateView
(
{
[
questionId
]:
questionView
,
},
questionId
,
);
},
[]);
const
dispatchTransaction
=
tr
=>
{
let
{
state
,
transactions
}
=
questionView
.
state
.
applyTransaction
(
tr
);
questionView
.
updateState
(
state
);
context
.
updateView
({},
questionId
);
if
(
!
tr
.
getMeta
(
'
fromOutside
'
))
{
let
outerTr
=
view
.
state
.
tr
,
offsetMap
=
StepMap
.
offset
(
getPos
()
+
1
);
for
(
let
i
=
0
;
i
<
transactions
.
length
;
i
++
)
{
let
steps
=
transactions
[
i
].
steps
;
for
(
let
j
=
0
;
j
<
steps
.
length
;
j
++
)
outerTr
.
step
(
steps
[
j
].
map
(
offsetMap
));
}
if
(
outerTr
.
docChanged
)
view
.
dispatch
(
outerTr
);
}
};
const
clickMe
=
()
=>
{
setShowExplanation
(
true
);
@@ -13,6 +72,7 @@ export default ({ node, view, getPos }) => {
return
(
<>
<
div
ref
=
{
editorRef
}
/
>
<
button
onClick
=
{
clickMe
}
>
Show
Explanation
<
/button
>
{
showExplanation
&&
(
<
input
type
=
"
text
"
placeholder
=
"
type your explanation
"
><
/input
>