@soffits/dsh-card-board 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +19 -6
- package/client.actions.js +36 -61
- package/client.js +277 -145
- package/examples/boards/home/board.json +25 -5
- package/examples/boards/home/cards/chores.json +40 -10
- package/examples/boards/home/cards/energy.json +53 -8
- package/examples/boards/home/cards/house.json +44 -11
- package/examples/boards/home/cards/next-weeks.json +47 -6
- package/examples/boards/home/cards/savings.json +64 -11
- package/examples/boards/home/cards/spending.json +44 -7
- package/examples/boards/home/cards/weather.json +29 -3
- package/index.js +3 -0
- package/locale/en.json +50 -1
- package/locale/fr.json +50 -0
- package/locale/zh.json +50 -1
- package/package.json +3 -2
- package/src/messages.js +53 -0
- package/src/routes.js +13 -2
- package/src/schema.js +57 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
- Languages: any text on a card or board can be a string or a map of language id to text (`{ "en": "Today", "fr": "Aujourd’hui" }`, `en` required), and the page shows the one for DSH's active language, falling back from the exact tag to its primary language to `en`. Numbers, dates, ages and units are formatted with `Intl` in that language.
|
|
6
|
+
- The page's own words are one `locale/<tag>.json` per language (English, French and Chinese ship), served by a new `GET /api/card-board/locale` route and picked by DSH's active language, live. A new language is a new file; nothing in the code names one.
|
|
7
|
+
- `board.json` takes an optional `assistant` name; the chat buttons then say "Ask <name>".
|
|
8
|
+
- Phones: one column with moderate chart heights, tap targets of at least 40 px (at 768 px and below, or on touch), list and status row buttons wrap under the row text on narrow cards, tabs wrap instead of scrolling, long titles, labels, chips and legend entries shorten with the full text on hover and tap, chart and timeline labels fit their space (marker labels no longer collide with the goal label, bar labels stay inside the card), the snooze picker is a bottom sheet. Four columns on very wide screens.
|
|
9
|
+
- Fix: the buttons chunk registers as a chunk of the package (`{ id, chunk }`) and no longer declares anything at the top level, so two plugins that ship it no longer break each other (the second one failed to register); a failed load is retried.
|
|
10
|
+
- Fix: the default chat button's label was missing from the page's words.
|
|
11
|
+
|
|
3
12
|
## 0.3.1
|
|
4
13
|
|
|
5
14
|
- Line charts: a goal drawn as points, and markers, no longer run past the plot when they reach beyond the series; x labels that would repeat or overlap are left out.
|
package/README.md
CHANGED
|
@@ -71,11 +71,12 @@ Board and card ids are lowercase letters, digits, `-` and `_`, up to 64 characte
|
|
|
71
71
|
"title": "Home",
|
|
72
72
|
"viewers": ["alex", "sam"],
|
|
73
73
|
"order": ["weather", "savings", "energy"],
|
|
74
|
-
"layout": { "next-weeks": { "w": 2, "h": 1 } }
|
|
74
|
+
"layout": { "next-weeks": { "w": 2, "h": 1 } },
|
|
75
|
+
"assistant": "Robin"
|
|
75
76
|
}
|
|
76
77
|
```
|
|
77
78
|
|
|
78
|
-
`order` lists cards to put first; the rest follow by id. `layout` sets a card's width and height in grid cells (1 to 3). The grid has
|
|
79
|
+
`order` lists cards to put first; the rest follow by id. `layout` sets a card's width and height in grid cells (1 to 3). The grid has four columns on a very wide screen, three on a wide one, two on a medium one and one on a phone; a wide card shrinks to fit. `assistant` is optional: the name the chat buttons ask ("Ask Robin" instead of "Ask"). `title` can be [text in several languages](#languages).
|
|
79
80
|
|
|
80
81
|
A card:
|
|
81
82
|
|
|
@@ -103,7 +104,19 @@ A card:
|
|
|
103
104
|
|
|
104
105
|
Unknown fields are errors, so a typo fails when the file is written instead of quietly not showing. A card that doesn't parse or fails the schema shows as a small error card with the reason; the rest of the board is unaffected.
|
|
105
106
|
|
|
106
|
-
Colours are never given directly. `tone` is one of `ok`, `warn`, `bad`, `muted` or `accent`, and the page maps it to DSH's theme, light or dark.
|
|
107
|
+
Colours are never given directly. `tone` is one of `ok`, `warn`, `bad`, `muted` or `accent`, and the page maps it to DSH's theme, light or dark. Dates are `YYYY-MM-DD` or ISO date-times. Numbers, dates and units are formatted by the page in the viewer's language.
|
|
108
|
+
|
|
109
|
+
### Languages
|
|
110
|
+
|
|
111
|
+
Every text a person reads (titles, labels, units, sub-lines, chip text, list rows, point and span labels, a status row's value, action labels) is either a string, shown as it is to everyone, or a map from language id to text:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
"title": { "en": "Today", "fr": "Aujourd’hui", "zh": "今天" }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Ids are lowercase BCP 47 tags and `en` is required, the same shape DSH uses for localized package text. The page shows the text for DSH's active language: the exact tag (`pt-br`), then its primary language (`pt`), then `en`. So one board reads in French to one person and in Chinese to another, and the file holds no preference of its own. Things that are data, not words (a to-do's title, a merchant), stay plain strings. Bar series names (the keys of `values`) and x values are not translated.
|
|
118
|
+
|
|
119
|
+
The page's own words (buttons, empty states, errors) live in [`locale/<tag>.json`](locale), under `ui`, one file per language. English, French and Chinese ship. Which languages exist is whatever files are there: a new language is one new file with the same keys as `en.json`, no code change (a test checks every file has every key and the same `{placeholders}`), and a missing key falls back to the primary language, then English.
|
|
107
120
|
|
|
108
121
|
### stat
|
|
109
122
|
|
|
@@ -212,7 +225,7 @@ A card, a list row or a status row can carry up to six buttons:
|
|
|
212
225
|
]
|
|
213
226
|
```
|
|
214
227
|
|
|
215
|
-
- `chat` opens a new conversation (or the session named in `payload.session`) with a draft that quotes the card or row and carries its ids as JSON, after `payload.prompt` if you gave one. Nothing is sent until the person sends it, so the message comes from them like any other. Every card also has a chat button in its corner without declaring one.
|
|
228
|
+
- `chat` opens a new conversation (or the session named in `payload.session`) with a draft that quotes the card or row and carries its ids as JSON, after `payload.prompt` if you gave one. Nothing is sent until the person sends it, so the message comes from them like any other. Every card also has a chat button in its corner without declaring one; when the board names an `assistant` the button says who it asks. A `label` can be text in several languages.
|
|
216
229
|
- `done`, `snooze` and `event` are pressed on the server. A snooze without `payload.until` asks: in 3 hours, tomorrow at 9:00, or a time.
|
|
217
230
|
- `link` opens `payload.url`.
|
|
218
231
|
|
|
@@ -237,7 +250,7 @@ It's appended to the action log, emitted in-process as the Cordis event `card-bo
|
|
|
237
250
|
|
|
238
251
|
The button shows the press as pending until the card file is written again, then done. If nothing rewrites the card within `actionTimeoutSeconds`, it says nothing picked the press up. So a handler should rewrite the card when it has acted, even if only `updatedAt` changes.
|
|
239
252
|
|
|
240
|
-
The buttons come from [`client.actions.js`](client.actions.js), a
|
|
253
|
+
The buttons come from [`client.actions.js`](client.actions.js), loaded with the page. On a phone they are at least 40 px, and a snooze picker opens as a sheet at the bottom of the screen.
|
|
241
254
|
|
|
242
255
|
## Writing cards: the CLI
|
|
243
256
|
|
|
@@ -260,7 +273,7 @@ From JavaScript the same checks are `import { checkCard, checkBoard } from '@sof
|
|
|
260
273
|
|
|
261
274
|
## How the page updates
|
|
262
275
|
|
|
263
|
-
The page polls `GET /api/card-board/board?id=<board>` while it's visible, with the last `ETag` in `If-None-Match`. The tag is built from file sizes and times, so an unchanged board answers 304 without reading a card. Coming back to the tab checks at once.
|
|
276
|
+
The page polls `GET /api/card-board/board?id=<board>` while it's visible, with the last `ETag` in `If-None-Match`. The tag is built from file sizes and times, so an unchanged board answers 304 without reading a card. Coming back to the tab checks at once. The page's words come once per language from `GET /api/card-board/locale?tag=<id>` (the merged `locale/*.json`, English filling gaps).
|
|
264
277
|
|
|
265
278
|
## Development
|
|
266
279
|
|
package/client.actions.js
CHANGED
|
@@ -4,13 +4,23 @@
|
|
|
4
4
|
*
|
|
5
5
|
* A DSH client chunk: dsh-card-board's client loads it with
|
|
6
6
|
* `require.async('./client.actions.js')`. Another plugin can ship a copy as
|
|
7
|
-
* its own `client.actions.js`, changing OWNER below to its package name
|
|
8
|
-
*
|
|
7
|
+
* its own `client.actions.js`, changing OWNER below to its package name.
|
|
8
|
+
*
|
|
9
|
+
* DSH runs a chunk as a classic script, so everything sits inside one function
|
|
10
|
+
* (a top-level `const` would clash with another plugin's copy and the second
|
|
11
|
+
* chunk would never register).
|
|
9
12
|
*
|
|
10
13
|
* const { createActions } = await require.async('./client.actions.js')
|
|
11
|
-
* const ui = createActions({ React, ctx,
|
|
14
|
+
* const ui = createActions({ React, ctx, t, press })
|
|
12
15
|
* h(ui.ActionBar, { actions, states, chat, onPress })
|
|
13
16
|
*
|
|
17
|
+
* `t(key, params)` gives the words in the person's language; the host plugin
|
|
18
|
+
* keeps them in its one message table. The keys it must know are exported as
|
|
19
|
+
* `KEYS`: chat, chatAbout, done, snooze, event, link, in3h, tomorrow, pick,
|
|
20
|
+
* set, cancel, sending, pending, handled, unhandled, failed ({message}),
|
|
21
|
+
* noWorkspace. `t` is called while rendering, so a language switch shows up
|
|
22
|
+
* without building the buttons again.
|
|
23
|
+
*
|
|
14
24
|
* `press(action, extra)` is the plugin's own server call for done, snooze and
|
|
15
25
|
* event (extra carries `until` for a snooze); it should resolve once the
|
|
16
26
|
* server has accepted the press. `chat` and `link` never reach the server:
|
|
@@ -18,65 +28,37 @@
|
|
|
18
28
|
* UI's own workspace service (so the person sends it themselves, signed in as
|
|
19
29
|
* themselves), and link opens the URL.
|
|
20
30
|
*/
|
|
31
|
+
(() => {
|
|
21
32
|
const OWNER = '@soffits/dsh-card-board'
|
|
22
33
|
|
|
23
|
-
const
|
|
24
|
-
en: {
|
|
25
|
-
chat: 'Ask',
|
|
26
|
-
chatAbout: 'Chat about this',
|
|
27
|
-
done: 'Done',
|
|
28
|
-
snooze: 'Snooze',
|
|
29
|
-
open: 'Open',
|
|
30
|
-
in3h: 'In 3 hours',
|
|
31
|
-
tomorrow: 'Tomorrow 9:00',
|
|
32
|
-
pick: 'Pick a time…',
|
|
33
|
-
set: 'Snooze',
|
|
34
|
-
cancel: 'Cancel',
|
|
35
|
-
sending: 'Sending…',
|
|
36
|
-
pending: 'Waiting for it to be picked up',
|
|
37
|
-
handled: 'Done',
|
|
38
|
-
unhandled: 'Nothing picked this up yet',
|
|
39
|
-
failed: 'Didn’t go through: {message}',
|
|
40
|
-
noWorkspace: 'Open a conversation once first, then try again.',
|
|
41
|
-
},
|
|
42
|
-
zh: {
|
|
43
|
-
chat: '问问',
|
|
44
|
-
chatAbout: '聊聊这个',
|
|
45
|
-
done: '完成',
|
|
46
|
-
snooze: '稍后提醒',
|
|
47
|
-
open: '打开',
|
|
48
|
-
in3h: '3 小时后',
|
|
49
|
-
tomorrow: '明天 9:00',
|
|
50
|
-
pick: '选个时间…',
|
|
51
|
-
set: '稍后提醒',
|
|
52
|
-
cancel: '取消',
|
|
53
|
-
sending: '发送中…',
|
|
54
|
-
pending: '等待处理',
|
|
55
|
-
handled: '已处理',
|
|
56
|
-
unhandled: '还没有被处理',
|
|
57
|
-
failed: '没有成功:{message}',
|
|
58
|
-
noWorkspace: '请先打开一次对话,再试一次。',
|
|
59
|
-
},
|
|
60
|
-
}
|
|
34
|
+
const KEYS = ['chat', 'chatAbout', 'done', 'snooze', 'event', 'link', 'in3h', 'tomorrow', 'pick', 'set', 'cancel', 'sending', 'pending', 'handled', 'unhandled', 'failed', 'noWorkspace']
|
|
61
35
|
|
|
62
36
|
const CSS = `
|
|
63
|
-
.ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
64
|
-
.ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;gap:
|
|
37
|
+
.ua-bar{display:flex;flex-wrap:wrap;gap:6px;align-items:center;min-width:0}
|
|
38
|
+
.ua-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:32px;max-width:100%;padding:0 12px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;text-decoration:none;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3)}
|
|
39
|
+
.ua-btn span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
65
40
|
.ua-btn svg{flex:none;width:14px;height:14px}
|
|
66
41
|
.ua-btn:disabled{cursor:default;opacity:.7}
|
|
67
42
|
@media (hover:hover){.ua-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
|
|
68
|
-
.ua-icon{width:
|
|
43
|
+
.ua-icon{width:32px;padding:0;box-shadow:none;color:var(--dsw-alias-label-tertiary)}
|
|
69
44
|
.ua-btn[data-state=pending] svg,.ua-btn[data-state=sending] svg{animation:ua-pulse 1.2s ease-in-out infinite}
|
|
70
45
|
.ua-btn[data-state=done]{color:var(--dsw-alias-state-success-primary)}
|
|
71
46
|
.ua-btn[data-state=unhandled]{color:var(--dsw-alias-state-warn-label,var(--dsw-alias-state-warn-primary))}
|
|
72
47
|
@keyframes ua-pulse{50%{opacity:.35}}
|
|
73
|
-
.ua-wrap{position:relative;display:inline-flex}
|
|
48
|
+
.ua-wrap{position:relative;display:inline-flex;max-width:100%;flex-wrap:wrap;align-items:center;gap:4px 8px}
|
|
74
49
|
.ua-menu{position:absolute;z-index:20;top:calc(100% + 4px);right:0;min-width:168px;padding:4px;border-radius:12px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-base));box-shadow:0 6px 24px #0000001f,inset 0 0 0 .5px var(--dsw-alias-border-l2);display:flex;flex-direction:column}
|
|
75
|
-
.ua-menu button{display:flex;align-items:center;gap:8px;padding:7px 10px;border:0;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
50
|
+
.ua-menu button{display:flex;align-items:center;gap:8px;min-height:36px;padding:7px 10px;border:0;border-radius:8px;background:none;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
76
51
|
@media (hover:hover){.ua-menu button:hover{background:var(--dsw-alias-interactive-bg-hover)}}
|
|
77
|
-
.ua-menu input{margin:4px 6px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:
|
|
52
|
+
.ua-menu input{margin:4px 6px;min-height:36px;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l3);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:16px}
|
|
78
53
|
.ua-menuRow{display:flex;justify-content:flex-end;gap:4px;padding:2px 4px}
|
|
79
|
-
.ua-error{color:var(--dsw-alias-state-error-primary);font-size:12px}
|
|
54
|
+
.ua-error{flex-basis:100%;color:var(--dsw-alias-state-error-primary);font-size:12px;overflow-wrap:anywhere}
|
|
55
|
+
@media (width<=768px),(pointer:coarse){
|
|
56
|
+
.ua-btn{min-height:40px}
|
|
57
|
+
.ua-icon{width:40px}
|
|
58
|
+
.ua-menu{position:fixed;z-index:1000;top:auto;left:12px;right:12px;bottom:12px;max-height:60vh;overflow:auto;padding:8px;box-shadow:0 8px 40px #00000040,inset 0 0 0 .5px var(--dsw-alias-border-l2)}
|
|
59
|
+
.ua-menu button{min-height:44px;font-size:15px}
|
|
60
|
+
.ua-menu input{min-height:44px}
|
|
61
|
+
}
|
|
80
62
|
`
|
|
81
63
|
|
|
82
64
|
const ICONS = {
|
|
@@ -89,10 +71,6 @@ const ICONS = {
|
|
|
89
71
|
unhandled: 'M8 3.5v5.5M8 12v.5',
|
|
90
72
|
}
|
|
91
73
|
|
|
92
|
-
function fill(text, params) {
|
|
93
|
-
return String(text).replace(/\{(\w+)\}/g, (match, key) => (key in params ? String(params[key]) : match))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
74
|
/** The next 09:00 after now, as an ISO string. */
|
|
97
75
|
function tomorrowMorning(now = new Date()) {
|
|
98
76
|
const date = new Date(now)
|
|
@@ -117,14 +95,12 @@ function chatText({ prompt = '', title, lines = [], context }) {
|
|
|
117
95
|
* @param {object} options
|
|
118
96
|
* @param {object} options.React - the page's React
|
|
119
97
|
* @param {object} options.ctx - the plugin's client context (ctx.get reaches the Web UI's services)
|
|
120
|
-
* @param {string}
|
|
98
|
+
* @param {(key: string, params?: object) => string} options.t - the words in the person's language, one of KEYS
|
|
121
99
|
* @param {(action: object, extra: object) => Promise<unknown>} [options.press] - the server call for done, snooze and event
|
|
122
100
|
*/
|
|
123
|
-
function createActions({ React, ctx,
|
|
101
|
+
function createActions({ React, ctx, t, press }) {
|
|
124
102
|
const h = React.createElement
|
|
125
103
|
const { useState, useEffect, useRef } = React
|
|
126
|
-
const words = WORDS[String(locale).toLowerCase().startsWith('zh') ? 'zh' : 'en']
|
|
127
|
-
const t = key => words[key] ?? WORDS.en[key] ?? key
|
|
128
104
|
|
|
129
105
|
if (typeof document !== 'undefined' && !document.getElementById('dsh-actions-ui-style')) {
|
|
130
106
|
const style = document.createElement('style')
|
|
@@ -197,7 +173,7 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
197
173
|
const [menu, setMenu] = useState(false)
|
|
198
174
|
useEffect(() => { if (state) setLocal(null) }, [state])
|
|
199
175
|
const shown = local ?? state
|
|
200
|
-
const label = action.label ?? t(action.kind
|
|
176
|
+
const label = action.label ?? t(action.kind)
|
|
201
177
|
const title = shown === 'sending' ? t('sending') : shown === 'pending' ? t('pending') : shown === 'done' ? t('handled') : shown === 'unhandled' ? t('unhandled') : error ?? label
|
|
202
178
|
const icon = shown === 'done' ? 'done' : shown === 'unhandled' ? 'unhandled' : action.kind
|
|
203
179
|
const className = `ua-btn${compact ? ' ua-icon' : ''}`
|
|
@@ -222,7 +198,7 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
222
198
|
}
|
|
223
199
|
} catch (reason) {
|
|
224
200
|
setLocal(null)
|
|
225
|
-
setError(
|
|
201
|
+
setError(t('failed', { message: reason?.message ?? String(reason) }))
|
|
226
202
|
}
|
|
227
203
|
}
|
|
228
204
|
const onClick = () => {
|
|
@@ -254,6 +230,5 @@ function createActions({ React, ctx, locale = 'en', press }) {
|
|
|
254
230
|
return { ActionBar, ActionButton, Icon, startChat, chatText, t }
|
|
255
231
|
}
|
|
256
232
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
233
|
+
window.__ModuleLoader__.load({ id: OWNER, chunk: 'client.actions.js', factory: () => ({ createActions, chatText, KEYS }) })
|
|
234
|
+
})()
|