@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.
- package/.turbo/turbo-build.log +15 -20
- package/CHANGELOG.md +26 -0
- package/README.md +171 -1
- package/dist/compiler/component-compiler.d.ts.map +1 -1
- package/dist/compiler/component-compiler.js +59 -8
- package/dist/compiler/component-compiler.js.map +1 -1
- package/dist/component-manager/component-manager.d.ts +39 -0
- package/dist/component-manager/component-manager.d.ts.map +1 -0
- package/dist/component-manager/component-manager.js +474 -0
- package/dist/component-manager/component-manager.js.map +1 -0
- package/dist/component-manager/index.d.ts +3 -0
- package/dist/component-manager/index.d.ts.map +1 -0
- package/dist/component-manager/index.js +6 -0
- package/dist/component-manager/index.js.map +1 -0
- package/dist/component-manager/types.d.ts +62 -0
- package/dist/component-manager/types.d.ts.map +1 -0
- package/dist/component-manager/types.js +3 -0
- package/dist/component-manager/types.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/registry/component-registry-service.d.ts +16 -1
- package/dist/registry/component-registry-service.d.ts.map +1 -1
- package/dist/registry/component-registry-service.js +212 -10
- package/dist/registry/component-registry-service.js.map +1 -1
- package/dist/registry/component-registry.d.ts +1 -1
- package/dist/registry/component-registry.d.ts.map +1 -1
- package/dist/registry/component-registry.js.map +1 -1
- package/dist/registry/component-resolver.d.ts.map +1 -1
- package/dist/registry/component-resolver.js +122 -52
- package/dist/registry/component-resolver.js.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/runtime/component-hierarchy.d.ts +4 -0
- package/dist/runtime/component-hierarchy.d.ts.map +1 -1
- package/dist/runtime/component-hierarchy.js +127 -12
- package/dist/runtime/component-hierarchy.js.map +1 -1
- package/dist/runtime.umd.js +535 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/component-unwrapper.d.ts +7 -0
- package/dist/utilities/component-unwrapper.d.ts.map +1 -0
- package/dist/utilities/component-unwrapper.js +369 -0
- package/dist/utilities/component-unwrapper.js.map +1 -0
- 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-loader.d.ts +3 -0
- package/dist/utilities/library-loader.d.ts.map +1 -1
- package/dist/utilities/library-loader.js +101 -17
- package/dist/utilities/library-loader.js.map +1 -1
- package/examples/component-registry-integration.ts +191 -0
- package/package.json +6 -5
- package/src/compiler/component-compiler.ts +101 -23
- package/src/component-manager/component-manager.ts +736 -0
- package/src/component-manager/index.ts +13 -0
- package/src/component-manager/types.ts +204 -0
- package/src/index.ts +37 -1
- package/src/registry/component-registry-service.ts +315 -18
- package/src/registry/component-registry.ts +1 -1
- package/src/registry/component-resolver.ts +159 -67
- package/src/registry/index.ts +1 -1
- package/src/runtime/component-hierarchy.ts +124 -13
- package/src/types/index.ts +2 -0
- package/src/utilities/component-unwrapper.ts +481 -0
- package/src/utilities/index.ts +2 -1
- 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
|
-
|
|
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
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
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
|