@soffits/dsh-card-board 0.9.1 → 0.10.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0
4
+
5
+ - Undo: an action can declare an `inverse` (`{ "kind", "payload"? }`, on `done`, `snooze` and `event`). Pressing one shows an Undo in DSH's own toast for about 8 seconds, in English, French and Chinese; tapping it sends an `undo` press (channel `ui.action.undo`) that carries the inverse the card offered, so the owner of the item can reverse it (done and reopen, snooze and unsnooze) even after the card was rewritten.
6
+ - A row ticked done stays in place, struck through and ticked, until the board is refreshed or left. Unticking its box is the same undo.
7
+ - Every undo is its own record in the action log (who, when, which press it takes back); a press that was taken back shows as `undone`.
8
+ - Fix: a press only bridges the gap until the card is written again. After that the card's own `checked` decides whether a row's box is ticked, so an item reopened somewhere else shows unticked instead of staying ticked for a day because of its old press.
9
+ - Touch targets: the checkbox and the toast's Undo are at least 40 px on touch and narrow screens, and not selectable.
10
+
3
11
  ## 0.9.1
4
12
 
5
13
  - Select-all on a board no longer picks up chrome: summary chips, the day line, tiles, icons, new and just-now marks join the non-selectable parts; titles, notes and numbers still copy.
package/README.md CHANGED
@@ -280,8 +280,8 @@ A card, a list row or a status row can carry up to six buttons:
280
280
 
281
281
  ```json
282
282
  "actions": [
283
- { "kind": "done", "id": "library-books:done" },
284
- { "kind": "snooze", "id": "library-books:snooze" },
283
+ { "kind": "done", "id": "library-books:done", "inverse": { "kind": "reopen" } },
284
+ { "kind": "snooze", "id": "library-books:snooze", "inverse": { "kind": "unsnooze", "payload": { "until": "2026-03-02T09:00:00Z" } } },
285
285
  { "kind": "step", "id": "library-books:renew", "label": { "en": "Renew the books online", "fr": "Renouveler les livres en ligne" } },
286
286
  { "kind": "chat", "id": "landlord:ask", "label": "Draft a message", "payload": { "prompt": "Help me write a short follow-up to the landlord." } },
287
287
  { "kind": "event", "id": "front-door:lock", "label": "Lock" },
@@ -296,6 +296,8 @@ A card, a list row or a status row can carry up to six buttons:
296
296
 
297
297
  `id` is yours: letters, digits and `. _ : -`, unique within the card or row. `label` is optional except for `event` and `step`. `payload` is any small object (up to 4 KB of JSON).
298
298
 
299
+ `inverse` (on `done`, `snooze` and `event`) says the action can be taken back: `kind` is the name its owner knows the way back by (`reopen`, `unsnooze`), `payload` what that needs (a snooze's previous date). A press of such an action shows an Undo in a toast for about 8 seconds, and a ticked row stays in view, struck through, until the board is refreshed or left; unticking it is the same undo. A step has no inverse.
300
+
299
301
  The plugin doesn't act on a press itself. It checks that the person may see the board and that the action is in the card as written, then records an event:
300
302
 
301
303
  ```json
@@ -313,6 +315,14 @@ The plugin doesn't act on a press itself. It checks that the person may see the
313
315
 
314
316
  It's appended to the action log, emitted in-process as the Cordis event `card-board/action`, and published on channel `ui.action.<kind>` through [dsh-cron-jobs](https://github.com/soffits/dsh-cron-jobs) when that's installed, so a job subscribed to `ui.action.done` can mark the thing done wherever it lives. `person` is `owner` on a single-person DSH.
315
317
 
318
+ Taking a press back is another press, appended to the same log, so every record says who, when, what and whether it was undone. Its `action` is `undo` (channel `ui.action.undo`), `undoes` names the press, `of` is the kind it takes back, `inverse` the declared name, and `payload` is the action's own payload without the time the person picked, plus the inverse's. The press keeps the inverse as the card offered it, so an undo works after the card was rewritten, and a press taken back shows as `undone`. A handler that receives a press and its undo in one batch should treat the pair as nothing happening.
319
+
320
+ ```json
321
+ { "press": "5d0f…", "action": "undo", "of": "done", "id": "library-books:done", "undoes": "fcb114dd-3890-42e6-af4b-b23173edf8e0", "inverse": "reopen", "payload": {}, "person": "alex", "at": "2026-03-02T09:41:15.000Z", "source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row": 1 } }
322
+ ```
323
+
324
+ The press log is never a second source of the item's state: a press only marks the gap until the owner of the item writes the card again, and after that a row's box follows the card's `checked`.
325
+
316
326
  The button shows the press as pending until the card file is written again, then done (a step is done once recorded, since sending it is the whole job). If nothing rewrites the card within `actionTimeoutSeconds`, it says nothing picked the press up. So a handler should rewrite the card when it has acted, even if only `updatedAt` changes.
317
327
 
318
328
  The buttons come from [`@soffits/dsh-ui-actions`](https://github.com/soffits/dsh-ui-actions), a separate plugin the board uses when it is installed (`dsh plugin --profile web add @soffits/dsh-ui-actions`; DSH 0.2.2-rc.1 or later). Without it cards show no buttons. A chat button opens a new conversation with the card or row attached to the message box as a small card, and the person writes beside it; a chat button's words ("Ask", "Chat about this") and the done and snooze buttons' words come from that plugin, in the person's language. On a phone the buttons are at least 40 px, and a snooze picker opens as a sheet at the bottom of the screen.
package/client.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @soffits/dsh-card-board 0.9.1: built by scripts/build.mjs from src/client/. Do not edit. */
1
+ /* @soffits/dsh-card-board 0.10.0: built by scripts/build.mjs from src/client/. Do not edit. */
2
2
  window.__ModuleLoader__.load({
3
3
  id: "@soffits/dsh-card-board",
4
4
  factory: (require) => {
@@ -121,13 +121,14 @@ h3.cb-truncOpen{overflow:visible}
121
121
  .cb-rowText{flex:1;min-width:0}
122
122
  .cb-rowTitle{display:flex;align-items:center;gap:6px;min-width:0;font-size:14px;line-height:20px}
123
123
  .cb-rowSub{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
124
- .cb-done .cb-rowTitle{color:var(--dsw-alias-label-tertiary)}
124
+ .cb-done .cb-rowTitle{color:var(--dsw-alias-label-tertiary);text-decoration:line-through}
125
125
  .cb-rowMeta{display:flex;align-items:center;gap:8px;min-width:0;max-width:45%}
126
126
  .cb-rowMeta>*{min-width:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
127
127
  .cb-when{flex:none;color:var(--dsw-alias-label-tertiary);font-size:12px;font-variant-numeric:tabular-nums}
128
128
  .cb-rowActions{display:inline-flex;flex-wrap:wrap;justify-content:flex-end;min-width:0}
129
129
  .cb-rowSteps{flex-basis:100%;min-width:0;padding-left:41px}
130
130
  .cb-doneBox{flex:none;display:inline-flex;align-items:center;min-width:28px;min-height:28px;justify-content:center}
131
+ .cb-toastUndo{display:inline-block;min-width:40px;min-height:40px;margin:-12px -6px;padding:0 6px;line-height:40px;text-align:center;-webkit-user-select:none;user-select:none;touch-action:manipulation}
131
132
  .cb-visuallyHidden{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
132
133
  .cb-dotSlot{flex:none;display:inline-grid;place-items:center;width:28px}
133
134
  .cb-statusSpark{flex:0 1 90px;min-width:48px}
@@ -245,6 +246,8 @@ button.cb-cardOpen{border:0;background:transparent;padding:0;font:inherit;cursor
245
246
  @media (width<=640px){.cb-sheetModal.cb-sheetModal{width:calc(100vw - 16px)}}
246
247
  @media (width<=768px),(pointer:coarse){
247
248
  .cb-cardLink{width:40px;height:40px;margin:-9px 0}
249
+ .cb-doneBox{min-width:40px;min-height:40px;margin:-6px -6px -6px -10px}
250
+ .cb-doneBox label{display:inline-flex;align-items:center;justify-content:center;min-width:40px;min-height:40px}
248
251
  .cb-cardChat{margin:-9px -10px -9px 0}
249
252
  }
250
253
  `;
@@ -842,6 +845,27 @@ function shownRows(rows, open, limit, live) {
842
845
  return rows.filter((row, i) => i < limit || row.key !== void 0 && (live?.freshRows?.has(row.key) || live?.rows?.[row.key] > 0));
843
846
  }
844
847
 
848
+ // src/client/ticks.js
849
+ var doneOf = (row) => row?.actions?.find((action) => action.kind === "done");
850
+ function keepOf(row, index) {
851
+ const done = doneOf(row);
852
+ return done === void 0 ? void 0 : { id: done.id, index, row: { ...row, checked: true, actions: [done] } };
853
+ }
854
+ function keepTicked(rows, kept = []) {
855
+ const present = new Set(rows.map((row) => doneOf(row)?.id));
856
+ const missing = kept.filter((entry) => !present.has(entry.id)).sort((a, b) => a.index - b.index);
857
+ if (missing.length === 0) return rows;
858
+ const merged = [...rows];
859
+ for (const entry of missing) merged.splice(Math.min(entry.index, merged.length), 0, entry.row);
860
+ return merged;
861
+ }
862
+ function doneState(row, latest) {
863
+ const state = latest?.state;
864
+ const checked = state === "undone" ? false : state === "pending" || row.checked === true;
865
+ return { checked, undo: checked && latest?.undoable ? latest.press : void 0 };
866
+ }
867
+ var withKept = (kept = [], entry) => [...kept.filter((other) => other.id !== entry.id), entry];
868
+
845
869
  // src/client/cards.js
846
870
  var STATE_OF_TONE = { ok: "done", warn: "warning", bad: "error" };
847
871
  var DIRECTION_ICON = { up: "trending-up", down: "trending-down" };
@@ -927,7 +951,7 @@ function Row({ lead, title, sub, meta, value, spark, row, index, washCount, fres
927
951
  };
928
952
  return (0, import_react6.createElement)(
929
953
  "li",
930
- { className: ["cb-row", className, row.checked && "cb-done", isActive(row.active, now) && "cb-rowNow", go && "cb-rowOpens", wash].filter(Boolean).join(" "), ...opens },
954
+ { className: ["cb-row", className, isActive(row.active, now) && "cb-rowNow", go && "cb-rowOpens", wash].filter(Boolean).join(" "), ...opens },
931
955
  lead,
932
956
  (0, import_react6.createElement)(
933
957
  "div",
@@ -948,18 +972,19 @@ function Row({ lead, title, sub, meta, value, spark, row, index, washCount, fres
948
972
  );
949
973
  }
950
974
  function DoneBox({ row, index, done, rowControls, t }) {
951
- const state = rowControls.state(index, done.id);
952
- const checked = row.checked === true || state === "done" || state === "pending";
975
+ const { checked, undo } = doneState(row, rowControls.latest(index, done.id));
976
+ const label = t(checked ? undo ? "markNotDone" : "checked" : "markDone");
953
977
  return (0, import_react6.createElement)(
954
978
  "span",
955
979
  { className: "cb-doneBox", onClick: (event) => event.stopPropagation() },
956
980
  (0, import_react6.createElement)(import_dsh_client_ui_primitives.Checkbox, {
957
981
  checked,
958
- disabled: checked,
959
- title: t(checked ? "checked" : "markDone"),
960
- label: (0, import_react6.createElement)("span", { className: "cb-visuallyHidden" }, t(checked ? "checked" : "markDone")),
982
+ disabled: checked ? undo === void 0 : index < 0,
983
+ title: label,
984
+ label: (0, import_react6.createElement)("span", { className: "cb-visuallyHidden" }, label),
961
985
  onChange: (value) => {
962
986
  if (value) rowControls.press(index, done);
987
+ else if (undo) rowControls.undo(undo);
963
988
  }
964
989
  })
965
990
  );
@@ -968,9 +993,13 @@ var rowLive = (live, row) => ({ washCount: live.rows?.[row.key] ?? 0, fresh: row
968
993
  function ListCard({ data, live, locale, t, rowActions, all = false, onOpenRow, rowControls }) {
969
994
  const kit = useKit();
970
995
  const [open, setOpen] = (0, import_react6.useState)(false);
971
- const rows = shownRows(data.rows, open || all, LIST_ROWS, live);
972
- const hidden = data.rows.length - rows.length;
973
- const doneOf = (row) => row.actions?.find((action) => action.kind === "done");
996
+ const listed = keepTicked(data.rows, rowControls?.kept);
997
+ const rows = shownRows(listed, open || all, LIST_ROWS, live);
998
+ const hidden = listed.length - rows.length;
999
+ const ticked = (row) => {
1000
+ const done = doneOf(row);
1001
+ return done !== void 0 && rowControls !== void 0 ? doneState(row, rowControls.latest(data.rows.indexOf(row), done.id)).checked : row.checked === true;
1002
+ };
974
1003
  const progress = data.progress;
975
1004
  return (0, import_react6.createElement)(
976
1005
  "div",
@@ -991,13 +1020,13 @@ function ListCard({ data, live, locale, t, rowActions, all = false, onOpenRow, r
991
1020
  progress.sub && (0, import_react6.createElement)("div", { className: "cb-rowSub" }, progress.sub)
992
1021
  )
993
1022
  ),
994
- data.rows.length === 0 ? (0, import_react6.createElement)("p", { className: "cb-muted" }, data.empty ?? t("listEmpty")) : (0, import_react6.createElement)("ul", { className: "cb-rows" }, rows.map((row, i) => (0, import_react6.createElement)(Row, {
1023
+ listed.length === 0 ? (0, import_react6.createElement)("p", { className: "cb-muted" }, data.empty ?? t("listEmpty")) : (0, import_react6.createElement)("ul", { className: "cb-rows" }, rows.map((row, i) => (0, import_react6.createElement)(Row, {
995
1024
  key: row.key ?? i,
996
1025
  index: data.rows.indexOf(row),
997
1026
  row: doneOf(row) && rowControls ? { ...row, actions: row.actions.filter((a) => a.kind !== "done") } : row,
998
1027
  rowActions,
999
1028
  onOpenRow,
1000
- className: i >= LIST_ROWS ? "cb-rowLate" : void 0,
1029
+ className: [i >= LIST_ROWS && "cb-rowLate", ticked(row) && "cb-done"].filter(Boolean).join(" ") || void 0,
1001
1030
  ...rowLive(live, row),
1002
1031
  lead: [
1003
1032
  doneOf(row) && rowControls && (0, import_react6.createElement)(DoneBox, { key: "check", row, index: data.rows.indexOf(row), done: doneOf(row), rowControls, t }),
@@ -1012,7 +1041,7 @@ function ListCard({ data, live, locale, t, rowActions, all = false, onOpenRow, r
1012
1041
  (0, import_react6.createElement)(RowWhen, { row, locale, t })
1013
1042
  )
1014
1043
  }))),
1015
- !all && (hidden > 0 || open) && data.rows.length > LIST_ROWS + 1 && (0, import_react6.createElement)(
1044
+ !all && (hidden > 0 || open) && listed.length > LIST_ROWS + 1 && (0, import_react6.createElement)(
1016
1045
  import_dsh_client_ui_primitives.Button,
1017
1046
  { variant: "ghost", size: "sm", className: "cb-more", onClick: () => setOpen((value) => !value) },
1018
1047
  open ? t("showFewer") : t("showMore", { n: hidden })
@@ -1249,6 +1278,9 @@ function statesOf(presses, row) {
1249
1278
  for (const press of presses ?? []) if (press.row === row) states[press.id] = press.state;
1250
1279
  return states;
1251
1280
  }
1281
+ function latestOf(presses, row, id) {
1282
+ return (presses ?? []).findLast((press) => press.id === id && (row < 0 || press.row === row));
1283
+ }
1252
1284
  function Body({ card, live, wash, locale, t, rowActions, all, onOpenRow, rowControls }) {
1253
1285
  const data = card.data;
1254
1286
  switch (card.type) {
@@ -1267,7 +1299,7 @@ function Body({ card, live, wash, locale, t, rowActions, all, onOpenRow, rowCont
1267
1299
  }
1268
1300
  }
1269
1301
  }
1270
- function Card({ entry, live, boardId, assistant, tracks, active, locale, t, press, onOpen, sheet = false, row: openRow }) {
1302
+ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, press, undo, kept, onOpen, sheet = false, row: openRow }) {
1271
1303
  const kit = useKit();
1272
1304
  const actions = useButtons();
1273
1305
  const now = kit.useNow();
@@ -1298,7 +1330,7 @@ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, pres
1298
1330
  const rowLine = (row) => card.type === "status" ? statusRowLine(card.data.rows[row], locale) : listRowLine(card.data.rows[row]);
1299
1331
  const askName = assistant ? t("action.chatNamed", { name: assistant }) : void 0;
1300
1332
  const named = (list) => assistant ? list?.map((action) => action.kind === "chat" && action.label === void 0 ? { ...action, label: askName } : action) : list;
1301
- const onPress = (target) => (action, extra) => press(action, extra, { card: entry.id, ...target });
1333
+ const onPress = (target) => (action, extra) => press(action, extra, { card: entry.id, ...target }, target.row === void 0 ? void 0 : card.data.rows?.[target.row]);
1302
1334
  const rowActions = actions && ((row, list, part2) => (0, import_react9.createElement)(actions.ActionBar, {
1303
1335
  actions: named(list),
1304
1336
  part: part2,
@@ -1309,7 +1341,10 @@ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, pres
1309
1341
  }));
1310
1342
  const rowControls = {
1311
1343
  press: (row, action) => onPress({ row })(action),
1312
- state: (row, id) => statesOf(entry.presses, row)[id]
1344
+ state: (row, id) => statesOf(entry.presses, row)[id],
1345
+ latest: (row, id) => latestOf(entry.presses, row, id),
1346
+ kept,
1347
+ undo: (pressId) => undo(pressId, entry.id)
1313
1348
  };
1314
1349
  const chat = actions && (0, import_react9.createElement)("span", { className: "cb-cardChat" }, (0, import_react9.createElement)(actions.ActionButton, { action: { kind: "chat", id: "_chat", label: askName }, compact: true, about: about() }));
1315
1350
  const others = card.actions?.filter((action) => action.kind !== "step") ?? [];
@@ -1342,7 +1377,7 @@ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, pres
1342
1377
  t,
1343
1378
  rowActions: rowActions && ((_, list, part2) => rowActions(index, list, part2)),
1344
1379
  all: true,
1345
- rowControls: { press: (_, action) => rowControls.press(index, action), state: (_, id) => rowControls.state(index, id) }
1380
+ rowControls: { ...rowControls, kept: [], press: (_, action) => rowControls.press(index, action), state: (_, id) => rowControls.state(index, id), latest: (_, id) => rowControls.latest(index, id) }
1346
1381
  }),
1347
1382
  (0, import_react9.createElement)(DetailParts, { detail: target.detail, locale, t })
1348
1383
  );
@@ -1445,6 +1480,8 @@ function Sheet({ open, onClose, title, closeLabel, children }) {
1445
1480
  // src/client/page.js
1446
1481
  var STORE_KEY = "dsh-card-board:board";
1447
1482
  var SEEN_AFTER_MS = 2500;
1483
+ var UNDO_HOLD_MS = 7e3;
1484
+ var TOAST_KEYS = { done: "toast.done", snooze: "toast.snooze" };
1448
1485
  function requestError(status, body) {
1449
1486
  const error = new Error(body?.error ?? `HTTP ${status}`);
1450
1487
  error.status = status;
@@ -1491,6 +1528,9 @@ function BoardsPage() {
1491
1528
  const currentRef = (0, import_react11.useRef)(null);
1492
1529
  const translateRef = (0, import_react11.useRef)(t);
1493
1530
  translateRef.current = t;
1531
+ const [kept, setKept] = (0, import_react11.useState)({});
1532
+ const [toast, setToast] = (0, import_react11.useState)(null);
1533
+ const toasts = (0, import_react11.useRef)(0);
1494
1534
  const board = view.board;
1495
1535
  const boardRef = (0, import_react11.useRef)(null);
1496
1536
  boardRef.current = board;
@@ -1551,18 +1591,36 @@ function BoardsPage() {
1551
1591
  }
1552
1592
  }, [loadBoard, loadCard, loadList, show]);
1553
1593
  const status = kit.useEventStream(current ? `api/card-board/events?board=${encodeURIComponent(current)}` : null, onEvent);
1554
- const press = (0, import_react11.useCallback)(async (action, extra, target) => {
1594
+ const post = (0, import_react11.useCallback)(async (body) => {
1555
1595
  const response = await fetch(api("action"), {
1556
1596
  method: "POST",
1557
1597
  credentials: "same-origin",
1558
1598
  headers: { "content-type": "application/json" },
1559
- body: JSON.stringify({ board: currentRef.current, ...target, id: action.id, ...extra })
1599
+ body: JSON.stringify({ board: currentRef.current, ...body })
1560
1600
  });
1561
- const body = await response.json().catch(() => null);
1562
- if (!response.ok) throw new Error(errorText(requestError(response.status, body), translateRef.current));
1601
+ const answer = await response.json().catch(() => null);
1602
+ if (!response.ok) throw new Error(errorText(requestError(response.status, answer), translateRef.current));
1563
1603
  loadBoard(currentRef.current, false);
1564
- return body;
1604
+ return answer;
1565
1605
  }, [loadBoard]);
1606
+ const showToast = (0, import_react11.useCallback)((next) => setToast({ seq: ++toasts.current, ...next }), []);
1607
+ const undo = (0, import_react11.useCallback)(async (pressId, card) => {
1608
+ try {
1609
+ await post({ card, undo: pressId });
1610
+ showToast({ text: "toast.undone" });
1611
+ } catch {
1612
+ showToast({ text: "toast.undoFailed" });
1613
+ }
1614
+ }, [post, showToast]);
1615
+ const press = (0, import_react11.useCallback)(async (action, extra, target, row) => {
1616
+ const answer = await post({ ...target, id: action.id, ...extra });
1617
+ if (answer?.undoable) {
1618
+ showToast({ text: TOAST_KEYS[action.kind] ?? "toast.event", undo: () => undo(answer.press, target.card) });
1619
+ const keep = action.kind === "done" && row !== void 0 ? keepOf(row, target.row) : void 0;
1620
+ if (keep) setKept((prev) => ({ ...prev, [target.card]: withKept(prev[target.card], keep) }));
1621
+ }
1622
+ return answer;
1623
+ }, [post, showToast, undo]);
1566
1624
  (0, import_react11.useEffect)(() => {
1567
1625
  loadList();
1568
1626
  }, [loadList]);
@@ -1570,6 +1628,8 @@ function BoardsPage() {
1570
1628
  currentRef.current = current;
1571
1629
  if (!current) return;
1572
1630
  etag.current = null;
1631
+ setKept({});
1632
+ setToast(null);
1573
1633
  setView((prev) => prev.board?.id === current ? prev : { board: null, live: {} });
1574
1634
  loadBoard(current, true);
1575
1635
  }, [current, loadBoard]);
@@ -1657,7 +1717,7 @@ function BoardsPage() {
1657
1717
  (0, import_react11.createElement)(
1658
1718
  "div",
1659
1719
  { className: "cb-grid", style: { gridTemplateColumns: `repeat(${tracks}, minmax(0, 1fr))`, gridAutoRows: `${ROW}px`, columnGap: GAP } },
1660
- board.cards.map((entry) => (0, import_react11.createElement)(Card, { key: entry.id, entry, live: liveOf(view.live, entry.id), boardId: board.id, assistant: board.assistant, tracks, active, locale, t, press, onOpen: (row) => openCard(board.id, entry.id, row) }))
1720
+ board.cards.map((entry) => (0, import_react11.createElement)(Card, { key: entry.id, entry, live: liveOf(view.live, entry.id), boardId: board.id, assistant: board.assistant, tracks, active, locale, t, press, undo, kept: kept[entry.id], onOpen: (row) => openCard(board.id, entry.id, row) }))
1661
1721
  )
1662
1722
  );
1663
1723
  const openEntry = opened.card && board && (!opened.board || opened.board === board.id) ? board.cards.find((entry) => entry.id === opened.card && entry.card) : void 0;
@@ -1668,7 +1728,7 @@ function BoardsPage() {
1668
1728
  onClose: closeCard,
1669
1729
  title: openRow ? openRow.title ?? openRow.label : openCardData?.title,
1670
1730
  closeLabel: t("close")
1671
- }, openEntry && (0, import_react11.createElement)(Card, { entry: openEntry, live: liveOf(view.live, openEntry.id), boardId: board.id, assistant: board.assistant, tracks: 1, active, locale, t, press, sheet: true, row: opened.row }));
1731
+ }, openEntry && (0, import_react11.createElement)(Card, { entry: openEntry, live: liveOf(view.live, openEntry.id), boardId: board.id, assistant: board.assistant, tracks: 1, active, locale, t, press, undo, kept: kept[openEntry.id], sheet: true, row: opened.row }));
1672
1732
  return (0, import_react11.createElement)(
1673
1733
  "div",
1674
1734
  { className: "cb-page" },
@@ -1684,7 +1744,17 @@ function BoardsPage() {
1684
1744
  boards && boards.length > 1 && (0, import_react11.createElement)("div", { className: "cb-tabs", role: "tablist" }, boards.map((b) => (0, import_react11.createElement)(import_dsh_client_ui_primitives4.Pill, { key: b.id, active: b.id === current, role: "tab", "aria-selected": b.id === current, title: titleOf(b), onClick: () => choose(b.id) }, titleOf(b)))),
1685
1745
  content
1686
1746
  ),
1687
- board && sheet
1747
+ board && sheet,
1748
+ toast && (0, import_react11.createElement)(import_dsh_client_ui_primitives4.Toast, {
1749
+ key: toast.seq,
1750
+ text: t(toast.text),
1751
+ tone: "success",
1752
+ ...toast.undo ? { holdMs: UNDO_HOLD_MS, actions: [{ label: (0, import_react11.createElement)("span", { className: "cb-toastUndo" }, t("undo")), onClick: () => {
1753
+ setToast(null);
1754
+ toast.undo();
1755
+ } }] } : {},
1756
+ onDone: () => setToast(null)
1757
+ })
1688
1758
  );
1689
1759
  }
1690
1760
 
@@ -59,11 +59,13 @@
59
59
  },
60
60
  {
61
61
  "kind": "done",
62
- "id": "library-books:done"
62
+ "id": "library-books:done",
63
+ "inverse": { "kind": "reopen" }
63
64
  },
64
65
  {
65
66
  "kind": "snooze",
66
- "id": "library-books:snooze"
67
+ "id": "library-books:snooze",
68
+ "inverse": { "kind": "unsnooze", "payload": { "until": "2026-03-02T09:00:00Z" } }
67
69
  }
68
70
  ],
69
71
  "key": "chore-2",
package/locale/en.json CHANGED
@@ -40,6 +40,13 @@
40
40
  "close": "Close",
41
41
  "history": "History",
42
42
  "markDone": "Mark done",
43
- "rowGone": "This item is no longer on the card."
43
+ "rowGone": "This item is no longer on the card.",
44
+ "toast.done": "Marked done.",
45
+ "toast.snooze": "Snoozed.",
46
+ "toast.event": "Done.",
47
+ "toast.undone": "Undone.",
48
+ "toast.undoFailed": "Couldn’t undo that.",
49
+ "undo": "Undo",
50
+ "markNotDone": "Mark not done"
44
51
  }
45
52
  }
package/locale/fr.json CHANGED
@@ -40,6 +40,13 @@
40
40
  "close": "Fermer",
41
41
  "history": "Historique",
42
42
  "markDone": "Marquer comme fait",
43
- "rowGone": "Cet élément n’est plus sur la carte."
43
+ "rowGone": "Cet élément n’est plus sur la carte.",
44
+ "toast.done": "Marqué comme fait.",
45
+ "toast.snooze": "Reporté.",
46
+ "toast.event": "C’est fait.",
47
+ "toast.undone": "Annulé.",
48
+ "toast.undoFailed": "Impossible d’annuler.",
49
+ "undo": "Annuler",
50
+ "markNotDone": "Marquer comme non fait"
44
51
  }
45
52
  }
package/locale/zh.json CHANGED
@@ -40,6 +40,13 @@
40
40
  "close": "关闭",
41
41
  "history": "记录",
42
42
  "markDone": "标为完成",
43
- "rowGone": "这一项已经不在卡片上了。"
43
+ "rowGone": "这一项已经不在卡片上了。",
44
+ "toast.done": "已标为完成。",
45
+ "toast.snooze": "已推迟。",
46
+ "toast.event": "已完成。",
47
+ "toast.undone": "已撤销。",
48
+ "toast.undoFailed": "没能撤销。",
49
+ "undo": "撤销",
50
+ "markNotDone": "标为未完成"
44
51
  }
45
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soffits/dsh-card-board",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "A data-driven card board for DeepSeek Harness: scripts write small JSON cards, the Web UI shows each person the boards they may see.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/presses.js CHANGED
@@ -9,10 +9,16 @@
9
9
  * A press is pending until its card file is written again after it (done),
10
10
  * or until the timeout passes with no write (unhandled). Recent presses are
11
11
  * kept in memory and reloaded from the log's tail after a restart.
12
+ *
13
+ * An action that declares an `inverse` can be taken back: the press keeps the
14
+ * inverse as the card offered it, and an undo press (`action: 'undo'`, naming
15
+ * the press it takes back in `undoes`) becomes the event of the way back. The
16
+ * log is append-only, so "undone" is the later record that points at the press.
12
17
  */
13
18
  import { randomUUID } from 'node:crypto'
14
19
  import { appendFile, mkdir, open, stat } from 'node:fs/promises'
15
20
  import { dirname } from 'node:path'
21
+ import { UNDO_KIND } from './schema.js'
16
22
 
17
23
  const KEEP_MS = 24 * 3600 * 1000
18
24
  const TAIL_BYTES = 1024 * 1024
@@ -71,19 +77,25 @@ export function createPresses({ logPath, publisher, notify = () => {}, timeoutSe
71
77
  async function press({ action, person, user, board, card, row, payload }) {
72
78
  const events = await list()
73
79
  const at = now()
74
- const twin = events.find(event => event.id === action.id && event.person === person && event.source.board === board && event.source.card === card && event.source.row === row && at - Date.parse(event.at) < DOUBLE_TAP_MS)
80
+ const twin = events.find(event => event.action !== UNDO_KIND && !events.some(later => later.undoes === event.press) && event.id === action.id && event.person === person && event.source.board === board && event.source.card === card && event.source.row === row && at - Date.parse(event.at) < DOUBLE_TAP_MS)
75
81
  if (twin) return twin
76
82
  const event = {
77
83
  press: randomUUID(),
78
84
  action: action.kind,
79
85
  id: action.id,
80
86
  ...(action.label ? { label: action.label } : {}),
87
+ ...(action.inverse ? { inverse: action.inverse } : {}),
81
88
  payload,
82
89
  person,
83
90
  ...(user ? { user } : {}),
84
91
  at: new Date(at).toISOString(),
85
92
  source: { plugin: 'dsh-card-board', board, card, ...(row === undefined ? {} : { row }) },
86
93
  }
94
+ return record(event)
95
+ }
96
+
97
+ /** Append one event to the log and the recent list, tell in-process listeners and publish it. */
98
+ async function record(event) {
87
99
  await mkdir(dirname(logPath), { recursive: true })
88
100
  await appendFile(logPath, `${JSON.stringify(event)}\n`, { mode: 0o600 })
89
101
  recent.push(event)
@@ -97,6 +109,37 @@ export function createPresses({ logPath, publisher, notify = () => {}, timeoutSe
97
109
  return event
98
110
  }
99
111
 
112
+ /**
113
+ * Take one press back. Whoever pressed may; the way back is the inverse the card offered when it was pressed, so
114
+ * nothing the browser says decides what happens. Undoing twice returns the first undo.
115
+ * @returns {Promise<{ event: object } | { problem: 'unknown' | 'forbidden' | 'no-inverse' }>}
116
+ */
117
+ async function undo({ press: id, person, user, board, card }) {
118
+ const events = await list()
119
+ const original = events.find(event => event.press === id && event.action !== UNDO_KIND)
120
+ if (original === undefined || original.source.board !== board || original.source.card !== card) return { problem: 'unknown' }
121
+ if (original.person !== person) return { problem: 'forbidden' }
122
+ if (!original.inverse) return { problem: 'no-inverse' }
123
+ const earlier = events.find(event => event.action === UNDO_KIND && event.undoes === id)
124
+ if (earlier) return { event: earlier }
125
+ // The press's own additions (a snooze time the person picked) don't belong to the way back.
126
+ const { until: _picked, ...own } = original.payload ?? {}
127
+ const event = {
128
+ press: randomUUID(),
129
+ action: UNDO_KIND,
130
+ of: original.action,
131
+ id: original.id,
132
+ undoes: original.press,
133
+ inverse: original.inverse.kind,
134
+ payload: { ...own, ...(original.inverse.payload ?? {}) },
135
+ person,
136
+ ...(user ? { user } : {}),
137
+ at: new Date(now()).toISOString(),
138
+ source: original.source,
139
+ }
140
+ return { event: await record(event) }
141
+ }
142
+
100
143
  /**
101
144
  * The presses on one card with their state: done once the card file was
102
145
  * written after the press, unhandled after the timeout, else pending.
@@ -104,16 +147,17 @@ export function createPresses({ logPath, publisher, notify = () => {}, timeoutSe
104
147
  async function statesFor(board, card, cardPath) {
105
148
  const events = (await list()).filter(event => event.source.board === board && event.source.card === card)
106
149
  if (events.length === 0) return []
150
+ const undone = new Set(events.filter(event => event.action === UNDO_KIND).map(event => event.undoes))
107
151
  const written = await stat(cardPath).then(info => info.mtimeMs, () => 0)
108
152
  const at = now()
109
- return events.map(event => {
153
+ return events.filter(event => event.action !== UNDO_KIND).map(event => {
110
154
  const time = Date.parse(event.at)
111
155
  // A step is carried out by sending it to the assistant (dsh-ui-actions does that right after the press), so it
112
156
  // is done once recorded; the others wait for their owner to write the card again.
113
- const state = event.action === 'step' || written > time ? 'done' : at - time > timeoutSeconds * 1000 ? 'unhandled' : 'pending'
114
- return { press: event.press, id: event.id, ...(event.source.row === undefined ? {} : { row: event.source.row }), at: event.at, state }
157
+ const state = undone.has(event.press) ? 'undone' : event.action === 'step' || written > time ? 'done' : at - time > timeoutSeconds * 1000 ? 'unhandled' : 'pending'
158
+ return { press: event.press, id: event.id, ...(event.source.row === undefined ? {} : { row: event.source.row }), at: event.at, state, ...(event.inverse && state !== 'undone' ? { undoable: true } : {}) }
115
159
  })
116
160
  }
117
161
 
118
- return { press, statesFor, list }
162
+ return { press, undo, statesFor, list }
119
163
  }
package/src/routes.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * GET /api/card-board/events?board=<id> Server-Sent Events: which card or board.json changed
11
11
  * POST /api/card-board/seen the card versions the viewer has seen
12
12
  * GET /api/card-board/locale?tag=fr the page's own words for a language (from locale/*.json)
13
- * POST /api/card-board/action press a step, done, snooze or event action
13
+ * POST /api/card-board/action press a step, done, snooze or event action, or take a press back (`undo`)
14
14
  *
15
15
  * Every card entry carries its content `version` (and `rows`, the versions of its keyed rows) and, when something
16
16
  * in it is new since the viewer last looked, `fresh: { card: true, rows: [keys] }`.
@@ -209,7 +209,8 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
209
209
  } catch {
210
210
  return json(400, { error: 'The body must be JSON.' })
211
211
  }
212
- const { board, card, row, id, until } = body ?? {}
212
+ const { board, card, row, id, until, undo } = body ?? {}
213
+ if (undo !== undefined) return undoPress({ board, card, undo })
213
214
  if (typeof board !== 'string' || !ID_PATTERN.test(board) || typeof card !== 'string' || !ID_PATTERN.test(card) || typeof id !== 'string')
214
215
  return json(400, { error: 'Say which board, card and action.' })
215
216
  if (row !== undefined && !(Number.isInteger(row) && row >= 0)) return json(400, { error: 'row must be a row index.' })
@@ -232,7 +233,22 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
232
233
  row,
233
234
  payload,
234
235
  })
235
- return json(200, { press: event.press, state: 'pending', at: event.at })
236
+ return json(200, { press: event.press, state: 'pending', at: event.at, ...(event.inverse ? { undoable: true } : {}) })
237
+ }
238
+
239
+ /** Take back a press: the body names the press, and the board and card it was made on. */
240
+ async function undoPress({ board, card, undo }) {
241
+ if (typeof board !== 'string' || !ID_PATTERN.test(board) || typeof card !== 'string' || !ID_PATTERN.test(card) || typeof undo !== 'string' || undo.length > 100)
242
+ return json(400, { error: 'Say which board, card and press.' })
243
+ const viewer = await viewerOf(people, identity())
244
+ if (viewer.unavailable) return json(503, { error: NO_PROVIDER })
245
+ const root = await resolveDataDir(dataDir)
246
+ const entry = root === undefined ? undefined : await readBoard(root, board)
247
+ if (!maySee(viewer, entry?.board) || entry === undefined) return json(403, { error: 'You can’t act on this board.' })
248
+ const result = await presses.undo({ press: undo, person: viewer.mode === 'owner' ? 'owner' : viewer.person, user: identity()?.current?.()?.id, board, card })
249
+ if (result.problem === 'forbidden') return json(403, { error: 'You can’t act on this board.' })
250
+ if (result.problem) return json(409, { error: 'This action can’t be undone.' })
251
+ return json(200, { press: result.event.press, state: 'pending', at: result.event.at, undoes: result.event.undoes })
236
252
  }
237
253
 
238
254
  return [
package/src/schema.js CHANGED
@@ -18,6 +18,10 @@ export const ICON_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/
18
18
  export const ACTION_KINDS = Object.freeze(['chat', 'step', 'done', 'snooze', 'event', 'link'])
19
19
  /** Kinds the server records as events; chat and link happen in the browser only. */
20
20
  export const PRESS_KINDS = Object.freeze(['step', 'done', 'snooze', 'event'])
21
+ /** Kinds that may declare an `inverse`, the way back the page offers as Undo. A step has none: sending it is the whole job. */
22
+ export const INVERSE_KINDS = Object.freeze(['done', 'snooze', 'event'])
23
+ /** The kind of the press that takes another back; its channel is `ui.action.undo`. */
24
+ export const UNDO_KIND = 'undo'
21
25
  /** Suggested steps per card or row: a few clear next moves, not a menu. */
22
26
  export const MAX_STEPS = 3
23
27
  export const ACTION_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/
@@ -177,6 +181,18 @@ function rowLook(c, row, path, keys, { toneRequired = false } = {}) {
177
181
  c.optional(row, 'active', v => timeWindow(c, v, join(path, 'active')))
178
182
  }
179
183
 
184
+ /** Problems with an action's `inverse`: the name its owner knows the way back by, and what that press carries. */
185
+ function inverse(c, value, path, kind) {
186
+ if (!INVERSE_KINDS.includes(kind)) return c.fail(path, `isn't allowed on a ${kind} action`)
187
+ if (!c.object(value, path, ['kind'], ['payload'])) return
188
+ if ('kind' in value && (typeof value.kind !== 'string' || !ACTION_ID_PATTERN.test(value.kind))) c.fail(join(path, 'kind'), 'must be letters, digits and . _ : - (up to 100), starting with a letter or digit')
189
+ if ('payload' in value) {
190
+ const payload = value.payload
191
+ if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) c.fail(join(path, 'payload'), 'must be an object')
192
+ else if (Buffer.byteLength(JSON.stringify(payload)) > MAX_PAYLOAD_BYTES) c.fail(join(path, 'payload'), `is larger than ${MAX_PAYLOAD_BYTES} bytes`)
193
+ }
194
+ }
195
+
180
196
  /** Problems with an `actions` list (on a card, a list row or a status row). */
181
197
  function actions(c, list, path) {
182
198
  if (!c.array(list, path, { max: MAX_ACTIONS })) return
@@ -184,7 +200,7 @@ function actions(c, list, path) {
184
200
  const seen = new Set()
185
201
  list.forEach((action, i) => {
186
202
  const p = join(path, i)
187
- if (!c.object(action, p, ['kind', 'id'], ['label', 'payload'])) return
203
+ if (!c.object(action, p, ['kind', 'id'], ['label', 'payload', 'inverse'])) return
188
204
  const kindOk = c.oneOf(action.kind, join(p, 'kind'), ACTION_KINDS)
189
205
  if (typeof action.id !== 'string' || !ACTION_ID_PATTERN.test(action.id)) c.fail(join(p, 'id'), 'must be letters, digits and . _ : - (up to 100), starting with a letter or digit')
190
206
  else if (seen.has(action.id)) c.fail(join(p, 'id'), 'repeats another action id here')
@@ -198,6 +214,7 @@ function actions(c, list, path) {
198
214
  if (Buffer.byteLength(JSON.stringify(payload)) > MAX_PAYLOAD_BYTES) c.fail(pp, `is larger than ${MAX_PAYLOAD_BYTES} bytes`)
199
215
  }
200
216
  if (!kindOk) return
217
+ c.optional(action, 'inverse', v => inverse(c, v, join(p, 'inverse'), action.kind))
201
218
  if (action.kind === 'link') {
202
219
  if (!isSafeLink(payload?.url)) c.fail(join(join(p, 'payload'), 'url'), 'is required: an http(s) URL or a path starting with /')
203
220
  }