piral-core 0.15.0-alpha.4122 → 0.15.0-alpha.4284
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/esm/components/ExtensionSlot.js +12 -4
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/types/api.d.ts +16 -3
- package/esm/types/extension.d.ts +19 -0
- package/esm/types/state.d.ts +18 -0
- package/lib/components/ExtensionSlot.js +12 -4
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/types/api.d.ts +16 -3
- package/lib/types/extension.d.ts +19 -0
- package/lib/types/state.d.ts +18 -0
- package/package.json +8 -8
- package/src/components/ExtensionSlot.test.tsx +32 -1
- package/src/components/ExtensionSlot.tsx +33 -16
- package/src/types/api.ts +21 -3
- package/src/types/extension.ts +19 -0
- package/src/types/state.ts +18 -0
|
@@ -17,21 +17,29 @@ const renderExtensions = [
|
|
|
17
17
|
defaults: {},
|
|
18
18
|
pilet: '',
|
|
19
19
|
reference: {
|
|
20
|
-
displayName: '
|
|
20
|
+
displayName: 'AnyComponent',
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
|
+
function defaultOrder(extensions) {
|
|
25
|
+
return extensions;
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
28
|
* The extension slot component to be used when the available
|
|
26
29
|
* extensions of a given name should be rendered at a specific
|
|
27
30
|
* location.
|
|
28
31
|
*/
|
|
29
32
|
export function ExtensionSlot(props) {
|
|
30
|
-
const { name, render = defaultRender, empty, params, children } = props;
|
|
33
|
+
const { name, render = defaultRender, empty, params, children, emptySkipsRender = false, order = defaultOrder, } = props;
|
|
31
34
|
const extensions = useGlobalState((s) => (name ? s.registry.extensions[name] || none : renderExtensions));
|
|
32
|
-
|
|
35
|
+
const isEmpty = extensions.length === 0 && isfunc(empty);
|
|
36
|
+
const content = isEmpty
|
|
33
37
|
? [defaultRender(empty(), 'empty')]
|
|
34
|
-
: extensions.map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, children: children, params: Object.assign(Object.assign({}, defaults),
|
|
38
|
+
: order(extensions).map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, children: children, params: Object.assign(Object.assign({}, defaults), params) })));
|
|
39
|
+
if (isEmpty && emptySkipsRender) {
|
|
40
|
+
return content[0];
|
|
41
|
+
}
|
|
42
|
+
return render(content);
|
|
35
43
|
}
|
|
36
44
|
ExtensionSlot.displayName = `ExtensionSlot`;
|
|
37
45
|
//# sourceMappingURL=ExtensionSlot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAE1D,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YAChD,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H,CAAC,CAAC;IAEP,IAAI,OAAO,IAAI,gBAAgB,EAAE;QAC/B,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
|
package/esm/types/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
3
|
import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
|
|
4
4
|
import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
|
|
@@ -33,6 +33,10 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
33
33
|
* The provided parameters for showing the extension.
|
|
34
34
|
*/
|
|
35
35
|
params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
|
|
36
|
+
/**
|
|
37
|
+
* The optional children to receive, if any.
|
|
38
|
+
*/
|
|
39
|
+
children?: ReactNode;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* The meta data registered for a page.
|
|
@@ -53,6 +57,15 @@ export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T,
|
|
|
53
57
|
*/
|
|
54
58
|
meta: PiralPageMeta;
|
|
55
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The meta data registered for a page.
|
|
62
|
+
*/
|
|
63
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Shorthand for the definition of an extension component.
|
|
67
|
+
*/
|
|
68
|
+
export declare type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap ? AnyComponent<ExtensionComponentProps<TName>> : TName extends string ? AnyComponent<ExtensionComponentProps<any>> : AnyComponent<ExtensionComponentProps<TName>>;
|
|
56
69
|
/**
|
|
57
70
|
* Defines the Pilet API from piral-core.
|
|
58
71
|
* This interface will be consumed by pilet developers so that their pilet can interact with the piral instance.
|
|
@@ -93,14 +106,14 @@ export interface PiletCoreApi {
|
|
|
93
106
|
* @param Component The component to be rendered.
|
|
94
107
|
* @param defaults Optionally, sets the default values for the expected data.
|
|
95
108
|
*/
|
|
96
|
-
registerExtension<TName>(name: TName extends string ? TName : string, Component:
|
|
109
|
+
registerExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>, defaults?: Partial<ExtensionParams<TName>>): RegistrationDisposer;
|
|
97
110
|
/**
|
|
98
111
|
* Unregisters a global extension component.
|
|
99
112
|
* Only previously registered extension components can be unregistered.
|
|
100
113
|
* @param name The name of the extension slot to unregister from.
|
|
101
114
|
* @param Component The registered extension component to unregister.
|
|
102
115
|
*/
|
|
103
|
-
unregisterExtension<TName>(name: TName extends string ? TName : string, Component:
|
|
116
|
+
unregisterExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>): void;
|
|
104
117
|
/**
|
|
105
118
|
* React component for displaying extensions for a given name.
|
|
106
119
|
* @param props The extension's rendering props.
|
package/esm/types/extension.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { PiralCustomExtensionSlotMap } from './custom';
|
|
3
|
+
import type { ExtensionRegistration } from './state';
|
|
3
4
|
/**
|
|
4
5
|
* The mapping of the existing (known) extension slots.
|
|
5
6
|
*/
|
|
@@ -18,9 +19,27 @@ export interface BaseExtensionSlotProps<TName, TParams> {
|
|
|
18
19
|
* for the specified extension.
|
|
19
20
|
*/
|
|
20
21
|
empty?(): ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Determines if the `render` function should be called in case no
|
|
24
|
+
* components are available for the specified extension.
|
|
25
|
+
*
|
|
26
|
+
* If true, `empty` will be called and returned from the slot.
|
|
27
|
+
* If false, `render` will be called with the result of calling `empty`.
|
|
28
|
+
* The result of calling `render` will then be returned from the slot.
|
|
29
|
+
*/
|
|
30
|
+
emptySkipsRender?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Defines the order of the components to render.
|
|
33
|
+
* May be more convient than using `render` w.r.t. ordering extensions
|
|
34
|
+
* by their supplied metadata.
|
|
35
|
+
* @param extensions The registered extensions.
|
|
36
|
+
* @returns The ordered extensions.
|
|
37
|
+
*/
|
|
38
|
+
order?(extensions: Array<ExtensionRegistration>): Array<ExtensionRegistration>;
|
|
21
39
|
/**
|
|
22
40
|
* Defines how the provided nodes should be rendered.
|
|
23
41
|
* @param nodes The rendered extension nodes.
|
|
42
|
+
* @returns The rendered nodes, i.e., an ReactElement.
|
|
24
43
|
*/
|
|
25
44
|
render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
|
|
26
45
|
/**
|
package/esm/types/state.d.ts
CHANGED
|
@@ -21,21 +21,39 @@ export declare type WrappedComponent<TProps> = ComponentType<PropsWithChildren<W
|
|
|
21
21
|
* The base type for pilet component registration in the global state context.
|
|
22
22
|
*/
|
|
23
23
|
export interface BaseRegistration {
|
|
24
|
+
/**
|
|
25
|
+
* The pilet registering the component.
|
|
26
|
+
*/
|
|
24
27
|
pilet: string;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* The interface modeling the registration of a pilet page component.
|
|
28
31
|
*/
|
|
29
32
|
export interface PageRegistration extends BaseRegistration {
|
|
33
|
+
/**
|
|
34
|
+
* The registered page component.
|
|
35
|
+
*/
|
|
30
36
|
component: WrappedComponent<PageComponentProps>;
|
|
37
|
+
/**
|
|
38
|
+
* The page's associated metadata.
|
|
39
|
+
*/
|
|
31
40
|
meta: PiralPageMeta;
|
|
32
41
|
}
|
|
33
42
|
/**
|
|
34
43
|
* The interface modeling the registration of a pilet extension component.
|
|
35
44
|
*/
|
|
36
45
|
export interface ExtensionRegistration extends BaseRegistration {
|
|
46
|
+
/**
|
|
47
|
+
* The wrapped registered extension component.
|
|
48
|
+
*/
|
|
37
49
|
component: WrappedComponent<ExtensionComponentProps<string>>;
|
|
50
|
+
/**
|
|
51
|
+
* The original extension component that has been registered.
|
|
52
|
+
*/
|
|
38
53
|
reference: any;
|
|
54
|
+
/**
|
|
55
|
+
* The default params (i.e., meta) of the extension.
|
|
56
|
+
*/
|
|
39
57
|
defaults: any;
|
|
40
58
|
}
|
|
41
59
|
/**
|
|
@@ -20,21 +20,29 @@ const renderExtensions = [
|
|
|
20
20
|
defaults: {},
|
|
21
21
|
pilet: '',
|
|
22
22
|
reference: {
|
|
23
|
-
displayName: '
|
|
23
|
+
displayName: 'AnyComponent',
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
];
|
|
27
|
+
function defaultOrder(extensions) {
|
|
28
|
+
return extensions;
|
|
29
|
+
}
|
|
27
30
|
/**
|
|
28
31
|
* The extension slot component to be used when the available
|
|
29
32
|
* extensions of a given name should be rendered at a specific
|
|
30
33
|
* location.
|
|
31
34
|
*/
|
|
32
35
|
function ExtensionSlot(props) {
|
|
33
|
-
const { name, render = utils_1.defaultRender, empty, params, children } = props;
|
|
36
|
+
const { name, render = utils_1.defaultRender, empty, params, children, emptySkipsRender = false, order = defaultOrder, } = props;
|
|
34
37
|
const extensions = (0, hooks_1.useGlobalState)((s) => (name ? s.registry.extensions[name] || utils_1.none : renderExtensions));
|
|
35
|
-
|
|
38
|
+
const isEmpty = extensions.length === 0 && (0, piral_base_1.isfunc)(empty);
|
|
39
|
+
const content = isEmpty
|
|
36
40
|
? [(0, utils_1.defaultRender)(empty(), 'empty')]
|
|
37
|
-
: extensions.map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, children: children, params: Object.assign(Object.assign({}, defaults),
|
|
41
|
+
: order(extensions).map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, children: children, params: Object.assign(Object.assign({}, defaults), params) })));
|
|
42
|
+
if (isEmpty && emptySkipsRender) {
|
|
43
|
+
return content[0];
|
|
44
|
+
}
|
|
45
|
+
return render(content);
|
|
38
46
|
}
|
|
39
47
|
exports.ExtensionSlot = ExtensionSlot;
|
|
40
48
|
ExtensionSlot.displayName = `ExtensionSlot`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,mDAAgD;AAChD,oCAAiE;AACjE,oCAA+C;AAG/C,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,CAAC;AAE1D,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,IAAA,6BAAqB,GAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YAChD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAA,6BAAa,EAAC,UAAU,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAC7G,OAAO,oBAAC,SAAS,oBAAK,IAAI,EAAI,CAAC;QACjC,CAAC;QACD,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,SAAS,EAAE;YACT,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"ExtensionSlot.js","sourceR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AC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1G,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,mBAAM,EAAC,KAAK,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,OAAO;QACrB,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAC/E,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,MAAM,IAEX,CACH,CAAC,CAAC;IAEP,IAAI,OAAO,IAAI,gBAAgB,EAAE;QAC/B,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;KACnB;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AA9BD,sCA8BC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
|
package/lib/types/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
3
|
import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
|
|
4
4
|
import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
|
|
@@ -33,6 +33,10 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
33
33
|
* The provided parameters for showing the extension.
|
|
34
34
|
*/
|
|
35
35
|
params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
|
|
36
|
+
/**
|
|
37
|
+
* The optional children to receive, if any.
|
|
38
|
+
*/
|
|
39
|
+
children?: ReactNode;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* The meta data registered for a page.
|
|
@@ -53,6 +57,15 @@ export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T,
|
|
|
53
57
|
*/
|
|
54
58
|
meta: PiralPageMeta;
|
|
55
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The meta data registered for a page.
|
|
62
|
+
*/
|
|
63
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Shorthand for the definition of an extension component.
|
|
67
|
+
*/
|
|
68
|
+
export declare type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap ? AnyComponent<ExtensionComponentProps<TName>> : TName extends string ? AnyComponent<ExtensionComponentProps<any>> : AnyComponent<ExtensionComponentProps<TName>>;
|
|
56
69
|
/**
|
|
57
70
|
* Defines the Pilet API from piral-core.
|
|
58
71
|
* This interface will be consumed by pilet developers so that their pilet can interact with the piral instance.
|
|
@@ -93,14 +106,14 @@ export interface PiletCoreApi {
|
|
|
93
106
|
* @param Component The component to be rendered.
|
|
94
107
|
* @param defaults Optionally, sets the default values for the expected data.
|
|
95
108
|
*/
|
|
96
|
-
registerExtension<TName>(name: TName extends string ? TName : string, Component:
|
|
109
|
+
registerExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>, defaults?: Partial<ExtensionParams<TName>>): RegistrationDisposer;
|
|
97
110
|
/**
|
|
98
111
|
* Unregisters a global extension component.
|
|
99
112
|
* Only previously registered extension components can be unregistered.
|
|
100
113
|
* @param name The name of the extension slot to unregister from.
|
|
101
114
|
* @param Component The registered extension component to unregister.
|
|
102
115
|
*/
|
|
103
|
-
unregisterExtension<TName>(name: TName extends string ? TName : string, Component:
|
|
116
|
+
unregisterExtension<TName>(name: TName extends string ? TName : string, Component: AnyExtensionComponent<TName>): void;
|
|
104
117
|
/**
|
|
105
118
|
* React component for displaying extensions for a given name.
|
|
106
119
|
* @param props The extension's rendering props.
|
package/lib/types/extension.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { PiralCustomExtensionSlotMap } from './custom';
|
|
3
|
+
import type { ExtensionRegistration } from './state';
|
|
3
4
|
/**
|
|
4
5
|
* The mapping of the existing (known) extension slots.
|
|
5
6
|
*/
|
|
@@ -18,9 +19,27 @@ export interface BaseExtensionSlotProps<TName, TParams> {
|
|
|
18
19
|
* for the specified extension.
|
|
19
20
|
*/
|
|
20
21
|
empty?(): ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Determines if the `render` function should be called in case no
|
|
24
|
+
* components are available for the specified extension.
|
|
25
|
+
*
|
|
26
|
+
* If true, `empty` will be called and returned from the slot.
|
|
27
|
+
* If false, `render` will be called with the result of calling `empty`.
|
|
28
|
+
* The result of calling `render` will then be returned from the slot.
|
|
29
|
+
*/
|
|
30
|
+
emptySkipsRender?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Defines the order of the components to render.
|
|
33
|
+
* May be more convient than using `render` w.r.t. ordering extensions
|
|
34
|
+
* by their supplied metadata.
|
|
35
|
+
* @param extensions The registered extensions.
|
|
36
|
+
* @returns The ordered extensions.
|
|
37
|
+
*/
|
|
38
|
+
order?(extensions: Array<ExtensionRegistration>): Array<ExtensionRegistration>;
|
|
21
39
|
/**
|
|
22
40
|
* Defines how the provided nodes should be rendered.
|
|
23
41
|
* @param nodes The rendered extension nodes.
|
|
42
|
+
* @returns The rendered nodes, i.e., an ReactElement.
|
|
24
43
|
*/
|
|
25
44
|
render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
|
|
26
45
|
/**
|
package/lib/types/state.d.ts
CHANGED
|
@@ -21,21 +21,39 @@ export declare type WrappedComponent<TProps> = ComponentType<PropsWithChildren<W
|
|
|
21
21
|
* The base type for pilet component registration in the global state context.
|
|
22
22
|
*/
|
|
23
23
|
export interface BaseRegistration {
|
|
24
|
+
/**
|
|
25
|
+
* The pilet registering the component.
|
|
26
|
+
*/
|
|
24
27
|
pilet: string;
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* The interface modeling the registration of a pilet page component.
|
|
28
31
|
*/
|
|
29
32
|
export interface PageRegistration extends BaseRegistration {
|
|
33
|
+
/**
|
|
34
|
+
* The registered page component.
|
|
35
|
+
*/
|
|
30
36
|
component: WrappedComponent<PageComponentProps>;
|
|
37
|
+
/**
|
|
38
|
+
* The page's associated metadata.
|
|
39
|
+
*/
|
|
31
40
|
meta: PiralPageMeta;
|
|
32
41
|
}
|
|
33
42
|
/**
|
|
34
43
|
* The interface modeling the registration of a pilet extension component.
|
|
35
44
|
*/
|
|
36
45
|
export interface ExtensionRegistration extends BaseRegistration {
|
|
46
|
+
/**
|
|
47
|
+
* The wrapped registered extension component.
|
|
48
|
+
*/
|
|
37
49
|
component: WrappedComponent<ExtensionComponentProps<string>>;
|
|
50
|
+
/**
|
|
51
|
+
* The original extension component that has been registered.
|
|
52
|
+
*/
|
|
38
53
|
reference: any;
|
|
54
|
+
/**
|
|
55
|
+
* The default params (i.e., meta) of the extension.
|
|
56
|
+
*/
|
|
39
57
|
defaults: any;
|
|
40
58
|
}
|
|
41
59
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4284",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"import": "./esm/index.js",
|
|
35
35
|
"require": "./lib/index.js"
|
|
36
36
|
},
|
|
37
|
-
"./esm
|
|
38
|
-
"import": "./esm
|
|
37
|
+
"./esm/*": {
|
|
38
|
+
"import": "./esm/*"
|
|
39
39
|
},
|
|
40
|
-
"./lib
|
|
41
|
-
"require": "./lib
|
|
40
|
+
"./lib/*": {
|
|
41
|
+
"require": "./lib/*"
|
|
42
42
|
},
|
|
43
43
|
"./package.json": "./package.json"
|
|
44
44
|
},
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@dbeining/react-atom": "^4.0.0",
|
|
76
|
-
"piral-base": "0.15.0-alpha.
|
|
77
|
-
"piral-debug-utils": "0.15.0-alpha.
|
|
76
|
+
"piral-base": "0.15.0-alpha.4284",
|
|
77
|
+
"piral-debug-utils": "0.15.0-alpha.4284"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"react": ">=16.8.0",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"@libre/atom",
|
|
105
105
|
"@dbeining/react-atom"
|
|
106
106
|
],
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "c48d6a2c320241d04e3c9c4c4edb423345003587"
|
|
108
108
|
}
|
|
@@ -49,6 +49,11 @@ const state = {
|
|
|
49
49
|
component: StubComponent3,
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
|
+
lol: [
|
|
53
|
+
{
|
|
54
|
+
component: StubComponent1,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
52
57
|
},
|
|
53
58
|
},
|
|
54
59
|
};
|
|
@@ -118,7 +123,7 @@ describe('Extension Module', () => {
|
|
|
118
123
|
it('overrides the empty renderer on not available extension', () => {
|
|
119
124
|
const node = mount(<ExtensionSlot name="qxz" empty={() => <StubComponent1 key="empty" />} />);
|
|
120
125
|
expect(node.find(StubComponent1).length).toBe(1);
|
|
121
|
-
expect(node.find(
|
|
126
|
+
expect(node.find(StubComponent2).length).toBe(0);
|
|
122
127
|
});
|
|
123
128
|
|
|
124
129
|
it('overrides the empty renderer on an available extension', () => {
|
|
@@ -138,4 +143,30 @@ describe('Extension Module', () => {
|
|
|
138
143
|
expect(node.find(StubComponent1).length).toBe(1);
|
|
139
144
|
expect(node.find(StubComponent2).length).toBe(1);
|
|
140
145
|
});
|
|
146
|
+
|
|
147
|
+
it('does not use the render function with empty when emptySkipsRender is set', () => {
|
|
148
|
+
const node = mount(
|
|
149
|
+
<ExtensionSlot
|
|
150
|
+
name="foo"
|
|
151
|
+
emptySkipsRender
|
|
152
|
+
empty={() => <StubComponent2 key="empty" />}
|
|
153
|
+
render={(nodes) => <StubComponent1 children={nodes} />}
|
|
154
|
+
/>,
|
|
155
|
+
);
|
|
156
|
+
expect(node.find(StubComponent1).length).toBe(0);
|
|
157
|
+
expect(node.find(StubComponent2).length).toBe(1);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('does use the render function without empty independent if emptySkipsRender is set', () => {
|
|
161
|
+
const node = mount(
|
|
162
|
+
<ExtensionSlot
|
|
163
|
+
name="lol"
|
|
164
|
+
emptySkipsRender
|
|
165
|
+
empty={() => <StubComponent2 key="empty" />}
|
|
166
|
+
render={(nodes) => <StubComponent1 children={nodes} />}
|
|
167
|
+
/>,
|
|
168
|
+
);
|
|
169
|
+
expect(node.find(StubComponent1).length).toBe(2);
|
|
170
|
+
expect(node.find(StubComponent2).length).toBe(0);
|
|
171
|
+
});
|
|
141
172
|
});
|
|
@@ -20,33 +20,50 @@ const renderExtensions: [ExtensionRegistration] = [
|
|
|
20
20
|
defaults: {},
|
|
21
21
|
pilet: '',
|
|
22
22
|
reference: {
|
|
23
|
-
displayName: '
|
|
23
|
+
displayName: 'AnyComponent',
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
26
|
];
|
|
27
27
|
|
|
28
|
+
function defaultOrder(extensions: Array<ExtensionRegistration>) {
|
|
29
|
+
return extensions;
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* The extension slot component to be used when the available
|
|
30
34
|
* extensions of a given name should be rendered at a specific
|
|
31
35
|
* location.
|
|
32
36
|
*/
|
|
33
37
|
export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
|
|
34
|
-
const {
|
|
38
|
+
const {
|
|
39
|
+
name,
|
|
40
|
+
render = defaultRender,
|
|
41
|
+
empty,
|
|
42
|
+
params,
|
|
43
|
+
children,
|
|
44
|
+
emptySkipsRender = false,
|
|
45
|
+
order = defaultOrder,
|
|
46
|
+
} = props;
|
|
35
47
|
const extensions = useGlobalState((s) => (name ? s.registry.extensions[name] || none : renderExtensions));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const isEmpty = extensions.length === 0 && isfunc(empty);
|
|
49
|
+
const content = isEmpty
|
|
50
|
+
? [defaultRender(empty(), 'empty')]
|
|
51
|
+
: order(extensions).map(({ component: Component, reference, defaults = {} }, i) => (
|
|
52
|
+
<Component
|
|
53
|
+
key={`${reference?.displayName || '_'}${i}`}
|
|
54
|
+
children={children}
|
|
55
|
+
params={{
|
|
56
|
+
...defaults,
|
|
57
|
+
...params,
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
));
|
|
61
|
+
|
|
62
|
+
if (isEmpty && emptySkipsRender) {
|
|
63
|
+
return content[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return render(content);
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
ExtensionSlot.displayName = `ExtensionSlot`;
|
package/src/types/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
3
|
import type {
|
|
4
4
|
PiletApi,
|
|
@@ -46,6 +46,10 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
46
46
|
* The provided parameters for showing the extension.
|
|
47
47
|
*/
|
|
48
48
|
params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
|
|
49
|
+
/**
|
|
50
|
+
* The optional children to receive, if any.
|
|
51
|
+
*/
|
|
52
|
+
children?: ReactNode;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/**
|
|
@@ -70,6 +74,20 @@ export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T,
|
|
|
70
74
|
meta: PiralPageMeta;
|
|
71
75
|
}
|
|
72
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The meta data registered for a page.
|
|
79
|
+
*/
|
|
80
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Shorthand for the definition of an extension component.
|
|
84
|
+
*/
|
|
85
|
+
export type AnyExtensionComponent<TName> = TName extends keyof PiralExtensionSlotMap
|
|
86
|
+
? AnyComponent<ExtensionComponentProps<TName>>
|
|
87
|
+
: TName extends string
|
|
88
|
+
? AnyComponent<ExtensionComponentProps<any>>
|
|
89
|
+
: AnyComponent<ExtensionComponentProps<TName>>;
|
|
90
|
+
|
|
73
91
|
/**
|
|
74
92
|
* Defines the Pilet API from piral-core.
|
|
75
93
|
* This interface will be consumed by pilet developers so that their pilet can interact with the piral instance.
|
|
@@ -112,7 +130,7 @@ export interface PiletCoreApi {
|
|
|
112
130
|
*/
|
|
113
131
|
registerExtension<TName>(
|
|
114
132
|
name: TName extends string ? TName : string,
|
|
115
|
-
Component:
|
|
133
|
+
Component: AnyExtensionComponent<TName>,
|
|
116
134
|
defaults?: Partial<ExtensionParams<TName>>,
|
|
117
135
|
): RegistrationDisposer;
|
|
118
136
|
/**
|
|
@@ -123,7 +141,7 @@ export interface PiletCoreApi {
|
|
|
123
141
|
*/
|
|
124
142
|
unregisterExtension<TName>(
|
|
125
143
|
name: TName extends string ? TName : string,
|
|
126
|
-
Component:
|
|
144
|
+
Component: AnyExtensionComponent<TName>,
|
|
127
145
|
): void;
|
|
128
146
|
/**
|
|
129
147
|
* React component for displaying extensions for a given name.
|
package/src/types/extension.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { PiralCustomExtensionSlotMap } from './custom';
|
|
3
|
+
import type { ExtensionRegistration } from './state';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The mapping of the existing (known) extension slots.
|
|
@@ -19,9 +20,27 @@ export interface BaseExtensionSlotProps<TName, TParams> {
|
|
|
19
20
|
* for the specified extension.
|
|
20
21
|
*/
|
|
21
22
|
empty?(): ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if the `render` function should be called in case no
|
|
25
|
+
* components are available for the specified extension.
|
|
26
|
+
*
|
|
27
|
+
* If true, `empty` will be called and returned from the slot.
|
|
28
|
+
* If false, `render` will be called with the result of calling `empty`.
|
|
29
|
+
* The result of calling `render` will then be returned from the slot.
|
|
30
|
+
*/
|
|
31
|
+
emptySkipsRender?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Defines the order of the components to render.
|
|
34
|
+
* May be more convient than using `render` w.r.t. ordering extensions
|
|
35
|
+
* by their supplied metadata.
|
|
36
|
+
* @param extensions The registered extensions.
|
|
37
|
+
* @returns The ordered extensions.
|
|
38
|
+
*/
|
|
39
|
+
order?(extensions: Array<ExtensionRegistration>): Array<ExtensionRegistration>;
|
|
22
40
|
/**
|
|
23
41
|
* Defines how the provided nodes should be rendered.
|
|
24
42
|
* @param nodes The rendered extension nodes.
|
|
43
|
+
* @returns The rendered nodes, i.e., an ReactElement.
|
|
25
44
|
*/
|
|
26
45
|
render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
|
|
27
46
|
/**
|
package/src/types/state.ts
CHANGED
|
@@ -47,6 +47,9 @@ export type WrappedComponent<TProps> = ComponentType<PropsWithChildren<Without<T
|
|
|
47
47
|
* The base type for pilet component registration in the global state context.
|
|
48
48
|
*/
|
|
49
49
|
export interface BaseRegistration {
|
|
50
|
+
/**
|
|
51
|
+
* The pilet registering the component.
|
|
52
|
+
*/
|
|
50
53
|
pilet: string;
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -54,7 +57,13 @@ export interface BaseRegistration {
|
|
|
54
57
|
* The interface modeling the registration of a pilet page component.
|
|
55
58
|
*/
|
|
56
59
|
export interface PageRegistration extends BaseRegistration {
|
|
60
|
+
/**
|
|
61
|
+
* The registered page component.
|
|
62
|
+
*/
|
|
57
63
|
component: WrappedComponent<PageComponentProps>;
|
|
64
|
+
/**
|
|
65
|
+
* The page's associated metadata.
|
|
66
|
+
*/
|
|
58
67
|
meta: PiralPageMeta;
|
|
59
68
|
}
|
|
60
69
|
|
|
@@ -62,8 +71,17 @@ export interface PageRegistration extends BaseRegistration {
|
|
|
62
71
|
* The interface modeling the registration of a pilet extension component.
|
|
63
72
|
*/
|
|
64
73
|
export interface ExtensionRegistration extends BaseRegistration {
|
|
74
|
+
/**
|
|
75
|
+
* The wrapped registered extension component.
|
|
76
|
+
*/
|
|
65
77
|
component: WrappedComponent<ExtensionComponentProps<string>>;
|
|
78
|
+
/**
|
|
79
|
+
* The original extension component that has been registered.
|
|
80
|
+
*/
|
|
66
81
|
reference: any;
|
|
82
|
+
/**
|
|
83
|
+
* The default params (i.e., meta) of the extension.
|
|
84
|
+
*/
|
|
67
85
|
defaults: any;
|
|
68
86
|
}
|
|
69
87
|
|