-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): make links clickable in locations and description areas
Signed-off-by: Richard Steinmetz <[email protected]>
- Loading branch information
Showing
6 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ | |
@import 'import.scss'; | ||
@import 'print.scss'; | ||
@import 'public.scss'; | ||
@import 'props-linkify-links.scss'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.property-text__input--linkify { | ||
flex-basis: min-content; | ||
} | ||
|
||
.linkify-links { | ||
border: 2px solid var(--color-border-maxcontrast); | ||
border-radius: var(--border-radius-large); | ||
cursor: text; | ||
width: 100% !important; | ||
box-sizing: border-box; | ||
margin-top: 1px !important; | ||
padding: 12px; | ||
white-space: pre-line; | ||
overflow: auto; | ||
line-height: normal; | ||
word-break: break-word; | ||
display: inline-block; | ||
vertical-align: top; | ||
max-height: 16em; | ||
max-height: calc(100vh - 500px); | ||
|
||
a.linkified::after { | ||
content: ' ↗'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { find as findLinks } from 'linkifyjs' | ||
|
||
export default { | ||
props: { | ||
linkifyLinks: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
computed: { | ||
showLinksClickable() { | ||
return this.linkifyLinks | ||
&& this.textareaHasFocus === false | ||
&& typeof this.value === 'string' | ||
&& this.value.length > 4 | ||
&& findLinks(this.value).length > 0 | ||
}, | ||
linkifyMinHeight() { | ||
return this.rows > 1 ? '68px' : '48px' | ||
}, | ||
}, | ||
data() { | ||
return { | ||
textareaHasFocus: false, | ||
} | ||
}, | ||
|
||
methods: { | ||
handleShowTextarea(evt) { | ||
|
||
if (this.isReadOnly || this.linkifyLinks === false) { | ||
// do nothing | ||
return | ||
} | ||
if (evt.target && evt.target.tagName === 'A') { | ||
// a link was clicked, do nothing | ||
return | ||
} | ||
if (this.textareaHasFocus === true) { | ||
// the textarea is shown already, should never happen | ||
console.error('this.textareaHasFocus is true but click event is dispatched on div') | ||
return | ||
} | ||
|
||
const parent = evt.currentTarget.parentElement | ||
this.textareaHasFocus = true | ||
|
||
this.$nextTick(() => { | ||
if (parent && parent.firstElementChild) { | ||
const textarea = parent.firstElementChild | ||
textarea.focus() | ||
if (this.value && this.value.length > 64) { | ||
textarea.selectionStart = textarea.selectionEnd = 0 | ||
} else { | ||
textarea.selectionStart = textarea.selectionEnd = 64 | ||
} | ||
} | ||
}) | ||
}, | ||
|
||
/** | ||
* @param {boolean} hasFocus | ||
*/ | ||
handleToggleTextareaFocus(hasFocus) { | ||
if (this.linkifyLinks === false) { | ||
// do nothing | ||
return | ||
} | ||
this.textareaHasFocus = hasFocus | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters