Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/editor_ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Editor UI

on:
push:
branches: [ "master" ]
tags: [ "editor-ui-v*" ]
pull_request:
branches: [ "**" ]

permissions:
contents: read

concurrency:
group: editor-ui-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
working-directory: editor-ui

jobs:
test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# The tests run the editor against bust's bridge over stdio.
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.13"
- run: pip install -e ..
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
cache: npm
cache-dependency-path: editor-ui/package-lock.json
- run: npm ci
- run: npm test
env:
PYTHON: python
- run: npm pack --dry-run

# Pushing a tag editor-ui-vX.Y.Z publishes that version to npm, with npm
# trusted publishing, so no token is stored here. The package must exist on
# npm with this workflow set as its trusted publisher.
publish:
needs: test
if: startsWith(github.ref, 'refs/tags/editor-ui-v')
runs-on: ubuntu-24.04
environment: npm
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Check that the tag matches the package version
run: |
version="$(node -p 'require("./package.json").version')"
if [ "editor-ui-v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match version $version in editor-ui/package.json"
exit 1
fi
- run: npm ci
- run: npm run build
- run: npm publish --provenance --access public
2 changes: 2 additions & 0 deletions editor-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
1 change: 1 addition & 0 deletions editor-ui/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
38 changes: 38 additions & 0 deletions editor-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# bust-editor

The register map editor of [bust](https://github.com/logvik-org/bust), for the web. Like bust's console editor, it shows the registers in a table, the fields and bits of the selected register below, and the keys of the one in focus beside them. Right-click or Shift+F10 on a register or field opens a menu of what to do with it, and changes go through dialogs built from bust's JSON Schema. [cloudbust](https://cloudbust.org) runs it with bust in the browser.

The editor never changes a register map itself. Every change goes to bust as JSON Patch operations, and bust either makes it or rejects it with its problems, which the editor shows next to the values they are about. So the editor only ever holds register maps bust accepts.

## Use

```ts
import { BustBridge, RegisterMapEditor } from "bust-editor";
import "bust-editor/style.css";

const bridge = new BustBridge(transport);
const editor = new RegisterMapEditor(container, bridge, {
onChange: (state) => console.log(state.text),
});
await editor.open(registerMapText);
```

`transport` takes one JSON-RPC 2.0 request as a string and resolves to bust's response. bust answers these in `bust.editing.bridge`: call `EditorBridge().handle(request)` in Python (Pyodide in a browser), or run `python -m bust.editing.bridge` and exchange one message per line over stdin and stdout. The methods are listed in [bridge.py](../bust/editing/bridge.py).

The look follows bust's documentation, in light and dark. Set the `--bust-*` variables named at the top of `style.css` to theme it.

## Develop

Node.js 22.12 or newer, and a Python with bust installed for the tests:

```sh
pip install -e ..
npm ci
PYTHON=python npm test
```

`npm test` builds `dist/` and runs the editor in happy-dom against a bust bridge process.

## Release

Set `version` in `package.json` and push a tag `editor-ui-vX.Y.Z`. The Editor UI workflow tests the package and publishes it to npm with trusted publishing.
146 changes: 146 additions & 0 deletions editor-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions editor-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "bust-editor",
"version": "0.1.0",
"description": "Register map editor for bust, the VHDL register file generator",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/logvik-org/bust.git",
"directory": "editor-ui"
},
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./style.css": "./dist/style.css"
},
"files": [
"dist"
],
"sideEffects": [
"*.css"
],
"engines": {
"node": ">=22.12"
},
"scripts": {
"build": "tsc && cp src/style.css dist/",
"test": "npm run build && node --test tests/*.test.mjs"
},
"devDependencies": {
"@types/node": "22.20.5",
"happy-dom": "21.0.3",
"typescript": "5.9.3"
}
}
40 changes: 40 additions & 0 deletions editor-ui/src/diagram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { element } from "./dom.js";
import type { BitSegment } from "./protocol.js";

// A register's bits from the highest down, drawn as bust's documentation
// draws them: a box per field with its name, its bit numbers above and its
// reset value below. Unused bits are a dashed box.
export function bitDiagram(
segments: BitSegment[],
selectedName: string | undefined,
onSelect?: (name: string) => void,
): HTMLElement {
const width = segments.reduce((highest, segment) => Math.max(highest, segment.high + 1), 0);
const diagram = element("div", { class: "bust-editor-diagram", role: "group", "aria-label": "Bits" });
diagram.style.setProperty("--bust-editor-bit-count", String(width));
for (const segment of segments) {
const column = `${width - segment.high} / ${width - segment.low + 1}`;
const numbers =
segment.high === segment.low
? [element("span", {}, String(segment.high))]
: [element("span", {}, String(segment.high)), element("span", {}, String(segment.low))];
const label = element("span", { class: "bust-editor-diagram-bits" }, ...numbers);
const box = segment.isUnused || !onSelect
? element("span", { class: "bust-editor-diagram-box" }, element("span", {}, segment.isUnused ? "" : segment.name))
: element("button", { type: "button", class: "bust-editor-diagram-box", title: segment.name }, element("span", {}, segment.name));
if (box instanceof HTMLButtonElement) {
box.addEventListener("click", () => onSelect!(segment.name));
if (segment.name === selectedName) {
box.setAttribute("aria-current", "true");
}
}
const reset = element("span", { class: "bust-editor-diagram-reset" }, segment.reset);
const cell = element("div", { class: "bust-editor-diagram-segment" }, label, box, reset);
if (segment.isUnused) {
cell.classList.add("bust-editor-unused");
}
cell.style.gridColumn = column;
diagram.append(cell);
}
return diagram;
}
20 changes: 20 additions & 0 deletions editor-ui/src/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function element<K extends keyof HTMLElementTagNameMap>(
tag: K,
attributes: Record<string, string> = {},
...children: (Node | string)[]
): HTMLElementTagNameMap[K] {
const created = document.createElement(tag);
for (const [name, value] of Object.entries(attributes)) {
created.setAttribute(name, value);
}
created.append(...children);
return created;
}

export function hex(value: number, digits: number): string {
return "0x" + value.toString(16).toUpperCase().padStart(digits, "0");
}

export function bitRange(low: number, high: number): string {
return low === high ? `[${low}]` : `[${high}:${low}]`;
}
Loading
Loading