pxt-core 7.5.41 → 7.5.44

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
@@ -113450,7 +113450,7 @@ var ts;
113450
113450
  return r;
113451
113451
  }
113452
113452
  pxtc.emptyExtInfo = emptyExtInfo;
113453
- const numberAttributes = ["weight", "imageLiteral", "topblockWeight"];
113453
+ const numberAttributes = ["weight", "imageLiteral", "topblockWeight", "inlineInputModeLimit"];
113454
113454
  const booleanAttributes = [
113455
113455
  "advanced",
113456
113456
  "handlerStatement",
@@ -10911,7 +10911,13 @@ var pxt;
10911
10911
  const totalOptions = def.parameters.length;
10912
10912
  const buttonDelta = toggle ? totalOptions : 1;
10913
10913
  const variableInlineInputs = info.blocksById[b.type].attributes.inlineInputMode === "variable";
10914
+ const inlineInputModeLimit = info.blocksById[b.type].attributes.inlineInputModeLimit || 4;
10914
10915
  const compileHiddenArguments = info.blocksById[b.type].attributes.compileHiddenArguments;
10916
+ const breakString = info.blocksById[b.type].attributes.expandableArgumentBreaks;
10917
+ let breaks;
10918
+ if (breakString) {
10919
+ breaks = breakString.split(/[;,]/).map(s => parseInt(s));
10920
+ }
10915
10921
  const state = new MutationState(b);
10916
10922
  state.setEventsEnabled(false);
10917
10923
  state.setValue(numVisibleAttr, 0);
@@ -11019,7 +11025,7 @@ var pxt;
11019
11025
  }
11020
11026
  updateButtons();
11021
11027
  if (variableInlineInputs)
11022
- b.setInputsInline(visibleOptions < 4);
11028
+ b.setInputsInline(visibleOptions < inlineInputModeLimit);
11023
11029
  if (!skipRender)
11024
11030
  b.render();
11025
11031
  }
@@ -11066,7 +11072,28 @@ var pxt;
11066
11072
  updateButtons();
11067
11073
  }
11068
11074
  function addDelta(delta) {
11069
- return Math.min(Math.max(state.getNumber(numVisibleAttr) + delta, 0), totalOptions);
11075
+ const newValue = Math.min(Math.max(state.getNumber(numVisibleAttr) + delta, 0), totalOptions);
11076
+ if (breaks) {
11077
+ if (delta >= 0) {
11078
+ if (newValue === 0)
11079
+ return 0;
11080
+ for (const breakpoint of breaks) {
11081
+ if (breakpoint >= newValue) {
11082
+ return breakpoint;
11083
+ }
11084
+ }
11085
+ return totalOptions;
11086
+ }
11087
+ else {
11088
+ for (let i = 0; i < breaks.length; i++) {
11089
+ if (breaks[i] >= newValue) {
11090
+ return i > 0 ? breaks[i - 1] : 0;
11091
+ }
11092
+ }
11093
+ return breaks[breaks.length - 1];
11094
+ }
11095
+ }
11096
+ return newValue;
11070
11097
  }
11071
11098
  function setInputVisible(input, visible) {
11072
11099
  // If the block isn't rendered, Blockly will crash
@@ -7349,7 +7349,13 @@ var pxt;
7349
7349
  const totalOptions = def.parameters.length;
7350
7350
  const buttonDelta = toggle ? totalOptions : 1;
7351
7351
  const variableInlineInputs = info.blocksById[b.type].attributes.inlineInputMode === "variable";
7352
+ const inlineInputModeLimit = info.blocksById[b.type].attributes.inlineInputModeLimit || 4;
7352
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
+ }
7353
7359
  const state = new MutationState(b);
7354
7360
  state.setEventsEnabled(false);
7355
7361
  state.setValue(numVisibleAttr, 0);
@@ -7457,7 +7463,7 @@ var pxt;
7457
7463
  }
7458
7464
  updateButtons();
7459
7465
  if (variableInlineInputs)
7460
- b.setInputsInline(visibleOptions < 4);
7466
+ b.setInputsInline(visibleOptions < inlineInputModeLimit);
7461
7467
  if (!skipRender)
7462
7468
  b.render();
7463
7469
  }
@@ -7504,7 +7510,28 @@ var pxt;
7504
7510
  updateButtons();
7505
7511
  }
7506
7512
  function addDelta(delta) {
7507
- 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;
7508
7535
  }
7509
7536
  function setInputVisible(input, visible) {
7510
7537
  // If the block isn't rendered, Blockly will crash
package/built/pxtlib.js CHANGED
@@ -15764,7 +15764,7 @@ var ts;
15764
15764
  return r;
15765
15765
  }
15766
15766
  pxtc.emptyExtInfo = emptyExtInfo;
15767
- const numberAttributes = ["weight", "imageLiteral", "topblockWeight"];
15767
+ const numberAttributes = ["weight", "imageLiteral", "topblockWeight", "inlineInputModeLimit"];
15768
15768
  const booleanAttributes = [
15769
15769
  "advanced",
15770
15770
  "handlerStatement",
@@ -107,7 +107,8 @@ declare namespace pxt.runner {
107
107
  function buildSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo>;
108
108
  enum LanguageMode {
109
109
  Blocks = 0,
110
- TypeScript = 1
110
+ TypeScript = 1,
111
+ Python = 2
111
112
  }
112
113
  let editorLanguageMode: LanguageMode;
113
114
  function setEditorContextAsync(mode: LanguageMode, localeInfo: string): Promise<void>;
@@ -1845,6 +1845,7 @@ var pxt;
1845
1845
  (function (LanguageMode) {
1846
1846
  LanguageMode[LanguageMode["Blocks"] = 0] = "Blocks";
1847
1847
  LanguageMode[LanguageMode["TypeScript"] = 1] = "TypeScript";
1848
+ LanguageMode[LanguageMode["Python"] = 2] = "Python";
1848
1849
  })(LanguageMode = runner.LanguageMode || (runner.LanguageMode = {}));
1849
1850
  runner.editorLanguageMode = LanguageMode.Blocks;
1850
1851
  function setEditorContextAsync(mode, localeInfo) {
@@ -1874,7 +1875,14 @@ var pxt;
1874
1875
  case "fileloaded":
1875
1876
  let fm = m;
1876
1877
  let name = fm.name;
1877
- setEditorContextAsync(/\.ts$/i.test(name) ? LanguageMode.TypeScript : LanguageMode.Blocks, fm.locale);
1878
+ let mode = LanguageMode.Blocks;
1879
+ if (/\.ts$/i.test(name)) {
1880
+ mode = LanguageMode.TypeScript;
1881
+ }
1882
+ else if (/\.py$/i.test(name)) {
1883
+ mode = LanguageMode.Python;
1884
+ }
1885
+ setEditorContextAsync(mode, fm.locale);
1878
1886
  break;
1879
1887
  case "popout":
1880
1888
  let mp = /((\/v[0-9+])\/)?[^\/]*#(doc|md):([^&?:]+)/i.exec(window.location.href);
@@ -2072,24 +2080,33 @@ var pxt;
2072
2080
  el.setAttribute("aria-disabled", "false");
2073
2081
  }
2074
2082
  }
2075
- function renderHash() {
2083
+ async function renderHashAsync() {
2076
2084
  let m = /^#(doc|md|tutorial|book|project|projectid|print):([^&?:]+)(:([^&?:]+):([^&?:]+))?/i.exec(window.location.hash);
2077
2085
  if (m) {
2078
2086
  pushHistory();
2087
+ if (m[4]) {
2088
+ let mode = LanguageMode.TypeScript;
2089
+ if (/^blocks$/i.test(m[4])) {
2090
+ mode = LanguageMode.Blocks;
2091
+ }
2092
+ else if (/^python$/i.test(m[4])) {
2093
+ mode = LanguageMode.Python;
2094
+ }
2095
+ await setEditorContextAsync(mode, m[5]);
2096
+ }
2079
2097
  // navigation occured
2080
- const p = m[4] ? setEditorContextAsync(/^blocks$/.test(m[4]) ? LanguageMode.Blocks : LanguageMode.TypeScript, m[5]) : Promise.resolve();
2081
- p.then(() => render(m[1], decodeURIComponent(m[2])));
2098
+ render(m[1], decodeURIComponent(m[2]));
2082
2099
  }
2083
2100
  }
2084
2101
  let promise = pxt.editor.initEditorExtensionsAsync();
2085
2102
  promise.then(() => {
2086
2103
  window.addEventListener("message", receiveDocMessage, false);
2087
2104
  window.addEventListener("hashchange", () => {
2088
- renderHash();
2105
+ renderHashAsync();
2089
2106
  }, false);
2090
2107
  parent.postMessage({ type: "sidedocready" }, "*");
2091
2108
  // delay load doc page to allow simulator to load first
2092
- setTimeout(() => renderHash(), 1);
2109
+ setTimeout(() => renderHashAsync(), 1);
2093
2110
  });
2094
2111
  }
2095
2112
  runner.startDocsServer = startDocsServer;
@@ -2108,7 +2125,7 @@ var pxt;
2108
2125
  if (files[readme])
2109
2126
  md += files[readme].replace(/^#+/, "$0#") + '\n'; // bump all headers down 1
2110
2127
  cfg.files.filter(f => f != pxt.CONFIG_NAME && f != readme)
2111
- .filter(f => (runner.editorLanguageMode == LanguageMode.Blocks) == /\.blocks?$/.test(f))
2128
+ .filter(f => matchesLanguageMode(f, runner.editorLanguageMode))
2112
2129
  .forEach(f => {
2113
2130
  if (!/^main\.(ts|blocks)$/.test(f))
2114
2131
  md += `
@@ -2163,6 +2180,16 @@ ${linkString}
2163
2180
  return renderMarkdownAsync(content, md, options);
2164
2181
  }
2165
2182
  runner.renderProjectFilesAsync = renderProjectFilesAsync;
2183
+ function matchesLanguageMode(filename, mode) {
2184
+ switch (mode) {
2185
+ case LanguageMode.Blocks:
2186
+ return /\.blocks?$/.test(filename);
2187
+ case LanguageMode.TypeScript:
2188
+ return /\.ts?$/.test(filename);
2189
+ case LanguageMode.Python:
2190
+ return /\.py?$/.test(filename);
2191
+ }
2192
+ }
2166
2193
  function renderDocAsync(content, docid) {
2167
2194
  docid = docid.replace(/^\//, "");
2168
2195
  return pxt.Cloud.markdownAsync(docid)