Skip to content

Commit

Permalink
Merge pull request #5355 from SergeyMosin/clickable-links
Browse files Browse the repository at this point in the history
make links clickable in locations and description areas - rel: #5030
  • Loading branch information
st3iny authored Aug 8, 2023
2 parents b40506a + 8fa9d99 commit ba23fe1
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 11 deletions.
1 change: 1 addition & 0 deletions css/calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
@import 'import.scss';
@import 'print.scss';
@import 'public.scss';
@import 'props-linkify-links.scss';
25 changes: 25 additions & 0 deletions css/props-linkify-links.scss
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: '';
}
}
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"css-color-names": "^1.0.1",
"debounce": "^1.2.1",
"jstz": "^2.1.1",
"linkifyjs": "^4.1.1",
"lodash": "^4.17.21",
"md5": "^2.3.0",
"p-limit": "^4.0.0",
Expand Down
13 changes: 10 additions & 3 deletions src/components/Editor/Properties/PropertyText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@
:class="{ 'property-text__icon--hidden': !showIcon }" />

<div class="property-text__input"
:class="{ 'property-text__input--readonly': isReadOnly }">
<textarea v-if="!isReadOnly"
:class="{ 'property-text__input--readonly': isReadOnly, 'property-text__input--linkify': showLinksClickable }">
<textarea v-if="!isReadOnly && !showLinksClickable"
v-autosize="true"
:placeholder="placeholder"
:rows="rows"
:title="readableName"
:value="value"
@focus="handleToggleTextareaFocus(true)"
@blur="handleToggleTextareaFocus(false)"
@input.prevent.stop="changeValue" />
<!-- eslint-disable-next-line vue/singleline-html-element-content-newline -->
<div v-else
v-linkify="{ text: value, linkify: true }" />
v-linkify="{ text: value, linkify: true }"
:class="{ 'linkify-links': linkifyLinks && !isReadOnly }"
:style="{ 'min-height': linkifyMinHeight }"
@click="handleShowTextarea" />
</div>

<div v-if="hasInfo"
Expand All @@ -58,6 +63,7 @@ import PropertyMixin from '../../../mixins/PropertyMixin.js'
import linkify from '@nextcloud/vue/dist/Directives/Linkify.js'
import InformationVariant from 'vue-material-design-icons/InformationVariant.vue'
import PropertyLinksMixin from '../../../mixins/PropertyLinksMixin.js'
export default {
name: 'PropertyText',
Expand All @@ -68,6 +74,7 @@ export default {
},
mixins: [
PropertyMixin,
PropertyLinksMixin,
],
computed: {
display() {
Expand Down
72 changes: 72 additions & 0 deletions src/mixins/PropertyLinksMixin.js
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
},
},
}
2 changes: 2 additions & 0 deletions src/views/EditSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@
<PropertyText :is-read-only="isReadOnly"
:prop-model="rfcProps.location"
:value="location"
:linkify-links="true"
@update:value="updateLocation" />
<PropertyText :is-read-only="isReadOnly"
:prop-model="rfcProps.description"
:value="description"
:linkify-links="true"
@update:value="updateDescription" />

<PropertySelect :is-read-only="isReadOnly"
Expand Down
2 changes: 2 additions & 0 deletions src/views/EditSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@
<PropertyText :is-read-only="isReadOnly"
:prop-model="rfcProps.location"
:value="location"
:linkify-links="true"
@update:value="updateLocation" />
<PropertyText :is-read-only="isReadOnly"
:prop-model="rfcProps.description"
:value="description"
:linkify-links="true"
@update:value="updateDescription" />

<InvitationResponseButtons v-if="isViewedByAttendee"
Expand Down

0 comments on commit ba23fe1

Please sign in to comment.