From 9f3a245a3cfd28ffa30a2c6b154f0a421c7a6d76 Mon Sep 17 00:00:00 2001 From: Yaacov Date: Fri, 13 Sep 2024 15:59:39 +0200 Subject: [PATCH] Tiptap: handle images drag and drop Add a new extension: ImageUploadTiptapExtension --- confiture-web-app/package.json | 1 + .../src/components/audit/NotesModal.vue | 12 +- .../src/components/ui/Tiptap.vue | 19 +- confiture-web-app/src/store/audit.ts | 1 + confiture-web-app/src/styles/main.css | 39 ++++ .../src/tiptap/ImageUploadTiptapExtension.ts | 166 ++++++++++++++++++ yarn.lock | 5 + 7 files changed, 236 insertions(+), 7 deletions(-) create mode 100644 confiture-web-app/src/tiptap/ImageUploadTiptapExtension.ts diff --git a/confiture-web-app/package.json b/confiture-web-app/package.json index 5ddddb7f..1a8eea77 100644 --- a/confiture-web-app/package.json +++ b/confiture-web-app/package.json @@ -19,6 +19,7 @@ "@sentry/vue": "^7.37.2", "@tiptap/extension-code-block-lowlight": "^2.5.9", "@tiptap/extension-highlight": "^2.5.9", + "@tiptap/extension-image": "^2.6.6", "@tiptap/extension-link": "^2.5.9", "@tiptap/extension-task-item": "^2.5.9", "@tiptap/extension-task-list": "^2.5.9", diff --git a/confiture-web-app/src/components/audit/NotesModal.vue b/confiture-web-app/src/components/audit/NotesModal.vue index f793c463..8869f352 100644 --- a/confiture-web-app/src/components/audit/NotesModal.vue +++ b/confiture-web-app/src/components/audit/NotesModal.vue @@ -47,7 +47,10 @@ const files = computed( ) || [] ); -const handleNotesChange = debounce(() => emit("confirm", notes.value), 500); +const handleNotesChange = debounce((notesContent: string) => { + notes.value = notesContent; + emit("confirm", notes.value); +}, 500); function handleUploadFile(file: File) { auditStore @@ -116,8 +119,7 @@ function handleDeleteFile(file: AuditFile) { rows="10" :disabled="isOffline" aria-describedby="notes-markdown" - @input="handleNotesChange" - @update:content="($content) => (notes = $content)" + @update:content="handleNotesChange" /> (); const emit = defineEmits(["update:content"]); +const uniqueId = computed(() => route.params.uniqueId as string); + function getContent() { let jsonContent; try { @@ -57,6 +68,10 @@ const editor = useEditor({ }), TaskItem, TaskList, + ImageExtension.configure({ inline: false }), + ImageUploadTiptapExtension.configure({ + uniqueId: uniqueId.value + }), Typography.configure({ openDoubleQuote: "« ", closeDoubleQuote: " »" @@ -66,7 +81,7 @@ const editor = useEditor({ // The content has changed. emit("update:content", JSON.stringify(editor.getJSON())); } -}); +}) as ShallowRef;