Skip to content

Commit 6712030

Browse files
authored
Add mobile support
2 parents 08bdfaa + 2d6349f commit 6712030

32 files changed

+1570
-208
lines changed

api/Joplin.d.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import JoplinSettings from './JoplinSettings';
1010
import JoplinContentScripts from './JoplinContentScripts';
1111
import JoplinClipboard from './JoplinClipboard';
1212
import JoplinWindow from './JoplinWindow';
13+
import BasePlatformImplementation from '../BasePlatformImplementation';
14+
import JoplinImaging from './JoplinImaging';
1315
/**
1416
* This is the main entry point to the Joplin API. You can access various services using the provided accessors.
1517
*
16-
* **This is a beta API**
18+
* The API is now relatively stable and in general maintaining backward compatibility is a top priority, so you shouldn't except much breakages.
1719
*
18-
* Please note that the plugin API is relatively new and should be considered Beta state. Besides possible bugs, what it means is that there might be necessary breaking changes from one version to the next. Whenever such change is needed, best effort will be done to:
20+
* If a breaking change ever becomes needed, best effort will be done to:
1921
*
20-
* - Maintain backward compatibility;
21-
* - When possible, deprecate features instead of removing them;
22+
* - Deprecate features instead of removing them, so as to give you time to fix the issue;
2223
* - Document breaking changes in the changelog;
2324
*
24-
* 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. There won't be any major API rewrite or architecture changes, but possibly small tweaks like function signature change, type change, etc.
25-
*
26-
* Eventually, the plugin API will be versioned to make this process smoother.
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.
2726
*/
2827
export default class Joplin {
2928
private data_;
3029
private plugins_;
30+
private imaging_;
3131
private workspace_;
3232
private filters_;
3333
private commands_;
@@ -37,9 +37,11 @@ export default class Joplin {
3737
private contentScripts_;
3838
private clipboard_;
3939
private window_;
40-
constructor(implementation: any, plugin: Plugin, store: any);
40+
private implementation_;
41+
constructor(implementation: BasePlatformImplementation, plugin: Plugin, store: any);
4142
get data(): JoplinData;
4243
get clipboard(): JoplinClipboard;
44+
get imaging(): JoplinImaging;
4345
get window(): JoplinWindow;
4446
get plugins(): JoplinPlugins;
4547
get workspace(): JoplinWorkspace;
@@ -66,6 +68,9 @@ export default class Joplin {
6668
* - [fs-extra](https://www.npmjs.com/package/fs-extra)
6769
*
6870
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/nativeModule)
71+
*
72+
* <span class="platform-desktop">desktop</span>
6973
*/
7074
require(_path: string): any;
75+
versionInfo(): Promise<import("./types").VersionInfo>;
7176
}

api/JoplinClipboard.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ export default class JoplinClipboard {
44
constructor(electronClipboard: any, electronNativeImage: any);
55
readText(): Promise<string>;
66
writeText(text: string): Promise<void>;
7+
/** <span class="platform-desktop">desktop</span> */
78
readHtml(): Promise<string>;
9+
/** <span class="platform-desktop">desktop</span> */
810
writeHtml(html: string): Promise<void>;
911
/**
1012
* Returns the image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
13+
*
14+
* <span class="platform-desktop">desktop</span>
1115
*/
1216
readImage(): Promise<string>;
1317
/**
1418
* Takes an image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
19+
*
20+
* <span class="platform-desktop">desktop</span>
1521
*/
1622
writeImage(dataUrl: string): Promise<void>;
1723
/**

api/JoplinCommands.d.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from './types';
2+
import Plugin from '../Plugin';
23
/**
34
* This class allows executing or registering new Joplin commands. Commands
45
* can be executed or associated with
@@ -15,11 +16,17 @@ import { Command } from './types';
1516
*
1617
* * [Main screen commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands)
1718
* * [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/commands/editorCommandDeclarations.ts)
19+
* * [Editor commands](https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.ts)
1920
*
2021
* To view what arguments are supported, you can open any of these files
2122
* and look at the `execute()` command.
2223
*
24+
* Note that many of these commands only work on desktop. The more limited list of mobile
25+
* commands can be found in these places:
26+
*
27+
* * [Global commands](https://github.com/laurent22/joplin/tree/dev/packages/app-mobile/commands)
28+
* * [Editor commands](https://github.com/laurent22/joplin/blob/dev/packages/app-mobile/components/NoteEditor/commandDeclarations.ts)
29+
*
2330
* ## Executing editor commands
2431
*
2532
* There might be a situation where you want to invoke editor commands
@@ -49,9 +56,10 @@ import { Command } from './types';
4956
*
5057
*/
5158
export default class JoplinCommands {
52-
/**
53-
* <span class="platform-desktop">desktop</span> Executes the given
54-
* command.
59+
private plugin_;
60+
constructor(plugin_: Plugin);
61+
/**
62+
* Executes the given command.
5563
*
5664
* The command can take any number of arguments, and the supported
5765
* arguments will vary based on the command. For custom commands, this
@@ -68,9 +76,9 @@ export default class JoplinCommands {
6876
* await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");
6977
* ```
7078
*/
71-
execute(commandName: string, ...args: any[]): Promise<any | void>;
72-
/**
73-
* <span class="platform-desktop">desktop</span> Registers a new command.
79+
execute(commandName: string, ...args: any[]): Promise<any | void>;
80+
/**
81+
* Registers a new command.
7482
*
7583
* ```typescript
7684
* // Register a new commmand called "testCommand1"
@@ -85,5 +93,5 @@ export default class JoplinCommands {
8593
* });
8694
* ```
8795
*/
88-
register(command: Command): Promise<void>;
96+
register(command: Command): Promise<void>;
8997
}

api/JoplinContentScripts.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default class JoplinContentScripts {
2121
* for more information.
2222
*
2323
* * [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)
24+
* * [View the editor plugin tutorial](https://joplinapp.org/help/api/tutorials/cm6_plugin)
25+
* * [View the legacy editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
2526
*
2627
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
2728
*

api/JoplinData.d.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { ModelType } from '../../../BaseModel';
2+
import Plugin from '../Plugin';
13
import { Path } from './types';
24
/**
3-
* This module provides access to the Joplin data API: https://joplinapp.org/api/references/rest_api/
5+
* This module provides access to the Joplin data API: https://joplinapp.org/help/api/references/rest_api
46
* This is the main way to retrieve data, such as notes, notebooks, tags, etc.
57
* or to update them or delete them.
68
*
@@ -11,12 +13,12 @@ import { Path } from './types';
1113
* In general you would use the methods in this class as if you were using a REST API. There are four methods that map to GET, POST, PUT and DELETE calls.
1214
* And each method takes these parameters:
1315
*
14-
* * `path`: This is an array that represents the path to the resource in the form `["resouceName", "resourceId", "resourceLink"]` (eg. ["tags", ":id", "notes"]). The "resources" segment is the name of the resources you want to access (eg. "notes", "folders", etc.). If not followed by anything, it will refer to all the resources in that collection. The optional "resourceId" points to a particular resources within the collection. Finally, an optional "link" can be present, which links the resource to a collection of resources. This can be used in the API for example to retrieve all the notes associated with a tag.
16+
* * `path`: This is an array that represents the path to the resource in the form `["resourceName", "resourceId", "resourceLink"]` (eg. ["tags", ":id", "notes"]). The "resources" segment is the name of the resources you want to access (eg. "notes", "folders", etc.). If not followed by anything, it will refer to all the resources in that collection. The optional "resourceId" points to a particular resources within the collection. Finally, an optional "link" can be present, which links the resource to a collection of resources. This can be used in the API for example to retrieve all the notes associated with a tag.
1517
* * `query`: (Optional) The query parameters. In a URL, this is the part after the question mark "?". In this case, it should be an object with key/value pairs.
1618
* * `data`: (Optional) Applies to PUT and POST calls only. The request body contains the data you want to create or modify, for example the content of a note or folder.
1719
* * `files`: (Optional) Used to create new resources and associate them with files.
1820
*
19-
* Please refer to the [Joplin API documentation](https://joplinapp.org/api/references/rest_api/) for complete details about each call. As the plugin runs within the Joplin application **you do not need an authorisation token** to use this API.
21+
* Please refer to the [Joplin API documentation](https://joplinapp.org/help/api/references/rest_api) for complete details about each call. As the plugin runs within the Joplin application **you do not need an authorisation token** to use this API.
2022
*
2123
* For example:
2224
*
@@ -38,10 +40,34 @@ import { Path } from './types';
3840
export default class JoplinData {
3941
private api_;
4042
private pathSegmentRegex_;
43+
private plugin;
44+
constructor(plugin: Plugin);
4145
private serializeApiBody;
4246
private pathToString;
4347
get(path: Path, query?: any): Promise<any>;
4448
post(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
4549
put(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
4650
delete(path: Path, query?: any): Promise<any>;
51+
itemType(itemId: string): Promise<ModelType>;
52+
resourcePath(resourceId: string): Promise<string>;
53+
/**
54+
* Gets an item user data. User data are key/value pairs. The `key` can be any
55+
* arbitrary string, while the `value` can be of any type supported by
56+
* [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description)
57+
*
58+
* User data is synchronised across devices, and each value wil be merged based on their timestamp:
59+
*
60+
* - If value is modified by client 1, then modified by client 2, it will take the value from client 2
61+
* - If value is modified by client 1, then deleted by client 2, the value will be deleted after merge
62+
* - If value is deleted by client 1, then updated by client 2, the value will be restored and set to the value from client 2 after merge
63+
*/
64+
userDataGet<T>(itemType: ModelType, itemId: string, key: string): Promise<T>;
65+
/**
66+
* Sets a note user data. See {@link JoplinData.userDataGet} for more details.
67+
*/
68+
userDataSet<T>(itemType: ModelType, itemId: string, key: string, value: T): Promise<void>;
69+
/**
70+
* Deletes a note user data. See {@link JoplinData.userDataGet} for more details.
71+
*/
72+
userDataDelete(itemType: ModelType, itemId: string, key: string): Promise<void>;
4773
}

api/JoplinFilters.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { FilterHandler } from '../../../eventManager';
12
/**
23
* @ignore
34
*
45
* Not sure if it's the best way to hook into the app
56
* so for now disable filters.
67
*/
78
export default class JoplinFilters {
8-
on(name: string, callback: Function): Promise<void>;
9-
off(name: string, callback: Function): Promise<void>;
9+
on(name: string, callback: FilterHandler): Promise<void>;
10+
off(name: string, callback: FilterHandler): Promise<void>;
1011
}

api/JoplinImaging.d.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Rectangle } from './types';
2+
export interface CreateFromBufferOptions {
3+
width?: number;
4+
height?: number;
5+
scaleFactor?: number;
6+
}
7+
export interface CreateFromPdfOptions {
8+
/**
9+
* The first page to export. Defaults to `1`, the first page in
10+
* the document.
11+
*/
12+
minPage?: number;
13+
/**
14+
* The number of the last page to convert. Defaults to the last page
15+
* if not given.
16+
*
17+
* If `maxPage` is greater than the number of pages in the PDF, all pages
18+
* in the PDF will be converted to images.
19+
*/
20+
maxPage?: number;
21+
scaleFactor?: number;
22+
}
23+
export interface PdfInfo {
24+
pageCount: number;
25+
}
26+
export interface Implementation {
27+
createFromPath: (path: string) => Promise<unknown>;
28+
createFromPdf: (path: string, options: CreateFromPdfOptions) => Promise<unknown[]>;
29+
getPdfInfo: (path: string) => Promise<PdfInfo>;
30+
}
31+
export interface ResizeOptions {
32+
width?: number;
33+
height?: number;
34+
quality?: 'good' | 'better' | 'best';
35+
}
36+
export type Handle = string;
37+
/**
38+
* Provides imaging functions to resize or process images. You create an image
39+
* using one of the `createFrom` functions, then use the other functions to
40+
* process the image.
41+
*
42+
* Images are associated with a handle which is what will be available to the
43+
* plugin. Once you are done with an image, free it using the `free()` function.
44+
*
45+
* [View the
46+
* example](https://github.com/laurent22/joplin/blob/dev/packages/app-cli/tests/support/plugins/imaging/src/index.ts)
47+
*
48+
* <span class="platform-desktop">desktop</span>
49+
*/
50+
export default class JoplinImaging {
51+
private implementation_;
52+
private images_;
53+
constructor(implementation: Implementation);
54+
private createImageHandle;
55+
private imageByHandle;
56+
private cacheImage;
57+
/**
58+
* Creates an image from the provided path. Note that images and PDFs are supported. If you
59+
* provide a URL instead of a local path, the file will be downloaded first then converted to an
60+
* image.
61+
*/
62+
createFromPath(filePath: string): Promise<Handle>;
63+
createFromResource(resourceId: string): Promise<Handle>;
64+
createFromPdfPath(path: string, options?: CreateFromPdfOptions): Promise<Handle[]>;
65+
createFromPdfResource(resourceId: string, options?: CreateFromPdfOptions): Promise<Handle[]>;
66+
getPdfInfoFromPath(path: string): Promise<PdfInfo>;
67+
getPdfInfoFromResource(resourceId: string): Promise<PdfInfo>;
68+
getSize(handle: Handle): Promise<any>;
69+
resize(handle: Handle, options?: ResizeOptions): Promise<string>;
70+
crop(handle: Handle, rectangle: Rectangle): Promise<string>;
71+
toPngFile(handle: Handle, filePath: string): Promise<void>;
72+
/**
73+
* Quality is between 0 and 100
74+
*/
75+
toJpgFile(handle: Handle, filePath: string, quality?: number): Promise<void>;
76+
private tempFilePath;
77+
/**
78+
* Creates a new Joplin resource from the image data. The image will be
79+
* first converted to a JPEG.
80+
*/
81+
toJpgResource(handle: Handle, resourceProps: any, quality?: number): Promise<import("../../database/types").ResourceEntity>;
82+
/**
83+
* Creates a new Joplin resource from the image data. The image will be
84+
* first converted to a PNG.
85+
*/
86+
toPngResource(handle: Handle, resourceProps: any): Promise<import("../../database/types").ResourceEntity>;
87+
/**
88+
* Image data is not automatically deleted by Joplin so make sure you call
89+
* this method on the handle once you are done.
90+
*/
91+
free(handles: Handle[] | Handle): Promise<void>;
92+
}

api/JoplinInterop.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { ExportModule, ImportModule } from './types';
99
*
1010
* See the documentation of the [[ExportModule]] and [[ImportModule]] for more information.
1111
*
12-
* You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/api/references/rest_api/
12+
* You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/help/api/references/rest_api
13+
*
14+
* <span class="platform-desktop">desktop</span>: While it is possible to register import and export
15+
* modules on mobile, there is no GUI to activate them.
1316
*/
1417
export default class JoplinInterop {
15-
registerExportModule(module: ExportModule): Promise<void>;
16-
registerImportModule(module: ImportModule): Promise<void>;
18+
registerExportModule(module: ExportModule): Promise<void>;
19+
registerImportModule(module: ImportModule): Promise<void>;
1720
}

api/JoplinSettings.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ChangeEvent {
66
*/
77
keys: string[];
88
}
9-
export declare type ChangeHandler = (event: ChangeEvent)=> void;
9+
export type ChangeHandler = (event: ChangeEvent) => void;
1010
/**
1111
* This API allows registering new settings and setting sections, as well as getting and setting settings. Once a setting has been registered it will appear in the config screen and be editable by the user.
1212
*
@@ -19,8 +19,6 @@ export declare type ChangeHandler = (event: ChangeEvent)=> void;
1919
export default class JoplinSettings {
2020
private plugin_;
2121
constructor(plugin: Plugin);
22-
private get keyPrefix();
23-
private namespacedKey;
2422
/**
2523
* Registers new settings.
2624
* Note that registering a setting item is dynamic and will be gone next time Joplin starts.
@@ -40,6 +38,12 @@ export default class JoplinSettings {
4038
*/
4139
registerSection(name: string, section: SettingSection): Promise<void>;
4240
/**
41+
* Gets setting values (only applies to setting you registered from your plugin)
42+
*/
43+
values(keys: string[] | string): Promise<Record<string, unknown>>;
44+
/**
45+
* @deprecated Use joplin.settings.values()
46+
*
4347
* Gets a setting value (only applies to setting you registered from your plugin)
4448
*/
4549
value(key: string): Promise<any>;

api/JoplinViews.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import JoplinViewsMenuItems from './JoplinViewsMenuItems';
44
import JoplinViewsMenus from './JoplinViewsMenus';
55
import JoplinViewsToolbarButtons from './JoplinViewsToolbarButtons';
66
import JoplinViewsPanels from './JoplinViewsPanels';
7+
import JoplinViewsNoteList from './JoplinViewsNoteList';
8+
import JoplinViewsEditors from './JoplinViewsEditor';
79
/**
810
* This namespace provides access to view-related services.
911
*
@@ -13,16 +15,20 @@ import JoplinViewsPanels from './JoplinViewsPanels';
1315
export default class JoplinViews {
1416
private store;
1517
private plugin;
16-
private dialogs_;
1718
private panels_;
1819
private menuItems_;
1920
private menus_;
2021
private toolbarButtons_;
22+
private dialogs_;
23+
private editors_;
24+
private noteList_;
2125
private implementation_;
2226
constructor(implementation: any, plugin: Plugin, store: any);
2327
get dialogs(): JoplinViewsDialogs;
2428
get panels(): JoplinViewsPanels;
29+
get editors(): JoplinViewsEditors;
2530
get menuItems(): JoplinViewsMenuItems;
2631
get menus(): JoplinViewsMenus;
2732
get toolbarButtons(): JoplinViewsToolbarButtons;
33+
get noteList(): JoplinViewsNoteList;
2834
}

0 commit comments

Comments
 (0)