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
55
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
Viewing commit
a23c2d55
Prev
Next
Show latest version
1 file
+
51
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
a23c2d55
add new component
· a23c2d55
chris
authored
3 years ago
wax-prosemirror-components/src/components/UndoRedoButton.js
0 → 100644
+
51
−
0
Options
/* eslint react/prop-types: 0 */
import
React
,
{
useContext
,
useMemo
}
from
'
react
'
;
import
{
WaxContext
}
from
'
wax-prosemirror-core
'
;
import
MenuButton
from
'
../ui/buttons/MenuButton
'
;
const
UndoRedoButton
=
({
view
=
{},
item
})
=>
{
const
{
active
,
icon
,
label
,
run
,
select
,
title
}
=
item
;
const
{
view
:
{
main
},
activeViewId
,
activeView
,
}
=
useContext
(
WaxContext
);
const
isEditable
=
main
.
props
.
editable
(
editable
=>
{
return
editable
;
});
const
{
state
}
=
view
;
const
handleMouseDown
=
(
e
,
editorState
,
editorDispatch
)
=>
{
e
.
preventDefault
();
run
(
editorState
,
editorDispatch
);
};
const
isActive
=
!!
(
active
(
activeView
.
state
,
activeViewId
)
&&
select
(
state
,
activeViewId
,
activeView
)
);
let
isDisabled
=
!
select
(
state
,
activeViewId
,
activeView
);
if
(
!
isEditable
)
isDisabled
=
true
;
const
UndoRedoButtonComponent
=
useMemo
(
()
=>
(
<
MenuButton
active
=
{
isActive
||
false
}
disabled
=
{
isDisabled
}
iconName
=
{
icon
}
label
=
{
label
}
onMouseDown
=
{
e
=>
handleMouseDown
(
e
,
main
.
state
,
main
.
dispatch
)}
title
=
{
title
}
/
>
),
[
isActive
,
isDisabled
],
);
return
UndoRedoButtonComponent
;
};
export
default
UndoRedoButton
;