From: Alexander Ebert Date: Tue, 18 Jul 2023 10:00:01 +0000 (+0200) Subject: Report image attachments to the editor X-Git-Tag: 6.0.0_Alpha_7~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=91d6eca8719179d3b35cee540bc86ec7d051bfbd;p=GitHub%2FWoltLab%2FWCF.git Report image attachments to the editor See https://www.woltlab.com/community/thread/300722-broken-image-icon-when-editing-a-post-with-a-video-file-attached/ --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Attachment.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Attachment.ts index d63ca1c530..12add01a88 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Attachment.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Attachment.ts @@ -75,14 +75,33 @@ function setupRemoveAttachment(ckeditor: CKEditor): void { }); } +function getInlineImageIds(element: HTMLElement): number[] { + const messageTabMenu = element.nextElementSibling; + if (!messageTabMenu || !messageTabMenu.classList.contains("messageTabMenu")) { + return []; + } + + const attachmentList = messageTabMenu.querySelector(".formAttachmentContent > .formAttachmentList"); + if (!attachmentList) { + return []; + } + + return Array.from(attachmentList.querySelectorAll('.formAttachmentListItem[data-is-image="1"]')).map( + (listItem) => parseInt(listItem.dataset.objectId!), + ); +} + export function setup(element: HTMLElement): void { listenToCkeditor(element).setupConfiguration(({ configuration, features }) => { if (!features.attachment) { return; } + const inlineImageIds = getInlineImageIds(element); + // TODO: The typings do not include our custom plugins yet. (configuration as any).woltlabAttachment = { + inlineImageIds, resolveAttachmentUrl(attachmentId: number, isThumbnail: boolean) { let thumbnail = ""; if (isThumbnail) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Attachment.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Attachment.js index 65baf634ce..689c48165c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Attachment.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Attachment.js @@ -41,13 +41,26 @@ define(["require", "exports", "./Event"], function (require, exports, Event_1) { ckeditor.removeAll("imageInline", { attachmentId }); }); } + function getInlineImageIds(element) { + const messageTabMenu = element.nextElementSibling; + if (!messageTabMenu || !messageTabMenu.classList.contains("messageTabMenu")) { + return []; + } + const attachmentList = messageTabMenu.querySelector(".formAttachmentContent > .formAttachmentList"); + if (!attachmentList) { + return []; + } + return Array.from(attachmentList.querySelectorAll('.formAttachmentListItem[data-is-image="1"]')).map((listItem) => parseInt(listItem.dataset.objectId)); + } function setup(element) { (0, Event_1.listenToCkeditor)(element).setupConfiguration(({ configuration, features }) => { if (!features.attachment) { return; } + const inlineImageIds = getInlineImageIds(element); // TODO: The typings do not include our custom plugins yet. configuration.woltlabAttachment = { + inlineImageIds, resolveAttachmentUrl(attachmentId, isThumbnail) { let thumbnail = ""; if (isThumbnail) {