UNPKG

flipper-plugin

Version:

Flipper Desktop plugin SDK and components

78 lines 2.64 kB
"use strict"; /** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SandyPluginDefinition = void 0; /** * A sandy plugin definition represents a loaded plugin definition, storing two things: * the loaded JS module, and the meta data (typically coming from package.json). * * Also delegates some of the standard plugin functionality to have a similar public static api as FlipperPlugin */ class SandyPluginDefinition { constructor(details, module, css) { this.id = details.id; this.css = css; this.details = details; if (details.pluginType === 'device' || module.supportsDevice || module.devicePlugin) { // device plugin this.isDevicePlugin = true; if (!module.devicePlugin || typeof module.devicePlugin !== 'function') { throw new Error(`Flipper device plugin '${this.id}' should export named function called 'devicePlugin'`); } } else { this.isDevicePlugin = false; if (!module.plugin || typeof module.plugin !== 'function') { throw new Error(`Flipper plugin '${this.id}' should export named function called 'plugin'`); } } if (!module.Component || typeof module.Component !== 'function') { throw new Error(`Flipper plugin '${this.id}' should export named function called 'Component'`); } this.module = module; this.module.Component.displayName = `FlipperPlugin(${this.id})`; } asDevicePluginModule() { if (!this.isDevicePlugin) throw new Error('Not a device plugin'); return this.module; } asPluginModule() { if (this.isDevicePlugin) throw new Error('Not an application plugin'); return this.module; } get packageName() { return this.details.name; } get title() { return this.details.title; } get icon() { return this.details.icon; } get category() { return this.details.category; } get gatekeeper() { return this.details.gatekeeper; } get version() { return this.details.version; } get keyboardActions() { // TODO: T68882551 support keyboard actions return []; } } exports.SandyPluginDefinition = SandyPluginDefinition; //# sourceMappingURL=SandyPluginDefinition.js.map