@kupcad/playground 0.1.1 → 0.1.3
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/README.md +10 -4
- package/package.json +5 -5
- package/src/Playground.svelte +47 -15
package/README.md
CHANGED
|
@@ -22,6 +22,10 @@ the PWA) embeds; it keeps nothing of the page's.
|
|
|
22
22
|
is called with the script at each of the person's edits (not with the `source` it was given),
|
|
23
23
|
and an `actions` snippet puts the host's own buttons in the model's toolbar, after Export
|
|
24
24
|
(`.kc-control` gives them its look). It keeps no draft: a page loaded again shows `source`.
|
|
25
|
+
* **For a host that gives it other scripts** (examples to choose from): `load(script)` (the
|
|
26
|
+
component's, by `bind:this`) puts one in the editor in place of the person's, which the
|
|
27
|
+
editor's undo takes back, and runs it at once on its own values, its model framed whole (an
|
|
28
|
+
edit's keeps the camera); the core, the console and the layout stay as they are.
|
|
25
29
|
* **When it runs** (`runner.js`, `Runner`): once the script stays as it is for a moment after an
|
|
26
30
|
edit (`DELAY_MS`, 300), at once when a parameter's value changes or it starts. A run under
|
|
27
31
|
way when the next starts is stopped (the worker drops or ends its call), so what is shown is
|
|
@@ -40,8 +44,10 @@ the PWA) embeds; it keeps nothing of the page's.
|
|
|
40
44
|
resize them (`@kupcad/ui`'s `Splitter`), and the toolbar's Parameters button hides the
|
|
41
45
|
parameters for the model's width; the sizes, and what is hidden or folded, are kept in
|
|
42
46
|
`settings`, by default the page's localStorage (`localSettings`, the `playground.*` keys), and
|
|
43
|
-
how the view looks too (the pane's `view.*` keys), all followed as they are set
|
|
44
|
-
stacks the panes
|
|
47
|
+
how the view looks too (the pane's `view.*` keys), all followed as they are set. A page 800px
|
|
48
|
+
wide or less stacks the panes, each at a height of its own (the script a few lines, the model
|
|
49
|
+
4:3 of its width, at most 32em, the console and the parameters as tall as their lines), and
|
|
50
|
+
the playground scrolls; on a phone the view's panel is under the model (`ViewerPane`'s).
|
|
45
51
|
* **The console** (`@kupcad/ui`'s `ConsolePanel`, under the model): each run, what it printed
|
|
46
52
|
(`puts`, `print`, `inspect`), its warnings and its error, a line naming a place taking the
|
|
47
53
|
editor there, and the core's log (the worker module's stdout and stderr).
|
|
@@ -74,8 +80,8 @@ pnpm test:browser # the smoke test: the page built, in headless Chromium
|
|
|
74
80
|
|
|
75
81
|
The runner's timing against a stand-in for the core, the marks, the downloads, and the component
|
|
76
82
|
on the real core (`@kupcad/wasm`'s `testCore`) under jsdom: the model shown, the findings and the
|
|
77
|
-
run's error marked, a problem clicked revealing its line, an edit and a value running again,
|
|
78
|
-
export downloaded and one refused. In a browser, with the real worker, the smoke test
|
|
83
|
+
run's error marked, a problem clicked revealing its line, an edit and a value running again, a
|
|
84
|
+
script loaded in place of the one shown, an export downloaded and one refused. In a browser, with the real worker, the smoke test
|
|
79
85
|
(`smoke/playground.spec.js`): the page built (`vite build`, the worker an ES module as a site's
|
|
80
86
|
build makes it) and served, the example run to Ready, its parts and parameters shown, `param`
|
|
81
87
|
highlighted as a function, and a script that raises saying so.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kupcad/playground",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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.
|
|
28
|
-
"@kupcad/protocol": "0.1.
|
|
29
|
-
"@kupcad/ui": "0.1.
|
|
30
|
-
"@kupcad/wasm": "0.1.
|
|
27
|
+
"@kupcad/editor": "0.1.3",
|
|
28
|
+
"@kupcad/protocol": "0.1.3",
|
|
29
|
+
"@kupcad/ui": "0.1.3",
|
|
30
|
+
"@kupcad/wasm": "0.1.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@codemirror/lint": "^6.9.7",
|
package/src/Playground.svelte
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
bars between the panes resize them, and the toolbar's Parameters button hides theirs (for the
|
|
10
10
|
model's width); the sizes, what is hidden or folded, and how the view looks are kept in
|
|
11
11
|
`settings` (the page's localStorage by default), and follow them as they are set. It keeps
|
|
12
|
-
nothing else of the page's: the page gives the script it starts with (`source`)
|
|
13
|
-
of each edit of it (`onsource`), for its own buttons in the
|
|
14
|
-
save it.
|
|
12
|
+
nothing else of the page's: the page gives the script it starts with (`source`) and another
|
|
13
|
+
in its place (`load`), and is told of each edit of it (`onsource`), for its own buttons in the
|
|
14
|
+
toolbar (`actions`) to share or save it.
|
|
15
15
|
-->
|
|
16
16
|
<script>
|
|
17
17
|
import { onMount, untrack } from 'svelte';
|
|
@@ -102,8 +102,13 @@
|
|
|
102
102
|
/** The playground's width, once laid out. */
|
|
103
103
|
let width = $state(0);
|
|
104
104
|
|
|
105
|
-
/** The script as the editor has it: the user's, from the one the page gave
|
|
105
|
+
/** The script as the editor has it: the user's, from the one the page gave last. */
|
|
106
106
|
let value = $state(untrack(() => source));
|
|
107
|
+
/**
|
|
108
|
+
* How many scripts the page loaded: the parameters' fields are made again for each, and the
|
|
109
|
+
* view frames each one's model whole (another subject), where an edit's keeps the camera.
|
|
110
|
+
*/
|
|
111
|
+
let loads = $state(0);
|
|
107
112
|
let editor = $state(/** @type {EditorClass | null} */ (null));
|
|
108
113
|
/** `check`'s findings of the script as it is, none while it changed since. */
|
|
109
114
|
let findings = $state(/** @type {Finding[]} */ ([]));
|
|
@@ -149,6 +154,20 @@
|
|
|
149
154
|
};
|
|
150
155
|
});
|
|
151
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Puts `script` in the editor in place of the one there (the editor's undo takes that back),
|
|
159
|
+
* and runs it at once on its own values (none the panel set for the last), its model framed
|
|
160
|
+
* whole.
|
|
161
|
+
* @param {string} script another the page gives: an example, a script it opened
|
|
162
|
+
*/
|
|
163
|
+
export function load(script) {
|
|
164
|
+
value = script;
|
|
165
|
+
findings = [];
|
|
166
|
+
overrides = {};
|
|
167
|
+
loads += 1;
|
|
168
|
+
runner?.run(script, {}, { now: true });
|
|
169
|
+
}
|
|
170
|
+
|
|
152
171
|
/** @param {string} line of the core's log, which goes to the console */
|
|
153
172
|
function log(line) {
|
|
154
173
|
consoleLines = appendLines(consoleLines, linesOfLog(line));
|
|
@@ -210,6 +229,7 @@
|
|
|
210
229
|
<div class="model">
|
|
211
230
|
<ViewerPane
|
|
212
231
|
model={ran?.preview.model ?? null}
|
|
232
|
+
subject="script {loads}"
|
|
213
233
|
options={viewerOptions}
|
|
214
234
|
bind:panel={() => panelOpen, (open) => settings.set(KEYS.panelOpen, open)}
|
|
215
235
|
{status}
|
|
@@ -270,13 +290,16 @@
|
|
|
270
290
|
{/if}
|
|
271
291
|
<!-- Hidden, not gone: what its fields hold stays, and the toggle has it to control -->
|
|
272
292
|
<aside class="params" id="{id}-params" aria-label="Parameters" hidden={!paramsOpen}>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
293
|
+
<!-- Made again for each script loaded: no field keeps what was typed in the last's -->
|
|
294
|
+
{#key loads}
|
|
295
|
+
<ParamsPanel
|
|
296
|
+
schema={header.params.schema}
|
|
297
|
+
values={header.params.values}
|
|
298
|
+
error={header.error}
|
|
299
|
+
bind:overrides
|
|
300
|
+
onchange={valuesChanged}
|
|
301
|
+
/>
|
|
302
|
+
{/key}
|
|
280
303
|
</aside>
|
|
281
304
|
{/if}
|
|
282
305
|
</div>
|
|
@@ -330,26 +353,35 @@
|
|
|
330
353
|
background: var(--kc-bg);
|
|
331
354
|
}
|
|
332
355
|
/* A narrow page: the script over the model, the parameters under it */
|
|
356
|
+
/* Narrow, the panes stacked, each at a height of its own, and the playground scrolled: the
|
|
357
|
+
script a few lines, the model 4:3 of its width (at most 32em), the console and the
|
|
358
|
+
parameters as tall as their lines */
|
|
333
359
|
@media (max-width: 800px) {
|
|
334
360
|
.kc-playground {
|
|
335
361
|
flex-direction: column;
|
|
362
|
+
overflow-y: auto;
|
|
336
363
|
}
|
|
337
364
|
/* Stacked, each the page's width: the columns' bars have nothing to resize */
|
|
338
365
|
.kc-playground > :global(.kc-splitter.columns) {
|
|
339
366
|
display: none;
|
|
340
367
|
}
|
|
341
368
|
.code {
|
|
342
|
-
flex
|
|
369
|
+
flex: none;
|
|
343
370
|
width: auto;
|
|
371
|
+
height: 20em;
|
|
344
372
|
border-right: none;
|
|
345
373
|
border-bottom: 1px solid var(--kc-border);
|
|
346
374
|
}
|
|
347
|
-
.view
|
|
348
|
-
|
|
349
|
-
|
|
375
|
+
.view,
|
|
376
|
+
.model {
|
|
377
|
+
flex: none;
|
|
378
|
+
}
|
|
379
|
+
.model {
|
|
380
|
+
--kc-model-min-height: min(75cqw, 32em);
|
|
350
381
|
}
|
|
351
382
|
.params {
|
|
352
383
|
width: auto;
|
|
384
|
+
overflow: visible;
|
|
353
385
|
border-left: none;
|
|
354
386
|
border-top: 1px solid var(--kc-border);
|
|
355
387
|
}
|