Skip to content

Commit b089be0

Browse files
authored
chore: Update turtle demo for v12 (#2634)
1 parent c950147 commit b089be0

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

examples/turtle-field-demo/field_turtle.js

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ class FieldTurtle extends Blockly.Field {
1515
// (for backwards compatibility reasons serializable is false by default).
1616
SERIALIZABLE = true;
1717

18-
// The cursor property defines what the mouse will look like when the user
19-
// hovers over the field. By default the cursor will be whatever
20-
// .blocklyDraggable's cursor is defined as (vis. grab). Most fields define
21-
// this property as 'default'.
22-
CURSOR = 'pointer';
23-
2418
// How far to move the text to keep it to the right of the turtle.
2519
// May change if the turtle gets fancy enough.
2620
TEXT_OFFSET_X = 80;
@@ -90,33 +84,16 @@ class FieldTurtle extends Blockly.Field {
9084
// textElement_ (text) we can call the super-function. If we only wanted
9185
// one or the other, we could call their individual createX functions.
9286
super.initView();
87+
if (this.fieldGroup_) {
88+
Blockly.utils.dom.addClass(this.fieldGroup_, 'turtleField');
89+
}
9390

9491
// Note that the field group is created by the abstract field's init_
9592
// function. This means that *all elements* should be children of the
9693
// fieldGroup_.
9794
this.createView_();
9895
}
9996

100-
// Updates how the field looks depending on if it is editable or not.
101-
updateEditable() {
102-
if (!this.fieldGroup_) {
103-
// Not initialized yet.
104-
return;
105-
}
106-
// The default functionality just makes it so the borderRect_ does not
107-
// highlight when hovered.
108-
super.updateEditable();
109-
// Things like this are best applied to the clickTarget_. By default the
110-
// click target is the same as getSvgRoot, which by default is the
111-
// fieldGroup_.
112-
const group = this.getClickTarget_();
113-
if (!this.isCurrentlyEditable()) {
114-
group.style.cursor = 'not-allowed';
115-
} else {
116-
group.style.cursor = this.CURSOR;
117-
}
118-
}
119-
12097
// Gets the text to display when the block is collapsed
12198
getText() {
12299
let text = this.value_.turtleName + ' wearing a ' + this.value_.hat;
@@ -403,7 +380,7 @@ class FieldTurtle extends Blockly.Field {
403380
};
404381

405382
const widget = document.createElement('div');
406-
widget.className = 'customFieldsTurtleWidget blocklyNonSelectable';
383+
widget.className = 'customFieldsTurtleWidget';
407384

408385
const table = document.createElement('div');
409386
table.className = 'table';

examples/turtle-field-demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
function toggleEnabled() {
117117
var blocks = workspace.getAllBlocks(false);
118118
for (var i = 0, block; (block = blocks[i]); i++) {
119-
block.setEnabled(!block.isEnabled());
119+
block.setDisabledReason(block.isEnabled(), 'Toggle block enabled');
120120
}
121121
}
122122

examples/turtle-field-demo/turtle.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
.customFieldsTurtleWidget {
88
width: 150px;
9+
user-select: none;
10+
-ms-user-select: none;
11+
-webkit-user-select: none;
912
}
1013

1114
.customFieldsTurtleWidget button {
@@ -42,7 +45,15 @@
4245
width: 100%;
4346
}
4447

45-
.blocklySvg .blocklyNonEditableText text,
46-
.blocklySvg .blocklyEditableText text {
48+
.turtleField.blocklyEditableField {
49+
cursor: pointer;
50+
}
51+
52+
.turtleField.blocklyNonEditableField {
53+
cursor: not-allowed;
54+
}
55+
56+
.blocklySvg .blocklyNonEditableField .blocklyFieldText,
57+
.blocklySvg .blocklyEditableField .blocklyFieldText {
4758
fill: #000;
4859
}

0 commit comments

Comments
 (0)