Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Implement reference preview rendering #743

Merged
merged 14 commits into from
Aug 31, 2022
Merged
Prev Previous commit
Next Next commit
Check before sending a request
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Aug 30, 2022
commit 523f3e6e13f854f1c0b12e0cd9fab62e1cb44b92
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nextcloud/vue-richtext",
"version": "2.0.0-dev.1",
"version": "2.0.0-dev.2",
"description": "Vue component for rich content strings including markdown support.",
"keywords": [
"vuejs",
Expand Down
16 changes: 13 additions & 3 deletions src/ReferenceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import ReferenceWidget from './ReferenceWidget.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { isWidgetRegistered } from './widgets.js'
import { URL_PATTERN } from './helpers.js'

export default {
name: 'ReferenceList',
components: { ReferenceWidget },
Expand All @@ -24,7 +26,7 @@ export default {
},
limit: {
type: Number,
default: 5
default: 1
}
},
data() {
Expand All @@ -34,11 +36,14 @@ export default {
}
},
computed: {
values() {
return this.references ? Object.values(this.references) : []
},
firstReference() {
return this.references ? Object.values(this.references)[0] : null
return this.values[0] ?? null
},
displayedReferences() {
return this.references ? Object.values(this.references).slice(0, this.limit) : null
return this.values.slice(0, this.limit)
},
hasCustomWidget() {
return (reference) => isWidgetRegistered(reference.richObjectType)
Expand All @@ -62,6 +67,11 @@ export default {
return
}

if (!URL_PATTERN.exec(this.text)) {
this.loading = false
return
}

axios.post(generateOcsUrl('references/extract', 2), {
text: this.text,
resolve: true,
Expand Down
6 changes: 3 additions & 3 deletions src/autolink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { visit, SKIP } from 'unist-util-visit'
import { u } from 'unist-builder'
import { URL_PATTERN_AUTOLINK } from './helpers.js'

const Link = {
name: 'Link',
Expand Down Expand Up @@ -47,9 +48,8 @@ export const remarkAutolink = function({ autolink, useMarkdown }) {
}
}

const urlRegex = /(\s|\(|^)((https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*))(?=\s|\)|$)/ig
export const parseUrl = (text, linkComponent) => {
let match = urlRegex.exec(text)
let match = URL_PATTERN_AUTOLINK.exec(text)
const list = []
let start = 0
while (match !== null) {
Expand All @@ -71,7 +71,7 @@ export const parseUrl = (text, linkComponent) => {
list.push(textAfter)
}
start = match.index + match[0].length
match = urlRegex.exec(text)
match = URL_PATTERN_AUTOLINK.exec(text)
}
list.push(text.substring(start))
const joinedText = list.map((item) => typeof item === 'string' ? item : item.props.href).join('')
Expand Down
1 change: 1 addition & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const URL_PATTERN = /(\s|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig