docs

Designer (web editor)

The designer is a browser-based editor for Liuska templates. It ships inside the liuska binary. Its live preview is rendered by the real engine through /api/preview, so what you see is exactly what liuska render produces.

Running it

liuska serve --templates ./templates

Then open http://127.0.0.1:8080.

Working with templates

The screen has a canvas showing the page, an element palette, a properties panel for the selected element, and a data panel.

  1. Page setup: choose the size, orientation and margins. The header and footer bands are shown on the canvas, and their heights are set in the page properties.
  2. Add elements from the palette (text, rect, line, image, table, chart, group), then drag to move and use the handles to resize. Header and footer elements are placed inside their band.
  3. Properties: position and size (in pt, or a unit string such as 10mm or 50%), style properties, a named style, visibleIf, and type-specific options such as text overflow or image fit.
  4. Bindings: type {{customer.name}} into text content. Filters work as in the format: {{ total | currency:"EUR" }}. See templates.md.
  5. Tables: set the data path, then choose fixed columns (edit key, header, width, align and format per column), columnsFrom (a data path), or autoColumns. Header, row and alt-row styles, borders and totals are set in the panel.
  6. Charts: pick the kind (bar, line, area, pie, donut, scatter) and set the data path and the category key. Then choose fixed series (key, label, color, format, and per series the kind and left/right axis for combo charts), seriesFrom (a data path) or autoSeries. Stacking, horizontal bars, title, legend position, axis labels, ranges, tick formats and label rotation, data labels and palette are set in the panel. The chart is drawn by the engine in the preview, so it looks exactly as in the PDF. See templates.md.
  7. Anchors: to make an element follow a growing table (totals, notes, signature), anchor its top edge to the table's bottom edge with an offset. Charts anchor the same way, and a table can be anchored under a chart.
  8. Sample data: paste or load JSON in the data panel. The canvas, preview and validation use it, but it is not part of the template: loading or pasting data does not mark the template as changed. The designer keeps it per template in the browser (localStorage), so it is there again next time you open the template. Embed in template writes it into the template as sampleData (saved with it; Remove from template takes it out again). A template's sampleDataFile is loaded automatically through the server, relative to its --templates directory (GET /api/sample-data); when the server can't provide it (no --templates, file elsewhere), use Pick file…. When a template is opened, the browser copy wins over embedded sampleData, which wins over sampleDataFile; Use embedded / Clear drop the browser copy.
  9. Pages: the canvas shows every page of the document, stacked vertically, laid out by the engine (POST /api/layout) with the current sample data. Tables continue onto the following pages (each part shows its rows and a 2/5 badge), elements anchored under a table appear where the table ends, repeated elements are drawn on each page they repeat on, the header and footer are on every page (with that page's {{page}}), and elements after a pageBreak are on their own pages. Everything is editable on any page: click, drag, resize or nudge an element wherever it appears. A drag moves the element immediately and the page layout catches up a moment later. Header, footer and repeated elements get their handles on the page you clicked. The pager and thumbnails at the top right jump between pages. The dot next to the pager is green when the layout is current, amber while it updates, and grey when the server is not running. In that case pages come from page breaks only, and tables show their first page.
  10. Preview: the preview re-renders as you edit and pages through multi-page output (page N of M). The server renders the page as a one-page PDF (/api/preview?format=pdf) and the designer draws it with pdf.js, loaded the first time the preview runs. If pdf.js cannot run in the browser, the preview falls back to PNGs rendered by the server. Validation issues from /api/validate, such as unknown bindings or bad formats, are listed with the element they refer to.
  11. Save: this writes template v1 JSON. The file works with liuska render, batch and the HTTP API, and can be edited by hand, with schema validation in VS Code via $schema.

Developing the designer

liuska serve                 # API on :8080 (or from source: go -C generator run . serve)
cd editor-web
npm install
npm run dev                  # http://localhost:5173, proxies /api -> http://127.0.0.1:8080

Other scripts:

npm run typecheck
npm test
npm run build                # -> editor-web/dist

To check a production build without rebuilding the Go binary, run liuska serve --editor-dir editor-web/dist. Release builds embed editor-web/dist into liuska (see .github/workflows/release.yml).