@memberjunction/react-runtime 2.93.0 → 2.94.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 (62) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +180 -2
  4. package/dist/compiler/component-compiler.d.ts.map +1 -1
  5. package/dist/compiler/component-compiler.js +206 -57
  6. package/dist/compiler/component-compiler.js.map +1 -1
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +13 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/registry/component-registry-service.d.ts +4 -3
  12. package/dist/registry/component-registry-service.d.ts.map +1 -1
  13. package/dist/registry/component-registry-service.js +27 -11
  14. package/dist/registry/component-registry-service.js.map +1 -1
  15. package/dist/registry/component-registry.d.ts +4 -3
  16. package/dist/registry/component-registry.d.ts.map +1 -1
  17. package/dist/registry/component-registry.js.map +1 -1
  18. package/dist/registry/component-resolver.d.ts +2 -1
  19. package/dist/registry/component-resolver.d.ts.map +1 -1
  20. package/dist/registry/component-resolver.js +42 -10
  21. package/dist/registry/component-resolver.js.map +1 -1
  22. package/dist/runtime/component-hierarchy.d.ts.map +1 -1
  23. package/dist/runtime/component-hierarchy.js +8 -2
  24. package/dist/runtime/component-hierarchy.js.map +1 -1
  25. package/dist/runtime/prop-builder.d.ts +2 -2
  26. package/dist/runtime/prop-builder.d.ts.map +1 -1
  27. package/dist/runtime/prop-builder.js +32 -14
  28. package/dist/runtime/prop-builder.js.map +1 -1
  29. package/dist/runtime.umd.js +1 -1
  30. package/dist/types/dependency-types.d.ts +62 -0
  31. package/dist/types/dependency-types.d.ts.map +1 -0
  32. package/dist/types/dependency-types.js +3 -0
  33. package/dist/types/dependency-types.js.map +1 -0
  34. package/dist/types/index.d.ts +8 -10
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/index.js +1 -0
  37. package/dist/types/index.js.map +1 -1
  38. package/dist/utilities/index.d.ts +1 -0
  39. package/dist/utilities/index.d.ts.map +1 -1
  40. package/dist/utilities/index.js +1 -0
  41. package/dist/utilities/index.js.map +1 -1
  42. package/dist/utilities/library-dependency-resolver.d.ts +19 -0
  43. package/dist/utilities/library-dependency-resolver.d.ts.map +1 -0
  44. package/dist/utilities/library-dependency-resolver.js +410 -0
  45. package/dist/utilities/library-dependency-resolver.js.map +1 -0
  46. package/dist/utilities/library-loader.d.ts +9 -0
  47. package/dist/utilities/library-loader.d.ts.map +1 -1
  48. package/dist/utilities/library-loader.js +143 -0
  49. package/dist/utilities/library-loader.js.map +1 -1
  50. package/package.json +5 -5
  51. package/src/compiler/component-compiler.ts +227 -77
  52. package/src/index.ts +18 -4
  53. package/src/registry/component-registry-service.ts +32 -14
  54. package/src/registry/component-registry.ts +8 -7
  55. package/src/registry/component-resolver.ts +51 -10
  56. package/src/runtime/component-hierarchy.ts +12 -4
  57. package/src/runtime/prop-builder.ts +38 -18
  58. package/src/types/dependency-types.ts +110 -0
  59. package/src/types/index.ts +17 -21
  60. package/src/utilities/index.ts +1 -0
  61. package/src/utilities/library-dependency-resolver.ts +603 -0
  62. package/src/utilities/library-loader.ts +252 -0
@@ -1,24 +1,24 @@
1
1
 
2
- > @memberjunction/react-runtime@2.93.0 build
2
+ > @memberjunction/react-runtime@2.94.0 build
3
3
  > npm run build:node && npm run build:umd
4
4
 
5
5
 
6
- > @memberjunction/react-runtime@2.93.0 build:node
6
+ > @memberjunction/react-runtime@2.94.0 build:node
7
7
  > tsc
8
8
 
9
9
 
10
- > @memberjunction/react-runtime@2.93.0 build:umd
10
+ > @memberjunction/react-runtime@2.94.0 build:umd
11
11
  > webpack --config webpack.umd.config.js
12
12
 
13
13
  [BABEL] Note: The code generator has deoptimised the styling of /home/runner/work/MJ/MJ/packages/MJCoreEntities/dist/generated/entity_subclasses.js as it exceeds the max of 500KB.
14
- asset runtime.umd.js 1.88 MiB [emitted] [minimized] [big] (name: main) 1 related asset
14
+ asset runtime.umd.js 1.91 MiB [emitted] [minimized] [big] (name: main) 1 related asset
15
15
  runtime modules 344 bytes 2 modules
16
16
  modules by path ../../../node_modules/ 1.01 MiB 237 modules
17
17
  modules by path ../../MJGlobal/ 174 KiB
18
18
  modules by path ../../MJGlobal/node_modules/uuid/dist/commonjs-browser/*.js 35 KiB 21 modules
19
19
  modules by path ../../MJGlobal/dist/ 139 KiB 14 modules
20
20
  modules by path ../../MJCore/ 643 KiB 31 modules
21
- modules by path ./dist/ 283 KiB 23 modules
21
+ modules by path ./dist/ 336 KiB 25 modules
22
22
  modules by path ../../MJCoreEntities/dist/ 2.04 MiB
23
23
  modules by path ../../MJCoreEntities/dist/custom/*.js 241 KiB 15 modules
24
24
  modules by path ../../MJCoreEntities/dist/custom/ResourcePermissions/*.js 46.9 KiB 3 modules
@@ -27,4 +27,4 @@ modules by path ../../InteractiveComponents/dist/*.js 36.8 KiB
27
27
  ../../InteractiveComponents/dist/index.js 1.21 KiB [built] [code generated]
28
28
  ../../InteractiveComponents/dist/data-requirements.js 79 bytes [built] [code generated]
29
29
  + 8 modules
30
- webpack 5.92.1 compiled successfully in 108887 ms
30
+ webpack 5.92.1 compiled successfully in 109563 ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @memberjunction/react-runtime
2
2
 
3
+ ## 2.94.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 455654e: migration (unrelated) to bump to minor
8
+ - 7c27b04: migration
9
+ - 98afc80: migrations
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [eed16e0]
14
+ - @memberjunction/interactive-component-types@2.94.0
15
+ - @memberjunction/core-entities@2.94.0
16
+ - @memberjunction/core@2.94.0
17
+ - @memberjunction/global@2.94.0
18
+
3
19
  ## 2.93.0
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -165,20 +165,198 @@ const context = {
165
165
  const MyComponent = runtime.registry.get('MyComponent', 'MyNamespace');
166
166
 
167
167
  // Execute the component factory
168
- const { component } = MyComponent(context);
168
+ const componentObject = MyComponent(context);
169
+
170
+ // The componentObject contains the React component and method accessors
171
+ const { component, print, refresh, getCurrentDataState, isDirty } = componentObject;
169
172
 
170
173
  // Render with props
171
174
  const props = {
172
175
  data: { name: 'World' },
173
176
  userState: {},
174
177
  callbacks: {
175
- RefreshData: () => console.log('Refresh clicked!')
178
+ OpenEntityRecord: (entityName, key) => console.log('Open entity:', entityName),
179
+ RegisterMethod: (methodName, handler) => {
180
+ // Component will register its methods here
181
+ }
176
182
  }
177
183
  };
178
184
 
179
185
  React.createElement(component, props);
180
186
  ```
181
187
 
188
+ ## Component Methods System
189
+
190
+ ### Overview
191
+
192
+ Components can expose methods that allow containers to interact with them beyond just passing props. This enables scenarios like:
193
+ - AI agents introspecting component state
194
+ - Containers checking if components have unsaved changes
195
+ - Programmatic validation and reset operations
196
+ - Custom business logic exposed by components
197
+
198
+ ### How Components Register Methods
199
+
200
+ Components register their methods during initialization using the `RegisterMethod` callback:
201
+
202
+ ```typescript
203
+ function MyComponent({ callbacks, data, userState }) {
204
+ const [currentData, setCurrentData] = React.useState(data);
205
+ const [isDirty, setIsDirty] = React.useState(false);
206
+
207
+ // Register methods on mount
208
+ React.useEffect(() => {
209
+ if (callbacks?.RegisterMethod) {
210
+ // Register standard methods
211
+ callbacks.RegisterMethod('getCurrentDataState', () => {
212
+ return currentData;
213
+ });
214
+
215
+ callbacks.RegisterMethod('isDirty', () => {
216
+ return isDirty;
217
+ });
218
+
219
+ callbacks.RegisterMethod('reset', () => {
220
+ setCurrentData(data);
221
+ setIsDirty(false);
222
+ });
223
+
224
+ callbacks.RegisterMethod('validate', () => {
225
+ // Custom validation logic
226
+ if (!currentData.name) {
227
+ return { valid: false, errors: ['Name is required'] };
228
+ }
229
+ return true;
230
+ });
231
+
232
+ // Register custom methods
233
+ callbacks.RegisterMethod('exportToCSV', () => {
234
+ // Custom export logic
235
+ return convertToCSV(currentData);
236
+ });
237
+ }
238
+ }, [callbacks, currentData, isDirty]);
239
+
240
+ return (
241
+ <div>
242
+ {/* Component UI */}
243
+ </div>
244
+ );
245
+ }
246
+ ```
247
+
248
+ ### Standard Methods
249
+
250
+ The ComponentObject interface defines standard methods that components can optionally implement:
251
+
252
+ - **`getCurrentDataState()`**: Returns the current data being displayed
253
+ - **`getDataStateHistory()`**: Returns an array of timestamped state changes
254
+ - **`validate()`**: Validates the component state
255
+ - **`isDirty()`**: Checks if there are unsaved changes
256
+ - **`reset()`**: Resets the component to initial state
257
+ - **`scrollTo(target)`**: Scrolls to a specific element
258
+ - **`focus(target)`**: Sets focus to an element
259
+ - **`print()`**: Prints the component content
260
+ - **`refresh()`**: Refreshes the component data
261
+
262
+ ### Using Component Methods
263
+
264
+ After compilation, the ComponentObject provides typed access to standard methods:
265
+
266
+ ```typescript
267
+ // Compile the component
268
+ const result = await compiler.compile({
269
+ componentName: 'MyComponent',
270
+ componentCode: componentCode
271
+ });
272
+
273
+ // Get the component object
274
+ const componentObject = result.component.component(context);
275
+
276
+ // Call standard methods directly (type-safe)
277
+ const currentData = componentObject.getCurrentDataState();
278
+ const isDirty = componentObject.isDirty();
279
+ const validationResult = componentObject.validate();
280
+
281
+ if (isDirty) {
282
+ componentObject.reset();
283
+ }
284
+
285
+ // Call custom methods via invokeMethod
286
+ if (componentObject.hasMethod('exportToCSV')) {
287
+ const csvData = componentObject.invokeMethod('exportToCSV');
288
+ }
289
+ ```
290
+
291
+ ### Method Availability
292
+
293
+ All methods are optional. The runtime provides sensible defaults when methods aren't registered:
294
+
295
+ - `getCurrentDataState()` returns `undefined`
296
+ - `getDataStateHistory()` returns `[]`
297
+ - `isDirty()` returns `false`
298
+ - `validate()` returns `true`
299
+ - Other methods perform no operation if not implemented
300
+
301
+ ### Integration with Angular
302
+
303
+ The Angular wrapper (`@memberjunction/ng-react`) provides strongly-typed access to all standard methods:
304
+
305
+ ```typescript
306
+ export class MyDashboard {
307
+ @ViewChild(MJReactComponent) reactComponent!: MJReactComponent;
308
+
309
+ checkComponentState() {
310
+ // Standard methods have full TypeScript support
311
+ if (this.reactComponent.isDirty()) {
312
+ const data = this.reactComponent.getCurrentDataState();
313
+ console.log('Component has unsaved changes:', data);
314
+ }
315
+
316
+ // Validate before saving
317
+ const validation = this.reactComponent.validate();
318
+ if (validation === true || validation.valid) {
319
+ // Save data...
320
+ }
321
+
322
+ // Custom methods
323
+ if (this.reactComponent.hasMethod('generateReport')) {
324
+ const report = this.reactComponent.invokeMethod('generateReport', options);
325
+ }
326
+ }
327
+ }
328
+ ```
329
+
330
+ ### Method Declaration in Component Spec
331
+
332
+ Components can declare their supported methods in the ComponentSpec for discovery:
333
+
334
+ ```typescript
335
+ const componentSpec = {
336
+ name: 'MyComponent',
337
+ code: '...',
338
+ methods: [
339
+ {
340
+ name: 'getCurrentDataState',
341
+ category: 'standard',
342
+ description: 'Returns current component data',
343
+ returnType: 'DataState | undefined'
344
+ },
345
+ {
346
+ name: 'exportToExcel',
347
+ category: 'custom',
348
+ description: 'Exports data to Excel format',
349
+ parameters: [{
350
+ name: 'options',
351
+ type: '{includeHeaders?: boolean, sheetName?: string}',
352
+ required: false
353
+ }],
354
+ returnType: 'Promise<Blob>'
355
+ }
356
+ ]
357
+ };
358
+ ```
359
+
182
360
  ## Advanced Features
183
361
 
184
362
  ### Component Hierarchies
@@ -1 +1 @@
1
- {"version":3,"file":"component-compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,cAAc,EAEd,iBAAiB,EACjB,cAAc,EAGf,MAAM,UAAU,CAAC;AAsBlB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,gBAAgB,CAAW;IACnC,OAAO,CAAC,aAAa,CAAM;gBAMf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAS5C,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAS5B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAyElE,OAAO,CAAC,kBAAkB;IAkC1B,OAAO,CAAC,iBAAiB;YAmDX,qBAAqB;YAwGrB,UAAU;IA+BxB,OAAO,CAAC,UAAU;IAmElB,OAAO,CAAC,sBAAsB;IA0E9B,OAAO,CAAC,sBAAsB;IAiE9B,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,sBAAsB;IAa9B,UAAU,IAAI,IAAI;IAQlB,YAAY,IAAI,MAAM;IAQtB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;CAGpD"}
1
+ {"version":3,"file":"component-compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,cAAc,EAEd,iBAAiB,EACjB,cAAc,EAGf,MAAM,UAAU,CAAC;AAyBlB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,gBAAgB,CAAW;IACnC,OAAO,CAAC,aAAa,CAAM;gBAMf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAS5C,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAS5B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAyElE,OAAO,CAAC,kBAAkB;IAkC1B,OAAO,CAAC,iBAAiB;YA6KX,qBAAqB;YA2HrB,UAAU;IA+BxB,OAAO,CAAC,UAAU;IAyElB,OAAO,CAAC,sBAAsB;IA0E9B,OAAO,CAAC,sBAAsB;IAiE9B,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,sBAAsB;IAa9B,UAAU,IAAI,IAAI;IAQlB,YAAY,IAAI,MAAM;IAQtB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;CAGpD"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentCompiler = void 0;
4
4
  const library_registry_1 = require("../utilities/library-registry");
5
+ const library_loader_1 = require("../utilities/library-loader");
5
6
  const DEFAULT_COMPILER_CONFIG = {
6
7
  babel: {
7
8
  presets: ['react'],
@@ -10,7 +11,8 @@ const DEFAULT_COMPILER_CONFIG = {
10
11
  minify: false,
11
12
  sourceMaps: false,
12
13
  cache: true,
13
- maxCacheSize: 100
14
+ maxCacheSize: 100,
15
+ debug: false
14
16
  };
15
17
  class ComponentCompiler {
16
18
  constructor(config) {
@@ -38,7 +40,7 @@ class ComponentCompiler {
38
40
  const transpiledCode = this.transpileComponent(options.componentCode, options.componentName, options);
39
41
  const componentFactory = this.createComponentFactory(transpiledCode, options.componentName, loadedLibraries);
40
42
  const compiledComponent = {
41
- component: componentFactory,
43
+ factory: componentFactory,
42
44
  id: this.generateComponentId(options.componentName),
43
45
  name: options.componentName,
44
46
  compiledAt: new Date(),
@@ -99,6 +101,7 @@ class ComponentCompiler {
99
101
  useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer, useLayoutEffect,
100
102
  libraries, styles, console, components
101
103
  ) {
104
+ // Parse the component code once to get the component definition
102
105
  ${libraryDeclarations ? libraryDeclarations + '\n ' : ''}${componentDeclarations ? componentDeclarations + '\n ' : ''}${componentCode}
103
106
 
104
107
  // Ensure the component exists
@@ -106,16 +109,137 @@ class ComponentCompiler {
106
109
  throw new Error('Component "${componentName}" is not defined in the provided code');
107
110
  }
108
111
 
109
- // Return the component with utilities
112
+ // Store the component in a variable so we don't lose it
113
+ const UserComponent = ${componentName};
114
+
115
+ // Debug logging to understand what we're getting
116
+ console.log('Component ${componentName} type:', typeof UserComponent);
117
+ if (typeof UserComponent === 'object' && UserComponent !== null) {
118
+ console.log('Component ${componentName} keys:', Object.keys(UserComponent));
119
+ console.log('Component ${componentName} has .component:', 'component' in UserComponent);
120
+ if ('component' in UserComponent) {
121
+ console.log('Component ${componentName}.component type:', typeof UserComponent.component);
122
+ }
123
+ }
124
+
125
+ // Check if the component is already a ComponentObject (has a .component property)
126
+ // If so, extract the actual React component
127
+ const ActualComponent = (typeof UserComponent === 'object' && UserComponent !== null && 'component' in UserComponent)
128
+ ? UserComponent.component
129
+ : UserComponent;
130
+
131
+ // Validate that we have a function (React component)
132
+ if (typeof ActualComponent !== 'function') {
133
+ console.error('Invalid component type for ${componentName}:', typeof ActualComponent);
134
+ console.error('ActualComponent value:', ActualComponent);
135
+ console.error('Original UserComponent value:', UserComponent);
136
+ throw new Error('Component "${componentName}" must be a function (React component) or an object with a .component property that is a function. Got: ' + typeof ActualComponent);
137
+ }
138
+
139
+ // Create a fresh method registry for each factory call
140
+ const methodRegistry = new Map();
141
+
142
+ // Create a wrapper component that provides RegisterMethod in callbacks
143
+ const ComponentWithMethodRegistry = React.forwardRef((props, ref) => {
144
+ // Register methods on mount
145
+ React.useEffect(() => {
146
+ // Clear previous methods
147
+ methodRegistry.clear();
148
+
149
+ // Provide RegisterMethod callback if callbacks exist
150
+ if (props.callbacks && typeof props.callbacks.RegisterMethod === 'function') {
151
+ // Component can now register its methods
152
+ // This will be called from within the component
153
+ }
154
+ }, [props.callbacks]);
155
+
156
+ // Create enhanced callbacks with RegisterMethod
157
+ const enhancedCallbacks = React.useMemo(() => {
158
+ if (!props.callbacks) return {};
159
+
160
+ return {
161
+ ...props.callbacks,
162
+ RegisterMethod: (methodName, handler) => {
163
+ if (methodName && handler) {
164
+ methodRegistry.set(methodName, handler);
165
+ }
166
+ }
167
+ };
168
+ }, [props.callbacks]);
169
+
170
+ // Render the original component with enhanced callbacks
171
+ return React.createElement(ActualComponent, {
172
+ ...props,
173
+ callbacks: enhancedCallbacks
174
+ });
175
+ });
176
+
177
+ ComponentWithMethodRegistry.displayName = '${componentName}WithMethods';
178
+
179
+ // Return the component object with method access
110
180
  return {
111
- component: ${componentName},
181
+ component: ComponentWithMethodRegistry,
182
+
183
+ // Legacy methods for backward compatibility
112
184
  print: function() {
113
- if (typeof window !== 'undefined' && window.print) {
185
+ const printMethod = methodRegistry.get('print');
186
+ if (printMethod) {
187
+ printMethod();
188
+ } else if (typeof window !== 'undefined' && window.print) {
114
189
  window.print();
115
190
  }
116
191
  },
117
192
  refresh: function(data) {
193
+ const refreshMethod = methodRegistry.get('refresh');
194
+ if (refreshMethod) {
195
+ refreshMethod(data);
196
+ }
118
197
  // Refresh functionality is handled by the host environment
198
+ },
199
+
200
+ // Standard method accessors with type safety
201
+ getCurrentDataState: function() {
202
+ const method = methodRegistry.get('getCurrentDataState');
203
+ return method ? method() : undefined;
204
+ },
205
+ getDataStateHistory: function() {
206
+ const method = methodRegistry.get('getDataStateHistory');
207
+ return method ? method() : [];
208
+ },
209
+ validate: function() {
210
+ const method = methodRegistry.get('validate');
211
+ return method ? method() : true;
212
+ },
213
+ isDirty: function() {
214
+ const method = methodRegistry.get('isDirty');
215
+ return method ? method() : false;
216
+ },
217
+ reset: function() {
218
+ const method = methodRegistry.get('reset');
219
+ if (method) method();
220
+ },
221
+ scrollTo: function(target) {
222
+ const method = methodRegistry.get('scrollTo');
223
+ if (method) method(target);
224
+ },
225
+ focus: function(target) {
226
+ const method = methodRegistry.get('focus');
227
+ if (method) method(target);
228
+ },
229
+
230
+ // Generic method invoker for custom methods
231
+ invokeMethod: function(methodName, ...args) {
232
+ const method = methodRegistry.get(methodName);
233
+ if (method) {
234
+ return method(...args);
235
+ }
236
+ console.warn(\`Method '\${methodName}' is not registered on component ${componentName}\`);
237
+ return undefined;
238
+ },
239
+
240
+ // Check if a method exists
241
+ hasMethod: function(methodName) {
242
+ return methodRegistry.has(methodName);
119
243
  }
120
244
  };
121
245
  }
@@ -123,12 +247,16 @@ class ComponentCompiler {
123
247
  }
124
248
  async loadRequiredLibraries(libraries, componentLibraries) {
125
249
  const loadedLibraries = new Map();
126
- console.log('🔍 loadRequiredLibraries called with:', {
127
- librariesCount: libraries?.length || 0,
128
- libraries: libraries?.map(l => ({ name: l.name, version: l.version, globalVariable: l.globalVariable }))
129
- });
250
+ if (this.config.debug) {
251
+ console.log('🔍 loadRequiredLibraries called with:', {
252
+ librariesCount: libraries?.length || 0,
253
+ libraries: libraries?.map(l => ({ name: l.name, version: l.version, globalVariable: l.globalVariable }))
254
+ });
255
+ }
130
256
  if (!libraries || libraries.length === 0) {
131
- console.log('📚 No libraries to load, returning empty map');
257
+ if (this.config.debug) {
258
+ console.log('📚 No libraries to load, returning empty map');
259
+ }
132
260
  return loadedLibraries;
133
261
  }
134
262
  if (typeof window === 'undefined') {
@@ -141,53 +269,69 @@ class ComponentCompiler {
141
269
  else {
142
270
  console.warn('âš ī¸ No componentLibraries provided for LibraryRegistry initialization');
143
271
  }
144
- const loadPromises = libraries.map(async (lib) => {
145
- console.log(`đŸ“Ļ Processing library: ${lib.name}`);
146
- const isApproved = library_registry_1.LibraryRegistry.isApproved(lib.name);
147
- console.log(` ✓ Approved check for ${lib.name}: ${isApproved}`);
148
- if (!isApproved) {
149
- console.error(` ❌ Library '${lib.name}' is not approved`);
150
- throw new Error(`Library '${lib.name}' is not approved. Only approved libraries can be used.`);
151
- }
152
- const libraryDef = library_registry_1.LibraryRegistry.getLibrary(lib.name);
153
- console.log(` ✓ Library definition found for ${lib.name}: ${!!libraryDef}`);
154
- if (!libraryDef) {
155
- console.error(` ❌ Library '${lib.name}' not found in registry`);
156
- throw new Error(`Library '${lib.name}' not found in registry`);
157
- }
158
- const resolvedVersion = library_registry_1.LibraryRegistry.resolveVersion(lib.name, lib.version);
159
- console.log(` ✓ Resolved version for ${lib.name}: ${resolvedVersion}`);
160
- const cdnUrl = library_registry_1.LibraryRegistry.getCdnUrl(lib.name, resolvedVersion);
161
- console.log(` ✓ CDN URL for ${lib.name}: ${cdnUrl}`);
162
- if (!cdnUrl) {
163
- console.error(` ❌ No CDN URL found for library '${lib.name}' version '${lib.version || 'default'}'`);
164
- throw new Error(`No CDN URL found for library '${lib.name}' version '${lib.version || 'default'}'`);
165
- }
166
- if (window[lib.globalVariable]) {
167
- console.log(` â„šī¸ Library ${lib.name} already loaded globally as ${lib.globalVariable}`);
168
- loadedLibraries.set(lib.globalVariable, window[lib.globalVariable]);
169
- return;
170
- }
171
- const versionInfo = libraryDef.versions[resolvedVersion || libraryDef.defaultVersion];
172
- if (versionInfo?.cssUrls) {
173
- await this.loadStyles(versionInfo.cssUrls);
272
+ const libraryNames = libraries.map(lib => lib.name);
273
+ if (this.config.debug) {
274
+ console.log('đŸ“Ļ Using dependency-aware loading for libraries:', libraryNames);
275
+ }
276
+ try {
277
+ const loadedLibraryMap = await library_loader_1.LibraryLoader.loadLibrariesWithDependencies(libraryNames, componentLibraries, 'component-compiler', { debug: this.config.debug });
278
+ for (const lib of libraries) {
279
+ const isApproved = library_registry_1.LibraryRegistry.isApproved(lib.name);
280
+ if (!isApproved) {
281
+ console.error(`❌ Library '${lib.name}' is not approved`);
282
+ throw new Error(`Library '${lib.name}' is not approved. Only approved libraries can be used.`);
283
+ }
284
+ const loadedValue = loadedLibraryMap.get(lib.name);
285
+ if (loadedValue) {
286
+ loadedLibraries.set(lib.globalVariable, loadedValue);
287
+ if (this.config.debug) {
288
+ console.log(`✅ Mapped ${lib.name} to global variable ${lib.globalVariable}`);
289
+ }
290
+ }
291
+ else {
292
+ const globalValue = window[lib.globalVariable];
293
+ if (globalValue) {
294
+ loadedLibraries.set(lib.globalVariable, globalValue);
295
+ if (this.config.debug) {
296
+ console.log(`✅ Found ${lib.name} already loaded as ${lib.globalVariable}`);
297
+ }
298
+ }
299
+ else {
300
+ console.error(`❌ Library '${lib.name}' failed to load`);
301
+ throw new Error(`Library '${lib.name}' failed to load or did not expose '${lib.globalVariable}'`);
302
+ }
303
+ }
174
304
  }
175
- console.log(` đŸ“Ĩ Loading script from CDN for ${lib.name}...`);
176
- await this.loadScript(cdnUrl, lib.globalVariable);
177
- const libraryValue = window[lib.globalVariable];
178
- console.log(` ✓ Library ${lib.name} loaded successfully, global variable ${lib.globalVariable} is:`, typeof libraryValue);
179
- if (libraryValue) {
180
- loadedLibraries.set(lib.globalVariable, libraryValue);
181
- console.log(` ✅ Added ${lib.name} to loaded libraries map`);
305
+ }
306
+ catch (error) {
307
+ console.error('Failed to load libraries with dependencies:', error);
308
+ if (this.config.debug) {
309
+ console.warn('âš ī¸ Falling back to non-dependency-aware loading due to error');
182
310
  }
183
- else {
184
- console.error(` ❌ Library '${lib.name}' failed to expose global variable '${lib.globalVariable}'`);
185
- throw new Error(`Library '${lib.name}' failed to load or did not expose '${lib.globalVariable}'`);
311
+ for (const lib of libraries) {
312
+ if (window[lib.globalVariable]) {
313
+ loadedLibraries.set(lib.globalVariable, window[lib.globalVariable]);
314
+ }
315
+ else {
316
+ const libraryDef = library_registry_1.LibraryRegistry.getLibrary(lib.name);
317
+ if (libraryDef) {
318
+ const resolvedVersion = library_registry_1.LibraryRegistry.resolveVersion(lib.name, lib.version);
319
+ const cdnUrl = library_registry_1.LibraryRegistry.getCdnUrl(lib.name, resolvedVersion);
320
+ if (cdnUrl) {
321
+ await this.loadScript(cdnUrl, lib.globalVariable);
322
+ const libraryValue = window[lib.globalVariable];
323
+ if (libraryValue) {
324
+ loadedLibraries.set(lib.globalVariable, libraryValue);
325
+ }
326
+ }
327
+ }
328
+ }
186
329
  }
187
- });
188
- await Promise.all(loadPromises);
189
- console.log(`✅ All libraries loaded successfully. Total: ${loadedLibraries.size}`);
190
- console.log('📚 Loaded libraries map:', Array.from(loadedLibraries.keys()));
330
+ }
331
+ if (this.config.debug) {
332
+ console.log(`✅ All libraries loaded successfully. Total: ${loadedLibraries.size}`);
333
+ console.log('📚 Loaded libraries map:', Array.from(loadedLibraries.keys()));
334
+ }
191
335
  return loadedLibraries;
192
336
  }
193
337
  async loadStyles(urls) {
@@ -237,12 +381,17 @@ class ComponentCompiler {
237
381
  const checkInterval = 100;
238
382
  const checkGlobal = () => {
239
383
  if (window[globalName]) {
240
- console.log(` ✓ Global variable ${globalName} found after ${attempts * checkInterval}ms`);
384
+ if (this.config.debug) {
385
+ console.log(` ✓ Global variable ${globalName} found after ${attempts * checkInterval}ms`);
386
+ }
241
387
  resolve();
242
388
  }
243
389
  else if (attempts >= maxAttempts) {
244
- console.error(` ❌ ${globalName} not found after ${attempts * checkInterval}ms`);
245
- console.log(` â„šī¸ Window properties:`, Object.keys(window).filter(k => k.toLowerCase().includes(globalName.toLowerCase())));
390
+ if (this.config.debug) {
391
+ console.error(` ❌ ${globalName} not found after ${attempts * checkInterval}ms`);
392
+ const matchingKeys = Object.keys(window).filter(k => k.toLowerCase().includes(globalName.toLowerCase()));
393
+ console.log(` â„šī¸ Matching window properties: ${matchingKeys.join(', ') || 'none'}`);
394
+ }
246
395
  reject(new Error(`${globalName} not found after loading script from ${url}`));
247
396
  }
248
397
  else {