@memberjunction/react-runtime 2.98.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 (71) hide show
  1. package/.turbo/turbo-build.log +15 -20
  2. package/CHANGELOG.md +26 -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 +59 -8
  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 +7 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +18 -1
  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/component-unwrapper.d.ts +7 -0
  45. package/dist/utilities/component-unwrapper.d.ts.map +1 -0
  46. package/dist/utilities/component-unwrapper.js +369 -0
  47. package/dist/utilities/component-unwrapper.js.map +1 -0
  48. package/dist/utilities/index.d.ts +1 -0
  49. package/dist/utilities/index.d.ts.map +1 -1
  50. package/dist/utilities/index.js +1 -0
  51. package/dist/utilities/index.js.map +1 -1
  52. package/dist/utilities/library-loader.d.ts +3 -0
  53. package/dist/utilities/library-loader.d.ts.map +1 -1
  54. package/dist/utilities/library-loader.js +101 -17
  55. package/dist/utilities/library-loader.js.map +1 -1
  56. package/examples/component-registry-integration.ts +191 -0
  57. package/package.json +6 -5
  58. package/src/compiler/component-compiler.ts +101 -23
  59. package/src/component-manager/component-manager.ts +736 -0
  60. package/src/component-manager/index.ts +13 -0
  61. package/src/component-manager/types.ts +204 -0
  62. package/src/index.ts +37 -1
  63. package/src/registry/component-registry-service.ts +315 -18
  64. package/src/registry/component-registry.ts +1 -1
  65. package/src/registry/component-resolver.ts +159 -67
  66. package/src/registry/index.ts +1 -1
  67. package/src/runtime/component-hierarchy.ts +124 -13
  68. package/src/types/index.ts +2 -0
  69. package/src/utilities/component-unwrapper.ts +481 -0
  70. package/src/utilities/index.ts +2 -1
  71. package/src/utilities/library-loader.ts +155 -22
@@ -16,6 +16,7 @@ import {
16
16
  import { ComponentStyles, ComponentObject } from '@memberjunction/interactive-component-types';
17
17
  import { LibraryRegistry } from '../utilities/library-registry';
18
18
  import { LibraryLoader } from '../utilities/library-loader';
19
+ import { unwrapLibraryComponent, unwrapLibraryComponents, unwrapAllLibraryComponents } from '../utilities/component-unwrapper';
19
20
  import { ComponentLibraryEntity } from '@memberjunction/core-entities';
20
21
 
21
22
  /**
@@ -98,7 +99,8 @@ export class ComponentCompiler {
98
99
  const componentFactory = this.createComponentFactory(
99
100
  transpiledCode,
100
101
  options.componentName,
101
- loadedLibraries
102
+ loadedLibraries,
103
+ options
102
104
  );
103
105
 
104
106
  // Build the compiled component
@@ -119,7 +121,8 @@ export class ComponentCompiler {
119
121
  success: true,
120
122
  component: compiledComponent,
121
123
  duration: Date.now() - startTime,
122
- size: transpiledCode.length
124
+ size: transpiledCode.length,
125
+ loadedLibraries: loadedLibraries
123
126
  };
124
127
 
125
128
  } catch (error) {
@@ -248,13 +251,19 @@ export class ComponentCompiler {
248
251
  function createComponent(
249
252
  React, ReactDOM,
250
253
  useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer, useLayoutEffect,
251
- libraries, styles, console, components
254
+ libraries, styles, console, components,
255
+ unwrapLibraryComponent, unwrapLibraryComponents, unwrapAllLibraryComponents
252
256
  ) {
253
257
  if (!React)
254
258
  console.log('[React-Runtime-JS] React is not defined');
255
259
  if (!ReactDOM)
256
260
  console.log('[React-Runtime-JS] ReactDOM is not defined');
257
261
 
262
+ // Make unwrap functions available with legacy names for backward compatibility
263
+ const unwrapComponent = unwrapLibraryComponent;
264
+ const unwrapComponents = unwrapLibraryComponents;
265
+ const unwrapAllComponents = unwrapAllLibraryComponents;
266
+
258
267
  // Code for ${componentName}
259
268
  ${componentCode}
260
269
 
@@ -490,6 +499,18 @@ export class ComponentCompiler {
490
499
  return false;
491
500
  }
492
501
 
502
+ // Filter out entries with 'unknown' name or missing globalVariable
503
+ if (lib.name === 'unknown' || lib.name === 'null' || lib.name === 'undefined') {
504
+ console.warn(`⚠️ Filtering out invalid library with name '${lib.name}':`, lib);
505
+ return false;
506
+ }
507
+
508
+ // Check for missing or invalid globalVariable
509
+ if (!lib.globalVariable || lib.globalVariable === 'undefined' || lib.globalVariable === 'null') {
510
+ console.warn(`⚠️ Filtering out library '${lib.name}' with invalid globalVariable:`, lib.globalVariable);
511
+ return false;
512
+ }
513
+
493
514
  const libNameLower = lib.name.toLowerCase();
494
515
  if (libNameLower === 'react' || libNameLower === 'reactdom') {
495
516
  console.warn(`⚠️ Library '${lib.name}' is automatically loaded by the React runtime and should not be requested separately`);
@@ -703,19 +724,22 @@ export class ComponentCompiler {
703
724
  * @param transpiledCode - Transpiled JavaScript code
704
725
  * @param componentName - Name of the component
705
726
  * @param loadedLibraries - Map of loaded libraries
727
+ * @param options - Compile options containing spec and other metadata
706
728
  * @returns Component factory function
707
729
  */
708
730
  private createComponentFactory(
709
731
  transpiledCode: string,
710
732
  componentName: string,
711
- loadedLibraries: Map<string, any>
733
+ loadedLibraries: Map<string, any>,
734
+ options: CompileOptions
712
735
  ): (context: RuntimeContext, styles?: ComponentStyles) => ComponentObject {
713
736
  try {
714
- // Create the factory function with all React hooks
737
+ // Create the factory function with all React hooks and utility functions
715
738
  const factoryCreator = new Function(
716
739
  'React', 'ReactDOM',
717
740
  'useState', 'useEffect', 'useCallback', 'useMemo', 'useRef', 'useContext', 'useReducer', 'useLayoutEffect',
718
741
  'libraries', 'styles', 'console', 'components',
742
+ 'unwrapLibraryComponent', 'unwrapLibraryComponents', 'unwrapAllLibraryComponents',
719
743
  `${transpiledCode}; return createComponent;`
720
744
  );
721
745
 
@@ -723,29 +747,80 @@ export class ComponentCompiler {
723
747
  return (context: RuntimeContext, styles: any = {}, components: Record<string, any> = {}) => {
724
748
  const { React, ReactDOM, libraries = {} } = context;
725
749
 
750
+ // Diagnostic: Check if React is null when creating component
751
+ if (!React) {
752
+ console.error('🔴 CRITICAL: React is NULL in createComponentFactory!');
753
+ console.error('Context provided:', context);
754
+ console.error('Context keys:', Object.keys(context));
755
+ throw new Error('React is null in runtime context when creating component factory');
756
+ }
757
+
758
+ // Additional diagnostic for React hooks
759
+ if (!React.useState || !React.useEffect) {
760
+ console.error('🔴 CRITICAL: React hooks are missing!');
761
+ console.error('React object keys:', React ? Object.keys(React) : 'React is null');
762
+ console.error('useState:', typeof React?.useState);
763
+ console.error('useEffect:', typeof React?.useEffect);
764
+ }
765
+
726
766
  // Merge loaded libraries with context libraries
767
+ // IMPORTANT: Only include libraries that are NOT dependency-only
768
+ // We need to filter based on the libraries array from options
727
769
  const mergedLibraries = { ...libraries };
770
+
771
+ // Only add libraries that are explicitly requested in the component
772
+ // This prevents dependency-only libraries from being accessible
773
+ const specLibraryNames = new Set(
774
+ (options.libraries || []).map((lib: any) => lib.globalVariable).filter(Boolean)
775
+ );
776
+
728
777
  loadedLibraries.forEach((value, key) => {
729
- mergedLibraries[key] = value;
778
+ // Only add if this library is in the spec (not just a dependency)
779
+ if (specLibraryNames.has(key)) {
780
+ mergedLibraries[key] = value;
781
+ } else if (this.config.debug) {
782
+ console.log(`⚠️ Filtering out dependency-only library: ${key}`);
783
+ }
730
784
  });
731
785
 
786
+ // Create bound versions of unwrap functions with debug flag
787
+ const boundUnwrapLibraryComponent = (lib: any, name: string) => unwrapLibraryComponent(lib, name, this.config.debug);
788
+ const boundUnwrapLibraryComponents = (lib: any, ...names: string[]) => unwrapLibraryComponents(lib, ...names, this.config.debug as any);
789
+ const boundUnwrapAllLibraryComponents = (lib: any) => unwrapAllLibraryComponents(lib, this.config.debug);
790
+
732
791
  // Execute the factory creator to get the createComponent function
733
- const createComponentFn = factoryCreator(
734
- React,
735
- ReactDOM,
736
- React.useState,
737
- React.useEffect,
738
- React.useCallback,
739
- React.useMemo,
740
- React.useRef,
741
- React.useContext,
742
- React.useReducer,
743
- React.useLayoutEffect,
744
- mergedLibraries,
745
- styles,
746
- console,
747
- components
748
- );
792
+ let createComponentFn;
793
+ try {
794
+ createComponentFn = factoryCreator(
795
+ React,
796
+ ReactDOM,
797
+ React.useState,
798
+ React.useEffect,
799
+ React.useCallback,
800
+ React.useMemo,
801
+ React.useRef,
802
+ React.useContext,
803
+ React.useReducer,
804
+ React.useLayoutEffect,
805
+ mergedLibraries,
806
+ styles,
807
+ console,
808
+ components,
809
+ boundUnwrapLibraryComponent,
810
+ boundUnwrapLibraryComponents,
811
+ boundUnwrapAllLibraryComponents
812
+ );
813
+ } catch (error: any) {
814
+ console.error('🔴 CRITICAL: Error calling factoryCreator with React hooks!');
815
+ console.error('Error:', error?.message || error);
816
+ console.error('React is:', React);
817
+ console.error('React type:', typeof React);
818
+ if (React) {
819
+ console.error('React.useState:', typeof React.useState);
820
+ console.error('React.useEffect:', typeof React.useEffect);
821
+ }
822
+ throw new Error(`Failed to create component factory: ${error?.message || error}`);
823
+ }
749
824
 
750
825
  // Call createComponent to get the actual component
751
826
  const Component = createComponentFn(
@@ -762,7 +837,10 @@ export class ComponentCompiler {
762
837
  mergedLibraries,
763
838
  styles,
764
839
  console,
765
- components
840
+ components,
841
+ boundUnwrapLibraryComponent,
842
+ boundUnwrapLibraryComponents,
843
+ boundUnwrapAllLibraryComponents
766
844
  );
767
845
 
768
846
  // Return the component directly