Skip to content

Commit a3f09ed

Browse files
committed
Initial commit
0 parents  commit a3f09ed

35 files changed

+12545
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
node_modules/
3+
publish/

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.md
2+
!README.md
3+
/*.jpl
4+
/api
5+
/src
6+
/dist
7+
tsconfig.json
8+
webpack.config.js

GENERATOR_DOC.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Plugin development
2+
3+
This documentation describes how to create a plugin, and how to work with the plugin builder framework and API.
4+
5+
## Installation
6+
7+
First, install [Yeoman](http://yeoman.io) and generator-joplin using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).
8+
9+
```bash
10+
npm install -g yo@4.3.1
11+
npm install -g generator-joplin
12+
```
13+
14+
Then generate your new project:
15+
16+
```bash
17+
yo --node-package-manager npm joplin
18+
```
19+
20+
## Structure
21+
22+
The main two files you will want to look at are:
23+
24+
- `/src/index.ts`, which contains the entry point for the plugin source code.
25+
- `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc.
26+
27+
The file `/plugin.config.json` could also be useful if you intend to use [external scripts](#external-script-files), such as content scripts or webview scripts.
28+
29+
## Building the plugin
30+
31+
The plugin is built using Webpack, which creates the compiled code in `/dist`. A JPL archive will also be created at the root, which can use to distribute the plugin.
32+
33+
To build the plugin, simply run `npm run dist`.
34+
35+
The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
36+
37+
## Updating the manifest version number
38+
39+
You can run `npm run updateVersion` to bump the patch part of the version number, so for example 1.0.3 will become 1.0.4. This script will update both the package.json and manifest.json version numbers so as to keep them in sync.
40+
41+
## Publishing the plugin
42+
43+
To publish the plugin, add it to npmjs.com by running `npm publish`. Later on, a script will pick up your plugin and add it automatically to the Joplin plugin repository as long as the package satisfies these conditions:
44+
45+
- In `package.json`, the name starts with "joplin-plugin-". For example, "joplin-plugin-toc".
46+
- In `package.json`, the keywords include "joplin-plugin".
47+
- In the `publish/` directory, there should be a .jpl and .json file (which are built by `npm run dist`)
48+
49+
In general all this is done automatically by the plugin generator, which will set the name and keywords of package.json, and will put the right files in the "publish" directory. But if something doesn't work and your plugin doesn't appear in the repository, double-check the above conditions.
50+
51+
## Updating the plugin framework
52+
53+
To update the plugin framework, run `npm run update`.
54+
55+
In general this command tries to do the right thing - in particular it's going to merge the changes in package.json and .gitignore instead of overwriting. It will also leave "/src" as well as README.md untouched.
56+
57+
The file that may cause problem is "webpack.config.js" because it's going to be overwritten. For that reason, if you want to change it, consider creating a separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file.
58+
59+
## External script files
60+
61+
By default, the compiler (webpack) is going to compile `src/index.ts` only (as well as any file it imports), and any other file will simply be copied to the plugin package. In some cases this is sufficient, however if you have [content scripts](https://joplinapp.org/api/references/plugin_api/classes/joplincontentscripts.html) or [webview scripts](https://joplinapp.org/api/references/plugin_api/classes/joplinviewspanels.html#addscript) you might want to compile them too, in particular in these two cases:
62+
63+
- The script is a TypeScript file - in which case it has to be compiled to JavaScript.
64+
65+
- The script requires modules you've added to package.json. In that case, the script, whether JS or TS, must be compiled so that the dependencies are bundled with the JPL file.
66+
67+
To get such an external script file to compile, you need to add it to the `extraScripts` array in `plugin.config.json`. The path you add should be relative to /src. For example, if you have a file in "/src/webviews/index.ts", the path should be set to "webviews/index.ts". Once compiled, the file will always be named with a .js extension. So you will get "webviews/index.js" in the plugin package, and that's the path you should use to reference the file.
68+
69+
## More information
70+
71+
- [Joplin Plugin API](https://joplinapp.org/api/references/plugin_api/classes/joplin.html)
72+
- [Joplin Data API](https://joplinapp.org/help/api/references/rest_api)
73+
- [Joplin Plugin Manifest](https://joplinapp.org/api/references/plugin_manifest/)
74+
- Ask for help on the [forum](https://discourse.joplinapp.org/) or our [Discord channel](https://discord.gg/VSj7AFHvpq)
75+
76+
## License
77+
78+
MIT © Laurent Cozic

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Joplin Plugin
2+
3+
This is your new Joplin plugin. It is suggested that you use this README file to document your plugin.
4+
5+
For information on how to build or publish the plugin, please see [GENERATOR_DOC.md](./GENERATOR_DOC.md)

api/Global.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Plugin from '../Plugin';
2+
import Joplin from './Joplin';
3+
/**
4+
* @ignore
5+
*/
6+
/**
7+
* @ignore
8+
*/
9+
export default class Global {
10+
private joplin_;
11+
constructor(implementation: any, plugin: Plugin, store: any);
12+
get joplin(): Joplin;
13+
get process(): any;
14+
}

api/Joplin.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import Plugin from '../Plugin';
2+
import JoplinData from './JoplinData';
3+
import JoplinPlugins from './JoplinPlugins';
4+
import JoplinWorkspace from './JoplinWorkspace';
5+
import JoplinFilters from './JoplinFilters';
6+
import JoplinCommands from './JoplinCommands';
7+
import JoplinViews from './JoplinViews';
8+
import JoplinInterop from './JoplinInterop';
9+
import JoplinSettings from './JoplinSettings';
10+
import JoplinContentScripts from './JoplinContentScripts';
11+
import JoplinClipboard from './JoplinClipboard';
12+
import JoplinWindow from './JoplinWindow';
13+
import BasePlatformImplementation from '../BasePlatformImplementation';
14+
import JoplinImaging from './JoplinImaging';
15+
/**
16+
* This is the main entry point to the Joplin API. You can access various services using the provided accessors.
17+
*
18+
* The API is now relatively stable and in general maintaining backward compatibility is a top priority, so you shouldn't except much breakages.
19+
*
20+
* If a breaking change ever becomes needed, best effort will be done to:
21+
*
22+
* - Deprecate features instead of removing them, so as to give you time to fix the issue;
23+
* - Document breaking changes in the changelog;
24+
*
25+
* So if you are developing a plugin, please keep an eye on the changelog as everything will be in there with information about how to update your code.
26+
*/
27+
export default class Joplin {
28+
private data_;
29+
private plugins_;
30+
private imaging_;
31+
private workspace_;
32+
private filters_;
33+
private commands_;
34+
private views_;
35+
private interop_;
36+
private settings_;
37+
private contentScripts_;
38+
private clipboard_;
39+
private window_;
40+
private implementation_;
41+
constructor(implementation: BasePlatformImplementation, plugin: Plugin, store: any);
42+
get data(): JoplinData;
43+
get clipboard(): JoplinClipboard;
44+
get imaging(): JoplinImaging;
45+
get window(): JoplinWindow;
46+
get plugins(): JoplinPlugins;
47+
get workspace(): JoplinWorkspace;
48+
get contentScripts(): JoplinContentScripts;
49+
/**
50+
* @ignore
51+
*
52+
* Not sure if it's the best way to hook into the app
53+
* so for now disable filters.
54+
*/
55+
get filters(): JoplinFilters;
56+
get commands(): JoplinCommands;
57+
get views(): JoplinViews;
58+
get interop(): JoplinInterop;
59+
get settings(): JoplinSettings;
60+
/**
61+
* It is not possible to bundle native packages with a plugin, because they
62+
* need to work cross-platforms. Instead access to certain useful native
63+
* packages is provided using this function.
64+
*
65+
* Currently these packages are available:
66+
*
67+
* - [sqlite3](https://www.npmjs.com/package/sqlite3)
68+
* - [fs-extra](https://www.npmjs.com/package/fs-extra)
69+
*
70+
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/nativeModule)
71+
*/
72+
require(_path: string): any;
73+
versionInfo(): Promise<import("./types").VersionInfo>;
74+
}

api/JoplinClipboard.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default class JoplinClipboard {
2+
private electronClipboard_;
3+
private electronNativeImage_;
4+
constructor(electronClipboard: any, electronNativeImage: any);
5+
readText(): Promise<string>;
6+
writeText(text: string): Promise<void>;
7+
readHtml(): Promise<string>;
8+
writeHtml(html: string): Promise<void>;
9+
/**
10+
* Returns the image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
11+
*/
12+
readImage(): Promise<string>;
13+
/**
14+
* Takes an image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
15+
*/
16+
writeImage(dataUrl: string): Promise<void>;
17+
/**
18+
* Returns the list available formats (mime types).
19+
*
20+
* For example [ 'text/plain', 'text/html' ]
21+
*/
22+
availableFormats(): Promise<string[]>;
23+
}

api/JoplinCommands.d.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Command } from './types';
2+
/**
3+
* This class allows executing or registering new Joplin commands. Commands
4+
* can be executed or associated with
5+
* {@link JoplinViewsToolbarButtons | toolbar buttons} or
6+
* {@link JoplinViewsMenuItems | menu items}.
7+
*
8+
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command)
9+
*
10+
* ## Executing Joplin's internal commands
11+
*
12+
* It is also possible to execute internal Joplin's commands which, as of
13+
* now, are not well documented. You can find the list directly on GitHub
14+
* though at the following locations:
15+
*
16+
* * [Main screen commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands)
17+
* * [Global commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/commands)
18+
* * [Editor commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.ts)
19+
*
20+
* To view what arguments are supported, you can open any of these files
21+
* and look at the `execute()` command.
22+
*
23+
* ## Executing editor commands
24+
*
25+
* There might be a situation where you want to invoke editor commands
26+
* without using a {@link JoplinContentScripts | contentScript}. For this
27+
* reason Joplin provides the built in `editor.execCommand` command.
28+
*
29+
* `editor.execCommand` should work with any core command in both the
30+
* [CodeMirror](https://codemirror.net/doc/manual.html#execCommand) and
31+
* [TinyMCE](https://www.tiny.cloud/docs/api/tinymce/tinymce.editorcommands/#execcommand) editors,
32+
* as well as most functions calls directly on a CodeMirror editor object (extensions).
33+
*
34+
* * [CodeMirror commands](https://codemirror.net/doc/manual.html#commands)
35+
* * [TinyMCE core editor commands](https://www.tiny.cloud/docs/advanced/editor-command-identifiers/#coreeditorcommands)
36+
*
37+
* `editor.execCommand` supports adding arguments for the commands.
38+
*
39+
* ```typescript
40+
* await joplin.commands.execute('editor.execCommand', {
41+
* name: 'madeUpCommand', // CodeMirror and TinyMCE
42+
* args: [], // CodeMirror and TinyMCE
43+
* ui: false, // TinyMCE only
44+
* value: '', // TinyMCE only
45+
* });
46+
* ```
47+
*
48+
* [View the example using the CodeMirror editor](https://github.com/laurent22/joplin/blob/dev/packages/app-cli/tests/support/plugins/codemirror_content_script/src/index.ts)
49+
*
50+
*/
51+
export default class JoplinCommands {
52+
/**
53+
* <span class="platform-desktop">desktop</span> Executes the given
54+
* command.
55+
*
56+
* The command can take any number of arguments, and the supported
57+
* arguments will vary based on the command. For custom commands, this
58+
* is the `args` passed to the `execute()` function. For built-in
59+
* commands, you can find the supported arguments by checking the links
60+
* above.
61+
*
62+
* ```typescript
63+
* // Create a new note in the current notebook:
64+
* await joplin.commands.execute('newNote');
65+
*
66+
* // Create a new sub-notebook under the provided notebook
67+
* // Note: internally, notebooks are called "folders".
68+
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
69+
* ```
70+
*/
71+
execute(commandName: string, ...args: any[]): Promise<any | void>;
72+
/**
73+
* <span class="platform-desktop">desktop</span> Registers a new command.
74+
*
75+
* ```typescript
76+
* // Register a new commmand called "testCommand1"
77+
*
78+
* await joplin.commands.register({
79+
* name: 'testCommand1',
80+
* label: 'My Test Command 1',
81+
* iconName: 'fas fa-music',
82+
* execute: () => {
83+
* alert('Testing plugin command 1');
84+
* },
85+
* });
86+
* ```
87+
*/
88+
register(command: Command): Promise<void>;
89+
}

api/JoplinContentScripts.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Plugin from '../Plugin';
2+
import { ContentScriptType } from './types';
3+
export default class JoplinContentScripts {
4+
private plugin;
5+
constructor(plugin: Plugin);
6+
/**
7+
* Registers a new content script. Unlike regular plugin code, which runs in
8+
* a separate process, content scripts run within the main process code and
9+
* thus allow improved performances and more customisations in specific
10+
* cases. It can be used for example to load a Markdown or editor plugin.
11+
*
12+
* Note that registering a content script in itself will do nothing - it
13+
* will only be loaded in specific cases by the relevant app modules (eg.
14+
* the Markdown renderer or the code editor). So it is not a way to inject
15+
* and run arbitrary code in the app, which for safety and performance
16+
* reasons is not supported.
17+
*
18+
* The plugin generator provides a way to build any content script you might
19+
* want to package as well as its dependencies. See the [Plugin Generator
20+
* doc](https://github.com/laurent22/joplin/blob/dev/packages/generator-joplin/README.md)
21+
* for more information.
22+
*
23+
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
24+
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
25+
*
26+
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
27+
*
28+
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
29+
* @param id A unique ID for the content script.
30+
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
31+
*/
32+
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
33+
/**
34+
* Listens to a messages sent from the content script using postMessage().
35+
* See {@link ContentScriptType} for more information as well as the
36+
* [postMessage
37+
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
38+
*/
39+
onMessage(contentScriptId: string, callback: any): Promise<void>;
40+
}

0 commit comments

Comments
 (0)