@remvst/game-navigation-react 1.0.0
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/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/react-game-plugin.d.ts +7 -0
- package/lib/react-game-plugin.js +17 -0
- package/lib/react-screen.d.ts +12 -0
- package/lib/react-screen.js +41 -0
- package/package.json +24 -0
- package/src/index.ts +2 -0
- package/src/react-game-plugin.ts +14 -0
- package/src/react-screen.ts +46 -0
- package/tsconfig.json +14 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./react-game-plugin"), exports);
|
|
18
|
+
__exportStar(require("./react-screen"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactGamePlugin = void 0;
|
|
4
|
+
const game_navigation_core_1 = require("@remvst/game-navigation-core");
|
|
5
|
+
class ReactGamePlugin extends game_navigation_core_1.GamePlugin {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.key = ReactGamePlugin.key;
|
|
9
|
+
}
|
|
10
|
+
setup() {
|
|
11
|
+
}
|
|
12
|
+
render() {
|
|
13
|
+
// no-op
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ReactGamePlugin = ReactGamePlugin;
|
|
17
|
+
ReactGamePlugin.key = 'react';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HTMLScreen } from '@remvst/game-navigation-html';
|
|
3
|
+
export declare abstract class ReactScreen extends HTMLScreen {
|
|
4
|
+
private root;
|
|
5
|
+
private rootContainer;
|
|
6
|
+
abstract rootComponent(): Promise<React.ReactElement>;
|
|
7
|
+
setup(): void;
|
|
8
|
+
foreground(): void;
|
|
9
|
+
background(): void;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
rebuild(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactScreen = void 0;
|
|
4
|
+
const client_1 = require("react-dom/client");
|
|
5
|
+
const game_navigation_html_1 = require("@remvst/game-navigation-html");
|
|
6
|
+
class ReactScreen extends game_navigation_html_1.HTMLScreen {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.rootContainer = document.createElement('div');
|
|
10
|
+
}
|
|
11
|
+
setup() {
|
|
12
|
+
super.setup();
|
|
13
|
+
this.root = (0, client_1.createRoot)(this.rootContainer);
|
|
14
|
+
this.rootComponent().then(component => {
|
|
15
|
+
this.root?.render(component);
|
|
16
|
+
});
|
|
17
|
+
this.rootContainer.style.width = '100%';
|
|
18
|
+
this.rootContainer.style.height = '100%';
|
|
19
|
+
}
|
|
20
|
+
foreground() {
|
|
21
|
+
super.foreground();
|
|
22
|
+
this.view.style.display = 'block';
|
|
23
|
+
this.view.appendChild(this.rootContainer);
|
|
24
|
+
}
|
|
25
|
+
background() {
|
|
26
|
+
super.background();
|
|
27
|
+
this.view.style.display = 'none';
|
|
28
|
+
this.rootContainer.parentNode?.removeChild(this.rootContainer);
|
|
29
|
+
}
|
|
30
|
+
destroy() {
|
|
31
|
+
super.destroy();
|
|
32
|
+
this.root.unmount();
|
|
33
|
+
this.root = null;
|
|
34
|
+
}
|
|
35
|
+
rebuild() {
|
|
36
|
+
this.root.unmount();
|
|
37
|
+
this.root = (0, client_1.createRoot)(this.rootContainer);
|
|
38
|
+
this.rootComponent().then(component => this.root.render(component));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ReactScreen = ReactScreen;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@remvst/game-navigation-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rm -rf lib && tsc",
|
|
8
|
+
"prepublishOnly": "npm i && npm run build"
|
|
9
|
+
},
|
|
10
|
+
"author": "Rémi Vansteelandt",
|
|
11
|
+
"license": "UNLICENSED",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@types/react-dom": "^18.2.0",
|
|
14
|
+
"react": "^18.2.0",
|
|
15
|
+
"react-dom": "^18.2.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@remvst/game-navigation-core": "file:../game-navigation-core",
|
|
19
|
+
"@remvst/game-navigation-html": "file:../game-navigation-html"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.2.2"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GamePlugin } from "@remvst/game-navigation-core";
|
|
2
|
+
|
|
3
|
+
export class ReactGamePlugin extends GamePlugin {
|
|
4
|
+
|
|
5
|
+
static readonly key = 'react';
|
|
6
|
+
readonly key = ReactGamePlugin.key;
|
|
7
|
+
|
|
8
|
+
setup(): void {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
render(): void {
|
|
12
|
+
// no-op
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRoot, Root } from 'react-dom/client';
|
|
2
|
+
import { HTMLScreen } from '@remvst/game-navigation-html';
|
|
3
|
+
|
|
4
|
+
export abstract class ReactScreen extends HTMLScreen {
|
|
5
|
+
|
|
6
|
+
private root: Root;
|
|
7
|
+
private rootContainer = document.createElement('div');
|
|
8
|
+
|
|
9
|
+
abstract rootComponent(): Promise<React.ReactElement>;
|
|
10
|
+
|
|
11
|
+
setup() {
|
|
12
|
+
super.setup();
|
|
13
|
+
|
|
14
|
+
this.root = createRoot(this.rootContainer);
|
|
15
|
+
this.rootComponent().then(component => {
|
|
16
|
+
this.root?.render(component);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.rootContainer.style.width = '100%';
|
|
20
|
+
this.rootContainer.style.height = '100%';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
foreground(): void {
|
|
24
|
+
super.foreground();
|
|
25
|
+
this.view.style.display = 'block';
|
|
26
|
+
this.view.appendChild(this.rootContainer);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
background(): void {
|
|
30
|
+
super.background();
|
|
31
|
+
this.view.style.display = 'none';
|
|
32
|
+
this.rootContainer.parentNode?.removeChild(this.rootContainer);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
destroy() {
|
|
36
|
+
super.destroy();
|
|
37
|
+
this.root.unmount();
|
|
38
|
+
this.root = null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
rebuild() {
|
|
42
|
+
this.root.unmount();
|
|
43
|
+
this.root = createRoot(this.rootContainer);
|
|
44
|
+
this.rootComponent().then(component => this.root.render(component));
|
|
45
|
+
}
|
|
46
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"strict": false,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowJs": false,
|
|
9
|
+
"outDir": "./lib",
|
|
10
|
+
"skipLibCheck": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["./src/**/*"],
|
|
13
|
+
"exclude": ["node_modules"]
|
|
14
|
+
}
|