Skip to content

Commit 514e825

Browse files
committed
[WIP] Support Blockly v12
Signed-off-by: Hollow Man <[email protected]>
1 parent 44a8cf0 commit 514e825

File tree

8 files changed

+145
-190
lines changed

8 files changed

+145
-190
lines changed

package-lock.json

Lines changed: 63 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mit-app-inventor/blockly-plugin-workspace-multiselect",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"description": "A Blockly plugin that allows to drag, select and doing actions on multiple blocks in the workspace.",
55
"scripts": {
66
"audit:fix": "blockly-scripts auditFix",
@@ -43,13 +43,13 @@
4343
},
4444
"devDependencies": {
4545
"@blockly/dev-scripts": "^4.0.9",
46-
"@blockly/dev-tools": "^8.1.2",
47-
"@blockly/keyboard-navigation": "^0.6.14",
48-
"@blockly/workspace-backpack": "^6.0.16",
49-
"blockly": "^11.2.2"
46+
"@blockly/dev-tools": "^9.0.2",
47+
"@blockly/keyboard-navigation": "^3.0.1",
48+
"@blockly/workspace-backpack": "^7.0.2",
49+
"blockly": "^12.3.0"
5050
},
5151
"peerDependencies": {
52-
"blockly": ">=11 <12"
52+
"blockly": ">=12"
5353
},
5454
"publishConfig": {},
5555
"eslintConfig": {

src/multiselect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export class Multiselect {
441441
'blocklyDropdownMenu') > -1)) {
442442
this.controls_.revertLastUnselectedBlock();
443443
}
444-
this.controls_.disableMultiselect();
444+
// this.controls_.disableMultiselect();
445445
}
446446
}
447447
}

src/multiselect_contextmenu.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const registerDuplicate = function() {
210210
});
211211
dragSelection.clear();
212212
multiDraggable.clearAll_();
213-
Blockly.common.setSelected(null);
213+
Blockly.common.setSelected(workspace);
214214
} else {
215215
apply(scope.block);
216216
}
@@ -234,7 +234,7 @@ const registerDuplicate = function() {
234234
connectionDBList.forEach(function(connectionDB) {
235235
connectionDB[0].connect(connectionDB[1]);
236236
});
237-
Blockly.common.setSelected(multiDraggable);
237+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
238238
Blockly.Events.setGroup(false);
239239
},
240240
scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK,
@@ -801,7 +801,7 @@ const registerPaste = function(useCopyPasteCrossTab) {
801801
blockList[connectionDB[1]].previousConnection);
802802
});
803803
Blockly.Events.setGroup(false);
804-
Blockly.common.setSelected(multiDraggable);
804+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
805805
return true;
806806
},
807807
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
@@ -845,7 +845,7 @@ const registerSelectAll = function() {
845845
} else {
846846
Blockly.getSelected().unselect();
847847
}
848-
Blockly.common.setSelected(null);
848+
Blockly.common.setSelected(scope.workspace);
849849
multiDraggable.clearAll_();
850850
dragSelectionWeakMap.get(scope.workspace).clear();
851851
}
@@ -868,7 +868,7 @@ const registerSelectAll = function() {
868868
}
869869
});
870870

871-
Blockly.common.setSelected(multiDraggable);
871+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
872872
},
873873
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
874874
id,
@@ -1135,7 +1135,7 @@ const registerCommentDuplicate = function() {
11351135
});
11361136
dragSelection.clear();
11371137
multiDraggable.clearAll_();
1138-
Blockly.common.setSelected(null);
1138+
Blockly.common.setSelected(workspace);
11391139
} else {
11401140
apply(scope.comment);
11411141
}
@@ -1147,7 +1147,7 @@ const registerCommentDuplicate = function() {
11471147
comment.select();
11481148
}
11491149
}
1150-
Blockly.common.setSelected(multiDraggable);
1150+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
11511151
Blockly.Events.setGroup(false);
11521152
},
11531153
scopeType: Blockly.ContextMenuRegistry.ScopeType.COMMENT,

src/multiselect_controls.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export class MultiselectControls {
387387
}
388388
this.multiDraggable.clearAll_();
389389
this.dragSelection.clear();
390-
Blockly.common.setSelected(null);
390+
Blockly.common.setSelected(this.workspace_);
391391
} else if (Blockly.getSelected() &&
392392
!(Blockly.getSelected() instanceof MultiselectDraggable)) {
393393
// Blockly.getSelected() is not a multiselectDraggable
@@ -410,7 +410,7 @@ export class MultiselectControls {
410410
// Set selected to multiDraggable if dragSelection not empty
411411
if (this.dragSelection.size && !(Blockly.getSelected() instanceof
412412
MultiselectDraggable)) {
413-
Blockly.common.setSelected(this.multiDraggable);
413+
Blockly.getFocusManager().updateFocusedNode(this.multiDraggable);
414414
} else if (this.lastSelectedElement_ &&
415415
!inPasteShortcut.get(this.workspace_)) {
416416
this.updateDraggables_(this.lastSelectedElement_);
@@ -420,7 +420,7 @@ export class MultiselectControls {
420420
MultiselectDraggable)) {
421421
if (Blockly.getSelected() instanceof Blockly.BlockSvg &&
422422
!Blockly.getSelected().isShadow()) {
423-
Blockly.common.setSelected(null);
423+
Blockly.common.setSelected(this.workspace_);
424424
}
425425
// TODO: Look into this after gesture has been updated at Blockly
426426
// Currently, the setSelected is called twice even with selection of
@@ -533,7 +533,7 @@ export class MultiselectControls {
533533
// Ensure that Blockly selects multidraggable if
534534
// our set is not empty.
535535
if (this.dragSelection.size && !Blockly.getSelected()) {
536-
Blockly.common.setSelected(this.multiDraggable);
536+
Blockly.getFocusManager().updateFocusedNode(this.multiDraggable);
537537
}
538538
if (this.hasDisableWorkspaceDrag_) {
539539
this.workspace_.options.moveOptions.drag = true;

src/multiselect_draggable.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,50 @@ export class MultiselectDraggable {
3232
this.dragSelection = dragSelectionWeakMap.get(workspace);
3333
}
3434

35+
/**
36+
* Determines if this draggable can be focused.
37+
* @returns {boolean} Always returns true.
38+
*/
39+
canBeFocused() {
40+
return true;
41+
}
42+
43+
/**
44+
* Gets the focusable element for this draggable.
45+
* @returns {MultiselectDraggable} This draggable instance.
46+
*/
47+
getFocusableElement() {
48+
return this;
49+
}
50+
51+
/**
52+
* Gets the focusable tree for this draggable.
53+
* @returns {Blockly.Workspace} The workspace containing this draggable.
54+
*/
55+
getFocusableTree() {
56+
return this.workspace;
57+
}
58+
59+
/** See IFocusableNode.onNodeFocus. */
60+
onNodeFocus() {
61+
// for (const id of this.dragSelection) {
62+
// const block = this.workspace.getBlockById(id);
63+
// if (block) {
64+
// block.addSelect();
65+
// }
66+
// }
67+
}
68+
69+
/** See IFocusableNode.onNodeBlur. */
70+
onNodeBlur() {
71+
// for (const id of this.dragSelection) {
72+
// const block = this.workspace.getBlockById(id);
73+
// if (block) {
74+
// block.removeSelect();
75+
// }
76+
// }
77+
}
78+
3579
/**
3680
* Clears everything in the subDraggables
3781
* map of the MultiselectDraggable object.
@@ -71,14 +115,15 @@ export class MultiselectDraggable {
71115

72116
// This is the feature where we added a pointer down event listener.
73117
// This was added to mitigate the issue of setStart[draggable] overwriting
74-
// the call that passes the multidraggable to Blockly.common.SetSelected().
118+
// the call that passes the multidraggable to
119+
// Blockly.getFocusManager().updateFocusedNode().
75120
// This should be updated/fixed when a more flexible gesture handling
76121
// system is implemented.
77122
// TODO: Look into these after gestures have been updated
78123
/**
79124
* Adds a pointer down event listener to a subdraggable to mitigate issue
80125
* of setStart[draggable] overwriting the call that passes the
81-
* multidraggable to Blockly.common.SetSelected().
126+
* multidraggable to Blockly.getFocusManager().updateFocusedNode().
82127
* @param {Blockly.IDraggable} subDraggable A draggable object that will
83128
* have an event listener added to
84129
* @private
@@ -101,7 +146,8 @@ export class MultiselectDraggable {
101146
/**
102147
* Removes a pointer down event listener from a subdraggable to
103148
* mitigate issue of setStart[draggable] overwriting the call that
104-
* passes the multidraggable to Blockly.common.SetSelected().
149+
* passes the multidraggable to
150+
* Blockly.getFocusManager().updateFocusedNode().
105151
* @param {Blockly.IDraggable} subDraggable A draggable object
106152
* that will have an event listener removed from
107153
* @private
@@ -122,13 +168,17 @@ export class MultiselectDraggable {
122168
/**
123169
* The handler for the pointer down event that mitigates
124170
* the issue of setStart[draggable] overwriting the call that
125-
* passes the multidraggable to Blockly.common.SetSelected().
171+
* passes the multidraggable to Blockly.getFocusManager().updateFocusedNode().
126172
* @param {PointerEvent} event A pointer down event
127173
* @private
128174
*/
129175
pointerDownEventHandler_(event) {
130176
if (!inMultipleSelectionModeWeakMap.get(this.workspace)) {
131-
Blockly.common.setSelected(this);
177+
Blockly.getFocusManager().updateFocusedNode(this);
178+
const gesture = this.workspace.getGesture(event);
179+
if (gesture) {
180+
gesture.startBlock = this;
181+
}
132182
}
133183
}
134184

@@ -266,12 +316,7 @@ export class MultiselectDraggable {
266316
// This needs to be worked on to see if we can make the
267317
// highlighting of the subdraggables in real time.
268318
for (const draggable of this.subDraggables) {
269-
if (draggable[0] instanceof Blockly.BlockSvg &&
270-
!draggable[0].isShadow()) {
271-
draggable[0].select();
272-
} else {
273-
draggable[0].select();
274-
}
319+
draggable[0].select();
275320
}
276321
}
277322

src/multiselect_shortcut.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ const registerPaste = function(useCopyPasteCrossTab) {
433433
blockList[connectionDB[1]].previousConnection);
434434
});
435435

436-
Blockly.common.setSelected(multiDraggable);
436+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
437437
Blockly.Events.setGroup(false);
438438
return true;
439439
},
@@ -493,7 +493,7 @@ const registerSelectAll = function() {
493493
} else {
494494
Blockly.getSelected().unselect();
495495
}
496-
Blockly.common.setSelected(null);
496+
Blockly.common.setSelected(workspace);
497497
multiDraggable.clearAll_();
498498
dragSelectionWeakMap.get(workspace).clear();
499499
}
@@ -516,7 +516,7 @@ const registerSelectAll = function() {
516516
}
517517
});
518518

519-
Blockly.common.setSelected(multiDraggable);
519+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
520520
return true;
521521
},
522522
};

test/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import * as Blockly from 'blockly';
1212
import {toolboxCategories, createPlayground} from '@blockly/dev-tools';
1313
import {Multiselect} from '../src/index';
1414
import {Backpack} from '@blockly/workspace-backpack';
15-
import {NavigationController} from '@blockly/keyboard-navigation';
15+
// import {NavigationController} from '@blockly/keyboard-navigation';
1616

17-
const navigationController = new NavigationController();
17+
// const navigationController = new NavigationController();
1818
/**
1919
* Create a workspace.
2020
* @param {HTMLElement} blocklyDiv The blockly container div.
@@ -28,7 +28,7 @@ function createWorkspace(blocklyDiv, options) {
2828
const backpack = new Backpack(workspace);
2929
backpack.init();
3030

31-
navigationController.addWorkspace(workspace);
31+
// navigationController.addWorkspace(workspace);
3232

3333
// Initialize multiselect plugin.
3434
const multiselectPlugin = new Multiselect(workspace);
@@ -38,8 +38,8 @@ function createWorkspace(blocklyDiv, options) {
3838
}
3939

4040
Blockly.ContextMenuItems.registerCommentOptions();
41-
// Initialize keyboard nav plugin.
42-
navigationController.init();
41+
// // Initialize keyboard nav plugin.
42+
// navigationController.init();
4343

4444
document.addEventListener('DOMContentLoaded', function() {
4545
const defaultOptions = {

0 commit comments

Comments
 (0)