@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
46 lines (45 loc) • 1.59 kB
JavaScript
//#region src/plugins/plugin-manager.ts
/**
* Create the plugin manager store
*
* This store manages all plugins registered with the API client
*/
var createPluginManager = ({ plugins = [] }) => {
const registeredPlugins = /* @__PURE__ */ new Map();
plugins.forEach((plugin) => {
const pluginInstance = plugin();
registeredPlugins.set(pluginInstance.name, pluginInstance);
});
return {
getSpecificationExtensions: (name) => {
const extensions = [];
for (const plugin of registeredPlugins.values()) for (const extension of plugin.extensions) if (extension.name === name) extensions.push(extension);
return extensions;
},
getViewComponents: (viewName) => {
const components = [];
for (const plugin of registeredPlugins.values()) {
const viewComponents = plugin.views?.[viewName];
if (viewComponents) components.push(...viewComponents);
}
return components;
},
notifyInit: (config) => {
for (const plugin of registeredPlugins.values()) plugin.hooks?.onInit?.({ config });
},
notifyConfigChange: (config) => {
for (const plugin of registeredPlugins.values()) plugin.hooks?.onConfigChange?.({ config });
},
notifyDestroy: () => {
for (const plugin of registeredPlugins.values()) plugin.hooks?.onDestroy?.();
},
getApiClientPlugins: () => {
const apiClientPlugins = [];
for (const plugin of registeredPlugins.values()) if (plugin.apiClientPlugins) apiClientPlugins.push(...plugin.apiClientPlugins);
return apiClientPlugins;
}
};
};
//#endregion
export { createPluginManager };
//# sourceMappingURL=plugin-manager.js.map