@kupcad/playground 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kupcad/playground",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "KupCAD in the browser: a script's editor, its model and its parameters, running on the core compiled to WebAssembly in a worker. One Svelte component a page embeds.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -24,10 +24,10 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@kupcad/editor": "0.1.7",
28
- "@kupcad/protocol": "0.1.7",
29
- "@kupcad/ui": "0.1.7",
30
- "@kupcad/wasm": "0.1.7"
27
+ "@kupcad/editor": "0.1.8",
28
+ "@kupcad/protocol": "0.1.8",
29
+ "@kupcad/ui": "0.1.8",
30
+ "@kupcad/wasm": "0.1.8"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@codemirror/language": "^6.13.1",
@@ -27,6 +27,7 @@
27
27
  linesOfLog,
28
28
  linesOfRun,
29
29
  localSettings,
30
+ paneKeys,
30
31
  ParamsPanel,
31
32
  plainValues,
32
33
  problemsOf,
@@ -38,7 +39,7 @@
38
39
  import { createKupcadWorker } from '@kupcad/wasm';
39
40
  import { download } from './download.js';
40
41
  import { marksOf } from './marks.js';
41
- import { Runner } from './runner.js';
42
+ import { DELAY_MS, Runner } from './runner.js';
42
43
 
43
44
  /** @import { Editor as EditorClass, EditorLanguage } from '@kupcad/editor' */
44
45
  /** @import { ExportFormat, Finding, ParamValues, Preview } from '@kupcad/protocol/types' */
@@ -67,6 +68,8 @@
67
68
  * (`.kc-control` gives them its look)
68
69
  * @property {readonly ShortcutGroup[]} [shortcuts] the host's own, listed before the viewer's
69
70
  * @property {boolean} [shortcutsOpen] whether the shortcuts' dialog shows; bindable
71
+ * @property {number} [runDelayMs] how long the script stays as it is after an edit before it
72
+ * runs (runner.js's DELAY_MS); a test gives 0, so a run that would come comes at once
70
73
  */
71
74
 
72
75
  /** @type {Props} */
@@ -82,20 +85,14 @@
82
85
  actions: hostActions,
83
86
  shortcuts = [],
84
87
  shortcutsOpen = $bindable(false),
88
+ runDelayMs = DELAY_MS,
85
89
  } = $props();
86
90
 
87
91
  /**
88
92
  * The settings' keys: the editor's and the parameters' widths, whether the parameters and the
89
93
  * view's panel show, the console's height and state.
90
94
  */
91
- const KEYS = {
92
- editor: 'playground.editor',
93
- params: 'playground.params',
94
- paramsOpen: 'playground.paramsOpen',
95
- panelOpen: 'playground.panelOpen',
96
- console: 'playground.console',
97
- open: 'playground.consoleOpen',
98
- };
95
+ const KEYS = { editor: 'playground.editor', ...paneKeys('playground') };
99
96
  /** The least the model is given, however wide the editor is made. */
100
97
  const MIN_VIEW = 320;
101
98
  const id = $props.id();
@@ -151,18 +148,22 @@
151
148
  onMount(() => {
152
149
  const made = kupcad ? null : createKupcadWorker(wasm ? { wasm, log } : { log });
153
150
  core = kupcad ?? made;
154
- runner = new Runner(/** @type {KupcadApi} */ (core), {
155
- onfindings: (next, of) => {
156
- if (runs && of === value) findings = next;
151
+ runner = new Runner(
152
+ /** @type {KupcadApi} */ (core),
153
+ {
154
+ onfindings: (next, of) => {
155
+ if (runs && of === value) findings = next;
156
+ },
157
+ onpreview: (preview, of) => {
158
+ if (!runs) return;
159
+ ran = { preview, source: of };
160
+ notice = '';
161
+ consoleLines = appendLines(consoleLines, linesOfRun(preview.header, name));
162
+ },
163
+ onerror: (error) => (notice = errorText(error)),
157
164
  },
158
- onpreview: (preview, of) => {
159
- if (!runs) return;
160
- ran = { preview, source: of };
161
- notice = '';
162
- consoleLines = appendLines(consoleLines, linesOfRun(preview.header, name));
163
- },
164
- onerror: (error) => (notice = errorText(error)),
165
- });
165
+ { delayMs: runDelayMs },
166
+ );
166
167
  if (value !== '') runner.run(value, {}, { now: true, files });
167
168
  return () => {
168
169
  runner?.stop();
@@ -251,9 +252,13 @@
251
252
  runner?.run(value, values, { now: true, files });
252
253
  }
253
254
 
254
- /** @param {Problem | ConsoleLine} place a problem or a console line with a line, clicked */
255
+ /**
256
+ * Shows the script where a problem or a console line is, clicked; one in a library (`file`),
257
+ * another file than the editor's, isn't shown.
258
+ * @param {{ line: number | null, column: number | null, file?: string | null }} place
259
+ */
255
260
  function reveal(place) {
256
- if (place.line !== null) editor?.reveal(place.line, place.column ?? 1);
261
+ if (place.line !== null && !place.file) editor?.reveal(place.line, place.column ?? 1);
257
262
  }
258
263
 
259
264
  /** @param {ExportFormat} format */
@@ -313,6 +318,7 @@
313
318
  {status}
314
319
  {problems}
315
320
  onproblem={reveal}
321
+ onsource={(part) => part.source && reveal({ file: null, ...part.source })}
316
322
  onscreenshot={screenshot}
317
323
  {settings}
318
324
  {shortcuts}
package/src/marks.js CHANGED
@@ -8,7 +8,8 @@
8
8
 
9
9
  /**
10
10
  * @param {readonly Finding[]} findings `check`'s
11
- * @param {readonly Problem[]} problems the run's (`problemsOf(header)`): those with a line
11
+ * @param {readonly Problem[]} problems the run's (`problemsOf(header)`): those with a line in
12
+ * the script (not in a library, `file`)
12
13
  * @returns {Mark[]}
13
14
  */
14
15
  export function marksOf(findings, problems) {
@@ -16,7 +17,8 @@ export function marksOf(findings, problems) {
16
17
  /** @type {Mark[]} */
17
18
  const placed = [];
18
19
  for (const problem of problems) {
19
- if (problem.line === null || (checked && problem.severity === 'error')) continue;
20
+ if (problem.line === null || problem.file || (checked && problem.severity === 'error'))
21
+ continue;
20
22
  const { severity, message, line } = problem;
21
23
  placed.push({ severity, message, line, column: problem.column ?? 1 });
22
24
  }