pxt-core 7.4.24 → 7.4.27

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.
@@ -8,7 +8,7 @@
8
8
  <script type="text/javascript">
9
9
  if(/[&?]translate=1/.test(window.location.href)) {
10
10
  var _jipt = [];
11
- _jipt.push(['project', 'kindscript']);
11
+ _jipt.push(['project', 'makecode']);
12
12
  _jipt.push(['escape', function() {
13
13
  window.location.href = window.location.href.replace(/[$\?]translate=1/, '');
14
14
  }]);
@@ -114,6 +114,7 @@
114
114
  var deps = /deps(?:[:=])([^&?]+)/i.exec(window.location.href);
115
115
  var prebuiltSimJs = /prebuilt(?:[:=])1/i.test(window.location.href);
116
116
  var single = !!/single(?:[:=])1/i.test(window.location.href);
117
+ var server = !!/server(?:[:=])1/i.test(window.location.href);
117
118
 
118
119
  var codeFromSrc = /code(?:[:=])([^&?]+)/i.exec(window.location.href);
119
120
  var codeFromData = undefined;
@@ -129,7 +130,7 @@
129
130
  }
130
131
  var code = codeFromData || (codeFromSrc ? codeFromSrc[1] : undefined);
131
132
 
132
- if (!id && !code && !debugSim) {
133
+ if (!id && !code && !debugSim && !server) {
133
134
  console.error("missing id or code");
134
135
  loading.textContent = 'Oops, wrong arguments...';
135
136
  return;
@@ -159,10 +160,35 @@
159
160
  initAppCache();
160
161
 
161
162
  window.addEventListener('message', msg => {
162
- if (typeof window !== 'undefined' && window.parent !== window
163
- && msg.data && msg.data.type == "messagepacket") {
164
- // propagate message packets to parent frames
165
- window.parent.postMessage(msg.data, "*");
163
+ var data = msg.data;
164
+ if (typeof window !== 'undefined' && window.parent !== window && data) {
165
+ if (data.type == "messagepacket") {
166
+ // propagate message packets to parent frames
167
+ window.parent.postMessage(msg.data, "*");
168
+ }
169
+ else if (server && data.type === "simulateproject") {
170
+ var files = typeof data.project === "string" ? JSON.parse(data.project) : data.project;
171
+ ksRunnerReady(() => {
172
+ const deps = JSON.parse(files["pxt.json"]).dependencies
173
+ prebuiltCodePromise.then(builtSimJs => {
174
+ var options = {
175
+ code: files["main.ts"],
176
+ assets: JSON.stringify(files),
177
+ dependencies: Object.keys(deps).map(v => v + "=" + deps[v]),
178
+ highContrast: highContrast,
179
+ light: light,
180
+ fullScreen: fullScreen,
181
+ builtJsInfo: builtSimJs,
182
+ single: single
183
+ };
184
+ console.log('simulating project')
185
+ pxt.runner.simulateAsync(sims, options).then(function() {
186
+ console.log('simulator started for project...')
187
+ $(loading).remove();
188
+ })
189
+ });
190
+ })
191
+ }
166
192
  }
167
193
  });
168
194
 
@@ -183,6 +209,7 @@
183
209
  var theme = pxt.appTarget.appTheme;
184
210
  document.title = theme.title;
185
211
  if (footer) pxt.runner.initFooter(document.getElementById('footer'), id);
212
+ if (server) return;
186
213
  if (hex) {
187
214
  console.log('compiling script to hex')
188
215
  pxt.runner.generateHexFileAsync(options).then(function(hex) {