-
Notifications
You must be signed in to change notification settings - Fork 96
Merge @nextcloud/vue-richtext into @nextcloud/vue
#3841
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e17db7
Merge nextcloud/vue-richtext into nextcloud/vue
raimund-schluessler 9d82207
Remove dependency to @nextcloud/vue-richtext
raimund-schluessler bfae031
Fix JSDoc lint warnings
raimund-schluessler e5e3a5e
Add NcRichText.spec.js test file
raimund-schluessler 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
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,99 @@ | ||
| <template> | ||
| <div class="widgets--list" :class="{'icon-loading': loading }"> | ||
| <div v-for="reference in displayedReferences" :key="reference.openGraphObject.id"> | ||
| <NcReferenceWidget :reference="reference" /> | ||
| </div> | ||
| </div> | ||
| </template> | ||
| <script> | ||
| import NcReferenceWidget from './NcReferenceWidget.vue' | ||
| import { URL_PATTERN } from './helpers.js' | ||
|
|
||
| import axios from '@nextcloud/axios' | ||
| import { generateOcsUrl } from '@nextcloud/router' | ||
|
|
||
| export default { | ||
| name: 'NcReferenceList', | ||
| components: { | ||
| NcReferenceWidget, | ||
| }, | ||
| props: { | ||
| text: { | ||
| type: String, | ||
| default: '', | ||
| }, | ||
| referenceData: { | ||
| type: Object, | ||
| default: null, | ||
| }, | ||
| limit: { | ||
| type: Number, | ||
| default: 1, | ||
| }, | ||
| }, | ||
| data() { | ||
| return { | ||
| references: null, | ||
| loading: true, | ||
| } | ||
| }, | ||
| computed: { | ||
| values() { | ||
| return this.referenceData | ||
| ? this.referenceData | ||
| : (this.references ? Object.values(this.references) : []) | ||
| }, | ||
| firstReference() { | ||
| return this.values[0] ?? null | ||
| }, | ||
| displayedReferences() { | ||
| return this.values.slice(0, this.limit) | ||
| }, | ||
| }, | ||
| watch: { | ||
| text: 'fetch', | ||
| }, | ||
| mounted() { | ||
| this.fetch() | ||
| }, | ||
| methods: { | ||
| fetch() { | ||
| this.loading = true | ||
| if (this.referenceData) { | ||
| this.loading = false | ||
| return | ||
| } | ||
|
|
||
| if (!(new RegExp(URL_PATTERN).exec(this.text))) { | ||
| this.loading = false | ||
| return | ||
| } | ||
|
|
||
| this.resolve().then((response) => { | ||
| this.references = response.data.ocs.data.references | ||
| this.loading = false | ||
| }).catch((error) => { | ||
| console.error('Failed to extract references', error) | ||
| this.loading = false | ||
| }) | ||
| }, | ||
| resolve() { | ||
| const match = (new RegExp(URL_PATTERN).exec(this.text.trim())) | ||
| if (this.limit === 1 && match) { | ||
| return axios.get(generateOcsUrl('references/resolve', 2) + `?reference=${encodeURIComponent(match[0])}`) | ||
| } | ||
|
|
||
| return axios.post(generateOcsUrl('references/extract', 2), { | ||
| text: this.text, | ||
| resolve: true, | ||
| limit: this.limit, | ||
| }) | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
| <style lang="scss" scoped> | ||
| .widgets--list.icon-loading { | ||
| min-height: 44px; | ||
| } | ||
| </style> |
67 changes: 67 additions & 0 deletions
67
src/components/NcRichText/NcReferencePicker/NcCustomPickerElement.vue
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,67 @@ | ||
| <template> | ||
| <div ref="domElement" /> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { renderCustomPickerElement, isCustomPickerElementRegistered, destroyCustomPickerElement } from './customPickerElements.js' | ||
|
|
||
| export default { | ||
| name: 'NcCustomPickerElement', | ||
| props: { | ||
| /** | ||
| * The reference provider | ||
| */ | ||
| provider: { | ||
| type: Object, | ||
| required: true, | ||
| }, | ||
| }, | ||
| data() { | ||
| return { | ||
| isRegistered: isCustomPickerElementRegistered(this.provider.id), | ||
| renderResult: null, | ||
| } | ||
| }, | ||
| mounted() { | ||
| if (this.isRegistered) { | ||
| this.renderElement() | ||
| } | ||
| }, | ||
| beforeDestroy() { | ||
| if (this.isRegistered) { | ||
| destroyCustomPickerElement(this.provider.id, this.$el, this.renderResult) | ||
| } | ||
| }, | ||
| methods: { | ||
| renderElement() { | ||
| if (this.$refs.domElement) { | ||
| this.$refs.domElement.innerHTML = '' | ||
| } | ||
|
|
||
| const renderFunctionResult = renderCustomPickerElement(this.$refs.domElement, { providerId: this.provider.id, accessible: false }) | ||
| // this works whether renderCustomPickerElement returns a promise or a value | ||
| Promise.resolve(renderFunctionResult).then(result => { | ||
| this.renderResult = result | ||
| if (this.renderResult.object?._isVue && this.renderResult.object?.$on) { | ||
| this.renderResult.object.$on('submit', this.onSubmit) | ||
| this.renderResult.object.$on('cancel', this.onCancel) | ||
| } | ||
| this.renderResult.element.addEventListener('submit', (e) => { | ||
| this.onSubmit(e.detail) | ||
| }) | ||
| this.renderResult.element.addEventListener('cancel', this.onCancel) | ||
| }) | ||
| }, | ||
| onSubmit(value) { | ||
| this.$emit('submit', value) | ||
| }, | ||
| onCancel() { | ||
| this.$emit('cancel') | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| // nothing yet | ||
| </style> |
142 changes: 142 additions & 0 deletions
142
src/components/NcRichText/NcReferencePicker/NcProviderList.vue
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,142 @@ | ||
| <template> | ||
| <div class="provider-list"> | ||
| <NcMultiselect ref="provider-select" | ||
| v-model="selectedProvider" | ||
| class="provider-list--select" | ||
| track-by="id" | ||
| label="title" | ||
| :placeholder="multiselectPlaceholder" | ||
| :options="options" | ||
| :internal-search="false" | ||
| :clear-on-select="true" | ||
| :preserve-search="true" | ||
| :option-height="44" | ||
| @search-change="query = $event" | ||
| @input="onProviderSelected"> | ||
| <template #option="{option}"> | ||
| <div v-if="option.isLink" class="provider"> | ||
| <LinkVariantIcon class="link-icon" :size="20" /> | ||
| <span>{{ option.title }}</span> | ||
| </div> | ||
| <div v-else class="provider"> | ||
| <img class="provider-icon" | ||
| :src="option.icon_url"> | ||
| <NcHighlight class="option-text" | ||
| :search="query" | ||
| :text="option.title" /> | ||
| </div> | ||
| </template> | ||
| </NcMultiselect> | ||
| <NcEmptyContent class="provider-list--empty-content"> | ||
| <template #icon> | ||
| <LinkVariantIcon /> | ||
| </template> | ||
| </NcEmptyContent> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { searchProvider } from './providerHelper.js' | ||
| import { isUrl } from './utils.js' | ||
| import NcEmptyContent from '../../NcEmptyContent/index.js' | ||
| import NcHighlight from '../../NcHighlight/index.js' | ||
| import NcMultiselect from '../../NcMultiselect/index.js' | ||
|
|
||
| import LinkVariantIcon from 'vue-material-design-icons/LinkVariant.vue' | ||
|
|
||
| export default { | ||
| name: 'NcProviderList', | ||
| components: { | ||
| NcMultiselect, | ||
| NcHighlight, | ||
| NcEmptyContent, | ||
| LinkVariantIcon, | ||
| }, | ||
| data() { | ||
| return { | ||
| selectedProvider: null, | ||
| query: '', | ||
| // TODO translate? | ||
| multiselectPlaceholder: 'Select a link provider', | ||
| } | ||
| }, | ||
| computed: { | ||
| options() { | ||
| const result = [] | ||
| if (this.query !== '' && isUrl(this.query)) { | ||
| result.push({ | ||
| id: this.query, | ||
| title: this.query, | ||
| isLink: true, | ||
| }) | ||
| } | ||
| result.push(...searchProvider(this.query)) | ||
| return result | ||
| }, | ||
| }, | ||
| methods: { | ||
| focus() { | ||
| this.$nextTick(() => { | ||
| this.$refs['provider-select']?.$el?.focus() | ||
| }) | ||
| }, | ||
| onProviderSelected(p) { | ||
| if (p !== null) { | ||
| if (p.isLink) { | ||
| this.$emit('submit', p.title) | ||
| } else { | ||
| this.$emit('select-provider', p) | ||
| } | ||
| this.selectedProvider = null | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .provider-list { | ||
| width: 100%; | ||
| min-height: 350px; | ||
| // multiselect dropdown is wider than the select input | ||
| // this avoids overflow | ||
| padding-right: 2px; | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| &--empty-content { | ||
| margin-top: auto !important; | ||
| margin-bottom: auto !important; | ||
| } | ||
|
|
||
| &--select { | ||
| width: 100%; | ||
|
|
||
| .provider { | ||
| display: flex; | ||
| align-items: center; | ||
| height: 28px; | ||
| overflow: hidden; | ||
|
|
||
| .link-icon { | ||
| margin-right: 8px; | ||
| } | ||
|
|
||
| .provider-icon { | ||
| width: 20px; | ||
| height: 20px; | ||
| object-fit: contain; | ||
| margin-right: 8px; | ||
| filter: var(--background-invert-if-dark); | ||
| } | ||
|
|
||
| .option-text { | ||
| overflow: hidden; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
| </style> |
Oops, something went wrong.
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.