UNPKG

@atlaskit/editor-common

Version:

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

116 lines 4.39 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { getAutoConvertPatternsFromModule } from './module-helpers'; var DefaultExtensionProvider = /*#__PURE__*/function () { function DefaultExtensionProvider(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) { _classCallCheck(this, DefaultExtensionProvider); this.manifestsPromise = Promise.resolve(manifests); this.autoConvertHandlers = autoConvertHandlers; } return _createClass(DefaultExtensionProvider, [{ key: "getExtensions", value: function getExtensions() { return this.manifestsPromise; } }, { key: "getExtension", value: function () { var _getExtension = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(type, key) { var extension; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return this.manifestsPromise; case 2: extension = _context.sent.find(function (manifest) { return manifest.type === type && manifest.key === key; }); if (extension) { _context.next = 5; break; } throw new Error("Extension with type \"".concat(type, "\" and key \"").concat(key, "\" not found!")); case 5: return _context.abrupt("return", extension); case 6: case "end": return _context.stop(); } }, _callee, this); })); function getExtension(_x, _x2) { return _getExtension.apply(this, arguments); } return getExtension; }() }, { key: "search", value: function () { var _search = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(keyword) { var extensions; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return this.manifestsPromise; case 2: extensions = _context2.sent.filter(function (manifest) { return manifest.title.toLowerCase().includes(keyword.toLowerCase()); }); return _context2.abrupt("return", extensions); case 4: case "end": return _context2.stop(); } }, _callee2, this); })); function search(_x3) { return _search.apply(this, arguments); } return search; }() }, { key: "getAutoConverter", value: function () { var _getAutoConverter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var autoConverters; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: if (!this.autoConvertHandlers) { _context3.next = 2; break; } return _context3.abrupt("return", this.autoConvertHandlers); case 2: _context3.t0 = getAutoConvertPatternsFromModule; _context3.next = 5; return this.manifestsPromise; case 5: _context3.t1 = _context3.sent; autoConverters = (0, _context3.t0)(_context3.t1); return _context3.abrupt("return", autoConverters); case 8: case "end": return _context3.stop(); } }, _callee3, this); })); function getAutoConverter() { return _getAutoConverter.apply(this, arguments); } return getAutoConverter; }() }]); }(); export { DefaultExtensionProvider as default };