@kupcad/playground 0.1.0 → 0.1.2
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 +6 -2
- package/package.json +5 -5
- package/src/Playground.svelte +29 -11
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; the core, the console and the
|
|
28
|
+
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
|
|
@@ -74,8 +78,8 @@ pnpm test:browser # the smoke test: the page built, in headless Chromium
|
|
|
74
78
|
|
|
75
79
|
The runner's timing against a stand-in for the core, the marks, the downloads, and the component
|
|
76
80
|
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
|
|
81
|
+
run's error marked, a problem clicked revealing its line, an edit and a value running again, a
|
|
82
|
+
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
83
|
(`smoke/playground.spec.js`): the page built (`vite build`, the worker an ES module as a site's
|
|
80
84
|
build makes it) and served, the example run to Ready, its parts and parameters shown, `param`
|
|
81
85
|
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.2",
|
|
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.2",
|
|
28
|
+
"@kupcad/protocol": "0.1.2",
|
|
29
|
+
"@kupcad/ui": "0.1.2",
|
|
30
|
+
"@kupcad/wasm": "0.1.2"
|
|
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,10 @@
|
|
|
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
|
+
/** How many scripts the page loaded: the parameters' fields are made again for each. */
|
|
108
|
+
let loads = $state(0);
|
|
107
109
|
let editor = $state(/** @type {EditorClass | null} */ (null));
|
|
108
110
|
/** `check`'s findings of the script as it is, none while it changed since. */
|
|
109
111
|
let findings = $state(/** @type {Finding[]} */ ([]));
|
|
@@ -149,6 +151,19 @@
|
|
|
149
151
|
};
|
|
150
152
|
});
|
|
151
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Puts `script` in the editor in place of the one there (the editor's undo takes that back),
|
|
156
|
+
* and runs it at once on its own values: none the panel set for the last.
|
|
157
|
+
* @param {string} script another the page gives: an example, a script it opened
|
|
158
|
+
*/
|
|
159
|
+
export function load(script) {
|
|
160
|
+
value = script;
|
|
161
|
+
findings = [];
|
|
162
|
+
overrides = {};
|
|
163
|
+
loads += 1;
|
|
164
|
+
runner?.run(script, {}, { now: true });
|
|
165
|
+
}
|
|
166
|
+
|
|
152
167
|
/** @param {string} line of the core's log, which goes to the console */
|
|
153
168
|
function log(line) {
|
|
154
169
|
consoleLines = appendLines(consoleLines, linesOfLog(line));
|
|
@@ -270,13 +285,16 @@
|
|
|
270
285
|
{/if}
|
|
271
286
|
<!-- Hidden, not gone: what its fields hold stays, and the toggle has it to control -->
|
|
272
287
|
<aside class="params" id="{id}-params" aria-label="Parameters" hidden={!paramsOpen}>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
288
|
+
<!-- Made again for each script loaded: no field keeps what was typed in the last's -->
|
|
289
|
+
{#key loads}
|
|
290
|
+
<ParamsPanel
|
|
291
|
+
schema={header.params.schema}
|
|
292
|
+
values={header.params.values}
|
|
293
|
+
error={header.error}
|
|
294
|
+
bind:overrides
|
|
295
|
+
onchange={valuesChanged}
|
|
296
|
+
/>
|
|
297
|
+
{/key}
|
|
280
298
|
</aside>
|
|
281
299
|
{/if}
|
|
282
300
|
</div>
|