This repository was archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Implement reference preview rendering #743
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7c7ef89
Add reference widget implementation
juliusknorr 8772a6a
Add axios and export more functions
juliusknorr a466e86
Switch to @nextcloud packages
juliusknorr 3f9032a
Fix test with additional container
juliusknorr a87d56c
Bump version to 2.0.0-dev.0
juliusknorr 5d5d145
Fix styling and clean up registration API
juliusknorr e4da2d3
Fix spacing in tests
juliusknorr 1496843
Bump dev version
juliusknorr d0ecd22
Rename package org to nextcloud
juliusknorr d900706
Set proper max contrast for link
juliusknorr a287761
Remove non-specific no access message
juliusknorr 523f3e6
Check before sending a request
juliusknorr 831fba7
Reactive resizing and addressing review comments
juliusknorr edd681d
Strip protocol from displayed link
juliusknorr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add reference widget implementation
Signed-off-by: Julius Härtl <[email protected]>
- Loading branch information
commit 7c7ef89bbdfb78ac3646921e4d80a4ed2bcd903b
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,94 @@ | ||
| <template> | ||
| <div> | ||
| <div v-if="noAccess"> | ||
| <p>You may not have access to this reference!</p> | ||
| </div> | ||
|
|
||
| <div v-else-if="reference && hasCustomWidget" ref="customWidget" class="widget-custom" /> | ||
|
|
||
| <div v-else-if="reference && reference.openGraphObject && !hasCustomWidget" class="widget-default"> | ||
| <div v-if="reference.openGraphObject.thumb" class="widget-default--image" :style="{ 'backgroundImage': 'url(' + reference.openGraphObject.thumb + ')' }" /> | ||
juliusknorr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <p class="widget-default--title"> | ||
| <strong>{{ reference.openGraphObject.name }}</strong> | ||
| </p> | ||
| <p class="widget-default--description"> | ||
| {{ reference.openGraphObject.description }} | ||
| </p> | ||
| <p class="widget-default--link"> | ||
| <a :href="reference.openGraphObject.link" target="_blank">{{ reference.openGraphObject.link }}</a> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </template> | ||
| <script> | ||
| import { renderWidget, isWidgetRegistered } from './widgets.js' | ||
|
|
||
| export default { | ||
| name: 'ReferenceWidget', | ||
| props: { | ||
| reference: { | ||
| type: Object, | ||
| required: true | ||
| } | ||
| }, | ||
| data() { | ||
| return {} | ||
| }, | ||
| computed: { | ||
| hasCustomWidget() { | ||
| return isWidgetRegistered(this.reference.richObjectType) | ||
| }, | ||
| noAccess() { | ||
| return this.reference && !this.reference.accessible | ||
| } | ||
| }, | ||
| mounted() { | ||
| this.renderWidget() | ||
| }, | ||
| methods: { | ||
| renderWidget() { | ||
| if (this.$refs.customWidget) { | ||
| this.$refs.customWidget.innerHTML = '' | ||
| } | ||
| if (this?.reference?.richObjectType === 'open-graph') { | ||
| return | ||
| } | ||
| this.$nextTick(() => { | ||
| // Waiting for the ref to become available | ||
| renderWidget(this.reference.richObjectType, this.reference.richObject, this.$refs.customWidget) | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| </script> | ||
| <style lang="scss" scoped> | ||
| .widget-custom { | ||
| max-width: 500px; | ||
| margin: auto; | ||
| margin-bottom: 10px; | ||
| padding: 12px; | ||
| border-radius: var(--border-radius-large); | ||
| background-color: var(--color-primary-light); | ||
| } | ||
|
|
||
| .widget-default { | ||
| max-width: 500px; | ||
| margin: auto; | ||
| margin-bottom: 10px; | ||
| padding: 12px; | ||
| border-radius: var(--border-radius-large); | ||
| background-color: var(--color-background-dark); | ||
|
|
||
| &--image { | ||
| // FIXME: open graph images are likely 1.91:1 ratio | ||
| height: 260px; | ||
| width: 500px; | ||
| background-position: center; | ||
| background-size: cover; | ||
| } | ||
|
|
||
| &--link a { | ||
| color: var(--color-text-maxcontrast); | ||
| } | ||
| } | ||
| </style> | ||
This file contains hidden or 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,88 @@ | ||
| <template> | ||
| <div :class="{'icon-loading': loading }"> | ||
| <div v-for="reference in displayedReferences" :key="reference.openGraphObject.id"> | ||
| <ReferenceWidget :reference="reference" /> | ||
| </div> | ||
| </div> | ||
| </template> | ||
| <script> | ||
| import ReferenceWidget from './ReferenceWidget.vue' | ||
|
|
||
| export default { | ||
| name: 'References', | ||
| components: { ReferenceWidget }, | ||
| props: { | ||
| text: { | ||
| type: String, | ||
| default: '' | ||
| }, | ||
| referenceData: { | ||
| type: Object | ||
| }, | ||
| limit: { | ||
| type: Number, | ||
| default: 5 | ||
| } | ||
| }, | ||
| data() { | ||
| return { | ||
| references: null, | ||
| loading: true | ||
| } | ||
| }, | ||
| computed: { | ||
| firstReference() { | ||
| return this.references ? Object.values(this.references)[0] : null | ||
| }, | ||
| displayedReferences() { | ||
| return this.references ? Object.values(this.references).slice(0, this.limit) : null | ||
| }, | ||
| hasCustomWidget() { | ||
| return (reference) => !!widgets[reference.richObjectType] | ||
| }, | ||
| noAccess() { | ||
| return (reference) => reference && !reference.accessible | ||
| } | ||
| }, | ||
| watch: { | ||
| text: 'fetch' | ||
| }, | ||
| mounted() { | ||
| this.fetch() | ||
| }, | ||
| methods: { | ||
| fetch() { | ||
| this.loading = true | ||
| if (this.referenceData) { | ||
| this.references = this.referenceData | ||
| this.loading = false | ||
| return | ||
| } | ||
|
|
||
| fetch('http://nextcloud.dev.local/ocs/v2.php/references/extract?format=json', { | ||
juliusknorr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| text: this.text, | ||
| resolve: true, | ||
| requesttoken: window.oc_requesttoken, | ||
| limit: this.limit | ||
| }), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| requesttoken: window.oc_requesttoken | ||
| } | ||
| }) | ||
| .then(response => response.json()) | ||
| .then(json => { | ||
| console.log(json) | ||
| this.references = json.ocs.data.references | ||
| this.loading = false | ||
| }) | ||
| .catch(error => { | ||
| console.error(error) | ||
| this.loading = false | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| </script> | ||
This file contains hidden or 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 hidden or 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,41 @@ | ||
|
|
||
| if (!window._vue_richtext_widgets) { | ||
| window._vue_richtext_widgets = {} | ||
| } | ||
|
|
||
| const isWidgetRegistered = (id) => { | ||
| return !!window._vue_richtext_widgets[id] | ||
| } | ||
|
|
||
| const registerWidget = (id, callback) => { | ||
| if (window._vue_richtext_widgets[id]) { | ||
| console.error('Widget for id ' + id + ' already registered') | ||
| return | ||
| } | ||
|
|
||
| window._vue_richtext_widgets[id] = { | ||
| id, | ||
| callback | ||
| } | ||
| } | ||
|
|
||
| const renderWidget = (id, richObjectData, el) => { | ||
| if (id === 'open-graph') { | ||
| return | ||
| } | ||
|
|
||
| if (!window._vue_richtext_widgets[id]) { | ||
| console.error('Widget for id ' + id + ' not registered') | ||
| return | ||
| } | ||
|
|
||
| window._vue_richtext_widgets[id].callback(richObjectData, el) | ||
| } | ||
|
|
||
| window._registerWidget = registerWidget | ||
|
|
||
| export { | ||
| registerWidget, | ||
| renderWidget, | ||
| isWidgetRegistered | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.