From c6088f84ff18a1384cf30f419703442c1cecb812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 23 Aug 2023 18:19:03 +0200 Subject: [PATCH] fix(newfilemenu): fix handler requirement, deprecate iconClass and fix context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/index.ts | 5 ++--- lib/newFileMenu.ts | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 425eccb9..466124ec 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -68,9 +68,8 @@ export const removeNewFileMenuEntry = function(entry: Entry | string) { * Get the list of registered entries from the upload menu * * @param {Folder} context the creation context. Usually the current folder FileInfo - * @param {View} view the current view */ -export const getNewFileMenuEntries = function(context?: Folder, view?: View) { +export const getNewFileMenuEntries = function(context?: Folder) { const newFileMenu = getNewFileMenu() - return newFileMenu.getEntries(context, view) + return newFileMenu.getEntries(context) } diff --git a/lib/newFileMenu.ts b/lib/newFileMenu.ts index 20b57179..eacafa82 100644 --- a/lib/newFileMenu.ts +++ b/lib/newFileMenu.ts @@ -21,7 +21,6 @@ */ import { Folder } from './files/folder' -import { View } from './navigation/view' import logger from './utils/logger' export interface Entry { @@ -35,16 +34,22 @@ export interface Entry { * Condition wether this entry is shown or not * @param {Folder} context the creation context. Usually the current folder */ - if?: (context: Folder, view: View) => boolean + if?: (context: Folder) => boolean /** * Either iconSvgInline or iconClass must be defined * Svg as inline string. */ iconSvgInline?: string - /** Existing icon css class */ + /** + * Existing icon css class + * @deprecated use iconSvgInline instead + */ iconClass?: string - /** Function to be run after creation */ - handler?: (context: Folder, view: View) => void + /** + * Function to be run after creation + * @param {Folder} context the creation context. Usually the current folder + */ + handler: (context: Folder) => void } export class NewFileMenu { @@ -73,12 +78,11 @@ export class NewFileMenu { * Get the list of registered entries * * @param {Folder} context the creation context. Usually the current folder - * @param {View} view the current view */ - public getEntries(context?: Folder, view?: View): Array { - if (context && view) { + public getEntries(context?: Folder): Array { + if (context) { return this._entries - .filter(entry => typeof entry.if === 'function' ? entry.if(context, view) : true) + .filter(entry => typeof entry.if === 'function' ? entry.if(context) : true) } return this._entries } @@ -88,7 +92,7 @@ export class NewFileMenu { } private validateEntry(entry: Entry) { - if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass)) { + if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass || entry.handler)) { throw new Error('Invalid entry') }