Skip to content

Commit fe7b59c

Browse files
LightLight
Light
authored and
Light
committed
feat: Add copy button
0 parents  commit fe7b59c

35 files changed

+13118
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
node_modules/
3+
publish/

.npmignore

+8
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

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# generator-joplin
2+
3+
Scaffolds out a new Joplin plugin
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
11+
npm install -g generator-joplin
12+
```
13+
14+
Then generate your new project:
15+
16+
```bash
17+
yo joplin
18+
```
19+
20+
## Development
21+
22+
To test the generator for development purposes, follow the instructions there: https://yeoman.io/authoring/#running-the-generator
23+
This is a template to create a new Joplin plugin.
24+
25+
## Structure
26+
27+
The main two files you will want to look at are:
28+
29+
- `/src/index.ts`, which contains the entry point for the plugin source code.
30+
- `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc.
31+
32+
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.
33+
34+
## Building the plugin
35+
36+
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.
37+
38+
To build the plugin, simply run `npm run dist`.
39+
40+
The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
41+
42+
## Publishing the plugin
43+
44+
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:
45+
46+
- In `package.json`, the name starts with "joplin-plugin-". For example, "joplin-plugin-toc".
47+
- In `package.json`, the keywords include "joplin-plugin".
48+
- In the `publish/` directory, there should be a .jpl and .json file (which are built by `npm run dist`)
49+
50+
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.
51+
52+
## Updating the plugin framework
53+
54+
To update the plugin framework, run `npm run update`.
55+
56+
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.
57+
58+
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.
59+
60+
## External script files
61+
62+
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:
63+
64+
- The script is a TypeScript file - in which case it has to be compiled to JavaScript.
65+
66+
- 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.
67+
68+
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.
69+
70+
## License
71+
72+
MIT © Laurent Cozic

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Light
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Joplin Plugin
2+
3+
This is a template to create a new Joplin plugin.
4+
5+
The main two files you will want to look at are:
6+
7+
- `/src/index.ts`, which contains the entry point for the plugin source code.
8+
- `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc.
9+
10+
## Building the plugin
11+
12+
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.
13+
14+
To build the plugin, simply run `npm run dist`.
15+
16+
The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript.
17+
18+
## Updating the plugin framework
19+
20+
To update the plugin framework, run `npm run update`.
21+
22+
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.
23+
24+
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.

api/Global.d.ts

+14
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

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

api/JoplinClipboard.d.ts

+23
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

+89
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

+40
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)