function upload(fileList: HTMLElement, file: WoltlabCoreFileElement, editorId: string): void {
const element = document.createElement("li");
- element.classList.add("attachment__list__item");
- element.append(file);
+ element.classList.add("attachment__item");
+
+ const fileWrapper = document.createElement("div");
+ fileWrapper.classList.add("attachment__item__file");
+ fileWrapper.append(file);
+
+ const filename = document.createElement("div");
+ filename.classList.add("attachment__item__filename");
+ filename.textContent = file.filename!;
+
+ element.append(fileWrapper, filename);
fileList.append(element);
void file.ready.then(() => {
return;
}
- element.append(
+ const buttonList = document.createElement("div");
+ buttonList.classList.add("attachment__item__buttons");
+ buttonList.append(
getDeleteAttachButton(fileId, (data as FileProcessorData).attachmentID, editorId, element),
getInsertAttachBbcodeButton(
(data as FileProcessorData).attachmentID,
const url = file.thumbnails.find((thumbnail) => thumbnail.identifier === "")?.link;
if (url !== undefined) {
- element.append(getInsertThumbnailButton((data as FileProcessorData).attachmentID, url, editorId));
+ buttonList.append(getInsertThumbnailButton((data as FileProcessorData).attachmentID, url, editorId));
}
}
+
+ element.append(buttonList);
});
}
+import { getExtensionByMimeType, getIconNameByFilename } from "WoltLabSuite/Core/FileUtil";
+
const enum State {
Initial,
Uploading,
}
get iconName(): string | undefined {
- return this.dataset.iconName;
+ if (this.mimeType === undefined) {
+ return undefined;
+ }
+
+ const fileExtension = getExtensionByMimeType(this.mimeType);
+ if (fileExtension === "") {
+ return undefined;
+ }
+
+ const iconName = getIconNameByFilename(fileExtension);
+ if (iconName === "") {
+ return undefined;
+ }
+
+ return `file-${iconName}`;
}
get previewUrl(): string | undefined {
exports.setup = void 0;
function upload(fileList, file, editorId) {
const element = document.createElement("li");
- element.classList.add("attachment__list__item");
- element.append(file);
+ element.classList.add("attachment__item");
+ const fileWrapper = document.createElement("div");
+ fileWrapper.classList.add("attachment__item__file");
+ fileWrapper.append(file);
+ const filename = document.createElement("div");
+ filename.classList.add("attachment__item__filename");
+ filename.textContent = file.filename;
+ element.append(fileWrapper, filename);
fileList.append(element);
void file.ready.then(() => {
const data = file.data;
// TODO: error handling
return;
}
- element.append(getDeleteAttachButton(fileId, data.attachmentID, editorId, element), getInsertAttachBbcodeButton(data.attachmentID, file.isImage() && file.link ? file.link : "", editorId));
+ const buttonList = document.createElement("div");
+ buttonList.classList.add("attachment__item__buttons");
+ buttonList.append(getDeleteAttachButton(fileId, data.attachmentID, editorId, element), getInsertAttachBbcodeButton(data.attachmentID, file.isImage() && file.link ? file.link : "", editorId));
if (file.isImage()) {
const thumbnail = file.thumbnails.find((thumbnail) => thumbnail.identifier === "tiny");
if (thumbnail !== undefined) {
}
const url = file.thumbnails.find((thumbnail) => thumbnail.identifier === "")?.link;
if (url !== undefined) {
- element.append(getInsertThumbnailButton(data.attachmentID, url, editorId));
+ buttonList.append(getInsertThumbnailButton(data.attachmentID, url, editorId));
}
}
+ element.append(buttonList);
});
}
function getDeleteAttachButton(fileId, attachmentId, editorId, element) {
-define(["require", "exports"], function (require, exports) {
+define(["require", "exports", "WoltLabSuite/Core/FileUtil"], function (require, exports, FileUtil_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WoltlabCoreFileElement = exports.Thumbnail = void 0;
return this.#fileId;
}
get iconName() {
- return this.dataset.iconName;
+ if (this.mimeType === undefined) {
+ return undefined;
+ }
+ const fileExtension = (0, FileUtil_1.getExtensionByMimeType)(this.mimeType);
+ if (fileExtension === "") {
+ return undefined;
+ }
+ const iconName = (0, FileUtil_1.getIconNameByFilename)(fileExtension);
+ if (iconName === "") {
+ return undefined;
+ }
+ return `file-${iconName}`;
}
get previewUrl() {
return this.dataset.previewUrl;
}
/* attachments tab in editor */
+.attachment__list {
+ display: grid;
+ gap: 10px;
+ grid-auto-flow: column;
+ // TODO: use container queries to make this more dynamic?
+ grid-template-columns: repeat(3, 1fr);
+}
+
+.attachment__list:not(:empty) {
+ margin-top: 20px;
+}
+
+.attachment__item {
+ border: 1px solid var(--wcfContentBorderInner);
+ border-radius: var(--wcfBorderRadius);
+ box-shadow: var(--wcfBoxShadowCard);
+ display: grid;
+ gap: 10px;
+ grid-template-areas:
+ "file filename"
+ "file buttons";
+ grid-template-columns: 64px auto;
+ padding: 10px;
+}
+
+.attachment__item__file {
+ grid-area: file;
+}
+
+.attachment__item__filename {
+ font-size: 12px;
+ grid-area: filename;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.attachment__item__buttons {
+ column-gap: 5px;
+ display: flex;
+ grid-area: buttons;
+ justify-content: end;
+}
+
.formAttachmentContent {
.formAttachmentList {
display: flex;