@memberjunction/react-runtime 2.99.0 → 2.100.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.
Files changed (61) hide show
  1. package/.turbo/turbo-build.log +15 -20
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +171 -1
  4. package/dist/compiler/component-compiler.d.ts.map +1 -1
  5. package/dist/compiler/component-compiler.js +10 -1
  6. package/dist/compiler/component-compiler.js.map +1 -1
  7. package/dist/component-manager/component-manager.d.ts +39 -0
  8. package/dist/component-manager/component-manager.d.ts.map +1 -0
  9. package/dist/component-manager/component-manager.js +474 -0
  10. package/dist/component-manager/component-manager.js.map +1 -0
  11. package/dist/component-manager/index.d.ts +3 -0
  12. package/dist/component-manager/index.d.ts.map +1 -0
  13. package/dist/component-manager/index.js +6 -0
  14. package/dist/component-manager/index.js.map +1 -0
  15. package/dist/component-manager/types.d.ts +62 -0
  16. package/dist/component-manager/types.d.ts.map +1 -0
  17. package/dist/component-manager/types.js +3 -0
  18. package/dist/component-manager/types.js.map +1 -0
  19. package/dist/index.d.ts +6 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +11 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/registry/component-registry-service.d.ts +16 -1
  24. package/dist/registry/component-registry-service.d.ts.map +1 -1
  25. package/dist/registry/component-registry-service.js +212 -10
  26. package/dist/registry/component-registry-service.js.map +1 -1
  27. package/dist/registry/component-registry.d.ts +1 -1
  28. package/dist/registry/component-registry.d.ts.map +1 -1
  29. package/dist/registry/component-registry.js.map +1 -1
  30. package/dist/registry/component-resolver.d.ts.map +1 -1
  31. package/dist/registry/component-resolver.js +122 -52
  32. package/dist/registry/component-resolver.js.map +1 -1
  33. package/dist/registry/index.d.ts +1 -1
  34. package/dist/registry/index.d.ts.map +1 -1
  35. package/dist/registry/index.js.map +1 -1
  36. package/dist/runtime/component-hierarchy.d.ts +4 -0
  37. package/dist/runtime/component-hierarchy.d.ts.map +1 -1
  38. package/dist/runtime/component-hierarchy.js +127 -12
  39. package/dist/runtime/component-hierarchy.js.map +1 -1
  40. package/dist/runtime.umd.js +535 -1
  41. package/dist/types/index.d.ts +1 -0
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/utilities/library-loader.d.ts +3 -0
  45. package/dist/utilities/library-loader.d.ts.map +1 -1
  46. package/dist/utilities/library-loader.js +85 -17
  47. package/dist/utilities/library-loader.js.map +1 -1
  48. package/examples/component-registry-integration.ts +191 -0
  49. package/package.json +6 -5
  50. package/src/compiler/component-compiler.ts +14 -1
  51. package/src/component-manager/component-manager.ts +736 -0
  52. package/src/component-manager/index.ts +13 -0
  53. package/src/component-manager/types.ts +204 -0
  54. package/src/index.ts +27 -1
  55. package/src/registry/component-registry-service.ts +315 -18
  56. package/src/registry/component-registry.ts +1 -1
  57. package/src/registry/component-resolver.ts +159 -67
  58. package/src/registry/index.ts +1 -1
  59. package/src/runtime/component-hierarchy.ts +124 -13
  60. package/src/types/index.ts +2 -0
  61. package/src/utilities/library-loader.ts +133 -22
@@ -59,6 +59,11 @@ export class LibraryLoader {
59
59
  private static loadedResources = new Map<string, LoadedResource>();
60
60
  private static loadedLibraryStates = new Map<string, LoadedLibraryState>();
61
61
  private static dependencyResolver = new LibraryDependencyResolver({ debug: false });
62
+
63
+ /**
64
+ * Enable progressive delay for library initialization (useful for test harness)
65
+ */
66
+ public static enableProgressiveDelay: boolean = false;
62
67
 
63
68
  /**
64
69
  * Load all standard libraries (core + UI + CSS)
@@ -255,32 +260,44 @@ export class LibraryLoader {
255
260
  script.removeEventListener('error', onError);
256
261
  };
257
262
 
258
- const onLoad = () => {
263
+ const onLoad = async () => {
259
264
  cleanup();
260
- const global = (window as any)[globalName];
261
- if (global) {
262
- if (debug) {
263
- console.log(`✅ Library '${globalName}' loaded successfully from ${url}`);
265
+
266
+ // Use progressive delay if enabled, otherwise use original behavior
267
+ if (LibraryLoader.enableProgressiveDelay) {
268
+ try {
269
+ const global = await LibraryLoader.waitForGlobalVariable(globalName, url, debug);
270
+ resolve(global);
271
+ } catch (error) {
272
+ reject(error);
264
273
  }
265
- resolve(global);
266
274
  } else {
267
- // Some libraries may take a moment to initialize
268
- const timeoutId = resourceManager.setTimeout(
269
- LIBRARY_LOADER_COMPONENT_ID,
270
- () => {
271
- const delayedGlobal = (window as any)[globalName];
272
- if (delayedGlobal) {
273
- if (debug) {
274
- console.log(`✅ Library '${globalName}' loaded successfully (delayed initialization)`);
275
+ // Original behavior
276
+ const global = (window as any)[globalName];
277
+ if (global) {
278
+ if (debug) {
279
+ console.log(`✅ Library '${globalName}' loaded successfully from ${url}`);
280
+ }
281
+ resolve(global);
282
+ } else {
283
+ // Some libraries may take a moment to initialize
284
+ const timeoutId = resourceManager.setTimeout(
285
+ LIBRARY_LOADER_COMPONENT_ID,
286
+ () => {
287
+ const delayedGlobal = (window as any)[globalName];
288
+ if (delayedGlobal) {
289
+ if (debug) {
290
+ console.log(`✅ Library '${globalName}' loaded successfully (delayed initialization)`);
291
+ }
292
+ resolve(delayedGlobal);
293
+ } else {
294
+ reject(new Error(`${globalName} not found after script load`));
275
295
  }
276
- resolve(delayedGlobal);
277
- } else {
278
- reject(new Error(`${globalName} not found after script load`));
279
- }
280
- },
281
- 100,
282
- { url, globalName }
283
- );
296
+ },
297
+ 100,
298
+ { url, globalName }
299
+ );
300
+ }
284
301
  }
285
302
  };
286
303
 
@@ -309,6 +326,100 @@ export class LibraryLoader {
309
326
  return promise;
310
327
  }
311
328
 
329
+ /**
330
+ * Check if a library global variable is properly initialized
331
+ * Generic check that works for any library
332
+ */
333
+ private static isLibraryReady(globalVariable: any): boolean {
334
+ if (!globalVariable) {
335
+ return false;
336
+ }
337
+
338
+ // For functions, they're ready immediately
339
+ if (typeof globalVariable === 'function') {
340
+ return true;
341
+ }
342
+
343
+ // For objects, check if they have properties (not an empty object)
344
+ if (typeof globalVariable === 'object') {
345
+ // Check for non-empty object with enumerable properties
346
+ const keys = Object.keys(globalVariable);
347
+ // Some libraries might have only non-enumerable properties,
348
+ // so also check for common indicators of initialization
349
+ return keys.length > 0 ||
350
+ Object.getOwnPropertyNames(globalVariable).length > 1 || // > 1 to exclude just constructor
351
+ globalVariable.constructor !== Object; // Has a custom constructor
352
+ }
353
+
354
+ // For other types (string, number, etc.), consider them ready
355
+ return true;
356
+ }
357
+
358
+ /**
359
+ * Wait for a global variable to be available with progressive delays
360
+ * @param globalName The name of the global variable to wait for
361
+ * @param url The URL of the script (for debugging)
362
+ * @param debug Whether to log debug information
363
+ * @returns The global variable once it's available
364
+ */
365
+ private static async waitForGlobalVariable(
366
+ globalName: string,
367
+ url: string,
368
+ debug: boolean = false
369
+ ): Promise<any> {
370
+ const delays = [0, 100, 200, 300, 400]; // Total: 1000ms max delay
371
+ const maxAttempts = delays.length;
372
+ let totalDelay = 0;
373
+
374
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
375
+ // Wait for the specified delay (0ms on first attempt)
376
+ if (attempt > 0) {
377
+ const delay = delays[attempt];
378
+ if (debug) {
379
+ console.log(`⏳ Waiting ${delay}ms for ${globalName} to initialize (attempt ${attempt + 1}/${maxAttempts})...`);
380
+ }
381
+ await new Promise(resolve => {
382
+ resourceManager.setTimeout(
383
+ LIBRARY_LOADER_COMPONENT_ID,
384
+ () => resolve(undefined),
385
+ delay,
386
+ { globalName, attempt }
387
+ );
388
+ });
389
+ totalDelay += delay;
390
+ }
391
+
392
+ // Check if the global variable exists
393
+ const global = (window as any)[globalName];
394
+ if (global) {
395
+ // Use generic library readiness check
396
+ const isReady = this.isLibraryReady(global);
397
+
398
+ if (isReady) {
399
+ if (debug) {
400
+ if (totalDelay > 0) {
401
+ console.log(`✅ ${globalName} ready after ${totalDelay}ms delay`);
402
+ } else {
403
+ console.log(`✅ Library '${globalName}' loaded successfully from ${url}`);
404
+ }
405
+ }
406
+ return global;
407
+ } else if (debug && attempt < maxAttempts - 1) {
408
+ console.log(`🔄 ${globalName} exists but not fully initialized, will retry...`);
409
+ }
410
+ }
411
+ }
412
+
413
+ // Final check after all attempts
414
+ const finalGlobal = (window as any)[globalName];
415
+ if (finalGlobal) {
416
+ console.warn(`⚠️ ${globalName} loaded but may not be fully initialized after ${totalDelay}ms`);
417
+ return finalGlobal;
418
+ }
419
+
420
+ throw new Error(`${globalName} not found after script load and ${totalDelay}ms delay`);
421
+ }
422
+
312
423
  /**
313
424
  * Load CSS from URL
314
425
  */