piral-core 0.15.0-alpha.3809 → 0.15.0-alpha.3933
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/ForeignComponentContainer.d.ts +1 -0
- package/esm/components/ForeignComponentContainer.js +4 -3
- package/esm/components/ForeignComponentContainer.js.map +1 -1
- package/esm/types/components.d.ts +6 -3
- package/esm/utils/media.js +1 -2
- package/esm/utils/media.js.map +1 -1
- package/lib/components/ForeignComponentContainer.d.ts +1 -0
- package/lib/components/ForeignComponentContainer.js +4 -3
- package/lib/components/ForeignComponentContainer.js.map +1 -1
- package/lib/types/components.d.ts +6 -3
- package/lib/utils/media.js +1 -2
- package/lib/utils/media.js.map +1 -1
- package/package.json +4 -4
- package/src/actions/portal.test.ts +53 -8
- package/src/components/ForeignComponentContainer.tsx +4 -3
- package/src/components/PiralView.test.tsx +1 -1
- package/src/components/PiralView.tsx +1 -1
- package/src/createInstance.test.tsx +5 -0
- package/src/hooks/globalState-server.test.ts +41 -0
- package/src/types/components.ts +6 -3
- package/src/utils/extension.test.tsx +1 -1
- 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
|
@@ -7,6 +7,7 @@ interface ForeignComponentContainerProps<T> {
|
|
|
7
7
|
innerProps: T & BaseComponentProps;
|
|
8
8
|
}
|
|
9
9
|
export declare class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
10
|
+
private locals?;
|
|
10
11
|
private current?;
|
|
11
12
|
private previous?;
|
|
12
13
|
private handler;
|
|
@@ -3,6 +3,7 @@ import { isfunc } from 'piral-base';
|
|
|
3
3
|
export class ForeignComponentContainer extends React.Component {
|
|
4
4
|
constructor() {
|
|
5
5
|
super(...arguments);
|
|
6
|
+
this.locals = {};
|
|
6
7
|
this.handler = (ev) => {
|
|
7
8
|
const { innerProps } = this.props;
|
|
8
9
|
ev.stopPropagation();
|
|
@@ -17,7 +18,7 @@ export class ForeignComponentContainer extends React.Component {
|
|
|
17
18
|
const { $component, $context, innerProps } = this.props;
|
|
18
19
|
const { mount } = $component;
|
|
19
20
|
if (node && isfunc(mount)) {
|
|
20
|
-
mount(node, innerProps, $context);
|
|
21
|
+
mount(node, innerProps, $context, this.locals);
|
|
21
22
|
node.addEventListener('render-html', this.handler, false);
|
|
22
23
|
}
|
|
23
24
|
this.previous = node;
|
|
@@ -31,7 +32,7 @@ export class ForeignComponentContainer extends React.Component {
|
|
|
31
32
|
current && this.componentDidMount();
|
|
32
33
|
}
|
|
33
34
|
else if (isfunc(update)) {
|
|
34
|
-
update(current, innerProps, $context);
|
|
35
|
+
update(current, innerProps, $context, this.locals);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
componentWillUnmount() {
|
|
@@ -39,7 +40,7 @@ export class ForeignComponentContainer extends React.Component {
|
|
|
39
40
|
const { $component } = this.props;
|
|
40
41
|
const { unmount } = $component;
|
|
41
42
|
if (node && isfunc(unmount)) {
|
|
42
|
-
unmount(node);
|
|
43
|
+
unmount(node, this.locals);
|
|
43
44
|
node.removeEventListener('render-html', this.handler, false);
|
|
44
45
|
}
|
|
45
46
|
this.previous = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForeignComponentContainer.js","sourceRoot":"","sources":["../../src/components/ForeignComponentContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAWpC,MAAM,OAAO,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAApG;;
|
|
1
|
+
{"version":3,"file":"ForeignComponentContainer.js","sourceRoot":"","sources":["../../src/components/ForeignComponentContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAA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,QAAQ,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACxC,OAAO,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;SACrC;aAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SACpD;IACH,CAAC;IAED,oBAAoB;QAClB,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC3B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;QAE/B,IAAI,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE;YAC3B,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3B,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,OAAO,+CAAqB,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,GAAI,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -41,20 +41,23 @@ export interface ForeignComponent<TProps> {
|
|
|
41
41
|
* @param element The container hosting the element.
|
|
42
42
|
* @param props The props to transport.
|
|
43
43
|
* @param ctx The associated context.
|
|
44
|
+
* @param locals The local state of this component instance.
|
|
44
45
|
*/
|
|
45
|
-
mount(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
46
|
+
mount(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
46
47
|
/**
|
|
47
48
|
* Called when the component should be updated.
|
|
48
49
|
* @param element The container hosting the element.
|
|
49
50
|
* @param props The props to transport.
|
|
50
51
|
* @param ctx The associated context.
|
|
52
|
+
* @param locals The local state of this component instance.
|
|
51
53
|
*/
|
|
52
|
-
update?(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
54
|
+
update?(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
53
55
|
/**
|
|
54
56
|
* Called when a component is unmounted.
|
|
55
57
|
* @param element The container that was hosting the element.
|
|
58
|
+
* @param locals The local state of this component instance.
|
|
56
59
|
*/
|
|
57
|
-
unmount?(element: HTMLElement): void;
|
|
60
|
+
unmount?(element: HTMLElement, locals: Record<string, any>): void;
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
63
|
* Possible shapes for a component.
|
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"}
|
|
@@ -7,6 +7,7 @@ interface ForeignComponentContainerProps<T> {
|
|
|
7
7
|
innerProps: T & BaseComponentProps;
|
|
8
8
|
}
|
|
9
9
|
export declare class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
10
|
+
private locals?;
|
|
10
11
|
private current?;
|
|
11
12
|
private previous?;
|
|
12
13
|
private handler;
|
|
@@ -6,6 +6,7 @@ const piral_base_1 = require("piral-base");
|
|
|
6
6
|
class ForeignComponentContainer extends React.Component {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
|
+
this.locals = {};
|
|
9
10
|
this.handler = (ev) => {
|
|
10
11
|
const { innerProps } = this.props;
|
|
11
12
|
ev.stopPropagation();
|
|
@@ -20,7 +21,7 @@ class ForeignComponentContainer extends React.Component {
|
|
|
20
21
|
const { $component, $context, innerProps } = this.props;
|
|
21
22
|
const { mount } = $component;
|
|
22
23
|
if (node && (0, piral_base_1.isfunc)(mount)) {
|
|
23
|
-
mount(node, innerProps, $context);
|
|
24
|
+
mount(node, innerProps, $context, this.locals);
|
|
24
25
|
node.addEventListener('render-html', this.handler, false);
|
|
25
26
|
}
|
|
26
27
|
this.previous = node;
|
|
@@ -34,7 +35,7 @@ class ForeignComponentContainer extends React.Component {
|
|
|
34
35
|
current && this.componentDidMount();
|
|
35
36
|
}
|
|
36
37
|
else if ((0, piral_base_1.isfunc)(update)) {
|
|
37
|
-
update(current, innerProps, $context);
|
|
38
|
+
update(current, innerProps, $context, this.locals);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
componentWillUnmount() {
|
|
@@ -42,7 +43,7 @@ class ForeignComponentContainer extends React.Component {
|
|
|
42
43
|
const { $component } = this.props;
|
|
43
44
|
const { unmount } = $component;
|
|
44
45
|
if (node && (0, piral_base_1.isfunc)(unmount)) {
|
|
45
|
-
unmount(node);
|
|
46
|
+
unmount(node, this.locals);
|
|
46
47
|
node.removeEventListener('render-html', this.handler, false);
|
|
47
48
|
}
|
|
48
49
|
this.previous = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForeignComponentContainer.js","sourceRoot":"","sources":["../../src/components/ForeignComponentContainer.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AAWpC,MAAa,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAApG;;
|
|
1
|
+
{"version":3,"file":"ForeignComponentContainer.js","sourceRoot":"","sources":["../../src/components/ForeignComponentContainer.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AAWpC,MAAa,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAApG;;QACU,WAAM,GAAyB,EAAE,CAAC;QAGlC,YAAO,GAAG,CAAC,EAAe,EAAE,EAA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,EAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SACpD;IACH,CAAC;IAED,oBAAoB;QAClB,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC3B,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAClC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;QAE/B,IAAI,IAAI,IAAI,IAAA,mBAAM,EAAC,OAAO,CAAC,EAAE;YAC3B,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3B,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,OAAO,+CAAqB,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,GAAI,CAAC;IAC/D,CAAC;CACF;AAzDD,8DAyDC"}
|
|
@@ -41,20 +41,23 @@ export interface ForeignComponent<TProps> {
|
|
|
41
41
|
* @param element The container hosting the element.
|
|
42
42
|
* @param props The props to transport.
|
|
43
43
|
* @param ctx The associated context.
|
|
44
|
+
* @param locals The local state of this component instance.
|
|
44
45
|
*/
|
|
45
|
-
mount(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
46
|
+
mount(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
46
47
|
/**
|
|
47
48
|
* Called when the component should be updated.
|
|
48
49
|
* @param element The container hosting the element.
|
|
49
50
|
* @param props The props to transport.
|
|
50
51
|
* @param ctx The associated context.
|
|
52
|
+
* @param locals The local state of this component instance.
|
|
51
53
|
*/
|
|
52
|
-
update?(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
54
|
+
update?(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
53
55
|
/**
|
|
54
56
|
* Called when a component is unmounted.
|
|
55
57
|
* @param element The container that was hosting the element.
|
|
58
|
+
* @param locals The local state of this component instance.
|
|
56
59
|
*/
|
|
57
|
-
unmount?(element: HTMLElement): void;
|
|
60
|
+
unmount?(element: HTMLElement, locals: Record<string, any>): void;
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
63
|
* Possible shapes for a component.
|
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.3933",
|
|
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.3933",
|
|
52
|
+
"piral-debug-utils": "0.15.0-alpha.3933"
|
|
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": "520a272d09f02543153f1d8b2ae23a3ae10acd6f"
|
|
83
83
|
}
|
|
@@ -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
|
});
|
|
@@ -11,6 +11,7 @@ interface ForeignComponentContainerProps<T> {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
|
|
14
|
+
private locals?: Record<string, any> = {};
|
|
14
15
|
private current?: HTMLElement;
|
|
15
16
|
private previous?: HTMLElement;
|
|
16
17
|
private handler = (ev: CustomEvent) => {
|
|
@@ -29,7 +30,7 @@ export class ForeignComponentContainer<T> extends React.Component<ForeignCompone
|
|
|
29
30
|
const { mount } = $component;
|
|
30
31
|
|
|
31
32
|
if (node && isfunc(mount)) {
|
|
32
|
-
mount(node, innerProps, $context);
|
|
33
|
+
mount(node, innerProps, $context, this.locals);
|
|
33
34
|
node.addEventListener('render-html', this.handler, false);
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -45,7 +46,7 @@ export class ForeignComponentContainer<T> extends React.Component<ForeignCompone
|
|
|
45
46
|
previous && this.componentWillUnmount();
|
|
46
47
|
current && this.componentDidMount();
|
|
47
48
|
} else if (isfunc(update)) {
|
|
48
|
-
update(current, innerProps, $context);
|
|
49
|
+
update(current, innerProps, $context, this.locals);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -55,7 +56,7 @@ export class ForeignComponentContainer<T> extends React.Component<ForeignCompone
|
|
|
55
56
|
const { unmount } = $component;
|
|
56
57
|
|
|
57
58
|
if (node && isfunc(unmount)) {
|
|
58
|
-
unmount(node);
|
|
59
|
+
unmount(node, this.locals);
|
|
59
60
|
node.removeEventListener('render-html', this.handler, false);
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -43,7 +43,7 @@ const state = {
|
|
|
43
43
|
|
|
44
44
|
(hooks as any).useGlobalState = (select: any) => select(state);
|
|
45
45
|
|
|
46
|
-
(routes as any).PiralRoutes = ({}) => <StubDashboard />;
|
|
46
|
+
(routes as any).PiralRoutes = ({ }) => <StubDashboard />;
|
|
47
47
|
|
|
48
48
|
describe('Portal Module', () => {
|
|
49
49
|
it('renders the dashboard / content in layout if loaded without error', () => {
|
|
@@ -42,7 +42,7 @@ const PiralProvider: React.FC = ({ children }) => {
|
|
|
42
42
|
/**
|
|
43
43
|
* The props for the PiralView component.
|
|
44
44
|
*/
|
|
45
|
-
export interface PiralViewProps {}
|
|
45
|
+
export interface PiralViewProps { }
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* The component responsible for the generic view of the application.
|
|
@@ -11,4 +11,9 @@ describe('Piral-Core createInstance module', () => {
|
|
|
11
11
|
const instance = createInstance({ async: true });
|
|
12
12
|
expect(instance.options.strategy).toBe(blazingStrategy);
|
|
13
13
|
});
|
|
14
|
+
|
|
15
|
+
it('createInstance with empty actions uses the standard strategy', () => {
|
|
16
|
+
const instance = createInstance({ actions: {} });
|
|
17
|
+
expect(instance.options.strategy).toBe(standardStrategy);
|
|
18
|
+
})
|
|
14
19
|
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
import { useGlobalState } from './globalState';
|
|
5
|
+
|
|
6
|
+
jest.mock('react', () => {
|
|
7
|
+
const { Atom } = require('@libre/atom');
|
|
8
|
+
const state = Atom.of({
|
|
9
|
+
foo: 5,
|
|
10
|
+
bar: {
|
|
11
|
+
qxz: 'hello',
|
|
12
|
+
},
|
|
13
|
+
list: [1, 2, 3],
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
createContext: jest.fn(),
|
|
17
|
+
useContext: () => ({ state }),
|
|
18
|
+
useState: (v) => [v, jest.fn()],
|
|
19
|
+
useMemo: (f) => f(),
|
|
20
|
+
useLayoutEffect: (f) => f(),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('Media Module', () => {
|
|
25
|
+
it('in here window should be undefined', () => {
|
|
26
|
+
expect(typeof window).toBe('undefined');
|
|
27
|
+
const result = useGlobalState((m) => (m as any).foo);
|
|
28
|
+
expect(result).toBe(5);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('gets full state object', () => {
|
|
32
|
+
const result = useGlobalState();
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
foo: 5,
|
|
35
|
+
bar: {
|
|
36
|
+
qxz: 'hello',
|
|
37
|
+
},
|
|
38
|
+
list: [1, 2, 3],
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
package/src/types/components.ts
CHANGED
|
@@ -45,20 +45,23 @@ export interface ForeignComponent<TProps> {
|
|
|
45
45
|
* @param element The container hosting the element.
|
|
46
46
|
* @param props The props to transport.
|
|
47
47
|
* @param ctx The associated context.
|
|
48
|
+
* @param locals The local state of this component instance.
|
|
48
49
|
*/
|
|
49
|
-
mount(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
50
|
+
mount(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
50
51
|
/**
|
|
51
52
|
* Called when the component should be updated.
|
|
52
53
|
* @param element The container hosting the element.
|
|
53
54
|
* @param props The props to transport.
|
|
54
55
|
* @param ctx The associated context.
|
|
56
|
+
* @param locals The local state of this component instance.
|
|
55
57
|
*/
|
|
56
|
-
update?(element: HTMLElement, props: TProps, ctx: ComponentContext): void;
|
|
58
|
+
update?(element: HTMLElement, props: TProps, ctx: ComponentContext, locals: Record<string, any>): void;
|
|
57
59
|
/**
|
|
58
60
|
* Called when a component is unmounted.
|
|
59
61
|
* @param element The container that was hosting the element.
|
|
62
|
+
* @param locals The local state of this component instance.
|
|
60
63
|
*/
|
|
61
|
-
unmount?(element: HTMLElement): void;
|
|
64
|
+
unmount?(element: HTMLElement, locals: Record<string, any>): void;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
package/src/utils/guid.test.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { generateId } from './guid';
|
|
1
|
+
import { buildName, generateId } from './guid';
|
|
2
2
|
|
|
3
3
|
describe('Guid Utility Module', () => {
|
|
4
|
+
it('buildName returns name with its prefix', () => {
|
|
5
|
+
const result = buildName('Ma', 'Majd');
|
|
6
|
+
expect(result).toEqual('Ma://Majd');
|
|
7
|
+
});
|
|
8
|
+
|
|
4
9
|
it('Generates two consecutive different guids', () => {
|
|
5
10
|
const guid1 = generateId();
|
|
6
11
|
const guid2 = generateId();
|
|
@@ -8,9 +8,61 @@ import {
|
|
|
8
8
|
prependItems,
|
|
9
9
|
appendItems,
|
|
10
10
|
updateKey,
|
|
11
|
+
replaceOrAddItem,
|
|
12
|
+
includeItem,
|
|
13
|
+
tryParseJson,
|
|
14
|
+
removeNested,
|
|
11
15
|
} from './helpers';
|
|
12
16
|
|
|
13
17
|
describe('Helpers Module', () => {
|
|
18
|
+
it('removeNested removes keys values', () => {
|
|
19
|
+
const obj = { d: 'test', z: ['test arr'] };
|
|
20
|
+
const result = removeNested(obj, () => true);
|
|
21
|
+
const expectedResult = { d: {}, z: {} };
|
|
22
|
+
expect(result).toEqual(expectedResult);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('removeNested removes keys values with nested arrays', () => {
|
|
26
|
+
const obj = { z: [['test arr'], ['test arr2']] };
|
|
27
|
+
const result = removeNested(obj, () => true);
|
|
28
|
+
const expectedResult = { z: { '0': [], '1': [] } };
|
|
29
|
+
expect(result).toEqual(expectedResult);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('removeNested splits keys values', () => {
|
|
33
|
+
const obj = { d: 'test', z: ['test arr'] };
|
|
34
|
+
const result = removeNested(obj, () => false);
|
|
35
|
+
const expectedResult = { d: { '0': 't', '1': 'e', '2': 's', '3': 't' }, z: { '0': 'test arr' } };
|
|
36
|
+
expect(result).toEqual(expectedResult);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('tryParseJson parses a JSON string', () => {
|
|
40
|
+
const content = '{"result":true, "count":42}';
|
|
41
|
+
const result = tryParseJson(content);
|
|
42
|
+
expect(result).toEqual({ result: true, count: 42 });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('tryParseJson return empty object if the content is not valid', () => {
|
|
46
|
+
const content = '"result":true, "count":42';
|
|
47
|
+
const result = tryParseJson(content);
|
|
48
|
+
expect(result).toEqual({});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('includeItem adds an item to array', () => {
|
|
52
|
+
const result = includeItem([1, 2, 3], 4);
|
|
53
|
+
expect(result).toEqual([1, 2, 3, 4]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('replaceOrAddItem replaces the first item', () => {
|
|
57
|
+
const result = replaceOrAddItem([1, 2, 3], 4, () => true);
|
|
58
|
+
expect(result).toEqual([4, 2, 3]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('replaceOrAddItem adds the item the end', () => {
|
|
62
|
+
const result = replaceOrAddItem([1, 2, 3], 4, () => false);
|
|
63
|
+
expect(result).toEqual([1, 2, 3, 4]);
|
|
64
|
+
});
|
|
65
|
+
|
|
14
66
|
it('prependItem works with an existing array', () => {
|
|
15
67
|
const result = prependItem([1, 2, 3], 4);
|
|
16
68
|
expect(result).toEqual([4, 1, 2, 3]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
import { getCurrentLayout } from './media';
|
|
5
|
+
|
|
6
|
+
describe('Media Module', () => {
|
|
7
|
+
it('in here window should be undefined', () => {
|
|
8
|
+
expect(typeof window).toBe('undefined');
|
|
9
|
+
const breakpoints = ['min-width: 200px', 'max-width: 199px'];
|
|
10
|
+
const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'qxz');
|
|
11
|
+
expect(result).toBe('qxz');
|
|
12
|
+
});
|
|
13
|
+
});
|
package/src/utils/media.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
|
-
import { none } from './helpers';
|
|
3
2
|
import { LayoutTypes, LayoutBreakpoints } from '../types';
|
|
4
3
|
|
|
5
4
|
export const defaultLayouts: LayoutTypes = ['desktop', 'tablet', 'mobile'];
|
|
@@ -8,7 +7,7 @@ export const defaultBreakpoints: LayoutBreakpoints = ['(min-width: 991px)', '(mi
|
|
|
8
7
|
|
|
9
8
|
const mm =
|
|
10
9
|
typeof window === 'undefined' || !isfunc(window.matchMedia)
|
|
11
|
-
? () => ({ matches:
|
|
10
|
+
? () => ({ matches: undefined })
|
|
12
11
|
: (q: string) => window.matchMedia(q);
|
|
13
12
|
|
|
14
13
|
export function getCurrentLayout<T>(breakpoints: Array<string>, layouts: Array<T>, defaultLayout: T) {
|