@startside/swa 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/swa/1.0/spec.md CHANGED
@@ -320,6 +320,7 @@ optional.
320
320
  <tr><td><code>accountService</code></td><td>a service name</td><td>The service of its account (section 7.13)</td></tr>
321
321
  <tr><td><code>accountScope</code></td><td>permissions, space-separated</td><td>Only accounts allowing one of them are offered</td></tr>
322
322
  <tr><td><code>debugMode</code></td><td><code>true</code></td><td><code>widget.log</code> writes to the console</td></tr>
323
+ <tr><td><code>export</code></td><td><code>false</code></td><td>Not sent as a file: a host offers no way to send this widget with its settings to someone else, and refuses a file claiming it. For a widget showing its signed-in account's own data, which means nothing without it</td></tr>
323
324
  </tbody>
324
325
  </table>
325
326
 
@@ -459,6 +460,8 @@ Labels **SHOULD** be short and in English.
459
460
  | `data-commit="ok"` | a `text` control | Its value applies only when confirmed (section 6.5) |
460
461
  | `data-share` | a `hidden` control | A shared link may carry its value |
461
462
  | `data-load` | a `hidden` control with `data-share` | A label, at most 40 characters: a person who already has the widget is offered a button with it, loading the shared value into their copy |
463
+ | `maxlength` | a `hidden` control with `data-share` | The longest value a shared link may carry for it, line breaks and tabs included (a whole text); a host **MAY** cap it (Startside: 16,000). Without it, a short value with no line breaks |
464
+ | `data-file` | a `hidden` control | File extensions, space-separated (`.cook`): a file of one of them, opened in the host (dropped on the page, chosen), makes this widget with the file's text as this setting's value; a host that exports a widget as files **SHOULD** write this setting's value as a file of that extension rather than among the settings. *At risk* (Appendix C) |
462
465
  | `data-feed` | an `option` | The feed of that choice (section 6.4); `none`: the choice has no feed |
463
466
 
464
467
  A `button` or `input` with `type="submit"` in the settings form asks the host for a button confirming the settings,
@@ -601,6 +604,52 @@ back for 1 second instead of an activation's 5: a browser on a touch screen may
601
604
  > **Note:** A tap in a widget within 5 seconds of a click on the host's page, or 1 second of a tap on it, is ignored: a
602
605
  > host can't tell it from a frame taking the focus.
603
606
 
607
+ ### 6.8 The keyboard coming into a widget
608
+
609
+ A host that lets people go from widget to widget with the keyboard **MAY** move the focus into a widget's document
610
+ on a key of its own. When it does, the focus goes to:
611
+
612
+ 1. the first element of the widget's body that has the `autofocus` attribute [[HTML](#ref-html)], if it can take the
613
+ focus;
614
+ 2. else the first element inside that one that can (a grid whose cells take the focus in turn);
615
+ 3. else the first element of the widget's body that can;
616
+ 4. else the document itself.
617
+
618
+ An element can take the focus here when it is shown, not disabled, and in the sequential focus order. A host
619
+ **SHOULD NOT** let `autofocus` take the focus as a widget loads among others; on a widget's own page the browser's
620
+ own behaviour applies.
621
+
622
+ The focus given this way is given by the host (6.7): what the person then does in the widget counts as theirs.
623
+
624
+ A host **MAY** take the focus back, to its own control for the widget, on an `Escape` `keydown` that reaches the
625
+ widget's `window` uncancelled, with no modifier, while the widget's document has the focus. A widget that uses
626
+ Escape itself (to close a panel of its own) calls `preventDefault()` on it.
627
+
628
+ A host **MUST NOT** act on these keys for a widget that took the focus by itself (6.7): only for one that was given it,
629
+ by the person or by the host. It decides once the event's dispatch is over, whichever listener cancels it.
630
+
631
+ A host **MAY** give a widget that has the focus the directions of a game controller it reads itself (its D-pad) as
632
+ arrow keys: a `keydown` event as a direction is pressed and a `keyup` as it is let go, with `key` and `code` set to
633
+ `ArrowUp`, `ArrowDown`, `ArrowLeft` or `ArrowRight`, dispatched on the widget's focused element (its `body` with none);
634
+ a back button of its choice as `Escape`, and an action button of the controller as `Enter`, after whose uncancelled `keydown` the host activates the focused
635
+ element when it is a button or a link (its `click()`).
636
+ These events are not trusted (`isTrusted` is false) and trigger no default action of the browser's: a widget that
637
+ handles the arrow keys in its own listeners needs nothing more to be played with a controller.
638
+
639
+ When a host gives the focus back to a widget after a window of the host's that the widget opened (7's `openPhoto`,
640
+ `openItems` and the like) closes, the focus **SHOULD** return to the element of the widget that had it; if that element
641
+ is gone, to where the keyboard comes in (the steps above).
642
+
643
+ A host **MAY** likewise act on an arrow key's `keydown` that reaches the widget's `window` uncancelled, with no
644
+ modifier (moving to the next widget that way), unless the event's target is, or is inside, an element where the
645
+ browser uses arrows itself: a text field, a `select`, an editable element, a media element, an element with the role
646
+ `slider`, `spinbutton`, `listbox`, `combobox`, `menu`, `menubar`, `tablist`, `radiogroup`, `tree`, `grid` or
647
+ `application`, or an element that can still scroll that way. A widget that uses the arrows itself (a game's moves)
648
+ calls `preventDefault()` on them.
649
+
650
+ > **Note:** A game marks its board: `<div class="board" tabindex="0" autofocus>`. A widget whose first control is
651
+ > already the one to use needs nothing.
652
+
604
653
  ## 7. The `Widget` interface
605
654
 
606
655
  ### 7.1 The `widget` object
@@ -648,8 +697,8 @@ interface Widget : EventTarget {
648
697
  undefined clearPeriodical(DOMString name);
649
698
 
650
699
  // 7.7 Lists and grips
651
- undefined countGrip(Element box, DOMString itemSelector, optional CountGripOptions options = {});
652
- undefined heightGrip(Element box, Element scroller, optional HeightGripOptions options = {});
700
+ undefined countGrip(HTMLElement box, DOMString itemSelector, optional CountGripOptions options = {});
701
+ undefined heightGrip(HTMLElement box, HTMLElement scroller, optional HeightGripOptions options = {});
653
702
 
654
703
  // 7.8 Memory and stored data
655
704
  readonly attribute WidgetStorage storage;
@@ -685,13 +734,15 @@ interface Widget : EventTarget {
685
734
  USVString? shareUrl();
686
735
  any share(optional ShareData data = {});
687
736
  any addWidget(AddWidgetSpec spec);
688
- boolean dragWidget(Element element, (AddWidgetSpec or Function) spec);
737
+ boolean dragWidget(Element element, (AddWidgetSpec or DragWidgetCallback) spec);
689
738
  readonly attribute boolean canFullSize;
690
739
  readonly attribute boolean fullSize;
691
740
  undefined openFull();
692
741
  undefined closeFull();
693
742
  readonly attribute boolean fullScreen;
694
743
  undefined setFullScreen(boolean on);
744
+ undefined setActionStates(record<DOMString, WidgetActionState> states);
745
+ Promise<undefined> saveFile(WidgetSaveFile file, optional WidgetSaveOptions options = {});
695
746
  };
696
747
  ```
697
748
 
@@ -781,6 +832,11 @@ dictionary WidgetSettingOption {
781
832
  - **Every state in the skeleton.** The content, and what shows while loading, when there is nothing, and after a
782
833
  failure, are elements of the skeleton, shown or hidden with the `hidden` attribute. A style giving one of them a
783
834
  `display` overrides `hidden`: add `.x[hidden] { display: none; }`.
835
+ - **Loading at its size.** What shows while loading has the shape and size of what is coming: a skeleton of its
836
+ rows, its picture's box at its proportions, its title's line. A widget that is a line of "Loading…" until its
837
+ content arrives jumps as it draws, and moves the page around it; one drawn from what it kept (7.8, 7.9) shows no
838
+ placeholder at all. On a first load the host knows no height to hold for it: the widget's own placeholder is all
839
+ there is.
784
840
  - **Repeated items from a `template`.** A list's row, a grid's cell: a `template` element in the skeleton, its content
785
841
  cloned for each item (`template.content.firstElementChild.cloneNode(true)`).
786
842
  - **Parts found under `widget.body`.** In the `load` listener, `widget.body.querySelector('.count')`: on its own page
@@ -949,6 +1005,7 @@ and ends its part of the load as settling does.
949
1005
  | `fullsize` | it was maximized or restored, its box at its new size | `fullSize`'s new value | no | `onFullSize` |
950
1006
  | `fullscreen` | it went full screen or left it, after `fullsize` when both change | `fullScreen`'s new value | no | `onFullScreen` |
951
1007
  | `settingschange` | the person applied settings that changed, or renamed the widget (7.3, 7.5) | `{ names }`: the settings changed, `title` for a rename | yes: canceling skips the refresh | none |
1008
+ | `action` | the person chose one of the widget's own actions in its options menu (7.13) | `{ id }`: the action's | no | none |
952
1009
 
953
1010
  Event types are lowercase, as the platform's are. A host **MAY** fire other events; their types **MUST** be lowercase and
954
1011
  **MUST NOT** begin with `on`. Such an event isn't cancelable, and has a null `detail` unless the host says otherwise.
@@ -1021,7 +1078,8 @@ dictionary HeightGripOptions {
1021
1078
  `onDone(default)`, *default* being the default value of `setting` (else of the widget's `count` or `limit` setting);
1022
1079
  maximized, it fits the window again instead.
1023
1080
  - `heightGrip(box, scroller, options)` gives the same grip to a list that keeps every item and scrolls in *scroller*: its
1024
- height follows the drag, never taller than the list, then settles on whole items and calls `onDone(pixels)`. Maximized,
1081
+ height follows the drag, never taller than the list, then settles on whole items, never ending on a heading among
1082
+ them (a title with nothing under it: it ends on the item before), and calls `onDone(pixels)`. Maximized,
1025
1083
  the list takes the window's height instead.
1026
1084
 
1027
1085
  Framed, the host follows the pointer once it leaves the frame and relays its moves. Either grip stays under the
@@ -1188,9 +1246,19 @@ dictionary PhotoSpec {
1188
1246
  DOMString alt;
1189
1247
  DOMString title;
1190
1248
  USVString preview;
1249
+ USVString zoom;
1191
1250
  unsigned long width;
1192
1251
  unsigned long height;
1193
- DOMString credit;
1252
+ (PhotoCredit or DOMString) credit;
1253
+ };
1254
+
1255
+ dictionary PhotoCredit {
1256
+ DOMString name;
1257
+ DOMString creator;
1258
+ DOMString creditText;
1259
+ DOMString copyrightNotice;
1260
+ USVString license;
1261
+ USVString url;
1194
1262
  };
1195
1263
  ```
1196
1264
 
@@ -1209,8 +1277,13 @@ URL the widget gives. `videoState` and the `videostate` event (`onVideoState`) r
1209
1277
  standalone, the video opens on its site.
1210
1278
 
1211
1279
  **Pictures.** `openPhoto(photo)` shows a picture at full size in the host's window: an `https` URL or one of the host's.
1212
- `preview` is shown while `src` loads; `width` and `height` give its proportions at once; `credit` is what its licence asks
1213
- to go with it, shared with it. Standalone, a new tab. Pictures a widget shows **MUST** be ones it may show: public domain, or under a licence or permission that allows it,
1280
+ `preview` is shown while `src` loads; `zoom`, a larger picture of the same, is asked only when the person zooms in
1281
+ (else `src` is enlarged); `width` and `height` give its proportions at once; `credit` is what its licence asks
1282
+ to go with it: a `PhotoCredit`, whose members are schema.org's `ImageObject` properties of the same names (the work's
1283
+ `name`, its `creator` as a name, the `creditText` naming who keeps or gives the picture, the `copyrightNotice` naming who
1284
+ the licence says to name, the `license`'s address, the picture's page `url`; all optional, the addresses `https`), or a
1285
+ plain string, read as its `creditText`. The host shares it with the picture as text and keeps it with what it makes of
1286
+ the picture; it **MAY** shorten its text, and drops what it can't read. Standalone, a new tab. Pictures a widget shows **MUST** be ones it may show: public domain, or under a licence or permission that allows it,
1214
1287
  their required credits kept.
1215
1288
 
1216
1289
  ### 7.13 The page
@@ -1226,6 +1299,24 @@ dictionary AddWidgetSpec {
1226
1299
  DOMString title;
1227
1300
  record<DOMString, DOMString> values; // at most 12, 200 characters each
1228
1301
  };
1302
+
1303
+ callback DragWidgetCallback = any (DragEvent event); // an AddWidgetSpec; nothing: the drag doesn't start
1304
+
1305
+ dictionary WidgetSaveFile {
1306
+ required DOMString name; // with its extension; cleaned by the host
1307
+ required DOMString type; // one its extension takes; "" for the usual one
1308
+ required (DOMString or Blob or ArrayBuffer) data; // 8 MiB at most
1309
+ };
1310
+
1311
+ dictionary WidgetSaveOptions {
1312
+ WidgetEvent action; // the `action` event of the choice this file answers
1313
+ };
1314
+
1315
+ dictionary WidgetActionState { // a member left out: as it was; null: as the file declares it
1316
+ boolean? disabled; // greyed: nothing to act on
1317
+ boolean? hidden; // not in the menu
1318
+ DOMString? label; // another label, 1 to 40 characters
1319
+ };
1229
1320
  ```
1230
1321
 
1231
1322
  - `shareUrl()` returns the widget's address on its host (`/add/<key>`), or null for an untrusted file.
@@ -1233,13 +1324,113 @@ dictionary AddWidgetSpec {
1233
1324
  - `addWidget(spec)` adds a widget of the host's directory after this one, with *spec*'s title and values. Trusted files
1234
1325
  only; activation-gated. The member is **absent** where no widget can be added (a preview, standalone).
1235
1326
  - `dragWidget(element, spec)` makes *element* draggable onto the page, creating the widget *spec* names (or returns, if
1236
- a function, as the drag starts) where it is dropped; it returns false, leaving *element* alone, where drags can't
1327
+ a function, as the drag starts: it is given the drag's `DragEvent`, and returning nothing cancels the drag) where it
1328
+ is dropped; it returns false, leaving *element* alone, where drags can't
1237
1329
  reach the page (framed, standalone).
1238
1330
  - **Maximized.** A person may maximize any widget. `canFullSize` says whether the host can; `openFull()` and
1239
1331
  `closeFull()` do it from a control of the widget's own; `fullSize` says which; `fullsize` (`onFullSize`) is fired once its
1240
1332
  box has its new size. `setFullScreen(on)`, activation-gated, puts the widget alone over the window, maximized first if it isn't, in the browser's full screen where there is one; `false` puts
1241
1333
  the widget back as it was before (on the page if the full screen maximized it). `fullScreen` says whether it is, the
1242
1334
  person's Esc included; `fullscreen` (`onFullScreen`) is fired as it changes.
1335
+ - **Its own actions.** A widget may have actions of its own in its options menu, for what belongs to the widget but
1336
+ not in its body (a recipe's *Reset*). **They are declared in the file**, as its settings are (section 5), and read
1337
+ by the host without running the widget:
1338
+
1339
+ ```html
1340
+ <menu id="actions" hidden>
1341
+ <button type="button" name="reset" data-icon="reset" data-confirm="Reset checked items and timers?" disabled>Reset</button>
1342
+ </menu>
1343
+ ```
1344
+
1345
+ Each `button` that is a child of the `menu` declares one action, in document order: `name` is its id (1 to 40
1346
+ letters, digits, `-`, `_` or `.`, unique), its text the label (text, never markup, 40 characters at most),
1347
+ `disabled` and `hidden` its state as the widget starts (greyed; not in the menu until the widget says otherwise),
1348
+ `data-icon` and `data-confirm` optional. Five at most, the hidden ones counted. A host reads
1349
+ the declaration strictly: an action whose id, label or question breaks these bounds is left out whole, never
1350
+ shortened, and the ones past the fifth are left out. The declaration is data: the host removes it from the
1351
+ widget's body, as the settings form, and never moves its elements or their handlers into its own page. What makes
1352
+ an action usable (its name, its greyed state, the keyboard, the focus given back) is the host's menu, not these
1353
+ hidden buttons.
1354
+ - `data-icon` hints at the picture the widget would like beside the label: one of the generic names `reset`,
1355
+ `refresh`, `undo`, `redo`, `copy`, `download`, `upload`, `share`, `add`, `remove`, `clear`, `edit`, `search`,
1356
+ `print`, `play`, `pause`, `stop`, `check`, `star`, `info`, `settings`, for which the host draws its own picture,
1357
+ or one emoji (a pictograph, one character as people see it: not a letter or another symbol), shown as given; a
1358
+ host **MAY** ignore it, and shows nothing for anything else.
1359
+ - `data-confirm` is a question (200 characters at most) the host asks in a dialog of its own before firing
1360
+ `action`, the action's label naming the answer that goes ahead; it fires only on that answer, and only if the
1361
+ widget still offers that action, with the same label, then. A host that can't ask **MUST NOT** fire. A widget
1362
+ asks nothing of its own for it (10.1: no browser dialogs).
1363
+ - **The running widget only changes their state**: `setActionStates(states)`, keyed by declared id, sets
1364
+ `disabled`, `hidden` or another `label` (a word that depends on its state, or a translation) of the actions it
1365
+ names, leaving the others and the members not given as they were. A member given as `null` goes back to what
1366
+ the file declares: `{ label: null }` restores the declared label. An id the file doesn't declare, or a label
1367
+ that isn't 1 to 40 characters, throws a `TypeError`. A widget **SHOULD** call it whenever what an action acts on
1368
+ changes. States last while the widget runs: a reload, or a widget the host builds again (6.4), starts from the
1369
+ declaration, and the widget says them again as it loads.
1370
+ - **Declared is not ready.** The host lists a declared action from the start, greyed until the widget has started:
1371
+ its first `load` dispatched, or its first `setActionStates`. One chosen then fires `action` (7.6.1) with its id
1372
+ in `detail.id`; a host **MUST NOT** fire it before, nor for an action disabled or hidden. Started means the
1373
+ `load` event was dispatched, not that what its listeners began has finished: a widget whose `load` fetches its
1374
+ data can be sent `action` before the data is there. A widget whose action needs that data declares the button
1375
+ `disabled` (or `hidden`) and enables it with `setActionStates` once the data has come.
1376
+ - The choice was made in the host's menu, not in the widget: it does not count as activation in the widget (6.7),
1377
+ so an action that needs one (a file picker, the clipboard) opens a control of the widget's own for the person
1378
+ to press. A download is the exception: the host delivers it (`saveFile`, below).
1379
+ - **A file to keep.** An action may produce one file for the person to download. Its declaration says which, in
1380
+ `data-save`: the extensions it may produce, space-separated, each a dot and 1 to 10 letters or digits.
1381
+
1382
+ ```html
1383
+ <button type="button" name="download" data-icon="download" data-save=".cook" disabled>Download as .cook</button>
1384
+ ```
1385
+
1386
+ ```js
1387
+ widget.addEventListener('action', (event) => {
1388
+ if (event.detail.id !== 'download') return;
1389
+ widget.saveFile({ name: title + '.cook', type: 'text/plain;charset=utf-8', data: text }, { action: event });
1390
+ });
1391
+ ```
1392
+
1393
+ The widget builds the content; the host authorizes, checks and delivers it. `data-save` is read from the file
1394
+ with the rest of the declaration, and `setActionStates` can't change it. It is independent of a setting's
1395
+ `data-file` (5.3), which keeps its meaning.
1396
+ - **What a choice allows.** `saveFile(file, { action: event })` answers one choice in the menu: *event* is the
1397
+ `action` event the host fired for it. One file per choice, within 30 seconds of it, and one save at a time
1398
+ per widget. The choice belongs to the widget as it runs then: it ends with a reload or a widget the host
1399
+ builds again (6.4), and never passes to what replaces it. An event the widget makes itself, an id it supplies
1400
+ or a claim of activation allow nothing. A call without `action` rejects with `NotAllowedError`: a download
1401
+ from a control of the widget's own is not specified yet (it needs a host dialog showing the final name and a
1402
+ declaration for the whole widget; [Issue 32](#issue-32)).
1403
+ - **The data** is a string, a `Blob` or an `ArrayBuffer`, 8 MiB at most in bytes (a string counted as UTF-8),
1404
+ copied as the call is made: the caller's buffer stays usable. Never an address, a stream or anything the host
1405
+ would fetch.
1406
+ - **The name** (1,024 characters at most as given, the type 255) is cleaned by the host: its last part only (no folders), no control or direction characters,
1407
+ nothing a disk refuses, no dots or spaces at its ends, never a device's name, 120 characters at most before
1408
+ its extension, a fallback when nothing is left. Its extension is read after cleaning and is the last one; an
1409
+ extension before it loses its dot (`invoice.exe.cook` becomes `invoice-exe.cook`).
1410
+ - **The extension** must be one the action declares **and** one the host allows. A host keeps an allow-list of
1411
+ data formats, never a block-list; Startside's is `.cook`, `.txt`, `.md`, `.csv`, `.json`, `.ics` and `.opml`.
1412
+ An action declaring another extension gets nothing for it.
1413
+ - **The type** must be one the extension takes (Startside: `text/plain` for each of them; also `text/markdown`
1414
+ for `.md`, `text/csv` for `.csv`, `application/json` for `.json`, `text/calendar` for `.ics`, `text/x-opml`,
1415
+ `application/xml` and `text/xml` for `.opml`); `""` asks for the usual one. A `Blob`'s own type is ignored:
1416
+ the host makes the file. A host **MUST NOT** render, preview or open the content, nor give the widget the
1417
+ file's address.
1418
+ - **Delivery.** While the person's choice still counts as activation in the host's page, the download starts.
1419
+ If it no longer does (a handler that computed or fetched first), the host shows a control of its own naming
1420
+ the file ("Download “name”?"), for those exact bytes: pressing it delivers the file, Cancel gives it up. A
1421
+ widget that stops while it is shown (removed, reloaded, built again) takes the control and the file with it. No
1422
+ other question is asked for a declared download: choosing it is the intent. `data-confirm` works as for any
1423
+ action, before `action` fires.
1424
+ - **The promise** resolves once the host has handed the file to the browser, which is not "saved": the browser
1425
+ may still block it or the person cancel it there. It rejects with a `DOMException`: `NotAllowedError` (no
1426
+ such choice, one already used or too old, or another save going on), `NotSupportedError` (a name, an
1427
+ extension, a type or data the action or the host doesn't take), `QuotaExceededError` (over 8 MiB),
1428
+ `AbortError` (the person cancelled the host's control). A refused file uses its choice up. A host shows no
1429
+ "Saved" notice and no path.
1430
+ - On a widget's own page (10.3) the call and its rules are the same; there they shape the API and do not
1431
+ protect, since the widget isn't sandboxed ([Issue 15](#issue-15)).
1432
+ - There is no way to make a list of actions in script: none of the widgets written so far needs one only known as
1433
+ it runs ([Issue 32](#issue-32)).
1243
1434
  - **Accounts.** A trusted widget declaring `accountService` and a hidden setting named `account` has its account in its
1244
1435
  settings: the host lists the page's accounts of that service (those allowing one of `accountScope`'s permissions; an
1245
1436
  account reporting none allows none, an account's permissions read space- or comma-separated) and
@@ -1818,7 +2009,8 @@ defensively; the keyboard's help as the board's description, a win announced by
1818
2009
  **Example 7.** A small application: a to-do list kept with the widget (a hidden setting, 7.8), its rows from a
1819
2010
  `template`, filled with text (what's typed is never markup), one listener on the list for every row; the browser's own
1820
2011
  controls for the keyboard (a form submitted by Enter, checkboxes); the focus moved to the next row when one is removed,
1821
- and each change announced.
2012
+ and each change announced. An action of its own in the options menu (7.13), declared in the file: *Remove done items*,
2013
+ greyed until an item is done, the host asking before it runs.
1822
2014
 
1823
2015
  ```html
1824
2016
  <!doctype html>
@@ -1846,6 +2038,9 @@ and each change announced.
1846
2038
  <form id="preferences" hidden>
1847
2039
  <input type="hidden" name="items" value="[]" />
1848
2040
  </form>
2041
+ <menu id="actions" hidden>
2042
+ <button type="button" name="clear" data-icon="clear" data-confirm="Remove the done items?" disabled>Remove done items</button>
2043
+ </menu>
1849
2044
  <div class="todo">
1850
2045
  <form class="add">
1851
2046
  <label class="visually-hidden">New item <input type="text" name="text" maxlength="200" autocomplete="off" required /></label>
@@ -1888,7 +2083,10 @@ and each change announced.
1888
2083
  );
1889
2084
  list.hidden = !Todo.items.length;
1890
2085
  widget.body.querySelector('.empty').hidden = !!Todo.items.length;
2086
+ Todo.actions();
1891
2087
  };
2088
+ // The menu's action follows the list: usable once an item is done (7.13), said again whenever that changes.
2089
+ Todo.actions = () => widget.setActionStates({ clear: { disabled: !Todo.items.some((item) => item.done) } });
1892
2090
  // Wired once, on the first load: one listener on the list for every row's checkbox and button.
1893
2091
  widget.addEventListener('load', () => {
1894
2092
  Todo.items = Todo.read();
@@ -1912,6 +2110,7 @@ and each change announced.
1912
2110
  item.done = e.target.checked;
1913
2111
  li.classList.toggle('done', item.done);
1914
2112
  Todo.save();
2113
+ Todo.actions();
1915
2114
  });
1916
2115
  list.addEventListener('click', (e) => {
1917
2116
  const button = e.target.closest('.remove');
@@ -1927,6 +2126,15 @@ and each change announced.
1927
2126
  });
1928
2127
  Todo.draw();
1929
2128
  });
2129
+ // Chosen in the options menu, and confirmed there: the host asked the question the file declares.
2130
+ widget.addEventListener('action', (event) => {
2131
+ if (event.detail.id !== 'clear') return;
2132
+ const before = Todo.items.length;
2133
+ Todo.items = Todo.items.filter((item) => !item.done);
2134
+ Todo.save();
2135
+ Todo.draw();
2136
+ Todo.say('Removed ' + (before - Todo.items.length) + ' done');
2137
+ });
1930
2138
  widget.addEventListener('refresh', () => {
1931
2139
  Todo.items = Todo.read();
1932
2140
  Todo.draw();
@@ -1966,16 +2174,22 @@ and each change announced.
1966
2174
  | `apiVersion` `1.0` | read as any metadata |
1967
2175
  | Readonly attributes and `FrozenArray` (7.1) | accessors without a setter, or non-writable properties, on `widget` itself (not on a `Widget` prototype); `preferences` a frozen array of frozen copies, made again when the declared settings change, so not the same array across such a change |
1968
2176
  | Starting on its own page (6.6, 10.3) | the widget code runs as the page reads it, before `widget.body` is set: a widget finds its parts in `load` (7.3.1), where every environment has it |
2177
+ | `maxlength` and `data-file` on a `hidden` control (5.3) | added November 8, 2026 for the Recipe widget (a Cooklang text in a link, a `.cook` file opened): implemented in Startside only; `data-file` read from the file by the host's catalogue, the first widget declaring an extension taking it, text only, 16,000 characters at most |
1969
2178
  | Host limits (unspecified) | a framed widget's settings: a value of 20,000 characters, a name of 100, all of them 100,000 together (a value over isn't kept; the widget's console says so); read keys over 2000 characters dropped; feeds cut to 99 items and an item's HTML to 120,000 characters; the unread count shown up to 99; the reader's list 500 items, titles 300 and content 200,000 characters; an added widget's file name 40 characters |
2179
+ | The keyboard coming into a widget (6.8) | implemented in Startside (November 13, 2026): Enter on a widget's title bar moves the focus in, by `autofocus` and the steps of 6.8; an uncancelled Escape gives it back, an uncancelled arrow goes on to the next widget; a game controller read by the page is given as arrow keys, Enter and Escape. On a widget's own page there is no other widget: the browser's own `autofocus` applies |
2180
+ | A widget's own actions and `saveFile` (7.13) | implemented in Startside (November 12, 2026): actions declared in `<menu id="actions" hidden>`, listed in the options menu, `setActionStates`, the `action` event, `data-confirm` asked by the host, and one file per choice through `saveFile` (8 MiB at most, the extension among the action's `data-save` and the host's allow-list). On a widget's own page the runtime's menu lists them the same way. Used by the Recipe (Reset, Download as .cook), Dial Slate (Reset), Bluesky and Mastodon (Disconnect); Example 7 declares one |
2181
+ | A picture's credit in fields (7.12) | implemented in Startside (November 13, 2026): `PhotoCredit`, schema.org's `ImageObject` property names, or a plain string read as `creditText`; shared with the picture as text |
1970
2182
 
1971
2183
  The runtime is served at `https://startside.app/swa/1.0/runtime.js` (one minified script, its styles in it, with none of
1972
2184
  UWA's API, globals or extensions of built-in objects: it runs SWA files only); a Startside
1973
2185
  page skips it, and its catalogue lists the files that load it. The same runtime and types make the npm package
1974
2186
  `@startside/swa` (1.0.0 published November 8, 2026; 1.0.1 adds this specification, the quickstart and the guide for
1975
- agents in Markdown, and the command `validate` and `inline`: Appendix F), served by jsDelivr and unpkg (4.3). jsDelivr keeps a
2187
+ agents in Markdown, and the command `validate` and `inline`: Appendix F; 1.0.2, November 16, the API's additions since,
2188
+ declared actions and saved files (7.13), a photo's zoom and credit (7.12), and its types corrected), served by jsDelivr and unpkg (4.3). jsDelivr keeps a
1976
2189
  range's file (`@1`) up to 12 hours and lets a browser keep it up to 7 days, an exact version's for good; unpkg sends
1977
- `@1` on to the exact version: a runtime fix reaches a CDN address within those times, startside.app's at once. Startside's own widgets are 52 UWA 1.2 files and 29 RWA
1978
- files; Appendix A's first example is an SWA one.
2190
+ `@1` on to the exact version: a runtime fix reaches a CDN address within those times, startside.app's at once. Startside's own widgets are 57 SWA files (51 of
2191
+ them its UWA widgets, rewritten November 11, 2026), 29 RWA files and one UWA 1.2 file (xkcd), as of November 15, 2026; Appendix A's first example is
2192
+ an SWA one.
1979
2193
 
1980
2194
  ## Appendix D. IDL Index
1981
2195
 
@@ -1983,7 +2197,7 @@ files; Appendix A's first example is an SWA one.
1983
2197
  `WidgetSetting`, `WidgetSettingOption` (7.2), `ChromeColorOptions` (7.4), `CountGripOptions`, `HeightGripOptions` (7.7),
1984
2198
  `ReadItemsOptions` (7.10), `ReaderItem`, `OpenItemsOptions` (7.11),
1985
2199
  `PlayAudioOptions`, `AudioState`, `AudioControls`, `AudioInfo`, `VideoSpec`, `VideoState`, `PhotoSpec` (7.12),
1986
- `ShareData`, `AddWidgetSpec` (7.13), `WidgetEventInit` (7.6.1), `FetchFeedOptions` (8.2); the callback `ReadKey` (7.10); the typedef `ContentFeed` (8.5); the mixin `WidgetElement` (11.2, for UWA files).
2200
+ `ShareData`, `AddWidgetSpec`, `WidgetActionState` (7.13), `WidgetEventInit` (7.6.1), `FetchFeedOptions` (8.2); the callbacks `ReadKey` (7.10) and `DragWidgetCallback` (7.13); the typedef `ContentFeed` (8.5); the mixin `WidgetElement` (11.2, for UWA files).
1987
2201
 
1988
2202
  ## Appendix E. Open issues
1989
2203
 
@@ -2050,6 +2264,19 @@ draft. Each is to be resolved before the specification is considered complete.
2050
2264
 
2051
2265
  <a id="issue-30"></a>**Issue 30. The room a widget has.** A widget's height is its content's (7.3.2). Define whether a host tells a widget the room it has (a window shorter than the widget, a host that frames it at a fixed height: `widget.layout` or a `resize` event's `detail` with the width and the height available), and whether a widget may ask for more.
2052
2266
 
2267
+ <a id="issue-31"></a>**Issue 31. Libraries from npm.** A framed widget's scripts may come from any `https` address today
2268
+ (4.8, 10.1 limits connections, not scripts), and nothing says how. Consider dependencies declared in an import map in
2269
+ the file, from one source (npm through jsDelivr's `/+esm`), at exact versions with integrity: a host can then read them
2270
+ without running the widget, the validator refuse a version that isn't pinned, the person be told code comes from
2271
+ elsewhere (Privacy), a host keep them offline and, later, serve them itself. Its plan: `docs/plans/swa-npm-dependencies.md`.
2272
+
2273
+ <a id="issue-32"></a>**Issue 32. A widget's own actions.** *Resolved* (7.13, November 12, 2026: actions declared in the file, `<menu id="actions">`, their state changed by `setActionStates`, the `action` event, an icon hint and a question the host asks; a first version made the list in script, `setActions`, dropped the same day for the declaration; then a file to keep, `data-save` and `saveFile`, answering a choice in the menu). Open: a list only known as the widget runs, should a widget need one; a download from a control of the widget's own (`saveFile` without `action`: a host dialog showing the final name, and a declaration for the whole widget); opening a file from the menu (the same extension syntax and limits, its own authorization: the host opening the picker from its own click). A widget's options menu (▾; on its own page, 10.3) holds the host's actions
2274
+ only (Refresh, Maximize, Mark all as read). Some actions are the widget's but don't belong in its body: the Recipe
2275
+ widget's *Start over*, which unticks everything and stops its timers, is a button at the bottom of the recipe for now
2276
+ (the Startside user, November 2026: "Start Over should be a widget action"). Consider actions a widget declares (in its
2277
+ metadata, or `widget.setActions([{ id, label }])` as its state changes) that the host lists in the menu with its own,
2278
+ and an `action` event carrying the `id` when one is chosen; a question it then asks stays in the widget's body.
2279
+
2053
2280
  ---
2054
2281
 
2055
2282
  ## Appendix F. Tools for authors
package/swa/1.0/swa.d.ts CHANGED
@@ -43,6 +43,8 @@ declare global {
43
43
  fullscreen: WidgetEvent<boolean>;
44
44
  /** Cancelable: canceling skips the refresh that follows. */
45
45
  settingschange: WidgetEvent<{ names: string[] }>;
46
+ /** One of the widget's own actions (declared in `<menu id="actions">`, 7.13) chosen in its options menu. */
47
+ action: WidgetEvent<{ id: string }>;
46
48
  }
47
49
 
48
50
  interface Widget extends EventTarget {
@@ -106,8 +108,9 @@ declare global {
106
108
  clearPeriodical(name: string): void;
107
109
 
108
110
  // 7.7 Lists and grips
109
- countGrip(box: Element, itemSelector: string, options?: CountGripOptions): void;
110
- heightGrip(box: Element, scroller: Element, options?: HeightGripOptions): void;
111
+ /** `box` an HTML element: the grip sets its style. */
112
+ countGrip(box: HTMLElement, itemSelector: string, options?: CountGripOptions): void;
113
+ heightGrip(box: HTMLElement, scroller: HTMLElement, options?: HeightGripOptions): void;
111
114
 
112
115
  // 7.8 Memory and stored data
113
116
  readonly storage: WidgetStorage;
@@ -147,7 +150,8 @@ declare global {
147
150
  share(data?: { text?: string; url?: string }): unknown;
148
151
  /** Absent where no widget can be added (a preview, a widget on its own page): `if (widget.addWidget)`. */
149
152
  addWidget?(spec: AddWidgetSpec): unknown;
150
- dragWidget(element: Element, spec: AddWidgetSpec | (() => AddWidgetSpec)): boolean;
153
+ /** `spec`, or a function giving it as the drag starts, given the drag's event; nothing given, the drag doesn't start. */
154
+ dragWidget(element: Element, spec: AddWidgetSpec | ((event: DragEvent) => AddWidgetSpec | null | undefined)): boolean;
151
155
  readonly canFullSize: boolean;
152
156
  readonly fullSize: boolean;
153
157
  openFull(): void;
@@ -155,6 +159,30 @@ declare global {
155
159
  /** Full screen: the browser's, or the widget alone over the window where the browser has none (7.13). */
156
160
  readonly fullScreen: boolean;
157
161
  setFullScreen(on: boolean): void;
162
+ /**
163
+ * Changes the state of actions the file declares (`<menu id="actions">`, 7.13), by id: greyed, hidden, another
164
+ * label. An id the file doesn't declare throws a TypeError. States last while the widget runs.
165
+ */
166
+ setActionStates(states: Record<string, WidgetActionState>): void;
167
+ /**
168
+ * A file the widget made, for the person to keep (7.13): the host checks its name, its extension and its type,
169
+ * and delivers it. `options.action`: the `action` event of a choice of an action whose declaration carries
170
+ * `data-save`; one file per choice, within 30 seconds. Resolves once the host handed the file to the browser
171
+ * (not "saved"); rejects with a DOMException: NotAllowedError (no such choice, or already used), NotSupportedError
172
+ * (a name, an extension or a type the action or the host doesn't take), QuotaExceededError (over 8 MiB),
173
+ * AbortError (the person cancelled). Without `options.action`: NotAllowedError.
174
+ */
175
+ saveFile(file: WidgetSaveFile, options?: { action?: WidgetEvent<{ id: string }> }): Promise<void>;
176
+ }
177
+
178
+ /** A file a widget saves (7.13). */
179
+ interface WidgetSaveFile {
180
+ /** Its name, with its extension: one the action declares (`data-save`). The host cleans it. */
181
+ name: string;
182
+ /** Its type, one its extension takes ('' for the usual one): "text/plain;charset=utf-8". */
183
+ type: string;
184
+ /** Its content, 8 MiB at most (a string's as UTF-8); copied as the call is made. */
185
+ data: string | Blob | ArrayBuffer;
158
186
  }
159
187
 
160
188
  /** Settings typed by the control that declares them (7.5): a checkbox's a boolean, a range's or a number's a number. */
@@ -345,9 +373,44 @@ declare global {
345
373
  alt?: string;
346
374
  title?: string;
347
375
  preview?: string;
376
+ /** A larger picture of the same, asked only when the person zooms in. */
377
+ zoom?: string;
348
378
  width?: number;
349
379
  height?: number;
350
- credit?: string;
380
+ /** What the picture's licence asks to go with it. A plain string is its credit text. */
381
+ credit?: PhotoCredit | string;
382
+ }
383
+
384
+ /**
385
+ * A picture's credit, in schema.org's ImageObject names (https://schema.org/ImageObject), every member optional.
386
+ * Addresses are `https`.
387
+ */
388
+ interface PhotoCredit {
389
+ /** The work's title. */
390
+ name?: string;
391
+ /** Who made it. */
392
+ creator?: string;
393
+ /** The credit line: who keeps or gives the picture (a museum, an agency). */
394
+ creditText?: string;
395
+ /** Who the licence says to name, as it asks ("Photo: …", "© …"). */
396
+ copyrightNotice?: string;
397
+ /** The licence's address. */
398
+ license?: string;
399
+ /** The picture's page at its source. */
400
+ url?: string;
401
+ }
402
+
403
+ /**
404
+ * What a running widget may change of an action its file declares (7.13). A field left out stays as it was; `null`
405
+ * puts it back to what the file declares.
406
+ */
407
+ interface WidgetActionState {
408
+ /** Greyed: nothing to act on. */
409
+ disabled?: boolean | null;
410
+ /** Not in the menu. */
411
+ hidden?: boolean | null;
412
+ /** Another label, 1 to 40 characters: a word that depends on its state, or a translation. */
413
+ label?: string | null;
351
414
  }
352
415
 
353
416
  interface AddWidgetSpec {