File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright 2024 Google LLC
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+ 'use strict' ;
7+
8+ /**
9+ * @fileoverview Blocks that have both a previous connection and an output
10+ * connection while they are being dragged.
11+ */
12+
13+ import * as Blockly from 'blockly/core' ;
14+
15+ Blockly . Blocks [ 'test_chameleon' ] = {
16+ hasOutput : true ,
17+ hasPrevious : true ,
18+
19+ init : function ( ) {
20+ this . appendDummyInput ( ) . appendField ( 'chameleon' ) ;
21+ this . setColour ( 120 ) ;
22+ this . updateShape ( ) ;
23+ } ,
24+
25+ onchange : function ( e ) {
26+ if ( e . type === Blockly . Events . BLOCK_DRAG ) {
27+ console . log ( 'got drag event' ) ;
28+ this . hasPrevious =
29+ ! this . outputConnection || ! this . outputConnection . targetBlock ( ) ;
30+ this . hasOutput = ! this . getPreviousBlock ( ) ;
31+ this . updateShape ( ) ;
32+ }
33+ } ,
34+
35+ updateShape : function ( ) {
36+ this . setPreviousStatement ( this . hasPrevious ) ;
37+ this . setOutput ( this . hasOutput ) ;
38+ } ,
39+ } ;
40+
41+ /**
42+ * The Chameleon Category.
43+ */
44+ export const category = {
45+ kind : 'CATEGORY' ,
46+ name : 'Chameleon' ,
47+ contents : [
48+ {
49+ kind : 'BLOCK' ,
50+ type : 'test_chameleon' ,
51+ } ,
52+ ] ,
53+ } ;
54+
55+ /**
56+ * Initialize this toolbox category.
57+ * @param {!Blockly.WorkspaceSvg } workspace The Blockly workspace.
58+ */
59+ export function onInit ( workspace ) {
60+ // NOP
61+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ import * as Blockly from 'blockly/core';
1414
1515import { category as alignCategory , onInit as initAlign } from './align' ;
1616import { category as basicCategory , onInit as initBasic } from './basic' ;
17+ import {
18+ category as chameleonCategory ,
19+ onInit as initChameleon ,
20+ } from './chameleon' ;
1721import {
1822 category as connectionsCategory ,
1923 onInit as initConnections ,
@@ -34,6 +38,7 @@ export const toolboxTestBlocks = {
3438 contents : [
3539 alignCategory ,
3640 basicCategory ,
41+ chameleonCategory ,
3742 connectionsCategory ,
3843 dragCategory ,
3944 fieldsCategory ,
@@ -50,6 +55,7 @@ export const toolboxTestBlocks = {
5055export function toolboxTestBlocksInit ( workspace ) {
5156 initAlign ( workspace ) ;
5257 initBasic ( workspace ) ;
58+ initChameleon ( workspace ) ;
5359 initConnections ( workspace ) ;
5460 initDrag ( workspace ) ;
5561 initFields ( workspace ) ;
You can’t perform that action at this time.
0 commit comments