import { dispatchToCkeditor } from "../Ckeditor/Event";
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
import { getPhrase } from "WoltLabSuite/Core/Language";
+import { removeUploadProgress, trackUploadProgress } from "WoltLabSuite/Core/Component/File/File";
type FileProcessorData = {
attachmentID: number;
element.append(errorElement);
}
-function trackUploadProgress(element: HTMLElement, file: WoltlabCoreFileElement): void {
- const progress = document.createElement("progress");
- progress.classList.add("fileList__item__progress__bar");
- progress.max = 100;
- const readout = document.createElement("span");
- readout.classList.add("fileList__item__progress__readout");
-
- file.addEventListener("uploadProgress", (event: CustomEvent<number>) => {
- progress.value = event.detail;
- readout.textContent = `${event.detail}%`;
-
- if (progress.parentNode === null) {
- element.classList.add("attachment__item--uploading");
-
- const wrapper = document.createElement("div");
- wrapper.classList.add("fileList__item__progress");
- wrapper.append(progress, readout);
-
- element.append(wrapper);
- }
- });
-}
-
-function removeUploadProgress(element: HTMLElement): void {
- if (!element.classList.contains("attachment__item--uploading")) {
- return;
- }
-
- element.classList.remove("attachment__item--uploading");
- element.querySelector(".fileList__item__progress")?.remove();
-}
-
export function createAttachmentFromFile(file: WoltlabCoreFileElement, editor: HTMLElement) {
const element = document.createElement("li");
element.classList.add("fileList__item", "attachment__item");
--- /dev/null
+import WoltlabCoreFileElement from "WoltLabSuite/Core/Component/File/woltlab-core-file";
+
+export function trackUploadProgress(element: HTMLElement, file: WoltlabCoreFileElement): void {
+ const progress = document.createElement("progress");
+ progress.classList.add("fileList__item__progress__bar");
+ progress.max = 100;
+ const readout = document.createElement("span");
+ readout.classList.add("fileList__item__progress__readout");
+
+ file.addEventListener("uploadProgress", (event: CustomEvent<number>) => {
+ progress.value = event.detail;
+ readout.textContent = `${event.detail}%`;
+
+ if (progress.parentNode === null) {
+ element.classList.add("fileProcessor__item--uploading");
+
+ const wrapper = document.createElement("div");
+ wrapper.classList.add("fileList__item__progress");
+ wrapper.append(progress, readout);
+
+ element.append(wrapper);
+ }
+ });
+}
+
+export function removeUploadProgress(element: HTMLElement): void {
+ if (!element.classList.contains("fileProcessor__item--uploading")) {
+ return;
+ }
+
+ element.classList.remove("fileProcessor__item--uploading");
+ element.querySelector(".fileList__item__progress")?.remove();
+}
import { deleteFile } from "WoltLabSuite/Core/Api/Files/DeleteFile";
import { formatFilesize } from "WoltLabSuite/Core/FileUtil";
import DomChangeListener from "WoltLabSuite/Core/Dom/Change/Listener";
+import { removeUploadProgress, trackUploadProgress } from "WoltLabSuite/Core/Component/File/File";
const _data = new Map<string, FileProcessor>();
}
}
- #trackUploadProgress(element: HTMLElement, file: WoltlabCoreFileElement): void {
- const progress = document.createElement("progress");
- progress.classList.add("fileList__item__progress__bar");
- progress.max = 100;
- const readout = document.createElement("span");
- readout.classList.add("fileList__item__progress__readout");
-
- file.addEventListener("uploadProgress", (event: CustomEvent<number>) => {
- progress.value = event.detail;
- readout.textContent = `${event.detail}%`;
-
- if (progress.parentNode === null) {
- element.classList.add("fileProcessor__item--uploading");
-
- const wrapper = document.createElement("div");
- wrapper.classList.add("fileList__item__progress");
- wrapper.append(progress, readout);
-
- element.append(wrapper);
- }
- });
- }
-
- #removeUploadProgress(element: HTMLElement): void {
- if (!element.classList.contains("fileProcessor__item--uploading")) {
- return;
- }
-
- element.classList.remove("fileProcessor__item--uploading");
- element.querySelector(".fileList__item__progress")?.remove();
- }
-
#registerFile(element: WoltlabCoreFileElement, container: HTMLElement | null = null): void {
if (container === null) {
if (this.showBigPreview) {
container.append(fileSize);
}
- this.#trackUploadProgress(container, element);
+ trackUploadProgress(container, element);
element.ready
.then(() => {
this.#markElementUploadHasFailed(container!, element, reason);
})
.finally(() => {
- this.#removeUploadProgress(container!);
+ removeUploadProgress(container!);
});
}
-define(["require", "exports", "tslib", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Ui/Dropdown/Simple", "WoltLabSuite/Core/Dom/Change/Listener", "../Ckeditor/Event", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Language"], function (require, exports, tslib_1, FileUtil_1, Simple_1, Listener_1, Event_1, DeleteFile_1, Language_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Ui/Dropdown/Simple", "WoltLabSuite/Core/Dom/Change/Listener", "../Ckeditor/Event", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Component/File/File"], function (require, exports, tslib_1, FileUtil_1, Simple_1, Listener_1, Event_1, DeleteFile_1, Language_1, File_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createAttachmentFromFile = void 0;
errorElement.textContent = errorMessage;
element.append(errorElement);
}
- function trackUploadProgress(element, file) {
- const progress = document.createElement("progress");
- progress.classList.add("fileList__item__progress__bar");
- progress.max = 100;
- const readout = document.createElement("span");
- readout.classList.add("fileList__item__progress__readout");
- file.addEventListener("uploadProgress", (event) => {
- progress.value = event.detail;
- readout.textContent = `${event.detail}%`;
- if (progress.parentNode === null) {
- element.classList.add("attachment__item--uploading");
- const wrapper = document.createElement("div");
- wrapper.classList.add("fileList__item__progress");
- wrapper.append(progress, readout);
- element.append(wrapper);
- }
- });
- }
- function removeUploadProgress(element) {
- if (!element.classList.contains("attachment__item--uploading")) {
- return;
- }
- element.classList.remove("attachment__item--uploading");
- element.querySelector(".fileList__item__progress")?.remove();
- }
function createAttachmentFromFile(file, editor) {
const element = document.createElement("li");
element.classList.add("fileList__item", "attachment__item");
fileInitializationFailed(element, file, reason);
})
.finally(() => {
- removeUploadProgress(element);
+ (0, File_1.removeUploadProgress)(element);
});
- trackUploadProgress(element, file);
+ (0, File_1.trackUploadProgress)(element, file);
return element;
}
exports.createAttachmentFromFile = createAttachmentFromFile;
--- /dev/null
+define(["require", "exports"], function (require, exports) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.removeUploadProgress = exports.trackUploadProgress = void 0;
+ function trackUploadProgress(element, file) {
+ const progress = document.createElement("progress");
+ progress.classList.add("fileList__item__progress__bar");
+ progress.max = 100;
+ const readout = document.createElement("span");
+ readout.classList.add("fileList__item__progress__readout");
+ file.addEventListener("uploadProgress", (event) => {
+ progress.value = event.detail;
+ readout.textContent = `${event.detail}%`;
+ if (progress.parentNode === null) {
+ element.classList.add("fileProcessor__item--uploading");
+ const wrapper = document.createElement("div");
+ wrapper.classList.add("fileList__item__progress");
+ wrapper.append(progress, readout);
+ element.append(wrapper);
+ }
+ });
+ }
+ exports.trackUploadProgress = trackUploadProgress;
+ function removeUploadProgress(element) {
+ if (!element.classList.contains("fileProcessor__item--uploading")) {
+ return;
+ }
+ element.classList.remove("fileProcessor__item--uploading");
+ element.querySelector(".fileList__item__progress")?.remove();
+ }
+ exports.removeUploadProgress = removeUploadProgress;
+});
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.1
*/
-define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Dom/Change/Listener"], function (require, exports, tslib_1, Language_1, DeleteFile_1, FileUtil_1, Listener_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Api/Files/DeleteFile", "WoltLabSuite/Core/FileUtil", "WoltLabSuite/Core/Dom/Change/Listener", "WoltLabSuite/Core/Component/File/File"], function (require, exports, tslib_1, Language_1, DeleteFile_1, FileUtil_1, Listener_1, File_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValues = exports.FileProcessor = void 0;
element.parentElement.parentElement.remove();
}
}
- #trackUploadProgress(element, file) {
- const progress = document.createElement("progress");
- progress.classList.add("fileList__item__progress__bar");
- progress.max = 100;
- const readout = document.createElement("span");
- readout.classList.add("fileList__item__progress__readout");
- file.addEventListener("uploadProgress", (event) => {
- progress.value = event.detail;
- readout.textContent = `${event.detail}%`;
- if (progress.parentNode === null) {
- element.classList.add("fileProcessor__item--uploading");
- const wrapper = document.createElement("div");
- wrapper.classList.add("fileList__item__progress");
- wrapper.append(progress, readout);
- element.append(wrapper);
- }
- });
- }
- #removeUploadProgress(element) {
- if (!element.classList.contains("fileProcessor__item--uploading")) {
- return;
- }
- element.classList.remove("fileProcessor__item--uploading");
- element.querySelector(".fileList__item__progress")?.remove();
- }
#registerFile(element, container = null) {
if (container === null) {
if (this.showBigPreview) {
fileSize.textContent = (0, FileUtil_1.formatFilesize)(element.fileSize || parseInt(element.dataset.fileSize));
container.append(fileSize);
}
- this.#trackUploadProgress(container, element);
+ (0, File_1.trackUploadProgress)(container, element);
element.ready
.then(() => {
if (this.#replaceElement !== undefined) {
this.#markElementUploadHasFailed(container, element, reason);
})
.finally(() => {
- this.#removeUploadProgress(container);
+ (0, File_1.removeUploadProgress)(container);
});
}
#fileInitializationCompleted(element, container) {