dsh-onesheet 0.3.0 → 0.3.2
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 +8 -0
- package/client.js +33 -14
- package/index.js +22 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,14 @@ dsh plugin add "link:/path/to/onesheet"
|
|
|
38
38
|
|
|
39
39
|
调用 `show_figure(scene)`。`say` 是这一页唯一那句话;`items` 里的元素画在 760 宽的坐标系里。
|
|
40
40
|
|
|
41
|
+
## 图卡模式是"每轮都在"的
|
|
42
|
+
|
|
43
|
+
开关打开后,宿主在**每次装配 system prompt 时**都会把那段要求放进去(动态 section + 装配末尾兜底,见 `index.js` 的 `ensureModeSection`)。之前的 0.3.x 只挂了一个静态 section,遇到把这个 preset 用 "complete 段" 整体替换时那段会消失——0.3.2 起不会了。
|
|
44
|
+
|
|
45
|
+
## 收起一张卡
|
|
46
|
+
|
|
47
|
+
每张卡标题行右侧有「收起 / 展开」。收起的卡只剩一行标题,长会话里可以把自己不用的卡折起来,翻页和内容都还在,点「展开」原样回来。
|
|
48
|
+
|
|
41
49
|
## 两种画法
|
|
42
50
|
|
|
43
51
|
**A. 元素式**(`items`)
|
package/client.js
CHANGED
|
@@ -94,6 +94,10 @@ window.__ModuleLoader__.load({
|
|
|
94
94
|
.fk-head{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
|
|
95
95
|
.fk-title{font-size:15px;font-weight:700;color:var(--dsw-alias-label-primary);line-height:1.4}
|
|
96
96
|
.fk-sub{font-size:12.5px;color:var(--dsw-alias-label-secondary)}
|
|
97
|
+
.fk-fold{margin-left:auto;padding:2px 9px;border-radius:99px;border:1px solid var(--dsw-alias-border-l1);background:transparent;color:var(--dsw-alias-label-secondary);font:11px/1.5 system-ui;cursor:pointer;opacity:.75}
|
|
98
|
+
.fk-fold:hover{opacity:1;border-color:#f5c74a;color:var(--dsw-alias-label-primary)}
|
|
99
|
+
.fk-collapsed{padding-top:14px!important;padding-bottom:14px!important}
|
|
100
|
+
.fk-collapsed .fk-stage,.fk-collapsed .fk-say,.fk-collapsed .fk-foot,.fk-collapsed .fk-hint,.fk-collapsed .fk-map-row{display:none!important}
|
|
97
101
|
.fk-stage{position:relative;width:100%;margin-top:12px}
|
|
98
102
|
.fk-item{position:absolute;box-sizing:border-box;animation:fk-in .34s ease-out both}
|
|
99
103
|
.fk-box{border:0 solid var(--dsw-alias-border-l2);border-radius:12px;background:var(--dsw-alias-bg-layer-2);display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:0 6px;overflow:visible}
|
|
@@ -574,21 +578,23 @@ window.__ModuleLoader__.load({
|
|
|
574
578
|
pill.textContent = on ? '图卡 · 开' : '图卡 · 关'
|
|
575
579
|
|
|
576
580
|
pill.classList.toggle('fk-mode-on', on)
|
|
577
|
-
//
|
|
581
|
+
// 和宿主对一次状态(启动时 + 每 15 秒):别让本地缓存的标签和真实状态漂移
|
|
582
|
+
const syncStatus = async () => {
|
|
583
|
+
try {
|
|
584
|
+
const r = await fetch('/api/onesheet/cardmode', {
|
|
585
|
+
method: 'POST',
|
|
586
|
+
headers: { 'content-type': 'application/json' },
|
|
587
|
+
body: JSON.stringify({ action: 'status' }),
|
|
588
|
+
credentials: 'same-origin',
|
|
589
|
+
})
|
|
590
|
+
const payload = await r.json()
|
|
591
|
+
if (payload && payload.ok) setPillUi(payload.on ? '1' : '0')
|
|
592
|
+
} catch {}
|
|
593
|
+
}
|
|
578
594
|
if (!window.__fkModeSynced) {
|
|
579
595
|
window.__fkModeSynced = true
|
|
580
|
-
void (
|
|
581
|
-
|
|
582
|
-
const r = await fetch('/api/onesheet/cardmode', {
|
|
583
|
-
method: 'POST',
|
|
584
|
-
headers: { 'content-type': 'application/json' },
|
|
585
|
-
body: JSON.stringify({ action: 'status' }),
|
|
586
|
-
credentials: 'same-origin',
|
|
587
|
-
})
|
|
588
|
-
const payload = await r.json()
|
|
589
|
-
if (payload && payload.ok) setPillUi(payload.on ? '1' : '0')
|
|
590
|
-
} catch {}
|
|
591
|
-
})()
|
|
596
|
+
void syncStatus()
|
|
597
|
+
window.setInterval(() => { void syncStatus() }, 15000)
|
|
592
598
|
}
|
|
593
599
|
}
|
|
594
600
|
|
|
@@ -752,6 +758,7 @@ window.__ModuleLoader__.load({
|
|
|
752
758
|
// 引用兜底:插入失败时,在卡底显示一段已被选中的文字,Ctrl+C 就能拿走
|
|
753
759
|
const [quote, setQuote] = useState('')
|
|
754
760
|
const quoteRef = useRef(null)
|
|
761
|
+
const [collapsed, setCollapsed] = useState(false)
|
|
755
762
|
useEffect(() => {
|
|
756
763
|
try { if (typeof window !== 'undefined' && window.__fkMapTick) window.__fkMapTick() } catch {}
|
|
757
764
|
}, [])
|
|
@@ -973,7 +980,7 @@ window.__ModuleLoader__.load({
|
|
|
973
980
|
return h(
|
|
974
981
|
'div',
|
|
975
982
|
{
|
|
976
|
-
className: svgMode ? 'fk-card fk-doc' : 'fk-card',
|
|
983
|
+
className: (svgMode ? 'fk-card fk-doc' : 'fk-card') + (collapsed ? ' fk-collapsed' : ''),
|
|
977
984
|
tabIndex: 0,
|
|
978
985
|
style: {
|
|
979
986
|
padding: `${px(26)} ${px(26)} ${px(18)}`,
|
|
@@ -989,6 +996,18 @@ window.__ModuleLoader__.load({
|
|
|
989
996
|
{ className: 'fk-head', style: { gap: px(10) } },
|
|
990
997
|
h('div', { className: 'fk-title', style: { fontSize: px(21) } }, scene.title),
|
|
991
998
|
scene.sub ? h('div', { className: 'fk-sub', style: { fontSize: px(13) } }, scene.sub) : null,
|
|
999
|
+
h(
|
|
1000
|
+
'button',
|
|
1001
|
+
{
|
|
1002
|
+
className: 'fk-fold',
|
|
1003
|
+
title: collapsed ? '展开这张' : '收起这张(只留标题)',
|
|
1004
|
+
onClick: (event) => {
|
|
1005
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
1006
|
+
setCollapsed((value) => !value)
|
|
1007
|
+
},
|
|
1008
|
+
},
|
|
1009
|
+
collapsed ? '展开' : '收起',
|
|
1010
|
+
),
|
|
992
1011
|
),
|
|
993
1012
|
h(
|
|
994
1013
|
'div',
|
package/index.js
CHANGED
|
@@ -148,20 +148,30 @@ function figureId() {
|
|
|
148
148
|
return `f${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
function ensureModeSection(ctx) {
|
|
152
|
+
try {
|
|
153
|
+
ctx.systemPrompt.section({
|
|
154
|
+
name: 'onesheet-card-mode',
|
|
155
|
+
order: 900,
|
|
156
|
+
text: () => (readMode() ? MODE_TEXT : ''),
|
|
157
|
+
})
|
|
158
|
+
} catch {}
|
|
159
|
+
try {
|
|
160
|
+
ctx.on('system-prompt/assemble', async (assembly, _context, next) => {
|
|
161
|
+
const out = await next()
|
|
162
|
+
try {
|
|
163
|
+
if (!readMode()) return out
|
|
164
|
+
const sections = Array.isArray(out.sections) ? out.sections : []
|
|
165
|
+
if (sections.some((entry) => entry && entry.name === 'onesheet-card-mode')) return out
|
|
166
|
+
return { ...out, sections: [...sections, { name: 'onesheet-card-mode', text: MODE_TEXT }] }
|
|
167
|
+
} catch { return out }
|
|
168
|
+
})
|
|
169
|
+
} catch {}
|
|
170
|
+
}
|
|
171
|
+
|
|
151
172
|
export function apply(ctx) {
|
|
173
|
+
ensureModeSection(ctx)
|
|
152
174
|
// 图卡模式:状态存在 ~/.dsh/onesheet/card-mode.json(旧版本写在插件目录,首次读取时迁移),开时往系统提示里加一段(不改用户的输入)
|
|
153
|
-
let sectionDispose = null
|
|
154
|
-
const syncSection = (on) => {
|
|
155
|
-
if (sectionDispose) { try { sectionDispose() } catch {} ; sectionDispose = null }
|
|
156
|
-
if (!on) return
|
|
157
|
-
try {
|
|
158
|
-
sectionDispose = ctx.systemPrompt.section({ name: 'onesheet-card-mode', text: MODE_TEXT, order: 900 })
|
|
159
|
-
} catch {
|
|
160
|
-
sectionDispose = null
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
syncSection(readMode())
|
|
164
|
-
|
|
165
175
|
ctx.effect(() =>
|
|
166
176
|
ctx.tools.register({
|
|
167
177
|
name: 'card_mode',
|
|
@@ -196,7 +206,6 @@ export function apply(ctx) {
|
|
|
196
206
|
}
|
|
197
207
|
const on = action === 'on'
|
|
198
208
|
const ok = writeMode(on)
|
|
199
|
-
syncSection(on)
|
|
200
209
|
return {
|
|
201
210
|
ok,
|
|
202
211
|
on,
|
|
@@ -224,7 +233,6 @@ export function apply(ctx) {
|
|
|
224
233
|
const off = ['off', '关', '0', 'false'].includes(arg)
|
|
225
234
|
if (!on && !off) return { kind: 'error', text: '用法:/cardmode on | off | status' }
|
|
226
235
|
const ok = writeMode(on)
|
|
227
|
-
syncSection(on)
|
|
228
236
|
return {
|
|
229
237
|
kind: 'success',
|
|
230
238
|
text: on
|
|
@@ -350,7 +358,6 @@ export function apply(ctx) {
|
|
|
350
358
|
else if (action === 'toggle') on = !on
|
|
351
359
|
if (mutating) {
|
|
352
360
|
writeMode(on)
|
|
353
|
-
syncSection(on)
|
|
354
361
|
}
|
|
355
362
|
return new Response(JSON.stringify({ ok: true, on, message: '图卡模式:' + (on ? '开' : '关') }), {
|
|
356
363
|
status: 200,
|