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
!374
Add feedback
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add feedback
add-feedback
into
master
Overview
0
Commits
22
Pipelines
0
Changes
28
Merged
Christos
requested to merge
add-feedback
into
master
3 years ago
Overview
0
Commits
22
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Compare
version 6
version 16
2315dced
3 years ago
version 15
c87abd11
3 years ago
version 14
fc85b069
3 years ago
version 13
84074a53
3 years ago
version 12
d473f8cb
3 years ago
version 11
1a725964
3 years ago
version 10
2557a378
3 years ago
version 9
ffa8f032
3 years ago
version 8
dbd8892d
3 years ago
version 7
5291b064
3 years ago
version 6
450e11cf
3 years ago
version 5
1aaf93c3
3 years ago
version 4
83d54d06
3 years ago
version 3
bd3a06d1
3 years ago
version 2
04165dd4
3 years ago
version 1
04dd6b55
3 years ago
master (base)
and
version 7
latest version
44da4478
22 commits,
3 years ago
version 16
2315dced
21 commits,
3 years ago
version 15
c87abd11
19 commits,
3 years ago
version 14
fc85b069
18 commits,
3 years ago
version 13
84074a53
17 commits,
3 years ago
version 12
d473f8cb
16 commits,
3 years ago
version 11
1a725964
15 commits,
3 years ago
version 10
2557a378
14 commits,
3 years ago
version 9
ffa8f032
13 commits,
3 years ago
version 8
dbd8892d
12 commits,
3 years ago
version 7
5291b064
11 commits,
3 years ago
version 6
450e11cf
10 commits,
3 years ago
version 5
1aaf93c3
9 commits,
3 years ago
version 4
83d54d06
7 commits,
3 years ago
version 3
bd3a06d1
6 commits,
3 years ago
version 2
04165dd4
5 commits,
3 years ago
version 1
04dd6b55
4 commits,
3 years ago
Show latest version
4 files
+
156
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
wax-prosemirror-services/src/FillTheGapQuestionService/components/ContainerEditor.js
0 → 100644
+
152
−
0
Options
/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/prop-types */
import
React
,
{
useContext
,
useRef
,
useEffect
}
from
'
react
'
;
import
styled
from
'
styled-components
'
;
import
{
EditorView
}
from
'
prosemirror-view
'
;
import
{
EditorState
,
TextSelection
}
from
'
prosemirror-state
'
;
import
{
StepMap
}
from
'
prosemirror-transform
'
;
import
{
keymap
}
from
'
prosemirror-keymap
'
;
import
{
baseKeymap
}
from
'
prosemirror-commands
'
;
import
{
undo
,
redo
}
from
'
prosemirror-history
'
;
import
{
WaxContext
}
from
'
wax-prosemirror-core
'
;
const
EditorWrapper
=
styled
.
span
`
> .ProseMirror {
// background: #a6a6a6 !important;
// border: 1px solid #a6a6a6;
// border-radius: 4px;
// box-shadow: none;
// color: #fff !important;
// display: inline;
// min-width: 50px;
// padding: 0px 2px 0px 2px !important;
// white-space: break-spaces;
// width: auto;
// word-wrap: break-word;
&:focus {
outline: none;
}
p.empty-node:first-child::before {
content: attr(data-content);
}
.empty-node::before {
color: rgb(170, 170, 170);
float: left;
font-style: italic;
height: 0px;
pointer-events: none;
}
}
`
;
const
EditorComponent
=
({
node
,
view
,
getPos
})
=>
{
const
editorRef
=
useRef
();
const
context
=
useContext
(
WaxContext
);
let
gapContainerView
;
const
questionId
=
node
.
attrs
.
id
;
const
isEditable
=
context
.
view
.
main
.
props
.
editable
(
editable
=>
{
return
editable
;
});
let
finalPlugins
=
[];
const
createKeyBindings
=
()
=>
{
const
keys
=
getKeys
();
Object
.
keys
(
baseKeymap
).
forEach
(
key
=>
{
keys
[
key
]
=
baseKeymap
[
key
];
});
return
keys
;
};
const
getKeys
=
()
=>
{
return
{
'
Mod-z
'
:
()
=>
undo
(
view
.
state
,
view
.
dispatch
),
'
Mod-y
'
:
()
=>
redo
(
view
.
state
,
view
.
dispatch
),
};
};
const
plugins
=
[
keymap
(
createKeyBindings
()),
...
context
.
app
.
getPlugins
()];
finalPlugins
=
finalPlugins
.
concat
([...
plugins
]);
const
{
activeViewId
}
=
context
;
useEffect
(()
=>
{
gapContainerView
=
new
EditorView
(
{
mount
:
editorRef
.
current
,
},
{
editable
:
()
=>
isEditable
,
state
:
EditorState
.
create
({
doc
:
node
,
plugins
:
finalPlugins
,
}),
// This is the magic part
dispatchTransaction
,
disallowedTools
:
[
'
Images
'
,
'
Lists
'
,
'
lift
'
,
'
Tables
'
,
'
FillTheGap
'
],
handleDOMEvents
:
{
mousedown
:
()
=>
{
context
.
view
[
activeViewId
].
dispatch
(
context
.
view
[
activeViewId
].
state
.
tr
.
setSelection
(
TextSelection
.
between
(
context
.
view
[
activeViewId
].
state
.
selection
.
$anchor
,
context
.
view
[
activeViewId
].
state
.
selection
.
$head
,
),
),
);
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
(
gapContainerView
.
hasFocus
())
gapContainerView
.
focus
();
},
},
attributes
:
{
spellcheck
:
'
false
'
,
},
},
);
// Set Each note into Wax's Context
context
.
updateView
(
{
[
questionId
]:
gapContainerView
,
},
questionId
,
);
gapContainerView
.
focus
();
},
[]);
const
dispatchTransaction
=
tr
=>
{
const
{
state
,
transactions
}
=
gapContainerView
.
state
.
applyTransaction
(
tr
);
gapContainerView
.
updateState
(
state
);
context
.
updateView
({},
questionId
);
if
(
!
tr
.
getMeta
(
'
fromOutside
'
))
{
const
outerTr
=
view
.
state
.
tr
;
const
offsetMap
=
StepMap
.
offset
(
getPos
()
+
1
);
for
(
let
i
=
0
;
i
<
transactions
.
length
;
i
++
)
{
const
{
steps
}
=
transactions
[
i
];
for
(
let
j
=
0
;
j
<
steps
.
length
;
j
++
)
outerTr
.
step
(
steps
[
j
].
map
(
offsetMap
));
}
if
(
outerTr
.
docChanged
)
view
.
dispatch
(
outerTr
.
setMeta
(
'
outsideView
'
,
questionId
));
}
};
return
(
<
EditorWrapper
>
<
div
ref
=
{
editorRef
}
/
>
<
/EditorWrapper
>
);
};
export
default
EditorComponent
;