piral-core 0.14.8-beta.3487 → 0.14.8-beta.3504
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/Piral.d.ts +2 -2
- package/esm/Piral.js +1 -1
- package/esm/Piral.js.map +1 -1
- package/esm/components/Mediator.js +11 -8
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/ResponsiveLayout.js +3 -3
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SetComponent.js +2 -2
- package/esm/components/SetComponent.js.map +1 -1
- package/esm/components/SetError.js +2 -2
- package/esm/components/SetError.js.map +1 -1
- package/esm/components/SetProvider.js +2 -2
- package/esm/components/SetProvider.js.map +1 -1
- package/esm/components/SetRedirect.js +2 -2
- package/esm/components/SetRedirect.js.map +1 -1
- package/esm/components/SetRoute.js +2 -2
- package/esm/components/SetRoute.js.map +1 -1
- package/esm/createInstance.d.ts +2 -2
- package/esm/createInstance.js +3 -1
- package/esm/createInstance.js.map +1 -1
- package/esm/state/withApi.js +2 -3
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/instance.d.ts +18 -3
- package/lib/Piral.d.ts +2 -2
- package/lib/Piral.js +1 -1
- package/lib/Piral.js.map +1 -1
- package/lib/components/Mediator.js +10 -7
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/ResponsiveLayout.js +2 -2
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SetComponent.js +1 -1
- package/lib/components/SetComponent.js.map +1 -1
- package/lib/components/SetError.js +1 -1
- package/lib/components/SetError.js.map +1 -1
- package/lib/components/SetProvider.js +1 -1
- package/lib/components/SetProvider.js.map +1 -1
- package/lib/components/SetRedirect.js +1 -1
- package/lib/components/SetRedirect.js.map +1 -1
- package/lib/components/SetRoute.js +1 -1
- package/lib/components/SetRoute.js.map +1 -1
- package/lib/createInstance.d.ts +2 -2
- package/lib/createInstance.js +3 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/state/withApi.js +1 -2
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/instance.d.ts +18 -3
- package/package.json +4 -4
- package/src/Piral.tsx +3 -3
- package/src/actions/app.ts +1 -1
- package/src/components/Mediator.test.tsx +4 -3
- package/src/components/Mediator.tsx +15 -8
- package/src/components/ResponsiveLayout.test.tsx +15 -5
- package/src/components/ResponsiveLayout.tsx +3 -3
- package/src/components/SetComponent.tsx +2 -2
- package/src/components/SetError.tsx +2 -2
- package/src/components/SetProvider.tsx +2 -2
- package/src/components/SetRedirect.tsx +2 -2
- package/src/components/SetRoute.tsx +2 -2
- package/src/createInstance.tsx +5 -2
- package/src/state/withApi.tsx +2 -3
- package/src/types/instance.ts +19 -3
package/esm/Piral.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PiralProps } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the Piral app shell frame. Use this component together
|
|
5
5
|
* with an existing instance to render the app shell.
|
|
@@ -15,4 +15,4 @@ const app = (
|
|
|
15
15
|
);
|
|
16
16
|
```
|
|
17
17
|
*/
|
|
18
|
-
export declare const Piral: React.FC<
|
|
18
|
+
export declare const Piral: React.FC<PiralProps>;
|
package/esm/Piral.js
CHANGED
|
@@ -19,7 +19,7 @@ const app = (
|
|
|
19
19
|
*/
|
|
20
20
|
export const Piral = ({ instance = createInstance(), breakpoints, children }) => (React.createElement(StateContext.Provider, { value: instance.context },
|
|
21
21
|
React.createElement(ResponsiveLayout, { breakpoints: breakpoints }),
|
|
22
|
-
React.createElement(Mediator, { options: instance.options }),
|
|
22
|
+
React.createElement(Mediator, { options: instance.options, key: instance.id }),
|
|
23
23
|
React.createElement(PiralView, null,
|
|
24
24
|
React.createElement(PortalRenderer, { id: "root" }),
|
|
25
25
|
children)));
|
package/esm/Piral.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Piral.js","sourceRoot":"","sources":["../src/Piral.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGrF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"Piral.js","sourceRoot":"","sources":["../src/Piral.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGrF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyB,CAAC,EAAE,QAAQ,GAAG,cAAc,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CACrG,oBAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,CAAC,OAAO;IAC5C,oBAAC,gBAAgB,IAAC,WAAW,EAAE,WAAW,GAAI;IAC9C,oBAAC,QAAQ,IAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAI;IACzD,oBAAC,SAAS;QACR,oBAAC,cAAc,IAAC,EAAE,EAAC,MAAM,GAAG;QAC3B,QAAQ,CACC,CACU,CACzB,CAAC;AACF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { startLoadingPilets } from 'piral-base';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext } from '../hooks';
|
|
4
4
|
import { none } from '../utils';
|
|
5
5
|
/**
|
|
6
6
|
* The Mediator component for interfacing with pilets loading.
|
|
7
7
|
*/
|
|
8
8
|
export const Mediator = ({ options }) => {
|
|
9
|
-
const initialize =
|
|
9
|
+
const { initialize, readState } = useGlobalStateContext();
|
|
10
10
|
React.useEffect(() => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const shouldLoad = readState(s => s.app.loading);
|
|
12
|
+
if (shouldLoad) {
|
|
13
|
+
const { connect, disconnect } = startLoadingPilets(options);
|
|
14
|
+
const notifier = (error, pilets, loaded) => {
|
|
15
|
+
initialize(!loaded, error, pilets);
|
|
16
|
+
};
|
|
17
|
+
connect(notifier);
|
|
18
|
+
return () => disconnect(notifier);
|
|
19
|
+
}
|
|
17
20
|
}, none);
|
|
18
21
|
// tslint:disable-next-line:no-null-keyword
|
|
19
22
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mediator.js","sourceRoot":"","sources":["../../src/components/Mediator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAqB,kBAAkB,EAAiB,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Mediator.js","sourceRoot":"","sources":["../../src/components/Mediator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAqB,kBAAkB,EAAiB,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAYhC;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAA4B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IAC/D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,qBAAqB,EAAE,CAAC;IAE1D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,UAAU,EAAE;YACd,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;YAC5D,MAAM,QAAQ,GAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBACxD,UAAU,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACrC,CAAC,CAAC;YACF,OAAO,CAAC,QAAQ,CAAC,CAAC;YAClB,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SACnC;IAEH,CAAC,EAAE,IAAI,CAAC,CAAC;IAET,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useMedia, useGlobalState,
|
|
2
|
+
import { useMedia, useGlobalState, useGlobalStateContext } from '../hooks';
|
|
3
3
|
import { defaultLayouts, defaultRender, defaultBreakpoints } from '../utils';
|
|
4
4
|
/**
|
|
5
5
|
* The component capable of identifying and switching the currently used layout.
|
|
6
6
|
*/
|
|
7
7
|
export const ResponsiveLayout = ({ breakpoints = defaultBreakpoints, children }) => {
|
|
8
8
|
const current = useGlobalState((m) => m.app.layout) || 'desktop';
|
|
9
|
-
const
|
|
9
|
+
const { changeLayout } = useGlobalStateContext();
|
|
10
10
|
const selected = useMedia(breakpoints, defaultLayouts, current);
|
|
11
11
|
React.useEffect(() => {
|
|
12
12
|
if (selected !== current) {
|
|
13
|
-
|
|
13
|
+
changeLayout(selected);
|
|
14
14
|
}
|
|
15
15
|
}, [selected]);
|
|
16
16
|
return defaultRender(children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponsiveLayout.js","sourceRoot":"","sources":["../../src/components/ResponsiveLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"ResponsiveLayout.js","sourceRoot":"","sources":["../../src/components/ResponsiveLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAa7E;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAAE,WAAW,GAAG,kBAAkB,EAAE,QAAQ,EAAE,EAAE,EAAE;IAClH,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;IACjE,MAAM,EAAE,YAAY,EAAE,GAAG,qBAAqB,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAEhE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ,KAAK,OAAO,EAAE;YACxB,YAAY,CAAC,QAAQ,CAAC,CAAC;SACxB;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC,CAAC;AACF,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
2
2
|
/**
|
|
3
3
|
* The component capable of setting a layout component at mounting.
|
|
4
4
|
*/
|
|
5
5
|
export function SetComponent({ name, component, }) {
|
|
6
|
-
const setComponent =
|
|
6
|
+
const { setComponent } = useGlobalStateContext();
|
|
7
7
|
useSetter(() => component && setComponent(name, component));
|
|
8
8
|
// tslint:disable-next-line:no-null-keyword
|
|
9
9
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetComponent.js","sourceRoot":"","sources":["../../src/components/SetComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SetComponent.js","sourceRoot":"","sources":["../../src/components/SetComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAiB5D;;GAEG;AACH,MAAM,UAAU,YAAY,CAAqC,EAC/D,IAAI,EACJ,SAAS,GACe;IACxB,MAAM,EAAE,YAAY,EAAE,GAAG,qBAAqB,EAAE,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
2
2
|
/**
|
|
3
3
|
* The component capable of setting a globally defined error handler component at mounting.
|
|
4
4
|
*/
|
|
5
5
|
export function SetError({ type, component, }) {
|
|
6
|
-
const setErrorComponent =
|
|
6
|
+
const { setErrorComponent } = useGlobalStateContext();
|
|
7
7
|
useSetter(() => component && setErrorComponent(type, component));
|
|
8
8
|
// tslint:disable-next-line:no-null-keyword
|
|
9
9
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetError.js","sourceRoot":"","sources":["../../src/components/SetError.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SetError.js","sourceRoot":"","sources":["../../src/components/SetError.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAiB5D;;GAEG;AACH,MAAM,UAAU,QAAQ,CAA0C,EAChE,IAAI,EACJ,SAAS,GACW;IACpB,MAAM,EAAE,iBAAiB,EAAE,GAAG,qBAAqB,EAAE,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,IAAI,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACjE,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
2
2
|
/**
|
|
3
3
|
* The component capable of setting a global provider at mounting.
|
|
4
4
|
*/
|
|
5
5
|
export function SetProvider({ provider }) {
|
|
6
|
-
const includeProvider =
|
|
6
|
+
const { includeProvider } = useGlobalStateContext();
|
|
7
7
|
useSetter(() => provider && includeProvider(provider));
|
|
8
8
|
// tslint:disable-next-line:no-null-keyword
|
|
9
9
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetProvider.js","sourceRoot":"","sources":["../../src/components/SetProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SetProvider.js","sourceRoot":"","sources":["../../src/components/SetProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAY5D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAoB;IACxD,MAAM,EAAC,eAAe,EAAC,GAAG,qBAAqB,EAAE,CAAC;IAClD,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Redirect } from 'react-router';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
4
4
|
/**
|
|
5
5
|
* The component capable of setting a global redirect route at mounting.
|
|
6
6
|
*/
|
|
7
7
|
export function SetRedirect({ from, to }) {
|
|
8
|
-
const setRoute =
|
|
8
|
+
const { setRoute } = useGlobalStateContext();
|
|
9
9
|
useSetter(() => setRoute(from, () => React.createElement(Redirect, { to: to })));
|
|
10
10
|
// tslint:disable-next-line:no-null-keyword
|
|
11
11
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetRedirect.js","sourceRoot":"","sources":["../../src/components/SetRedirect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SetRedirect.js","sourceRoot":"","sources":["../../src/components/SetRedirect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAgB5D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE,EAAoB;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,qBAAqB,EAAE,CAAC;IAC7C,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAC,QAAQ,IAAC,EAAE,EAAE,EAAE,GAAI,CAAC,CAAC,CAAC;IAC5D,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
2
2
|
/**
|
|
3
3
|
* The component capable of setting a global route at mounting.
|
|
4
4
|
*/
|
|
5
5
|
export function SetRoute({ path, component }) {
|
|
6
|
-
const setRoute =
|
|
6
|
+
const { setRoute } = useGlobalStateContext();
|
|
7
7
|
useSetter(() => component && setRoute(path, component));
|
|
8
8
|
// tslint:disable-next-line:no-null-keyword
|
|
9
9
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetRoute.js","sourceRoot":"","sources":["../../src/components/SetRoute.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SetRoute.js","sourceRoot":"","sources":["../../src/components/SetRoute.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAgB5D;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAS,EAAE,IAAI,EAAE,SAAS,EAAoB;IACpE,MAAM,EAAE,QAAQ,EAAE,GAAG,qBAAqB,EAAE,CAAC;IAC7C,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACxD,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/esm/createInstance.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PiralInstanceOptions, PiralInstance } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new PiralInstance component, which can be used for
|
|
4
4
|
* bootstrapping the application easily.
|
|
@@ -19,4 +19,4 @@ const app = (
|
|
|
19
19
|
render(app, document.querySelector('#app'));
|
|
20
20
|
```
|
|
21
21
|
*/
|
|
22
|
-
export declare function createInstance(config?:
|
|
22
|
+
export declare function createInstance(config?: PiralInstanceOptions): PiralInstance;
|
package/esm/createInstance.js
CHANGED
|
@@ -3,6 +3,7 @@ import { blazingStrategy, standardStrategy, createListener, isfunc } from 'piral
|
|
|
3
3
|
import { defaultApiFactory, defaultDependencySelector, defaultModuleRequester } from './modules';
|
|
4
4
|
import { createGlobalState, createActions, includeActions } from './state';
|
|
5
5
|
import { createPiletOptions } from './helpers';
|
|
6
|
+
import { generateId } from './utils';
|
|
6
7
|
/**
|
|
7
8
|
* Creates a new PiralInstance component, which can be used for
|
|
8
9
|
* bootstrapping the application easily.
|
|
@@ -24,7 +25,7 @@ render(app, document.querySelector('#app'));
|
|
|
24
25
|
```
|
|
25
26
|
*/
|
|
26
27
|
export function createInstance(config = {}) {
|
|
27
|
-
const { state, actions, availablePilets = [], plugins, requestPilets = defaultModuleRequester, loaderConfig, async = false, shareDependencies = defaultDependencySelector, loadPilet, loaders, debug, apiFactory = defaultApiFactory, } = config;
|
|
28
|
+
const { id = generateId(), state, actions, availablePilets = [], plugins, requestPilets = defaultModuleRequester, loaderConfig, async = false, shareDependencies = defaultDependencySelector, loadPilet, loaders, debug, apiFactory = defaultApiFactory, } = config;
|
|
28
29
|
const globalState = createGlobalState(state);
|
|
29
30
|
const events = createListener(globalState);
|
|
30
31
|
const context = createActions(globalState, events);
|
|
@@ -53,6 +54,7 @@ export function createInstance(config = {}) {
|
|
|
53
54
|
}
|
|
54
55
|
context.options = options;
|
|
55
56
|
return __assign(events, {
|
|
57
|
+
id,
|
|
56
58
|
createApi,
|
|
57
59
|
context,
|
|
58
60
|
root,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInstance.js","sourceRoot":"","sources":["../src/createInstance.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAA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,GAAG,OAAO,IAAI,EAAE,CAAC;IACrC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IACtF,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,SAAS,CAAC;QACrB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO;QAClD,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,kBAAkB,CAAC;QACjC,OAAO;QACP,SAAS;QACT,OAAO;QACP,SAAS;QACT,eAAe;QACf,YAAY;QACZ,iBAAiB;QACjB,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB;QAC5E,aAAa;QACb,KAAK;KACN,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE;QACX,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAClC;IAED,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;IAE1B,OAAO,QAAQ,CAAC,MAAM,EAAE;QACtB,EAAE;QACF,SAAS;QACT,OAAO;QACP,IAAI;QACJ,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
|
package/esm/state/withApi.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { isfunc } from 'piral-base';
|
|
3
3
|
import { __RouterContext } from 'react-router';
|
|
4
4
|
import { PiralError, PiralLoadingIndicator, ErrorBoundary, PortalRenderer } from '../components';
|
|
5
|
-
import {
|
|
5
|
+
import { useGlobalStateContext } from '../hooks';
|
|
6
6
|
import { defaultRender, convertComponent, none } from '../utils';
|
|
7
7
|
// this is an arbitrary start number to have 6 digits
|
|
8
8
|
let portalIdBase = 123456;
|
|
@@ -63,8 +63,7 @@ function wrapReactComponent(Component, stasisOptions, piral, Wrapper) {
|
|
|
63
63
|
}
|
|
64
64
|
function wrapForeignComponent(component, stasisOptions, piral, Wrapper) {
|
|
65
65
|
return React.memo((props) => {
|
|
66
|
-
const { destroyPortal } =
|
|
67
|
-
const { state, readState } = useGlobalStateContext();
|
|
66
|
+
const { state, readState, destroyPortal } = useGlobalStateContext();
|
|
68
67
|
const router = React.useContext(__RouterContext);
|
|
69
68
|
const id = React.useMemo(() => (portalIdBase++).toString(26), none);
|
|
70
69
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
package/esm/state/withApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAAwB,cAAc,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAAwB,cAAc,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AA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AAQ,EAAE,oBAAC,qBAAqB,OAAG,IAAG,KAAK,CAAkB,CAAC;QACvF,CAAC;QACD,WAAW,CAAC,KAAK,EAAE,KAAU;YAC3B,OAAO,oBAAC,UAAU,kBAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,EAAI,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/esm/types/instance.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
|
|
2
2
|
import type { GlobalStateContext } from './state';
|
|
3
3
|
import type { LayoutBreakpoints } from './layout';
|
|
4
|
+
import { PiralConfiguration } from './config';
|
|
4
5
|
/**
|
|
5
6
|
* The props of the Piral component.
|
|
6
7
|
*/
|
|
7
|
-
export interface
|
|
8
|
+
export interface PiralProps {
|
|
8
9
|
/**
|
|
9
10
|
* The specific Piral instance to be used.
|
|
10
11
|
*/
|
|
@@ -15,10 +16,24 @@ export interface PortalProps {
|
|
|
15
16
|
breakpoints?: LayoutBreakpoints;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* The
|
|
19
|
-
|
|
19
|
+
* The options for creating a new PiralInstance object.
|
|
20
|
+
*/
|
|
21
|
+
export interface PiralInstanceOptions extends PiralConfiguration {
|
|
22
|
+
/**
|
|
23
|
+
* Defines the id of this instance. Used in case of multiple instances.
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The PiralInstance object, which is an event emitter with some other
|
|
29
|
+
* utilities and helper. This object is the source for the React
|
|
30
|
+
* functional component (`Piral`).
|
|
20
31
|
*/
|
|
21
32
|
export interface PiralInstance extends EventEmitter {
|
|
33
|
+
/**
|
|
34
|
+
* The id of the Piral instance.
|
|
35
|
+
*/
|
|
36
|
+
id: string;
|
|
22
37
|
/**
|
|
23
38
|
* The global state context instance.
|
|
24
39
|
*/
|
package/lib/Piral.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PiralProps } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the Piral app shell frame. Use this component together
|
|
5
5
|
* with an existing instance to render the app shell.
|
|
@@ -15,4 +15,4 @@ const app = (
|
|
|
15
15
|
);
|
|
16
16
|
```
|
|
17
17
|
*/
|
|
18
|
-
export declare const Piral: React.FC<
|
|
18
|
+
export declare const Piral: React.FC<PiralProps>;
|
package/lib/Piral.js
CHANGED
|
@@ -22,7 +22,7 @@ const app = (
|
|
|
22
22
|
*/
|
|
23
23
|
const Piral = ({ instance = (0, createInstance_1.createInstance)(), breakpoints, children }) => (React.createElement(state_1.StateContext.Provider, { value: instance.context },
|
|
24
24
|
React.createElement(components_1.ResponsiveLayout, { breakpoints: breakpoints }),
|
|
25
|
-
React.createElement(components_1.Mediator, { options: instance.options }),
|
|
25
|
+
React.createElement(components_1.Mediator, { options: instance.options, key: instance.id }),
|
|
26
26
|
React.createElement(components_1.PiralView, null,
|
|
27
27
|
React.createElement(components_1.PortalRenderer, { id: "root" }),
|
|
28
28
|
children)));
|
package/lib/Piral.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Piral.js","sourceRoot":"","sources":["../src/Piral.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,mCAAuC;AACvC,qDAAkD;AAClD,6CAAqF;AAGrF;;;;;;;;;;;;;;GAcG;AACI,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"Piral.js","sourceRoot":"","sources":["../src/Piral.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,mCAAuC;AACvC,qDAAkD;AAClD,6CAAqF;AAGrF;;;;;;;;;;;;;;GAcG;AACI,MAAM,KAAK,GAAyB,CAAC,EAAE,QAAQ,GAAG,IAAA,+BAAc,GAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CACrG,oBAAC,oBAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,QAAQ,CAAC,OAAO;IAC5C,oBAAC,6BAAgB,IAAC,WAAW,EAAE,WAAW,GAAI;IAC9C,oBAAC,qBAAQ,IAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAI;IACzD,oBAAC,sBAAS;QACR,oBAAC,2BAAc,IAAC,EAAE,EAAC,MAAM,GAAG;QAC3B,QAAQ,CACC,CACU,CACzB,CAAC;AATW,QAAA,KAAK,SAShB;AACF,aAAK,CAAC,WAAW,GAAG,OAAO,CAAC"}
|
|
@@ -9,14 +9,17 @@ const utils_1 = require("../utils");
|
|
|
9
9
|
* The Mediator component for interfacing with pilets loading.
|
|
10
10
|
*/
|
|
11
11
|
const Mediator = ({ options }) => {
|
|
12
|
-
const initialize = (0, hooks_1.
|
|
12
|
+
const { initialize, readState } = (0, hooks_1.useGlobalStateContext)();
|
|
13
13
|
React.useEffect(() => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const shouldLoad = readState(s => s.app.loading);
|
|
15
|
+
if (shouldLoad) {
|
|
16
|
+
const { connect, disconnect } = (0, piral_base_1.startLoadingPilets)(options);
|
|
17
|
+
const notifier = (error, pilets, loaded) => {
|
|
18
|
+
initialize(!loaded, error, pilets);
|
|
19
|
+
};
|
|
20
|
+
connect(notifier);
|
|
21
|
+
return () => disconnect(notifier);
|
|
22
|
+
}
|
|
20
23
|
}, utils_1.none);
|
|
21
24
|
// tslint:disable-next-line:no-null-keyword
|
|
22
25
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mediator.js","sourceRoot":"","sources":["../../src/components/Mediator.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAkF;AAClF,
|
|
1
|
+
{"version":3,"file":"Mediator.js","sourceRoot":"","sources":["../../src/components/Mediator.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAkF;AAClF,oCAAiD;AACjD,oCAAgC;AAYhC;;GAEG;AACI,MAAM,QAAQ,GAA4B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;IAC/D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IAE1D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,UAAU,EAAE;YACd,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,IAAA,+BAAkB,EAAC,OAAO,CAAC,CAAC;YAC5D,MAAM,QAAQ,GAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBACxD,UAAU,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACrC,CAAC,CAAC;YACF,OAAO,CAAC,QAAQ,CAAC,CAAC;YAClB,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SACnC;IAEH,CAAC,EAAE,YAAI,CAAC,CAAC;IAET,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAnBW,QAAA,QAAQ,YAmBnB"}
|
|
@@ -9,11 +9,11 @@ const utils_1 = require("../utils");
|
|
|
9
9
|
*/
|
|
10
10
|
const ResponsiveLayout = ({ breakpoints = utils_1.defaultBreakpoints, children }) => {
|
|
11
11
|
const current = (0, hooks_1.useGlobalState)((m) => m.app.layout) || 'desktop';
|
|
12
|
-
const
|
|
12
|
+
const { changeLayout } = (0, hooks_1.useGlobalStateContext)();
|
|
13
13
|
const selected = (0, hooks_1.useMedia)(breakpoints, utils_1.defaultLayouts, current);
|
|
14
14
|
React.useEffect(() => {
|
|
15
15
|
if (selected !== current) {
|
|
16
|
-
|
|
16
|
+
changeLayout(selected);
|
|
17
17
|
}
|
|
18
18
|
}, [selected]);
|
|
19
19
|
return (0, utils_1.defaultRender)(children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponsiveLayout.js","sourceRoot":"","sources":["../../src/components/ResponsiveLayout.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"ResponsiveLayout.js","sourceRoot":"","sources":["../../src/components/ResponsiveLayout.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,oCAA2E;AAC3E,oCAA6E;AAa7E;;GAEG;AACI,MAAM,gBAAgB,GAAoC,CAAC,EAAE,WAAW,GAAG,0BAAkB,EAAE,QAAQ,EAAE,EAAE,EAAE;IAClH,MAAM,OAAO,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;IACjE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAA,gBAAQ,EAAC,WAAW,EAAE,sBAAc,EAAE,OAAO,CAAC,CAAC;IAEhE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ,KAAK,OAAO,EAAE;YACxB,YAAY,CAAC,QAAQ,CAAC,CAAC;SACxB;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,IAAA,qBAAa,EAAC,QAAQ,CAAC,CAAC;AACjC,CAAC,CAAC;AAZW,QAAA,gBAAgB,oBAY3B;AACF,wBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
|
|
@@ -6,7 +6,7 @@ const hooks_1 = require("../hooks");
|
|
|
6
6
|
* The component capable of setting a layout component at mounting.
|
|
7
7
|
*/
|
|
8
8
|
function SetComponent({ name, component, }) {
|
|
9
|
-
const setComponent = (0, hooks_1.
|
|
9
|
+
const { setComponent } = (0, hooks_1.useGlobalStateContext)();
|
|
10
10
|
(0, hooks_1.useSetter)(() => component && setComponent(name, component));
|
|
11
11
|
// tslint:disable-next-line:no-null-keyword
|
|
12
12
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetComponent.js","sourceRoot":"","sources":["../../src/components/SetComponent.tsx"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"SetComponent.js","sourceRoot":"","sources":["../../src/components/SetComponent.tsx"],"names":[],"mappings":";;;AACA,oCAA4D;AAiB5D;;GAEG;AACH,SAAgB,YAAY,CAAqC,EAC/D,IAAI,EACJ,SAAS,GACe;IACxB,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IACjD,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AARD,oCAQC"}
|
|
@@ -6,7 +6,7 @@ const hooks_1 = require("../hooks");
|
|
|
6
6
|
* The component capable of setting a globally defined error handler component at mounting.
|
|
7
7
|
*/
|
|
8
8
|
function SetError({ type, component, }) {
|
|
9
|
-
const setErrorComponent = (0, hooks_1.
|
|
9
|
+
const { setErrorComponent } = (0, hooks_1.useGlobalStateContext)();
|
|
10
10
|
(0, hooks_1.useSetter)(() => component && setErrorComponent(type, component));
|
|
11
11
|
// tslint:disable-next-line:no-null-keyword
|
|
12
12
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetError.js","sourceRoot":"","sources":["../../src/components/SetError.tsx"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"SetError.js","sourceRoot":"","sources":["../../src/components/SetError.tsx"],"names":[],"mappings":";;;AACA,oCAA4D;AAiB5D;;GAEG;AACH,SAAgB,QAAQ,CAA0C,EAChE,IAAI,EACJ,SAAS,GACW;IACpB,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IACtD,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,SAAS,IAAI,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACjE,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4BAQC"}
|
|
@@ -6,7 +6,7 @@ const hooks_1 = require("../hooks");
|
|
|
6
6
|
* The component capable of setting a global provider at mounting.
|
|
7
7
|
*/
|
|
8
8
|
function SetProvider({ provider }) {
|
|
9
|
-
const includeProvider = (0, hooks_1.
|
|
9
|
+
const { includeProvider } = (0, hooks_1.useGlobalStateContext)();
|
|
10
10
|
(0, hooks_1.useSetter)(() => provider && includeProvider(provider));
|
|
11
11
|
// tslint:disable-next-line:no-null-keyword
|
|
12
12
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetProvider.js","sourceRoot":"","sources":["../../src/components/SetProvider.tsx"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"SetProvider.js","sourceRoot":"","sources":["../../src/components/SetProvider.tsx"],"names":[],"mappings":";;;AACA,oCAA4D;AAY5D;;GAEG;AACH,SAAgB,WAAW,CAAC,EAAE,QAAQ,EAAoB;IACxD,MAAM,EAAC,eAAe,EAAC,GAAG,IAAA,6BAAqB,GAAE,CAAC;IAClD,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AALD,kCAKC"}
|
|
@@ -8,7 +8,7 @@ const hooks_1 = require("../hooks");
|
|
|
8
8
|
* The component capable of setting a global redirect route at mounting.
|
|
9
9
|
*/
|
|
10
10
|
function SetRedirect({ from, to }) {
|
|
11
|
-
const setRoute = (0, hooks_1.
|
|
11
|
+
const { setRoute } = (0, hooks_1.useGlobalStateContext)();
|
|
12
12
|
(0, hooks_1.useSetter)(() => setRoute(from, () => React.createElement(react_router_1.Redirect, { to: to })));
|
|
13
13
|
// tslint:disable-next-line:no-null-keyword
|
|
14
14
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetRedirect.js","sourceRoot":"","sources":["../../src/components/SetRedirect.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,+CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"SetRedirect.js","sourceRoot":"","sources":["../../src/components/SetRedirect.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,+CAAwC;AACxC,oCAA4D;AAgB5D;;GAEG;AACH,SAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE,EAAoB;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IAC7C,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAC,uBAAQ,IAAC,EAAE,EAAE,EAAE,GAAI,CAAC,CAAC,CAAC;IAC5D,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AALD,kCAKC"}
|
|
@@ -6,7 +6,7 @@ const hooks_1 = require("../hooks");
|
|
|
6
6
|
* The component capable of setting a global route at mounting.
|
|
7
7
|
*/
|
|
8
8
|
function SetRoute({ path, component }) {
|
|
9
|
-
const setRoute = (0, hooks_1.
|
|
9
|
+
const { setRoute } = (0, hooks_1.useGlobalStateContext)();
|
|
10
10
|
(0, hooks_1.useSetter)(() => component && setRoute(path, component));
|
|
11
11
|
// tslint:disable-next-line:no-null-keyword
|
|
12
12
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetRoute.js","sourceRoot":"","sources":["../../src/components/SetRoute.tsx"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"SetRoute.js","sourceRoot":"","sources":["../../src/components/SetRoute.tsx"],"names":[],"mappings":";;;AAEA,oCAA4D;AAgB5D;;GAEG;AACH,SAAgB,QAAQ,CAAS,EAAE,IAAI,EAAE,SAAS,EAAoB;IACpE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,6BAAqB,GAAE,CAAC;IAC7C,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACxD,2CAA2C;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AALD,4BAKC"}
|
package/lib/createInstance.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PiralInstanceOptions, PiralInstance } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new PiralInstance component, which can be used for
|
|
4
4
|
* bootstrapping the application easily.
|
|
@@ -19,4 +19,4 @@ const app = (
|
|
|
19
19
|
render(app, document.querySelector('#app'));
|
|
20
20
|
```
|
|
21
21
|
*/
|
|
22
|
-
export declare function createInstance(config?:
|
|
22
|
+
export declare function createInstance(config?: PiralInstanceOptions): PiralInstance;
|
package/lib/createInstance.js
CHANGED
|
@@ -6,6 +6,7 @@ const piral_base_1 = require("piral-base");
|
|
|
6
6
|
const modules_1 = require("./modules");
|
|
7
7
|
const state_1 = require("./state");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
9
10
|
/**
|
|
10
11
|
* Creates a new PiralInstance component, which can be used for
|
|
11
12
|
* bootstrapping the application easily.
|
|
@@ -27,7 +28,7 @@ render(app, document.querySelector('#app'));
|
|
|
27
28
|
```
|
|
28
29
|
*/
|
|
29
30
|
function createInstance(config = {}) {
|
|
30
|
-
const { state, actions, availablePilets = [], plugins, requestPilets = modules_1.defaultModuleRequester, loaderConfig, async = false, shareDependencies = modules_1.defaultDependencySelector, loadPilet, loaders, debug, apiFactory = modules_1.defaultApiFactory, } = config;
|
|
31
|
+
const { id = (0, utils_1.generateId)(), state, actions, availablePilets = [], plugins, requestPilets = modules_1.defaultModuleRequester, loaderConfig, async = false, shareDependencies = modules_1.defaultDependencySelector, loadPilet, loaders, debug, apiFactory = modules_1.defaultApiFactory, } = config;
|
|
31
32
|
const globalState = (0, state_1.createGlobalState)(state);
|
|
32
33
|
const events = (0, piral_base_1.createListener)(globalState);
|
|
33
34
|
const context = (0, state_1.createActions)(globalState, events);
|
|
@@ -56,6 +57,7 @@ function createInstance(config = {}) {
|
|
|
56
57
|
}
|
|
57
58
|
context.options = options;
|
|
58
59
|
return (0, tslib_1.__assign)(events, {
|
|
60
|
+
id,
|
|
59
61
|
createApi,
|
|
60
62
|
context,
|
|
61
63
|
root,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInstance.js","sourceRoot":"","sources":["../src/createInstance.tsx"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,2CAAuF;AACvF,uCAAiG;AACjG,mCAA2E;AAC3E,uCAA+C;
|
|
1
|
+
{"version":3,"file":"createInstance.js","sourceRoot":"","sources":["../src/createInstance.tsx"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,2CAAuF;AACvF,uCAAiG;AACjG,mCAA2E;AAC3E,uCAA+C;AAC/C,mCAAqC;AAGrC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc,CAAC,SAA+B,EAAE;IAC9D,MAAM,EACJ,EAAE,GAAG,IAAA,kBAAU,GAAE,EACjB,KAAK,EACL,OAAO,EACP,eAAe,GAAG,EAAE,EACpB,OAAO,EACP,aAAa,GAAG,gCAAsB,EACtC,YAAY,EACZ,KAAK,GAAG,KAAK,EACb,iBAAiB,GAAG,mCAAyB,EAC7C,SAAS,EACT,OAAO,EACP,KAAK,EACL,UAAU,GAAG,2BAAiB,GAC/B,GAAG,MAAM,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 +66,7 @@ function wrapReactComponent(Component, stasisOptions, piral, Wrapper) {
|
|
|
66
66
|
}
|
|
67
67
|
function wrapForeignComponent(component, stasisOptions, piral, Wrapper) {
|
|
68
68
|
return React.memo((props) => {
|
|
69
|
-
const { destroyPortal } = (0, hooks_1.
|
|
70
|
-
const { state, readState } = (0, hooks_1.useGlobalStateContext)();
|
|
69
|
+
const { state, readState, destroyPortal } = (0, hooks_1.useGlobalStateContext)();
|
|
71
70
|
const router = React.useContext(react_router_1.__RouterContext);
|
|
72
71
|
const id = React.useMemo(() => (portalIdBase++).toString(26), utils_1.none);
|
|
73
72
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
package/lib/state/withApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,8CAAuH;AACvH,
|
|
1
|
+
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,8CAAuH;AACvH,oCAAiD;AACjD,oCAAiE;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAS1E,MAAM,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAA7F;;QAGU,YAAO,GAAG,CAAC,EAAe,EAAE,EAAE;YACpC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAClC,EAAE,CAAC,eAAe,EAAE,CAAC;YACrB,UAAU,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAA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AAI,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;KACvE;IAED,OAAO,kBAAkB,CAAI,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,UAAU,CAAC,QAAkD,EAAE,WAAmB;IACzF,OAAO,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,cAAc,CAAC;AAClE,CAAC;AAED,SAAgB,OAAO,CACrB,OAA2B,EAC3B,SAAoD,EACpD,KAAe,EACf,SAAuB,EACvB,cAAsB,SAAS;IAE/B,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAEvF,OAAO,aAAa,CAAS,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE;QAClE,OAAO,CAAC,KAAK;YACX,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,WAAW,CAAC,KAAK;YACf,OAAO,oBAAC,KAAK,CAAC,QAAQ,IAAC,QAAQ,EAAE,oBAAC,kCAAqB,OAAG,IAAG,KAAK,CAAkB,CAAC;QACvF,CAAC;QACD,WAAW,CAAC,KAAK,EAAE,KAAU;YAC3B,OAAO,oBAAC,uBAAU,kBAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,EAAI,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AArBD,0BAqBC"}
|
package/lib/types/instance.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
|
|
2
2
|
import type { GlobalStateContext } from './state';
|
|
3
3
|
import type { LayoutBreakpoints } from './layout';
|
|
4
|
+
import { PiralConfiguration } from './config';
|
|
4
5
|
/**
|
|
5
6
|
* The props of the Piral component.
|
|
6
7
|
*/
|
|
7
|
-
export interface
|
|
8
|
+
export interface PiralProps {
|
|
8
9
|
/**
|
|
9
10
|
* The specific Piral instance to be used.
|
|
10
11
|
*/
|
|
@@ -15,10 +16,24 @@ export interface PortalProps {
|
|
|
15
16
|
breakpoints?: LayoutBreakpoints;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* The
|
|
19
|
-
|
|
19
|
+
* The options for creating a new PiralInstance object.
|
|
20
|
+
*/
|
|
21
|
+
export interface PiralInstanceOptions extends PiralConfiguration {
|
|
22
|
+
/**
|
|
23
|
+
* Defines the id of this instance. Used in case of multiple instances.
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The PiralInstance object, which is an event emitter with some other
|
|
29
|
+
* utilities and helper. This object is the source for the React
|
|
30
|
+
* functional component (`Piral`).
|
|
20
31
|
*/
|
|
21
32
|
export interface PiralInstance extends EventEmitter {
|
|
33
|
+
/**
|
|
34
|
+
* The id of the Piral instance.
|
|
35
|
+
*/
|
|
36
|
+
id: string;
|
|
22
37
|
/**
|
|
23
38
|
* The global state context instance.
|
|
24
39
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.14.8-beta.
|
|
3
|
+
"version": "0.14.8-beta.3504",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@dbeining/react-atom": "^4.0.0",
|
|
53
|
-
"piral-base": "0.14.8-beta.
|
|
54
|
-
"piral-debug-utils": "0.14.8-beta.
|
|
53
|
+
"piral-base": "0.14.8-beta.3504",
|
|
54
|
+
"piral-debug-utils": "0.14.8-beta.3504"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": ">=16.8.0",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"@libre/atom",
|
|
79
79
|
"@dbeining/react-atom"
|
|
80
80
|
],
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "8e89db6eb732293e4abda6bb3c0cbe6fd0335248"
|
|
82
82
|
}
|
package/src/Piral.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { StateContext } from './state';
|
|
3
3
|
import { createInstance } from './createInstance';
|
|
4
4
|
import { PiralView, Mediator, ResponsiveLayout, PortalRenderer } from './components';
|
|
5
|
-
import type {
|
|
5
|
+
import type { PiralProps } from './types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Represents the Piral app shell frame. Use this component together
|
|
@@ -19,10 +19,10 @@ const app = (
|
|
|
19
19
|
);
|
|
20
20
|
```
|
|
21
21
|
*/
|
|
22
|
-
export const Piral: React.FC<
|
|
22
|
+
export const Piral: React.FC<PiralProps> = ({ instance = createInstance(), breakpoints, children }) => (
|
|
23
23
|
<StateContext.Provider value={instance.context}>
|
|
24
24
|
<ResponsiveLayout breakpoints={breakpoints} />
|
|
25
|
-
<Mediator options={instance.options} />
|
|
25
|
+
<Mediator options={instance.options} key={instance.id} />
|
|
26
26
|
<PiralView>
|
|
27
27
|
<PortalRenderer id="root" />
|
|
28
28
|
{children}
|
package/src/actions/app.ts
CHANGED
|
@@ -22,6 +22,9 @@ function createMockContainer() {
|
|
|
22
22
|
dispatch(update) {
|
|
23
23
|
swap(state, update);
|
|
24
24
|
},
|
|
25
|
+
readState(select) {
|
|
26
|
+
return select(deref(state));
|
|
27
|
+
},
|
|
25
28
|
initialize(loading, error, modules) {
|
|
26
29
|
swap(state, (state) => ({
|
|
27
30
|
...state,
|
|
@@ -42,9 +45,7 @@ describe('Component Mediator', () => {
|
|
|
42
45
|
const options = {
|
|
43
46
|
createApi: jest.fn(),
|
|
44
47
|
fetchPilets: () => {
|
|
45
|
-
return new Promise<Array<PiletMetadata>>((resolve
|
|
46
|
-
resolve([]);
|
|
47
|
-
});
|
|
48
|
+
return new Promise<Array<PiletMetadata>>((resolve) => resolve([]));
|
|
48
49
|
},
|
|
49
50
|
};
|
|
50
51
|
const { context } = createMockContainer();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { LoadPiletsOptions, startLoadingPilets, PiletsLoading } from 'piral-base';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext } from '../hooks';
|
|
4
4
|
import { none } from '../utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -17,15 +17,22 @@ export interface MediatorProps {
|
|
|
17
17
|
* The Mediator component for interfacing with pilets loading.
|
|
18
18
|
*/
|
|
19
19
|
export const Mediator: React.FC<MediatorProps> = ({ options }) => {
|
|
20
|
-
const initialize =
|
|
20
|
+
const { initialize, readState } = useGlobalStateContext();
|
|
21
|
+
|
|
21
22
|
React.useEffect(() => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const shouldLoad = readState(s => s.app.loading);
|
|
24
|
+
|
|
25
|
+
if (shouldLoad) {
|
|
26
|
+
const { connect, disconnect } = startLoadingPilets(options);
|
|
27
|
+
const notifier: PiletsLoading = (error, pilets, loaded) => {
|
|
28
|
+
initialize(!loaded, error, pilets);
|
|
29
|
+
};
|
|
30
|
+
connect(notifier);
|
|
31
|
+
return () => disconnect(notifier);
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
}, none);
|
|
35
|
+
|
|
29
36
|
// tslint:disable-next-line:no-null-keyword
|
|
30
37
|
return null;
|
|
31
38
|
};
|
|
@@ -19,7 +19,9 @@ StubComponent.displayName = 'StubComponent';
|
|
|
19
19
|
describe('Responsive Module', () => {
|
|
20
20
|
it('always renders the given children', () => {
|
|
21
21
|
const changeTo = jest.fn();
|
|
22
|
-
(hooks as any).
|
|
22
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
23
|
+
changeLayout: changeTo,
|
|
24
|
+
});
|
|
23
25
|
(hooks as any).useMedia = () => 'desktop';
|
|
24
26
|
const node = mount(
|
|
25
27
|
<ResponsiveLayout breakpoints={defaultBreakpoints}>
|
|
@@ -31,7 +33,9 @@ describe('Responsive Module', () => {
|
|
|
31
33
|
|
|
32
34
|
it('does not call changeTo when nothing changed', () => {
|
|
33
35
|
const changeTo = jest.fn();
|
|
34
|
-
(hooks as any).
|
|
36
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
37
|
+
changeLayout: changeTo,
|
|
38
|
+
});
|
|
35
39
|
(hooks as any).useMedia = () => 'desktop';
|
|
36
40
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
37
41
|
expect(changeTo).not.toHaveBeenCalled();
|
|
@@ -39,7 +43,9 @@ describe('Responsive Module', () => {
|
|
|
39
43
|
|
|
40
44
|
it('does not call changeTo when nothing changed', () => {
|
|
41
45
|
const changeTo = jest.fn();
|
|
42
|
-
(hooks as any).
|
|
46
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
47
|
+
changeLayout: changeTo,
|
|
48
|
+
});
|
|
43
49
|
(hooks as any).useMedia = () => 'desktop';
|
|
44
50
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
45
51
|
expect(changeTo).not.toHaveBeenCalled();
|
|
@@ -47,7 +53,9 @@ describe('Responsive Module', () => {
|
|
|
47
53
|
|
|
48
54
|
it('does calls changeTo when someething changed (desktop -> tablet)', () => {
|
|
49
55
|
const changeTo = jest.fn();
|
|
50
|
-
(hooks as any).
|
|
56
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
57
|
+
changeLayout: changeTo,
|
|
58
|
+
});
|
|
51
59
|
(hooks as any).useMedia = () => 'tablet';
|
|
52
60
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
53
61
|
expect(changeTo).toHaveBeenCalledWith('tablet');
|
|
@@ -55,7 +63,9 @@ describe('Responsive Module', () => {
|
|
|
55
63
|
|
|
56
64
|
it('does calls changeTo when someething changed (desktop -> mobile)', () => {
|
|
57
65
|
const changeTo = jest.fn();
|
|
58
|
-
(hooks as any).
|
|
66
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
67
|
+
changeLayout: changeTo,
|
|
68
|
+
});
|
|
59
69
|
(hooks as any).useMedia = () => 'mobile';
|
|
60
70
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
61
71
|
expect(changeTo).toHaveBeenCalledWith('mobile');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useMedia, useGlobalState,
|
|
2
|
+
import { useMedia, useGlobalState, useGlobalStateContext } from '../hooks';
|
|
3
3
|
import { defaultLayouts, defaultRender, defaultBreakpoints } from '../utils';
|
|
4
4
|
import { LayoutBreakpoints } from '../types';
|
|
5
5
|
|
|
@@ -18,12 +18,12 @@ export interface ResponsiveLayoutProps {
|
|
|
18
18
|
*/
|
|
19
19
|
export const ResponsiveLayout: React.FC<ResponsiveLayoutProps> = ({ breakpoints = defaultBreakpoints, children }) => {
|
|
20
20
|
const current = useGlobalState((m) => m.app.layout) || 'desktop';
|
|
21
|
-
const
|
|
21
|
+
const { changeLayout } = useGlobalStateContext();
|
|
22
22
|
const selected = useMedia(breakpoints, defaultLayouts, current);
|
|
23
23
|
|
|
24
24
|
React.useEffect(() => {
|
|
25
25
|
if (selected !== current) {
|
|
26
|
-
|
|
26
|
+
changeLayout(selected);
|
|
27
27
|
}
|
|
28
28
|
}, [selected]);
|
|
29
29
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
import { ComponentsState } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ export function SetComponent<TKey extends keyof ComponentsState>({
|
|
|
23
23
|
name,
|
|
24
24
|
component,
|
|
25
25
|
}: SetComponentProps<TKey>): React.ReactElement {
|
|
26
|
-
const setComponent =
|
|
26
|
+
const { setComponent } = useGlobalStateContext();
|
|
27
27
|
useSetter(() => component && setComponent(name, component));
|
|
28
28
|
// tslint:disable-next-line:no-null-keyword
|
|
29
29
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
import { ErrorComponentsState } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ export function SetError<TKey extends keyof ErrorComponentsState>({
|
|
|
23
23
|
type,
|
|
24
24
|
component,
|
|
25
25
|
}: SetErrorProps<TKey>): React.ReactElement {
|
|
26
|
-
const setErrorComponent =
|
|
26
|
+
const { setErrorComponent } = useGlobalStateContext();
|
|
27
27
|
useSetter(() => component && setErrorComponent(type, component));
|
|
28
28
|
// tslint:disable-next-line:no-null-keyword
|
|
29
29
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The props for the SetProvider component.
|
|
@@ -15,7 +15,7 @@ export interface SetProviderProps {
|
|
|
15
15
|
* The component capable of setting a global provider at mounting.
|
|
16
16
|
*/
|
|
17
17
|
export function SetProvider({ provider }: SetProviderProps): React.ReactElement {
|
|
18
|
-
const includeProvider =
|
|
18
|
+
const {includeProvider} = useGlobalStateContext();
|
|
19
19
|
useSetter(() => provider && includeProvider(provider));
|
|
20
20
|
// tslint:disable-next-line:no-null-keyword
|
|
21
21
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Redirect } from 'react-router';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The props for the SetRedirect component.
|
|
@@ -20,7 +20,7 @@ export interface SetRedirectProps {
|
|
|
20
20
|
* The component capable of setting a global redirect route at mounting.
|
|
21
21
|
*/
|
|
22
22
|
export function SetRedirect({ from, to }: SetRedirectProps): React.ReactElement {
|
|
23
|
-
const setRoute =
|
|
23
|
+
const { setRoute } = useGlobalStateContext();
|
|
24
24
|
useSetter(() => setRoute(from, () => <Redirect to={to} />));
|
|
25
25
|
// tslint:disable-next-line:no-null-keyword
|
|
26
26
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RouteComponentProps } from 'react-router';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The props for the SetRoute component.
|
|
@@ -20,7 +20,7 @@ export interface SetRouteProps<T = {}> {
|
|
|
20
20
|
* The component capable of setting a global route at mounting.
|
|
21
21
|
*/
|
|
22
22
|
export function SetRoute<T = {}>({ path, component }: SetRouteProps<T>): React.ReactElement {
|
|
23
|
-
const setRoute =
|
|
23
|
+
const { setRoute } = useGlobalStateContext();
|
|
24
24
|
useSetter(() => component && setRoute(path, component));
|
|
25
25
|
// tslint:disable-next-line:no-null-keyword
|
|
26
26
|
return null;
|
package/src/createInstance.tsx
CHANGED
|
@@ -3,7 +3,8 @@ import { blazingStrategy, standardStrategy, createListener, isfunc } from 'piral
|
|
|
3
3
|
import { defaultApiFactory, defaultDependencySelector, defaultModuleRequester } from './modules';
|
|
4
4
|
import { createGlobalState, createActions, includeActions } from './state';
|
|
5
5
|
import { createPiletOptions } from './helpers';
|
|
6
|
-
import
|
|
6
|
+
import { generateId } from './utils';
|
|
7
|
+
import type { PiralInstanceOptions, PiralInstance } from './types';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Creates a new PiralInstance component, which can be used for
|
|
@@ -25,8 +26,9 @@ const app = (
|
|
|
25
26
|
render(app, document.querySelector('#app'));
|
|
26
27
|
```
|
|
27
28
|
*/
|
|
28
|
-
export function createInstance(config:
|
|
29
|
+
export function createInstance(config: PiralInstanceOptions = {}): PiralInstance {
|
|
29
30
|
const {
|
|
31
|
+
id = generateId(),
|
|
30
32
|
state,
|
|
31
33
|
actions,
|
|
32
34
|
availablePilets = [],
|
|
@@ -71,6 +73,7 @@ export function createInstance(config: PiralConfiguration = {}): PiralInstance {
|
|
|
71
73
|
context.options = options;
|
|
72
74
|
|
|
73
75
|
return __assign(events, {
|
|
76
|
+
id,
|
|
74
77
|
createApi,
|
|
75
78
|
context,
|
|
76
79
|
root,
|
package/src/state/withApi.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { isfunc } from 'piral-base';
|
|
3
3
|
import { __RouterContext } from 'react-router';
|
|
4
4
|
import { PiralError, PiralLoadingIndicator, ErrorBoundary, ErrorBoundaryOptions, PortalRenderer } from '../components';
|
|
5
|
-
import {
|
|
5
|
+
import { useGlobalStateContext } from '../hooks';
|
|
6
6
|
import { defaultRender, convertComponent, none } from '../utils';
|
|
7
7
|
import {
|
|
8
8
|
AnyComponent,
|
|
@@ -107,8 +107,7 @@ function wrapForeignComponent<T>(
|
|
|
107
107
|
Wrapper: React.ComponentType<any>,
|
|
108
108
|
) {
|
|
109
109
|
return React.memo((props: T) => {
|
|
110
|
-
const { destroyPortal } =
|
|
111
|
-
const { state, readState } = useGlobalStateContext();
|
|
110
|
+
const { state, readState, destroyPortal } = useGlobalStateContext();
|
|
112
111
|
const router = React.useContext(__RouterContext);
|
|
113
112
|
const id = React.useMemo(() => (portalIdBase++).toString(26), none);
|
|
114
113
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
package/src/types/instance.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
|
|
2
2
|
import type { GlobalStateContext } from './state';
|
|
3
3
|
import type { LayoutBreakpoints } from './layout';
|
|
4
|
+
import { PiralConfiguration } from './config';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The props of the Piral component.
|
|
7
8
|
*/
|
|
8
|
-
export interface
|
|
9
|
+
export interface PiralProps {
|
|
9
10
|
/**
|
|
10
11
|
* The specific Piral instance to be used.
|
|
11
12
|
*/
|
|
@@ -17,10 +18,25 @@ export interface PortalProps {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
|
-
* The
|
|
21
|
-
|
|
21
|
+
* The options for creating a new PiralInstance object.
|
|
22
|
+
*/
|
|
23
|
+
export interface PiralInstanceOptions extends PiralConfiguration {
|
|
24
|
+
/**
|
|
25
|
+
* Defines the id of this instance. Used in case of multiple instances.
|
|
26
|
+
*/
|
|
27
|
+
id?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The PiralInstance object, which is an event emitter with some other
|
|
32
|
+
* utilities and helper. This object is the source for the React
|
|
33
|
+
* functional component (`Piral`).
|
|
22
34
|
*/
|
|
23
35
|
export interface PiralInstance extends EventEmitter {
|
|
36
|
+
/**
|
|
37
|
+
* The id of the Piral instance.
|
|
38
|
+
*/
|
|
39
|
+
id: string;
|
|
24
40
|
/**
|
|
25
41
|
* The global state context instance.
|
|
26
42
|
*/
|