@arcanejs/react-toolkit 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +289 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # `@arcanejs/react-toolkit`
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/%40arcanejs%2Freact-toolkit)](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
+ The UI has also been designed primarily with touch devices in mind,
15
+ but also works well with a cursor and keyboard.
16
+
17
+ ## Status / Suitability / Security Disclaimer
18
+
19
+ This project is **experimental**,
20
+ and takes advantage of unstable `react` APIs exposed via `react-render`.
21
+ It's not suitable for production or commercial projects yet,
22
+ especially those that rely on regular updates of dependencies
23
+ for security reasons,
24
+ as usage of this project may make it difficult to keep `react` up-to-date
25
+ (that being said, the license does not prohibit this,
26
+ so feel free to at-your-own-risk).
27
+
28
+ There are also no authentication mechanisms implemented yet,
29
+ so be careful when exposing your control panels over the network,
30
+ as this will allow anyone to interact with your processes.
31
+
32
+ ## Why
33
+
34
+ Sometimes you're working on relatively simple local applications or scripts,
35
+ and would like to have a way to interact with the state or configuration
36
+ of these applications in real-time,
37
+ for example:
38
+
39
+ - Lighting control or AV systems
40
+ - Home-Automation or Office building management and operation
41
+
42
+ ### Why Not
43
+
44
+ This project is not designed to be a general-purpose application framework,
45
+ in particular, it's not suitable for any project / application that:
46
+
47
+ - Needs to scale beyond a single Node.js process
48
+ - Is stateless _(It's explicitly designed to manage in-memory state)_
49
+ - Will be exposed over the internet _(no authentication has been implemented)_
50
+
51
+ ## Usage
52
+
53
+ Install the following packages:
54
+
55
+ ```
56
+ npm install --save react@^18 @arcanejs/toolkit @arcanejs/react-toolkit
57
+ ```
58
+
59
+ Note:
60
+
61
+ - We explicitly require `react` version 18
62
+ - We don't need `react-dom` or any react native libraries,
63
+ `@arcanejs/react-toolkit` is the react renderer.
64
+
65
+ Then you can then create control panels using react to manage the
66
+ server-side state like this:
67
+
68
+ ```ts
69
+ import { useState } from 'react';
70
+ import { Toolkit } from '@arcanejs/toolkit';
71
+ import { ToolkitRenderer, Group, Switch, SliderButton } from '@arcanejs/react-toolkit';
72
+
73
+ const toolkit = new Toolkit();
74
+
75
+ // Expose the toolkit control panel on HTTP port 3000
76
+ // Navigate to http://localhost:3000 to access the control panel
77
+ // this will be printed in your console
78
+ toolkit.start({
79
+ mode: 'automatic',
80
+ port: 3000,
81
+ });
82
+
83
+ const ControlPanel = () => {
84
+ const [switchState, setSwitchState] = useState<'off' | 'on'>('off');
85
+ const [sliderValue, setSliderValue] = useState(50);
86
+
87
+ return (
88
+ <Group direction='vertical'>
89
+ <Group>
90
+ {`Switch State: ${switchState}`}
91
+ <Switch
92
+ state={switchState}
93
+ onChange={setSwitchState}
94
+ />
95
+ </Group>
96
+ <Group>
97
+ {`Slider Value: ${sliderValue}`}
98
+ <SliderButton
99
+ value={sliderValue}
100
+ onChange={setSliderValue}
101
+ min={0}
102
+ max={100}
103
+ />
104
+ </Group>
105
+ </Group>
106
+ );
107
+ };
108
+
109
+ // Start rendering the control panel with @arcanejs/react-toolkit
110
+ ToolkitRenderer.render(<ControlPanel />, toolkit);
111
+ ```
112
+
113
+ You would then be able to access the following control panel
114
+ from [localhost:3000](http://localhost:3000):
115
+
116
+ ![Control Panel Screenshot](./docs/example-controller.png)
117
+
118
+ Please note:
119
+
120
+ - You can not use normal `react-dom` / HTML elements in these applications
121
+ or components, only `@arcanejs` components are supported.
122
+
123
+ - You are welcome to abstract / componentize your application as you like,
124
+ in the same manner that you would any `react-dom` or `react-native` project.
125
+
126
+ _See the [counter example](https://github.com/arcanejs/arcanejs/blob/main/examples/react/src/counter.tsx)._
127
+
128
+ - This react / component-tree / state is managed server-side,
129
+ and does not accurately represent the HTML used on the frontend.
130
+ Your `@arcanejs` tree is converted to a JSON representation,
131
+ and then sent to clients / browsers over a WebSocket.
132
+ There is then a separate `react-dom` application
133
+ that is loaded in the browser,
134
+ and then used to render the JSON representation of the `@arcanejs` tree.
135
+
136
+ - There is currently no ability to introduce custom components with your
137
+ own JSON definition and `react-dom` rendering in the browser.
138
+ Apps can only be composed of the below supported components,
139
+ or composite components directly built by these components.
140
+
141
+ _(This is something that is planned for the future)._
142
+
143
+ ## Components
144
+
145
+ For full example usage all of our components in applications that are
146
+ ready-to-run, we recommend that you check-out the
147
+ [examples directory](https://github.com/arcanejs/arcanejs/tree/main/examples/react).
148
+
149
+ ### `Button`
150
+
151
+ **Properties:**
152
+
153
+ - `text: string` (optional)
154
+
155
+ Text to display on the button
156
+
157
+ - `icon: string` (optional)
158
+
159
+ In icon name from [Material Icons](https://fonts.google.com/icons) to include
160
+ on the button.
161
+
162
+ - `error: string` (optional)
163
+
164
+ When set, highlight the button in a way to indicate an error,
165
+ and expose the given text as a tooltip upon user hover.
166
+
167
+ - `mode: 'normal' | 'pressed'` (default: `'normal'`)
168
+
169
+ Should the button display as pressed or not.
170
+
171
+ - `onClick: () => void | Promise<void>`
172
+
173
+ Set an event listener for when the button is pressed.
174
+
175
+ The listener can throw an exception, or return a promise that rejects,
176
+ to indicate an error and propagate an error message to the user,
177
+ similar to setting the `error` property.
178
+
179
+ e.g.:
180
+
181
+ ```tsx
182
+ const MyComponent = () => (
183
+ <Button text="Stop" onClick={() => doAThing()} icon="close" />
184
+ );
185
+ ```
186
+
187
+ ### `Group`
188
+
189
+ This component is the primary building block when it comes to creating layouts,
190
+ you generally have many groups,
191
+ and nest them to achieve the desired layout.
192
+
193
+ You can think of a group as similar to a `<div>` or `<section>` in HTML.
194
+
195
+ **Properties:**
196
+
197
+ - `direction: 'horizontal' | 'vertical'` (default: `'horizontal'`)
198
+
199
+ Whether to arrange the children of this group in a row or column.
200
+
201
+ - `wrap: boolean` (default: false)
202
+
203
+ If true, when the group runs out of vertical or horizontal space, child
204
+ components will be wrapped, and start to be arranged on additional columns
205
+ or rows.
206
+
207
+ - `border: boolean` (default: false)
208
+
209
+ If true, this group will have a border and a different color background
210
+ to its parent.
211
+
212
+ This allows you to add a distinctive border between components,
213
+ without needing to set a header, add header components,
214
+ or make it collapsible.
215
+
216
+ - `title: string` (optional)
217
+
218
+ If set, will display a title as a header at the top of the group.
219
+
220
+ - `editableTitle: boolean` (default: false)
221
+
222
+ If true,
223
+ will allow the user to click on the title to change it,
224
+ which will trigger a callback to the listener `onTitleChanged`.
225
+
226
+ - `defaultCollapsibleState: 'open' | 'closed' | 'auto'`
227
+ (optional, default: `undefined`)
228
+
229
+ If set,
230
+ will allow the user to expand / collapse the given group,
231
+ by default set to the given state.
232
+
233
+ Whether a group is open or closed is independent on a per-client basis,
234
+ and a fresh page reload will set the collapsible state to the default set here.
235
+
236
+ - `labels: { text: string }[] | null` (default: null)
237
+
238
+ Adds labels next to the title in the group header.
239
+
240
+ **Special Child Components**
241
+
242
+ - `GroupHeader`
243
+
244
+ You can add components to the header of a group by wrapping them in a
245
+ `<GroupHeader/>` component directly under the `<Group/>`.
246
+
247
+ You can add as many separate `GroupHeader` components as needed throughout
248
+ a `<Group>` component's direct children,
249
+ and all nested components will be placed in the header.
250
+
251
+ Currently `GroupHeader` only supports rendering the following children:
252
+
253
+ - `Button`
254
+
255
+ TODO: example
256
+
257
+ ### `Label`
258
+
259
+ TODO
260
+
261
+ ### `Rect`
262
+
263
+ TODO
264
+
265
+ ### `SliderButton`
266
+
267
+ TODO
268
+
269
+ ### `Switch`
270
+
271
+ TODO
272
+
273
+ ### `Tabs`
274
+
275
+ TODO
276
+
277
+ ### `TextInput`
278
+
279
+ TODO
280
+
281
+ ### `Timeline`
282
+
283
+ TODO
284
+
285
+ ## [Examples](https://github.com/arcanejs/arcanejs/tree/main/examples/react)
286
+
287
+ For a comprehensive list of examples,
288
+ please see the example directory in the arcane monorepo:
289
+ <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.0",
3
+ "version": "0.1.2",
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.0"
43
+ "@arcanejs/toolkit": "^0.2.0"
44
44
  },
45
45
  "files": [
46
46
  "dist"