@soffits/dsh-card-board 0.3.1 → 0.4.1

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