2019-05-28 18:55:02 +02:00
|
|
|
<template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div v-if="editor !== null">
|
2020-02-18 08:57:00 +01:00
|
|
|
<div
|
|
|
|
class="editor"
|
2020-09-29 09:53:48 +02:00
|
|
|
:class="{ short_mode: isShortMode, comment_mode: isCommentMode }"
|
2020-02-18 08:57:00 +01:00
|
|
|
id="tiptab-editor"
|
|
|
|
:data-actor-id="currentActor && currentActor.id"
|
|
|
|
>
|
2021-05-02 19:27:23 +02:00
|
|
|
<div
|
2022-08-26 16:08:58 +02:00
|
|
|
class="mb-2 menubar bar-is-hidden"
|
2021-05-02 19:27:23 +02:00
|
|
|
v-if="isDescriptionMode"
|
|
|
|
:editor="editor"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('bold') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleBold().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Bold')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatBold :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('italic') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleItalic().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Italic')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatItalic :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('underline') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleUnderline().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Underline')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatUnderline :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-11-02 18:09:26 +01:00
|
|
|
:class="{
|
|
|
|
'is-active': editor?.isActive('heading', {
|
|
|
|
level: props.headingLevel[0],
|
|
|
|
}),
|
|
|
|
}"
|
|
|
|
@click="
|
|
|
|
editor
|
|
|
|
?.chain()
|
|
|
|
.focus()
|
|
|
|
.toggleHeading({ level: props.headingLevel[0] })
|
|
|
|
.run()
|
|
|
|
"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Heading Level 1')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatHeader1 :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-11-02 18:09:26 +01:00
|
|
|
:class="{
|
|
|
|
'is-active': editor?.isActive('heading', {
|
|
|
|
level: props.headingLevel[1],
|
|
|
|
}),
|
|
|
|
}"
|
|
|
|
@click="
|
|
|
|
editor
|
|
|
|
?.chain()
|
|
|
|
.focus()
|
|
|
|
.toggleHeading({ level: props.headingLevel[1] })
|
|
|
|
.run()
|
|
|
|
"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Heading Level 2')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatHeader2 :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-11-02 18:09:26 +01:00
|
|
|
:class="{
|
|
|
|
'is-active': editor?.isActive('heading', {
|
|
|
|
level: props.headingLevel[2],
|
|
|
|
}),
|
|
|
|
}"
|
|
|
|
@click="
|
|
|
|
editor
|
|
|
|
?.chain()
|
|
|
|
.focus()
|
|
|
|
.toggleHeading({ level: props.headingLevel[2] })
|
|
|
|
.run()
|
|
|
|
"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Heading Level 3')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatHeader3 :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
@click="showLinkMenu()"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('link') }"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Add link')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<LinkIcon :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2022-10-11 17:47:53 +02:00
|
|
|
v-if="editor?.isActive('link')"
|
2021-05-02 19:27:23 +02:00
|
|
|
class="menubar__button"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().unsetLink().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Remove link')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<LinkOff :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
@click="showImagePrompt()"
|
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Add picture')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<Image :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
v-if="!isBasicMode"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('bulletList') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleBulletList().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Bullet list')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatListBulleted :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('orderedList') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleOrderedList().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Ordered list')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatListNumbered :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-10-11 17:47:53 +02:00
|
|
|
:class="{ 'is-active': editor?.isActive('blockquote') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleBlockquote().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Quote')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatQuoteClose :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().undo().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Undo')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<Undo :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
class="menubar__button"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().redo().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Redo')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<Redo :size="24" />
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
2021-04-30 12:20:31 +02:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-04-30 12:20:31 +02:00
|
|
|
<bubble-menu
|
|
|
|
v-if="editor && isCommentMode"
|
2021-05-02 19:27:23 +02:00
|
|
|
class="bubble-menu"
|
2020-02-18 08:57:00 +01:00
|
|
|
:editor="editor"
|
2021-05-02 19:27:23 +02:00
|
|
|
:tippy-options="{ duration: 100 }"
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
2021-05-02 19:27:23 +02:00
|
|
|
<button
|
|
|
|
class="menububble__button"
|
|
|
|
:class="{ 'is-active': editor.isActive('bold') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleBold().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Bold')"
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatBold :size="24" />
|
|
|
|
<span class="visually-hidden">{{ t("Bold") }}</span>
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menububble__button"
|
|
|
|
:class="{ 'is-active': editor.isActive('italic') }"
|
2022-07-12 10:55:28 +02:00
|
|
|
@click="editor?.chain().focus().toggleItalic().run()"
|
2021-05-02 19:27:23 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
:title="t('Italic')"
|
2021-05-02 19:27:23 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<FormatItalic :size="24" />
|
|
|
|
<span class="visually-hidden">{{ t("Italic") }}</span>
|
2021-05-02 19:27:23 +02:00
|
|
|
</button>
|
2021-04-30 12:20:31 +02:00
|
|
|
</bubble-menu>
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<editor-content class="editor__content" :editor="editor" v-if="editor" />
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-05-28 18:55:02 +02:00
|
|
|
</template>
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2022-10-11 17:47:53 +02:00
|
|
|
import { useEditor, EditorContent, BubbleMenu } from "@tiptap/vue-3";
|
2021-11-25 16:31:09 +01:00
|
|
|
import Blockquote from "@tiptap/extension-blockquote";
|
|
|
|
import BulletList from "@tiptap/extension-bullet-list";
|
2022-11-02 18:09:26 +01:00
|
|
|
import Heading, { Level } from "@tiptap/extension-heading";
|
2021-04-30 12:20:31 +02:00
|
|
|
import Document from "@tiptap/extension-document";
|
|
|
|
import Paragraph from "@tiptap/extension-paragraph";
|
2021-11-25 16:31:09 +01:00
|
|
|
import Bold from "@tiptap/extension-bold";
|
|
|
|
import Italic from "@tiptap/extension-italic";
|
|
|
|
import Strike from "@tiptap/extension-strike";
|
2021-04-30 12:20:31 +02:00
|
|
|
import Text from "@tiptap/extension-text";
|
2021-11-25 16:31:09 +01:00
|
|
|
import Dropcursor from "@tiptap/extension-dropcursor";
|
|
|
|
import Gapcursor from "@tiptap/extension-gapcursor";
|
|
|
|
import History from "@tiptap/extension-history";
|
2021-05-02 20:41:23 +02:00
|
|
|
import { IActor, IPerson, usernameWithDomain } from "../types/actor";
|
2021-04-30 12:20:31 +02:00
|
|
|
import CustomImage from "./Editor/Image";
|
2022-10-25 19:01:26 +02:00
|
|
|
import RichEditorKeyboardSubmit from "./Editor/RichEditorKeyboardSubmit";
|
2020-11-26 11:41:13 +01:00
|
|
|
import { UPLOAD_MEDIA } from "../graphql/upload";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { listenFileUpload } from "../utils/upload";
|
2021-04-30 12:20:31 +02:00
|
|
|
import Mention from "@tiptap/extension-mention";
|
|
|
|
import MentionOptions from "./Editor/Mention";
|
|
|
|
import OrderedList from "@tiptap/extension-ordered-list";
|
|
|
|
import ListItem from "@tiptap/extension-list-item";
|
|
|
|
import Underline from "@tiptap/extension-underline";
|
|
|
|
import Link from "@tiptap/extension-link";
|
2021-11-07 14:59:20 +01:00
|
|
|
import { AutoDir } from "./Editor/Autodir";
|
2022-07-12 10:55:28 +02:00
|
|
|
// import sanitizeHtml from "sanitize-html";
|
2022-10-11 17:56:22 +02:00
|
|
|
import { computed, inject, onBeforeUnmount, watch } from "vue";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { Dialog } from "@/plugins/dialog";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import { useMutation } from "@vue/apollo-composable";
|
|
|
|
import { Notifier } from "@/plugins/notifier";
|
2022-08-26 16:08:58 +02:00
|
|
|
import FormatBold from "vue-material-design-icons/FormatBold.vue";
|
|
|
|
import FormatItalic from "vue-material-design-icons/FormatItalic.vue";
|
|
|
|
import FormatUnderline from "vue-material-design-icons/FormatUnderline.vue";
|
|
|
|
import FormatHeader1 from "vue-material-design-icons/FormatHeader1.vue";
|
|
|
|
import FormatHeader2 from "vue-material-design-icons/FormatHeader2.vue";
|
|
|
|
import FormatHeader3 from "vue-material-design-icons/FormatHeader3.vue";
|
|
|
|
import LinkIcon from "vue-material-design-icons/Link.vue";
|
|
|
|
import LinkOff from "vue-material-design-icons/LinkOff.vue";
|
|
|
|
import Image from "vue-material-design-icons/Image.vue";
|
|
|
|
import FormatListBulleted from "vue-material-design-icons/FormatListBulleted.vue";
|
|
|
|
import FormatListNumbered from "vue-material-design-icons/FormatListNumbered.vue";
|
|
|
|
import FormatQuoteClose from "vue-material-design-icons/FormatQuoteClose.vue";
|
|
|
|
import Undo from "vue-material-design-icons/Undo.vue";
|
|
|
|
import Redo from "vue-material-design-icons/Redo.vue";
|
2022-10-31 13:03:03 +01:00
|
|
|
import Placeholder from "@tiptap/extension-placeholder";
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
modelValue: string;
|
2023-10-17 16:41:31 +02:00
|
|
|
mode?: "description" | "comment" | "basic";
|
2022-07-12 10:55:28 +02:00
|
|
|
maxSize?: number;
|
|
|
|
ariaLabel?: string;
|
|
|
|
currentActor: IPerson;
|
2022-10-31 11:43:18 +01:00
|
|
|
placeholder?: string;
|
2022-11-02 18:09:26 +01:00
|
|
|
headingLevel?: Level[];
|
2022-07-12 10:55:28 +02:00
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
mode: "description",
|
|
|
|
maxSize: 100_000_000,
|
2022-11-02 18:09:26 +01:00
|
|
|
headingLevel: () => [3, 4, 5],
|
2022-07-12 10:55:28 +02:00
|
|
|
}
|
|
|
|
);
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2022-10-25 19:01:26 +02:00
|
|
|
const emit = defineEmits(["update:modelValue", "submit"]);
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isDescriptionMode = computed((): boolean => {
|
|
|
|
return props.mode === "description" || isBasicMode.value;
|
|
|
|
});
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isCommentMode = computed((): boolean => {
|
|
|
|
return props.mode === "comment";
|
|
|
|
});
|
2021-10-10 16:24:12 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isShortMode = computed((): boolean => {
|
|
|
|
return isBasicMode.value;
|
|
|
|
});
|
2019-05-31 17:58:03 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isBasicMode = computed((): boolean => {
|
|
|
|
return props.mode === "basic";
|
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const transformPastedHTML = (html: string): string => {
|
|
|
|
// When using comment mode, limit to acceptable tags
|
|
|
|
if (isCommentMode.value) {
|
|
|
|
// return sanitizeHtml(html, {
|
|
|
|
// allowedTags: ["b", "i", "em", "strong", "a"],
|
|
|
|
// allowedAttributes: {
|
|
|
|
// a: ["href", "rel", "target"],
|
|
|
|
// },
|
|
|
|
// });
|
2021-11-13 15:45:05 +01:00
|
|
|
return html;
|
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return html;
|
|
|
|
};
|
2021-11-13 15:45:05 +01:00
|
|
|
|
2023-08-02 15:09:08 +02:00
|
|
|
const ariaLabel = computed(() => props.ariaLabel);
|
|
|
|
const headingLevel = computed(() => props.headingLevel);
|
|
|
|
const placeholder = computed(() => props.placeholder);
|
|
|
|
const value = computed(() => props.modelValue);
|
|
|
|
|
2022-10-31 11:43:18 +01:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
|
|
|
|
2022-10-11 17:47:53 +02:00
|
|
|
const editor = useEditor({
|
|
|
|
editorProps: {
|
|
|
|
attributes: {
|
|
|
|
"aria-multiline": isShortMode.value.toString(),
|
2023-08-02 15:09:08 +02:00
|
|
|
"aria-label": ariaLabel.value ?? "",
|
2022-10-11 17:47:53 +02:00
|
|
|
role: "textbox",
|
|
|
|
class:
|
2022-10-25 19:01:26 +02:00
|
|
|
"prose dark:prose-invert prose-sm lg:prose-lg xl:prose-xl bg-zinc-50 dark:bg-zinc-700 focus:outline-none !max-w-full",
|
2022-10-11 17:47:53 +02:00
|
|
|
},
|
|
|
|
transformPastedHTML: transformPastedHTML,
|
|
|
|
},
|
|
|
|
extensions: [
|
|
|
|
Blockquote,
|
|
|
|
BulletList,
|
2022-10-31 18:04:30 +01:00
|
|
|
Heading.configure({
|
2023-08-02 15:09:08 +02:00
|
|
|
levels: headingLevel.value,
|
2022-10-31 18:04:30 +01:00
|
|
|
}),
|
2022-10-11 17:47:53 +02:00
|
|
|
Document,
|
|
|
|
Paragraph,
|
|
|
|
Text,
|
|
|
|
OrderedList,
|
|
|
|
ListItem,
|
|
|
|
Mention.configure(MentionOptions),
|
|
|
|
CustomImage,
|
|
|
|
AutoDir,
|
|
|
|
Underline,
|
|
|
|
Bold,
|
|
|
|
Italic,
|
|
|
|
Strike,
|
|
|
|
Dropcursor,
|
|
|
|
Gapcursor,
|
|
|
|
History,
|
|
|
|
Link.configure({
|
|
|
|
HTMLAttributes: { target: "_blank", rel: "noopener noreferrer ugc" },
|
|
|
|
}),
|
2022-10-25 19:01:26 +02:00
|
|
|
RichEditorKeyboardSubmit.configure({
|
|
|
|
submit: () => emit("submit"),
|
|
|
|
}),
|
2022-10-31 11:43:18 +01:00
|
|
|
Placeholder.configure({
|
2023-08-02 15:09:08 +02:00
|
|
|
placeholder: placeholder.value ?? t("Write something"),
|
2022-10-31 13:03:03 +01:00
|
|
|
}),
|
2022-10-11 17:47:53 +02:00
|
|
|
],
|
|
|
|
injectCSS: false,
|
2023-08-02 15:09:08 +02:00
|
|
|
content: value.value,
|
2022-10-11 17:47:53 +02:00
|
|
|
onUpdate: () => {
|
|
|
|
emit("update:modelValue", editor.value?.getHTML());
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
watch(value, (val: string) => {
|
|
|
|
if (!editor.value) return;
|
|
|
|
if (val !== editor.value.getHTML()) {
|
|
|
|
editor.value.commands.setContent(val, false);
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const dialog = inject<Dialog>("dialog");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a popup to get the link from the URL
|
|
|
|
*/
|
|
|
|
const showLinkMenu = (): void => {
|
|
|
|
dialog?.prompt({
|
|
|
|
message: t("Enter the link URL"),
|
2022-10-11 17:47:53 +02:00
|
|
|
hasInput: true,
|
2022-07-12 10:55:28 +02:00
|
|
|
inputAttrs: {
|
|
|
|
type: "url",
|
|
|
|
},
|
|
|
|
onConfirm: (prompt: string) => {
|
|
|
|
if (!editor.value) return;
|
|
|
|
editor.value.chain().focus().setLink({ href: prompt }).run();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const {
|
|
|
|
mutate: uploadMediaMutation,
|
|
|
|
onDone: uploadMediaDone,
|
|
|
|
onError: uploadMediaError,
|
|
|
|
} = useMutation(UPLOAD_MEDIA);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a file prompt, upload picture and insert it into editor
|
|
|
|
*/
|
|
|
|
const showImagePrompt = async (): Promise<void> => {
|
|
|
|
const image = await listenFileUpload();
|
|
|
|
uploadMediaMutation({
|
|
|
|
file: image,
|
|
|
|
name: image.name,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
uploadMediaDone(({ data }) => {
|
|
|
|
if (data.uploadMedia && data.uploadMedia.url && editor.value) {
|
|
|
|
editor.value
|
2021-05-02 20:41:23 +02:00
|
|
|
.chain()
|
|
|
|
.focus()
|
2022-07-12 10:55:28 +02:00
|
|
|
.setImage({
|
|
|
|
src: data.uploadMedia.url,
|
2022-11-04 18:18:49 +01:00
|
|
|
alt: "",
|
2022-07-12 10:55:28 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
"data-media-id": data.uploadMedia.id,
|
2021-05-02 20:41:23 +02:00
|
|
|
})
|
|
|
|
.run();
|
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2021-05-02 20:41:23 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const notifier = inject<Notifier>("notifier");
|
2021-05-02 19:27:23 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
uploadMediaError((error) => {
|
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
|
|
notifier?.error(error.graphQLErrors[0].message);
|
2019-05-28 18:55:02 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We use this to programatically insert an actor mention when creating a reply to comment
|
|
|
|
*/
|
|
|
|
const replyToComment = (actor: IActor): void => {
|
|
|
|
if (!editor.value) return;
|
|
|
|
editor.value
|
|
|
|
.chain()
|
|
|
|
.focus()
|
|
|
|
.insertContent({
|
|
|
|
type: "mention",
|
|
|
|
attrs: {
|
|
|
|
id: usernameWithDomain(actor),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.insertContent(" ")
|
|
|
|
.run();
|
|
|
|
};
|
|
|
|
|
|
|
|
const focus = (): void => {
|
|
|
|
editor.value?.chain().focus("end");
|
|
|
|
};
|
|
|
|
|
|
|
|
defineExpose({ replyToComment, focus });
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
editor.value?.destroy();
|
|
|
|
});
|
2019-05-28 18:55:02 +02:00
|
|
|
</script>
|
|
|
|
<style lang="scss">
|
2021-11-04 18:14:36 +01:00
|
|
|
@use "@/styles/_mixins" as *;
|
2021-05-02 19:27:23 +02:00
|
|
|
@import "./Editor/style.scss";
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.menubar {
|
2023-08-02 15:09:08 +02:00
|
|
|
transition:
|
|
|
|
visibility 0.2s 0.4s,
|
|
|
|
opacity 0.2s 0.4s;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
&__button {
|
|
|
|
font-weight: bold;
|
|
|
|
display: inline-flex;
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
padding: 0.2rem 0.5rem;
|
2022-07-12 10:55:28 +02:00
|
|
|
// @include margin-right(0.2rem);
|
2020-02-18 08:57:00 +01:00
|
|
|
border-radius: 3px;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.editor {
|
|
|
|
position: relative;
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
p.is-empty:first-child::before {
|
|
|
|
content: attr(data-empty-text);
|
|
|
|
float: left;
|
|
|
|
color: #aaa;
|
|
|
|
pointer-events: none;
|
|
|
|
height: 0;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
.editor__content div.ProseMirror {
|
|
|
|
min-height: 10rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.short_mode {
|
|
|
|
div.ProseMirror {
|
|
|
|
min-height: 5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.comment_mode {
|
2020-02-18 08:57:00 +01:00
|
|
|
div.ProseMirror {
|
2020-09-29 09:53:48 +02:00
|
|
|
min-height: 2rem;
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&__content {
|
|
|
|
div.ProseMirror {
|
|
|
|
min-height: 2.5rem;
|
|
|
|
box-shadow: inset 0 1px 2px rgba(10, 10, 10, 0.1);
|
|
|
|
border-radius: 4px;
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
padding: 12px 6px;
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
h1 {
|
|
|
|
font-size: 2em;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
h2 {
|
|
|
|
font-size: 1.5em;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
h3 {
|
|
|
|
font-size: 1.25em;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
// ul,
|
|
|
|
// ol {
|
|
|
|
// @include padding-left(1rem);
|
|
|
|
// }
|
2019-10-10 11:05:53 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
ul {
|
|
|
|
list-style-type: disc;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
li > p,
|
|
|
|
li > ol,
|
|
|
|
li > ul {
|
|
|
|
margin: 0;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
blockquote {
|
2022-07-12 10:55:28 +02:00
|
|
|
// @include padding-left(0.8rem);
|
2020-02-18 08:57:00 +01:00
|
|
|
font-style: italic;
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
p {
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
img {
|
|
|
|
max-width: 100%;
|
|
|
|
border-radius: 3px;
|
2019-05-28 18:55:02 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2021-05-02 19:27:23 +02:00
|
|
|
.bubble-menu {
|
2020-02-18 08:57:00 +01:00
|
|
|
display: flex;
|
2021-05-02 19:27:23 +02:00
|
|
|
background-color: #0d0d0d;
|
|
|
|
padding: 0.2rem;
|
|
|
|
border-radius: 0.5rem;
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2021-05-02 19:27:23 +02:00
|
|
|
button {
|
|
|
|
border: none;
|
|
|
|
background: none;
|
|
|
|
color: #fff;
|
|
|
|
font-size: 0.85rem;
|
|
|
|
font-weight: 500;
|
|
|
|
padding: 0 0.2rem;
|
|
|
|
opacity: 0.6;
|
2020-02-18 08:57:00 +01:00
|
|
|
cursor: pointer;
|
|
|
|
|
2021-05-02 19:27:23 +02:00
|
|
|
&:hover,
|
2020-02-18 08:57:00 +01:00
|
|
|
&.is-active {
|
2021-05-02 19:27:23 +02:00
|
|
|
opacity: 1;
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 16:20:58 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.suggestion-list {
|
|
|
|
padding: 0.2rem;
|
|
|
|
font-size: 0.8rem;
|
|
|
|
font-weight: bold;
|
|
|
|
&__no-results {
|
|
|
|
padding: 0.2rem 0.5rem;
|
|
|
|
}
|
|
|
|
&__item {
|
|
|
|
border-radius: 5px;
|
|
|
|
padding: 0.2rem 0.5rem;
|
|
|
|
margin-bottom: 0.2rem;
|
|
|
|
cursor: pointer;
|
|
|
|
&:last-child {
|
|
|
|
margin-bottom: 0;
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
&.is-empty {
|
|
|
|
opacity: 0.5;
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2020-06-19 19:27:10 +02:00
|
|
|
|
|
|
|
.media + .media {
|
|
|
|
margin-top: 0;
|
|
|
|
padding-top: 0;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2020-06-19 19:27:10 +02:00
|
|
|
.tippy-box[data-theme~="dark"] {
|
2020-02-18 08:57:00 +01:00
|
|
|
padding: 0;
|
|
|
|
font-size: 1rem;
|
|
|
|
text-align: inherit;
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.visually-hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
2022-10-31 11:43:18 +01:00
|
|
|
|
|
|
|
.ProseMirror p.is-editor-empty:first-child::before {
|
|
|
|
content: attr(data-placeholder);
|
|
|
|
float: left;
|
|
|
|
color: #adb5bd;
|
|
|
|
pointer-events: none;
|
|
|
|
height: 0;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
</style>
|
2022-11-02 18:15:19 +01:00
|
|
|
<style>
|
|
|
|
.menubar__button {
|
|
|
|
@apply mx-0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
.menubar__button.is-active {
|
|
|
|
@apply bg-zinc-300 dark:bg-zinc-500;
|
|
|
|
}
|
2023-09-05 19:28:36 +02:00
|
|
|
|
|
|
|
.mention[data-id] {
|
|
|
|
@apply inline-block border border-zinc-600 dark:border-zinc-300 rounded py-0.5 px-1;
|
|
|
|
}
|
2022-11-02 18:15:19 +01:00
|
|
|
</style>
|