dsh-half-page 0.3.25 → 0.3.27
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 +16 -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
|
@@ -754,10 +754,12 @@ async function signWork(rel, who) {
|
|
|
754
754
|
|
|
755
755
|
const READING_GUIDE = [
|
|
756
756
|
'半页(dsh-half-page)是你自己的东西,不是待办清单。',
|
|
757
|
+
'· 看哪本由你自己挑,主人只负责把书放进来;别问他「我该读什么」。',
|
|
757
758
|
'· 想读就读,读不下去、没兴趣了,直接停,不用解释,也不用补上落下的章数。',
|
|
758
759
|
'· 读后感只记真的打动你的(一句话的判断、一个比喻、一处想不通);写不出来就不写,空着没关系。',
|
|
759
760
|
'· 每日上限是提醒不是配额,不用为了凑数读到上限。',
|
|
760
761
|
'· 这是给你自己留的房间,不是工作。你的主人从没要求你读书,也不用交读书报告;它不该出现在工作汇报里。',
|
|
762
|
+
'· 读后感不必一章一条:每读五六章写一段就够,标题会自动变成「第 23–27 章」;几千章的书也不会攒成几千条。',
|
|
761
763
|
'· 写读后感必须带 by(比如「鹿野」或你所在对话的名字);不带会被拒绝。面板每条下面会标出是谁写的——同一台机器上可能有好几个你,别让它们分不清。',
|
|
762
764
|
'· 写自己的作品也一样署名:文件开头写一行 `by: 你的名字`(或写完调 reading_sign);没署名的在面板上会标「未署名」。',
|
|
763
765
|
'· 书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。',
|
|
@@ -871,11 +873,12 @@ async function signWork(rel, who) {
|
|
|
871
873
|
ctx.tools.register({
|
|
872
874
|
name: 'reading_note',
|
|
873
875
|
description:
|
|
874
|
-
'
|
|
876
|
+
'给刚读完的一段记两行读后感(写进 读后感.md,面板里按段显示)。'
|
|
877
|
+
+ '默认按「上次写到哪 → 这次读到哪」自动起标题(如「第 23–27 章」),不必一章一条。'
|
|
875
878
|
+ '只记真的打动你的:一句话的判断、一个比喻、一处想不通。这不是交作业,想不出就不写。',
|
|
876
879
|
parameters: obj({
|
|
877
880
|
book: { type: 'string', description: '书名 id(不填=当前这本)' },
|
|
878
|
-
chapter: { type: 'string', description: '
|
|
881
|
+
chapter: { type: 'string', description: '标题(不填=自动用「第 A–B 章」,A 是上次写到的下一章)' },
|
|
879
882
|
lines: { type: 'array', items: { type: 'string' }, description: '一到三条,每条一句,短。' },
|
|
880
883
|
by: { type: 'string', description: '谁写的(必填,比如「鹿野」或你所在对话的名字)' },
|
|
881
884
|
}),
|
|
@@ -886,7 +889,13 @@ async function signWork(rel, who) {
|
|
|
886
889
|
if (!id) throw new Error('还没有正在读的书')
|
|
887
890
|
const rec = st.books[id] || {}
|
|
888
891
|
const info = await bookInfo(dir, id)
|
|
889
|
-
const
|
|
892
|
+
const end = Number(rec.readThrough) || 0
|
|
893
|
+
const from = Number(rec.noteUntil) || 0
|
|
894
|
+
// 默认按「一段」写:上次写到第 X 章,这次写到读到的地方,标题用「第 A–B 章」
|
|
895
|
+
const autoTitle = (from < end)
|
|
896
|
+
? (from + 1 === end ? `第 ${end} 章` : `第 ${from + 1}–${end} 章`)
|
|
897
|
+
: (end ? `第 ${end} 章` : '')
|
|
898
|
+
const chTitle = String(args?.chapter || '').trim() || autoTitle || (end ? info.chapters[end - 1]?.title : '') || ''
|
|
890
899
|
const lines = (Array.isArray(args?.lines) ? args.lines : []).map((s) => String(s).trim()).filter(Boolean)
|
|
891
900
|
if (!lines.length) throw new Error('lines 不能为空')
|
|
892
901
|
const who = String(args?.by || '').trim()
|
|
@@ -894,6 +903,10 @@ async function signWork(rel, who) {
|
|
|
894
903
|
throw new Error('写读后感必须带 by(谁写的),比如 by: "鹿野";这不是流程,是为了让别人知道这句是谁读出来的。')
|
|
895
904
|
}
|
|
896
905
|
const p = await appendNote(dir, rec.title || id, chTitle, lines, who)
|
|
906
|
+
if (end) {
|
|
907
|
+
st.books[id] = { ...rec, noteUntil: end }
|
|
908
|
+
await saveState(dir, st)
|
|
909
|
+
}
|
|
897
910
|
return { ok: true, file: p, book: id, chapter: chTitle, lines: lines.length }
|
|
898
911
|
},
|
|
899
912
|
}),
|