scratch-blocks 2.1.5 → 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 +58 -14
- 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/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_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 +21 -28
- package/package.json +1 -1
- 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 +18 -6
- 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 +37 -21
- package/src/scratch_comment_bubble.ts +30 -19
- package/src/scratch_comment_icon.ts +9 -12
- 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/types/continuous-toolbox.d.ts +0 -1
package/AGENTS.md
CHANGED
|
@@ -92,26 +92,69 @@ When adding runtime checks for states that should never happen (including guard-
|
|
|
92
92
|
|
|
93
93
|
## TypeScript guidelines
|
|
94
94
|
|
|
95
|
-
###
|
|
95
|
+
### Avoid `any`
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
100
|
|
|
101
|
-
|
|
101
|
+
### Non-null assertions (`!`)
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
- Can the type carry the uncertainty directly (`prop?: T`, `T | null`) and be assigned conditionally?
|
|
105
|
-
- Can you use optional chaining for best-effort UI updates (`node?.setAttribute(...)`)?
|
|
106
|
-
- If data is required (e.g., mutation XML attrs), can you validate and fail clearly instead of asserting?
|
|
103
|
+
Do not use `!` unless you genuinely know — in a way the compiler cannot prove — that a value is non-null. Prefer:
|
|
107
104
|
|
|
108
|
-
|
|
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`
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
If data is required (e.g., deserialized event fields), validate and fail with a logged error rather than asserting.
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
143
|
+
|
|
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.
|
|
146
|
+
|
|
147
|
+
### Loop style
|
|
148
|
+
|
|
149
|
+
Prefer `for...of` over index-based `for` loops when the index is not needed.
|
|
150
|
+
|
|
151
|
+
### Unused values
|
|
152
|
+
|
|
153
|
+
Keep `no-unused-vars` enabled. Preferred handling:
|
|
154
|
+
|
|
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.
|
|
115
158
|
|
|
116
159
|
## Common patterns
|
|
117
160
|
|
|
@@ -144,5 +187,6 @@ Review all changes and confirm:
|
|
|
144
187
|
- **Simplicity**: Implementation is as simple as possible; no unnecessary code remains.
|
|
145
188
|
- **`node_modules/`**: No changes within this directory. In particular, no direct edits to Blockly source files.
|
|
146
189
|
- **Runtime checks**: Any new guards for states that should never happen include diagnostic logging.
|
|
190
|
+
- **Build passes**: `npm run build` completes successfully.
|
|
147
191
|
- **Tests pass**: `npm run test` completes with no failures.
|
|
148
192
|
- **No lint errors**: `npm run test:lint` passes. Iterate with `npm run format` and/or manual changes as needed.
|