Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador annotations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador annotations
Commits
121d3d9e
Commit
121d3d9e
authored
Jan 18, 2023
by
Anthony
Browse files
Options
Downloads
Patches
Plain Diff
Add link button
parent
3808b772
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TextEditor.js
+7
-0
7 additions, 0 deletions
src/TextEditor.js
src/TextEditorLink.js
+65
-0
65 additions, 0 deletions
src/TextEditorLink.js
with
72 additions
and
0 deletions
src/TextEditor.js
+
7
−
0
View file @
121d3d9e
...
...
@@ -8,6 +8,7 @@ import ItalicIcon from '@material-ui/icons/FormatItalic';
import
{
withStyles
}
from
'
@material-ui/core/styles
'
;
import
{
stateToHTML
}
from
'
draft-js-export-html
'
;
import
{
stateFromHTML
}
from
'
draft-js-import-html
'
;
import
{
onAddLink
}
from
'
./TextEditorLink
'
;
/** */
class
TextEditor
extends
Component
{
...
...
@@ -67,6 +68,7 @@ class TextEditor extends Component {
render
()
{
const
{
classes
}
=
this
.
props
;
const
{
editorState
}
=
this
.
state
;
const
{
setEditorState
}
=
this
.
setState
;
const
currentStyle
=
editorState
.
getCurrentInlineStyle
();
return
(
...
...
@@ -88,6 +90,11 @@ class TextEditor extends Component {
<
ItalicIcon
/>
<
/ToggleButton
>
<
/ToggleButtonGroup
>
<
button
onClick
=
{()
=>
onAddLink
(
editorState
,
setEditorState
)}
>
link
<
/button
>
<
div
className
=
{
classes
.
editorRoot
}
onClick
=
{
this
.
handleFocus
}
>
<
Editor
...
...
This diff is collapsed.
Click to expand it.
src/TextEditorLink.js
0 → 100644
+
65
−
0
View file @
121d3d9e
// Add Link Component
import
React
from
'
react
'
;
import
{
CompositeDecorator
,
EditorState
,
Modifier
}
from
'
draft-js
'
;
/** */
function
Link
({
entityKey
,
contentState
,
children
})
{
const
{
url
}
=
contentState
.
getEntity
(
entityKey
).
getData
();
return
(
<
a
style
=
{{
color
:
'
blue
'
,
fontStyle
:
'
italic
'
}}
href
=
{
url
}
target
=
"
_blank
"
rel
=
"
noreferrer
"
>
{
children
}
<
/a
>
);
}
/** */
const
findLinkEntities
=
(
contentBlock
,
callback
,
contentState
)
=>
{
contentBlock
.
findEntityRanges
((
character
)
=>
{
const
entityKey
=
character
.
getEntity
();
return
(
entityKey
!==
null
&&
contentState
.
getEntity
(
entityKey
).
getType
()
===
'
LINK
'
);
},
callback
);
};
/** */
export
const
createLinkDecorator
=
()
=>
new
CompositeDecorator
([
{
component
:
Link
,
strategy
:
findLinkEntities
,
},
]);
// call all together
/** */
export
const
onAddLink
=
(
editorState
,
setEditorState
)
=>
{
const
linkUrl
=
window
.
prompt
(
'
Add link http://
'
);
const
decorator
=
createLinkDecorator
();
if
(
linkUrl
)
{
const
displayLink
=
window
.
prompt
(
'
Display Text
'
);
if
(
displayLink
)
{
const
currentContent
=
editorState
.
getCurrentContent
();
const
createEntity
=
currentContent
.
createEntity
(
'
LINK
'
,
'
MUTABLE
'
,
{
url
:
linkUrl
,
});
const
entityKey
=
currentContent
.
getLastCreatedEntityKey
();
const
selection
=
editorState
.
getSelection
();
const
textWithEntity
=
Modifier
.
insertText
(
currentContent
,
selection
,
displayLink
,
null
,
entityKey
,
);
const
newState
=
EditorState
.
createWithContent
(
textWithEntity
,
decorator
);
setEditorState
(
newState
);
}
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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