From 225ade036b1ad29de8287ac53a8c66244bcc8364 Mon Sep 17 00:00:00 2001 From: Kinflou <149606337+Kinflou@users.noreply.github.com> Date: Sun, 15 Nov 2026 00:17:36 +0800 Subject: [PATCH 1/2] Page layout, a navigation tree, a schema-editor lesson and a light theme - Layout: the page fills the window and never scrolls. The navigation runs down the left side, the content scrolls beside it, and the Back/Next bar stays at the bottom. On a narrow screen the navigation goes on top. - Navigation: a tree of parts and their sections, built from PARTS in paging.ts. The part being read starts open, and the current page is marked. - Chapters: placeholder pages for Part 2 (Basics) and Part 3 (Generating code). - "Your first schema" (2.1): the lesson on the left, and on the right the playground's editor (comline-web-kit/editor) with a Compile button. Compiling shows the generated Rust or TypeScript beside the schema, or lists the errors. Any page can put a workspace beside its lesson with slot="workspace". A Code component colours inline schema snippets the way the editor does. - Theme: dark stays the default. A header toggle switches to a warm light theme and remembers the choice. All colours are variables in global.css. - Build: the kit's editor WASM is now built (COMLINE_KIT_EDITOR=0 is gone from CI), and the yarn cache key changed so an old kit packed without the editor isn't restored. --- .github/workflows/deploy.yml | 21 +- package.json | 7 +- src/app.html | 6 + src/lib/editor/Code.svelte | 72 ++++ src/lib/editor/SchemaEditor.svelte | 327 ++++++++++++++++++ src/lib/paging.ts | 32 +- src/lib/sim/Simulation.svelte | 19 +- src/lib/ui/ThemeToggle.svelte | 47 +++ src/lib/ui/navigation_button.svelte | 19 +- src/lib/ui/navigation_table.svelte | 110 +++++- src/lib/ui/tutorial_page.svelte | 125 ++++++- src/routes/+layout.svelte | 40 ++- src/routes/part-1_introduction/+page.svelte | 3 +- .../sect-1_what-is-comline/+page.svelte | 2 +- .../sect-3_try-it/+page.svelte | 2 +- src/routes/part-2_basics/+page.svelte | 10 + .../sect-1_your-first-schema/+page.svelte | 44 +++ .../sect-2_structs-and-enums/+page.svelte | 10 + .../sect-3_protocols/+page.svelte | 10 + .../part-3_generating-code/+page.svelte | 10 + .../sect-1_running-the-generator/+page.svelte | 10 + .../+page.svelte | 10 + src/styles/global.css | 91 ++++- tests/first-schema.test.ts | 29 ++ tests/navigation.test.ts | 37 ++ tests/theme.test.ts | 23 ++ vite.config.ts | 5 + yarn.lock | 72 +++- 28 files changed, 1121 insertions(+), 72 deletions(-) create mode 100644 src/lib/editor/Code.svelte create mode 100644 src/lib/editor/SchemaEditor.svelte create mode 100644 src/lib/ui/ThemeToggle.svelte create mode 100644 src/routes/part-2_basics/+page.svelte create mode 100644 src/routes/part-2_basics/sect-1_your-first-schema/+page.svelte create mode 100644 src/routes/part-2_basics/sect-2_structs-and-enums/+page.svelte create mode 100644 src/routes/part-2_basics/sect-3_protocols/+page.svelte create mode 100644 src/routes/part-3_generating-code/+page.svelte create mode 100644 src/routes/part-3_generating-code/sect-1_running-the-generator/+page.svelte create mode 100644 src/routes/part-3_generating-code/sect-2_using-the-generated-code/+page.svelte create mode 100644 tests/first-schema.test.ts create mode 100644 tests/navigation.test.ts create mode 100644 tests/theme.test.ts 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..d382b61 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=2e058f14451ec96da0d72ab462abd89697773132" }, "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 @@ -