gwchq-textjam 0.5.2 → 0.5.3

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,240 +1,240 @@
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
- Publishing is handled by the **"NPM Publish (Scan + Bump + Publish)"** GitHub Actions workflow (`.github/workflows/publish.yml`) — there is no manual `npm publish` step.
95
-
96
- ### Running the workflow
97
-
98
- 1. Go to the repo's **Actions** tab → **NPM Publish (Scan + Bump + Publish)** → **Run workflow**.
99
- 2. Fill in the inputs:
100
- - `git_branch` — the branch to scan, bump, tag, and publish from (defaults to the current release branch).
101
- - `version_bump_type` — `patch`, `minor`, or `major`, following [semantic versioning](https://semver.org/).
102
- - `run_publish` — leave checked to publish to npm, or uncheck for a scan + version-bump dry run.
103
- 3. Run it. The workflow will:
104
- - Run the shared dependency, secrets, and SAST scans (`security-scan` → `secrets-scan` → `sast-scan`).
105
- - Run the test suite (`test`).
106
- - Bump `package.json`, commit, tag (`vX.Y.Z`), and push to `git_branch` (`bump-version`).
107
- - Build the library (via the `prepublishOnly` hook) and run `npm publish` (`publish`).
108
-
109
- Each stage gates the next — if a scan or the test suite fails, the version is never bumped and nothing is published.
110
-
111
- ### Verify publication
112
-
113
- ```bash
114
- npm view gwchq-textjam version
115
- ```
116
-
117
- ### What Gets Published
118
-
119
- The following files are included in the npm package (as defined in `package.json` → `files`):
120
-
121
- - `dist/` - Built library files
122
- - `README.md` - This file
123
- - `LICENSE` - License file
124
-
125
- ### Package Exports
126
-
127
- Consumers can import:
128
-
129
- - Main component: `import { TextJamEditor } from "gwchq-textjam"`
130
- - Stylesheet: `import "gwchq-textjam/style.css"`
131
-
132
- # Using the editor as a React component
133
-
134
- The editor can be imported and rendered directly inside another React application. The package exports the `TextJamEditor` component and `styles.css`:
135
-
136
- ```tsx
137
- import { TextJamEditor } from "gwchq-textjam";
138
- import "gwchq-textjam/style.css";
139
-
140
- export function EditorWrapper() {
141
- return (
142
- <TextJamEditor
143
- project={{ project_type: "python", identifier: "my-py-app" }}
144
- />
145
- );
146
- }
147
- ```
148
-
149
- The consumer's webpack config should include the following setups
150
-
151
- ```
152
- {
153
- ...,
154
- modules: {
155
- rules: [
156
- ...,
157
- {
158
- test: /\.map$/,
159
- type: "asset/resource",
160
- },
161
- {
162
- test: /\.whl$/,
163
- type: "asset/resource",
164
- },
165
- {
166
- test: /\.glb$/,
167
- type: "asset/resource",
168
- },
169
- ]
170
- },
171
- plugins: [
172
- new CopyWebpackPlugin({
173
- patterns: [
174
- ...,
175
- {
176
- from: "node_modules/gwchq-textjam/dist/assets",
177
- to: "assets",
178
- },
179
- ],
180
- }),
181
- ],
182
- resolve: {
183
- extensions: ['.js', '.jsx'],
184
- alias: {
185
- 'react': path.resolve(__dirname, 'node_modules/react'),
186
- 'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
187
- 'react-redux': path.resolve(__dirname, 'node_modules/react-redux'),
188
- },
189
- fallback: {
190
- stream: require.resolve('stream-browserify'),
191
- path: require.resolve('path-browserify'),
192
- util: require.resolve('util/'),
193
- assert: require.resolve("assert"),
194
- },
195
- },
196
- }
197
- ```
198
-
199
- ### Component props
200
-
201
- `TextJamEditor` accepts the following props (previously exposed as web-component attributes):
202
-
203
- - `project`: an object with the project data. Contains the following props:
204
- - `project_type`: Possible values `web` | `python`. Default project files will be created according to this value
205
- - `identifier`: A string that represents the project id. If provided, cached project with same id will be loaded
206
- - `author`: an object with owner user data (firstName, lastName, id)
207
- - `components`: an array of project components (files and folders)
208
- - `packageApiUrl`: A string with url to download pyodide packages. If not provided - default value is pyodide CDN.
209
- - `isSharedProject`: a boolean to show a shared project interface instead the regular editor if `true` (`false` by default)
210
- - `isCodeVisible`: a boolean to show or hide the code panel (`true` by default)
211
-
212
- // TODO: review old options below
213
-
214
- - `loadCache`: Load latest version of project code from local storage (defaults to `true`)
215
- - `locale`: Locale for UI elements and to determine the language of projects loaded from the API (defaults to `en`)
216
- - `outputOnly`: Only display the output panel (defaults to `false`)
217
- - `outputPanels`: Array of output panel names to display (defaults to `['text', 'visual']`)
218
- - `outputSplitView`: Start with split view in output panel (defaults to `false`, i.e. tabbed view)
219
- - `projectNameEditable`: Allow the user to edit the project name in the project bar (defaults to `false`)
220
- - `readOnly`: Display the editor in read-only mode (defaults to `false`)
221
- - `sidebarOptions`: Array of strings specifying the panels to be displayed in the sidebar. Options include `"projects"`, `"file"`, `"download"`, `"settings"`.
222
-
223
- 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.
224
-
225
- ### Events and callbacks
226
-
227
- 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:
228
-
229
- - `editor-codeChanged`
230
- - `editor-navigateToProjectsPage`
231
- - `editor-projectOwnerLoaded`
232
- - `editor-runCompleted`
233
- - `editor-runStarted`
234
- - `editor-stepChanged`
235
- - `editor-logIn`
236
- - `editor-signUp`
237
- - `editor-quizReady`
238
- - `editor-themeUpdated`
239
-
240
- 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
+ Publishing is handled by the **"NPM Publish (Scan + Bump + Publish)"** GitHub Actions workflow (`.github/workflows/publish.yml`) — there is no manual `npm publish` step.
95
+
96
+ ### Running the workflow
97
+
98
+ 1. Go to the repo's **Actions** tab → **NPM Publish (Scan + Bump + Publish)** → **Run workflow**.
99
+ 2. Fill in the inputs:
100
+ - `git_branch` — the branch to scan, bump, tag, and publish from (defaults to the current release branch).
101
+ - `version_bump_type` — `patch`, `minor`, or `major`, following [semantic versioning](https://semver.org/).
102
+ - `run_publish` — leave checked to publish to npm, or uncheck for a scan + version-bump dry run.
103
+ 3. Run it. The workflow will:
104
+ - Run the shared dependency, secrets, and SAST scans (`security-scan` → `secrets-scan` → `sast-scan`).
105
+ - Run the test suite (`test`).
106
+ - Bump `package.json`, commit, tag (`vX.Y.Z`), and push to `git_branch` (`bump-version`).
107
+ - Build the library (via the `prepublishOnly` hook) and run `npm publish` (`publish`).
108
+
109
+ Each stage gates the next — if a scan or the test suite fails, the version is never bumped and nothing is published.
110
+
111
+ ### Verify publication
112
+
113
+ ```bash
114
+ npm view gwchq-textjam version
115
+ ```
116
+
117
+ ### What Gets Published
118
+
119
+ The following files are included in the npm package (as defined in `package.json` → `files`):
120
+
121
+ - `dist/` - Built library files
122
+ - `README.md` - This file
123
+ - `LICENSE` - License file
124
+
125
+ ### Package Exports
126
+
127
+ Consumers can import:
128
+
129
+ - Main component: `import { TextJamEditor } from "gwchq-textjam"`
130
+ - Stylesheet: `import "gwchq-textjam/style.css"`
131
+
132
+ # Using the editor as a React component
133
+
134
+ The editor can be imported and rendered directly inside another React application. The package exports the `TextJamEditor` component and `styles.css`:
135
+
136
+ ```tsx
137
+ import { TextJamEditor } from "gwchq-textjam";
138
+ import "gwchq-textjam/style.css";
139
+
140
+ export function EditorWrapper() {
141
+ return (
142
+ <TextJamEditor
143
+ project={{ project_type: "python", identifier: "my-py-app" }}
144
+ />
145
+ );
146
+ }
147
+ ```
148
+
149
+ The consumer's webpack config should include the following setups
150
+
151
+ ```
152
+ {
153
+ ...,
154
+ modules: {
155
+ rules: [
156
+ ...,
157
+ {
158
+ test: /\.map$/,
159
+ type: "asset/resource",
160
+ },
161
+ {
162
+ test: /\.whl$/,
163
+ type: "asset/resource",
164
+ },
165
+ {
166
+ test: /\.glb$/,
167
+ type: "asset/resource",
168
+ },
169
+ ]
170
+ },
171
+ plugins: [
172
+ new CopyWebpackPlugin({
173
+ patterns: [
174
+ ...,
175
+ {
176
+ from: "node_modules/gwchq-textjam/dist/assets",
177
+ to: "assets",
178
+ },
179
+ ],
180
+ }),
181
+ ],
182
+ resolve: {
183
+ extensions: ['.js', '.jsx'],
184
+ alias: {
185
+ 'react': path.resolve(__dirname, 'node_modules/react'),
186
+ 'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
187
+ 'react-redux': path.resolve(__dirname, 'node_modules/react-redux'),
188
+ },
189
+ fallback: {
190
+ stream: require.resolve('stream-browserify'),
191
+ path: require.resolve('path-browserify'),
192
+ util: require.resolve('util/'),
193
+ assert: require.resolve("assert"),
194
+ },
195
+ },
196
+ }
197
+ ```
198
+
199
+ ### Component props
200
+
201
+ `TextJamEditor` accepts the following props (previously exposed as web-component attributes):
202
+
203
+ - `project`: an object with the project data. Contains the following props:
204
+ - `project_type`: Possible values `web` | `python`. Default project files will be created according to this value
205
+ - `identifier`: A string that represents the project id. If provided, cached project with same id will be loaded
206
+ - `author`: an object with owner user data (firstName, lastName, id)
207
+ - `components`: an array of project components (files and folders)
208
+ - `packageApiUrl`: A string with url to download pyodide packages. If not provided - default value is pyodide CDN.
209
+ - `isSharedProject`: a boolean to show a shared project interface instead the regular editor if `true` (`false` by default)
210
+ - `isCodeVisible`: a boolean to show or hide the code panel (`true` by default)
211
+
212
+ // TODO: review old options below
213
+
214
+ - `loadCache`: Load latest version of project code from local storage (defaults to `true`)
215
+ - `locale`: Locale for UI elements and to determine the language of projects loaded from the API (defaults to `en`)
216
+ - `outputOnly`: Only display the output panel (defaults to `false`)
217
+ - `outputPanels`: Array of output panel names to display (defaults to `['text', 'visual']`)
218
+ - `outputSplitView`: Start with split view in output panel (defaults to `false`, i.e. tabbed view)
219
+ - `projectNameEditable`: Allow the user to edit the project name in the project bar (defaults to `false`)
220
+ - `readOnly`: Display the editor in read-only mode (defaults to `false`)
221
+ - `sidebarOptions`: Array of strings specifying the panels to be displayed in the sidebar. Options include `"projects"`, `"file"`, `"download"`, `"settings"`.
222
+
223
+ 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.
224
+
225
+ ### Events and callbacks
226
+
227
+ 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:
228
+
229
+ - `editor-codeChanged`
230
+ - `editor-navigateToProjectsPage`
231
+ - `editor-projectOwnerLoaded`
232
+ - `editor-runCompleted`
233
+ - `editor-runStarted`
234
+ - `editor-stepChanged`
235
+ - `editor-logIn`
236
+ - `editor-signUp`
237
+ - `editor-quizReady`
238
+ - `editor-themeUpdated`
239
+
240
+ These events make it possible for the host page to react to code execution, project changes, authentication requests, and theme updates.