(core) Widget options api

Summary:
Adding configuration options for CustomWidgets.

Custom widgets can now store options (in JSON) in viewSection metadata.

Changes in grist-plugin-api:
- Adding onOptions handler, that will be invoked when the widget is ready and when the configuration is changed
- Adding WidgetAPI - new API to read and save a configuration for widget.

Changes in Grist:
- Rewriting CustomView code, and extracting code that is responsible for showing the iframe and registering Rpc.
- Adding Open Configuration button to Widget section in the Creator panel and in the section menu.
- Custom Widgets can implement "configure" method, to show configuration screen when requested.

Test Plan: Browser tests.

Reviewers: paulfitz, dsagal

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3185
This commit is contained in:
Jarosław Sadziński
2022-01-12 14:30:51 +01:00
parent 5a876976d5
commit 85ef873ce5
18 changed files with 1087 additions and 318 deletions

25
app/plugin/WidgetAPI.ts Normal file
View File

@@ -0,0 +1,25 @@
/**
* API to manage Custom Widget state.
*/
export interface WidgetAPI {
/**
* Gets all options stored by the widget. Options are stored as plain JSON object.
*/
getOptions(): Promise<object | null>;
/**
* Replaces all options stored by the widget.
*/
setOptions(options: {[key: string]: any}): Promise<void>;
/**
* Clears all the options.
*/
clearOptions(): Promise<void>;
/**
* Store single value in the Widget options object (and create it if necessary).
*/
setOption(key: string, value: any): Promise<void>;
/**
* Get single value from Widget options object.
*/
getOption(key: string): Promise<any>;
}