@antv/t8
Version:
T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative T8 markdown syntax that can be used to describe the content of data interpretation reports.
107 lines (103 loc) • 4.11 kB
JavaScript
;
require('../schema/paragraph.js');
require('../schema/phrase.js');
var isSpecType = require('../schema/utils/isSpecType.js');
var isPluginType = require('./utils/isPluginType.js');
require('tslib');
/**
* PluginManager class responsible for registering, managing, and retrieving
* different types of plugins (entities, custom phrases, and blocks).
*
* This class serves as a central registry for all plugin components in the application,
* allowing dynamic extension of functionality through the plugin system.
*/
var PluginManager = /** @class */ (function () {
/**
* Creates a new PluginManager instance and registers provided plugins.
* If no plugins are provided, only presets will be registered.
*
* @param plugins - Optional array of plugins to register
*/
function PluginManager(plugins) {
/** Storage for entity type plugins mapped by their entity type */
this.entities = {};
/** Storage for custom phrase plugins mapped by their key/identifier */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.customPhrases = {};
/** Storage for custom block plugins mapped by their key/identifier */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.customBlocks = {};
if (plugins)
this.registerAll(plugins);
}
/**
* Registers a single plugin based on its type.
* The plugin is stored in the appropriate collection based on its descriptor type.
*
* @param plugin - The plugin to register
*/
PluginManager.prototype.register = function (plugin) {
if (isPluginType.isBlockDescriptor(plugin)) {
this.customBlocks[plugin.key] = plugin;
}
if (isPluginType.isEntityDescriptor(plugin)) {
this.entities[plugin.key] = plugin;
}
if (isPluginType.isCustomPhraseDescriptor(plugin)) {
this.customPhrases[plugin.key] = plugin;
}
};
/**
* Registers multiple plugins at once.
*
* @param plugins - Array of plugins to register
*/
PluginManager.prototype.registerAll = function (plugins) {
var _this = this;
plugins.forEach(function (plugin) { return _this.register(plugin); });
};
/**
* Retrieves an entity descriptor by its entity type.
*
* @param entityType - The type of entity to retrieve
* @returns The corresponding entity descriptor or undefined if not found
*/
PluginManager.prototype.getEntityDescriptor = function (entityType) {
return this.entities[entityType];
};
/**
* Retrieves a custom phrase descriptor by its type.
*
* @param customType - The type identifier of the custom phrase
* @returns The corresponding custom phrase descriptor or undefined if not found
*/
PluginManager.prototype.getCustomPhraseDescriptor = function (customType) {
return this.customPhrases[customType];
};
/**
* Retrieves a block descriptor by its type.
*
* @param customType - The type identifier of the block
* @returns The corresponding block descriptor or undefined if not found
*/
PluginManager.prototype.getBlockDescriptor = function (customType) {
return this.customBlocks[customType];
};
/**
* Retrieves a phrase descriptor based on a phrase specification.
* This method determines the appropriate descriptor type from the specification.
*
* @param spec - The phrase specification to look up
* @returns The corresponding phrase descriptor or null if not found
*/
PluginManager.prototype.getPhraseDescriptorBySpec = function (spec) {
if (isSpecType.isCustomPhrase(spec))
return this.getCustomPhraseDescriptor(spec.metadata.customType);
if (isSpecType.isEntityPhrase(spec))
return this.getEntityDescriptor(spec.metadata.entityType);
return null;
};
return PluginManager;
}());
exports.PluginManager = PluginManager;
//# sourceMappingURL=PluginManager.js.map