pxt-core 13.2.9 → 13.2.11

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/pxtsim.js CHANGED
@@ -6506,7 +6506,7 @@ var pxsim;
6506
6506
  this.setState(SimulatorState.Pending);
6507
6507
  }
6508
6508
  focus() {
6509
- const frame = this.simFrames()[0];
6509
+ const frame = this.mainFrame();
6510
6510
  if (frame)
6511
6511
  frame.focus();
6512
6512
  }
@@ -6553,7 +6553,7 @@ var pxsim;
6553
6553
  this.themes = themes;
6554
6554
  }
6555
6555
  startRecording(width) {
6556
- const frame = this.simFrames()[0];
6556
+ const frame = this.mainFrame();
6557
6557
  if (!frame)
6558
6558
  return undefined;
6559
6559
  this.postMessage({
@@ -6561,7 +6561,7 @@ var pxsim;
6561
6561
  action: 'start',
6562
6562
  source: MESSAGE_SOURCE,
6563
6563
  width
6564
- });
6564
+ }, undefined, frame.id);
6565
6565
  }
6566
6566
  stopRecording() {
6567
6567
  this.postMessage({ type: 'recorder', source: MESSAGE_SOURCE, action: 'stop' });
@@ -6635,6 +6635,14 @@ var pxsim;
6635
6635
  frames.unshift(loanedFrame);
6636
6636
  return frames;
6637
6637
  }
6638
+ /**
6639
+ * Returns the main simulator frame: the first frame not running a
6640
+ * simulator extension, or undefined when there is none.
6641
+ * @param skipLoaned excludes the loaned simulator's frame, as `simFrames` does
6642
+ */
6643
+ mainFrame(skipLoaned = false) {
6644
+ return this.simFrames(skipLoaned).find(frame => !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL]);
6645
+ }
6638
6646
  getSimUrl() {
6639
6647
  var _a, _b;
6640
6648
  const simUrl = this.options.simUrl || ((_a = window.pxtConfig) === null || _a === void 0 ? void 0 : _a.simUrl) || ((_b = pxt.webConfig) === null || _b === void 0 ? void 0 : _b.simUrl) || `${location.origin}/sim/simulator.html`;
@@ -6667,8 +6675,8 @@ var pxsim;
6667
6675
  // include index of the source iframe
6668
6676
  broadcastmsg.srcFrameIndex = this.simFrames().findIndex((item) => item.contentWindow === source);
6669
6677
  const sourceFrame = broadcastmsg.srcFrameIndex >= 0 ? this.simFrames()[broadcastmsg.srcFrameIndex] : undefined;
6670
- // jacdac messages from a board sim other than first should be dropped
6671
- if (broadcastmsg.srcFrameIndex > 0 && mkcdFrames.find(f => f === sourceFrame) && messageChannel === "jacdac")
6678
+ // jacdac messages from a board sim other than the main frame should be dropped
6679
+ if (sourceFrame !== this.mainFrame() && mkcdFrames.find(f => f === sourceFrame) && messageChannel === "jacdac")
6672
6680
  return;
6673
6681
  // if the editor is hosted in a multi-editor setting
6674
6682
  // don't start extra frames
@@ -6777,13 +6785,14 @@ var pxsim;
6777
6785
  }
6778
6786
  // now that we have iframe starts,
6779
6787
  // dispatch message to other frames
6788
+ const mainFrame = this.mainFrame();
6780
6789
  for (let i = 0; i < frames.length; ++i) {
6781
6790
  const frame = frames[i];
6782
6791
  // same frame as source
6783
6792
  if (source && frame.contentWindow == source)
6784
6793
  continue;
6785
- // if jacdac message, don't send to other (board) simulator frames
6786
- if (i > 0 && !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] &&
6794
+ // if jacdac message, don't send to (board) simulator frames other than the main frame
6795
+ if (frame !== mainFrame && !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] &&
6787
6796
  msg.type === "messagepacket" && msg.channel === "jacdac")
6788
6797
  continue;
6789
6798
  // frame not in DOM
@@ -6888,9 +6897,10 @@ var pxsim;
6888
6897
  this._currentRuntime = undefined;
6889
6898
  this.container.textContent = "";
6890
6899
  }
6891
- if (!this.simFrames().length) {
6892
- this.container.appendChild(this.createFrame());
6893
- this.applyAspectRatio(aspectRatio);
6900
+ if (!this.mainFrame()) {
6901
+ const wrapper = this.createFrame();
6902
+ this.container.insertBefore(wrapper, this.container.firstElementChild);
6903
+ this.applyAspectRatioToFrame(wrapper.firstElementChild, aspectRatio);
6894
6904
  this.setStarting();
6895
6905
  }
6896
6906
  }
@@ -6932,10 +6942,11 @@ var pxsim;
6932
6942
  // returns a simulator iframe that can be hosted anywhere in the page
6933
6943
  // while a loaned simulator is active, all other iframes are suspended
6934
6944
  loanSimulator() {
6945
+ var _a;
6935
6946
  if (this.loanedSimulator)
6936
6947
  return this.loanedSimulator;
6937
6948
  // reuse first simulator or create new one
6938
- this.loanedSimulator = this.container.firstElementChild || this.createFrame();
6949
+ this.loanedSimulator = ((_a = this.mainFrame(true)) === null || _a === void 0 ? void 0 : _a.parentElement) || this.createFrame();
6939
6950
  if (this.loanedSimulator.parentNode)
6940
6951
  this.container.removeChild(this.loanedSimulator);
6941
6952
  return this.loanedSimulator;
@@ -7000,8 +7011,8 @@ var pxsim;
7000
7011
  }
7001
7012
  cleanupFrames() {
7002
7013
  // drop unused extras frames after 5 seconds
7003
- const frames = this.simFrames(true);
7004
- frames.shift(); // drop first frame
7014
+ const mainFrame = this.mainFrame(true);
7015
+ const frames = this.simFrames(true).filter(frame => frame !== mainFrame);
7005
7016
  frames.filter(frame => !frame.dataset[PERMANENT])
7006
7017
  .forEach(frame => {
7007
7018
  if (this.state == SimulatorState.Stopped
@@ -7019,7 +7030,10 @@ var pxsim;
7019
7030
  return;
7020
7031
  const frames = this.simFrames();
7021
7032
  frames.forEach(frame => {
7022
- this.options.removeElement(frame.parentElement, completeHandler);
7033
+ if (frame.dataset[PERMANENT] && this.options.hideElement)
7034
+ this.options.hideElement(frame.parentElement, completeHandler);
7035
+ else
7036
+ this.options.removeElement(frame.parentElement, completeHandler);
7023
7037
  });
7024
7038
  // Execute the complete handler if there are no frames in sim view
7025
7039
  if (frames.length == 0 && completeHandler) {
@@ -7087,10 +7101,10 @@ var pxsim;
7087
7101
  this.singleSimulator = false;
7088
7102
  this.breakpointsSet = false;
7089
7103
  // first frame
7090
- let frame = this.simFrames()[0];
7104
+ let frame = this.mainFrame();
7091
7105
  if (!frame) {
7092
7106
  let wrapper = this.createFrame();
7093
- this.container.appendChild(wrapper);
7107
+ this.container.insertBefore(wrapper, this.container.firstElementChild);
7094
7108
  frame = wrapper.firstElementChild;
7095
7109
  }
7096
7110
  this.startFrame(frame);
package/built/server.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface ServeOptions {
14
14
  noauth?: boolean;
15
15
  backport?: number;
16
16
  https?: boolean;
17
+ localRepos?: pxt.Map<string>;
17
18
  }
18
19
  export declare function compileScriptAsync(id: string): Promise<string>;
19
20
  export declare function serveAsync(options: ServeOptions): Promise<void>;
package/built/server.js CHANGED
@@ -11,6 +11,7 @@ const nodeutil = require("./nodeutil");
11
11
  const hid = require("./hid");
12
12
  const net = require("net");
13
13
  const storage = require("./storage");
14
+ const localrepos = require("./localrepos");
14
15
  const subwebapp_1 = require("./subwebapp");
15
16
  const util_1 = require("util");
16
17
  var U = pxt.Util;
@@ -363,6 +364,10 @@ function handleApiAsync(req, res, elts) {
363
364
  // target config
364
365
  return readFileAsync("targetconfig.json").then(buf => JSON.parse(buf.toString("utf8")));
365
366
  }
367
+ else if (cmd == "GET localrepos")
368
+ return Promise.resolve({ repos: Object.keys(serveOptions.localRepos || {}) });
369
+ else if (cmd == "GET gh")
370
+ return Promise.resolve().then(() => localrepos.resolveLocalRepoRequest(serveOptions.localRepos || {}, innerPath));
366
371
  else
367
372
  throw throwError(400, `unknown command ${cmd.slice(0, 140)}`);
368
373
  }
@@ -890,6 +895,14 @@ async function compileScriptAsync(id) {
890
895
  return r;
891
896
  }
892
897
  exports.compileScriptAsync = compileScriptAsync;
898
+ function logLocalRepos() {
899
+ const slugs = Object.keys(serveOptions.localRepos || {});
900
+ if (!slugs.length)
901
+ return;
902
+ console.log(`Serving GitHub repositories from local directories:`);
903
+ for (const slug of slugs)
904
+ console.log(` ${slug} -> ${serveOptions.localRepos[slug]}`);
905
+ }
893
906
  function serveAsync(options) {
894
907
  serveOptions = options;
895
908
  if (!serveOptions.port)
@@ -899,6 +912,7 @@ function serveAsync(options) {
899
912
  if (!serveOptions.hostname)
900
913
  serveOptions.hostname = "localhost";
901
914
  setupRootDir();
915
+ logLocalRepos();
902
916
  const wsServerPromise = initSocketServer(serveOptions.wsPort, serveOptions.hostname);
903
917
  if (serveOptions.serial)
904
918
  initSerialMonitor();