-
Notifications
You must be signed in to change notification settings - Fork 126
feat: image and video blocks #3638
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
Open
+318
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
168 changes: 168 additions & 0 deletions
src/components/Questions/QuestionMedia.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,168 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <Question | ||
| v-bind="questionProps" | ||
| :titlePlaceholder="answerType.titlePlaceholder" | ||
| :warningInvalid="answerType.warningInvalid" | ||
| v-on="commonListeners"> | ||
| <div class="question-media"> | ||
| <img | ||
| v-if="isImage && url" | ||
| :src="url" | ||
| :alt="alt" | ||
| class="question-media__image" | ||
| referrerpolicy="no-referrer" | ||
| loading="lazy" /> | ||
|
|
||
| <a | ||
| v-else-if="!isImage && url" | ||
| :href="url" | ||
| class="question-media__link" | ||
| target="_blank" | ||
| rel="noopener noreferrer external"> | ||
| {{ alt || url }} | ||
| </a> | ||
|
|
||
| <p v-else class="question-media__empty"> | ||
| {{ | ||
| isImage | ||
| ? t('forms', 'No image address set yet.') | ||
| : t('forms', 'No video address set yet.') | ||
| }} | ||
| </p> | ||
|
|
||
| <template v-if="!readOnly"> | ||
| <NcTextField | ||
| :label="t('forms', 'Address')" | ||
| placeholder="https://" | ||
| :modelValue="url" | ||
| @update:modelValue="onUrlChange" /> | ||
| <NcTextField | ||
| :label=" | ||
| isImage | ||
| ? t('forms', 'Description for screen readers') | ||
| : t('forms', 'Link text') | ||
| " | ||
| :modelValue="alt" | ||
| @update:modelValue="onAltChange" /> | ||
| <NcNoteCard v-if="isExternal" type="warning"> | ||
| {{ | ||
| t( | ||
| 'forms', | ||
| 'This address is on another site. Loading it tells that site the IP address of everyone who opens the form.', | ||
| ) | ||
| }} | ||
| </NcNoteCard> | ||
| </template> | ||
| </div> | ||
| </Question> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { t } from '@nextcloud/l10n' | ||
| import { computed, defineComponent } from 'vue' | ||
| import NcNoteCard from '@nextcloud/vue/components/NcNoteCard' | ||
| import NcTextField from '@nextcloud/vue/components/NcTextField' | ||
| import Question from './Question.vue' | ||
| import { | ||
| QUESTION_EMITS, | ||
| QUESTION_PROPS, | ||
| useQuestion, | ||
| } from '../../composables/useQuestion.ts' | ||
|
|
||
| export default defineComponent({ | ||
| name: 'QuestionMedia', | ||
|
|
||
| components: { | ||
| NcNoteCard, | ||
| NcTextField, | ||
| Question, | ||
| }, | ||
|
|
||
| props: QUESTION_PROPS, | ||
| emits: QUESTION_EMITS, | ||
|
|
||
| setup(props, { emit }) { | ||
| const question = useQuestion(props, { emit }) | ||
|
|
||
| const extraSettings = computed( | ||
| () => (props.extraSettings as Record<string, unknown> | undefined) ?? {}, | ||
| ) | ||
|
|
||
| const isImage = computed( | ||
| () => | ||
| (props.answerType as { mediaKind?: string })?.mediaKind !== 'video', | ||
| ) | ||
|
|
||
| const url = computed<string>(() => (extraSettings.value.url as string) || '') | ||
| const alt = computed<string>(() => (extraSettings.value.alt as string) || '') | ||
|
|
||
| /** | ||
| * Whether the address points somewhere other than this instance, which is worth | ||
| * warning about because loading it discloses the respondent to that host. | ||
| */ | ||
| const isExternal = computed<boolean>(() => { | ||
| if (!url.value) { | ||
| return false | ||
| } | ||
| try { | ||
| return ( | ||
| new URL(url.value, window.location.origin).origin | ||
| !== window.location.origin | ||
| ) | ||
| } catch { | ||
| // An address that cannot be parsed is not yet worth warning about. | ||
| return false | ||
| } | ||
| }) | ||
|
|
||
| /** | ||
| * @param value the new address | ||
| */ | ||
| function onUrlChange(value: string): void { | ||
| question.onExtraSettingsChange({ url: value || null }) | ||
| } | ||
|
|
||
| /** | ||
| * @param value the new description or link text | ||
| */ | ||
| function onAltChange(value: string): void { | ||
| question.onExtraSettingsChange({ alt: value || null }) | ||
| } | ||
|
|
||
| return { | ||
| ...question, | ||
| alt, | ||
| isExternal, | ||
| isImage, | ||
| onAltChange, | ||
| onUrlChange, | ||
| t, | ||
| url, | ||
| } | ||
| }, | ||
| }) | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .question-media { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
|
|
||
| &__image { | ||
| border-radius: var(--border-radius); | ||
| max-height: 400px; | ||
| max-width: 100%; | ||
| object-fit: contain; | ||
| } | ||
|
|
||
| &__empty { | ||
| 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
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
Oops, something went wrong.
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.