piral-core 0.15.0-alpha.3740 → 0.15.0-alpha.3784

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 (61) hide show
  1. package/debug.codegen +1 -1
  2. package/debug.codegen.d.ts +5 -1
  3. package/esm/actions/app.d.ts +3 -3
  4. package/esm/actions/app.js +8 -10
  5. package/esm/actions/app.js.map +1 -1
  6. package/esm/components/DefaultRouteSwitch.d.ts +3 -0
  7. package/esm/components/DefaultRouteSwitch.js +10 -0
  8. package/esm/components/DefaultRouteSwitch.js.map +1 -0
  9. package/esm/components/PiralRoutes.d.ts +5 -0
  10. package/esm/components/PiralRoutes.js +5 -6
  11. package/esm/components/PiralRoutes.js.map +1 -1
  12. package/esm/components/PiralView.js +2 -2
  13. package/esm/components/PiralView.js.map +1 -1
  14. package/esm/components/components.d.ts +6 -1
  15. package/esm/components/components.js +6 -0
  16. package/esm/components/components.js.map +1 -1
  17. package/esm/components/index.d.ts +1 -0
  18. package/esm/components/index.js +1 -0
  19. package/esm/components/index.js.map +1 -1
  20. package/esm/emulator.js +6 -2
  21. package/esm/emulator.js.map +1 -1
  22. package/esm/state/createGlobalState.js +2 -1
  23. package/esm/state/createGlobalState.js.map +1 -1
  24. package/esm/types/components.d.ts +23 -1
  25. package/esm/types/state.d.ts +10 -4
  26. package/lib/actions/app.d.ts +3 -3
  27. package/lib/actions/app.js +7 -9
  28. package/lib/actions/app.js.map +1 -1
  29. package/lib/components/DefaultRouteSwitch.d.ts +3 -0
  30. package/lib/components/DefaultRouteSwitch.js +14 -0
  31. package/lib/components/DefaultRouteSwitch.js.map +1 -0
  32. package/lib/components/PiralRoutes.d.ts +5 -0
  33. package/lib/components/PiralRoutes.js +5 -6
  34. package/lib/components/PiralRoutes.js.map +1 -1
  35. package/lib/components/PiralView.js +2 -2
  36. package/lib/components/PiralView.js.map +1 -1
  37. package/lib/components/components.d.ts +6 -1
  38. package/lib/components/components.js +7 -1
  39. package/lib/components/components.js.map +1 -1
  40. package/lib/components/index.d.ts +1 -0
  41. package/lib/components/index.js +1 -0
  42. package/lib/components/index.js.map +1 -1
  43. package/lib/emulator.js +5 -1
  44. package/lib/emulator.js.map +1 -1
  45. package/lib/state/createGlobalState.js +1 -0
  46. package/lib/state/createGlobalState.js.map +1 -1
  47. package/lib/types/components.d.ts +23 -1
  48. package/lib/types/state.d.ts +10 -4
  49. package/package.json +4 -4
  50. package/src/actions/app.ts +13 -12
  51. package/src/components/DefaultRouteSwitch.tsx +14 -0
  52. package/src/components/PiralRoutes.test.tsx +7 -6
  53. package/src/components/PiralRoutes.tsx +12 -13
  54. package/src/components/PiralView.tsx +9 -2
  55. package/src/components/components.tsx +15 -1
  56. package/src/components/index.ts +1 -0
  57. package/src/emulator.ts +13 -2
  58. package/src/state/createGlobalState.test.ts +15 -1
  59. package/src/state/createGlobalState.ts +8 -1
  60. package/src/types/components.ts +24 -1
  61. package/src/types/state.ts +10 -3
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PiralDebug = exports.PiralLayout = exports.PiralRouter = exports.PiralLoadingIndicator = exports.PiralError = exports.getPiralComponent = void 0;
3
+ exports.PiralDebug = exports.PiralLayout = exports.PiralRouteSwitch = exports.PiralRouter = exports.PiralLoadingIndicator = exports.PiralError = exports.getPiralComponent = void 0;
4
4
  const React = require("react");
5
5
  const hooks_1 = require("../hooks");
6
6
  function getPiralComponent(name) {
7
7
  return (props) => {
8
8
  const Component = (0, hooks_1.useGlobalState)((s) => s.components[name]);
9
+ // tslint:disable-next-line:no-null-keyword
9
10
  return Component ? React.createElement(Component, Object.assign({}, props)) : null;
10
11
  };
11
12
  }
@@ -25,6 +26,11 @@ exports.PiralLoadingIndicator = getPiralComponent('LoadingIndicator');
25
26
  * By default the BrowserRouter is used.
26
27
  */
27
28
  exports.PiralRouter = getPiralComponent('Router');
29
+ /**
30
+ * Gets the currently registered Route Switch component.
31
+ * By default the DefaultRouteSwitch component is used.
32
+ */
33
+ exports.PiralRouteSwitch = getPiralComponent('RouteSwitch');
28
34
  /**
29
35
  * Gets the currently registered Layout component.
30
36
  * By default the children are rendered.
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components/components.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,oCAA0C;AAG1C,SAAgB,iBAAiB,CAAqC,IAAU;IAC9E,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,SAAS,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC,CAAC,CAAC,oBAAC,SAAS,oBAAK,KAAK,EAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AALD,8CAKC;AAED;;;GAGG;AACU,QAAA,UAAU,GAAwC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAE9F;;;GAGG;AACU,QAAA,qBAAqB,GAA+C,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAEvH;;;GAGG;AACU,QAAA,WAAW,GAAqC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAEzF;;;GAGG;AACU,QAAA,WAAW,GAAqC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAEzF;;;GAGG;AACU,QAAA,UAAU,GAAwB,iBAAiB,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/components/components.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,oCAA0C;AAU1C,SAAgB,iBAAiB,CAAqC,IAAU;IAC9E,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,SAAS,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,2CAA2C;QAC3C,OAAO,SAAS,CAAC,CAAC,CAAC,oBAAC,SAAS,oBAAK,KAAK,EAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AAND,8CAMC;AAED;;;GAGG;AACU,QAAA,UAAU,GAAwC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAE9F;;;GAGG;AACU,QAAA,qBAAqB,GAA+C,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAEvH;;;GAGG;AACU,QAAA,WAAW,GAAqC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAEzF;;;GAGG;AACU,QAAA,gBAAgB,GAA0C,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAExG;;;GAGG;AACU,QAAA,WAAW,GAAqC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAEzF;;;GAGG;AACU,QAAA,UAAU,GAAwB,iBAAiB,CAAC,OAAO,CAAC,CAAC"}
@@ -3,6 +3,7 @@ export * from './DefaultErrorInfo';
3
3
  export * from './DefaultLayout';
4
4
  export * from './DefaultLoader';
5
5
  export * from './DefaultRouter';
6
+ export * from './DefaultRouteSwitch';
6
7
  export * from './ErrorBoundary';
7
8
  export * from './ExtensionSlot';
8
9
  export * from './Mediator';
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
6
6
  (0, tslib_1.__exportStar)(require("./DefaultLayout"), exports);
7
7
  (0, tslib_1.__exportStar)(require("./DefaultLoader"), exports);
8
8
  (0, tslib_1.__exportStar)(require("./DefaultRouter"), exports);
9
+ (0, tslib_1.__exportStar)(require("./DefaultRouteSwitch"), exports);
9
10
  (0, tslib_1.__exportStar)(require("./ErrorBoundary"), exports);
10
11
  (0, tslib_1.__exportStar)(require("./ExtensionSlot"), exports);
11
12
  (0, tslib_1.__exportStar)(require("./Mediator"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,kEAAmC;AACnC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,0DAA2B;AAC3B,6DAA8B;AAC9B,2DAA4B;AAC5B,gEAAiC;AACjC,kEAAmC;AACnC,8DAA+B;AAC/B,0DAA2B;AAC3B,2DAA4B;AAC5B,2DAA4B;AAC5B,6DAA8B;AAC9B,6DAA8B;AAC9B,0DAA2B;AAC3B,iEAAkC;AAClC,+DAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,kEAAmC;AACnC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,oEAAqC;AACrC,+DAAgC;AAChC,+DAAgC;AAChC,0DAA2B;AAC3B,6DAA8B;AAC9B,2DAA4B;AAC5B,gEAAiC;AACjC,kEAAmC;AACnC,8DAA+B;AAC/B,0DAA2B;AAC3B,2DAA4B;AAC5B,2DAA4B;AAC5B,6DAA8B;AAC9B,6DAA8B;AAC9B,0DAA2B;AAC3B,iEAAkC;AAClC,+DAAgC"}
package/lib/emulator.js CHANGED
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.integrateEmulator = void 0;
4
4
  const piral_debug_utils_1 = require("piral-debug-utils");
5
5
  function integrateEmulator(context, options) {
6
- options.fetchPilets = (0, piral_debug_utils_1.withEmulatorPilets)(options.fetchPilets, {
6
+ (0, piral_debug_utils_1.installPiletEmulator)(options.fetchPilets, {
7
7
  addPilet: context.addPilet,
8
8
  removePilet: context.removePilet,
9
+ integrate(emulator) {
10
+ context.dispatch((s) => (Object.assign(Object.assign({}, s), { components: Object.assign(Object.assign({}, s.components), emulator.components) })));
11
+ options.fetchPilets = emulator.requester;
12
+ },
9
13
  });
10
14
  }
11
15
  exports.integrateEmulator = integrateEmulator;
@@ -1 +1 @@
1
- {"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AACA,yDAAuD;AAGvD,SAAgB,iBAAiB,CAAC,OAA2B,EAAE,OAA0B;IACvF,OAAO,CAAC,WAAW,GAAG,IAAA,sCAAkB,EAAC,OAAO,CAAC,WAAW,EAAE;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAC;AACL,CAAC;AALD,8CAKC"}
1
+ {"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AACA,yDAAyD;AAGzD,SAAgB,iBAAiB,CAAC,OAA2B,EAAE,OAA0B;IACvF,IAAA,wCAAoB,EAAC,OAAO,CAAC,WAAW,EAAE;QACxC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,SAAS,CAAC,QAAQ;YAChB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iCACnB,CAAC,KACJ,UAAU,kCACL,CAAC,CAAC,UAAU,GACZ,QAAQ,CAAC,UAAU,KAExB,CAAC,CAAC;YAEJ,OAAO,CAAC,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC;QAC3C,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAhBD,8CAgBC"}
@@ -27,6 +27,7 @@ function createGlobalState(customState = {}) {
27
27
  ErrorInfo: components_1.DefaultErrorInfo,
28
28
  LoadingIndicator: components_1.DefaultLoadingIndicator,
29
29
  Router: components_1.DefaultRouter,
30
+ RouteSwitch: components_1.DefaultRouteSwitch,
30
31
  Layout: components_1.DefaultLayout,
31
32
  },
32
33
  errorComponents: {},
@@ -1 +1 @@
1
- {"version":3,"file":"createGlobalState.js","sourceRoot":"","sources":["../../src/state/createGlobalState.ts"],"names":[],"mappings":";;;AAAA,qDAA4C;AAC5C,8CAAwG;AAGxG,SAAS,MAAM,CAAI,YAAe,EAAE,WAA6B;IA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O,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,OAAO,iBAAI,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AACpD,CAAC;AA5BD,8CA4BC"}
@@ -1,5 +1,5 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { RouteComponentProps } from 'react-router';
2
+ import type { RouteComponentProps, SwitchProps } from 'react-router';
3
3
  import type { FirstParametersOf, UnionOf } from './common';
4
4
  import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
5
5
  import type { LayoutType } from './layout';
@@ -181,3 +181,25 @@ export interface LayoutProps {
181
181
  */
182
182
  export interface RouterProps {
183
183
  }
184
+ /**
185
+ * The props of the RouteSwitch component.
186
+ */
187
+ export interface RouteSwitchProps extends SwitchProps {
188
+ /**
189
+ * The component that should be used in case nothing was found.
190
+ */
191
+ NotFound: ComponentType<RouteComponentProps>;
192
+ /**
193
+ * The component to register for the different paths.
194
+ */
195
+ paths: Array<{
196
+ /**
197
+ * The exact path to use.
198
+ */
199
+ path: string;
200
+ /**
201
+ * The component to register for this path.
202
+ */
203
+ Component: ComponentType<RouteComponentProps>;
204
+ }>;
205
+ }
@@ -7,7 +7,7 @@ import type { LayoutType } from './layout';
7
7
  import type { SharedDataItem, DataStoreTarget } from './data';
8
8
  import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
9
9
  import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, PiralPageMeta, PiletEntry } from './api';
10
- import type { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors } from './components';
10
+ import type { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors, RouteSwitchProps } from './components';
11
11
  export interface StateDispatcher<TState> {
12
12
  (state: TState): Partial<TState>;
13
13
  }
@@ -59,6 +59,10 @@ export interface ComponentsState extends PiralCustomComponentsState {
59
59
  * The layout used for pages.
60
60
  */
61
61
  Layout: ComponentType<LayoutProps>;
62
+ /**
63
+ * The route switch used for determining the route registration.
64
+ */
65
+ RouteSwitch: ComponentType<RouteSwitchProps>;
62
66
  /**
63
67
  * A component that can be used for debugging purposes.
64
68
  */
@@ -174,18 +178,20 @@ export interface PiralActions extends PiralCustomActions {
174
178
  /**
175
179
  * Injects an evaluated pilet at runtime - removes the pilet from registry first if available.
176
180
  * @param pilet The pilet to be injected.
181
+ * @returns The injected pilet.
177
182
  */
178
- injectPilet(pilet: Pilet): void;
183
+ injectPilet(pilet: Pilet): Pilet;
179
184
  /**
180
185
  * Adds a pilet at runtime by loading it, evaluating it, and then injecting it.
181
186
  * @param pilet The pilet to be added.
187
+ * @returns The promise indicating when the pilet was fully added.
182
188
  */
183
- addPilet(pilet: PiletEntry): void;
189
+ addPilet(pilet: PiletEntry): Promise<void>;
184
190
  /**
185
191
  * Removes a pilet by unloading it and deleting all component registrations.
186
192
  * @param name The name of the pilet to remove.
187
193
  */
188
- removePilet(name: string): void;
194
+ removePilet(name: string): Promise<void>;
189
195
  /**
190
196
  * Defines a single action for Piral.
191
197
  * @param actionName The name of the action to define.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-alpha.3740",
3
+ "version": "0.15.0-alpha.3784",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@dbeining/react-atom": "^4.0.0",
51
- "piral-base": "0.15.0-alpha.3740",
52
- "piral-debug-utils": "0.15.0-alpha.3740"
51
+ "piral-base": "0.15.0-alpha.3784",
52
+ "piral-debug-utils": "0.15.0-alpha.3784"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0",
@@ -79,5 +79,5 @@
79
79
  "@libre/atom",
80
80
  "@dbeining/react-atom"
81
81
  ],
82
- "gitHead": "e70f3043f4e6750dfab89dd5fd7c9da874cb2883"
82
+ "gitHead": "e2dc030bd7e656d349caf5353740e45329e471f1"
83
83
  }
@@ -1,7 +1,7 @@
1
1
  import { ComponentType } from 'react';
2
2
  import { RouteComponentProps } from 'react-router';
3
3
  import { runPilet } from 'piral-base';
4
- import { withKey, replaceOrAddItem, removeNested, withProvider, withRoute } from '../utils';
4
+ import { withKey, replaceOrAddItem, removeNested, withProvider, withRoute, noop } from '../utils';
5
5
  import {
6
6
  LayoutType,
7
7
  ComponentsState,
@@ -32,18 +32,15 @@ export function initialize(ctx: GlobalStateContext, loading: boolean, error: Err
32
32
  }));
33
33
  }
34
34
 
35
- export function addPilet(ctx: GlobalStateContext, meta: PiletEntry) {
36
- ctx.options.loadPilet(meta).then((pilet) => {
37
- try {
38
- ctx.injectPilet(pilet);
39
- runPilet(ctx.options.createApi, pilet, ctx.options.hooks);
40
- } catch (error) {
41
- console.error(error);
42
- }
43
- });
35
+ export function addPilet(ctx: GlobalStateContext, meta: PiletEntry): Promise<void> {
36
+ return ctx.options
37
+ .loadPilet(meta)
38
+ .then((pilet) => ctx.injectPilet(pilet))
39
+ .then((pilet) => runPilet(ctx.options.createApi, pilet, ctx.options.hooks))
40
+ .then(noop);
44
41
  }
45
42
 
46
- export function removePilet(ctx: GlobalStateContext, name: string) {
43
+ export function removePilet(ctx: GlobalStateContext, name: string): Promise<void> {
47
44
  ctx.dispatch((state) => ({
48
45
  ...state,
49
46
  modules: state.modules.filter((m) => m.name !== name),
@@ -53,9 +50,11 @@ export function removePilet(ctx: GlobalStateContext, name: string) {
53
50
  ctx.emit('unload-pilet', {
54
51
  name,
55
52
  });
53
+
54
+ return Promise.resolve();
56
55
  }
57
56
 
58
- export function injectPilet(ctx: GlobalStateContext, pilet: Pilet) {
57
+ export function injectPilet(ctx: GlobalStateContext, pilet: Pilet): Pilet {
59
58
  ctx.dispatch((state) => ({
60
59
  ...state,
61
60
  modules: replaceOrAddItem(state.modules, pilet, (m) => m.name === pilet.name),
@@ -65,6 +64,8 @@ export function injectPilet(ctx: GlobalStateContext, pilet: Pilet) {
65
64
  ctx.emit('unload-pilet', {
66
65
  name: pilet.name,
67
66
  });
67
+
68
+ return pilet;
68
69
  }
69
70
 
70
71
  export function setComponent<TKey extends keyof ComponentsState>(
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { Switch, Route } from 'react-router';
3
+ import { RouteSwitchProps } from '../types';
4
+
5
+ export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
6
+ return (
7
+ <Switch {...props}>
8
+ {paths.map(({ path, Component }) => (
9
+ <Route exact key={path} path={path} component={Component} />
10
+ ))}
11
+ <Route component={NotFound} />
12
+ </Switch>
13
+ );
14
+ };
@@ -2,6 +2,7 @@ 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';
5
6
  import { PiralRoutes } from './PiralRoutes';
6
7
 
7
8
  const mountWithRouter = (node, url = '/') =>
@@ -52,7 +53,7 @@ StubBarPage.displayName = 'StubBarPage';
52
53
 
53
54
  describe('Routes Module', () => {
54
55
  it('always goes to the given home on "/"', () => {
55
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/');
56
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/');
56
57
  expect(node.find(StubHome).length).toBe(1);
57
58
  expect(node.find(StubNotFound).length).toBe(0);
58
59
  expect(node.find(StubCustomPage).length).toBe(0);
@@ -60,7 +61,7 @@ describe('Routes Module', () => {
60
61
  });
61
62
 
62
63
  it('goes to the not found on an invalid path', () => {
63
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/qxz');
64
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/qxz');
64
65
  expect(node.find(StubHome).length).toBe(0);
65
66
  expect(node.find(StubNotFound).length).toBe(1);
66
67
  expect(node.find(StubCustomPage).length).toBe(0);
@@ -68,7 +69,7 @@ describe('Routes Module', () => {
68
69
  });
69
70
 
70
71
  it('goes to the custom page on "/custom"', () => {
71
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/custom');
72
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/custom');
72
73
  expect(node.find(StubHome).length).toBe(0);
73
74
  expect(node.find(StubNotFound).length).toBe(0);
74
75
  expect(node.find(StubCustomPage).length).toBe(1);
@@ -76,7 +77,7 @@ describe('Routes Module', () => {
76
77
  });
77
78
 
78
79
  it('goes exactly to the page on "/foo/bar"', () => {
79
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/foo/bar');
80
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/foo/bar');
80
81
  expect(node.find(StubHome).length).toBe(0);
81
82
  expect(node.find(StubNotFound).length).toBe(0);
82
83
  expect(node.find(StubCustomPage).length).toBe(0);
@@ -84,7 +85,7 @@ describe('Routes Module', () => {
84
85
  });
85
86
 
86
87
  it('goes exactly to the page on "/foo"', () => {
87
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/foo');
88
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/foo');
88
89
  expect(node.find(StubHome).length).toBe(0);
89
90
  expect(node.find(StubNotFound).length).toBe(0);
90
91
  expect(node.find(StubCustomPage).length).toBe(0);
@@ -93,7 +94,7 @@ describe('Routes Module', () => {
93
94
  });
94
95
 
95
96
  it('goes exactly to the page on "/bar"', () => {
96
- const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} />, '/bar');
97
+ const node = mountWithRouter(<PiralRoutes NotFound={StubNotFound} RouteSwitch={DefaultRouteSwitch} />, '/bar');
97
98
  expect(node.find(StubHome).length).toBe(0);
98
99
  expect(node.find(StubNotFound).length).toBe(0);
99
100
  expect(node.find(StubCustomPage).length).toBe(0);
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
- import { Route, Switch, RouteComponentProps, SwitchProps } from 'react-router';
2
+ import { RouteComponentProps, SwitchProps } from 'react-router';
3
3
  import { useGlobalState } from '../hooks';
4
+ import { RouteSwitchProps } from '../types';
4
5
 
5
6
  /**
6
7
  * The props used by the PiralRoutes component.
@@ -10,25 +11,23 @@ export interface RoutesProps extends SwitchProps {
10
11
  * Sets the component for showing the not found page.
11
12
  */
12
13
  NotFound: React.ComponentType<RouteComponentProps>;
14
+ /**
15
+ * Sets the component for actually switching the routes.
16
+ */
17
+ RouteSwitch: React.ComponentType<RouteSwitchProps>;
13
18
  }
14
19
 
15
20
  /**
16
21
  * The component for defining the exclusive routes to be used.
17
22
  */
18
- export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, ...props }) => {
23
+ export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, RouteSwitch, ...props }) => {
19
24
  const routes = useGlobalState((s) => s.routes);
20
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 }));
21
30
 
22
- return (
23
- <Switch {...props}>
24
- {Object.keys(routes).map((url) => (
25
- <Route exact key={url} path={url} component={routes[url]} />
26
- ))}
27
- {Object.keys(pages).map((url) => (
28
- <Route exact key={url} path={url} component={pages[url].component} />
29
- ))}
30
- <Route component={NotFound} />
31
- </Switch>
32
- );
31
+ return <RouteSwitch NotFound={NotFound} paths={paths} {...props} />;
33
32
  };
34
33
  PiralRoutes.displayName = 'Routes';
@@ -1,7 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import { RouteComponentProps, StaticRouter } from 'react-router';
3
- import { PiralError, PiralRouter, PiralLoadingIndicator, PiralLayout, PiralDebug } from './components';
4
3
  import { PiralRoutes } from './PiralRoutes';
4
+ import {
5
+ PiralError,
6
+ PiralRouter,
7
+ PiralLoadingIndicator,
8
+ PiralRouteSwitch,
9
+ PiralLayout,
10
+ PiralDebug,
11
+ } from './components';
5
12
  import { useGlobalState } from '../hooks';
6
13
 
7
14
  const NotFound: React.FC<RouteComponentProps> = (props) => <PiralError type="not_found" {...props} />;
@@ -15,7 +22,7 @@ const PiralContent: React.FC = () => {
15
22
  <PiralLoadingIndicator />
16
23
  ) : (
17
24
  <PiralLayout currentLayout={layout}>
18
- <PiralRoutes NotFound={NotFound} />
25
+ <PiralRoutes NotFound={NotFound} RouteSwitch={PiralRouteSwitch} />
19
26
  </PiralLayout>
20
27
  );
21
28
  };
@@ -1,10 +1,18 @@
1
1
  import * as React from 'react';
2
2
  import { useGlobalState } from '../hooks';
3
- import { ComponentsState, ErrorInfoProps, LoadingIndicatorProps, RouterProps, LayoutProps } from '../types';
3
+ import {
4
+ ComponentsState,
5
+ ErrorInfoProps,
6
+ LoadingIndicatorProps,
7
+ RouterProps,
8
+ LayoutProps,
9
+ RouteSwitchProps,
10
+ } from '../types';
4
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]);
15
+ // tslint:disable-next-line:no-null-keyword
8
16
  return Component ? <Component {...props} /> : null;
9
17
  };
10
18
  }
@@ -27,6 +35,12 @@ export const PiralLoadingIndicator: React.ComponentType<LoadingIndicatorProps> =
27
35
  */
28
36
  export const PiralRouter: React.ComponentType<RouterProps> = getPiralComponent('Router');
29
37
 
38
+ /**
39
+ * Gets the currently registered Route Switch component.
40
+ * By default the DefaultRouteSwitch component is used.
41
+ */
42
+ export const PiralRouteSwitch: React.ComponentType<RouteSwitchProps> = getPiralComponent('RouteSwitch');
43
+
30
44
  /**
31
45
  * Gets the currently registered Layout component.
32
46
  * By default the children are rendered.
@@ -3,6 +3,7 @@ export * from './DefaultErrorInfo';
3
3
  export * from './DefaultLayout';
4
4
  export * from './DefaultLoader';
5
5
  export * from './DefaultRouter';
6
+ export * from './DefaultRouteSwitch';
6
7
  export * from './ErrorBoundary';
7
8
  export * from './ExtensionSlot';
8
9
  export * from './Mediator';
package/src/emulator.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import { LoadPiletsOptions } from 'piral-base';
2
- import { withEmulatorPilets } from 'piral-debug-utils';
2
+ import { installPiletEmulator } from 'piral-debug-utils';
3
3
  import { GlobalStateContext } from './types';
4
4
 
5
5
  export function integrateEmulator(context: GlobalStateContext, options: LoadPiletsOptions) {
6
- options.fetchPilets = withEmulatorPilets(options.fetchPilets, {
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;
19
+ },
9
20
  });
10
21
  }
@@ -1,6 +1,12 @@
1
1
  import { deref } from '@dbeining/react-atom';
2
2
  import { createGlobalState } from './createGlobalState';
3
- import { DefaultErrorInfo, DefaultLoadingIndicator, DefaultLayout, DefaultRouter } from '../components';
3
+ import {
4
+ DefaultErrorInfo,
5
+ DefaultLoadingIndicator,
6
+ DefaultLayout,
7
+ DefaultRouter,
8
+ DefaultRouteSwitch,
9
+ } from '../components';
4
10
 
5
11
  process.env.PIRAL_PUBLIC_PATH = '/';
6
12
 
@@ -22,6 +28,7 @@ describe('Create Global State Module', () => {
22
28
  LoadingIndicator: DefaultLoadingIndicator,
23
29
  Router: DefaultRouter,
24
30
  Layout: DefaultLayout,
31
+ RouteSwitch: DefaultRouteSwitch,
25
32
  },
26
33
  routes: {},
27
34
  registry: {
@@ -50,6 +57,7 @@ describe('Create Global State Module', () => {
50
57
  LoadingIndicator: DefaultLoadingIndicator,
51
58
  Router: DefaultRouter,
52
59
  Layout: DefaultLayout,
60
+ RouteSwitch: DefaultRouteSwitch,
53
61
  },
54
62
  routes: {},
55
63
  registry: {
@@ -82,6 +90,7 @@ describe('Create Global State Module', () => {
82
90
  LoadingIndicator: DefaultLoadingIndicator,
83
91
  Router: DefaultRouter,
84
92
  Layout: DefaultLayout,
93
+ RouteSwitch: DefaultRouteSwitch,
85
94
  },
86
95
  routes,
87
96
  registry: {
@@ -110,6 +119,7 @@ describe('Create Global State Module', () => {
110
119
  LoadingIndicator: DefaultLoadingIndicator,
111
120
  Router: DefaultRouter,
112
121
  Layout: DefaultLayout,
122
+ RouteSwitch: DefaultRouteSwitch,
113
123
  },
114
124
  registry: {
115
125
  extensions: {},
@@ -140,6 +150,7 @@ describe('Create Global State Module', () => {
140
150
  LoadingIndicator: DefaultLoadingIndicator,
141
151
  Router: DefaultRouter,
142
152
  Layout: DefaultLayout,
153
+ RouteSwitch: DefaultRouteSwitch,
143
154
  },
144
155
  registry: {
145
156
  extensions: {},
@@ -170,6 +181,7 @@ describe('Create Global State Module', () => {
170
181
  LoadingIndicator: DefaultLoadingIndicator,
171
182
  Router: DefaultRouter,
172
183
  Layout: DefaultLayout,
184
+ RouteSwitch: DefaultRouteSwitch,
173
185
  },
174
186
  registry: {
175
187
  extensions: {},
@@ -206,6 +218,7 @@ describe('Create Global State Module', () => {
206
218
  LoadingIndicator: DefaultLoadingIndicator,
207
219
  Router: DefaultRouter,
208
220
  Layout: DefaultLayout,
221
+ RouteSwitch: DefaultRouteSwitch,
209
222
  },
210
223
  registry: {
211
224
  extensions: {},
@@ -241,6 +254,7 @@ describe('Create Global State Module', () => {
241
254
  LoadingIndicator: DefaultLoadingIndicator,
242
255
  Router: DefaultRouter,
243
256
  Layout: DefaultLayout,
257
+ RouteSwitch: DefaultRouteSwitch,
244
258
  },
245
259
  registry: {
246
260
  extensions: {},
@@ -1,5 +1,11 @@
1
1
  import { Atom } from '@dbeining/react-atom';
2
- import { DefaultErrorInfo, DefaultLoadingIndicator, DefaultLayout, DefaultRouter } from '../components';
2
+ import {
3
+ DefaultErrorInfo,
4
+ DefaultLoadingIndicator,
5
+ DefaultLayout,
6
+ DefaultRouter,
7
+ DefaultRouteSwitch,
8
+ } from '../components';
3
9
  import { GlobalState, NestedPartial } from '../types';
4
10
 
5
11
  function extend<T>(defaultState: T, customState: NestedPartial<T>) {
@@ -29,6 +35,7 @@ export function createGlobalState(customState: NestedPartial<GlobalState> = {})
29
35
  ErrorInfo: DefaultErrorInfo,
30
36
  LoadingIndicator: DefaultLoadingIndicator,
31
37
  Router: DefaultRouter,
38
+ RouteSwitch: DefaultRouteSwitch,
32
39
  Layout: DefaultLayout,
33
40
  },
34
41
  errorComponents: {},
@@ -1,5 +1,5 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { RouteComponentProps } from 'react-router';
2
+ import type { RouteComponentProps, SwitchProps } from 'react-router';
3
3
  import type { FirstParametersOf, UnionOf } from './common';
4
4
  import type { PiralCustomErrors, PiralCustomComponentConverters } from './custom';
5
5
  import type { LayoutType } from './layout';
@@ -194,3 +194,26 @@ export interface LayoutProps {
194
194
  * The props of a Router component.
195
195
  */
196
196
  export interface RouterProps {}
197
+
198
+ /**
199
+ * The props of the RouteSwitch component.
200
+ */
201
+ export interface RouteSwitchProps extends SwitchProps {
202
+ /**
203
+ * The component that should be used in case nothing was found.
204
+ */
205
+ NotFound: ComponentType<RouteComponentProps>;
206
+ /**
207
+ * The component to register for the different paths.
208
+ */
209
+ paths: Array<{
210
+ /**
211
+ * The exact path to use.
212
+ */
213
+ path: string;
214
+ /**
215
+ * The component to register for this path.
216
+ */
217
+ Component: ComponentType<RouteComponentProps>;
218
+ }>;
219
+ }
@@ -28,6 +28,7 @@ import type {
28
28
  RouterProps,
29
29
  LayoutProps,
30
30
  Errors,
31
+ RouteSwitchProps,
31
32
  } from './components';
32
33
 
33
34
  export interface StateDispatcher<TState> {
@@ -87,6 +88,10 @@ export interface ComponentsState extends PiralCustomComponentsState {
87
88
  * The layout used for pages.
88
89
  */
89
90
  Layout: ComponentType<LayoutProps>;
91
+ /**
92
+ * The route switch used for determining the route registration.
93
+ */
94
+ RouteSwitch: ComponentType<RouteSwitchProps>;
90
95
  /**
91
96
  * A component that can be used for debugging purposes.
92
97
  */
@@ -207,18 +212,20 @@ export interface PiralActions extends PiralCustomActions {
207
212
  /**
208
213
  * Injects an evaluated pilet at runtime - removes the pilet from registry first if available.
209
214
  * @param pilet The pilet to be injected.
215
+ * @returns The injected pilet.
210
216
  */
211
- injectPilet(pilet: Pilet): void;
217
+ injectPilet(pilet: Pilet): Pilet;
212
218
  /**
213
219
  * Adds a pilet at runtime by loading it, evaluating it, and then injecting it.
214
220
  * @param pilet The pilet to be added.
221
+ * @returns The promise indicating when the pilet was fully added.
215
222
  */
216
- addPilet(pilet: PiletEntry): void;
223
+ addPilet(pilet: PiletEntry): Promise<void>;
217
224
  /**
218
225
  * Removes a pilet by unloading it and deleting all component registrations.
219
226
  * @param name The name of the pilet to remove.
220
227
  */
221
- removePilet(name: string): void;
228
+ removePilet(name: string): Promise<void>;
222
229
  /**
223
230
  * Defines a single action for Piral.
224
231
  * @param actionName The name of the action to define.