gwchq-textjam 0.2.8 → 0.2.9

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 CHANGED
@@ -1,266 +1,266 @@
1
- # Getting Started
2
-
3
- This project provides a React component containing the Raspberry Pi Code Editor for embedding inside other applications. Although originally bootstrapped with [Create React App](https://github.com/facebook/create-react-app), the application has been ejected so all the build scripts etc. are now in the repo. Legacy web-component assets are still published for backwards compatibility, but the primary integration surface is the `TextJamEditor` React component.
4
-
5
- # Local development
6
-
7
- The app test page at `http://localhost:3011` can be used to develop the React component in isolation if needed.
8
-
9
- ## Install dependencies
10
-
11
- This repository uses Yarn 3 (see `package.json` → `packageManager`). Please install dependencies with Yarn:
12
-
13
- ```
14
- yarn install
15
- ```
16
-
17
- Using `npm install` can fail due to strict peer-dependency resolution in npm for some legacy packages in this project.
18
-
19
- ## Available Scripts
20
-
21
- In the project directory, you can run:
22
-
23
- ### `yarn start`
24
-
25
- Runs the app in the development mode.\
26
- Open [http://localhost:3011](http://localhost:3011) to view the web component test page in the browser.
27
-
28
- The page will reload if you make edits.\
29
- You will also see any lint errors in the console.
30
-
31
- ### `yarn test`
32
-
33
- Launches the test runner in interactive watch mode.\
34
- See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
35
-
36
- ### `yarn build:lib`
37
-
38
- Builds the lib for production to the `dist` folder.\
39
- It bundles React in production mode and optimizes the build for the best performance.
40
-
41
- The build is minified and the filenames include the hashes.\
42
- Your app is ready to be deployed!
43
-
44
- See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
45
-
46
- ## Styling
47
-
48
- The dev playground (`webpack.config.js`) keeps styles in JavaScript via `style-loader` for the fastest live reload experience. The library build (`webpack.lib.config.js`) extracts all CSS/SCSS into `dist/style.css` using `MiniCssExtractPlugin` so consumers can import a single stylesheet while still benefitting from CSS Modules (`*.module.(css|scss)`) for scoped styles.
49
-
50
- ### Styling Best Practices for Developers
51
-
52
- **Focus on CSS Modules**: When adding or modifying styles, prioritize CSS Modules over global styles. Use the `.module.css` or `.module.scss` naming convention to ensure styles are scoped to components and avoid style conflicts.
53
-
54
- **Refactor Global Styles**: When working on existing code, identify global styles and refactor them into CSS Modules when possible. This improves maintainability, reduces style conflicts, and makes components more self-contained.
55
-
56
- **CSS Modules Structure**:
57
-
58
- - Component-specific styles should live in `ComponentName/styles.module.scss` alongside the component
59
- - Import styles as: `import classes from './styles.module.scss'`
60
- - Use class names from the imported styles object: `className={classes.container}`
61
- - Webpack automatically generates scoped class names like `ComponentName__container--abc123`
62
-
63
- **When Global Styles Are Acceptable**:
64
-
65
- - Design system tokens and variables (e.g., color palettes, spacing scales)
66
- - Third-party library overrides that cannot be modularized
67
- - Base resets or typography that must apply globally
68
-
69
- **Example - Preferred CSS Modules Approach**:
70
-
71
- ```jsx
72
- // ComponentName/ComponentName.jsx
73
- import classes from "./styles.module.scss";
74
-
75
- export function ComponentName() {
76
- return <div className={classes.container}>Content</div>;
77
- }
78
- ```
79
-
80
- ```scss
81
- // ComponentName/styles.module.scss
82
- .container {
83
- padding: 1rem;
84
- background: var(--color-background);
85
- }
86
- ```
87
-
88
- ## Testing
89
-
90
- Automated unit tests can be run via the `yarn test` command. These unit tests are written using the JavaScript testing framework `Jest` and make use of the tools provided by the [React Testing Library](https://testing-library.com/docs/). Automated accessibility testing for components is available via the `jest-axe` library. This can be achieved using the `haveNoViolations` matcher provided by `jest-axe`, although this does not guarantee that the tested components have no accessibility issues.
91
-
92
- ## Publishing to npm
93
-
94
- ### Prerequisites
95
-
96
- 1. Ensure you're logged into npm:
97
-
98
- ```bash
99
- npm login
100
- ```
101
-
102
- 2. Verify you have publish access to the `gwchq-textjam` package.
103
-
104
- 3. Make sure all changes are committed and the working directory is clean.
105
-
106
- ### Publishing Steps
107
-
108
- 1. **Update the version** in `package.json` following [semantic versioning](https://semver.org/):
109
- - Patch: `0.1.2` → `0.1.3` (bug fixes)
110
- - Minor: `0.1.2` → `0.2.0` (new features, backwards compatible)
111
- - Major: `0.1.2` → `1.0.0` (breaking changes)
112
- 2. **Build the library** (automatically runs via `prepublishOnly` hook):
113
-
114
- ```bash
115
- yarn build:lib
116
- ```
117
-
118
- This creates the `dist` folder with:
119
-
120
- - `index.js` - The main ESM module
121
- - `style.css` - Extracted stylesheet
122
- - `assets/` - Static assets (icons, fonts, etc.)
123
-
124
- 3. **Verify the build output**:
125
-
126
- - Check that `dist/index.js` exists and is properly built
127
- - Verify `dist/style.css` contains all styles
128
- - Ensure all required assets are in `dist/assets/`
129
-
130
- 4. **Publish to npm**:
131
-
132
- ```bash
133
- npm publish
134
- ```
135
-
136
- The `prepublishOnly` script will automatically run `yarn build:lib` before publishing.
137
-
138
- 5. **Verify publication**:
139
- ```bash
140
- npm view gwchq-textjam version
141
- ```
142
-
143
- ### What Gets Published
144
-
145
- The following files are included in the npm package (as defined in `package.json` → `files`):
146
-
147
- - `dist/` - Built library files
148
- - `README.md` - This file
149
- - `LICENSE` - License file
150
-
151
- ### Package Exports
152
-
153
- Consumers can import:
154
-
155
- - Main component: `import { TextJamEditor } from "gwchq-textjam"`
156
- - Stylesheet: `import "gwchq-textjam/style.css"`
157
-
158
- # Using the editor as a React component
159
-
160
- The editor can be imported and rendered directly inside another React application. The package exports the `TextJamEditor` component and `styles.css`:
161
-
162
- ```tsx
163
- import { TextJamEditor } from "gwchq-textjam";
164
- import "gwchq-textjam/style.css";
165
-
166
- export function EditorWrapper() {
167
- return (
168
- <TextJamEditor
169
- project={{ project_type: "python", identifier: "my-py-app" }}
170
- />
171
- );
172
- }
173
- ```
174
-
175
- The consumer's webpack config should include the following setups
176
-
177
- ```
178
- {
179
- ...,
180
- modules: {
181
- rules: [
182
- ...,
183
- {
184
- test: /\.map$/,
185
- type: "asset/resource",
186
- },
187
- {
188
- test: /\.whl$/,
189
- type: "asset/resource",
190
- },
191
- {
192
- test: /\.glb$/,
193
- type: "asset/resource",
194
- },
195
- ]
196
- },
197
- plugins: [
198
- new CopyWebpackPlugin({
199
- patterns: [
200
- ...,
201
- {
202
- from: "node_modules/gwchq-textjam/dist/assets",
203
- to: "assets",
204
- },
205
- ],
206
- }),
207
- ],
208
- resolve: {
209
- extensions: ['.js', '.jsx'],
210
- alias: {
211
- 'react': path.resolve(__dirname, 'node_modules/react'),
212
- 'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
213
- 'react-redux': path.resolve(__dirname, 'node_modules/react-redux'),
214
- },
215
- fallback: {
216
- stream: require.resolve('stream-browserify'),
217
- path: require.resolve('path-browserify'),
218
- util: require.resolve('util/'),
219
- assert: require.resolve("assert"),
220
- },
221
- },
222
- }
223
- ```
224
-
225
- ### Component props
226
-
227
- `TextJamEditor` accepts the following props (previously exposed as web-component attributes):
228
-
229
- - `project`: an object with the project data. Contains the following props:
230
- - `project_type`: Possible values `web` | `python`. Default project files will be created according to this value
231
- - `identifier`: A string that represents the project id. If provided, cached project with same id will be loaded
232
- - `author`: an object with owner user data (firstName, lastName, id)
233
- - `components`: an array of project components (files and folders)
234
- - `packageApiUrl`: A string with url to download pyodide packages. If not provided - default value is pyodide CDN.
235
- - `isSharedProject`: a boolean to show a shared project interface instead the regular editor if `true` (`false` by default)
236
- - `isCodeVisible`: a boolean to show or hide the code panel (`true` by default)
237
-
238
- // TODO: review old options below
239
-
240
- - `loadCache`: Load latest version of project code from local storage (defaults to `true`)
241
- - `locale`: Locale for UI elements and to determine the language of projects loaded from the API (defaults to `en`)
242
- - `outputOnly`: Only display the output panel (defaults to `false`)
243
- - `outputPanels`: Array of output panel names to display (defaults to `['text', 'visual']`)
244
- - `outputSplitView`: Start with split view in output panel (defaults to `false`, i.e. tabbed view)
245
- - `projectNameEditable`: Allow the user to edit the project name in the project bar (defaults to `false`)
246
- - `readOnly`: Display the editor in read-only mode (defaults to `false`)
247
- - `sidebarOptions`: Array of strings specifying the panels to be displayed in the sidebar. Options include `"projects"`, `"file"`, `"download"`, `"settings"`.
248
-
249
- When no props are supplied the component falls back to parsing the current page’s query string so the local development experience (`yarn start`) continues to work unchanged. You can override this by explicitly passing `queryString` or the equivalent props.
250
-
251
- ### Events and callbacks
252
-
253
- For backwards compatibility the editor continues to dispatch the following `document` events. You can listen for them from your host application if you rely on the legacy integration layer:
254
-
255
- - `editor-codeChanged`
256
- - `editor-navigateToProjectsPage`
257
- - `editor-projectOwnerLoaded`
258
- - `editor-runCompleted`
259
- - `editor-runStarted`
260
- - `editor-stepChanged`
261
- - `editor-logIn`
262
- - `editor-signUp`
263
- - `editor-quizReady`
264
- - `editor-themeUpdated`
265
-
266
- These events make it possible for the host page to react to code execution, project changes, authentication requests, and theme updates.
1
+ # Getting Started
2
+
3
+ This project provides a React component containing the Raspberry Pi Code Editor for embedding inside other applications. Although originally bootstrapped with [Create React App](https://github.com/facebook/create-react-app), the application has been ejected so all the build scripts etc. are now in the repo. Legacy web-component assets are still published for backwards compatibility, but the primary integration surface is the `TextJamEditor` React component.
4
+
5
+ # Local development
6
+
7
+ The app test page at `http://localhost:3011` can be used to develop the React component in isolation if needed.
8
+
9
+ ## Install dependencies
10
+
11
+ This repository uses Yarn 3 (see `package.json` → `packageManager`). Please install dependencies with Yarn:
12
+
13
+ ```
14
+ yarn install
15
+ ```
16
+
17
+ Using `npm install` can fail due to strict peer-dependency resolution in npm for some legacy packages in this project.
18
+
19
+ ## Available Scripts
20
+
21
+ In the project directory, you can run:
22
+
23
+ ### `yarn start`
24
+
25
+ Runs the app in the development mode.\
26
+ Open [http://localhost:3011](http://localhost:3011) to view the web component test page in the browser.
27
+
28
+ The page will reload if you make edits.\
29
+ You will also see any lint errors in the console.
30
+
31
+ ### `yarn test`
32
+
33
+ Launches the test runner in interactive watch mode.\
34
+ See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
35
+
36
+ ### `yarn build:lib`
37
+
38
+ Builds the lib for production to the `dist` folder.\
39
+ It bundles React in production mode and optimizes the build for the best performance.
40
+
41
+ The build is minified and the filenames include the hashes.\
42
+ Your app is ready to be deployed!
43
+
44
+ See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
45
+
46
+ ## Styling
47
+
48
+ The dev playground (`webpack.config.js`) keeps styles in JavaScript via `style-loader` for the fastest live reload experience. The library build (`webpack.lib.config.js`) extracts all CSS/SCSS into `dist/style.css` using `MiniCssExtractPlugin` so consumers can import a single stylesheet while still benefitting from CSS Modules (`*.module.(css|scss)`) for scoped styles.
49
+
50
+ ### Styling Best Practices for Developers
51
+
52
+ **Focus on CSS Modules**: When adding or modifying styles, prioritize CSS Modules over global styles. Use the `.module.css` or `.module.scss` naming convention to ensure styles are scoped to components and avoid style conflicts.
53
+
54
+ **Refactor Global Styles**: When working on existing code, identify global styles and refactor them into CSS Modules when possible. This improves maintainability, reduces style conflicts, and makes components more self-contained.
55
+
56
+ **CSS Modules Structure**:
57
+
58
+ - Component-specific styles should live in `ComponentName/styles.module.scss` alongside the component
59
+ - Import styles as: `import classes from './styles.module.scss'`
60
+ - Use class names from the imported styles object: `className={classes.container}`
61
+ - Webpack automatically generates scoped class names like `ComponentName__container--abc123`
62
+
63
+ **When Global Styles Are Acceptable**:
64
+
65
+ - Design system tokens and variables (e.g., color palettes, spacing scales)
66
+ - Third-party library overrides that cannot be modularized
67
+ - Base resets or typography that must apply globally
68
+
69
+ **Example - Preferred CSS Modules Approach**:
70
+
71
+ ```jsx
72
+ // ComponentName/ComponentName.jsx
73
+ import classes from "./styles.module.scss";
74
+
75
+ export function ComponentName() {
76
+ return <div className={classes.container}>Content</div>;
77
+ }
78
+ ```
79
+
80
+ ```scss
81
+ // ComponentName/styles.module.scss
82
+ .container {
83
+ padding: 1rem;
84
+ background: var(--color-background);
85
+ }
86
+ ```
87
+
88
+ ## Testing
89
+
90
+ Automated unit tests can be run via the `yarn test` command. These unit tests are written using the JavaScript testing framework `Jest` and make use of the tools provided by the [React Testing Library](https://testing-library.com/docs/). Automated accessibility testing for components is available via the `jest-axe` library. This can be achieved using the `haveNoViolations` matcher provided by `jest-axe`, although this does not guarantee that the tested components have no accessibility issues.
91
+
92
+ ## Publishing to npm
93
+
94
+ ### Prerequisites
95
+
96
+ 1. Ensure you're logged into npm:
97
+
98
+ ```bash
99
+ npm login
100
+ ```
101
+
102
+ 2. Verify you have publish access to the `gwchq-textjam` package.
103
+
104
+ 3. Make sure all changes are committed and the working directory is clean.
105
+
106
+ ### Publishing Steps
107
+
108
+ 1. **Update the version** in `package.json` following [semantic versioning](https://semver.org/):
109
+ - Patch: `0.1.2` → `0.1.3` (bug fixes)
110
+ - Minor: `0.1.2` → `0.2.0` (new features, backwards compatible)
111
+ - Major: `0.1.2` → `1.0.0` (breaking changes)
112
+ 2. **Build the library** (automatically runs via `prepublishOnly` hook):
113
+
114
+ ```bash
115
+ yarn build:lib
116
+ ```
117
+
118
+ This creates the `dist` folder with:
119
+
120
+ - `index.js` - The main ESM module
121
+ - `style.css` - Extracted stylesheet
122
+ - `assets/` - Static assets (icons, fonts, etc.)
123
+
124
+ 3. **Verify the build output**:
125
+
126
+ - Check that `dist/index.js` exists and is properly built
127
+ - Verify `dist/style.css` contains all styles
128
+ - Ensure all required assets are in `dist/assets/`
129
+
130
+ 4. **Publish to npm**:
131
+
132
+ ```bash
133
+ npm publish
134
+ ```
135
+
136
+ The `prepublishOnly` script will automatically run `yarn build:lib` before publishing.
137
+
138
+ 5. **Verify publication**:
139
+ ```bash
140
+ npm view gwchq-textjam version
141
+ ```
142
+
143
+ ### What Gets Published
144
+
145
+ The following files are included in the npm package (as defined in `package.json` → `files`):
146
+
147
+ - `dist/` - Built library files
148
+ - `README.md` - This file
149
+ - `LICENSE` - License file
150
+
151
+ ### Package Exports
152
+
153
+ Consumers can import:
154
+
155
+ - Main component: `import { TextJamEditor } from "gwchq-textjam"`
156
+ - Stylesheet: `import "gwchq-textjam/style.css"`
157
+
158
+ # Using the editor as a React component
159
+
160
+ The editor can be imported and rendered directly inside another React application. The package exports the `TextJamEditor` component and `styles.css`:
161
+
162
+ ```tsx
163
+ import { TextJamEditor } from "gwchq-textjam";
164
+ import "gwchq-textjam/style.css";
165
+
166
+ export function EditorWrapper() {
167
+ return (
168
+ <TextJamEditor
169
+ project={{ project_type: "python", identifier: "my-py-app" }}
170
+ />
171
+ );
172
+ }
173
+ ```
174
+
175
+ The consumer's webpack config should include the following setups
176
+
177
+ ```
178
+ {
179
+ ...,
180
+ modules: {
181
+ rules: [
182
+ ...,
183
+ {
184
+ test: /\.map$/,
185
+ type: "asset/resource",
186
+ },
187
+ {
188
+ test: /\.whl$/,
189
+ type: "asset/resource",
190
+ },
191
+ {
192
+ test: /\.glb$/,
193
+ type: "asset/resource",
194
+ },
195
+ ]
196
+ },
197
+ plugins: [
198
+ new CopyWebpackPlugin({
199
+ patterns: [
200
+ ...,
201
+ {
202
+ from: "node_modules/gwchq-textjam/dist/assets",
203
+ to: "assets",
204
+ },
205
+ ],
206
+ }),
207
+ ],
208
+ resolve: {
209
+ extensions: ['.js', '.jsx'],
210
+ alias: {
211
+ 'react': path.resolve(__dirname, 'node_modules/react'),
212
+ 'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
213
+ 'react-redux': path.resolve(__dirname, 'node_modules/react-redux'),
214
+ },
215
+ fallback: {
216
+ stream: require.resolve('stream-browserify'),
217
+ path: require.resolve('path-browserify'),
218
+ util: require.resolve('util/'),
219
+ assert: require.resolve("assert"),
220
+ },
221
+ },
222
+ }
223
+ ```
224
+
225
+ ### Component props
226
+
227
+ `TextJamEditor` accepts the following props (previously exposed as web-component attributes):
228
+
229
+ - `project`: an object with the project data. Contains the following props:
230
+ - `project_type`: Possible values `web` | `python`. Default project files will be created according to this value
231
+ - `identifier`: A string that represents the project id. If provided, cached project with same id will be loaded
232
+ - `author`: an object with owner user data (firstName, lastName, id)
233
+ - `components`: an array of project components (files and folders)
234
+ - `packageApiUrl`: A string with url to download pyodide packages. If not provided - default value is pyodide CDN.
235
+ - `isSharedProject`: a boolean to show a shared project interface instead the regular editor if `true` (`false` by default)
236
+ - `isCodeVisible`: a boolean to show or hide the code panel (`true` by default)
237
+
238
+ // TODO: review old options below
239
+
240
+ - `loadCache`: Load latest version of project code from local storage (defaults to `true`)
241
+ - `locale`: Locale for UI elements and to determine the language of projects loaded from the API (defaults to `en`)
242
+ - `outputOnly`: Only display the output panel (defaults to `false`)
243
+ - `outputPanels`: Array of output panel names to display (defaults to `['text', 'visual']`)
244
+ - `outputSplitView`: Start with split view in output panel (defaults to `false`, i.e. tabbed view)
245
+ - `projectNameEditable`: Allow the user to edit the project name in the project bar (defaults to `false`)
246
+ - `readOnly`: Display the editor in read-only mode (defaults to `false`)
247
+ - `sidebarOptions`: Array of strings specifying the panels to be displayed in the sidebar. Options include `"projects"`, `"file"`, `"download"`, `"settings"`.
248
+
249
+ When no props are supplied the component falls back to parsing the current page’s query string so the local development experience (`yarn start`) continues to work unchanged. You can override this by explicitly passing `queryString` or the equivalent props.
250
+
251
+ ### Events and callbacks
252
+
253
+ For backwards compatibility the editor continues to dispatch the following `document` events. You can listen for them from your host application if you rely on the legacy integration layer:
254
+
255
+ - `editor-codeChanged`
256
+ - `editor-navigateToProjectsPage`
257
+ - `editor-projectOwnerLoaded`
258
+ - `editor-runCompleted`
259
+ - `editor-runStarted`
260
+ - `editor-stepChanged`
261
+ - `editor-logIn`
262
+ - `editor-signUp`
263
+ - `editor-quizReady`
264
+ - `editor-themeUpdated`
265
+
266
+ These events make it possible for the host page to react to code execution, project changes, authentication requests, and theme updates.