summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/content_editor/components/wrappers/media.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/content_editor/components/wrappers/media.vue')
-rw-r--r--app/assets/javascripts/content_editor/components/wrappers/media.vue51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/assets/javascripts/content_editor/components/wrappers/media.vue b/app/assets/javascripts/content_editor/components/wrappers/media.vue
new file mode 100644
index 00000000000..37119bdd066
--- /dev/null
+++ b/app/assets/javascripts/content_editor/components/wrappers/media.vue
@@ -0,0 +1,51 @@
+<script>
+import { GlLoadingIcon } from '@gitlab/ui';
+import { NodeViewWrapper } from '@tiptap/vue-2';
+
+const tagNameMap = {
+ image: 'img',
+ video: 'video',
+ audio: 'audio',
+};
+
+export default {
+ name: 'MediaWrapper',
+ components: {
+ NodeViewWrapper,
+ GlLoadingIcon,
+ },
+ props: {
+ node: {
+ type: Object,
+ required: true,
+ },
+ },
+ computed: {
+ tagName() {
+ return tagNameMap[this.node.type.name] || 'img';
+ },
+ },
+};
+</script>
+<template>
+ <node-view-wrapper class="gl-display-inline-block">
+ <span class="gl-relative" :class="{ [`media-container ${tagName}-container`]: true }">
+ <gl-loading-icon v-if="node.attrs.uploading" class="gl-absolute gl-left-50p gl-top-half" />
+ <component
+ :is="tagName"
+ data-testid="media"
+ :class="{
+ 'gl-max-w-full gl-h-auto': tagName !== 'audio',
+ 'gl-opacity-5': node.attrs.uploading,
+ }"
+ :title="node.attrs.title || node.attrs.alt"
+ :alt="node.attrs.alt"
+ :src="node.attrs.src"
+ controls="true"
+ />
+ <a v-if="tagName !== 'img'" :href="node.attrs.canonicalSrc || node.attrs.src" @click.prevent>
+ {{ node.attrs.title || node.attrs.alt }}
+ </a>
+ </span>
+ </node-view-wrapper>
+</template>