2019-05-28 18:55:02 +02:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<div v-if="editor">
|
|
|
|
<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"
|
|
|
|
>
|
|
|
|
<editor-menu-bar
|
|
|
|
v-if="isDescriptionMode"
|
|
|
|
:editor="editor"
|
|
|
|
v-slot="{ commands, isActive, focused }"
|
|
|
|
>
|
|
|
|
<div class="menubar bar-is-hidden" :class="{ 'is-focused': focused }">
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.bold() }"
|
|
|
|
@click="commands.bold"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-bold" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.italic() }"
|
|
|
|
@click="commands.italic"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-italic" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.underline() }"
|
|
|
|
@click="commands.underline"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-underline" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.heading({ level: 1 }) }"
|
|
|
|
@click="commands.heading({ level: 1 })"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-header-1" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.heading({ level: 2 }) }"
|
|
|
|
@click="commands.heading({ level: 2 })"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-header-2" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.heading({ level: 3 }) }"
|
|
|
|
@click="commands.heading({ level: 3 })"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-header-3" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
@click="showLinkMenu(commands.link, isActive.link())"
|
|
|
|
:class="{ 'is-active': isActive.link() }"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="link" />
|
|
|
|
</button>
|
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
<button
|
|
|
|
class="menubar__button"
|
|
|
|
v-if="!isBasicMode"
|
|
|
|
@click="showImagePrompt(commands.image)"
|
|
|
|
type="button"
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-icon icon="image" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menubar__button"
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
:class="{ 'is-active': isActive.bullet_list() }"
|
|
|
|
@click="commands.bullet_list"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-list-bulleted" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.ordered_list() }"
|
|
|
|
@click="commands.ordered_list"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-list-numbered" />
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2020-09-02 17:42:17 +02:00
|
|
|
v-if="!isBasicMode"
|
2020-02-18 08:57:00 +01:00
|
|
|
class="menubar__button"
|
|
|
|
:class="{ 'is-active': isActive.blockquote() }"
|
|
|
|
@click="commands.blockquote"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-quote-close" />
|
|
|
|
</button>
|
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
<button v-if="!isBasicMode" class="menubar__button" @click="commands.undo" type="button">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-icon icon="undo" />
|
|
|
|
</button>
|
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
<button v-if="!isBasicMode" class="menubar__button" @click="commands.redo" type="button">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-icon icon="redo" />
|
|
|
|
</button>
|
2019-10-10 10:25:33 +02:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</editor-menu-bar>
|
|
|
|
|
|
|
|
<editor-menu-bubble
|
|
|
|
v-if="isCommentMode"
|
|
|
|
:editor="editor"
|
|
|
|
:keep-in-bounds="true"
|
|
|
|
v-slot="{ commands, isActive, menu }"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="menububble"
|
|
|
|
:class="{ 'is-active': menu.isActive }"
|
|
|
|
:style="`left: ${menu.left}px; bottom: ${menu.bottom}px;`"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="menububble__button"
|
|
|
|
:class="{ 'is-active': isActive.bold() }"
|
|
|
|
@click="commands.bold"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-bold" />
|
|
|
|
<span class="visually-hidden">{{ $t("Bold") }}</span>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="menububble__button"
|
|
|
|
:class="{ 'is-active': isActive.italic() }"
|
|
|
|
@click="commands.italic"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
<b-icon icon="format-italic" />
|
|
|
|
<span class="visually-hidden">{{ $t("Italic") }}</span>
|
|
|
|
</button>
|
2019-05-29 16:46:23 +02:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</editor-menu-bubble>
|
|
|
|
|
|
|
|
<editor-content class="editor__content" :editor="editor" />
|
|
|
|
</div>
|
|
|
|
<div class="suggestion-list" v-show="showSuggestions" ref="suggestions">
|
|
|
|
<template v-if="hasResults">
|
|
|
|
<div
|
|
|
|
v-for="(actor, index) in filteredActors"
|
|
|
|
:key="actor.id"
|
2020-06-19 19:27:10 +02:00
|
|
|
class="media suggestion-list__item"
|
2020-02-18 08:57:00 +01:00
|
|
|
:class="{ 'is-selected': navigatedActorIndex === index }"
|
|
|
|
@click="selectActor(actor)"
|
|
|
|
>
|
2020-06-19 19:27:10 +02:00
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-16x16" v-if="actor.avatar">
|
|
|
|
<img :src="actor.avatar.url" alt="" />
|
|
|
|
</figure>
|
|
|
|
</div>
|
|
|
|
<div class="media-content">
|
|
|
|
{{ actor.name }}
|
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
2020-06-19 19:27:10 +02:00
|
|
|
<div v-else class="suggestion-list__item is-empty">{{ $t("No profiles found") }}</div>
|
2019-05-29 16:46:23 +02:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
2019-05-28 18:55:02 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
|
|
|
import { Editor, EditorContent, EditorMenuBar, EditorMenuBubble } from "tiptap";
|
2019-05-28 18:55:02 +02:00
|
|
|
import {
|
2020-02-18 08:57:00 +01:00
|
|
|
Blockquote,
|
|
|
|
HardBreak,
|
|
|
|
Heading,
|
|
|
|
OrderedList,
|
|
|
|
BulletList,
|
|
|
|
ListItem,
|
|
|
|
TodoItem,
|
|
|
|
TodoList,
|
|
|
|
Bold,
|
|
|
|
Code,
|
|
|
|
Italic,
|
|
|
|
Link,
|
|
|
|
Underline,
|
|
|
|
History,
|
|
|
|
Placeholder,
|
|
|
|
Mention,
|
|
|
|
} from "tiptap-extensions";
|
2020-06-19 19:27:10 +02:00
|
|
|
import tippy, { Instance, sticky } from "tippy.js";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { SEARCH_PERSONS } from "../graphql/search";
|
|
|
|
import { Actor, IActor, IPerson } from "../types/actor";
|
|
|
|
import Image from "./Editor/Image";
|
2020-09-29 09:53:48 +02:00
|
|
|
import MaxSize from "./Editor/MaxSize";
|
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";
|
|
|
|
import { CURRENT_ACTOR_CLIENT } from "../graphql/actor";
|
|
|
|
import { IComment } from "../types/comment.model";
|
2019-05-28 18:55:02 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: { EditorContent, EditorMenuBar, EditorMenuBubble },
|
2019-05-31 17:58:03 +02:00
|
|
|
apollo: {
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
2019-05-31 17:58:03 +02:00
|
|
|
},
|
|
|
|
},
|
2019-05-28 18:55:02 +02:00
|
|
|
})
|
2019-10-10 10:25:33 +02:00
|
|
|
export default class EditorComponent extends Vue {
|
|
|
|
@Prop({ required: true }) value!: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Prop({ required: false, default: "description" }) mode!: string;
|
2019-05-31 17:58:03 +02:00
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
@Prop({ required: false, default: 100_000_000 }) maxSize!: number;
|
|
|
|
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor!: IPerson;
|
2019-05-31 17:58:03 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
editor: Editor | null = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Editor Suggestions
|
|
|
|
*/
|
|
|
|
query!: string | null;
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2019-05-29 16:46:23 +02:00
|
|
|
filteredActors: IActor[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
suggestionRange!: Record<string, unknown> | null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
navigatedActorIndex = 0;
|
|
|
|
|
2020-06-19 19:27:10 +02:00
|
|
|
popup!: Instance[] | null;
|
2019-05-29 16:46:23 +02:00
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
get isDescriptionMode(): boolean {
|
|
|
|
return this.mode === "description" || this.isBasicMode;
|
2019-11-15 18:36:47 +01:00
|
|
|
}
|
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
get isCommentMode(): boolean {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.mode === "comment";
|
2019-11-15 18:36:47 +01:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
get isShortMode(): boolean {
|
|
|
|
return this.isBasicMode;
|
|
|
|
}
|
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
get hasResults(): boolean {
|
|
|
|
return this.filteredActors.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showSuggestions(): boolean {
|
|
|
|
return (this.query || this.hasResults) as boolean;
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
get isBasicMode(): boolean {
|
|
|
|
return this.mode === "basic";
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
// eslint-disable-next-line
|
|
|
|
insertMention(obj: { range: any; attrs: any }) {
|
|
|
|
console.log("initialize Mention");
|
|
|
|
}
|
2019-05-29 16:46:23 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
observer!: MutationObserver | null;
|
2019-05-29 16:46:23 +02:00
|
|
|
|
2020-09-02 17:42:17 +02:00
|
|
|
mounted(): void {
|
2019-05-28 18:55:02 +02:00
|
|
|
this.editor = new Editor({
|
|
|
|
extensions: [
|
|
|
|
new Blockquote(),
|
|
|
|
new BulletList(),
|
|
|
|
new HardBreak(),
|
|
|
|
new Heading({ levels: [1, 2, 3] }),
|
2019-05-29 16:46:23 +02:00
|
|
|
new Mention({
|
|
|
|
items: () => [],
|
2020-02-18 08:57:00 +01:00
|
|
|
onEnter: ({
|
|
|
|
items,
|
|
|
|
query,
|
|
|
|
range,
|
|
|
|
command,
|
|
|
|
virtualNode,
|
|
|
|
}: {
|
|
|
|
items: any;
|
|
|
|
query: any;
|
|
|
|
range: any;
|
|
|
|
command: any;
|
|
|
|
virtualNode: any;
|
|
|
|
}) => {
|
2019-05-29 16:46:23 +02:00
|
|
|
this.query = query;
|
|
|
|
this.filteredActors = items;
|
|
|
|
this.suggestionRange = range;
|
|
|
|
this.renderPopup(virtualNode);
|
2020-02-18 08:57:00 +01:00
|
|
|
// we save the command for inserting a selected mention
|
|
|
|
// this allows us to call it inside of our custom popup
|
|
|
|
// via keyboard navigation and on click
|
2019-05-29 16:46:23 +02:00
|
|
|
this.insertMention = command;
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
/**
|
|
|
|
* is called when a suggestion has changed
|
|
|
|
*/
|
|
|
|
onChange: ({
|
|
|
|
items,
|
|
|
|
query,
|
|
|
|
range,
|
|
|
|
virtualNode,
|
|
|
|
}: {
|
|
|
|
items: any;
|
|
|
|
query: any;
|
|
|
|
range: any;
|
|
|
|
virtualNode: any;
|
|
|
|
}) => {
|
2019-05-29 16:46:23 +02:00
|
|
|
this.query = query;
|
|
|
|
this.filteredActors = items;
|
|
|
|
this.suggestionRange = range;
|
2019-11-15 18:36:47 +01:00
|
|
|
this.navigatedActorIndex = 0;
|
2019-05-29 16:46:23 +02:00
|
|
|
this.renderPopup(virtualNode);
|
|
|
|
},
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
/**
|
|
|
|
* is called when a suggestion is cancelled
|
|
|
|
*/
|
2019-05-29 16:46:23 +02:00
|
|
|
onExit: () => {
|
2020-02-18 08:57:00 +01:00
|
|
|
// reset all saved values
|
2019-05-29 16:46:23 +02:00
|
|
|
this.query = null;
|
|
|
|
this.filteredActors = [];
|
|
|
|
this.suggestionRange = null;
|
2019-11-15 18:36:47 +01:00
|
|
|
this.navigatedActorIndex = 0;
|
2019-05-29 16:46:23 +02:00
|
|
|
this.destroyPopup();
|
|
|
|
},
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
/**
|
|
|
|
* is called on every keyDown event while a suggestion is active
|
|
|
|
*/
|
|
|
|
onKeyDown: ({ event }: { event: KeyboardEvent }) => {
|
2020-06-19 19:27:10 +02:00
|
|
|
if (event.key === "ArrowUp") {
|
2019-05-29 16:46:23 +02:00
|
|
|
this.upHandler();
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-19 19:27:10 +02:00
|
|
|
if (event.key === "ArrowDown") {
|
2019-05-29 16:46:23 +02:00
|
|
|
this.downHandler();
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-19 19:27:10 +02:00
|
|
|
if (event.key === "Enter") {
|
2019-05-29 16:46:23 +02:00
|
|
|
this.enterHandler();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
onFilter: async (items: any, query: string) => {
|
2019-05-29 16:46:23 +02:00
|
|
|
if (!query) {
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
const result = await this.$apollo.query({
|
|
|
|
query: SEARCH_PERSONS,
|
|
|
|
variables: {
|
|
|
|
searchText: query,
|
|
|
|
},
|
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
// TODO: TipTap doesn't handle async for onFilter, hence the following line.
|
2019-05-29 16:46:23 +02:00
|
|
|
this.filteredActors = result.data.searchPersons.elements;
|
|
|
|
return this.filteredActors;
|
|
|
|
},
|
|
|
|
}),
|
2019-05-28 18:55:02 +02:00
|
|
|
new ListItem(),
|
|
|
|
new OrderedList(),
|
|
|
|
new TodoItem(),
|
|
|
|
new TodoList(),
|
|
|
|
new Link(),
|
|
|
|
new Bold(),
|
|
|
|
new Code(),
|
|
|
|
new Italic(),
|
|
|
|
new Underline(),
|
|
|
|
new History(),
|
|
|
|
new Placeholder({
|
2020-02-18 08:57:00 +01:00
|
|
|
emptyEditorClass: "is-empty",
|
|
|
|
emptyNodeText: this.$t("Write something…") as string,
|
2019-05-29 16:46:23 +02:00
|
|
|
showOnlyWhenEditable: false,
|
|
|
|
}),
|
|
|
|
new Image(),
|
2020-09-29 09:53:48 +02:00
|
|
|
new MaxSize({ maxSize: this.maxSize }),
|
2019-05-28 18:55:02 +02:00
|
|
|
],
|
2020-11-26 11:41:13 +01:00
|
|
|
onUpdate: ({
|
|
|
|
getHTML,
|
|
|
|
transaction,
|
|
|
|
getJSON,
|
|
|
|
}: {
|
|
|
|
getHTML: Function;
|
|
|
|
getJSON: Function;
|
|
|
|
transaction: unknown;
|
|
|
|
}) => {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$emit("input", getHTML());
|
2019-05-28 18:55:02 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
this.editor.setContent(this.value);
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("value")
|
2020-09-29 09:53:48 +02:00
|
|
|
onValueChanged(val: string): void {
|
2019-10-10 10:25:33 +02:00
|
|
|
if (!this.editor) return;
|
2019-05-28 18:55:02 +02:00
|
|
|
if (val !== this.editor.getHTML()) {
|
|
|
|
this.editor.setContent(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
showLinkMenu(command: Function, active: boolean): Function | undefined {
|
|
|
|
if (!this.editor) return undefined;
|
2019-10-10 10:25:33 +02:00
|
|
|
if (active) return command({ href: null });
|
|
|
|
this.$buefy.dialog.prompt({
|
2020-02-18 08:57:00 +01:00
|
|
|
message: this.$t("Enter the link URL") as string,
|
2019-10-10 10:25:33 +02:00
|
|
|
inputAttrs: {
|
2020-02-18 08:57:00 +01:00
|
|
|
type: "url",
|
2019-10-10 10:25:33 +02:00
|
|
|
},
|
|
|
|
trapFocus: true,
|
|
|
|
onConfirm: (value) => {
|
|
|
|
command({ href: value });
|
|
|
|
if (!this.editor) return;
|
|
|
|
this.editor.focus();
|
|
|
|
},
|
2019-05-28 18:55:02 +02:00
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
return undefined;
|
2019-05-28 18:55:02 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
upHandler(): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.navigatedActorIndex =
|
|
|
|
(this.navigatedActorIndex + this.filteredActors.length - 1) % this.filteredActors.length;
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* navigate to the next item
|
|
|
|
* if it's the last item, navigate to the first one
|
|
|
|
*/
|
2020-09-29 09:53:48 +02:00
|
|
|
downHandler(): void {
|
2019-11-15 18:36:47 +01:00
|
|
|
this.navigatedActorIndex = (this.navigatedActorIndex + 1) % this.filteredActors.length;
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
enterHandler(): void {
|
2019-11-15 18:36:47 +01:00
|
|
|
const actor = this.filteredActors[this.navigatedActorIndex];
|
2019-05-29 16:46:23 +02:00
|
|
|
if (actor) {
|
|
|
|
this.selectActor(actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* we have to replace our suggestion text with a mention
|
|
|
|
* so it's important to pass also the position of your suggestion text
|
|
|
|
* @param actor IActor
|
|
|
|
*/
|
2020-09-29 09:53:48 +02:00
|
|
|
selectActor(actor: IActor): void {
|
2019-11-15 18:36:47 +01:00
|
|
|
const actorModel = new Actor(actor);
|
2019-05-29 16:46:23 +02:00
|
|
|
this.insertMention({
|
|
|
|
range: this.suggestionRange,
|
|
|
|
attrs: {
|
2019-11-15 18:36:47 +01:00
|
|
|
id: actorModel.id,
|
2020-02-18 08:57:00 +01:00
|
|
|
// usernameWithDomain returns with a @ prefix and tiptap adds one itself
|
|
|
|
label: actorModel.usernameWithDomain().substring(1),
|
2019-05-29 16:46:23 +02:00
|
|
|
},
|
|
|
|
});
|
2019-10-10 10:25:33 +02:00
|
|
|
if (!this.editor) return;
|
2019-05-29 16:46:23 +02:00
|
|
|
this.editor.focus();
|
|
|
|
}
|
|
|
|
|
2020-06-19 19:27:10 +02:00
|
|
|
/** We use this to programatically insert an actor mention when creating a reply to comment */
|
2020-09-29 09:53:48 +02:00
|
|
|
replyToComment(comment: IComment): void {
|
2020-08-14 11:32:23 +02:00
|
|
|
if (!comment.actor) return;
|
2019-11-15 18:36:47 +01:00
|
|
|
const actorModel = new Actor(comment.actor);
|
|
|
|
if (!this.editor) return;
|
2020-02-18 08:57:00 +01:00
|
|
|
this.editor.commands.mention({
|
|
|
|
id: actorModel.id,
|
|
|
|
label: actorModel.usernameWithDomain().substring(1),
|
|
|
|
});
|
2019-11-15 18:36:47 +01:00
|
|
|
this.editor.focus();
|
|
|
|
}
|
|
|
|
|
2019-05-29 16:46:23 +02:00
|
|
|
/**
|
|
|
|
* renders a popup with suggestions
|
|
|
|
* tiptap provides a virtualNode object for using popper.js (or tippy.js) for popups
|
|
|
|
* @param node
|
|
|
|
*/
|
2020-09-29 09:53:48 +02:00
|
|
|
renderPopup(node: Element): void {
|
2019-05-29 16:46:23 +02:00
|
|
|
if (this.popup) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-19 19:27:10 +02:00
|
|
|
this.popup = tippy("#mobilizon", {
|
2020-09-29 09:53:48 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2020-06-19 19:27:10 +02:00
|
|
|
// @ts-ignore
|
|
|
|
getReferenceClientRect: node.getBoundingClientRect,
|
|
|
|
appendTo: () => document.body,
|
2019-05-29 16:46:23 +02:00
|
|
|
content: this.$refs.suggestions as HTMLElement,
|
2020-02-18 08:57:00 +01:00
|
|
|
trigger: "mouseenter",
|
2019-05-29 16:46:23 +02:00
|
|
|
interactive: true,
|
2020-06-19 19:27:10 +02:00
|
|
|
sticky: true, // make sure position of tippy is updated when content changes
|
|
|
|
plugins: [sticky],
|
|
|
|
showOnCreate: true,
|
2020-02-18 08:57:00 +01:00
|
|
|
theme: "dark",
|
|
|
|
placement: "top-start",
|
2019-05-29 16:46:23 +02:00
|
|
|
inertia: true,
|
|
|
|
duration: [400, 200],
|
2020-06-19 19:27:10 +02:00
|
|
|
}) as Instance[];
|
2019-05-29 16:46:23 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
destroyPopup(): void {
|
2019-05-29 16:46:23 +02:00
|
|
|
if (this.popup) {
|
2020-09-29 09:53:48 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2020-06-19 19:27:10 +02:00
|
|
|
// @ts-ignore
|
|
|
|
this.popup[0].destroy();
|
2019-05-29 16:46:23 +02:00
|
|
|
this.popup = null;
|
|
|
|
}
|
|
|
|
if (this.observer) {
|
|
|
|
this.observer.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 11:01:52 +02:00
|
|
|
/**
|
|
|
|
* Show a file prompt, upload picture and insert it into editor
|
|
|
|
* @param command
|
|
|
|
*/
|
2020-09-29 09:53:48 +02:00
|
|
|
async showImagePrompt(command: Function): Promise<void> {
|
2019-05-31 11:01:52 +02:00
|
|
|
const image = await listenFileUpload();
|
2020-10-09 19:29:12 +02:00
|
|
|
try {
|
|
|
|
const { data } = await this.$apollo.mutate({
|
2020-11-26 11:41:13 +01:00
|
|
|
mutation: UPLOAD_MEDIA,
|
2020-10-09 19:29:12 +02:00
|
|
|
variables: {
|
|
|
|
file: image,
|
|
|
|
name: image.name,
|
|
|
|
},
|
|
|
|
});
|
2020-11-26 11:41:13 +01:00
|
|
|
if (data.uploadMedia && data.uploadMedia.url) {
|
|
|
|
command({ src: data.uploadMedia.url, "data-media-id": data.uploadMedia.id });
|
2020-10-09 19:29:12 +02:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
|
|
this.$notifier.error(error.graphQLErrors[0].message);
|
|
|
|
}
|
2019-05-31 11:01:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
beforeDestroy(): void {
|
2019-10-10 10:25:33 +02:00
|
|
|
if (!this.editor) return;
|
2020-06-19 19:27:10 +02:00
|
|
|
this.destroyPopup();
|
2019-05-28 18:55:02 +02:00
|
|
|
this.editor.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
$color-black: #000;
|
|
|
|
$color-white: #eee;
|
|
|
|
|
|
|
|
.menubar {
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
transition: visibility 0.2s 0.4s, opacity 0.2s 0.4s;
|
|
|
|
|
|
|
|
&__button {
|
|
|
|
font-weight: bold;
|
|
|
|
display: inline-flex;
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
color: $color-black;
|
|
|
|
padding: 0.2rem 0.5rem;
|
|
|
|
margin-right: 0.2rem;
|
|
|
|
border-radius: 3px;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: rgba($color-black, 0.05);
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&.is-active {
|
|
|
|
background-color: rgba($color-black, 0.1);
|
2019-05-28 18:55:02 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
background-color: white;
|
|
|
|
border-radius: 4px;
|
|
|
|
color: #363636;
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
padding: 12px 6px;
|
|
|
|
|
|
|
|
&:focus {
|
2020-06-17 15:54:24 +02:00
|
|
|
border-color: $background-color;
|
2020-02-18 08:57:00 +01:00
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
word-wrap: break-word;
|
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
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
* {
|
|
|
|
caret-color: currentColor;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
ul,
|
|
|
|
ol {
|
|
|
|
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 {
|
|
|
|
border-left: 3px solid rgba($color-black, 0.1);
|
|
|
|
color: rgba($color-black, 0.8);
|
|
|
|
padding-left: 0.8rem;
|
|
|
|
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
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.menububble {
|
|
|
|
position: absolute;
|
|
|
|
display: flex;
|
|
|
|
z-index: 20;
|
|
|
|
background: $color-black;
|
|
|
|
border-radius: 5px;
|
|
|
|
padding: 0.3rem;
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
transform: translateX(-50%);
|
|
|
|
visibility: hidden;
|
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 0.2s, visibility 0.2s;
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
opacity: 1;
|
|
|
|
visibility: visible;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&__button {
|
|
|
|
display: inline-flex;
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
color: $color-white;
|
|
|
|
padding: 0.2rem 0.5rem;
|
|
|
|
margin-right: 0.2rem;
|
|
|
|
border-radius: 3px;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&:hover {
|
|
|
|
background-color: rgba($color-white, 0.1);
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&.is-active {
|
|
|
|
background-color: rgba($color-white, 0.2);
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&__form {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&__input {
|
|
|
|
font: inherit;
|
|
|
|
border: none;
|
|
|
|
background: transparent;
|
|
|
|
color: $color-white;
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 16:20:58 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.suggestion-list {
|
|
|
|
padding: 0.2rem;
|
|
|
|
border: 2px solid rgba($color-black, 0.1);
|
|
|
|
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-selected,
|
|
|
|
&:hover {
|
|
|
|
background-color: rgba($color-white, 0.2);
|
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
|
|
|
background-color: $color-black;
|
|
|
|
padding: 0;
|
|
|
|
font-size: 1rem;
|
|
|
|
text-align: inherit;
|
|
|
|
color: $color-white;
|
|
|
|
border-radius: 5px;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.visually-hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
2019-05-28 18:55:02 +02:00
|
|
|
</style>
|