piral-core 0.15.0-alpha.3905 → 0.15.0-alpha.4005
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/components/ExtensionSlot.js +2 -1
- package/esm/components/ExtensionSlot.js.map +1 -1
- package/esm/modules/element.js +15 -12
- package/esm/modules/element.js.map +1 -1
- package/esm/utils/media.js +1 -2
- package/esm/utils/media.js.map +1 -1
- package/lib/components/ExtensionSlot.js +2 -1
- package/lib/components/ExtensionSlot.js.map +1 -1
- package/lib/modules/element.js +15 -12
- package/lib/modules/element.js.map +1 -1
- package/lib/utils/media.js +1 -2
- package/lib/utils/media.js.map +1 -1
- package/package.json +4 -4
- package/src/RootListener.test.tsx +45 -0
- package/src/actions/app.test.ts +90 -2
- package/src/actions/portal.test.ts +53 -8
- package/src/components/ExtensionSlot.test.tsx +56 -5
- package/src/components/ExtensionSlot.tsx +3 -4
- package/src/components/ForeignComponentContainer.test.tsx +119 -0
- package/src/components/PiralView-server.test.tsx +60 -0
- package/src/components/PiralView.test.tsx +1 -1
- package/src/components/PiralView.tsx +1 -1
- package/src/components/SwitchErrorInfo.test.tsx +38 -0
- package/src/createInstance.test.tsx +10 -0
- package/src/hooks/globalState-server.test.ts +41 -0
- package/src/hooks/setter-server.test.ts +22 -0
- package/src/hooks/setter.test.ts +19 -0
- package/src/modules/element-server.test.ts +29 -0
- package/src/modules/element.test.ts +77 -0
- package/src/modules/element.ts +16 -12
- package/src/state/withApi.test.tsx +28 -9
- package/src/utils/extension.test.tsx +11 -1
- package/src/utils/foreign.test.ts +22 -4
- package/src/utils/guid.test.ts +6 -1
- package/src/utils/helpers.test.ts +52 -0
- package/src/utils/media-server.test.ts +13 -0
- package/src/utils/media.ts +1 -2
- package/src/utils/state.test.ts +39 -0
|
@@ -3,6 +3,7 @@ import { isfunc } from 'piral-base';
|
|
|
3
3
|
import { wrapComponent } from './wrapComponent';
|
|
4
4
|
import { useGlobalState, useGlobalStateContext } from '../hooks';
|
|
5
5
|
import { defaultRender, none } from '../utils';
|
|
6
|
+
const wrapper = ({ children }) => defaultRender(children);
|
|
6
7
|
const renderExtensions = [
|
|
7
8
|
{
|
|
8
9
|
component: (props) => {
|
|
@@ -10,7 +11,7 @@ const renderExtensions = [
|
|
|
10
11
|
const converters = context.converters;
|
|
11
12
|
const piral = context.apis._;
|
|
12
13
|
const { component, props: args } = props.params;
|
|
13
|
-
const Component = React.useMemo(() => wrapComponent(converters, component, { piral },
|
|
14
|
+
const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, wrapper), [component]);
|
|
14
15
|
return React.createElement(Component, Object.assign({}, args));
|
|
15
16
|
},
|
|
16
17
|
defaults: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YAChD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/Ex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,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1G,OAAO,MAAM,CACX,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
|
package/esm/modules/element.js
CHANGED
|
@@ -67,17 +67,20 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
|
|
|
67
67
|
customElements.define('piral-extension', PiralExtension);
|
|
68
68
|
}
|
|
69
69
|
export function renderElement(context, element, props) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
if (typeof window !== 'undefined') {
|
|
71
|
+
let [id, portal] = renderInDom(context, element, ExtensionSlot, props);
|
|
72
|
+
const evName = 'extension-props-changed';
|
|
73
|
+
const handler = (ev) => update(ev.detail);
|
|
74
|
+
const dispose = () => {
|
|
75
|
+
context.hidePortal(id, portal);
|
|
76
|
+
element.removeEventListener(evName, handler);
|
|
77
|
+
};
|
|
78
|
+
const update = (newProps) => {
|
|
79
|
+
[id, portal] = changeDomPortal(id, portal, context, element, ExtensionSlot, newProps);
|
|
80
|
+
};
|
|
81
|
+
element.addEventListener(evName, handler);
|
|
82
|
+
return [dispose, update];
|
|
83
|
+
}
|
|
84
|
+
return [noop, noop];
|
|
82
85
|
}
|
|
83
86
|
//# sourceMappingURL=element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/modules/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAO7F,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,gBAAgB,IAAI,MAAM,EAAE;IAC/D,MAAM,cAAe,SAAQ,WAAW;QAAxC;;YACE,YAAO,GAAe,IAAI,CAAC;YAC3B,WAAM,GAAc,IAAI,CAAC;YACzB,UAAK,GAAG;gBACN,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACjD,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;aAC3C,CAAC;QA+DJ,CAAC;QA7DC,IAAI,MAAM;YACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,CAAC,KAAK;YACd,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B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C3B,OAAiC,EACjC,KAAU;IAEV,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,MAAM,GAAG,yBAAyB,CAAC;QACzC,MAAM,OAAO,GAAG,CAAC,EAAe,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QACvD,MAAM,OAAO,GAAe,GAAG,EAAE;YAC/B,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAC/B,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC;QACF,MAAM,MAAM,GAAc,CAAC,QAAQ,EAAE,EAAE;YACrC,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QACxF,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC1B;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
package/esm/utils/media.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
|
-
import { none } from './helpers';
|
|
3
2
|
export const defaultLayouts = ['desktop', 'tablet', 'mobile'];
|
|
4
3
|
export const defaultBreakpoints = ['(min-width: 991px)', '(min-width: 481px)', '(max-width: 480px)'];
|
|
5
4
|
const mm = typeof window === 'undefined' || !isfunc(window.matchMedia)
|
|
6
|
-
? () => ({ matches:
|
|
5
|
+
? () => ({ matches: undefined })
|
|
7
6
|
: (q) => window.matchMedia(q);
|
|
8
7
|
export function getCurrentLayout(breakpoints, layouts, defaultLayout) {
|
|
9
8
|
const query = breakpoints.findIndex((q) => mm(q).matches);
|
package/esm/utils/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC,MAAM,CAAC,MAAM,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,MAAM,UAAU,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC"}
|
|
@@ -6,6 +6,7 @@ const piral_base_1 = require("piral-base");
|
|
|
6
6
|
const wrapComponent_1 = require("./wrapComponent");
|
|
7
7
|
const hooks_1 = require("../hooks");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const wrapper = ({ children }) => (0, utils_1.defaultRender)(children);
|
|
9
10
|
const renderExtensions = [
|
|
10
11
|
{
|
|
11
12
|
component: (props) => {
|
|
@@ -13,7 +14,7 @@ const renderExtensions = [
|
|
|
13
14
|
const converters = context.converters;
|
|
14
15
|
const piral = context.apis._;
|
|
15
16
|
const { component, props: args } = props.params;
|
|
16
|
-
const Component = React.useMemo(() => (0, wrapComponent_1.wrapComponent)(converters, component, { piral },
|
|
17
|
+
const Component = React.useMemo(() => (0, wrapComponent_1.wrapComponent)(converters, component, { piral }, wrapper), [component]);
|
|
17
18
|
return React.createElement(Component, Object.assign({}, args));
|
|
18
19
|
},
|
|
19
20
|
defaults: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,mDAAgD;AAChD,oCAAiE;AACjE,oCAA+C;AAG/C,MAAM,gBAAgB,GAA4B;IAChD;QACE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,IAAA,6BAAqB,GAAE,CAAC;YACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YAChD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,mDAAgD;AAChD,oCAAiE;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AA,mBAAM,EAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
|
package/lib/modules/element.js
CHANGED
|
@@ -70,18 +70,21 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
|
|
|
70
70
|
customElements.define('piral-extension', PiralExtension);
|
|
71
71
|
}
|
|
72
72
|
function renderElement(context, element, props) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
if (typeof window !== 'undefined') {
|
|
74
|
+
let [id, portal] = (0, utils_1.renderInDom)(context, element, components_1.ExtensionSlot, props);
|
|
75
|
+
const evName = 'extension-props-changed';
|
|
76
|
+
const handler = (ev) => update(ev.detail);
|
|
77
|
+
const dispose = () => {
|
|
78
|
+
context.hidePortal(id, portal);
|
|
79
|
+
element.removeEventListener(evName, handler);
|
|
80
|
+
};
|
|
81
|
+
const update = (newProps) => {
|
|
82
|
+
[id, portal] = (0, utils_1.changeDomPortal)(id, portal, context, element, components_1.ExtensionSlot, newProps);
|
|
83
|
+
};
|
|
84
|
+
element.addEventListener(evName, handler);
|
|
85
|
+
return [dispose, update];
|
|
86
|
+
}
|
|
87
|
+
return [utils_1.noop, utils_1.noop];
|
|
85
88
|
}
|
|
86
89
|
exports.renderElement = renderElement;
|
|
87
90
|
//# sourceMappingURL=element.js.map
|
|
@@ -1 +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,CAAC,MAAM,CAAC;gBAC/B,MAAM,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACjD,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE,IAAA,uBAAe,EAAC,IAAI,CAAC,UAAU,CAAC;aAC3C,CAAC;QA+DJ,CAAC;QA7DC,IAAI,MAAM;YACR,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,CAAC,KAAK;YACd,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK;YACZ,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,K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AAO,GAAe,GAAG,EAAE;YAC/B,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAC/B,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC,CAAC;QACF,MAAM,MAAM,GAAc,CAAC,QAAQ,EAAE,EAAE;YACrC,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,IAAA,uBAAe,EAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,0BAAa,EAAE,QAAQ,CAAC,CAAC;QACxF,CAAC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAC1B;IAED,OAAO,CAAC,YAAI,EAAE,YAAI,CAAC,CAAC;AACtB,CAAC;AArBD,sCAqBC"}
|
package/lib/utils/media.js
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCurrentLayout = exports.defaultBreakpoints = exports.defaultLayouts = void 0;
|
|
4
4
|
const piral_base_1 = require("piral-base");
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
6
5
|
exports.defaultLayouts = ['desktop', 'tablet', 'mobile'];
|
|
7
6
|
exports.defaultBreakpoints = ['(min-width: 991px)', '(min-width: 481px)', '(max-width: 480px)'];
|
|
8
7
|
const mm = typeof window === 'undefined' || !(0, piral_base_1.isfunc)(window.matchMedia)
|
|
9
|
-
? () => ({ matches:
|
|
8
|
+
? () => ({ matches: undefined })
|
|
10
9
|
: (q) => window.matchMedia(q);
|
|
11
10
|
function getCurrentLayout(breakpoints, layouts, defaultLayout) {
|
|
12
11
|
const query = breakpoints.findIndex((q) => mm(q).matches);
|
package/lib/utils/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAGvB,QAAA,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE9D,QAAA,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,SAAgB,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC;AAJD,4CAIC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4005",
|
|
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.
|
|
52
|
-
"piral-debug-utils": "0.15.0-alpha.
|
|
51
|
+
"piral-base": "0.15.0-alpha.4005",
|
|
52
|
+
"piral-debug-utils": "0.15.0-alpha.4005"
|
|
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": "
|
|
82
|
+
"gitHead": "612f2072dea6b5d02e3672be3972e850ae95d446"
|
|
83
83
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, unmountComponentAtNode } from 'react-dom';
|
|
3
|
+
import { act } from 'react-dom/test-utils';
|
|
4
|
+
import { RootListener } from './RootListener';
|
|
5
|
+
|
|
6
|
+
jest.mock('./hooks/globalState', () => ({
|
|
7
|
+
useGlobalStateContext: () => ({
|
|
8
|
+
showPortal() {},
|
|
9
|
+
}),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('RootListener Component', () => {
|
|
13
|
+
it('renders the RootListener instance with default settings', async () => {
|
|
14
|
+
const element = document.createElement('div');
|
|
15
|
+
const removed = jest.fn();
|
|
16
|
+
document.body.appendChild(element);
|
|
17
|
+
const container = document.body.appendChild(document.createElement('div'));
|
|
18
|
+
render(<RootListener />, container);
|
|
19
|
+
document.body.removeEventListener = removed;
|
|
20
|
+
await act(() => {
|
|
21
|
+
const event = new CustomEvent('render-html', {
|
|
22
|
+
bubbles: true,
|
|
23
|
+
detail: {
|
|
24
|
+
target: element,
|
|
25
|
+
props: {},
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
element.dispatchEvent(event);
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
});
|
|
31
|
+
await act(() => Promise.resolve());
|
|
32
|
+
expect(removed).not.toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('removes the RootListener successfully', async () => {
|
|
36
|
+
const container = document.body.appendChild(document.createElement('div'));
|
|
37
|
+
const removed = jest.fn();
|
|
38
|
+
render(<RootListener />, container);
|
|
39
|
+
document.body.removeEventListener = removed;
|
|
40
|
+
await act(() => Promise.resolve());
|
|
41
|
+
unmountComponentAtNode(container);
|
|
42
|
+
await act(() => Promise.resolve());
|
|
43
|
+
expect(removed).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
package/src/actions/app.test.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { Atom, deref } from '@dbeining/react-atom';
|
|
3
|
-
import { createListener } from 'piral-base';
|
|
4
|
-
import {
|
|
3
|
+
import { createListener, Pilet } from 'piral-base';
|
|
4
|
+
import {
|
|
5
|
+
changeLayout,
|
|
6
|
+
includeProvider,
|
|
7
|
+
initialize,
|
|
8
|
+
injectPilet,
|
|
9
|
+
removePilet,
|
|
10
|
+
setComponent,
|
|
11
|
+
setErrorComponent,
|
|
12
|
+
setRoute,
|
|
13
|
+
} from './app';
|
|
5
14
|
import { createActions } from '../state';
|
|
6
15
|
import { mount } from 'enzyme';
|
|
16
|
+
import { RootListener } from '../RootListener';
|
|
17
|
+
|
|
18
|
+
const pilet: Pilet = {
|
|
19
|
+
name: 'my-pilet',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
link: undefined,
|
|
22
|
+
custom: undefined,
|
|
23
|
+
};
|
|
7
24
|
|
|
8
25
|
describe('App Actions Module', () => {
|
|
9
26
|
it('changeLayout changes the current layout', () => {
|
|
@@ -23,6 +40,77 @@ describe('App Actions Module', () => {
|
|
|
23
40
|
});
|
|
24
41
|
});
|
|
25
42
|
|
|
43
|
+
it('initialize initializes state data', () => {
|
|
44
|
+
const state = Atom.of({
|
|
45
|
+
app: {},
|
|
46
|
+
});
|
|
47
|
+
const ctx = createActions(state, createListener({}));
|
|
48
|
+
const modules = ['pilet 1', 'pilet 2', 'pilet 3'];
|
|
49
|
+
initialize(ctx, false, undefined, modules);
|
|
50
|
+
expect(deref(state)).toEqual({
|
|
51
|
+
app: { error: undefined, loading: false },
|
|
52
|
+
modules: ['pilet 1', 'pilet 2', 'pilet 3'],
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('removePilet removes pilet', () => {
|
|
57
|
+
const state = Atom.of({
|
|
58
|
+
app: {},
|
|
59
|
+
modules: [pilet],
|
|
60
|
+
registry: { 'my-pilet': pilet },
|
|
61
|
+
});
|
|
62
|
+
const ctx = createActions(state, createListener({}));
|
|
63
|
+
removePilet(ctx, 'my-pilet');
|
|
64
|
+
expect(deref(state)).toEqual({ app: {}, modules: [], registry: { 'my-pilet': pilet } });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('injectPilet injects pilet', () => {
|
|
68
|
+
const pilet2: Pilet = {
|
|
69
|
+
name: 'my-pilet2',
|
|
70
|
+
version: '1.0.0',
|
|
71
|
+
link: undefined,
|
|
72
|
+
custom: undefined,
|
|
73
|
+
};
|
|
74
|
+
const state = Atom.of({
|
|
75
|
+
app: {},
|
|
76
|
+
modules: [pilet2],
|
|
77
|
+
registry: { pilet2 },
|
|
78
|
+
});
|
|
79
|
+
const ctx = createActions(state, createListener({}));
|
|
80
|
+
injectPilet(ctx, pilet);
|
|
81
|
+
expect(deref(state)).toEqual({ app: {}, modules: [pilet2, pilet], registry: { pilet2 } });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('setComponent set component', () => {
|
|
85
|
+
const state = Atom.of({
|
|
86
|
+
components: {},
|
|
87
|
+
});
|
|
88
|
+
const ctx = createActions(state, createListener({}));
|
|
89
|
+
const node = RootListener;
|
|
90
|
+
setComponent(ctx, 'ComponentName', node);
|
|
91
|
+
expect(deref(state)).toEqual({ components: { ComponentName: RootListener } });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('setErrorComponent set error component', () => {
|
|
95
|
+
const state = Atom.of({
|
|
96
|
+
errorComponents: {},
|
|
97
|
+
});
|
|
98
|
+
const ctx = createActions(state, createListener({}));
|
|
99
|
+
const node = RootListener;
|
|
100
|
+
setErrorComponent(ctx, 'ComponentName', node);
|
|
101
|
+
expect(deref(state)).toEqual({ errorComponents: { ComponentName: RootListener } });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('setRoute sets route', () => {
|
|
105
|
+
const state = Atom.of({
|
|
106
|
+
routes: {},
|
|
107
|
+
});
|
|
108
|
+
const ctx = createActions(state, createListener({}));
|
|
109
|
+
const node = RootListener;
|
|
110
|
+
setRoute(ctx, './dist', RootListener);
|
|
111
|
+
expect(deref(state)).toEqual({ routes: { './dist': RootListener } });
|
|
112
|
+
});
|
|
113
|
+
|
|
26
114
|
it('allows using includeProvider once', () => {
|
|
27
115
|
const state = Atom.of({
|
|
28
116
|
provider: undefined,
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
3
|
-
import { showPortal, destroyPortal } from './portal';
|
|
3
|
+
import { showPortal, destroyPortal, hidePortal, updatePortal } from './portal';
|
|
4
4
|
|
|
5
5
|
describe('Piral-Core portal actions', () => {
|
|
6
|
-
it('
|
|
6
|
+
it('destroyPortal removes a portal', () => {
|
|
7
|
+
const children = React.createElement('div');
|
|
8
|
+
const portal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
9
|
+
|
|
10
|
+
const state = Atom.of({
|
|
11
|
+
portals: { test: { portal } },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const ctx: any = {
|
|
15
|
+
state,
|
|
16
|
+
dispatch(update) {
|
|
17
|
+
swap(state, update);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
destroyPortal(ctx, 'test');
|
|
22
|
+
const { portals } = deref(ctx.state);
|
|
23
|
+
expect(portals).not.toBeNull();
|
|
24
|
+
expect(portals.test).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('hidePortal hides a portal', () => {
|
|
7
28
|
const children = React.createElement('div');
|
|
8
29
|
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
9
30
|
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
@@ -19,18 +40,20 @@ describe('Piral-Core portal actions', () => {
|
|
|
19
40
|
},
|
|
20
41
|
};
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
hidePortal(ctx, 'test', newPortal);
|
|
23
44
|
const { portals } = deref(ctx.state);
|
|
24
45
|
expect(portals).not.toBeNull();
|
|
25
46
|
expect(portals.test).not.toBeNull();
|
|
26
47
|
});
|
|
27
48
|
|
|
28
|
-
it('
|
|
49
|
+
it('updatePortal updates a portal', () => {
|
|
29
50
|
const children = React.createElement('div');
|
|
30
|
-
const
|
|
51
|
+
const current: React.ReactPortal = { key: 'current', children: { children }, type: 'div', props: null };
|
|
52
|
+
const next: React.ReactPortal = { key: 'next', children: { children }, type: 'div', props: null };
|
|
53
|
+
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
31
54
|
|
|
32
55
|
const state = Atom.of({
|
|
33
|
-
portals: {
|
|
56
|
+
portals: { p1: { portal } },
|
|
34
57
|
});
|
|
35
58
|
|
|
36
59
|
const ctx: any = {
|
|
@@ -40,9 +63,31 @@ describe('Piral-Core portal actions', () => {
|
|
|
40
63
|
},
|
|
41
64
|
};
|
|
42
65
|
|
|
43
|
-
|
|
66
|
+
updatePortal(ctx, 'test', current, next);
|
|
44
67
|
const { portals } = deref(ctx.state);
|
|
45
68
|
expect(portals).not.toBeNull();
|
|
46
|
-
expect(portals.test).
|
|
69
|
+
expect(portals.test).not.toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('showPortal adds a portal', () => {
|
|
73
|
+
const children = React.createElement('div');
|
|
74
|
+
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
75
|
+
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
76
|
+
|
|
77
|
+
const state = Atom.of({
|
|
78
|
+
portals: { p1: { portal } },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const ctx: any = {
|
|
82
|
+
state,
|
|
83
|
+
dispatch(update) {
|
|
84
|
+
swap(state, update);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
showPortal(ctx, 'test', newPortal);
|
|
89
|
+
const { portals } = deref(ctx.state);
|
|
90
|
+
expect(portals).not.toBeNull();
|
|
91
|
+
expect(portals.test).not.toBeNull();
|
|
47
92
|
});
|
|
48
93
|
});
|
|
@@ -3,18 +3,33 @@ import { mount } from 'enzyme';
|
|
|
3
3
|
import { ExtensionSlot } from './ExtensionSlot';
|
|
4
4
|
|
|
5
5
|
jest.mock('../hooks/globalState', () => ({
|
|
6
|
-
useGlobalState(select: any)
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
useGlobalState: (select: any) => select(state),
|
|
7
|
+
useGlobalStateContext: () => ({
|
|
8
|
+
converters: {
|
|
9
|
+
html: ({ component }) => component,
|
|
10
|
+
},
|
|
11
|
+
apis: {
|
|
12
|
+
_: {
|
|
13
|
+
meta: {
|
|
14
|
+
name: 'PiletName',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
9
19
|
}));
|
|
10
20
|
|
|
21
|
+
(React as any).useMemo = (cb) => cb();
|
|
22
|
+
|
|
11
23
|
const StubComponent1: React.FC = (props) => <div children={props.children} />;
|
|
12
24
|
StubComponent1.displayName = 'StubComponent1';
|
|
13
25
|
|
|
14
26
|
const StubComponent2: React.FC = (props) => <div children={props.children} />;
|
|
15
27
|
StubComponent2.displayName = 'StubComponent2';
|
|
16
28
|
|
|
29
|
+
const StubComponent3: React.FC = (props) => <div children={props.children} />;
|
|
30
|
+
|
|
17
31
|
const state = {
|
|
32
|
+
portals: {},
|
|
18
33
|
registry: {
|
|
19
34
|
extensions: {
|
|
20
35
|
foo: [],
|
|
@@ -29,13 +44,41 @@ const state = {
|
|
|
29
44
|
component: StubComponent2,
|
|
30
45
|
},
|
|
31
46
|
],
|
|
47
|
+
bla: [
|
|
48
|
+
{
|
|
49
|
+
component: StubComponent3,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
32
52
|
},
|
|
33
53
|
},
|
|
34
54
|
};
|
|
35
55
|
|
|
36
|
-
(React as any).useMemo = (cb) => cb();
|
|
37
|
-
|
|
38
56
|
describe('Extension Module', () => {
|
|
57
|
+
it('is able to default render not available extension with no name', () => {
|
|
58
|
+
const node = mount(<ExtensionSlot />);
|
|
59
|
+
expect(node.at(0).exists()).toBe(true);
|
|
60
|
+
expect(node.find(StubComponent1).length).toBe(0);
|
|
61
|
+
expect(node.find('div').length).toBe(0);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('is able to default render given component with no name', () => {
|
|
65
|
+
const component = {
|
|
66
|
+
type: 'html',
|
|
67
|
+
component: {
|
|
68
|
+
mount(element) {
|
|
69
|
+
const container = document.createElement('div');
|
|
70
|
+
container.textContent = 'Hello!';
|
|
71
|
+
element.appendChild(container);
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const node = mount(<ExtensionSlot params={{ component }} />);
|
|
76
|
+
expect(node.at(0).exists()).toBe(true);
|
|
77
|
+
expect(node.find(StubComponent1).length).toBe(0);
|
|
78
|
+
expect(node.find('div').length).toBe(1);
|
|
79
|
+
expect(node.text()).toContain('Hello!');
|
|
80
|
+
});
|
|
81
|
+
|
|
39
82
|
it('is able to default render not available extension', () => {
|
|
40
83
|
const node = mount(<ExtensionSlot name="qxz" />);
|
|
41
84
|
expect(node.at(0).exists()).toBe(true);
|
|
@@ -62,6 +105,14 @@ describe('Extension Module', () => {
|
|
|
62
105
|
const node = mount(<ExtensionSlot name="bar" />);
|
|
63
106
|
expect(node.find(StubComponent1).length).toBe(2);
|
|
64
107
|
expect(node.find(StubComponent2).length).toBe(1);
|
|
108
|
+
expect(node.find(StubComponent3).length).toBe(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('is able to render extension without displayName', () => {
|
|
112
|
+
const node = mount(<ExtensionSlot name="bla" />);
|
|
113
|
+
expect(node.find(StubComponent1).length).toBe(0);
|
|
114
|
+
expect(node.find(StubComponent2).length).toBe(0);
|
|
115
|
+
expect(node.find(StubComponent3).length).toBe(1);
|
|
65
116
|
});
|
|
66
117
|
|
|
67
118
|
it('overrides the empty renderer on not available extension', () => {
|
|
@@ -5,6 +5,8 @@ import { useGlobalState, useGlobalStateContext } from '../hooks';
|
|
|
5
5
|
import { defaultRender, none } from '../utils';
|
|
6
6
|
import { ExtensionRegistration, ExtensionSlotProps } from '../types';
|
|
7
7
|
|
|
8
|
+
const wrapper = ({ children }) => defaultRender(children);
|
|
9
|
+
|
|
8
10
|
const renderExtensions: [ExtensionRegistration] = [
|
|
9
11
|
{
|
|
10
12
|
component: (props) => {
|
|
@@ -12,10 +14,7 @@ const renderExtensions: [ExtensionRegistration] = [
|
|
|
12
14
|
const converters = context.converters;
|
|
13
15
|
const piral = context.apis._;
|
|
14
16
|
const { component, props: args } = props.params;
|
|
15
|
-
const Component = React.useMemo(
|
|
16
|
-
() => wrapComponent(converters, component, { piral }, defaultRender),
|
|
17
|
-
[component],
|
|
18
|
-
);
|
|
17
|
+
const Component = React.useMemo(() => wrapComponent(converters, component, { piral }, wrapper), [component]);
|
|
19
18
|
return <Component {...args} />;
|
|
20
19
|
},
|
|
21
20
|
defaults: {},
|