|
1 | | -# React + TypeScript + Vite |
| 1 | +# Z-Wave JS Playground |
2 | 2 |
|
3 | | -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. |
| 3 | +An interactive, browser-based sandbox to build and test scripts to interact with a Z-Wave controller. |
4 | 4 |
|
5 | | -Currently, two official plugins are available: |
| 5 | +**Fully-local:** All code is executed locally in your browser, and is **not** sent to any server. Only type declarations are fetched from [jsDelivr](https://www.jsdelivr.com/). |
6 | 6 |
|
7 | | -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh |
8 | | -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
| 7 | +**Rich editor:** The built-in editor provides syntax highlighting, code completion, and error checking. |
9 | 8 |
|
10 | | -## Expanding the ESLint configuration |
| 9 | +**Sharing and embedding:** Share your scripts with others by copying the URL, or embed them in an iframe your own website. |
11 | 10 |
|
12 | | -If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: |
| 11 | + |
13 | 12 |
|
14 | | -- Configure the top-level `parserOptions` property like this: |
| 13 | +## How it works |
15 | 14 |
|
16 | | -```js |
17 | | -export default tseslint.config({ |
18 | | - languageOptions: { |
19 | | - // other options... |
20 | | - parserOptions: { |
21 | | - project: ['./tsconfig.node.json', './tsconfig.app.json'], |
22 | | - tsconfigRootDir: import.meta.dirname, |
23 | | - }, |
24 | | - }, |
25 | | -}) |
26 | | -``` |
| 15 | +- [esbuild](https://esbuild.github.io/) is used to pre-bundle Z-Wave JS while eliminating browser-incompatible dependencies and transpile your TypeScript code in the browser |
| 16 | +- [Monaco Editor](https://microsoft.github.io/monaco-editor/) powers the code editor |
| 17 | +- [TypeScript](https://www.npmjs.com/package/typescript) and [@typescript/ata](https://www.npmjs.com/package/@typescript/ata) are used to automatically download the type definitions |
| 18 | +- [@zwave-js/bindings-browser](https://www.npmjs.com/package/@zwave-js/bindings-browser) allows Z-Wave JS to use the browser's Web Serial and storage APIs |
| 19 | + |
| 20 | +When you press **Run**, the code is transpiled locally using `esbuild`. The playground hooks it up to a serial port (requires a Chromium-based browser) and executes it. The browser console output is redirected to the console panel. |
| 21 | + |
| 22 | +Some of these dependencies are pretty big (roughly 30 MB total), so the initial load might take a while. When embedded, the playground will ask first whether it should load the dependencies. |
27 | 23 |
|
28 | | -- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` |
29 | | -- Optionally add `...tseslint.configs.stylisticTypeChecked` |
30 | | -- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: |
31 | | - |
32 | | -```js |
33 | | -// eslint.config.js |
34 | | -import react from 'eslint-plugin-react' |
35 | | - |
36 | | -export default tseslint.config({ |
37 | | - // Set the react version |
38 | | - settings: { react: { version: '18.3' } }, |
39 | | - plugins: { |
40 | | - // Add the react plugin |
41 | | - react, |
42 | | - }, |
43 | | - rules: { |
44 | | - // other rules... |
45 | | - // Enable its recommended rules |
46 | | - ...react.configs.recommended.rules, |
47 | | - ...react.configs['jsx-runtime'].rules, |
48 | | - }, |
49 | | -}) |
| 24 | +## Embedding |
| 25 | + |
| 26 | +You can embed the playground in your own website using an iframe. Click the **Embed** button to get the URL for the iframe. Because the playground requires access to the serial port, these permissions must be granted explicitly: |
| 27 | +```html |
| 28 | +<iframe allow="serial" src="..."></iframe> |
50 | 29 | ``` |
| 30 | + |
| 31 | +We recommend a height of at least `750px` for the iframe. |
0 commit comments