-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
528 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,64 @@ | ||
import type {ComponentRegistry as ComponentRegistryInterface} from './types'; | ||
import type { | ||
ComponentDefinition, | ||
ComponentDefinitionParams, | ||
ComponentDictionary, | ||
ComponentRegistry as ComponentRegistryInterface | ||
} from './types'; | ||
|
||
// import {XP_COMPONENT_TYPE} from './constants'; | ||
|
||
export class ComponentRegistry implements ComponentRegistryInterface { | ||
|
||
// private pages: ComponentDictionary = {}; | ||
// private parts: ComponentDictionary = {}; | ||
// private layouts: ComponentDictionary = {}; | ||
private _macros: {[macroName: string]: React.FunctionComponent<any>} = {}; | ||
private _pages: ComponentDictionary = {}; | ||
private _parts: ComponentDictionary = {}; | ||
private _layouts: ComponentDictionary = {}; | ||
private _macros: ComponentDictionary = {}; | ||
|
||
public addMacro<PROPS = {}>(name: string, component: React.FunctionComponent<PROPS>): React.FunctionComponent<PROPS> { | ||
this._macros[name] = component; | ||
return this._macros[name]; | ||
public addMacro<PROPS = {}>(name: string, obj: ComponentDefinitionParams<PROPS>): void { | ||
this._macros[name] = obj as ComponentDefinition<{}>; | ||
} | ||
|
||
// public addLayout(name: string, obj: ComponentDefinitionParams): void { | ||
// return ComponentRegistry.addType('layout', name, obj); | ||
// } | ||
public addLayout<PROPS = {}>(name: string, obj: ComponentDefinitionParams<PROPS>): void { | ||
this._layouts[name] = obj as ComponentDefinition<{}>; | ||
} | ||
|
||
// public addPage(name: string, obj: ComponentDefinitionParams): void { | ||
// return ComponentRegistry.addType('page', name, obj); | ||
// } | ||
public addPage<PROPS = {}>(name: string, obj: ComponentDefinitionParams<PROPS>): void { | ||
this._pages[name] = obj as ComponentDefinition<{}>; | ||
} | ||
|
||
// public addPart(name: string, obj: ComponentDefinitionParams): void { | ||
// return ComponentRegistry.addType('part', name, obj); | ||
// } | ||
public addPart<PROPS = {}>(name: string, obj: ComponentDefinitionParams<PROPS>): void { | ||
this._parts[name] = obj as ComponentDefinition<{}>; | ||
} | ||
|
||
public getMacro<PROPS = {}>(name: string): React.FunctionComponent<PROPS> | undefined { | ||
return this._macros[name]; | ||
public getLayout<PROPS = {}>(name: string): ComponentDefinition<PROPS> | undefined { | ||
return this._layouts[name] as ComponentDefinition<PROPS>; | ||
} | ||
|
||
// public getPage(name: string): ComponentDefinition | undefined { | ||
// return ComponentRegistry.getType('page', name); | ||
// } | ||
public getMacro<PROPS = {}>(name: string): ComponentDefinition<PROPS> | undefined { | ||
return this._macros[name] as ComponentDefinition<PROPS>; | ||
} | ||
|
||
// public getPart(name: string): ComponentDefinition | undefined { | ||
// return ComponentRegistry.getType('part', name); | ||
// } | ||
public getPage<PROPS = {}>(name: string): ComponentDefinition<PROPS> | undefined { | ||
return this._pages[name] as ComponentDefinition<PROPS>; | ||
} | ||
|
||
// public getLayout(name: string): ComponentDefinition | undefined { | ||
// return ComponentRegistry.getType('layout', name); | ||
// } | ||
public getPart<PROPS = {}>(name: string): ComponentDefinition<PROPS> | undefined { | ||
return this._parts[name] as ComponentDefinition<PROPS>; | ||
} | ||
|
||
public hasMacro(name: string): boolean { | ||
return this._macros[name] !== undefined; | ||
} | ||
|
||
public hasLayout(name: string): boolean { | ||
return this._layouts[name] !== undefined; | ||
} | ||
|
||
public hasPage(name: string): boolean { | ||
return this._pages[name] !== undefined; | ||
} | ||
|
||
public hasPart(name: string): boolean { | ||
return this._parts[name] !== undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type {PartComponent} from '@enonic-types/core'; | ||
|
||
import type {ComponentRegistry} from '../types'; | ||
|
||
|
||
export function BasePart({ | ||
component, | ||
componentRegistry | ||
}: { | ||
component: PartComponent | ||
componentRegistry: ComponentRegistry | ||
}) { | ||
// console.debug('BasePart component', component); | ||
|
||
const { | ||
config: props, | ||
descriptor | ||
} = component; | ||
// console.debug('BasePart descriptor', descriptor); | ||
|
||
const partDefinition = componentRegistry.getPart(descriptor); | ||
if (!partDefinition) { | ||
throw new Error(`Part definition not found for descriptor: ${descriptor}`); | ||
// TODO return ErrorBoundary instead of throwing. | ||
} | ||
const {View} = partDefinition; | ||
if (!View) { | ||
throw new Error(`Part view not found for descriptor: ${descriptor}`); | ||
// TODO return ErrorBoundary instead of throwing. | ||
} | ||
props.componentRegistry = componentRegistry; | ||
return (<View {...props}/>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.