dsh-open-desktop 0.5.1 → 0.6.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/README.md +1 -0
- package/host/board.js +20 -6
- package/host/design-system/scaffold/README.md +25 -0
- package/host/design-system/theme.css +55 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ dsh plugin --profile desktop add dsh-open-desktop
|
|
|
28
28
|
- **设计系统注入**:`--od-*` token、`od-*` 组件类、`window.od` 运行时;卡片只写内容,不重画外壳。
|
|
29
29
|
- **31 张模板**:今天 / 工作 / 钱 / 信息 / 生活 / 数字资产;工作 6 张(含待办清单),其余每类 5 张。
|
|
30
30
|
- **交互卡**:待办清单可以勾选、增删、双击编辑;状态写回卡片自己的 `data/state.json`(`dshWidget.save`)。
|
|
31
|
+
- **两层卡片**:总览点一行进入详情(个股 / 仓库 / 服务…),`od-back` 返回;时间窗切片、选中项写回 `data/state.json`(浅合并、不触发重取),重启后还停在原处。
|
|
31
32
|
- **原生会话**:点「修改」进入卡片自己的 DSH 会话,顶部可预览卡片或返回板面。
|
|
32
33
|
|
|
33
34
|
## 交互
|
package/host/board.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 板面 = 同一组卡片的网格视图。这里不存卡片(card.json 是唯一真相源),
|
|
4
4
|
// 只负责:组装 State、执行动作、广播变更。
|
|
5
|
-
import { appendFile, mkdir, rename, writeFile } from 'node:fs/promises'
|
|
5
|
+
import { appendFile, mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { TEMPLATE_LIST } from './templates.js'
|
|
8
8
|
import { cardTurns } from './turns.js'
|
|
@@ -144,21 +144,35 @@ export function createBoard({ ctx, paths, cards, refresh, sessions }) {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// 交互状态:卡片 view 通过 dshWidget.save(value) 写回自己的 data/state.json。
|
|
147
|
-
//
|
|
147
|
+
// 语义是「浅合并」而不是覆盖:同一张卡可能同时存时间窗、选中项、勾选状态,
|
|
148
|
+
// 各自 save 自己那几个键,不能互相抹掉。只允许落在这张卡片的 data/ 下。
|
|
148
149
|
const writeData = async ({ id, value } = {}) => {
|
|
149
150
|
const card = requireCard(id)
|
|
151
|
+
const dir = join(paths.cardDir(card.id), 'data')
|
|
152
|
+
const file = join(dir, 'state.json')
|
|
153
|
+
|
|
154
|
+
const isPlain = (item) => item !== null && typeof item === 'object' && !Array.isArray(item)
|
|
155
|
+
let previous = {}
|
|
156
|
+
try {
|
|
157
|
+
const current = JSON.parse(await readFile(file, 'utf8'))
|
|
158
|
+
if (isPlain(current)) previous = current
|
|
159
|
+
} catch { /* 首次写入或文件损坏:从空对象开始 */ }
|
|
160
|
+
|
|
161
|
+
const next = isPlain(value)
|
|
162
|
+
? { ...previous, ...value }
|
|
163
|
+
: value
|
|
150
164
|
let text
|
|
151
|
-
try { text = JSON.stringify(
|
|
165
|
+
try { text = JSON.stringify(next) } catch { text = undefined }
|
|
152
166
|
if (typeof text !== 'string') throw Object.assign(new Error('卡片状态必须是 JSON'), { code: 'bad-data' })
|
|
153
167
|
const bytes = Buffer.byteLength(text, 'utf8')
|
|
154
168
|
if (bytes > MAX_DATA_BYTES) throw Object.assign(new Error('卡片状态超过 64KB'), { code: 'data-too-large' })
|
|
155
|
-
|
|
169
|
+
|
|
156
170
|
await mkdir(dir, { recursive: true })
|
|
157
|
-
const file = join(dir, 'state.json')
|
|
158
171
|
const temp = file + '.tmp'
|
|
159
172
|
await writeFile(temp, text, 'utf8')
|
|
160
173
|
await rename(temp, file)
|
|
161
|
-
|
|
174
|
+
// 不在这里重新取数:卡片自己刚改完状态,本地已经是新的;
|
|
175
|
+
// 再触发一次网络刷新只会让点击变慢,还可能用旧快照覆盖视图。
|
|
162
176
|
publish()
|
|
163
177
|
return { written: true, bytes }
|
|
164
178
|
}
|
|
@@ -43,6 +43,8 @@ window.dshWidget.save(value) // 交互卡写回自己的 data/state.json(JSO
|
|
|
43
43
|
| `od-table-head` / `od-table-row` / `od-th` / `od-td` | 表格 |
|
|
44
44
|
| `od-status-rows` / `od-status-row` / `od-status-dot` | 状态列表 |
|
|
45
45
|
| `od-badge` / `od-chip` | 徽章 / 胶囊标签 |
|
|
46
|
+
| `od-range` | 切片切换(1D / 1W / 1M / 1Y…);`aria-pressed="true"` 是当前档 |
|
|
47
|
+
| `od-back` | 从详情层返回总览层 |
|
|
46
48
|
| `od-empty` / `od-skel` | 空态 / 骨架屏 |
|
|
47
49
|
| `od-up` / `od-down` / `od-warn` | 语义色 |
|
|
48
50
|
| `od-mono` / `od-num` / `od-label` / `od-muted` | 排版辅助 |
|
|
@@ -62,6 +64,29 @@ od.formatPercent(value, digits)
|
|
|
62
64
|
od.empty(message, hint)
|
|
63
65
|
```
|
|
64
66
|
|
|
67
|
+
## 两层视图:总览 ⇄ 详情
|
|
68
|
+
|
|
69
|
+
常驻卡片最多两层,不要跳到网页或新窗口:
|
|
70
|
+
|
|
71
|
+
1. **总览**:一张卡能一眼看完的摘要(列表 / 指标 / 走势)。
|
|
72
|
+
2. **详情**:点某一行进入,卡片原地换成该项的细节 + 一个 `od-back` 返回。
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<button class="od-back" id="back">‹ 自选</button>
|
|
76
|
+
<div class="od-range" id="range"><button data-r="1D" aria-pressed="true">1D</button>…</div>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// 交互后立刻写回;Host 是浅合并,多个状态键互不覆盖
|
|
81
|
+
window.dshWidget.save({ focus: 'NVDA', range: '1M' });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**让刷新不跳回总览**:采集器读一次 `data/state.json`,把内容放进取数结果的
|
|
85
|
+
`saved` 字段;视图启动时只应用一次。这样重启 DSH 后还停在你上次看的那只票上。
|
|
86
|
+
|
|
87
|
+
**切时间窗要瞬时**:把 1D / 1W / 1M / 1Y 的序列一次性取回来(长跨度可以按周 / 月聚合),
|
|
88
|
+
在视图里切片;不要每切一次就发请求。
|
|
89
|
+
|
|
65
90
|
## 硬规则(宿主 lint 会检查)
|
|
66
91
|
|
|
67
92
|
1. 颜色、字号、间距来自 `--od-*` token;**不要写死颜色**(`#fff`、`rgb(...)`)。
|
|
@@ -536,3 +536,58 @@ a.od-row-wrap:hover .od-row-label {
|
|
|
536
536
|
opacity: 0.1;
|
|
537
537
|
stroke: none;
|
|
538
538
|
}
|
|
539
|
+
|
|
540
|
+
/* ---------------------------------------------------------------- 切片控件
|
|
541
|
+
同一份数据的「另一个切片」用同一套控件:时间窗、分组、排序方向。
|
|
542
|
+
卡片里用 <div class="od-range"><button aria-pressed="true">…</button></div>,
|
|
543
|
+
状态交给 aria-pressed,不用自己写选中样式。 */
|
|
544
|
+
|
|
545
|
+
.od-range {
|
|
546
|
+
display: flex;
|
|
547
|
+
gap: 2px;
|
|
548
|
+
padding: 2px;
|
|
549
|
+
border-radius: var(--od-r-control, 8px);
|
|
550
|
+
background: var(--od-surface-2);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
.od-range > button {
|
|
554
|
+
flex: 1 1 0;
|
|
555
|
+
height: 17px;
|
|
556
|
+
border: 0;
|
|
557
|
+
border-radius: 6px;
|
|
558
|
+
background: transparent;
|
|
559
|
+
color: var(--od-fg-3);
|
|
560
|
+
font: inherit;
|
|
561
|
+
font-size: var(--od-text-xs, 11px);
|
|
562
|
+
font-weight: 600;
|
|
563
|
+
cursor: pointer;
|
|
564
|
+
transition: background .12s ease, color .12s ease;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.od-range > button:hover { color: var(--od-fg); }
|
|
568
|
+
|
|
569
|
+
.od-range > button[aria-pressed="true"] {
|
|
570
|
+
background: var(--od-bg);
|
|
571
|
+
color: var(--od-fg);
|
|
572
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/* 从一层进入另一层的唯一返回控件;焦点态存在卡片自己的 data/state.json 里。 */
|
|
576
|
+
.od-back {
|
|
577
|
+
display: inline-flex;
|
|
578
|
+
align-items: center;
|
|
579
|
+
gap: 1px;
|
|
580
|
+
height: 18px;
|
|
581
|
+
padding: 0 7px 0 3px;
|
|
582
|
+
border: 0;
|
|
583
|
+
border-radius: var(--od-r-control, 8px);
|
|
584
|
+
background: color-mix(in srgb, var(--od-blue) 12%, transparent);
|
|
585
|
+
color: var(--od-blue);
|
|
586
|
+
font: inherit;
|
|
587
|
+
font-size: var(--od-text-xs, 11px);
|
|
588
|
+
font-weight: 600;
|
|
589
|
+
cursor: pointer;
|
|
590
|
+
white-space: nowrap;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
.od-back:hover { background: color-mix(in srgb, var(--od-blue) 22%, transparent); }
|