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.
Files changed (188) hide show
  1. package/AGENTS.md +76 -24
  2. package/README.md +40 -0
  3. package/dist/main.mjs +1 -1
  4. package/dist/types/src/block_reporting.d.ts.map +1 -1
  5. package/dist/types/src/blocks/procedures.d.ts +2 -2
  6. package/dist/types/src/blocks/procedures.d.ts.map +1 -1
  7. package/dist/types/src/checkable_continuous_flyout.d.ts +6 -3
  8. package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
  9. package/dist/types/src/checkbox_bubble.d.ts +7 -7
  10. package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
  11. package/dist/types/src/colours.d.ts.map +1 -1
  12. package/dist/types/src/context_menu_items.d.ts.map +1 -1
  13. package/dist/types/src/events/events_block_comment_base.d.ts +1 -1
  14. package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
  15. package/dist/types/src/events/events_block_drag_end.d.ts +1 -1
  16. package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
  17. package/dist/types/src/events/events_block_drag_outside.d.ts +1 -1
  18. package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
  19. package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
  20. package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
  21. package/dist/types/src/fields/field_note.d.ts +6 -4
  22. package/dist/types/src/fields/field_note.d.ts.map +1 -1
  23. package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
  24. package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
  25. package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
  26. package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
  27. package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
  28. package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
  29. package/dist/types/src/fields/scratch_field_variable.d.ts +1 -0
  30. package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
  31. package/dist/types/src/flyout_checkbox_icon.d.ts +5 -5
  32. package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
  33. package/dist/types/src/glows.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +1 -0
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/procedures.d.ts +4 -4
  37. package/dist/types/src/procedures.d.ts.map +1 -1
  38. package/dist/types/src/recyclable_block_flyout_inflater.d.ts +2 -2
  39. package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
  40. package/dist/types/src/renderer/cat/cat_face.d.ts +1 -1
  41. package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
  42. package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
  43. package/dist/types/src/renderer/constants.d.ts.map +1 -1
  44. package/dist/types/src/renderer/drawer.d.ts.map +1 -1
  45. package/dist/types/src/renderer/render_info.d.ts.map +1 -1
  46. package/dist/types/src/scratch_blocks_utils.d.ts +22 -0
  47. package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
  48. package/dist/types/src/scratch_c_block_wrap.d.ts +2 -0
  49. package/dist/types/src/scratch_c_block_wrap.d.ts.map +1 -0
  50. package/dist/types/src/scratch_comment_bubble.d.ts +4 -4
  51. package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
  52. package/dist/types/src/scratch_comment_icon.d.ts +1 -1
  53. package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
  54. package/dist/types/src/scratch_continuous_category.d.ts +3 -1
  55. package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
  56. package/dist/types/src/scratch_continuous_toolbox.d.ts +2 -1
  57. package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
  58. package/dist/types/src/status_indicator_label.d.ts +3 -3
  59. package/dist/types/src/status_indicator_label.d.ts.map +1 -1
  60. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
  61. package/dist/types/src/variables.d.ts +1 -1
  62. package/dist/types/src/variables.d.ts.map +1 -1
  63. package/dist/types/src/workspace_block_lookup.d.ts +4 -0
  64. package/dist/types/src/workspace_block_lookup.d.ts.map +1 -0
  65. package/eslint.config.mjs +23 -26
  66. package/package.json +10 -3
  67. package/src/block_reporting.ts +5 -5
  68. package/src/blocks/control.ts +5 -5
  69. package/src/blocks/event.ts +1 -1
  70. package/src/blocks/motion.ts +2 -2
  71. package/src/blocks/procedures.ts +162 -69
  72. package/src/blocks/sensing.ts +0 -1
  73. package/src/blocks/vertical_extensions.ts +11 -8
  74. package/src/checkable_continuous_flyout.ts +45 -12
  75. package/src/checkbox_bubble.ts +7 -7
  76. package/src/colours.ts +4 -2
  77. package/src/context_menu_items.ts +41 -16
  78. package/src/data_category.ts +11 -3
  79. package/src/events/events_block_comment_base.ts +5 -1
  80. package/src/events/events_block_comment_change.ts +5 -1
  81. package/src/events/events_block_comment_collapse.ts +6 -2
  82. package/src/events/events_block_comment_create.ts +5 -1
  83. package/src/events/events_block_comment_move.ts +6 -2
  84. package/src/events/events_block_comment_resize.ts +6 -2
  85. package/src/events/events_block_drag_end.ts +5 -1
  86. package/src/events/events_block_drag_outside.ts +5 -1
  87. package/src/events/events_scratch_variable_create.ts +5 -1
  88. package/src/fields/field_colour_slider.ts +3 -5
  89. package/src/fields/field_matrix.ts +33 -17
  90. package/src/fields/field_note.ts +56 -20
  91. package/src/fields/field_textinput_removable.ts +13 -4
  92. package/src/fields/field_variable_getter.ts +20 -6
  93. package/src/fields/field_vertical_separator.ts +5 -1
  94. package/src/fields/scratch_field_angle.ts +32 -21
  95. package/src/fields/scratch_field_dropdown.ts +6 -2
  96. package/src/fields/scratch_field_number.ts +22 -13
  97. package/src/fields/scratch_field_variable.ts +26 -12
  98. package/src/flyout_checkbox_icon.ts +9 -5
  99. package/src/glows.ts +5 -5
  100. package/src/index.ts +21 -11
  101. package/src/procedures.ts +92 -42
  102. package/src/recyclable_block_flyout_inflater.ts +5 -4
  103. package/src/renderer/cat/cat_face.ts +1 -1
  104. package/src/renderer/cat/drawer.ts +4 -1
  105. package/src/renderer/constants.ts +19 -14
  106. package/src/renderer/drawer.ts +2 -1
  107. package/src/renderer/render_info.ts +12 -9
  108. package/src/renderer/renderer.ts +1 -1
  109. package/src/scratch_blocks_utils.ts +0 -2
  110. package/src/scratch_c_block_wrap.ts +108 -0
  111. package/src/scratch_comment_bubble.ts +30 -19
  112. package/src/scratch_comment_icon.ts +9 -12
  113. package/src/scratch_connection_checker.ts +1 -2
  114. package/src/scratch_continuous_category.ts +20 -11
  115. package/src/scratch_continuous_toolbox.ts +12 -3
  116. package/src/scratch_dragger.ts +2 -2
  117. package/src/scratch_variable_map.ts +1 -1
  118. package/src/status_indicator_label.ts +13 -9
  119. package/src/status_indicator_label_flyout_inflater.ts +2 -1
  120. package/src/variables.ts +21 -14
  121. package/src/workspace_block_lookup.ts +14 -0
  122. package/src/xml.ts +1 -1
  123. package/tsconfig.build.json +4 -0
  124. package/tsconfig.json +1 -1
  125. package/vitest.config.ts +35 -0
  126. package/dist/types/tests/blocks/logic_ternary_test.d.ts +0 -13
  127. package/dist/types/tests/blocks/logic_ternary_test.d.ts.map +0 -1
  128. package/dist/types/tests/jsunit/block_test.d.ts +0 -4
  129. package/dist/types/tests/jsunit/block_test.d.ts.map +0 -1
  130. package/dist/types/tests/jsunit/connection_db_test.d.ts +0 -25
  131. package/dist/types/tests/jsunit/connection_db_test.d.ts.map +0 -1
  132. package/dist/types/tests/jsunit/connection_test.d.ts +0 -39
  133. package/dist/types/tests/jsunit/connection_test.d.ts.map +0 -1
  134. package/dist/types/tests/jsunit/db_test.d.ts +0 -7
  135. package/dist/types/tests/jsunit/db_test.d.ts.map +0 -1
  136. package/dist/types/tests/jsunit/event_test.d.ts +0 -76
  137. package/dist/types/tests/jsunit/event_test.d.ts.map +0 -1
  138. package/dist/types/tests/jsunit/extensions_test.d.ts +0 -18
  139. package/dist/types/tests/jsunit/extensions_test.d.ts.map +0 -1
  140. package/dist/types/tests/jsunit/field_angle_test.d.ts +0 -3
  141. package/dist/types/tests/jsunit/field_angle_test.d.ts.map +0 -1
  142. package/dist/types/tests/jsunit/field_number_test.d.ts +0 -3
  143. package/dist/types/tests/jsunit/field_number_test.d.ts.map +0 -1
  144. package/dist/types/tests/jsunit/field_test.d.ts +0 -8
  145. package/dist/types/tests/jsunit/field_test.d.ts.map +0 -1
  146. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts +0 -5
  147. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +0 -1
  148. package/dist/types/tests/jsunit/field_variable_test.d.ts +0 -19
  149. package/dist/types/tests/jsunit/field_variable_test.d.ts.map +0 -1
  150. package/dist/types/tests/jsunit/generator_test.d.ts +0 -2
  151. package/dist/types/tests/jsunit/generator_test.d.ts.map +0 -1
  152. package/dist/types/tests/jsunit/gesture_test.d.ts +0 -10
  153. package/dist/types/tests/jsunit/gesture_test.d.ts.map +0 -1
  154. package/dist/types/tests/jsunit/input_test.d.ts +0 -9
  155. package/dist/types/tests/jsunit/input_test.d.ts.map +0 -1
  156. package/dist/types/tests/jsunit/json_test.d.ts +0 -11
  157. package/dist/types/tests/jsunit/json_test.d.ts.map +0 -1
  158. package/dist/types/tests/jsunit/names_test.d.ts +0 -5
  159. package/dist/types/tests/jsunit/names_test.d.ts.map +0 -1
  160. package/dist/types/tests/jsunit/procedure_test.d.ts +0 -15
  161. package/dist/types/tests/jsunit/procedure_test.d.ts.map +0 -1
  162. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts +0 -14
  163. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +0 -1
  164. package/dist/types/tests/jsunit/svg_test.d.ts +0 -14
  165. package/dist/types/tests/jsunit/svg_test.d.ts.map +0 -1
  166. package/dist/types/tests/jsunit/test_runner.d.ts +0 -2
  167. package/dist/types/tests/jsunit/test_runner.d.ts.map +0 -1
  168. package/dist/types/tests/jsunit/test_utilities.d.ts +0 -50
  169. package/dist/types/tests/jsunit/test_utilities.d.ts.map +0 -1
  170. package/dist/types/tests/jsunit/utils_test.d.ts +0 -10
  171. package/dist/types/tests/jsunit/utils_test.d.ts.map +0 -1
  172. package/dist/types/tests/jsunit/variable_map_test.d.ts +0 -28
  173. package/dist/types/tests/jsunit/variable_map_test.d.ts.map +0 -1
  174. package/dist/types/tests/jsunit/variable_model_test.d.ts +0 -14
  175. package/dist/types/tests/jsunit/variable_model_test.d.ts.map +0 -1
  176. package/dist/types/tests/jsunit/widget_div_test.d.ts +0 -37
  177. package/dist/types/tests/jsunit/widget_div_test.d.ts.map +0 -1
  178. package/dist/types/tests/jsunit/workspace_comment_test.d.ts +0 -13
  179. package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +0 -1
  180. package/dist/types/tests/jsunit/workspace_test.d.ts +0 -22
  181. package/dist/types/tests/jsunit/workspace_test.d.ts.map +0 -1
  182. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts +0 -33
  183. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +0 -1
  184. package/dist/types/tests/jsunit/xml_test.d.ts +0 -55
  185. package/dist/types/tests/jsunit/xml_test.d.ts.map +0 -1
  186. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts +0 -12
  187. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +0 -1
  188. 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. Run `npm run test:lint` after meaningful code changes.
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 # Compile TypeScript and bundle with webpack → dist/main.mjs
27
- npm run test:lint # Run ESLint
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
- ### When using non-null assertions (`!`)
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
- Use sparingly and only when you genuinely know — in a way the compiler cannot prove that a value is not null or
95
- undefined. Prefer type guards (`if (!x) return`), optional chaining (`?.`), or nullish coalescing (`??`) instead. The
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
- Before adding a new `!`, quickly check these alternatives:
147
+ ### Loop style
99
148
 
100
- - Can you narrow once and reuse a local (`const x = ...; if (!x) return;`)?
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
- Prefer narrowing once and reusing a local variable over repeating assertions at each use site.
151
+ ### Unused values
106
152
 
107
- ### When using type assertions (`as`)
153
+ Keep `no-unused-vars` enabled. Preferred handling:
108
154
 
109
- Rely on TypeScript's inference and explicit type annotations first. Use `as SomeType` only when necessary (e.g., when
110
- narrowing a union that inference can't resolve). Treat `as unknown as Type` as a last resort, and add a comment
111
- explaining why it is both necessary and safe.
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
- - Confirm changes are confined to requested scope.
137
- - Confirm no edits were made under `node_modules/blockly/`.
138
- - If you added runtime checks for states that should never happen (especially early-outs), confirm diagnostics were
139
- added where appropriate.
140
- - Run `npm run test:lint`.
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