@24i/bigscreen-sdk 1.0.18-bs-player.2373 → 1.0.18-bs.player.2362
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/package.json +7 -7
- package/packages/router/src/Route.tsx +27 -10
- package/packages/router/src/Router.tsx +13 -59
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@24i/bigscreen-sdk",
|
|
3
|
-
"version": "1.0.18-bs
|
|
3
|
+
"version": "1.0.18-bs.player.2362",
|
|
4
4
|
"description": "SmartApps BIGscreen SDK monorepo",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@24i/appstage-shared-analytics": "1.0.16-alpha.58",
|
|
41
41
|
"@24i/appstage-shared-events-manager": "1.0.7",
|
|
42
42
|
"@24i/appstage-shared-perf-utils": "1.0.5",
|
|
43
|
-
"@24i/bigscreen-players-engine-base": "0.1.
|
|
44
|
-
"@24i/smartapps-datalayer": "3.0.
|
|
43
|
+
"@24i/bigscreen-players-engine-base": "0.1.0",
|
|
44
|
+
"@24i/smartapps-datalayer": "3.0.7-alpha.998",
|
|
45
45
|
"@sentry/browser": "7.35.0",
|
|
46
46
|
"@sentry/types": "7.35.0",
|
|
47
47
|
"@types/gtag.js": "^0.0.12",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"@24i/bigscreen-sdk": "file:.",
|
|
56
56
|
"@24i/eslint-config-smartapps-bigscreen-linters": "file:./libs/linters",
|
|
57
57
|
"@24i/smartapps-bigscreen-changelog-generator": "0.17.0",
|
|
58
|
-
"@babel/core": "^7.
|
|
59
|
-
"@babel/preset-env": "^7.
|
|
58
|
+
"@babel/core": "^7.21.0",
|
|
59
|
+
"@babel/preset-env": "^7.20.2",
|
|
60
60
|
"@types/fs-extra": "^11.0.1",
|
|
61
61
|
"@types/inquirer": "^9.0.3",
|
|
62
|
-
"@types/jest": "^29.
|
|
62
|
+
"@types/jest": "^29.2.3",
|
|
63
63
|
"@types/minimist": "^1.2.2",
|
|
64
64
|
"@types/node": "^18.7.18",
|
|
65
65
|
"@types/react": "^18.0.33",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"fs-extra": "^11.1.0",
|
|
71
71
|
"full-icu": "^1.5.0",
|
|
72
72
|
"identity-obj-proxy": "^3.0.0",
|
|
73
|
-
"inquirer": "^9.
|
|
73
|
+
"inquirer": "^9.1.4",
|
|
74
74
|
"jest": "^29.3.1",
|
|
75
75
|
"jest-canvas-mock": "^2.4.0",
|
|
76
76
|
"jest-environment-jsdom": "^29.0.3",
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Component,
|
|
4
4
|
createRef,
|
|
5
5
|
detachNode,
|
|
6
|
-
Reference,
|
|
7
6
|
replaceNode,
|
|
8
7
|
} from '@24i/bigscreen-sdk/jsx';
|
|
9
8
|
import { filter, forEach } from '@24i/bigscreen-sdk/perf-utils/array';
|
|
@@ -14,9 +13,9 @@ import { IRoute, RouteParams } from './types';
|
|
|
14
13
|
|
|
15
14
|
type Props = {
|
|
16
15
|
path: string,
|
|
17
|
-
domParent?: Reference<HTMLElement>;
|
|
18
16
|
regexpPath?: RegExp,
|
|
19
17
|
paramNames?: string[],
|
|
18
|
+
isDetachable?: boolean;
|
|
20
19
|
Component: Function,
|
|
21
20
|
};
|
|
22
21
|
|
|
@@ -27,10 +26,18 @@ export class Route extends Component<Props> {
|
|
|
27
26
|
|
|
28
27
|
isDetached = false;
|
|
29
28
|
|
|
29
|
+
domParent: HTMLElement | null = null;
|
|
30
|
+
|
|
30
31
|
domRef = createRef<HTMLDivElement>();
|
|
31
32
|
|
|
32
33
|
component = createRef<IRoute | null>();
|
|
33
34
|
|
|
35
|
+
componentDidMount() {
|
|
36
|
+
const { isDetachable } = this.props;
|
|
37
|
+
this.domParent = this.domRef.current?.parentElement!;
|
|
38
|
+
if (isDetachable) this.detach();
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
getParams(): RouteParams {
|
|
35
42
|
const { regexpPath, paramNames } = this.props;
|
|
36
43
|
if (!paramNames || !regexpPath) return {};
|
|
@@ -56,6 +63,7 @@ export class Route extends Component<Props> {
|
|
|
56
63
|
|
|
57
64
|
show() {
|
|
58
65
|
menuService.addEventListener('visibilitychange', this.onMenuVisibilityChange);
|
|
66
|
+
this.showRoute();
|
|
59
67
|
if (!this.wasCreated) {
|
|
60
68
|
this.mountRoute();
|
|
61
69
|
this.component.current?.activate(this.getParams());
|
|
@@ -66,7 +74,10 @@ export class Route extends Component<Props> {
|
|
|
66
74
|
|
|
67
75
|
hide() {
|
|
68
76
|
menuService.removeEventListener('visibilitychange', this.onMenuVisibilityChange);
|
|
69
|
-
this.
|
|
77
|
+
if (this.wasCreated) {
|
|
78
|
+
this.component.current?.deactivate();
|
|
79
|
+
this.hideRoute();
|
|
80
|
+
}
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
replace(newRoute: Route) {
|
|
@@ -78,9 +89,8 @@ export class Route extends Component<Props> {
|
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
attach() {
|
|
81
|
-
const { domParent } = this.props;
|
|
82
92
|
if (this.isDetached) {
|
|
83
|
-
attachNode(this.domRef, domParent!);
|
|
93
|
+
attachNode(this.domRef, this.domParent!);
|
|
84
94
|
this.isDetached = false;
|
|
85
95
|
}
|
|
86
96
|
}
|
|
@@ -104,12 +114,14 @@ export class Route extends Component<Props> {
|
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
|
|
107
|
-
showRoute() {
|
|
108
|
-
|
|
117
|
+
private showRoute() {
|
|
118
|
+
const { isDetachable } = this.props;
|
|
119
|
+
if (!isDetachable) this.domRef.current!.style.display = 'block';
|
|
109
120
|
}
|
|
110
121
|
|
|
111
|
-
hideRoute() {
|
|
112
|
-
|
|
122
|
+
private hideRoute() {
|
|
123
|
+
const { isDetachable } = this.props;
|
|
124
|
+
if (!isDetachable) this.domRef.current!.style.display = 'none';
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
private mountRoute() {
|
|
@@ -122,8 +134,13 @@ export class Route extends Component<Props> {
|
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
render() {
|
|
137
|
+
const { isDetachable } = this.props;
|
|
125
138
|
return (
|
|
126
|
-
<div
|
|
139
|
+
<div
|
|
140
|
+
className="route"
|
|
141
|
+
style={!isDetachable ? { display: 'none' } : {}}
|
|
142
|
+
ref={this.domRef}
|
|
143
|
+
/>
|
|
127
144
|
);
|
|
128
145
|
}
|
|
129
146
|
}
|
|
@@ -28,8 +28,6 @@ const filterNulls = (allChildren: (JSX.Element | null)[]) => (
|
|
|
28
28
|
export class Router extends Component<Props> {
|
|
29
29
|
paths: { [key: string]: RoutePath } = {};
|
|
30
30
|
|
|
31
|
-
routerDomRef = createRef<HTMLDivElement>();
|
|
32
|
-
|
|
33
31
|
static defaultProps = {
|
|
34
32
|
defaultPath: '/',
|
|
35
33
|
detachInactiveRoutes: true,
|
|
@@ -40,14 +38,12 @@ export class Router extends Component<Props> {
|
|
|
40
38
|
constructor(props: Props) {
|
|
41
39
|
super(props);
|
|
42
40
|
routerRef.current = this;
|
|
43
|
-
|
|
44
|
-
this.createRefs(children);
|
|
41
|
+
this.createRefs();
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
componentDidMount() {
|
|
48
45
|
window.document.addEventListener('keydown', this.onKeyDown, false);
|
|
49
46
|
window.addEventListener('hashchange', this.onHashChange, false);
|
|
50
|
-
this.hideAllRoutes();
|
|
51
47
|
this.goToDefaultPath();
|
|
52
48
|
}
|
|
53
49
|
|
|
@@ -95,8 +91,6 @@ export class Router extends Component<Props> {
|
|
|
95
91
|
return activeRoutePath?.ref.current || null;
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
// TODO: refactor to reduce complexity
|
|
99
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
100
94
|
switchRoutes(
|
|
101
95
|
routePathToHide: RoutePath | null,
|
|
102
96
|
routePathToShow: RoutePath | null,
|
|
@@ -110,31 +104,18 @@ export class Router extends Component<Props> {
|
|
|
110
104
|
} else if (routePathToShow) {
|
|
111
105
|
routeToHide!.hide();
|
|
112
106
|
routePathToHide.isVisible = false;
|
|
113
|
-
if (detachInactiveRoutes)
|
|
114
|
-
routeToHide!.replace(routeToShow!);
|
|
115
|
-
} else {
|
|
116
|
-
routeToHide!.hideRoute();
|
|
117
|
-
routeToShow!.showRoute();
|
|
118
|
-
}
|
|
107
|
+
if (detachInactiveRoutes) routeToHide!.replace(routeToShow!);
|
|
119
108
|
routeToShow!.show();
|
|
120
109
|
routePathToShow.isVisible = true;
|
|
121
110
|
return;
|
|
122
111
|
} else {
|
|
123
112
|
routeToHide!.hide();
|
|
124
113
|
routePathToHide.isVisible = false;
|
|
125
|
-
if (detachInactiveRoutes)
|
|
126
|
-
routeToHide!.detach();
|
|
127
|
-
} else {
|
|
128
|
-
routeToHide!.hideRoute();
|
|
129
|
-
}
|
|
114
|
+
if (detachInactiveRoutes) routeToHide!.detach();
|
|
130
115
|
}
|
|
131
116
|
}
|
|
132
117
|
if (routePathToShow) {
|
|
133
|
-
if (detachInactiveRoutes)
|
|
134
|
-
routeToShow!.attach();
|
|
135
|
-
} else {
|
|
136
|
-
routeToShow!.showRoute();
|
|
137
|
-
}
|
|
118
|
+
if (detachInactiveRoutes) routeToShow!.attach();
|
|
138
119
|
routeToShow!.show();
|
|
139
120
|
routePathToShow.isVisible = true;
|
|
140
121
|
}
|
|
@@ -144,10 +125,11 @@ export class Router extends Component<Props> {
|
|
|
144
125
|
this.getActiveRoute()?.focus();
|
|
145
126
|
}
|
|
146
127
|
|
|
147
|
-
createRefs(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
128
|
+
createRefs() {
|
|
129
|
+
const { children } = this.props;
|
|
130
|
+
forEach(children, (child: JSX.Element) => {
|
|
131
|
+
if (child.type === Route) {
|
|
132
|
+
const { path } = child.props;
|
|
151
133
|
const { regexpPath, paramNames } = pathToRegExp(path);
|
|
152
134
|
this.paths[path] = {
|
|
153
135
|
ref: createRef<Route>(),
|
|
@@ -169,28 +151,9 @@ export class Router extends Component<Props> {
|
|
|
169
151
|
}
|
|
170
152
|
}
|
|
171
153
|
|
|
172
|
-
|
|
173
|
-
const { detachInactiveRoutes } = this.props;
|
|
174
|
-
|
|
175
|
-
const route = this.paths[key];
|
|
176
|
-
if (!route.isVisible) {
|
|
177
|
-
if (detachInactiveRoutes) {
|
|
178
|
-
route.ref.current!.detach();
|
|
179
|
-
} else {
|
|
180
|
-
route.ref.current!.hideRoute();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
appendRoutes(routes: JSX.Element[]) {
|
|
187
|
-
this.createRefs(routes);
|
|
188
|
-
this.appendMount(this.renderRoutes(routes), this.routerDomRef);
|
|
189
|
-
this.hideAllRoutes();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
renderRoutes(routes: JSX.Element[]) {
|
|
193
|
-
return filterNulls(map(routes, (child: JSX.Element) => {
|
|
154
|
+
render() {
|
|
155
|
+
const { children, detachInactiveRoutes } = this.props;
|
|
156
|
+
return filterNulls(map(children, (child: JSX.Element) => {
|
|
194
157
|
if (child.type === Route) {
|
|
195
158
|
const { path, Component: RouteComponent } = child.props;
|
|
196
159
|
const route = this.paths[path];
|
|
@@ -198,23 +161,14 @@ export class Router extends Component<Props> {
|
|
|
198
161
|
<Route
|
|
199
162
|
ref={route.ref}
|
|
200
163
|
path={path}
|
|
201
|
-
domParent={this.routerDomRef}
|
|
202
164
|
regexpPath={route.regexpPath}
|
|
203
165
|
Component={RouteComponent}
|
|
204
166
|
paramNames={route.paramNames}
|
|
167
|
+
isDetachable={detachInactiveRoutes}
|
|
205
168
|
/>
|
|
206
169
|
);
|
|
207
170
|
}
|
|
208
171
|
return null;
|
|
209
172
|
}));
|
|
210
173
|
}
|
|
211
|
-
|
|
212
|
-
render() {
|
|
213
|
-
const { children } = this.props;
|
|
214
|
-
return (
|
|
215
|
-
<div ref={this.routerDomRef} className="router">
|
|
216
|
-
{this.renderRoutes(children)}
|
|
217
|
-
</div>
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
174
|
}
|