mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move client code to core
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
This commit is contained in:
47
app/client/lib/CustomSectionElement.ts
Normal file
47
app/client/lib/CustomSectionElement.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user