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

formatting_toolbar.vue « components « content_editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc27278d2555a4125738330e852b57f341dd1fc9 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<script>
import CommentTemplatesDropdown from '~/vue_shared/components/markdown/comment_templates_dropdown.vue';
import { __, sprintf } from '~/locale';
import { getModifierKey } from '~/constants';
import trackUIControl from '../services/track_ui_control';
import ToolbarButton from './toolbar_button.vue';
import ToolbarAttachmentButton from './toolbar_attachment_button.vue';
import ToolbarTableButton from './toolbar_table_button.vue';
import ToolbarTextStyleDropdown from './toolbar_text_style_dropdown.vue';
import ToolbarMoreDropdown from './toolbar_more_dropdown.vue';

export default {
  components: {
    ToolbarButton,
    ToolbarTextStyleDropdown,
    ToolbarTableButton,
    ToolbarAttachmentButton,
    ToolbarMoreDropdown,
    CommentTemplatesDropdown,
  },
  inject: {
    newCommentTemplatePath: { default: null },
    tiptapEditor: { default: null },
    contentEditor: { default: null },
  },
  props: {
    supportsQuickActions: {
      type: Boolean,
      required: false,
      default: false,
    },
    hideAttachmentButton: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    const modifierKey = getModifierKey();
    const shiftKey = modifierKey === '⌘' ? '⇧' : 'Shift+';

    return {
      i18n: {
        bold: sprintf(__('Bold (%{modifierKey}B)'), { modifierKey }),
        italic: sprintf(__('Italic (%{modifierKey}I)'), { modifierKey }),
        strike: sprintf(__('Strikethrough (%{modifierKey}%{shiftKey}X)'), {
          modifierKey,
          shiftKey,
        }),
        quote: __('Insert a quote'),
        code: __('Code'),
        link: sprintf(__('Insert link (%{modifierKey}K)'), { modifierKey }),
        bulletList: __('Add a bullet list'),
        numberedList: __('Add a numbered list'),
        taskList: __('Add a checklist'),
      },
    };
  },
  computed: {
    codeSuggestionsEnabled() {
      return this.contentEditor.codeSuggestionsConfig?.canSuggest;
    },
  },
  methods: {
    trackToolbarControlExecution({ contentType, value }) {
      trackUIControl({ property: contentType, value });
    },
    insertSavedReply(savedReply) {
      this.tiptapEditor.chain().focus().pasteContent(savedReply).run();
    },
  },
};
</script>
<template>
  <div
    class="gl-w-full gl-display-flex gl-align-items-center gl-flex-wrap gl-border-b gl-border-gray-100 gl-px-3 gl-rounded-top-base gl-justify-content-space-between"
    data-testid="formatting-toolbar"
  >
    <div class="gl-py-3 gl-display-flex gl-flex-wrap">
      <toolbar-text-style-dropdown
        data-testid="text-styles"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        v-if="codeSuggestionsEnabled"
        data-testid="code-suggestion"
        content-type="codeSuggestion"
        icon-name="doc-code"
        editor-command="insertCodeSuggestion"
        :label="__('Insert suggestion')"
        :show-active-state="false"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="bold"
        content-type="bold"
        icon-name="bold"
        editor-command="toggleBold"
        :label="i18n.bold"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="italic"
        content-type="italic"
        icon-name="italic"
        editor-command="toggleItalic"
        :label="i18n.italic"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="strike"
        content-type="strike"
        icon-name="strikethrough"
        editor-command="toggleStrike"
        :label="i18n.strike"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="blockquote"
        content-type="blockquote"
        icon-name="quote"
        editor-command="toggleBlockquote"
        :label="i18n.quote"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="code"
        content-type="code"
        icon-name="code"
        editor-command="toggleCode"
        :label="i18n.code"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="link"
        content-type="link"
        icon-name="link"
        editor-command="editLink"
        :label="i18n.link"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="bullet-list"
        content-type="bulletList"
        icon-name="list-bulleted"
        class="gl-display-none gl-sm-display-inline"
        editor-command="toggleBulletList"
        :label="i18n.bulletList"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="ordered-list"
        content-type="orderedList"
        icon-name="list-numbered"
        class="gl-display-none gl-sm-display-inline"
        editor-command="toggleOrderedList"
        :label="i18n.numberedList"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-button
        data-testid="task-list"
        content-type="taskList"
        icon-name="list-task"
        class="gl-display-none gl-sm-display-inline"
        editor-command="toggleTaskList"
        :label="i18n.taskList"
        @execute="trackToolbarControlExecution"
      />
      <toolbar-table-button data-testid="table" @execute="trackToolbarControlExecution" />
      <toolbar-attachment-button
        v-if="!hideAttachmentButton"
        data-testid="attachment"
        @execute="trackToolbarControlExecution"
      />
      <!-- TODO Add icon and trigger functionality from here -->
      <toolbar-button
        v-if="supportsQuickActions"
        data-testid="quick-actions"
        content-type="quickAction"
        icon-name="quick-actions"
        class="gl-display-none gl-sm-display-inline"
        editor-command="insertQuickAction"
        :label="__('Add a quick action')"
        @execute="trackToolbarControlExecution"
      />
      <comment-templates-dropdown
        v-if="newCommentTemplatePath"
        :new-comment-template-path="newCommentTemplatePath"
        @select="insertSavedReply"
      />
      <toolbar-more-dropdown data-testid="more" @execute="trackToolbarControlExecution" />
    </div>
  </div>
</template>