@memberjunction/ng-react 2.95.0 → 2.97.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/dist/lib/components/mj-react-component.component.d.ts +7 -1
- package/dist/lib/components/mj-react-component.component.js +33 -10
- package/dist/lib/components/mj-react-component.component.js.map +1 -1
- package/dist/lib/config/react-debug.config.d.ts +42 -0
- package/dist/lib/config/react-debug.config.js +60 -0
- package/dist/lib/config/react-debug.config.js.map +1 -0
- package/dist/lib/services/angular-adapter.service.d.ts +6 -1
- package/dist/lib/services/angular-adapter.service.js +26 -8
- package/dist/lib/services/angular-adapter.service.js.map +1 -1
- package/dist/lib/services/react-bridge.service.d.ts +1 -0
- package/dist/lib/services/react-bridge.service.js +20 -5
- package/dist/lib/services/react-bridge.service.js.map +1 -1
- package/dist/lib/services/script-loader.service.d.ts +4 -1
- package/dist/lib/services/script-loader.service.js +3 -2
- package/dist/lib/services/script-loader.service.js.map +1 -1
- package/dist/lib/utilities/runtime-utilities.d.ts +2 -1
- package/dist/lib/utilities/runtime-utilities.js +46 -1
- package/dist/lib/utilities/runtime-utilities.js.map +1 -1
- package/dist/public-api.d.ts +1 -1
- package/dist/public-api.js +2 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +4 -4
- package/dist/lib/default-styles.d.ts +0 -10
- package/dist/lib/default-styles.js +0 -106
- package/dist/lib/default-styles.js.map +0 -1
|
@@ -7,6 +7,7 @@ import { Injectable } from '@angular/core';
|
|
|
7
7
|
import { BehaviorSubject, firstValueFrom } from 'rxjs';
|
|
8
8
|
import { filter } from 'rxjs/operators';
|
|
9
9
|
import { AngularAdapterService } from './angular-adapter.service';
|
|
10
|
+
import { ReactDebugConfig } from '../config/react-debug.config';
|
|
10
11
|
import * as i0 from "@angular/core";
|
|
11
12
|
import * as i1 from "./angular-adapter.service";
|
|
12
13
|
/**
|
|
@@ -24,6 +25,8 @@ export class ReactBridgeService {
|
|
|
24
25
|
this.firstComponentAttempted = false;
|
|
25
26
|
this.maxWaitTime = 5000; // Maximum 5 seconds wait time
|
|
26
27
|
this.checkInterval = 200; // Check every 200ms
|
|
28
|
+
// Debug flag from project configuration
|
|
29
|
+
this.debug = ReactDebugConfig.getDebugMode();
|
|
27
30
|
// Bootstrap React immediately on service initialization
|
|
28
31
|
this.bootstrapReact();
|
|
29
32
|
}
|
|
@@ -35,8 +38,16 @@ export class ReactBridgeService {
|
|
|
35
38
|
*/
|
|
36
39
|
async bootstrapReact() {
|
|
37
40
|
try {
|
|
38
|
-
|
|
39
|
-
console.log(
|
|
41
|
+
// Log the debug mode being used
|
|
42
|
+
console.log(`ReactBridgeService: Initializing React with debug mode = ${this.debug} (from ReactDebugConfig)`);
|
|
43
|
+
// Pass debug flag to get development builds when debug is enabled
|
|
44
|
+
await this.adapter.initialize(undefined, undefined, { debug: this.debug });
|
|
45
|
+
if (this.debug) {
|
|
46
|
+
console.log('React ecosystem pre-loaded successfully with DEVELOPMENT builds (detailed error messages)');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.log('React ecosystem pre-loaded successfully with PRODUCTION builds (minified)');
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
catch (error) {
|
|
42
53
|
console.error('Failed to pre-load React ecosystem:', error);
|
|
@@ -55,7 +66,9 @@ export class ReactBridgeService {
|
|
|
55
66
|
this.firstComponentAttempted = true;
|
|
56
67
|
if (isFirstComponent) {
|
|
57
68
|
// First component - check periodically until React is ready
|
|
58
|
-
|
|
69
|
+
if (this.debug) {
|
|
70
|
+
console.log('First React component loading - checking for React initialization');
|
|
71
|
+
}
|
|
59
72
|
const startTime = Date.now();
|
|
60
73
|
while (Date.now() - startTime < this.maxWaitTime) {
|
|
61
74
|
try {
|
|
@@ -68,7 +81,9 @@ export class ReactBridgeService {
|
|
|
68
81
|
testRoot.unmount();
|
|
69
82
|
// React is ready!
|
|
70
83
|
this.reactReadySubject.next(true);
|
|
71
|
-
|
|
84
|
+
if (this.debug) {
|
|
85
|
+
console.log(`React is fully ready after ${Date.now() - startTime}ms`);
|
|
86
|
+
}
|
|
72
87
|
return;
|
|
73
88
|
}
|
|
74
89
|
}
|
|
@@ -94,7 +109,7 @@ export class ReactBridgeService {
|
|
|
94
109
|
* @returns React context with React, ReactDOM, Babel, and libraries
|
|
95
110
|
*/
|
|
96
111
|
async getReactContext() {
|
|
97
|
-
await this.adapter.initialize();
|
|
112
|
+
await this.adapter.initialize(undefined, undefined, { debug: this.debug });
|
|
98
113
|
return this.adapter.getRuntimeContext();
|
|
99
114
|
}
|
|
100
115
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-bridge.service.js","sourceRoot":"","sources":["../../../src/lib/services/react-bridge.service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;;;AAGlE;;;GAGG;AAEH,MAAM,OAAO,kBAAkB;IAY7B,YAAoB,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAX1C,eAAU,GAAG,IAAI,GAAG,EAAO,CAAC;QAEpC,8BAA8B;QACtB,sBAAiB,GAAG,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;QACzD,gBAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,CAAC;QAE3D,2DAA2D;QACnD,4BAAuB,GAAG,KAAK,CAAC;QAChC,gBAAW,GAAG,IAAI,CAAC,CAAC,8BAA8B;QAClD,kBAAa,GAAG,GAAG,CAAC,CAAC,oBAAoB;QAG/C,wDAAwD;QACxD,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,CAAC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AC,OAAO,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;mFAvLU,kBAAkB;uEAAlB,kBAAkB,WAAlB,kBAAkB,mBADL,MAAM;;iFACnB,kBAAkB;cAD9B,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["/**\n * @fileoverview Service to manage React and ReactDOM instances with proper lifecycle.\n * Bridges Angular components with React rendering capabilities.\n * @module @memberjunction/ng-react\n */\n\nimport { Injectable, OnDestroy } from '@angular/core';\nimport { BehaviorSubject, firstValueFrom } from 'rxjs';\nimport { filter } from 'rxjs/operators';\nimport { AngularAdapterService } from './angular-adapter.service';\nimport { RuntimeContext } from '@memberjunction/react-runtime';\n\n/**\n * Service to manage React and ReactDOM instances with proper lifecycle.\n * Provides methods for creating and managing React roots in Angular applications.\n */\n@Injectable({ providedIn: 'root' })\nexport class ReactBridgeService implements OnDestroy {\n private reactRoots = new Set<any>();\n \n // Track React readiness state\n private reactReadySubject = new BehaviorSubject<boolean>(false);\n public reactReady$ = this.reactReadySubject.asObservable();\n \n // Track if this is the first component trying to use React\n private firstComponentAttempted = false;\n private maxWaitTime = 5000; // Maximum 5 seconds wait time\n private checkInterval = 200; // Check every 200ms\n\n constructor(private adapter: AngularAdapterService) {\n // Bootstrap React immediately on service initialization\n this.bootstrapReact();\n }\n\n ngOnDestroy(): void {\n this.cleanup();\n }\n\n /**\n * Bootstrap React early during service initialization\n */\n private async bootstrapReact(): Promise<void> {\n try {\n await this.adapter.initialize();\n console.log('React ecosystem pre-loaded successfully');\n } catch (error) {\n console.error('Failed to pre-load React ecosystem:', error);\n }\n }\n\n /**\n * Wait for React to be ready, with special handling for first component\n */\n async waitForReactReady(): Promise<void> {\n // If already ready, return immediately\n if (this.reactReadySubject.value) {\n return;\n }\n\n // Check if this is the first component attempting to use React\n const isFirstComponent = !this.firstComponentAttempted;\n this.firstComponentAttempted = true;\n\n if (isFirstComponent) {\n // First component - check periodically until React is ready\n console.log('First React component loading - checking for React initialization');\n \n const startTime = Date.now();\n \n while (Date.now() - startTime < this.maxWaitTime) {\n try {\n const testDiv = document.createElement('div');\n const context = this.adapter.getRuntimeContext();\n \n if (context.ReactDOM?.createRoot) {\n // Try to create a test root\n const testRoot = context.ReactDOM.createRoot(testDiv);\n if (testRoot) {\n testRoot.unmount();\n // React is ready!\n this.reactReadySubject.next(true);\n console.log(`React is fully ready after ${Date.now() - startTime}ms`);\n return;\n }\n }\n } catch (error) {\n // Not ready yet, continue checking\n }\n \n // Wait before next check\n await new Promise(resolve => setTimeout(resolve, this.checkInterval));\n }\n \n // If we've exhausted the wait time, throw error\n console.error('React readiness test failed after maximum wait time');\n this.firstComponentAttempted = false;\n throw new Error(`ReactDOM.createRoot not available after ${this.maxWaitTime}ms`);\n } else {\n // Subsequent components wait for the ready signal\n await firstValueFrom(this.reactReady$.pipe(filter(ready => ready)));\n }\n }\n\n /**\n * Get the current React context if loaded\n * @returns React context with React, ReactDOM, Babel, and libraries\n */\n async getReactContext(): Promise<RuntimeContext> {\n await this.adapter.initialize();\n return this.adapter.getRuntimeContext();\n }\n\n /**\n * Get the current React context synchronously\n * @returns React context or null if not loaded\n */\n getCurrentContext(): RuntimeContext | null {\n if (!this.adapter.isInitialized()) {\n return null;\n }\n return this.adapter.getRuntimeContext();\n }\n\n /**\n * Create a React root for rendering\n * @param container - DOM element to render into\n * @returns React root instance\n */\n createRoot(container: HTMLElement): any {\n const context = this.getCurrentContext();\n if (!context?.ReactDOM?.createRoot) {\n throw new Error('ReactDOM.createRoot not available');\n }\n\n const root = context.ReactDOM.createRoot(container);\n this.reactRoots.add(root);\n return root;\n }\n\n /**\n * Unmount and clean up a React root\n * @param root - React root to unmount\n */\n unmountRoot(root: any): void {\n if (root && typeof root.unmount === 'function') {\n try {\n root.unmount();\n } catch (error) {\n console.warn('Failed to unmount React root:', error);\n }\n }\n this.reactRoots.delete(root);\n }\n\n /**\n * Transpile JSX code to JavaScript\n * @param code - JSX code to transpile\n * @param filename - Optional filename for error messages\n * @returns Transpiled JavaScript code\n */\n transpileJSX(code: string, filename: string): string {\n return this.adapter.transpileJSX(code, filename);\n }\n\n /**\n * Clean up all React roots and reset context\n */\n private cleanup(): void {\n // Unmount all tracked React roots\n for (const root of this.reactRoots) {\n try {\n root.unmount();\n } catch (error) {\n console.warn('Failed to unmount React root:', error);\n }\n }\n this.reactRoots.clear();\n \n // Reset readiness state\n this.reactReadySubject.next(false);\n this.firstComponentAttempted = false;\n\n // Clean up adapter\n this.adapter.destroy();\n }\n\n /**\n * Check if React is currently ready\n * @returns true if React is ready\n */\n isReady(): boolean {\n return this.reactReadySubject.value;\n }\n\n /**\n * Get the number of active React roots\n * @returns Number of active roots\n */\n getActiveRootsCount(): number {\n return this.reactRoots.size;\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"react-bridge.service.js","sourceRoot":"","sources":["../../../src/lib/services/react-bridge.service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;;;AAEhE;;;GAGG;AAEH,MAAM,OAAO,kBAAkB;IAe7B,YAAoB,OAA8B;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAd1C,eAAU,GAAG,IAAI,GAAG,EAAO,CAAC;QAEpC,8BAA8B;QACtB,sBAAiB,GAAG,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;QACzD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Service to manage React and ReactDOM instances with proper lifecycle.\n * Bridges Angular components with React rendering capabilities.\n * @module @memberjunction/ng-react\n */\n\nimport { Injectable, OnDestroy } from '@angular/core';\nimport { BehaviorSubject, firstValueFrom } from 'rxjs';\nimport { filter } from 'rxjs/operators';\nimport { AngularAdapterService } from './angular-adapter.service';\nimport { RuntimeContext } from '@memberjunction/react-runtime';\nimport { ReactDebugConfig } from '../config/react-debug.config';\n\n/**\n * Service to manage React and ReactDOM instances with proper lifecycle.\n * Provides methods for creating and managing React roots in Angular applications.\n */\n@Injectable({ providedIn: 'root' })\nexport class ReactBridgeService implements OnDestroy {\n private reactRoots = new Set<any>();\n \n // Track React readiness state\n private reactReadySubject = new BehaviorSubject<boolean>(false);\n public reactReady$ = this.reactReadySubject.asObservable();\n \n // Track if this is the first component trying to use React\n private firstComponentAttempted = false;\n private maxWaitTime = 5000; // Maximum 5 seconds wait time\n private checkInterval = 200; // Check every 200ms\n \n // Debug flag from project configuration\n public debug: boolean = ReactDebugConfig.getDebugMode();\n\n constructor(private adapter: AngularAdapterService) {\n // Bootstrap React immediately on service initialization\n this.bootstrapReact();\n }\n\n ngOnDestroy(): void {\n this.cleanup();\n }\n\n /**\n * Bootstrap React early during service initialization\n */\n private async bootstrapReact(): Promise<void> {\n try {\n // Log the debug mode being used\n console.log(`ReactBridgeService: Initializing React with debug mode = ${this.debug} (from ReactDebugConfig)`);\n \n // Pass debug flag to get development builds when debug is enabled\n await this.adapter.initialize(undefined, undefined, { debug: this.debug });\n \n if (this.debug) {\n console.log('React ecosystem pre-loaded successfully with DEVELOPMENT builds (detailed error messages)');\n } else {\n console.log('React ecosystem pre-loaded successfully with PRODUCTION builds (minified)');\n }\n } catch (error) {\n console.error('Failed to pre-load React ecosystem:', error);\n }\n }\n\n /**\n * Wait for React to be ready, with special handling for first component\n */\n async waitForReactReady(): Promise<void> {\n // If already ready, return immediately\n if (this.reactReadySubject.value) {\n return;\n }\n\n // Check if this is the first component attempting to use React\n const isFirstComponent = !this.firstComponentAttempted;\n this.firstComponentAttempted = true;\n\n if (isFirstComponent) {\n // First component - check periodically until React is ready\n if (this.debug) {\n console.log('First React component loading - checking for React initialization');\n }\n \n const startTime = Date.now();\n \n while (Date.now() - startTime < this.maxWaitTime) {\n try {\n const testDiv = document.createElement('div');\n const context = this.adapter.getRuntimeContext();\n \n if (context.ReactDOM?.createRoot) {\n // Try to create a test root\n const testRoot = context.ReactDOM.createRoot(testDiv);\n if (testRoot) {\n testRoot.unmount();\n // React is ready!\n this.reactReadySubject.next(true);\n if (this.debug) {\n console.log(`React is fully ready after ${Date.now() - startTime}ms`);\n }\n return;\n }\n }\n } catch (error) {\n // Not ready yet, continue checking\n }\n \n // Wait before next check\n await new Promise(resolve => setTimeout(resolve, this.checkInterval));\n }\n \n // If we've exhausted the wait time, throw error\n console.error('React readiness test failed after maximum wait time');\n this.firstComponentAttempted = false;\n throw new Error(`ReactDOM.createRoot not available after ${this.maxWaitTime}ms`);\n } else {\n // Subsequent components wait for the ready signal\n await firstValueFrom(this.reactReady$.pipe(filter(ready => ready)));\n }\n }\n\n /**\n * Get the current React context if loaded\n * @returns React context with React, ReactDOM, Babel, and libraries\n */\n async getReactContext(): Promise<RuntimeContext> {\n await this.adapter.initialize(undefined, undefined, {debug: this.debug});\n return this.adapter.getRuntimeContext();\n }\n\n /**\n * Get the current React context synchronously\n * @returns React context or null if not loaded\n */\n getCurrentContext(): RuntimeContext | null {\n if (!this.adapter.isInitialized()) {\n return null;\n }\n return this.adapter.getRuntimeContext();\n }\n\n /**\n * Create a React root for rendering\n * @param container - DOM element to render into\n * @returns React root instance\n */\n createRoot(container: HTMLElement): any {\n const context = this.getCurrentContext();\n if (!context?.ReactDOM?.createRoot) {\n throw new Error('ReactDOM.createRoot not available');\n }\n\n const root = context.ReactDOM.createRoot(container);\n this.reactRoots.add(root);\n return root;\n }\n\n /**\n * Unmount and clean up a React root\n * @param root - React root to unmount\n */\n unmountRoot(root: any): void {\n if (root && typeof root.unmount === 'function') {\n try {\n root.unmount();\n } catch (error) {\n console.warn('Failed to unmount React root:', error);\n }\n }\n this.reactRoots.delete(root);\n }\n\n /**\n * Transpile JSX code to JavaScript\n * @param code - JSX code to transpile\n * @param filename - Optional filename for error messages\n * @returns Transpiled JavaScript code\n */\n transpileJSX(code: string, filename: string): string {\n return this.adapter.transpileJSX(code, filename);\n }\n\n /**\n * Clean up all React roots and reset context\n */\n private cleanup(): void {\n // Unmount all tracked React roots\n for (const root of this.reactRoots) {\n try {\n root.unmount();\n } catch (error) {\n console.warn('Failed to unmount React root:', error);\n }\n }\n this.reactRoots.clear();\n \n // Reset readiness state\n this.reactReadySubject.next(false);\n this.firstComponentAttempted = false;\n\n // Clean up adapter\n this.adapter.destroy();\n }\n\n /**\n * Check if React is currently ready\n * @returns true if React is ready\n */\n isReady(): boolean {\n return this.reactReadySubject.value;\n }\n\n /**\n * Get the number of active React roots\n * @returns Number of active roots\n */\n getActiveRootsCount(): number {\n return this.reactRoots.size;\n }\n}"]}
|
|
@@ -40,9 +40,12 @@ export declare class ScriptLoaderService implements OnDestroy {
|
|
|
40
40
|
* Load common React libraries and UI frameworks
|
|
41
41
|
* @param config Optional library configuration
|
|
42
42
|
* @param additionalLibraries Optional additional libraries to merge
|
|
43
|
+
* @param options Optional options including debug flag
|
|
43
44
|
* @returns Promise resolving to React ecosystem objects
|
|
44
45
|
*/
|
|
45
|
-
loadReactEcosystem(config?: LibraryConfiguration, additionalLibraries?: ExternalLibraryConfig[]
|
|
46
|
+
loadReactEcosystem(config?: LibraryConfiguration, additionalLibraries?: ExternalLibraryConfig[], options?: {
|
|
47
|
+
debug?: boolean;
|
|
48
|
+
}): Promise<{
|
|
46
49
|
React: any;
|
|
47
50
|
ReactDOM: any;
|
|
48
51
|
Babel: any;
|
|
@@ -93,11 +93,12 @@ export class ScriptLoaderService {
|
|
|
93
93
|
* Load common React libraries and UI frameworks
|
|
94
94
|
* @param config Optional library configuration
|
|
95
95
|
* @param additionalLibraries Optional additional libraries to merge
|
|
96
|
+
* @param options Optional options including debug flag
|
|
96
97
|
* @returns Promise resolving to React ecosystem objects
|
|
97
98
|
*/
|
|
98
|
-
async loadReactEcosystem(config, additionalLibraries) {
|
|
99
|
+
async loadReactEcosystem(config, additionalLibraries, options) {
|
|
99
100
|
// Use the new LibraryLoader from react-runtime for consistency
|
|
100
|
-
const result = await LibraryLoader.loadAllLibraries(config, additionalLibraries);
|
|
101
|
+
const result = await LibraryLoader.loadAllLibraries(config, additionalLibraries, options);
|
|
101
102
|
// The LibraryLoader handles all the loading, but we need to ensure
|
|
102
103
|
// ReactDOM.createRoot is available for Angular's specific needs
|
|
103
104
|
// The ReactBridgeService will handle the delayed validation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script-loader.service.js","sourceRoot":"","sources":["../../../src/lib/services/script-loader.service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,aAAa,EAGd,MAAM,+BAA+B,CAAC;;AAUvC;;;GAGG;AAEH,MAAM,OAAO,mBAAmB;IADhC;QAEU,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAC;QACzC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;KAkYvD;IAhYC,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAkB,EAAE,WAAW,GAAG,KAAK;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,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AAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,+BAA+B,CACrC,MAAyB,EACzB,UAAkB,EAClB,SAAgC,EAChC,OAA6B,EAC7B,MAA6B;QAE7B,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACjE,CAAC,CAAC;QAEF,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;YAC3B,aAAa;YACZ,MAAc,CAAC,kBAAkB,GAAG,GAAG,EAAE;gBACxC,IAAK,MAAc,CAAC,UAAU,KAAK,QAAQ,IAAK,MAAc,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;oBACxF,MAAc,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAC1C,WAAW,EAAE,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,MAAM,WAAW,GAAG,GAAG,EAAE;gBACvB,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAChD,WAAW,EAAE,CAAC;YAChB,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;oFAnYU,mBAAmB;uEAAnB,mBAAmB,WAAnB,mBAAmB,mBADN,MAAM;;iFACnB,mBAAmB;cAD/B,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["/**\n * @fileoverview Service for loading external scripts and CSS in Angular applications.\n * Manages the lifecycle of dynamically loaded resources with proper cleanup.\n * @module @memberjunction/ng-react\n */\n\nimport { Injectable, OnDestroy } from '@angular/core';\nimport { \n LibraryLoader,\n LibraryConfiguration,\n ExternalLibraryConfig\n} from '@memberjunction/react-runtime';\n\n/**\n * Represents a loaded script or CSS resource\n */\ninterface LoadedScript {\n element: HTMLScriptElement | HTMLLinkElement;\n promise: Promise<any>;\n}\n\n/**\n * Service for loading external scripts and CSS with proper cleanup.\n * Provides methods to dynamically load React and related libraries from CDN.\n */\n@Injectable({ providedIn: 'root' })\nexport class ScriptLoaderService implements OnDestroy {\n private loadedResources = new Map<string, LoadedScript>();\n private readonly cleanupOnDestroy = new Set<string>();\n\n ngOnDestroy(): void {\n this.cleanup();\n }\n\n /**\n * Load a script from URL with automatic cleanup tracking\n * @param url - Script URL to load\n * @param globalName - Expected global variable name\n * @param autoCleanup - Whether to cleanup on service destroy\n * @returns Promise resolving to the global object\n */\n async loadScript(url: string, globalName: string, autoCleanup = false): Promise<any> {\n const existing = this.loadedResources.get(url);\n if (existing) {\n return existing.promise;\n }\n\n const promise = this.createScriptPromise(url, globalName);\n const element = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement;\n \n if (element) {\n this.loadedResources.set(url, { element, promise });\n if (autoCleanup) {\n this.cleanupOnDestroy.add(url);\n }\n }\n\n return promise;\n }\n\n /**\n * Load a script with additional validation function\n * @param url - Script URL to load\n * @param globalName - Expected global variable name\n * @param validator - Function to validate the loaded object\n * @param autoCleanup - Whether to cleanup on service destroy\n * @returns Promise resolving to the validated global object\n */\n async loadScriptWithValidation(\n url: string, \n globalName: string, \n validator: (obj: any) => boolean,\n autoCleanup = false\n ): Promise<any> {\n const existing = this.loadedResources.get(url);\n if (existing) {\n const obj = await existing.promise;\n // Re-validate even for cached resources\n if (!validator(obj)) {\n throw new Error(`${globalName} loaded but failed validation`);\n }\n return obj;\n }\n\n const promise = this.createScriptPromiseWithValidation(url, globalName, validator);\n const element = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement;\n \n if (element) {\n this.loadedResources.set(url, { element, promise });\n if (autoCleanup) {\n this.cleanupOnDestroy.add(url);\n }\n }\n\n return promise;\n }\n\n /**\n * Load CSS from URL\n * @param url - CSS URL to load\n */\n loadCSS(url: string): void {\n if (this.loadedResources.has(url)) {\n return;\n }\n\n const existingLink = document.querySelector(`link[href=\"${url}\"]`);\n if (existingLink) {\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n document.head.appendChild(link);\n\n this.loadedResources.set(url, {\n element: link,\n promise: Promise.resolve()\n });\n }\n\n /**\n * Load common React libraries and UI frameworks\n * @param config Optional library configuration\n * @param additionalLibraries Optional additional libraries to merge\n * @returns Promise resolving to React ecosystem objects\n */\n async loadReactEcosystem(\n config?: LibraryConfiguration,\n additionalLibraries?: ExternalLibraryConfig[]\n ): Promise<{\n React: any;\n ReactDOM: any;\n Babel: any;\n libraries: any;\n }> {\n // Use the new LibraryLoader from react-runtime for consistency\n const result = await LibraryLoader.loadAllLibraries(config, additionalLibraries);\n \n // The LibraryLoader handles all the loading, but we need to ensure\n // ReactDOM.createRoot is available for Angular's specific needs\n // The ReactBridgeService will handle the delayed validation\n \n // Track loaded resources for cleanup\n LibraryLoader.getLoadedResources().forEach((resource, url) => {\n this.loadedResources.set(url, resource);\n });\n \n return result;\n }\n\n /**\n * Get library name from URL for global variable mapping\n * @param url - Library URL\n * @returns Global variable name\n */\n private getLibraryNameFromUrl(url: string): string {\n // Map known URLs to their global variable names\n if (url.includes('lodash')) return '_';\n if (url.includes('d3')) return 'd3';\n if (url.includes('Chart.js') || url.includes('chart')) return 'Chart';\n if (url.includes('dayjs')) return 'dayjs';\n if (url.includes('antd')) return 'antd';\n if (url.includes('react-bootstrap')) return 'ReactBootstrap';\n if (url.includes('react-dom')) return 'ReactDOM';\n if (url.includes('react')) return 'React';\n if (url.includes('babel')) return 'Babel';\n \n // Default: extract library name from filename\n const match = url.match(/\\/([^/]+?)(?:\\.min)?\\.js$/i);\n return match ? match[1] : 'UnknownLibrary';\n }\n\n /**\n * Remove a specific loaded resource\n * @param url - URL of resource to remove\n */\n removeResource(url: string): void {\n const resource = this.loadedResources.get(url);\n if (resource?.element && resource.element.parentNode) {\n resource.element.parentNode.removeChild(resource.element);\n }\n this.loadedResources.delete(url);\n this.cleanupOnDestroy.delete(url);\n }\n\n /**\n * Clean up all resources marked for auto-cleanup\n */\n private cleanup(): void {\n for (const url of this.cleanupOnDestroy) {\n this.removeResource(url);\n }\n this.cleanupOnDestroy.clear();\n }\n\n /**\n * Create a promise that resolves when script loads\n * @param url - Script URL\n * @param globalName - Expected global variable\n * @returns Promise resolving to global object\n */\n private createScriptPromise(url: string, globalName: string): Promise<any> {\n return new Promise((resolve, reject) => {\n // Check if already loaded\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n return;\n }\n\n // Check if script tag exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n this.waitForScriptLoad(existingScript as HTMLScriptElement, globalName, resolve, reject);\n return;\n }\n\n // Create new script\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n const global = (window as any)[globalName];\n if (global) {\n resolve(global);\n } else {\n reject(new Error(`${globalName} not found after script load`));\n }\n };\n\n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n this.loadedResources.set(url, { element: script, promise: Promise.resolve() });\n });\n }\n\n /**\n * Create a promise that resolves when script loads and passes validation\n * @param url - Script URL\n * @param globalName - Expected global variable\n * @param validator - Validation function\n * @returns Promise resolving to validated global object\n */\n private createScriptPromiseWithValidation(\n url: string, \n globalName: string, \n validator: (obj: any) => boolean\n ): Promise<any> {\n return new Promise((resolve, reject) => {\n // Check if already loaded and valid\n const existingGlobal = (window as any)[globalName];\n if (existingGlobal && validator(existingGlobal)) {\n resolve(existingGlobal);\n return;\n }\n\n // Check if script tag exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n this.waitForScriptLoadWithValidation(\n existingScript as HTMLScriptElement, \n globalName, \n validator,\n resolve, \n reject\n );\n return;\n }\n\n // Create new script\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n this.waitForValidation(globalName, validator, resolve, reject);\n };\n\n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n this.loadedResources.set(url, { element: script, promise: Promise.resolve() });\n });\n }\n\n /**\n * Wait for global object to be available and valid\n * @param globalName - Global variable name\n * @param validator - Validation function\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n * @param attempts - Current attempt number\n * @param maxAttempts - Maximum attempts before failing\n */\n private waitForValidation(\n globalName: string,\n validator: (obj: any) => boolean,\n resolve: (value: any) => void,\n reject: (reason: any) => void,\n attempts = 0,\n maxAttempts = 50 // 5 seconds total with 100ms intervals\n ): void {\n const global = (window as any)[globalName];\n \n if (global && validator(global)) {\n resolve(global);\n return;\n }\n\n if (attempts >= maxAttempts) {\n if (global) {\n reject(new Error(`${globalName} loaded but validation failed after ${maxAttempts} attempts`));\n } else {\n reject(new Error(`${globalName} not found after ${maxAttempts} attempts`));\n }\n return;\n }\n\n // Retry with exponential backoff for first few attempts, then fixed interval\n const delay = attempts < 5 ? Math.min(100 * Math.pow(1.5, attempts), 500) : 100;\n setTimeout(() => {\n this.waitForValidation(globalName, validator, resolve, reject, attempts + 1, maxAttempts);\n }, delay);\n }\n\n /**\n * Wait for existing script to load\n * @param script - Script element\n * @param globalName - Expected global variable\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n */\n private waitForScriptLoad(\n script: HTMLScriptElement,\n globalName: string,\n resolve: (value: any) => void,\n reject: (reason: any) => void\n ): void {\n const checkGlobal = () => {\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n return;\n }\n // Give it a moment for the global to be defined\n setTimeout(() => {\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n } else {\n reject(new Error(`${globalName} not found after script load`));\n }\n }, 100);\n };\n\n if ('readyState' in script) {\n // IE support\n (script as any).onreadystatechange = () => {\n if ((script as any).readyState === 'loaded' || (script as any).readyState === 'complete') {\n (script as any).onreadystatechange = null;\n checkGlobal();\n }\n };\n } else {\n // Modern browsers\n const loadHandler = () => {\n script.removeEventListener('load', loadHandler);\n checkGlobal();\n };\n script.addEventListener('load', loadHandler);\n }\n }\n\n /**\n * Wait for existing script to load with validation\n * @param script - Script element\n * @param globalName - Expected global variable\n * @param validator - Validation function\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n */\n private waitForScriptLoadWithValidation(\n script: HTMLScriptElement,\n globalName: string,\n validator: (obj: any) => boolean,\n resolve: (value: any) => void,\n reject: (reason: any) => void\n ): void {\n const checkGlobal = () => {\n this.waitForValidation(globalName, validator, resolve, reject);\n };\n\n if ('readyState' in script) {\n // IE support\n (script as any).onreadystatechange = () => {\n if ((script as any).readyState === 'loaded' || (script as any).readyState === 'complete') {\n (script as any).onreadystatechange = null;\n checkGlobal();\n }\n };\n } else {\n // Modern browsers\n const loadHandler = () => {\n script.removeEventListener('load', loadHandler);\n checkGlobal();\n };\n script.addEventListener('load', loadHandler);\n }\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"script-loader.service.js","sourceRoot":"","sources":["../../../src/lib/services/script-loader.service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,aAAa,EAGd,MAAM,+BAA+B,CAAC;;AAUvC;;;GAGG;AAEH,MAAM,OAAO,mBAAmB;IADhC;QAEU,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAC;QACzC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;KAoYvD;IAlYC,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAkB,EAAE,WAAW,GAAG,KAAK;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;QAED,MAAM,OAAO,GAAG,I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AC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAChD,WAAW,EAAE,CAAC;YAChB,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,+BAA+B,CACrC,MAAyB,EACzB,UAAkB,EAClB,SAAgC,EAChC,OAA6B,EAC7B,MAA6B;QAE7B,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACjE,CAAC,CAAC;QAEF,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;YAC3B,aAAa;YACZ,MAAc,CAAC,kBAAkB,GAAG,GAAG,EAAE;gBACxC,IAAK,MAAc,CAAC,UAAU,KAAK,QAAQ,IAAK,MAAc,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;oBACxF,MAAc,CAAC,kBAAkB,GAAG,IAAI,CAAC;oBAC1C,WAAW,EAAE,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,MAAM,WAAW,GAAG,GAAG,EAAE;gBACvB,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAChD,WAAW,EAAE,CAAC;YAChB,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;oFArYU,mBAAmB;uEAAnB,mBAAmB,WAAnB,mBAAmB,mBADN,MAAM;;iFACnB,mBAAmB;cAD/B,UAAU;eAAC,EAAE,UAAU,EAAE,MAAM,EAAE","sourcesContent":["/**\n * @fileoverview Service for loading external scripts and CSS in Angular applications.\n * Manages the lifecycle of dynamically loaded resources with proper cleanup.\n * @module @memberjunction/ng-react\n */\n\nimport { Injectable, OnDestroy } from '@angular/core';\nimport { \n LibraryLoader,\n LibraryConfiguration,\n ExternalLibraryConfig\n} from '@memberjunction/react-runtime';\n\n/**\n * Represents a loaded script or CSS resource\n */\ninterface LoadedScript {\n element: HTMLScriptElement | HTMLLinkElement;\n promise: Promise<any>;\n}\n\n/**\n * Service for loading external scripts and CSS with proper cleanup.\n * Provides methods to dynamically load React and related libraries from CDN.\n */\n@Injectable({ providedIn: 'root' })\nexport class ScriptLoaderService implements OnDestroy {\n private loadedResources = new Map<string, LoadedScript>();\n private readonly cleanupOnDestroy = new Set<string>();\n\n ngOnDestroy(): void {\n this.cleanup();\n }\n\n /**\n * Load a script from URL with automatic cleanup tracking\n * @param url - Script URL to load\n * @param globalName - Expected global variable name\n * @param autoCleanup - Whether to cleanup on service destroy\n * @returns Promise resolving to the global object\n */\n async loadScript(url: string, globalName: string, autoCleanup = false): Promise<any> {\n const existing = this.loadedResources.get(url);\n if (existing) {\n return existing.promise;\n }\n\n const promise = this.createScriptPromise(url, globalName);\n const element = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement;\n \n if (element) {\n this.loadedResources.set(url, { element, promise });\n if (autoCleanup) {\n this.cleanupOnDestroy.add(url);\n }\n }\n\n return promise;\n }\n\n /**\n * Load a script with additional validation function\n * @param url - Script URL to load\n * @param globalName - Expected global variable name\n * @param validator - Function to validate the loaded object\n * @param autoCleanup - Whether to cleanup on service destroy\n * @returns Promise resolving to the validated global object\n */\n async loadScriptWithValidation(\n url: string, \n globalName: string, \n validator: (obj: any) => boolean,\n autoCleanup = false\n ): Promise<any> {\n const existing = this.loadedResources.get(url);\n if (existing) {\n const obj = await existing.promise;\n // Re-validate even for cached resources\n if (!validator(obj)) {\n throw new Error(`${globalName} loaded but failed validation`);\n }\n return obj;\n }\n\n const promise = this.createScriptPromiseWithValidation(url, globalName, validator);\n const element = document.querySelector(`script[src=\"${url}\"]`) as HTMLScriptElement;\n \n if (element) {\n this.loadedResources.set(url, { element, promise });\n if (autoCleanup) {\n this.cleanupOnDestroy.add(url);\n }\n }\n\n return promise;\n }\n\n /**\n * Load CSS from URL\n * @param url - CSS URL to load\n */\n loadCSS(url: string): void {\n if (this.loadedResources.has(url)) {\n return;\n }\n\n const existingLink = document.querySelector(`link[href=\"${url}\"]`);\n if (existingLink) {\n return;\n }\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n document.head.appendChild(link);\n\n this.loadedResources.set(url, {\n element: link,\n promise: Promise.resolve()\n });\n }\n\n /**\n * Load common React libraries and UI frameworks\n * @param config Optional library configuration\n * @param additionalLibraries Optional additional libraries to merge\n * @param options Optional options including debug flag\n * @returns Promise resolving to React ecosystem objects\n */\n async loadReactEcosystem(\n config?: LibraryConfiguration,\n additionalLibraries?: ExternalLibraryConfig[],\n options?: { debug?: boolean }\n ): Promise<{\n React: any;\n ReactDOM: any;\n Babel: any;\n libraries: any;\n }> {\n // Use the new LibraryLoader from react-runtime for consistency\n const result = await LibraryLoader.loadAllLibraries(config, additionalLibraries, options);\n \n // The LibraryLoader handles all the loading, but we need to ensure\n // ReactDOM.createRoot is available for Angular's specific needs\n // The ReactBridgeService will handle the delayed validation\n \n // Track loaded resources for cleanup\n LibraryLoader.getLoadedResources().forEach((resource, url) => {\n this.loadedResources.set(url, resource);\n });\n \n return result;\n }\n\n /**\n * Get library name from URL for global variable mapping\n * @param url - Library URL\n * @returns Global variable name\n */\n private getLibraryNameFromUrl(url: string): string {\n // Map known URLs to their global variable names\n if (url.includes('lodash')) return '_';\n if (url.includes('d3')) return 'd3';\n if (url.includes('Chart.js') || url.includes('chart')) return 'Chart';\n if (url.includes('dayjs')) return 'dayjs';\n if (url.includes('antd')) return 'antd';\n if (url.includes('react-bootstrap')) return 'ReactBootstrap';\n if (url.includes('react-dom')) return 'ReactDOM';\n if (url.includes('react')) return 'React';\n if (url.includes('babel')) return 'Babel';\n \n // Default: extract library name from filename\n const match = url.match(/\\/([^/]+?)(?:\\.min)?\\.js$/i);\n return match ? match[1] : 'UnknownLibrary';\n }\n\n /**\n * Remove a specific loaded resource\n * @param url - URL of resource to remove\n */\n removeResource(url: string): void {\n const resource = this.loadedResources.get(url);\n if (resource?.element && resource.element.parentNode) {\n resource.element.parentNode.removeChild(resource.element);\n }\n this.loadedResources.delete(url);\n this.cleanupOnDestroy.delete(url);\n }\n\n /**\n * Clean up all resources marked for auto-cleanup\n */\n private cleanup(): void {\n for (const url of this.cleanupOnDestroy) {\n this.removeResource(url);\n }\n this.cleanupOnDestroy.clear();\n }\n\n /**\n * Create a promise that resolves when script loads\n * @param url - Script URL\n * @param globalName - Expected global variable\n * @returns Promise resolving to global object\n */\n private createScriptPromise(url: string, globalName: string): Promise<any> {\n return new Promise((resolve, reject) => {\n // Check if already loaded\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n return;\n }\n\n // Check if script tag exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n this.waitForScriptLoad(existingScript as HTMLScriptElement, globalName, resolve, reject);\n return;\n }\n\n // Create new script\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n const global = (window as any)[globalName];\n if (global) {\n resolve(global);\n } else {\n reject(new Error(`${globalName} not found after script load`));\n }\n };\n\n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n this.loadedResources.set(url, { element: script, promise: Promise.resolve() });\n });\n }\n\n /**\n * Create a promise that resolves when script loads and passes validation\n * @param url - Script URL\n * @param globalName - Expected global variable\n * @param validator - Validation function\n * @returns Promise resolving to validated global object\n */\n private createScriptPromiseWithValidation(\n url: string, \n globalName: string, \n validator: (obj: any) => boolean\n ): Promise<any> {\n return new Promise((resolve, reject) => {\n // Check if already loaded and valid\n const existingGlobal = (window as any)[globalName];\n if (existingGlobal && validator(existingGlobal)) {\n resolve(existingGlobal);\n return;\n }\n\n // Check if script tag exists\n const existingScript = document.querySelector(`script[src=\"${url}\"]`);\n if (existingScript) {\n this.waitForScriptLoadWithValidation(\n existingScript as HTMLScriptElement, \n globalName, \n validator,\n resolve, \n reject\n );\n return;\n }\n\n // Create new script\n const script = document.createElement('script');\n script.src = url;\n script.async = true;\n\n script.onload = () => {\n this.waitForValidation(globalName, validator, resolve, reject);\n };\n\n script.onerror = () => {\n reject(new Error(`Failed to load script: ${url}`));\n };\n\n document.head.appendChild(script);\n this.loadedResources.set(url, { element: script, promise: Promise.resolve() });\n });\n }\n\n /**\n * Wait for global object to be available and valid\n * @param globalName - Global variable name\n * @param validator - Validation function\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n * @param attempts - Current attempt number\n * @param maxAttempts - Maximum attempts before failing\n */\n private waitForValidation(\n globalName: string,\n validator: (obj: any) => boolean,\n resolve: (value: any) => void,\n reject: (reason: any) => void,\n attempts = 0,\n maxAttempts = 50 // 5 seconds total with 100ms intervals\n ): void {\n const global = (window as any)[globalName];\n \n if (global && validator(global)) {\n resolve(global);\n return;\n }\n\n if (attempts >= maxAttempts) {\n if (global) {\n reject(new Error(`${globalName} loaded but validation failed after ${maxAttempts} attempts`));\n } else {\n reject(new Error(`${globalName} not found after ${maxAttempts} attempts`));\n }\n return;\n }\n\n // Retry with exponential backoff for first few attempts, then fixed interval\n const delay = attempts < 5 ? Math.min(100 * Math.pow(1.5, attempts), 500) : 100;\n setTimeout(() => {\n this.waitForValidation(globalName, validator, resolve, reject, attempts + 1, maxAttempts);\n }, delay);\n }\n\n /**\n * Wait for existing script to load\n * @param script - Script element\n * @param globalName - Expected global variable\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n */\n private waitForScriptLoad(\n script: HTMLScriptElement,\n globalName: string,\n resolve: (value: any) => void,\n reject: (reason: any) => void\n ): void {\n const checkGlobal = () => {\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n return;\n }\n // Give it a moment for the global to be defined\n setTimeout(() => {\n if ((window as any)[globalName]) {\n resolve((window as any)[globalName]);\n } else {\n reject(new Error(`${globalName} not found after script load`));\n }\n }, 100);\n };\n\n if ('readyState' in script) {\n // IE support\n (script as any).onreadystatechange = () => {\n if ((script as any).readyState === 'loaded' || (script as any).readyState === 'complete') {\n (script as any).onreadystatechange = null;\n checkGlobal();\n }\n };\n } else {\n // Modern browsers\n const loadHandler = () => {\n script.removeEventListener('load', loadHandler);\n checkGlobal();\n };\n script.addEventListener('load', loadHandler);\n }\n }\n\n /**\n * Wait for existing script to load with validation\n * @param script - Script element\n * @param globalName - Expected global variable\n * @param validator - Validation function\n * @param resolve - Promise resolve function\n * @param reject - Promise reject function\n */\n private waitForScriptLoadWithValidation(\n script: HTMLScriptElement,\n globalName: string,\n validator: (obj: any) => boolean,\n resolve: (value: any) => void,\n reject: (reason: any) => void\n ): void {\n const checkGlobal = () => {\n this.waitForValidation(globalName, validator, resolve, reject);\n };\n\n if ('readyState' in script) {\n // IE support\n (script as any).onreadystatechange = () => {\n if ((script as any).readyState === 'loaded' || (script as any).readyState === 'complete') {\n (script as any).onreadystatechange = null;\n checkGlobal();\n }\n };\n } else {\n // Modern browsers\n const loadHandler = () => {\n script.removeEventListener('load', loadHandler);\n checkGlobal();\n };\n script.addEventListener('load', loadHandler);\n }\n }\n}"]}
|
|
@@ -9,11 +9,12 @@ import { ComponentUtilities } from '@memberjunction/interactive-component-types'
|
|
|
9
9
|
* to provide custom implementations of data access methods.
|
|
10
10
|
*/
|
|
11
11
|
export declare class RuntimeUtilities {
|
|
12
|
+
private debug;
|
|
12
13
|
/**
|
|
13
14
|
* Builds the complete utilities object for React components
|
|
14
15
|
* This is the main method that components will use
|
|
15
16
|
*/
|
|
16
|
-
buildUtilities(): ComponentUtilities;
|
|
17
|
+
buildUtilities(debug?: boolean): ComponentUtilities;
|
|
17
18
|
/**
|
|
18
19
|
* Sets up the utilities object - copied from skip-chat implementation
|
|
19
20
|
*/
|
|
@@ -13,11 +13,15 @@ import { SimpleVectorService } from '@memberjunction/ai-vectors-memory';
|
|
|
13
13
|
* to provide custom implementations of data access methods.
|
|
14
14
|
*/
|
|
15
15
|
let RuntimeUtilities = class RuntimeUtilities {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.debug = false;
|
|
18
|
+
}
|
|
16
19
|
/**
|
|
17
20
|
* Builds the complete utilities object for React components
|
|
18
21
|
* This is the main method that components will use
|
|
19
22
|
*/
|
|
20
|
-
buildUtilities() {
|
|
23
|
+
buildUtilities(debug = false) {
|
|
24
|
+
this.debug = debug;
|
|
21
25
|
const md = new Metadata();
|
|
22
26
|
return this.SetupUtilities(md);
|
|
23
27
|
}
|
|
@@ -53,6 +57,11 @@ let RuntimeUtilities = class RuntimeUtilities {
|
|
|
53
57
|
preferredModels: params.preferredModels,
|
|
54
58
|
modelPower: params.modelPower
|
|
55
59
|
});
|
|
60
|
+
console.log(`🤖 ExecutePrompt succeeded!`);
|
|
61
|
+
if (this.debug) {
|
|
62
|
+
console.log(' > params', params);
|
|
63
|
+
console.log(' > result:', result);
|
|
64
|
+
}
|
|
56
65
|
return {
|
|
57
66
|
success: result.success,
|
|
58
67
|
result: result.result || '',
|
|
@@ -79,6 +88,12 @@ let RuntimeUtilities = class RuntimeUtilities {
|
|
|
79
88
|
if (result.error) {
|
|
80
89
|
throw new Error(result.error || 'Failed to generate embeddings');
|
|
81
90
|
}
|
|
91
|
+
const numEmbeddings = Array.isArray(params.textToEmbed) ? result.embeddings?.length : 1;
|
|
92
|
+
console.log(`🤖 EmbedText succeeded! ${numEmbeddings} embeddings returned`);
|
|
93
|
+
if (this.debug) {
|
|
94
|
+
console.log(' > params', params);
|
|
95
|
+
console.log(' > result:', result);
|
|
96
|
+
}
|
|
82
97
|
return {
|
|
83
98
|
result: result.embeddings,
|
|
84
99
|
modelName: result.modelName,
|
|
@@ -107,9 +122,20 @@ let RuntimeUtilities = class RuntimeUtilities {
|
|
|
107
122
|
// Run a single query and return the results
|
|
108
123
|
try {
|
|
109
124
|
const result = await rq.RunQuery(params);
|
|
125
|
+
if (result.Success) {
|
|
126
|
+
console.log(`✅ RunQuery "${params.QueryName}" succeeded: ${result.RowCount} rows returned`);
|
|
127
|
+
if (this.debug) {
|
|
128
|
+
console.log(' > params', params);
|
|
129
|
+
console.log(' > result:', result);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.error(`❌ RunQuery failed: ${result.ErrorMessage}`);
|
|
134
|
+
}
|
|
110
135
|
return result;
|
|
111
136
|
}
|
|
112
137
|
catch (error) {
|
|
138
|
+
console.error(`❌ RunQuery threw exception:`, error);
|
|
113
139
|
LogError(error);
|
|
114
140
|
throw error; // Re-throw to handle it in the caller
|
|
115
141
|
}
|
|
@@ -122,9 +148,20 @@ let RuntimeUtilities = class RuntimeUtilities {
|
|
|
122
148
|
// Run a single view and return the results
|
|
123
149
|
try {
|
|
124
150
|
const result = await rv.RunView(params);
|
|
151
|
+
if (result.Success) {
|
|
152
|
+
console.log(`✅ RunView succeeded for ${params.EntityName}: ${result.TotalRowCount} rows returned`);
|
|
153
|
+
if (this.debug) {
|
|
154
|
+
console.log(' > params', params);
|
|
155
|
+
console.log(' > result:', result);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.error(`❌ RunView failed for ${params.EntityName}: ${result.ErrorMessage}`);
|
|
160
|
+
}
|
|
125
161
|
return result;
|
|
126
162
|
}
|
|
127
163
|
catch (error) {
|
|
164
|
+
console.error(`❌ RunView threw exception:`, error);
|
|
128
165
|
LogError(error);
|
|
129
166
|
throw error; // Re-throw to handle it in the caller
|
|
130
167
|
}
|
|
@@ -133,9 +170,17 @@ let RuntimeUtilities = class RuntimeUtilities {
|
|
|
133
170
|
// Runs multiple views and returns the results
|
|
134
171
|
try {
|
|
135
172
|
const results = await rv.RunViews(params);
|
|
173
|
+
const entityNames = params.map(p => p.EntityName).join(', ');
|
|
174
|
+
const totalRows = results.reduce((sum, r) => sum + (r.TotalRowCount || 0), 0);
|
|
175
|
+
console.log(`✅ RunViews succeeded for [${entityNames}]: ${totalRows} total rows returned`);
|
|
176
|
+
if (this.debug) {
|
|
177
|
+
console.log(' > params', params);
|
|
178
|
+
console.log(' > results:', results);
|
|
179
|
+
}
|
|
136
180
|
return results;
|
|
137
181
|
}
|
|
138
182
|
catch (error) {
|
|
183
|
+
console.error(`❌ RunViews threw exception:`, error);
|
|
139
184
|
LogError(error);
|
|
140
185
|
throw error; // Re-throw to handle it in the caller
|
|
141
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-utilities.js","sourceRoot":"","sources":["../../../src/lib/utilities/runtime-utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EAGR,QAAQ,EACR,UAAU,EAEX,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAYjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE;;;;GAIG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B;;;OAGG;IACI,cAAc;QACnB,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,EAAY;QACjC,MAAM,EAAE,GAAG,IAAI,OAAO,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAuB;YAC5B,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC;YACjC,EAAE,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAChC,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC;YACjC,EAAE,EAAE,IAAI,CAAC,mBAAmB,EAAE;SAC/B,CAAC;QACF,OAAO,CAAC,CA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AA0B;QAC5B,CAAC;IACH,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,gBAAgB,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * @fileoverview Runtime utilities for React components providing access to MemberJunction core functionality\n * @module @memberjunction/ng-react/utilities\n */\n\nimport { \n Metadata, \n RunView, \n RunQuery, \n RunViewParams, \n RunQueryParams,\n LogError,\n BaseEntity,\n IEntityDataProvider\n} from '@memberjunction/core';\n\nimport { MJGlobal, RegisterClass } from '@memberjunction/global';\nimport { \n ComponentUtilities, \n SimpleAITools, \n SimpleMetadata, \n SimpleRunQuery, \n SimpleRunView,\n SimpleExecutePromptParams,\n SimpleExecutePromptResult,\n SimpleEmbedTextParams,\n SimpleEmbedTextResult\n} from '@memberjunction/interactive-component-types';\nimport { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';\nimport { SimpleVectorService } from '@memberjunction/ai-vectors-memory';\n\n/**\n * Base class for providing runtime utilities to React components in Angular.\n * This class can be extended and registered with MJ's ClassFactory\n * to provide custom implementations of data access methods.\n */\n@RegisterClass(RuntimeUtilities, 'RuntimeUtilities')\nexport class RuntimeUtilities {\n /**\n * Builds the complete utilities object for React components\n * This is the main method that components will use\n */\n public buildUtilities(): ComponentUtilities {\n const md = new Metadata();\n return this.SetupUtilities(md);\n }\n\n /**\n * Sets up the utilities object - copied from skip-chat implementation\n */\n private SetupUtilities(md: Metadata): ComponentUtilities {\n const rv = new RunView();\n const rq = new RunQuery();\n const u: ComponentUtilities = {\n md: this.CreateSimpleMetadata(md),\n rv: this.CreateSimpleRunView(rv),\n rq: this.CreateSimpleRunQuery(rq),\n ai: this.CreateSimpleAITools()\n }; \n return u;\n }\n\n private CreateSimpleAITools(): SimpleAITools {\n // Get the GraphQL provider - it's the same as the BaseEntity provider\n const provider = BaseEntity.Provider;\n \n // Check if it's a GraphQLDataProvider\n if (!(provider instanceof GraphQLDataProvider)) {\n throw new Error('Current data provider is not a GraphQLDataProvider. AI tools require GraphQL provider.');\n }\n\n const graphQLProvider = provider as GraphQLDataProvider;\n \n return {\n ExecutePrompt: async (params: SimpleExecutePromptParams): Promise<SimpleExecutePromptResult> => {\n try {\n // Use the AI client from GraphQLDataProvider to execute simple prompt\n const result = await graphQLProvider.AI.ExecuteSimplePrompt({\n systemPrompt: params.systemPrompt,\n messages: params.messages,\n preferredModels: params.preferredModels,\n modelPower: params.modelPower\n });\n \n return {\n success: result.success,\n result: result.result || '',\n resultObject: result.resultObject,\n modelName: result.modelName || ''\n };\n } catch (error) {\n LogError(error);\n return {\n success: false,\n result: 'Failed to execute prompt: ' + (error instanceof Error ? error.message : String(error)),\n modelName: ''\n };\n }\n },\n \n EmbedText: async (params: SimpleEmbedTextParams): Promise<SimpleEmbedTextResult> => {\n try {\n // Use the AI client from GraphQLDataProvider to generate embeddings\n const result = await graphQLProvider.AI.EmbedText({\n textToEmbed: params.textToEmbed,\n modelSize: params.modelSize\n });\n \n if (result.error) {\n throw new Error(result.error || 'Failed to generate embeddings');\n }\n \n return {\n result: result.embeddings,\n modelName: result.modelName,\n vectorDimensions: result.vectorDimensions\n };\n } catch (error) {\n LogError(error);\n throw error; // Re-throw for embeddings as they're critical\n }\n },\n \n VectorService: new SimpleVectorService()\n };\n }\n\n private CreateSimpleMetadata(md: Metadata): SimpleMetadata {\n return {\n Entities: md.Entities,\n GetEntityObject: (entityName: string) => {\n return md.GetEntityObject(entityName)\n }\n }\n }\n\n private CreateSimpleRunQuery(rq: RunQuery): SimpleRunQuery {\n return {\n RunQuery: async (params: RunQueryParams) => {\n // Run a single query and return the results\n try {\n const result = await rq.RunQuery(params);\n return result;\n } catch (error) {\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n }\n }\n }\n\n private CreateSimpleRunView(rv: RunView): SimpleRunView {\n return {\n RunView: async (params: RunViewParams) => {\n // Run a single view and return the results\n try {\n const result = await rv.RunView(params);\n return result;\n } catch (error) {\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n },\n RunViews: async (params: RunViewParams[]) => {\n // Runs multiple views and returns the results\n try {\n const results = await rv.RunViews(params);\n return results;\n } catch (error) {\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n }\n }\n }\n}\n\n/**\n * Factory function to create RuntimeUtilities\n * In a Node.js environment, this will use MJ's ClassFactory for runtime substitution\n * In a browser environment, it will use the base class directly\n */\nexport function createRuntimeUtilities(): RuntimeUtilities {\n // Check if we're in a Node.js environment with MJGlobal available\n if (typeof window === 'undefined') {\n try {\n // Use ClassFactory to get the registered class, defaulting to base RuntimeUtilities\n const obj = MJGlobal.Instance.ClassFactory.CreateInstance<RuntimeUtilities>(RuntimeUtilities);\n if (!obj) {\n throw new Error('Failed to create RuntimeUtilities instance');\n }\n\n // Ensure the object is an instance of RuntimeUtilities\n return obj;\n } catch (e) {\n // Fall through to default\n }\n }\n \n // Default: just use the base class\n return new RuntimeUtilities();\n}"]}
|
|
1
|
+
{"version":3,"file":"runtime-utilities.js","sourceRoot":"","sources":["../../../src/lib/utilities/runtime-utilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EAGR,QAAQ,EACR,UAAU,EAEX,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAYjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE;;;;GAIG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAAtB;QACG,UAAK,GAAY,KAAK,CAAC;IAoLjC,CAAC;IAlLC;;;OAGG;IACI,cAAc,CAAC,QAAiB,KAAK;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,MAAM,EAAE,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CA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AC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAmB,gBAAgB,CAAC,CAAC;YAC9F,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YAED,uDAAuD;YACvD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,0BAA0B;QAC5B,CAAC;IACH,CAAC;IAED,mCAAmC;IACnC,OAAO,IAAI,gBAAgB,EAAE,CAAC;AAChC,CAAC","sourcesContent":["/**\n * @fileoverview Runtime utilities for React components providing access to MemberJunction core functionality\n * @module @memberjunction/ng-react/utilities\n */\n\nimport { \n Metadata, \n RunView, \n RunQuery, \n RunViewParams, \n RunQueryParams,\n LogError,\n BaseEntity,\n IEntityDataProvider\n} from '@memberjunction/core';\n\nimport { MJGlobal, RegisterClass } from '@memberjunction/global';\nimport { \n ComponentUtilities, \n SimpleAITools, \n SimpleMetadata, \n SimpleRunQuery, \n SimpleRunView,\n SimpleExecutePromptParams,\n SimpleExecutePromptResult,\n SimpleEmbedTextParams,\n SimpleEmbedTextResult\n} from '@memberjunction/interactive-component-types';\nimport { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';\nimport { SimpleVectorService } from '@memberjunction/ai-vectors-memory';\n\n/**\n * Base class for providing runtime utilities to React components in Angular.\n * This class can be extended and registered with MJ's ClassFactory\n * to provide custom implementations of data access methods.\n */\n@RegisterClass(RuntimeUtilities, 'RuntimeUtilities')\nexport class RuntimeUtilities {\n private debug: boolean = false;\n \n /**\n * Builds the complete utilities object for React components\n * This is the main method that components will use\n */\n public buildUtilities(debug: boolean = false): ComponentUtilities {\n this.debug = debug;\n const md = new Metadata();\n return this.SetupUtilities(md);\n }\n\n /**\n * Sets up the utilities object - copied from skip-chat implementation\n */\n private SetupUtilities(md: Metadata): ComponentUtilities {\n const rv = new RunView();\n const rq = new RunQuery();\n const u: ComponentUtilities = {\n md: this.CreateSimpleMetadata(md),\n rv: this.CreateSimpleRunView(rv),\n rq: this.CreateSimpleRunQuery(rq),\n ai: this.CreateSimpleAITools()\n }; \n return u;\n }\n\n private CreateSimpleAITools(): SimpleAITools {\n // Get the GraphQL provider - it's the same as the BaseEntity provider\n const provider = BaseEntity.Provider;\n \n // Check if it's a GraphQLDataProvider\n if (!(provider instanceof GraphQLDataProvider)) {\n throw new Error('Current data provider is not a GraphQLDataProvider. AI tools require GraphQL provider.');\n }\n\n const graphQLProvider = provider as GraphQLDataProvider;\n \n return {\n ExecutePrompt: async (params: SimpleExecutePromptParams): Promise<SimpleExecutePromptResult> => {\n try {\n // Use the AI client from GraphQLDataProvider to execute simple prompt\n const result = await graphQLProvider.AI.ExecuteSimplePrompt({\n systemPrompt: params.systemPrompt,\n messages: params.messages,\n preferredModels: params.preferredModels,\n modelPower: params.modelPower\n });\n\n console.log(`🤖 ExecutePrompt succeeded!`);\n if (this.debug) {\n console.log(' > params', params);\n console.log(' > result:', result);\n }\n\n return {\n success: result.success,\n result: result.result || '',\n resultObject: result.resultObject,\n modelName: result.modelName || ''\n };\n } catch (error) {\n LogError(error);\n return {\n success: false,\n result: 'Failed to execute prompt: ' + (error instanceof Error ? error.message : String(error)),\n modelName: ''\n };\n }\n },\n \n EmbedText: async (params: SimpleEmbedTextParams): Promise<SimpleEmbedTextResult> => {\n try {\n // Use the AI client from GraphQLDataProvider to generate embeddings\n const result = await graphQLProvider.AI.EmbedText({\n textToEmbed: params.textToEmbed,\n modelSize: params.modelSize\n });\n \n if (result.error) {\n throw new Error(result.error || 'Failed to generate embeddings');\n }\n\n const numEmbeddings: number = Array.isArray(params.textToEmbed) ? result.embeddings?.length : 1;\n console.log(`🤖 EmbedText succeeded! ${numEmbeddings} embeddings returned`);\n if (this.debug) {\n console.log(' > params', params);\n console.log(' > result:', result);\n }\n return {\n result: result.embeddings,\n modelName: result.modelName,\n vectorDimensions: result.vectorDimensions\n };\n } catch (error) {\n LogError(error);\n throw error; // Re-throw for embeddings as they're critical\n }\n },\n \n VectorService: new SimpleVectorService()\n };\n }\n\n private CreateSimpleMetadata(md: Metadata): SimpleMetadata {\n return {\n Entities: md.Entities,\n GetEntityObject: (entityName: string) => {\n return md.GetEntityObject(entityName)\n }\n }\n }\n\n private CreateSimpleRunQuery(rq: RunQuery): SimpleRunQuery {\n return {\n RunQuery: async (params: RunQueryParams) => {\n // Run a single query and return the results\n try {\n const result = await rq.RunQuery(params);\n if (result.Success) {\n console.log(`✅ RunQuery \"${params.QueryName}\" succeeded: ${result.RowCount} rows returned`);\n if (this.debug) {\n console.log(' > params', params);\n console.log(' > result:', result);\n }\n } else {\n console.error(`❌ RunQuery failed: ${result.ErrorMessage}`);\n }\n return result;\n } catch (error) {\n console.error(`❌ RunQuery threw exception:`, error);\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n }\n }\n }\n\n private CreateSimpleRunView(rv: RunView): SimpleRunView {\n return {\n RunView: async (params: RunViewParams) => {\n // Run a single view and return the results\n try {\n const result = await rv.RunView(params);\n if (result.Success) {\n console.log(`✅ RunView succeeded for ${params.EntityName}: ${result.TotalRowCount} rows returned`);\n if (this.debug) {\n console.log(' > params', params);\n console.log(' > result:', result);\n }\n } else {\n console.error(`❌ RunView failed for ${params.EntityName}: ${result.ErrorMessage}`);\n }\n return result;\n } catch (error) {\n console.error(`❌ RunView threw exception:`, error);\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n },\n RunViews: async (params: RunViewParams[]) => {\n // Runs multiple views and returns the results\n try {\n const results = await rv.RunViews(params);\n const entityNames = params.map(p => p.EntityName).join(', ');\n const totalRows = results.reduce((sum, r) => sum + (r.TotalRowCount || 0), 0);\n console.log(`✅ RunViews succeeded for [${entityNames}]: ${totalRows} total rows returned`);\n if (this.debug) {\n console.log(' > params', params);\n console.log(' > results:', results);\n }\n return results;\n } catch (error) {\n console.error(`❌ RunViews threw exception:`, error);\n LogError(error);\n throw error; // Re-throw to handle it in the caller\n }\n }\n }\n }\n}\n\n/**\n * Factory function to create RuntimeUtilities\n * In a Node.js environment, this will use MJ's ClassFactory for runtime substitution\n * In a browser environment, it will use the base class directly\n */\nexport function createRuntimeUtilities(): RuntimeUtilities {\n // Check if we're in a Node.js environment with MJGlobal available\n if (typeof window === 'undefined') {\n try {\n // Use ClassFactory to get the registered class, defaulting to base RuntimeUtilities\n const obj = MJGlobal.Instance.ClassFactory.CreateInstance<RuntimeUtilities>(RuntimeUtilities);\n if (!obj) {\n throw new Error('Failed to create RuntimeUtilities instance');\n }\n\n // Ensure the object is an instance of RuntimeUtilities\n return obj;\n } catch (e) {\n // Fall through to default\n }\n }\n \n // Default: just use the base class\n return new RuntimeUtilities();\n}"]}
|
package/dist/public-api.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export * from './lib/components/mj-react-component.component';
|
|
|
8
8
|
export * from './lib/services/script-loader.service';
|
|
9
9
|
export * from './lib/services/react-bridge.service';
|
|
10
10
|
export * from './lib/services/angular-adapter.service';
|
|
11
|
-
export * from './lib/
|
|
11
|
+
export * from './lib/config/react-debug.config';
|
package/dist/public-api.js
CHANGED
|
@@ -11,6 +11,6 @@ export * from './lib/components/mj-react-component.component';
|
|
|
11
11
|
export * from './lib/services/script-loader.service';
|
|
12
12
|
export * from './lib/services/react-bridge.service';
|
|
13
13
|
export * from './lib/services/angular-adapter.service';
|
|
14
|
-
//
|
|
15
|
-
export * from './lib/
|
|
14
|
+
// Configuration
|
|
15
|
+
export * from './lib/config/react-debug.config';
|
|
16
16
|
//# sourceMappingURL=public-api.js.map
|
package/dist/public-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS;AACT,cAAc,cAAc,CAAC;AAE7B,aAAa;AACb,cAAc,+CAA+C,CAAC;AAE9D,WAAW;AACX,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AAEvD,
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS;AACT,cAAc,cAAc,CAAC;AAE7B,aAAa;AACb,cAAc,+CAA+C,CAAC;AAE9D,WAAW;AACX,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AAEvD,gBAAgB;AAChB,cAAc,iCAAiC,CAAC","sourcesContent":["/**\n * @fileoverview Public API Surface of @memberjunction/ng-react\n * This file exports all public APIs from the Angular React integration library.\n * @module @memberjunction/ng-react\n */\n\n// Module\nexport * from './lib/module';\n\n// Components\nexport * from './lib/components/mj-react-component.component';\n\n// Services\nexport * from './lib/services/script-loader.service';\nexport * from './lib/services/react-bridge.service';\nexport * from './lib/services/angular-adapter.service';\n\n// Configuration\nexport * from './lib/config/react-debug.config';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.97.0",
|
|
4
4
|
"description": "Angular components for hosting React components in MemberJunction applications",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "ngc -p tsconfig.json",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"styles"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@memberjunction/core": "2.
|
|
44
|
-
"@memberjunction/react-runtime": "2.
|
|
45
|
-
"@memberjunction/interactive-component-types": "^2.
|
|
43
|
+
"@memberjunction/core": "2.97.0",
|
|
44
|
+
"@memberjunction/react-runtime": "2.97.0",
|
|
45
|
+
"@memberjunction/interactive-component-types": "^2.97.0",
|
|
46
46
|
"@angular/common": ">=18.0.0",
|
|
47
47
|
"@angular/core": ">=18.0.0",
|
|
48
48
|
"@angular/platform-browser": ">=18.0.0",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Default styles for React components in MemberJunction.
|
|
3
|
-
* These styles provide a consistent design system for React components.
|
|
4
|
-
* @module @memberjunction/ng-react
|
|
5
|
-
*/
|
|
6
|
-
import { ComponentStyles } from '@memberjunction/interactive-component-types';
|
|
7
|
-
/**
|
|
8
|
-
* Default styles that match the Skip design system
|
|
9
|
-
*/
|
|
10
|
-
export declare const DEFAULT_STYLES: ComponentStyles;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Default styles for React components in MemberJunction.
|
|
3
|
-
* These styles provide a consistent design system for React components.
|
|
4
|
-
* @module @memberjunction/ng-react
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Default styles that match the Skip design system
|
|
8
|
-
*/
|
|
9
|
-
export const DEFAULT_STYLES = {
|
|
10
|
-
colors: {
|
|
11
|
-
// Primary colors - modern purple/blue gradient feel
|
|
12
|
-
primary: '#5B4FE9',
|
|
13
|
-
primaryHover: '#4940D4',
|
|
14
|
-
primaryLight: '#E8E6FF',
|
|
15
|
-
// Secondary colors - sophisticated gray
|
|
16
|
-
secondary: '#64748B',
|
|
17
|
-
secondaryHover: '#475569',
|
|
18
|
-
// Status colors
|
|
19
|
-
success: '#10B981',
|
|
20
|
-
successLight: '#D1FAE5',
|
|
21
|
-
warning: '#F59E0B',
|
|
22
|
-
warningLight: '#FEF3C7',
|
|
23
|
-
error: '#EF4444',
|
|
24
|
-
errorLight: '#FEE2E2',
|
|
25
|
-
info: '#3B82F6',
|
|
26
|
-
infoLight: '#DBEAFE',
|
|
27
|
-
// Base colors
|
|
28
|
-
background: '#FFFFFF',
|
|
29
|
-
surface: '#F8FAFC',
|
|
30
|
-
surfaceHover: '#F1F5F9',
|
|
31
|
-
// Text colors with better contrast
|
|
32
|
-
text: '#1E293B',
|
|
33
|
-
textSecondary: '#64748B',
|
|
34
|
-
textTertiary: '#94A3B8',
|
|
35
|
-
textInverse: '#FFFFFF',
|
|
36
|
-
// Border colors
|
|
37
|
-
border: '#E2E8F0',
|
|
38
|
-
borderLight: '#F1F5F9',
|
|
39
|
-
borderFocus: '#5B4FE9',
|
|
40
|
-
// Shadows (as color strings for easy use)
|
|
41
|
-
shadow: 'rgba(0, 0, 0, 0.05)',
|
|
42
|
-
shadowMedium: 'rgba(0, 0, 0, 0.1)',
|
|
43
|
-
shadowLarge: 'rgba(0, 0, 0, 0.15)',
|
|
44
|
-
},
|
|
45
|
-
spacing: {
|
|
46
|
-
xs: '4px',
|
|
47
|
-
sm: '8px',
|
|
48
|
-
md: '16px',
|
|
49
|
-
lg: '24px',
|
|
50
|
-
xl: '32px',
|
|
51
|
-
xxl: '48px',
|
|
52
|
-
xxxl: '64px',
|
|
53
|
-
},
|
|
54
|
-
typography: {
|
|
55
|
-
fontFamily: '-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif',
|
|
56
|
-
fontSize: {
|
|
57
|
-
xs: '11px',
|
|
58
|
-
sm: '12px',
|
|
59
|
-
md: '14px',
|
|
60
|
-
lg: '16px',
|
|
61
|
-
xl: '20px',
|
|
62
|
-
xxl: '24px',
|
|
63
|
-
xxxl: '32px',
|
|
64
|
-
},
|
|
65
|
-
fontWeight: {
|
|
66
|
-
light: '300',
|
|
67
|
-
regular: '400',
|
|
68
|
-
medium: '500',
|
|
69
|
-
semibold: '600',
|
|
70
|
-
bold: '700',
|
|
71
|
-
},
|
|
72
|
-
lineHeight: {
|
|
73
|
-
tight: '1.25',
|
|
74
|
-
normal: '1.5',
|
|
75
|
-
relaxed: '1.75',
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
borders: {
|
|
79
|
-
radius: {
|
|
80
|
-
sm: '6px',
|
|
81
|
-
md: '8px',
|
|
82
|
-
lg: '12px',
|
|
83
|
-
xl: '16px',
|
|
84
|
-
full: '9999px',
|
|
85
|
-
},
|
|
86
|
-
width: {
|
|
87
|
-
thin: '1px',
|
|
88
|
-
medium: '2px',
|
|
89
|
-
thick: '3px',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
shadows: {
|
|
93
|
-
sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
94
|
-
md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
|
|
95
|
-
lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
|
|
96
|
-
xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
|
|
97
|
-
inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
|
|
98
|
-
},
|
|
99
|
-
transitions: {
|
|
100
|
-
fast: '150ms ease-in-out',
|
|
101
|
-
normal: '250ms ease-in-out',
|
|
102
|
-
slow: '350ms ease-in-out',
|
|
103
|
-
},
|
|
104
|
-
overflow: 'auto'
|
|
105
|
-
};
|
|
106
|
-
//# sourceMappingURL=default-styles.js.map
|