Skip to content

v0.6.4.1 — choices of your own, styled tags, the clipboard

Choose a tag to compare

@github-actions github-actions released this 08 Nov 05:07
· 91 commits to main since this release

The first step release, between patches. Most of it comes from a day of building apps with
Declare and fixing what they ran into: a choice control you draw yourself, rich text whose
tags take your own styles, copy and paste at any view, and a text field that sits on its
label's baseline. Two refusals are new, each for code that compiled before and drew
something other than what it said.

The flagship calendar is 164.4 KB gzipped at this tag.

Breaking: 2 changes to make — npx declare-changes app.declare lists the ones in your program.

Breaking changes

a null fontFamily → provided("fontFamily")

A family has no null meaning: null drew the browser's default serif, not the face from above, so the face from above is now read by name.

Find: /\bfontFamily\s*=\s*{[^}]*\bnull\b/

Text [ text = "Title", fontFamily = { app.big ? "Georgia" : null } ]
Text [ text = "Title", fontFamily = { app.big ? "Georgia" : provided("fontFamily") } ]

Docs: View.fontFamily

Watch for: codeFamily keeps null, which is its own default, the house monospace face.

a width on a flexing child of a WrappingLayout → minWidth, or a child that does not flex

A wrapping run gives a flexing child its width along the row, so a width written beside flexes was never the width it got; it is now refused at its line.

View [ width = 400, layout: WrappingLayout [ spacing = 6 ],
    View [ flexes = true, width = 80, height = 30 ] ]
View [ width = 400, layout: WrappingLayout [ spacing = 6 ],
    View [ flexes = true, minWidth = 80, height = 30 ] ]

Docs: WrappingLayout · View.flexes

Watch for: for a fixed width, take flexes off the child; a class that flexes (a Spacer) cannot be given one.

New

ChoiceControl and ChoiceItem make a choice among several, drawn entirely as your own.
ChoiceControl holds value for one of several, or values with multiple = true for
several at once, either bound with <->. Its direct children that are ChoiceItems are the
options: each has a choice, knows whether it is on, and chooses itself when pressed. The
control is one Tab stop, the arrows move between the options, and a screen reader hears a list
of options. RadioGroup and Radio are now these two with the radio look, unchanged for
programs that use them.

ChoiceControl [ value <-> app.size, layout: SimpleLayout [ axis = x, spacing = 4 ],
    ChoiceItem [ choice = "S", width = 40, height = 32, cornerRadius = 6,
        fill = { on ? "steelblue" : "gainsboro" }, Text [ x = center, y = center, text = "S" ] ],
    ChoiceItem [ choice = "M", width = 40, height = 32, cornerRadius = 6,
        fill = { on ? "steelblue" : "gainsboro" }, Text [ x = center, y = center, text = "M" ] ] ]

tagStyles gives each element of rich text a style of your own. <b>, <i>, a link or
a heading in loaded HTML or Markdown could only ever look bold, italic or underlined, because
a textStyles entry matches a span's class, never a tag. Now
tagStyles = { { strong: "Figure", link: "Ref", h2: "Section" } } names, for strong, em,
strike, code, link, quote and h1–h6, a style from the palette or a top-level style. Nested
tags compose: <b><i> wears the strong style, then the em style over it.

Copy, cut and paste at any view. ⌘C, ⌘X and ⌘V, and the Edit menu, go to the focused
view if it declares onClipboardCopy, onClipboardCut or onClipboardPaste, or else to its
nearest ancestor that does. The clipboard holds one thing in several representations, by MIME
type: a copy puts as many as it likes, and a paste reads the best one it understands.
Clipboard.copy(text) writes from a button. A focused text field keeps the clipboard for
itself, as before.

board: View [ focusable = true,
    onClipboardCopy(e: ClipboardEvent) {
        e.put(app.selected.title)
        e.put("application/x-card", JSON.stringify(app.selected))
    },
    onClipboardPaste(e: ClipboardEvent) {
        const card = e.get("application/x-card")
        app.add(card !== null ? JSON.parse(card) : { title: e.text })
    } ]

textAlign on rich text. HTMLText and Markdown center or end-align their paragraphs
and headings: start, center, end, left or right.

A text field has a baseline. TextInput declares where its line sits, so a label and a
field in a row with align = baseline share one line, on the web and on the Mac.

Smaller changes

  • A hidden child that flexes keeps the size its layout last gave it. Hiding one released it to
    its content's size, and a screen sized from its own content could re-run without end.
  • [*] followed by a name replicates the records: :columns[*].items[] is every item of every
    column, not one empty instance per column.
  • A link built as base + "#comments" is that URL's fragment, no longer refused as an unknown
    anchor in the app.
  • Media.playing no longer echoes the element's own play and pause reports back to it, a loop
    that could freeze the page.
  • An editable that grows from one line to several keeps its focus, and reports no blur.
  • On the Mac, rich text draws black, extrabold, thin and extralight at their weights.
  • A Sheet's content scrolls inside it when taller than the sheet.
  • The checker: a child 0 wide in a columns grid is named, with flexes = true as the cure; a
    program outside the Declare tree is served whole, with its data files, and a request it makes
    that fails is named; a locator's fill sets a value in one input event, as a paste does.
  • DECLARE4022 and DECLARE4026 keep the controls you drew, pointing to ChoiceControl;
    DECLARE4036 reports a ChoiceItem outside a ChoiceControl.
  • declare-help answers each name when given several, and a namespace member.
  • The guide: a custom control written start to finish (chapter 17), fitting a line to its room
    with measureText (chapter 12), and copy and paste (chapter 9).