diff --git a/pxtblocks/help.ts b/pxtblocks/help.ts index fed942979d55..21dd47582161 100644 --- a/pxtblocks/help.ts +++ b/pxtblocks/help.ts @@ -5,7 +5,7 @@ import * as Blockly from "blockly"; import { cleanOuterHTML, getFirstChildWithAttr } from "./xml"; import { promptTranslateBlock } from "./external"; import { createToolboxBlock } from "./toolbox"; -import { DuplicateOnDragStrategy } from "./plugins/duplicateOnDrag"; +import { DuplicateOnDragStrategy, setDuplicateOnDragStrategy } from "./plugins/duplicateOnDrag"; export function setBuiltinHelpInfo(block: any, id: string) { const info = pxt.blocks.getBlockDefinition(id); @@ -23,7 +23,7 @@ export function setHelpResources(block: Blockly.BlockSvg, id: string, name: stri if (colour) block.setColour(colour); if (undeletable) block.setDeletable(false); - block.setDragStrategy(new DuplicateOnDragStrategy(block)); + setDuplicateOnDragStrategy(block); let tb = document.getElementById('blocklyToolboxDefinition'); let xml: HTMLElement = tb ? getFirstChildWithAttr(tb, "block", "type", id) as HTMLElement : undefined; diff --git a/pxtblocks/loader.ts b/pxtblocks/loader.ts index 71aaa3543bd0..1f9da7053821 100644 --- a/pxtblocks/loader.ts +++ b/pxtblocks/loader.ts @@ -25,7 +25,7 @@ import { initContextMenu } from "./contextMenu"; import { renderCodeCard } from "./codecardRenderer"; import { applyMonkeyPatches } from "./monkeyPatches"; import { FieldDropdown } from "./fields/field_dropdown"; -import { DuplicateOnDragStrategy, setDraggableShadowBlocks } from "./plugins/duplicateOnDrag"; +import { setDraggableShadowBlocks, setDuplicateOnDragStrategy } from "./plugins/duplicateOnDrag"; interface BlockDefinition { @@ -217,9 +217,7 @@ function initBlock(block: Blockly.Block, info: pxtc.BlocksInfo, fn: pxtc.SymbolI const helpUrl = pxt.blocks.getHelpUrl(fn); if (helpUrl) block.setHelpUrl(helpUrl) - if ((block as Blockly.BlockSvg).setDragStrategy) { - (block as Blockly.BlockSvg).setDragStrategy(new DuplicateOnDragStrategy(block as Blockly.BlockSvg)); - } + setDuplicateOnDragStrategy(block); block.setColour(typeof color === "string" ? pxt.toolbox.getAccessibleBackground(color) : color); let blockShape = provider.SHAPES.ROUND; diff --git a/pxtblocks/plugins/duplicateOnDrag/dragStrategy.ts b/pxtblocks/plugins/duplicateOnDrag/dragStrategy.ts index 58910104b7fb..49702d336376 100644 --- a/pxtblocks/plugins/duplicateOnDrag/dragStrategy.ts +++ b/pxtblocks/plugins/duplicateOnDrag/dragStrategy.ts @@ -468,3 +468,8 @@ export class DuplicateOnDragStrategy implements Blockly.IDragStrategy { this.dragging = false; } } + + +export function setDuplicateOnDragStrategy(block: Blockly.Block | Blockly.BlockSvg) { + (block as Blockly.BlockSvg).setDragStrategy?.(new DuplicateOnDragStrategy(block as Blockly.BlockSvg)); +} \ No newline at end of file diff --git a/pxtblocks/plugins/functions/blocks/argumentReporterBlocks.ts b/pxtblocks/plugins/functions/blocks/argumentReporterBlocks.ts index fa6ff4b54633..37c2d3b2a286 100644 --- a/pxtblocks/plugins/functions/blocks/argumentReporterBlocks.ts +++ b/pxtblocks/plugins/functions/blocks/argumentReporterBlocks.ts @@ -7,7 +7,7 @@ import { ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE, } from "../constants"; import { MsgKey } from "../msg"; -import { DUPLICATE_ON_DRAG_MUTATION_KEY, DuplicateOnDragStrategy } from "../../duplicateOnDrag"; +import { DUPLICATE_ON_DRAG_MUTATION_KEY, DuplicateOnDragStrategy, setDuplicateOnDragStrategy } from "../../duplicateOnDrag"; import { PathObject } from "../../renderer/pathObject"; type ArgumentReporterMixinType = typeof ARGUMENT_REPORTER_MIXIN; @@ -57,7 +57,7 @@ Blockly.Blocks[ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE] = { extensions: ["output_boolean"], }); this.typeName_ = "boolean"; - this.setDragStrategy(new DuplicateOnDragStrategy(this)); + setDuplicateOnDragStrategy(this); }, }; @@ -77,7 +77,7 @@ Blockly.Blocks[ARGUMENT_REPORTER_STRING_BLOCK_TYPE] = { extensions: ["output_string"], }); this.typeName_ = "string"; - this.setDragStrategy(new DuplicateOnDragStrategy(this)); + setDuplicateOnDragStrategy(this); }, }; @@ -97,7 +97,7 @@ Blockly.Blocks[ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE] = { extensions: ["output_number"], }); this.typeName_ = "number"; - this.setDragStrategy(new DuplicateOnDragStrategy(this)); + setDuplicateOnDragStrategy(this); }, }; @@ -117,7 +117,7 @@ Blockly.Blocks[ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE] = { extensions: ["output_array"], }); this.typeName_ = "Array"; - this.setDragStrategy(new DuplicateOnDragStrategy(this)); + setDuplicateOnDragStrategy(this); }, }; @@ -139,7 +139,7 @@ Blockly.Blocks[ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE] = { output: null, }); this.typeName_ = ""; - this.setDragStrategy(new DuplicateOnDragStrategy(this)); + setDuplicateOnDragStrategy(this); }, mutationToDom(this: ArgumentReporterBlock) {