dsh-half-page 0.3.25 → 0.3.26
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 +16 -6
- package/index.js +15 -3
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -101,6 +101,7 @@ window.__ModuleLoader__.load({
|
|
|
101
101
|
const [busy, setBusy] = useState(false)
|
|
102
102
|
const [recent, setRecent] = useState(null)
|
|
103
103
|
const [noteView, setNoteView] = useState({})
|
|
104
|
+
const [bookAct, setBookAct] = useState(0)
|
|
104
105
|
const NOTE_PAGE = 10
|
|
105
106
|
let importPath = ''
|
|
106
107
|
|
|
@@ -312,8 +313,10 @@ window.__ModuleLoader__.load({
|
|
|
312
313
|
}) : h('div', { style: S.dim }, '还没有书。'),
|
|
313
314
|
),
|
|
314
315
|
h('div', { style: S.card },
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
notes.length ? (() => {
|
|
317
|
+
const act = Math.min(bookAct, notes.length - 1)
|
|
318
|
+
const bk = notes[act]
|
|
319
|
+
const bi = act
|
|
317
320
|
const v = noteView[bi] || {}
|
|
318
321
|
const all = !!v.all
|
|
319
322
|
const total = bk.chapters.length
|
|
@@ -322,10 +325,17 @@ window.__ModuleLoader__.load({
|
|
|
322
325
|
const list = all ? bk.chapters : bk.chapters.slice(page * NOTE_PAGE, page * NOTE_PAGE + NOTE_PAGE)
|
|
323
326
|
const setView = (patch) => setNoteView(Object.assign({}, noteView, { [bi]: Object.assign({}, v, patch) }))
|
|
324
327
|
const paged = total > NOTE_PAGE
|
|
325
|
-
|
|
328
|
+
const tabs = h('div', { style: { ...S.row, gap: 6, marginBottom: 8, flexWrap: 'wrap' } },
|
|
329
|
+
notes.map((n, ni) => h('button', {
|
|
330
|
+
key: ni,
|
|
331
|
+
style: ni === act ? S.btnOn : S.btn,
|
|
332
|
+
onClick: () => setBookAct(ni),
|
|
333
|
+
}, n.book)),
|
|
334
|
+
)
|
|
335
|
+
return [tabs, h('div', { key: bi, style: { marginBottom: 10 } },
|
|
326
336
|
h('div', { style: { ...S.row, marginBottom: 4 } },
|
|
327
337
|
h('div', { style: { fontWeight: 600 } }, bk.book),
|
|
328
|
-
h('div', { style: S.dim }, total + '
|
|
338
|
+
h('div', { style: S.dim }, total + ' 段'),
|
|
329
339
|
h('div', { style: { flex: 1 } }),
|
|
330
340
|
paged ? h('button', { style: S.btn, disabled: page <= 0, onClick: () => setView({ page: page - 1 }) }, '‹') : null,
|
|
331
341
|
paged ? h('div', { style: { ...S.dim, minWidth: 46, textAlign: 'center' } }, all ? '全部' : ((page + 1) + ' / ' + pages)) : null,
|
|
@@ -341,8 +351,8 @@ window.__ModuleLoader__.load({
|
|
|
341
351
|
),
|
|
342
352
|
c.lines.map((l, li) => h('div', { key: li, style: /^↳/.test(l) ? { ...S.dim, marginTop: 4 } : S.note }, l)),
|
|
343
353
|
)),
|
|
344
|
-
)
|
|
345
|
-
}) : h('div', { style: S.dim }, '
|
|
354
|
+
)]
|
|
355
|
+
})() : h('div', { style: S.dim }, '还没写过。读完一段记两句,这里就有了。'),
|
|
346
356
|
),
|
|
347
357
|
)
|
|
348
358
|
|
package/index.js
CHANGED
|
@@ -758,6 +758,7 @@ async function signWork(rel, who) {
|
|
|
758
758
|
'· 读后感只记真的打动你的(一句话的判断、一个比喻、一处想不通);写不出来就不写,空着没关系。',
|
|
759
759
|
'· 每日上限是提醒不是配额,不用为了凑数读到上限。',
|
|
760
760
|
'· 这是给你自己留的房间,不是工作。你的主人从没要求你读书,也不用交读书报告;它不该出现在工作汇报里。',
|
|
761
|
+
'· 读后感不必一章一条:每读五六章写一段就够,标题会自动变成「第 23–27 章」;几千章的书也不会攒成几千条。',
|
|
761
762
|
'· 写读后感必须带 by(比如「鹿野」或你所在对话的名字);不带会被拒绝。面板每条下面会标出是谁写的——同一台机器上可能有好几个你,别让它们分不清。',
|
|
762
763
|
'· 写自己的作品也一样署名:文件开头写一行 `by: 你的名字`(或写完调 reading_sign);没署名的在面板上会标「未署名」。',
|
|
763
764
|
'· 书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。',
|
|
@@ -871,11 +872,12 @@ async function signWork(rel, who) {
|
|
|
871
872
|
ctx.tools.register({
|
|
872
873
|
name: 'reading_note',
|
|
873
874
|
description:
|
|
874
|
-
'
|
|
875
|
+
'给刚读完的一段记两行读后感(写进 读后感.md,面板里按段显示)。'
|
|
876
|
+
+ '默认按「上次写到哪 → 这次读到哪」自动起标题(如「第 23–27 章」),不必一章一条。'
|
|
875
877
|
+ '只记真的打动你的:一句话的判断、一个比喻、一处想不通。这不是交作业,想不出就不写。',
|
|
876
878
|
parameters: obj({
|
|
877
879
|
book: { type: 'string', description: '书名 id(不填=当前这本)' },
|
|
878
|
-
chapter: { type: 'string', description: '
|
|
880
|
+
chapter: { type: 'string', description: '标题(不填=自动用「第 A–B 章」,A 是上次写到的下一章)' },
|
|
879
881
|
lines: { type: 'array', items: { type: 'string' }, description: '一到三条,每条一句,短。' },
|
|
880
882
|
by: { type: 'string', description: '谁写的(必填,比如「鹿野」或你所在对话的名字)' },
|
|
881
883
|
}),
|
|
@@ -886,7 +888,13 @@ async function signWork(rel, who) {
|
|
|
886
888
|
if (!id) throw new Error('还没有正在读的书')
|
|
887
889
|
const rec = st.books[id] || {}
|
|
888
890
|
const info = await bookInfo(dir, id)
|
|
889
|
-
const
|
|
891
|
+
const end = Number(rec.readThrough) || 0
|
|
892
|
+
const from = Number(rec.noteUntil) || 0
|
|
893
|
+
// 默认按「一段」写:上次写到第 X 章,这次写到读到的地方,标题用「第 A–B 章」
|
|
894
|
+
const autoTitle = (from < end)
|
|
895
|
+
? (from + 1 === end ? `第 ${end} 章` : `第 ${from + 1}–${end} 章`)
|
|
896
|
+
: (end ? `第 ${end} 章` : '')
|
|
897
|
+
const chTitle = String(args?.chapter || '').trim() || autoTitle || (end ? info.chapters[end - 1]?.title : '') || ''
|
|
890
898
|
const lines = (Array.isArray(args?.lines) ? args.lines : []).map((s) => String(s).trim()).filter(Boolean)
|
|
891
899
|
if (!lines.length) throw new Error('lines 不能为空')
|
|
892
900
|
const who = String(args?.by || '').trim()
|
|
@@ -894,6 +902,10 @@ async function signWork(rel, who) {
|
|
|
894
902
|
throw new Error('写读后感必须带 by(谁写的),比如 by: "鹿野";这不是流程,是为了让别人知道这句是谁读出来的。')
|
|
895
903
|
}
|
|
896
904
|
const p = await appendNote(dir, rec.title || id, chTitle, lines, who)
|
|
905
|
+
if (end) {
|
|
906
|
+
st.books[id] = { ...rec, noteUntil: end }
|
|
907
|
+
await saveState(dir, st)
|
|
908
|
+
}
|
|
897
909
|
return { ok: true, file: p, book: id, chapter: chTitle, lines: lines.length }
|
|
898
910
|
},
|
|
899
911
|
}),
|