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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/markdown/toolbar.vue')
-rw-r--r--app/assets/javascripts/vue_shared/components/markdown/toolbar.vue208
1 files changed, 116 insertions, 92 deletions
diff --git a/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue b/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue
index 4733afb7504..d4b1abedc02 100644
--- a/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue
+++ b/app/assets/javascripts/vue_shared/components/markdown/toolbar.vue
@@ -1,24 +1,26 @@
<script>
-import { GlButton, GlLink, GlLoadingIcon, GlSprintf, GlIcon } from '@gitlab/ui';
+import { GlButton, GlLoadingIcon, GlSprintf, GlIcon, GlTooltipDirective } from '@gitlab/ui';
+import { updateText } from '~/lib/utils/text_markdown';
+import { __, sprintf } from '~/locale';
+import { PROMO_URL } from 'jh_else_ce/lib/utils/url_utility';
+import EditorModeSwitcher from './editor_mode_switcher.vue';
export default {
components: {
GlButton,
- GlLink,
GlLoadingIcon,
GlSprintf,
GlIcon,
+ EditorModeSwitcher,
+ },
+ directives: {
+ GlTooltip: GlTooltipDirective,
},
props: {
markdownDocsPath: {
type: String,
required: true,
},
- quickActionsDocsPath: {
- type: String,
- required: false,
- default: '',
- },
canAttachFile: {
type: Boolean,
required: false,
@@ -29,10 +31,46 @@ export default {
required: false,
default: true,
},
+ showContentEditorSwitcher: {
+ type: Boolean,
+ required: false,
+ default: false,
+ },
},
computed: {
- hasQuickActionsDocsPath() {
- return this.quickActionsDocsPath !== '';
+ showEditorModeSwitcher() {
+ return this.showContentEditorSwitcher;
+ },
+ },
+ methods: {
+ insertIntoTextarea(...lines) {
+ const text = lines.join('\n');
+ const textArea = this.$el.closest('.md-area')?.querySelector('textarea');
+ if (textArea && !textArea.value) {
+ updateText({
+ textArea,
+ tag: text,
+ cursorOffset: 0,
+ wrap: false,
+ });
+ }
+ },
+ handleEditorModeChanged(isFirstSwitch) {
+ if (isFirstSwitch) {
+ this.insertIntoTextarea(
+ __(`### Rich text editor`),
+ '',
+ sprintf(
+ __(
+ 'Try out **styling** _your_ content right here or read the [direction](%{directionUrl}).',
+ ),
+ {
+ directionUrl: `${PROMO_URL}/direction/plan/knowledge/content_editor/`,
+ },
+ ),
+ );
+ }
+ this.$emit('enableContentEditor');
},
},
};
@@ -41,94 +79,80 @@ export default {
<template>
<div
v-if="showCommentToolBar"
- class="comment-toolbar gl-mx-2 gl-mb-2 gl-px-4 gl-bg-gray-10 gl-rounded-bottom-left-base gl-rounded-bottom-right-base clearfix"
+ class="comment-toolbar gl-display-flex gl-flex-direction-row gl-px-2 gl-rounded-bottom-left-base gl-rounded-bottom-right-base"
+ :class="
+ showContentEditorSwitcher
+ ? 'gl-justify-content-space-between gl-align-items-center gl-border-t gl-border-gray-100'
+ : 'gl-justify-content-end gl-my-2'
+ "
>
- <div class="toolbar-text gl-font-sm">
- <template v-if="!hasQuickActionsDocsPath && markdownDocsPath">
- <gl-sprintf
- :message="
- s__('MarkdownToolbar|Supports %{markdownDocsLinkStart}Markdown%{markdownDocsLinkEnd}')
- "
- >
- <template #markdownDocsLink="{ content }">
- <gl-link :href="markdownDocsPath" target="_blank" class="gl-font-sm">{{
- content
- }}</gl-link>
- </template>
- </gl-sprintf>
- </template>
- <template v-if="hasQuickActionsDocsPath && markdownDocsPath">
- <gl-sprintf
- :message="
- s__(
- 'NoteToolbar|Supports %{markdownDocsLinkStart}Markdown%{markdownDocsLinkEnd}. For %{quickActionsDocsLinkStart}quick actions%{quickActionsDocsLinkEnd}, type %{keyboardStart}/%{keyboardEnd}.',
- )
- "
- >
- <template #markdownDocsLink="{ content }">
- <gl-link :href="markdownDocsPath" target="_blank" class="gl-font-sm">{{
- content
- }}</gl-link>
- </template>
- <template #keyboard="{ content }">
- <kbd>{{ content }}</kbd>
- </template>
- <template #quickActionsDocsLink="{ content }">
- <gl-link :href="quickActionsDocsPath" target="_blank" class="gl-font-sm">{{
- content
- }}</gl-link>
- </template>
- </gl-sprintf>
- </template>
- </div>
- <span v-if="canAttachFile" class="uploading-container gl-font-sm gl-line-height-32">
- <span class="uploading-progress-container hide">
- <gl-icon name="paperclip" />
- <span class="attaching-file-message"></span>
- <!-- eslint-disable-next-line @gitlab/vue-require-i18n-strings -->
- <span class="uploading-progress">0%</span>
- <gl-loading-icon size="sm" inline />
- </span>
- <span class="uploading-error-container hide">
- <span class="uploading-error-icon">
+ <editor-mode-switcher
+ v-if="showEditorModeSwitcher"
+ size="small"
+ value="markdown"
+ @switch="handleEditorModeChanged"
+ />
+ <div class="gl-display-flex">
+ <div v-if="canAttachFile" class="uploading-container gl-font-sm gl-line-height-32 gl-mr-3">
+ <span class="uploading-progress-container hide">
<gl-icon name="paperclip" />
+ <span class="attaching-file-message"></span>
+ <!-- eslint-disable-next-line @gitlab/vue-require-i18n-strings -->
+ <span class="uploading-progress">0%</span>
+ <gl-loading-icon size="sm" inline />
</span>
- <span class="uploading-error-message"></span>
+ <span class="uploading-error-container hide">
+ <span class="uploading-error-icon">
+ <gl-icon name="paperclip" />
+ </span>
+ <span class="uploading-error-message"></span>
- <gl-sprintf
- :message="
- __(
- '%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}.',
- )
- "
+ <gl-sprintf
+ :message="
+ __(
+ '%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}.',
+ )
+ "
+ >
+ <template #retryButton="{ content }">
+ <gl-button
+ variant="link"
+ category="primary"
+ class="retry-uploading-link gl-vertical-align-baseline gl-font-sm!"
+ >
+ {{ content }}
+ </gl-button>
+ </template>
+ <template #newFileButton="{ content }">
+ <gl-button
+ variant="link"
+ category="primary"
+ class="markdown-selector attach-new-file gl-vertical-align-baseline gl-font-sm!"
+ >
+ {{ content }}
+ </gl-button>
+ </template>
+ </gl-sprintf>
+ </span>
+ <gl-button
+ variant="link"
+ category="primary"
+ class="button-cancel-uploading-files gl-vertical-align-baseline hide gl-font-sm!"
>
- <template #retryButton="{ content }">
- <gl-button
- variant="link"
- category="primary"
- class="retry-uploading-link gl-vertical-align-baseline gl-font-sm!"
- >
- {{ content }}
- </gl-button>
- </template>
- <template #newFileButton="{ content }">
- <gl-button
- variant="link"
- category="primary"
- class="markdown-selector attach-new-file gl-vertical-align-baseline gl-font-sm!"
- >
- {{ content }}
- </gl-button>
- </template>
- </gl-sprintf>
- </span>
+ {{ __('Cancel') }}
+ </gl-button>
+ </div>
<gl-button
- variant="link"
- category="primary"
- class="button-cancel-uploading-files gl-vertical-align-baseline hide gl-font-sm!"
- >
- {{ __('Cancel') }}
- </gl-button>
- </span>
+ v-if="markdownDocsPath"
+ v-gl-tooltip
+ icon="markdown-mark"
+ :href="markdownDocsPath"
+ target="_blank"
+ category="tertiary"
+ size="small"
+ title="Markdown is supported"
+ class="gl-px-3!"
+ />
+ </div>
</div>
</template>