-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add context menu and improve events types
- Loading branch information
Showing
11 changed files
with
242 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import jiti from 'jiti' | ||
import type { | ||
ContextMenuCallback, | ||
ContextMenuOptions, | ||
DefineContextMenu, | ||
DefineContextMenuWithOptions, | ||
Harmonix, | ||
HarmonixContextMenu, | ||
HarmonixContextMenuInput | ||
} from './types' | ||
import { filename } from 'pathe/utils' | ||
|
||
export const resolveHarmonixContextMenu = ( | ||
ctm: HarmonixContextMenuInput, | ||
harmonixOptions: Harmonix['options'] | ||
): HarmonixContextMenu => { | ||
if (typeof ctm === 'string') { | ||
const _jiti = jiti(harmonixOptions.rootDir, { | ||
interopDefault: true | ||
}) | ||
const _ctmPath = _jiti.resolve(ctm) | ||
const contextMenu = _jiti(_ctmPath) as HarmonixContextMenu | ||
const options: ContextMenuOptions = { | ||
name: contextMenu.options.name || filename(_ctmPath).split('.')[0], | ||
type: contextMenu.options.type || 'message' | ||
} | ||
|
||
return { options, callback: contextMenu.callback } | ||
} else { | ||
return ctm | ||
} | ||
} | ||
|
||
export const defineContextMenu: DefineContextMenu & | ||
DefineContextMenuWithOptions = ( | ||
...args: [ContextMenuOptions | ContextMenuCallback, ContextMenuCallback?] | ||
): HarmonixContextMenu => { | ||
let options: ContextMenuOptions = {} | ||
|
||
if (args.length === 1) { | ||
const [callback] = args as [ContextMenuCallback] | ||
|
||
return { | ||
options, | ||
callback | ||
} | ||
} else { | ||
const [opts, callback] = args as [ContextMenuOptions, ContextMenuCallback] | ||
|
||
options = opts | ||
return { | ||
options, | ||
callback | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.