piral-core 0.14.8-beta.3500 → 0.14.8-beta.3511
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/Piral.d.ts +2 -2
- package/esm/Piral.js +3 -1
- package/esm/Piral.js.map +1 -1
- package/esm/RootListener.d.ts +2 -0
- package/esm/RootListener.js +23 -0
- package/esm/RootListener.js.map +1 -0
- package/esm/components/ExtensionSlot.js +2 -2
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/components/Mediator.js +11 -8
- package/esm/components/Mediator.js.map +1 -1
- package/esm/components/ResponsiveLayout.js +3 -3
- package/esm/components/ResponsiveLayout.js.map +1 -1
- package/esm/components/SetComponent.js +2 -2
- package/esm/components/SetComponent.js.map +1 -1
- package/esm/components/SetError.js +2 -2
- package/esm/components/SetError.js.map +1 -1
- package/esm/components/SetProvider.js +2 -2
- package/esm/components/SetProvider.js.map +1 -1
- package/esm/components/SetRedirect.js +2 -2
- package/esm/components/SetRedirect.js.map +1 -1
- package/esm/components/SetRoute.js +2 -2
- package/esm/components/SetRoute.js.map +1 -1
- package/esm/createInstance.d.ts +2 -2
- package/esm/createInstance.js +3 -1
- package/esm/createInstance.js.map +1 -1
- package/esm/modules/api.d.ts +3 -4
- package/esm/modules/api.js +1 -106
- package/esm/modules/api.js.map +1 -1
- package/esm/modules/core.d.ts +3 -0
- package/esm/modules/core.js +48 -0
- package/esm/modules/core.js.map +1 -0
- package/esm/modules/element.d.ts +5 -0
- package/esm/modules/element.js +83 -0
- package/esm/modules/element.js.map +1 -0
- package/esm/modules/index.d.ts +1 -0
- package/esm/modules/index.js +1 -0
- package/esm/modules/index.js.map +1 -1
- package/esm/state/withApi.js +2 -3
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/extension.d.ts +7 -3
- package/esm/types/instance.d.ts +18 -3
- package/esm/utils/extension.d.ts +13 -0
- package/esm/utils/extension.js +32 -0
- package/esm/utils/extension.js.map +1 -1
- package/lib/Piral.d.ts +2 -2
- package/lib/Piral.js +3 -1
- package/lib/Piral.js.map +1 -1
- package/lib/RootListener.d.ts +2 -0
- package/lib/RootListener.js +27 -0
- package/lib/RootListener.js.map +1 -0
- package/lib/components/ExtensionSlot.js +2 -2
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/components/Mediator.js +10 -7
- package/lib/components/Mediator.js.map +1 -1
- package/lib/components/ResponsiveLayout.js +2 -2
- package/lib/components/ResponsiveLayout.js.map +1 -1
- package/lib/components/SetComponent.js +1 -1
- package/lib/components/SetComponent.js.map +1 -1
- package/lib/components/SetError.js +1 -1
- package/lib/components/SetError.js.map +1 -1
- package/lib/components/SetProvider.js +1 -1
- package/lib/components/SetProvider.js.map +1 -1
- package/lib/components/SetRedirect.js +1 -1
- package/lib/components/SetRedirect.js.map +1 -1
- package/lib/components/SetRoute.js +1 -1
- package/lib/components/SetRoute.js.map +1 -1
- package/lib/createInstance.d.ts +2 -2
- package/lib/createInstance.js +3 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/modules/api.d.ts +3 -4
- package/lib/modules/api.js +3 -109
- package/lib/modules/api.js.map +1 -1
- package/lib/modules/core.d.ts +3 -0
- package/lib/modules/core.js +52 -0
- package/lib/modules/core.js.map +1 -0
- package/lib/modules/element.d.ts +5 -0
- package/lib/modules/element.js +87 -0
- package/lib/modules/element.js.map +1 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +1 -0
- package/lib/modules/index.js.map +1 -1
- package/lib/state/withApi.js +1 -2
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/extension.d.ts +7 -3
- package/lib/types/instance.d.ts +18 -3
- package/lib/utils/extension.d.ts +13 -0
- package/lib/utils/extension.js +34 -1
- package/lib/utils/extension.js.map +1 -1
- package/package.json +4 -4
- package/src/Piral.tsx +5 -3
- package/src/RootListener.tsx +26 -0
- package/src/actions/app.ts +1 -1
- package/src/components/ExtensionSlot.tsx +2 -1
- package/src/components/Mediator.test.tsx +4 -3
- package/src/components/Mediator.tsx +15 -8
- package/src/components/ResponsiveLayout.test.tsx +15 -5
- package/src/components/ResponsiveLayout.tsx +3 -3
- package/src/components/SetComponent.tsx +2 -2
- package/src/components/SetError.tsx +2 -2
- package/src/components/SetProvider.tsx +2 -2
- package/src/components/SetRedirect.tsx +2 -2
- package/src/components/SetRoute.tsx +2 -2
- package/src/createInstance.tsx +5 -2
- package/src/modules/api.test.ts +15 -15
- package/src/modules/api.ts +3 -125
- package/src/modules/core.test.ts +148 -0
- package/src/modules/core.ts +50 -0
- package/src/modules/element.ts +103 -0
- package/src/modules/index.ts +1 -0
- package/src/state/withApi.tsx +2 -3
- package/src/types/extension.ts +7 -2
- package/src/types/instance.ts +19 -3
- package/src/utils/extension.tsx +41 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCoreApi = void 0;
|
|
4
|
+
const element_1 = require("./element");
|
|
5
|
+
const state_1 = require("../state");
|
|
6
|
+
const components_1 = require("../components");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
function createCoreApi(context) {
|
|
9
|
+
return (api, meta) => {
|
|
10
|
+
const pilet = meta.name;
|
|
11
|
+
return {
|
|
12
|
+
getData(name) {
|
|
13
|
+
return context.readDataValue(name);
|
|
14
|
+
},
|
|
15
|
+
setData(name, value, options) {
|
|
16
|
+
const { target = 'memory', expires } = (0, utils_1.createDataOptions)(options);
|
|
17
|
+
const expiration = (0, utils_1.getDataExpiration)(expires);
|
|
18
|
+
return context.tryWriteDataItem(name, value, pilet, target, expiration);
|
|
19
|
+
},
|
|
20
|
+
registerPage(route, arg, meta) {
|
|
21
|
+
context.registerPage(route, {
|
|
22
|
+
pilet,
|
|
23
|
+
meta,
|
|
24
|
+
component: (0, state_1.withApi)(context, arg, api, 'page'),
|
|
25
|
+
});
|
|
26
|
+
return () => api.unregisterPage(route);
|
|
27
|
+
},
|
|
28
|
+
unregisterPage(route) {
|
|
29
|
+
context.unregisterPage(route);
|
|
30
|
+
},
|
|
31
|
+
registerExtension(name, arg, defaults) {
|
|
32
|
+
context.registerExtension(name, {
|
|
33
|
+
pilet,
|
|
34
|
+
component: (0, state_1.withApi)(context, arg, api, 'extension'),
|
|
35
|
+
reference: arg,
|
|
36
|
+
defaults,
|
|
37
|
+
});
|
|
38
|
+
return () => api.unregisterExtension(name, arg);
|
|
39
|
+
},
|
|
40
|
+
unregisterExtension(name, arg) {
|
|
41
|
+
context.unregisterExtension(name, arg);
|
|
42
|
+
},
|
|
43
|
+
renderHtmlExtension(element, props) {
|
|
44
|
+
const [dispose] = (0, element_1.renderElement)(context, element, props);
|
|
45
|
+
return dispose;
|
|
46
|
+
},
|
|
47
|
+
Extension: components_1.ExtensionSlot,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.createCoreApi = createCoreApi;
|
|
52
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/modules/core.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAC1C,oCAAmC;AACnC,8CAA8C;AAC9C,oCAAgE;AAGhE,SAAgB,aAAa,CAAC,OAA2B;IACvD,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;gBAC1B,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;gBAClE,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;gBAC9C,OAAO,OAAO,CAA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
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderElement = void 0;
|
|
4
|
+
const components_1 = require("../components");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
if (typeof window !== 'undefined' && 'customElements' in window) {
|
|
7
|
+
class PiralExtension extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.dispose = utils_1.noop;
|
|
11
|
+
this.update = utils_1.noop;
|
|
12
|
+
this.props = {
|
|
13
|
+
name: this.getAttribute('name'),
|
|
14
|
+
params: (0, utils_1.tryParseJson)(this.getAttribute('params')),
|
|
15
|
+
empty: undefined,
|
|
16
|
+
children: (0, utils_1.reactifyContent)(this.childNodes),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
get params() {
|
|
20
|
+
return this.props.params;
|
|
21
|
+
}
|
|
22
|
+
set params(value) {
|
|
23
|
+
this.props.params = value;
|
|
24
|
+
this.update(this.props);
|
|
25
|
+
}
|
|
26
|
+
get name() {
|
|
27
|
+
return this.props.name;
|
|
28
|
+
}
|
|
29
|
+
set name(value) {
|
|
30
|
+
this.props.name = value;
|
|
31
|
+
this.update(this.props);
|
|
32
|
+
}
|
|
33
|
+
get empty() {
|
|
34
|
+
return this.props.empty;
|
|
35
|
+
}
|
|
36
|
+
set empty(value) {
|
|
37
|
+
this.props.empty = value;
|
|
38
|
+
this.update(this.props);
|
|
39
|
+
}
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
if (this.isConnected) {
|
|
42
|
+
this.dispatchEvent(new CustomEvent('render-html', {
|
|
43
|
+
bubbles: true,
|
|
44
|
+
detail: {
|
|
45
|
+
target: this,
|
|
46
|
+
props: this.props,
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
this.dispose();
|
|
53
|
+
this.dispose = utils_1.noop;
|
|
54
|
+
this.update = utils_1.noop;
|
|
55
|
+
}
|
|
56
|
+
attributeChangedCallback(name, _, newValue) {
|
|
57
|
+
switch (name) {
|
|
58
|
+
case 'name':
|
|
59
|
+
this.name = newValue;
|
|
60
|
+
break;
|
|
61
|
+
case 'params':
|
|
62
|
+
this.params = (0, utils_1.tryParseJson)(newValue);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static get observedAttributes() {
|
|
67
|
+
return ['name', 'params'];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
customElements.define('piral-extension', PiralExtension);
|
|
71
|
+
}
|
|
72
|
+
function renderElement(context, element, props) {
|
|
73
|
+
let [id, portal] = (0, utils_1.renderInDom)(context, element, components_1.ExtensionSlot, props);
|
|
74
|
+
const evName = 'extension-props-changed';
|
|
75
|
+
const handler = (ev) => update(ev.detail);
|
|
76
|
+
const dispose = () => {
|
|
77
|
+
context.hidePortal(id, portal);
|
|
78
|
+
element.removeEventListener(evName, handler);
|
|
79
|
+
};
|
|
80
|
+
const update = (newProps) => {
|
|
81
|
+
[id, portal] = (0, utils_1.changeDomPortal)(id, portal, context, element, components_1.ExtensionSlot, newProps);
|
|
82
|
+
};
|
|
83
|
+
element.addEventListener(evName, handler);
|
|
84
|
+
return [dispose, update];
|
|
85
|
+
}
|
|
86
|
+
exports.renderElement = renderElement;
|
|
87
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/modules/element.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAC9C,oCAA6F;AAO7F,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,gBAAgB,IAAI,MAAM,EAAE;IAC/D,MAAM,cAAe,SAAQ,WAAW;QAAxC;;YACE,YAAO,GAAe,YAAI,CAAC;YAC3B,WAAM,GAAc,YAAI,CAAC;YACzB,UAAK,GAAG;gBACN,IAAI,EAAE,IAAI,CAAC,YAAY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,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAjBD,sCAiBC"}
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
(0, tslib_1.__exportStar)(require("./api"), exports);
|
|
5
5
|
(0, tslib_1.__exportStar)(require("./dependencies"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./element"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/lib/modules/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":";;;AAAA,qDAAsB;AACtB,8DAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":";;;AAAA,qDAAsB;AACtB,8DAA+B;AAC/B,yDAA0B"}
|
package/lib/state/withApi.js
CHANGED
|
@@ -66,8 +66,7 @@ function wrapReactComponent(Component, stasisOptions, piral, Wrapper) {
|
|
|
66
66
|
}
|
|
67
67
|
function wrapForeignComponent(component, stasisOptions, piral, Wrapper) {
|
|
68
68
|
return React.memo((props) => {
|
|
69
|
-
const { destroyPortal } = (0, hooks_1.
|
|
70
|
-
const { state, readState } = (0, hooks_1.useGlobalStateContext)();
|
|
69
|
+
const { state, readState, destroyPortal } = (0, hooks_1.useGlobalStateContext)();
|
|
71
70
|
const router = React.useContext(react_router_1.__RouterContext);
|
|
72
71
|
const id = React.useMemo(() => (portalIdBase++).toString(26), utils_1.none);
|
|
73
72
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
package/lib/state/withApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,8CAAuH;AACvH,
|
|
1
|
+
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,8CAAuH;AACvH,oCAAiD;AACjD,oCAAiE;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAS1E,MAAM,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAA7F;;QAGU,YAAO,GAAG,CAAC,EAAe,EAAE,EAAE;YACpC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAClC,EAAE,CAAC,eAAe,EAAE,CAAC;YACrB,UAAU,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC;QAEM,YAAO,GAAG,CAAC,IAAoB,EAAE,EAAE;YACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC,CAAC;IA6CJ,CAAC;IA3CC,iBAAiB;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;QAE7B,IAAI,IAAI,IAAI,IAAA,mBAAM,EAAC,KAAK,CAAC,EAAE;YACzB,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC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,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAEvF,OAAO,aAAa,CAAS,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE;QAClE,OAAO,CAAC,KAAK;YACX,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,WAAW,CAAC,KAAK;YACf,OAAO,oBAAC,KAAK,CAAC,QAAQ,IAAC,QAAQ,EAAE,oBAAC,kCAAqB,OAAG,IAAG,KAAK,CAAkB,CAAC;QACvF,CAAC;QACD,WAAW,CAAC,KAAK,EAAE,KAAU;YAC3B,OAAO,oBAAC,uBAAU,kBAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,IAAM,KAAK,EAAI,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AArBD,0BAqBC"}
|
package/lib/types/extension.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { PiralCustomExtensionSlotMap } from './custom';
|
|
3
3
|
/**
|
|
4
4
|
* The mapping of the existing (known) extension slots.
|
|
@@ -9,16 +9,20 @@ export interface PiralExtensionSlotMap extends PiralCustomExtensionSlotMap {
|
|
|
9
9
|
* The basic props for defining an extension slot.
|
|
10
10
|
*/
|
|
11
11
|
export interface BaseExtensionSlotProps<TName, TParams> {
|
|
12
|
+
/**
|
|
13
|
+
* The children to transport, if any.
|
|
14
|
+
*/
|
|
15
|
+
children?: ReactNode;
|
|
12
16
|
/**
|
|
13
17
|
* Defines what should be rendered when no components are available
|
|
14
18
|
* for the specified extension.
|
|
15
19
|
*/
|
|
16
|
-
empty?():
|
|
20
|
+
empty?(): ReactNode;
|
|
17
21
|
/**
|
|
18
22
|
* Defines how the provided nodes should be rendered.
|
|
19
23
|
* @param nodes The rendered extension nodes.
|
|
20
24
|
*/
|
|
21
|
-
render?(nodes: Array<
|
|
25
|
+
render?(nodes: Array<ReactNode>): ReactElement<any, any> | null;
|
|
22
26
|
/**
|
|
23
27
|
* The custom parameters for the given extension.
|
|
24
28
|
*/
|
package/lib/types/instance.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
|
|
2
2
|
import type { GlobalStateContext } from './state';
|
|
3
3
|
import type { LayoutBreakpoints } from './layout';
|
|
4
|
+
import { PiralConfiguration } from './config';
|
|
4
5
|
/**
|
|
5
6
|
* The props of the Piral component.
|
|
6
7
|
*/
|
|
7
|
-
export interface
|
|
8
|
+
export interface PiralProps {
|
|
8
9
|
/**
|
|
9
10
|
* The specific Piral instance to be used.
|
|
10
11
|
*/
|
|
@@ -15,10 +16,24 @@ export interface PortalProps {
|
|
|
15
16
|
breakpoints?: LayoutBreakpoints;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* The
|
|
19
|
-
|
|
19
|
+
* The options for creating a new PiralInstance object.
|
|
20
|
+
*/
|
|
21
|
+
export interface PiralInstanceOptions extends PiralConfiguration {
|
|
22
|
+
/**
|
|
23
|
+
* Defines the id of this instance. Used in case of multiple instances.
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The PiralInstance object, which is an event emitter with some other
|
|
29
|
+
* utilities and helper. This object is the source for the React
|
|
30
|
+
* functional component (`Piral`).
|
|
20
31
|
*/
|
|
21
32
|
export interface PiralInstance extends EventEmitter {
|
|
33
|
+
/**
|
|
34
|
+
* The id of the Piral instance.
|
|
35
|
+
*/
|
|
36
|
+
id: string;
|
|
22
37
|
/**
|
|
23
38
|
* The global state context instance.
|
|
24
39
|
*/
|
package/lib/utils/extension.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ExtensionComponentProps, WrappedComponent } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the given component to an extension component.
|
|
5
|
+
* @param Component The component to transform.
|
|
6
|
+
* @returns The extension component (receiving its props via params).
|
|
7
|
+
*/
|
|
3
8
|
export declare function toExtension<T>(Component: React.ComponentType<T>): WrappedComponent<ExtensionComponentProps<T>>;
|
|
9
|
+
/**
|
|
10
|
+
* Reactifies the list of child nodes to a React Node by removing the
|
|
11
|
+
* nodes from the DOM and carrying it in a React Node, where it would be
|
|
12
|
+
* attached at a slot.
|
|
13
|
+
* @param childNodes The child nodes to reactify.
|
|
14
|
+
* @returns The React Node.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reactifyContent(childNodes: NodeListOf<ChildNode>): React.ReactNode;
|
package/lib/utils/extension.js
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toExtension = void 0;
|
|
3
|
+
exports.reactifyContent = exports.toExtension = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
|
+
function removeAll(nodes) {
|
|
6
|
+
nodes.forEach((node) => node.remove());
|
|
7
|
+
}
|
|
8
|
+
const SlotCarrier = ({ nodes }) => {
|
|
9
|
+
const host = React.useRef();
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
var _a;
|
|
12
|
+
(_a = host.current) === null || _a === void 0 ? void 0 : _a.append(...nodes);
|
|
13
|
+
return () => removeAll(nodes);
|
|
14
|
+
}, [nodes]);
|
|
15
|
+
if (nodes.length) {
|
|
16
|
+
return React.createElement("slot", { ref: host });
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Transforms the given component to an extension component.
|
|
22
|
+
* @param Component The component to transform.
|
|
23
|
+
* @returns The extension component (receiving its props via params).
|
|
24
|
+
*/
|
|
5
25
|
function toExtension(Component) {
|
|
6
26
|
return (props) => React.createElement(Component, Object.assign({}, props.params));
|
|
7
27
|
}
|
|
8
28
|
exports.toExtension = toExtension;
|
|
29
|
+
/**
|
|
30
|
+
* Reactifies the list of child nodes to a React Node by removing the
|
|
31
|
+
* nodes from the DOM and carrying it in a React Node, where it would be
|
|
32
|
+
* attached at a slot.
|
|
33
|
+
* @param childNodes The child nodes to reactify.
|
|
34
|
+
* @returns The React Node.
|
|
35
|
+
*/
|
|
36
|
+
function reactifyContent(childNodes) {
|
|
37
|
+
const nodes = Array.prototype.filter.call(childNodes, Boolean);
|
|
38
|
+
removeAll(nodes);
|
|
39
|
+
return React.createElement(SlotCarrier, { nodes: nodes });
|
|
40
|
+
}
|
|
41
|
+
exports.reactifyContent = reactifyContent;
|
|
9
42
|
//# sourceMappingURL=extension.js.map
|
|
@@ -1 +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
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/utils/extension.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAG/B,SAAS,SAAS,CAAC,KAAuB;IACxC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACzC,CAAC;AAMD,MAAM,WAAW,GAA+B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAmB,CAAC;IAE7C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;;QACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,IAAI,KAAK,CAAC,MAAM,EAAE;QAChB,OAAO,8BAAM,GAAG,EAAE,IAAI,GAAI,CAAC;KAC5B;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAgB,WAAW,CAAI,SAAiC;IAC9D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,CAAC,MAAM,EAAI,CAAC;AACpD,CAAC;AAFD,kCAEC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,UAAiC;IAC/D,MAAM,KAAK,GAAqB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACjF,SAAS,CAAC,KAAK,CAAC,CAAC;IACjB,OAAO,oBAAC,WAAW,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;AACvC,CAAC;AAJD,0CAIC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.14.8-beta.
|
|
3
|
+
"version": "0.14.8-beta.3511",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@dbeining/react-atom": "^4.0.0",
|
|
53
|
-
"piral-base": "0.14.8-beta.
|
|
54
|
-
"piral-debug-utils": "0.14.8-beta.
|
|
53
|
+
"piral-base": "0.14.8-beta.3511",
|
|
54
|
+
"piral-debug-utils": "0.14.8-beta.3511"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"react": ">=16.8.0",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"@libre/atom",
|
|
79
79
|
"@dbeining/react-atom"
|
|
80
80
|
],
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "69a69677e9c44c0013c3220877978d262e11c9ac"
|
|
82
82
|
}
|
package/src/Piral.tsx
CHANGED
|
@@ -2,7 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { StateContext } from './state';
|
|
3
3
|
import { createInstance } from './createInstance';
|
|
4
4
|
import { PiralView, Mediator, ResponsiveLayout, PortalRenderer } from './components';
|
|
5
|
-
import
|
|
5
|
+
import { RootListener } from './RootListener';
|
|
6
|
+
import type { PiralProps } from './types';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Represents the Piral app shell frame. Use this component together
|
|
@@ -19,10 +20,11 @@ const app = (
|
|
|
19
20
|
);
|
|
20
21
|
```
|
|
21
22
|
*/
|
|
22
|
-
export const Piral: React.FC<
|
|
23
|
+
export const Piral: React.FC<PiralProps> = ({ instance = createInstance(), breakpoints, children }) => (
|
|
23
24
|
<StateContext.Provider value={instance.context}>
|
|
24
25
|
<ResponsiveLayout breakpoints={breakpoints} />
|
|
25
|
-
<Mediator options={instance.options} />
|
|
26
|
+
<Mediator options={instance.options} key={instance.id} />
|
|
27
|
+
<RootListener />
|
|
26
28
|
<PiralView>
|
|
27
29
|
<PortalRenderer id="root" />
|
|
28
30
|
{children}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useGlobalStateContext } from '.';
|
|
3
|
+
import { renderElement } from './modules';
|
|
4
|
+
|
|
5
|
+
export const RootListener: React.FC = () => {
|
|
6
|
+
const context = useGlobalStateContext();
|
|
7
|
+
|
|
8
|
+
React.useLayoutEffect(() => {
|
|
9
|
+
if (typeof document !== 'undefined') {
|
|
10
|
+
const handler = (ev: CustomEvent) => {
|
|
11
|
+
ev.stopPropagation();
|
|
12
|
+
const { target, props } = ev.detail;
|
|
13
|
+
const [dispose, update] = renderElement(context, target, props);
|
|
14
|
+
target.dispose = dispose;
|
|
15
|
+
target.update = update;
|
|
16
|
+
};
|
|
17
|
+
document.body.addEventListener('render-html', handler, false);
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
document.body.removeEventListener('render-html', handler, false);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, [context]);
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
};
|
package/src/actions/app.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { ExtensionSlotProps } from '../types';
|
|
|
10
10
|
* location.
|
|
11
11
|
*/
|
|
12
12
|
export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
|
|
13
|
-
const { name, render = defaultRender, empty, params } = props;
|
|
13
|
+
const { name, render = defaultRender, empty, params, children } = props;
|
|
14
14
|
const extensions = useGlobalState((s) => s.registry.extensions[name] || none);
|
|
15
15
|
return render(
|
|
16
16
|
extensions.length === 0 && isfunc(empty)
|
|
@@ -18,6 +18,7 @@ export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
|
|
|
18
18
|
: extensions.map(({ component: Component, reference, defaults = {} }, i) => (
|
|
19
19
|
<Component
|
|
20
20
|
key={`${reference?.displayName || '_'}${i}`}
|
|
21
|
+
children={children}
|
|
21
22
|
params={{
|
|
22
23
|
...defaults,
|
|
23
24
|
...(params || {}),
|
|
@@ -22,6 +22,9 @@ function createMockContainer() {
|
|
|
22
22
|
dispatch(update) {
|
|
23
23
|
swap(state, update);
|
|
24
24
|
},
|
|
25
|
+
readState(select) {
|
|
26
|
+
return select(deref(state));
|
|
27
|
+
},
|
|
25
28
|
initialize(loading, error, modules) {
|
|
26
29
|
swap(state, (state) => ({
|
|
27
30
|
...state,
|
|
@@ -42,9 +45,7 @@ describe('Component Mediator', () => {
|
|
|
42
45
|
const options = {
|
|
43
46
|
createApi: jest.fn(),
|
|
44
47
|
fetchPilets: () => {
|
|
45
|
-
return new Promise<Array<PiletMetadata>>((resolve
|
|
46
|
-
resolve([]);
|
|
47
|
-
});
|
|
48
|
+
return new Promise<Array<PiletMetadata>>((resolve) => resolve([]));
|
|
48
49
|
},
|
|
49
50
|
};
|
|
50
51
|
const { context } = createMockContainer();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { LoadPiletsOptions, startLoadingPilets, PiletsLoading } from 'piral-base';
|
|
3
|
-
import {
|
|
3
|
+
import { useGlobalStateContext } from '../hooks';
|
|
4
4
|
import { none } from '../utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -17,15 +17,22 @@ export interface MediatorProps {
|
|
|
17
17
|
* The Mediator component for interfacing with pilets loading.
|
|
18
18
|
*/
|
|
19
19
|
export const Mediator: React.FC<MediatorProps> = ({ options }) => {
|
|
20
|
-
const initialize =
|
|
20
|
+
const { initialize, readState } = useGlobalStateContext();
|
|
21
|
+
|
|
21
22
|
React.useEffect(() => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const shouldLoad = readState(s => s.app.loading);
|
|
24
|
+
|
|
25
|
+
if (shouldLoad) {
|
|
26
|
+
const { connect, disconnect } = startLoadingPilets(options);
|
|
27
|
+
const notifier: PiletsLoading = (error, pilets, loaded) => {
|
|
28
|
+
initialize(!loaded, error, pilets);
|
|
29
|
+
};
|
|
30
|
+
connect(notifier);
|
|
31
|
+
return () => disconnect(notifier);
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
}, none);
|
|
35
|
+
|
|
29
36
|
// tslint:disable-next-line:no-null-keyword
|
|
30
37
|
return null;
|
|
31
38
|
};
|
|
@@ -19,7 +19,9 @@ StubComponent.displayName = 'StubComponent';
|
|
|
19
19
|
describe('Responsive Module', () => {
|
|
20
20
|
it('always renders the given children', () => {
|
|
21
21
|
const changeTo = jest.fn();
|
|
22
|
-
(hooks as any).
|
|
22
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
23
|
+
changeLayout: changeTo,
|
|
24
|
+
});
|
|
23
25
|
(hooks as any).useMedia = () => 'desktop';
|
|
24
26
|
const node = mount(
|
|
25
27
|
<ResponsiveLayout breakpoints={defaultBreakpoints}>
|
|
@@ -31,7 +33,9 @@ describe('Responsive Module', () => {
|
|
|
31
33
|
|
|
32
34
|
it('does not call changeTo when nothing changed', () => {
|
|
33
35
|
const changeTo = jest.fn();
|
|
34
|
-
(hooks as any).
|
|
36
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
37
|
+
changeLayout: changeTo,
|
|
38
|
+
});
|
|
35
39
|
(hooks as any).useMedia = () => 'desktop';
|
|
36
40
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
37
41
|
expect(changeTo).not.toHaveBeenCalled();
|
|
@@ -39,7 +43,9 @@ describe('Responsive Module', () => {
|
|
|
39
43
|
|
|
40
44
|
it('does not call changeTo when nothing changed', () => {
|
|
41
45
|
const changeTo = jest.fn();
|
|
42
|
-
(hooks as any).
|
|
46
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
47
|
+
changeLayout: changeTo,
|
|
48
|
+
});
|
|
43
49
|
(hooks as any).useMedia = () => 'desktop';
|
|
44
50
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
45
51
|
expect(changeTo).not.toHaveBeenCalled();
|
|
@@ -47,7 +53,9 @@ describe('Responsive Module', () => {
|
|
|
47
53
|
|
|
48
54
|
it('does calls changeTo when someething changed (desktop -> tablet)', () => {
|
|
49
55
|
const changeTo = jest.fn();
|
|
50
|
-
(hooks as any).
|
|
56
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
57
|
+
changeLayout: changeTo,
|
|
58
|
+
});
|
|
51
59
|
(hooks as any).useMedia = () => 'tablet';
|
|
52
60
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
53
61
|
expect(changeTo).toHaveBeenCalledWith('tablet');
|
|
@@ -55,7 +63,9 @@ describe('Responsive Module', () => {
|
|
|
55
63
|
|
|
56
64
|
it('does calls changeTo when someething changed (desktop -> mobile)', () => {
|
|
57
65
|
const changeTo = jest.fn();
|
|
58
|
-
(hooks as any).
|
|
66
|
+
(hooks as any).useGlobalStateContext = () => ({
|
|
67
|
+
changeLayout: changeTo,
|
|
68
|
+
});
|
|
59
69
|
(hooks as any).useMedia = () => 'mobile';
|
|
60
70
|
mount(<ResponsiveLayout breakpoints={defaultBreakpoints} />);
|
|
61
71
|
expect(changeTo).toHaveBeenCalledWith('mobile');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useMedia, useGlobalState,
|
|
2
|
+
import { useMedia, useGlobalState, useGlobalStateContext } from '../hooks';
|
|
3
3
|
import { defaultLayouts, defaultRender, defaultBreakpoints } from '../utils';
|
|
4
4
|
import { LayoutBreakpoints } from '../types';
|
|
5
5
|
|
|
@@ -18,12 +18,12 @@ export interface ResponsiveLayoutProps {
|
|
|
18
18
|
*/
|
|
19
19
|
export const ResponsiveLayout: React.FC<ResponsiveLayoutProps> = ({ breakpoints = defaultBreakpoints, children }) => {
|
|
20
20
|
const current = useGlobalState((m) => m.app.layout) || 'desktop';
|
|
21
|
-
const
|
|
21
|
+
const { changeLayout } = useGlobalStateContext();
|
|
22
22
|
const selected = useMedia(breakpoints, defaultLayouts, current);
|
|
23
23
|
|
|
24
24
|
React.useEffect(() => {
|
|
25
25
|
if (selected !== current) {
|
|
26
|
-
|
|
26
|
+
changeLayout(selected);
|
|
27
27
|
}
|
|
28
28
|
}, [selected]);
|
|
29
29
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
import { ComponentsState } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ export function SetComponent<TKey extends keyof ComponentsState>({
|
|
|
23
23
|
name,
|
|
24
24
|
component,
|
|
25
25
|
}: SetComponentProps<TKey>): React.ReactElement {
|
|
26
|
-
const setComponent =
|
|
26
|
+
const { setComponent } = useGlobalStateContext();
|
|
27
27
|
useSetter(() => component && setComponent(name, component));
|
|
28
28
|
// tslint:disable-next-line:no-null-keyword
|
|
29
29
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
import { ErrorComponentsState } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ export function SetError<TKey extends keyof ErrorComponentsState>({
|
|
|
23
23
|
type,
|
|
24
24
|
component,
|
|
25
25
|
}: SetErrorProps<TKey>): React.ReactElement {
|
|
26
|
-
const setErrorComponent =
|
|
26
|
+
const { setErrorComponent } = useGlobalStateContext();
|
|
27
27
|
useSetter(() => component && setErrorComponent(type, component));
|
|
28
28
|
// tslint:disable-next-line:no-null-keyword
|
|
29
29
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGlobalStateContext, useSetter } from '../hooks';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The props for the SetProvider component.
|
|
@@ -15,7 +15,7 @@ export interface SetProviderProps {
|
|
|
15
15
|
* The component capable of setting a global provider at mounting.
|
|
16
16
|
*/
|
|
17
17
|
export function SetProvider({ provider }: SetProviderProps): React.ReactElement {
|
|
18
|
-
const includeProvider =
|
|
18
|
+
const {includeProvider} = useGlobalStateContext();
|
|
19
19
|
useSetter(() => provider && includeProvider(provider));
|
|
20
20
|
// tslint:disable-next-line:no-null-keyword
|
|
21
21
|
return null;
|