Skip to content

Commit c84cb31

Browse files
committed
[WIP] Support Blockly v12
Signed-off-by: Hollow Man <[email protected]>
1 parent 09b626c commit c84cb31

File tree

8 files changed

+294
-352
lines changed

8 files changed

+294
-352
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
},
4444
"devDependencies": {
4545
"@blockly/dev-scripts": "^4.0.9",
46-
"@blockly/dev-tools": "^8.1.2",
47-
"@blockly/keyboard-navigation": "^0.6.12",
48-
"@blockly/workspace-backpack": "^6.0.16",
49-
"blockly": "^11.2.2"
46+
"@blockly/dev-tools": "^9.0.2",
47+
"@blockly/keyboard-navigation": "^2.0.0",
48+
"@blockly/workspace-backpack": "^7.0.2",
49+
"blockly": "^12.2.0"
5050
},
5151
"peerDependencies": {
5252
"blockly": ">=11"

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,
@@ -789,7 +789,7 @@ const registerPaste = function(useCopyPasteCrossTab) {
789789
blockList[connectionDB[1]].previousConnection);
790790
});
791791
Blockly.Events.setGroup(false);
792-
Blockly.common.setSelected(multiDraggable);
792+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
793793
return true;
794794
},
795795
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
@@ -833,7 +833,7 @@ const registerSelectAll = function() {
833833
} else {
834834
Blockly.getSelected().unselect();
835835
}
836-
Blockly.common.setSelected(null);
836+
Blockly.common.setSelected(scope.workspace);
837837
multiDraggable.clearAll_();
838838
dragSelectionWeakMap.get(scope.workspace).clear();
839839
}
@@ -856,7 +856,7 @@ const registerSelectAll = function() {
856856
}
857857
});
858858

859-
Blockly.common.setSelected(multiDraggable);
859+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
860860
},
861861
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
862862
id,
@@ -1115,7 +1115,7 @@ const registerCommentDuplicate = function() {
11151115
});
11161116
dragSelection.clear();
11171117
multiDraggable.clearAll_();
1118-
Blockly.common.setSelected(null);
1118+
Blockly.common.setSelected(workspace);
11191119
} else {
11201120
apply(scope.comment);
11211121
}
@@ -1127,7 +1127,7 @@ const registerCommentDuplicate = function() {
11271127
comment.select();
11281128
}
11291129
}
1130-
Blockly.common.setSelected(multiDraggable);
1130+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
11311131
Blockly.Events.setGroup(false);
11321132
},
11331133
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
@@ -405,7 +405,7 @@ export class MultiselectControls {
405405
// Set selected to multiDraggable if dragSelection not empty
406406
if (this.dragSelection.size && !(Blockly.getSelected() instanceof
407407
MultiselectDraggable)) {
408-
Blockly.common.setSelected(this.multiDraggable);
408+
Blockly.getFocusManager().updateFocusedNode(this.multiDraggable);
409409
} else if (this.lastSelectedElement_ &&
410410
!inPasteShortcut.get(this.workspace_)) {
411411
this.updateDraggables_(this.lastSelectedElement_);
@@ -415,7 +415,7 @@ export class MultiselectControls {
415415
MultiselectDraggable)) {
416416
if (Blockly.getSelected() instanceof Blockly.BlockSvg &&
417417
!Blockly.getSelected().isShadow()) {
418-
Blockly.common.setSelected(null);
418+
Blockly.common.setSelected(this.workspace_);
419419
}
420420
// TODO: Look into this after gesture has been updated at Blockly
421421
// Currently, the setSelected is called twice even with selection of
@@ -528,7 +528,7 @@ export class MultiselectControls {
528528
// Ensure that Blockly selects multidraggable if
529529
// our set is not empty.
530530
if (this.dragSelection.size && !Blockly.getSelected()) {
531-
Blockly.common.setSelected(this.multiDraggable);
531+
Blockly.getFocusManager().updateFocusedNode(this.multiDraggable);
532532
}
533533
if (this.hasDisableWorkspaceDrag_) {
534534
this.workspace_.options.moveOptions.drag = true;

src/multiselect_draggable.js

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

35+
canBeFocused() {
36+
return true;
37+
}
38+
39+
/** See IFocusableNode.getFocusableElement. */
40+
getFocusableElement() {
41+
return this;
42+
}
43+
44+
/** See IFocusableNode.getFocusableTree. */
45+
getFocusableTree() {
46+
return this.workspace;
47+
}
48+
49+
/** See IFocusableNode.onNodeFocus. */
50+
onNodeFocus() {
51+
// for (const id of this.dragSelection) {
52+
// const block = this.workspace.getBlockById(id);
53+
// if (block) {
54+
// block.addSelect();
55+
// }
56+
// }
57+
}
58+
59+
/** See IFocusableNode.onNodeBlur. */
60+
onNodeBlur() {
61+
// for (const id of this.dragSelection) {
62+
// const block = this.workspace.getBlockById(id);
63+
// if (block) {
64+
// block.removeSelect();
65+
// }
66+
// }
67+
}
68+
3569
/**
3670
* Clears everything in the subDraggables
3771
* map of the MultiselectDraggable object.
@@ -71,14 +105,14 @@ export class MultiselectDraggable {
71105

72106
// This is the feature where we added a pointer down event listener.
73107
// This was added to mitigate the issue of setStart[draggable] overwriting
74-
// the call that passes the multidraggable to Blockly.common.SetSelected().
108+
// the call that passes the multidraggable to Blockly.getFocusManager().updateFocusedNode().
75109
// This should be updated/fixed when a more flexible gesture handling
76110
// system is implemented.
77111
// TODO: Look into these after gestures have been updated
78112
/**
79113
* Adds a pointer down event listener to a subdraggable to mitigate issue
80114
* of setStart[draggable] overwriting the call that passes the
81-
* multidraggable to Blockly.common.SetSelected().
115+
* multidraggable to Blockly.getFocusManager().updateFocusedNode().
82116
* @param {Blockly.IDraggable} subDraggable A draggable object that will
83117
* have an event listener added to
84118
* @private
@@ -101,7 +135,7 @@ export class MultiselectDraggable {
101135
/**
102136
* Removes a pointer down event listener from a subdraggable to
103137
* mitigate issue of setStart[draggable] overwriting the call that
104-
* passes the multidraggable to Blockly.common.SetSelected().
138+
* passes the multidraggable to Blockly.getFocusManager().updateFocusedNode().
105139
* @param {Blockly.IDraggable} subDraggable A draggable object
106140
* that will have an event listener removed from
107141
* @private
@@ -122,13 +156,16 @@ export class MultiselectDraggable {
122156
/**
123157
* The handler for the pointer down event that mitigates
124158
* the issue of setStart[draggable] overwriting the call that
125-
* passes the multidraggable to Blockly.common.SetSelected().
159+
* passes the multidraggable to Blockly.getFocusManager().updateFocusedNode().
126160
* @param {PointerEvent} event A pointer down event
127161
* @private
128162
*/
129163
pointerDownEventHandler_(event) {
130164
if (!inMultipleSelectionModeWeakMap.get(this.workspace)) {
131-
Blockly.common.setSelected(this);
165+
Blockly.getFocusManager().updateFocusedNode(this);
166+
const gesture = this.workspace.getGesture(event);
167+
if (gesture)
168+
gesture.startBlock = this;
132169
}
133170
}
134171

@@ -266,12 +303,7 @@ export class MultiselectDraggable {
266303
// This needs to be worked on to see if we can make the
267304
// highlighting of the subdraggables in real time.
268305
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-
}
306+
draggable[0].select();
275307
}
276308
}
277309

src/multiselect_shortcut.js

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

428-
Blockly.common.setSelected(multiDraggable);
428+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
429429
Blockly.Events.setGroup(false);
430430
return true;
431431
},
@@ -485,7 +485,7 @@ const registerSelectAll = function() {
485485
} else {
486486
Blockly.getSelected().unselect();
487487
}
488-
Blockly.common.setSelected(null);
488+
Blockly.common.setSelected(workspace);
489489
multiDraggable.clearAll_();
490490
dragSelectionWeakMap.get(workspace).clear();
491491
}
@@ -508,7 +508,7 @@ const registerSelectAll = function() {
508508
}
509509
});
510510

511-
Blockly.common.setSelected(multiDraggable);
511+
Blockly.getFocusManager().updateFocusedNode(multiDraggable);
512512
return true;
513513
},
514514
};

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)