Skip to content

v0.7.1 — sizes that follow content, a Switch with words, and calling the model from a check

Latest

Choose a tag to compare

@github-actions github-actions released this 19 Nov 07:27
· 16 commits to main since this release

0.7.1 settles what a view's content size is. A view's size from its content is what its
children bring with nothing in them giving way, and a layout that sizes its children now says
how long that is: place() may return { boxes, contentWidth } (contentHeight along a
column) instead of its bare boxes. shrinks always promised this ("the size its content gives
it"), but a container's content size had been counted from the sizes its own layout gave its
children, so it could depend on itself. A header looped at sign-in, a title laid out empty
stayed at its padding, and a group of tags that shrinks stayed one tag wide. They hold now.

class Strip extends Layout [
    place() {
        let x = 0
        const boxes = this.laid().map((c) => { const b = { x: x }; x = x + c.width + 8; return b })
        return { boxes: boxes, contentWidth: Math.max(0, x - 8) }
        }
    ]

Controls size to their words. A Segmented with no width is as wide as its labels need, each
with its margin at either side; a Button given a width narrower than its label cuts it inside
its margins, with an ellipsis and the whole label as its accessible name. A
Switch takes a label, as a Checkbox does.

And a check can call the program's model directly: drive.call(path, method, …args) in a
verify script calls a method and returns its result, so the rules a dataset class keeps can be
tested case by case, beside the scripts that press what a person presses.

The flagship calendar is 177.7 KB gzipped at this tag.

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

Breaking changes

A built-in color name declared as another type → declared Color

fill, textColor, textFill and tint mean a color on every class: a value set on one is
taken as a color whatever the class declares, so tint: string was handed a number and failed
with no report. A class's own declaration of one of these names is now refused unless it is a
Color (or a number, which is what a color is).

Find: /\b(?:tint|fill|textColor|textFill)\s*:\s*(?:string|boolean|object|array|any)\b/

class Avatar [ width = 32, height = 32, tint: string = "#80a7ff", fill = { Color.from(classroot.tint) } ]
class Avatar [ width = 32, height = 32, tint: Color = #80a7ff, fill = { classroot.tint } ]

Docs: Paint and themes · Color

Watch for: a value of your own that isn't a color takes another name: avatarTone, not tint.

A name both a member and a script binding → rename one

A bare name that an attribute or method and a top-level script function or value both answer
to was a warning, and the member silently won: an App method initialsOf(id) that meant to call
the script's initialsOf(name) called itself. It is now an error (DECLARE4045). A library
class's own member meeting a script name is still allowed.

script { function initialsOf(name: string): string { return name.slice(0, 1) } }
App [ width = 200, height = 100, initialsOf(id: string) -> string { return initialsOf(id) } ]
script { function initialsOfName(name: string): string { return name.slice(0, 1) } }
App [ width = 200, height = 100, initialsOf(id: string) -> string { return initialsOfName(id) } ]

Docs: Program structure · DECLARE4045

A size beside a computed flexes → flexes = true with a computed maxWidth

width = { … } beside flexes = { phone } was refused only at run time, in a state where
flexes was true. It is refused at compile time now, at the size's line. A size beside
flexes reads, to anyone from CSS, as the size it grows from; the form that says "grow, but
no wider than this" is flexes = true with a maxWidth (and minWidth for a floor).

side: View [ height = 100%, width = { app.phone ? 0 : 280 }, flexes = { app.phone } ]
side: View [ height = 100%, flexes = true, maxWidth = { app.phone ? 0 : 280 }, minWidth = { app.phone ? 0 : 280 } ]

Docs: Layout · View.flexes

A ResponsiveLayout view sized from its content → given a width

A ResponsiveLayout chooses its arrangement by the width it is given, so it has no width of
its own to offer. Its documentation always required a given width; a view that broke that
failed silently. Now a rule that reads such a view's contentWidth (a parent sizing it from its
content in any way) is refused where it reads, and so is the view when nothing gives it a
width; shrinks on it is refused at compile time. A WrappingLayout with columns is the same.

card: View [ shrinks = true,
    layout: ResponsiveLayout [ plan = { [({ from: 600, flow: "row", gap: 20 }), ({ from: 0, flow: "stack", gap: 8 })] } ] ]
card: View [ width = 100%,
    layout: ResponsiveLayout [ plan = { [({ from: 600, flow: "row", gap: 20 }), ({ from: 0, flow: "stack", gap: 8 })] } ] ]

Docs: Layout · ResponsiveLayout

A Segmented with no width → as wide as its labels

A Segmented divided segmentMinWidth × items evenly, so a long label was cut in a control
with room to spare. With no width it is now as wide as its labels need, each label whole with
its margin (the theme's segmentedLabelInset) at either side; given a width, its segments
share it, and a label that can't fit is cut with an ellipsis inside its margins.

Segmented [ items = { [ ({ id: "d", label: "Day" }), ({ id: "w", label: "Week" }) ] } ]
Segmented [ width = 200, items = { [ ({ id: "d", label: "Day" }), ({ id: "w", label: "Week" }) ] } ]

Docs: Controls · Segmented

Watch for: a Segmented with no width changes size with no error. Give it a width where the old size mattered.

A Switch's fill, stroke and cornerRadius → the theme's

A Switch was its pill, so its own fill, stroke and cornerRadius painted it. It now holds
a label beside the pill, which is a part of it, so those attributes no longer reach the pill.
Its colors come from the theme (accent when on, control or trackFill when off).

Find: /\bSwitch\s*\[[^\]]*?\b(?:fill|stroke|cornerRadius)\s*=/

Switch [ checked = true, fill = #2E6FE0, accessibilityLabel = "Wi-Fi" ]
Switch [ checked = true, label = "Wi-Fi" ]

Docs: Switch · Paint and themes

Watch for: a subclass of Switch that reads its own width for the pill: the pill is now narrower than the control when it has a label.

A DataSource's error on screen → the program's own words, chosen by failure

A production app shows a person no words the platform wrote. error is the platform's account
of a failure for a developer; in a production build it is now a code with its values, which
declare-help turns back into the sentence. What a person reads is the program's own words,
chosen by failure: why the request failed, as one of a closed set.

notice: Text [ visible = { app.weather.failed }, text = { "Couldn't load: " + app.weather.error } ]
notice: Text [ visible = { app.weather.failed },
    text = { app.weather.failure == "offline" ? "You're offline." : "The forecast didn't load." } ]

Docs: DataSource.failure · Data

Watch for: a development build still shows the sentence, so the change shows only in a production build.

New

  • A layout says its content length. place() may return { boxes, contentWidth } (or
    contentHeight along a column), the view's content size worked out from what its children
    bring before the room is applied; null says it has none (a ResponsiveLayout). A layout
    that returns bare boxes leaves the content size to what it draws, as before. SimpleLayout
    reports it when it flexes or shrinks a child, WrappingLayout one row's length.
  • Segmented's segmentWidths: equal (the default), every segment as wide as the
    widest label needs, or proportional, each as wide as its own.
  • Switch [ label = "Wi-Fi" ]: shown, part of what a press reaches, and its name to a
    screen reader. The words come first and the switch after them, every platform's order for a
    switch; given a wider width the switch keeps to the trailing edge, so a full-width labeled
    switch is a settings row. Its focus ring circles the switch alone.
  • A Button cuts its label inside its margins when given a width narrower than its words,
    with an ellipsis and the whole label as its accessible name; verify reports a label cut short.
  • Text.truncated reports a last line cut short with an ellipsis, not only lines dropped
    past maxLines, and a TextLabel has it too.
  • drive.call(path, method, …args) in a verify script calls a method on a live node and
    returns its result: the way to test a model's rules directly. It goes around the controls, so
    it says a rule is right, not that a person can reach it; the verdict counts calls apart from
    input. expect(value).toMatchObject(…) joins the value matchers.
  • verify reports text cut short or spilling: a control's own words cut short, and text
    drawn past the view it sits in when that view has a ground or the text lands on a neighbor.

Smaller changes

  • A rule that closes an exists gate while the views under it come in, or while a list
    attaches its new rows, no longer attaches into the removed parent (it threw
    "Cannot read properties of null (reading 'insertChild')").
  • The dev server recompiles a program when a .ts file its script imports changes, or one
    that file imports in turn; it had kept serving the old code.
  • A rule loop's report names the loop among the rules that ran most, and leads with it when the
    rule at the limit is the library's; an error raised in library code (a layout's place(), a
    library class's rule) names where the program wrote the view it was working on.
  • A size read from the parent's through another attribute is reported below zero as a direct
    read is.
  • An object as a value: the message shows the line corrected (= { {} }), and the notation
    chapter states the rule.
  • A window a program opens (a page to print) no longer stalls verify for 30 seconds: the
    program's page is put back in front, and the window is said.
  • A later declarator of a comma list is a local: const a = 1, on = … in a method no longer
    reads as a write to the attribute on.
  • __declare.explainKey("Space") says who would take a key pressed now, each stop from the
    focused view to the App; __declare.evaluate returns the result as value beside its text.
  • DECLARE4044 (warning): onHold beside onPointerMove with no drag event, since on touch the
    carry goes to the page's scroll. drive.hold(path, ms, { thenDrag: [dx, dy] }) holds and
    carries, as a finger does.
  • declare-changes reads a Find: of several patterns, lists a class or schema of the
    program's whose name the platform now uses, and prints each hit's line.
  • TextSizeSwitch sizes to its letters as any Segmented does, rather than a fixed 102.
  • The calendar keeps one row at every width (the brand goes and the dates shorten as it
    narrows, and below 480 Today gives way to the date, which goes to today when pressed), and
    has a year of a working life in it, with holidays on their days. The sampler's toggles card stacks its switches beside the radios.
  • The docs: the layout chapter states that nothing a layout gives a child may depend on itself,
    and place()'s return; the run-and-check chapter teaches testing the model's rules with
    drive.call; the accessibility chapter's example of a control with no visible name is a
    Slider.