pxt-core 7.5.40 → 7.5.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/pxt.js CHANGED
@@ -108310,6 +108310,7 @@ var pxt;
108310
108310
  }
108311
108311
  github.join = join;
108312
108312
  function upgradeRules(cfg, id) {
108313
+ var _a;
108313
108314
  if (!cfg)
108314
108315
  return null;
108315
108316
  const parsed = parseRepoId(id);
@@ -108318,7 +108319,7 @@ var pxt;
108318
108319
  const repoData = cfg.approvedRepoLib;
108319
108320
  // lookup base repo for upgrade rules
108320
108321
  // (since nested repoes share the same version number)
108321
- return cfg.approvedRepoLib && pxt.U.lookup(cfg.approvedRepoLib, parsed.slug.toLowerCase()).upgrades;
108322
+ return cfg.approvedRepoLib && ((_a = pxt.U.lookup(cfg.approvedRepoLib, parsed.slug.toLowerCase())) === null || _a === void 0 ? void 0 : _a.upgrades);
108322
108323
  }
108323
108324
  function upgradedDisablesVariants(cfg, id) {
108324
108325
  const rules = upgradeRules(cfg, id) || [];
@@ -108691,6 +108692,7 @@ var pxt;
108691
108692
  constructor(io) {
108692
108693
  var _a;
108693
108694
  this.io = io;
108695
+ this.initialized = false;
108694
108696
  this.cmdSeq = pxt.U.randomUint32();
108695
108697
  this.lock = new pxt.U.PromiseQueue();
108696
108698
  this.flashing = false;
@@ -108705,6 +108707,7 @@ var pxt;
108705
108707
  this.jacdacAvailable = false;
108706
108708
  this.onSerial = (buf, isStderr) => { };
108707
108709
  this.onCustomEvent = (type, payload) => { };
108710
+ this.onConnectionChanged = () => { };
108708
108711
  let frames = [];
108709
108712
  io.onDeviceConnectionChanged = connect => this.disconnectAsync()
108710
108713
  .then(() => connect && this.reconnectAsync());
@@ -108772,6 +108775,7 @@ var pxt;
108772
108775
  });
108773
108776
  }
108774
108777
  resetState() {
108778
+ this.initialized = false;
108775
108779
  this.lock = new pxt.U.PromiseQueue();
108776
108780
  this.info = null;
108777
108781
  this.infoRaw = null;
@@ -108794,6 +108798,12 @@ var pxt;
108794
108798
  return Promise.resolve(); // ignore
108795
108799
  return Promise.reject(new Error("invalid custom event type"));
108796
108800
  }
108801
+ isConnected() {
108802
+ return this.io.isConnected() && this.initialized;
108803
+ }
108804
+ isConnecting() {
108805
+ return this.io.isConnecting() || (this.io.isConnected() && !this.initialized);
108806
+ }
108797
108807
  reconnectAsync() {
108798
108808
  this.resetState();
108799
108809
  log(`reconnect raw=${this.rawMode}`);
@@ -109002,8 +109012,10 @@ var pxt;
109002
109012
  .then(() => { });
109003
109013
  }
109004
109014
  initAsync() {
109005
- if (this.rawMode)
109015
+ if (this.rawMode) {
109016
+ this.initialized = true;
109006
109017
  return Promise.resolve();
109018
+ }
109007
109019
  return Promise.resolve()
109008
109020
  .then(() => this.talkAsync(HF2.HF2_CMD_BININFO))
109009
109021
  .then(binfo => {
@@ -109037,13 +109049,16 @@ var pxt;
109037
109049
  };
109038
109050
  log(`Board-ID: ${this.info.BoardID} v${this.info.Parsed.Version} f${this.info.Parsed.Features}`);
109039
109051
  })
109040
- .then(() => this.talkAsync(HF2.HF2_CMD_JDS_CONFIG, new Uint8Array([1])).then(() => {
109052
+ .then(() => this.talkAsync(HF2.HF2_CMD_JDS_CONFIG, new Uint8Array([1]))
109053
+ .then(() => {
109041
109054
  this.jacdacAvailable = true;
109042
109055
  }, _err => {
109043
109056
  this.jacdacAvailable = false;
109044
109057
  }))
109045
109058
  .then(() => {
109046
109059
  this.reconnectTries = 0;
109060
+ this.initialized = true;
109061
+ this.io.onConnectionChanged();
109047
109062
  });
109048
109063
  }
109049
109064
  }
@@ -112545,11 +112560,11 @@ var pxt;
112545
112560
  * The DAP wrapper is active and the device is connected
112546
112561
  */
112547
112562
  function isConnected() {
112548
- return !!wrapper && wrapper.io.isConnected();
112563
+ return !!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.isConnected());
112549
112564
  }
112550
112565
  packetio.isConnected = isConnected;
112551
112566
  function isConnecting() {
112552
- return !!wrapper && wrapper.io.isConnecting();
112567
+ return !!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.isConnecting());
112553
112568
  }
112554
112569
  packetio.isConnecting = isConnecting;
112555
112570
  function icon() {
@@ -5962,6 +5962,7 @@ var pxt;
5962
5962
  registerFieldEditor('position', pxtblockly.FieldPosition);
5963
5963
  registerFieldEditor('melody', pxtblockly.FieldCustomMelody);
5964
5964
  registerFieldEditor('soundeffect', pxtblockly.FieldSoundEffect);
5965
+ registerFieldEditor('autocomplete', pxtblockly.FieldAutoComplete);
5965
5966
  }
5966
5967
  blocks.initFieldEditors = initFieldEditors;
5967
5968
  function registerFieldEditor(selector, field, validator) {
@@ -12037,6 +12038,156 @@ var pxtblockly;
12037
12038
  }
12038
12039
  pxtblockly.FieldArgumentVariable = FieldArgumentVariable;
12039
12040
  })(pxtblockly || (pxtblockly = {}));
12041
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
12042
+ var pxtblockly;
12043
+ (function (pxtblockly) {
12044
+ class FieldTextDropdown extends Blockly.FieldTextDropdown {
12045
+ constructor(text, options, opt_validator) {
12046
+ super(text, options.values, opt_validator);
12047
+ this.isFieldCustom_ = true;
12048
+ }
12049
+ }
12050
+ pxtblockly.FieldTextDropdown = FieldTextDropdown;
12051
+ })(pxtblockly || (pxtblockly = {}));
12052
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
12053
+ /// <reference path="./field_textdropdown.ts" />
12054
+ var pxtblockly;
12055
+ (function (pxtblockly) {
12056
+ class FieldAutoComplete extends Blockly.FieldTextDropdown {
12057
+ constructor(text, options, opt_validator) {
12058
+ super(text, () => [], opt_validator);
12059
+ this.isFieldCustom_ = true;
12060
+ this.key = options.key;
12061
+ this.isTextValid_ = true;
12062
+ }
12063
+ isOptionListDynamic() {
12064
+ return true;
12065
+ }
12066
+ getDisplayText_() {
12067
+ return this.parsedValue || "";
12068
+ }
12069
+ doValueUpdate_(newValue) {
12070
+ if (newValue === null)
12071
+ return;
12072
+ if (/['"`].*['"`]/.test(newValue)) {
12073
+ this.parsedValue = JSON.parse(newValue);
12074
+ }
12075
+ else {
12076
+ this.parsedValue = newValue;
12077
+ }
12078
+ this.value_ = this.parsedValue;
12079
+ }
12080
+ getValue() {
12081
+ if (this.parsedValue) {
12082
+ return JSON.stringify(this.parsedValue);
12083
+ }
12084
+ else
12085
+ return '""';
12086
+ }
12087
+ getOptions() {
12088
+ var _a;
12089
+ const workspace = (_a = this.sourceBlock_) === null || _a === void 0 ? void 0 : _a.workspace;
12090
+ if (!workspace)
12091
+ return [];
12092
+ const res = [];
12093
+ const fields = pxtblockly.getAllFields(workspace, field => field instanceof FieldAutoComplete && field.getKey() === this.key);
12094
+ const options = fields.map(field => field.ref.getDisplayText_());
12095
+ for (const option of options) {
12096
+ if (!option.trim() || res.some(tuple => tuple[0] === option))
12097
+ continue;
12098
+ res.push([option, option]);
12099
+ }
12100
+ res.sort((a, b) => a[0].localeCompare(b[0]));
12101
+ return res;
12102
+ }
12103
+ showDropdown_() {
12104
+ const options = this.getOptions();
12105
+ if (options.length)
12106
+ super.showDropdown_();
12107
+ }
12108
+ getKey() {
12109
+ if (this.key)
12110
+ return this.key;
12111
+ if (this.sourceBlock_)
12112
+ return this.sourceBlock_.type;
12113
+ return undefined;
12114
+ }
12115
+ // Copied from field_string in pxt-blockly
12116
+ initView() {
12117
+ // Add quotes around the string
12118
+ // Positioned on updatSize, after text size is calculated.
12119
+ this.quoteSize_ = 16;
12120
+ this.quoteWidth_ = 8;
12121
+ this.quoteLeftX_ = 0;
12122
+ this.quoteRightX_ = 0;
12123
+ this.quoteY_ = 10;
12124
+ if (this.quoteLeft_)
12125
+ this.quoteLeft_.parentNode.removeChild(this.quoteLeft_);
12126
+ this.quoteLeft_ = Blockly.utils.dom.createSvgElement('text', {
12127
+ 'font-size': this.quoteSize_ + 'px',
12128
+ 'class': 'field-text-quote'
12129
+ }, this.fieldGroup_);
12130
+ super.initView();
12131
+ if (this.quoteRight_)
12132
+ this.quoteRight_.parentNode.removeChild(this.quoteRight_);
12133
+ this.quoteRight_ = Blockly.utils.dom.createSvgElement('text', {
12134
+ 'font-size': this.quoteSize_ + 'px',
12135
+ 'class': 'field-text-quote'
12136
+ }, this.fieldGroup_);
12137
+ this.quoteLeft_.appendChild(document.createTextNode('"'));
12138
+ this.quoteRight_.appendChild(document.createTextNode('"'));
12139
+ }
12140
+ // Copied from field_string in pxt-blockly
12141
+ updateSize_() {
12142
+ super.updateSize_();
12143
+ const sWidth = Math.max(this.size_.width, 1);
12144
+ const xPadding = 3;
12145
+ let addedWidth = this.positionLeft(sWidth + xPadding);
12146
+ this.textElement_.setAttribute('x', addedWidth.toString());
12147
+ addedWidth += this.positionRight(addedWidth + sWidth + xPadding);
12148
+ this.size_.width = sWidth + addedWidth;
12149
+ }
12150
+ // Copied from field_string in pxt-blockly
12151
+ positionRight(x) {
12152
+ if (!this.quoteRight_) {
12153
+ return 0;
12154
+ }
12155
+ let addedWidth = 0;
12156
+ if (this.sourceBlock_.RTL) {
12157
+ this.quoteRightX_ = Blockly.FieldString.quotePadding;
12158
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
12159
+ }
12160
+ else {
12161
+ this.quoteRightX_ = x + Blockly.FieldString.quotePadding;
12162
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
12163
+ }
12164
+ this.quoteRight_.setAttribute('transform', 'translate(' + this.quoteRightX_ + ',' + this.quoteY_ + ')');
12165
+ return addedWidth;
12166
+ }
12167
+ // Copied from field_string in pxt-blockly
12168
+ positionLeft(x) {
12169
+ if (!this.quoteLeft_) {
12170
+ return 0;
12171
+ }
12172
+ let addedWidth = 0;
12173
+ if (this.sourceBlock_.RTL) {
12174
+ this.quoteLeftX_ = x + this.quoteWidth_ + Blockly.FieldString.quotePadding * 2;
12175
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
12176
+ }
12177
+ else {
12178
+ this.quoteLeftX_ = 0;
12179
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
12180
+ }
12181
+ this.quoteLeft_.setAttribute('transform', 'translate(' + this.quoteLeftX_ + ',' + this.quoteY_ + ')');
12182
+ return addedWidth;
12183
+ }
12184
+ createSVGArrow_() {
12185
+ // This creates the little arrow for dropdown fields. Intentionally
12186
+ // do nothing
12187
+ }
12188
+ }
12189
+ pxtblockly.FieldAutoComplete = FieldAutoComplete;
12190
+ })(pxtblockly || (pxtblockly = {}));
12040
12191
  /// <reference path="../../localtypings/blockly.d.ts" />
12041
12192
  /// <reference path="../../built/pxtsim.d.ts" />
12042
12193
  var pxtblockly;
@@ -15729,17 +15880,6 @@ var pxtblockly;
15729
15880
  })(pxtblockly || (pxtblockly = {}));
15730
15881
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
15731
15882
  var pxtblockly;
15732
- (function (pxtblockly) {
15733
- class FieldTextDropdown extends Blockly.FieldTextDropdown {
15734
- constructor(text, options, opt_validator) {
15735
- super(text, options.values, opt_validator);
15736
- this.isFieldCustom_ = true;
15737
- }
15738
- }
15739
- pxtblockly.FieldTextDropdown = FieldTextDropdown;
15740
- })(pxtblockly || (pxtblockly = {}));
15741
- /// <reference path="../../localtypings/pxtblockly.d.ts" />
15742
- var pxtblockly;
15743
15883
  (function (pxtblockly) {
15744
15884
  class FieldTextInput extends Blockly.FieldTextInput {
15745
15885
  constructor(value, options, opt_validator) {
@@ -16851,11 +16991,11 @@ var pxtblockly;
16851
16991
  }
16852
16992
  }
16853
16993
  function getAllBlocksWithTilemaps(ws) {
16854
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
16994
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
16855
16995
  }
16856
16996
  pxtblockly.getAllBlocksWithTilemaps = getAllBlocksWithTilemaps;
16857
16997
  function getAllBlocksWithTilesets(ws) {
16858
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTileset);
16998
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTileset);
16859
16999
  }
16860
17000
  pxtblockly.getAllBlocksWithTilesets = getAllBlocksWithTilesets;
16861
17001
  function needsTilemapUpgrade(ws) {
@@ -16911,7 +17051,7 @@ var pxtblockly;
16911
17051
  }
16912
17052
  }
16913
17053
  pxtblockly.upgradeTilemapsInWorkspace = upgradeTilemapsInWorkspace;
16914
- function getAllFieldsCore(ws, predicate) {
17054
+ function getAllFields(ws, predicate) {
16915
17055
  const result = [];
16916
17056
  const top = ws.getTopBlocks(false);
16917
17057
  top.forEach(block => getAllFieldsRecursive(block));
@@ -16932,6 +17072,7 @@ var pxtblockly;
16932
17072
  }
16933
17073
  }
16934
17074
  }
17075
+ pxtblockly.getAllFields = getAllFields;
16935
17076
  function getAllReferencedTiles(workspace, excludeBlockID) {
16936
17077
  var _a;
16937
17078
  let all = {};
@@ -16970,10 +17111,10 @@ var pxtblockly;
16970
17111
  function getTemporaryAssets(workspace, type) {
16971
17112
  switch (type) {
16972
17113
  case "image" /* Image */:
16973
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
17114
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
16974
17115
  .map(f => f.ref.getAsset());
16975
17116
  case "animation" /* Animation */:
16976
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
17117
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
16977
17118
  .map(f => f.ref.getAsset());
16978
17119
  default: return [];
16979
17120
  }
@@ -515,6 +515,51 @@ declare namespace pxtblockly {
515
515
  dropdownCreate(): any;
516
516
  }
517
517
  }
518
+ declare namespace pxtblockly {
519
+ interface FieldTextDropdownOptions extends Blockly.FieldCustomOptions {
520
+ values: any;
521
+ }
522
+ class FieldTextDropdown extends Blockly.FieldTextDropdown implements Blockly.FieldCustom {
523
+ isFieldCustom_: boolean;
524
+ constructor(text: string, options: FieldTextDropdownOptions, opt_validator?: Function);
525
+ }
526
+ }
527
+ declare namespace Blockly {
528
+ interface FieldTextDropdown {
529
+ showDropdown_(): void;
530
+ isTextValid_: boolean;
531
+ }
532
+ }
533
+ declare namespace pxtblockly {
534
+ interface FieldAutoCompleteOptions extends Blockly.FieldCustomOptions {
535
+ key: string;
536
+ }
537
+ class FieldAutoComplete extends Blockly.FieldTextDropdown implements Blockly.FieldCustom {
538
+ isFieldCustom_: boolean;
539
+ protected key: string;
540
+ protected parsedValue: string;
541
+ protected quoteSize_: number;
542
+ protected quoteWidth_: number;
543
+ protected quoteLeftX_: number;
544
+ protected quoteRightX_: number;
545
+ protected quoteY_: number;
546
+ protected quoteLeft_: SVGTextElement;
547
+ protected quoteRight_: SVGTextElement;
548
+ constructor(text: string, options: FieldAutoCompleteOptions, opt_validator?: Function);
549
+ isOptionListDynamic(): boolean;
550
+ getDisplayText_(): string;
551
+ doValueUpdate_(newValue: string): void;
552
+ getValue(): string;
553
+ getOptions(): [string, string][];
554
+ showDropdown_(): void;
555
+ getKey(): string;
556
+ initView(): void;
557
+ updateSize_(): void;
558
+ positionRight(x: number): number;
559
+ positionLeft(x: number): number;
560
+ createSVGArrow_(): void;
561
+ }
562
+ }
518
563
  declare namespace pxtblockly {
519
564
  class FieldBreakpoint extends Blockly.FieldNumber implements Blockly.FieldCustom {
520
565
  isFieldCustom_: boolean;
@@ -1231,15 +1276,6 @@ declare namespace pxtblockly {
1231
1276
  constructor(value: string, options?: StyleOptions, opt_validator?: Function);
1232
1277
  }
1233
1278
  }
1234
- declare namespace pxtblockly {
1235
- interface FieldTextDropdownOptions extends Blockly.FieldCustomOptions {
1236
- values: any;
1237
- }
1238
- class FieldTextDropdown extends Blockly.FieldTextDropdown implements Blockly.FieldCustom {
1239
- isFieldCustom_: boolean;
1240
- constructor(text: string, options: FieldTextDropdownOptions, opt_validator?: Function);
1241
- }
1242
- }
1243
1279
  declare namespace pxtblockly {
1244
1280
  class FieldTextInput extends Blockly.FieldTextInput implements Blockly.FieldCustom {
1245
1281
  isFieldCustom_: boolean;
@@ -1469,6 +1505,7 @@ declare namespace pxtblockly {
1469
1505
  function getAllBlocksWithTilesets(ws: Blockly.Workspace): FieldEditorReference<FieldTileset>[];
1470
1506
  function needsTilemapUpgrade(ws: Blockly.Workspace): boolean;
1471
1507
  function upgradeTilemapsInWorkspace(ws: Blockly.Workspace, proj: pxt.TilemapProject): void;
1508
+ function getAllFields<U extends Blockly.Field>(ws: Blockly.Workspace, predicate: (field: Blockly.Field) => boolean): FieldEditorReference<U>[];
1472
1509
  function getAllReferencedTiles(workspace: Blockly.Workspace, excludeBlockID?: string): pxt.Tile[];
1473
1510
  function getTemporaryAssets(workspace: Blockly.Workspace, type: pxt.AssetType): pxt.Asset[];
1474
1511
  function workspaceToScreenCoordinates(ws: Blockly.WorkspaceSvg, wsCoordinates: Blockly.utils.Coordinate): Blockly.utils.Coordinate;
@@ -2400,6 +2400,7 @@ var pxt;
2400
2400
  registerFieldEditor('position', pxtblockly.FieldPosition);
2401
2401
  registerFieldEditor('melody', pxtblockly.FieldCustomMelody);
2402
2402
  registerFieldEditor('soundeffect', pxtblockly.FieldSoundEffect);
2403
+ registerFieldEditor('autocomplete', pxtblockly.FieldAutoComplete);
2403
2404
  }
2404
2405
  blocks.initFieldEditors = initFieldEditors;
2405
2406
  function registerFieldEditor(selector, field, validator) {
@@ -8475,6 +8476,156 @@ var pxtblockly;
8475
8476
  }
8476
8477
  pxtblockly.FieldArgumentVariable = FieldArgumentVariable;
8477
8478
  })(pxtblockly || (pxtblockly = {}));
8479
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
8480
+ var pxtblockly;
8481
+ (function (pxtblockly) {
8482
+ class FieldTextDropdown extends Blockly.FieldTextDropdown {
8483
+ constructor(text, options, opt_validator) {
8484
+ super(text, options.values, opt_validator);
8485
+ this.isFieldCustom_ = true;
8486
+ }
8487
+ }
8488
+ pxtblockly.FieldTextDropdown = FieldTextDropdown;
8489
+ })(pxtblockly || (pxtblockly = {}));
8490
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
8491
+ /// <reference path="./field_textdropdown.ts" />
8492
+ var pxtblockly;
8493
+ (function (pxtblockly) {
8494
+ class FieldAutoComplete extends Blockly.FieldTextDropdown {
8495
+ constructor(text, options, opt_validator) {
8496
+ super(text, () => [], opt_validator);
8497
+ this.isFieldCustom_ = true;
8498
+ this.key = options.key;
8499
+ this.isTextValid_ = true;
8500
+ }
8501
+ isOptionListDynamic() {
8502
+ return true;
8503
+ }
8504
+ getDisplayText_() {
8505
+ return this.parsedValue || "";
8506
+ }
8507
+ doValueUpdate_(newValue) {
8508
+ if (newValue === null)
8509
+ return;
8510
+ if (/['"`].*['"`]/.test(newValue)) {
8511
+ this.parsedValue = JSON.parse(newValue);
8512
+ }
8513
+ else {
8514
+ this.parsedValue = newValue;
8515
+ }
8516
+ this.value_ = this.parsedValue;
8517
+ }
8518
+ getValue() {
8519
+ if (this.parsedValue) {
8520
+ return JSON.stringify(this.parsedValue);
8521
+ }
8522
+ else
8523
+ return '""';
8524
+ }
8525
+ getOptions() {
8526
+ var _a;
8527
+ const workspace = (_a = this.sourceBlock_) === null || _a === void 0 ? void 0 : _a.workspace;
8528
+ if (!workspace)
8529
+ return [];
8530
+ const res = [];
8531
+ const fields = pxtblockly.getAllFields(workspace, field => field instanceof FieldAutoComplete && field.getKey() === this.key);
8532
+ const options = fields.map(field => field.ref.getDisplayText_());
8533
+ for (const option of options) {
8534
+ if (!option.trim() || res.some(tuple => tuple[0] === option))
8535
+ continue;
8536
+ res.push([option, option]);
8537
+ }
8538
+ res.sort((a, b) => a[0].localeCompare(b[0]));
8539
+ return res;
8540
+ }
8541
+ showDropdown_() {
8542
+ const options = this.getOptions();
8543
+ if (options.length)
8544
+ super.showDropdown_();
8545
+ }
8546
+ getKey() {
8547
+ if (this.key)
8548
+ return this.key;
8549
+ if (this.sourceBlock_)
8550
+ return this.sourceBlock_.type;
8551
+ return undefined;
8552
+ }
8553
+ // Copied from field_string in pxt-blockly
8554
+ initView() {
8555
+ // Add quotes around the string
8556
+ // Positioned on updatSize, after text size is calculated.
8557
+ this.quoteSize_ = 16;
8558
+ this.quoteWidth_ = 8;
8559
+ this.quoteLeftX_ = 0;
8560
+ this.quoteRightX_ = 0;
8561
+ this.quoteY_ = 10;
8562
+ if (this.quoteLeft_)
8563
+ this.quoteLeft_.parentNode.removeChild(this.quoteLeft_);
8564
+ this.quoteLeft_ = Blockly.utils.dom.createSvgElement('text', {
8565
+ 'font-size': this.quoteSize_ + 'px',
8566
+ 'class': 'field-text-quote'
8567
+ }, this.fieldGroup_);
8568
+ super.initView();
8569
+ if (this.quoteRight_)
8570
+ this.quoteRight_.parentNode.removeChild(this.quoteRight_);
8571
+ this.quoteRight_ = Blockly.utils.dom.createSvgElement('text', {
8572
+ 'font-size': this.quoteSize_ + 'px',
8573
+ 'class': 'field-text-quote'
8574
+ }, this.fieldGroup_);
8575
+ this.quoteLeft_.appendChild(document.createTextNode('"'));
8576
+ this.quoteRight_.appendChild(document.createTextNode('"'));
8577
+ }
8578
+ // Copied from field_string in pxt-blockly
8579
+ updateSize_() {
8580
+ super.updateSize_();
8581
+ const sWidth = Math.max(this.size_.width, 1);
8582
+ const xPadding = 3;
8583
+ let addedWidth = this.positionLeft(sWidth + xPadding);
8584
+ this.textElement_.setAttribute('x', addedWidth.toString());
8585
+ addedWidth += this.positionRight(addedWidth + sWidth + xPadding);
8586
+ this.size_.width = sWidth + addedWidth;
8587
+ }
8588
+ // Copied from field_string in pxt-blockly
8589
+ positionRight(x) {
8590
+ if (!this.quoteRight_) {
8591
+ return 0;
8592
+ }
8593
+ let addedWidth = 0;
8594
+ if (this.sourceBlock_.RTL) {
8595
+ this.quoteRightX_ = Blockly.FieldString.quotePadding;
8596
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8597
+ }
8598
+ else {
8599
+ this.quoteRightX_ = x + Blockly.FieldString.quotePadding;
8600
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8601
+ }
8602
+ this.quoteRight_.setAttribute('transform', 'translate(' + this.quoteRightX_ + ',' + this.quoteY_ + ')');
8603
+ return addedWidth;
8604
+ }
8605
+ // Copied from field_string in pxt-blockly
8606
+ positionLeft(x) {
8607
+ if (!this.quoteLeft_) {
8608
+ return 0;
8609
+ }
8610
+ let addedWidth = 0;
8611
+ if (this.sourceBlock_.RTL) {
8612
+ this.quoteLeftX_ = x + this.quoteWidth_ + Blockly.FieldString.quotePadding * 2;
8613
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8614
+ }
8615
+ else {
8616
+ this.quoteLeftX_ = 0;
8617
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8618
+ }
8619
+ this.quoteLeft_.setAttribute('transform', 'translate(' + this.quoteLeftX_ + ',' + this.quoteY_ + ')');
8620
+ return addedWidth;
8621
+ }
8622
+ createSVGArrow_() {
8623
+ // This creates the little arrow for dropdown fields. Intentionally
8624
+ // do nothing
8625
+ }
8626
+ }
8627
+ pxtblockly.FieldAutoComplete = FieldAutoComplete;
8628
+ })(pxtblockly || (pxtblockly = {}));
8478
8629
  /// <reference path="../../localtypings/blockly.d.ts" />
8479
8630
  /// <reference path="../../built/pxtsim.d.ts" />
8480
8631
  var pxtblockly;
@@ -12167,17 +12318,6 @@ var pxtblockly;
12167
12318
  })(pxtblockly || (pxtblockly = {}));
12168
12319
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
12169
12320
  var pxtblockly;
12170
- (function (pxtblockly) {
12171
- class FieldTextDropdown extends Blockly.FieldTextDropdown {
12172
- constructor(text, options, opt_validator) {
12173
- super(text, options.values, opt_validator);
12174
- this.isFieldCustom_ = true;
12175
- }
12176
- }
12177
- pxtblockly.FieldTextDropdown = FieldTextDropdown;
12178
- })(pxtblockly || (pxtblockly = {}));
12179
- /// <reference path="../../localtypings/pxtblockly.d.ts" />
12180
- var pxtblockly;
12181
12321
  (function (pxtblockly) {
12182
12322
  class FieldTextInput extends Blockly.FieldTextInput {
12183
12323
  constructor(value, options, opt_validator) {
@@ -13289,11 +13429,11 @@ var pxtblockly;
13289
13429
  }
13290
13430
  }
13291
13431
  function getAllBlocksWithTilemaps(ws) {
13292
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
13432
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
13293
13433
  }
13294
13434
  pxtblockly.getAllBlocksWithTilemaps = getAllBlocksWithTilemaps;
13295
13435
  function getAllBlocksWithTilesets(ws) {
13296
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTileset);
13436
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTileset);
13297
13437
  }
13298
13438
  pxtblockly.getAllBlocksWithTilesets = getAllBlocksWithTilesets;
13299
13439
  function needsTilemapUpgrade(ws) {
@@ -13349,7 +13489,7 @@ var pxtblockly;
13349
13489
  }
13350
13490
  }
13351
13491
  pxtblockly.upgradeTilemapsInWorkspace = upgradeTilemapsInWorkspace;
13352
- function getAllFieldsCore(ws, predicate) {
13492
+ function getAllFields(ws, predicate) {
13353
13493
  const result = [];
13354
13494
  const top = ws.getTopBlocks(false);
13355
13495
  top.forEach(block => getAllFieldsRecursive(block));
@@ -13370,6 +13510,7 @@ var pxtblockly;
13370
13510
  }
13371
13511
  }
13372
13512
  }
13513
+ pxtblockly.getAllFields = getAllFields;
13373
13514
  function getAllReferencedTiles(workspace, excludeBlockID) {
13374
13515
  var _a;
13375
13516
  let all = {};
@@ -13408,10 +13549,10 @@ var pxtblockly;
13408
13549
  function getTemporaryAssets(workspace, type) {
13409
13550
  switch (type) {
13410
13551
  case "image" /* Image */:
13411
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
13552
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
13412
13553
  .map(f => f.ref.getAsset());
13413
13554
  case "animation" /* Animation */:
13414
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
13555
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
13415
13556
  .map(f => f.ref.getAsset());
13416
13557
  default: return [];
13417
13558
  }
package/built/pxtlib.d.ts CHANGED
@@ -1438,6 +1438,7 @@ declare namespace pxt.HF2 {
1438
1438
  function enableLog(): void;
1439
1439
  class Wrapper implements pxt.packetio.PacketIOWrapper {
1440
1440
  readonly io: pxt.packetio.PacketIO;
1441
+ private initialized;
1441
1442
  private cmdSeq;
1442
1443
  constructor(io: pxt.packetio.PacketIO);
1443
1444
  private lock;
@@ -1458,9 +1459,12 @@ declare namespace pxt.HF2 {
1458
1459
  jacdacAvailable: boolean;
1459
1460
  onSerial: (buf: Uint8Array, isStderr: boolean) => void;
1460
1461
  onCustomEvent: (type: string, payload: Uint8Array) => void;
1462
+ onConnectionChanged: () => void;
1461
1463
  private resetState;
1462
1464
  onEvent(id: number, f: (buf: Uint8Array) => void): void;
1463
1465
  sendCustomEventAsync(type: string, payload: Uint8Array): Promise<void>;
1466
+ isConnected(): boolean;
1467
+ isConnecting(): boolean;
1464
1468
  reconnectAsync(): Promise<void>;
1465
1469
  disconnectAsync(): Promise<void>;
1466
1470
  error(m: string): any;
@@ -1849,6 +1853,8 @@ declare namespace pxt.packetio {
1849
1853
  onSerial: (buf: Uint8Array, isStderr: boolean) => void;
1850
1854
  reconnectAsync(): Promise<void>;
1851
1855
  disconnectAsync(): Promise<void>;
1856
+ isConnected(): boolean;
1857
+ isConnecting(): boolean;
1852
1858
  reflashAsync(resp: pxtc.CompileResult): Promise<void>;
1853
1859
  onCustomEvent: (type: string, payload: Uint8Array) => void;
1854
1860
  sendCustomEventAsync(type: string, payload: Uint8Array): Promise<void>;