scratch-blocks 2.1.4 → 2.1.6
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/AGENTS.md +76 -24
- package/README.md +40 -0
- package/dist/main.mjs +1 -1
- package/dist/types/src/block_reporting.d.ts.map +1 -1
- package/dist/types/src/blocks/procedures.d.ts +2 -2
- package/dist/types/src/blocks/procedures.d.ts.map +1 -1
- package/dist/types/src/checkable_continuous_flyout.d.ts +6 -3
- package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
- package/dist/types/src/checkbox_bubble.d.ts +7 -7
- package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
- package/dist/types/src/colours.d.ts.map +1 -1
- package/dist/types/src/context_menu_items.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
- package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
- package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
- package/dist/types/src/fields/field_note.d.ts +6 -4
- package/dist/types/src/fields/field_note.d.ts.map +1 -1
- package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
- package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
- package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts +1 -0
- package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
- package/dist/types/src/flyout_checkbox_icon.d.ts +5 -5
- package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
- package/dist/types/src/glows.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/procedures.d.ts +4 -4
- package/dist/types/src/procedures.d.ts.map +1 -1
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts +2 -2
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/render_info.d.ts.map +1 -1
- package/dist/types/src/scratch_blocks_utils.d.ts +22 -0
- package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
- package/dist/types/src/scratch_c_block_wrap.d.ts +2 -0
- package/dist/types/src/scratch_c_block_wrap.d.ts.map +1 -0
- package/dist/types/src/scratch_comment_bubble.d.ts +4 -4
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_category.d.ts +3 -1
- package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_toolbox.d.ts +2 -1
- package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label.d.ts +3 -3
- package/dist/types/src/status_indicator_label.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/variables.d.ts +1 -1
- package/dist/types/src/variables.d.ts.map +1 -1
- package/dist/types/src/workspace_block_lookup.d.ts +4 -0
- package/dist/types/src/workspace_block_lookup.d.ts.map +1 -0
- package/eslint.config.mjs +23 -26
- package/package.json +10 -3
- package/src/block_reporting.ts +5 -5
- package/src/blocks/control.ts +5 -5
- package/src/blocks/event.ts +1 -1
- package/src/blocks/motion.ts +2 -2
- package/src/blocks/procedures.ts +162 -69
- package/src/blocks/sensing.ts +0 -1
- package/src/blocks/vertical_extensions.ts +11 -8
- package/src/checkable_continuous_flyout.ts +45 -12
- package/src/checkbox_bubble.ts +7 -7
- package/src/colours.ts +4 -2
- package/src/context_menu_items.ts +41 -16
- package/src/data_category.ts +11 -3
- package/src/events/events_block_comment_base.ts +5 -1
- package/src/events/events_block_comment_change.ts +5 -1
- package/src/events/events_block_comment_collapse.ts +6 -2
- package/src/events/events_block_comment_create.ts +5 -1
- package/src/events/events_block_comment_move.ts +6 -2
- package/src/events/events_block_comment_resize.ts +6 -2
- package/src/events/events_block_drag_end.ts +5 -1
- package/src/events/events_block_drag_outside.ts +5 -1
- package/src/events/events_scratch_variable_create.ts +5 -1
- package/src/fields/field_colour_slider.ts +3 -5
- package/src/fields/field_matrix.ts +33 -17
- package/src/fields/field_note.ts +56 -20
- package/src/fields/field_textinput_removable.ts +13 -4
- package/src/fields/field_variable_getter.ts +20 -6
- package/src/fields/field_vertical_separator.ts +5 -1
- package/src/fields/scratch_field_angle.ts +32 -21
- package/src/fields/scratch_field_dropdown.ts +6 -2
- package/src/fields/scratch_field_number.ts +22 -13
- package/src/fields/scratch_field_variable.ts +26 -12
- package/src/flyout_checkbox_icon.ts +9 -5
- package/src/glows.ts +5 -5
- package/src/index.ts +21 -11
- package/src/procedures.ts +92 -42
- package/src/recyclable_block_flyout_inflater.ts +5 -4
- package/src/renderer/cat/cat_face.ts +1 -1
- package/src/renderer/cat/drawer.ts +4 -1
- package/src/renderer/constants.ts +19 -14
- package/src/renderer/drawer.ts +2 -1
- package/src/renderer/render_info.ts +12 -9
- package/src/renderer/renderer.ts +1 -1
- package/src/scratch_blocks_utils.ts +0 -2
- package/src/scratch_c_block_wrap.ts +108 -0
- package/src/scratch_comment_bubble.ts +30 -19
- package/src/scratch_comment_icon.ts +9 -12
- package/src/scratch_connection_checker.ts +1 -2
- package/src/scratch_continuous_category.ts +20 -11
- package/src/scratch_continuous_toolbox.ts +12 -3
- package/src/scratch_dragger.ts +2 -2
- package/src/scratch_variable_map.ts +1 -1
- package/src/status_indicator_label.ts +13 -9
- package/src/status_indicator_label_flyout_inflater.ts +2 -1
- package/src/variables.ts +21 -14
- package/src/workspace_block_lookup.ts +14 -0
- package/src/xml.ts +1 -1
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +35 -0
- package/dist/types/tests/blocks/logic_ternary_test.d.ts +0 -13
- package/dist/types/tests/blocks/logic_ternary_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/block_test.d.ts +0 -4
- package/dist/types/tests/jsunit/block_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/connection_db_test.d.ts +0 -25
- package/dist/types/tests/jsunit/connection_db_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/connection_test.d.ts +0 -39
- package/dist/types/tests/jsunit/connection_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/db_test.d.ts +0 -7
- package/dist/types/tests/jsunit/db_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/event_test.d.ts +0 -76
- package/dist/types/tests/jsunit/event_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/extensions_test.d.ts +0 -18
- package/dist/types/tests/jsunit/extensions_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/field_angle_test.d.ts +0 -3
- package/dist/types/tests/jsunit/field_angle_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/field_number_test.d.ts +0 -3
- package/dist/types/tests/jsunit/field_number_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/field_test.d.ts +0 -8
- package/dist/types/tests/jsunit/field_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/field_variable_getter_test.d.ts +0 -5
- package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/field_variable_test.d.ts +0 -19
- package/dist/types/tests/jsunit/field_variable_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/generator_test.d.ts +0 -2
- package/dist/types/tests/jsunit/generator_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/gesture_test.d.ts +0 -10
- package/dist/types/tests/jsunit/gesture_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/input_test.d.ts +0 -9
- package/dist/types/tests/jsunit/input_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/json_test.d.ts +0 -11
- package/dist/types/tests/jsunit/json_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/names_test.d.ts +0 -5
- package/dist/types/tests/jsunit/names_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/procedure_test.d.ts +0 -15
- package/dist/types/tests/jsunit/procedure_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts +0 -14
- package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/svg_test.d.ts +0 -14
- package/dist/types/tests/jsunit/svg_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/test_runner.d.ts +0 -2
- package/dist/types/tests/jsunit/test_runner.d.ts.map +0 -1
- package/dist/types/tests/jsunit/test_utilities.d.ts +0 -50
- package/dist/types/tests/jsunit/test_utilities.d.ts.map +0 -1
- package/dist/types/tests/jsunit/utils_test.d.ts +0 -10
- package/dist/types/tests/jsunit/utils_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/variable_map_test.d.ts +0 -28
- package/dist/types/tests/jsunit/variable_map_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/variable_model_test.d.ts +0 -14
- package/dist/types/tests/jsunit/variable_model_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/widget_div_test.d.ts +0 -37
- package/dist/types/tests/jsunit/widget_div_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/workspace_comment_test.d.ts +0 -13
- package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/workspace_test.d.ts +0 -22
- package/dist/types/tests/jsunit/workspace_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts +0 -33
- package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +0 -1
- package/dist/types/tests/jsunit/xml_test.d.ts +0 -55
- package/dist/types/tests/jsunit/xml_test.d.ts.map +0 -1
- package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts +0 -12
- package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +0 -1
- package/types/continuous-toolbox.d.ts +0 -1
package/AGENTS.md
CHANGED
|
@@ -9,7 +9,8 @@ Use these defaults unless the user asks otherwise:
|
|
|
9
9
|
3. Never edit `node_modules/blockly/`; extend/override from `src/` instead.
|
|
10
10
|
4. When adding runtime guards for states that should never happen, log actionable context unless the path is expected
|
|
11
11
|
control flow.
|
|
12
|
-
5.
|
|
12
|
+
5. When fixing a bug, start by adding one or more tests to reproduce the issue, then implement the fix. Iterate until
|
|
13
|
+
all tests pass, including but not limited to the new tests.
|
|
13
14
|
|
|
14
15
|
## What this repository is
|
|
15
16
|
|
|
@@ -23,12 +24,14 @@ palette and workspace.
|
|
|
23
24
|
## Build and lint
|
|
24
25
|
|
|
25
26
|
```sh
|
|
26
|
-
npm run build
|
|
27
|
-
npm run
|
|
27
|
+
npm run build # Compile TypeScript and bundle with webpack → dist/main.mjs
|
|
28
|
+
npm run format # Auto-format code
|
|
29
|
+
npm run test:lint # Check for lint and formatting issues (does not run other tests)
|
|
30
|
+
npm run test # Run unit and browser tests (but not lint)
|
|
31
|
+
npm run test:unit # Run unit tests only
|
|
32
|
+
npm run test:browser # Run browser tests only
|
|
28
33
|
```
|
|
29
34
|
|
|
30
|
-
There are test files under `tests/` but no `npm test` script is wired up yet.
|
|
31
|
-
|
|
32
35
|
## Repository layout
|
|
33
36
|
|
|
34
37
|
```text
|
|
@@ -89,26 +92,69 @@ When adding runtime checks for states that should never happen (including guard-
|
|
|
89
92
|
|
|
90
93
|
## TypeScript guidelines
|
|
91
94
|
|
|
92
|
-
###
|
|
95
|
+
### Avoid `any`
|
|
96
|
+
|
|
97
|
+
Do not use `any` as a type annotation. Prefer proper types, `unknown`, or a union. When calling into Blockly APIs
|
|
98
|
+
that have weak types, add a local cast (`as ConcreteType`) with a comment explaining the narrowing rather than
|
|
99
|
+
propagating `any` throughout the caller.
|
|
100
|
+
|
|
101
|
+
### Non-null assertions (`!`)
|
|
102
|
+
|
|
103
|
+
Do not use `!` unless you genuinely know — in a way the compiler cannot prove — that a value is non-null. Prefer:
|
|
104
|
+
|
|
105
|
+
- A type guard with early return: `if (!x) return;`
|
|
106
|
+
- Optional chaining for best-effort reads: `node?.getAttribute(...)`
|
|
107
|
+
- Nullish coalescing for fallbacks: `value ?? default`
|
|
108
|
+
|
|
109
|
+
If data is required (e.g., deserialized event fields), validate and fail with a logged error rather than asserting.
|
|
110
|
+
|
|
111
|
+
Prefer narrowing once into a local variable over repeating `!` at each use site.
|
|
112
|
+
|
|
113
|
+
#### Removing non-null assertions
|
|
114
|
+
|
|
115
|
+
When replacing `!` due to linting, preserve the fail-fast behavior. If code would have crashed on
|
|
116
|
+
`maybeNull.property`, replace with explicit validation that throws, not silent degradation:
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
// ❌ BAD: Silently masks an error that would have been loud before
|
|
120
|
+
const badResult = maybeElement?.property ?? fallback
|
|
121
|
+
|
|
122
|
+
// ✅ GOOD: Turns a generic crash into a specific, actionable error with context
|
|
123
|
+
if (!maybeElement) throw new Error('Missing required element')
|
|
124
|
+
const goodResult = maybeElement.property
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Only use graceful degradation (`if (!x) return`) when the situation genuinely warrants it (e.g., optional UI
|
|
128
|
+
updates). For required data (configuration, mutations, required relationships), preserve the crash behavior with an
|
|
129
|
+
explicit error.
|
|
130
|
+
|
|
131
|
+
### Type assertions (`as`)
|
|
132
|
+
|
|
133
|
+
Rely on TypeScript's inference and explicit annotations first. Use `as SomeType` only when necessary (e.g., narrowing
|
|
134
|
+
a union inference can't resolve). Treat `as unknown as Type` as a last resort; add a comment explaining why it is
|
|
135
|
+
both necessary and safe.
|
|
136
|
+
|
|
137
|
+
### Nullish coalescing and optional chaining
|
|
138
|
+
|
|
139
|
+
Prefer `??` over `|| default` for null/undefined fallbacks, and `?.` over `x && x.y` for optional member access.
|
|
140
|
+
Both are safer (they don't coerce falsy values) and trigger lint errors if the left-hand side is provably non-null.
|
|
141
|
+
|
|
142
|
+
### Promises
|
|
93
143
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`!` operator silences the compiler without adding any runtime safety, so a misplaced one becomes a runtime crash.
|
|
144
|
+
Do not leave promises floating. Either `await` the result, return it, or prefix with `void` to explicitly discard it.
|
|
145
|
+
Unhandled promise rejections are silent failures.
|
|
97
146
|
|
|
98
|
-
|
|
147
|
+
### Loop style
|
|
99
148
|
|
|
100
|
-
|
|
101
|
-
- Can the type carry the uncertainty directly (`prop?: T`, `T | null`) and be assigned conditionally?
|
|
102
|
-
- Can you use optional chaining for best-effort UI updates (`node?.setAttribute(...)`)?
|
|
103
|
-
- If data is required (e.g., mutation XML attrs), can you validate and fail clearly instead of asserting?
|
|
149
|
+
Prefer `for...of` over index-based `for` loops when the index is not needed.
|
|
104
150
|
|
|
105
|
-
|
|
151
|
+
### Unused values
|
|
106
152
|
|
|
107
|
-
|
|
153
|
+
Keep `no-unused-vars` enabled. Preferred handling:
|
|
108
154
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
155
|
+
- Remove dead locals/imports when possible.
|
|
156
|
+
- For intentionally unused function parameters, prefix with `_` (e.g. `_event`).
|
|
157
|
+
- For required locals in no-op/interface-conformance paths, use `void value` to mark the discard explicitly.
|
|
112
158
|
|
|
113
159
|
## Common patterns
|
|
114
160
|
|
|
@@ -133,8 +179,14 @@ explaining why it is both necessary and safe.
|
|
|
133
179
|
|
|
134
180
|
## Before submitting changes
|
|
135
181
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
-
|
|
139
|
-
|
|
140
|
-
-
|
|
182
|
+
Review all changes and confirm:
|
|
183
|
+
|
|
184
|
+
- **Scope**: Changes are confined to the user request; nothing extra was added or modified.
|
|
185
|
+
- **Correctness**: Changes make sense and edge cases were considered.
|
|
186
|
+
- **Comments**: Comments are necessary, short, and clear; self-explanatory code has no comment.
|
|
187
|
+
- **Simplicity**: Implementation is as simple as possible; no unnecessary code remains.
|
|
188
|
+
- **`node_modules/`**: No changes within this directory. In particular, no direct edits to Blockly source files.
|
|
189
|
+
- **Runtime checks**: Any new guards for states that should never happen include diagnostic logging.
|
|
190
|
+
- **Build passes**: `npm run build` completes successfully.
|
|
191
|
+
- **Tests pass**: `npm run test` completes with no failures.
|
|
192
|
+
- **No lint errors**: `npm run test:lint` passes. Iterate with `npm run format` and/or manual changes as needed.
|
package/README.md
CHANGED
|
@@ -40,6 +40,46 @@ We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep i
|
|
|
40
40
|
[donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community,
|
|
41
41
|
and resource development efforts. Donations of any size are appreciated. Thank you!
|
|
42
42
|
|
|
43
|
+
## Development
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm ci
|
|
47
|
+
npm run build
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Testing
|
|
51
|
+
|
|
52
|
+
Unit tests run in jsdom and need no additional setup:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm run test:unit
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Browser tests run in Chromium via Playwright. Install the browser once after `npm ci`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx playwright install chromium
|
|
62
|
+
npm run test:browser
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To run all tests:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm test
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
To debug a failing browser test with a visible browser window:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm run test:browser -- --browser.headless=false
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
or, to also pause on startup and open devtools:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
PWDEBUG=1 npm run test:browser
|
|
81
|
+
```
|
|
82
|
+
|
|
43
83
|
## Committing
|
|
44
84
|
|
|
45
85
|
This project uses [semantic release](https://github.com/semantic-release/semantic-release) to ensure version bumps
|