Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make links clickable in locations and description areas - rel: #5030 #5355

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

Check warning on line 34 in src/components/Editor/Properties/PropertyText.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Properties/PropertyText.vue#L34

Added line #L34 was not covered by tests
v-autosize="true"
:placeholder="placeholder"
:rows="rows"
:title="readableName"
:value="value"
@focus="handleToggleTextareaFocus(true)"
@blur="handleToggleTextareaFocus(false)"

Check warning on line 41 in src/components/Editor/Properties/PropertyText.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/Properties/PropertyText.vue#L40-L41

Added lines #L40 - L41 were not covered by tests
@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 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 @@
},
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

Check warning on line 16 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L11-L16

Added lines #L11 - L16 were not covered by tests
},
linkifyMinHeight() {
return this.rows > 1 ? '68px' : '48px'

Check warning on line 19 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L18-L19

Added lines #L18 - L19 were not covered by tests
},
},
data() {
return {

Check warning on line 23 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L22-L23

Added lines #L22 - L23 were not covered by tests
textareaHasFocus: false,
}
},

methods: {
handleShowTextarea(evt) {

Check warning on line 29 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L29

Added line #L29 was not covered by tests

if (this.isReadOnly || this.linkifyLinks === false) {

Check warning on line 31 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L31

Added line #L31 was not covered by tests
// do nothing
return

Check warning on line 33 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L33

Added line #L33 was not covered by tests
}
if (evt.target && evt.target.tagName === 'A') {

Check warning on line 35 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L35

Added line #L35 was not covered by tests
// a link was clicked, do nothing
return

Check warning on line 37 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L37

Added line #L37 was not covered by tests
}
if (this.textareaHasFocus === true) {

Check warning on line 39 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L39

Added line #L39 was not covered by tests
// the textarea is shown already, should never happen
console.error('this.textareaHasFocus is true but click event is dispatched on div')
return

Check warning on line 42 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L41-L42

Added lines #L41 - L42 were not covered by tests
}

const parent = evt.currentTarget.parentElement
this.textareaHasFocus = true

Check warning on line 46 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L45-L46

Added lines #L45 - L46 were not covered by tests

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

Check warning on line 55 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L48-L55

Added lines #L48 - L55 were not covered by tests
}
}
})
},

/**
* @param {boolean} hasFocus
*/
handleToggleTextareaFocus(hasFocus) {
if (this.linkifyLinks === false) {

Check warning on line 65 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L64-L65

Added lines #L64 - L65 were not covered by tests
// do nothing
return

Check warning on line 67 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L67

Added line #L67 was not covered by tests
}
this.textareaHasFocus = hasFocus

Check warning on line 69 in src/mixins/PropertyLinksMixin.js

View check run for this annotation

Codecov / codecov/patch

src/mixins/PropertyLinksMixin.js#L69

Added line #L69 was not covered by tests
},
},
}
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
Loading