@wastee/dsh-goal-record-board 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/README.md +8 -5
- package/client.js +142 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,18 +29,21 @@ dsh plugin add @wastee/dsh-goal-record-board
|
|
|
29
29
|
## 用法
|
|
30
30
|
|
|
31
31
|
1. 当前会话有目标时,会话标题栏会出现一个清单图标的按钮,鼠标悬停时显示"目标记录看板"。点击后在右侧栏打开"目标记录看板"页签;没有目标的会话不显示这个按钮。
|
|
32
|
-
2.
|
|
32
|
+
2. 打开看板后,先显示第一批记录:取最近的若干整轮,累计不少于 10 条记录;同一轮的记录不拆开,所以这一批可能略多于 10 条,某一轮记录特别多时列表也会跟着变长。总共不足 10 条时全部显示。顶部一行条数:部分显示时写"已显示 X / N 条记录 · M 轮",全部显示后写"N 条记录 · M 轮"。轮数按不同的轮次号统计;轮次未知的记录只计入条数,不计入轮数。条数行的数字变化会被屏幕阅读器读出来。
|
|
33
33
|
3. 记录按轮次分组,最新的一轮排在最上面。组标题写"第 N 轮";这一轮最新的记录不在今天时,组标题右侧再补上日期(月-日)。
|
|
34
34
|
4. 每条记录默认折叠成一行,从左到右是时间和这条记录的问题摘要。摘要取问题一段的内容,把换行压成空格,太长时在末尾省略;问题为空时改显示成果的摘要。
|
|
35
35
|
5. 点击一行,在这行下方直接显示问题、方案、成果三段全文,长文字不截断,也不需要再点第二次;再点一次同一行收起。
|
|
36
36
|
6. 焦点在展开的记录里时,按 Esc 收起这条记录,焦点回到这一行的按钮上。
|
|
37
|
-
7.
|
|
38
|
-
8.
|
|
39
|
-
9.
|
|
37
|
+
7. 还有更早的记录时,列表末尾显示"加载更多"按钮,跟着列表一起滚动。点一次继续显示后面的整轮,每次新增至少 10 条,剩下的不足 10 条时一次显示完;已经展开的行保持展开,焦点落到新出现的第一行。"加载更多"可以用 Tab 选中,按 Enter 或空格触发。
|
|
38
|
+
8. 全部记录显示完后,"加载更多"按钮消失,列表末尾显示"没有更早的记录了"。如果第一批就包含全部记录,不显示按钮,也不显示这条提示。
|
|
39
|
+
9. 看板在页签内部自己滚动。记录多时,先显示最近几轮,点"加载更多"继续往前看,可以一直翻到最早一轮;最底部的记录能完整看到;滚动时当前这一轮的组标题固定在顶部。
|
|
40
|
+
10. 看板开着时新产生的记录会出现在最上面,并短暂高亮一次;条数行跟着更新,已经看到的更早记录不会被挤掉。
|
|
41
|
+
11. 切到别的页签再回来,或关掉再打开看板,会重新从第一批开始显示。
|
|
42
|
+
12. 没有记录时,看板显示空状态提示,不显示条数行,也没有"加载更多"按钮和"没有更早的记录了"提示。
|
|
40
43
|
|
|
41
44
|
## 数据从哪来
|
|
42
45
|
|
|
43
|
-
记录来自模型在每轮结束时调用的 `goal_record`
|
|
46
|
+
记录来自模型在每轮结束时调用的 `goal_record` 工具。这个工具调用的三个字段(问题、方案、成果)会被会话日志持久保存;看板从日志中派生出列表,不写入第二份存储。因此刷新、分叉或重放会话后,记录仍然可以从日志重建。记录列表仍然一次发给浏览器,分批显示只影响页面上画多少行,不改日志、投影格式和 `goal_record` 工具。
|
|
44
47
|
|
|
45
48
|
只有三个字段都非空、且目标处于活动状态的轮次才会出现在看板上。
|
|
46
49
|
|
package/client.js
CHANGED
|
@@ -19,6 +19,8 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const NS = 'goalRecordBoard'
|
|
20
20
|
/** Stable empty list for renders without a projection. */
|
|
21
21
|
const NO_RECORDS = []
|
|
22
|
+
/** Target record count for the first batch and for each "load more" click. */
|
|
23
|
+
const RECORDS_PER_PAGE = 10
|
|
22
24
|
|
|
23
25
|
const zh = {
|
|
24
26
|
menu: '目标记录看板',
|
|
@@ -32,6 +34,9 @@ window.__ModuleLoader__.load({
|
|
|
32
34
|
roundHeader: '第 {n} 轮',
|
|
33
35
|
unknownRound: '轮次未知',
|
|
34
36
|
countLine: '{n} 条记录 · {m} 轮',
|
|
37
|
+
countLinePartial: '已显示 {r} / {n} 条记录 · {m} 轮',
|
|
38
|
+
loadMore: '加载更多',
|
|
39
|
+
endOfList: '没有更早的记录了',
|
|
35
40
|
}
|
|
36
41
|
const en = {
|
|
37
42
|
menu: 'Goal Record Board',
|
|
@@ -45,6 +50,9 @@ window.__ModuleLoader__.load({
|
|
|
45
50
|
roundHeader: 'Round {n}',
|
|
46
51
|
unknownRound: 'Unknown round',
|
|
47
52
|
countLine: '{n} records · {m} rounds',
|
|
53
|
+
countLinePartial: 'Showing {r} of {n} records · {m} rounds',
|
|
54
|
+
loadMore: 'Load more',
|
|
55
|
+
endOfList: 'No earlier records',
|
|
48
56
|
}
|
|
49
57
|
const dicts = { zh, en, ja: en, es: en, fr: en, de: en, ru: en, pt: en }
|
|
50
58
|
|
|
@@ -109,6 +117,51 @@ window.__ModuleLoader__.load({
|
|
|
109
117
|
return groups
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Whole groups from index `start` onward until at least `minimum` records
|
|
122
|
+
* are covered. A turn is never split across batches; running out of groups
|
|
123
|
+
* returns whatever is left.
|
|
124
|
+
*/
|
|
125
|
+
function takeBatch(groups, start, minimum) {
|
|
126
|
+
const batch = []
|
|
127
|
+
let total = 0
|
|
128
|
+
for (let index = start; index < groups.length && total < minimum; index += 1) {
|
|
129
|
+
const group = groups[index]
|
|
130
|
+
batch.push(group)
|
|
131
|
+
total += group.records.length
|
|
132
|
+
}
|
|
133
|
+
return batch
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Newest-first groups up to and including the group that holds `pivotId`;
|
|
138
|
+
* null when that record is gone and the caller must fall back to the first
|
|
139
|
+
* batch.
|
|
140
|
+
*/
|
|
141
|
+
function groupsThroughPivot(groups, pivotId) {
|
|
142
|
+
if (typeof pivotId !== 'string') return null
|
|
143
|
+
for (let index = 0; index < groups.length; index += 1) {
|
|
144
|
+
if (groups[index].records.some(record => record.id === pivotId)) {
|
|
145
|
+
return groups.slice(0, index + 1)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Total records across a list of turn groups. */
|
|
152
|
+
function sumRecords(groups) {
|
|
153
|
+
let total = 0
|
|
154
|
+
for (const group of groups) total += group.records.length
|
|
155
|
+
return total
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Id of the oldest record in a newest-first batch: the shown boundary. */
|
|
159
|
+
function lastRecordId(groups) {
|
|
160
|
+
const group = groups[groups.length - 1]
|
|
161
|
+
if (group === undefined) return null
|
|
162
|
+
return group.records[group.records.length - 1].id
|
|
163
|
+
}
|
|
164
|
+
|
|
112
165
|
/** Collapse text to one line: newlines become spaces and outer blanks go away. */
|
|
113
166
|
function singleLine(text) {
|
|
114
167
|
return typeof text === 'string' ? text.replace(/\s*\n\s*/g, ' ').trim() : ''
|
|
@@ -137,6 +190,15 @@ window.__ModuleLoader__.load({
|
|
|
137
190
|
.replace('{m}', String(counts.rounds))
|
|
138
191
|
}
|
|
139
192
|
|
|
193
|
+
/** Partial count line: shown records, total records and total rounds. */
|
|
194
|
+
function partialCountText(t, shownRecords, records) {
|
|
195
|
+
const counts = countRecords(records)
|
|
196
|
+
return String(t('countLinePartial'))
|
|
197
|
+
.replace('{r}', String(shownRecords))
|
|
198
|
+
.replace('{n}', String(counts.total))
|
|
199
|
+
.replace('{m}', String(counts.rounds))
|
|
200
|
+
}
|
|
201
|
+
|
|
140
202
|
/** Row clock; a record on another day than its group's newest also shows MM-DD. */
|
|
141
203
|
function rowTime(record, groupDay) {
|
|
142
204
|
const clock = formatClock(record.time)
|
|
@@ -167,11 +229,20 @@ window.__ModuleLoader__.load({
|
|
|
167
229
|
}
|
|
168
230
|
|
|
169
231
|
function Row(props) {
|
|
170
|
-
const { record, t, timeText, summary, isNew } = props
|
|
232
|
+
const { record, t, timeText, summary, isNew, focusId, onFocusHandled } = props
|
|
171
233
|
const [open, setOpen] = React.useState(false)
|
|
172
234
|
const drawerId = React.useId()
|
|
173
235
|
const headRef = React.useRef(null)
|
|
174
236
|
|
|
237
|
+
// "Load more" moves focus to the first newly shown row. The parent clears
|
|
238
|
+
// focusId right after, so this runs once and later renders leave focus be.
|
|
239
|
+
React.useEffect(() => {
|
|
240
|
+
if (focusId !== record.id) return
|
|
241
|
+
const head = headRef.current
|
|
242
|
+
if (head !== null) head.focus()
|
|
243
|
+
onFocusHandled()
|
|
244
|
+
}, [focusId, record.id, onFocusHandled])
|
|
245
|
+
|
|
175
246
|
// Escape collapses an open row, moves focus back to its button, and stops
|
|
176
247
|
// the event so the host page does not also act on it. A collapsed row
|
|
177
248
|
// leaves Escape alone.
|
|
@@ -216,7 +287,7 @@ window.__ModuleLoader__.load({
|
|
|
216
287
|
}
|
|
217
288
|
|
|
218
289
|
function Group(props) {
|
|
219
|
-
const { group, t, todayKey, freshIds } = props
|
|
290
|
+
const { group, t, todayKey, freshIds, focusId, onFocusHandled } = props
|
|
220
291
|
const newest = group.records[0]
|
|
221
292
|
const newestDay = dayKey(newest.time)
|
|
222
293
|
const dateText = newestDay === todayKey ? '' : formatDate(newest.time)
|
|
@@ -229,6 +300,8 @@ window.__ModuleLoader__.load({
|
|
|
229
300
|
timeText: rowTime(record, newestDay),
|
|
230
301
|
summary: summarize(record),
|
|
231
302
|
isNew: freshIds.has(record.id),
|
|
303
|
+
focusId,
|
|
304
|
+
onFocusHandled,
|
|
232
305
|
})),
|
|
233
306
|
)
|
|
234
307
|
}
|
|
@@ -258,6 +331,15 @@ window.__ModuleLoader__.load({
|
|
|
258
331
|
const hasBaseline = React.useRef(false)
|
|
259
332
|
const timers = React.useRef(new Set())
|
|
260
333
|
const [freshIds, setFreshIds] = React.useState(() => new Set())
|
|
334
|
+
// `pivotId` is the oldest record currently shown; it decides where the
|
|
335
|
+
// visible list ends. `pinned` remembers the first batch once, so records
|
|
336
|
+
// that arrive later only extend the newest end instead of pushing rows
|
|
337
|
+
// the user already read out of view.
|
|
338
|
+
const [pivotId, setPivotId] = React.useState(null)
|
|
339
|
+
const [focusId, setFocusId] = React.useState(null)
|
|
340
|
+
const pinned = React.useRef(null)
|
|
341
|
+
// Stable callback: Row effects depend on it and must not re-run each render.
|
|
342
|
+
const onFocusHandled = React.useCallback(() => { setFocusId(null) }, [])
|
|
261
343
|
|
|
262
344
|
// Mark records that appeared after the baseline; the first defined
|
|
263
345
|
// projection (an empty array included) only records the baseline. A
|
|
@@ -302,14 +384,54 @@ window.__ModuleLoader__.load({
|
|
|
302
384
|
timers.current.clear()
|
|
303
385
|
}, [])
|
|
304
386
|
|
|
387
|
+
const groups = groupByTurn(records)
|
|
388
|
+
const firstBatch = takeBatch(groups, 0, RECORDS_PER_PAGE)
|
|
389
|
+
|
|
390
|
+
// Pin the first batch the first time a non-empty projection arrives. Its
|
|
391
|
+
// boundary never moves afterwards, so a live update cannot hide records
|
|
392
|
+
// the user already saw.
|
|
393
|
+
React.useEffect(() => {
|
|
394
|
+
if (pinned.current !== null || records.length === 0) return
|
|
395
|
+
const currentGroups = groupByTurn(records)
|
|
396
|
+
const batch = takeBatch(currentGroups, 0, RECORDS_PER_PAGE)
|
|
397
|
+
const boundary = lastRecordId(batch)
|
|
398
|
+
if (boundary === null) return
|
|
399
|
+
pinned.current = { complete: batch.length === currentGroups.length }
|
|
400
|
+
setPivotId(boundary)
|
|
401
|
+
}, [records])
|
|
402
|
+
|
|
403
|
+
// A replaced projection can lose the pivot; fall back to the first batch
|
|
404
|
+
// instead of failing.
|
|
405
|
+
const shownGroups = groupsThroughPivot(groups, pivotId) ?? firstBatch
|
|
406
|
+
const shownRecords = sumRecords(shownGroups)
|
|
407
|
+
const allShown = shownGroups.length === groups.length
|
|
408
|
+
const initialComplete = pinned.current === null
|
|
409
|
+
? firstBatch.length === groups.length
|
|
410
|
+
: pinned.current.complete
|
|
411
|
+
|
|
412
|
+
// One click appends whole older groups until roughly another page of records.
|
|
413
|
+
const loadMore = () => {
|
|
414
|
+
const batch = takeBatch(groups, shownGroups.length, RECORDS_PER_PAGE)
|
|
415
|
+
const boundary = lastRecordId(batch)
|
|
416
|
+
if (boundary === null) return
|
|
417
|
+
setPivotId(boundary)
|
|
418
|
+
// The first row of a newest-first batch is that group's newest record.
|
|
419
|
+
setFocusId(batch[0].records[0].id)
|
|
420
|
+
}
|
|
421
|
+
|
|
305
422
|
const todayKey = dayKey(Date.now())
|
|
306
423
|
return h('div', { className: 'grb-root' },
|
|
307
424
|
h('div', { className: 'grb-scroll' },
|
|
308
425
|
records.length === 0
|
|
309
426
|
? h(EmptyState, { t })
|
|
310
427
|
: [
|
|
311
|
-
h('div', {
|
|
312
|
-
|
|
428
|
+
h('div', {
|
|
429
|
+
key: 'count',
|
|
430
|
+
className: 'grb-count',
|
|
431
|
+
role: 'status',
|
|
432
|
+
'aria-atomic': 'true',
|
|
433
|
+
}, allShown ? countText(t, records) : partialCountText(t, shownRecords, records)),
|
|
434
|
+
shownGroups.map(group => h(Group, {
|
|
313
435
|
// A group only ever gains records at its newest end, so the
|
|
314
436
|
// oldest record keeps the key stable across updates.
|
|
315
437
|
key: group.turn + ':' + group.records[group.records.length - 1].id,
|
|
@@ -317,7 +439,19 @@ window.__ModuleLoader__.load({
|
|
|
317
439
|
t,
|
|
318
440
|
todayKey,
|
|
319
441
|
freshIds,
|
|
442
|
+
focusId,
|
|
443
|
+
onFocusHandled,
|
|
320
444
|
})),
|
|
445
|
+
allShown ? null : h('div', { key: 'more', className: 'grb-more' },
|
|
446
|
+
h('button', {
|
|
447
|
+
type: 'button',
|
|
448
|
+
className: 'grb-more-button',
|
|
449
|
+
onClick: loadMore,
|
|
450
|
+
}, t('loadMore')),
|
|
451
|
+
),
|
|
452
|
+
allShown && !initialComplete
|
|
453
|
+
? h('div', { key: 'end', className: 'grb-end' }, t('endOfList'))
|
|
454
|
+
: null,
|
|
321
455
|
],
|
|
322
456
|
),
|
|
323
457
|
)
|
|
@@ -383,6 +517,10 @@ window.__ModuleLoader__.load({
|
|
|
383
517
|
'.grb-root{display:flex;flex-direction:column;height:100%;min-height:0;overflow:hidden;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}',
|
|
384
518
|
'.grb-scroll{--dsh-scrollbar-width:9px;--dsh-scrollbar-thumb-border:2px;flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding:12px 12px 28px}',
|
|
385
519
|
'.grb-count{padding:0 8px;margin-bottom:4px;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary)}',
|
|
520
|
+
'.grb-more{display:flex;justify-content:center;padding:8px 8px 4px}',
|
|
521
|
+
'.grb-more-button{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 10px;border:.5px solid transparent;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;line-height:18px;cursor:pointer;box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l3,var(--dsw-alias-border-l2)))}',
|
|
522
|
+
'@media (hover:hover){.grb-more-button:hover{background:var(--dsw-alias-interactive-bg-hover)}}',
|
|
523
|
+
'.grb-end{padding:8px;text-align:center;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary)}',
|
|
386
524
|
'.grb-group-head{position:sticky;top:0;z-index:1;display:flex;justify-content:space-between;align-items:baseline;padding:12px 8px 6px;background:var(--dsw-alias-bg-base);border-bottom:.5px solid var(--dsw-alias-border-l1)}',
|
|
387
525
|
'.grb-group-title{font-size:12px;line-height:20px;font-weight:500;color:var(--dsw-alias-label-secondary)}',
|
|
388
526
|
'.grb-group-date{font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary);font-variant-numeric:tabular-nums}',
|