piral-core 0.14.3-beta.3299 → 0.14.4-beta.3313

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.
@@ -1,5 +1,4 @@
1
- import { cloneElement, createElement } from 'react';
2
- import { withKey, replaceOrAddItem, removeNested } from '../utils';
1
+ import { withKey, replaceOrAddItem, removeNested, withProvider, withRoute } from '../utils';
3
2
  export function changeLayout(ctx, current) {
4
3
  ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { app: withKey(state.app, 'layout', current) })));
5
4
  }
@@ -20,10 +19,9 @@ export function setErrorComponent(ctx, type, component) {
20
19
  ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { errorComponents: withKey(state.errorComponents, type, component) })));
21
20
  }
22
21
  export function setRoute(ctx, path, component) {
23
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { routes: withKey(state.routes, path, component) })));
22
+ ctx.dispatch(withRoute(path, component));
24
23
  }
25
24
  export function includeProvider(ctx, provider) {
26
- const wrapper = (props) => cloneElement(provider, props);
27
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { provider: !state.provider ? wrapper : (props) => createElement(state.provider, undefined, wrapper(props)) })));
25
+ ctx.dispatch(withProvider(provider));
28
26
  }
29
27
  //# sourceMappingURL=app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/actions/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWnE,MAAM,UAAU,YAAY,CAAC,GAAuB,EAAE,OAAmB;IACvE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,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EACvB,IAAY,EACZ,SAAgD;IAEhD,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAuB,EAAE,QAAqB;IAC5E,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvC,CAAC"}
@@ -1,14 +1,14 @@
1
- import { appendItem, excludeOn, withKey, withoutKey } from '../utils';
1
+ import { withExtension, withoutExtension, withoutPage, withPage } from '../utils';
2
2
  export function registerPage(ctx, name, value) {
3
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: withKey(state.registry.pages, name, value) }) })));
3
+ ctx.dispatch(withPage(name, value));
4
4
  }
5
5
  export function unregisterPage(ctx, name) {
6
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: withoutKey(state.registry.pages, name) }) })));
6
+ ctx.dispatch(withoutPage(name));
7
7
  }
8
8
  export function registerExtension(ctx, name, value) {
9
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: withKey(state.registry.extensions, name, appendItem(state.registry.extensions[name], value)) }) })));
9
+ ctx.dispatch(withExtension(name, value));
10
10
  }
11
11
  export function unregisterExtension(ctx, name, reference) {
12
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: withKey(state.registry.extensions, name, excludeOn(state.registry.extensions[name], (m) => m.reference === reference)) }) })));
12
+ ctx.dispatch(withoutExtension(name, reference));
13
13
  }
14
14
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/actions/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM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Q,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAC7E,OAEH,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/actions/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGlF,MAAM,UAAU,YAAY,CAAC,GAAuB,EAAE,IAAY,EAAE,KAAuB;IACzF,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAuB,EAAE,IAAY;IAClE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAuB,EAAE,IAAY,EAAE,KAA4B;IACnG,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAuB,EAAE,IAAY,EAAE,SAAc;IACvF,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import { ExtensionComponentProps } from '../types';
3
+ export declare function toExtension<T>(Component: React.ComponentType<T>): React.ComponentType<ExtensionComponentProps<T>>;
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ export function toExtension(Component) {
3
+ return (props) => React.createElement(Component, Object.assign({}, props.params));
4
+ }
5
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,UAAU,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC"}
@@ -1,8 +1,10 @@
1
1
  export * from './compare';
2
2
  export * from './data';
3
+ export * from './extension';
3
4
  export * from './foreign';
4
5
  export * from './guid';
5
6
  export * from './helpers';
6
7
  export * from './media';
7
8
  export * from './react';
9
+ export * from './state';
8
10
  export * from './storage';
@@ -1,9 +1,11 @@
1
1
  export * from './compare';
2
2
  export * from './data';
3
+ export * from './extension';
3
4
  export * from './foreign';
4
5
  export * from './guid';
5
6
  export * from './helpers';
6
7
  export * from './media';
7
8
  export * from './react';
9
+ export * from './state';
8
10
  export * from './storage';
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { ComponentType } from 'react';
2
+ import { RouteComponentProps } from 'react-router';
3
+ import { GlobalState, PageRegistration, ExtensionRegistration } from '../types';
4
+ /**
5
+ * Returns a dispatcher that includes all mentioned dispatchers.
6
+ * @param dispatchers The dispatchers to include.
7
+ */
8
+ export declare function withAll(...dispatchers: Array<(state: GlobalState) => GlobalState>): (state: GlobalState) => GlobalState;
9
+ /**
10
+ * Returns a dispatcher that adds a page registration.
11
+ * @param name The path of the page to register.
12
+ * @param value The value of the page to register.
13
+ * @returns The dispatcher.
14
+ */
15
+ export declare function withPage(name: string, value: PageRegistration): (state: GlobalState) => GlobalState;
16
+ /**
17
+ * Returns a dispatcher that removes a page registration.
18
+ * @param name The path of the page to unregister.
19
+ * @returns The dispatcher.
20
+ */
21
+ export declare function withoutPage(name: string): (state: GlobalState) => GlobalState;
22
+ /**
23
+ * Returns a dispatcher that adds an extension registration.
24
+ * @param name The name of the extension to register.
25
+ * @param value The value of the extension to register.
26
+ * @returns The dispatcher.
27
+ */
28
+ export declare function withExtension(name: string, value: ExtensionRegistration): (state: GlobalState) => GlobalState;
29
+ /**
30
+ * Returns a dispatcher that removes an extension registration.
31
+ * @param name The name of the extension to unregister.
32
+ * @param reference The reference for the extension.
33
+ * @returns The dispatcher.
34
+ */
35
+ export declare function withoutExtension(name: string, reference: any): (state: GlobalState) => GlobalState;
36
+ /**
37
+ * Returns a dispatcher that adds an extension registration from the root (no Pilet API).
38
+ * @param name The name of the extension to register.
39
+ * @param component The extension's component to use.
40
+ * @returns The dispatcher.
41
+ */
42
+ export declare function withRootExtension<T>(name: string, component: ComponentType<T>): (state: GlobalState) => GlobalState;
43
+ /**
44
+ * Returns a dispatcher that adds another provider.
45
+ * @param provider The provider to include.
46
+ * @returns The dispatcher.
47
+ */
48
+ export declare function withProvider(provider: JSX.Element): (state: GlobalState) => GlobalState;
49
+ /**
50
+ * Returns a dispatcher that registers another route.
51
+ * @param path The path of the route to register.
52
+ * @param component The component representing the route.
53
+ * @returns The dispatcher.
54
+ */
55
+ export declare function withRoute<T>(path: string, component: ComponentType<RouteComponentProps<T>>): (state: GlobalState) => GlobalState;
@@ -0,0 +1,83 @@
1
+ import { cloneElement, createElement } from 'react';
2
+ import { toExtension } from './extension';
3
+ import { withKey, withoutKey, appendItem, excludeOn } from './helpers';
4
+ /**
5
+ * Returns a dispatcher that includes all mentioned dispatchers.
6
+ * @param dispatchers The dispatchers to include.
7
+ */
8
+ export function withAll(...dispatchers) {
9
+ return (state) => {
10
+ for (const dispatcher of dispatchers) {
11
+ state = dispatcher(state);
12
+ }
13
+ return state;
14
+ };
15
+ }
16
+ /**
17
+ * Returns a dispatcher that adds a page registration.
18
+ * @param name The path of the page to register.
19
+ * @param value The value of the page to register.
20
+ * @returns The dispatcher.
21
+ */
22
+ export function withPage(name, value) {
23
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: withKey(state.registry.pages, name, value) }) }));
24
+ }
25
+ /**
26
+ * Returns a dispatcher that removes a page registration.
27
+ * @param name The path of the page to unregister.
28
+ * @returns The dispatcher.
29
+ */
30
+ export function withoutPage(name) {
31
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: withoutKey(state.registry.pages, name) }) }));
32
+ }
33
+ /**
34
+ * Returns a dispatcher that adds an extension registration.
35
+ * @param name The name of the extension to register.
36
+ * @param value The value of the extension to register.
37
+ * @returns The dispatcher.
38
+ */
39
+ export function withExtension(name, value) {
40
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: withKey(state.registry.extensions, name, appendItem(state.registry.extensions[name], value)) }) }));
41
+ }
42
+ /**
43
+ * Returns a dispatcher that removes an extension registration.
44
+ * @param name The name of the extension to unregister.
45
+ * @param reference The reference for the extension.
46
+ * @returns The dispatcher.
47
+ */
48
+ export function withoutExtension(name, reference) {
49
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: withKey(state.registry.extensions, name, excludeOn(state.registry.extensions[name], (m) => m.reference === reference)) }) }));
50
+ }
51
+ /**
52
+ * Returns a dispatcher that adds an extension registration from the root (no Pilet API).
53
+ * @param name The name of the extension to register.
54
+ * @param component The extension's component to use.
55
+ * @returns The dispatcher.
56
+ */
57
+ export function withRootExtension(name, component) {
58
+ return withExtension(name, {
59
+ component: toExtension(component),
60
+ defaults: {},
61
+ pilet: '',
62
+ reference: component,
63
+ });
64
+ }
65
+ /**
66
+ * Returns a dispatcher that adds another provider.
67
+ * @param provider The provider to include.
68
+ * @returns The dispatcher.
69
+ */
70
+ export function withProvider(provider) {
71
+ const wrapper = (props) => cloneElement(provider, props);
72
+ return (state) => (Object.assign(Object.assign({}, state), { provider: !state.provider ? wrapper : (props) => createElement(state.provider, undefined, wrapper(props)) }));
73
+ }
74
+ /**
75
+ * Returns a dispatcher that registers another route.
76
+ * @param path The path of the route to register.
77
+ * @param component The component representing the route.
78
+ * @returns The dispatcher.
79
+ */
80
+ export function withRoute(path, component) {
81
+ return (state) => (Object.assign(Object.assign({}, state), { routes: withKey(state.routes, path, component) }));
82
+ }
83
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/utils/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,aAAa,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGvE;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,GAAG,WAAuD;IAChF,OAAO,CAAC,KAAkB,EAAe,EAAE;QACzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YACpC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3B;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAA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AAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAI,IAAY,EAAE,SAA2B;IAC5E,OAAO,aAAa,CAAC,IAAI,EAAE;QACzB,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC;QACjC,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,SAAS;KACrB,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAqB;IAChD,MAAM,OAAO,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEnE,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,IACzG,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,IAAY,EAAE,SAAgD;IACzF,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,IAC9C,CAAC;AACL,CAAC"}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.includeProvider = exports.setRoute = exports.setErrorComponent = exports.setComponent = exports.injectPilet = exports.initialize = exports.changeLayout = void 0;
4
- const react_1 = require("react");
5
4
  const utils_1 = require("../utils");
6
5
  function changeLayout(ctx, current) {
7
6
  ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { app: (0, utils_1.withKey)(state.app, 'layout', current) })));
@@ -28,12 +27,11 @@ function setErrorComponent(ctx, type, component) {
28
27
  }
29
28
  exports.setErrorComponent = setErrorComponent;
30
29
  function setRoute(ctx, path, component) {
31
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { routes: (0, utils_1.withKey)(state.routes, path, component) })));
30
+ ctx.dispatch((0, utils_1.withRoute)(path, component));
32
31
  }
33
32
  exports.setRoute = setRoute;
34
33
  function includeProvider(ctx, provider) {
35
- const wrapper = (props) => (0, react_1.cloneElement)(provider, props);
36
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { provider: !state.provider ? wrapper : (props) => (0, react_1.createElement)(state.provider, undefined, wrapper(props)) })));
34
+ ctx.dispatch((0, utils_1.withProvider)(provider));
37
35
  }
38
36
  exports.includeProvider = includeProvider;
39
37
  //# sourceMappingURL=app.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/actions/app.ts"],"names":[],"mappings":";;;AAAA,iCAAmE;AAEnE,oCAAmE;AAWnE,SAAgB,YAAY,CAAC,GAAuB,EAAE,OAAmB;IACvE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,GAAG,EAAE,IAAA,eAAO,EAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,IAC1C,CAAC,CAAC;AACN,CAAC;AALD,oCAKC;AAED,SAAgB,UAAU,CAAC,GAAuB,EAAE,OAAgB,EAAE,KAAwB,EAAE,OAAqB;IACnH,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,GAAG,kCACE,KAAK,CAAC,GAAG,KACZ,KAAK;YACL,OAAO,KAET,OAAO,IACP,CAAC,CAAC;AACN,CAAC;AAVD,gCAUC;AAED,SAAgB,WAAW,CAAC,GAAuB,EAAE,KAAY;IAC/D,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,OAAO,EAAE,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tension = exports.registerExtension = exports.unregisterPage = exports.registerPage = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  function registerPage(ctx, name, value) {
6
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, utils_1.withKey)(state.registry.pages, name, value) }) })));
6
+ ctx.dispatch((0, utils_1.withPage)(name, value));
7
7
  }
8
8
  exports.registerPage = registerPage;
9
9
  function unregisterPage(ctx, name) {
10
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, utils_1.withoutKey)(state.registry.pages, name) }) })));
10
+ ctx.dispatch((0, utils_1.withoutPage)(name));
11
11
  }
12
12
  exports.unregisterPage = unregisterPage;
13
13
  function registerExtension(ctx, name, value) {
14
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, utils_1.withKey)(state.registry.extensions, name, (0, utils_1.appendItem)(state.registry.extensions[name], value)) }) })));
14
+ ctx.dispatch((0, utils_1.withExtension)(name, value));
15
15
  }
16
16
  exports.registerExtension = registerExtension;
17
17
  function unregisterExtension(ctx, name, reference) {
18
- ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, utils_1.withKey)(state.registry.extensions, name, (0, utils_1.excludeOn)(state.registry.extensions[name], (m) => m.reference === reference)) }) })));
18
+ ctx.dispatch((0, utils_1.withoutExtension)(name, reference));
19
19
  }
20
20
  exports.unregisterExtension = unregisterExtension;
21
21
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/actions/components.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;AAGtE,SAAgB,YAAY,CAAC,GAAuB,EAAE,IAAY,EAAE,KAAuB;IACzF,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,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AAS,CAAC,CAC7E,OAEH,CAAC,CAAC;AACN,CAAC;AAZD,kDAYC"}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/actions/components.ts"],"names":[],"mappings":";;;AAAA,oCAAkF;AAGlF,SAAgB,YAAY,CAAC,GAAuB,EAAE,IAAY,EAAE,KAAuB;IACzF,GAAG,CAAC,QAAQ,CAAC,IAAA,gBAAQ,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAFD,oCAEC;AAED,SAAgB,cAAc,CAAC,GAAuB,EAAE,IAAY;IAClE,GAAG,CAAC,QAAQ,CAAC,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC;AAED,SAAgB,iBAAiB,CAAC,GAAuB,EAAE,IAAY,EAAE,KAA4B;IACnG,GAAG,CAAC,QAAQ,CAAC,IAAA,qBAAa,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC;AAFD,8CAEC;AAED,SAAgB,mBAAmB,CAAC,GAAuB,EAAE,IAAY,EAAE,SAAc;IACvF,GAAG,CAAC,QAAQ,CAAC,IAAA,wBAAgB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAClD,CAAC;AAFD,kDAEC"}
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import { ExtensionComponentProps } from '../types';
3
+ export declare function toExtension<T>(Component: React.ComponentType<T>): React.ComponentType<ExtensionComponentProps<T>>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toExtension = void 0;
4
+ const React = require("react");
5
+ function toExtension(Component) {
6
+ return (props) => React.createElement(Component, Object.assign({}, props.params));
7
+ }
8
+ exports.toExtension = toExtension;
9
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAG/B,SAAgB,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC;AAFD,kCAEC"}
@@ -1,8 +1,10 @@
1
1
  export * from './compare';
2
2
  export * from './data';
3
+ export * from './extension';
3
4
  export * from './foreign';
4
5
  export * from './guid';
5
6
  export * from './helpers';
6
7
  export * from './media';
7
8
  export * from './react';
9
+ export * from './state';
8
10
  export * from './storage';
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./compare"), exports);
5
5
  (0, tslib_1.__exportStar)(require("./data"), exports);
6
+ (0, tslib_1.__exportStar)(require("./extension"), exports);
6
7
  (0, tslib_1.__exportStar)(require("./foreign"), exports);
7
8
  (0, tslib_1.__exportStar)(require("./guid"), exports);
8
9
  (0, tslib_1.__exportStar)(require("./helpers"), exports);
9
10
  (0, tslib_1.__exportStar)(require("./media"), exports);
10
11
  (0, tslib_1.__exportStar)(require("./react"), exports);
12
+ (0, tslib_1.__exportStar)(require("./state"), exports);
11
13
  (0, tslib_1.__exportStar)(require("./storage"), exports);
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B;AAC1B,sDAAuB;AACvB,yDAA0B;AAC1B,sDAAuB;AACvB,yDAA0B;AAC1B,uDAAwB;AACxB,uDAAwB;AACxB,yDAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B;AAC1B,sDAAuB;AACvB,2DAA4B;AAC5B,yDAA0B;AAC1B,sDAAuB;AACvB,yDAA0B;AAC1B,uDAAwB;AACxB,uDAAwB;AACxB,uDAAwB;AACxB,yDAA0B"}
@@ -0,0 +1,55 @@
1
+ import { ComponentType } from 'react';
2
+ import { RouteComponentProps } from 'react-router';
3
+ import { GlobalState, PageRegistration, ExtensionRegistration } from '../types';
4
+ /**
5
+ * Returns a dispatcher that includes all mentioned dispatchers.
6
+ * @param dispatchers The dispatchers to include.
7
+ */
8
+ export declare function withAll(...dispatchers: Array<(state: GlobalState) => GlobalState>): (state: GlobalState) => GlobalState;
9
+ /**
10
+ * Returns a dispatcher that adds a page registration.
11
+ * @param name The path of the page to register.
12
+ * @param value The value of the page to register.
13
+ * @returns The dispatcher.
14
+ */
15
+ export declare function withPage(name: string, value: PageRegistration): (state: GlobalState) => GlobalState;
16
+ /**
17
+ * Returns a dispatcher that removes a page registration.
18
+ * @param name The path of the page to unregister.
19
+ * @returns The dispatcher.
20
+ */
21
+ export declare function withoutPage(name: string): (state: GlobalState) => GlobalState;
22
+ /**
23
+ * Returns a dispatcher that adds an extension registration.
24
+ * @param name The name of the extension to register.
25
+ * @param value The value of the extension to register.
26
+ * @returns The dispatcher.
27
+ */
28
+ export declare function withExtension(name: string, value: ExtensionRegistration): (state: GlobalState) => GlobalState;
29
+ /**
30
+ * Returns a dispatcher that removes an extension registration.
31
+ * @param name The name of the extension to unregister.
32
+ * @param reference The reference for the extension.
33
+ * @returns The dispatcher.
34
+ */
35
+ export declare function withoutExtension(name: string, reference: any): (state: GlobalState) => GlobalState;
36
+ /**
37
+ * Returns a dispatcher that adds an extension registration from the root (no Pilet API).
38
+ * @param name The name of the extension to register.
39
+ * @param component The extension's component to use.
40
+ * @returns The dispatcher.
41
+ */
42
+ export declare function withRootExtension<T>(name: string, component: ComponentType<T>): (state: GlobalState) => GlobalState;
43
+ /**
44
+ * Returns a dispatcher that adds another provider.
45
+ * @param provider The provider to include.
46
+ * @returns The dispatcher.
47
+ */
48
+ export declare function withProvider(provider: JSX.Element): (state: GlobalState) => GlobalState;
49
+ /**
50
+ * Returns a dispatcher that registers another route.
51
+ * @param path The path of the route to register.
52
+ * @param component The component representing the route.
53
+ * @returns The dispatcher.
54
+ */
55
+ export declare function withRoute<T>(path: string, component: ComponentType<RouteComponentProps<T>>): (state: GlobalState) => GlobalState;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withRoute = exports.withProvider = exports.withRootExtension = exports.withoutExtension = exports.withExtension = exports.withoutPage = exports.withPage = exports.withAll = void 0;
4
+ const react_1 = require("react");
5
+ const extension_1 = require("./extension");
6
+ const helpers_1 = require("./helpers");
7
+ /**
8
+ * Returns a dispatcher that includes all mentioned dispatchers.
9
+ * @param dispatchers The dispatchers to include.
10
+ */
11
+ function withAll(...dispatchers) {
12
+ return (state) => {
13
+ for (const dispatcher of dispatchers) {
14
+ state = dispatcher(state);
15
+ }
16
+ return state;
17
+ };
18
+ }
19
+ exports.withAll = withAll;
20
+ /**
21
+ * Returns a dispatcher that adds a page registration.
22
+ * @param name The path of the page to register.
23
+ * @param value The value of the page to register.
24
+ * @returns The dispatcher.
25
+ */
26
+ function withPage(name, value) {
27
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, helpers_1.withKey)(state.registry.pages, name, value) }) }));
28
+ }
29
+ exports.withPage = withPage;
30
+ /**
31
+ * Returns a dispatcher that removes a page registration.
32
+ * @param name The path of the page to unregister.
33
+ * @returns The dispatcher.
34
+ */
35
+ function withoutPage(name) {
36
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { pages: (0, helpers_1.withoutKey)(state.registry.pages, name) }) }));
37
+ }
38
+ exports.withoutPage = withoutPage;
39
+ /**
40
+ * Returns a dispatcher that adds an extension registration.
41
+ * @param name The name of the extension to register.
42
+ * @param value The value of the extension to register.
43
+ * @returns The dispatcher.
44
+ */
45
+ function withExtension(name, value) {
46
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, helpers_1.withKey)(state.registry.extensions, name, (0, helpers_1.appendItem)(state.registry.extensions[name], value)) }) }));
47
+ }
48
+ exports.withExtension = withExtension;
49
+ /**
50
+ * Returns a dispatcher that removes an extension registration.
51
+ * @param name The name of the extension to unregister.
52
+ * @param reference The reference for the extension.
53
+ * @returns The dispatcher.
54
+ */
55
+ function withoutExtension(name, reference) {
56
+ return (state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { extensions: (0, helpers_1.withKey)(state.registry.extensions, name, (0, helpers_1.excludeOn)(state.registry.extensions[name], (m) => m.reference === reference)) }) }));
57
+ }
58
+ exports.withoutExtension = withoutExtension;
59
+ /**
60
+ * Returns a dispatcher that adds an extension registration from the root (no Pilet API).
61
+ * @param name The name of the extension to register.
62
+ * @param component The extension's component to use.
63
+ * @returns The dispatcher.
64
+ */
65
+ function withRootExtension(name, component) {
66
+ return withExtension(name, {
67
+ component: (0, extension_1.toExtension)(component),
68
+ defaults: {},
69
+ pilet: '',
70
+ reference: component,
71
+ });
72
+ }
73
+ exports.withRootExtension = withRootExtension;
74
+ /**
75
+ * Returns a dispatcher that adds another provider.
76
+ * @param provider The provider to include.
77
+ * @returns The dispatcher.
78
+ */
79
+ function withProvider(provider) {
80
+ const wrapper = (props) => (0, react_1.cloneElement)(provider, props);
81
+ return (state) => (Object.assign(Object.assign({}, state), { provider: !state.provider ? wrapper : (props) => (0, react_1.createElement)(state.provider, undefined, wrapper(props)) }));
82
+ }
83
+ exports.withProvider = withProvider;
84
+ /**
85
+ * Returns a dispatcher that registers another route.
86
+ * @param path The path of the route to register.
87
+ * @param component The component representing the route.
88
+ * @returns The dispatcher.
89
+ */
90
+ function withRoute(path, component) {
91
+ return (state) => (Object.assign(Object.assign({}, state), { routes: (0, helpers_1.withKey)(state.routes, path, component) }));
92
+ }
93
+ exports.withRoute = withRoute;
94
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/utils/state.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AE,CAAC,iCACvC,KAAK,KACR,MAAM,EAAE,IAAA,iBAAO,EAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,IAC9C,CAAC;AACL,CAAC;AALD,8BAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.14.3-beta.3299",
3
+ "version": "0.14.4-beta.3313",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -48,6 +48,17 @@
48
48
  "typedoc": "typedoc --json ../../../docs/types/piral-core.json src --exclude \"src/**/*.test.*\"",
49
49
  "test": "echo \"Error: run tests from root\" && exit 1"
50
50
  },
51
+ "dependencies": {
52
+ "@dbeining/react-atom": "^4.0.0",
53
+ "piral-base": "0.14.4-beta.3313",
54
+ "piral-debug-utils": "0.14.4-beta.3313"
55
+ },
56
+ "peerDependencies": {
57
+ "react": ">=16.8.0",
58
+ "react-dom": ">=16.8.0",
59
+ "react-router": ">=5.0.0",
60
+ "react-router-dom": ">=5.0.0"
61
+ },
51
62
  "devDependencies": {
52
63
  "@types/history": "^4.7.8",
53
64
  "@types/react": "^17.0.0",
@@ -56,12 +67,6 @@
56
67
  "react": "^17.0.1",
57
68
  "react-dom": "^17.0.1"
58
69
  },
59
- "peerDependencies": {
60
- "react": ">=16.8.0",
61
- "react-dom": ">=16.8.0",
62
- "react-router": ">=5.0.0",
63
- "react-router-dom": ">=5.0.0"
64
- },
65
70
  "sharedDependencies": [
66
71
  "react",
67
72
  "react-dom",
@@ -73,10 +78,5 @@
73
78
  "@libre/atom",
74
79
  "@dbeining/react-atom"
75
80
  ],
76
- "dependencies": {
77
- "@dbeining/react-atom": "^4.0.0",
78
- "piral-base": "0.14.3-beta.3299",
79
- "piral-debug-utils": "0.14.3-beta.3299"
80
- },
81
- "gitHead": "2329c97cbca23e133c1b432ead68964f6ea411f3"
81
+ "gitHead": "ab1a8f12eecbe2824fc7fe9b7a9acae33a91c0fd"
82
82
  }
@@ -1,6 +1,6 @@
1
1
  import { ComponentType, cloneElement, createElement } from 'react';
2
2
  import { RouteComponentProps } from 'react-router';
3
- import { withKey, replaceOrAddItem, removeNested } from '../utils';
3
+ import { withKey, replaceOrAddItem, removeNested, withProvider, withRoute } from '../utils';
4
4
  import {
5
5
  LayoutType,
6
6
  ComponentsState,
@@ -36,7 +36,7 @@ export function injectPilet(ctx: GlobalStateContext, pilet: Pilet) {
36
36
  modules: replaceOrAddItem(state.modules, pilet, (m) => m.name === pilet.name),
37
37
  registry: removeNested<RegistryState, BaseRegistration>(state.registry, (m) => m.pilet === pilet.name),
38
38
  }));
39
-
39
+
40
40
  ctx.emit('unload-pilet', {
41
41
  name: pilet.name,
42
42
  });
@@ -69,17 +69,9 @@ export function setRoute<T = {}>(
69
69
  path: string,
70
70
  component: ComponentType<RouteComponentProps<T>>,
71
71
  ) {
72
- ctx.dispatch((state) => ({
73
- ...state,
74
- routes: withKey(state.routes, path, component),
75
- }));
72
+ ctx.dispatch(withRoute(path, component));
76
73
  }
77
74
 
78
75
  export function includeProvider(ctx: GlobalStateContext, provider: JSX.Element) {
79
- const wrapper: React.FC = (props) => cloneElement(provider, props);
80
-
81
- ctx.dispatch((state) => ({
82
- ...state,
83
- provider: !state.provider ? wrapper : (props) => createElement(state.provider, undefined, wrapper(props)),
84
- }));
76
+ ctx.dispatch(withProvider(provider));
85
77
  }
@@ -1,46 +1,18 @@
1
- import { appendItem, excludeOn, withKey, withoutKey } from '../utils';
1
+ import { withExtension, withoutExtension, withoutPage, withPage } from '../utils';
2
2
  import { PageRegistration, ExtensionRegistration, GlobalStateContext } from '../types';
3
3
 
4
4
  export function registerPage(ctx: GlobalStateContext, name: string, value: PageRegistration) {
5
- ctx.dispatch((state) => ({
6
- ...state,
7
- registry: {
8
- ...state.registry,
9
- pages: withKey(state.registry.pages, name, value),
10
- },
11
- }));
5
+ ctx.dispatch(withPage(name, value));
12
6
  }
13
7
 
14
8
  export function unregisterPage(ctx: GlobalStateContext, name: string) {
15
- ctx.dispatch((state) => ({
16
- ...state,
17
- registry: {
18
- ...state.registry,
19
- pages: withoutKey(state.registry.pages, name),
20
- },
21
- }));
9
+ ctx.dispatch(withoutPage(name));
22
10
  }
23
11
 
24
12
  export function registerExtension(ctx: GlobalStateContext, name: string, value: ExtensionRegistration) {
25
- ctx.dispatch((state) => ({
26
- ...state,
27
- registry: {
28
- ...state.registry,
29
- extensions: withKey(state.registry.extensions, name, appendItem(state.registry.extensions[name], value)),
30
- },
31
- }));
13
+ ctx.dispatch(withExtension(name, value));
32
14
  }
33
15
 
34
16
  export function unregisterExtension(ctx: GlobalStateContext, name: string, reference: any) {
35
- ctx.dispatch((state) => ({
36
- ...state,
37
- registry: {
38
- ...state.registry,
39
- extensions: withKey(
40
- state.registry.extensions,
41
- name,
42
- excludeOn(state.registry.extensions[name], (m) => m.reference === reference),
43
- ),
44
- },
45
- }));
17
+ ctx.dispatch(withoutExtension(name, reference));
46
18
  }
@@ -74,7 +74,7 @@ describe('Piral-Core helpers module', () => {
74
74
  const optionsConfig: PiletOptionsConfig = {
75
75
  createApi: createMockApi,
76
76
  availablePilets: providedPilets,
77
- shareDependencies: jest.fn(deps => deps),
77
+ shareDependencies: jest.fn((deps) => deps),
78
78
  context: globalContext,
79
79
  loadPilet: jest.fn(),
80
80
  requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
@@ -114,7 +114,7 @@ describe('Piral-Core helpers module', () => {
114
114
  createApi: createMockApi,
115
115
  availablePilets: providedPilets,
116
116
  context: globalContext,
117
- shareDependencies: jest.fn(deps => deps),
117
+ shareDependencies: jest.fn((deps) => deps),
118
118
  loadPilet: jest.fn(),
119
119
  requestPilets: jest.fn(() => Promise.resolve(providedPilets)),
120
120
  strategy: jest.fn(),
@@ -153,7 +153,7 @@ describe('Piral-Core helpers module', () => {
153
153
  createApi: createMockApi,
154
154
  availablePilets: providedPilets,
155
155
  context: globalContext,
156
- shareDependencies: jest.fn(deps => deps),
156
+ shareDependencies: jest.fn((deps) => deps),
157
157
  loadPilet: jest.fn(),
158
158
  requestPilets: requestPilets,
159
159
  strategy: jest.fn(),
@@ -207,7 +207,7 @@ describe('Piral-Core helpers module', () => {
207
207
  createApi: createMockApi,
208
208
  availablePilets: providedPilets,
209
209
  context: globalContext,
210
- shareDependencies: jest.fn(deps => deps),
210
+ shareDependencies: jest.fn((deps) => deps),
211
211
  loadPilet: jest.fn(),
212
212
  requestPilets: requestPilets,
213
213
  strategy: jest.fn(),
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { mount } from 'enzyme';
3
+ import { toExtension } from './extension';
4
+
5
+ describe('Util Extension.', () => {
6
+ it('Convert some component to an extension component.', () => {
7
+ const Component = (props) => <b>{props.title}</b>;
8
+ const Extension = toExtension(Component);
9
+ const node = mount(<Extension piral={undefined} params={{ title: 'Foo' }} />);
10
+ expect(node.find('b').length).toBe(1);
11
+ });
12
+ });
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import { ExtensionComponentProps } from '../types';
3
+
4
+ export function toExtension<T>(Component: React.ComponentType<T>): React.ComponentType<ExtensionComponentProps<T>> {
5
+ return (props) => <Component {...props.params} />;
6
+ }
@@ -1,8 +1,10 @@
1
1
  export * from './compare';
2
2
  export * from './data';
3
+ export * from './extension';
3
4
  export * from './foreign';
4
5
  export * from './guid';
5
6
  export * from './helpers';
6
7
  export * from './media';
7
8
  export * from './react';
9
+ export * from './state';
8
10
  export * from './storage';
@@ -0,0 +1,128 @@
1
+ import { cloneElement, ComponentType, createElement } from 'react';
2
+ import { RouteComponentProps } from 'react-router';
3
+ import { toExtension } from './extension';
4
+ import { withKey, withoutKey, appendItem, excludeOn } from './helpers';
5
+ import { GlobalState, PageRegistration, ExtensionRegistration } from '../types';
6
+
7
+ /**
8
+ * Returns a dispatcher that includes all mentioned dispatchers.
9
+ * @param dispatchers The dispatchers to include.
10
+ */
11
+ export function withAll(...dispatchers: Array<(state: GlobalState) => GlobalState>) {
12
+ return (state: GlobalState): GlobalState => {
13
+ for (const dispatcher of dispatchers) {
14
+ state = dispatcher(state);
15
+ }
16
+
17
+ return state;
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Returns a dispatcher that adds a page registration.
23
+ * @param name The path of the page to register.
24
+ * @param value The value of the page to register.
25
+ * @returns The dispatcher.
26
+ */
27
+ export function withPage(name: string, value: PageRegistration) {
28
+ return (state: GlobalState): GlobalState => ({
29
+ ...state,
30
+ registry: {
31
+ ...state.registry,
32
+ pages: withKey(state.registry.pages, name, value),
33
+ },
34
+ });
35
+ }
36
+
37
+ /**
38
+ * Returns a dispatcher that removes a page registration.
39
+ * @param name The path of the page to unregister.
40
+ * @returns The dispatcher.
41
+ */
42
+ export function withoutPage(name: string) {
43
+ return (state: GlobalState): GlobalState => ({
44
+ ...state,
45
+ registry: {
46
+ ...state.registry,
47
+ pages: withoutKey(state.registry.pages, name),
48
+ },
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Returns a dispatcher that adds an extension registration.
54
+ * @param name The name of the extension to register.
55
+ * @param value The value of the extension to register.
56
+ * @returns The dispatcher.
57
+ */
58
+ export function withExtension(name: string, value: ExtensionRegistration) {
59
+ return (state: GlobalState): GlobalState => ({
60
+ ...state,
61
+ registry: {
62
+ ...state.registry,
63
+ extensions: withKey(state.registry.extensions, name, appendItem(state.registry.extensions[name], value)),
64
+ },
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Returns a dispatcher that removes an extension registration.
70
+ * @param name The name of the extension to unregister.
71
+ * @param reference The reference for the extension.
72
+ * @returns The dispatcher.
73
+ */
74
+ export function withoutExtension(name: string, reference: any) {
75
+ return (state: GlobalState): GlobalState => ({
76
+ ...state,
77
+ registry: {
78
+ ...state.registry,
79
+ extensions: withKey(
80
+ state.registry.extensions,
81
+ name,
82
+ excludeOn(state.registry.extensions[name], (m) => m.reference === reference),
83
+ ),
84
+ },
85
+ });
86
+ }
87
+
88
+ /**
89
+ * Returns a dispatcher that adds an extension registration from the root (no Pilet API).
90
+ * @param name The name of the extension to register.
91
+ * @param component The extension's component to use.
92
+ * @returns The dispatcher.
93
+ */
94
+ export function withRootExtension<T>(name: string, component: ComponentType<T>) {
95
+ return withExtension(name, {
96
+ component: toExtension(component),
97
+ defaults: {},
98
+ pilet: '',
99
+ reference: component,
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Returns a dispatcher that adds another provider.
105
+ * @param provider The provider to include.
106
+ * @returns The dispatcher.
107
+ */
108
+ export function withProvider(provider: JSX.Element) {
109
+ const wrapper: React.FC = (props) => cloneElement(provider, props);
110
+
111
+ return (state: GlobalState): GlobalState => ({
112
+ ...state,
113
+ provider: !state.provider ? wrapper : (props) => createElement(state.provider, undefined, wrapper(props)),
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Returns a dispatcher that registers another route.
119
+ * @param path The path of the route to register.
120
+ * @param component The component representing the route.
121
+ * @returns The dispatcher.
122
+ */
123
+ export function withRoute<T>(path: string, component: ComponentType<RouteComponentProps<T>>) {
124
+ return (state: GlobalState): GlobalState => ({
125
+ ...state,
126
+ routes: withKey(state.routes, path, component),
127
+ });
128
+ }