piral-core 0.14.0-pre.3018 → 0.14.0-pre.3085
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/debug-pilet.d.ts +3 -0
- package/debug-pilet.js +12 -0
- package/debug-pilet.ts +11 -0
- package/debug-piral.d.ts +4 -0
- package/debug-piral.js +59 -0
- package/debug-piral.ts +74 -0
- package/esm/Piral.js +6 -8
- package/esm/Piral.js.map +1 -1
- package/esm/actions/app.js +9 -10
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/components.js +4 -5
- package/esm/actions/components.js.map +1 -1
- package/esm/actions/data.js +16 -17
- package/esm/actions/data.js.map +1 -1
- package/esm/actions/define.js +2 -3
- package/esm/actions/define.js.map +1 -1
- package/esm/actions/portal.d.ts +2 -0
- package/esm/actions/portal.js +9 -4
- package/esm/actions/portal.js.map +1 -1
- package/esm/actions/state.js +1 -1
- package/esm/actions/state.js.map +1 -1
- package/esm/components/DefaultErrorInfo.js +1 -2
- package/esm/components/DefaultErrorInfo.js.map +1 -1
- package/esm/components/DefaultLayout.js +1 -4
- package/esm/components/DefaultLayout.js.map +1 -1
- package/esm/components/DefaultLoader.js +1 -1
- package/esm/components/DefaultLoader.js.map +1 -1
- package/esm/components/ErrorBoundary.js +13 -18
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/components/ExtensionSlot.js +5 -9
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/components/Mediator.js +8 -8
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/PiralRoutes.js +8 -8
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/PiralView.js +11 -16
- package/esm/components/PiralView.js.map +1 -1
- package/esm/components/PortalRenderer.d.ts +5 -0
- package/esm/components/PortalRenderer.js +7 -0
- package/esm/components/PortalRenderer.js.map +1 -0
- package/esm/components/ResponsiveLayout.js +5 -6
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SetComponent.js +3 -4
- package/esm/components/SetComponent.js.map +1 -1
- package/esm/components/SetError.js +3 -4
- package/esm/components/SetError.js.map +1 -1
- package/esm/components/SetErrors.js +2 -3
- package/esm/components/SetErrors.js.map +1 -1
- package/esm/components/SetLayout.js +2 -3
- package/esm/components/SetLayout.js.map +1 -1
- package/esm/components/SetProvider.js +3 -4
- package/esm/components/SetProvider.js.map +1 -1
- package/esm/components/SetRedirect.js +3 -4
- package/esm/components/SetRedirect.js.map +1 -1
- package/esm/components/SetRoute.js +3 -4
- package/esm/components/SetRoute.js.map +1 -1
- package/esm/components/SwitchErrorInfo.js +12 -10
- package/esm/components/SwitchErrorInfo.js.map +1 -1
- package/esm/components/components.js +8 -9
- package/esm/components/components.js.map +1 -1
- package/esm/components/index.d.ts +1 -0
- package/esm/components/index.js +1 -0
- package/esm/components/index.js.map +1 -1
- package/esm/createInstance.js +24 -25
- package/esm/createInstance.js.map +1 -1
- package/esm/helpers.d.ts +11 -26
- package/esm/helpers.js +18 -56
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/action.js +1 -1
- package/esm/hooks/action.js.map +1 -1
- package/esm/hooks/actions.js +1 -1
- package/esm/hooks/actions.js.map +1 -1
- package/esm/hooks/globalState.js +5 -5
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +0 -5
- package/esm/hooks/index.js +0 -5
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/media.js +8 -7
- package/esm/hooks/media.js.map +1 -1
- package/esm/hooks/setter.js +3 -2
- package/esm/hooks/setter.js.map +1 -1
- package/esm/hooks/sharedData.js +2 -2
- package/esm/hooks/sharedData.js.map +1 -1
- package/esm/modules/api.js +79 -28
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/dependencies.d.ts +3 -4
- package/esm/modules/dependencies.js +11 -14
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/state/createActions.js +7 -12
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.js +6 -8
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/state/stateContext.js +1 -1
- package/esm/state/stateContext.js.map +1 -1
- package/esm/state/withApi.js +59 -62
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/config.d.ts +23 -16
- package/esm/types/state.d.ts +13 -0
- package/esm/utils/compare.js +4 -4
- package/esm/utils/compare.js.map +1 -1
- package/esm/utils/data.js +6 -7
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/foreign.d.ts +4 -2
- package/esm/utils/foreign.js +16 -8
- package/esm/utils/foreign.js.map +1 -1
- package/esm/utils/guid.js +3 -3
- package/esm/utils/guid.js.map +1 -1
- package/esm/utils/helpers.d.ts +11 -8
- package/esm/utils/helpers.js +28 -17
- package/esm/utils/helpers.js.map +1 -1
- package/esm/utils/media.js +8 -7
- package/esm/utils/media.js.map +1 -1
- package/esm/utils/storage.js +13 -14
- package/esm/utils/storage.js.map +1 -1
- package/lib/Piral.js +9 -11
- package/lib/Piral.js.map +1 -1
- package/lib/actions/app.js +11 -12
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/components.js +5 -6
- package/lib/actions/components.js.map +1 -1
- package/lib/actions/data.js +17 -18
- package/lib/actions/data.js.map +1 -1
- package/lib/actions/define.js +2 -3
- package/lib/actions/define.js.map +1 -1
- package/lib/actions/index.js +7 -7
- package/lib/actions/index.js.map +1 -1
- package/lib/actions/portal.d.ts +2 -0
- package/lib/actions/portal.js +12 -5
- package/lib/actions/portal.js.map +1 -1
- package/lib/actions/state.js +3 -3
- package/lib/actions/state.js.map +1 -1
- package/lib/components/DefaultErrorInfo.js +4 -5
- package/lib/components/DefaultErrorInfo.js.map +1 -1
- package/lib/components/DefaultLayout.js +2 -5
- package/lib/components/DefaultLayout.js.map +1 -1
- package/lib/components/DefaultLoader.js +2 -2
- package/lib/components/DefaultLoader.js.map +1 -1
- package/lib/components/ErrorBoundary.js +18 -22
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/ExtensionSlot.js +10 -14
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/Mediator.js +11 -11
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/PiralRoutes.js +11 -11
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralView.js +16 -21
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/PortalRenderer.d.ts +5 -0
- package/lib/components/PortalRenderer.js +11 -0
- package/lib/components/PortalRenderer.js.map +1 -0
- package/lib/components/ResponsiveLayout.js +9 -10
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SetComponent.js +4 -5
- package/lib/components/SetComponent.js.map +1 -1
- package/lib/components/SetError.js +4 -5
- package/lib/components/SetError.js.map +1 -1
- package/lib/components/SetErrors.js +4 -5
- package/lib/components/SetErrors.js.map +1 -1
- package/lib/components/SetLayout.js +4 -5
- package/lib/components/SetLayout.js.map +1 -1
- package/lib/components/SetProvider.js +4 -5
- package/lib/components/SetProvider.js.map +1 -1
- package/lib/components/SetRedirect.js +6 -7
- package/lib/components/SetRedirect.js.map +1 -1
- package/lib/components/SetRoute.js +4 -5
- package/lib/components/SetRoute.js.map +1 -1
- package/lib/components/SwitchErrorInfo.js +14 -12
- package/lib/components/SwitchErrorInfo.js.map +1 -1
- package/lib/components/components.js +5 -6
- package/lib/components/components.js.map +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +20 -19
- package/lib/components/index.js.map +1 -1
- package/lib/createInstance.js +31 -32
- package/lib/createInstance.js.map +1 -1
- package/lib/helpers.d.ts +11 -26
- package/lib/helpers.js +19 -59
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/action.js +3 -3
- package/lib/hooks/action.js.map +1 -1
- package/lib/hooks/actions.js +4 -4
- package/lib/hooks/actions.js.map +1 -1
- package/lib/hooks/globalState.js +8 -8
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +0 -5
- package/lib/hooks/index.js +7 -12
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/media.js +10 -9
- package/lib/hooks/media.js.map +1 -1
- package/lib/hooks/setter.js +4 -3
- package/lib/hooks/setter.js.map +1 -1
- package/lib/hooks/sharedData.js +3 -3
- package/lib/hooks/sharedData.js.map +1 -1
- package/lib/index.js +9 -9
- package/lib/index.js.map +1 -1
- package/lib/modules/api.js +86 -35
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/dependencies.d.ts +3 -4
- package/lib/modules/dependencies.js +13 -16
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/modules/index.js +3 -3
- package/lib/modules/index.js.map +1 -1
- package/lib/state/createActions.js +8 -13
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.js +9 -11
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/index.js +5 -5
- package/lib/state/index.js.map +1 -1
- package/lib/state/stateContext.js +1 -1
- package/lib/state/stateContext.js.map +1 -1
- package/lib/state/withApi.js +67 -70
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/config.d.ts +23 -16
- package/lib/types/index.js +13 -13
- package/lib/types/index.js.map +1 -1
- package/lib/types/state.d.ts +13 -0
- package/lib/utils/compare.js +4 -4
- package/lib/utils/compare.js.map +1 -1
- package/lib/utils/data.js +6 -7
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/foreign.d.ts +4 -2
- package/lib/utils/foreign.js +21 -11
- package/lib/utils/foreign.js.map +1 -1
- package/lib/utils/guid.js +3 -3
- package/lib/utils/guid.js.map +1 -1
- package/lib/utils/helpers.d.ts +11 -8
- package/lib/utils/helpers.js +30 -17
- package/lib/utils/helpers.js.map +1 -1
- package/lib/utils/index.js +9 -9
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/media.js +7 -6
- package/lib/utils/media.js.map +1 -1
- package/lib/utils/react.js +1 -1
- package/lib/utils/react.js.map +1 -1
- package/lib/utils/storage.js +11 -12
- package/lib/utils/storage.js.map +1 -1
- package/package.json +12 -5
- package/src/Piral.tsx +2 -1
- package/src/actions/portal.ts +19 -1
- package/src/components/ExtensionSlot.tsx +2 -2
- package/src/components/Mediator.tsx +2 -1
- package/src/components/PortalRenderer.tsx +12 -0
- package/src/components/SwitchErrorInfo.tsx +5 -1
- package/src/components/index.ts +1 -0
- package/src/createInstance.tsx +6 -7
- package/src/helpers.test.tsx +7 -39
- package/src/helpers.tsx +32 -85
- package/src/hooks/index.ts +0 -5
- package/src/hooks/media.ts +2 -1
- package/src/hooks/setter.ts +2 -1
- package/src/modules/api.ts +72 -4
- package/src/modules/dependencies.test.ts +18 -5
- package/src/modules/dependencies.ts +12 -18
- package/src/state/withApi.tsx +12 -14
- package/src/types/config.ts +23 -17
- package/src/types/state.ts +13 -0
- package/src/utils/foreign.test.ts +4 -4
- package/src/utils/foreign.ts +28 -5
- package/src/utils/helpers.ts +21 -7
- package/src/utils/media.ts +2 -1
- package/esm/hooks/debounce.d.ts +0 -8
- package/esm/hooks/debounce.js +0 -18
- package/esm/hooks/debounce.js.map +0 -1
- package/esm/hooks/lockBodyScroll.d.ts +0 -6
- package/esm/hooks/lockBodyScroll.js +0 -15
- package/esm/hooks/lockBodyScroll.js.map +0 -1
- package/esm/hooks/onClickOutside.d.ts +0 -8
- package/esm/hooks/onClickOutside.js +0 -23
- package/esm/hooks/onClickOutside.js.map +0 -1
- package/esm/hooks/onScreenVisible.d.ts +0 -11
- package/esm/hooks/onScreenVisible.js +0 -28
- package/esm/hooks/onScreenVisible.js.map +0 -1
- package/esm/hooks/promise.d.ts +0 -13
- package/esm/hooks/promise.js +0 -21
- package/esm/hooks/promise.js.map +0 -1
- package/lib/hooks/debounce.d.ts +0 -8
- package/lib/hooks/debounce.js +0 -22
- package/lib/hooks/debounce.js.map +0 -1
- package/lib/hooks/lockBodyScroll.d.ts +0 -6
- package/lib/hooks/lockBodyScroll.js +0 -19
- package/lib/hooks/lockBodyScroll.js.map +0 -1
- package/lib/hooks/onClickOutside.d.ts +0 -8
- package/lib/hooks/onClickOutside.js +0 -27
- package/lib/hooks/onClickOutside.js.map +0 -1
- package/lib/hooks/onScreenVisible.d.ts +0 -11
- package/lib/hooks/onScreenVisible.js +0 -32
- package/lib/hooks/onScreenVisible.js.map +0 -1
- package/lib/hooks/promise.d.ts +0 -13
- package/lib/hooks/promise.js +0 -25
- package/lib/hooks/promise.js.map +0 -1
- package/src/hooks/debounce.test.ts +0 -67
- package/src/hooks/debounce.ts +0 -19
- package/src/hooks/lockBodyScroll.test.ts +0 -24
- package/src/hooks/lockBodyScroll.ts +0 -15
- package/src/hooks/onClickOutside.test.ts +0 -113
- package/src/hooks/onClickOutside.ts +0 -25
- package/src/hooks/onScreenVisible.test.ts +0 -68
- package/src/hooks/onScreenVisible.ts +0 -28
- package/src/hooks/promise.test.ts +0 -76
- package/src/hooks/promise.ts +0 -35
package/src/Piral.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { StateContext } from './state';
|
|
3
3
|
import { createInstance } from './createInstance';
|
|
4
|
-
import { PiralView, Mediator, ResponsiveLayout } from './components';
|
|
4
|
+
import { PiralView, Mediator, ResponsiveLayout, PortalRenderer } from './components';
|
|
5
5
|
import type { PortalProps } from './types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -21,6 +21,7 @@ const app = (
|
|
|
21
21
|
*/
|
|
22
22
|
export const Piral: React.FC<PortalProps> = ({ instance = createInstance(), breakpoints, children }) => (
|
|
23
23
|
<StateContext.Provider value={instance.context}>
|
|
24
|
+
<PortalRenderer id="root" />
|
|
24
25
|
<ResponsiveLayout breakpoints={breakpoints} />
|
|
25
26
|
<Mediator options={instance.options} />
|
|
26
27
|
<PiralView>{children}</PiralView>
|
package/src/actions/portal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactPortal } from 'react';
|
|
2
|
-
import { withoutKey, includeItem,
|
|
2
|
+
import { withoutKey, withKey, includeItem, excludeItem, replaceOrAddItem } from '../utils';
|
|
3
3
|
import { GlobalStateContext } from '../types';
|
|
4
4
|
|
|
5
5
|
export function destroyPortal(ctx: GlobalStateContext, id: string) {
|
|
@@ -9,6 +9,24 @@ export function destroyPortal(ctx: GlobalStateContext, id: string) {
|
|
|
9
9
|
}));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export function hidePortal(ctx: GlobalStateContext, id: string, entry: ReactPortal) {
|
|
13
|
+
ctx.dispatch((state) => ({
|
|
14
|
+
...state,
|
|
15
|
+
portals: withKey(state.portals, id, excludeItem(state.portals[id], entry)),
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function updatePortal(ctx: GlobalStateContext, id: string, current: ReactPortal, next: ReactPortal) {
|
|
20
|
+
ctx.dispatch((state) => ({
|
|
21
|
+
...state,
|
|
22
|
+
portals: withKey(
|
|
23
|
+
state.portals,
|
|
24
|
+
id,
|
|
25
|
+
replaceOrAddItem(state.portals[id], next, (m) => m === current),
|
|
26
|
+
),
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
export function showPortal(ctx: GlobalStateContext, id: string, entry: ReactPortal) {
|
|
13
31
|
ctx.dispatch((state) => ({
|
|
14
32
|
...state,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { isfunc } from 'piral-base';
|
|
3
3
|
import { useGlobalState } from '../hooks';
|
|
4
|
-
import { defaultRender } from '../utils';
|
|
4
|
+
import { defaultRender, none } from '../utils';
|
|
5
5
|
import { ExtensionSlotProps } from '../types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -11,7 +11,7 @@ import { ExtensionSlotProps } from '../types';
|
|
|
11
11
|
*/
|
|
12
12
|
export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
|
|
13
13
|
const { name, render = defaultRender, empty, params } = props;
|
|
14
|
-
const extensions = useGlobalState((s) => s.registry.extensions[name] ||
|
|
14
|
+
const extensions = useGlobalState((s) => s.registry.extensions[name] || none);
|
|
15
15
|
return render(
|
|
16
16
|
extensions.length === 0 && isfunc(empty)
|
|
17
17
|
? [defaultRender(empty(), 'empty')]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { LoadPiletsOptions, startLoadingPilets, PiletsLoading } from 'piral-base';
|
|
3
3
|
import { useAction } from '../hooks';
|
|
4
|
+
import { none } from '../utils';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The props of the Mediator component.
|
|
@@ -24,7 +25,7 @@ export const Mediator: React.FC<MediatorProps> = ({ options }) => {
|
|
|
24
25
|
};
|
|
25
26
|
connect(notifier);
|
|
26
27
|
return () => disconnect(notifier);
|
|
27
|
-
},
|
|
28
|
+
}, none);
|
|
28
29
|
// tslint:disable-next-line:no-null-keyword
|
|
29
30
|
return null;
|
|
30
31
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useGlobalState } from '../hooks';
|
|
3
|
+
import { defaultRender, none } from '../utils';
|
|
4
|
+
|
|
5
|
+
export interface PortalRendererProps {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PortalRenderer: React.FC<PortalRendererProps> = ({ id }) => {
|
|
10
|
+
const children = useGlobalState((m) => m.portals[id]) || none;
|
|
11
|
+
return defaultRender(children);
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useGlobalState } from '../hooks';
|
|
3
|
-
import { defaultRender } from '../utils';
|
|
3
|
+
import { defaultRender, none } from '../utils';
|
|
4
4
|
import { ErrorComponentsState, Errors, ErrorInfoProps } from '../types';
|
|
5
5
|
|
|
6
6
|
function renderComponent<TKey extends keyof ErrorComponentsState>(
|
|
@@ -10,6 +10,10 @@ function renderComponent<TKey extends keyof ErrorComponentsState>(
|
|
|
10
10
|
const name = props.type;
|
|
11
11
|
const Component = components[name];
|
|
12
12
|
|
|
13
|
+
if (process.env.NODE_ENV === 'development') {
|
|
14
|
+
React.useEffect(() => console.error('[dev-info] An error occurred in the Piral instance.', props), none);
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
if (!Component) {
|
|
14
18
|
const Unknown = components.unknown;
|
|
15
19
|
|
package/src/components/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './ExtensionSlot';
|
|
|
7
7
|
export * from './Mediator';
|
|
8
8
|
export * from './PiralRoutes';
|
|
9
9
|
export * from './PiralView';
|
|
10
|
+
export * from './PortalRenderer';
|
|
10
11
|
export * from './ResponsiveLayout';
|
|
11
12
|
export * from './SetComponent';
|
|
12
13
|
export * from './SetError';
|
package/src/createInstance.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
2
|
import { blazingStrategy, standardStrategy, createListener, isfunc } from 'piral-base';
|
|
3
|
-
import {
|
|
3
|
+
import { defaultApiFactory, defaultDependencySelector, defaultModuleRequester } from './modules';
|
|
4
4
|
import { createGlobalState, createActions, includeActions } from './state';
|
|
5
5
|
import { createPiletOptions } from './helpers';
|
|
6
6
|
import type { PiralConfiguration, PiralInstance } from './types';
|
|
@@ -30,21 +30,20 @@ export function createInstance(config: PiralConfiguration = {}): PiralInstance {
|
|
|
30
30
|
state,
|
|
31
31
|
actions,
|
|
32
32
|
availablePilets = [],
|
|
33
|
-
extendApi,
|
|
34
33
|
plugins,
|
|
35
34
|
requestPilets = defaultModuleRequester,
|
|
36
|
-
fetchDependency,
|
|
37
|
-
getDependencies = getLocalDependencies,
|
|
38
35
|
loaderConfig,
|
|
39
36
|
async = false,
|
|
37
|
+
shareDependencies = defaultDependencySelector,
|
|
40
38
|
loadPilet,
|
|
41
39
|
loaders,
|
|
40
|
+
debug,
|
|
42
41
|
apiFactory = defaultApiFactory,
|
|
43
42
|
} = config;
|
|
44
43
|
const globalState = createGlobalState(state);
|
|
45
44
|
const events = createListener(globalState);
|
|
46
45
|
const context = createActions(globalState, events);
|
|
47
|
-
const definedPlugins = plugins ||
|
|
46
|
+
const definedPlugins = plugins || [];
|
|
48
47
|
const usedPlugins = Array.isArray(definedPlugins) ? definedPlugins : [definedPlugins];
|
|
49
48
|
const createApi = apiFactory(context, usedPlugins);
|
|
50
49
|
const root = createApi({
|
|
@@ -58,11 +57,11 @@ export function createInstance(config: PiralConfiguration = {}): PiralInstance {
|
|
|
58
57
|
loaders,
|
|
59
58
|
loadPilet,
|
|
60
59
|
availablePilets,
|
|
61
|
-
fetchDependency,
|
|
62
60
|
loaderConfig,
|
|
63
|
-
|
|
61
|
+
shareDependencies,
|
|
64
62
|
strategy: isfunc(async) ? async : async ? blazingStrategy : standardStrategy,
|
|
65
63
|
requestPilets,
|
|
64
|
+
debug,
|
|
66
65
|
});
|
|
67
66
|
|
|
68
67
|
if (actions) {
|
package/src/helpers.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createPiletOptions, PiletOptionsConfig
|
|
1
|
+
import { createPiletOptions, PiletOptionsConfig } from './helpers';
|
|
2
2
|
import { globalDependencies } from './modules';
|
|
3
|
-
import { PiletMetadata
|
|
3
|
+
import { PiletMetadata } from 'piral-base';
|
|
4
4
|
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
5
5
|
|
|
6
6
|
function createMockApi(meta: PiletMetadata) {
|
|
@@ -16,6 +16,7 @@ function createMockContainer() {
|
|
|
16
16
|
const state = Atom.of({
|
|
17
17
|
registry: {
|
|
18
18
|
pages: {},
|
|
19
|
+
extensions: {},
|
|
19
20
|
wrappers: {},
|
|
20
21
|
},
|
|
21
22
|
routes: {},
|
|
@@ -48,35 +49,6 @@ function createMockContainer() {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
describe('Piral-Core helpers module', () => {
|
|
51
|
-
it('setSharedDependencies set the shared dependecies', () => {
|
|
52
|
-
// Arrange
|
|
53
|
-
const dependencies: AvailableDependencies = {
|
|
54
|
-
gg: {},
|
|
55
|
-
ff: {},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Act
|
|
59
|
-
const dependencyGetter = setSharedDependencies(dependencies);
|
|
60
|
-
const result = dependencyGetter();
|
|
61
|
-
|
|
62
|
-
// Assert
|
|
63
|
-
expect(result).not.toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('extendSharedDependencies should extend the dependecies', () => {
|
|
67
|
-
// Arrange
|
|
68
|
-
const additionalDependencies: AvailableDependencies = {
|
|
69
|
-
gg: {},
|
|
70
|
-
ff: {},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Act
|
|
74
|
-
const extendedDependecies = extendSharedDependencies(additionalDependencies);
|
|
75
|
-
|
|
76
|
-
// Assert
|
|
77
|
-
expect(extendedDependecies).not.toBeUndefined();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
52
|
it('createPiletOptions creates the options using the provided pilets', () => {
|
|
81
53
|
const wasUndefined = process.env.DEBUG_PIRAL === undefined;
|
|
82
54
|
|
|
@@ -102,9 +74,8 @@ describe('Piral-Core helpers module', () => {
|
|
|
102
74
|
const optionsConfig: PiletOptionsConfig = {
|
|
103
75
|
createApi: createMockApi,
|
|
104
76
|
availablePilets: providedPilets,
|
|
77
|
+
shareDependencies: jest.fn(deps => deps),
|
|
105
78
|
context: globalContext,
|
|
106
|
-
fetchDependency: jest.fn(),
|
|
107
|
-
getDependencies: jest.fn(),
|
|
108
79
|
loadPilet: jest.fn(),
|
|
109
80
|
requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
|
|
110
81
|
strategy: jest.fn(),
|
|
@@ -143,8 +114,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
143
114
|
createApi: createMockApi,
|
|
144
115
|
availablePilets: providedPilets,
|
|
145
116
|
context: globalContext,
|
|
146
|
-
|
|
147
|
-
getDependencies: () => globalDependencies,
|
|
117
|
+
shareDependencies: jest.fn(deps => deps),
|
|
148
118
|
loadPilet: jest.fn(),
|
|
149
119
|
requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
|
|
150
120
|
strategy: jest.fn(),
|
|
@@ -183,8 +153,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
183
153
|
createApi: createMockApi,
|
|
184
154
|
availablePilets: providedPilets,
|
|
185
155
|
context: globalContext,
|
|
186
|
-
|
|
187
|
-
getDependencies: jest.fn(),
|
|
156
|
+
shareDependencies: jest.fn(deps => deps),
|
|
188
157
|
loadPilet: jest.fn(),
|
|
189
158
|
requestPilets: requestPilets,
|
|
190
159
|
strategy: jest.fn(),
|
|
@@ -238,8 +207,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
238
207
|
createApi: createMockApi,
|
|
239
208
|
availablePilets: providedPilets,
|
|
240
209
|
context: globalContext,
|
|
241
|
-
|
|
242
|
-
getDependencies: jest.fn(),
|
|
210
|
+
shareDependencies: jest.fn(deps => deps),
|
|
243
211
|
loadPilet: jest.fn(),
|
|
244
212
|
requestPilets: requestPilets,
|
|
245
213
|
strategy: jest.fn(),
|
package/src/helpers.tsx
CHANGED
|
@@ -1,115 +1,62 @@
|
|
|
1
|
-
import { addChangeHandler } from '@dbeining/react-atom';
|
|
2
1
|
import {
|
|
3
2
|
PiletApiCreator,
|
|
4
3
|
LoadPiletsOptions,
|
|
5
4
|
CustomSpecLoaders,
|
|
6
5
|
DefaultLoaderConfig,
|
|
7
|
-
PiletDependencyFetcher,
|
|
8
|
-
getDependencyResolver,
|
|
9
6
|
getDefaultLoader,
|
|
10
7
|
extendLoader,
|
|
11
8
|
PiletLoader,
|
|
12
9
|
} from 'piral-base';
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
Pilet,
|
|
17
|
-
PiletRequester,
|
|
18
|
-
GlobalStateContext,
|
|
19
|
-
PiletDependencyGetter,
|
|
20
|
-
PiletLoadingStrategy,
|
|
21
|
-
} from './types';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates a dependency getter that sets the shared dependencies explicitly.
|
|
25
|
-
* Overrides the potentially set shared dependencies from the Piral CLI, but
|
|
26
|
-
* keeps all global dependencies such as react, react-dom, ...
|
|
27
|
-
* @param sharedDependencies The shared dependencies to declare.
|
|
28
|
-
*/
|
|
29
|
-
export function setSharedDependencies(sharedDependencies: AvailableDependencies) {
|
|
30
|
-
const dependencies = {
|
|
31
|
-
...globalDependencies,
|
|
32
|
-
...sharedDependencies,
|
|
33
|
-
};
|
|
34
|
-
return () => dependencies;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a dependency getter that extends the shared dependencies with additional dependencies.
|
|
39
|
-
* @param additionalDependencies The additional dependencies to declare.
|
|
40
|
-
*/
|
|
41
|
-
export function extendSharedDependencies(additionalDependencies: AvailableDependencies) {
|
|
42
|
-
const dependencies = {
|
|
43
|
-
...getLocalDependencies(),
|
|
44
|
-
...additionalDependencies,
|
|
45
|
-
};
|
|
46
|
-
return () => dependencies;
|
|
47
|
-
}
|
|
10
|
+
import { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
11
|
+
import { globalDependencies } from './modules';
|
|
12
|
+
import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
|
|
48
13
|
|
|
49
14
|
export interface PiletOptionsConfig {
|
|
15
|
+
context: GlobalStateContext;
|
|
16
|
+
loaders?: CustomSpecLoaders;
|
|
17
|
+
loaderConfig?: DefaultLoaderConfig;
|
|
50
18
|
availablePilets: Array<Pilet>;
|
|
51
|
-
createApi: PiletApiCreator;
|
|
52
|
-
fetchDependency: PiletDependencyFetcher;
|
|
53
|
-
getDependencies: PiletDependencyGetter;
|
|
54
19
|
strategy: PiletLoadingStrategy;
|
|
55
|
-
|
|
56
|
-
loaderConfig?: DefaultLoaderConfig;
|
|
57
|
-
loaders?: CustomSpecLoaders;
|
|
20
|
+
createApi: PiletApiCreator;
|
|
58
21
|
loadPilet: PiletLoader;
|
|
59
|
-
|
|
22
|
+
requestPilets: PiletRequester;
|
|
23
|
+
shareDependencies: DependencySelector;
|
|
24
|
+
debug?: DebuggerExtensionOptions;
|
|
60
25
|
}
|
|
61
26
|
|
|
62
27
|
export function createPiletOptions({
|
|
63
28
|
context,
|
|
64
|
-
|
|
65
|
-
availablePilets,
|
|
66
|
-
fetchDependency,
|
|
67
|
-
getDependencies,
|
|
29
|
+
loaders,
|
|
68
30
|
loaderConfig,
|
|
69
|
-
|
|
31
|
+
availablePilets,
|
|
70
32
|
strategy,
|
|
71
|
-
|
|
33
|
+
createApi,
|
|
34
|
+
loadPilet,
|
|
72
35
|
requestPilets,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
shareDependencies,
|
|
37
|
+
debug,
|
|
38
|
+
}: PiletOptionsConfig) {
|
|
39
|
+
const options: LoadPiletsOptions = {
|
|
40
|
+
config: loaderConfig,
|
|
41
|
+
strategy,
|
|
42
|
+
loadPilet: extendLoader(loadPilet ?? getDefaultLoader(loaderConfig), loaders),
|
|
43
|
+
createApi,
|
|
44
|
+
pilets: availablePilets,
|
|
45
|
+
fetchPilets: requestPilets,
|
|
46
|
+
dependencies: shareDependencies(globalDependencies),
|
|
47
|
+
};
|
|
76
48
|
|
|
77
49
|
// if we build the debug version of piral (debug and emulator build)
|
|
78
50
|
if (process.env.DEBUG_PIRAL) {
|
|
79
|
-
const {
|
|
80
|
-
|
|
81
|
-
installPiralDebug({
|
|
82
|
-
context,
|
|
83
|
-
createApi,
|
|
84
|
-
getDependencies,
|
|
85
|
-
loadPilet,
|
|
86
|
-
requestPilets,
|
|
87
|
-
onChange(cb: (previous: any, current: any) => void) {
|
|
88
|
-
addChangeHandler(context.state, 'debugging', ({ previous, current }) => {
|
|
89
|
-
cb(previous, current);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
});
|
|
51
|
+
const { integrate } = require('../debug-piral');
|
|
52
|
+
integrate(context, options, debug);
|
|
93
53
|
}
|
|
94
54
|
|
|
55
|
+
// if we build the emulator version of piral (shipped to pilets)
|
|
95
56
|
if (process.env.DEBUG_PILET) {
|
|
96
|
-
const {
|
|
97
|
-
|
|
98
|
-
requestPilets = withEmulatorPilets(requestPilets, {
|
|
99
|
-
inject: context.injectPilet,
|
|
100
|
-
createApi,
|
|
101
|
-
loadPilet,
|
|
102
|
-
});
|
|
57
|
+
const { integrate } = require('../debug-pilet');
|
|
58
|
+
integrate(context, options);
|
|
103
59
|
}
|
|
104
60
|
|
|
105
|
-
return
|
|
106
|
-
config: loaderConfig,
|
|
107
|
-
strategy,
|
|
108
|
-
loadPilet,
|
|
109
|
-
createApi,
|
|
110
|
-
getDependencies,
|
|
111
|
-
pilets: availablePilets,
|
|
112
|
-
fetchPilets: requestPilets,
|
|
113
|
-
dependencies: globalDependencies,
|
|
114
|
-
};
|
|
61
|
+
return options;
|
|
115
62
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
export * from './action';
|
|
2
2
|
export * from './actions';
|
|
3
|
-
export * from './debounce';
|
|
4
3
|
export * from './globalState';
|
|
5
|
-
export * from './lockBodyScroll';
|
|
6
4
|
export * from './media';
|
|
7
|
-
export * from './onClickOutside';
|
|
8
|
-
export * from './onScreenVisible';
|
|
9
|
-
export * from './promise';
|
|
10
5
|
export * from './setter';
|
|
11
6
|
export * from './sharedData';
|
package/src/hooks/media.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
+
import { none } from '../utils/helpers';
|
|
2
3
|
import { getCurrentLayout } from '../utils/media';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -17,7 +18,7 @@ export function useMedia<T>(queries: Array<string>, values: Array<T>, defaultVal
|
|
|
17
18
|
window.addEventListener('resize', handler);
|
|
18
19
|
return () => window.removeEventListener('resize', handler);
|
|
19
20
|
}
|
|
20
|
-
},
|
|
21
|
+
}, none);
|
|
21
22
|
|
|
22
23
|
return value;
|
|
23
24
|
}
|
package/src/hooks/setter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect as useSideEffect } from 'react';
|
|
2
|
+
import { none } from '../utils/helpers';
|
|
2
3
|
|
|
3
4
|
function useMainEffect(cb: () => void) {
|
|
4
5
|
cb();
|
|
@@ -11,5 +12,5 @@ const useEffect = typeof window !== 'undefined' ? useSideEffect : useMainEffect;
|
|
|
11
12
|
* @param cb The callback to be invoked on mounting.
|
|
12
13
|
*/
|
|
13
14
|
export function useSetter(cb: () => void) {
|
|
14
|
-
useEffect(cb,
|
|
15
|
+
useEffect(cb, none);
|
|
15
16
|
}
|
package/src/modules/api.ts
CHANGED
|
@@ -2,10 +2,78 @@ import { isfunc, PiletApiCreator, PiletApiExtender, initializeApi, mergeApis } f
|
|
|
2
2
|
import { __assign } from 'tslib';
|
|
3
3
|
import { withApi } from '../state';
|
|
4
4
|
import { ExtensionSlot } from '../components';
|
|
5
|
-
import { createDataOptions, getDataExpiration, renderInDom } from '../utils';
|
|
6
|
-
import { GlobalStateContext, PiletCoreApi, PiralPlugin } from '../types';
|
|
5
|
+
import { createDataOptions, getDataExpiration, renderInDom, tryParseJson, changeDomPortal, noop } from '../utils';
|
|
6
|
+
import { Disposable, GlobalStateContext, PiletCoreApi, PiralPlugin } from '../types';
|
|
7
|
+
|
|
8
|
+
interface Updatable {
|
|
9
|
+
(newProps: any): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if ('customElements' in window) {
|
|
13
|
+
class PiralExtension extends HTMLElement {
|
|
14
|
+
dispose: Disposable = noop;
|
|
15
|
+
update: Updatable = noop;
|
|
16
|
+
|
|
17
|
+
getProps() {
|
|
18
|
+
const name = this.getAttribute('name');
|
|
19
|
+
const params = tryParseJson(this.getAttribute('params'));
|
|
20
|
+
return { name, params };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
if (this.isConnected) {
|
|
25
|
+
this.dispatchEvent(
|
|
26
|
+
new CustomEvent('render-html', {
|
|
27
|
+
bubbles: true,
|
|
28
|
+
detail: {
|
|
29
|
+
target: this,
|
|
30
|
+
props: this.getProps(),
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this.dispose();
|
|
39
|
+
this.dispose = noop;
|
|
40
|
+
this.update = noop;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
attributeChangedCallback() {
|
|
44
|
+
this.update(this.getProps());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static get observedAttributes() {
|
|
48
|
+
return ['name', 'params'];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
customElements.define('piral-extension', PiralExtension);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function render(context: GlobalStateContext, element: HTMLElement | ShadowRoot, props: any): [Disposable, Updatable] {
|
|
56
|
+
let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
|
|
57
|
+
const dispose: Disposable = () => context.hidePortal(id, portal);
|
|
58
|
+
const update: Updatable = (newProps) => {
|
|
59
|
+
[id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
|
|
60
|
+
};
|
|
61
|
+
return [dispose, update];
|
|
62
|
+
}
|
|
7
63
|
|
|
8
64
|
export function createCoreApi(context: GlobalStateContext): PiletApiExtender<PiletCoreApi> {
|
|
65
|
+
document.body.addEventListener(
|
|
66
|
+
'render-html',
|
|
67
|
+
(ev: CustomEvent) => {
|
|
68
|
+
ev.stopPropagation();
|
|
69
|
+
const container = ev.detail.target;
|
|
70
|
+
const [dispose, update] = render(context, container, ev.detail.props);
|
|
71
|
+
container.dispose = dispose;
|
|
72
|
+
container.update = update;
|
|
73
|
+
},
|
|
74
|
+
false,
|
|
75
|
+
);
|
|
76
|
+
|
|
9
77
|
return (api, target) => {
|
|
10
78
|
const pilet = target.name;
|
|
11
79
|
return {
|
|
@@ -41,8 +109,8 @@ export function createCoreApi(context: GlobalStateContext): PiletApiExtender<Pil
|
|
|
41
109
|
context.unregisterExtension(name as string, arg);
|
|
42
110
|
},
|
|
43
111
|
renderHtmlExtension(element, props) {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
112
|
+
const [dispose] = render(context, element, props);
|
|
113
|
+
return dispose;
|
|
46
114
|
},
|
|
47
115
|
Extension: ExtensionSlot,
|
|
48
116
|
};
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globalDependencies, defaultDependencySelector, defaultModuleRequester } from './dependencies';
|
|
2
2
|
|
|
3
3
|
describe('Dependencies Module', () => {
|
|
4
|
-
it('
|
|
5
|
-
|
|
6
|
-
expect(
|
|
7
|
-
expect(
|
|
4
|
+
it('globalDependencies should contain global dependencies', () => {
|
|
5
|
+
expect(globalDependencies).toHaveProperty('react');
|
|
6
|
+
expect(globalDependencies).toHaveProperty('history');
|
|
7
|
+
expect(globalDependencies).not.toHaveProperty('foo');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('defaultDependencySelector should return given dependencies', () => {
|
|
11
|
+
const deps = defaultDependencySelector({
|
|
12
|
+
foo: 'bar',
|
|
13
|
+
});
|
|
14
|
+
expect(deps).toHaveProperty('foo');
|
|
15
|
+
expect(deps).not.toHaveProperty('bar');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('defaultModuleRequester should return given dependencies', async () => {
|
|
19
|
+
const mods = await defaultModuleRequester();
|
|
20
|
+
expect(mods).toEqual([]);
|
|
8
21
|
});
|
|
9
22
|
});
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { PiletMetadata, AvailableDependencies, isfunc } from 'piral-base';
|
|
2
2
|
|
|
3
|
-
const sharedDependencies: AvailableDependencies = {};
|
|
4
|
-
|
|
5
|
-
if (process.env.SHARED_DEPENDENCIES) {
|
|
6
|
-
const fillDependencies = require('../../dependencies.codegen');
|
|
7
|
-
|
|
8
|
-
if (isfunc(fillDependencies)) {
|
|
9
|
-
fillDependencies(sharedDependencies);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
/**
|
|
14
4
|
* The global dependencies, which represent the dependencies
|
|
15
|
-
*
|
|
5
|
+
* shared from the app shell itself.
|
|
16
6
|
*/
|
|
17
7
|
export const globalDependencies: AvailableDependencies = {
|
|
18
8
|
react: require('react'),
|
|
@@ -26,16 +16,20 @@ export const globalDependencies: AvailableDependencies = {
|
|
|
26
16
|
'@dbeining/react-atom': require('@dbeining/react-atom'),
|
|
27
17
|
};
|
|
28
18
|
|
|
19
|
+
if (process.env.SHARED_DEPENDENCIES) {
|
|
20
|
+
const fillDependencies = require('../../dependencies.codegen');
|
|
21
|
+
|
|
22
|
+
if (isfunc(fillDependencies)) {
|
|
23
|
+
fillDependencies(globalDependencies);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
31
|
-
* are the global dependencies and the implicitly shared
|
|
28
|
+
* The default dependency selector, which just returns the provided
|
|
32
29
|
* dependencies.
|
|
33
30
|
*/
|
|
34
|
-
export function
|
|
35
|
-
return
|
|
36
|
-
...globalDependencies,
|
|
37
|
-
...sharedDependencies,
|
|
38
|
-
};
|
|
31
|
+
export function defaultDependencySelector(dependencies: AvailableDependencies) {
|
|
32
|
+
return dependencies;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
/**
|