mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
1654a2681f
Summary: This moves all client code to core, and makes minimal fix-ups to get grist and grist-core to compile correctly. The client works in core, but I'm leaving clean-up around the build and bundles to follow-up. Test Plan: existing tests pass; server-dev bundle looks sane Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2627
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { SafeBrowser, ViewProcess } from 'app/client/lib/SafeBrowser';
|
|
import { PluginInstance } from 'app/common/PluginInstance';
|
|
|
|
export { ViewProcess } from 'app/client/lib/SafeBrowser';
|
|
|
|
/**
|
|
* A PluginCustomSection identifies one custom section in a plugin.
|
|
*/
|
|
export interface PluginCustomSection {
|
|
pluginId: string;
|
|
sectionId: string;
|
|
}
|
|
|
|
export class CustomSectionElement {
|
|
|
|
/**
|
|
* Get the list of all available custom sections in all plugins' contributions.
|
|
*/
|
|
public static getSections(plugins: PluginInstance[]): PluginCustomSection[] {
|
|
return plugins.reduce<PluginCustomSection[]>((acc, plugin) => {
|
|
const customSections = plugin.definition.manifest.contributions.customSections;
|
|
const pluginId = plugin.definition.id;
|
|
if (customSections) {
|
|
// collect identifiers
|
|
const sectionIds = customSections.map(section => ({sectionId: section.name, pluginId}));
|
|
// concat to the accumulator
|
|
return acc.concat(sectionIds);
|
|
}
|
|
return acc;
|
|
}, []);
|
|
}
|
|
|
|
/**
|
|
* Find a section matching sectionName in the plugin instances' constributions and returns
|
|
* it. Returns `undefined` if not found.
|
|
*/
|
|
public static find(plugin: PluginInstance, sectionName: string): ViewProcess|undefined {
|
|
const customSections = plugin.definition.manifest.contributions.customSections;
|
|
if (customSections) {
|
|
const section = customSections.find(({ name }) => name === sectionName);
|
|
if (section) {
|
|
const safeBrowser = plugin.safeBrowser as SafeBrowser;
|
|
return safeBrowser.createViewProcess(section.path);
|
|
}
|
|
}
|
|
}
|
|
}
|