summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/editor/constants.js
blob: d235319dfd7bd5963631e637a0f43e3572905595 (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
import { getModifierKey } from '~/constants';
import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants';
import { s__, __, sprintf } from '~/locale';

const modifierKey = getModifierKey();

export const URI_PREFIX = 'gitlab';
export const CONTENT_UPDATE_DEBOUNCE = DEFAULT_DEBOUNCE_AND_THROTTLE_MS;

export const EDITOR_READY_EVENT = 'editor-ready';

export const EDITOR_TYPE_CODE = 'vs.editor.ICodeEditor';
export const EDITOR_TYPE_DIFF = 'vs.editor.IDiffEditor';

export const EDITOR_CODE_INSTANCE_FN = 'createInstance';
export const EDITOR_DIFF_INSTANCE_FN = 'createDiffInstance';

export const EDITOR_TOOLBAR_LEFT_GROUP = 'left';
export const EDITOR_TOOLBAR_RIGHT_GROUP = 'right';

export const SOURCE_EDITOR_INSTANCE_ERROR_NO_EL = s__(
  'SourceEditor|"el" parameter is required for createInstance()',
);
export const ERROR_INSTANCE_REQUIRED_FOR_EXTENSION = s__(
  'SourceEditor|Source Editor instance is required to set up an extension.',
);
export const EDITOR_EXTENSION_DEFINITION_ERROR = s__(
  'SourceEditor|Extension definition should be either a class or a function',
);
export const EDITOR_EXTENSION_NO_DEFINITION_ERROR = s__(
  'SourceEditor|`definition` property is expected on the extension.',
);
export const EDITOR_EXTENSION_DEFINITION_TYPE_ERROR = s__(
  'SourceEditor|Extension definition should be either class, function, or an Array of definitions.',
);
export const EDITOR_EXTENSION_NOT_SPECIFIED_FOR_UNUSE_ERROR = s__(
  'SourceEditor|No extension for unuse has been specified.',
);
export const EDITOR_EXTENSION_NOT_REGISTERED_ERROR = s__('SourceEditor|%{name} is not registered.');
export const EDITOR_EXTENSION_NAMING_CONFLICT_ERROR = s__(
  'SourceEditor|Name conflict for "%{prop}()" method.',
);
export const EDITOR_EXTENSION_STORE_IS_MISSING_ERROR = s__(
  'SourceEditor|Extensions Store is required to check for an extension.',
);

//
// EXTENSIONS' CONSTANTS
//

// Source Editor Base Extension
export const EXTENSION_BASE_LINE_LINK_ANCHOR_CLASS = 'link-anchor';
export const EXTENSION_BASE_LINE_NUMBERS_CLASS = 'line-numbers';

// For CI config schemas the filename must match
// '*.gitlab-ci.yml' regardless of project configuration.
// https://gitlab.com/gitlab-org/gitlab/-/issues/293641
export const EXTENSION_CI_SCHEMA_FILE_NAME_MATCH = '.gitlab-ci.yml';

export const EXTENSION_MARKDOWN_PREVIEW_PANEL_CLASS = 'md';
export const EXTENSION_MARKDOWN_PREVIEW_PANEL_PARENT_CLASS = 'source-editor-preview';
export const EXTENSION_MARKDOWN_PREVIEW_ACTION_ID = 'markdown-preview';
export const EXTENSION_MARKDOWN_PREVIEW_HIDE_ACTION_ID = 'markdown-preview-hide';
export const EXTENSION_MARKDOWN_PREVIEW_PANEL_WIDTH = 0.5; // 50% of the width
export const EXTENSION_MARKDOWN_PREVIEW_UPDATE_DELAY = 250; // ms
export const EXTENSION_MARKDOWN_PREVIEW_LABEL = __('Preview Markdown');
export const EXTENSION_MARKDOWN_HIDE_PREVIEW_LABEL = __('Hide Live Preview');
export const EXTENSION_MARKDOWN_BUTTONS = [
  {
    id: 'bold',
    label: sprintf(s__('MarkdownEditor|Add bold text (%{modifierKey}B)'), {
      modifierKey,
    }),
    data: {
      mdTag: '**',
      mdShortcuts: '["mod+b"]',
    },
  },
  {
    id: 'italic',
    label: sprintf(s__('MarkdownEditor|Add italic text (%{modifierKey}I)'), {
      modifierKey,
    }),
    data: {
      mdTag: '_',
      mdShortcuts: '["mod+i"]',
    },
  },
  {
    id: 'strikethrough',
    label: sprintf(s__('MarkdownEditor|Add strikethrough text (%{modifierKey}⇧X)'), {
      modifierKey,
    }),
    data: {
      mdTag: '~~',
      mdShortcuts: '["mod+shift+x]',
    },
  },
  {
    id: 'quote',
    label: __('Insert a quote'),
    data: {
      mdTag: '> ',
      mdPrepend: true,
    },
  },
  {
    id: 'code',
    label: __('Insert code'),
    data: {
      mdTag: '`',
      mdBlock: '```',
    },
  },
  {
    id: 'link',
    label: sprintf(s__('MarkdownEditor|Add a link (%{modifier_key}K)'), {
      modifierKey,
    }),
    data: {
      mdTag: '[{text}](url)',
      mdSelect: 'url',
      mdShortcuts: '["mod+k"]',
    },
  },
  {
    id: 'list-bulleted',
    label: __('Add a bullet list'),
    data: {
      mdTag: '- ',
      mdPrepend: true,
    },
  },
  {
    id: 'list-numbered',
    label: __('Add a numbered list'),
    data: {
      mdTag: '1. ',
      mdPrepend: true,
    },
  },
  {
    id: 'list-task',
    label: __('Add a checklist'),
    data: {
      mdTag: '- [ ] ',
      mdPrepend: true,
    },
  },
  {
    id: 'details-block',
    label: __('Add a collapsible section'),
    data: {
      mdTag: '<details><summary>Click to expand</summary>\n{text}\n</details>',
      mdPrepend: true,
      mdSelect: __('Click to expand'),
    },
  },
  {
    id: 'table',
    label: __('Add a table'),
    data: {
      /* eslint-disable-next-line @gitlab/require-i18n-strings */
      mdTag: '| header | header |\n| ------ | ------ |\n|        |        |\n|        |        |',
      mdPrepend: true,
    },
  },
];