pxt-core 7.5.40 → 7.5.43

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.
@@ -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) {
@@ -7348,7 +7349,13 @@ var pxt;
7348
7349
  const totalOptions = def.parameters.length;
7349
7350
  const buttonDelta = toggle ? totalOptions : 1;
7350
7351
  const variableInlineInputs = info.blocksById[b.type].attributes.inlineInputMode === "variable";
7352
+ const inlineInputModeLimit = info.blocksById[b.type].attributes.inlineInputModeLimit || 4;
7351
7353
  const compileHiddenArguments = info.blocksById[b.type].attributes.compileHiddenArguments;
7354
+ const breakString = info.blocksById[b.type].attributes.expandableArgumentBreaks;
7355
+ let breaks;
7356
+ if (breakString) {
7357
+ breaks = breakString.split(/[;,]/).map(s => parseInt(s));
7358
+ }
7352
7359
  const state = new MutationState(b);
7353
7360
  state.setEventsEnabled(false);
7354
7361
  state.setValue(numVisibleAttr, 0);
@@ -7456,7 +7463,7 @@ var pxt;
7456
7463
  }
7457
7464
  updateButtons();
7458
7465
  if (variableInlineInputs)
7459
- b.setInputsInline(visibleOptions < 4);
7466
+ b.setInputsInline(visibleOptions < inlineInputModeLimit);
7460
7467
  if (!skipRender)
7461
7468
  b.render();
7462
7469
  }
@@ -7503,7 +7510,28 @@ var pxt;
7503
7510
  updateButtons();
7504
7511
  }
7505
7512
  function addDelta(delta) {
7506
- return Math.min(Math.max(state.getNumber(numVisibleAttr) + delta, 0), totalOptions);
7513
+ const newValue = Math.min(Math.max(state.getNumber(numVisibleAttr) + delta, 0), totalOptions);
7514
+ if (breaks) {
7515
+ if (delta >= 0) {
7516
+ if (newValue === 0)
7517
+ return 0;
7518
+ for (const breakpoint of breaks) {
7519
+ if (breakpoint >= newValue) {
7520
+ return breakpoint;
7521
+ }
7522
+ }
7523
+ return totalOptions;
7524
+ }
7525
+ else {
7526
+ for (let i = 0; i < breaks.length; i++) {
7527
+ if (breaks[i] >= newValue) {
7528
+ return i > 0 ? breaks[i - 1] : 0;
7529
+ }
7530
+ }
7531
+ return breaks[breaks.length - 1];
7532
+ }
7533
+ }
7534
+ return newValue;
7507
7535
  }
7508
7536
  function setInputVisible(input, visible) {
7509
7537
  // If the block isn't rendered, Blockly will crash
@@ -8475,6 +8503,156 @@ var pxtblockly;
8475
8503
  }
8476
8504
  pxtblockly.FieldArgumentVariable = FieldArgumentVariable;
8477
8505
  })(pxtblockly || (pxtblockly = {}));
8506
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
8507
+ var pxtblockly;
8508
+ (function (pxtblockly) {
8509
+ class FieldTextDropdown extends Blockly.FieldTextDropdown {
8510
+ constructor(text, options, opt_validator) {
8511
+ super(text, options.values, opt_validator);
8512
+ this.isFieldCustom_ = true;
8513
+ }
8514
+ }
8515
+ pxtblockly.FieldTextDropdown = FieldTextDropdown;
8516
+ })(pxtblockly || (pxtblockly = {}));
8517
+ /// <reference path="../../localtypings/pxtblockly.d.ts" />
8518
+ /// <reference path="./field_textdropdown.ts" />
8519
+ var pxtblockly;
8520
+ (function (pxtblockly) {
8521
+ class FieldAutoComplete extends Blockly.FieldTextDropdown {
8522
+ constructor(text, options, opt_validator) {
8523
+ super(text, () => [], opt_validator);
8524
+ this.isFieldCustom_ = true;
8525
+ this.key = options.key;
8526
+ this.isTextValid_ = true;
8527
+ }
8528
+ isOptionListDynamic() {
8529
+ return true;
8530
+ }
8531
+ getDisplayText_() {
8532
+ return this.parsedValue || "";
8533
+ }
8534
+ doValueUpdate_(newValue) {
8535
+ if (newValue === null)
8536
+ return;
8537
+ if (/['"`].*['"`]/.test(newValue)) {
8538
+ this.parsedValue = JSON.parse(newValue);
8539
+ }
8540
+ else {
8541
+ this.parsedValue = newValue;
8542
+ }
8543
+ this.value_ = this.parsedValue;
8544
+ }
8545
+ getValue() {
8546
+ if (this.parsedValue) {
8547
+ return JSON.stringify(this.parsedValue);
8548
+ }
8549
+ else
8550
+ return '""';
8551
+ }
8552
+ getOptions() {
8553
+ var _a;
8554
+ const workspace = (_a = this.sourceBlock_) === null || _a === void 0 ? void 0 : _a.workspace;
8555
+ if (!workspace)
8556
+ return [];
8557
+ const res = [];
8558
+ const fields = pxtblockly.getAllFields(workspace, field => field instanceof FieldAutoComplete && field.getKey() === this.key);
8559
+ const options = fields.map(field => field.ref.getDisplayText_());
8560
+ for (const option of options) {
8561
+ if (!option.trim() || res.some(tuple => tuple[0] === option))
8562
+ continue;
8563
+ res.push([option, option]);
8564
+ }
8565
+ res.sort((a, b) => a[0].localeCompare(b[0]));
8566
+ return res;
8567
+ }
8568
+ showDropdown_() {
8569
+ const options = this.getOptions();
8570
+ if (options.length)
8571
+ super.showDropdown_();
8572
+ }
8573
+ getKey() {
8574
+ if (this.key)
8575
+ return this.key;
8576
+ if (this.sourceBlock_)
8577
+ return this.sourceBlock_.type;
8578
+ return undefined;
8579
+ }
8580
+ // Copied from field_string in pxt-blockly
8581
+ initView() {
8582
+ // Add quotes around the string
8583
+ // Positioned on updatSize, after text size is calculated.
8584
+ this.quoteSize_ = 16;
8585
+ this.quoteWidth_ = 8;
8586
+ this.quoteLeftX_ = 0;
8587
+ this.quoteRightX_ = 0;
8588
+ this.quoteY_ = 10;
8589
+ if (this.quoteLeft_)
8590
+ this.quoteLeft_.parentNode.removeChild(this.quoteLeft_);
8591
+ this.quoteLeft_ = Blockly.utils.dom.createSvgElement('text', {
8592
+ 'font-size': this.quoteSize_ + 'px',
8593
+ 'class': 'field-text-quote'
8594
+ }, this.fieldGroup_);
8595
+ super.initView();
8596
+ if (this.quoteRight_)
8597
+ this.quoteRight_.parentNode.removeChild(this.quoteRight_);
8598
+ this.quoteRight_ = Blockly.utils.dom.createSvgElement('text', {
8599
+ 'font-size': this.quoteSize_ + 'px',
8600
+ 'class': 'field-text-quote'
8601
+ }, this.fieldGroup_);
8602
+ this.quoteLeft_.appendChild(document.createTextNode('"'));
8603
+ this.quoteRight_.appendChild(document.createTextNode('"'));
8604
+ }
8605
+ // Copied from field_string in pxt-blockly
8606
+ updateSize_() {
8607
+ super.updateSize_();
8608
+ const sWidth = Math.max(this.size_.width, 1);
8609
+ const xPadding = 3;
8610
+ let addedWidth = this.positionLeft(sWidth + xPadding);
8611
+ this.textElement_.setAttribute('x', addedWidth.toString());
8612
+ addedWidth += this.positionRight(addedWidth + sWidth + xPadding);
8613
+ this.size_.width = sWidth + addedWidth;
8614
+ }
8615
+ // Copied from field_string in pxt-blockly
8616
+ positionRight(x) {
8617
+ if (!this.quoteRight_) {
8618
+ return 0;
8619
+ }
8620
+ let addedWidth = 0;
8621
+ if (this.sourceBlock_.RTL) {
8622
+ this.quoteRightX_ = Blockly.FieldString.quotePadding;
8623
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8624
+ }
8625
+ else {
8626
+ this.quoteRightX_ = x + Blockly.FieldString.quotePadding;
8627
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8628
+ }
8629
+ this.quoteRight_.setAttribute('transform', 'translate(' + this.quoteRightX_ + ',' + this.quoteY_ + ')');
8630
+ return addedWidth;
8631
+ }
8632
+ // Copied from field_string in pxt-blockly
8633
+ positionLeft(x) {
8634
+ if (!this.quoteLeft_) {
8635
+ return 0;
8636
+ }
8637
+ let addedWidth = 0;
8638
+ if (this.sourceBlock_.RTL) {
8639
+ this.quoteLeftX_ = x + this.quoteWidth_ + Blockly.FieldString.quotePadding * 2;
8640
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8641
+ }
8642
+ else {
8643
+ this.quoteLeftX_ = 0;
8644
+ addedWidth = this.quoteWidth_ + Blockly.FieldString.quotePadding;
8645
+ }
8646
+ this.quoteLeft_.setAttribute('transform', 'translate(' + this.quoteLeftX_ + ',' + this.quoteY_ + ')');
8647
+ return addedWidth;
8648
+ }
8649
+ createSVGArrow_() {
8650
+ // This creates the little arrow for dropdown fields. Intentionally
8651
+ // do nothing
8652
+ }
8653
+ }
8654
+ pxtblockly.FieldAutoComplete = FieldAutoComplete;
8655
+ })(pxtblockly || (pxtblockly = {}));
8478
8656
  /// <reference path="../../localtypings/blockly.d.ts" />
8479
8657
  /// <reference path="../../built/pxtsim.d.ts" />
8480
8658
  var pxtblockly;
@@ -12167,17 +12345,6 @@ var pxtblockly;
12167
12345
  })(pxtblockly || (pxtblockly = {}));
12168
12346
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
12169
12347
  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
12348
  (function (pxtblockly) {
12182
12349
  class FieldTextInput extends Blockly.FieldTextInput {
12183
12350
  constructor(value, options, opt_validator) {
@@ -13289,11 +13456,11 @@ var pxtblockly;
13289
13456
  }
13290
13457
  }
13291
13458
  function getAllBlocksWithTilemaps(ws) {
13292
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
13459
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTilemap && !f.isGreyBlock);
13293
13460
  }
13294
13461
  pxtblockly.getAllBlocksWithTilemaps = getAllBlocksWithTilemaps;
13295
13462
  function getAllBlocksWithTilesets(ws) {
13296
- return getAllFieldsCore(ws, f => f instanceof pxtblockly.FieldTileset);
13463
+ return getAllFields(ws, f => f instanceof pxtblockly.FieldTileset);
13297
13464
  }
13298
13465
  pxtblockly.getAllBlocksWithTilesets = getAllBlocksWithTilesets;
13299
13466
  function needsTilemapUpgrade(ws) {
@@ -13349,7 +13516,7 @@ var pxtblockly;
13349
13516
  }
13350
13517
  }
13351
13518
  pxtblockly.upgradeTilemapsInWorkspace = upgradeTilemapsInWorkspace;
13352
- function getAllFieldsCore(ws, predicate) {
13519
+ function getAllFields(ws, predicate) {
13353
13520
  const result = [];
13354
13521
  const top = ws.getTopBlocks(false);
13355
13522
  top.forEach(block => getAllFieldsRecursive(block));
@@ -13370,6 +13537,7 @@ var pxtblockly;
13370
13537
  }
13371
13538
  }
13372
13539
  }
13540
+ pxtblockly.getAllFields = getAllFields;
13373
13541
  function getAllReferencedTiles(workspace, excludeBlockID) {
13374
13542
  var _a;
13375
13543
  let all = {};
@@ -13408,10 +13576,10 @@ var pxtblockly;
13408
13576
  function getTemporaryAssets(workspace, type) {
13409
13577
  switch (type) {
13410
13578
  case "image" /* Image */:
13411
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
13579
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldSpriteEditor && field.isTemporaryAsset())
13412
13580
  .map(f => f.ref.getAsset());
13413
13581
  case "animation" /* Animation */:
13414
- return getAllFieldsCore(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
13582
+ return getAllFields(workspace, field => field instanceof pxtblockly.FieldAnimationEditor && field.isTemporaryAsset())
13415
13583
  .map(f => f.ref.getAsset());
13416
13584
  default: return [];
13417
13585
  }
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>;
package/built/pxtlib.js CHANGED
@@ -10624,6 +10624,7 @@ var pxt;
10624
10624
  }
10625
10625
  github.join = join;
10626
10626
  function upgradeRules(cfg, id) {
10627
+ var _a;
10627
10628
  if (!cfg)
10628
10629
  return null;
10629
10630
  const parsed = parseRepoId(id);
@@ -10632,7 +10633,7 @@ var pxt;
10632
10633
  const repoData = cfg.approvedRepoLib;
10633
10634
  // lookup base repo for upgrade rules
10634
10635
  // (since nested repoes share the same version number)
10635
- return cfg.approvedRepoLib && pxt.U.lookup(cfg.approvedRepoLib, parsed.slug.toLowerCase()).upgrades;
10636
+ return cfg.approvedRepoLib && ((_a = pxt.U.lookup(cfg.approvedRepoLib, parsed.slug.toLowerCase())) === null || _a === void 0 ? void 0 : _a.upgrades);
10636
10637
  }
10637
10638
  function upgradedDisablesVariants(cfg, id) {
10638
10639
  const rules = upgradeRules(cfg, id) || [];
@@ -11005,6 +11006,7 @@ var pxt;
11005
11006
  constructor(io) {
11006
11007
  var _a;
11007
11008
  this.io = io;
11009
+ this.initialized = false;
11008
11010
  this.cmdSeq = pxt.U.randomUint32();
11009
11011
  this.lock = new pxt.U.PromiseQueue();
11010
11012
  this.flashing = false;
@@ -11019,6 +11021,7 @@ var pxt;
11019
11021
  this.jacdacAvailable = false;
11020
11022
  this.onSerial = (buf, isStderr) => { };
11021
11023
  this.onCustomEvent = (type, payload) => { };
11024
+ this.onConnectionChanged = () => { };
11022
11025
  let frames = [];
11023
11026
  io.onDeviceConnectionChanged = connect => this.disconnectAsync()
11024
11027
  .then(() => connect && this.reconnectAsync());
@@ -11086,6 +11089,7 @@ var pxt;
11086
11089
  });
11087
11090
  }
11088
11091
  resetState() {
11092
+ this.initialized = false;
11089
11093
  this.lock = new pxt.U.PromiseQueue();
11090
11094
  this.info = null;
11091
11095
  this.infoRaw = null;
@@ -11108,6 +11112,12 @@ var pxt;
11108
11112
  return Promise.resolve(); // ignore
11109
11113
  return Promise.reject(new Error("invalid custom event type"));
11110
11114
  }
11115
+ isConnected() {
11116
+ return this.io.isConnected() && this.initialized;
11117
+ }
11118
+ isConnecting() {
11119
+ return this.io.isConnecting() || (this.io.isConnected() && !this.initialized);
11120
+ }
11111
11121
  reconnectAsync() {
11112
11122
  this.resetState();
11113
11123
  log(`reconnect raw=${this.rawMode}`);
@@ -11316,8 +11326,10 @@ var pxt;
11316
11326
  .then(() => { });
11317
11327
  }
11318
11328
  initAsync() {
11319
- if (this.rawMode)
11329
+ if (this.rawMode) {
11330
+ this.initialized = true;
11320
11331
  return Promise.resolve();
11332
+ }
11321
11333
  return Promise.resolve()
11322
11334
  .then(() => this.talkAsync(HF2.HF2_CMD_BININFO))
11323
11335
  .then(binfo => {
@@ -11351,13 +11363,16 @@ var pxt;
11351
11363
  };
11352
11364
  log(`Board-ID: ${this.info.BoardID} v${this.info.Parsed.Version} f${this.info.Parsed.Features}`);
11353
11365
  })
11354
- .then(() => this.talkAsync(HF2.HF2_CMD_JDS_CONFIG, new Uint8Array([1])).then(() => {
11366
+ .then(() => this.talkAsync(HF2.HF2_CMD_JDS_CONFIG, new Uint8Array([1]))
11367
+ .then(() => {
11355
11368
  this.jacdacAvailable = true;
11356
11369
  }, _err => {
11357
11370
  this.jacdacAvailable = false;
11358
11371
  }))
11359
11372
  .then(() => {
11360
11373
  this.reconnectTries = 0;
11374
+ this.initialized = true;
11375
+ this.io.onConnectionChanged();
11361
11376
  });
11362
11377
  }
11363
11378
  }
@@ -14859,11 +14874,11 @@ var pxt;
14859
14874
  * The DAP wrapper is active and the device is connected
14860
14875
  */
14861
14876
  function isConnected() {
14862
- return !!wrapper && wrapper.io.isConnected();
14877
+ return !!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.isConnected());
14863
14878
  }
14864
14879
  packetio.isConnected = isConnected;
14865
14880
  function isConnecting() {
14866
- return !!wrapper && wrapper.io.isConnecting();
14881
+ return !!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.isConnecting());
14867
14882
  }
14868
14883
  packetio.isConnecting = isConnecting;
14869
14884
  function icon() {
@@ -15749,7 +15764,7 @@ var ts;
15749
15764
  return r;
15750
15765
  }
15751
15766
  pxtc.emptyExtInfo = emptyExtInfo;
15752
- const numberAttributes = ["weight", "imageLiteral", "topblockWeight"];
15767
+ const numberAttributes = ["weight", "imageLiteral", "topblockWeight", "inlineInputModeLimit"];
15753
15768
  const booleanAttributes = [
15754
15769
  "advanced",
15755
15770
  "handlerStatement",