diff --git a/__tests__/fileAction.spec.ts b/__tests__/fileAction.spec.ts
index e4496169..6e2839bb 100644
--- a/__tests__/fileAction.spec.ts
+++ b/__tests__/fileAction.spec.ts
@@ -3,7 +3,7 @@
/* eslint-disable no-new */
import { beforeEach, describe, expect, test, vi } from 'vitest'
-import { getFileActions, registerFileAction, FileAction } from '../lib/fileAction'
+import { getFileActions, registerFileAction, FileAction, DefaultType } from '../lib/fileAction'
import logger from '../lib/utils/logger'
describe('FileActions init', () => {
@@ -208,9 +208,9 @@ describe('FileActions creation', () => {
execBatch: async () => [true],
enabled: () => true,
order: 100,
- default: true,
+ default: DefaultType.DEFAULT,
inline: () => true,
- renderInline() {
+ renderInline: async() => {
const span = document.createElement('span')
span.textContent = 'test'
return span
@@ -218,14 +218,14 @@ describe('FileActions creation', () => {
})
expect(action.id).toBe('test')
- expect(action.displayName([], {})).toBe('Test')
- expect(action.iconSvgInline([], {})).toBe('')
- await expect(action.exec({} as any, {}, '/')).resolves.toBe(true)
- await expect(action.execBatch?.([], {}, '/')).resolves.toStrictEqual([true])
- expect(action.enabled?.({} as any, {})).toBe(true)
+ expect(action.displayName([], {} as any)).toBe('Test')
+ expect(action.iconSvgInline([], {} as any)).toBe('')
+ await expect(action.exec({} as any, {} as any, '/')).resolves.toBe(true)
+ await expect(action.execBatch?.([], {} as any, '/')).resolves.toStrictEqual([true])
+ expect(action.enabled?.({} as any, {} as any)).toBe(true)
expect(action.order).toBe(100)
- expect(action.default).toBe(true)
- expect(action.inline?.({} as any, {})).toBe(true)
- expect(action.renderInline?.({} as any, {}).outerHTML).toBe('test')
+ expect(action.default).toBe(DefaultType.DEFAULT)
+ expect(action.inline?.({} as any, {} as any)).toBe(true)
+ expect((await action.renderInline?.({} as any, {} as any))?.outerHTML).toBe('test')
})
})
diff --git a/lib/fileAction.ts b/lib/fileAction.ts
index 7f446402..d86113f5 100644
--- a/lib/fileAction.ts
+++ b/lib/fileAction.ts
@@ -1,5 +1,5 @@
/**
- * @copyright Copyright (c) 2021 John Molakvoæ
+ * @copyright Copyright (c) 2023 John Molakvoæ
*
* @author John Molakvoæ
*
@@ -24,6 +24,18 @@ import { Node } from './files/node'
import { View } from './navigation/view'
import logger from './utils/logger'
+declare global {
+ interface Window {
+ OC: any;
+ _nc_fileactions: FileAction[] | undefined;
+ }
+}
+
+export enum DefaultType {
+ DEFAULT = 'default',
+ HIDDEN = 'hidden',
+}
+
interface FileActionData {
/** Unique ID */
id: string
@@ -50,7 +62,7 @@ interface FileActionData {
/** This action order in the list */
order?: number,
/** Make this action the default */
- default?: boolean,
+ default?: DefaultType,
/**
* If true, the renderInline function will be called
*/
@@ -59,7 +71,7 @@ interface FileActionData {
* If defined, the returned html element will be
* appended before the actions menu.
*/
- renderInline?: (file: Node, view: View) => HTMLElement,
+ renderInline?: (file: Node, view: View) => Promise,
}
export class FileAction {
@@ -141,7 +153,7 @@ export class FileAction {
throw new Error('Invalid order')
}
- if ('default' in action && typeof action.default !== 'boolean') {
+ if (action.default && !Object.values(DefaultType).includes(action.default)) {
throw new Error('Invalid default')
}