@arcanejs/react-toolkit 0.1.0 → 0.1.1
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/README.md +186 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# `@arcanejs/react-toolkit`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@arcanejs/react-toolkit)
|
|
4
|
+
|
|
5
|
+
`@arcanejs/react-toolkit` Allows you to quickly create real-time control panels
|
|
6
|
+
for your JavaScript / TypeScript single-server apps,
|
|
7
|
+
using a custom react renderer, and WebSockets.
|
|
8
|
+
|
|
9
|
+
Control panels can be accessed by any number of
|
|
10
|
+
browsers / devices / clients simultaneously,
|
|
11
|
+
and changes caused by any client will be immediately propagated to all other
|
|
12
|
+
clients.
|
|
13
|
+
|
|
14
|
+
## Status / Suitability / Security Disclaimer
|
|
15
|
+
|
|
16
|
+
This project is **experimental**,
|
|
17
|
+
and takes advantage of unstable `react` APIs exposed via `react-render`.
|
|
18
|
+
It's not suitable for production or commercial projects yet,
|
|
19
|
+
especially those that rely on regular updates of dependencies
|
|
20
|
+
for security reasons,
|
|
21
|
+
as usage of this project may make it difficult to keep `react` up-to-date
|
|
22
|
+
(that being said, the license does not prohibit this,
|
|
23
|
+
so feel free to at-your-own-risk).
|
|
24
|
+
|
|
25
|
+
There are also no authentication mechanisms implemented yet,
|
|
26
|
+
so be careful when exposing your control panels over the network,
|
|
27
|
+
as this will allow anyone to interact with your processes.
|
|
28
|
+
|
|
29
|
+
## Why
|
|
30
|
+
|
|
31
|
+
Sometimes you're working on relatively simple local applications or scripts,
|
|
32
|
+
and would like to have a way to interact with the state or configuration
|
|
33
|
+
of these applications in real-time,
|
|
34
|
+
for example:
|
|
35
|
+
|
|
36
|
+
- Lighting control or AV systems
|
|
37
|
+
- Home-Automation or Office building management and operation
|
|
38
|
+
|
|
39
|
+
### Why Not
|
|
40
|
+
|
|
41
|
+
This project is not designed to be a general-purpose application framework,
|
|
42
|
+
in particular, it's not suitable for any project / application that:
|
|
43
|
+
|
|
44
|
+
- Needs to scale beyond a single Node.js process
|
|
45
|
+
- Is stateless _(It's explicitly designed to manage in-memory state)_
|
|
46
|
+
- Will be exposed over the internet _(no authentication has been implemented)_
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Install the following packages:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
npm install --save react@^18 @arcanejs/toolkit @arcanejs/react-toolkit
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Note:
|
|
57
|
+
|
|
58
|
+
- We explicitly require `react` version 18
|
|
59
|
+
- We don't need `react-dom` or any react native libraries,
|
|
60
|
+
`@arcanejs/react-toolkit` is the react renderer.
|
|
61
|
+
|
|
62
|
+
Then you can then create control panels using react to manage the
|
|
63
|
+
server-side state like this:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { useState } from 'react';
|
|
67
|
+
import { Toolkit } from '@arcanejs/toolkit';
|
|
68
|
+
import { ToolkitRenderer, Group, Switch, SliderButton } from '@arcanejs/react-toolkit';
|
|
69
|
+
|
|
70
|
+
const toolkit = new Toolkit();
|
|
71
|
+
|
|
72
|
+
// Expose the toolkit control panel on HTTP port 3000
|
|
73
|
+
// Navigate to http://localhost:3000 to access the control panel
|
|
74
|
+
// this will be printed in your console
|
|
75
|
+
toolkit.start({
|
|
76
|
+
mode: 'automatic',
|
|
77
|
+
port: 3000,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const ControlPanel = () => {
|
|
81
|
+
const [switchState, setSwitchState] = useState<'off' | 'on'>('off');
|
|
82
|
+
const [sliderValue, setSliderValue] = useState(50);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<Group direction='vertical'>
|
|
86
|
+
<Group>
|
|
87
|
+
{`Switch State: ${switchState}`}
|
|
88
|
+
<Switch
|
|
89
|
+
state={switchState}
|
|
90
|
+
onChange={setSwitchState}
|
|
91
|
+
/>
|
|
92
|
+
</Group>
|
|
93
|
+
<Group>
|
|
94
|
+
{`Slider Value: ${sliderValue}`}
|
|
95
|
+
<SliderButton
|
|
96
|
+
value={sliderValue}
|
|
97
|
+
onChange={setSliderValue}
|
|
98
|
+
min={0}
|
|
99
|
+
max={100}
|
|
100
|
+
/>
|
|
101
|
+
</Group>
|
|
102
|
+
</Group>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Start rendering the control panel with @arcanejs/react-toolkit
|
|
107
|
+
ToolkitRenderer.render(<ControlPanel />, toolkit);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
You would then be able to access the following control panel
|
|
111
|
+
from [localhost:3000](http://localhost:3000):
|
|
112
|
+
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
Please note:
|
|
116
|
+
|
|
117
|
+
- You can not use normal `react-dom` / HTML elements in these applications
|
|
118
|
+
or components, only `@arcanejs` components are supported.
|
|
119
|
+
|
|
120
|
+
- You are welcome to abstract / componentize your application as you like,
|
|
121
|
+
in the same manner that you would any `react-dom` or `react-native` project.
|
|
122
|
+
|
|
123
|
+
_See the [counter example](https://github.com/arcanejs/arcanejs/blob/main/examples/react/src/counter.tsx)._
|
|
124
|
+
|
|
125
|
+
- This react / component-tree / state is managed server-side,
|
|
126
|
+
and does not accurately represent the HTML used on the frontend.
|
|
127
|
+
Your `@arcanejs` tree is converted to a JSON representation,
|
|
128
|
+
and then sent to clients / browsers over a WebSocket.
|
|
129
|
+
There is then a separate `react-dom` application
|
|
130
|
+
that is loaded in the browser,
|
|
131
|
+
and then used to render the JSON representation of the `@arcanejs` tree.
|
|
132
|
+
|
|
133
|
+
- There is currently no ability to introduce custom components with your
|
|
134
|
+
own JSON definition and `react-dom` rendering in the browser.
|
|
135
|
+
Apps can only be composed of the below supported components,
|
|
136
|
+
or composite components directly built by these components.
|
|
137
|
+
|
|
138
|
+
_(This is something that is planned for the future)._
|
|
139
|
+
|
|
140
|
+
## Components
|
|
141
|
+
|
|
142
|
+
For full example usage all of our components in applications that are
|
|
143
|
+
ready-to-run, we recommend that you check-out the
|
|
144
|
+
[examples directory](https://github.com/arcanejs/arcanejs/tree/main/examples/react).
|
|
145
|
+
|
|
146
|
+
### `Button`
|
|
147
|
+
|
|
148
|
+
TODO
|
|
149
|
+
|
|
150
|
+
### `Group`
|
|
151
|
+
|
|
152
|
+
TODO
|
|
153
|
+
|
|
154
|
+
### `Label`
|
|
155
|
+
|
|
156
|
+
TODO
|
|
157
|
+
|
|
158
|
+
### `Rect`
|
|
159
|
+
|
|
160
|
+
TODO
|
|
161
|
+
|
|
162
|
+
### `SliderButton`
|
|
163
|
+
|
|
164
|
+
TODO
|
|
165
|
+
|
|
166
|
+
### `Switch`
|
|
167
|
+
|
|
168
|
+
TODO
|
|
169
|
+
|
|
170
|
+
### `Tabs`
|
|
171
|
+
|
|
172
|
+
TODO
|
|
173
|
+
|
|
174
|
+
### `TextInput`
|
|
175
|
+
|
|
176
|
+
TODO
|
|
177
|
+
|
|
178
|
+
### `Timeline`
|
|
179
|
+
|
|
180
|
+
TODO
|
|
181
|
+
|
|
182
|
+
## [Examples](https://github.com/arcanejs/arcanejs/tree/main/examples/react)
|
|
183
|
+
|
|
184
|
+
For a comprehensive list of examples,
|
|
185
|
+
please see the example directory in the arcane monorepo:
|
|
186
|
+
<https://github.com/arcanejs/arcanejs/tree/main/examples/react>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcanejs/react-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Build web-accessible control interfaces for your long-running Node.js processes",
|
|
6
6
|
"keywords": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"react": "^18",
|
|
43
|
-
"@arcanejs/toolkit": "^0.1.
|
|
43
|
+
"@arcanejs/toolkit": "^0.1.1"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|