diff --git a/__tests__/fileAction.spec.ts b/__tests__/fileAction.spec.ts index f4329e7a..e73fd2e5 100644 --- a/__tests__/fileAction.spec.ts +++ b/__tests__/fileAction.spec.ts @@ -173,6 +173,17 @@ describe('Invalid FileAction creation', () => { } as any as FileAction) }).toThrowError('Invalid order') }) + test('Invalid parent', () => { + expect(() => { + new FileAction({ + id: 'test', + displayName: () => 'Test', + iconSvgInline: () => '', + exec: async () => true, + parent: true, + } as any as FileAction) + }).toThrowError('Invalid parent') + }) test('Invalid default', () => { expect(() => { new FileAction({ diff --git a/lib/fileAction.ts b/lib/fileAction.ts index 06716893..72f45506 100644 --- a/lib/fileAction.ts +++ b/lib/fileAction.ts @@ -40,6 +40,7 @@ interface FileActionData { iconSvgInline: (files: Node[], view: View) => string /** Condition wether this action is shown or not */ enabled?: (files: Node[], view: View) => boolean + /** * Function executed on single file action * @return true if the action was executed successfully, @@ -54,9 +55,16 @@ interface FileActionData { * @throws Error if the action failed */ execBatch?: (files: Node[], view: View, dir: string) => Promise<(boolean|null)[]> + /** This action order in the list */ order?: number, + /** + * This action's parent id in the list. + * If none found, will be displayed as a top-level action. + */ + parent?: string, + /** * Make this action the default. * If multiple actions are default, the first one @@ -119,6 +127,10 @@ export class FileAction { return this._action.order } + get parent() { + return this._action.parent + } + get default() { return this._action.default } @@ -165,6 +177,10 @@ export class FileAction { throw new Error('Invalid order') } + if ('parent' in action && typeof action.parent !== 'string') { + throw new Error('Invalid parent') + } + if (action.default && !Object.values(DefaultType).includes(action.default)) { throw new Error('Invalid default') } diff --git a/package.json b/package.json index 6387e879..9d7ea80d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "build": "vite --mode production build", "build:doc": "typedoc --out dist/doc lib && touch dist/doc/.nojekyll", "dev": "vite --mode development build", - "dev:watch": "vite --mode development build --watch", + "watch": "vite --mode development build --watch", "lint": "eslint .", "lint:fix": "eslint --fix .", "test": "vitest run",