@memberjunction/react-runtime 2.93.0 â 2.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +28 -0
- package/README.md +180 -2
- package/dist/compiler/component-compiler.d.ts +1 -0
- package/dist/compiler/component-compiler.d.ts.map +1 -1
- package/dist/compiler/component-compiler.js +253 -61
- package/dist/compiler/component-compiler.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/registry/component-registry-service.d.ts +6 -3
- package/dist/registry/component-registry-service.d.ts.map +1 -1
- package/dist/registry/component-registry-service.js +38 -11
- package/dist/registry/component-registry-service.js.map +1 -1
- package/dist/registry/component-registry.d.ts +6 -3
- package/dist/registry/component-registry.d.ts.map +1 -1
- package/dist/registry/component-registry.js +17 -0
- package/dist/registry/component-registry.js.map +1 -1
- package/dist/registry/component-resolver.d.ts +2 -1
- package/dist/registry/component-resolver.d.ts.map +1 -1
- package/dist/registry/component-resolver.js +101 -14
- package/dist/registry/component-resolver.js.map +1 -1
- package/dist/runtime/component-hierarchy.d.ts.map +1 -1
- package/dist/runtime/component-hierarchy.js +75 -13
- package/dist/runtime/component-hierarchy.js.map +1 -1
- package/dist/runtime/prop-builder.d.ts +2 -2
- package/dist/runtime/prop-builder.d.ts.map +1 -1
- package/dist/runtime/prop-builder.js +32 -14
- package/dist/runtime/prop-builder.js.map +1 -1
- package/dist/runtime.umd.js +1 -1
- package/dist/types/dependency-types.d.ts +62 -0
- package/dist/types/dependency-types.d.ts.map +1 -0
- package/dist/types/dependency-types.js +3 -0
- package/dist/types/dependency-types.js.map +1 -0
- package/dist/types/index.d.ts +8 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/library-dependency-resolver.d.ts +19 -0
- package/dist/utilities/library-dependency-resolver.d.ts.map +1 -0
- package/dist/utilities/library-dependency-resolver.js +419 -0
- package/dist/utilities/library-dependency-resolver.js.map +1 -0
- package/dist/utilities/library-loader.d.ts +9 -0
- package/dist/utilities/library-loader.d.ts.map +1 -1
- package/dist/utilities/library-loader.js +164 -0
- package/dist/utilities/library-loader.js.map +1 -1
- package/package.json +5 -5
- package/src/compiler/component-compiler.ts +280 -82
- package/src/index.ts +20 -5
- package/src/registry/component-registry-service.ts +53 -14
- package/src/registry/component-registry.ts +36 -7
- package/src/registry/component-resolver.ts +130 -16
- package/src/runtime/component-hierarchy.ts +101 -27
- package/src/runtime/prop-builder.ts +38 -18
- package/src/types/dependency-types.ts +110 -0
- package/src/types/index.ts +17 -21
- package/src/utilities/index.ts +1 -0
- package/src/utilities/library-dependency-resolver.ts +613 -0
- package/src/utilities/library-loader.ts +274 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComponentCompiler = void 0;
|
|
4
4
|
const library_registry_1 = require("../utilities/library-registry");
|
|
5
|
+
const library_loader_1 = require("../utilities/library-loader");
|
|
5
6
|
const DEFAULT_COMPILER_CONFIG = {
|
|
6
7
|
babel: {
|
|
7
8
|
presets: ['react'],
|
|
@@ -10,10 +11,12 @@ const DEFAULT_COMPILER_CONFIG = {
|
|
|
10
11
|
minify: false,
|
|
11
12
|
sourceMaps: false,
|
|
12
13
|
cache: true,
|
|
13
|
-
maxCacheSize: 100
|
|
14
|
+
maxCacheSize: 100,
|
|
15
|
+
debug: false
|
|
14
16
|
};
|
|
15
17
|
class ComponentCompiler {
|
|
16
18
|
constructor(config) {
|
|
19
|
+
this.CORE_LIBRARIES = new Set(['React', 'ReactDOM']);
|
|
17
20
|
this.config = { ...DEFAULT_COMPILER_CONFIG, ...config };
|
|
18
21
|
this.compilationCache = new Map();
|
|
19
22
|
}
|
|
@@ -38,7 +41,7 @@ class ComponentCompiler {
|
|
|
38
41
|
const transpiledCode = this.transpileComponent(options.componentCode, options.componentName, options);
|
|
39
42
|
const componentFactory = this.createComponentFactory(transpiledCode, options.componentName, loadedLibraries);
|
|
40
43
|
const compiledComponent = {
|
|
41
|
-
|
|
44
|
+
factory: componentFactory,
|
|
42
45
|
id: this.generateComponentId(options.componentName),
|
|
43
46
|
name: options.componentName,
|
|
44
47
|
compiledAt: new Date(),
|
|
@@ -84,51 +87,219 @@ class ComponentCompiler {
|
|
|
84
87
|
wrapComponentCode(componentCode, componentName, libraries, dependencies) {
|
|
85
88
|
const libraryDeclarations = libraries && libraries.length > 0
|
|
86
89
|
? libraries
|
|
87
|
-
.filter(lib => lib.globalVariable)
|
|
90
|
+
.filter(lib => lib.globalVariable && !this.CORE_LIBRARIES.has(lib.globalVariable))
|
|
88
91
|
.map(lib => `const ${lib.globalVariable} = libraries['${lib.globalVariable}'];`)
|
|
89
92
|
.join('\n ')
|
|
90
93
|
: '';
|
|
94
|
+
const libraryLogChecks = libraries && libraries.length > 0
|
|
95
|
+
? libraries
|
|
96
|
+
.filter(lib => lib.globalVariable && !this.CORE_LIBRARIES.has(lib.globalVariable))
|
|
97
|
+
.map(lib => `\nif (!${lib.globalVariable}) { console.error('[React-Runtime-JS] Library "${lib.globalVariable}" is not defined'); } else { console.log('[React-Runtime-JS] Library "${lib.globalVariable}" is defined'); }`)
|
|
98
|
+
.join('\n ')
|
|
99
|
+
: '';
|
|
91
100
|
const componentDeclarations = dependencies && dependencies.length > 0
|
|
92
101
|
? dependencies
|
|
93
|
-
.
|
|
102
|
+
.filter(dep => dep.name !== componentName)
|
|
103
|
+
.map(dep => `const ${dep.name} = componentsOuter['${dep.name}'];`)
|
|
104
|
+
.join('\n ')
|
|
105
|
+
: '';
|
|
106
|
+
const componentLogChecks = dependencies && dependencies.length > 0
|
|
107
|
+
? dependencies
|
|
108
|
+
.filter(dep => dep.name !== componentName)
|
|
109
|
+
.map(dep => `if (!${dep.name}) { console.error('[React-Runtime-JS] Dependency "${dep.name}" is not defined'); } else { console.log('[React-Runtime-JS] Dependency "${dep.name}" is defined'); }`)
|
|
94
110
|
.join('\n ')
|
|
95
111
|
: '';
|
|
96
|
-
|
|
112
|
+
const wrappedCode = `
|
|
97
113
|
function createComponent(
|
|
98
114
|
React, ReactDOM,
|
|
99
115
|
useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer, useLayoutEffect,
|
|
100
116
|
libraries, styles, console, components
|
|
101
117
|
) {
|
|
102
|
-
|
|
118
|
+
// Code for ${componentName}
|
|
119
|
+
${componentCode}
|
|
103
120
|
|
|
104
121
|
// Ensure the component exists
|
|
105
122
|
if (typeof ${componentName} === 'undefined') {
|
|
106
123
|
throw new Error('Component "${componentName}" is not defined in the provided code');
|
|
107
124
|
}
|
|
125
|
+
else {
|
|
126
|
+
console.log('[React-Runtime-JS] Component "${componentName}" is defined');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Store the component in a variable so we don't lose it
|
|
130
|
+
const UserComponent = ${componentName};
|
|
131
|
+
|
|
132
|
+
// Check if the component is already a ComponentObject (has a .component property)
|
|
133
|
+
// If so, extract the actual React component
|
|
134
|
+
const ActualComponent = (typeof UserComponent === 'object' && UserComponent !== null && 'component' in UserComponent)
|
|
135
|
+
? UserComponent.component
|
|
136
|
+
: UserComponent;
|
|
137
|
+
|
|
138
|
+
// Debug logging to understand what we're getting
|
|
139
|
+
console.log('[React-Runtime-JS]Component ${componentName} type:', typeof UserComponent);
|
|
140
|
+
if (typeof UserComponent === 'object' && UserComponent !== null) {
|
|
141
|
+
console.log('[React-Runtime-JS]Component ${componentName} keys:', Object.keys(UserComponent));
|
|
142
|
+
console.log('[React-Runtime-JS]Component ${componentName} has .component:', 'component' in UserComponent);
|
|
143
|
+
if ('component' in UserComponent) {
|
|
144
|
+
console.log('[React-Runtime-JS]Component ${componentName}.component type:', typeof UserComponent.component);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Validate that we have a function (React component)
|
|
149
|
+
if (typeof ActualComponent !== 'function') {
|
|
150
|
+
console.error('[React-Runtime-JS] Invalid component type for ${componentName}:', typeof ActualComponent);
|
|
151
|
+
console.error('[React-Runtime-JS] ActualComponent value:', ActualComponent);
|
|
152
|
+
console.error('[React-Runtime-JS] Original UserComponent value:', UserComponent);
|
|
153
|
+
throw new Error('[React-Runtime-JS] Component "${componentName}" must be a function (React component) or an object with a .component property that is a function. Got: ' + typeof ActualComponent);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let componentsOuter = null, utilitiesOuter = null;
|
|
157
|
+
const DestructureWrapperUserComponent = (props) => {
|
|
158
|
+
if (!componentsOuter) {
|
|
159
|
+
componentsOuter = props?.components || components;
|
|
160
|
+
}
|
|
161
|
+
if (!utilitiesOuter) {
|
|
162
|
+
utilitiesOuter = props?.utilities;
|
|
163
|
+
}
|
|
164
|
+
console.log('Props for ${componentName}:', props);
|
|
165
|
+
console.log('components for ${componentName}:', componentsOuter);
|
|
166
|
+
console.log('styles for ${componentName}:', styles);
|
|
167
|
+
console.log('utilities for ${componentName}:', utilitiesOuter);
|
|
168
|
+
console.log('libraries for ${componentName}:', libraries);
|
|
169
|
+
${libraryDeclarations ? '// Destructure Libraries\n' + libraryDeclarations + '\n ' : ''}
|
|
170
|
+
${componentDeclarations ? '// Destructure Dependencies\n' + componentDeclarations + '\n ' : ''}
|
|
171
|
+
${libraryLogChecks}
|
|
172
|
+
${componentLogChecks}
|
|
173
|
+
|
|
174
|
+
const newProps = {
|
|
175
|
+
...props,
|
|
176
|
+
components: componentsOuter,
|
|
177
|
+
utilities: utilitiesOuter
|
|
178
|
+
}
|
|
179
|
+
return ActualComponent(newProps);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// Create a fresh method registry for each factory call
|
|
183
|
+
const methodRegistry = new Map();
|
|
184
|
+
|
|
185
|
+
// Create a wrapper component that provides RegisterMethod in callbacks
|
|
186
|
+
const ComponentWithMethodRegistry = (props) => {
|
|
187
|
+
// Register methods on mount
|
|
188
|
+
React.useEffect(() => {
|
|
189
|
+
// Clear previous methods
|
|
190
|
+
methodRegistry.clear();
|
|
191
|
+
|
|
192
|
+
// Provide RegisterMethod callback if callbacks exist
|
|
193
|
+
if (props.callbacks && typeof props.callbacks.RegisterMethod === 'function') {
|
|
194
|
+
// Component can now register its methods
|
|
195
|
+
// This will be called from within the component
|
|
196
|
+
}
|
|
197
|
+
}, [props.callbacks]);
|
|
198
|
+
|
|
199
|
+
// Create enhanced callbacks with RegisterMethod
|
|
200
|
+
const enhancedCallbacks = React.useMemo(() => {
|
|
201
|
+
if (!props.callbacks) return {};
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...props.callbacks,
|
|
205
|
+
RegisterMethod: (methodName, handler) => {
|
|
206
|
+
if (methodName && handler) {
|
|
207
|
+
methodRegistry.set(methodName, handler);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}, [props.callbacks]);
|
|
212
|
+
|
|
213
|
+
// Render the original component with enhanced callbacks
|
|
214
|
+
return React.createElement(DestructureWrapperUserComponent, {
|
|
215
|
+
...props,
|
|
216
|
+
callbacks: enhancedCallbacks
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
ComponentWithMethodRegistry.displayName = '${componentName}WithMethods';
|
|
108
221
|
|
|
109
|
-
// Return the component with
|
|
222
|
+
// Return the component object with method access
|
|
110
223
|
return {
|
|
111
|
-
component:
|
|
224
|
+
component: ComponentWithMethodRegistry,
|
|
225
|
+
|
|
112
226
|
print: function() {
|
|
113
|
-
|
|
227
|
+
const printMethod = methodRegistry.get('print');
|
|
228
|
+
if (printMethod) {
|
|
229
|
+
printMethod();
|
|
230
|
+
} else if (typeof window !== 'undefined' && window.print) {
|
|
114
231
|
window.print();
|
|
115
232
|
}
|
|
116
233
|
},
|
|
117
234
|
refresh: function(data) {
|
|
235
|
+
const refreshMethod = methodRegistry.get('refresh');
|
|
236
|
+
if (refreshMethod) {
|
|
237
|
+
refreshMethod(data);
|
|
238
|
+
}
|
|
118
239
|
// Refresh functionality is handled by the host environment
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
// Standard method accessors with type safety
|
|
243
|
+
getCurrentDataState: function() {
|
|
244
|
+
const method = methodRegistry.get('getCurrentDataState');
|
|
245
|
+
return method ? method() : undefined;
|
|
246
|
+
},
|
|
247
|
+
getDataStateHistory: function() {
|
|
248
|
+
const method = methodRegistry.get('getDataStateHistory');
|
|
249
|
+
return method ? method() : [];
|
|
250
|
+
},
|
|
251
|
+
validate: function() {
|
|
252
|
+
const method = methodRegistry.get('validate');
|
|
253
|
+
return method ? method() : true;
|
|
254
|
+
},
|
|
255
|
+
isDirty: function() {
|
|
256
|
+
const method = methodRegistry.get('isDirty');
|
|
257
|
+
return method ? method() : false;
|
|
258
|
+
},
|
|
259
|
+
reset: function() {
|
|
260
|
+
const method = methodRegistry.get('reset');
|
|
261
|
+
if (method) method();
|
|
262
|
+
},
|
|
263
|
+
scrollTo: function(target) {
|
|
264
|
+
const method = methodRegistry.get('scrollTo');
|
|
265
|
+
if (method) method(target);
|
|
266
|
+
},
|
|
267
|
+
focus: function(target) {
|
|
268
|
+
const method = methodRegistry.get('focus');
|
|
269
|
+
if (method) method(target);
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
// Generic method invoker for custom methods
|
|
273
|
+
invokeMethod: function(methodName, ...args) {
|
|
274
|
+
const method = methodRegistry.get(methodName);
|
|
275
|
+
if (method) {
|
|
276
|
+
return method(...args);
|
|
277
|
+
}
|
|
278
|
+
console.warn(\`[React-Runtime-JS] Method '\${methodName}' is not registered on component ${componentName}\`);
|
|
279
|
+
return undefined;
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
// Check if a method exists
|
|
283
|
+
hasMethod: function(methodName) {
|
|
284
|
+
return methodRegistry.has(methodName);
|
|
119
285
|
}
|
|
120
286
|
};
|
|
121
287
|
}
|
|
122
288
|
`;
|
|
289
|
+
return wrappedCode;
|
|
123
290
|
}
|
|
124
291
|
async loadRequiredLibraries(libraries, componentLibraries) {
|
|
125
292
|
const loadedLibraries = new Map();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
293
|
+
if (this.config.debug) {
|
|
294
|
+
console.log('đ loadRequiredLibraries called with:', {
|
|
295
|
+
librariesCount: libraries?.length || 0,
|
|
296
|
+
libraries: libraries?.map(l => ({ name: l.name, version: l.version, globalVariable: l.globalVariable }))
|
|
297
|
+
});
|
|
298
|
+
}
|
|
130
299
|
if (!libraries || libraries.length === 0) {
|
|
131
|
-
|
|
300
|
+
if (this.config.debug) {
|
|
301
|
+
console.log('đ No libraries to load, returning empty map');
|
|
302
|
+
}
|
|
132
303
|
return loadedLibraries;
|
|
133
304
|
}
|
|
134
305
|
if (typeof window === 'undefined') {
|
|
@@ -141,53 +312,69 @@ class ComponentCompiler {
|
|
|
141
312
|
else {
|
|
142
313
|
console.warn('â ī¸ No componentLibraries provided for LibraryRegistry initialization');
|
|
143
314
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
315
|
+
const libraryNames = libraries.map(lib => lib.name);
|
|
316
|
+
if (this.config.debug) {
|
|
317
|
+
console.log('đĻ Using dependency-aware loading for libraries:', libraryNames);
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const loadedLibraryMap = await library_loader_1.LibraryLoader.loadLibrariesWithDependencies(libraryNames, componentLibraries, 'component-compiler', { debug: this.config.debug });
|
|
321
|
+
for (const lib of libraries) {
|
|
322
|
+
const isApproved = library_registry_1.LibraryRegistry.isApproved(lib.name);
|
|
323
|
+
if (!isApproved) {
|
|
324
|
+
console.error(`â Library '${lib.name}' is not approved`);
|
|
325
|
+
throw new Error(`Library '${lib.name}' is not approved. Only approved libraries can be used.`);
|
|
326
|
+
}
|
|
327
|
+
const loadedValue = loadedLibraryMap.get(lib.name);
|
|
328
|
+
if (loadedValue) {
|
|
329
|
+
loadedLibraries.set(lib.globalVariable, loadedValue);
|
|
330
|
+
if (this.config.debug) {
|
|
331
|
+
console.log(`â
Mapped ${lib.name} to global variable ${lib.globalVariable}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
const globalValue = window[lib.globalVariable];
|
|
336
|
+
if (globalValue) {
|
|
337
|
+
loadedLibraries.set(lib.globalVariable, globalValue);
|
|
338
|
+
if (this.config.debug) {
|
|
339
|
+
console.log(`â
Found ${lib.name} already loaded as ${lib.globalVariable}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
console.error(`â Library '${lib.name}' failed to load`);
|
|
344
|
+
throw new Error(`Library '${lib.name}' failed to load or did not expose '${lib.globalVariable}'`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
174
347
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
loadedLibraries.set(lib.globalVariable, libraryValue);
|
|
181
|
-
console.log(` â
Added ${lib.name} to loaded libraries map`);
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
console.error('Failed to load libraries with dependencies:', error);
|
|
351
|
+
if (this.config.debug) {
|
|
352
|
+
console.warn('â ī¸ Falling back to non-dependency-aware loading due to error');
|
|
182
353
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
354
|
+
for (const lib of libraries) {
|
|
355
|
+
if (window[lib.globalVariable]) {
|
|
356
|
+
loadedLibraries.set(lib.globalVariable, window[lib.globalVariable]);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
const libraryDef = library_registry_1.LibraryRegistry.getLibrary(lib.name);
|
|
360
|
+
if (libraryDef) {
|
|
361
|
+
const resolvedVersion = library_registry_1.LibraryRegistry.resolveVersion(lib.name, lib.version);
|
|
362
|
+
const cdnUrl = library_registry_1.LibraryRegistry.getCdnUrl(lib.name, resolvedVersion);
|
|
363
|
+
if (cdnUrl) {
|
|
364
|
+
await this.loadScript(cdnUrl, lib.globalVariable);
|
|
365
|
+
const libraryValue = window[lib.globalVariable];
|
|
366
|
+
if (libraryValue) {
|
|
367
|
+
loadedLibraries.set(lib.globalVariable, libraryValue);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
186
372
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
373
|
+
}
|
|
374
|
+
if (this.config.debug) {
|
|
375
|
+
console.log(`â
All libraries loaded successfully. Total: ${loadedLibraries.size}`);
|
|
376
|
+
console.log('đ Loaded libraries map:', Array.from(loadedLibraries.keys()));
|
|
377
|
+
}
|
|
191
378
|
return loadedLibraries;
|
|
192
379
|
}
|
|
193
380
|
async loadStyles(urls) {
|
|
@@ -237,12 +424,17 @@ class ComponentCompiler {
|
|
|
237
424
|
const checkInterval = 100;
|
|
238
425
|
const checkGlobal = () => {
|
|
239
426
|
if (window[globalName]) {
|
|
240
|
-
|
|
427
|
+
if (this.config.debug) {
|
|
428
|
+
console.log(` â Global variable ${globalName} found after ${attempts * checkInterval}ms`);
|
|
429
|
+
}
|
|
241
430
|
resolve();
|
|
242
431
|
}
|
|
243
432
|
else if (attempts >= maxAttempts) {
|
|
244
|
-
|
|
245
|
-
|
|
433
|
+
if (this.config.debug) {
|
|
434
|
+
console.error(` â ${globalName} not found after ${attempts * checkInterval}ms`);
|
|
435
|
+
const matchingKeys = Object.keys(window).filter(k => k.toLowerCase().includes(globalName.toLowerCase()));
|
|
436
|
+
console.log(` âšī¸ Matching window properties: ${matchingKeys.join(', ') || 'none'}`);
|
|
437
|
+
}
|
|
246
438
|
reject(new Error(`${globalName} not found after loading script from ${url}`));
|
|
247
439
|
}
|
|
248
440
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-compiler.js","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":";;;AAeA,oEAAgE;AAMhE,MAAM,uBAAuB,GAAmB;IAC9C,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,OAAO,EAAE,EAAE;KACZ;IACD,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,IAAI;IACX,YAAY,EAAE,GAAG;CAClB,CAAC;AAMF,MAAa,iBAAiB;IAU5B,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;QACxD,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAMD,gBAAgB,CAAC,KAAU;QACzB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;IAOD,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YAEH,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACtB,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;gBACrF,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO;wBACL,OAAO,EAA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EAAE,CAAC;IAC9C,CAAC;CACF;AAxmBD,8CAwmBC","sourcesContent":["/**\n * @fileoverview Platform-agnostic React component compiler.\n * Compiles React component source code into executable components using Babel.\n * @module @memberjunction/react-runtime/compiler\n */\n\nimport { UserInfo } from '@memberjunction/core';\nimport { \n CompileOptions, \n CompiledComponent, \n CompilationResult,\n CompilerConfig,\n ComponentError,\n RuntimeContext\n} from '../types';\nimport { LibraryRegistry } from '../utilities/library-registry';\nimport { ComponentLibraryEntity } from '@memberjunction/core-entities';\n\n/**\n * Default compiler configuration\n */\nconst DEFAULT_COMPILER_CONFIG: CompilerConfig = {\n babel: {\n presets: ['react'],\n plugins: []\n },\n minify: false,\n sourceMaps: false,\n cache: true,\n maxCacheSize: 100\n};\n\n/**\n * Platform-agnostic React component compiler.\n * Transforms JSX/React component source code into executable JavaScript.\n */\nexport class ComponentCompiler {\n private config: CompilerConfig;\n private compilationCache: Map<string, CompiledComponent>;\n private cacheAccessOrder: string[]; // Track access order for LRU\n private babelInstance: any;\n\n /**\n * Creates a new ComponentCompiler instance\n * @param config - Optional compiler configuration\n */\n constructor(config?: Partial<CompilerConfig>) {\n this.config = { ...DEFAULT_COMPILER_CONFIG, ...config };\n this.compilationCache = new Map();\n }\n\n /**\n * Sets the Babel instance to use for compilation\n * @param babel - The Babel standalone instance\n */\n setBabelInstance(babel: any): void {\n this.babelInstance = babel;\n }\n\n /**\n * Compiles a React component from source code\n * @param options - Compilation options\n * @returns Promise resolving to compilation result\n */\n async compile(options: CompileOptions): Promise<CompilationResult> {\n const startTime = Date.now();\n\n try {\n // Check cache first if enabled\n if (this.config.cache) {\n const cached = this.getCachedComponent(options.componentName, options.componentCode);\n if (cached) {\n return {\n success: true,\n component: cached,\n duration: Date.now() - startTime\n };\n }\n }\n\n // Validate inputs\n this.validateCompileOptions(options);\n\n // Load required libraries if specified\n const loadedLibraries = await this.loadRequiredLibraries(options.libraries!, options.allLibraries);\n\n // Transpile the component code\n const transpiledCode = this.transpileComponent(\n options.componentCode,\n options.componentName,\n options\n );\n\n // Create the component factory with loaded libraries\n const componentFactory = this.createComponentFactory(\n transpiledCode,\n options.componentName,\n loadedLibraries\n );\n\n // Build the compiled component\n const compiledComponent: CompiledComponent = {\n component: componentFactory,\n id: this.generateComponentId(options.componentName),\n name: options.componentName,\n compiledAt: new Date(),\n warnings: []\n };\n\n // Cache if enabled\n if (this.config.cache) {\n this.cacheComponent(compiledComponent, options.componentCode);\n }\n\n return {\n success: true,\n component: compiledComponent,\n duration: Date.now() - startTime,\n size: transpiledCode.length\n };\n\n } catch (error) {\n return {\n success: false,\n error: this.createCompilationError(error, options.componentName),\n duration: Date.now() - startTime\n };\n }\n }\n\n /**\n * Transpiles JSX/React code to JavaScript\n * @param code - Source code to transpile\n * @param componentName - Name of the component\n * @param options - Compilation options\n * @returns Transpiled JavaScript code\n */\n private transpileComponent(\n code: string,\n componentName: string,\n options: CompileOptions\n ): string {\n if (!this.babelInstance) {\n throw new Error('Babel instance not set. Call setBabelInstance() first.');\n }\n\n const wrappedCode = this.wrapComponentCode(code, componentName, options.libraries, options.dependencies);\n\n try {\n const result = this.babelInstance.transform(wrappedCode, {\n presets: options.babelPresets || this.config.babel.presets,\n plugins: options.babelPlugins || this.config.babel.plugins,\n filename: `${componentName}.jsx`,\n sourceMaps: this.config.sourceMaps,\n minified: this.config.minify\n });\n\n return result.code;\n } catch (error: any) {\n throw new Error(`Transpilation failed: ${error.message}`);\n }\n }\n\n /**\n * Wraps component code in a factory function for execution\n * @param componentCode - Raw component code\n * @param componentName - Name of the component\n * @param libraries - Optional library dependencies\n * @param dependencies - Optional child component dependencies\n * @returns Wrapped component code\n */\n private wrapComponentCode(componentCode: string, componentName: string, libraries?: any[], dependencies?: Array<{ name: string }>): string {\n // Generate library declarations if libraries are provided\n const libraryDeclarations = libraries && libraries.length > 0\n ? libraries\n .filter(lib => lib.globalVariable) // Only include libraries with globalVariable\n .map(lib => `const ${lib.globalVariable} = libraries['${lib.globalVariable}'];`)\n .join('\\n ')\n : '';\n \n // Generate component declarations if dependencies are provided\n const componentDeclarations = dependencies && dependencies.length > 0\n ? dependencies\n .map(dep => `const ${dep.name} = components['${dep.name}'];`)\n .join('\\n ')\n : '';\n\n return `\n function createComponent(\n React, ReactDOM, \n useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer, useLayoutEffect,\n libraries, styles, console, components\n ) {\n ${libraryDeclarations ? libraryDeclarations + '\\n ' : ''}${componentDeclarations ? componentDeclarations + '\\n ' : ''}${componentCode}\n \n // Ensure the component exists\n if (typeof ${componentName} === 'undefined') {\n throw new Error('Component \"${componentName}\" is not defined in the provided code');\n }\n \n // Return the component with utilities\n return {\n component: ${componentName},\n print: function() { \n if (typeof window !== 'undefined' && window.print) {\n window.print(); \n }\n },\n refresh: function(data) { \n // Refresh functionality is handled by the host environment\n }\n };\n }\n `;\n }\n\n /**\n * Load required libraries from the registry\n * @param libraries - Array of library dependencies\n * @param contextUser - Context user for accessing library registry\n * @returns Map of loaded libraries\n */\n private async loadRequiredLibraries(libraries: any[], componentLibraries: ComponentLibraryEntity[]): Promise<Map<string, any>> {\n const loadedLibraries = new Map<string, any>();\n \n console.log('đ loadRequiredLibraries called with:', {\n librariesCount: libraries?.length || 0,\n libraries: libraries?.map(l => ({ name: l.name, version: l.version, globalVariable: l.globalVariable }))\n });\n \n if (!libraries || libraries.length === 0) {\n console.log('đ No libraries to load, returning empty map');\n return loadedLibraries;\n }\n\n // Only works in browser environment\n if (typeof window === 'undefined') {\n console.warn('Library loading is only supported in browser environments');\n return loadedLibraries;\n }\n\n // Initialize LibraryRegistry with componentLibraries if provided\n if (componentLibraries) {\n await LibraryRegistry.Config(false, componentLibraries);\n } else {\n console.warn('â ī¸ No componentLibraries provided for LibraryRegistry initialization');\n }\n\n const loadPromises = libraries.map(async (lib) => {\n console.log(`đĻ Processing library: ${lib.name}`);\n \n // Check if library is approved\n const isApproved = LibraryRegistry.isApproved(lib.name);\n console.log(` â Approved check for ${lib.name}: ${isApproved}`);\n \n if (!isApproved) {\n console.error(` â Library '${lib.name}' is not approved`);\n throw new Error(`Library '${lib.name}' is not approved. Only approved libraries can be used.`);\n }\n\n // Get library definition for complete info\n const libraryDef = LibraryRegistry.getLibrary(lib.name);\n console.log(` â Library definition found for ${lib.name}: ${!!libraryDef}`);\n \n if (!libraryDef) {\n console.error(` â Library '${lib.name}' not found in registry`);\n throw new Error(`Library '${lib.name}' not found in registry`);\n }\n\n // Get CDN URL for the library\n const resolvedVersion = LibraryRegistry.resolveVersion(lib.name, lib.version);\n console.log(` â Resolved version for ${lib.name}: ${resolvedVersion}`);\n \n const cdnUrl = LibraryRegistry.getCdnUrl(lib.name, resolvedVersion);\n console.log(` â CDN URL for ${lib.name}: ${cdnUrl}`);\n \n if (!cdnUrl) {\n console.error(` â No CDN URL found for library '${lib.name}' version '${lib.version || 'default'}'`);\n throw new Error(`No CDN URL found for library '${lib.name}' version '${lib.version || 'default'}'`);\n }\n\n // Check if already loaded\n if ((window as any)[lib.globalVariable]) {\n console.log(` âšī¸ Library ${lib.name} already loaded globally as ${lib.globalVariable}`);\n loadedLibraries.set(lib.globalVariable, (window as any)[lib.globalVariable]);\n return;\n }\n\n // Load CSS files if the library requires them\n const versionInfo = libraryDef.versions[resolvedVersion || libraryDef.defaultVersion];\n if (versionInfo?.cssUrls) {\n await this.loadStyles(versionInfo.cssUrls);\n }\n\n // Load the library dynamically (cdnUrl is guaranteed to be non-null here due to check above)\n console.log(` đĨ Loading script from CDN for ${lib.name}...`);\n await this.loadScript(cdnUrl!, lib.globalVariable);\n \n // Capture the library value from global scope\n // Note: Libraries loaded from CDN typically attach to window automatically\n // We capture them here to pass through the component's closure\n const libraryValue = (window as any)[lib.globalVariable];\n console.log(` â Library ${lib.name} loaded successfully, global variable ${lib.globalVariable} is:`, typeof libraryValue);\n \n if (libraryValue) {\n loadedLibraries.set(lib.globalVariable, libraryValue);\n console.log(` â
Added ${lib.name} to loaded libraries map`);\n } else {\n console.error(` â Library '${lib.name}' failed to expose global variable '${lib.globalVariable}'`);\n throw new Error(`Library '${lib.name}' failed to load or did not expose '${lib.globalVariable}'`);\n }\n });\n\n await Promise.all(loadPromises);\n \n console.log(`â
All libraries loaded successfully. Total: ${loadedLibraries.size}`);\n console.log('đ Loaded libraries map:', Array.from(loadedLibraries.keys()));\n \n return loadedLibraries;\n }\n\n /**\n * Load CSS stylesheets dynamically\n * @param urls - Array of CSS URLs to load\n * @returns Promise that resolves when all stylesheets are loaded\n */\n private async loadStyles(urls: string[]): Promise<void> {\n const loadPromises = urls.map(url => {\n return new Promise<void>((resolve) => {\n // Check if stylesheet already exists\n const existingLink = document.querySelector(`link[href=\"${url}\"]`);\n if (existingLink) {\n resolve();\n return;\n }\n\n // Create new link element\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n \n // CSS load events are not reliable cross-browser, so resolve immediately\n // The CSS will load asynchronously but won't block component rendering\n document.head.appendChild(link);\n resolve();\n });\n });\n\n await Promise.all(loadPromises);\n }\n\n /**\n * Load a script dynamically\n * @param url - Script URL\n * @param globalName - Expected global variable name\n * @returns Promise that resolves when script is loaded\n */\n private loadScript(url: string, globalName: string): Promise<void> {\n return new Promise((resolve, reject) => {\n // Check if script already exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n // Wait for it to finish loading with exponential backoff\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds total with 100ms intervals\n const checkLoaded = () => {\n if ((window as any)[globalName]) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(`${globalName} not found after ${maxAttempts * 100}ms waiting for existing script`));\n } else {\n attempts++;\n setTimeout(checkLoaded, 100);\n }\n };\n checkLoaded();\n return;\n }\n\n // Create new script element\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n \n script.onload = () => {\n // More robust checking with multiple attempts\n let attempts = 0;\n const maxAttempts = 20; // 2 seconds total\n const checkInterval = 100; // Check every 100ms\n \n const checkGlobal = () => {\n if ((window as any)[globalName]) {\n console.log(` â Global variable ${globalName} found after ${attempts * checkInterval}ms`);\n resolve();\n } else if (attempts >= maxAttempts) {\n // Final check - some libraries might use a different global name pattern\n console.error(` â ${globalName} not found after ${attempts * checkInterval}ms`);\n console.log(` âšī¸ Window properties:`, Object.keys(window).filter(k => k.toLowerCase().includes(globalName.toLowerCase())));\n reject(new Error(`${globalName} not found after loading script from ${url}`));\n } else {\n attempts++;\n setTimeout(checkGlobal, checkInterval);\n }\n };\n \n // Start checking immediately (don't wait 100ms first)\n checkGlobal();\n };\n \n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n \n document.head.appendChild(script);\n });\n }\n\n /**\n * Creates a component factory function from transpiled code\n * @param transpiledCode - Transpiled JavaScript code\n * @param componentName - Name of the component\n * @param loadedLibraries - Map of loaded libraries\n * @returns Component factory function\n */\n private createComponentFactory(\n transpiledCode: string, \n componentName: string,\n loadedLibraries: Map<string, any>\n ): Function {\n try {\n // Create the factory function with all React hooks\n const factoryCreator = new Function(\n 'React', 'ReactDOM',\n 'useState', 'useEffect', 'useCallback', 'useMemo', 'useRef', 'useContext', 'useReducer', 'useLayoutEffect',\n 'libraries', 'styles', 'console', 'components',\n `${transpiledCode}; return createComponent;`\n );\n\n // Return a function that executes the factory with runtime context\n return (context: RuntimeContext, styles: any = {}, components: Record<string, any> = {}) => {\n const { React, ReactDOM, libraries = {} } = context;\n \n // Merge loaded libraries with context libraries\n const mergedLibraries = { ...libraries };\n loadedLibraries.forEach((value, key) => {\n mergedLibraries[key] = value;\n });\n\n // Execute the factory creator to get the createComponent function\n const createComponentFn = factoryCreator(\n React,\n ReactDOM,\n React.useState,\n React.useEffect,\n React.useCallback,\n React.useMemo,\n React.useRef,\n React.useContext,\n React.useReducer,\n React.useLayoutEffect,\n mergedLibraries,\n styles,\n console,\n components\n );\n\n // Call createComponent to get the actual component\n const Component = createComponentFn(\n React,\n ReactDOM,\n React.useState,\n React.useEffect,\n React.useCallback,\n React.useMemo,\n React.useRef,\n React.useContext,\n React.useReducer,\n React.useLayoutEffect,\n mergedLibraries,\n styles,\n console,\n components\n );\n\n // Return the component directly\n return Component;\n };\n } catch (error: any) {\n throw new Error(`Failed to create component factory: ${error.message}`);\n }\n }\n\n\n /**\n * Validates compilation options\n * @param options - Options to validate\n * @throws Error if validation fails\n */\n private validateCompileOptions(options: CompileOptions): void {\n // Check if options object exists\n if (!options) {\n throw new Error(\n 'Component compilation failed: No options provided.\\n' +\n 'Expected an object with componentName and componentCode properties.\\n' +\n 'Example: { componentName: \"MyComponent\", componentCode: \"function MyComponent() { ... }\" }'\n );\n }\n\n // Check component name\n if (!options.componentName) {\n const providedKeys = Object.keys(options).join(', ');\n throw new Error(\n 'Component compilation failed: Component name is required.\\n' +\n `Received options with keys: [${providedKeys}]\\n` +\n 'Please ensure your component spec includes a \"name\" property.\\n' +\n 'Example: { name: \"MyComponent\", code: \"...\" }'\n );\n }\n\n // Check component code\n if (!options.componentCode) {\n throw new Error(\n `Component compilation failed: Component code is required for \"${options.componentName}\".\\n` +\n 'Please ensure your component spec includes a \"code\" property with the component source code.\\n' +\n 'Example: { name: \"MyComponent\", code: \"function MyComponent() { return <div>Hello</div>; }\" }'\n );\n }\n\n // Check code type\n if (typeof options.componentCode !== 'string') {\n const actualType = typeof options.componentCode;\n throw new Error(\n `Component compilation failed: Component code must be a string for \"${options.componentName}\".\\n` +\n `Received type: ${actualType}\\n` +\n `Received value: ${JSON.stringify(options.componentCode).substring(0, 100)}...\\n` +\n 'Please ensure the code property contains a string of JavaScript/JSX code.'\n );\n }\n\n // Check if code is empty or whitespace only\n if (options.componentCode.trim().length === 0) {\n throw new Error(\n `Component compilation failed: Component code is empty for \"${options.componentName}\".\\n` +\n 'The code property must contain valid JavaScript/JSX code defining a React component.'\n );\n }\n\n // Basic syntax check\n if (!options.componentCode.includes(options.componentName)) {\n throw new Error(\n `Component compilation failed: Component code must define a component named \"${options.componentName}\".\\n` +\n 'The function/component name in the code must match the componentName property.\\n' +\n `Expected to find: function ${options.componentName}(...) or const ${options.componentName} = ...\\n` +\n 'Code preview: ' + options.componentCode.substring(0, 200) + '...'\n );\n }\n }\n\n /**\n * Generates a unique component ID\n * @param componentName - Name of the component\n * @returns Unique component ID\n */\n private generateComponentId(componentName: string): string {\n return `${componentName}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n }\n\n /**\n * Gets a cached component if available\n * @param componentName - Name of the component\n * @param code - Component source code\n * @returns Cached component or undefined\n */\n private getCachedComponent(componentName: string, code: string): CompiledComponent | undefined {\n // Create cache key based on name AND content hash\n const cacheKey = this.createCacheKey(componentName, code);\n return this.compilationCache.get(cacheKey);\n }\n\n /**\n * Creates a cache key based on component name and code content\n * @param componentName - Name of the component\n * @param code - Component source code\n * @returns Cache key\n */\n private createCacheKey(componentName: string, code: string): string {\n // Simple hash function for code content\n let hash = 0;\n for (let i = 0; i < code.length; i++) {\n const char = code.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return `${componentName}_${hash.toString(36)}`;\n }\n\n /**\n * Caches a compiled component\n * @param component - Component to cache\n * @param code - Original source code\n */\n private cacheComponent(component: CompiledComponent, code: string): void {\n // Enforce cache size limit\n if (this.compilationCache.size >= this.config.maxCacheSize) {\n // Remove oldest entry (first in map)\n const firstKey = this.compilationCache.keys().next().value;\n if (firstKey)\n this.compilationCache.delete(firstKey);\n }\n\n const cacheKey = this.createCacheKey(component.name, code);\n this.compilationCache.set(cacheKey, component);\n }\n\n /**\n * Creates a standardized compilation error\n * @param error - Original error\n * @param componentName - Name of the component\n * @returns Formatted component error\n */\n private createCompilationError(error: any, componentName: string): ComponentError {\n return {\n message: error.message || 'Unknown compilation error',\n stack: error.stack,\n componentName,\n phase: 'compilation',\n details: error\n };\n }\n\n /**\n * Clears the compilation cache\n */\n clearCache(): void {\n this.compilationCache.clear();\n }\n\n /**\n * Gets current cache size\n * @returns Number of cached components\n */\n getCacheSize(): number {\n return this.compilationCache.size;\n }\n\n /**\n * Updates compiler configuration\n * @param config - New configuration options\n */\n updateConfig(config: Partial<CompilerConfig>): void {\n this.config = { ...this.config, ...config };\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"component-compiler.js","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":";;;AAgBA,oEAAgE;AAChE,gEAA4D;AAM5D,MAAM,uBAAuB,GAAmB;IAC9C,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,OAAO,EAAE,EAAE;KACZ;IACD,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,IAAI;IACX,YAAY,EAAE,GAAG;IACjB,KAAK,EAAE,KAAK;CACb,CAAC;AAMF,MAAa,iBAAiB;IAU5B,YAAY,MAAgC;QA8H3B,mBAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;QA7H/D,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;QACxD,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAMD,gBAAgB,CAAC,KAAU;QACzB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;IAOD,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YAEH,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACtB,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;gBACrF,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,SAAS,EAAE,MAAM;wBACjB,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;qBAC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C9D,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,2BAA2B;YACrD,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,aAAa;YACb,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;IAKD,UAAU;QACR,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAMD,YAAY;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;IACpC,CAAC;IAMD,YAAY,CAAC,MAA+B;QAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAC9C,CAAC;CACF;AA3yBD,8CA2yBC","sourcesContent":["/**\n * @fileoverview Platform-agnostic React component compiler.\n * Compiles React component source code into executable components using Babel.\n * @module @memberjunction/react-runtime/compiler\n */\n\nimport { UserInfo } from '@memberjunction/core';\nimport { \n CompileOptions, \n CompiledComponent, \n CompilationResult,\n CompilerConfig,\n ComponentError,\n RuntimeContext\n} from '../types';\nimport { ComponentStyles, ComponentObject } from '@memberjunction/interactive-component-types';\nimport { LibraryRegistry } from '../utilities/library-registry';\nimport { LibraryLoader } from '../utilities/library-loader';\nimport { ComponentLibraryEntity } from '@memberjunction/core-entities';\n\n/**\n * Default compiler configuration\n */\nconst DEFAULT_COMPILER_CONFIG: CompilerConfig = {\n babel: {\n presets: ['react'],\n plugins: []\n },\n minify: false,\n sourceMaps: false,\n cache: true,\n maxCacheSize: 100,\n debug: false\n};\n\n/**\n * Platform-agnostic React component compiler.\n * Transforms JSX/React component source code into executable JavaScript.\n */\nexport class ComponentCompiler {\n private config: CompilerConfig;\n private compilationCache: Map<string, CompiledComponent>;\n private cacheAccessOrder: string[]; // Track access order for LRU\n private babelInstance: any;\n\n /**\n * Creates a new ComponentCompiler instance\n * @param config - Optional compiler configuration\n */\n constructor(config?: Partial<CompilerConfig>) {\n this.config = { ...DEFAULT_COMPILER_CONFIG, ...config };\n this.compilationCache = new Map();\n }\n\n /**\n * Sets the Babel instance to use for compilation\n * @param babel - The Babel standalone instance\n */\n setBabelInstance(babel: any): void {\n this.babelInstance = babel;\n }\n\n /**\n * Compiles a React component from source code\n * @param options - Compilation options\n * @returns Promise resolving to compilation result\n */\n async compile(options: CompileOptions): Promise<CompilationResult> {\n const startTime = Date.now();\n\n try {\n // Check cache first if enabled\n if (this.config.cache) {\n const cached = this.getCachedComponent(options.componentName, options.componentCode);\n if (cached) {\n return {\n success: true,\n component: cached,\n duration: Date.now() - startTime\n };\n }\n }\n\n // Validate inputs\n this.validateCompileOptions(options);\n\n // Load required libraries if specified\n const loadedLibraries = await this.loadRequiredLibraries(options.libraries!, options.allLibraries);\n\n // Transpile the component code\n const transpiledCode = this.transpileComponent(\n options.componentCode,\n options.componentName,\n options\n );\n\n // Create the component factory with loaded libraries\n const componentFactory = this.createComponentFactory(\n transpiledCode,\n options.componentName,\n loadedLibraries\n );\n\n // Build the compiled component\n const compiledComponent: CompiledComponent = {\n factory: componentFactory,\n id: this.generateComponentId(options.componentName),\n name: options.componentName,\n compiledAt: new Date(),\n warnings: []\n };\n\n // Cache if enabled\n if (this.config.cache) {\n this.cacheComponent(compiledComponent, options.componentCode);\n }\n\n return {\n success: true,\n component: compiledComponent,\n duration: Date.now() - startTime,\n size: transpiledCode.length\n };\n\n } catch (error) {\n return {\n success: false,\n error: this.createCompilationError(error, options.componentName),\n duration: Date.now() - startTime\n };\n }\n }\n\n /**\n * Transpiles JSX/React code to JavaScript\n * @param code - Source code to transpile\n * @param componentName - Name of the component\n * @param options - Compilation options\n * @returns Transpiled JavaScript code\n */\n private transpileComponent(\n code: string,\n componentName: string,\n options: CompileOptions\n ): string {\n if (!this.babelInstance) {\n throw new Error('Babel instance not set. Call setBabelInstance() first.');\n }\n\n const wrappedCode = this.wrapComponentCode(code, componentName, options.libraries, options.dependencies);\n\n try {\n const result = this.babelInstance.transform(wrappedCode, {\n presets: options.babelPresets || this.config.babel.presets,\n plugins: options.babelPlugins || this.config.babel.plugins,\n filename: `${componentName}.jsx`,\n sourceMaps: this.config.sourceMaps,\n minified: this.config.minify\n });\n\n return result.code;\n } catch (error: any) {\n throw new Error(`Transpilation failed: ${error.message}`);\n }\n }\n\n /**\n * Wraps component code in a factory function for execution\n * @param componentCode - Raw component code\n * @param componentName - Name of the component\n * @param libraries - Optional library dependencies\n * @param dependencies - Optional child component dependencies\n * @returns Wrapped component code\n */\n // Core libraries that are passed as parameters to createComponent and should not be destructured\n private readonly CORE_LIBRARIES = new Set(['React', 'ReactDOM']);\n\n private wrapComponentCode(componentCode: string, componentName: string, libraries?: any[], dependencies?: Array<{ name: string }>): string {\n // Generate library declarations if libraries are provided\n // Skip core libraries as they're passed as parameters to createComponent\n const libraryDeclarations = libraries && libraries.length > 0\n ? libraries\n .filter(lib => lib.globalVariable && !this.CORE_LIBRARIES.has(lib.globalVariable)) // Skip core libraries\n .map(lib => `const ${lib.globalVariable} = libraries['${lib.globalVariable}'];`)\n .join('\\n ')\n : '';\n const libraryLogChecks = libraries && libraries.length > 0 \n ? libraries\n .filter(lib => lib.globalVariable && !this.CORE_LIBRARIES.has(lib.globalVariable)) // Skip core libraries\n .map(lib => `\\nif (!${lib.globalVariable}) { console.error('[React-Runtime-JS] Library \"${lib.globalVariable}\" is not defined'); } else { console.log('[React-Runtime-JS] Library \"${lib.globalVariable}\" is defined'); }`)\n .join('\\n ')\n : '';\n\n // Generate component declarations if dependencies are provided\n // Filter out the component being compiled to avoid naming conflicts\n const componentDeclarations = dependencies && dependencies.length > 0\n ? dependencies\n .filter(dep => dep.name !== componentName) // Don't destructure the component being compiled itself\n .map(dep => `const ${dep.name} = componentsOuter['${dep.name}'];`)\n .join('\\n ')\n : '';\n const componentLogChecks = dependencies && dependencies.length > 0\n ? dependencies\n .filter(dep => dep.name !== componentName) // Don't destructure the component being compiled itself\n .map(dep => `if (!${dep.name}) { console.error('[React-Runtime-JS] Dependency \"${dep.name}\" is not defined'); } else { console.log('[React-Runtime-JS] Dependency \"${dep.name}\" is defined'); }`)\n .join('\\n ')\n : '';\n\n const wrappedCode = `\n function createComponent(\n React, ReactDOM, \n useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer, useLayoutEffect,\n libraries, styles, console, components\n ) {\n // Code for ${componentName}\n ${componentCode}\n \n // Ensure the component exists\n if (typeof ${componentName} === 'undefined') {\n throw new Error('Component \"${componentName}\" is not defined in the provided code');\n }\n else {\n console.log('[React-Runtime-JS] Component \"${componentName}\" is defined');\n }\n \n // Store the component in a variable so we don't lose it\n const UserComponent = ${componentName};\n\n // Check if the component is already a ComponentObject (has a .component property)\n // If so, extract the actual React component\n const ActualComponent = (typeof UserComponent === 'object' && UserComponent !== null && 'component' in UserComponent)\n ? UserComponent.component\n : UserComponent;\n \n // Debug logging to understand what we're getting\n console.log('[React-Runtime-JS]Component ${componentName} type:', typeof UserComponent);\n if (typeof UserComponent === 'object' && UserComponent !== null) {\n console.log('[React-Runtime-JS]Component ${componentName} keys:', Object.keys(UserComponent));\n console.log('[React-Runtime-JS]Component ${componentName} has .component:', 'component' in UserComponent);\n if ('component' in UserComponent) {\n console.log('[React-Runtime-JS]Component ${componentName}.component type:', typeof UserComponent.component);\n }\n }\n \n // Validate that we have a function (React component)\n if (typeof ActualComponent !== 'function') {\n console.error('[React-Runtime-JS] Invalid component type for ${componentName}:', typeof ActualComponent);\n console.error('[React-Runtime-JS] ActualComponent value:', ActualComponent);\n console.error('[React-Runtime-JS] Original UserComponent value:', UserComponent);\n throw new Error('[React-Runtime-JS] Component \"${componentName}\" must be a function (React component) or an object with a .component property that is a function. Got: ' + typeof ActualComponent);\n }\n\n let componentsOuter = null, utilitiesOuter = null;\n const DestructureWrapperUserComponent = (props) => {\n if (!componentsOuter) {\n componentsOuter = props?.components || components;\n }\n if (!utilitiesOuter) {\n utilitiesOuter = props?.utilities;\n }\n console.log('Props for ${componentName}:', props);\n console.log('components for ${componentName}:', componentsOuter);\n console.log('styles for ${componentName}:', styles);\n console.log('utilities for ${componentName}:', utilitiesOuter);\n console.log('libraries for ${componentName}:', libraries);\n ${libraryDeclarations ? '// Destructure Libraries\\n' + libraryDeclarations + '\\n ' : ''}\n ${componentDeclarations ? '// Destructure Dependencies\\n' + componentDeclarations + '\\n ' : ''}\n ${libraryLogChecks}\n ${componentLogChecks} \n\n const newProps = {\n ...props,\n components: componentsOuter,\n utilities: utilitiesOuter \n }\n return ActualComponent(newProps);\n };\n \n // Create a fresh method registry for each factory call\n const methodRegistry = new Map();\n \n // Create a wrapper component that provides RegisterMethod in callbacks\n const ComponentWithMethodRegistry = (props) => {\n // Register methods on mount\n React.useEffect(() => {\n // Clear previous methods\n methodRegistry.clear();\n \n // Provide RegisterMethod callback if callbacks exist\n if (props.callbacks && typeof props.callbacks.RegisterMethod === 'function') {\n // Component can now register its methods\n // This will be called from within the component\n }\n }, [props.callbacks]);\n \n // Create enhanced callbacks with RegisterMethod\n const enhancedCallbacks = React.useMemo(() => {\n if (!props.callbacks) return {};\n \n return {\n ...props.callbacks,\n RegisterMethod: (methodName, handler) => {\n if (methodName && handler) {\n methodRegistry.set(methodName, handler);\n }\n }\n };\n }, [props.callbacks]);\n \n // Render the original component with enhanced callbacks\n return React.createElement(DestructureWrapperUserComponent, {\n ...props,\n callbacks: enhancedCallbacks\n });\n };\n \n ComponentWithMethodRegistry.displayName = '${componentName}WithMethods';\n \n // Return the component object with method access\n return {\n component: ComponentWithMethodRegistry,\n \n print: function() { \n const printMethod = methodRegistry.get('print');\n if (printMethod) {\n printMethod();\n } else if (typeof window !== 'undefined' && window.print) {\n window.print(); \n }\n },\n refresh: function(data) { \n const refreshMethod = methodRegistry.get('refresh');\n if (refreshMethod) {\n refreshMethod(data);\n }\n // Refresh functionality is handled by the host environment\n },\n \n // Standard method accessors with type safety\n getCurrentDataState: function() {\n const method = methodRegistry.get('getCurrentDataState');\n return method ? method() : undefined;\n },\n getDataStateHistory: function() {\n const method = methodRegistry.get('getDataStateHistory');\n return method ? method() : [];\n },\n validate: function() {\n const method = methodRegistry.get('validate');\n return method ? method() : true;\n },\n isDirty: function() {\n const method = methodRegistry.get('isDirty');\n return method ? method() : false;\n },\n reset: function() {\n const method = methodRegistry.get('reset');\n if (method) method();\n },\n scrollTo: function(target) {\n const method = methodRegistry.get('scrollTo');\n if (method) method(target);\n },\n focus: function(target) {\n const method = methodRegistry.get('focus');\n if (method) method(target);\n },\n \n // Generic method invoker for custom methods\n invokeMethod: function(methodName, ...args) {\n const method = methodRegistry.get(methodName);\n if (method) {\n return method(...args);\n }\n console.warn(\\`[React-Runtime-JS] Method '\\${methodName}' is not registered on component ${componentName}\\`);\n return undefined;\n },\n \n // Check if a method exists\n hasMethod: function(methodName) {\n return methodRegistry.has(methodName);\n }\n };\n }\n `;\n\n return wrappedCode;\n }\n\n /**\n * Load required libraries from the registry with dependency resolution\n * @param libraries - Array of library dependencies\n * @param componentLibraries - All available component libraries for dependency resolution\n * @returns Map of loaded libraries\n */\n private async loadRequiredLibraries(libraries: any[], componentLibraries: ComponentLibraryEntity[]): Promise<Map<string, any>> {\n const loadedLibraries = new Map<string, any>();\n \n if (this.config.debug) {\n console.log('đ loadRequiredLibraries called with:', {\n librariesCount: libraries?.length || 0,\n libraries: libraries?.map(l => ({ name: l.name, version: l.version, globalVariable: l.globalVariable }))\n });\n }\n \n if (!libraries || libraries.length === 0) {\n if (this.config.debug) {\n console.log('đ No libraries to load, returning empty map');\n }\n return loadedLibraries;\n }\n\n // Only works in browser environment\n if (typeof window === 'undefined') {\n console.warn('Library loading is only supported in browser environments');\n return loadedLibraries;\n }\n\n // Initialize LibraryRegistry with componentLibraries if provided\n if (componentLibraries) {\n await LibraryRegistry.Config(false, componentLibraries);\n } else {\n console.warn('â ī¸ No componentLibraries provided for LibraryRegistry initialization');\n }\n\n // Extract library names from the requested libraries\n const libraryNames = libraries.map(lib => lib.name);\n \n if (this.config.debug) {\n console.log('đĻ Using dependency-aware loading for libraries:', libraryNames);\n }\n\n try {\n // Use the new dependency-aware loading\n const loadedLibraryMap = await LibraryLoader.loadLibrariesWithDependencies(\n libraryNames,\n componentLibraries,\n 'component-compiler',\n { debug: this.config.debug }\n );\n\n // Map the results to match the expected format\n // We need to map from library name to global variable\n for (const lib of libraries) {\n // Check if library is approved first\n const isApproved = LibraryRegistry.isApproved(lib.name);\n if (!isApproved) {\n console.error(`â Library '${lib.name}' is not approved`);\n throw new Error(`Library '${lib.name}' is not approved. Only approved libraries can be used.`);\n }\n\n // Get the loaded library from the map\n const loadedValue = loadedLibraryMap.get(lib.name);\n \n if (loadedValue) {\n // Store by global variable name for component access\n loadedLibraries.set(lib.globalVariable, loadedValue);\n if (this.config.debug) {\n console.log(`â
Mapped ${lib.name} to global variable ${lib.globalVariable}`);\n }\n } else {\n // Fallback: check if it's already globally available (might be a dependency)\n const globalValue = (window as any)[lib.globalVariable];\n if (globalValue) {\n loadedLibraries.set(lib.globalVariable, globalValue);\n if (this.config.debug) {\n console.log(`â
Found ${lib.name} already loaded as ${lib.globalVariable}`);\n }\n } else {\n console.error(`â Library '${lib.name}' failed to load`);\n throw new Error(`Library '${lib.name}' failed to load or did not expose '${lib.globalVariable}'`);\n }\n }\n }\n } catch (error: any) {\n console.error('Failed to load libraries with dependencies:', error);\n \n // Fallback to old loading method if dependency resolution fails\n if (this.config.debug) {\n console.warn('â ī¸ Falling back to non-dependency-aware loading due to error');\n }\n \n // Load each library independently (old method)\n for (const lib of libraries) {\n if ((window as any)[lib.globalVariable]) {\n loadedLibraries.set(lib.globalVariable, (window as any)[lib.globalVariable]);\n } else {\n // Try to load using LibraryRegistry\n const libraryDef = LibraryRegistry.getLibrary(lib.name);\n if (libraryDef) {\n const resolvedVersion = LibraryRegistry.resolveVersion(lib.name, lib.version);\n const cdnUrl = LibraryRegistry.getCdnUrl(lib.name, resolvedVersion);\n \n if (cdnUrl) {\n await this.loadScript(cdnUrl, lib.globalVariable);\n const libraryValue = (window as any)[lib.globalVariable];\n if (libraryValue) {\n loadedLibraries.set(lib.globalVariable, libraryValue);\n }\n }\n }\n }\n }\n }\n \n if (this.config.debug) {\n console.log(`â
All libraries loaded successfully. Total: ${loadedLibraries.size}`);\n console.log('đ Loaded libraries map:', Array.from(loadedLibraries.keys()));\n }\n \n return loadedLibraries;\n }\n\n /**\n * Load CSS stylesheets dynamically\n * @param urls - Array of CSS URLs to load\n * @returns Promise that resolves when all stylesheets are loaded\n */\n private async loadStyles(urls: string[]): Promise<void> {\n const loadPromises = urls.map(url => {\n return new Promise<void>((resolve) => {\n // Check if stylesheet already exists\n const existingLink = document.querySelector(`link[href=\"${url}\"]`);\n if (existingLink) {\n resolve();\n return;\n }\n\n // Create new link element\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n \n // CSS load events are not reliable cross-browser, so resolve immediately\n // The CSS will load asynchronously but won't block component rendering\n document.head.appendChild(link);\n resolve();\n });\n });\n\n await Promise.all(loadPromises);\n }\n\n /**\n * Load a script dynamically\n * @param url - Script URL\n * @param globalName - Expected global variable name\n * @returns Promise that resolves when script is loaded\n */\n private loadScript(url: string, globalName: string): Promise<void> {\n return new Promise((resolve, reject) => {\n // Check if script already exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n // Wait for it to finish loading with exponential backoff\n let attempts = 0;\n const maxAttempts = 50; // 5 seconds total with 100ms intervals\n const checkLoaded = () => {\n if ((window as any)[globalName]) {\n resolve();\n } else if (attempts >= maxAttempts) {\n reject(new Error(`${globalName} not found after ${maxAttempts * 100}ms waiting for existing script`));\n } else {\n attempts++;\n setTimeout(checkLoaded, 100);\n }\n };\n checkLoaded();\n return;\n }\n\n // Create new script element\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n \n script.onload = () => {\n // More robust checking with multiple attempts\n let attempts = 0;\n const maxAttempts = 20; // 2 seconds total\n const checkInterval = 100; // Check every 100ms\n \n const checkGlobal = () => {\n if ((window as any)[globalName]) {\n if (this.config.debug) {\n console.log(` â Global variable ${globalName} found after ${attempts * checkInterval}ms`);\n }\n resolve();\n } else if (attempts >= maxAttempts) {\n // Final check - some libraries might use a different global name pattern\n if (this.config.debug) {\n console.error(` â ${globalName} not found after ${attempts * checkInterval}ms`);\n // Only log matching property names, not the entire window object\n const matchingKeys = Object.keys(window).filter(k => k.toLowerCase().includes(globalName.toLowerCase()));\n console.log(` âšī¸ Matching window properties: ${matchingKeys.join(', ') || 'none'}`);\n }\n reject(new Error(`${globalName} not found after loading script from ${url}`));\n } else {\n attempts++;\n setTimeout(checkGlobal, checkInterval);\n }\n };\n \n // Start checking immediately (don't wait 100ms first)\n checkGlobal();\n };\n \n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n \n document.head.appendChild(script);\n });\n }\n\n /**\n * Creates a component factory function from transpiled code\n * @param transpiledCode - Transpiled JavaScript code\n * @param componentName - Name of the component\n * @param loadedLibraries - Map of loaded libraries\n * @returns Component factory function\n */\n private createComponentFactory(\n transpiledCode: string, \n componentName: string,\n loadedLibraries: Map<string, any>\n ): (context: RuntimeContext, styles?: ComponentStyles) => ComponentObject {\n try {\n // Create the factory function with all React hooks\n const factoryCreator = new Function(\n 'React', 'ReactDOM',\n 'useState', 'useEffect', 'useCallback', 'useMemo', 'useRef', 'useContext', 'useReducer', 'useLayoutEffect',\n 'libraries', 'styles', 'console', 'components',\n `${transpiledCode}; return createComponent;`\n );\n\n // Return a function that executes the factory with runtime context\n return (context: RuntimeContext, styles: any = {}, components: Record<string, any> = {}) => {\n const { React, ReactDOM, libraries = {} } = context;\n \n // Merge loaded libraries with context libraries\n const mergedLibraries = { ...libraries };\n loadedLibraries.forEach((value, key) => {\n mergedLibraries[key] = value;\n });\n\n // Execute the factory creator to get the createComponent function\n const createComponentFn = factoryCreator(\n React,\n ReactDOM,\n React.useState,\n React.useEffect,\n React.useCallback,\n React.useMemo,\n React.useRef,\n React.useContext,\n React.useReducer,\n React.useLayoutEffect,\n mergedLibraries,\n styles,\n console,\n components\n );\n\n // Call createComponent to get the actual component\n const Component = createComponentFn(\n React,\n ReactDOM,\n React.useState,\n React.useEffect,\n React.useCallback,\n React.useMemo,\n React.useRef,\n React.useContext,\n React.useReducer,\n React.useLayoutEffect,\n mergedLibraries,\n styles,\n console,\n components\n );\n\n // Return the component directly\n return Component;\n };\n } catch (error: any) {\n throw new Error(`Failed to create component factory: ${error.message}`);\n }\n }\n\n\n /**\n * Validates compilation options\n * @param options - Options to validate\n * @throws Error if validation fails\n */\n private validateCompileOptions(options: CompileOptions): void {\n // Check if options object exists\n if (!options) {\n throw new Error(\n 'Component compilation failed: No options provided.\\n' +\n 'Expected an object with componentName and componentCode properties.\\n' +\n 'Example: { componentName: \"MyComponent\", componentCode: \"function MyComponent() { ... }\" }'\n );\n }\n\n // Check component name\n if (!options.componentName) {\n const providedKeys = Object.keys(options).join(', ');\n throw new Error(\n 'Component compilation failed: Component name is required.\\n' +\n `Received options with keys: [${providedKeys}]\\n` +\n 'Please ensure your component spec includes a \"name\" property.\\n' +\n 'Example: { name: \"MyComponent\", code: \"...\" }'\n );\n }\n\n // Check component code\n if (!options.componentCode) {\n throw new Error(\n `Component compilation failed: Component code is required for \"${options.componentName}\".\\n` +\n 'Please ensure your component spec includes a \"code\" property with the component source code.\\n' +\n 'Example: { name: \"MyComponent\", code: \"function MyComponent() { return <div>Hello</div>; }\" }'\n );\n }\n\n // Check code type\n if (typeof options.componentCode !== 'string') {\n const actualType = typeof options.componentCode;\n throw new Error(\n `Component compilation failed: Component code must be a string for \"${options.componentName}\".\\n` +\n `Received type: ${actualType}\\n` +\n `Received value: ${JSON.stringify(options.componentCode).substring(0, 100)}...\\n` +\n 'Please ensure the code property contains a string of JavaScript/JSX code.'\n );\n }\n\n // Check if code is empty or whitespace only\n if (options.componentCode.trim().length === 0) {\n throw new Error(\n `Component compilation failed: Component code is empty for \"${options.componentName}\".\\n` +\n 'The code property must contain valid JavaScript/JSX code defining a React component.'\n );\n }\n\n // Basic syntax check\n if (!options.componentCode.includes(options.componentName)) {\n throw new Error(\n `Component compilation failed: Component code must define a component named \"${options.componentName}\".\\n` +\n 'The function/component name in the code must match the componentName property.\\n' +\n `Expected to find: function ${options.componentName}(...) or const ${options.componentName} = ...\\n` +\n 'Code preview: ' + options.componentCode.substring(0, 200) + '...'\n );\n }\n }\n\n /**\n * Generates a unique component ID\n * @param componentName - Name of the component\n * @returns Unique component ID\n */\n private generateComponentId(componentName: string): string {\n return `${componentName}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;\n }\n\n /**\n * Gets a cached component if available\n * @param componentName - Name of the component\n * @param code - Component source code\n * @returns Cached component or undefined\n */\n private getCachedComponent(componentName: string, code: string): CompiledComponent | undefined {\n // Create cache key based on name AND content hash\n const cacheKey = this.createCacheKey(componentName, code);\n return this.compilationCache.get(cacheKey);\n }\n\n /**\n * Creates a cache key based on component name and code content\n * @param componentName - Name of the component\n * @param code - Component source code\n * @returns Cache key\n */\n private createCacheKey(componentName: string, code: string): string {\n // Simple hash function for code content\n let hash = 0;\n for (let i = 0; i < code.length; i++) {\n const char = code.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n return `${componentName}_${hash.toString(36)}`;\n }\n\n /**\n * Caches a compiled component\n * @param component - Component to cache\n * @param code - Original source code\n */\n private cacheComponent(component: CompiledComponent, code: string): void {\n // Enforce cache size limit\n if (this.compilationCache.size >= this.config.maxCacheSize) {\n // Remove oldest entry (first in map)\n const firstKey = this.compilationCache.keys().next().value;\n if (firstKey)\n this.compilationCache.delete(firstKey);\n }\n\n const cacheKey = this.createCacheKey(component.name, code);\n this.compilationCache.set(cacheKey, component);\n }\n\n /**\n * Creates a standardized compilation error\n * @param error - Original error\n * @param componentName - Name of the component\n * @returns Formatted component error\n */\n private createCompilationError(error: any, componentName: string): ComponentError {\n return {\n message: error.message || 'Unknown compilation error',\n stack: error.stack,\n componentName,\n phase: 'compilation',\n details: error\n };\n }\n\n /**\n * Clears the compilation cache\n */\n clearCache(): void {\n this.compilationCache.clear();\n }\n\n /**\n * Gets current cache size\n * @returns Number of cached components\n */\n getCacheSize(): number {\n return this.compilationCache.size;\n }\n\n /**\n * Updates compiler configuration\n * @param config - New configuration options\n */\n updateConfig(config: Partial<CompilerConfig>): void {\n this.config = { ...this.config, ...config };\n }\n}"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './types';
|
|
|
5
5
|
export { ComponentCompiler } from './compiler';
|
|
6
6
|
export { DEFAULT_PRESETS, DEFAULT_PLUGINS, PRODUCTION_CONFIG, DEVELOPMENT_CONFIG, getBabelConfig, validateBabelPresets, getJSXConfig } from './compiler';
|
|
7
7
|
export { ComponentRegistry } from './registry';
|
|
8
|
-
export { ComponentResolver, ComponentSpec, ResolvedComponents } from './registry';
|
|
8
|
+
export { ComponentResolver, ComponentSpec, ResolvedComponents, ComponentRegistryService } from './registry';
|
|
9
9
|
export { createErrorBoundary, withErrorBoundary, formatComponentError, createErrorLogger } from './runtime';
|
|
10
10
|
export { buildComponentProps, normalizeCallbacks, normalizeStyles, validateComponentProps, mergeProps, createPropsTransformer, wrapCallbacksWithLogging, extractPropPaths, PropBuilderOptions } from './runtime';
|
|
11
11
|
export { ComponentHierarchyRegistrar, registerComponentHierarchy, validateComponentSpec, flattenComponentHierarchy, countComponentsInHierarchy, HierarchyRegistrationResult, ComponentRegistrationError, HierarchyRegistrationOptions } from './runtime';
|
|
@@ -39,10 +39,11 @@ export declare const DEFAULT_CONFIGS: {
|
|
|
39
39
|
export declare function createReactRuntime(babelInstance: any, config?: {
|
|
40
40
|
compiler?: Partial<import('./types').CompilerConfig>;
|
|
41
41
|
registry?: Partial<import('./types').RegistryConfig>;
|
|
42
|
-
}, runtimeContext?: import('./types').RuntimeContext): {
|
|
42
|
+
}, runtimeContext?: import('./types').RuntimeContext, debug?: boolean): {
|
|
43
43
|
compiler: ComponentCompiler;
|
|
44
44
|
registry: ComponentRegistry;
|
|
45
45
|
resolver: ComponentResolver;
|
|
46
46
|
version: string;
|
|
47
|
+
debug: boolean;
|
|
47
48
|
};
|
|
48
49
|
//# sourceMappingURL=index.d.ts.map
|