@soffits/dsh-card-board 0.17.3 → 0.18.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 +10 -0
- package/README.md +4 -2
- package/client.js +25 -15
- package/index.js +4 -3
- package/package.json +1 -1
- package/src/presses.js +4 -1
- package/src/routes.js +14 -5
- package/src/schema.js +15 -4
- package/src/store.js +7 -7
- package/src/watch.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
A press names its row by the row's `key` (`source.row` in the event is now that key), so it lands on the row the person tapped even when the card was rewritten in between. Before, it named the row by its place: after a handled row dropped out, or a quick second tick, a press could answer or tick the row below it, since rows often share button ids. A row without a key still goes by its place; an index that points at a keyed row is refused. Rows ticked this visit are kept apart by key too, so ticking a second one no longer hides the first.
|
|
6
|
+
|
|
7
|
+
Open live streams now end when the plugin is unloaded or reloaded, so pages reconnect instead of waiting on a stream that will never send again (the cleanup was registered on an event Cordis doesn't send, so file watches leaked too). A card that can be found but not read shows as a broken card instead of failing the whole board, an unreadable action log no longer blocks every board, and a failing change listener is logged instead of escaping.
|
|
8
|
+
|
|
9
|
+
## 0.17.4
|
|
10
|
+
|
|
11
|
+
The opened view wraps a long unbroken word (an id, a key, a path) in its heading and text instead of growing wider than a phone screen and scrolling sideways, and an opened row's tick box flows in one row with its other buttons.
|
|
12
|
+
|
|
3
13
|
## 0.17.3
|
|
4
14
|
|
|
5
15
|
An opened row reads well on a phone. The sheet used to draw it as a list row, so on a narrow screen its title was squeezed into a column a word wide beside its chip and buttons, under a heading that already said the same. Now the heading is the title, and under it come the row's facts on one wrapping line (chip, sub, day), its detail, and every button with its label on a wrapping row: the detail's, the row's own (an unlabelled done as a labelled box), then Ask. List rows on a card keep their layout, but their words no longer shrink below a readable width: what doesn't fit beside them wraps underneath, and in a narrow card the buttons take at most half the row.
|
package/README.md
CHANGED
|
@@ -329,16 +329,18 @@ The plugin doesn't act on a press itself. It checks that the person may see the
|
|
|
329
329
|
"person": "alex",
|
|
330
330
|
"user": "<verified user id>",
|
|
331
331
|
"at": "2026-03-02T09:41:12.000Z",
|
|
332
|
-
"source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row":
|
|
332
|
+
"source": { "plugin": "dsh-card-board", "board": "home", "card": "chores", "row": "chore-2" }
|
|
333
333
|
}
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
+
`source.row` names the row by its `key`, so a press lands on the row the person saw even when the card was rewritten in between; a row without a key goes by its place in `rows`, which a rewrite can shift, so give every row with buttons a key.
|
|
337
|
+
|
|
336
338
|
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.
|
|
337
339
|
|
|
338
340
|
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.
|
|
339
341
|
|
|
340
342
|
```json
|
|
341
|
-
{ "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":
|
|
343
|
+
{ "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": "chore-2" } }
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
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`.
|
package/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @soffits/dsh-card-board 0.
|
|
1
|
+
/* @soffits/dsh-card-board 0.18.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) => {
|
|
@@ -272,7 +272,9 @@ button.cb-cardMore{border:0;background:transparent;padding:0;font:inherit;cursor
|
|
|
272
272
|
.cb-bubbleHead{color:var(--dsw-alias-label-tertiary)}
|
|
273
273
|
/* The opened card */
|
|
274
274
|
.cb-sheetModal.cb-sheetModal{width:min(720px,calc(100vw - 32px));max-width:none;max-height:100%}
|
|
275
|
-
.cb-sheet{min-width:0;min-height:0;overflow-y:auto;overscroll-behavior:contain}
|
|
275
|
+
.cb-sheet{min-width:0;min-height:0;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;overflow-wrap:anywhere}
|
|
276
|
+
/* a long unbroken word (an id, a key, a path) wraps instead of widening the sheet */
|
|
277
|
+
.cb-sheetModal h2{min-width:0;overflow-wrap:anywhere}
|
|
276
278
|
.cb-cardInSheet{padding:0;box-shadow:none;background:transparent;border-radius:0}
|
|
277
279
|
.cb-detail{display:flex;flex-direction:column;gap:14px;margin-top:4px}
|
|
278
280
|
.cb-detailText{margin:0;color:var(--dsw-alias-label-secondary);font-size:14px;line-height:21px;white-space:pre-wrap}
|
|
@@ -288,6 +290,7 @@ button.cb-cardMore{border:0;background:transparent;padding:0;font:inherit;cursor
|
|
|
288
290
|
.cb-openRow .cb-detail{margin-top:0}
|
|
289
291
|
.cb-openActions{display:flex;flex-direction:column;gap:8px;min-width:0}
|
|
290
292
|
.cb-openButtons{display:flex;flex-wrap:wrap;align-items:center;gap:6px;min-width:0}
|
|
293
|
+
.cb-openButtons>.ua-bar{display:contents}
|
|
291
294
|
.cb-doneBoxLabelled{justify-content:flex-start;padding:0 10px 0 6px;border-radius:8px;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3);font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
|
|
292
295
|
/* the opened view shows every word: nothing is cut to a line or two */
|
|
293
296
|
.cb-sheet .cb-trunc{white-space:normal;display:block;-webkit-line-clamp:unset;overflow:visible;text-overflow:clip}
|
|
@@ -979,12 +982,14 @@ function dropAfter(rect, x, y, single) {
|
|
|
979
982
|
|
|
980
983
|
// src/client/ticks.js
|
|
981
984
|
var doneOf = (row) => row?.actions?.find((action) => action.kind === "done" && action.label === void 0);
|
|
985
|
+
var rowRef = (row, index) => row?.key ?? index;
|
|
986
|
+
var keptId = (row) => row.key ?? doneOf(row)?.id;
|
|
982
987
|
function keepOf(row, index) {
|
|
983
988
|
const done = doneOf(row);
|
|
984
|
-
return done === void 0 ? void 0 : { id:
|
|
989
|
+
return done === void 0 ? void 0 : { id: keptId(row), index, row: { ...row, checked: true, actions: [done] } };
|
|
985
990
|
}
|
|
986
991
|
function keepTicked(rows, kept = []) {
|
|
987
|
-
const present = new Set(rows.map(
|
|
992
|
+
const present = new Set(rows.map(keptId));
|
|
988
993
|
const missing = kept.filter((entry) => !present.has(entry.id)).sort((a, b) => a.index - b.index);
|
|
989
994
|
if (missing.length === 0) return rows;
|
|
990
995
|
const merged = [...rows];
|
|
@@ -1115,13 +1120,14 @@ function Row({ lead, title, sub, meta, value, spark, row, index, washCount, fres
|
|
|
1115
1120
|
buttons?.length > 0 && (0, import_react6.createElement)(
|
|
1116
1121
|
"span",
|
|
1117
1122
|
{ className: "cb-rowActions" },
|
|
1118
|
-
buttons.some((action) => action.kind === "step") && rowActions(index, buttons, "steps"),
|
|
1119
|
-
rowActions(index, buttons, "buttons")
|
|
1123
|
+
buttons.some((action) => action.kind === "step") && rowActions(rowRef(row, index), buttons, "steps"),
|
|
1124
|
+
rowActions(rowRef(row, index), buttons, "buttons")
|
|
1120
1125
|
)
|
|
1121
1126
|
);
|
|
1122
1127
|
}
|
|
1123
1128
|
function DoneBox({ row, index, done, rowControls, t, labelled = false }) {
|
|
1124
|
-
const
|
|
1129
|
+
const ref = rowRef(row, index);
|
|
1130
|
+
const { checked, undo } = doneState(row, rowControls.latest(ref, done.id));
|
|
1125
1131
|
const label = t(checked ? undo ? "markNotDone" : "checked" : "markDone");
|
|
1126
1132
|
return (0, import_react6.createElement)(
|
|
1127
1133
|
"span",
|
|
@@ -1132,7 +1138,7 @@ function DoneBox({ row, index, done, rowControls, t, labelled = false }) {
|
|
|
1132
1138
|
title: label,
|
|
1133
1139
|
label: (0, import_react6.createElement)("span", { className: labelled ? void 0 : "cb-visuallyHidden" }, label),
|
|
1134
1140
|
onChange: (value) => {
|
|
1135
|
-
if (value) rowControls.press(
|
|
1141
|
+
if (value) rowControls.press(ref, done);
|
|
1136
1142
|
else if (undo) rowControls.undo(undo);
|
|
1137
1143
|
}
|
|
1138
1144
|
})
|
|
@@ -1147,7 +1153,7 @@ function ListCard({ data, live, locale, t, rowActions, ask, all = false, onOpenR
|
|
|
1147
1153
|
const hidden = listed.length - rows.length;
|
|
1148
1154
|
const ticked = (row) => {
|
|
1149
1155
|
const done = doneOf(row);
|
|
1150
|
-
return done !== void 0 && rowControls !== void 0 ? doneState(row, rowControls.latest(data.rows.indexOf(row), done.id)).checked : row.checked === true;
|
|
1156
|
+
return done !== void 0 && rowControls !== void 0 ? doneState(row, rowControls.latest(rowRef(row, data.rows.indexOf(row)), done.id)).checked : row.checked === true;
|
|
1151
1157
|
};
|
|
1152
1158
|
const progress = data.progress;
|
|
1153
1159
|
return (0, import_react6.createElement)(
|
|
@@ -1221,12 +1227,12 @@ function OpenedRow({ row, kind, index, live, locale, t, rowActions, ask, rowCont
|
|
|
1221
1227
|
(buttons.length > 0 || done && rowControls) && (0, import_react6.createElement)(
|
|
1222
1228
|
"footer",
|
|
1223
1229
|
{ className: "cb-openActions" },
|
|
1224
|
-
buttons.some((action) => action.kind === "step") && rowActions(index, buttons, "steps", false),
|
|
1230
|
+
buttons.some((action) => action.kind === "step") && rowActions(rowRef(row, index), buttons, "steps", false),
|
|
1225
1231
|
(0, import_react6.createElement)(
|
|
1226
1232
|
"div",
|
|
1227
1233
|
{ className: "cb-openButtons" },
|
|
1228
1234
|
done && rowControls && (0, import_react6.createElement)(DoneBox, { row, index, done, rowControls, t, labelled: true }),
|
|
1229
|
-
buttons.some((action) => action.kind !== "step") && rowActions(index, buttons, "buttons", false)
|
|
1235
|
+
buttons.some((action) => action.kind !== "step") && rowActions(rowRef(row, index), buttons, "buttons", false)
|
|
1230
1236
|
)
|
|
1231
1237
|
)
|
|
1232
1238
|
);
|
|
@@ -1558,10 +1564,14 @@ function Card({ entry, live, boardId, assistant, tracks, active, locale, t, pres
|
|
|
1558
1564
|
lines: row === void 0 ? summaryLines(card, locale, t).slice(0, 15) : [line],
|
|
1559
1565
|
context: { board: boardId, card: entry.id, ...row === void 0 ? {} : { row }, type: card.type, updatedAt: card.updatedAt }
|
|
1560
1566
|
});
|
|
1561
|
-
const
|
|
1567
|
+
const indexOf = (row) => typeof row === "string" ? card.data.rows.findIndex((other) => other.key === row) : row;
|
|
1568
|
+
const rowLine = (row) => card.type === "status" ? statusRowLine(card.data.rows[indexOf(row)], locale) : listRowLine(card.data.rows[indexOf(row)]);
|
|
1562
1569
|
const askName = assistant ? t("action.chatNamed", { name: assistant }) : void 0;
|
|
1563
1570
|
const named = (list) => assistant ? list?.map((action) => action.kind === "chat" && action.label === void 0 ? { ...action, label: askName } : action) : list;
|
|
1564
|
-
const onPress = (target) => (action, extra) =>
|
|
1571
|
+
const onPress = (target) => (action, extra) => {
|
|
1572
|
+
const index = target.row === void 0 ? -1 : indexOf(target.row);
|
|
1573
|
+
return press(action, extra, { card: entry.id, ...target }, index >= 0 ? { row: card.data.rows[index], index } : void 0);
|
|
1574
|
+
};
|
|
1565
1575
|
const rowActions = actions && ((row, list, part2, compact = true) => (0, import_react10.createElement)(actions.ActionBar, {
|
|
1566
1576
|
actions: named(list),
|
|
1567
1577
|
part: part2,
|
|
@@ -2045,11 +2055,11 @@ function BoardsPage() {
|
|
|
2045
2055
|
showToast({ text: "toast.undoFailed" });
|
|
2046
2056
|
}
|
|
2047
2057
|
}, [post, showToast]);
|
|
2048
|
-
const press = (0, import_react15.useCallback)(async (action, extra, target,
|
|
2058
|
+
const press = (0, import_react15.useCallback)(async (action, extra, target, at2) => {
|
|
2049
2059
|
const answer = await post({ ...target, id: action.id, ...extra });
|
|
2050
2060
|
if (answer?.undoable) {
|
|
2051
2061
|
showToast({ text: TOAST_KEYS[action.kind] ?? "toast.event", undo: () => undo(answer.press, target.card) });
|
|
2052
|
-
const keep = action.kind === "done" &&
|
|
2062
|
+
const keep = action.kind === "done" && at2 !== void 0 ? keepOf(at2.row, at2.index) : void 0;
|
|
2053
2063
|
if (keep) setKept((prev) => ({ ...prev, [target.card]: withKept(prev[target.card], keep) }));
|
|
2054
2064
|
}
|
|
2055
2065
|
return answer;
|
package/index.js
CHANGED
|
@@ -68,9 +68,9 @@ export function apply(ctx, config) {
|
|
|
68
68
|
timeoutSeconds: config.actionTimeoutSeconds ?? 300,
|
|
69
69
|
warn: message => logger.warn(message),
|
|
70
70
|
})
|
|
71
|
-
const watches = createWatches()
|
|
72
|
-
ctx.
|
|
73
|
-
const routes = createRoutes({
|
|
71
|
+
const watches = createWatches({ warn: message => logger.warn(message) })
|
|
72
|
+
ctx.effect(() => () => watches.close())
|
|
73
|
+
const { routes, close } = createRoutes({
|
|
74
74
|
dataDir,
|
|
75
75
|
people,
|
|
76
76
|
identity: () => ctx.get('requestIdentity'),
|
|
@@ -82,6 +82,7 @@ export function apply(ctx, config) {
|
|
|
82
82
|
messages: createMessages(fileURLToPath(new URL('./locale', import.meta.url))),
|
|
83
83
|
version,
|
|
84
84
|
})
|
|
85
|
+
ctx.effect(() => close)
|
|
85
86
|
for (const route of routes) ctx.connection.fetch.register(route)
|
|
86
87
|
logger.info(`serving boards from ${dataDir} (${people.enabled ? 'per person' : 'single owner'})`)
|
|
87
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-card-board",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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
|
@@ -64,7 +64,10 @@ async function readTail(path) {
|
|
|
64
64
|
*/
|
|
65
65
|
export function createPresses({ logPath, publisher, notify = () => {}, timeoutSeconds, warn = () => {}, now = Date.now }) {
|
|
66
66
|
let recent
|
|
67
|
-
const loaded = readTail(logPath).then(events => { recent = events }
|
|
67
|
+
const loaded = readTail(logPath).then(events => { recent = events }, error => {
|
|
68
|
+
warn(`action log ${logPath} unreadable, starting without recent presses: ${error.message}`)
|
|
69
|
+
recent = []
|
|
70
|
+
})
|
|
68
71
|
|
|
69
72
|
async function list() {
|
|
70
73
|
await loaded
|
package/src/routes.js
CHANGED
|
@@ -20,7 +20,7 @@ import { join } from 'node:path'
|
|
|
20
20
|
import { mayAct, maySee, maySeeCard, viewerOf, withoutActions } from './access.js'
|
|
21
21
|
import { parseArrangement } from './arrange.js'
|
|
22
22
|
import { LANGUAGE_ID } from './messages.js'
|
|
23
|
-
import { ID_PATTERN, PRESS_KINDS, findAction } from './schema.js'
|
|
23
|
+
import { ID_PATTERN, KEY_PATTERN, PRESS_KINDS, findAction } from './schema.js'
|
|
24
24
|
import { cardVersions, freshness, parseSeen } from './seen.js'
|
|
25
25
|
import { boardTag, cardPath, cardTag, listBoards, readBoard, readCard, readCards, resolveDataDir } from './store.js'
|
|
26
26
|
|
|
@@ -63,6 +63,9 @@ const NO_PROVIDER = 'This board needs a sign-in plugin that provides requestIden
|
|
|
63
63
|
* @param {number} [options.heartbeatMs]
|
|
64
64
|
*/
|
|
65
65
|
export function createRoutes({ dataDir, people, identity, pollSeconds, presses, seen, arrange, watches, messages, version = '', heartbeatMs = HEARTBEAT_MS }) {
|
|
66
|
+
/** Ends each open events stream. DSH only drops a route on unload, so a stream it already answered would live on. */
|
|
67
|
+
const streams = new Set()
|
|
68
|
+
|
|
66
69
|
/** The viewer and their board, or the Response that refuses them. */
|
|
67
70
|
async function access(board) {
|
|
68
71
|
const viewer = await viewerOf(people, identity())
|
|
@@ -154,14 +157,20 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
154
157
|
let unwatch = () => {}
|
|
155
158
|
let unarrange = () => {}
|
|
156
159
|
const heartbeat = setInterval(() => send(': ping\n\n'), heartbeatMs)
|
|
160
|
+
const end = () => {
|
|
161
|
+
finish()
|
|
162
|
+
try { controller.close() } catch { /* already closed */ }
|
|
163
|
+
}
|
|
157
164
|
finish = () => {
|
|
158
165
|
if (!open) return
|
|
159
166
|
open = false
|
|
160
167
|
clearInterval(heartbeat)
|
|
161
168
|
unwatch()
|
|
162
169
|
unarrange()
|
|
170
|
+
streams.delete(end)
|
|
163
171
|
request.signal?.removeEventListener?.('abort', finish)
|
|
164
172
|
}
|
|
173
|
+
streams.add(end)
|
|
165
174
|
request.signal?.addEventListener?.('abort', finish)
|
|
166
175
|
send(': connected\n\n')
|
|
167
176
|
// The viewer's own arrangement changing elsewhere (another device) reaches this page too.
|
|
@@ -172,8 +181,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
172
181
|
const again = await access(id)
|
|
173
182
|
if (again.refused) {
|
|
174
183
|
data({ type: 'gone' })
|
|
175
|
-
|
|
176
|
-
try { controller.close() } catch { /* already closed */ }
|
|
184
|
+
end()
|
|
177
185
|
return
|
|
178
186
|
}
|
|
179
187
|
}
|
|
@@ -250,7 +258,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
250
258
|
if (undo !== undefined) return undoPress({ board, card, undo })
|
|
251
259
|
if (typeof board !== 'string' || !ID_PATTERN.test(board) || typeof card !== 'string' || !ID_PATTERN.test(card) || typeof id !== 'string')
|
|
252
260
|
return json(400, { error: 'Say which board, card and action.' })
|
|
253
|
-
if (row !== undefined && !(Number.isInteger(row) && row >= 0)) return json(400, { error: 'row must be a row index.' })
|
|
261
|
+
if (row !== undefined && !(Number.isInteger(row) && row >= 0) && !(typeof row === 'string' && KEY_PATTERN.test(row))) return json(400, { error: 'row must be a row key, or the index of a row without one.' })
|
|
254
262
|
if (until !== undefined && (typeof until !== 'string' || !DATE_TIME.test(until) || Number.isNaN(Date.parse(until))))
|
|
255
263
|
return json(400, { error: 'until must be an ISO date-time with a zone.' })
|
|
256
264
|
const viewer = await viewerOf(people, identity())
|
|
@@ -288,7 +296,7 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
288
296
|
return json(200, { press: result.event.press, state: 'pending', at: result.event.at, undoes: result.event.undoes })
|
|
289
297
|
}
|
|
290
298
|
|
|
291
|
-
|
|
299
|
+
const routes = [
|
|
292
300
|
{ path: BOARDS_PATH, methods: ['GET'], requestBody: 'buffered', fetch: boards },
|
|
293
301
|
{ path: BOARD_PATH, methods: ['GET'], requestBody: 'buffered', fetch: board },
|
|
294
302
|
{ path: CARD_PATH, methods: ['GET'], requestBody: 'buffered', fetch: card },
|
|
@@ -298,4 +306,5 @@ export function createRoutes({ dataDir, people, identity, pollSeconds, presses,
|
|
|
298
306
|
{ path: LOCALE_PATH, methods: ['GET'], requestBody: 'buffered', fetch: locale },
|
|
299
307
|
{ path: ACTION_PATH, methods: ['POST'], requestBody: 'buffered', fetch: action },
|
|
300
308
|
]
|
|
309
|
+
return { routes, close: () => { for (const end of [...streams]) end() } }
|
|
301
310
|
}
|
package/src/schema.js
CHANGED
|
@@ -603,14 +603,25 @@ export function checkCard(card) {
|
|
|
603
603
|
return c.problems
|
|
604
604
|
}
|
|
605
605
|
|
|
606
|
+
/**
|
|
607
|
+
* The row a press names: by its `key`, so a press still finds it after the card
|
|
608
|
+
* was rewritten; only a row without a key goes by its place.
|
|
609
|
+
*/
|
|
610
|
+
export function findRow(card, row) {
|
|
611
|
+
const rows = card?.data?.rows
|
|
612
|
+
if (!Array.isArray(rows)) return undefined
|
|
613
|
+
if (typeof row === 'string') return rows.find(candidate => candidate?.key === row)
|
|
614
|
+
return rows[row]?.key === undefined ? rows[row] : undefined
|
|
615
|
+
}
|
|
616
|
+
|
|
606
617
|
/**
|
|
607
618
|
* The action a press names, looked up in the card as written: on the card
|
|
608
|
-
* itself, or on
|
|
609
|
-
* those its detail shows when opened. Undefined when there is no
|
|
610
|
-
* so a browser can only press what the data offers.
|
|
619
|
+
* itself, or on a row of a list or status card (`findRow`), among its own
|
|
620
|
+
* buttons and those its detail shows when opened. Undefined when there is no
|
|
621
|
+
* such action, so a browser can only press what the data offers.
|
|
611
622
|
*/
|
|
612
623
|
export function findAction(card, actionId, row) {
|
|
613
|
-
const holder = row === undefined ? card : card
|
|
624
|
+
const holder = row === undefined ? card : findRow(card, row)
|
|
614
625
|
const list = [holder?.actions, holder?.detail?.actions].flatMap(value => (Array.isArray(value) ? value : []))
|
|
615
626
|
return list.find(action => action?.id === actionId)
|
|
616
627
|
}
|
package/src/store.js
CHANGED
|
@@ -19,17 +19,17 @@ const MAX_BOARD_BYTES = 64 * 1024
|
|
|
19
19
|
|
|
20
20
|
/** A file's content if it is a regular file inside `root` and not too big; else a reason. */
|
|
21
21
|
async function readInside(root, path, maxBytes) {
|
|
22
|
-
let real
|
|
23
22
|
try {
|
|
24
|
-
real = await realpath(path)
|
|
23
|
+
const real = await realpath(path)
|
|
24
|
+
if (!real.startsWith(root + sep)) return { problem: 'points outside the data folder' }
|
|
25
|
+
const info = await stat(real)
|
|
26
|
+
if (!info.isFile()) return { problem: 'is not a file' }
|
|
27
|
+
if (info.size > maxBytes) return { problem: `is larger than ${Math.round(maxBytes / 1024)} KB` }
|
|
28
|
+
return { text: await readFile(real, 'utf8') }
|
|
25
29
|
} catch (error) {
|
|
30
|
+
// Gone between two of the reads (a producer replacing it) counts as missing, like gone before them.
|
|
26
31
|
return { missing: error.code === 'ENOENT', problem: error.code === 'ENOENT' ? 'file not found' : `cannot read: ${error.code ?? error.message}` }
|
|
27
32
|
}
|
|
28
|
-
if (!real.startsWith(root + sep)) return { problem: 'points outside the data folder' }
|
|
29
|
-
const info = await stat(real)
|
|
30
|
-
if (!info.isFile()) return { problem: 'is not a file' }
|
|
31
|
-
if (info.size > maxBytes) return { problem: `is larger than ${Math.round(maxBytes / 1024)} KB` }
|
|
32
|
-
return { text: await readFile(real, 'utf8') }
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async function readJson(root, path, maxBytes, check) {
|
package/src/watch.js
CHANGED
|
@@ -40,8 +40,9 @@ export function changes(before, after) {
|
|
|
40
40
|
* @param {object} [options]
|
|
41
41
|
* @param {number} [options.pollMs] - the stat poll's interval (default 10 s)
|
|
42
42
|
* @param {number} [options.settleMs] - how long a burst of file events is gathered before one scan (default 120 ms)
|
|
43
|
+
* @param {(message: string) => void} [options.warn] - told when a change listener fails
|
|
43
44
|
*/
|
|
44
|
-
export function createWatches({ pollMs = 10_000, settleMs = 120 } = {}) {
|
|
45
|
+
export function createWatches({ pollMs = 10_000, settleMs = 120, warn = () => {} } = {}) {
|
|
45
46
|
const boards = new Map()
|
|
46
47
|
|
|
47
48
|
function open(dir) {
|
|
@@ -55,7 +56,9 @@ export function createWatches({ pollMs = 10_000, settleMs = 120 } = {}) {
|
|
|
55
56
|
const files = await snapshot(dir)
|
|
56
57
|
const events = entry.files === null ? [] : changes(entry.files, files)
|
|
57
58
|
entry.files = files
|
|
58
|
-
for (const event of events)
|
|
59
|
+
for (const event of events)
|
|
60
|
+
for (const listener of entry.listeners)
|
|
61
|
+
Promise.resolve().then(() => listener(event)).catch(error => warn(`a change listener failed: ${error.message}`))
|
|
59
62
|
} while (entry.again)
|
|
60
63
|
})().finally(() => { entry.scanning = null })
|
|
61
64
|
return entry.scanning
|