@@ -6,16 +6,24 @@ import { TabsLayout } from '../layouts/TabsLayout';
66import { LayoutProps } from '../layouts/LayoutProps' ;
77import { LabelInstanceTableLayout } from '../layouts/LabelInstanceTableLayout' ;
88import { SingleItemLayout } from '../layouts/SingleItemLayout' ;
9+ import { wrapComponent } from './componentWrapper' ;
10+
11+ export interface RegistryConfig {
12+ componentWrapper ?: React . ComponentType ;
13+ }
914
1015class Registry {
11- name : string ;
12- _usedNames : string [ ] = [ ] ;
16+ private readonly config ?: RegistryConfig ;
17+ private readonly usedNames : string [ ] = [ ] ;
18+ private readonly demoEntries : DemoEntry [ ] = [ ] ;
1319
14- _demoEntries : DemoEntry [ ] = [ ] ;
15- _currentDemo ?: DemoEntry ;
20+ private currentDemo ?: DemoEntry ;
1621
17- constructor ( name : string ) {
22+ readonly name : string ;
23+
24+ constructor ( name : string , config ?: RegistryConfig ) {
1825 this . name = name ;
26+ this . config = config ;
1927 }
2028
2129 registerAsGrid ( name : string , minWidth : number , componentRegistrator : ( registry : Registry ) => void ) {
@@ -49,27 +57,27 @@ class Registry {
4957 urlPrefix : string = '' ,
5058 layoutOpts : object = { } ) {
5159
52- if ( this . _usedNames . indexOf ( name ) !== - 1 ) {
60+ if ( this . usedNames . indexOf ( name ) !== - 1 ) {
5361 throw new Error ( `name ${ name } was already used` ) ;
5462 }
5563
56- this . _currentDemo = new DemoEntry ( name , layoutComponent , urlPrefix , layoutOpts ) ;
57- this . _demoEntries . push ( this . _currentDemo ) ;
64+ this . currentDemo = new DemoEntry ( name , layoutComponent , urlPrefix , layoutOpts ) ;
65+ this . demoEntries . push ( this . currentDemo ) ;
5866
59- this . _usedNames . push ( name ) ;
67+ this . usedNames . push ( name ) ;
6068
6169 componentRegistrator ( this ) ;
6270
6371 return this ;
6472 }
6573
6674 get names ( ) : string [ ] {
67- return this . _usedNames ;
75+ return this . usedNames ;
6876 }
6977
7078 description ( markdown : string ) {
71- if ( this . _currentDemo ) {
72- this . _currentDemo . description ( markdown ) ;
79+ if ( this . currentDemo ) {
80+ this . currentDemo . description ( markdown ) ;
7381 } else {
7482 throw new Error ( 'call register method prior setting the description' ) ;
7583 }
@@ -78,8 +86,12 @@ class Registry {
7886 }
7987
8088 add ( title : string , component : React . ComponentType , description : string = '' ) {
81- if ( this . _currentDemo ) {
82- this . _currentDemo . add ( title , description , component ) ;
89+ const componentToRegister = this . config && this . config . componentWrapper ?
90+ wrapComponent ( this . config . componentWrapper , component ) :
91+ component ;
92+
93+ if ( this . currentDemo ) {
94+ this . currentDemo . add ( title , description , componentToRegister ) ;
8395 } else {
8496 throw new Error ( 'call register method prior adding elements' ) ;
8597 }
@@ -88,14 +100,14 @@ class Registry {
88100 }
89101
90102 firstMiniAppByUrl ( url : string ) : DemoEntry | null {
91- const byUrl = this . _demoEntries
103+ const byUrl = this . demoEntries
92104 . filter ( entry => entry . isMiniApp ( ) && url . startsWith ( entry . urlPrefix ) ) ;
93105
94106 return byUrl . length > 0 ? byUrl [ 0 ] : null ;
95107 }
96108
97109 findByName ( name : string ) : DemoEntry | null {
98- const byName = this . _demoEntries
110+ const byName = this . demoEntries
99111 . filter ( entry => entry . name === name ) ;
100112
101113 if ( byName . length === 0 ) {
0 commit comments