UNPKG

@xcons/core

Version:

XCons Core System - Component Architecture Platform

1 lines โ€ข 7.31 kB
!function(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i(require("@xcons/common")):"function"==typeof define&&define.amd?define(["@xcons/common"],i):"object"==typeof exports?exports.XConsCore=i(require("@xcons/common")):e.XConsCore=i(e.XConsCommon)}(this,e=>(()=>{"use strict";var i={789:i=>{i.exports=e}},t={};function n(e){var s=t[e];if(void 0!==s)return s.exports;var r=t[e]={exports:{}};return i[e](r,r.exports,n),r.exports}n.d=(e,i)=>{for(var t in i)n.o(i,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:i[t]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};n.r(s),n.d(s,{BUILD_TIME:()=>l,PACKAGE_AUTHOR:()=>o,PACKAGE_DESC:()=>a,PACKAGE_INFO:()=>u,PACKAGE_NAME:()=>r,PACKAGE_VERSION:()=>g,PluginHost:()=>p,default:()=>f,defaultPluginHost:()=>h});const r="@xcons/core",a="XCons Core System - Component Architecture Platform",o="XCon Studio Team",g="3.0.2",l="2025-10-23T18:16:55.503Z",u={name:r,version:g,buildTime:l,description:a,author:o};var d=n(789);const c=d.CoreLogger.createChild(r,"PLUGIN-HOST");class p{constructor(){this.plugins=new Map,this.globalRegistries=new Map,this.sharedDependencies=new Map,this.isInitialized=!1}initialize(){this.isInitialized?c.warn("Plugin Host already initialized, skipping..."):(this.setupSharedDependencies(),this.setupGlobalAPI(),this.isInitialized=!0,c.info("๐Ÿš€ XCons Plugin Host initialized"))}setupSharedDependencies(){this.sharedDependencies.set("logger",c),"undefined"!=typeof window&&(this.sharedDependencies.set("window",window),this.sharedDependencies.set("document",document)),"undefined"!=typeof process&&this.sharedDependencies.set("process",process)}setupGlobalAPI(){const e={registerPlugin:e=>this.registerPlugin(e),getPlugin:e=>this.getPlugin(e),getPlugins:()=>this.getPlugins(),unregisterPlugin:e=>this.unregisterPlugin(e),registerGlobalRegistry:(e,i,t,n)=>{this.registerGlobalRegistry(e,i,t,n)},getGlobalRegistry:e=>this.getGlobalRegistry(e),getGlobalRegistries:()=>this.getGlobalRegistries(),provideDependency:(e,i)=>this.provideDependency(e,i),getDependency:e=>this.getDependency(e),getSharedDependencies:()=>this.getSharedDependencies(),version:"2.0.0",ready:!0,isInitialized:()=>this.isInitialized};"undefined"!=typeof window&&(window.XConsCore=e,document.dispatchEvent(new CustomEvent("XConsCore:ready"))),void 0!==n.g&&(n.g.XConsCore=e)}async registerPlugin(e){c.info(`๐Ÿ“ฆ Registering plugin: ${e.name}@${e.version}`);try{if(!this.validatePlugin(e))throw new Error(`Invalid plugin: ${e.name}`);this.plugins.has(e.name)&&(c.warn(`โš ๏ธ Plugin ${e.name} already registered, updating`),await this.unregisterPlugin(e.name)),e.status="initializing";const i={name:e.name,version:e.version,type:e.type,status:e.status,plugin:e,capabilities:e.getCapabilities?.()||[],registeredAt:new Date};if(this.plugins.set(e.name,i),await e.initialize(),e.status="ready",i.status="ready",e.getGlobalRegistries){const i=e.getGlobalRegistries();Object.entries(i).forEach(([i,t])=>{const n=this.getPluginNamespace(e.type);this.registerGlobalRegistry(i,t,e.name,n)})}c.info(`โœ… Plugin ${e.name} registered successfully`),this.emit("plugin:registered",{plugin:e.name,type:e.type,capabilities:i.capabilities})}catch(i){throw e.status="error",this.plugins.has(e.name)&&(this.plugins.get(e.name).status="error"),c.error(`โŒ Failed to register plugin ${e.name}:`,i),i}}async unregisterPlugin(e){const i=this.plugins.get(e);if(!i)return c.warn(`Plugin not found: ${e}`),!1;try{i.plugin.deactivate&&await i.plugin.deactivate(),i.plugin.destroy&&await i.plugin.destroy();const t=[];return this.globalRegistries.forEach((i,n)=>{i.plugin===e&&t.push(n)}),t.forEach(e=>{this.globalRegistries.delete(e)}),this.plugins.delete(e),c.info(`๐Ÿ—‘๏ธ Plugin ${e} unregistered successfully`),this.emit("plugin:unregistered",{plugin:e}),!0}catch(t){return c.error(`โŒ Failed to unregister plugin ${e}:`,t),!1}}registerGlobalRegistry(e,i,t,s){const r={name:e,instance:i,plugin:t,namespace:s,registeredAt:new Date};this.globalRegistries.set(e,r),"undefined"!=typeof window&&(window[s]=window[s]||{},window[s][e]=i),void 0!==n.g&&(n.g[s]=n.g[s]||{},n.g[s][e]=i),c.debug(`๐Ÿ“‹ Global registry registered: ${s}.${e} (from ${t})`)}getGlobalRegistry(e){const i=this.globalRegistries.get(e);return i?i.instance:void 0}getGlobalRegistries(){return Object.fromEntries(this.globalRegistries.entries())}getPluginNamespace(e){switch(e){case"widget-core":return"__XCONS_WIDGET__";case"datasource-core":return"__XCONS_DATASOURCE__";case"core":return"__XCONS_CORE__";default:return"__XCONS_OTHER__"}}provideDependency(e,i){this.sharedDependencies.set(e,i),c.debug(`๐Ÿ”ง Shared dependency provided: ${e}`)}getDependency(e){return this.sharedDependencies.get(e)}getSharedDependencies(){return Object.fromEntries(this.sharedDependencies.entries())}validatePlugin(e){return!!(e.name&&e.version&&e.type&&"function"==typeof e.initialize)}getPlugin(e){return this.plugins.get(e)}getPlugins(){return Array.from(this.plugins.values())}getRegisteredPluginNames(){return Array.from(this.plugins.keys())}isPluginRegistered(e){return this.plugins.has(e)}getPluginCount(){return this.plugins.size}async clearPlugins(){const e=this.getRegisteredPluginNames().map(e=>this.unregisterPlugin(e));await Promise.allSettled(e),this.plugins.clear(),this.globalRegistries.clear(),c.info("๐Ÿงน All plugins cleared")}emit(e,i){"undefined"!=typeof document&&document.dispatchEvent(new CustomEvent(`XConsCore:${e}`,{detail:i}))}getPluginStats(){const e=this.getPlugins(),i={},t={};return e.forEach(e=>{i[e.type]=(i[e.type]||0)+1,t[e.status]=(t[e.status]||0)+1}),{total:e.length,byType:i,byStatus:t,registries:this.globalRegistries.size,dependencies:this.sharedDependencies.size}}getIsInitialized(){return this.isInitialized}}const h="undefined"!=typeof window?(window.__XCONS_PLUGIN_HOST__||(window.__XCONS_PLUGIN_HOST__=new p),window.__XCONS_PLUGIN_HOST__):void 0!==n.g?(n.g.__XCONS_PLUGIN_HOST__||(n.g.__XCONS_PLUGIN_HOST__=new p),n.g.__XCONS_PLUGIN_HOST__):new p,_=d.CoreLogger.getInstance();class y{constructor(){this.name=r,this.version=g,this.type="core",this.status="idle"}async initialize(){d.GlobalFlagManager.hasFlag("__XCONS_CORE_INITIALIZED__")?_.debug("Core Plugin already initialized, skipping..."):(d.GlobalFlagManager.setFlag("__XCONS_CORE_INITIALIZED__",!0),this.status="ready",h.initialize(),_.info("Core Plugin ready"))}getCapabilities(){return[]}getGlobalRegistries(){return{defaultPluginHost:h}}async activate(){_.info("Core Plugin activated")}async deactivate(){_.info("Core Plugin deactivated")}async destroy(){d.GlobalFlagManager.removeFlag("__XCONS_CORE_INITIALIZED__"),_.info("Core Plugin destroyed")}}!async function(){try{d.LoggerRegistry.registerPackage(r,{enabled:!1,level:d.LoggerLogLevel.DEBUG,prefix:r});const e=new y;await e.initialize(),await e.activate(),_.info("Core Plugin running")}catch(e){_.error("Failed to setup Core Plugin:",e)}}();const f={version:g,buildTime:l,packageInfo:u};return s})());