UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

35 lines 1.33 kB
import { getAutoConvertPatternsFromModule } from './module-helpers'; export default class DefaultExtensionProvider { constructor(manifests, /** * Allows for an optional list of pre compiled auto convert handlers to be passed. * Useful for performance improvements or to support legacy converters. * * Warning: If this attribute is passed, this provider will ignore auto convert patterns from the manifests. */ autoConvertHandlers) { this.manifestsPromise = Promise.resolve(manifests); this.autoConvertHandlers = autoConvertHandlers; } getExtensions() { return this.manifestsPromise; } async getExtension(type, key) { const extension = (await this.manifestsPromise).find(manifest => manifest.type === type && manifest.key === key); if (!extension) { throw new Error(`Extension with type "${type}" and key "${key}" not found!`); } return extension; } async search(keyword) { const extensions = (await this.manifestsPromise).filter(manifest => manifest.title.toLowerCase().includes(keyword.toLowerCase())); return extensions; } async getAutoConverter() { if (this.autoConvertHandlers) { return this.autoConvertHandlers; } const autoConverters = getAutoConvertPatternsFromModule(await this.manifestsPromise); return autoConverters; } }