From 2647084b8df8712eca510a2e9af55df207f95003 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 21 Dec 2025 19:49:24 +0100 Subject: [PATCH] chore: adjust types to only use interfaces if possible Signed-off-by: Ferdinand Thiessen --- lib/navigation/view.ts | 23 +++++++++++++++-------- lib/newMenu/NewMenu.ts | 10 +++++----- lib/newMenu/functions.ts | 6 +++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/navigation/view.ts b/lib/navigation/view.ts index 5757461b4..729f54dae 100644 --- a/lib/navigation/view.ts +++ b/lib/navigation/view.ts @@ -3,15 +3,23 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import type { Folder } from '../node/folder.ts' -import type { Node } from '../node/node.ts' +import type { IFolder, INode } from '../node/index.ts' import isSvg from 'is-svg' import { Column } from './column.ts' export type ContentsWithRoot = { - folder: Folder, - contents: Node[] + folder: IFolder, + contents: INode[] +} + +export interface IGetContentsOptions { + /** + * Abort signal to be able to cancel the request. + * + *@see https://developer.mozilla.org/en-US/docs/Web/API/AbortController + */ + signal: AbortSignal } export interface IView { @@ -42,11 +50,11 @@ export interface IView { * This method _must_ also return the current directory * information alongside with its content. * - * Usually a abort signal is provided to be able to + * An abort signal is provided to be able to * cancel the request if the user change directory * {@see https://developer.mozilla.org/en-US/docs/Web/API/AbortController }. */ - getContents(path: string, options: { signal: AbortSignal }): Promise + getContents(path: string, options: IGetContentsOptions): Promise /** * If set then the view will be hidden from the navigation unless its the active view. @@ -95,8 +103,7 @@ export interface IView { /** * Method called to load child views if any */ - // eslint-disable-next-line no-use-before-define - loadChildViews?: (view: View) => Promise + loadChildViews?: (view: IView) => Promise } export class View implements IView { diff --git a/lib/newMenu/NewMenu.ts b/lib/newMenu/NewMenu.ts index cfc5688f3..0495075cc 100644 --- a/lib/newMenu/NewMenu.ts +++ b/lib/newMenu/NewMenu.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import type { Folder, Node } from '../node/index.ts' +import type { IFolder, INode } from '../node/index.ts' import logger from '../utils/logger.ts' @@ -43,7 +43,7 @@ export interface NewMenuEntry { * Condition wether this entry is shown or not * @param context the creation context. Usually the current folder */ - enabled?: (context: Folder) => boolean + enabled?: (context: IFolder) => boolean /** * Either iconSvgInline or iconClass must be defined @@ -59,7 +59,7 @@ export interface NewMenuEntry { * @param context - The creation context. Usually the current folder * @param content - List of file/folders present in the context folder */ - handler: (context: Folder, content: Node[]) => void + handler: (context: IFolder, content: INode[]) => void } export class NewMenu { @@ -88,9 +88,9 @@ export class NewMenu { /** * Get the list of registered entries * - * @param {Folder} context the creation context. Usually the current folder + * @param context - The creation context. Usually the current folder */ - public getEntries(context?: Folder): Array { + public getEntries(context?: IFolder): Array { if (context) { return this._entries .filter(entry => typeof entry.enabled === 'function' ? entry.enabled(context) : true) diff --git a/lib/newMenu/functions.ts b/lib/newMenu/functions.ts index 110b7b803..2a45a7f56 100644 --- a/lib/newMenu/functions.ts +++ b/lib/newMenu/functions.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import type { Folder } from '../node/index.ts' +import type { IFolder } from '../node/index.ts' import type { NewMenuEntry } from './NewMenu.ts' import { NewMenu } from './NewMenu.ts' @@ -43,9 +43,9 @@ export function removeNewFileMenuEntry(entry: NewMenuEntry | string) { /** * Get the list of registered entries from the upload menu * - * @param {Folder} context - The current folder to get the available entries + * @param context - The current folder to get the available entries */ -export function getNewFileMenuEntries(context?: Folder): NewMenuEntry[] { +export function getNewFileMenuEntries(context?: IFolder): NewMenuEntry[] { const newFileMenu = getNewFileMenu() return newFileMenu.getEntries(context).sort((a: NewMenuEntry, b: NewMenuEntry) => { // If defined and different, sort by order