@genesislcap/foundation-layout 14.366.2-alpha-11da8b5.0 → 14.367.1-FUI-2341-3.2

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 (32) hide show
  1. package/dist/custom-elements.json +142 -3
  2. package/dist/dts/index.d.ts +2 -1
  3. package/dist/dts/index.d.ts.map +1 -1
  4. package/dist/dts/main/layout-item.d.ts +20 -0
  5. package/dist/dts/main/layout-item.d.ts.map +1 -1
  6. package/dist/dts/main/layout-main.d.ts +36 -8
  7. package/dist/dts/main/layout-main.d.ts.map +1 -1
  8. package/dist/dts/utils/factory-registry.d.ts +64 -0
  9. package/dist/dts/utils/factory-registry.d.ts.map +1 -0
  10. package/dist/dts/utils/index.d.ts +1 -0
  11. package/dist/dts/utils/index.d.ts.map +1 -1
  12. package/dist/dts/utils/types.d.ts +44 -3
  13. package/dist/dts/utils/types.d.ts.map +1 -1
  14. package/dist/esm/index.js +1 -0
  15. package/dist/esm/main/layout-item.js +26 -4
  16. package/dist/esm/main/layout-main.js +145 -46
  17. package/dist/esm/utils/factory-registry.js +89 -0
  18. package/dist/esm/utils/index.js +1 -0
  19. package/dist/foundation-layout.api.json +206 -9
  20. package/dist/foundation-layout.d.ts +157 -9
  21. package/docs/FRAMEWORK_COMPONENTS.md +568 -0
  22. package/docs/api/foundation-layout.componentfactory.md +46 -0
  23. package/docs/api/foundation-layout.foundationlayout.md +2 -2
  24. package/docs/api/foundation-layout.foundationlayout.registeritem.md +31 -7
  25. package/docs/api/foundation-layout.foundationlayoutitem.md +2 -0
  26. package/docs/api/foundation-layout.foundationlayoutitem.registration.md +18 -0
  27. package/docs/api/foundation-layout.getfactory.md +56 -0
  28. package/docs/api/foundation-layout.md +59 -0
  29. package/docs/api/foundation-layout.registerfactory.md +95 -0
  30. package/docs/api/foundation-layout.unregisterfactory.md +63 -0
  31. package/docs/api-report.md.api.md +20 -7
  32. package/package.json +12 -12
@@ -8,6 +8,45 @@ import { ResolvedLayoutConfig } from '@genesis-community/golden-layout';
8
8
  import { RootItemConfig } from '@genesis-community/golden-layout';
9
9
  import { ViewTemplate } from '@microsoft/fast-element';
10
10
 
11
+ /**
12
+ * @public
13
+ * Factory function for creating component instances in the layout.
14
+ * @remarks
15
+ * This is the recommended approach for framework-rendered components (React, Angular, Vue, etc.)
16
+ * because it allows each layout instance to create a fresh component rather than cloning existing
17
+ * DOM elements (which loses event listeners and framework bindings).
18
+ *
19
+ * The factory function receives a container element and should render the component into it.
20
+ * Optionally, it can return a cleanup function that will be called when the component is removed
21
+ * from the layout.
22
+ *
23
+ * @param container - The HTMLElement container where the component should be rendered
24
+ * @returns Optional cleanup function to be called when the component is removed
25
+ *
26
+ * @example
27
+ * React example:
28
+ * ```typescript
29
+ * layout.registerItem('my-component', (container) => {
30
+ * const root = createRoot(container);
31
+ * root.render(<MyComponent />);
32
+ * return () => root.unmount();
33
+ * });
34
+ * ```
35
+ *
36
+ * @example
37
+ * Angular example:
38
+ * ```typescript
39
+ * layout.registerItem('my-component', (container) => {
40
+ * const componentRef = createComponent(MyComponent, {
41
+ * environmentInjector: this.injector,
42
+ * hostElement: container
43
+ * });
44
+ * return () => componentRef.destroy();
45
+ * });
46
+ * ```
47
+ */
48
+ export declare type ComponentFactory = (container: HTMLElement) => void | (() => void);
49
+
11
50
  /**
12
51
  * Used to key what type of LayoutComponent an object is
13
52
  * @internal
@@ -276,21 +315,48 @@ export declare class FoundationLayout extends FoundationElement implements Layou
276
315
  removeItems(registration: string, force?: boolean): number;
277
316
  /**
278
317
  * @public
279
- * Register a collection of `Element` and associate them with an `ID` with the layout system for later use.
318
+ * Register a collection of `Element` or a factory function and associate them with an `ID` with the layout system for later use.
280
319
  * @remarks
281
- * You would use this to register elements that you later want to load when using {@link FoundationLayout.loadLayout}.
320
+ * You can register either an array of elements or a factory function.
321
+ *
322
+ * **Element registration**: Use this to register elements that you later want to load when using {@link FoundationLayout.loadLayout}.
282
323
  * Use {@link FoundationLayout.layoutRequiredRegistrations} to see what components need to be registered for a certain config
283
324
  * and then register them using this function before calling {@link FoundationLayout.loadLayout}.
325
+ * When registering an element it is moved by reference into the internals of the layout, so if you pass elements already in the DOM then they will disappear.
326
+ * If you want to avoid this you can pass copies using `element.cloneNode(true)`.
284
327
  *
285
- * When registering an element it is moved by reference into the internals of the layout, so if you pass elements already in the DOM then they will disappear. If you want to avoid this you can pass copies using `element.cloneNode(true)`.
328
+ * **Factory registration**: This is the recommended approach for framework-rendered components (React, Angular, Vue, etc.)
329
+ * because it allows each layout instance to create a fresh component rather than cloning existing
330
+ * DOM elements (which loses event listeners and framework bindings).
331
+ * The factory function will be called each time a new instance of the component is needed. It receives
332
+ * a container element and should render the component into it. Optionally, it can return a cleanup
333
+ * function that will be called when the component is removed from the layout.
286
334
  *
287
335
  * @param registration - string of the registration ID
288
- * @param elements - Elements[] containing the reference to the elements to register for later usage
336
+ * @param elementsOrFactory - Either Elements[] containing the reference to the elements to register, or a ComponentFactory function
289
337
  * @throws {@link LayoutUsageError} if you attempt to add an item before the layout has been initialised.
290
338
  * @throws {@link LayoutRegistrationError} if you attempt to use a `registration` name which is already in use (declarative html API and JavaScript API registrations use the same "pool" of registration names).
291
339
  * @returns - string defining the name of the registered item with the layout system (config.id if set).
340
+ *
341
+ * @example
342
+ * Element registration:
343
+ * ```typescript
344
+ * const div = document.createElement('div');
345
+ * div.innerHTML = '<h1>Hello</h1>';
346
+ * layout.registerItem('my-element', [div]);
347
+ * ```
348
+ *
349
+ * @example
350
+ * Factory registration (React):
351
+ * ```typescript
352
+ * layout.registerItem('text-field', (container) => {
353
+ * const root = createRoot(container);
354
+ * root.render(<TextFieldComponent />);
355
+ * return () => root.unmount();
356
+ * });
357
+ * ```
292
358
  */
293
- registerItem(registration: string, elements: Element[]): string;
359
+ registerItem(registration: string, elementsOrFactory: Element[] | ComponentFactory): string;
294
360
  /**
295
361
  * Internal APIs
296
362
  */
@@ -319,12 +385,13 @@ export declare class FoundationLayout extends FoundationElement implements Layou
319
385
  /**
320
386
  * Registers a function with golden layout to create a pane
321
387
  * @param elements - Elements[] to add to new new pane
388
+ * @param factory - ComponentFactory function to create component instances
322
389
  * @param id - optional string which is used to register the new function with golden layout. Defaults to sequentially setting the IDs for default items
323
390
  * @returns - string which is the registered ID
324
391
  * @throws - {@link LayoutRegistrationError} if the id is already in use
325
392
  * @internal
326
393
  */
327
- cacheElementsAndRegister({ elements, id }: RegistrationConfig): string;
394
+ cacheElementsAndRegister(config: RegistrationConfig): string;
328
395
  /**
329
396
  * Sets up the event listeners for the layout receive events
330
397
  * @internal
@@ -443,6 +510,9 @@ export declare class FoundationLayout extends FoundationElement implements Layou
443
510
  * This element is used to wrap html elements and configure their layout settings as part of the layout system.
444
511
  *
445
512
  * This is a simple component which is only used to define the layout splits; any JavaScript API interactions or custom styling is used via {@link FoundationLayout}.
513
+ *
514
+ * The item can either use slotted content or a factory function registered via {@link registerFactory}.
515
+ * When a factory is registered with the same name as the registration attribute, it takes precedence over slotted content.
446
516
  * @tagname %%prefix%%-layout-item
447
517
  */
448
518
  export declare class FoundationLayoutItem extends FoundationElement implements LayoutComponent {
@@ -471,6 +541,23 @@ export declare class FoundationLayout extends FoundationElement implements Layou
471
541
  * Using a duplicate registration name is a runtime error.
472
542
  * This registration name defaults to the number of the window it is.
473
543
  * It is highly recommended if you are using the JavaScript API that you set a registration name here manually.
544
+ *
545
+ * When using the declarative API with framework components, register a factory function via {@link registerFactory}
546
+ * using the same name as this registration attribute.
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * import { registerFactory } from '@genesislcap/foundation-layout';
551
+ * import { reactFactory } from './utils/react-layout-factory';
552
+ *
553
+ * // Register factory with the same name as the registration
554
+ * registerFactory('my-component', reactFactory(MyComponent));
555
+ * ```
556
+ *
557
+ * Then in JSX/HTML:
558
+ * ```tsx
559
+ * <rapid-layout-item registration="my-component" title="My Component" />
560
+ * ```
474
561
  * @public
475
562
  */
476
563
  registration: string;
@@ -539,6 +626,16 @@ export declare class FoundationLayout extends FoundationElement implements Layou
539
626
  cacheElementsAndRegister(config: RegistrationConfig): string;
540
627
  }
541
628
 
629
+ /**
630
+ * Retrieves a factory function by its key.
631
+ *
632
+ * @param key - The unique identifier for the factory.
633
+ * @returns The factory function, or undefined if not found.
634
+ *
635
+ * @public
636
+ */
637
+ export declare function getFactory(key: string): ComponentFactory | undefined;
638
+
542
639
  /**
543
640
  * A collection of SVG icons in base64 format.
544
641
  * @remarks
@@ -764,11 +861,46 @@ export declare class FoundationLayout extends FoundationElement implements Layou
764
861
  showMaximiseButton?: boolean;
765
862
  }
766
863
 
864
+ /**
865
+ * Registers a factory function with a unique key.
866
+ * This allows framework components to be used in the declarative layout API
867
+ * without needing to pass function references through HTML attributes.
868
+ *
869
+ * @param key - Unique identifier for the factory. Should be descriptive and unique across the application.
870
+ * @param factory - The factory function that creates the component.
871
+ * @throws {Error} If a factory with the same key is already registered.
872
+ *
873
+ * @example
874
+ * ```typescript
875
+ * // React example
876
+ * import { registerFactory } from '@genesislcap/foundation-layout';
877
+ * import { reactFactory } from './utils/react-layout-factory';
878
+ * import { MyComponent } from './components/MyComponent';
879
+ *
880
+ * registerFactory('my-component', reactFactory(MyComponent, { someProp: 'value' }));
881
+ * ```
882
+ *
883
+ * Then in your JSX:
884
+ * ```tsx
885
+ * <rapid-layout-item
886
+ * registration="my-item"
887
+ * title="My Component"
888
+ * factory-key="my-component"
889
+ * />
890
+ * ```
891
+ *
892
+ * @public
893
+ */
894
+ export declare function registerFactory(key: string, factory: ComponentFactory): void;
895
+
767
896
  /** @internal */
768
- export declare interface RegistrationConfig {
769
- elements: Element[];
897
+ export declare type RegistrationConfig = {
770
898
  id?: string;
771
- }
899
+ } & ({
900
+ elements: Element[];
901
+ } | {
902
+ factory: ComponentFactory;
903
+ });
772
904
 
773
905
  /**
774
906
  * @public
@@ -786,4 +918,20 @@ export declare class FoundationLayout extends FoundationElement implements Layou
786
918
  c: ResolvedLayoutConfig;
787
919
  };
788
920
 
921
+ /**
922
+ * Removes a factory from the registry.
923
+ * This is useful for cleanup when a component is unmounted or no longer needed.
924
+ *
925
+ * @param key - The unique identifier for the factory to remove.
926
+ * @returns True if the factory was found and removed, false otherwise.
927
+ *
928
+ * @example
929
+ * ```typescript
930
+ * unregisterFactory('my-component');
931
+ * ```
932
+ *
933
+ * @public
934
+ */
935
+ export declare function unregisterFactory(key: string): boolean;
936
+
789
937
  export { }