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

popover.vue « components « code_navigation « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4cc5a5cd6a25f1572d522b4349c1660cd519254f (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
<script>
import { GlButton } from '@gitlab/ui';
import DocLine from './doc_line.vue';

export default {
  components: {
    GlButton,
    DocLine,
  },
  props: {
    position: {
      type: Object,
      required: true,
    },
    data: {
      type: Object,
      required: true,
    },
    definitionPathPrefix: {
      type: String,
      required: true,
    },
    blobPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      offsetLeft: 0,
    };
  },
  computed: {
    isCurrentDefinition() {
      return this.data.definitionLineNumber - 1 === this.position.lineIndex;
    },
    positionStyles() {
      return {
        left: `${this.position.x - this.offsetLeft}px`,
        top: `${this.position.y + this.position.height}px`,
      };
    },
    definitionPath() {
      if (!this.data.definition_path) {
        return null;
      }

      if (this.isDefinitionCurrentBlob) {
        return `#L${this.data.definitionLineNumber}`;
      }

      return `${this.definitionPathPrefix}/${this.data.definition_path}`;
    },
    isDefinitionCurrentBlob() {
      return this.data.definition_path.indexOf(this.blobPath) === 0;
    },
  },
  watch: {
    position: {
      handler() {
        this.$nextTick(() => this.updateOffsetLeft());
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    updateOffsetLeft() {
      this.offsetLeft = Math.max(
        0,
        this.$el.offsetLeft + this.$el.offsetWidth - window.innerWidth + 20,
      );
    },
  },
  colorScheme: gon?.user_color_scheme,
};
</script>

<template>
  <div
    :style="positionStyles"
    class="popover code-navigation-popover popover-font-size-normal gl-popover bs-popover-bottom show"
  >
    <div :style="{ left: `${offsetLeft}px` }" class="arrow"></div>
    <div class="overflow-auto code-navigation-popover-container">
      <div
        v-for="(hover, index) in data.hover"
        :key="index"
        :class="{ 'border-bottom': index !== data.hover.length - 1 }"
      >
        <pre
          v-if="hover.language"
          ref="code-output"
          :class="$options.colorScheme"
          class="border-0 bg-transparent m-0 code highlight text-wrap"
        ><doc-line v-for="(tokens, tokenIndex) in hover.tokens" :key="tokenIndex" :language="hover.language" :tokens="tokens"/></pre>
        <p v-else ref="doc-output" class="p-3 m-0 gl-font-base">
          {{ hover.value }}
        </p>
      </div>
    </div>
    <div v-if="definitionPath || isCurrentDefinition" class="popover-body border-top">
      <span v-if="isCurrentDefinition" class="gl-font-weight-bold gl-font-base">
        {{ s__('CodeIntelligence|This is the definition') }}
      </span>
      <gl-button
        v-else
        :href="definitionPath"
        :target="isDefinitionCurrentBlob ? null : '_blank'"
        class="w-100"
        variant="default"
        data-testid="go-to-definition-btn"
      >
        {{ __('Go to definition') }}
      </gl-button>
    </div>
  </div>
</template>