@formant/ava-react
Version:
React components of AVA.
74 lines (72 loc) • 2.66 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/NarrativeTextVis/chore/plugin/PluginManager.ts
var PluginManager_exports = {};
__export(PluginManager_exports, {
PluginManager: () => PluginManager
});
module.exports = __toCommonJS(PluginManager_exports);
var import_ava = require("@formant/ava");
var import_lodash = require("lodash");
var import_plugin_protocol = require("./plugin-protocol.type");
var import_presets = require("./presets");
function getPlugins(plugins) {
return (0, import_lodash.isArray)(plugins) && plugins.length > 0 ? [...import_presets.presetPlugins, ...plugins] : import_presets.presetPlugins;
}
var PluginManager = class {
constructor(plugins) {
this.entities = {};
this.customPhrases = {};
this.customBlocks = {};
this.registerAll(getPlugins(plugins));
}
register(plugin) {
if ((0, import_plugin_protocol.isBlockDescriptor)(plugin)) {
this.customBlocks[plugin.key] = plugin;
}
if ((0, import_plugin_protocol.isEntityDescriptor)(plugin)) {
this.entities[plugin.key] = plugin;
}
if ((0, import_plugin_protocol.isCustomPhraseDescriptor)(plugin)) {
this.customPhrases[plugin.key] = plugin;
}
}
registerAll(plugins) {
plugins.forEach((plugin) => this.register(plugin));
}
getEntityDescriptor(entityType) {
return this.entities[entityType];
}
getCustomPhraseDescriptor(customType) {
return this.customPhrases[customType];
}
getBlockDescriptor(customType) {
return this.customBlocks[customType];
}
getPhraseDescriptorBySpec(spec) {
if ((0, import_ava.isCustomPhrase)(spec))
return this.getCustomPhraseDescriptor(spec.metadata.customType);
if ((0, import_ava.isEntityPhrase)(spec))
return this.getEntityDescriptor(spec.metadata.entityType);
return null;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PluginManager
});