Add default shadow color support to scene color blocks#485
Conversation
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
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
blocks/scene.js (1)
153-157: Avoid relying on Blockly private API for shadow initializationLines 153–157 construct the shadow DOM via string interpolation and call
respawnShadow_(), a private-style API. Whilecfg.inputColoris 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.
Summary
Added support for configuring default shadow colors on scene color-like blocks through a new
inputColorconfiguration option.Key Changes
initSceneColourLikeBlock()to accept an optionalinputColorproperty in the configuration objectinputColoris provided, a shadow block with the specified color is automatically created and attached to the block's input connectionImplementation Details
colourblock typehttps://claude.ai/code/session_018BDZmtQcAE2kbxPdRhpLKf
Summary by CodeRabbit