@soffits/dsh-card-board 0.3.0 → 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 ----------------------------------------------------------------
@@ -195,7 +246,8 @@ window.__ModuleLoader__.load({
195
246
  function LineChart({ data, locale, height }) {
196
247
  const [ref, width] = useWidth()
197
248
  const model = useMemo(() => {
198
- const allX = data.series.flatMap(s => s.points.map(p => p.x))
249
+ // The x range covers the series, a goal drawn as points and the markers, so none of them runs off the plot.
250
+ const allX = [...data.series.flatMap(s => s.points.map(p => p.x)), ...(data.goal?.points ?? []).map(p => p.x), ...(data.markers ?? []).map(m => m.x)]
199
251
  const times = allX.map(toTime)
200
252
  const timeAxis = times.every(Number.isFinite)
201
253
  const numberAxis = !timeAxis && allX.every(x => typeof x === 'number')
@@ -226,8 +278,30 @@ window.__ModuleLoader__.load({
226
278
  const xLabel = x => (model.timeAxis ? formatDay(toTime(x), locale, spanDays) : typeof x === 'number' ? formatNumber(x, locale) : String(x))
227
279
 
228
280
  const longest = data.series.reduce((best, s) => (s.points.length > best.points.length ? s : best), data.series[0])
229
- const labelCount = Math.max(2, Math.floor(plotW / 44))
230
- const xTicks = spread(longest.points.length, labelCount).map(i => longest.points[i].x)
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))
283
+ // Evenly spaced labels, minus any that would print the same text or sit on top of the one before.
284
+ const xTicks = []
285
+ for (const x of spread(longest.points.length, labelCount).map(i => longest.points[i].x)) {
286
+ const last = xTicks[xTicks.length - 1]
287
+ if (last !== undefined && (xLabel(last) === xLabel(x) || sx(x) - sx(last) < labelWidth)) continue
288
+ xTicks.push(x)
289
+ }
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
+ })
231
305
 
232
306
  const path = points => {
233
307
  let d = ''
@@ -249,16 +323,17 @@ window.__ModuleLoader__.load({
249
323
  h('line', { x1: left, x2: left + plotW, y1: sy(v), y2: sy(v), className: 'cb-rule' }),
250
324
  h('text', { x: left - 8, y: sy(v), className: 'cb-axis', textAnchor: 'end', dominantBaseline: 'middle' }, formatAxis(v, locale)))),
251
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))),
252
- (data.markers ?? []).map((m, i) => h('g', { key: `m${i}` },
253
- h('line', { x1: sx(m.x), x2: sx(m.x), y1: top, y2: top + plotH, className: 'cb-marker' }),
254
- 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)))),
255
330
  data.goal && (data.goal.points
256
331
  ? h('path', { d: path(data.goal.points), className: 'cb-goal' })
257
332
  : h('line', { x1: left, x2: left + plotW, y1: sy(data.goal.y), y2: sy(data.goal.y), className: 'cb-goal' })),
258
333
  data.goal?.label && (() => {
259
334
  const end = data.goal.points ? data.goal.points[data.goal.points.length - 1] : { x: null, y: data.goal.y }
260
335
  const x = end.x === null ? left + plotW : sx(end.x)
261
- 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))
262
337
  })(),
263
338
  data.series.map((s, i) => {
264
339
  const color = toneColor(s.tone, i)
@@ -307,7 +382,7 @@ window.__ModuleLoader__.load({
307
382
  h('div', { ref, className: 'cb-chart', style: { height } }, width > 0 && h('svg', { width, height, role: 'img' },
308
383
  h('line', { x1: 0, x2: width, y1: top + plotH + 0.5, y2: top + plotH + 0.5, className: 'cb-rule' }),
309
384
  data.goal && h('line', { x1: 0, x2: width, y1: sy(data.goal.y), y2: sy(data.goal.y), className: 'cb-goal' }),
310
- 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)),
311
386
  data.bars.map((bar, i) => {
312
387
  const cx = slot * i + slot / 2
313
388
  const tip = multi
@@ -334,7 +409,7 @@ window.__ModuleLoader__.load({
334
409
  rx: Math.min(4, p.w / 3), fill: p.color, fillOpacity: multi ? 0.85 : 0.55,
335
410
  })),
336
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)),
337
- 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)))
338
413
  }))),
339
414
  multi && h(Legend, { items: keys.map((key, k) => ({ label: key, color: toneColor(undefined, k) })), locale }))
340
415
  }
@@ -376,7 +451,7 @@ window.__ModuleLoader__.load({
376
451
  data.centre.sub && h('span', null, data.centre.sub))),
377
452
  h('table', { className: 'cb-donutTable' }, h('tbody', null, segments.map((s, i) => h('tr', { key: i },
378
453
  h('td', null, h('i', { style: { background: s.color } })),
379
- h('td', { className: 'cb-donutLabel' }, s.label),
454
+ h('td', { className: 'cb-donutLabel' }, h(Trunc, { text: s.label })),
380
455
  h('td', { className: 'cb-num' }, formatNumber(s.value, locale)),
381
456
  h('td', { className: 'cb-num cb-dim' }, total > 0 ? `${Math.round((s.value / total) * 100)}%` : '–'))))))
382
457
  }
@@ -411,13 +486,13 @@ window.__ModuleLoader__.load({
411
486
  ? h('p', { className: 'cb-muted' }, data.empty ?? t('listEmpty'))
412
487
  : h('ul', { className: 'cb-list' }, data.rows.map((row, i) =>
413
488
  h('li', { key: i, className: row.checked ? 'cb-done' : undefined },
414
- 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 })),
415
490
  h('div', { className: 'cb-listText' },
416
- h('div', { className: 'cb-listTitle' }, row.title),
417
- 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 })),
418
493
  row.date && h('span', { className: 'cb-listDate' }, formatDay(toTime(row.date), locale, 0)),
419
494
  row.chip && h(Chip, row.chip),
420
- rowActions && row.actions && rowActions(i, row.actions, listRowLine(row)))))
495
+ row.actions && rowActions && h('span', { className: 'cb-rowActions' }, rowActions(i, row.actions, listRowLine(row))))))
421
496
  if (!data.progress) return rows
422
497
  // Beside the rows when there is room for both, else a small ring with its count above them.
423
498
  const wide = width >= 460
@@ -481,7 +556,7 @@ window.__ModuleLoader__.load({
481
556
  now >= from && now <= to && h('line', { x1: sx(now), x2: sx(now), y1: tickH - 2, y2: height, className: 'cb-today' }),
482
557
  placed.map((p, i) => {
483
558
  const color = toneColor(p.tone ?? KIND_TONE[p.kind] ?? 'accent')
484
- const text = p.label.length > 16 ? `${p.label.slice(0, 15)}…` : p.label
559
+ const text = fit(p.label, 90)
485
560
  return h('g', { key: i },
486
561
  h('title', null, `${formatDay(p.time, locale, 0)} · ${p.label}`),
487
562
  p.kind === 'travel' ? h(PlaneGlyph, { x: p.x, y: pointY, color }) : h('circle', { cx: p.x, cy: pointY, r: 5, fill: color }),
@@ -492,11 +567,11 @@ window.__ModuleLoader__.load({
492
567
  const x = sx(s.a)
493
568
  const w = Math.max(6, sx(s.b) - x)
494
569
  const y = spansTop + i * 36
570
+ const full = `${s.label} · ${formatDay(toTime(s.from), locale, 0)} – ${formatDay(toTime(s.to), locale, 0)}`
495
571
  return h('g', { key: `s${i}` },
496
- h('title', null, `${s.label}: ${s.from} – ${s.to}`),
572
+ h('title', null, full),
497
573
  h('rect', { x, y, width: w, height: 12, rx: 6, fill: toneColor(s.tone ?? 'accent'), fillOpacity: 0.22 }),
498
- h('text', { x: Math.min(Math.max(x + w / 2, pad + 30), width - pad - 30), y: y + 26, className: 'cb-spanLabel', textAnchor: 'middle' },
499
- `${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)))
500
575
  })))
501
576
  }
502
577
 
@@ -518,11 +593,11 @@ window.__ModuleLoader__.load({
518
593
  return h('ul', { className: `cb-status${sparks ? ' cb-statusSparks' : ''}${hasActions ? ' cb-statusActions' : ''}` }, data.rows.map((row, i) =>
519
594
  h('li', { key: i },
520
595
  h('i', { className: 'cb-dot', style: { background: toneColor(row.tone) } }),
521
- h('span', { className: 'cb-statusLabel' }, row.label),
596
+ h(Trunc, { as: 'span', className: 'cb-statusLabel', text: row.label }),
522
597
  h('span', { className: 'cb-statusValue' },
523
- h('span', { style: row.tone === 'bad' || row.tone === 'warn' ? { color: toneColor(row.tone) } : undefined }, formatNumber(row.value, locale)),
524
- row.sub && h('small', null, row.sub)),
525
- 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' })),
526
601
  hasActions && h('span', { className: 'cb-rowActions' }, rowActions && row.actions ? rowActions(i, row.actions, statusRowLine(row, locale)) : null))))
527
602
  }
528
603
 
@@ -546,7 +621,7 @@ window.__ModuleLoader__.load({
546
621
  }
547
622
 
548
623
  /** A few plain lines saying what a card shows, for the agent. */
549
- function summaryLines(card, locale) {
624
+ function summaryLines(card, locale, t) {
550
625
  const data = card.data
551
626
  const lines = card.stat ? statLines(card.stat, locale) : []
552
627
  switch (card.type) {
@@ -554,9 +629,9 @@ window.__ModuleLoader__.load({
554
629
  case 'line':
555
630
  for (const series of data.series) {
556
631
  const last = [...series.points].reverse().find(p => typeof p.y === 'number')
557
- 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 }))
558
633
  }
559
- 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) }))
560
635
  return lines
561
636
  case 'bar':
562
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)}`))
@@ -565,7 +640,7 @@ window.__ModuleLoader__.load({
565
640
  return lines.concat(data.segments.map(s => `${s.label}: ${withUnit(s.value, data.unit, locale)}${total > 0 ? ` (${Math.round((s.value / total) * 100)}%)` : ''}`))
566
641
  }
567
642
  case 'list':
568
- 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))
569
644
  case 'timeline':
570
645
  return lines.concat((data.points ?? []).map(p => `${p.date}: ${p.label}`), (data.spans ?? []).map(s => `${s.from} – ${s.to}: ${s.label}`))
571
646
  case 'status':
@@ -584,9 +659,11 @@ window.__ModuleLoader__.load({
584
659
  // ---- card frame ----------------------------------------------------------
585
660
 
586
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 }
587
664
 
588
- function CardBody({ card, size, locale, t, rowActions }) {
589
- 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)
590
667
  const data = card.data
591
668
  switch (card.type) {
592
669
  case 'stat': return h(StatBlock, { data, locale })
@@ -605,16 +682,16 @@ window.__ModuleLoader__.load({
605
682
  h('path', { d: 'M6 3.5H3.5v9h9V10M9 3h4v4M13 3 7.5 8.5' }))
606
683
  }
607
684
 
608
- function Card({ entry, boardId, columns, now, locale, t, actions }) {
685
+ function Card({ entry, boardId, assistant, columns, now, active, locale, t, actions }) {
609
686
  const size = { w: Math.min(entry.w ?? 1, columns), h: entry.h ?? 1 }
610
- 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 }
611
688
  if (!entry.card) {
612
689
  return h('section', { className: 'cb-card cb-cardError', style },
613
- h('header', { className: 'cb-cardHead' }, h('h3', null, entry.id)),
690
+ h('header', { className: 'cb-cardHead' }, h('h3', { title: entry.id }, entry.id)),
614
691
  h('p', { className: 'cb-errorText' }, t('cardError')),
615
692
  h('ul', { className: 'cb-problems' }, (entry.problems ?? []).map((p, i) => h('li', { key: i }, p))))
616
693
  }
617
- const card = entry.card
694
+ const card = pickCard(entry.card, active)
618
695
  const updated = Date.parse(card.updatedAt)
619
696
  const age = Math.max(0, (now - updated) / 1000)
620
697
  const stale = typeof card.staleAfter === 'number' && age > card.staleAfter
@@ -625,14 +702,16 @@ window.__ModuleLoader__.load({
625
702
  text: actions.chatText({
626
703
  prompt: action.payload?.prompt ?? '',
627
704
  title: card.title,
628
- lines: row === undefined ? summaryLines(card, locale) : [rowLine],
705
+ lines: row === undefined ? summaryLines(card, locale, t) : [rowLine],
629
706
  context: action.payload?.context ?? context(row),
630
707
  }),
631
708
  session: action.payload?.session,
632
709
  })
633
- 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') }
634
713
  const rowActions = actions && ((row, list, line) => h(actions.ActionBar, {
635
- actions: list,
714
+ actions: named(list),
636
715
  states: statesOf(entry.presses, row),
637
716
  compact: true,
638
717
  chat: action => chat(action, row, line),
@@ -640,14 +719,14 @@ window.__ModuleLoader__.load({
640
719
  }))
641
720
  return h('section', { className: `cb-card${stale ? ' cb-cardStale' : ''}`, style, 'data-type': card.type },
642
721
  h('header', { className: 'cb-cardHead' },
643
- h('h3', null, card.title),
644
- 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) })),
645
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)),
646
725
  actions && h('span', { className: 'cb-cardChat' }, h(actions.ActionButton, { action: defaultChat, compact: true, chat: action => chat(action) }))),
647
726
  card.stat && h(StatBlock, { data: card.stat, locale, compact: true }),
648
- 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 })),
649
728
  actions && card.actions && h('footer', { className: 'cb-cardActions' }, h(actions.ActionBar, {
650
- actions: card.actions,
729
+ actions: named(card.actions),
651
730
  states: statesOf(entry.presses, undefined),
652
731
  chat: action => chat(action),
653
732
  onPress: (action, extra) => actions.press(action, extra, { card: entry.id }),
@@ -656,26 +735,32 @@ window.__ModuleLoader__.load({
656
735
 
657
736
  // ---- page ----------------------------------------------------------------
658
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
+
659
745
  async function getJson(path, etag) {
660
746
  const response = await fetch(api(path), { cache: 'no-store', credentials: 'same-origin', headers: etag ? { 'if-none-match': etag } : {} })
661
747
  if (response.status === 304) return { notModified: true }
662
748
  let body = null
663
749
  try { body = await response.json() } catch { /* not JSON */ }
664
- if (!response.ok) {
665
- const error = new Error(body?.error ?? `HTTP ${response.status}`)
666
- error.status = response.status
667
- throw error
668
- }
750
+ if (!response.ok) throw requestError(response.status, body)
669
751
  return { body, etag: response.headers.get('etag') }
670
752
  }
671
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
+
672
757
  function useColumns() {
673
758
  const [ref, width] = useWidth()
674
- return [ref, width >= 980 ? 3 : width >= 620 ? 2 : 1]
759
+ return [ref, width >= 1400 ? 4 : width >= 980 ? 3 : width >= 620 ? 2 : 1]
675
760
  }
676
761
 
677
- function BoardsPage({ translate: t }) {
678
- const locale = t('time.locale')
762
+ function BoardsPage() {
763
+ const { active, intl: locale, ready, t } = useActiveLocale()
679
764
  const [boards, setBoards] = useState(null)
680
765
  const [listError, setListError] = useState(null)
681
766
  const [selected, setSelected] = useState(() => { try { return localStorage.getItem(STORE_KEY) } catch { return null } })
@@ -688,6 +773,9 @@ window.__ModuleLoader__.load({
688
773
  const [gridRef, columns] = useColumns()
689
774
  const [actions, setActions] = useState(null)
690
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
691
779
 
692
780
  const loadList = useCallback(async () => {
693
781
  try {
@@ -696,9 +784,9 @@ window.__ModuleLoader__.load({
696
784
  setPollSeconds(body.pollSeconds ?? 30)
697
785
  setListError(null)
698
786
  } catch (error) {
699
- setListError(error.status === 503 ? t('noProvider') : error.message)
787
+ setListError(error)
700
788
  }
701
- }, [t])
789
+ }, [])
702
790
 
703
791
  const current = boards?.some(b => b.id === selected) ? selected : boards?.[0]?.id ?? null
704
792
 
@@ -712,7 +800,7 @@ window.__ModuleLoader__.load({
712
800
  etag.current = result.etag
713
801
  setBoard(result.body)
714
802
  } catch (error) {
715
- 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 }
716
804
  setRefreshFailed(true)
717
805
  }
718
806
  }, [loadList])
@@ -732,15 +820,15 @@ window.__ModuleLoader__.load({
732
820
  body: JSON.stringify({ board: currentRef.current, ...target, id: action.id, ...extra }),
733
821
  })
734
822
  const body = await response.json().catch(() => null)
735
- 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))
736
824
  loadBoard(currentRef.current, false)
737
825
  return body
738
826
  }
739
- const ui = createActions({ React, ctx: clientCtx, locale })
827
+ const ui = createActions({ React, ctx: clientCtx, t: (key, params) => translateRef.current(`action.${key}`, params) })
740
828
  setActions({ ...ui, press })
741
829
  }, error => console.warn('card-board: action buttons not loaded:', error))
742
830
  return () => { live = false }
743
- }, [loadBoard, locale])
831
+ }, [loadBoard])
744
832
 
745
833
  useEffect(() => {
746
834
  currentRef.current = current
@@ -771,27 +859,30 @@ window.__ModuleLoader__.load({
771
859
  return Number.isFinite(time) && time > max ? time : max
772
860
  }, 0)
773
861
 
862
+ const titleOf = entry => pickText(entry.title, active)
774
863
  const tabs = boards && boards.length > 1 && h('div', { className: 'cb-tabs', role: 'tablist' }, boards.map(b =>
775
- 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' })
776
867
 
777
868
  let content
778
- if (listError) content = h('p', { className: 'cb-notice' }, listError)
869
+ if (listError) content = h('p', { className: 'cb-notice' }, errorText(listError, t))
779
870
  else if (boards === null) content = h('p', { className: 'cb-muted' }, t('loading'))
780
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')))
781
- else if (boardError) content = h('p', { className: 'cb-notice' }, boardError)
872
+ else if (boardError) content = h('p', { className: 'cb-notice' }, errorText(boardError, t))
782
873
  else if (!board) content = h('p', { className: 'cb-muted' }, t('loading'))
783
874
  else content = h(React.Fragment, null,
784
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)))),
785
876
  board.cards.length === 0 && h('p', { className: 'cb-muted' }, t('noCards')),
786
877
  h('div', { className: 'cb-grid', style: { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` } },
787
- 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 }))))
788
879
 
789
880
  return h('div', { className: 'cb-page' },
790
881
  h('div', { className: 'cb-content', ref: gridRef },
791
882
  h('div', { className: 'cb-heading' },
792
- h('h1', null, boards?.length === 1 ? boards[0].title : t('title')),
883
+ h('h1', null, boards?.length === 1 ? titleOf(boards[0]) : t('title')),
793
884
  h('p', { className: 'cb-sub' },
794
- newest > 0 ? fill(t('updated'), { time: formatUpdated(newest, locale) }) : ' ',
885
+ newest > 0 ? t('updated', { time: formatUpdated(newest, locale) }) : ' ',
795
886
  refreshFailed && h('span', { className: 'cb-warnText' }, ` · ${t('refreshFailed')}`))),
796
887
  tabs,
797
888
  content))
@@ -807,30 +898,35 @@ window.__ModuleLoader__.load({
807
898
  }
808
899
 
809
900
  const CSS = `
810
- .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}
811
- .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}
812
903
  .cb-heading{padding-top:28px;margin-bottom:14px}
813
904
  [data-platform=darwin] .cb-heading{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
814
905
  .cb-heading h1{margin:0;font-size:22px;font-weight:600;line-height:30px}
815
906
  .cb-sub{margin:2px 0 0;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px}
816
907
  .cb-warnText{color:var(--cb-warn)}
817
- .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}
818
- .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)}
819
911
  .cb-tab[aria-selected=true]{color:var(--dsw-alias-label-primary);font-weight:500}
820
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)}
821
913
  @media (hover:hover){.cb-tab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}}
822
914
  .cb-grid{display:grid;gap:14px;grid-auto-flow:row dense;align-items:stretch}
823
- .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)}
824
916
  .cb-cardHead{display:flex;align-items:center;gap:8px;min-height:22px}
825
- .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}
826
- .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}
827
923
  .cb-cardActions{padding-top:4px}
828
- .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}
829
925
  .cb-statusActions{grid-template-columns:8px fit-content(45%) minmax(0,1fr) auto}
830
926
  .cb-statusSparks.cb-statusActions{grid-template-columns:8px fit-content(40%) minmax(0,1fr) minmax(56px,1.2fr) auto}
831
- .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)}
832
928
  @media (hover:hover){.cb-cardLink:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
833
- .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)}
834
930
  .cb-cardStale .cb-cardBody,.cb-cardStale .cb-stats{opacity:.62}
835
931
  .cb-cardBody{flex:1;min-width:0;display:flex;flex-direction:column;justify-content:flex-start}
836
932
  .cb-cardError{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--cb-bad) 35%,transparent)}
@@ -863,7 +959,7 @@ window.__ModuleLoader__.load({
863
959
  .cb-delta{font-style:normal;font-size:12px;font-weight:500}
864
960
  .cb-statSub{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px}
865
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}
866
- .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%}
867
963
  .cb-legend i,.cb-donutTable i{display:inline-block;width:8px;height:8px;border-radius:50%}
868
964
  .cb-legend b{font-weight:500;color:var(--dsw-alias-label-tertiary)}
869
965
  .cb-donut{display:flex;align-items:center;gap:24px}
@@ -876,7 +972,7 @@ window.__ModuleLoader__.load({
876
972
  .cb-donutTable{flex:1;min-width:0;border-collapse:collapse;font-size:13px}
877
973
  .cb-donutTable td{padding:4px 0;white-space:nowrap}
878
974
  .cb-donutTable td:first-child{width:8px;padding-right:10px}
879
- .cb-donutLabel{overflow:hidden;text-overflow:ellipsis;max-width:0;width:100%}
975
+ .cb-donutLabel{max-width:0;width:100%}
880
976
  .cb-num{text-align:right;padding-left:14px!important;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary)}
881
977
  .cb-dim{color:var(--dsw-alias-label-tertiary)}
882
978
  .cb-list{list-style:none;margin:0;padding:0}
@@ -889,7 +985,6 @@ window.__ModuleLoader__.load({
889
985
  .cb-list li{display:flex;align-items:center;gap:10px;padding:8px 2px;border-top:.5px solid var(--dsw-alias-border-l2)}
890
986
  .cb-list li:first-child{border-top:0}
891
987
  .cb-listText{flex:1;min-width:0}
892
- .cb-listTitle{overflow-wrap:anywhere}
893
988
  .cb-listSub{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
894
989
  .cb-listDate{flex:none;color:var(--dsw-alias-label-tertiary);font-size:12px;font-variant-numeric:tabular-nums}
895
990
  .cb-done .cb-listTitle{color:var(--dsw-alias-label-tertiary)}
@@ -897,7 +992,7 @@ window.__ModuleLoader__.load({
897
992
  .cb-check rect{fill:none;stroke:var(--dsw-alias-border-l4,var(--dsw-alias-label-caption));stroke-width:1.3}
898
993
  .cb-check[data-checked=true] rect{fill:var(--cb-accent);stroke:var(--cb-accent)}
899
994
  .cb-check path{fill:none;stroke:#fff;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
900
- .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}
901
996
  .cb-chip[data-tone=ok]{color:var(--cb-ok);background:color-mix(in srgb,var(--cb-ok) 12%,transparent)}
902
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)}
903
998
  .cb-chip[data-tone=bad]{color:var(--cb-bad);background:color-mix(in srgb,var(--cb-bad) 12%,transparent)}
@@ -912,18 +1007,60 @@ window.__ModuleLoader__.load({
912
1007
  .cb-statusValue{min-width:0;display:flex;flex-direction:column;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
913
1008
  .cb-statusValue small{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:16px}
914
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
+ }
915
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
+ }
916
1032
  `
917
1033
 
918
1034
  return {
919
1035
  inject: ['slots', 'locale'],
920
1036
  apply(ctx) {
921
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 = () => {}
922
1041
  ctx.effect(() => {
923
- const disposers = [ctx.locale.register(NS, 'en', en), ctx.locale.register(NS, 'zh', zh)]
924
- return () => { for (const dispose of disposers) dispose() }
925
- }, 'card-board: dictionaries')
926
- 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)
927
1064
 
928
1065
  ctx.effect(() => {
929
1066
  if (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return () => {}
@@ -939,14 +1076,16 @@ window.__ModuleLoader__.load({
939
1076
  name: 'main',
940
1077
  key: PANEL,
941
1078
  locale: NS,
942
- inject: () => ({ translate: t }),
943
1079
  }, BoardsPage))
944
1080
  ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
945
1081
  name: 'sidebar.panellist',
946
1082
  id: PANEL,
947
1083
  order: 13,
948
1084
  locale: NS,
949
- label: () => t('panel'),
1085
+ label: () => {
1086
+ const text = sidebarT('panel')
1087
+ return text === 'panel' ? '' : text
1088
+ },
950
1089
  }, SidebarIcon))
951
1090
  },
952
1091
  }