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
Commits
ce6a09ab
Commit
ce6a09ab
authored
3 years ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
fix mount
parent
b1d0d0b6
No related branches found
No related tags found
1 merge request
!289
Pm node views portals
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
editors/demo/src/HHMI/MultipleChoiceQuestionService/components/TestComponent.js
+27
-35
27 additions, 35 deletions
...MultipleChoiceQuestionService/components/TestComponent.js
with
27 additions
and
35 deletions
editors/demo/src/HHMI/MultipleChoiceQuestionService/components/TestComponent.js
+
27
−
35
View file @
ce6a09ab
/* eslint-disable react-hooks/exhaustive-deps */
import
React
,
{
useEffect
,
useRef
,
useMemo
}
from
'
react
'
;
import
React
,
{
useEffect
,
useRef
,
useMemo
,
useCallback
}
from
'
react
'
;
import
{
EditorState
}
from
'
prosemirror-state
'
;
import
{
EditorView
}
from
'
prosemirror-view
'
;
import
{
StepMap
}
from
'
prosemirror-transform
'
;
...
...
@@ -16,42 +16,34 @@ const EditorWrapper = styled.div`
let
questionView
;
export
default
({
node
,
view
,
getPos
})
=>
{
console
.
log
(
node
);
const
editorRef
=
useRef
();
useEffect
(()
=>
{
questionView
=
new
EditorView
(
{
mount
:
editorRef
.
current
},
{
state
:
EditorState
.
create
({
doc
:
node
,
// plugins: [keymap(createKeyBindings()), ...app.getPlugins()],
}),
dispatchTransaction
,
handleDOMEvents
:
{
// blur: () => {
// view[noteId].dispatch(
// view[noteId].state.tr.setSelection(
// new TextSelection(view[noteId].state.tr.doc.resolve(0)),
// ),
// );
// },
mousedown
:
()
=>
{
// 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.
const
setEditorRef
=
useCallback
(
// eslint-disable-next-line consistent-return
editorNode
=>
{
if
(
editorRef
.
current
)
{
console
.
log
(
editorRef
);
}
if
(
editorNode
)
{
questionView
=
new
EditorView
(
{
mount
:
editorNode
},
{
state
:
EditorState
.
create
({
doc
:
node
,
}),
dispatchTransaction
,
scrollMargin
:
200
,
scrollThreshold
:
200
,
if
(
view
.
hasFocus
())
questionView
.
focus
();
attributes
:
{
spellcheck
:
'
false
'
,
},
},
},
attributes
:
{
spellcheck
:
'
false
'
,
},
},
);
},
[]);
);
}
editorRef
.
current
=
editorNode
;
},
[],
);
const
dispatchTransaction
=
tr
=>
{
console
.
log
(
'
dispatch
'
,
questionView
.
state
.
applyTransaction
(
tr
));
let
{
state
,
transactions
}
=
questionView
.
state
.
applyTransaction
(
tr
);
...
...
@@ -96,7 +88,7 @@ export default ({ node, view, getPos }) => {
const
MemorizedComponent
=
useMemo
(
()
=>
(
<>
<
EditorWrapper
ref
=
{
e
ditorRef
}
style
=
{
styles
}
/
>
<
EditorWrapper
ref
=
{
setE
ditorRef
}
style
=
{
styles
}
/
>
<
button
onClick
=
{
clickMe
}
>
Click
me
<
/button
>
<
/
>
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment