Welcome to mirror list, hosted at ThFree Co, Russian Federation.

image_diff_viewer.vue « viewers « diff_viewer « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5ac65bcd1fde8229b7c88ac1f9d3bef5e151514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<script>
import ImageViewer from '../../content_viewer/viewers/image_viewer.vue';
import { diffModes, imageViewMode } from '../constants';
import OnionSkinViewer from './image_diff/onion_skin_viewer.vue';
import SwipeViewer from './image_diff/swipe_viewer.vue';
import TwoUpViewer from './image_diff/two_up_viewer.vue';

export default {
  components: {
    ImageViewer,
  },
  props: {
    diffMode: {
      type: String,
      required: true,
    },
    newPath: {
      type: String,
      required: true,
    },
    oldPath: {
      type: String,
      required: true,
    },
    newSize: {
      type: Number,
      required: false,
      default: 0,
    },
    oldSize: {
      type: Number,
      required: false,
      default: 0,
    },
  },
  data() {
    return {
      mode: imageViewMode.twoup,
    };
  },
  computed: {
    imageViewComponent() {
      switch (this.mode) {
        case imageViewMode.twoup:
          return TwoUpViewer;
        case imageViewMode.swipe:
          return SwipeViewer;
        case imageViewMode.onion:
          return OnionSkinViewer;
        default:
          return undefined;
      }
    },
    isNew() {
      return this.diffMode === diffModes.new;
    },
    isRenamed() {
      return this.diffMode === diffModes.renamed;
    },
    imagePath() {
      return this.isNew || this.isRenamed ? this.newPath : this.oldPath;
    },
  },
  methods: {
    changeMode(newMode) {
      this.mode = newMode;
    },
  },
  diffModes,
  imageViewMode,
};
</script>

<template>
  <div class="diff-file-container">
    <div v-if="diffMode === $options.diffModes.replaced" class="diff-viewer">
      <div class="image js-replaced-image">
        <component :is="imageViewComponent" v-bind="$props">
          <template #image-overlay="{ renderedWidth, renderedHeight }">
            <slot
              :rendered-width="renderedWidth"
              :rendered-height="renderedHeight"
              name="image-overlay"
            ></slot>
          </template>
        </component>
      </div>
      <div class="view-modes">
        <ul class="view-modes-menu">
          <li
            :class="{
              active: mode === $options.imageViewMode.twoup,
            }"
            @click="changeMode($options.imageViewMode.twoup)"
          >
            {{ s__('ImageDiffViewer|2-up') }}
          </li>
          <li
            :class="{
              active: mode === $options.imageViewMode.swipe,
            }"
            @click="changeMode($options.imageViewMode.swipe)"
          >
            {{ s__('ImageDiffViewer|Swipe') }}
          </li>
          <li
            :class="{
              active: mode === $options.imageViewMode.onion,
            }"
            @click="changeMode($options.imageViewMode.onion)"
          >
            {{ s__('ImageDiffViewer|Onion skin') }}
          </li>
        </ul>
      </div>
    </div>
    <div v-else class="diff-viewer">
      <div class="image">
        <image-viewer
          :path="imagePath"
          :file-size="isNew ? newSize : oldSize"
          :inner-css-classes="[
            'frame',
            {
              added: isNew,
              deleted: diffMode === $options.diffModes.deleted,
            },
          ]"
        >
          <template v-if="isNew || isRenamed" #image-overlay="{ renderedWidth, renderedHeight }">
            <slot
              :rendered-width="renderedWidth"
              :rendered-height="renderedHeight"
              name="image-overlay"
            ></slot>
          </template>
        </image-viewer>
      </div>
    </div>
  </div>
</template>