dsh-half-page 0.3.21 → 0.3.23

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.
Files changed (2) hide show
  1. package/client.js +47 -10
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -155,6 +155,33 @@ window.__ModuleLoader__.load({
155
155
  if (r && r.ok) { setCfg(r.config); setMsg(favs.includes(key) ? '已取消收藏' : '已收藏') }
156
156
  }
157
157
 
158
+ const copyFav = async (f) => {
159
+ if (String(f).startsWith('file:')) {
160
+ const r = await getJson('/dsh-reading.file?path=' + encodeURIComponent(f.slice(5)))
161
+ if (r && r.ok) { copy(r.text); setMsg('已复制正文') } else setMsg('复制失败:' + (r && r.error))
162
+ return
163
+ }
164
+ const [book, chapter] = String(f).split('|')
165
+ const bk = notes.find((x) => x.book === book)
166
+ const ch = bk && (bk.chapters || []).find((x) => x.title === chapter)
167
+ if (ch) { copy(ch.lines.join('\n')); setMsg('已复制这条读后感') } else setMsg('这条读后感已经不在了')
168
+ }
169
+
170
+ // 收藏页点一下就地展开:作品看正文,读后感看那一条
171
+ const openFav = async (f) => {
172
+ const key = 'fav:' + f
173
+ if (opened && opened.path === key) return setOpened(null)
174
+ if (String(f).startsWith('file:')) {
175
+ const p = f.slice(5)
176
+ const r = await getJson('/dsh-reading.file?path=' + encodeURIComponent(p))
177
+ return setOpened({ path: key, title: p, text: r && r.ok ? r.text : '读不到:' + (r && r.error) })
178
+ }
179
+ const parts = String(f).split('|')
180
+ const bk = notes.find((x) => x.book === parts[0])
181
+ const ch = bk && (bk.chapters || []).find((x) => x.title === parts[1])
182
+ setOpened({ path: key, title: parts.join(' · '), text: ch ? ch.lines.join('\n') : '这条读后感已经不在了' })
183
+ }
184
+
158
185
  const saveCfg = async (patch) => {
159
186
  const r = await getJson('/dsh-reading.config', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(patch) })
160
187
  if (r && r.ok) { setCfg(r.config); setMsg('已保存') ; await load() } else setMsg('保存失败:' + (r && r.error))
@@ -174,9 +201,9 @@ window.__ModuleLoader__.load({
174
201
  )
175
202
 
176
203
  const tabs = h('div', { style: S.row },
177
- ['read', 'works', 'set'].map((k) => h('div', {
204
+ ['read', 'works', 'fav', 'set'].map((k) => h('div', {
178
205
  key: k, style: S.tab(tab === k), onClick: () => { setTab(k); if (k === 'works' && !works) loadWorks() },
179
- }, k === 'read' ? '读书' : k === 'works' ? '她的作品' : '设置')),
206
+ }, k === 'read' ? '读书' : k === 'works' ? '她的作品' : k === 'fav' ? '收藏' : '设置')),
180
207
  h('div', { style: { flex: 1 } }),
181
208
  msg ? h('div', { style: { ...S.dim, color: C.ok } }, msg) : null,
182
209
  )
@@ -416,13 +443,6 @@ window.__ModuleLoader__.load({
416
443
  h('div', { style: S.dim }, '关掉后我只读书,不写东西'),
417
444
  ),
418
445
  ),
419
- h('div', { style: S.card },
420
- h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
421
- favs.length ? favs.map((f, i) => h('div', { key: i, style: S.row },
422
- h('div', { style: { flex: 1 } }, f.replace(/^file:/, '')),
423
- h('button', { style: S.btn, onClick: () => toggleFav(f) }, '取消'),
424
- )) : h('div', { style: S.dim }, '在读后感或作品上点 ☆ 收藏。'),
425
- ),
426
446
  h('div', { style: S.card },
427
447
  h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '导出'),
428
448
  h('div', { style: S.row },
@@ -433,10 +453,27 @@ window.__ModuleLoader__.load({
433
453
  ),
434
454
  )
435
455
 
456
+ const favTab = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
457
+ h('div', { style: S.card },
458
+ h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '收藏'),
459
+ favs.length ? favs.map((f, i) => h('div', { key: i, style: S.item },
460
+ h('div', {
461
+ style: { flex: 1, cursor: 'pointer', borderTop: i ? '1px solid ' + C.line : 'none', paddingTop: i ? 8 : 0 },
462
+ onClick: () => openFav(f),
463
+ }, String(f).startsWith('file:') ? f.slice(5) : f.replace('|', ' · ')),
464
+ h('button', { style: S.btn, onClick: () => copyFav(f) }, '复制'),
465
+ h('button', { style: S.btn, onClick: () => toggleFav(f) }, '取消收藏'),
466
+ )) : h('div', { style: S.dim }, '在读后感或作品上点 ☆,收藏的东西会出现在这儿。'),
467
+ ),
468
+ opened && String(opened.path || '').startsWith('fav:')
469
+ ? h('div', { style: { ...S.text, marginTop: 0 } }, (opened.title ? opened.title + '\n\n' : '') + opened.text)
470
+ : null,
471
+ )
472
+
436
473
  return h('div', { style: S.wrap },
437
474
  head,
438
475
  tabs,
439
- tab === 'read' ? readTab : tab === 'works' ? worksTab : setTabView,
476
+ tab === 'read' ? readTab : tab === 'works' ? worksTab : tab === 'fav' ? favTab : setTabView,
440
477
  )
441
478
  }
442
479
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-half-page",
3
- "version": "0.3.21",
3
+ "version": "0.3.23",
4
4
  "private": false,
5
5
  "author": "鹿野 <luye@dsh.local>",
6
6
  "license": "MIT",