Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.6: Upgrade to Blockly v10 #13

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18,782 changes: 3,707 additions & 15,075 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mit-app-inventor/blockly-plugin-workspace-multiselect",
"version": "0.1.5",
"version": "0.1.6",
"description": "A Blockly plugin that allows to drag, select and doing actions on multiple blocks in the workspace.",
"scripts": {
"audit:fix": "blockly-scripts auditFix",
Expand Down Expand Up @@ -39,15 +39,15 @@
"src"
],
"dependencies": {
"dragselect": "^2.7.3"
"dragselect": "^2.7.4"
},
"devDependencies": {
"@blockly/dev-scripts": "^1.2.31",
"@blockly/dev-tools": "^5.2.3",
"blockly": "^9.2.1"
"@blockly/dev-scripts": "^2.0.1",
"@blockly/dev-tools": "^7.0.2",
"blockly": "^10.0.2"
},
"peerDependencies": {
"blockly": "^9.0.0"
"blockly": "^10.0.0"
},
"publishConfig": {},
"eslintConfig": {
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @fileoverview specify the plugin exported API.
*/

export * from './multiselect_patch';
export {Multiselect} from './multiselect';
export {MultiselectBlockDragger} from './multiselect_block_dragger';
export {blockSelectionWeakMap, inMultipleSelectionModeWeakMap} from './global';
2 changes: 1 addition & 1 deletion src/multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Multiselect {

const wrappedFunc = function(e, ws) {
func.call(this, e, ws);
if (this.targetBlock_ && e.buttons === 1 &&
if (this.targetBlock && e.buttons === 1 &&
!inMultipleSelectionModeWeakMap.get(ws)) {
const preCondition = function(block) {
return !block.isInFlyout && block.isMovable() &&
Expand Down
12 changes: 11 additions & 1 deletion src/multiselect_block_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export class MultiselectBlockDragger extends Blockly.BlockDragger {
this.blockSelection = blockSelectionWeakMap.get(workspace);
}

/**
* Dispose of this block dragger.
*/
dispose() {
super.dispose();
this.blockDraggers_.forEach((blockDragger) => {
blockDragger.dispose();
});
}

/**
* Prepares the block dragger for a new drag.
* @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer
Expand Down Expand Up @@ -180,7 +190,7 @@ export class MultiselectBlockDragger extends Blockly.BlockDragger {
*/
this.draggingBlock_.getDescendants(false).forEach(function(block) {
if (!block.getChildren().length) {
block.render();
block.queueRender();
}
});

Expand Down
28 changes: 20 additions & 8 deletions src/multiselect_contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {blockSelectionWeakMap, hasSelectedParent, copyData,
* cross tab copy paste.
*/
const registerCopy = function(useCopyPasteCrossTab) {
const id = 'blockCopyToStorage';
const copyOptions = {
displayText: function(scope) {
let workableBlocksLength = 0;
Expand Down Expand Up @@ -108,9 +109,12 @@ const registerCopy = function(useCopyPasteCrossTab) {
return true;
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK,
id: 'blockCopyToStorage',
id,
weight: 0,
};
if (Blockly.ContextMenuRegistry.registry.getItem(id) !== null) {
Blockly.ContextMenuRegistry.registry.unregister(id);
}
Blockly.ContextMenuRegistry.registry.register(copyOptions);
};

Expand Down Expand Up @@ -209,14 +213,13 @@ const registerComment = function() {
const commentOption = {
displayText: function(scope) {
let workableBlocksLength = 0;
const state = scope.block.getCommentIcon();
const state = scope.block.hasIcon(Blockly.icons.CommentIcon.TYPE);
const workspace = scope.block.workspace;
const blockSelection = blockSelectionWeakMap.get(workspace);
blockSelection.forEach(function(id) {
const block = workspace.getBlockById(id);
if (commentOption.check(block) &&
(block.getCommentIcon() instanceof Blockly.Comment) ===
(state instanceof Blockly.Comment)) {
if (commentOption.check(block) && state === block.hasIcon(
Blockly.icons.CommentIcon.TYPE)) {
workableBlocksLength++;
}
});
Expand Down Expand Up @@ -256,7 +259,8 @@ const registerComment = function() {
commentOption.preconditionFn({block: block}) === 'enabled';
},
callback: function(scope) {
const hasCommentIcon = scope.block.getCommentIcon();
const hasCommentIcon = scope.block.hasIcon(
Blockly.icons.CommentIcon.TYPE);
const apply = function(block) {
if (commentOption.check(block)) {
if (hasCommentIcon) {
Expand Down Expand Up @@ -600,6 +604,7 @@ const registerDelete = function() {
* @param {boolean} useCopyPasteCrossTab Whether to use cross tab copy paste.
*/
const registerPaste = function(useCopyPasteCrossTab) {
const id = 'blockPasteFromStorage';
const pasteOption = {
displayText: function() {
const workableBlocksLength = blockNumGetFromStorage(useCopyPasteCrossTab);
Expand Down Expand Up @@ -661,16 +666,20 @@ const registerPaste = function(useCopyPasteCrossTab) {
return true;
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
id: 'blockPasteFromStorage',
id,
weight: 0,
};
if (Blockly.ContextMenuRegistry.registry.getItem(id) !== null) {
Blockly.ContextMenuRegistry.registry.unregister(id);
}
Blockly.ContextMenuRegistry.registry.register(pasteOption);
};

/**
* Add context menu 'Select all Blocks' for workspace.
*/
const registerSelectAll = function() {
const id = 'workspaceSelectAll';
const selectAllOption = {
displayText: function() {
return 'Select all Blocks';
Expand Down Expand Up @@ -711,9 +720,12 @@ const registerSelectAll = function() {
});
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
id: 'workspaceSelectAll',
id,
weight: 5,
};
if (Blockly.ContextMenuRegistry.registry.getItem(id) !== null) {
Blockly.ContextMenuRegistry.registry.unregister(id);
}
Blockly.ContextMenuRegistry.registry.register(selectAllOption);
};

Expand Down
19 changes: 0 additions & 19 deletions src/multiselect_patch.js

This file was deleted.

6 changes: 5 additions & 1 deletion src/multiselect_shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ const registerPaste = function(useCopyPasteCrossTab) {
* ctrl+a, cmd+a, or alt+a.
*/
const registeSelectAll = function() {
const name = 'selectall';
const selectAllShortcut = {
name: 'selectall',
name,
preconditionFn: function(workspace) {
return workspace.getTopBlocks().some(
(b) => selectAllShortcut.check(b)) ? true : false;
Expand Down Expand Up @@ -380,6 +381,9 @@ const registeSelectAll = function() {
return true;
},
};
if (name in Blockly.ShortcutRegistry.registry.getRegistry()) {
Blockly.ShortcutRegistry.registry.unregister(name);
}
Blockly.ShortcutRegistry.registry.register(selectAllShortcut);

const ctrlA = Blockly.ShortcutRegistry.registry.createSerializedKey(
Expand Down