piral-core 0.14.8-beta.3500 → 0.14.8-beta.3511
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 +3 -1
- package/esm/Piral.js.map +1 -1
- package/esm/RootListener.d.ts +2 -0
- package/esm/RootListener.js +23 -0
- package/esm/RootListener.js.map +1 -0
- package/esm/components/ExtensionSlot.js +2 -2
- package/esm/components/ExtensionSlot.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/modules/api.d.ts +3 -4
- package/esm/modules/api.js +1 -106
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/core.d.ts +3 -0
- package/esm/modules/core.js +48 -0
- package/esm/modules/core.js.map +1 -0
- package/esm/modules/element.d.ts +5 -0
- package/esm/modules/element.js +83 -0
- package/esm/modules/element.js.map +1 -0
- package/esm/modules/index.d.ts +1 -0
- package/esm/modules/index.js +1 -0
- package/esm/modules/index.js.map +1 -1
- package/esm/state/withApi.js +2 -3
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/extension.d.ts +7 -3
- package/esm/types/instance.d.ts +18 -3
- package/esm/utils/extension.d.ts +13 -0
- package/esm/utils/extension.js +32 -0
- package/esm/utils/extension.js.map +1 -1
- package/lib/Piral.d.ts +2 -2
- package/lib/Piral.js +3 -1
- package/lib/Piral.js.map +1 -1
- package/lib/RootListener.d.ts +2 -0
- package/lib/RootListener.js +27 -0
- package/lib/RootListener.js.map +1 -0
- package/lib/components/ExtensionSlot.js +2 -2
- package/lib/components/ExtensionSlot.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/modules/api.d.ts +3 -4
- package/lib/modules/api.js +3 -109
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/core.d.ts +3 -0
- package/lib/modules/core.js +52 -0
- package/lib/modules/core.js.map +1 -0
- package/lib/modules/element.d.ts +5 -0
- package/lib/modules/element.js +87 -0
- package/lib/modules/element.js.map +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +1 -0
- package/lib/modules/index.js.map +1 -1
- package/lib/state/withApi.js +1 -2
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/extension.d.ts +7 -3
- package/lib/types/instance.d.ts +18 -3
- package/lib/utils/extension.d.ts +13 -0
- package/lib/utils/extension.js +34 -1
- package/lib/utils/extension.js.map +1 -1
- package/package.json +4 -4
- package/src/Piral.tsx +5 -3
- package/src/RootListener.tsx +26 -0
- package/src/actions/app.ts +1 -1
- package/src/components/ExtensionSlot.tsx +2 -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/modules/api.test.ts +15 -15
- package/src/modules/api.ts +3 -125
- package/src/modules/core.test.ts +148 -0
- package/src/modules/core.ts +50 -0
- package/src/modules/element.ts +103 -0
- package/src/modules/index.ts +1 -0
- package/src/state/withApi.tsx +2 -3
- package/src/types/extension.ts +7 -2
- package/src/types/instance.ts +19 -3
- package/src/utils/extension.tsx +41 -0
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;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,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,MAAM,CAAC,KAAK,CAAC,CAAC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;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,MAAM,UAAU,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,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/extension.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { PiralCustomExtensionSlotMap } from './custom';
|
|
3
3
|
/**
|
|
4
4
|
* The mapping of the existing (known) extension slots.
|
|
@@ -9,16 +9,20 @@ export interface PiralExtensionSlotMap extends PiralCustomExtensionSlotMap {
|
|
|
9
9
|
* The basic props for defining an extension slot.
|
|
10
10
|
*/
|
|
11
11
|
export interface BaseExtensionSlotProps<TName, TParams> {
|
|
12
|
+
/**
|
|
13
|
+
* The children to transport, if any.
|
|
14
|
+
*/
|
|
15
|
+
children?: ReactNode;
|
|
12
16
|
/**
|
|
13
17
|
* Defines what should be rendered when no components are available
|
|
14
18
|
* for the specified extension.
|
|
15
19
|
*/
|
|
16
|
-
empty?():
|
|
20
|
+
empty?(): ReactNode;
|
|
17
21
|
/**
|
|
18
22
|
* Defines how the provided nodes should be rendered.
|
|
19
23
|
* @param nodes The rendered extension nodes.
|
|
20
24
|
*/
|
|
21
|
-
render?(nodes: Array<
|
|
25
|
+
render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
|
|
22
26
|
/**
|
|
23
27
|
* The custom parameters for the given extension.
|
|
24
28
|
*/
|
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/esm/utils/extension.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ExtensionComponentProps, WrappedComponent } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the given component to an extension component.
|
|
5
|
+
* @param Component The component to transform.
|
|
6
|
+
* @returns The extension component (receiving its props via params).
|
|
7
|
+
*/
|
|
3
8
|
export declare function toExtension<T>(Component: React.ComponentType<T>): WrappedComponent<ExtensionComponentProps<T>>;
|
|
9
|
+
/**
|
|
10
|
+
* Reactifies the list of child nodes to a React Node by removing the
|
|
11
|
+
* nodes from the DOM and carrying it in a React Node, where it would be
|
|
12
|
+
* attached at a slot.
|
|
13
|
+
* @param childNodes The child nodes to reactify.
|
|
14
|
+
* @returns The React Node.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reactifyContent(childNodes: NodeListOf<ChildNode>): React.ReactNode;
|
package/esm/utils/extension.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
function removeAll(nodes) {
|
|
3
|
+
nodes.forEach((node) => node.remove());
|
|
4
|
+
}
|
|
5
|
+
const SlotCarrier = ({ nodes }) => {
|
|
6
|
+
const host = React.useRef();
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
var _a;
|
|
9
|
+
(_a = host.current) === null || _a === void 0 ? void 0 : _a.append(...nodes);
|
|
10
|
+
return () => removeAll(nodes);
|
|
11
|
+
}, [nodes]);
|
|
12
|
+
if (nodes.length) {
|
|
13
|
+
return React.createElement("slot", { ref: host });
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Transforms the given component to an extension component.
|
|
19
|
+
* @param Component The component to transform.
|
|
20
|
+
* @returns The extension component (receiving its props via params).
|
|
21
|
+
*/
|
|
2
22
|
export function toExtension(Component) {
|
|
3
23
|
return (props) => React.createElement(Component, Object.assign({}, props.params));
|
|
4
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Reactifies the list of child nodes to a React Node by removing the
|
|
27
|
+
* nodes from the DOM and carrying it in a React Node, where it would be
|
|
28
|
+
* attached at a slot.
|
|
29
|
+
* @param childNodes The child nodes to reactify.
|
|
30
|
+
* @returns The React Node.
|
|
31
|
+
*/
|
|
32
|
+
export function reactifyContent(childNodes) {
|
|
33
|
+
const nodes = Array.prototype.filter.call(childNodes, Boolean);
|
|
34
|
+
removeAll(nodes);
|
|
35
|
+
return React.createElement(SlotCarrier, { nodes: nodes });
|
|
36
|
+
}
|
|
5
37
|
//# sourceMappingURL=extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,UAAU,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC"}
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,SAAS,SAAS,CAAC,KAAuB;IACxC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAMD,MAAM,WAAW,GAA+B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAmB,CAAC;IAE7C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;;QACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,IAAI,KAAK,CAAC,MAAM,EAAE;QAChB,OAAO,8BAAM,GAAG,EAAE,IAAI,GAAI,CAAC;KAC5B;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,UAAiC;IAC/D,MAAM,KAAK,GAAqB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjF,SAAS,CAAC,KAAK,CAAC,CAAC;IACjB,OAAO,oBAAC,WAAW,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;AACvC,CAAC"}
|
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
|
@@ -5,6 +5,7 @@ const React = require("react");
|
|
|
5
5
|
const state_1 = require("./state");
|
|
6
6
|
const createInstance_1 = require("./createInstance");
|
|
7
7
|
const components_1 = require("./components");
|
|
8
|
+
const RootListener_1 = require("./RootListener");
|
|
8
9
|
/**
|
|
9
10
|
* Represents the Piral app shell frame. Use this component together
|
|
10
11
|
* with an existing instance to render the app shell.
|
|
@@ -22,7 +23,8 @@ const app = (
|
|
|
22
23
|
*/
|
|
23
24
|
const Piral = ({ instance = (0, createInstance_1.createInstance)(), breakpoints, children }) => (React.createElement(state_1.StateContext.Provider, { value: instance.context },
|
|
24
25
|
React.createElement(components_1.ResponsiveLayout, { breakpoints: breakpoints }),
|
|
25
|
-
React.createElement(components_1.Mediator, { options: instance.options }),
|
|
26
|
+
React.createElement(components_1.Mediator, { options: instance.options, key: instance.id }),
|
|
27
|
+
React.createElement(RootListener_1.RootListener, null),
|
|
26
28
|
React.createElement(components_1.PiralView, null,
|
|
27
29
|
React.createElement(components_1.PortalRenderer, { id: "root" }),
|
|
28
30
|
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;
|
|
1
|
+
{"version":3,"file":"Piral.js","sourceRoot":"","sources":["../src/Piral.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,mCAAuC;AACvC,qDAAkD;AAClD,6CAAqF;AACrF,iDAA8C;AAG9C;;;;;;;;;;;;;;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,2BAAY,OAAG;IAChB,oBAAC,sBAAS;QACR,oBAAC,2BAAc,IAAC,EAAE,EAAC,MAAM,GAAG;QAC3B,QAAQ,CACC,CACU,CACzB,CAAC;AAVW,QAAA,KAAK,SAUhB;AACF,aAAK,CAAC,WAAW,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RootListener = void 0;
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const modules_1 = require("./modules");
|
|
7
|
+
const RootListener = () => {
|
|
8
|
+
const context = (0, _1.useGlobalStateContext)();
|
|
9
|
+
React.useLayoutEffect(() => {
|
|
10
|
+
if (typeof document !== 'undefined') {
|
|
11
|
+
const handler = (ev) => {
|
|
12
|
+
ev.stopPropagation();
|
|
13
|
+
const { target, props } = ev.detail;
|
|
14
|
+
const [dispose, update] = (0, modules_1.renderElement)(context, target, props);
|
|
15
|
+
target.dispose = dispose;
|
|
16
|
+
target.update = update;
|
|
17
|
+
};
|
|
18
|
+
document.body.addEventListener('render-html', handler, false);
|
|
19
|
+
return () => {
|
|
20
|
+
document.body.removeEventListener('render-html', handler, false);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, [context]);
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
exports.RootListener = RootListener;
|
|
27
|
+
//# sourceMappingURL=RootListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RootListener.js","sourceRoot":"","sources":["../src/RootListener.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,wBAA0C;AAC1C,uCAA0C;AAEnC,MAAM,YAAY,GAAa,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,wBAAqB,GAAE,CAAC;IAExC,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE;QACzB,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,MAAM,OAAO,GAAG,CAAC,EAAe,EAAE,EAAE;gBAClC,EAAE,CAAC,eAAe,EAAE,CAAC;gBACrB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC;gBACpC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAA,uBAAa,EAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBAChE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;gBACzB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YACzB,CAAC,CAAC;YACF,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAE9D,OAAO,GAAG,EAAE;gBACV,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACnE,CAAC,CAAC;SACH;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AArBW,QAAA,YAAY,gBAqBvB"}
|
|
@@ -11,11 +11,11 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
* location.
|
|
12
12
|
*/
|
|
13
13
|
function ExtensionSlot(props) {
|
|
14
|
-
const { name, render = utils_1.defaultRender, empty, params } = props;
|
|
14
|
+
const { name, render = utils_1.defaultRender, empty, params, children } = props;
|
|
15
15
|
const extensions = (0, hooks_1.useGlobalState)((s) => s.registry.extensions[name] || utils_1.none);
|
|
16
16
|
return render(extensions.length === 0 && (0, piral_base_1.isfunc)(empty)
|
|
17
17
|
? [(0, utils_1.defaultRender)(empty(), 'empty')]
|
|
18
|
-
: extensions.map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, params: Object.assign(Object.assign({}, defaults), (params || {})) }))));
|
|
18
|
+
: 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 || {})) }))));
|
|
19
19
|
}
|
|
20
20
|
exports.ExtensionSlot = ExtensionSlot;
|
|
21
21
|
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,oCAA0C;AAC1C,oCAA+C;AAG/C;;;;GAIG;AACH,SAAgB,aAAa,CAAmB,KAA4B;IAC1E,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,qBAAa,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,oCAA0C;AAC1C,oCAA+C;AAG/C;;;;GAIG;AACH,SAAgB,aAAa,CAAmB,KAA4B;IAC1E,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,qBAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAI,CAAC,CAAC;IAC9E,OAAO,MAAM,CACX,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,mBAAM,EAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,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,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,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,O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,OAAO,GAAG,OAAO,CAAC;IAE1B,OAAO,IAAA,gBAAQ,EAAC,MAAM,EAAE;QACtB,EAAE;QACF,SAAS;QACT,OAAO;QACP,IAAI;QACJ,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AArDD,wCAqDC"}
|
package/lib/modules/api.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PiletApiCreator
|
|
2
|
-
import { GlobalStateContext,
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function createExtenders(context: GlobalStateContext, apis: Array<PiralPlugin>): PiletApiExtender<Partial<import("piral-base").PiletApi>>[];
|
|
1
|
+
import { PiletApiCreator } from 'piral-base';
|
|
2
|
+
import { GlobalStateContext, PiralPlugin } from '../types';
|
|
3
|
+
export declare function createExtenders(context: GlobalStateContext, apis: Array<PiralPlugin>): import("piral-base").PiletApiExtender<Partial<import("piral-base").PiletApi>>[];
|
|
5
4
|
export declare function defaultApiFactory(context: GlobalStateContext, apis: Array<PiralPlugin>): PiletApiCreator;
|
package/lib/modules/api.js
CHANGED
|
@@ -1,116 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultApiFactory = exports.createExtenders =
|
|
3
|
+
exports.defaultApiFactory = exports.createExtenders = void 0;
|
|
4
4
|
const piral_base_1 = require("piral-base");
|
|
5
|
-
const
|
|
6
|
-
const components_1 = require("../components");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
if (typeof window !== 'undefined' && 'customElements' in window) {
|
|
9
|
-
class PiralExtension extends HTMLElement {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.dispose = utils_1.noop;
|
|
13
|
-
this.update = utils_1.noop;
|
|
14
|
-
}
|
|
15
|
-
getProps() {
|
|
16
|
-
const name = this.getAttribute('name');
|
|
17
|
-
const params = (0, utils_1.tryParseJson)(this.getAttribute('params'));
|
|
18
|
-
return { name, params };
|
|
19
|
-
}
|
|
20
|
-
connectedCallback() {
|
|
21
|
-
if (this.isConnected) {
|
|
22
|
-
this.dispatchEvent(new CustomEvent('render-html', {
|
|
23
|
-
bubbles: true,
|
|
24
|
-
detail: {
|
|
25
|
-
target: this,
|
|
26
|
-
props: this.getProps(),
|
|
27
|
-
},
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
disconnectedCallback() {
|
|
32
|
-
this.dispose();
|
|
33
|
-
this.dispose = utils_1.noop;
|
|
34
|
-
this.update = utils_1.noop;
|
|
35
|
-
}
|
|
36
|
-
attributeChangedCallback() {
|
|
37
|
-
this.update(this.getProps());
|
|
38
|
-
}
|
|
39
|
-
static get observedAttributes() {
|
|
40
|
-
return ['name', 'params'];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
customElements.define('piral-extension', PiralExtension);
|
|
44
|
-
}
|
|
45
|
-
function render(context, element, props) {
|
|
46
|
-
let [id, portal] = (0, utils_1.renderInDom)(context, element, components_1.ExtensionSlot, props);
|
|
47
|
-
const evName = 'extension-props-changed';
|
|
48
|
-
const handler = (ev) => update(ev.detail);
|
|
49
|
-
const dispose = () => {
|
|
50
|
-
context.hidePortal(id, portal);
|
|
51
|
-
element.removeEventListener(evName, handler);
|
|
52
|
-
};
|
|
53
|
-
const update = (newProps) => {
|
|
54
|
-
[id, portal] = (0, utils_1.changeDomPortal)(id, portal, context, element, components_1.ExtensionSlot, newProps);
|
|
55
|
-
};
|
|
56
|
-
element.addEventListener(evName, handler);
|
|
57
|
-
return [dispose, update];
|
|
58
|
-
}
|
|
59
|
-
function createCoreApi(context) {
|
|
60
|
-
if (typeof document !== 'undefined') {
|
|
61
|
-
document.body.addEventListener('render-html', (ev) => {
|
|
62
|
-
ev.stopPropagation();
|
|
63
|
-
const container = ev.detail.target;
|
|
64
|
-
const [dispose, update] = render(context, container, ev.detail.props);
|
|
65
|
-
container.dispose = dispose;
|
|
66
|
-
container.update = update;
|
|
67
|
-
}, false);
|
|
68
|
-
}
|
|
69
|
-
return (api, target) => {
|
|
70
|
-
const pilet = target.name;
|
|
71
|
-
return {
|
|
72
|
-
getData(name) {
|
|
73
|
-
return context.readDataValue(name);
|
|
74
|
-
},
|
|
75
|
-
setData(name, value, options) {
|
|
76
|
-
const { target = 'memory', expires } = (0, utils_1.createDataOptions)(options);
|
|
77
|
-
const expiration = (0, utils_1.getDataExpiration)(expires);
|
|
78
|
-
return context.tryWriteDataItem(name, value, pilet, target, expiration);
|
|
79
|
-
},
|
|
80
|
-
registerPage(route, arg, meta) {
|
|
81
|
-
context.registerPage(route, {
|
|
82
|
-
pilet,
|
|
83
|
-
meta,
|
|
84
|
-
component: (0, state_1.withApi)(context, arg, api, 'page'),
|
|
85
|
-
});
|
|
86
|
-
return () => api.unregisterPage(route);
|
|
87
|
-
},
|
|
88
|
-
unregisterPage(route) {
|
|
89
|
-
context.unregisterPage(route);
|
|
90
|
-
},
|
|
91
|
-
registerExtension(name, arg, defaults) {
|
|
92
|
-
context.registerExtension(name, {
|
|
93
|
-
pilet,
|
|
94
|
-
component: (0, state_1.withApi)(context, arg, api, 'extension'),
|
|
95
|
-
reference: arg,
|
|
96
|
-
defaults,
|
|
97
|
-
});
|
|
98
|
-
return () => api.unregisterExtension(name, arg);
|
|
99
|
-
},
|
|
100
|
-
unregisterExtension(name, arg) {
|
|
101
|
-
context.unregisterExtension(name, arg);
|
|
102
|
-
},
|
|
103
|
-
renderHtmlExtension(element, props) {
|
|
104
|
-
const [dispose] = render(context, element, props);
|
|
105
|
-
return dispose;
|
|
106
|
-
},
|
|
107
|
-
Extension: components_1.ExtensionSlot,
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
exports.createCoreApi = createCoreApi;
|
|
5
|
+
const core_1 = require("./core");
|
|
112
6
|
function createExtenders(context, apis) {
|
|
113
|
-
const creators = [createCoreApi, ...apis.filter(piral_base_1.isfunc)];
|
|
7
|
+
const creators = [core_1.createCoreApi, ...apis.filter(piral_base_1.isfunc)];
|
|
114
8
|
return creators.map((c) => {
|
|
115
9
|
const ctx = c(context);
|
|
116
10
|
if ((0, piral_base_1.isfunc)(ctx)) {
|
package/lib/modules/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/modules/api.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/modules/api.ts"],"names":[],"mappings":";;;AAAA,2CAA+E;AAE/E,iCAAuC;AAGvC,SAAgB,eAAe,CAAC,OAA2B,EAAE,IAAwB;IACnF,MAAM,QAAQ,GAAuB,CAAC,oBAAa,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAM,CAAC,CAAC,CAAC;IAC7E,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;QAEvB,IAAI,IAAA,mBAAM,EAAC,GAAG,CAAC,EAAE;YACf,OAAO,GAAG,CAAC;SACZ;aAAM;YACL,OAAO,GAAG,EAAE,CAAC,mBACR,GAAG,EACN,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,0CAaC;AAED,SAAgB,iBAAiB,CAAC,OAA2B,EAAE,IAAwB;IACrF,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAChC,OAAO,IAAA,sBAAS,EAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC;AAPD,8CAOC"}
|