scratch-blocks 2.0.6 → 2.0.8

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.
@@ -11,4 +11,14 @@ export declare function registerDeleteAll(): void;
11
11
  * all subsequent blocks in the stack.
12
12
  */
13
13
  export declare function registerDuplicateBlock(): void;
14
+ /**
15
+ * Overrides the copy keyboard shortcut so that it includes subsequent blocks
16
+ * in the stack (via the next connection) when copying a block.
17
+ */
18
+ export declare function registerCopyShortcut(): void;
19
+ /**
20
+ * Overrides the cut keyboard shortcut so that it includes subsequent blocks
21
+ * in the stack (via the next connection) when cutting a block.
22
+ */
23
+ export declare function registerCutShortcut(): void;
14
24
  //# sourceMappingURL=context_menu_items.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context_menu_items.d.ts","sourceRoot":"","sources":["../../../src/context_menu_items.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,mBAAmB,SAwBlC;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,SA2ChC;AAsCD;;;GAGG;AACH,wBAAgB,sBAAsB,SAiBrC"}
1
+ {"version":3,"file":"context_menu_items.d.ts","sourceRoot":"","sources":["../../../src/context_menu_items.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,mBAAmB,SAwBlC;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,SA2ChC;AAsCD;;;GAGG;AACH,wBAAgB,sBAAsB,SAiBrC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,SAuBnC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,SAwBlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scratch-blocks",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "Scratch Blocks is a library for building creative computing interfaces.",
5
5
  "author": "Massachusetts Institute of Technology",
6
6
  "license": "Apache-2.0",
@@ -153,3 +153,62 @@ export function registerDuplicateBlock() {
153
153
  Blockly.ContextMenuRegistry.registry.unregister(duplicateOption.id)
154
154
  Blockly.ContextMenuRegistry.registry.register(duplicateOption)
155
155
  }
156
+
157
+ /**
158
+ * Overrides the copy keyboard shortcut so that it includes subsequent blocks
159
+ * in the stack (via the next connection) when copying a block.
160
+ */
161
+ export function registerCopyShortcut() {
162
+ const original = Blockly.ShortcutRegistry.registry.getRegistry()[Blockly.ShortcutItems.names.COPY]
163
+ Blockly.ShortcutRegistry.registry.register(
164
+ {
165
+ ...original,
166
+ allowCollision: true, // we're intentionally overriding the default handler
167
+ callback(workspace, e, shortcut, scope) {
168
+ const focused = scope.focusedNode
169
+ if (focused instanceof Blockly.BlockSvg && !focused.isInFlyout) {
170
+ e.preventDefault()
171
+ const copyData = focused.toCopyData(true)
172
+ if (copyData) {
173
+ Blockly.clipboard.setLastCopiedData(copyData)
174
+ Blockly.clipboard.setLastCopiedWorkspace(focused.workspace)
175
+ Blockly.clipboard.setLastCopiedLocation(focused.getRelativeToSurfaceXY())
176
+ return true
177
+ }
178
+ }
179
+ return original.callback?.(workspace, e, shortcut, scope) ?? false
180
+ },
181
+ },
182
+ true, // allowOverrides: we're intentionally overriding the default handler
183
+ )
184
+ }
185
+
186
+ /**
187
+ * Overrides the cut keyboard shortcut so that it includes subsequent blocks
188
+ * in the stack (via the next connection) when cutting a block.
189
+ */
190
+ export function registerCutShortcut() {
191
+ const original = Blockly.ShortcutRegistry.registry.getRegistry()[Blockly.ShortcutItems.names.CUT]
192
+ Blockly.ShortcutRegistry.registry.register(
193
+ {
194
+ ...original,
195
+ allowCollision: true, // we're intentionally overriding the default handler
196
+ callback(workspace, e, shortcut, scope) {
197
+ const focused = scope.focusedNode
198
+ if (focused instanceof Blockly.BlockSvg && !focused.isInFlyout) {
199
+ e.preventDefault()
200
+ const copyData = focused.toCopyData(true)
201
+ if (copyData && focused.isDeletable()) {
202
+ Blockly.clipboard.setLastCopiedData(copyData)
203
+ Blockly.clipboard.setLastCopiedWorkspace(focused.workspace)
204
+ Blockly.clipboard.setLastCopiedLocation(focused.getRelativeToSurfaceXY())
205
+ focused.checkAndDelete()
206
+ return true
207
+ }
208
+ }
209
+ return original.callback?.(workspace, e, shortcut, scope) ?? false
210
+ },
211
+ },
212
+ true, // allowOverrides: we're intentionally overriding the default handler
213
+ )
214
+ }
package/src/index.ts CHANGED
@@ -154,6 +154,8 @@ Blockly.ContextMenuItems.registerCommentOptions()
154
154
  Blockly.ContextMenuRegistry.registry.unregister('blockDelete')
155
155
  contextMenuItems.registerDeleteBlock()
156
156
  contextMenuItems.registerDuplicateBlock()
157
+ contextMenuItems.registerCopyShortcut()
158
+ contextMenuItems.registerCutShortcut()
157
159
  Blockly.ContextMenuRegistry.registry.unregister('workspaceDelete')
158
160
  contextMenuItems.registerDeleteAll()
159
161
  Blockly.comments.CommentView.defaultCommentSize = new Blockly.utils.Size(200, 200)