piral-core 0.15.0-alpha.4034 → 0.15.0-alpha.4098
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 +14 -12
- package/esm/Piral.js.map +1 -1
- package/esm/PiralContext.d.ts +21 -0
- package/esm/PiralContext.js +34 -0
- package/esm/PiralContext.js.map +1 -0
- package/esm/actions/app.d.ts +1 -2
- package/esm/actions/app.js +0 -3
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/state.js +5 -1
- package/esm/actions/state.js.map +1 -1
- package/esm/components/ErrorBoundary.d.ts +4 -0
- package/esm/components/ErrorBoundary.js +3 -3
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/components/PiralGlobals.d.ts +6 -0
- package/esm/components/PiralGlobals.js +13 -0
- package/esm/components/PiralGlobals.js.map +1 -0
- package/esm/components/PiralSuspense.d.ts +5 -0
- package/esm/components/PiralSuspense.js +8 -0
- package/esm/components/PiralSuspense.js.map +1 -0
- package/esm/components/PiralView.d.ts +10 -1
- package/esm/components/PiralView.js +12 -24
- package/esm/components/PiralView.js.map +1 -1
- package/esm/components/ResponsiveLayout.d.ts +9 -1
- package/esm/components/ResponsiveLayout.js +5 -12
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/components.d.ts +13 -6
- package/esm/components/components.js +13 -6
- package/esm/components/components.js.map +1 -1
- package/esm/components/index.d.ts +2 -12
- package/esm/components/index.js +2 -12
- package/esm/components/index.js.map +1 -1
- package/esm/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/esm/{components → defaults}/DefaultErrorInfo.js +1 -2
- package/esm/defaults/DefaultErrorInfo.js.map +1 -0
- package/esm/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/esm/{components → defaults}/DefaultLayout.js +0 -0
- package/esm/defaults/DefaultLayout.js.map +1 -0
- package/esm/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/esm/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +1 -1
- package/esm/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/esm/{components → defaults}/DefaultRouteSwitch.d.ts +0 -0
- package/esm/{components → defaults}/DefaultRouteSwitch.js +0 -0
- package/esm/defaults/DefaultRouteSwitch.js.map +1 -0
- package/esm/defaults/DefaultRouter.d.ts +3 -0
- package/esm/{components → defaults}/DefaultRouter.js +0 -0
- package/esm/defaults/DefaultRouter.js.map +1 -0
- package/esm/defaults/index.d.ts +5 -0
- package/esm/defaults/index.js +6 -0
- package/esm/defaults/index.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/{components → setters}/SetComponent.d.ts +0 -0
- package/esm/{components → setters}/SetComponent.js +0 -0
- package/esm/setters/SetComponent.js.map +1 -0
- package/esm/{components → setters}/SetError.d.ts +0 -0
- package/esm/{components → setters}/SetError.js +0 -0
- package/esm/setters/SetError.js.map +1 -0
- package/esm/{components → setters}/SetErrors.d.ts +0 -0
- package/esm/{components → setters}/SetErrors.js +0 -0
- package/esm/setters/SetErrors.js.map +1 -0
- package/esm/{components → setters}/SetLayout.d.ts +0 -0
- package/esm/{components → setters}/SetLayout.js +0 -0
- package/esm/setters/SetLayout.js.map +1 -0
- package/esm/{components → setters}/SetProvider.d.ts +0 -0
- package/esm/{components → setters}/SetProvider.js +0 -0
- package/esm/setters/SetProvider.js.map +1 -0
- package/esm/{components → setters}/SetRedirect.d.ts +0 -0
- package/esm/{components → setters}/SetRedirect.js +0 -0
- package/esm/setters/SetRedirect.js.map +1 -0
- package/esm/{components → setters}/SetRoute.d.ts +0 -0
- package/esm/{components → setters}/SetRoute.js +0 -0
- package/esm/setters/SetRoute.js.map +1 -0
- package/esm/setters/index.d.ts +7 -0
- package/esm/setters/index.js +8 -0
- package/esm/setters/index.js.map +1 -0
- package/esm/state/createGlobalState.js +1 -2
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/components.d.ts +9 -1
- package/esm/types/instance.d.ts +10 -3
- package/esm/types/state.d.ts +2 -12
- package/esm/utils/compare.d.ts +1 -1
- package/esm/utils/compare.js +20 -3
- package/esm/utils/compare.js.map +1 -1
- package/esm/utils/media.js +1 -1
- package/esm/utils/media.js.map +1 -1
- package/lib/Piral.d.ts +2 -2
- package/lib/Piral.js +13 -11
- package/lib/Piral.js.map +1 -1
- package/lib/PiralContext.d.ts +21 -0
- package/lib/PiralContext.js +38 -0
- package/lib/PiralContext.js.map +1 -0
- package/lib/actions/app.d.ts +1 -2
- package/lib/actions/app.js +1 -5
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/index.js +6 -6
- package/lib/actions/index.js.map +1 -1
- package/lib/actions/state.js +5 -1
- package/lib/actions/state.js.map +1 -1
- package/lib/components/ErrorBoundary.d.ts +4 -0
- package/lib/components/ErrorBoundary.js +3 -3
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/components/PiralGlobals.d.ts +6 -0
- package/lib/components/PiralGlobals.js +17 -0
- package/lib/components/PiralGlobals.js.map +1 -0
- package/lib/components/PiralRoutes.js +1 -1
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/PiralSuspense.d.ts +5 -0
- package/lib/components/PiralSuspense.js +12 -0
- package/lib/components/PiralSuspense.js.map +1 -0
- package/lib/components/PiralView.d.ts +10 -1
- package/lib/components/PiralView.js +11 -23
- package/lib/components/PiralView.js.map +1 -1
- package/lib/components/ResponsiveLayout.d.ts +9 -1
- package/lib/components/ResponsiveLayout.js +3 -10
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/components.d.ts +13 -6
- package/lib/components/components.js +14 -7
- package/lib/components/components.js.map +1 -1
- package/lib/components/index.d.ts +2 -12
- package/lib/components/index.js +12 -22
- package/lib/components/index.js.map +1 -1
- package/lib/{components → defaults}/DefaultErrorInfo.d.ts +0 -0
- package/lib/{components → defaults}/DefaultErrorInfo.js +2 -3
- package/lib/defaults/DefaultErrorInfo.js.map +1 -0
- package/lib/{components → defaults}/DefaultLayout.d.ts +0 -0
- package/lib/{components → defaults}/DefaultLayout.js +0 -0
- package/lib/defaults/DefaultLayout.js.map +1 -0
- package/lib/{components/DefaultLoader.d.ts → defaults/DefaultLoadingIndicator.d.ts} +0 -0
- package/lib/{components/DefaultLoader.js → defaults/DefaultLoadingIndicator.js} +1 -1
- package/lib/defaults/DefaultLoadingIndicator.js.map +1 -0
- package/lib/{components → defaults}/DefaultRouteSwitch.d.ts +0 -0
- package/lib/{components → defaults}/DefaultRouteSwitch.js +1 -1
- package/lib/defaults/DefaultRouteSwitch.js.map +1 -0
- package/lib/defaults/DefaultRouter.d.ts +3 -0
- package/lib/{components → defaults}/DefaultRouter.js +0 -0
- package/lib/defaults/DefaultRouter.js.map +1 -0
- package/lib/defaults/index.d.ts +5 -0
- package/lib/defaults/index.js +9 -0
- package/lib/defaults/index.js.map +1 -0
- package/lib/hooks/actions.js +1 -1
- package/lib/hooks/actions.js.map +1 -1
- package/lib/hooks/index.js +6 -6
- package/lib/hooks/index.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -8
- package/lib/index.js.map +1 -1
- package/lib/modules/index.js +3 -3
- package/lib/modules/index.js.map +1 -1
- package/lib/{components → setters}/SetComponent.d.ts +0 -0
- package/lib/{components → setters}/SetComponent.js +0 -0
- package/lib/setters/SetComponent.js.map +1 -0
- package/lib/{components → setters}/SetError.d.ts +0 -0
- package/lib/{components → setters}/SetError.js +0 -0
- package/lib/setters/SetError.js.map +1 -0
- package/lib/{components → setters}/SetErrors.d.ts +0 -0
- package/lib/{components → setters}/SetErrors.js +0 -0
- package/lib/setters/SetErrors.js.map +1 -0
- package/lib/{components → setters}/SetLayout.d.ts +0 -0
- package/lib/{components → setters}/SetLayout.js +0 -0
- package/lib/setters/SetLayout.js.map +1 -0
- package/lib/{components → setters}/SetProvider.d.ts +0 -0
- package/lib/{components → setters}/SetProvider.js +0 -0
- package/lib/setters/SetProvider.js.map +1 -0
- package/lib/{components → setters}/SetRedirect.d.ts +0 -0
- package/lib/{components → setters}/SetRedirect.js +0 -0
- package/lib/setters/SetRedirect.js.map +1 -0
- package/lib/{components → setters}/SetRoute.d.ts +0 -0
- package/lib/{components → setters}/SetRoute.js +0 -0
- package/lib/setters/SetRoute.js.map +1 -0
- package/lib/setters/index.d.ts +7 -0
- package/lib/setters/index.js +11 -0
- package/lib/setters/index.js.map +1 -0
- package/lib/state/createGlobalState.js +6 -7
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/state/index.js +4 -4
- package/lib/state/index.js.map +1 -1
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/components.d.ts +9 -1
- package/lib/types/index.js +12 -12
- package/lib/types/index.js.map +1 -1
- package/lib/types/instance.d.ts +10 -3
- package/lib/types/state.d.ts +2 -12
- package/lib/utils/compare.d.ts +1 -1
- package/lib/utils/compare.js +22 -5
- package/lib/utils/compare.js.map +1 -1
- package/lib/utils/helpers.js +1 -1
- package/lib/utils/helpers.js.map +1 -1
- package/lib/utils/index.js +10 -10
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/media.js +1 -1
- package/lib/utils/media.js.map +1 -1
- package/package.json +20 -8
- package/src/Piral.test.tsx +3 -3
- package/src/Piral.tsx +18 -14
- package/src/PiralContext.tsx +43 -0
- package/src/actions/app.test.ts +0 -18
- package/src/actions/app.ts +0 -8
- package/src/actions/state.ts +6 -1
- package/src/components/ErrorBoundary.tsx +7 -3
- package/src/components/PiralGlobals.tsx +16 -0
- package/src/components/PiralRoutes.test.tsx +1 -1
- package/src/components/PiralSuspense.tsx +19 -0
- package/src/components/PiralView-server.test.tsx +1 -0
- package/src/components/PiralView.test.tsx +1 -0
- package/src/components/PiralView.tsx +28 -47
- package/src/components/ResponsiveLayout.test.tsx +14 -43
- package/src/components/ResponsiveLayout.tsx +18 -15
- package/src/components/components.tsx +13 -6
- package/src/components/index.ts +2 -12
- package/src/{components → defaults}/DefaultErrorInfo.test.tsx +0 -0
- package/src/{components → defaults}/DefaultErrorInfo.tsx +1 -2
- package/src/{components → defaults}/DefaultLayout.test.tsx +0 -0
- package/src/{components → defaults}/DefaultLayout.tsx +1 -1
- package/src/{components/DefaultLoader.test.tsx → defaults/DefaultLoadingIndicator.test.tsx} +2 -2
- package/src/{components/DefaultLoader.tsx → defaults/DefaultLoadingIndicator.tsx} +0 -0
- package/src/{components → defaults}/DefaultRouteSwitch.tsx +0 -0
- package/src/{components → defaults}/DefaultRouter.tsx +2 -1
- package/src/defaults/index.ts +5 -0
- package/src/index.tsx +1 -0
- package/src/{components → setters}/SetComponent.test.tsx +0 -0
- package/src/{components → setters}/SetComponent.tsx +0 -0
- package/src/{components → setters}/SetError.test.tsx +0 -0
- package/src/{components → setters}/SetError.tsx +0 -0
- package/src/{components → setters}/SetErrors.test.tsx +0 -0
- package/src/{components → setters}/SetErrors.tsx +0 -0
- package/src/{components → setters}/SetLayout.test.tsx +0 -0
- package/src/{components → setters}/SetLayout.tsx +0 -0
- package/src/{components → setters}/SetProvider.test.tsx +0 -0
- package/src/{components → setters}/SetProvider.tsx +0 -0
- package/src/{components → setters}/SetRedirect.test.tsx +0 -0
- package/src/{components → setters}/SetRedirect.tsx +0 -0
- package/src/{components → setters}/SetRoute.test.tsx +0 -0
- package/src/{components → setters}/SetRoute.tsx +0 -0
- package/src/setters/index.ts +7 -0
- package/src/state/createGlobalState.test.ts +1 -10
- package/src/state/createGlobalState.ts +2 -3
- package/src/state/withApi.tsx +2 -2
- package/src/types/components.ts +11 -2
- package/src/types/instance.ts +11 -3
- package/src/types/state.ts +2 -12
- package/src/utils/compare.test.ts +15 -15
- package/src/utils/compare.ts +23 -3
- package/src/utils/foreign.test.ts +1 -1
- package/src/utils/media.ts +1 -1
- package/esm/components/DefaultErrorInfo.js.map +0 -1
- package/esm/components/DefaultLayout.js.map +0 -1
- package/esm/components/DefaultLoader.js.map +0 -1
- package/esm/components/DefaultRouteSwitch.js.map +0 -1
- package/esm/components/DefaultRouter.d.ts +0 -2
- package/esm/components/DefaultRouter.js.map +0 -1
- package/esm/components/SetComponent.js.map +0 -1
- package/esm/components/SetError.js.map +0 -1
- package/esm/components/SetErrors.js.map +0 -1
- package/esm/components/SetLayout.js.map +0 -1
- package/esm/components/SetProvider.js.map +0 -1
- package/esm/components/SetRedirect.js.map +0 -1
- package/esm/components/SetRoute.js.map +0 -1
- package/lib/components/DefaultErrorInfo.js.map +0 -1
- package/lib/components/DefaultLayout.js.map +0 -1
- package/lib/components/DefaultLoader.js.map +0 -1
- package/lib/components/DefaultRouteSwitch.js.map +0 -1
- package/lib/components/DefaultRouter.d.ts +0 -2
- package/lib/components/DefaultRouter.js.map +0 -1
- package/lib/components/SetComponent.js.map +0 -1
- package/lib/components/SetError.js.map +0 -1
- package/lib/components/SetErrors.js.map +0 -1
- package/lib/components/SetLayout.js.map +0 -1
- package/lib/components/SetProvider.js.map +0 -1
- package/lib/components/SetRedirect.js.map +0 -1
- package/lib/components/SetRoute.js.map +0 -1
package/src/actions/state.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { swap, deref } from '@dbeining/react-atom';
|
|
2
|
+
import { isSame } from '../utils';
|
|
2
3
|
import { GlobalState, GlobalStateContext } from '../types';
|
|
3
4
|
|
|
5
|
+
function onlyChangedState(oldState: GlobalState, newState: GlobalState) {
|
|
6
|
+
return isSame(oldState, newState) ? oldState : newState;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export function dispatch(ctx: GlobalStateContext, update: (state: GlobalState) => GlobalState) {
|
|
5
|
-
swap(ctx.state, update);
|
|
10
|
+
swap(ctx.state, oldState => onlyChangedState(oldState, update(oldState)));
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
export function readState<S>(ctx: GlobalStateContext, read: (state: GlobalState) => S) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { RegisteredErrorInfo, RegisteredLoadingIndicator } from './components';
|
|
3
3
|
import { Errors, PiletApi } from '../types';
|
|
4
4
|
|
|
5
5
|
export interface ErrorBoundaryProps {
|
|
@@ -11,6 +11,10 @@ export interface ErrorBoundaryProps {
|
|
|
11
11
|
* The associated pilet api for the metadata.
|
|
12
12
|
*/
|
|
13
13
|
piral: PiletApi;
|
|
14
|
+
/**
|
|
15
|
+
* The content to render (i.e., where to apply the boundary to).
|
|
16
|
+
*/
|
|
17
|
+
children: React.ReactNode;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
export interface ErrorBoundaryState {
|
|
@@ -45,9 +49,9 @@ export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoun
|
|
|
45
49
|
|
|
46
50
|
if (error) {
|
|
47
51
|
const pilet = piral.meta.name;
|
|
48
|
-
return <
|
|
52
|
+
return <RegisteredErrorInfo type={errorType} error={error} pilet={pilet} {...rest} />;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
return <React.Suspense fallback={<
|
|
55
|
+
return <React.Suspense fallback={<RegisteredLoadingIndicator />}>{children}</React.Suspense>;
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PortalRenderer } from './PortalRenderer';
|
|
3
|
+
import { RegisteredDebug } from './components';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Integrates the global portal renderer and the debug utilities
|
|
7
|
+
* (if registered).
|
|
8
|
+
*/
|
|
9
|
+
export const PiralGlobals: React.FC = () => {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<PortalRenderer id="root" />
|
|
13
|
+
<RegisteredDebug />
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -2,8 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import * as hooks from '../hooks';
|
|
3
3
|
import { MemoryRouter } from 'react-router';
|
|
4
4
|
import { mount } from 'enzyme';
|
|
5
|
-
import { DefaultRouteSwitch } from './DefaultRouteSwitch';
|
|
6
5
|
import { PiralRoutes } from './PiralRoutes';
|
|
6
|
+
import { DefaultRouteSwitch } from '../defaults';
|
|
7
7
|
|
|
8
8
|
const mountWithRouter = (node, url = '/') =>
|
|
9
9
|
mount(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RegisteredErrorInfo, RegisteredLoadingIndicator } from './components';
|
|
3
|
+
import { useGlobalState } from '../hooks';
|
|
4
|
+
|
|
5
|
+
export interface PiralSuspenseProps {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PiralSuspense: React.FC<PiralSuspenseProps> = ({ children }) => {
|
|
10
|
+
const { error, loading } = useGlobalState((m) => m.app);
|
|
11
|
+
|
|
12
|
+
return error ? (
|
|
13
|
+
<RegisteredErrorInfo type="loading" error={error} />
|
|
14
|
+
) : loading ? (
|
|
15
|
+
<RegisteredLoadingIndicator />
|
|
16
|
+
) : (
|
|
17
|
+
<>{children}</>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -1,60 +1,41 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { RouteComponentProps
|
|
2
|
+
import { RouteComponentProps } from 'react-router';
|
|
3
|
+
import { PiralGlobals } from './PiralGlobals';
|
|
3
4
|
import { PiralRoutes } from './PiralRoutes';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
PiralRouteSwitch,
|
|
9
|
-
PiralLayout,
|
|
10
|
-
PiralDebug,
|
|
11
|
-
} from './components';
|
|
12
|
-
import { useGlobalState } from '../hooks';
|
|
5
|
+
import { PiralSuspense } from './PiralSuspense';
|
|
6
|
+
import { ResponsiveLayout } from './ResponsiveLayout';
|
|
7
|
+
import { RegisteredErrorInfo, RegisteredRouteSwitch, RegisteredLayout } from './components';
|
|
8
|
+
import { LayoutBreakpoints } from '../types';
|
|
13
9
|
|
|
14
|
-
const NotFound: React.FC<RouteComponentProps> = (props) => <
|
|
15
|
-
|
|
16
|
-
const PiralContent: React.FC = () => {
|
|
17
|
-
const { error, loading, layout } = useGlobalState((m) => m.app);
|
|
18
|
-
|
|
19
|
-
return error ? (
|
|
20
|
-
<PiralError type="loading" error={error} />
|
|
21
|
-
) : loading ? (
|
|
22
|
-
<PiralLoadingIndicator />
|
|
23
|
-
) : (
|
|
24
|
-
<PiralLayout currentLayout={layout}>
|
|
25
|
-
<PiralRoutes NotFound={NotFound} RouteSwitch={PiralRouteSwitch} />
|
|
26
|
-
</PiralLayout>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const FallbackRouter: React.FC = (props) => {
|
|
31
|
-
const publicPath = useGlobalState((s) => s.app.publicPath);
|
|
32
|
-
return <StaticRouter location="/" {...props} basename={publicPath} />;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const Router = typeof window === 'undefined' ? FallbackRouter : PiralRouter;
|
|
36
|
-
|
|
37
|
-
const PiralProvider: React.FC = ({ children }) => {
|
|
38
|
-
const provider = useGlobalState((m) => m.provider) || React.Fragment;
|
|
39
|
-
return React.createElement(provider, undefined, children);
|
|
40
|
-
};
|
|
10
|
+
const NotFound: React.FC<RouteComponentProps> = (props) => <RegisteredErrorInfo type="not_found" {...props} />;
|
|
41
11
|
|
|
42
12
|
/**
|
|
43
13
|
* The props for the PiralView component.
|
|
44
14
|
*/
|
|
45
|
-
export interface PiralViewProps {
|
|
15
|
+
export interface PiralViewProps {
|
|
16
|
+
/**
|
|
17
|
+
* The custom breakpoints for the different layout modi.
|
|
18
|
+
*/
|
|
19
|
+
breakpoints?: LayoutBreakpoints;
|
|
20
|
+
/**
|
|
21
|
+
* The extra content.
|
|
22
|
+
*/
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
}
|
|
46
25
|
|
|
47
26
|
/**
|
|
48
27
|
* The component responsible for the generic view of the application.
|
|
49
|
-
* This includes the
|
|
28
|
+
* This includes the used the current content and some convenience.
|
|
50
29
|
*/
|
|
51
|
-
export const PiralView: React.FC<PiralViewProps> = ({ children }) => (
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
export const PiralView: React.FC<PiralViewProps> = ({ breakpoints, children }) => (
|
|
31
|
+
<>
|
|
32
|
+
<PiralGlobals />
|
|
33
|
+
<PiralSuspense>
|
|
34
|
+
<ResponsiveLayout breakpoints={breakpoints} Layout={RegisteredLayout}>
|
|
35
|
+
<PiralRoutes NotFound={NotFound} RouteSwitch={RegisteredRouteSwitch} />
|
|
36
|
+
</ResponsiveLayout>
|
|
37
|
+
</PiralSuspense>
|
|
38
|
+
{children}
|
|
39
|
+
</>
|
|
59
40
|
);
|
|
60
41
|
PiralView.displayName = 'PiralView';
|
|
@@ -6,25 +6,15 @@ import { defaultBreakpoints } from '../utils';
|
|
|
6
6
|
|
|
7
7
|
jest.mock('../hooks');
|
|
8
8
|
|
|
9
|
-
(hooks as any).useGlobalState = (select: any) =>
|
|
10
|
-
select({
|
|
11
|
-
app: {
|
|
12
|
-
layout: 'desktop',
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const StubComponent: React.FC = () => <div />;
|
|
17
|
-
StubComponent.displayName = 'StubComponent';
|
|
18
|
-
|
|
19
9
|
describe('Responsive Module', () => {
|
|
20
10
|
it('always renders the given children', () => {
|
|
21
|
-
const changeTo = jest.fn();
|
|
22
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
23
|
-
changeLayout: changeTo,
|
|
24
|
-
});
|
|
25
11
|
(hooks as any).useMedia = () => 'desktop';
|
|
12
|
+
const Layout: React.FC = jest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
13
|
+
Layout.displayName = 'Layout';
|
|
14
|
+
const StubComponent: React.FC = () => <div />;
|
|
15
|
+
StubComponent.displayName = 'StubComponent';
|
|
26
16
|
const node = mount(
|
|
27
|
-
<ResponsiveLayout breakpoints={defaultBreakpoints}>
|
|
17
|
+
<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints}>
|
|
28
18
|
<StubComponent />)
|
|
29
19
|
</ResponsiveLayout>,
|
|
30
20
|
);
|
|
@@ -32,42 +22,23 @@ describe('Responsive Module', () => {
|
|
|
32
22
|
});
|
|
33
23
|
|
|
34
24
|
it('does not call changeTo when nothing changed', () => {
|
|
35
|
-
const changeTo = jest.fn();
|
|
36
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
37
|
-
changeLayout: changeTo,
|
|
38
|
-
});
|
|
39
|
-
(hooks as any).useMedia = () => 'desktop';
|
|
40
|
-
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
41
|
-
expect(changeTo).not.toHaveBeenCalled();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('does not call changeTo when nothing changed', () => {
|
|
45
|
-
const changeTo = jest.fn();
|
|
46
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
47
|
-
changeLayout: changeTo,
|
|
48
|
-
});
|
|
49
25
|
(hooks as any).useMedia = () => 'desktop';
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
const Layout = jest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
27
|
+
mount(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
28
|
+
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'desktop' }, {});
|
|
52
29
|
});
|
|
53
30
|
|
|
54
31
|
it('does calls changeTo when someething changed (desktop -> tablet)', () => {
|
|
55
|
-
const changeTo = jest.fn();
|
|
56
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
57
|
-
changeLayout: changeTo,
|
|
58
|
-
});
|
|
59
32
|
(hooks as any).useMedia = () => 'tablet';
|
|
60
|
-
|
|
61
|
-
|
|
33
|
+
const Layout = jest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
34
|
+
mount(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
35
|
+
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'tablet' }, {});
|
|
62
36
|
});
|
|
63
37
|
|
|
64
38
|
it('does calls changeTo when someething changed (desktop -> mobile)', () => {
|
|
65
|
-
const changeTo = jest.fn();
|
|
66
|
-
(hooks as any).useGlobalStateContext = () => ({
|
|
67
|
-
changeLayout: changeTo,
|
|
68
|
-
});
|
|
69
39
|
(hooks as any).useMedia = () => 'mobile';
|
|
70
|
-
|
|
71
|
-
|
|
40
|
+
const Layout = jest.fn().mockImplementation(({ children }) => <div>{children}</div>);
|
|
41
|
+
mount(<ResponsiveLayout Layout={Layout} breakpoints={defaultBreakpoints} />);
|
|
42
|
+
expect(Layout).toHaveBeenCalledWith({ currentLayout: 'mobile' }, {});
|
|
72
43
|
});
|
|
73
44
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useMedia
|
|
3
|
-
import { defaultLayouts,
|
|
4
|
-
import { LayoutBreakpoints } from '../types';
|
|
2
|
+
import { useMedia } from '../hooks';
|
|
3
|
+
import { defaultLayouts, defaultBreakpoints } from '../utils';
|
|
4
|
+
import { LayoutBreakpoints, LayoutProps } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The props for the ResponsiveLayout component.
|
|
@@ -11,22 +11,25 @@ export interface ResponsiveLayoutProps {
|
|
|
11
11
|
* The individual breakpoints to be used for the different layouts.
|
|
12
12
|
*/
|
|
13
13
|
breakpoints?: LayoutBreakpoints;
|
|
14
|
+
/**
|
|
15
|
+
* The actual layout component to render to transport.
|
|
16
|
+
*/
|
|
17
|
+
Layout: React.ComponentType<LayoutProps>;
|
|
18
|
+
/**
|
|
19
|
+
* The content to display.
|
|
20
|
+
*/
|
|
21
|
+
children: React.ReactNode;
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
/**
|
|
17
25
|
* The component capable of identifying and switching the currently used layout.
|
|
18
26
|
*/
|
|
19
|
-
export const ResponsiveLayout: React.FC<ResponsiveLayoutProps> = ({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
changeLayout(selected);
|
|
27
|
-
}
|
|
28
|
-
}, [selected]);
|
|
29
|
-
|
|
30
|
-
return defaultRender(children);
|
|
27
|
+
export const ResponsiveLayout: React.FC<ResponsiveLayoutProps> = ({
|
|
28
|
+
breakpoints = defaultBreakpoints,
|
|
29
|
+
Layout,
|
|
30
|
+
children,
|
|
31
|
+
}) => {
|
|
32
|
+
const selected = useMedia(breakpoints, defaultLayouts, 'desktop');
|
|
33
|
+
return <Layout currentLayout={selected}>{children}</Layout>;
|
|
31
34
|
};
|
|
32
35
|
ResponsiveLayout.displayName = 'ResponsiveLayout';
|
|
@@ -2,6 +2,13 @@ import * as React from 'react';
|
|
|
2
2
|
import { useGlobalState } from '../hooks';
|
|
3
3
|
import { ComponentsState } from '../types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Gets a registered layout component by its name.
|
|
7
|
+
* This will always return a valid component. If nothing is found
|
|
8
|
+
* then the returned component will just return null.
|
|
9
|
+
* @param name The name of the registered layout component.
|
|
10
|
+
* @returns The registered layout component or an empty stub component.
|
|
11
|
+
*/
|
|
5
12
|
export function getPiralComponent<TKey extends keyof ComponentsState>(name: TKey): ComponentsState[TKey] {
|
|
6
13
|
return (props) => {
|
|
7
14
|
const Component = useGlobalState((s) => s.components[name]);
|
|
@@ -14,34 +21,34 @@ export function getPiralComponent<TKey extends keyof ComponentsState>(name: TKey
|
|
|
14
21
|
* Gets the currently registered ErrorInfo component.
|
|
15
22
|
* By default the DefaultErrorInfo component is used.
|
|
16
23
|
*/
|
|
17
|
-
export const
|
|
24
|
+
export const RegisteredErrorInfo = getPiralComponent('ErrorInfo');
|
|
18
25
|
|
|
19
26
|
/**
|
|
20
27
|
* Gets the currently registered LoadingIndicator component.
|
|
21
28
|
* By default only Loading is rendered.
|
|
22
29
|
*/
|
|
23
|
-
export const
|
|
30
|
+
export const RegisteredLoadingIndicator = getPiralComponent('LoadingIndicator');
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
33
|
* Gets the currently registered Router component.
|
|
27
34
|
* By default the BrowserRouter is used.
|
|
28
35
|
*/
|
|
29
|
-
export const
|
|
36
|
+
export const RegisteredRouter = getPiralComponent('Router');
|
|
30
37
|
|
|
31
38
|
/**
|
|
32
39
|
* Gets the currently registered Route Switch component.
|
|
33
40
|
* By default the DefaultRouteSwitch component is used.
|
|
34
41
|
*/
|
|
35
|
-
export const
|
|
42
|
+
export const RegisteredRouteSwitch = getPiralComponent('RouteSwitch');
|
|
36
43
|
|
|
37
44
|
/**
|
|
38
45
|
* Gets the currently registered Layout component.
|
|
39
46
|
* By default the children are rendered.
|
|
40
47
|
*/
|
|
41
|
-
export const
|
|
48
|
+
export const RegisteredLayout = getPiralComponent('Layout');
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
51
|
* Gets the currently registered Debug component.
|
|
45
52
|
* By default nothing is used.
|
|
46
53
|
*/
|
|
47
|
-
export const
|
|
54
|
+
export const RegisteredDebug = getPiralComponent('Debug');
|
package/src/components/index.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
export * from './components';
|
|
2
|
-
export * from './DefaultErrorInfo';
|
|
3
|
-
export * from './DefaultLayout';
|
|
4
|
-
export * from './DefaultLoader';
|
|
5
|
-
export * from './DefaultRouter';
|
|
6
|
-
export * from './DefaultRouteSwitch';
|
|
7
2
|
export * from './ErrorBoundary';
|
|
8
3
|
export * from './ExtensionSlot';
|
|
9
4
|
export * from './Mediator';
|
|
5
|
+
export * from './PiralGlobals';
|
|
10
6
|
export * from './PiralRoutes';
|
|
7
|
+
export * from './PiralSuspense';
|
|
11
8
|
export * from './PiralView';
|
|
12
9
|
export * from './PortalRenderer';
|
|
13
10
|
export * from './ResponsiveLayout';
|
|
14
|
-
export * from './SetComponent';
|
|
15
|
-
export * from './SetError';
|
|
16
|
-
export * from './SetErrors';
|
|
17
|
-
export * from './SetLayout';
|
|
18
|
-
export * from './SetProvider';
|
|
19
|
-
export * from './SetRedirect';
|
|
20
|
-
export * from './SetRoute';
|
|
21
11
|
export * from './SwitchErrorInfo';
|
|
22
12
|
export * from './wrapComponent';
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DefaultLoadingIndicator } from './
|
|
2
|
+
import { DefaultLoadingIndicator } from './DefaultLoadingIndicator';
|
|
3
3
|
import { mount } from 'enzyme';
|
|
4
4
|
|
|
5
|
-
describe('Default
|
|
5
|
+
describe('Default Loading Indicator Component', () => {
|
|
6
6
|
it('renders correctly', () => {
|
|
7
7
|
const node = mount(<DefaultLoadingIndicator />);
|
|
8
8
|
expect(node.find('div').length).toBe(1);
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { BrowserRouter } from 'react-router-dom';
|
|
3
3
|
import { useGlobalState } from '../hooks';
|
|
4
|
+
import { RouterProps } from '../types';
|
|
4
5
|
|
|
5
|
-
export const DefaultRouter: React.FC = ({ children }) => {
|
|
6
|
+
export const DefaultRouter: React.FC<RouterProps> = ({ children }) => {
|
|
6
7
|
const publicPath = useGlobalState((s) => s.app.publicPath);
|
|
7
8
|
return <BrowserRouter basename={publicPath}>{children}</BrowserRouter>;
|
|
8
9
|
};
|
package/src/index.tsx
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
DefaultLayout,
|
|
7
7
|
DefaultRouter,
|
|
8
8
|
DefaultRouteSwitch,
|
|
9
|
-
} from '../
|
|
9
|
+
} from '../defaults';
|
|
10
10
|
|
|
11
11
|
process.env.PIRAL_PUBLIC_PATH = '/';
|
|
12
12
|
|
|
@@ -17,7 +17,6 @@ describe('Create Global State Module', () => {
|
|
|
17
17
|
const globalState = createGlobalState({});
|
|
18
18
|
expect(deref(globalState)).toEqual({
|
|
19
19
|
app: {
|
|
20
|
-
layout: 'desktop',
|
|
21
20
|
loading: true,
|
|
22
21
|
error: undefined,
|
|
23
22
|
publicPath: '/',
|
|
@@ -46,7 +45,6 @@ describe('Create Global State Module', () => {
|
|
|
46
45
|
const globalState = createGlobalState({});
|
|
47
46
|
expect(deref(globalState)).toEqual({
|
|
48
47
|
app: {
|
|
49
|
-
layout: 'desktop',
|
|
50
48
|
loading: true,
|
|
51
49
|
error: undefined,
|
|
52
50
|
publicPath: '/',
|
|
@@ -80,7 +78,6 @@ describe('Create Global State Module', () => {
|
|
|
80
78
|
expect(deref(globalState)).toEqual({
|
|
81
79
|
app: {
|
|
82
80
|
error: undefined,
|
|
83
|
-
layout: 'desktop',
|
|
84
81
|
loading: true,
|
|
85
82
|
publicPath: '/',
|
|
86
83
|
},
|
|
@@ -108,7 +105,6 @@ describe('Create Global State Module', () => {
|
|
|
108
105
|
const globalState = createGlobalState();
|
|
109
106
|
expect(deref(globalState)).toEqual({
|
|
110
107
|
app: {
|
|
111
|
-
layout: 'desktop',
|
|
112
108
|
loading: true,
|
|
113
109
|
error: undefined,
|
|
114
110
|
publicPath: '/',
|
|
@@ -139,7 +135,6 @@ describe('Create Global State Module', () => {
|
|
|
139
135
|
});
|
|
140
136
|
expect(deref(globalState)).toEqual({
|
|
141
137
|
app: {
|
|
142
|
-
layout: 'desktop',
|
|
143
138
|
loading: true,
|
|
144
139
|
error: undefined,
|
|
145
140
|
publicPath: '/',
|
|
@@ -170,7 +165,6 @@ describe('Create Global State Module', () => {
|
|
|
170
165
|
});
|
|
171
166
|
expect(deref(globalState)).toEqual({
|
|
172
167
|
app: {
|
|
173
|
-
layout: 'desktop',
|
|
174
168
|
loading: true,
|
|
175
169
|
error: undefined,
|
|
176
170
|
publicPath: '/',
|
|
@@ -198,7 +192,6 @@ describe('Create Global State Module', () => {
|
|
|
198
192
|
it('global state with non-default breakpoints and more routes', () => {
|
|
199
193
|
const globalState = createGlobalState({
|
|
200
194
|
app: {
|
|
201
|
-
layout: 'desktop',
|
|
202
195
|
},
|
|
203
196
|
routes: {
|
|
204
197
|
'/': '...' as any,
|
|
@@ -207,7 +200,6 @@ describe('Create Global State Module', () => {
|
|
|
207
200
|
});
|
|
208
201
|
expect(deref(globalState)).toEqual({
|
|
209
202
|
app: {
|
|
210
|
-
layout: 'desktop',
|
|
211
203
|
loading: true,
|
|
212
204
|
error: undefined,
|
|
213
205
|
publicPath: '/',
|
|
@@ -243,7 +235,6 @@ describe('Create Global State Module', () => {
|
|
|
243
235
|
});
|
|
244
236
|
expect(deref(globalState)).toEqual({
|
|
245
237
|
app: {
|
|
246
|
-
layout: 'desktop',
|
|
247
238
|
loading: false,
|
|
248
239
|
error: undefined,
|
|
249
240
|
publicPath: '/',
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Atom } from '@dbeining/react-atom';
|
|
2
|
+
import { GlobalState, NestedPartial } from '../types';
|
|
2
3
|
import {
|
|
3
4
|
DefaultErrorInfo,
|
|
4
5
|
DefaultLoadingIndicator,
|
|
5
6
|
DefaultLayout,
|
|
6
7
|
DefaultRouter,
|
|
7
8
|
DefaultRouteSwitch,
|
|
8
|
-
} from '../
|
|
9
|
-
import { GlobalState, NestedPartial } from '../types';
|
|
9
|
+
} from '../defaults';
|
|
10
10
|
|
|
11
11
|
function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
12
12
|
for (const key of Object.keys(customState)) {
|
|
@@ -28,7 +28,6 @@ export function createGlobalState(customState: NestedPartial<GlobalState> = {})
|
|
|
28
28
|
app: {
|
|
29
29
|
error: undefined,
|
|
30
30
|
loading: typeof window !== 'undefined',
|
|
31
|
-
layout: 'desktop',
|
|
32
31
|
publicPath: process.env.PIRAL_PUBLIC_PATH || '/',
|
|
33
32
|
},
|
|
34
33
|
components: {
|
package/src/state/withApi.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { ErrorBoundary, wrapComponent } from '../components';
|
|
|
4
4
|
import { defaultRender } from '../utils';
|
|
5
5
|
import { AnyComponent, Errors, PiletApi, BaseComponentProps, GlobalStateContext } from '../types';
|
|
6
6
|
|
|
7
|
-
const DefaultWrapper: React.FC = (props) => defaultRender(props.children);
|
|
7
|
+
const DefaultWrapper: React.FC<React.PropsWithChildren<{}>> = (props) => defaultRender(props.children);
|
|
8
8
|
|
|
9
9
|
function getWrapper(wrappers: Record<string, React.ComponentType<any>>, wrapperType: string) {
|
|
10
10
|
const WrapAll = wrappers['*'];
|
|
@@ -26,7 +26,7 @@ function makeWrapper<TProps>(
|
|
|
26
26
|
outerProps: any,
|
|
27
27
|
wrapperType: string,
|
|
28
28
|
errorType: keyof Errors,
|
|
29
|
-
): React.FC<TProps
|
|
29
|
+
): React.FC<React.PropsWithChildren<TProps>> {
|
|
30
30
|
const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
|
|
31
31
|
|
|
32
32
|
return (props) => (
|