mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
|
import {PluginInstance} from 'app/common/PluginInstance';
|
||
|
import {InternalImportSourceAPI} from 'app/plugin/InternalImportSourceAPI';
|
||
|
import {ImportSource} from 'app/plugin/PluginManifest';
|
||
|
import {checkers} from 'app/plugin/TypeCheckers';
|
||
|
|
||
|
/**
|
||
|
* Encapsulate together an import source contribution with its plugin instance and a callable stub
|
||
|
* for the ImportSourceAPI. Exposes as well a `fromArray` static method to get all the import
|
||
|
* sources from an array of plugins instances.
|
||
|
*/
|
||
|
export class ImportSourceElement {
|
||
|
|
||
|
/**
|
||
|
* Get all import sources from an array of plugin instances.
|
||
|
*/
|
||
|
public static fromArray(pluginInstances: PluginInstance[]): ImportSourceElement[] {
|
||
|
const importSources: ImportSourceElement[] = [];
|
||
|
for (const plugin of pluginInstances) {
|
||
|
const definitions = plugin.definition.manifest.contributions.importSources;
|
||
|
if (definitions) {
|
||
|
for (const importSource of definitions) {
|
||
|
importSources.push(new ImportSourceElement(plugin, importSource));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return importSources;
|
||
|
}
|
||
|
|
||
|
public importSourceStub: InternalImportSourceAPI;
|
||
|
|
||
|
private constructor(public plugin: PluginInstance, public importSource: ImportSource) {
|
||
|
this.importSourceStub = plugin.getStub<InternalImportSourceAPI>(importSource.importSource,
|
||
|
checkers.InternalImportSourceAPI);
|
||
|
}
|
||
|
}
|