-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Expose prompt to plugins as a command (#5058)
- Loading branch information
1 parent
01e6ca4
commit c5c38a3
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/app-desktop/gui/MainScreen/commands/showPrompt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
}, | ||
}, | ||
}); | ||
}); | ||
}, | ||
}; | ||
}; |