gristlabs_grist-core/app/common/CustomWidget.ts
Jarosław Sadziński 85ef873ce5 (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
2022-01-13 11:10:17 +01:00

52 lines
1.1 KiB
TypeScript

/**
* Custom widget manifest definition.
*/
export interface ICustomWidget {
/**
* Widget friendly name, used on the UI.
*/
name: string;
/**
* Widget unique id, probably in npm package format @gristlabs/custom-widget-name.
*/
widgetId: string;
/**
* Custom widget main page URL.
*/
url: string;
/**
* Optional desired access level.
*/
accessLevel?: AccessLevel;
}
/**
* Widget access level.
*/
export enum AccessLevel {
/**
* Default, no access to Grist.
*/
none = "none",
/**
* Read only access to table the widget is based on.
*/
read_table = "read table",
/**
* Full access to document on user's behalf.
*/
full = "full",
}
export function isSatisfied(current: AccessLevel, minimum: AccessLevel) {
function ordered(level: AccessLevel) {
switch(level) {
case AccessLevel.none: return 0;
case AccessLevel.read_table: return 1;
case AccessLevel.full: return 2;
default: throw new Error(`Unrecognized access level ${level}`);
}
}
return ordered(current) >= ordered(minimum);
}