@soffits/dsh-card-board 0.3.1 → 0.4.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/client.js CHANGED
@@ -22,49 +22,85 @@ window.__ModuleLoader__.load({
22
22
  const STORE_KEY = 'dsh-card-board:board'
23
23
  const api = path => new URL(`api/card-board/${path}`, document.baseURI).href
24
24
 
25
- const en = {
26
- panel: 'Boards',
27
- title: 'Boards',
28
- updated: 'Updated {time}',
29
- refreshFailed: 'Couldn’t refresh; trying again',
30
- loading: 'Loading…',
31
- emptyTitle: 'No boards yet.',
32
- emptyHint: 'A board shows up here once a script writes its board.json into the data folder.',
33
- noProvider: 'Boards need a sign-in plugin that says who is asking, and none is running.',
34
- noCards: 'This board has no cards yet.',
35
- cardError: 'This card can’t be shown',
36
- boardProblems: 'board.json has problems:',
37
- stale: 'stale · {age}',
38
- open: 'Open',
39
- listEmpty: 'Nothing here.',
40
- minutes: '{n} min',
41
- hours: '{n} h',
42
- days: '{n} d',
43
- 'time.locale': 'en-US',
44
- }
45
- const zh = {
46
- panel: '面板',
47
- title: '面板',
48
- updated: '{time} 更新',
49
- refreshFailed: '刷新失败,稍后重试',
50
- loading: '加载中…',
51
- emptyTitle: '还没有面板。',
52
- emptyHint: '脚本把 board.json 写进数据目录后,面板就会出现在这里。',
53
- noProvider: '面板需要一个能确认访问者身份的登录插件,但现在没有运行。',
54
- noCards: '这个面板还没有卡片。',
55
- cardError: '这张卡片无法显示',
56
- boardProblems: 'board.json 有问题:',
57
- stale: '已过时 · {age}',
58
- open: '打开',
59
- listEmpty: '暂无',
60
- minutes: '{n} 分钟',
61
- hours: '{n} 小时',
62
- days: '{n} 天',
63
- 'time.locale': 'zh-CN',
64
- }
65
-
66
- /** The client context, for the Web UI services the actions reach (set in apply). */
25
+ // ---- the page's own words -------------------------------------------------------
26
+ // One file per language in the package's locale folder (`ui` in locale/<tag>.json), served by the
27
+ // Host for the active language; the action buttons (client.actions.js) take theirs from the same
28
+ // files under `action.`. The code names no language. A test fails when a component renders a
29
+ // literal string instead of one of these.
30
+
31
+ const messageRequests = new Map()
32
+ /** The words for a DSH language id, fetched once per page load (a failed fetch is tried again next time). */
33
+ function fetchMessages(tag) {
34
+ if (!messageRequests.has(tag)) {
35
+ const request = fetch(api(`locale?tag=${encodeURIComponent(tag)}`), { credentials: 'same-origin' })
36
+ .then(response => (response.ok ? response.json() : Promise.reject(new Error(`HTTP ${response.status}`))))
37
+ .then(body => body.messages)
38
+ request.catch(() => messageRequests.delete(tag))
39
+ messageRequests.set(tag, request)
40
+ }
41
+ return messageRequests.get(tag)
42
+ }
43
+
44
+ /** What a card writes for a person to read: a string, or a map of language id → string (`en` always there). */
45
+ function pickText(value, active) {
46
+ if (typeof value !== 'object' || value === null) return value
47
+ const byId = new Map(Object.entries(value).map(([id, text]) => [id.toLowerCase(), text]))
48
+ const tag = String(active ?? 'en').toLowerCase()
49
+ const primary = tag.split('-')[0]
50
+ return byId.get(tag) ?? byId.get(primary) ?? [...byId].find(([id]) => id.split('-')[0] === primary)?.[1] ?? byId.get('en') ?? [...byId.values()][0] ?? ''
51
+ }
52
+
53
+ /** A card copy whose texts are resolved: walks the whole tree, so every component sees plain strings. */
54
+ function pickCard(card, active) {
55
+ const walk = value => {
56
+ if (Array.isArray(value)) return value.map(walk)
57
+ if (typeof value !== 'object' || value === null) return value
58
+ const keys = Object.keys(value)
59
+ if (keys.length > 0 && 'en' in value && keys.every(key => /^[a-z]{2,3}(-[a-z0-9]{2,8})*$/.test(key)) && keys.every(key => typeof value[key] === 'string')) return pickText(value, active)
60
+ return Object.fromEntries(keys.map(key => [key, key === 'payload' ? value[key] : walk(value[key])]))
61
+ }
62
+ return walk(card)
63
+ }
64
+
65
+ const fill = (text, params) => String(text).replace(/\{(\w+)\}/g, (match, key) => (key in params ? String(params[key]) : match))
66
+
67
+ /** The language id as an Intl locale, when this browser knows it. */
68
+ function intlTag(active) {
69
+ try {
70
+ return Intl.DateTimeFormat.supportedLocalesOf(active).length > 0 ? active : 'en'
71
+ } catch {
72
+ return 'en'
73
+ }
74
+ }
75
+
76
+ const translator = messages => (key, params) => {
77
+ const text = messages[key] ?? key
78
+ return params ? fill(text, params) : text
79
+ }
80
+
81
+ /** The client context: the locale service and the Web UI services the actions reach (set in apply). */
67
82
  let clientCtx = null
83
+
84
+ /**
85
+ * DSH's active language, live (the same value `useLocale(s => s.active)` gives a TSX plugin), with the
86
+ * page's words for it. `ready` turns true when they have arrived; a switch keeps the old words until the new ones do.
87
+ */
88
+ function useActiveLocale() {
89
+ const subscribe = useCallback(listener => clientCtx.locale.subscribe(listener), [])
90
+ const active = React.useSyncExternalStore(subscribe, () => clientCtx.locale.getSnapshot().active)
91
+ const [loaded, setLoaded] = useState(null)
92
+ const [attempt, setAttempt] = useState(0)
93
+ useEffect(() => {
94
+ let live = true
95
+ let timer
96
+ fetchMessages(active).then(
97
+ messages => { if (live) setLoaded({ active, messages }) },
98
+ () => { if (live) timer = setTimeout(() => setAttempt(count => count + 1), 3000) })
99
+ return () => { live = false; clearTimeout(timer) }
100
+ }, [active, attempt])
101
+ return useMemo(() => ({ active: loaded?.active ?? active, ready: loaded !== null, intl: intlTag(loaded?.active ?? active), t: translator(loaded?.messages ?? {}) }), [loaded, active])
102
+ }
103
+
68
104
  /** The shared action buttons (client.actions.js), loaded with the page. */
69
105
  let actionsModule
70
106
  const loadActions = () => {
@@ -75,8 +111,6 @@ window.__ModuleLoader__.load({
75
111
  return actionsModule
76
112
  }
77
113
 
78
- const fill = (text, params) => String(text).replace(/\{(\w+)\}/g, (match, key) => (key in params ? String(params[key]) : match))
79
-
80
114
  // ---- numbers, dates, tones -------------------------------------------------
81
115
 
82
116
  const TONES = { ok: 'var(--cb-ok)', warn: 'var(--cb-warn)', bad: 'var(--cb-bad)', muted: 'var(--cb-muted)', accent: 'var(--cb-accent)' }
@@ -90,11 +124,10 @@ window.__ModuleLoader__.load({
90
124
  return new Intl.NumberFormat(locale, { maximumFractionDigits: max }).format(value)
91
125
  }
92
126
 
93
- /** Short axis numbers: 18,240 → 18.2k. */
127
+ /** Short axis numbers in the language's own way: 18,240 → 18.2K, 1.8万. */
94
128
  function formatAxis(value, locale) {
95
129
  const abs = Math.abs(value)
96
- if (abs >= 1e6) return `${formatNumber(value / 1e6, locale, 1)}M`
97
- if (abs >= 1e4) return `${formatNumber(value / 1e3, locale, abs >= 1e5 ? 0 : 1)}k`
130
+ if (abs >= 1e4) return new Intl.NumberFormat(locale, { notation: 'compact', maximumFractionDigits: abs >= 1e5 ? 0 : 1 }).format(value)
98
131
  return formatNumber(value, locale, abs >= 100 ? 0 : 1)
99
132
  }
100
133
 
@@ -109,27 +142,36 @@ window.__ModuleLoader__.load({
109
142
 
110
143
  function formatDay(time, locale, spanDays) {
111
144
  const date = new Date(time)
112
- if (spanDays > 120) return date.toLocaleDateString(locale, { month: 'short' })
113
- return date.toLocaleDateString(locale, { month: 'numeric', day: 'numeric' })
145
+ if (spanDays > 120) return new Intl.DateTimeFormat(locale, { month: 'short' }).format(date)
146
+ return new Intl.DateTimeFormat(locale, { month: 'numeric', day: 'numeric' }).format(date)
114
147
  }
115
148
 
116
- function formatAge(seconds, t) {
117
- if (seconds < 3600) return fill(t('minutes'), { n: Math.max(1, Math.round(seconds / 60)) })
118
- if (seconds < 86400 * 2) return fill(t('hours'), { n: Math.round(seconds / 3600) })
119
- return fill(t('days'), { n: Math.round(seconds / 86400) })
149
+ /** How long ago, in the language's own units: 3 min, 5 h, 2 d. */
150
+ function formatAge(seconds, locale) {
151
+ const [unit, amount] = seconds < 3600 ? ['minute', Math.max(1, Math.round(seconds / 60))] : seconds < 86400 * 2 ? ['hour', Math.round(seconds / 3600)] : ['day', Math.round(seconds / 86400)]
152
+ return new Intl.NumberFormat(locale, { style: 'unit', unit, unitDisplay: 'short' }).format(amount)
120
153
  }
121
154
 
122
155
  function formatUpdated(time, locale) {
123
156
  const date = new Date(time)
124
157
  const today = new Date()
125
158
  const sameDay = date.toDateString() === today.toDateString()
126
- return sameDay
127
- ? date.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })
128
- : date.toLocaleString(locale, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })
159
+ return new Intl.DateTimeFormat(locale, sameDay ? { hour: '2-digit', minute: '2-digit' } : { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }).format(date)
129
160
  }
130
161
 
131
- /** About this many pixels per character of 11px label text. */
132
- const textWidth = text => String(text).length * 6.4
162
+ /** About this many pixels for 11px label text: CJK characters are about twice as wide. */
163
+ const textWidth = text => [...String(text)].reduce((sum, char) => sum + (char.charCodeAt(0) > 0x2e7f ? 11.5 : 6.4), 0)
164
+
165
+ /** `text` cut with an ellipsis to fit about `px` pixels of label text. */
166
+ function fit(text, px) {
167
+ if (textWidth(text) <= px) return String(text)
168
+ let out = ''
169
+ for (const char of String(text)) {
170
+ if (textWidth(`${out}${char}…`) > px) break
171
+ out += char
172
+ }
173
+ return `${out}…`
174
+ }
133
175
 
134
176
  /** Round tick values covering [min, max], about `count` of them. */
135
177
  function niceTicks(min, max, count) {
@@ -149,45 +191,54 @@ window.__ModuleLoader__.load({
149
191
  return Array.from({ length: count }, (_, i) => Math.round(i * step))
150
192
  }
151
193
 
194
+ /** A callback ref and the width of the element it is on, kept up to date as the element resizes (or appears later). */
152
195
  function useWidth() {
153
- const ref = useRef(null)
196
+ const [element, setElement] = useState(null)
154
197
  const [width, setWidth] = useState(0)
155
198
  useLayoutEffect(() => {
156
- const element = ref.current
157
199
  if (!element) return undefined
158
- setWidth(Math.floor(element.clientWidth))
159
200
  const observer = new ResizeObserver(([entry]) => setWidth(Math.floor(entry.contentRect.width)))
160
201
  observer.observe(element)
161
202
  return () => observer.disconnect()
162
- }, [])
163
- return [ref, width]
203
+ }, [element])
204
+ return [setElement, width]
164
205
  }
165
206
 
166
207
  // ---- pieces shared by cards ------------------------------------------------
167
208
 
209
+ /** Text that shortens to fit; hover shows all of it, and a tap opens it up (or closes it again). */
210
+ function Trunc({ text, as = 'div', className = '', lines = 1 }) {
211
+ const [open, setOpen] = useState(false)
212
+ return h(as, {
213
+ className: `cb-trunc${lines > 1 ? ' cb-trunc2' : ''}${open ? ' cb-truncOpen' : ''} ${className}`.trim(),
214
+ title: text,
215
+ onClick: () => setOpen(value => !value),
216
+ }, text)
217
+ }
218
+
168
219
  function Chip({ text, tone }) {
169
- return h('span', { className: 'cb-chip', 'data-tone': tone ?? 'muted' }, text)
220
+ return h('span', { className: 'cb-chip', 'data-tone': tone ?? 'muted', title: text }, text)
170
221
  }
171
222
 
172
223
  function Legend({ items, locale }) {
173
224
  return h('ul', { className: 'cb-legend' }, items.map((item, i) =>
174
225
  h('li', { key: i },
175
226
  h('i', { style: { background: item.color } }),
176
- h('span', null, item.label),
227
+ h(Trunc, { as: 'span', text: item.label }),
177
228
  item.value !== undefined && h('b', null, formatNumber(item.value, locale)))))
178
229
  }
179
230
 
180
231
  function StatBlock({ data, locale, compact }) {
181
232
  return h('div', { className: `cb-stats${compact ? ' cb-statsCompact' : ''}` }, data.items.map((item, i) =>
182
233
  h('div', { key: i, className: 'cb-stat' },
183
- !compact && h('div', { className: 'cb-statLabel' }, item.label),
234
+ !compact && h(Trunc, { className: 'cb-statLabel', text: item.label }),
184
235
  h('div', { className: 'cb-statValue', style: item.tone ? { color: toneColor(item.tone) } : undefined },
185
236
  h('span', null, formatNumber(item.value, locale)),
186
237
  item.unit && h('small', null, item.unit),
187
238
  item.delta && h('em', { className: 'cb-delta', style: { color: toneColor(item.delta.tone ?? 'muted') } },
188
239
  `${item.delta.value > 0 ? '▲' : item.delta.value < 0 ? '▼' : '•'} ${formatNumber(Math.abs(item.delta.value), locale)}${item.delta.unit ? ` ${item.delta.unit}` : ''}`)),
189
240
  (compact ? [item.label, item.sub].filter(Boolean).join(' · ') : item.sub) &&
190
- h('div', { className: 'cb-statSub' }, compact ? [item.label, item.sub].filter(Boolean).join(' · ') : item.sub))))
241
+ h(Trunc, { className: 'cb-statSub', lines: 2, text: compact ? [item.label, item.sub].filter(Boolean).join(' · ') : item.sub }))))
191
242
  }
192
243
 
193
244
  // ---- line ----------------------------------------------------------------
@@ -227,15 +278,31 @@ window.__ModuleLoader__.load({
227
278
  const xLabel = x => (model.timeAxis ? formatDay(toTime(x), locale, spanDays) : typeof x === 'number' ? formatNumber(x, locale) : String(x))
228
279
 
229
280
  const longest = data.series.reduce((best, s) => (s.points.length > best.points.length ? s : best), data.series[0])
230
- const labelCount = Math.max(2, Math.floor(plotW / 44))
281
+ const labelWidth = Math.max(36, ...longest.points.slice(0, 40).map(p => textWidth(xLabel(p.x)) + 12))
282
+ const labelCount = Math.max(2, Math.floor(plotW / labelWidth))
231
283
  // Evenly spaced labels, minus any that would print the same text or sit on top of the one before.
232
284
  const xTicks = []
233
285
  for (const x of spread(longest.points.length, labelCount).map(i => longest.points[i].x)) {
234
286
  const last = xTicks[xTicks.length - 1]
235
- if (last !== undefined && (xLabel(last) === xLabel(x) || sx(x) - sx(last) < 36)) continue
287
+ if (last !== undefined && (xLabel(last) === xLabel(x) || sx(x) - sx(last) < labelWidth)) continue
236
288
  xTicks.push(x)
237
289
  }
238
290
 
291
+ // Marker labels sit just above the x axis, right of their line (left of it near the right edge), in up to two rows;
292
+ // one that finds no free spot shows only its line, and its text on hover.
293
+ const labelRows = [[], []]
294
+ const markerLabels = [...(data.markers ?? [])].sort((a, b) => model.xValue(a.x) - model.xValue(b.x)).map(marker => {
295
+ const x = sx(marker.x)
296
+ const room = left + plotW - x - 6
297
+ const flip = room < Math.min(textWidth(marker.label), 90) && x - left > room
298
+ const space = Math.max(20, Math.min(120, flip ? x - left - 6 : room))
299
+ const width = Math.min(textWidth(marker.label), space)
300
+ const span = flip ? [x - 4 - width, x - 4] : [x + 4, x + 4 + width]
301
+ const row = labelRows.findIndex(taken => taken.every(([from, to]) => span[0] > to + 4 || span[1] < from - 4))
302
+ if (row >= 0) labelRows[row].push(span)
303
+ return { marker, x, flip, space, label: row >= 0 ? row : null }
304
+ })
305
+
239
306
  const path = points => {
240
307
  let d = ''
241
308
  let pen = false
@@ -256,16 +323,17 @@ window.__ModuleLoader__.load({
256
323
  h('line', { x1: left, x2: left + plotW, y1: sy(v), y2: sy(v), className: 'cb-rule' }),
257
324
  h('text', { x: left - 8, y: sy(v), className: 'cb-axis', textAnchor: 'end', dominantBaseline: 'middle' }, formatAxis(v, locale)))),
258
325
  xTicks.map((x, i) => h('text', { key: i, x: sx(x), y: height - 4, className: 'cb-axis', textAnchor: i === 0 && xTicks.length > 1 ? 'start' : i === xTicks.length - 1 && xTicks.length > 1 ? 'end' : 'middle' }, xLabel(x))),
259
- (data.markers ?? []).map((m, i) => h('g', { key: `m${i}` },
260
- h('line', { x1: sx(m.x), x2: sx(m.x), y1: top, y2: top + plotH, className: 'cb-marker' }),
261
- h('text', { x: sx(m.x) + 4, y: top + 8, className: 'cb-markerLabel' }, m.label))),
326
+ markerLabels.map(({ marker, x, label, flip, space }, i) => h('g', { key: `m${i}` },
327
+ h('line', { x1: x, x2: x, y1: top, y2: top + plotH, className: 'cb-marker' }),
328
+ h('title', null, marker.label),
329
+ label !== null && h('text', { x: flip ? x - 4 : x + 4, y: top + plotH - 5 - label * 13, className: 'cb-markerLabel', textAnchor: flip ? 'end' : 'start' }, fit(marker.label, space)))),
262
330
  data.goal && (data.goal.points
263
331
  ? h('path', { d: path(data.goal.points), className: 'cb-goal' })
264
332
  : h('line', { x1: left, x2: left + plotW, y1: sy(data.goal.y), y2: sy(data.goal.y), className: 'cb-goal' })),
265
333
  data.goal?.label && (() => {
266
334
  const end = data.goal.points ? data.goal.points[data.goal.points.length - 1] : { x: null, y: data.goal.y }
267
335
  const x = end.x === null ? left + plotW : sx(end.x)
268
- return h('text', { x: Math.min(x, left + plotW), y: sy(end.y) - 5, className: 'cb-goalLabel', textAnchor: 'end' }, data.goal.label)
336
+ return h('text', { x: Math.min(x, left + plotW), y: sy(end.y) - 5, className: 'cb-goalLabel', textAnchor: 'end' }, h('title', null, data.goal.label), fit(data.goal.label, plotW))
269
337
  })(),
270
338
  data.series.map((s, i) => {
271
339
  const color = toneColor(s.tone, i)
@@ -314,7 +382,7 @@ window.__ModuleLoader__.load({
314
382
  h('div', { ref, className: 'cb-chart', style: { height } }, width > 0 && h('svg', { width, height, role: 'img' },
315
383
  h('line', { x1: 0, x2: width, y1: top + plotH + 0.5, y2: top + plotH + 0.5, className: 'cb-rule' }),
316
384
  data.goal && h('line', { x1: 0, x2: width, y1: sy(data.goal.y), y2: sy(data.goal.y), className: 'cb-goal' }),
317
- data.goal?.label && h('text', { x: width, y: sy(data.goal.y) - 4, className: 'cb-goalLabel', textAnchor: 'end' }, data.goal.label),
385
+ data.goal?.label && h('text', { x: width, y: sy(data.goal.y) - 4, className: 'cb-goalLabel', textAnchor: 'end' }, h('title', null, data.goal.label), fit(data.goal.label, width)),
318
386
  data.bars.map((bar, i) => {
319
387
  const cx = slot * i + slot / 2
320
388
  const tip = multi
@@ -341,7 +409,7 @@ window.__ModuleLoader__.load({
341
409
  rx: Math.min(4, p.w / 3), fill: p.color, fillOpacity: multi ? 0.85 : 0.55,
342
410
  })),
343
411
  showValues && h('text', { x: cx, y: sy(peaks[i]) - 4, className: 'cb-barValue', textAnchor: 'middle' }, formatNumber(multi && !stacked ? peaks[i] : totals[i], locale, 1)),
344
- i % labelEvery === 0 && h('text', { x: cx, y: height - 4, className: 'cb-axis', textAnchor: 'middle' }, label(bar.x)))
412
+ i % labelEvery === 0 && h('text', { x: Math.min(Math.max(cx, textWidth(label(bar.x)) / 2), width - textWidth(label(bar.x)) / 2), y: height - 4, className: 'cb-axis', textAnchor: 'middle' }, label(bar.x)))
345
413
  }))),
346
414
  multi && h(Legend, { items: keys.map((key, k) => ({ label: key, color: toneColor(undefined, k) })), locale }))
347
415
  }
@@ -383,7 +451,7 @@ window.__ModuleLoader__.load({
383
451
  data.centre.sub && h('span', null, data.centre.sub))),
384
452
  h('table', { className: 'cb-donutTable' }, h('tbody', null, segments.map((s, i) => h('tr', { key: i },
385
453
  h('td', null, h('i', { style: { background: s.color } })),
386
- h('td', { className: 'cb-donutLabel' }, s.label),
454
+ h('td', { className: 'cb-donutLabel' }, h(Trunc, { text: s.label })),
387
455
  h('td', { className: 'cb-num' }, formatNumber(s.value, locale)),
388
456
  h('td', { className: 'cb-num cb-dim' }, total > 0 ? `${Math.round((s.value / total) * 100)}%` : '–'))))))
389
457
  }
@@ -418,13 +486,13 @@ window.__ModuleLoader__.load({
418
486
  ? h('p', { className: 'cb-muted' }, data.empty ?? t('listEmpty'))
419
487
  : h('ul', { className: 'cb-list' }, data.rows.map((row, i) =>
420
488
  h('li', { key: i, className: row.checked ? 'cb-done' : undefined },
421
- checkable && h('span', { className: 'cb-checkBox', role: 'img', 'aria-label': row.checked ? '✓' : '○' }, h(CheckGlyph, { checked: row.checked === true })),
489
+ checkable && h('span', { className: 'cb-checkBox', role: 'img', 'aria-label': t(row.checked ? 'checked' : 'unchecked') }, h(CheckGlyph, { checked: row.checked === true })),
422
490
  h('div', { className: 'cb-listText' },
423
- h('div', { className: 'cb-listTitle' }, row.title),
424
- row.sub && h('div', { className: 'cb-listSub' }, row.sub)),
491
+ h(Trunc, { className: 'cb-listTitle', lines: 2, text: row.title }),
492
+ row.sub && h(Trunc, { className: 'cb-listSub', lines: 2, text: row.sub })),
425
493
  row.date && h('span', { className: 'cb-listDate' }, formatDay(toTime(row.date), locale, 0)),
426
494
  row.chip && h(Chip, row.chip),
427
- rowActions && row.actions && rowActions(i, row.actions, listRowLine(row)))))
495
+ row.actions && rowActions && h('span', { className: 'cb-rowActions' }, rowActions(i, row.actions, listRowLine(row))))))
428
496
  if (!data.progress) return rows
429
497
  // Beside the rows when there is room for both, else a small ring with its count above them.
430
498
  const wide = width >= 460
@@ -488,7 +556,7 @@ window.__ModuleLoader__.load({
488
556
  now >= from && now <= to && h('line', { x1: sx(now), x2: sx(now), y1: tickH - 2, y2: height, className: 'cb-today' }),
489
557
  placed.map((p, i) => {
490
558
  const color = toneColor(p.tone ?? KIND_TONE[p.kind] ?? 'accent')
491
- const text = p.label.length > 16 ? `${p.label.slice(0, 15)}…` : p.label
559
+ const text = fit(p.label, 90)
492
560
  return h('g', { key: i },
493
561
  h('title', null, `${formatDay(p.time, locale, 0)} · ${p.label}`),
494
562
  p.kind === 'travel' ? h(PlaneGlyph, { x: p.x, y: pointY, color }) : h('circle', { cx: p.x, cy: pointY, r: 5, fill: color }),
@@ -499,11 +567,11 @@ window.__ModuleLoader__.load({
499
567
  const x = sx(s.a)
500
568
  const w = Math.max(6, sx(s.b) - x)
501
569
  const y = spansTop + i * 36
570
+ const full = `${s.label} · ${formatDay(toTime(s.from), locale, 0)} – ${formatDay(toTime(s.to), locale, 0)}`
502
571
  return h('g', { key: `s${i}` },
503
- h('title', null, `${s.label}: ${s.from} – ${s.to}`),
572
+ h('title', null, full),
504
573
  h('rect', { x, y, width: w, height: 12, rx: 6, fill: toneColor(s.tone ?? 'accent'), fillOpacity: 0.22 }),
505
- h('text', { x: Math.min(Math.max(x + w / 2, pad + 30), width - pad - 30), y: y + 26, className: 'cb-spanLabel', textAnchor: 'middle' },
506
- `${s.label} · ${formatDay(toTime(s.from), locale, 0)} – ${formatDay(toTime(s.to), locale, 0)}`))
574
+ h('text', { x: Math.min(Math.max(x + w / 2, pad + Math.min(plotW, textWidth(full) * 0.55) / 2), width - pad - Math.min(plotW, textWidth(full) * 0.55) / 2), y: y + 26, className: 'cb-spanLabel', textAnchor: 'middle' }, fit(full, plotW)))
507
575
  })))
508
576
  }
509
577
 
@@ -525,11 +593,11 @@ window.__ModuleLoader__.load({
525
593
  return h('ul', { className: `cb-status${sparks ? ' cb-statusSparks' : ''}${hasActions ? ' cb-statusActions' : ''}` }, data.rows.map((row, i) =>
526
594
  h('li', { key: i },
527
595
  h('i', { className: 'cb-dot', style: { background: toneColor(row.tone) } }),
528
- h('span', { className: 'cb-statusLabel' }, row.label),
596
+ h(Trunc, { as: 'span', className: 'cb-statusLabel', text: row.label }),
529
597
  h('span', { className: 'cb-statusValue' },
530
- h('span', { style: row.tone === 'bad' || row.tone === 'warn' ? { color: toneColor(row.tone) } : undefined }, formatNumber(row.value, locale)),
531
- row.sub && h('small', null, row.sub)),
532
- sparks && (row.spark ? h(Spark, { values: row.spark, color: toneColor(row.tone === 'ok' ? 'accent' : row.tone) }) : h('span', null)),
598
+ h('span', { className: 'cb-statusNum', style: row.tone === 'bad' || row.tone === 'warn' ? { color: toneColor(row.tone) } : undefined }, formatNumber(row.value, locale)),
599
+ row.sub && h(Trunc, { as: 'small', className: 'cb-statusSub', lines: 2, text: row.sub })),
600
+ sparks && (row.spark ? h(Spark, { values: row.spark, color: toneColor(row.tone === 'ok' ? 'accent' : row.tone) }) : h('span', { className: 'cb-spark' })),
533
601
  hasActions && h('span', { className: 'cb-rowActions' }, rowActions && row.actions ? rowActions(i, row.actions, statusRowLine(row, locale)) : null))))
534
602
  }
535
603
 
@@ -553,7 +621,7 @@ window.__ModuleLoader__.load({
553
621
  }
554
622
 
555
623
  /** A few plain lines saying what a card shows, for the agent. */
556
- function summaryLines(card, locale) {
624
+ function summaryLines(card, locale, t) {
557
625
  const data = card.data
558
626
  const lines = card.stat ? statLines(card.stat, locale) : []
559
627
  switch (card.type) {
@@ -561,9 +629,9 @@ window.__ModuleLoader__.load({
561
629
  case 'line':
562
630
  for (const series of data.series) {
563
631
  const last = [...series.points].reverse().find(p => typeof p.y === 'number')
564
- if (last) lines.push(`${series.name || 'latest'}: ${withUnit(last.y, data.unit, locale)} at ${last.x} (${series.points.length} points from ${series.points[0].x})`)
632
+ if (last) lines.push(t('summary.latest', { name: series.name || t('summary.latestName'), value: withUnit(last.y, data.unit, locale), x: last.x, n: series.points.length, from: series.points[0].x }))
565
633
  }
566
- if (data.goal?.y !== undefined) lines.push(`goal: ${withUnit(data.goal.y, data.unit, locale)}`)
634
+ if (data.goal?.y !== undefined) lines.push(t('summary.goal', { value: withUnit(data.goal.y, data.unit, locale) }))
567
635
  return lines
568
636
  case 'bar':
569
637
  return lines.concat(data.bars.slice(-10).map(bar => `${bar.x}: ${bar.values ? Object.entries(bar.values).map(([k, v]) => `${k} ${formatNumber(v, locale)}`).join(', ') : withUnit(bar.value, data.unit, locale)}`))
@@ -572,7 +640,7 @@ window.__ModuleLoader__.load({
572
640
  return lines.concat(data.segments.map(s => `${s.label}: ${withUnit(s.value, data.unit, locale)}${total > 0 ? ` (${Math.round((s.value / total) * 100)}%)` : ''}`))
573
641
  }
574
642
  case 'list':
575
- return lines.concat(data.progress ? [`progress: ${data.progress.done}/${data.progress.total}`] : [], data.rows.slice(0, 15).map(listRowLine))
643
+ return lines.concat(data.progress ? [t('summary.progress', data.progress)] : [], data.rows.slice(0, 15).map(listRowLine))
576
644
  case 'timeline':
577
645
  return lines.concat((data.points ?? []).map(p => `${p.date}: ${p.label}`), (data.spans ?? []).map(s => `${s.from} – ${s.to}: ${s.label}`))
578
646
  case 'status':
@@ -591,9 +659,11 @@ window.__ModuleLoader__.load({
591
659
  // ---- card frame ----------------------------------------------------------
592
660
 
593
661
  const CHART_HEIGHT = { 1: 150, 2: 360, 3: 560 }
662
+ /** One column (a phone): taller cards would only scroll further, so charts stay moderate. */
663
+ const CHART_HEIGHT_NARROW = { 1: 150, 2: 220, 3: 260 }
594
664
 
595
- function CardBody({ card, size, locale, t, rowActions }) {
596
- const height = CHART_HEIGHT[size.h] - (card.stat ? 40 : 0)
665
+ function CardBody({ card, size, narrow, locale, t, rowActions }) {
666
+ const height = (narrow ? CHART_HEIGHT_NARROW : CHART_HEIGHT)[size.h] - (card.stat ? 40 : 0)
597
667
  const data = card.data
598
668
  switch (card.type) {
599
669
  case 'stat': return h(StatBlock, { data, locale })
@@ -612,16 +682,16 @@ window.__ModuleLoader__.load({
612
682
  h('path', { d: 'M6 3.5H3.5v9h9V10M9 3h4v4M13 3 7.5 8.5' }))
613
683
  }
614
684
 
615
- function Card({ entry, boardId, columns, now, locale, t, actions }) {
685
+ function Card({ entry, boardId, assistant, columns, now, active, locale, t, actions }) {
616
686
  const size = { w: Math.min(entry.w ?? 1, columns), h: entry.h ?? 1 }
617
- const style = { gridColumn: `span ${size.w}`, gridRow: size.h > 1 ? `span ${size.h}` : undefined }
687
+ const style = { gridColumn: `span ${size.w}`, gridRow: size.h > 1 && columns > 1 ? `span ${size.h}` : undefined }
618
688
  if (!entry.card) {
619
689
  return h('section', { className: 'cb-card cb-cardError', style },
620
- h('header', { className: 'cb-cardHead' }, h('h3', null, entry.id)),
690
+ h('header', { className: 'cb-cardHead' }, h('h3', { title: entry.id }, entry.id)),
621
691
  h('p', { className: 'cb-errorText' }, t('cardError')),
622
692
  h('ul', { className: 'cb-problems' }, (entry.problems ?? []).map((p, i) => h('li', { key: i }, p))))
623
693
  }
624
- const card = entry.card
694
+ const card = pickCard(entry.card, active)
625
695
  const updated = Date.parse(card.updatedAt)
626
696
  const age = Math.max(0, (now - updated) / 1000)
627
697
  const stale = typeof card.staleAfter === 'number' && age > card.staleAfter
@@ -632,14 +702,16 @@ window.__ModuleLoader__.load({
632
702
  text: actions.chatText({
633
703
  prompt: action.payload?.prompt ?? '',
634
704
  title: card.title,
635
- lines: row === undefined ? summaryLines(card, locale) : [rowLine],
705
+ lines: row === undefined ? summaryLines(card, locale, t) : [rowLine],
636
706
  context: action.payload?.context ?? context(row),
637
707
  }),
638
708
  session: action.payload?.session,
639
709
  })
640
- const defaultChat = { kind: 'chat', id: '_chat', label: t('chatAbout') }
710
+ // A chat button without its own label says "Ask <assistant>" when the board names one.
711
+ const named = list => (assistant ? list?.map(action => (action.kind === 'chat' && action.label === undefined ? { ...action, label: t('action.chatNamed', { name: assistant }) } : action)) : list)
712
+ const defaultChat = { kind: 'chat', id: '_chat', label: assistant ? t('action.chatNamed', { name: assistant }) : t('action.chatAbout') }
641
713
  const rowActions = actions && ((row, list, line) => h(actions.ActionBar, {
642
- actions: list,
714
+ actions: named(list),
643
715
  states: statesOf(entry.presses, row),
644
716
  compact: true,
645
717
  chat: action => chat(action, row, line),
@@ -647,14 +719,14 @@ window.__ModuleLoader__.load({
647
719
  }))
648
720
  return h('section', { className: `cb-card${stale ? ' cb-cardStale' : ''}`, style, 'data-type': card.type },
649
721
  h('header', { className: 'cb-cardHead' },
650
- h('h3', null, card.title),
651
- stale && h('span', { className: 'cb-staleChip', title: new Date(updated).toLocaleString(locale) }, fill(t('stale'), { age: formatAge(age, t) })),
722
+ h(Trunc, { as: 'h3', text: card.title }),
723
+ stale && h('span', { className: 'cb-staleChip', title: new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' }).format(updated) }, t('stale', { age: formatAge(age, locale) })),
652
724
  card.link && h('a', { className: 'cb-cardLink', href: card.link, title: t('open'), 'aria-label': t('open'), ...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {}) }, h(LinkIcon)),
653
725
  actions && h('span', { className: 'cb-cardChat' }, h(actions.ActionButton, { action: defaultChat, compact: true, chat: action => chat(action) }))),
654
726
  card.stat && h(StatBlock, { data: card.stat, locale, compact: true }),
655
- h('div', { className: 'cb-cardBody' }, h(CardBody, { card, size, locale, t, rowActions })),
727
+ h('div', { className: 'cb-cardBody' }, h(CardBody, { card, size, narrow: columns === 1, locale, t, rowActions })),
656
728
  actions && card.actions && h('footer', { className: 'cb-cardActions' }, h(actions.ActionBar, {
657
- actions: card.actions,
729
+ actions: named(card.actions),
658
730
  states: statesOf(entry.presses, undefined),
659
731
  chat: action => chat(action),
660
732
  onPress: (action, extra) => actions.press(action, extra, { card: entry.id }),
@@ -663,26 +735,32 @@ window.__ModuleLoader__.load({
663
735
 
664
736
  // ---- page ----------------------------------------------------------------
665
737
 
738
+ /** A failed request: its status says what went wrong; the server's own words stay out of the page. */
739
+ function requestError(status, body) {
740
+ const error = new Error(body?.error ?? `HTTP ${status}`)
741
+ error.status = status
742
+ return error
743
+ }
744
+
666
745
  async function getJson(path, etag) {
667
746
  const response = await fetch(api(path), { cache: 'no-store', credentials: 'same-origin', headers: etag ? { 'if-none-match': etag } : {} })
668
747
  if (response.status === 304) return { notModified: true }
669
748
  let body = null
670
749
  try { body = await response.json() } catch { /* not JSON */ }
671
- if (!response.ok) {
672
- const error = new Error(body?.error ?? `HTTP ${response.status}`)
673
- error.status = response.status
674
- throw error
675
- }
750
+ if (!response.ok) throw requestError(response.status, body)
676
751
  return { body, etag: response.headers.get('etag') }
677
752
  }
678
753
 
754
+ const ERROR_KEYS = { 403: 'error.forbidden', 404: 'error.notFound', 409: 'error.gone', 503: 'error.noProvider' }
755
+ const errorText = (error, t) => (error.status === undefined ? error.message : t(ERROR_KEYS[error.status] ?? 'error.http', { status: error.status }))
756
+
679
757
  function useColumns() {
680
758
  const [ref, width] = useWidth()
681
- return [ref, width >= 980 ? 3 : width >= 620 ? 2 : 1]
759
+ return [ref, width >= 1400 ? 4 : width >= 980 ? 3 : width >= 620 ? 2 : 1]
682
760
  }
683
761
 
684
- function BoardsPage({ translate: t }) {
685
- const locale = t('time.locale')
762
+ function BoardsPage() {
763
+ const { active, intl: locale, ready, t } = useActiveLocale()
686
764
  const [boards, setBoards] = useState(null)
687
765
  const [listError, setListError] = useState(null)
688
766
  const [selected, setSelected] = useState(() => { try { return localStorage.getItem(STORE_KEY) } catch { return null } })
@@ -695,6 +773,9 @@ window.__ModuleLoader__.load({
695
773
  const [gridRef, columns] = useColumns()
696
774
  const [actions, setActions] = useState(null)
697
775
  const currentRef = useRef(null)
776
+ // The buttons ask for words at render time, so a language switch reaches them without rebuilding them.
777
+ const translateRef = useRef(t)
778
+ translateRef.current = t
698
779
 
699
780
  const loadList = useCallback(async () => {
700
781
  try {
@@ -703,9 +784,9 @@ window.__ModuleLoader__.load({
703
784
  setPollSeconds(body.pollSeconds ?? 30)
704
785
  setListError(null)
705
786
  } catch (error) {
706
- setListError(error.status === 503 ? t('noProvider') : error.message)
787
+ setListError(error)
707
788
  }
708
- }, [t])
789
+ }, [])
709
790
 
710
791
  const current = boards?.some(b => b.id === selected) ? selected : boards?.[0]?.id ?? null
711
792
 
@@ -719,7 +800,7 @@ window.__ModuleLoader__.load({
719
800
  etag.current = result.etag
720
801
  setBoard(result.body)
721
802
  } catch (error) {
722
- if (error.status === 403 || error.status === 404) { setBoard(null); setBoardError(error.message); loadList(); return }
803
+ if (error.status === 403 || error.status === 404) { setBoard(null); setBoardError(error); loadList(); return }
723
804
  setRefreshFailed(true)
724
805
  }
725
806
  }, [loadList])
@@ -739,15 +820,15 @@ window.__ModuleLoader__.load({
739
820
  body: JSON.stringify({ board: currentRef.current, ...target, id: action.id, ...extra }),
740
821
  })
741
822
  const body = await response.json().catch(() => null)
742
- if (!response.ok) throw new Error(body?.error ?? `HTTP ${response.status}`)
823
+ if (!response.ok) throw new Error(errorText(requestError(response.status, body), translateRef.current))
743
824
  loadBoard(currentRef.current, false)
744
825
  return body
745
826
  }
746
- const ui = createActions({ React, ctx: clientCtx, locale })
827
+ const ui = createActions({ React, ctx: clientCtx, t: (key, params) => translateRef.current(`action.${key}`, params) })
747
828
  setActions({ ...ui, press })
748
829
  }, error => console.warn('card-board: action buttons not loaded:', error))
749
830
  return () => { live = false }
750
- }, [loadBoard, locale])
831
+ }, [loadBoard])
751
832
 
752
833
  useEffect(() => {
753
834
  currentRef.current = current
@@ -778,27 +859,30 @@ window.__ModuleLoader__.load({
778
859
  return Number.isFinite(time) && time > max ? time : max
779
860
  }, 0)
780
861
 
862
+ const titleOf = entry => pickText(entry.title, active)
781
863
  const tabs = boards && boards.length > 1 && h('div', { className: 'cb-tabs', role: 'tablist' }, boards.map(b =>
782
- h('button', { key: b.id, type: 'button', role: 'tab', 'aria-selected': b.id === current, className: 'cb-tab', onClick: () => choose(b.id) }, b.title)))
864
+ h('button', { key: b.id, type: 'button', role: 'tab', 'aria-selected': b.id === current, className: 'cb-tab', title: titleOf(b), onClick: () => choose(b.id) }, h('span', null, titleOf(b)))))
865
+
866
+ if (!ready) return h('div', { className: 'cb-page' })
783
867
 
784
868
  let content
785
- if (listError) content = h('p', { className: 'cb-notice' }, listError)
869
+ if (listError) content = h('p', { className: 'cb-notice' }, errorText(listError, t))
786
870
  else if (boards === null) content = h('p', { className: 'cb-muted' }, t('loading'))
787
871
  else if (boards.length === 0) content = h('div', { className: 'cb-empty' }, h('p', { className: 'cb-emptyTitle' }, t('emptyTitle')), h('p', { className: 'cb-muted' }, t('emptyHint')))
788
- else if (boardError) content = h('p', { className: 'cb-notice' }, boardError)
872
+ else if (boardError) content = h('p', { className: 'cb-notice' }, errorText(boardError, t))
789
873
  else if (!board) content = h('p', { className: 'cb-muted' }, t('loading'))
790
874
  else content = h(React.Fragment, null,
791
875
  board.problems?.length > 0 && h('div', { className: 'cb-notice' }, t('boardProblems'), h('ul', { className: 'cb-problems' }, board.problems.map((p, i) => h('li', { key: i }, p)))),
792
876
  board.cards.length === 0 && h('p', { className: 'cb-muted' }, t('noCards')),
793
877
  h('div', { className: 'cb-grid', style: { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` } },
794
- board.cards.map(entry => h(Card, { key: entry.id, entry, boardId: board.id, columns, now, locale, t, actions }))))
878
+ board.cards.map(entry => h(Card, { key: entry.id, entry, boardId: board.id, assistant: board.assistant, columns, now, active, locale, t, actions }))))
795
879
 
796
880
  return h('div', { className: 'cb-page' },
797
881
  h('div', { className: 'cb-content', ref: gridRef },
798
882
  h('div', { className: 'cb-heading' },
799
- h('h1', null, boards?.length === 1 ? boards[0].title : t('title')),
883
+ h('h1', null, boards?.length === 1 ? titleOf(boards[0]) : t('title')),
800
884
  h('p', { className: 'cb-sub' },
801
- newest > 0 ? fill(t('updated'), { time: formatUpdated(newest, locale) }) : ' ',
885
+ newest > 0 ? t('updated', { time: formatUpdated(newest, locale) }) : ' ',
802
886
  refreshFailed && h('span', { className: 'cb-warnText' }, ` · ${t('refreshFailed')}`))),
803
887
  tabs,
804
888
  content))
@@ -814,30 +898,35 @@ window.__ModuleLoader__.load({
814
898
  }
815
899
 
816
900
  const CSS = `
817
- .cb-page{--cb-ok:var(--dsw-alias-state-success-primary,#22a06b);--cb-warn:var(--dsw-alias-state-warn-primary,#f5a524);--cb-bad:var(--dsw-alias-state-error-primary,#e5484d);--cb-muted:var(--dsw-alias-state-idle-primary,#b8bec9);--cb-accent:var(--dsw-alias-state-business-primary,#3b82f6);--cb-violet:var(--dsw-alias-state-done-primary,#8b5cf6);--cb-card:var(--dsw-alias-bg-base,#fff);--cb-track:var(--dsw-alias-border-l2,#0000001a);width:100%;height:100%;min-height:0;overflow:auto;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);font-size:14px;line-height:1.5;scrollbar-gutter:stable}
818
- .cb-content{max-width:1240px;margin:0 auto;padding:0 clamp(16px,3.2vw,40px) 48px}
901
+ .cb-page{overflow-x:hidden;--cb-ok:var(--dsw-alias-state-success-primary,#22a06b);--cb-warn:var(--dsw-alias-state-warn-primary,#f5a524);--cb-bad:var(--dsw-alias-state-error-primary,#e5484d);--cb-muted:var(--dsw-alias-state-idle-primary,#b8bec9);--cb-accent:var(--dsw-alias-state-business-primary,#3b82f6);--cb-violet:var(--dsw-alias-state-done-primary,#8b5cf6);--cb-card:var(--dsw-alias-bg-base,#fff);--cb-track:var(--dsw-alias-border-l2,#0000001a);width:100%;height:100%;min-height:0;overflow:auto;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);font-size:14px;line-height:1.5;scrollbar-gutter:stable}
902
+ .cb-content{box-sizing:border-box;max-width:1680px;margin:0 auto;padding:0 clamp(16px,3.2vw,40px) 48px}
819
903
  .cb-heading{padding-top:28px;margin-bottom:14px}
820
904
  [data-platform=darwin] .cb-heading{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
821
905
  .cb-heading h1{margin:0;font-size:22px;font-weight:600;line-height:30px}
822
906
  .cb-sub{margin:2px 0 0;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px}
823
907
  .cb-warnText{color:var(--cb-warn)}
824
- .cb-tabs{display:flex;gap:4px;margin:0 0 18px;border-bottom:.5px solid var(--dsw-alias-border-l2);overflow-x:auto;scrollbar-width:none}
825
- .cb-tab{position:relative;flex:none;padding:8px 12px 10px;border:0;background:none;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:14px;cursor:pointer;border-radius:8px 8px 0 0}
908
+ .cb-tabs{display:flex;flex-wrap:wrap;gap:0 4px;margin:0 0 18px;border-bottom:.5px solid var(--dsw-alias-border-l2)}
909
+ .cb-tab{position:relative;flex:0 1 auto;min-width:40px;justify-content:center;display:inline-flex;align-items:center;min-width:0;max-width:100%;min-height:40px;padding:8px 12px 10px;border:0;background:none;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:14px;cursor:pointer;border-radius:8px 8px 0 0}
910
+ .cb-tab span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:min(60vw,260px)}
826
911
  .cb-tab[aria-selected=true]{color:var(--dsw-alias-label-primary);font-weight:500}
827
912
  .cb-tab[aria-selected=true]:after{content:"";position:absolute;left:10px;right:10px;bottom:-.5px;height:2px;border-radius:2px;background:var(--cb-accent)}
828
913
  @media (hover:hover){.cb-tab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}}
829
914
  .cb-grid{display:grid;gap:14px;grid-auto-flow:row dense;align-items:stretch}
830
- .cb-card{box-sizing:border-box;min-width:0;display:flex;flex-direction:column;gap:10px;padding:16px 18px 18px;border-radius:16px;background:var(--cb-card);box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l2)}
915
+ .cb-card{container-type:inline-size;box-sizing:border-box;min-width:0;display:flex;flex-direction:column;gap:10px;padding:16px 18px 18px;border-radius:16px;background:var(--cb-card);box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l2)}
831
916
  .cb-cardHead{display:flex;align-items:center;gap:8px;min-height:22px}
832
- .cb-cardHead h3{flex:1;min-width:0;margin:0;font-size:15px;font-weight:600;line-height:22px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
833
- .cb-cardChat{display:inline-flex;margin-right:-6px}
917
+ .cb-cardHead h3{flex:1;min-width:0;margin:0;font-size:15px;font-weight:600;line-height:22px}
918
+ .cb-trunc{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
919
+ .cb-trunc2{white-space:normal;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow-wrap:anywhere}
920
+ .cb-truncOpen{white-space:normal;display:block;overflow:visible;overflow-wrap:anywhere}
921
+ h3.cb-truncOpen{overflow:visible}
922
+ .cb-cardChat{display:inline-flex;margin:-5px -8px -5px 0}
834
923
  .cb-cardActions{padding-top:4px}
835
- .cb-rowActions{display:inline-flex;justify-content:flex-end}
924
+ .cb-rowActions{display:inline-flex;flex-wrap:wrap;justify-content:flex-end;min-width:0}
836
925
  .cb-statusActions{grid-template-columns:8px fit-content(45%) minmax(0,1fr) auto}
837
926
  .cb-statusSparks.cb-statusActions{grid-template-columns:8px fit-content(40%) minmax(0,1fr) minmax(56px,1.2fr) auto}
838
- .cb-cardLink{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:6px;color:var(--dsw-alias-label-tertiary)}
927
+ .cb-cardLink{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;margin:-5px 0;border-radius:6px;color:var(--dsw-alias-label-tertiary)}
839
928
  @media (hover:hover){.cb-cardLink:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
840
- .cb-staleChip{flex:none;padding:1px 8px;border-radius:999px;font-size:11px;line-height:18px;color:var(--dsw-alias-state-warn-label,var(--cb-warn));background:color-mix(in srgb,var(--cb-warn) 14%,transparent)}
929
+ .cb-staleChip{flex:0 1 auto;min-width:0;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:1px 8px;border-radius:999px;font-size:11px;line-height:18px;color:var(--dsw-alias-state-warn-label,var(--cb-warn));background:color-mix(in srgb,var(--cb-warn) 14%,transparent)}
841
930
  .cb-cardStale .cb-cardBody,.cb-cardStale .cb-stats{opacity:.62}
842
931
  .cb-cardBody{flex:1;min-width:0;display:flex;flex-direction:column;justify-content:flex-start}
843
932
  .cb-cardError{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--cb-bad) 35%,transparent)}
@@ -870,7 +959,7 @@ window.__ModuleLoader__.load({
870
959
  .cb-delta{font-style:normal;font-size:12px;font-weight:500}
871
960
  .cb-statSub{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px}
872
961
  .cb-legend{display:flex;flex-wrap:wrap;gap:4px 14px;margin:8px 0 0;padding:0;list-style:none;color:var(--dsw-alias-label-secondary);font-size:12px}
873
- .cb-legend li{display:inline-flex;align-items:center;gap:6px}
962
+ .cb-legend li{display:inline-flex;align-items:center;gap:6px;min-width:0;max-width:100%}
874
963
  .cb-legend i,.cb-donutTable i{display:inline-block;width:8px;height:8px;border-radius:50%}
875
964
  .cb-legend b{font-weight:500;color:var(--dsw-alias-label-tertiary)}
876
965
  .cb-donut{display:flex;align-items:center;gap:24px}
@@ -883,7 +972,7 @@ window.__ModuleLoader__.load({
883
972
  .cb-donutTable{flex:1;min-width:0;border-collapse:collapse;font-size:13px}
884
973
  .cb-donutTable td{padding:4px 0;white-space:nowrap}
885
974
  .cb-donutTable td:first-child{width:8px;padding-right:10px}
886
- .cb-donutLabel{overflow:hidden;text-overflow:ellipsis;max-width:0;width:100%}
975
+ .cb-donutLabel{max-width:0;width:100%}
887
976
  .cb-num{text-align:right;padding-left:14px!important;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary)}
888
977
  .cb-dim{color:var(--dsw-alias-label-tertiary)}
889
978
  .cb-list{list-style:none;margin:0;padding:0}
@@ -896,7 +985,6 @@ window.__ModuleLoader__.load({
896
985
  .cb-list li{display:flex;align-items:center;gap:10px;padding:8px 2px;border-top:.5px solid var(--dsw-alias-border-l2)}
897
986
  .cb-list li:first-child{border-top:0}
898
987
  .cb-listText{flex:1;min-width:0}
899
- .cb-listTitle{overflow-wrap:anywhere}
900
988
  .cb-listSub{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
901
989
  .cb-listDate{flex:none;color:var(--dsw-alias-label-tertiary);font-size:12px;font-variant-numeric:tabular-nums}
902
990
  .cb-done .cb-listTitle{color:var(--dsw-alias-label-tertiary)}
@@ -904,7 +992,7 @@ window.__ModuleLoader__.load({
904
992
  .cb-check rect{fill:none;stroke:var(--dsw-alias-border-l4,var(--dsw-alias-label-caption));stroke-width:1.3}
905
993
  .cb-check[data-checked=true] rect{fill:var(--cb-accent);stroke:var(--cb-accent)}
906
994
  .cb-check path{fill:none;stroke:#fff;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
907
- .cb-chip{flex:none;padding:1px 8px;border-radius:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover,#0000000d);font-variant-numeric:tabular-nums;white-space:nowrap}
995
+ .cb-chip{flex:0 1 auto;max-width:11em;overflow:hidden;text-overflow:ellipsis;padding:1px 8px;border-radius:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-interactive-bg-hover,#0000000d);font-variant-numeric:tabular-nums;white-space:nowrap}
908
996
  .cb-chip[data-tone=ok]{color:var(--cb-ok);background:color-mix(in srgb,var(--cb-ok) 12%,transparent)}
909
997
  .cb-chip[data-tone=warn]{color:var(--dsw-alias-state-warn-label,var(--cb-warn));background:color-mix(in srgb,var(--cb-warn) 14%,transparent)}
910
998
  .cb-chip[data-tone=bad]{color:var(--cb-bad);background:color-mix(in srgb,var(--cb-bad) 12%,transparent)}
@@ -919,18 +1007,60 @@ window.__ModuleLoader__.load({
919
1007
  .cb-statusValue{min-width:0;display:flex;flex-direction:column;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
920
1008
  .cb-statusValue small{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:16px}
921
1009
  .cb-spark{min-width:0}
1010
+ @container (width<380px){
1011
+ .cb-list li{flex-wrap:wrap}
1012
+ .cb-list li .cb-listText{flex:1 1 9em}
1013
+ .cb-list li .cb-rowActions{flex:1 0 100%;justify-content:flex-start;padding-left:28px}
1014
+ }
1015
+ @container (width<380px){
1016
+ .cb-status,.cb-statusSparks,.cb-statusActions,.cb-statusSparks.cb-statusActions{grid-template-columns:8px minmax(0,1fr) auto}
1017
+ .cb-statusValue{display:contents}
1018
+ .cb-status li>.cb-dot{grid-column:1;grid-row:1}
1019
+ .cb-statusLabel{grid-column:2;grid-row:1}
1020
+ .cb-statusNum{grid-column:3;grid-row:1;justify-self:end}
1021
+ .cb-statusSub{grid-column:2/-1;grid-row:2}
1022
+ .cb-status li>.cb-spark{grid-column:2/-1;grid-row:3}
1023
+ .cb-spark:empty{display:none}
1024
+ .cb-statusActions li .cb-rowActions{grid-column:2/-1;grid-row:4;justify-content:flex-start}
1025
+ }
922
1026
  @media (width<=640px){.cb-heading{padding-top:18px}.cb-heading h1{font-size:20px}.cb-card{padding:14px 14px 16px;border-radius:14px}.cb-statValue{font-size:24px;line-height:30px}}
1027
+ @media (width<=768px),(pointer:coarse){
1028
+ .cb-cardLink{width:40px;height:40px;margin:-9px 0}
1029
+ .cb-cardChat{margin:-9px -10px -9px 0}
1030
+ .cb-tab{padding:8px 14px 10px}
1031
+ }
923
1032
  `
924
1033
 
925
1034
  return {
926
1035
  inject: ['slots', 'locale'],
927
1036
  apply(ctx) {
928
1037
  clientCtx = ctx
1038
+ // The sidebar entry's name comes from the same locale files: fetched for the active language, then
1039
+ // handed to DSH's own dictionary (which also makes the sidebar redraw).
1040
+ let forget = () => {}
929
1041
  ctx.effect(() => {
930
- const disposers = [ctx.locale.register(NS, 'en', en), ctx.locale.register(NS, 'zh', zh)]
931
- return () => { for (const dispose of disposers) dispose() }
932
- }, 'card-board: dictionaries')
933
- const t = ctx.locale.bind(NS)
1042
+ let live = true
1043
+ let loadedFor = null
1044
+ const load = () => {
1045
+ const active = ctx.locale.getSnapshot().active
1046
+ // Registering the words is itself a locale change notification, so only a new language starts a load.
1047
+ if (active === loadedFor) return
1048
+ loadedFor = active
1049
+ fetchMessages(active).then(messages => {
1050
+ if (!live) return
1051
+ forget()
1052
+ try {
1053
+ forget = ctx.locale.register(NS, active, { panel: messages.panel })
1054
+ } catch (error) {
1055
+ console.warn('card-board: sidebar name not registered:', error)
1056
+ }
1057
+ }, () => { if (live) { loadedFor = null; setTimeout(load, 3000) } })
1058
+ }
1059
+ load()
1060
+ const stop = ctx.locale.subscribe(load)
1061
+ return () => { live = false; stop(); forget() }
1062
+ }, 'card-board: sidebar words')
1063
+ const sidebarT = ctx.locale.bind(NS)
934
1064
 
935
1065
  ctx.effect(() => {
936
1066
  if (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return () => {}
@@ -946,14 +1076,16 @@ window.__ModuleLoader__.load({
946
1076
  name: 'main',
947
1077
  key: PANEL,
948
1078
  locale: NS,
949
- inject: () => ({ translate: t }),
950
1079
  }, BoardsPage))
951
1080
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
952
1081
  name: 'sidebar.panellist',
953
1082
  id: PANEL,
954
1083
  order: 13,
955
1084
  locale: NS,
956
- label: () => t('panel'),
1085
+ label: () => {
1086
+ const text = sidebarT('panel')
1087
+ return text === 'panel' ? '' : text
1088
+ },
957
1089
  }, SidebarIcon))
958
1090
  },
959
1091
  }