components

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

templ: version: v0.3.1001

Index

Constants

View Source
const CtxTileLocation = "tileLocation"

CtxTileLocation is where a handler leaves "<stack> / <env>" for the panel header to pick up.

A context stash rather than another parameter: every panel path already funnels through its handler's load(), and the app panel component takes thirteen arguments as it is. A path that skips load() simply renders no location, which is a missing line rather than a wrong one.

View Source
const CtxTileLocationColor = "tileLocationColor"

CtxTileLocationColor is the env colour beside it, stashed by the same call.

View Source
const CtxUpperEnv = "upperEnv"

CtxUpperEnv marks a tile living above the default env: the ladder's upper rungs get images by Promote on the releases page, so the tile's own Deploy button (a build from branch head) is hidden there.

Variables

View Source
var BaseURL string

BaseURL is the application's public origin (e.g. "https://example.com"). Empty in dev; set from main via the BASE_URL env var.

View Source
var StaticBaseURL = "/static"

StaticBaseURL is the base URL prefix for static assets. Set from main before any templates render.

View Source
var StaticManifest = map[string]string{
	"css/output.css":              "css/output.7e55e08bc1a4.css",
	"css/xterm.css":               "css/xterm.ba8e69856694.css",
	"images/apple-touch-icon.png": "images/apple-touch-icon.bf7ad3fd7ca1.png",
	"images/favicon-32.png":       "images/favicon-32.714289f559fa.png",
	"images/logo-mark.png":        "images/logo-mark.c7991eef2bbb.png",
	"js/codearea.js":              "js/codearea.92dd2a127302.js",
	"js/graph.js":                 "js/graph.d5b43ba587e1.js",
	"js/htmx.min.js":              "js/htmx.min.e209dda5c823.js",
	"js/live.js":                  "js/live.5db5b8066b4b.js",
	"js/logs.js":                  "js/logs.9f54f40bb54a.js",
	"js/main.js":                  "js/main.74e11d7962d3.js",
	"js/metrics.js":               "js/metrics.70604865d5ad.js",
	"js/ws.js":                    "js/ws.8bd2672afd0a.js",
	"js/xterm.min.js":             "js/xterm.min.4196e242ef1c.js",
}

StaticManifest maps original asset paths to fingerprinted paths.

Functions

func AuditList

func AuditList(events []repo.AuditEvent) templ.Component

AuditList is the secret trail for one scope: who read or wrote which value, and when. Reads are the point of it, a write already shows up as a changed value, but a reveal or a copy leaves no other trace.

func Avatar

func Avatar(path, name, sizeClasses string) templ.Component

Avatar renders an uploaded image, or the initials badge that every surface showed before uploads existed. sizeClasses carries the dimensions so callers keep control of scale (the sidebar badge and a members row are not the same size), and both branches use them so nothing shifts when someone uploads.

func CSRFFieldShell

func CSRFFieldShell(c echo.Context) templ.Component

func ConfirmDanger

func ConfirmDanger(c echo.Context, cfg ConfirmCfg) templ.Component

ConfirmDanger is the in-page version of the type-the-name guard the node Remove modal introduced. Destroying data is worth the friction: a named button is one mis-click, and none of this is undoable (docs/notes.md, misc, better delete guards).

func Confirmed

func Confirmed(c echo.Context, want string) bool

Confirmed reports whether the POST carries the exact name the operator was asked to type. Every delete that destroys data uses it, so the check is in one place: the browser only disables a button, and a disabled button is not a guard.

An empty expectation is never satisfiable. A row with no name would otherwise be removable by sending nothing at all, which is the opposite of what confirm-by-typing is for.

func EnvColor

func EnvColor(ctx context.Context, store repo.Store, stackID, envID string) string

EnvColor resolves one env's colour through the stack's ladder and org. Best-effort: "" on any lookup failure.

func EnvColorFromForm

func EnvColorFromForm(radio, custom string) (v string, ok bool)

EnvColorFromForm reads the picker: the radio, or the custom input when the custom radio is ticked. ok is false for a value envcolor rejects.

func EnvColorPicker

func EnvColorPicker(current string) templ.Component

EnvColorPicker is the six palette hues, "default" (clears the override), and a native colour input for anything else. Radios named color; picking a custom colour ticks the "custom" radio and the handler reads the input.

func EnvColorSource

func EnvColorSource(source string) templ.Component

EnvColorSource is the pill saying where a colour came from.

func EnvDot

func EnvDot(css, size string) templ.Component

EnvDot is the coloured dot beside an environment's name. css is an envcolor CSS value; size overrides the default 8px.

func ErrorPage

func ErrorPage(code int, message string) templ.Component

ErrorPage returns a templ component that renders an error page. This satisfies the middleware.ErrorPage signature.

func FlashOOB

func FlashOOB(c echo.Context) templ.Component

FlashOOB carries a flash on an htmx fragment response. A panel save swaps only its own region, so without this out-of-band swap the confirmation the handler set would never reach the user at the moment they saved.

func FlashTailwindClass

func FlashTailwindClass(t middleware.FlashType) string

FlashTailwindClass returns Tailwind CSS classes for a flash type.

func FlashToast

func FlashToast(c echo.Context) templ.Component

FlashToast renders the pending flash, if any. Reading it clears the cookie, so it shows exactly once.

func Initials

func Initials(name string) string

Initials picks up to two leading letters for the fallback badge. Words are what you would expect ("Fyrm Forge" is FF), plus a capital inside a word starts a new one, because product names are routinely written closed up ("FyrmForge" is FF, not F).

func Layout

func Layout(c echo.Context, title string) templ.Component

func Loading added in v0.3.0

func Loading(text string) templ.Component

Loading is the placeholder a lazy fragment shows until its hx-get answers.

func LogText

func LogText(text string) templ.Component

LogText renders stored output through the same viewer: search, level colouring and wrap, no SSE. The text is written into the lines element so it still reads without JavaScript; logs.js takes it from there.

func LogView

func LogView(streamURL string, multi bool) templ.Component

The live log viewer: SSE follow, search, level filter, timestamp/wrap toggles, JSON-aware rows (static/js/logs.js drives it). multi marks merged environment streams whose lines carry a "tile|" prefix.

LogView is the compact variant for drawer tabs; LogViewFull fills the remaining viewport height (use inside ShellFull), the Dozzle-style full-page experience. LogText is the same viewer over output that is already finished and stored (a cron run), with no stream behind it.

func LogViewFull

func LogViewFull(streamURL string, multi bool) templ.Component

func MetricChart

func MetricChart(label string, unit string, pts []TimePoint, fixedMax float64) templ.Component

MetricChart renders one metric as a proper line chart: real y scale, recessive quarter gridlines, y/x axis labels, and current/avg/peak header stats. fixedMax pins the scale (e.g. 100 for CPU %); 0 = scale to data. Hovering shows a crosshair + tooltip (static/js/metrics.js).

func MetricRange

func MetricRange(key string) (string, time.Duration)

MetricRange maps a picker key to its window; unknown keys fall back to 1h.

func MetricsFrag

func MetricsFrag(metricsURL, rangeKey string, cpu, mem, rx, tx []TimePoint) templ.Component

MetricsFrag is the range picker + charts; swaps itself on range change and auto-refreshes on a slow poll (samples land every 30s). metricsURL is the owning panel's fragment endpoint (e.g. "/apps/<id>/metrics").

func Modal(title, subtitle string) templ.Component

Modal is the panel's dialog shell.

Every confirm in stackr was the browser's native one (hx-confirm) until the node screens needed a dialog that shows two lists and takes a typed name (docs/plans/32-multi-node-ui.md, Drain and Remove). The existing confirms are left alone; they move onto this later, under the "consolidate all the UIs" note.

State lives in the DOM and nowhere else: htmx swaps the dialog into #modal-host, and closing it is emptying that element. Nothing to open, so nothing to leave open.

func ModalHost

func ModalHost() templ.Component

ModalHost is the empty element every modal is swapped into. One per page, in the shell.

func PageCtx added in v0.3.0

PageCtx bounds a call a page waits on. A miss has to render as unknown, never as a zero, and never as a request timeout 500.

func PanelHeader

func PanelHeader(h PanelHead, icon, actions templ.Component) templ.Component

PanelHeader is the drawer's fixed top: identity on the left, actions on the right, and the close button when it is rendered inside the drawer rather than on a full page.

func PanelTab

func PanelTab(base, active, key, label string) templ.Component

PanelTab is one tab. base is the panel's content URL ("/apps/<id>/panel/ content"); the tab key is appended. active must already be resolved to a real key, a panel with a default tab normalises it before rendering, so "which tab is lit" is one comparison rather than a rule per panel.

func PanelTabs

func PanelTabs() templ.Component

PanelTabs is the tab strip under the header. Its children are PanelTab.

func PlanBody

func PlanBody(c echo.Context, cfg PlanViewCfg, p *stackconf.Plan) templ.Component

func RequireConfirm

func RequireConfirm(c echo.Context, want string) error

RequireConfirm is Confirmed as a guard clause: nil to carry on, an error to return as-is. The message names what should have been typed, because the only people who see it are talking to the API by hand.

func SearchPalette

func SearchPalette() templ.Component

SearchPalette is the global search overlay ("/" or the rail icon opens it, main.js drives it). Rendered once per page from Layout so it exists on canvases and settings pages alike; hidden until opened. Results come from GET /search as an HTML fragment.

func SetupHoldingPage

func SetupHoldingPage(c echo.Context, org string) templ.Component

SetupHoldingPage is what a member sees while the org's owner is still in the onboarding wizard. Not a 404: they were invited, so they know the org is there, and not-found would only look broken.

It keeps the dashboard shell. A bare card with no nav is a dead end, the whole org is closed to this person, so the one thing the page owes them is the way back out to the orgs they can use.

func Shell

func Shell(c echo.Context, title string) templ.Component

Shell is the authenticated dashboard layout: a thin left icon rail (Railway style) + content. Nav labels live in tooltips; the rail stays ~56px.

func ShellFull

func ShellFull(c echo.Context, title string) templ.Component

ShellFull is Shell without the width cap or padding: the icon rail plus a full-viewport-height column. For canvas-style pages (graph).

func StashTileLocation

func StashTileLocation(c echo.Context, store repo.Store, t *repo.Tile)

StashTileLocation resolves "<stack> / <env>" for a tile and stashes it. Best-effort: a lookup failure leaves the header without the line.

func StashUpperEnv

func StashUpperEnv(c echo.Context, store repo.Store, t *repo.Tile)

StashUpperEnv sets the flag for the tile.

func StaticURL

func StaticURL(path string) string

StaticURL returns the full URL for a static asset, using the fingerprinted path from the manifest when available (production), or the plain path (dev).

func StatusBadge

func StatusBadge(status string) templ.Component

StatusBadge renders a colored status pill for app/db/deployment states.

func TileLocation

func TileLocation(c echo.Context) string

TileLocation reads the location a handler stashed, "" if none.

func TileLocationColor

func TileLocationColor(c echo.Context) string

TileLocationColor reads the env colour a handler stashed, "" if none.

func Toast

func Toast(message string, kind middleware.FlashType) templ.Component

Toast is the message itself: fixed, floats over the page (no layout shift), fades out after a few seconds, dismissible on click.

func ToastOOB

func ToastOOB(message string, kind middleware.FlashType) templ.Component

ToastOOB drops a toast into the page's flash slot on an htmx response. The cookie route (SetFlash + FlashOOB) only surfaces on the *next* request, so a message about the response being written right now has to go direct.

func UpperEnv

func UpperEnv(c echo.Context) bool

UpperEnv reads the flag a handler stashed.

func VarValue

func VarValue(c echo.Context) string

VarValue reads the value a variable form submitted, minting one when the Generate button was the submit.

Server-side on purpose: it is the same generator the config file's `default: generated` uses (config/secrets), so a secret made by hand and one made by an apply are the same kind of thing, and the plaintext never has to come back out of the browser to be stored.

func VarsEdit

func VarsEdit(c echo.Context, vars []repo.Variable, cfg VarsEditCfg) templ.Component

VarsEdit renders the rows. Page mode splits them into the two namespaces a reference names (${{ stack.vars.X }} / ${{ stack.secrets.X }}), because a mixed list gives no clue which one a row is reachable under. A drawer card is already one namespace, so it renders a single list.

func VarsEditor

func VarsEditor(c echo.Context, vars []repo.Variable, cfg VarsEditCfg) templ.Component

VarsEditor is the page-mode wrapper: it targets itself, so every round trip swaps the editor in place instead of reloading the settings page.

func WithFlash

func WithFlash(c echo.Context, body templ.Component) templ.Component

WithFlash pairs a fragment with the out-of-band flash slot, so any handler answering an htmx request confirms in place.

Types

type ConfirmCfg

type ConfirmCfg struct {
	// PostURL is where the form goes. Want is the exact text that has to be
	// typed, and is what the handler re-checks with components.Confirmed.
	PostURL string
	Want    string
	// Path is the full address of the thing, org / stack / env / tile, so
	// nobody deletes the right name in the wrong place.
	Path string
	// What it destroys, one sentence, present tense. Kept is what survives,
	// empty when nothing does.
	Warning string
	Kept    string
	Label   string // button text, "Delete" when empty
	// Target and Swap are htmx's, for the panels that replace themselves
	// rather than redirect.
	Target string
	Swap   string
	// ID makes the input's label and the form unique on a page carrying more
	// than one of these.
	ID string
}

ConfirmCfg is one destructive action guarded by typing its name.

type PanelHead

type PanelHead struct {
	Title string
	// Subtitle is what the tile is made of: an image, a source, an engine.
	Subtitle string
	// Location is where it lives, "<stack> / <env>". The full page has a
	// breadcrumb for this; the drawer has none, so a shared instance opened
	// from the org canvas would otherwise not say which environment it is in.
	Location string
	// LocationColor is the env's colour (envcolor CSS value) for the dot
	// before Location, "" for none.
	LocationColor string
	// Scope is how far the tile is shared ("org-scoped"). Separate from
	// Location because they answer different questions: an org-scoped
	// instance lives in one environment but serves every stack.
	Scope  string
	Status string
	// InDrawer adds the close button, the full page navigates instead.
	InDrawer bool
}

PanelHead is what a drawer's header shows. A struct rather than a parameter list because every tile kind fills the same slots and half of them are optional, a positional call would be six strings in a row and easy to transpose.

type PlanViewCfg

type PlanViewCfg struct {
	Summary   string // the stored plan's one-line summary
	Commit    string
	When      string // already formatted; the caller owns the timezone
	EnvSlug   string
	EnvColor  string // envcolor CSS value for the dot before EnvSlug
	Status    string // pending | applied | rejected | error
	StoredErr string // the plan row's own error text, if it failed to build

	// ApproveURL and RejectURL are empty on a plan nobody can decide any more.
	ApproveURL string
	RejectURL  string
	// InputURL collects a declared-but-unset value: it upserts the variable,
	// re-plans, and lands back on the new plan. Empty hides the boxes, which
	// is right when the values belong to a scope this plan cannot write yet:
	// an org plan cannot set secrets for stacks it has not created.
	InputURL string
	// ReplanURL recomputes the plan from the file as it is now. A stored plan
	// goes stale the moment the repo or the org moves on, and the only other
	// way to refresh it was to re-submit the binding form.
	ReplanURL string
	// Extra is rendered next to the buttons, and on its own when the plan has
	// none (an errored plan): the wizard puts "Decide later" there, since
	// skipping is a wizard idea and not a plan one, and a screen with no way
	// forward is a dead end.
	Extra templ.Component
}

PlanBody is one review of one plan, wherever it is being reviewed: the org plan page, a stack's plan page, and step 3 of the onboarding wizard. They used to be three layouts over the same data, which meant the wizard taught people to read a plan one way and the settings page another.

Org plans and stack plans both parse into stackconf.Plan, so the only thing the caller supplies is where its buttons post to.

type TimePoint

type TimePoint struct {
	T time.Time
	V float64
}

TimePoint is one sample on a metric chart.

func MetricPoints

func MetricPoints(ctx context.Context, store repo.Store, ref string, dur time.Duration) (cpu, mem, rx, tx []TimePoint)

MetricPoints loads samples for the window, bucket-averaged down to ≤240 points so a 24h span of 30s samples stays light to render.

type VarsEditCfg

type VarsEditCfg struct {
	PostURL  string // upsert endpoint; PostURL+"/delete" removes a row
	PanelURL string // where view-state round trips go; class/edit/new ride as queries
	ValueURL string // plaintext endpoint for secret Copy; ?name=X, audited
	Class    string // "plain" | "secret" for one drawer card; "" for a whole page
	// RefScope is the scope a row is read through: "stack" or "org". An
	// environment's rows use "stack" too, they shadow the stack-wide value at
	// resolution time rather than having a scope of their own. Blank hides the
	// reference hint.
	RefScope string

	EditName   string // row currently open for inline editing ("" = none)
	EditValue  string // that row's value
	EditSecret bool   // whether that row is a secret
	RevealName string // secret row currently shown unmasked ("" = none)
	Adding     bool   // render the empty new-variable row
	CanWrite   bool
	// Unset is the declared secrets with no value, shown under Secrets as
	// not-set rows. Page mode only.
	Unset []stackconf.Input
}

VarsEdit is the variables editor: rows edit inline in place, and the + button appends one editable row at the bottom. There is no standing form, every action (edit, add, save, cancel, delete) is a round trip that re-renders the whole editor, so the markup is only ever in one state.

The same component is both surfaces. In the canvas drawer it renders one class of one scope (the card that was clicked) and swaps into #drawer-body; on a settings page it renders every variable of the scope, secret flag and all, and swaps itself. Class == "" is what tells the two apart.

Secrets render masked and their plaintext stays off the DOM: Copy fetches the value from ValueURL (audited server-side), and only an explicit Reveal or edit pre-fill puts it in the markup, both of which the server logs.

Directories

Path Synopsis
templ: version: v0.3.1001
templ: version: v0.3.1001
templ: version: v0.3.1001
templ: version: v0.3.1001

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL