Skip to content

Build your personal knowledge base with Trilium Notes

refactor(ckeditor5): drop the unused file upload progress bar

Elian Doran1e055fd4f927
diff --git a/packages/ckeditor5/src/plugins/file_upload/progressbarview.spec.ts b/packages/ckeditor5/src/plugins/file_upload/progressbarview.spec.ts
deleted file mode 100644
index 161a605a83..0000000000
--- a/packages/ckeditor5/src/plugins/file_upload/progressbarview.spec.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import { Locale } from "ckeditor5";
-import { afterEach, beforeEach, describe, expect, it } from "vitest";
-
-import ProgressBarView from "./progressbarview.js";
-
-describe("ProgressBarView", () => {
- let locale: Locale;
- let view: ProgressBarView;
-
- beforeEach(() => {
- locale = new Locale();
- view = new ProgressBarView(locale);
- view.render();
- document.body.appendChild(view.element as HTMLElement);
- });
-
- afterEach(() => {
- view.element?.remove();
- view.destroy();
- });
-
- it("renders a div with the ck-progress-bar class", () => {
- expect(view.element?.tagName).toBe("DIV");
- expect(view.element?.classList.contains("ck-progress-bar")).toBe(true);
- });
-
- it("initial width observable is 100 (rendered as 100% on the element)", () => {
- expect(view.width).toBe(100);
- expect((view.element as HTMLElement).style.width).toBe("100%");
- });
-
- it("initial customWidth observable is 0 (rendered as 0% on the inner progress div)", () => {
- expect(view.customWidth).toBe(0);
- const inner = view.element?.querySelector(".ck-uploading-progress") as HTMLElement;
- expect(inner).not.toBeNull();
- expect(inner.style.width).toBe("0%");
- });
-
- it("updates the outer width style when the width observable changes", () => {
- view.set("width", 60);
- expect((view.element as HTMLElement).style.width).toBe("60%");
- });
-
- it("updates the inner progress div width style when customWidth changes", () => {
- view.set("customWidth", 42);
- const inner = view.element?.querySelector(".ck-uploading-progress") as HTMLElement;
- expect(inner.style.width).toBe("42%");
- });
-
- it("inner div contains the 'Uploading...' text", () => {
- const inner = view.element?.querySelector(".ck-uploading-progress");
- expect(inner?.textContent).toBe("Uploading...");
- });
-
- it("renders a cancel button element inside the view", () => {
- const btn = view.element?.querySelector("button");
- expect(btn).not.toBeNull();
- });
-
- it("fires the 'cancel' event when the cancel button is executed", () => {
- let cancelFired = false;
- view.on("cancel", () => {
- cancelFired = true;
- });
-
- const btn = view.element?.querySelector("button") as HTMLElement;
- expect(btn).not.toBeNull();
- btn.click();
-
- expect(cancelFired).toBe(true);
- });
-
- it("the cancel button has the standard CKEditor button CSS classes", () => {
- const btn = view.element?.querySelector("button");
- expect(btn?.classList.contains("ck")).toBe(true);
- expect(btn?.classList.contains("ck-button")).toBe(true);
- expect(btn?.classList.contains("ck-off")).toBe(true);
- });
-});
diff --git a/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts b/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts
deleted file mode 100644
index 3c59e53bf5..0000000000
--- a/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-import { IconCancel } from '@ckeditor/ckeditor5-icons';
-import { ButtonView, Locale, toUnit, View } from 'ckeditor5';
-
-const toPx = toUnit('%');
-
-export default class ProgressBarView extends View {
- private cancelButton: ButtonView;
- declare width: number;
- declare customWidth: number;
-
- constructor(locale: Locale) {
- super(locale);
-
- const bind = this.bindTemplate;
- this.cancelButton = this._createCancelButton(locale);
-
- // Views define their interface (state) using observable attributes.
- this.set('width', 100);
- this.set('customWidth', 0);
-
-
- this.setTemplate({
- tag: 'div',
-
- // The element of the view can be defined with its children.
- children: [
- {
- tag: 'div',
- children: ['Uploading...'],
- attributes: {
- class: ['ck-uploading-progress'],
- style: {
- width: bind.to('customWidth', toPx),
- }
- }
- },
- this.cancelButton,
- ],
- attributes: {
- class: [
- 'ck-progress-bar',
-
- // Observable attributes control the state of the view in DOM.
- //@ts-expect-error Type 'ListenerBinding' is not assignable to type 'TemplateSimpleValueSchema'
- bind.to('elementClass')
- ],
- style: {
- width: bind.to('width', toPx),
- }
- }
- });
- }
-
- _createCancelButton(locale: Locale) {
- const view = new ButtonView(locale);
- view.set({
- icon: IconCancel,
- tooltip: true,
- // An upstream message, so CKEditor's own catalog translates it — the editor package
- // deliberately declares no entry of its own for it.
- label: locale.t('Cancel'),
- //@ts-expect-error Object literal may only specify known properties, and 'attributes' does not exist in type
- attributes: {
- class: ['ck', 'ck-button', 'ck-off', 'ck-button-cancel', 'ck-uploading-cancel']
- }
- });
-
- view.on('execute', () => {
- this.fire('cancel')
- });
- return view;
- }
-}
diff --git a/packages/ckeditor5/src/theme/fileupload.css b/packages/ckeditor5/src/theme/fileupload.css
deleted file mode 100644
index 0be41d6f2a..0000000000
--- a/packages/ckeditor5/src/theme/fileupload.css
+++ /dev/null
@@ -1,30 +0,0 @@
-.ck.ck-sticky-panel > .ck-progress-bar {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
-
- border-left: 1px solid var(--ck-color-base-border);
- border-top: 1px solid var(--ck-color-base-border);
- border-right: 1px solid var(--ck-color-base-border);
-}
-
-.ck.ck-sticky-panel > .ck-progress-bar > .ck-uploading-progress {
- align-self: center;
- padding: 3px 5px;
- font-weight: bold;
-
- color: var(--ck-color-base-foreground);
- background-color: var(--ck-color-base-border);
-
- transition-property: width;
- transition-duration: .5s;
- transition-timing-function: linear;
-
-}
-
-.ck.ck-sticky-panel > .ck-progress-bar > .ck-uploading-cancel {
- align-self: flex-end;
- padding: 0 5px;
- font-weight: bold;
- color: var(--ck-color-base-error);
-}
\ No newline at end of file