Skip to content

v0.6.7 — a drag is a gesture of its own, and a key walks outward

Choose a tag to compare

@github-actions github-actions released this 11 Nov 15:54
· 47 commits to main since this release

A drag is what a press becomes when it wanders, as a click is what it becomes when it stays
put — and a press is now one or the other, never both, with nothing reported as a drag until
it is one. Three events say it: onDragStart, onDrag, onDragEnd. Declaring any of them
claims the gesture, so on a phone a finger moving on the view drags it instead of scrolling
the list it sits in. onPointerMove goes back to meaning what it says: every move of the
pointer over the view, hovering included.

card: View [ startX: number = 0,
    onDragStart() { startX = x },
    onDrag(e: PointerEvent) { x = startX + e.deltaX },
    onDragEnd(e: DragEndEvent) { if (e.canceled) x = startX } ]

A view that takes no clicks drags from the moment it is pressed; one that also takes clicks
(onClick, onDblClick, onHold, a link) drags once the press has wandered a few
pixels, so a tap stays a tap. Escape and the window losing focus end a drag canceled.

A key goes to the focused view and then outward, through each container to the App, and the
first view that binds it takes it — so a focused slider's arrows come before an App's, and a
field that binds Tab gets Tab. A view says which keys it answers with keyBindings: records
naming a key and the method it runs. The library's controls answer theirs the same way, so a
use site's own bindings add to a Button's Space and Enter rather than replace them. A
command returns false to hand the key on. Menus and buttons run commands the same way:
command: "bold" on a menu item or a Button walks from where the person was working, so
Edit › Copy and ⌘C reach the same view, and an item no view answers is greyed.

editor: View [ focusable = true,
    keyBindings = { [ ({ key: "Ctrl+B", command: "bold", label: "Bold" }),
        ({ key: "Escape", command: "clearAndPass" }) ] },
    bold() { app.bolded = !app.bolded },
    clearAndPass() { app.query = ""; return false } ]

Keys are spelled the Windows way — "Ctrl+S" is ⌘S on a Mac, Ctrl+S elsewhere — and the
Mac's glyphs ("⌘S") still mean the same.

The flagship calendar is 169.8 KB gzipped at this tag.

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

Breaking changes

a drag in onPointerMove → onDragStart, onDrag, onDragEnd

onPointerMove now hears every move, hovering included, and claims nothing; a drag is its
own resolved gesture.

handle: View [ startX: number = 0,
    onPointerDown(e: PointerEvent) { startX = x },
    onPointerMove(e: PointerEvent) { x = startX + e.deltaX },
    onPointerUp(e: PointerUpEvent) { if (e.canceled) x = startX } ]
handle: View [ startX: number = 0,
    onDragStart(e: PointerEvent) { startX = x },
    onDrag(e: PointerEvent) { x = startX + e.deltaX },
    onDragEnd(e: DragEndEvent) { if (e.canceled) x = startX } ]

Docs: Dragging · View.onDragStart · View.onPointerMove

Watch for: an onPointerMove that moves something now does so on hover too, and on a phone
the view no longer takes the finger, so the page scrolls instead. A subclass of Slider,
Switch, Splitter, Carousel, Sheet or DataGrid that overrides its pointer handlers:
their drags are the drag events now. A view that also takes clicks starts its drag a few
pixels into the press (the Slider, Switch and Splitter among them), and a mouse press
on a control inside a draggable view becomes that view's drag once it wanders, not once it
leaves the control.

Tab reaches the focused view's onKeyDown

Tab used to move focus before any handler saw it. It now arrives like any key, and moves
focus when it is handed on — an onKeyDown that takes the keys it wants and hands the rest
to super.onKeyDown(e) keeps Tab working; one that hands nothing on now stops Tab at the
view.

search: TextInput [
    onKeyDown(e: KeyEvent) {
        if (e.key == "Escape") app.query = ""
        } ]
search: TextInput [
    onKeyDown(e: KeyEvent) {
        if (e.key == "Escape") app.query = ""
        else super.onKeyDown(e)
        } ]

Docs: Key bindings · View.onKeyDown · View.keyBindings

Watch for: DECLARE4031 now warns on any view's onKeyDown that never calls super, not
only a Control's. A view that means every key — a game, a terminal — says
takesAllKeys = true.

Keys → KeyListener and Keyboard

The keyboard's member and the keyboard you ask now have a name each: a KeyListener hears
every key down and up, and Keyboard answers isDown, held and shortcutsInForce.

keys: Keys [ onKeyDown(e: KeyEvent) { if (Keys.isDown("ShiftLeft")) app.fast = true } ]
keys: KeyListener [ onKeyDown(e: KeyEvent) { if (Keyboard.isDown("ShiftLeft")) app.fast = true } ]

Find: Keys [ · Keys.isDown · Keys.held · Keys.shortcutsInForce · Keys.navClaim

Docs: KeyListener · Keyboard

Watch for: a class that extends Keys extends KeyListener now; Keyboard is no tag or base.

"Ctrl" in a shortcut's key means the command key

Shortcuts and keyBindings spell keys the Windows way: "Ctrl+S" is ⌘S on a Mac. A Mac's
own Control key is "MacCtrl".

keys: Shortcuts [ items = { [ ({ id: "t", key: "Ctrl+T", label: "Terminal" }) ] } ]
keys: Shortcuts [ items = { [ ({ id: "t", key: "MacCtrl+T", label: "Terminal" }) ] } ]

Docs: View.keyBindings

Watch for: a key written with Ctrl that meant the Mac's Control key — it now fires on ⌘.

Smaller changes

  • A focused control's own keys come before any App shortcut of the same key: an arrow
    Shortcuts on the App no longer takes the arrows from a focused slider.
  • Escape in a dialog's field cancels the field's edit first; the next Escape closes the
    dialog. One Escape closes the overlay nearest the focus.
  • An arrow a focused view doesn't take scrolls the scroller around it, and a scroller at
    its edge hands the key on to the one outside it.
  • On the Mac host a program's bindings get ⌘ chords before the host's menu — ⌘F, ⌘L and
    the rest — except ⌘Q, ⌘W, ⌘H and ⌘M; Escape typed in a native field reaches the program;
    ⌃T and ⌃D are debug builds' only.
  • The hold-⌘ panel lists labelled key bindings with the shortcuts.
  • New warnings: a binding whose command names no method (DECLARE4037), a key no press can
    match (DECLARE4038), the clipboard's keys taken from the platform (DECLARE4039), a standard
    key bound on the App without everywhere (DECLARE4040).
  • A second finger during a press is not a press. It used to take the press: the view
    under it clicked mid-drag, and the drag heard nothing more.
  • Edge scrolling moves a pane only once a drag has travelled toward its edge — a slider
    dragged sideways near a pane's bottom used to scroll the pane away — and reaches the pane
    the drag is carried into and, past the end of one, the pane around it.
  • On the canvas backend a pane inside a draggable view scrolls by touch, as on the DOM
    backend, and a row that drags sideways in a list no longer stops the list scrolling.
  • The Mac host sends the secondary and middle buttons as themselves, and right-click
    and Control-click open onContextMenu; a right-click used to be a left press that never
    ended.
  • A view reached through an argument the compiler cannot name stays live: a method
    reading a view's attribute through a parameter passed a ? : or a local went stale.
  • Media seeks under declare-verify land as on a real server.
  • Tools: --semantics names headings; __declare.evaluate(expr) takes one argument;
    __declare.stale() lists constraints whose value has gone stale; a press that follows a
    link out of the program says so; a list written bare that reads a value says to brace it;
    declare-help lists focusRingColor and View's accessibility… attributes.
  • Docs, each established by experiment: over and out belong
    to the topmost view; a drawing is not clipped and its text never wraps; Dataset.set
    lands in place; Focus.focus scrolls its target into view; a disabled control still
    covers what is beneath it; exists keeps its view while its condition holds.