UNPKG

@memberjunction/react-runtime

Version:

Platform-agnostic React component runtime for MemberJunction. Provides core compilation, registry, and execution capabilities for React components in any JavaScript environment.

74 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LibraryRegistry = void 0; class LibraryRegistry { static async Config(forceRefresh = false, componentLibraries) { if (!this._configured || forceRefresh) { const libraryGroups = new Map(); for (const lib of componentLibraries) { if (!libraryGroups.has(lib.Name.toLowerCase())) { libraryGroups.set(lib.Name.toLowerCase(), []); } libraryGroups.get(lib.Name.toLowerCase()).push(lib); } for (const [name, versions] of libraryGroups) { const libDef = { name, globalVariable: versions[0].GlobalVariable || "", category: versions[0].Category || "", versions: {}, defaultVersion: versions[0].Version || "" }; for (const version of versions) { libDef.versions[version.Version] = { cdnUrl: version.CDNUrl || "", cssUrls: version.CDNCssUrl?.split(",") || [] }; } this.libraries.set(name, libDef); } this._configured = true; } } static getLibrary(name) { if (!this._configured) throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!"); return this.libraries.get(name?.trim().toLowerCase()); } static getCdnUrl(name, version) { if (!this._configured) throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!"); const library = this.libraries.get(name?.trim().toLowerCase()); if (!library) return undefined; const targetVersion = version || library.defaultVersion; return library.versions[targetVersion]?.cdnUrl; } static isApproved(name) { if (!this._configured) throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!"); return this.libraries.has(name?.trim().toLowerCase()); } static resolveVersion(name, versionPattern) { if (!this._configured) throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!"); const library = this.libraries.get(name?.trim().toLowerCase()); if (!library) return undefined; if (!versionPattern) return library.defaultVersion; if (library.versions[versionPattern]) { return versionPattern; } return library.defaultVersion; } static registerLibrary(definition) { if (!this._configured) throw new Error("LibraryRegistry is not configured, call LibraryRegistry.Config() before using!"); this.libraries.set(definition.name?.trim().toLowerCase(), definition); } } exports.LibraryRegistry = LibraryRegistry; LibraryRegistry.libraries = new Map(); LibraryRegistry._configured = false; //# sourceMappingURL=library-registry.js.map