1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Expose prompt to plugins as a command (#5058)

This commit is contained in:
Nishant Mittal 2021-06-10 16:26:16 -07:00 committed by GitHub
parent 01e6ca4616
commit c5c38a323f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 0 deletions

View File

@ -278,6 +278,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map
packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map

3
.gitignore vendored
View File

@ -264,6 +264,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map
packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map

View File

@ -74,6 +74,7 @@ const commands = [
require('./gui/MainScreen/commands/toggleNoteList'), require('./gui/MainScreen/commands/toggleNoteList'),
require('./gui/MainScreen/commands/toggleSideBar'), require('./gui/MainScreen/commands/toggleSideBar'),
require('./gui/MainScreen/commands/toggleVisiblePanes'), require('./gui/MainScreen/commands/toggleVisiblePanes'),
require('./gui/MainScreen/commands/showPrompt'),
require('./gui/NoteEditor/commands/focusElementNoteBody'), require('./gui/NoteEditor/commands/focusElementNoteBody'),
require('./gui/NoteEditor/commands/focusElementNoteTitle'), require('./gui/NoteEditor/commands/focusElementNoteTitle'),
require('./gui/NoteEditor/commands/showLocalSearch'), require('./gui/NoteEditor/commands/showLocalSearch'),

View File

@ -135,6 +135,7 @@ const commands = [
require('./commands/openNote'), require('./commands/openNote'),
require('./commands/openFolder'), require('./commands/openFolder'),
require('./commands/openTag'), require('./commands/openTag'),
require('./commands/showPrompt'),
]; ];
class MainScreenComponent extends React.Component<Props, State> { class MainScreenComponent extends React.Component<Props, State> {

View File

@ -0,0 +1,41 @@
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
export const declaration: CommandDeclaration = {
name: 'showPrompt',
};
enum PromptInputType {
Dropdown = 'dropdown',
Datetime = 'datetime',
Tags = 'tags',
Text = 'text',
}
interface PromptConfig {
label: string;
inputType?: PromptInputType;
value?: any;
autocomplete?: any[];
buttons?: string[];
}
export const runtime = (comp: any): CommandRuntime => {
return {
execute: async (_context: CommandContext, config: PromptConfig) => {
return new Promise((resolve) => {
comp.setState({
promptOptions: {
...config,
onClose: async (answer: any, buttonType: string) => {
comp.setState({ promptOptions: null });
resolve({
answer: answer,
buttonType: buttonType,
});
},
},
});
});
},
};
};