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.
Files changed (120) hide show
  1. package/app.codegen +191 -0
  2. package/{debug.codegen.d.ts → app.codegen.d.ts} +10 -1
  3. package/esm/actions/app.d.ts +1 -0
  4. package/esm/actions/app.js +3 -0
  5. package/esm/actions/app.js.map +1 -1
  6. package/esm/components/PiralRoutes.js +2 -6
  7. package/esm/components/PiralRoutes.js.map +1 -1
  8. package/esm/components/wrapComponent.js +2 -2
  9. package/esm/components/wrapComponent.js.map +1 -1
  10. package/esm/createInstance.js +1 -1
  11. package/esm/createInstance.js.map +1 -1
  12. package/esm/debugger.js +3 -0
  13. package/esm/debugger.js.map +1 -1
  14. package/esm/defaults/{DefaultRouteSwitch.d.ts → DefaultRouteSwitch_v5.d.ts} +0 -0
  15. package/esm/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
  16. package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
  17. package/{lib/defaults/DefaultRouteSwitch.d.ts → esm/defaults/DefaultRouteSwitch_v6.d.ts} +0 -0
  18. package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
  19. package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
  20. package/esm/defaults/{DefaultRouter.d.ts → DefaultRouter_v5.d.ts} +0 -0
  21. package/esm/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
  22. package/esm/defaults/DefaultRouter_v5.js.map +1 -0
  23. package/{lib/defaults/DefaultRouter.d.ts → esm/defaults/DefaultRouter_v6.d.ts} +0 -0
  24. package/esm/defaults/DefaultRouter_v6.js +9 -0
  25. package/esm/defaults/DefaultRouter_v6.js.map +1 -0
  26. package/esm/emulator.js +2 -3
  27. package/esm/emulator.js.map +1 -1
  28. package/esm/helpers.js +1 -1
  29. package/esm/helpers.js.map +1 -1
  30. package/esm/hooks/index.d.ts +1 -0
  31. package/esm/hooks/index.js +1 -0
  32. package/esm/hooks/index.js.map +1 -1
  33. package/esm/hooks/routes.d.ts +2 -0
  34. package/esm/hooks/routes.js +11 -0
  35. package/esm/hooks/routes.js.map +1 -0
  36. package/esm/modules/dependencies.js +1 -1
  37. package/esm/modules/dependencies.js.map +1 -1
  38. package/esm/state/createGlobalState.js +2 -25
  39. package/esm/state/createGlobalState.js.map +1 -1
  40. package/esm/types/components.d.ts +14 -10
  41. package/esm/types/state.d.ts +6 -0
  42. package/lib/actions/app.d.ts +1 -0
  43. package/lib/actions/app.js +5 -1
  44. package/lib/actions/app.js.map +1 -1
  45. package/lib/components/PiralRoutes.js +1 -5
  46. package/lib/components/PiralRoutes.js.map +1 -1
  47. package/lib/components/wrapComponent.js +2 -2
  48. package/lib/components/wrapComponent.js.map +1 -1
  49. package/lib/createInstance.js +1 -1
  50. package/lib/createInstance.js.map +1 -1
  51. package/lib/debugger.js +3 -0
  52. package/lib/debugger.js.map +1 -1
  53. package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
  54. package/lib/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
  55. package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
  56. package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
  57. package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
  58. package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
  59. package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
  60. package/lib/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
  61. package/lib/defaults/DefaultRouter_v5.js.map +1 -0
  62. package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
  63. package/lib/defaults/DefaultRouter_v6.js +13 -0
  64. package/lib/defaults/DefaultRouter_v6.js.map +1 -0
  65. package/lib/emulator.js +2 -3
  66. package/lib/emulator.js.map +1 -1
  67. package/lib/helpers.js +3 -3
  68. package/lib/helpers.js.map +1 -1
  69. package/lib/hooks/index.d.ts +1 -0
  70. package/lib/hooks/index.js +1 -0
  71. package/lib/hooks/index.js.map +1 -1
  72. package/lib/hooks/routes.d.ts +2 -0
  73. package/lib/hooks/routes.js +15 -0
  74. package/lib/hooks/routes.js.map +1 -0
  75. package/lib/modules/dependencies.js +3 -3
  76. package/lib/modules/dependencies.js.map +1 -1
  77. package/lib/state/createGlobalState.js +2 -25
  78. package/lib/state/createGlobalState.js.map +1 -1
  79. package/lib/types/components.d.ts +14 -10
  80. package/lib/types/state.d.ts +6 -0
  81. package/package.json +10 -8
  82. package/src/Piral.test.tsx +7 -5
  83. package/src/RootListener.test.tsx +8 -4
  84. package/src/actions/app.ts +4 -0
  85. package/src/components/ForeignComponentContainer.test.tsx +9 -5
  86. package/src/components/PiralRoutes.test.tsx +23 -16
  87. package/src/components/PiralRoutes.tsx +2 -8
  88. package/src/components/wrapComponent.tsx +2 -2
  89. package/src/createInstance.tsx +1 -1
  90. package/src/debugger.ts +3 -0
  91. package/src/defaults/{DefaultRouteSwitch.tsx → DefaultRouteSwitch_v5.tsx} +1 -0
  92. package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
  93. package/src/defaults/{DefaultRouter.tsx → DefaultRouter_v5.tsx} +1 -0
  94. package/src/defaults/DefaultRouter_v6.tsx +10 -0
  95. package/src/emulator.ts +2 -10
  96. package/src/helpers.tsx +1 -1
  97. package/src/hooks/index.ts +1 -0
  98. package/src/hooks/routes.ts +14 -0
  99. package/src/hooks/setter.test.ts +1 -1
  100. package/src/modules/dependencies.ts +1 -1
  101. package/src/state/createGlobalState.test.ts +45 -48
  102. package/src/state/createGlobalState.ts +2 -32
  103. package/src/types/components.ts +15 -10
  104. package/src/types/state.ts +6 -0
  105. package/src/utils/foreign.test.ts +1 -1
  106. package/debug.codegen +0 -24
  107. package/dependencies.codegen +0 -37
  108. package/dependencies.codegen.d.ts +0 -1
  109. package/dependencies.codegen.native.js +0 -2
  110. package/esm/defaults/DefaultRouteSwitch.js.map +0 -1
  111. package/esm/defaults/DefaultRouter.js.map +0 -1
  112. package/esm/defaults/index.d.ts +0 -5
  113. package/esm/defaults/index.js +0 -6
  114. package/esm/defaults/index.js.map +0 -1
  115. package/lib/defaults/DefaultRouteSwitch.js.map +0 -1
  116. package/lib/defaults/DefaultRouter.js.map +0 -1
  117. package/lib/defaults/index.d.ts +0 -5
  118. package/lib/defaults/index.js +0 -9
  119. package/lib/defaults/index.js.map +0 -1
  120. 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).useGlobalState = (select: any) =>
18
- select({
19
- app: {},
20
- routes: {
21
- '/': StubHome,
22
- '/custom': StubCustomPage,
23
- },
24
- registry: {
25
- pages: {
26
- '/foo': { component: StubFooPage },
27
- '/foo/bar': { component: StubFooBarPage },
28
- '/bar': { component: StubBarPage },
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 { useGlobalState } from '../hooks';
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 routes = useGlobalState((s) => s.routes);
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 = React.useContext(__RouterContext);
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]);
@@ -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: process.env.BUILD_PCKG_VERSION || '1.0.0',
53
+ version: '0',
54
54
  spec: 'v0',
55
55
  basePath: '',
56
56
  link: '',
package/src/debugger.ts CHANGED
@@ -42,6 +42,9 @@ export function integrateDebugger(
42
42
  getGlobalState() {
43
43
  return context.readState((s) => s);
44
44
  },
45
+ navigate(path, state) {
46
+ return context.navigate(path, state);
47
+ },
45
48
  getPilets() {
46
49
  return context.readState((s) => s.modules);
47
50
  },
@@ -12,3 +12,4 @@ export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound
12
12
  </Switch>
13
13
  );
14
14
  };
15
+ DefaultRouteSwitch.displayName = 'DefaultRouteSwitch';
@@ -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';
@@ -7,3 +7,4 @@ export const DefaultRouter: React.FC<RouterProps> = ({ children }) => {
7
7
  const publicPath = useGlobalState((s) => s.app.publicPath);
8
8
  return <BrowserRouter basename={publicPath}>{children}</BrowserRouter>;
9
9
  };
10
+ DefaultRouter.displayName = 'DefaultRouter';
@@ -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(emulator) {
10
- context.dispatch((s) => ({
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 '../debug.codegen';
14
+ import { integrateDebugger, integrateEmulator } from '../app.codegen';
15
15
 
16
16
  export interface PiletOptionsConfig {
17
17
  context: GlobalStateContext;
@@ -2,5 +2,6 @@ export * from './action';
2
2
  export * from './actions';
3
3
  export * from './globalState';
4
4
  export * from './media';
5
+ export * from './routes';
5
6
  export * from './setter';
6
7
  export * from './sharedData';
@@ -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
+ }
@@ -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.resolve());
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 '../../dependencies.codegen';
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
- expect(deref(globalState)).toEqual({
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: DefaultErrorInfo,
27
- LoadingIndicator: DefaultLoadingIndicator,
28
- Router: DefaultRouter,
29
- Layout: DefaultLayout,
30
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
55
- LoadingIndicator: DefaultLoadingIndicator,
56
- Router: DefaultRouter,
57
- Layout: DefaultLayout,
58
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
87
- LoadingIndicator: DefaultLoadingIndicator,
88
- Router: DefaultRouter,
89
- Layout: DefaultLayout,
90
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
115
- LoadingIndicator: DefaultLoadingIndicator,
116
- Router: DefaultRouter,
117
- Layout: DefaultLayout,
118
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
145
- LoadingIndicator: DefaultLoadingIndicator,
146
- Router: DefaultRouter,
147
- Layout: DefaultLayout,
148
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
175
- LoadingIndicator: DefaultLoadingIndicator,
176
- Router: DefaultRouter,
177
- Layout: DefaultLayout,
178
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
210
- LoadingIndicator: DefaultLoadingIndicator,
211
- Router: DefaultRouter,
212
- Layout: DefaultLayout,
213
- RouteSwitch: DefaultRouteSwitch,
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: DefaultErrorInfo,
245
- LoadingIndicator: DefaultLoadingIndicator,
246
- Router: DefaultRouter,
247
- Layout: DefaultLayout,
248
- RouteSwitch: DefaultRouteSwitch,
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
  }
@@ -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
  }
@@ -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
- };
@@ -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,2 +0,0 @@
1
- // required for piral-native; otherwise non-essential
2
- export default function() {};
@@ -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"}
@@ -1,5 +0,0 @@
1
- export * from './DefaultErrorInfo';
2
- export * from './DefaultLayout';
3
- export * from './DefaultLoadingIndicator';
4
- export * from './DefaultRouter';
5
- export * from './DefaultRouteSwitch';
@@ -1,6 +0,0 @@
1
- export * from './DefaultErrorInfo';
2
- export * from './DefaultLayout';
3
- export * from './DefaultLoadingIndicator';
4
- export * from './DefaultRouter';
5
- export * from './DefaultRouteSwitch';
6
- //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,5 +0,0 @@
1
- export * from './DefaultErrorInfo';
2
- export * from './DefaultLayout';
3
- export * from './DefaultLoadingIndicator';
4
- export * from './DefaultRouter';
5
- export * from './DefaultRouteSwitch';
@@ -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"}
@@ -1,5 +0,0 @@
1
- export * from './DefaultErrorInfo';
2
- export * from './DefaultLayout';
3
- export * from './DefaultLoadingIndicator';
4
- export * from './DefaultRouter';
5
- export * from './DefaultRouteSwitch';