Skip to content

Add default shadow color support to scene color blocks#485

Merged
tracygardner merged 1 commit intomainfrom
claude/fix-color-input-slot-lliQv
Mar 28, 2026
Merged

Add default shadow color support to scene color blocks#485
tracygardner merged 1 commit intomainfrom
claude/fix-color-input-slot-lliQv

Conversation

@tracygardner
Copy link
Copy Markdown
Contributor

@tracygardner tracygardner commented Mar 28, 2026

Summary

Added support for configuring default shadow colors on scene color-like blocks through a new inputColor configuration option.

Key Changes

  • Extended initSceneColourLikeBlock() to accept an optional inputColor property in the configuration object
  • When inputColor is provided, a shadow block with the specified color is automatically created and attached to the block's input connection
  • The shadow block is respawned to ensure it displays correctly in the editor

Implementation Details

  • The shadow DOM is created using Blockly's XML utilities with a colour block type
  • The implementation safely checks for the existence of the input and its connection before attempting to set the shadow
  • This allows blocks to have sensible default colors that appear when no actual block is connected to the input

https://claude.ai/code/session_018BDZmtQcAE2kbxPdRhpLKf

Summary by CodeRabbit

  • New Features
    • Color input blocks now properly initialize with shadow color values when connections are active, improving the visual representation of default colors.

When dragging a colour list out of sky/ground/background blocks, the input
slot was left empty. Now uses setShadowDom to configure a colour shadow so
Blockly automatically respawns it when the connected block is removed.

https://claude.ai/code/session_018BDZmtQcAE2kbxPdRhpLKf
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The initSceneColourLikeBlock function in blocks/scene.js now initializes shadow DOM for color inputs. When an input has a live connection, the function creates a Blockly color shadow node with the color value from cfg.inputColor and forces its regeneration.

Changes

Cohort / File(s) Summary
Color Input Initialization
blocks/scene.js
Added shadow DOM initialization for color inputs in initSceneColourLikeBlock. Creates a <shadow type="colour"> node with the configured color value and regenerates it when the input has an active connection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A color shadow born anew,
Where inputs glow in vibrant hue,
The scene now knows its tinted way,
Shadow blocks dance, hooray, hooray! 🎨✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add default shadow color support to scene color blocks' directly and accurately describes the main change: adding support for default shadow colors to scene color blocks via a new inputColor configuration option.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-color-input-slot-lliQv

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
blocks/scene.js (1)

153-157: Avoid relying on Blockly private API for shadow initialization

Lines 153–157 construct the shadow DOM via string interpolation and call respawnShadow_(), a private-style API. While cfg.inputColor is hardcoded and safe, using Blockly's public DOM construction methods would be more defensive and reduce coupling to internal APIs that may change across versions.

Suggested hardening (optional)
-      const shadowDom = Blockly.utils.xml.textToDom(
-        `<shadow type="colour"><field name="COLOR">${cfg.inputColor}</field></shadow>`,
-      );
+      const shadowDom = Blockly.utils.xml.createElement("shadow");
+      shadowDom.setAttribute("type", "colour");
+      const fieldDom = Blockly.utils.xml.createElement("field");
+      fieldDom.setAttribute("name", "COLOR");
+      fieldDom.textContent = cfg.inputColor;
+      shadowDom.appendChild(fieldDom);
       input.connection.setShadowDom(shadowDom);
-      input.connection.respawnShadow_();
+      if (typeof input.connection.respawnShadow_ === "function") {
+        input.connection.respawnShadow_();
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@blocks/scene.js` around lines 153 - 157, The current code builds shadow
markup via string interpolation with Blockly.utils.xml.textToDom and then calls
the private method input.connection.respawnShadow_(); instead, construct the
shadow element using the public DOM helpers (e.g.,
Blockly.utils.xml.createElement and createTextNode) to create a <shadow
type="colour"> with a <field name="COLOR"> containing cfg.inputColor, pass that
element to input.connection.setShadowDom(shadowDom), remove the call to the
private input.connection.respawnShadow_(), and refresh the UI by calling
input.getSourceBlock().render() (guarding that input.getSourceBlock() exists) so
the shadow appears without relying on private APIs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@blocks/scene.js`:
- Around line 153-157: The current code builds shadow markup via string
interpolation with Blockly.utils.xml.textToDom and then calls the private method
input.connection.respawnShadow_(); instead, construct the shadow element using
the public DOM helpers (e.g., Blockly.utils.xml.createElement and
createTextNode) to create a <shadow type="colour"> with a <field name="COLOR">
containing cfg.inputColor, pass that element to
input.connection.setShadowDom(shadowDom), remove the call to the private
input.connection.respawnShadow_(), and refresh the UI by calling
input.getSourceBlock().render() (guarding that input.getSourceBlock() exists) so
the shadow appears without relying on private APIs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53de0bd4-267e-427a-9115-0936a6adedcd

📥 Commits

Reviewing files that changed from the base of the PR and between 664ca83 and 185dc55.

📒 Files selected for processing (1)
  • blocks/scene.js

@tracygardner tracygardner merged commit 5486e77 into main Mar 28, 2026
9 checks passed
@tracygardner tracygardner deleted the claude/fix-color-input-slot-lliQv branch March 28, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants