summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/content_editor/extensions/reference_label.js
blob: 716e191c3d5bf8c9d8eba8f2c15b663a242e52d2 (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
import { VueNodeViewRenderer } from '@tiptap/vue-2';
import { SCOPED_LABEL_DELIMITER } from '~/vue_shared/components/sidebar/labels_select_widget/constants';
import LabelWrapper from '../components/wrappers/label.vue';
import Reference from './reference';

export default Reference.extend({
  name: 'reference_label',

  addAttributes() {
    return {
      ...this.parent(),
      text: {
        default: null,
        parseHTML: (element) => {
          const text = element.querySelector('.gl-label-text').textContent;
          const scopedText = element.querySelector('.gl-label-text-scoped')?.textContent;
          if (!scopedText) return text;
          return `${text}${SCOPED_LABEL_DELIMITER}${scopedText}`;
        },
      },
      color: {
        default: null,
        parseHTML: (element) => element.querySelector('.gl-label-text').style.backgroundColor,
      },
    };
  },

  parseHTML() {
    return [{ tag: 'span.gl-label' }];
  },

  addNodeView() {
    return new VueNodeViewRenderer(LabelWrapper);
  },
});