piral-core 0.15.0-alpha.4284 → 0.15.0-alpha.4332
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/app.codegen +191 -0
- package/{debug.codegen.d.ts → app.codegen.d.ts} +10 -1
- package/esm/actions/app.d.ts +1 -0
- package/esm/actions/app.js +3 -0
- package/esm/actions/app.js.map +1 -1
- package/esm/components/PiralRoutes.js +2 -6
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/wrapComponent.js +2 -2
- package/esm/components/wrapComponent.js.map +1 -1
- package/esm/createInstance.js +1 -1
- package/esm/createInstance.js.map +1 -1
- package/esm/debugger.js +3 -0
- package/esm/debugger.js.map +1 -1
- package/esm/defaults/{DefaultRouteSwitch.d.ts → DefaultRouteSwitch_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouteSwitch.d.ts → esm/defaults/DefaultRouteSwitch_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/esm/defaults/{DefaultRouter.d.ts → DefaultRouter_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/esm/defaults/DefaultRouter_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouter.d.ts → esm/defaults/DefaultRouter_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouter_v6.js +9 -0
- package/esm/defaults/DefaultRouter_v6.js.map +1 -0
- package/esm/emulator.js +2 -3
- package/esm/emulator.js.map +1 -1
- package/esm/helpers.js +1 -1
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/index.d.ts +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/routes.d.ts +2 -0
- package/esm/hooks/routes.js +11 -0
- package/esm/hooks/routes.js.map +1 -0
- package/esm/modules/dependencies.js +1 -1
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/state/createGlobalState.js +2 -25
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/types/components.d.ts +14 -10
- package/esm/types/state.d.ts +6 -0
- package/lib/actions/app.d.ts +1 -0
- package/lib/actions/app.js +5 -1
- package/lib/actions/app.js.map +1 -1
- package/lib/components/PiralRoutes.js +1 -5
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/wrapComponent.js +2 -2
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/createInstance.js +1 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/debugger.js +3 -0
- package/lib/debugger.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/lib/defaults/DefaultRouter_v5.js.map +1 -0
- package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v6.js +13 -0
- package/lib/defaults/DefaultRouter_v6.js.map +1 -0
- package/lib/emulator.js +2 -3
- package/lib/emulator.js.map +1 -1
- package/lib/helpers.js +3 -3
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/routes.d.ts +2 -0
- package/lib/hooks/routes.js +15 -0
- package/lib/hooks/routes.js.map +1 -0
- package/lib/modules/dependencies.js +3 -3
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/state/createGlobalState.js +2 -25
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/types/components.d.ts +14 -10
- package/lib/types/state.d.ts +6 -0
- package/package.json +10 -8
- package/src/Piral.test.tsx +7 -5
- package/src/RootListener.test.tsx +8 -4
- package/src/actions/app.ts +4 -0
- package/src/components/ForeignComponentContainer.test.tsx +9 -5
- package/src/components/PiralRoutes.test.tsx +23 -16
- package/src/components/PiralRoutes.tsx +2 -8
- package/src/components/wrapComponent.tsx +2 -2
- package/src/createInstance.tsx +1 -1
- package/src/debugger.ts +3 -0
- package/src/defaults/{DefaultRouteSwitch.tsx → DefaultRouteSwitch_v5.tsx} +1 -0
- package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
- package/src/defaults/{DefaultRouter.tsx → DefaultRouter_v5.tsx} +1 -0
- package/src/defaults/DefaultRouter_v6.tsx +10 -0
- package/src/emulator.ts +2 -10
- package/src/helpers.tsx +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/routes.ts +14 -0
- package/src/hooks/setter.test.ts +1 -1
- package/src/modules/dependencies.ts +1 -1
- package/src/state/createGlobalState.test.ts +45 -48
- package/src/state/createGlobalState.ts +2 -32
- package/src/types/components.ts +15 -10
- package/src/types/state.ts +6 -0
- package/src/utils/foreign.test.ts +1 -1
- package/debug.codegen +0 -24
- package/dependencies.codegen +0 -37
- package/dependencies.codegen.d.ts +0 -1
- package/dependencies.codegen.native.js +0 -2
- package/esm/defaults/DefaultRouteSwitch.js.map +0 -1
- package/esm/defaults/DefaultRouter.js.map +0 -1
- package/esm/defaults/index.d.ts +0 -5
- package/esm/defaults/index.js +0 -6
- package/esm/defaults/index.js.map +0 -1
- package/lib/defaults/DefaultRouteSwitch.js.map +0 -1
- package/lib/defaults/DefaultRouter.js.map +0 -1
- package/lib/defaults/index.d.ts +0 -5
- package/lib/defaults/index.js +0 -9
- package/lib/defaults/index.js.map +0 -1
- package/src/defaults/index.ts +0 -5
|
@@ -3,7 +3,7 @@ import * as hooks from '../hooks';
|
|
|
3
3
|
import { MemoryRouter } from 'react-router';
|
|
4
4
|
import { mount } from 'enzyme';
|
|
5
5
|
import { PiralRoutes } from './PiralRoutes';
|
|
6
|
-
import { DefaultRouteSwitch } from '../defaults';
|
|
6
|
+
import { DefaultRouteSwitch } from '../defaults/DefaultRouteSwitch_v5';
|
|
7
7
|
|
|
8
8
|
const mountWithRouter = (node, url = '/') =>
|
|
9
9
|
mount(
|
|
@@ -14,21 +14,28 @@ const mountWithRouter = (node, url = '/') =>
|
|
|
14
14
|
|
|
15
15
|
jest.mock('../hooks');
|
|
16
16
|
|
|
17
|
-
(hooks as any).
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
(hooks as any).useRoutes = () => [
|
|
18
|
+
{
|
|
19
|
+
path: '/',
|
|
20
|
+
Component: StubHome,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: '/custom',
|
|
24
|
+
Component: StubCustomPage,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: '/foo',
|
|
28
|
+
Component: StubFooPage,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: '/foo/bar',
|
|
32
|
+
Component: StubFooBarPage,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: '/bar',
|
|
36
|
+
Component: StubBarPage,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
32
39
|
|
|
33
40
|
const StubHome: React.FC = (props) => <div />;
|
|
34
41
|
StubHome.displayName = 'StubHome';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
|
-
import {
|
|
3
|
+
import { useRoutes } from '../hooks';
|
|
4
4
|
import { RouteSwitchProps } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -21,13 +21,7 @@ export interface RoutesProps extends SwitchProps {
|
|
|
21
21
|
* The component for defining the exclusive routes to be used.
|
|
22
22
|
*/
|
|
23
23
|
export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, RouteSwitch, ...props }) => {
|
|
24
|
-
const
|
|
25
|
-
const pages = useGlobalState((s) => s.registry.pages);
|
|
26
|
-
const paths = [];
|
|
27
|
-
|
|
28
|
-
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
29
|
-
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
30
|
-
|
|
24
|
+
const paths = useRoutes();
|
|
31
25
|
return <RouteSwitch NotFound={NotFound} paths={paths} {...props} />;
|
|
32
26
|
};
|
|
33
27
|
PiralRoutes.displayName = 'Routes';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { __RouterContext } from 'react-router';
|
|
3
2
|
import { PortalRenderer } from './PortalRenderer';
|
|
4
3
|
import { ForeignComponentContainer } from './ForeignComponentContainer';
|
|
5
4
|
import { useGlobalStateContext } from '../hooks';
|
|
6
5
|
import { convertComponent, none } from '../utils';
|
|
6
|
+
import { useRouterContext } from '../../app.codegen';
|
|
7
7
|
import type { AnyComponent, ComponentConverters, ForeignComponent, PiletApi, BaseComponentProps } from '../types';
|
|
8
8
|
|
|
9
9
|
// this is an arbitrary start number to have 6 digits
|
|
@@ -32,7 +32,7 @@ function wrapForeignComponent<T>(
|
|
|
32
32
|
) {
|
|
33
33
|
return React.memo((props: T) => {
|
|
34
34
|
const { state, readState, destroyPortal } = useGlobalStateContext();
|
|
35
|
-
const router =
|
|
35
|
+
const router = useRouterContext();
|
|
36
36
|
const id = React.useMemo(() => (portalIdBase++).toString(26), none);
|
|
37
37
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
|
38
38
|
const innerProps = React.useMemo(() => ({ ...props, ...captured }), [props]);
|
package/src/createInstance.tsx
CHANGED
|
@@ -50,7 +50,7 @@ export function createInstance(config: PiralInstanceOptions = {}): PiralInstance
|
|
|
50
50
|
const createApi = apiFactory(context, usedPlugins);
|
|
51
51
|
const root = createApi({
|
|
52
52
|
name: '_',
|
|
53
|
-
version:
|
|
53
|
+
version: '0',
|
|
54
54
|
spec: 'v0',
|
|
55
55
|
basePath: '',
|
|
56
56
|
link: '',
|
package/src/debugger.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
//@ts-ignore
|
|
3
|
+
import { Routes, Route } from 'react-router-dom';
|
|
4
|
+
import { RouteSwitchProps } from '../types';
|
|
5
|
+
|
|
6
|
+
export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
|
|
7
|
+
return (
|
|
8
|
+
<Routes {...props}>
|
|
9
|
+
{paths.map(({ path, Component }) => (
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
<Route key={path} path={path} element={<Component />} />
|
|
12
|
+
))}
|
|
13
|
+
{
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
<Route element={<NotFound />} />
|
|
16
|
+
}
|
|
17
|
+
</Routes>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
DefaultRouteSwitch.displayName = 'DefaultRouteSwitch';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
3
|
+
import { useGlobalState } from '../hooks';
|
|
4
|
+
import { RouterProps } from '../types';
|
|
5
|
+
|
|
6
|
+
export const DefaultRouter: React.FC<RouterProps> = ({ children }) => {
|
|
7
|
+
const publicPath = useGlobalState((s) => s.app.publicPath);
|
|
8
|
+
return <BrowserRouter basename={publicPath}>{children}</BrowserRouter>;
|
|
9
|
+
};
|
|
10
|
+
DefaultRouter.displayName = 'DefaultRouter';
|
package/src/emulator.ts
CHANGED
|
@@ -6,16 +6,8 @@ export function integrateEmulator(context: GlobalStateContext, options: LoadPile
|
|
|
6
6
|
installPiletEmulator(options.fetchPilets, {
|
|
7
7
|
addPilet: context.addPilet,
|
|
8
8
|
removePilet: context.removePilet,
|
|
9
|
-
integrate(
|
|
10
|
-
|
|
11
|
-
...s,
|
|
12
|
-
components: {
|
|
13
|
-
...s.components,
|
|
14
|
-
...emulator.components,
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
options.fetchPilets = emulator.requester;
|
|
9
|
+
integrate(requester) {
|
|
10
|
+
options.fetchPilets = requester;
|
|
19
11
|
},
|
|
20
12
|
});
|
|
21
13
|
}
|
package/src/helpers.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import type { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
12
12
|
import { globalDependencies } from './modules';
|
|
13
13
|
import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
|
|
14
|
-
import { integrateDebugger, integrateEmulator } from '../
|
|
14
|
+
import { integrateDebugger, integrateEmulator } from '../app.codegen';
|
|
15
15
|
|
|
16
16
|
export interface PiletOptionsConfig {
|
|
17
17
|
context: GlobalStateContext;
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useGlobalState } from './globalState';
|
|
2
|
+
import { useRouteFilter } from '../../app.codegen';
|
|
3
|
+
import { AppPath } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useRoutes() {
|
|
6
|
+
const routes = useGlobalState((s) => s.routes);
|
|
7
|
+
const pages = useGlobalState((s) => s.registry.pages);
|
|
8
|
+
const paths: Array<AppPath> = [];
|
|
9
|
+
|
|
10
|
+
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
11
|
+
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
12
|
+
|
|
13
|
+
return useRouteFilter(paths);
|
|
14
|
+
}
|
package/src/hooks/setter.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ describe('UseSetter Hook Module', () => {
|
|
|
14
14
|
|
|
15
15
|
const root = createRoot(document.body.appendChild(document.createElement('div')));
|
|
16
16
|
root.render(React.createElement(MyComponent));
|
|
17
|
-
await act(() => Promise
|
|
17
|
+
await act(() => new Promise(resolve => setTimeout(resolve, 5)));
|
|
18
18
|
expect(cb).toHaveBeenCalled();
|
|
19
19
|
});
|
|
20
20
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
2
|
import type { AvailableDependencies, PiletEntries } from '../types';
|
|
3
|
-
import fillDependencies from '../../
|
|
3
|
+
import { fillDependencies } from '../../app.codegen';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The global dependencies, which represent the dependencies
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { deref } from '@dbeining/react-atom';
|
|
2
2
|
import { createGlobalState } from './createGlobalState';
|
|
3
|
-
import {
|
|
4
|
-
DefaultErrorInfo,
|
|
5
|
-
DefaultLoadingIndicator,
|
|
6
|
-
DefaultLayout,
|
|
7
|
-
DefaultRouter,
|
|
8
|
-
DefaultRouteSwitch,
|
|
9
|
-
} from '../defaults';
|
|
10
3
|
|
|
11
4
|
process.env.PIRAL_PUBLIC_PATH = '/';
|
|
12
5
|
|
|
@@ -15,7 +8,11 @@ describe('Create Global State Module', () => {
|
|
|
15
8
|
|
|
16
9
|
it('global state works with language as empty string', () => {
|
|
17
10
|
const globalState = createGlobalState({});
|
|
18
|
-
|
|
11
|
+
const tmp = deref(globalState);
|
|
12
|
+
|
|
13
|
+
console.log(tmp);
|
|
14
|
+
|
|
15
|
+
expect(tmp).toEqual({
|
|
19
16
|
app: {
|
|
20
17
|
loading: true,
|
|
21
18
|
error: undefined,
|
|
@@ -23,11 +20,11 @@ describe('Create Global State Module', () => {
|
|
|
23
20
|
},
|
|
24
21
|
errorComponents: {},
|
|
25
22
|
components: {
|
|
26
|
-
ErrorInfo:
|
|
27
|
-
LoadingIndicator:
|
|
28
|
-
Router:
|
|
29
|
-
Layout:
|
|
30
|
-
RouteSwitch:
|
|
23
|
+
ErrorInfo: expect.anything(),
|
|
24
|
+
LoadingIndicator: expect.anything(),
|
|
25
|
+
Router: expect.anything(),
|
|
26
|
+
Layout: expect.anything(),
|
|
27
|
+
RouteSwitch: expect.anything(),
|
|
31
28
|
},
|
|
32
29
|
routes: {},
|
|
33
30
|
registry: {
|
|
@@ -51,11 +48,11 @@ describe('Create Global State Module', () => {
|
|
|
51
48
|
},
|
|
52
49
|
errorComponents: {},
|
|
53
50
|
components: {
|
|
54
|
-
ErrorInfo:
|
|
55
|
-
LoadingIndicator:
|
|
56
|
-
Router:
|
|
57
|
-
Layout:
|
|
58
|
-
RouteSwitch:
|
|
51
|
+
ErrorInfo: expect.anything(),
|
|
52
|
+
LoadingIndicator: expect.anything(),
|
|
53
|
+
Router: expect.anything(),
|
|
54
|
+
Layout: expect.anything(),
|
|
55
|
+
RouteSwitch: expect.anything(),
|
|
59
56
|
},
|
|
60
57
|
routes: {},
|
|
61
58
|
registry: {
|
|
@@ -83,11 +80,11 @@ describe('Create Global State Module', () => {
|
|
|
83
80
|
},
|
|
84
81
|
errorComponents: {},
|
|
85
82
|
components: {
|
|
86
|
-
ErrorInfo:
|
|
87
|
-
LoadingIndicator:
|
|
88
|
-
Router:
|
|
89
|
-
Layout:
|
|
90
|
-
RouteSwitch:
|
|
83
|
+
ErrorInfo: expect.anything(),
|
|
84
|
+
LoadingIndicator: expect.anything(),
|
|
85
|
+
Router: expect.anything(),
|
|
86
|
+
Layout: expect.anything(),
|
|
87
|
+
RouteSwitch: expect.anything(),
|
|
91
88
|
},
|
|
92
89
|
routes,
|
|
93
90
|
registry: {
|
|
@@ -111,11 +108,11 @@ describe('Create Global State Module', () => {
|
|
|
111
108
|
},
|
|
112
109
|
errorComponents: {},
|
|
113
110
|
components: {
|
|
114
|
-
ErrorInfo:
|
|
115
|
-
LoadingIndicator:
|
|
116
|
-
Router:
|
|
117
|
-
Layout:
|
|
118
|
-
RouteSwitch:
|
|
111
|
+
ErrorInfo: expect.anything(),
|
|
112
|
+
LoadingIndicator: expect.anything(),
|
|
113
|
+
Router: expect.anything(),
|
|
114
|
+
Layout: expect.anything(),
|
|
115
|
+
RouteSwitch: expect.anything(),
|
|
119
116
|
},
|
|
120
117
|
registry: {
|
|
121
118
|
extensions: {},
|
|
@@ -141,11 +138,11 @@ describe('Create Global State Module', () => {
|
|
|
141
138
|
},
|
|
142
139
|
errorComponents: {},
|
|
143
140
|
components: {
|
|
144
|
-
ErrorInfo:
|
|
145
|
-
LoadingIndicator:
|
|
146
|
-
Router:
|
|
147
|
-
Layout:
|
|
148
|
-
RouteSwitch:
|
|
141
|
+
ErrorInfo: expect.anything(),
|
|
142
|
+
LoadingIndicator: expect.anything(),
|
|
143
|
+
Router: expect.anything(),
|
|
144
|
+
Layout: expect.anything(),
|
|
145
|
+
RouteSwitch: expect.anything(),
|
|
149
146
|
},
|
|
150
147
|
registry: {
|
|
151
148
|
extensions: {},
|
|
@@ -171,11 +168,11 @@ describe('Create Global State Module', () => {
|
|
|
171
168
|
},
|
|
172
169
|
errorComponents: {},
|
|
173
170
|
components: {
|
|
174
|
-
ErrorInfo:
|
|
175
|
-
LoadingIndicator:
|
|
176
|
-
Router:
|
|
177
|
-
Layout:
|
|
178
|
-
RouteSwitch:
|
|
171
|
+
ErrorInfo: expect.anything(),
|
|
172
|
+
LoadingIndicator: expect.anything(),
|
|
173
|
+
Router: expect.anything(),
|
|
174
|
+
Layout: expect.anything(),
|
|
175
|
+
RouteSwitch: expect.anything(),
|
|
179
176
|
},
|
|
180
177
|
registry: {
|
|
181
178
|
extensions: {},
|
|
@@ -206,11 +203,11 @@ describe('Create Global State Module', () => {
|
|
|
206
203
|
},
|
|
207
204
|
errorComponents: {},
|
|
208
205
|
components: {
|
|
209
|
-
ErrorInfo:
|
|
210
|
-
LoadingIndicator:
|
|
211
|
-
Router:
|
|
212
|
-
Layout:
|
|
213
|
-
RouteSwitch:
|
|
206
|
+
ErrorInfo: expect.anything(),
|
|
207
|
+
LoadingIndicator: expect.anything(),
|
|
208
|
+
Router: expect.anything(),
|
|
209
|
+
Layout: expect.anything(),
|
|
210
|
+
RouteSwitch: expect.anything(),
|
|
214
211
|
},
|
|
215
212
|
registry: {
|
|
216
213
|
extensions: {},
|
|
@@ -241,11 +238,11 @@ describe('Create Global State Module', () => {
|
|
|
241
238
|
},
|
|
242
239
|
errorComponents: {},
|
|
243
240
|
components: {
|
|
244
|
-
ErrorInfo:
|
|
245
|
-
LoadingIndicator:
|
|
246
|
-
Router:
|
|
247
|
-
Layout:
|
|
248
|
-
RouteSwitch:
|
|
241
|
+
ErrorInfo: expect.anything(),
|
|
242
|
+
LoadingIndicator: expect.anything(),
|
|
243
|
+
Router: expect.anything(),
|
|
244
|
+
Layout: expect.anything(),
|
|
245
|
+
RouteSwitch: expect.anything(),
|
|
249
246
|
},
|
|
250
247
|
registry: {
|
|
251
248
|
extensions: {},
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Atom } from '@dbeining/react-atom';
|
|
2
|
+
import { createDefaultState } from '../../app.codegen';
|
|
2
3
|
import { GlobalState, NestedPartial } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
DefaultErrorInfo,
|
|
5
|
-
DefaultLoadingIndicator,
|
|
6
|
-
DefaultLayout,
|
|
7
|
-
DefaultRouter,
|
|
8
|
-
DefaultRouteSwitch,
|
|
9
|
-
} from '../defaults';
|
|
10
4
|
|
|
11
5
|
function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
12
6
|
for (const key of Object.keys(customState)) {
|
|
@@ -24,30 +18,6 @@ function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
export function createGlobalState(customState: NestedPartial<GlobalState> = {}) {
|
|
27
|
-
const defaultState: GlobalState =
|
|
28
|
-
app: {
|
|
29
|
-
error: undefined,
|
|
30
|
-
loading: typeof window !== 'undefined',
|
|
31
|
-
publicPath: process.env.PIRAL_PUBLIC_PATH || '/',
|
|
32
|
-
},
|
|
33
|
-
components: {
|
|
34
|
-
ErrorInfo: DefaultErrorInfo,
|
|
35
|
-
LoadingIndicator: DefaultLoadingIndicator,
|
|
36
|
-
Router: DefaultRouter,
|
|
37
|
-
RouteSwitch: DefaultRouteSwitch,
|
|
38
|
-
Layout: DefaultLayout,
|
|
39
|
-
},
|
|
40
|
-
errorComponents: {},
|
|
41
|
-
registry: {
|
|
42
|
-
extensions: {},
|
|
43
|
-
pages: {},
|
|
44
|
-
wrappers: {},
|
|
45
|
-
},
|
|
46
|
-
routes: {},
|
|
47
|
-
data: {},
|
|
48
|
-
portals: {},
|
|
49
|
-
modules: [],
|
|
50
|
-
};
|
|
51
|
-
|
|
21
|
+
const defaultState: GlobalState = createDefaultState();
|
|
52
22
|
return Atom.of(extend(defaultState, customState));
|
|
53
23
|
}
|
package/src/types/components.ts
CHANGED
|
@@ -207,6 +207,20 @@ export interface RouterProps {
|
|
|
207
207
|
children?: ReactNode;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Represents a path in the app registration.
|
|
212
|
+
*/
|
|
213
|
+
export interface AppPath {
|
|
214
|
+
/**
|
|
215
|
+
* The exact path to use.
|
|
216
|
+
*/
|
|
217
|
+
path: string;
|
|
218
|
+
/**
|
|
219
|
+
* The component to register for this path.
|
|
220
|
+
*/
|
|
221
|
+
Component: ComponentType<RouteComponentProps>;
|
|
222
|
+
}
|
|
223
|
+
|
|
210
224
|
/**
|
|
211
225
|
* The props of the RouteSwitch component.
|
|
212
226
|
*/
|
|
@@ -218,14 +232,5 @@ export interface RouteSwitchProps extends SwitchProps {
|
|
|
218
232
|
/**
|
|
219
233
|
* The component to register for the different paths.
|
|
220
234
|
*/
|
|
221
|
-
paths: Array<
|
|
222
|
-
/**
|
|
223
|
-
* The exact path to use.
|
|
224
|
-
*/
|
|
225
|
-
path: string;
|
|
226
|
-
/**
|
|
227
|
-
* The component to register for this path.
|
|
228
|
-
*/
|
|
229
|
-
Component: ComponentType<RouteComponentProps>;
|
|
230
|
-
}>;
|
|
235
|
+
paths: Array<AppPath>;
|
|
231
236
|
}
|
package/src/types/state.ts
CHANGED
|
@@ -348,6 +348,12 @@ export interface PiralActions extends PiralCustomActions {
|
|
|
348
348
|
* @returns The desired part.
|
|
349
349
|
*/
|
|
350
350
|
readState<S>(select: (state: GlobalState) => S): S;
|
|
351
|
+
/**
|
|
352
|
+
* Performs a navigation.
|
|
353
|
+
* @param path The path to navigate to.
|
|
354
|
+
* @param state The optional state for the navigation.
|
|
355
|
+
*/
|
|
356
|
+
navigate(path: string, state?: any): void;
|
|
351
357
|
}
|
|
352
358
|
|
|
353
359
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { changeDomPortal, convertComponent, renderInDom } from './foreign';
|
|
3
|
-
import { DefaultLoadingIndicator } from '../defaults';
|
|
3
|
+
import { DefaultLoadingIndicator } from '../defaults/DefaultLoadingIndicator';
|
|
4
4
|
import { ForeignComponent } from '../types';
|
|
5
5
|
|
|
6
6
|
// const StubComponent: React.FC = (props) => <div />;
|
package/debug.codegen
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = function () {
|
|
2
|
-
const imports = [];
|
|
3
|
-
const exports = [];
|
|
4
|
-
|
|
5
|
-
// if we build the debug version of piral (debug and emulator build)
|
|
6
|
-
if (process.env.DEBUG_PIRAL) {
|
|
7
|
-
imports.push('import { integrateDebugger } from "./esm/debugger"');
|
|
8
|
-
exports.push(`export { integrateDebugger }`);
|
|
9
|
-
} else {
|
|
10
|
-
exports.push(`export function integrateDebugger() {}`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// if we build the emulator version of piral (shipped to pilets)
|
|
14
|
-
if (process.env.DEBUG_PILET) {
|
|
15
|
-
imports.push('import { integrateEmulator } from "./esm/emulator"');
|
|
16
|
-
exports.push(`export { integrateEmulator }`);
|
|
17
|
-
} else {
|
|
18
|
-
exports.push(`export function integrateEmulator() {}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return `${imports.join(';\n')}
|
|
22
|
-
${exports.join('\n')}
|
|
23
|
-
`;
|
|
24
|
-
};
|
package/dependencies.codegen
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function getIdentifiers(packageName) {
|
|
2
|
-
const packageJson = `${packageName}/package.json`;
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
const details = require(packageJson);
|
|
6
|
-
|
|
7
|
-
if (details.version) {
|
|
8
|
-
return [packageName, `${packageName}@${details.version}`];
|
|
9
|
-
}
|
|
10
|
-
} catch {}
|
|
11
|
-
|
|
12
|
-
return [packageName];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = function () {
|
|
16
|
-
const appName = process.env.BUILD_PCKG_NAME || '';
|
|
17
|
-
const externals = (process.env.SHARED_DEPENDENCIES || '').split(',').filter(Boolean);
|
|
18
|
-
const assignments = [];
|
|
19
|
-
const imports = [];
|
|
20
|
-
|
|
21
|
-
if (appName) {
|
|
22
|
-
assignments.push(`deps['${appName}']={}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
for (const name of externals) {
|
|
26
|
-
const identifiers = getIdentifiers(name);
|
|
27
|
-
const ref = `_${imports.length}`;
|
|
28
|
-
imports.push(`import * as ${ref} from ${JSON.stringify(name)}`);
|
|
29
|
-
|
|
30
|
-
for (const id of identifiers) {
|
|
31
|
-
assignments.push(`deps[${JSON.stringify(id)}]=${ref}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return `${imports.join(';\n')}
|
|
36
|
-
export default function(deps) {${assignments.join(';')}}`;
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (deps: Record<string, any>): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouteSwitch.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAA6B,EAAE,EAAE;QAAjC,EAAE,KAAK,EAAE,QAAQ,OAAY,EAAP,KAAK,cAA3B,qBAA6B,CAAF;IACxF,OAAO,CACL,oBAAC,MAAM,oBAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClC,oBAAC,KAAK,IAAC,KAAK,QAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAI,CAC7D,CAAC;QACF,oBAAC,KAAK,IAAC,SAAS,EAAE,QAAQ,GAAI,CACvB,CACV,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouter.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,CAAC,MAAM,aAAa,GAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3D,OAAO,oBAAC,aAAa,IAAC,QAAQ,EAAE,UAAU,IAAG,QAAQ,CAAiB,CAAC;AACzE,CAAC,CAAC"}
|
package/esm/defaults/index.d.ts
DELETED
package/esm/defaults/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouteSwitch.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch.tsx"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,+CAA6C;AAGtC,MAAM,kBAAkB,GAA+B,CAAC,EAA6B,EAAE,EAAE;QAAjC,EAAE,KAAK,EAAE,QAAQ,OAAY,EAAP,KAAK,sBAA3B,qBAA6B,CAAF;IACxF,OAAO,CACL,oBAAC,qBAAM,oBAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClC,oBAAC,oBAAK,IAAC,KAAK,QAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAI,CAC7D,CAAC;QACF,oBAAC,oBAAK,IAAC,SAAS,EAAE,QAAQ,GAAI,CACvB,CACV,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouter.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouter.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,uDAAiD;AACjD,oCAA0C;AAGnC,MAAM,aAAa,GAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3D,OAAO,oBAAC,gCAAa,IAAC,QAAQ,EAAE,UAAU,IAAG,QAAQ,CAAiB,CAAC;AACzE,CAAC,CAAC;AAHW,QAAA,aAAa,iBAGxB"}
|
package/lib/defaults/index.d.ts
DELETED
package/lib/defaults/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./DefaultErrorInfo"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./DefaultLayout"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./DefaultLoadingIndicator"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./DefaultRouter"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./DefaultRouteSwitch"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,0DAAgC;AAChC,oEAA0C;AAC1C,0DAAgC;AAChC,+DAAqC"}
|