diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a33de0c..17caa58 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,8 +26,9 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 45 # The wasm CI image: Rust stable 1.99.1 with the wasm32 targets, - # wasm-bindgen 0.2.127 and binaryen (wasm-opt), which is what - # `comline-simulator`'s `prepack` needs to build its WASM. + # wasm-bindgen 0.2.127, wasm-pack and binaryen (wasm-opt), which is what + # `comline-simulator`'s and `comline-web-kit`'s `prepack`s need to build + # their WASM. container: ghcr.io/comlineproject/ci-wasm@sha256:74efbad4c8b06d554d28e8a1e486f12ae5b6b4bd15a15db21a0925e020caa40a steps: - name: Checkout @@ -45,10 +46,11 @@ jobs: - name: Yarn run: corepack enable - # `comline-web-kit` (the playground's simulate view) is a git dependency, - # and so is its engine, `comline-simulator`, which compiles to WASM in - # its `prepack` (Rust to wasm-bindgen). The image has cargo, wasm-bindgen - # and wasm-opt; this caches the registry and git checkouts across runs. + # `comline-web-kit` (the playground's editor and simulate view) is a git + # dependency, and so is the sim's engine, `comline-simulator`. Both + # compile to WASM in their `prepack`: the kit builds the editor (the + # compiler and language server) with wasm-pack, the simulator with + # wasm-bindgen. This caches the registry and git checkouts across runs. - name: Cache cargo uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -60,18 +62,19 @@ jobs: # Yarn Berry's global cache holds the packed `comline-web-kit` and the # built `comline-simulator` archives: a hit skips the Rust build entirely. + # (`yarn-editor-`: caches from before the tutorial used the editor hold a + # kit packed without it, so they're never restored.) - name: Cache yarn uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ~/.yarn/berry/cache - key: ${{ runner.os }}-${{ runner.arch }}-yarn-${{ hashFiles('yarn.lock') }} - restore-keys: ${{ runner.os }}-${{ runner.arch }}-yarn- + key: ${{ runner.os }}-${{ runner.arch }}-yarn-editor-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-${{ runner.arch }}-yarn-editor- # Yarn's `npmMinimalAgeGate` (its default, one day) stays on. - name: Install dependencies env: COMLINE_SIMULATOR_SCRIPT: '0' # the tutorial only needs the lean sim - COMLINE_KIT_EDITOR: '0' # and not the kit's editor WASM run: yarn install - name: build diff --git a/package.json b/package.json index f641587..5c82e0a 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,13 @@ }, "type": "module", "dependencies": { + "@codemirror/lang-javascript": "^6.2.5", + "@codemirror/lang-rust": "^6.0.2", + "@codemirror/language": "^6.10.0", + "@codemirror/state": "^6.4.0", + "@codemirror/view": "^6.34.0", "@sveltejs/adapter-static": "^3.0.10", - "comline-web-kit": "git+https://github.com/ComlineProject/playground.git#workspace=comline-web-kit&commit=fe53d2edcd25cf8bcd77d9f52a3c2ec09d453136" + "comline-web-kit": "git+https://github.com/ComlineProject/playground.git#workspace=comline-web-kit&commit=f6077cc1a176f1cedd70225e804774e0ca4d00bc" }, "resolutions": { "cookie": "^0.7.2", diff --git a/src/app.html b/src/app.html index 77a5ff5..1d7491d 100644 --- a/src/app.html +++ b/src/app.html @@ -4,6 +4,12 @@ + + %sveltekit.head% diff --git a/src/lib/editor/Code.svelte b/src/lib/editor/Code.svelte new file mode 100644 index 0000000..dfb6dee --- /dev/null +++ b/src/lib/editor/Code.svelte @@ -0,0 +1,72 @@ + + + + +{#each tokens as t, i (i)}{t.text}{/each} + + diff --git a/src/lib/editor/SchemaEditor.svelte b/src/lib/editor/SchemaEditor.svelte new file mode 100644 index 0000000..0c669bb --- /dev/null +++ b/src/lib/editor/SchemaEditor.svelte @@ -0,0 +1,327 @@ + + +
+
+ {file} + + +
+ + +
+
+ +
+ {#if failure} +

The compiler failed: {failure}

+ {:else if errors.length > 0} +
+

+ {errors.length === 1 ? '1 error' : `${errors.length} errors`}{stale + ? ' (before your last edit)' + : ''}: +

+
    + {#each errors as e, i (i)} +
  • line {e.range.start.line + 1}: {e.message}
  • + {/each} +
+
+ {:else if output} +

+ Compiled into {output.length === 1 ? '1 file' : `${output.length} files`}{stale + ? ' (before your last edit: compile again to update)' + : ''}. +

+ {#if output.length > 1} +
+ {#each output as f, i (f.path)} + + {/each} +
+ {/if} + {#if output[shown]} +
+ {/if} + {:else} +

Press Compile to generate code from the schema.

+ {/if} +
+
+
+ + diff --git a/src/lib/paging.ts b/src/lib/paging.ts index 8c905e1..667464e 100644 --- a/src/lib/paging.ts +++ b/src/lib/paging.ts @@ -8,15 +8,33 @@ export interface Page { name: string } -/** Every tutorial page, in reading order. `pageUrl(id)` resolves against this - * and `NavigationTable` lists it. Ids are stable — add entries as routes land. */ -export const PAGES: Page[] = [ - { id: "p1", url: "part-1_introduction", name: "Introduction" }, - { id: "p1-s1", url: "part-1_introduction/sect-1_what-is-comline", name: "What is Comline?" }, - { id: "p1-s2", url: "part-1_introduction/sect-2_how-is-comline", name: "How is Comline?" }, - { id: "p1-s3", url: "part-1_introduction/sect-3_try-it", name: "Try it" }, +/** A part of the tutorial: its own page, then its sections. */ +export interface Part extends Page { + sections: Page[] +} + +/** The tutorial as a tree, which `NavigationTable` draws. Ids are stable — + * add entries as routes land. */ +export const PARTS: Part[] = [ + { id: "p1", url: "part-1_introduction", name: "Introduction", sections: [ + { id: "p1-s1", url: "part-1_introduction/sect-1_what-is-comline", name: "What is Comline?" }, + { id: "p1-s2", url: "part-1_introduction/sect-2_how-is-comline", name: "How is Comline?" }, + { id: "p1-s3", url: "part-1_introduction/sect-3_try-it", name: "Try it" }, + ] }, + { id: "p2", url: "part-2_basics", name: "Basics", sections: [ + { id: "p2-s1", url: "part-2_basics/sect-1_your-first-schema", name: "Your first schema" }, + { id: "p2-s2", url: "part-2_basics/sect-2_structs-and-enums", name: "Structs and enums" }, + { id: "p2-s3", url: "part-2_basics/sect-3_protocols", name: "Protocols" }, + ] }, + { id: "p3", url: "part-3_generating-code", name: "Generating code", sections: [ + { id: "p3-s1", url: "part-3_generating-code/sect-1_running-the-generator", name: "Running the generator" }, + { id: "p3-s2", url: "part-3_generating-code/sect-2_using-the-generated-code", name: "Using the generated code" }, + ] }, ] +/** Every tutorial page, in reading order. `pageUrl(id)` resolves against this. */ +export const PAGES: Page[] = PARTS.flatMap(({ sections, ...part }) => [part, ...sections]) + export const baseUrl = dev ? '/' : base + '/' /** The URL for a page id, or `null` when that page does not exist yet — callers diff --git a/src/lib/sim/Simulation.svelte b/src/lib/sim/Simulation.svelte index 3bce105..f2ccd43 100644 --- a/src/lib/sim/Simulation.svelte +++ b/src/lib/sim/Simulation.svelte @@ -50,14 +50,17 @@ diff --git a/src/lib/ui/ThemeToggle.svelte b/src/lib/ui/ThemeToggle.svelte new file mode 100644 index 0000000..9cee313 --- /dev/null +++ b/src/lib/ui/ThemeToggle.svelte @@ -0,0 +1,47 @@ + + + + + diff --git a/src/lib/ui/navigation_button.svelte b/src/lib/ui/navigation_button.svelte index 0b52d09..241ff03 100644 --- a/src/lib/ui/navigation_button.svelte +++ b/src/lib/ui/navigation_button.svelte @@ -5,7 +5,9 @@ - + + {text} @@ -16,15 +18,20 @@ padding: 10px 20px; cursor: pointer; text-decoration: none; - background-color: #322922; - color: #DBB594; - border-color: #4D3C2F; + background-color: var(--btn-bg); + color: var(--btn-fg); + border-color: var(--btn-border); border-style: ridge; } .btn:hover { - background-color: #3E3128; + background-color: var(--btn-hover); } .btn:active { - background-color: #28211D; + background-color: var(--btn-active); + } + .btn.disabled { + cursor: default; + opacity: 0.4; + background-color: var(--btn-bg); } diff --git a/src/lib/ui/navigation_table.svelte b/src/lib/ui/navigation_table.svelte index 955d8bb..2f8d57a 100644 --- a/src/lib/ui/navigation_table.svelte +++ b/src/lib/ui/navigation_table.svelte @@ -1,15 +1,115 @@ -