|
1 | 1 | <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
2 | 2 | <template>
|
3 | 3 | <div class="card-style flex w-full flex-col px-3 py-4 md:flex-row">
|
4 |
| - <div class="flex-col space-y-3 pt-3 md:grow md:space-y-4 md:pl-2 md:pt-0"> |
| 4 | + <div class="w-full flex-col space-y-3 pt-3 md:space-y-4 md:p-2 md:pt-0"> |
5 | 5 | <div class="flex flex-col justify-between md:flex-row">
|
6 | 6 | <div class="flex items-center justify-center space-x-2 md:space-x-4">
|
7 | 7 | <div class="w-min md:w-min">
|
|
24 | 24 | </div>
|
25 | 25 | </div>
|
26 | 26 | <div
|
27 |
| - class="mt-2 flex w-full items-center space-x-1 md:w-fit md:flex-row lg:space-x-3" |
| 27 | + class="mt-2 flex w-full items-center justify-center space-x-1 pt-3 md:w-fit md:flex-row md:pt-0 lg:space-x-3" |
28 | 28 | >
|
29 | 29 | <Icon
|
30 | 30 | @click="at()"
|
|
82 | 82 | />
|
83 | 83 | </div>
|
84 | 84 | </div>
|
85 |
| - <div v-if="discussionInput.highRisk" class="w-full md:w-full"> |
86 |
| - <textarea |
87 |
| - id="message" |
88 |
| - rows="4" |
89 |
| - class="focus-brand block w-full rounded-lg border border-action-red bg-layer-0 p-2.5 text-sm placeholder-action-red focus:border-none dark:border-action-red dark:text-primary-text dark:placeholder-action-red" |
90 |
| - :placeholder=" |
91 |
| - $t('i18n.components.card_discussion_input.leave_comment_high_risk') |
92 |
| - " |
93 |
| - ></textarea> |
94 |
| - </div> |
95 |
| - <div v-else class="w-full md:w-full"> |
96 |
| - <textarea |
97 |
| - id="message" |
98 |
| - rows="4" |
99 |
| - class="focus-brand block w-full rounded-lg border border-section-div bg-layer-0 p-2.5 text-sm text-primary-text placeholder-distinct-text" |
100 |
| - :placeholder=" |
101 |
| - $t('i18n.components.card_discussion_input.leave_comment') |
102 |
| - " |
103 |
| - ></textarea> |
| 85 | + <div class="w-full md:w-full"> |
| 86 | + <editor-content :editor="editor" /> |
104 | 87 | </div>
|
105 | 88 | <div class="flex items-center justify-between px-1">
|
106 | 89 | <p class="inline-flex items-center">
|
|
147 | 130 | <script setup lang="ts">
|
148 | 131 | import type { DiscussionInput } from "~/types/content/discussion";
|
149 | 132 | import { IconMap } from "~/types/icon-map";
|
| 133 | +import { useEditor, EditorContent } from "@tiptap/vue-3"; |
| 134 | +import Placeholder from "@tiptap/extension-placeholder"; |
| 135 | +import StarterKit from "@tiptap/starter-kit"; |
| 136 | +import Link from "@tiptap/extension-link"; |
| 137 | +import Mention from "@tiptap/extension-mention"; |
| 138 | +import Suggestion from "./Suggestion"; |
150 | 139 |
|
151 | 140 | const showTooltip = ref(false);
|
152 |
| - |
153 |
| -defineProps<{ |
| 141 | +const props = defineProps<{ |
154 | 142 | discussionInput: DiscussionInput;
|
155 | 143 | }>();
|
| 144 | +const i18n = useI18n(); |
| 145 | + |
| 146 | +const editor = useEditor({ |
| 147 | + extensions: [ |
| 148 | + StarterKit, |
| 149 | + Placeholder.configure({ |
| 150 | + placeholder: props.discussionInput.highRisk |
| 151 | + ? i18n.t( |
| 152 | + "i18n.components.card_discussion_input.leave_comment_high_risk" |
| 153 | + ) |
| 154 | + : i18n.t("i18n.components.card_discussion_input.leave_comment"), |
| 155 | + }), |
| 156 | + Link, |
| 157 | + Mention.configure({ |
| 158 | + HTMLAttributes: { |
| 159 | + class: |
| 160 | + "hover:underline font-bold rounded-2xl box-decoration-clone px-1 py-0.5", |
| 161 | + }, |
| 162 | + suggestion: Suggestion, |
| 163 | + }), |
| 164 | + ], |
| 165 | + editorProps: { |
| 166 | + attributes: { |
| 167 | + class: |
| 168 | + "focus-brand block w-full max-w-full rounded-lg border border-section-div bg-layer-0 p-2.5 text-sm text-primary-text placeholder-distinct-text prose dark:prose-invert text-clip", |
| 169 | + }, |
| 170 | + }, |
| 171 | +}); |
156 | 172 |
|
157 | 173 | const at = () => {
|
158 | 174 | console.log("click on at");
|
| 175 | + editor.value?.chain().focus().insertContent(" @").run(); |
159 | 176 | };
|
160 | 177 | const heading = () => {
|
161 | 178 | console.log("click on heading");
|
| 179 | + editor.value?.chain().focus().toggleHeading({ level: 1 }).run(); |
162 | 180 | };
|
163 | 181 | const bold = () => {
|
164 | 182 | console.log("click on bold");
|
| 183 | + editor.value?.chain().focus().toggleBold().run(); |
165 | 184 | };
|
166 | 185 | const italic = () => {
|
167 | 186 | console.log("click on italic");
|
| 187 | + editor.value?.chain().focus().toggleItalic().run(); |
168 | 188 | };
|
169 | 189 | const blockquote = () => {
|
170 | 190 | console.log("click on blockquote");
|
| 191 | + editor.value?.chain().focus().toggleCodeBlock().run(); |
171 | 192 | };
|
172 | 193 | const link = () => {
|
173 | 194 | console.log("click on link");
|
| 195 | + const previousUrl = editor.value?.getAttributes("link").href; |
| 196 | + const url = window.prompt("URL", previousUrl); |
| 197 | + |
| 198 | + if (url === null) { |
| 199 | + return; |
| 200 | + } |
| 201 | + |
| 202 | + if (url === "") { |
| 203 | + editor.value?.chain().focus().extendMarkRange("link").unsetLink().run(); |
| 204 | + return; |
| 205 | + } |
| 206 | + |
| 207 | + editor.value |
| 208 | + ?.chain() |
| 209 | + .focus() |
| 210 | + .extendMarkRange("link") |
| 211 | + .setLink({ href: url }) |
| 212 | + .run(); |
174 | 213 | };
|
175 |
| -// There is as of now no plan to add in attachments. |
| 214 | + |
| 215 | +// Note: There is as of now no plan to add in attachments. |
176 | 216 | // const attach = () => {
|
177 | 217 | // console.log("click on attach");
|
178 | 218 | // };
|
| 219 | + |
179 | 220 | const listul = () => {
|
180 | 221 | console.log("click on listul");
|
| 222 | + editor.value?.chain().focus().toggleBulletList().run(); |
181 | 223 | };
|
182 | 224 | const listol = () => {
|
183 | 225 | console.log("click on listol");
|
| 226 | + editor.value?.chain().focus().toggleOrderedList().run(); |
184 | 227 | };
|
185 | 228 | </script>
|
| 229 | + |
| 230 | +<style> |
| 231 | +.tiptap p.is-editor-empty:first-child::before { |
| 232 | + color: #adb5bd; |
| 233 | + content: attr(data-placeholder); |
| 234 | + float: left; |
| 235 | + height: 0; |
| 236 | + pointer-events: none; |
| 237 | +} |
| 238 | +</style> |
0 commit comments