userface
Version:
Universal Data-Driven UI Engine with live data, validation, and multi-platform support
135 lines (134 loc) • 4.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.componentRegistry = exports.ComponentRegistry = void 0;
class ComponentRegistry {
constructor() {
Object.defineProperty(this, "components", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
Object.defineProperty(this, "schemas", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
// === АДАПТЕРЫ ===
Object.defineProperty(this, "adapters", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
}
registerComponent(name, component, schema) {
console.log(`🔍 ComponentRegistry.registerComponent: registering ${name}`);
console.log(`🔍 ComponentRegistry.registerComponent: component type:`, typeof component);
console.log(`🔍 ComponentRegistry.registerComponent: current components:`, this.getComponentNames());
try {
// Если схема не предоставлена, создаем базовую
if (!schema) {
schema = {
name,
detectedPlatform: 'universal',
props: [],
events: []
};
}
this.components.set(name, component);
this.schemas.set(name, schema);
console.log(`✅ Component registered: ${name} {schema: '${schema?.name || 'default'}'}`);
console.log(`🔍 ComponentRegistry.registerComponent: after registration components:`, this.getComponentNames());
}
catch (error) {
console.error(`Failed to register component: ${name}`, error);
throw error;
}
}
getComponent(name) {
console.log(`🔍 ComponentRegistry.getComponent: looking for ${name}`);
console.log(`🔍 ComponentRegistry.getComponent: available components:`, this.getComponentNames());
const component = this.components.get(name);
if (!component) {
console.warn(`❌ ComponentRegistry.getComponent: Component not found: ${name}`);
console.warn(`❌ ComponentRegistry.getComponent: Available components:`, this.getComponentNames());
return null;
}
console.log(`✅ ComponentRegistry.getComponent: found ${name}, type:`, typeof component);
return component;
}
getComponentSchema(name) {
const schema = this.schemas.get(name);
if (!schema) {
console.warn(`Schema not found for component: ${name}`);
return null;
}
return schema;
}
getAllComponents() {
return new Map(this.components);
}
getAllSchemas() {
return new Map(this.schemas);
}
removeComponent(name) {
const component = this.components.get(name);
if (component) {
this.components.delete(name);
this.schemas.delete(name);
console.log(`Component removed: ${name}`);
}
else {
console.warn(`Component not found for removal: ${name}`);
}
}
clear() {
const count = this.components.size;
this.components.clear();
this.schemas.clear();
console.log(`Registry cleared, removed ${count} components`);
}
// === ДОПОЛНИТЕЛЬНЫЕ МЕТОДЫ ===
hasComponent(name) {
return this.components.has(name);
}
getComponentCount() {
return this.components.size;
}
getComponentNames() {
return Array.from(this.components.keys());
}
updateComponentSchema(name, schema) {
if (this.components.has(name)) {
this.schemas.set(name, schema);
console.log(`Schema updated for component: ${name}`);
}
else {
console.warn(`Cannot update schema for non-existent component: ${name}`);
}
}
validateComponent(name) {
const component = this.components.get(name);
const schema = this.schemas.get(name);
if (!component || !schema) {
return false;
}
// Базовая валидация компонента
return typeof component === 'function' || typeof component === 'object';
}
registerAdapter(adapter) {
const adapterId = adapter.id || `adapter-${this.adapters.size}`;
this.adapters.set(adapterId, adapter);
console.log(`Adapter registered: ${adapterId}`);
}
getAdapter(adapterId) {
return this.adapters.get(adapterId);
}
getAllAdapters() {
return Array.from(this.adapters.values());
}
}
exports.ComponentRegistry = ComponentRegistry;
exports.componentRegistry = new ComponentRegistry();