From fa83d481412b5c1e0e31703c0159e73a3b60a7a4 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sat, 2 Mar 2024 07:53:10 -0800 Subject: [PATCH] Chore: Plugin generator: Update types (#10010) --- .../app/templates/api/JoplinData.d.ts | 2 +- .../app/templates/api/JoplinImaging.d.ts | 2 +- .../templates/api/JoplinViewsNoteList.d.ts | 23 ++++++++++-- .../app/templates/api/noteListType.d.ts | 10 ++--- .../app/templates/api/noteListType.ts | 11 +++--- .../generators/app/templates/api/types.ts | 37 +++++++++++++++++++ packages/lib/BaseSyncTarget.ts | 2 +- 7 files changed, 70 insertions(+), 17 deletions(-) diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinData.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinData.d.ts index 78d2ca5f1..026150a69 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinData.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinData.d.ts @@ -13,7 +13,7 @@ import { Path } from './types'; * 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. * And each method takes these parameters: * - * * `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. + * * `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. * * `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. * * `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. * * `files`: (Optional) Used to create new resources and associate them with files. diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinImaging.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinImaging.d.ts index ba43a310a..54574b7f6 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinImaging.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinImaging.d.ts @@ -36,7 +36,7 @@ export default class JoplinImaging { createFromResource(resourceId: string): Promise; getSize(handle: Handle): Promise; resize(handle: Handle, options?: ResizeOptions): Promise; - crop(handle: Handle, rectange: Rectangle): Promise; + crop(handle: Handle, rectangle: Rectangle): Promise; toPngFile(handle: Handle, filePath: string): Promise; /** * Quality is between 0 and 100 diff --git a/packages/generator-joplin/generators/app/templates/api/JoplinViewsNoteList.d.ts b/packages/generator-joplin/generators/app/templates/api/JoplinViewsNoteList.d.ts index c8efcff83..1afb284c8 100644 --- a/packages/generator-joplin/generators/app/templates/api/JoplinViewsNoteList.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/JoplinViewsNoteList.d.ts @@ -7,14 +7,29 @@ import { ListRenderer } from './noteListType'; * * The app provides the required dependencies whenever a note is updated - you * process these dependencies, and return some props, which are then passed to - * your template and rendered. See [[[ListRenderer]]] for a detailed description + * your template and rendered. See [[ListRenderer]] for a detailed description * of each property of the renderer. * - * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/note_list_renderer) + * ## Reference * - * The default list renderer is implemented using the same API, so it worth checking it too: + * * [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/note_list_renderer) + * + * * [Default list renderer](https://github.com/laurent22/joplin/tree/dev/packages/lib/services/noteList/defaultListRenderer.ts) + * + * ## Screenshots: + * + * ### Top to bottom with title, date and body + * + * + * + * ### Left to right with thumbnails + * + * + * + * ### Top to bottom with editable title + * + * * - * [Default list renderer](https://github.com/laurent22/joplin/tree/dev/packages/lib/services/noteList/defaultListRenderer.ts) */ export default class JoplinViewsNoteList { private plugin_; diff --git a/packages/generator-joplin/generators/app/templates/api/noteListType.d.ts b/packages/generator-joplin/generators/app/templates/api/noteListType.d.ts index 03c0bb3df..3c60081d5 100644 --- a/packages/generator-joplin/generators/app/templates/api/noteListType.d.ts +++ b/packages/generator-joplin/generators/app/templates/api/noteListType.d.ts @@ -1,5 +1,5 @@ import { Size } from './types'; -type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_'; +type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.deleted_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.deleted_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_'; export declare enum ItemFlow { TopToBottom = "topToBottom", LeftToRight = "leftToRight" @@ -32,7 +32,7 @@ export type OnChangeHandler = (event: OnChangeEvent) => Promise; * `note.isWatched` tells you if the note is currently opened in an external * editor. In which case you would generally display some indicator. */ -export type ListRendererDepependency = ListRendererDatabaseDependency | 'item.size.width' | 'item.size.height' | 'item.selected' | 'note.titleHtml' | 'note.isWatched' | 'note.tags'; +export type ListRendererDependency = ListRendererDatabaseDependency | 'item.index' | 'item.size.width' | 'item.size.height' | 'item.selected' | 'note.titleHtml' | 'note.isWatched' | 'note.tags'; export interface ListRenderer { /** * It must be unique to your plugin. @@ -47,7 +47,7 @@ export interface ListRenderer { /** * The size of each item must be specified in advance for performance * reasons, and cannot be changed afterwards. If the item flow is top to - * bottom, you only need to specificy the item height (the width will be + * bottom, you only need to specify the item height (the width will be * ignored). */ itemSize: Size; @@ -74,7 +74,7 @@ export interface ListRenderer { * that you do not add more than what you need since there is a performance * penalty for each property. */ - dependencies: ListRendererDepependency[]; + dependencies: ListRendererDependency[]; /** * This is the HTML template that will be used to render the note list item. * This is a [Mustache template](https://github.com/janl/mustache.js) and it @@ -128,7 +128,7 @@ export interface ListRenderer { */ onRenderNote: OnRenderNoteHandler; /** - * This handler allows adding some interacivity to the note renderer - + * This handler allows adding some interactivity to the note renderer - * whenever an input element within the item is changed (for example, when a * checkbox is clicked, or a text input is changed), this `onChange` handler * is going to be called. diff --git a/packages/generator-joplin/generators/app/templates/api/noteListType.ts b/packages/generator-joplin/generators/app/templates/api/noteListType.ts index 112999c9a..30aeb8351 100644 --- a/packages/generator-joplin/generators/app/templates/api/noteListType.ts +++ b/packages/generator-joplin/generators/app/templates/api/noteListType.ts @@ -3,7 +3,7 @@ import { Size } from './types'; // AUTO-GENERATED by generate-database-type -type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_'; +type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.deleted_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.deleted_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_'; // AUTO-GENERATED by generate-database-type export enum ItemFlow { @@ -42,8 +42,9 @@ export type OnChangeHandler = (event: OnChangeEvent)=> Promise; * `note.isWatched` tells you if the note is currently opened in an external * editor. In which case you would generally display some indicator. */ -export type ListRendererDepependency = +export type ListRendererDependency = ListRendererDatabaseDependency | + 'item.index' | 'item.size.width' | 'item.size.height' | 'item.selected' | @@ -67,7 +68,7 @@ export interface ListRenderer { /** * The size of each item must be specified in advance for performance * reasons, and cannot be changed afterwards. If the item flow is top to - * bottom, you only need to specificy the item height (the width will be + * bottom, you only need to specify the item height (the width will be * ignored). */ itemSize: Size; @@ -96,7 +97,7 @@ export interface ListRenderer { * that you do not add more than what you need since there is a performance * penalty for each property. */ - dependencies: ListRendererDepependency[]; + dependencies: ListRendererDependency[]; /** * This is the HTML template that will be used to render the note list item. @@ -154,7 +155,7 @@ export interface ListRenderer { onRenderNote: OnRenderNoteHandler; /** - * This handler allows adding some interacivity to the note renderer - + * This handler allows adding some interactivity to the note renderer - * whenever an input element within the item is changed (for example, when a * checkbox is clicked, or a text input is changed), this `onChange` handler * is going to be called. diff --git a/packages/generator-joplin/generators/app/templates/api/types.ts b/packages/generator-joplin/generators/app/templates/api/types.ts index 580df03cf..b2a474fb4 100644 --- a/packages/generator-joplin/generators/app/templates/api/types.ts +++ b/packages/generator-joplin/generators/app/templates/api/types.ts @@ -533,6 +533,43 @@ export interface MarkdownItContentScriptModule extends Omit any; } +type EditorCommandCallback = (...args: any[])=> any; + +export interface CodeMirrorControl { + /** Points to a CodeMirror 6 EditorView instance. */ + editor: any; + cm6: any; + + /** `extension` should be a [CodeMirror 6 extension](https://codemirror.net/docs/ref/#state.Extension). */ + addExtension(extension: any|any[]): void; + + supportsCommand(name: string): boolean; + execCommand(name: string, ...args: any[]): any; + registerCommand(name: string, callback: EditorCommandCallback): void; + + joplinExtensions: { + /** + * Returns a [CodeMirror 6 extension](https://codemirror.net/docs/ref/#state.Extension) that + * registers the given [CompletionSource](https://codemirror.net/docs/ref/#autocomplete.CompletionSource). + * + * Use this extension rather than the built-in CodeMirror [`autocompletion`](https://codemirror.net/docs/ref/#autocomplete.autocompletion) + * if you don't want to use [languageData-based autocompletion](https://codemirror.net/docs/ref/#autocomplete.autocompletion^config.override). + * + * Using `autocompletion({ override: [ ... ]})` causes errors when done by multiple plugins. + */ + completionSource(completionSource: any): any; + + /** + * Creates an extension that enables or disables [`languageData`-based autocompletion](https://codemirror.net/docs/ref/#autocomplete.autocompletion^config.override). + */ + enableLanguageDataAutocomplete: { of: (enabled: boolean)=> any }; + }; +} + +export interface CodeMirrorContentScriptModule extends Omit { + plugin: (codeMirrorControl: CodeMirrorControl)=> void; +} + export enum ContentScriptType { /** * Registers a new Markdown-It plugin, which should follow the template diff --git a/packages/lib/BaseSyncTarget.ts b/packages/lib/BaseSyncTarget.ts index 5ca6503e9..66b1ba5b5 100644 --- a/packages/lib/BaseSyncTarget.ts +++ b/packages/lib/BaseSyncTarget.ts @@ -5,7 +5,7 @@ import shim from './shim'; import ResourceService from './services/ResourceService'; import ShareService from './services/share/ShareService'; -interface CheckConfigResult { +export interface CheckConfigResult { ok: boolean; errorMessage: string; }