diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js b/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/codemirror_content_script/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/content_script/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/content_script/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/content_script/api/types.ts b/packages/app-cli/tests/support/plugins/content_script/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/content_script/api/types.ts +++ b/packages/app-cli/tests/support/plugins/content_script/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/content_script/package.json b/packages/app-cli/tests/support/plugins/content_script/package.json index 761cec9f90..a7ad2623fb 100644 --- a/packages/app-cli/tests/support/plugins/content_script/package.json +++ b/packages/app-cli/tests/support/plugins/content_script/package.json @@ -20,4 +20,4 @@ "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } -} +} \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/content_script/webpack.config.js b/packages/app-cli/tests/support/plugins/content_script/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/content_script/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/content_script/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/dialog/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/dialog/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/dialog/api/types.ts b/packages/app-cli/tests/support/plugins/dialog/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/dialog/api/types.ts +++ b/packages/app-cli/tests/support/plugins/dialog/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/dialog/webpack.config.js b/packages/app-cli/tests/support/plugins/dialog/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/dialog/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/dialog/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/api/types.ts b/packages/app-cli/tests/support/plugins/editor_context_menu/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/api/types.ts +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js b/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/editor_context_menu/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/events/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/events/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/events/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/events/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/events/api/types.ts b/packages/app-cli/tests/support/plugins/events/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/events/api/types.ts +++ b/packages/app-cli/tests/support/plugins/events/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/events/package.json b/packages/app-cli/tests/support/plugins/events/package.json index 761cec9f90..a7ad2623fb 100644 --- a/packages/app-cli/tests/support/plugins/events/package.json +++ b/packages/app-cli/tests/support/plugins/events/package.json @@ -20,4 +20,4 @@ "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } -} +} \ No newline at end of file diff --git a/packages/app-cli/tests/support/plugins/events/webpack.config.js b/packages/app-cli/tests/support/plugins/events/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/events/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/events/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/jpl_test/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/jpl_test/api/types.ts b/packages/app-cli/tests/support/plugins/jpl_test/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/api/types.ts +++ b/packages/app-cli/tests/support/plugins/jpl_test/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/jpl_test/webpack.config.js b/packages/app-cli/tests/support/plugins/jpl_test/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/jpl_test/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/jpl_test/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/json_export/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/json_export/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/json_export/api/types.ts b/packages/app-cli/tests/support/plugins/json_export/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/json_export/api/types.ts +++ b/packages/app-cli/tests/support/plugins/json_export/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/json_export/webpack.config.js b/packages/app-cli/tests/support/plugins/json_export/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/json_export/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/json_export/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/menu/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/menu/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/menu/api/types.ts b/packages/app-cli/tests/support/plugins/menu/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/menu/api/types.ts +++ b/packages/app-cli/tests/support/plugins/menu/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/menu/webpack.config.js b/packages/app-cli/tests/support/plugins/menu/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/menu/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/menu/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/multi_selection/api/types.ts b/packages/app-cli/tests/support/plugins/multi_selection/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/api/types.ts +++ b/packages/app-cli/tests/support/plugins/multi_selection/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js b/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/multi_selection/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/register_command/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/register_command/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/register_command/api/types.ts b/packages/app-cli/tests/support/plugins/register_command/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/register_command/api/types.ts +++ b/packages/app-cli/tests/support/plugins/register_command/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/register_command/package.json b/packages/app-cli/tests/support/plugins/register_command/package.json index a7ad2623fb..761cec9f90 100644 --- a/packages/app-cli/tests/support/plugins/register_command/package.json +++ b/packages/app-cli/tests/support/plugins/register_command/package.json @@ -20,4 +20,4 @@ "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } -} \ No newline at end of file +} diff --git a/packages/app-cli/tests/support/plugins/register_command/src/index.ts b/packages/app-cli/tests/support/plugins/register_command/src/index.ts index 404709a518..8da39e85e0 100644 --- a/packages/app-cli/tests/support/plugins/register_command/src/index.ts +++ b/packages/app-cli/tests/support/plugins/register_command/src/index.ts @@ -35,6 +35,22 @@ joplin.plugins.register({ }, }); + await joplin.commands.register({ + name: 'folderContextMenuExample', + label: 'Folder menu item from plugin', + execute: async (folderId:string) => { + console.info('Click on folder: ' + folderId); + }, + }); + + await joplin.commands.register({ + name: 'tagContextMenuExample', + label: 'Tag menu item from plugin', + execute: async (tagId:string) => { + console.info('Click on tag: ' + tagId); + }, + }); + // Commands that return a result and take argument can only be used // programmatically, so it's not necessary to set a label and icon. await joplin.commands.register({ @@ -56,6 +72,9 @@ joplin.plugins.register({ await joplin.views.menuItems.create('contextMenuItem1', 'contextMenuCommandExample', MenuItemLocation.NoteListContextMenu); + await joplin.views.menuItems.create('folderMenuItem1', 'folderContextMenuExample', MenuItemLocation.FolderContextMenu); + await joplin.views.menuItems.create('tagMenuItem1', 'tagContextMenuExample', MenuItemLocation.TagContextMenu); + console.info('Running command with arguments...'); const result = await joplin.commands.execute('commandWithResult', 'abcd', 123); console.info('Result was: ' + result); diff --git a/packages/app-cli/tests/support/plugins/register_command/webpack.config.js b/packages/app-cli/tests/support/plugins/register_command/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/register_command/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/register_command/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/selected_text/api/types.ts b/packages/app-cli/tests/support/plugins/selected_text/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/api/types.ts +++ b/packages/app-cli/tests/support/plugins/selected_text/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js b/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/selected_text/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/settings/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/settings/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/settings/api/types.ts b/packages/app-cli/tests/support/plugins/settings/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/settings/api/types.ts +++ b/packages/app-cli/tests/support/plugins/settings/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/settings/webpack.config.js b/packages/app-cli/tests/support/plugins/settings/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/settings/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/settings/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/toc/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/toc/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/toc/api/types.ts b/packages/app-cli/tests/support/plugins/toc/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/toc/api/types.ts +++ b/packages/app-cli/tests/support/plugins/toc/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/toc/webpack.config.js b/packages/app-cli/tests/support/plugins/toc/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/toc/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/toc/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinPlugins.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinPlugins.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinSettings.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinSettings.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinWorkspace.d.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinWorkspace.d.ts index 0686d32a9c..bd6f718ab4 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinWorkspace.d.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3 +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent) => void; +declare type SyncStartHandler = (event: SyncStartEvent) => void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/api/types.ts b/packages/app-cli/tests/support/plugins/withExternalModules/api/types.ts index f81bc10384..582fa3b69e 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/api/types.ts +++ b/packages/app-cli/tests/support/plugins/withExternalModules/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location:MenuItemLocation):boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js b/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js index 1f3e9a8601..99ca5e6ec4 100644 --- a/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js +++ b/packages/app-cli/tests/support/plugins/withExternalModules/webpack.config.js @@ -13,7 +13,7 @@ function readManifest(manifestPath) { } function createPluginArchive(sourceDir, destPath) { - const distFiles = glob.sync(`${sourceDir}/**/*`) + const distFiles = glob.sync(`${sourceDir}/**/*`, { nodir: true }) .map(f => f.substr(sourceDir.length + 1)); if (!distFiles.length) { diff --git a/packages/app-desktop/gui/MenuBar.tsx b/packages/app-desktop/gui/MenuBar.tsx index 43d46e0f0a..f6e3b70719 100644 --- a/packages/app-desktop/gui/MenuBar.tsx +++ b/packages/app-desktop/gui/MenuBar.tsx @@ -12,7 +12,7 @@ import versionInfo from '@joplin/lib/versionInfo'; import { Module } from '@joplin/lib/services/interop/types'; import InteropServiceHelper from '../InteropServiceHelper'; import { _ } from '@joplin/lib/locale'; -import { MenuItem, MenuItemLocation } from '@joplin/lib/services/plugins/api/types'; +import { isContextMenuItemLocation, MenuItem, MenuItemLocation } from '@joplin/lib/services/plugins/api/types'; import SpellCheckerService from '@joplin/lib/services/spellChecker/SpellCheckerService'; import menuCommandNames from './menuCommandNames'; import stateToWhenClauseContext from '../services/commands/stateToWhenClauseContext'; @@ -697,7 +697,7 @@ function useMenu(props: Props) { for (const view of props.pluginMenuItems) { const location: MenuItemLocation = view.location; - if ([MenuItemLocation.Context, MenuItemLocation.EditorContextMenu, MenuItemLocation.NoteListContextMenu].includes(location)) continue; + if (isContextMenuItemLocation(location)) continue; const itemParent = rootMenus[location]; @@ -709,7 +709,7 @@ function useMenu(props: Props) { } for (const view of props.pluginMenus) { - if ([MenuItemLocation.Context, MenuItemLocation.EditorContextMenu, MenuItemLocation.NoteListContextMenu].includes(view.location)) continue; + if (isContextMenuItemLocation(view.location)) continue; const itemParent = rootMenus[view.location]; if (!itemParent) { diff --git a/packages/app-desktop/gui/SideBar/SideBar.tsx b/packages/app-desktop/gui/SideBar/SideBar.tsx index 1df4459bd2..485d07d450 100644 --- a/packages/app-desktop/gui/SideBar/SideBar.tsx +++ b/packages/app-desktop/gui/SideBar/SideBar.tsx @@ -8,6 +8,10 @@ import Setting from '@joplin/lib/models/Setting'; import MenuUtils from '@joplin/lib/services/commands/MenuUtils'; import InteropServiceHelper from '../../InteropServiceHelper'; import { _ } from '@joplin/lib/locale'; +import { PluginStates, utils as pluginUtils } from '@joplin/lib/services/plugins/reducer'; +import { MenuItemLocation } from '@joplin/lib/services/plugins/api/types'; +import { AppState } from '../../app'; +import { ModelType } from '@joplin/lib/BaseModel'; const { connect } = require('react-redux'); const shared = require('@joplin/lib/components/shared/side-menu-shared.js'); @@ -36,6 +40,7 @@ interface Props { syncReport: any; tags: any[]; syncStarted: boolean; + plugins: PluginStates; } interface State { @@ -101,6 +106,7 @@ class SideBarComponent extends React.Component { private tagItemsOrder_: any[] = []; private rootRef: any = null; private anchorItemRefs: any = {}; + private pluginsRef: any; constructor(props: any) { super(props); @@ -112,6 +118,14 @@ class SideBarComponent extends React.Component { folderHeaderIsExpanded: Setting.value('folderHeaderIsExpanded'), }; + // This whole component is a bit of a mess and rather than passing + // a plugins prop around, not knowing how it's going to affect + // re-rendering, we just keep a ref to it. Currently that's enough + // as plugins are only accessed from context menus. However if want + // to do more complex things with plugins in the sidebar, it will + // probably have to be refactored using React Hooks first. + this.pluginsRef = React.createRef(); + this.onFolderToggleClick_ = this.onFolderToggleClick_.bind(this); this.onKeyDown = this.onKeyDown.bind(this); this.onAllNotesClick_ = this.onAllNotesClick_.bind(this); @@ -294,6 +308,20 @@ class SideBarComponent extends React.Component { )); } + const pluginViews = pluginUtils.viewsByType(this.pluginsRef.current, 'menuItem'); + + for (const view of pluginViews) { + const location = view.location; + + if (itemType === ModelType.Tag && location === MenuItemLocation.TagContextMenu || + itemType === ModelType.Folder && location === MenuItemLocation.FolderContextMenu + ) { + menu.append( + new MenuItem(menuUtils.commandToStatefulMenuItem(view.commandName, itemId)) + ); + } + } + menu.popup(bridge().window()); } @@ -584,6 +612,8 @@ class SideBarComponent extends React.Component { // } render() { + this.pluginsRef.current = this.props.plugins; + const theme = themeStyle(this.props.themeId); const items = []; @@ -668,7 +698,7 @@ class SideBarComponent extends React.Component { } } -const mapStateToProps = (state: any) => { +const mapStateToProps = (state: AppState) => { return { folders: state.folders, tags: state.tags, @@ -685,6 +715,7 @@ const mapStateToProps = (state: any) => { collapsedFolderIds: state.collapsedFolderIds, decryptionWorker: state.decryptionWorker, resourceFetcher: state.resourceFetcher, + plugins: state.pluginService.plugins, }; }; diff --git a/packages/app-desktop/testPluginDemo.sh b/packages/app-desktop/testPluginDemo.sh index c6aa99864e..33a2927493 100755 --- a/packages/app-desktop/testPluginDemo.sh +++ b/packages/app-desktop/testPluginDemo.sh @@ -4,5 +4,5 @@ # It could be used to develop plugins too. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -PLUGIN_PATH="$SCRIPT_DIR/../app-cli/tests/support/plugins/editor_context_menu" +PLUGIN_PATH="$SCRIPT_DIR/../app-cli/tests/support/plugins/register_command" npm i --prefix="$PLUGIN_PATH" && npm start -- --dev-plugins "$PLUGIN_PATH" \ No newline at end of file diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinPlugins.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinPlugins.d.ts index 458445a660..47a4ae86f4 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinPlugins.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinPlugins.d.ts @@ -20,14 +20,20 @@ export default class JoplinPlugins { */ register(script: Script): Promise; /** - * Registers a new content script. Unlike regular plugin code, which runs in a separate process, content scripts run within the main process code - * and thus allow improved performances and more customisations in specific cases. It can be used for example to load a Markdown or editor plugin. + * Registers a new content script. Unlike regular plugin code, which + * runs in a separate process, content scripts run within the main + * process code and thus allow improved performances and more + * customisations in specific cases. It can be used for example to load + * a Markdown or editor plugin. * - * Note that registering a content script in itself will do nothing - it will only be loaded in specific cases by the relevant app modules - * (eg. the Markdown renderer or the code editor). So it is not a way to inject and run arbitrary code in the app, which for safety and performance reasons is not supported. + * Note that registering a content script in itself will do nothing - + * it will only be loaded in specific cases by the relevant app modules + * (eg. the Markdown renderer or the code editor). So it is not a way + * to inject and run arbitrary code in the app, which for safety and + * performance reasons is not supported. * - * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) - * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) * * @param type Defines how the script will be used. See the type definition for more information about each supported type. * @param id A unique ID for the content script. diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinSettings.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinSettings.d.ts index 0fa39d9640..d725ea47bd 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinSettings.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinSettings.d.ts @@ -37,7 +37,7 @@ export default class JoplinSettings { * * The list of available settings is not documented yet, but can be found by looking at the source code: * - * https://github.com/laurent22/joplin/blob/3539a452a359162c461d2849829d2d42973eab50/packages/app-mobile/lib/models/Setting.ts#L142 + * https://github.com/laurent22/joplin/blob/dev/packages/lib/models/Setting.ts#L142 */ globalValue(key: string): Promise; } diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinWorkspace.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinWorkspace.d.ts index 0686d32a9c..982c2e0b93 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinWorkspace.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinWorkspace.d.ts @@ -1,28 +1,54 @@ +import { Disposable } from './types'; +declare enum ItemChangeEventType { + Create = 1, + Update = 2, + Delete = 3, +} +interface ItemChangeEvent { + id: string; + event: ItemChangeEventType; +} +interface SyncStartEvent { + withErrors: boolean; +} +declare type ItemChangeHandler = (event: ItemChangeEvent)=> void; +declare type SyncStartHandler = (event: SyncStartEvent)=> void; /** - * The workspace service provides access to all the parts of Joplin that are being worked on - i.e. the currently selected notes or notebooks as well - * as various related events, such as when a new note is selected, or when the note content changes. + * The workspace service provides access to all the parts of Joplin that + * are being worked on - i.e. the currently selected notes or notebooks as + * well as various related events, such as when a new note is selected, or + * when the note content changes. * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins) */ export default class JoplinWorkspace { private store; - constructor(_implementation: any, store: any); + constructor(store: any); /** * Called when a new note or notes are selected. */ - onNoteSelectionChange(callback: Function): Promise; + onNoteSelectionChange(callback: Function): Promise; /** * Called when the content of a note changes. + * @deprecated Use `onNoteChange()` instead, which is reliably triggered whenever the note content, or any note property changes. */ onNoteContentChange(callback: Function): Promise; + /** + * Called when the content of a note changes. + */ + onNoteChange(handler: ItemChangeHandler): Promise; /** * Called when an alarm associated with a to-do is triggered. */ - onNoteAlarmTrigger(callback: Function): Promise; + onNoteAlarmTrigger(handler: Function): Promise; + /** + * Called when the synchronisation process is starting. + */ + onSyncStart(handler: SyncStartHandler): Promise; /** * Called when the synchronisation process has finished. */ - onSyncComplete(callback: Function): Promise; + onSyncComplete(callback: Function): Promise; /** * Gets the currently selected note */ @@ -32,3 +58,4 @@ export default class JoplinWorkspace { */ selectedNoteIds(): Promise; } +export {}; diff --git a/packages/generator-joplin/generators/app/templates/api/types.ts b/packages/generator-joplin/generators/app/templates/api/types.ts index f81bc10384..d14c63b49a 100644 --- a/packages/generator-joplin/generators/app/templates/api/types.ts +++ b/packages/generator-joplin/generators/app/templates/api/types.ts @@ -40,7 +40,7 @@ export interface Command { * Or | \|\| | "noteIsTodo \|\| noteTodoCompleted" * And | && | "oneNoteSelected && !inConflictFolder" * - * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/services/commands/stateToWhenClauseContext.ts). + * Currently the supported context variables aren't documented, but you can [find the list here](https://github.com/laurent22/joplin/blob/dev/packages/lib/services/commands/stateToWhenClauseContext.ts). * * Note: Commands are enabled by default unless you use this property. */ @@ -189,6 +189,10 @@ export interface Script { onStart?(event: any): Promise; } +export interface Disposable { + // dispose():void; +} + // ================================================================= // Menu types // ================================================================= @@ -204,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location: MenuItemLocation): boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem { @@ -318,9 +359,9 @@ export interface SettingSection { /** * An array of at least one element and at most three elements. * - * [0]: Resource name (eg. "notes", "folders", "tags", etc.) - * [1]: (Optional) Resource ID. - * [2]: (Optional) Resource link. + * - **[0]**: Resource name (eg. "notes", "folders", "tags", etc.) + * - **[1]**: (Optional) Resource ID. + * - **[2]**: (Optional) Resource link. */ export type Path = string[]; @@ -330,7 +371,8 @@ export type Path = string[]; export enum ContentScriptType { /** - * Registers a new Markdown-It plugin, which should follow the template below. + * Registers a new Markdown-It plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -346,14 +388,49 @@ export enum ContentScriptType { * } * } * ``` + * See [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * for a simple Markdown-it plugin example. * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * ## Exported members * - * - The **required** `plugin` key is the actual Markdown-It plugin - check the [official doc](https://github.com/markdown-it/markdown-it) for more information. The `options` parameter is of type [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml.ts), which contains a number of options, mostly useful for Joplin's internal code. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - Using the **optional** `assets` key you may specify assets such as JS or CSS that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - The **required** `plugin` key is the actual Markdown-It plugin - + * check the [official + * doc](https://github.com/markdown-it/markdown-it) for more + * information. The `options` parameter is of type + * [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts), + * which contains a number of options, mostly useful for Joplin's + * internal code. * - * To include a regular Markdown-It plugin, that doesn't make use of any Joplin-specific features, you would simply create a file such as this: + * - Using the **optional** `assets` key you may specify assets such as + * JS or CSS that should be loaded in the rendered HTML document. + * Check for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. + * + * ## Passing messages from the content script to your plugin + * + * The application provides the following function to allow executing + * commands from the rendered HTML code: + * + * `webviewApi.executeCommand(commandName, ...args)` + * + * So you can use this mechanism to pass messages from the note viewer + * to your own plugin. To do so you would define a command, using + * `joplin.commands.register`, then you would call this command using + * the `webviewApi` object. See again [the + * demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script) + * to see how this can be done. + * + * ## Registering an existing Markdown-it plugin + * + * To include a regular Markdown-It plugin, that doesn't make use of + * any Joplin-specific features, you would simply create a file such as + * this: * * ```javascript * module.exports = { @@ -367,7 +444,8 @@ export enum ContentScriptType { */ MarkdownItPlugin = 'markdownItPlugin', /** - * Registers a new CodeMirror plugin, which should follow the template below. + * Registers a new CodeMirror plugin, which should follow the template + * below. * * ```javascript * module.exports = { @@ -378,8 +456,8 @@ export enum ContentScriptType { * }, * codeMirrorResources: [], * codeMirrorOptions: { - * // ... - * }, + * // ... + * }, * assets: { * // ... * }, @@ -388,19 +466,42 @@ export enum ContentScriptType { * } * ``` * - * - The `context` argument is currently unused but could be used later on to provide access to your own plugin so that the content script and plugin can communicate. + * - The `context` argument is currently unused but could be used later + * on to provide access to your own plugin so that the content script + * and plugin can communicate. * - * - The `plugin` key is your CodeMirror plugin. This is where you can register new commands with CodeMirror or interact with the CodeMirror instance as needed. + * - The `plugin` key is your CodeMirror plugin. This is where you can + * register new commands with CodeMirror or interact with the + * CodeMirror instance as needed. * - * - The `codeMirrorResources` key is an array of CodeMirror resources that will be loaded and attached to the CodeMirror module. These are made up of addons, keymaps, and modes. For example, for a plugin that want's to enable clojure highlighting in code blocks. `codeMirrorResources` would be set to `['mode/clojure/clojure']`. + * - The `codeMirrorResources` key is an array of CodeMirror resources + * that will be loaded and attached to the CodeMirror module. These + * are made up of addons, keymaps, and modes. For example, for a + * plugin that want's to enable clojure highlighting in code blocks. + * `codeMirrorResources` would be set to `['mode/clojure/clojure']`. * - * - The `codeMirrorOptions` key contains all the [CodeMirror](https://codemirror.net/doc/manual.html#config) options that will be set or changed by this plugin. New options can alse be declared via [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), and then have their value set here. For example, a plugin that enables line numbers would set `codeMirrorOptions` to `{'lineNumbers': true}`. + * - The `codeMirrorOptions` key contains all the + * [CodeMirror](https://codemirror.net/doc/manual.html#config) + * options that will be set or changed by this plugin. New options + * can alse be declared via + * [`CodeMirror.defineOption`](https://codemirror.net/doc/manual.html#defineOption), + * and then have their value set here. For example, a plugin that + * enables line numbers would set `codeMirrorOptions` to + * `{'lineNumbers': true}`. * - * - Using the **optional** `assets` key you may specify **only** CSS assets that should be loaded in the rendered HTML document. Check for example the Joplin [Mermaid plugin](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/mermaid.ts) to see how the data should be structured. + * - Using the **optional** `assets` key you may specify **only** CSS + * assets that should be loaded in the rendered HTML document. Check + * for example the Joplin [Mermaid + * plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts) + * to see how the data should be structured. * - * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` keys must be provided for the plugin to be valid. Having multiple or all provided is also okay. + * One of the `plugin`, `codeMirrorResources`, or `codeMirrorOptions` + * keys must be provided for the plugin to be valid. Having multiple or + * all provided is also okay. * - * See the [demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) for an example of all these keys being used in one plugin. + * See the [demo + * plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script) + * for an example of all these keys being used in one plugin. */ CodeMirrorPlugin = 'codeMirrorPlugin', } diff --git a/packages/generator-joplin/package-lock.json b/packages/generator-joplin/package-lock.json index 14e1bd2c84..005e0b3492 100644 --- a/packages/generator-joplin/package-lock.json +++ b/packages/generator-joplin/package-lock.json @@ -1,6 +1,6 @@ { "name": "generator-joplin", - "version": "1.4.5", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/lib/services/plugins/api/types.ts b/packages/lib/services/plugins/api/types.ts index a4e18953fa..d14c63b49a 100644 --- a/packages/lib/services/plugins/api/types.ts +++ b/packages/lib/services/plugins/api/types.ts @@ -208,12 +208,49 @@ export enum MenuItemLocation { Note = 'note', Tools = 'tools', Help = 'help', + /** * @deprecated Do not use - same as NoteListContextMenu */ Context = 'context', + + // If adding an item here, don't forget to update isContextMenuItemLocation() + + /** + * When a command is called from the note list context menu, the + * command will receive the following arguments: + * + * - `noteIds:string[]`: IDs of the notes that were right-clicked on. + */ NoteListContextMenu = 'noteListContextMenu', + EditorContextMenu = 'editorContextMenu', + + /** + * When a command is called from a folder context menu, the + * command will receive the following arguments: + * + * - `folderId:string`: ID of the folder that was right-clicked on + */ + FolderContextMenu = 'folderContextMenu', + + /** + * When a command is called from a tag context menu, the + * command will receive the following arguments: + * + * - `tagId:string`: ID of the tag that was right-clicked on + */ + TagContextMenu = 'tagContextMenu', +} + +export function isContextMenuItemLocation(location: MenuItemLocation): boolean { + return [ + MenuItemLocation.Context, + MenuItemLocation.NoteListContextMenu, + MenuItemLocation.EditorContextMenu, + MenuItemLocation.FolderContextMenu, + MenuItemLocation.TagContextMenu, + ].includes(location); } export interface MenuItem {