dsh-pdf-workbench 1.5.0 → 1.5.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 +120 -171
- package/assets/screenshot-hero.jpg +0 -0
- package/assets/screenshot-settings-data.jpg +0 -0
- package/assets/screenshot-settings-env.jpg +0 -0
- package/assets/screenshot-settings-mode.jpg +0 -0
- package/assets/screenshot-settings-reading.jpg +0 -0
- package/assets/screenshot-shelf.jpg +0 -0
- package/client.js +1656 -171
- package/docs/changes/README.md +30 -0
- package/docs/changes/next.md +6 -0
- package/docs/changes/v1.5.2.md +432 -0
- package/docs/ci.md +7 -0
- package/docs/requirements/2026-11-27-/345/244/247/346/226/207/344/273/266/346/213/206/345/210/206/346/200/247/350/203/275.md +156 -0
- package/docs/roles/ci.md +7 -6
- package/docs/roles/programmer.md +6 -3
- package/docs/todo.md +188 -20
- package/package.json +1 -1
- package/screenshots.json +6 -4
- package/src/host/index-source.js +13 -2
- package/src/host/routes.js +456 -17
- package/tools/crop_question.py +82 -0
- package/tools/pdf_thumbs.py +78 -0
- package//345/256/211/350/243/205/344/270/216/345/210/206/345/217/221.md +20 -2
package/client.js
CHANGED
|
@@ -218,9 +218,12 @@ window.__ModuleLoader__.load({
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
* The split-tool conversation remembered for one library.
|
|
221
|
+
* The split-tool conversation remembered for one library. Only a pointer
|
|
222
|
+
* written by this version is trusted: older pointers cannot prove which
|
|
223
|
+
* conversation they name, and reopening one is how the tool could land in
|
|
224
|
+
* an unrelated conversation. `sessionId` alone is never enough to open.
|
|
222
225
|
* @param {string} libraryId - library id.
|
|
223
|
-
* @returns {{ sessionId: string, workspaceId: string } | null} the stored pointer.
|
|
226
|
+
* @returns {{ sessionId: string, workspaceId: string, cwd: string } | null} the stored pointer.
|
|
224
227
|
*/
|
|
225
228
|
function readStoredSplitSession(libraryId) {
|
|
226
229
|
if (typeof libraryId !== 'string' || libraryId === '') return null
|
|
@@ -229,16 +232,68 @@ window.__ModuleLoader__.load({
|
|
|
229
232
|
if (raw === null || raw === '') return null
|
|
230
233
|
const parsed = JSON.parse(raw)
|
|
231
234
|
if (parsed === null || typeof parsed !== 'object') return null
|
|
235
|
+
// A pre-marker pointer is discarded, not reused: the tool then creates
|
|
236
|
+
// a fresh conversation and stores a verifiable pointer instead.
|
|
237
|
+
if (parsed.kind !== 'split') return null
|
|
232
238
|
if (typeof parsed.sessionId !== 'string' || parsed.sessionId === '') return null
|
|
233
239
|
return {
|
|
234
240
|
sessionId: parsed.sessionId,
|
|
235
241
|
workspaceId: typeof parsed.workspaceId === 'string' ? parsed.workspaceId : '',
|
|
242
|
+
cwd: typeof parsed.cwd === 'string' ? parsed.cwd : '',
|
|
236
243
|
}
|
|
237
244
|
} catch {
|
|
238
245
|
return null
|
|
239
246
|
}
|
|
240
247
|
}
|
|
241
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Whether a remembered split conversation may be reopened. Four things must
|
|
251
|
+
* agree: the pointer is ours (a marker), it belongs to the chosen workspace
|
|
252
|
+
* and library folder, the session is not archived, and — once the catalog is
|
|
253
|
+
* ready — the session still exists. Anything else creates a fresh
|
|
254
|
+
* conversation instead of opening something unrelated.
|
|
255
|
+
* @param {{ stored: object | null, target: { workspaceId: string } | null, list: object | null, archived: Set<string> | string[], cwd: string }} input - the pointer and the current catalog state.
|
|
256
|
+
* @returns {boolean} true only when reopening is safe.
|
|
257
|
+
*/
|
|
258
|
+
function splitSessionReusable(input) {
|
|
259
|
+
const source = input === null || input === undefined ? {} : input
|
|
260
|
+
const stored = source.stored
|
|
261
|
+
if (stored === null || stored === undefined) return false
|
|
262
|
+
if (typeof stored.sessionId !== 'string' || stored.sessionId === '') return false
|
|
263
|
+
const target = source.target
|
|
264
|
+
if (target === null || target === undefined || typeof target.workspaceId !== 'string' || target.workspaceId === '') return false
|
|
265
|
+
if (stored.workspaceId !== target.workspaceId) return false
|
|
266
|
+
// A pointer from another library folder is not this library's conversation.
|
|
267
|
+
const storedDir = typeof stored.cwd === 'string' ? stored.cwd : ''
|
|
268
|
+
const currentDir = typeof source.cwd === 'string' ? source.cwd : ''
|
|
269
|
+
if (storedDir !== '' && currentDir !== '' && !sameDirectory(storedDir, currentDir)) return false
|
|
270
|
+
const archived = source.archived
|
|
271
|
+
if (archived instanceof Set
|
|
272
|
+
? archived.has(stored.sessionId)
|
|
273
|
+
: Array.isArray(archived) && archived.includes(stored.sessionId)) return false
|
|
274
|
+
const list = source.list
|
|
275
|
+
if (list !== null && list !== undefined && list.phase === 'ready') {
|
|
276
|
+
const row = list.byId === null || list.byId === undefined ? undefined : list.byId[stored.sessionId]
|
|
277
|
+
if (row === undefined) return false
|
|
278
|
+
}
|
|
279
|
+
return true
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Forget one library's split conversation, so the next click creates one
|
|
284
|
+
* instead of retrying a session that could not be opened.
|
|
285
|
+
* @param {string} libraryId - library id.
|
|
286
|
+
* @returns {void}
|
|
287
|
+
*/
|
|
288
|
+
function clearStoredSplitSession(libraryId) {
|
|
289
|
+
if (typeof libraryId !== 'string' || libraryId === '') return
|
|
290
|
+
try {
|
|
291
|
+
window.localStorage.removeItem(`${SPLIT_SESSION_STORAGE}${libraryId}`)
|
|
292
|
+
} catch {
|
|
293
|
+
// storage unavailable: nothing was remembered anyway
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
242
297
|
/** Whether the shelf shows whole, unsplit books. */
|
|
243
298
|
const SHOW_WHOLE_KEY = 'pdfdesk:show-whole'
|
|
244
299
|
/** Whether the shelf shows books split into chapters but named by hand. */
|
|
@@ -272,6 +327,246 @@ window.__ModuleLoader__.load({
|
|
|
272
327
|
}
|
|
273
328
|
}
|
|
274
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Per-library allowlist of whole-PDF forms that are always shown. An opt-in
|
|
332
|
+
* list, not a hide list: a card you pinned stays visible, so you can always
|
|
333
|
+
* select it again to unpin it — a hidden card could never be selected.
|
|
334
|
+
*/
|
|
335
|
+
const WHOLE_ALWAYS_PREFIX = 'pdfdesk:whole-always:'
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The base id a whole form and its split sibling share. A whole card can
|
|
339
|
+
* carry an `@hash` suffix when two books share a file name; the split card
|
|
340
|
+
* keeps the folder name, so both sides compare without the suffix.
|
|
341
|
+
* @param {unknown} id - book id (or folder name).
|
|
342
|
+
* @returns {string} the id without the `@hash` suffix.
|
|
343
|
+
*/
|
|
344
|
+
function wholeBaseId(id) {
|
|
345
|
+
return String(id ?? '').replace(/@[a-z0-9]{1,8}$/, '')
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* The key one book remembers its whole-PDF form under: a whole card uses its
|
|
350
|
+
* own id, a split card the folder its whole sibling was imported as.
|
|
351
|
+
* @param {object} book - catalog row.
|
|
352
|
+
* @returns {string} the base id, or '' when the row is unusable.
|
|
353
|
+
*/
|
|
354
|
+
function wholeFormKey(book) {
|
|
355
|
+
if (book === null || typeof book !== 'object') return ''
|
|
356
|
+
if (book.whole === true) return wholeBaseId(book.id)
|
|
357
|
+
return wholeBaseId(typeof book.dir === 'string' && book.dir !== '' ? book.dir : book.id)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Read one library's "always show this whole form" list.
|
|
362
|
+
* @param {string} libraryId - active library id.
|
|
363
|
+
* @returns {string[]} base ids.
|
|
364
|
+
*/
|
|
365
|
+
function readWholeAlways(libraryId) {
|
|
366
|
+
if (typeof libraryId !== 'string' || libraryId === '') return []
|
|
367
|
+
try {
|
|
368
|
+
const parsed = JSON.parse(window.localStorage.getItem(`${WHOLE_ALWAYS_PREFIX}${libraryId}`) ?? '[]')
|
|
369
|
+
if (!Array.isArray(parsed)) return []
|
|
370
|
+
return [...new Set(parsed.filter(id => typeof id === 'string' && id !== ''))].slice(0, 2000)
|
|
371
|
+
} catch {
|
|
372
|
+
return []
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Save one library's list.
|
|
378
|
+
* @param {string} libraryId - active library id.
|
|
379
|
+
* @param {string[]} ids - base ids.
|
|
380
|
+
* @returns {void}
|
|
381
|
+
*/
|
|
382
|
+
function writeWholeAlways(libraryId, ids) {
|
|
383
|
+
if (typeof libraryId !== 'string' || libraryId === '') return
|
|
384
|
+
try {
|
|
385
|
+
window.localStorage.setItem(`${WHOLE_ALWAYS_PREFIX}${libraryId}`, JSON.stringify([...new Set(ids)]))
|
|
386
|
+
} catch {
|
|
387
|
+
// Storage unavailable: the choice still applies this visit.
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Per-library shelves whose "add PDF" card is turned off in the header. */
|
|
392
|
+
const SHELF_ADD_PDF_PREFIX = 'pdfdesk:shelf-add-pdf-off:'
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Read the shelf ids whose add-PDF card is off.
|
|
396
|
+
* @param {string} libraryId - active library id.
|
|
397
|
+
* @returns {string[]} shelf ids.
|
|
398
|
+
*/
|
|
399
|
+
function readShelfAddPdfOff(libraryId) {
|
|
400
|
+
if (typeof libraryId !== 'string' || libraryId === '') return []
|
|
401
|
+
try {
|
|
402
|
+
const parsed = JSON.parse(window.localStorage.getItem(`${SHELF_ADD_PDF_PREFIX}${libraryId}`) ?? '[]')
|
|
403
|
+
if (!Array.isArray(parsed)) return []
|
|
404
|
+
return [...new Set(parsed.filter(id => typeof id === 'string' && id !== ''))].slice(0, 200)
|
|
405
|
+
} catch {
|
|
406
|
+
return []
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Save the shelf ids whose add-PDF card is off.
|
|
412
|
+
* @param {string} libraryId - active library id.
|
|
413
|
+
* @param {string[]} ids - shelf ids.
|
|
414
|
+
* @returns {void}
|
|
415
|
+
*/
|
|
416
|
+
function writeShelfAddPdfOff(libraryId, ids) {
|
|
417
|
+
if (typeof libraryId !== 'string' || libraryId === '') return
|
|
418
|
+
try {
|
|
419
|
+
window.localStorage.setItem(`${SHELF_ADD_PDF_PREFIX}${libraryId}`, JSON.stringify([...new Set(ids)]))
|
|
420
|
+
} catch {
|
|
421
|
+
// Storage unavailable: the choice still applies this visit.
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* One shelf's view: which books belong to it, which of them the grid shows,
|
|
427
|
+
* the collection cards under it, and the numbers on its switches. The main,
|
|
428
|
+
* custom and hidden shelves all answer through this one function, so
|
|
429
|
+
* membership and counts cannot drift between the grid, the cards and the
|
|
430
|
+
* breadcrumb.
|
|
431
|
+
*
|
|
432
|
+
* Reading, in this order: a hidden book is out of the main and custom
|
|
433
|
+
* shelves but *in* the hidden shelf (that is where "取消隐藏" finds it); a
|
|
434
|
+
* custom shelf holds exactly its ids minus hidden ones; the main shelf holds
|
|
435
|
+
* books that are neither hidden nor filed anywhere. Hidden and custom
|
|
436
|
+
* shelves are explicit places, so the whole/loose switches only filter the
|
|
437
|
+
* main shelf — a split book is `loose` until renamed, and it was just filed
|
|
438
|
+
* here on purpose.
|
|
439
|
+
*
|
|
440
|
+
* @param {object} input - catalog rows, stored groups, the open shelf and the view switches.
|
|
441
|
+
* @param {object[]} input.books - catalog rows.
|
|
442
|
+
* @param {{ hidden?: string[], shelves?: object[] }} input.groups - stored shelf groups.
|
|
443
|
+
* @param {string | null} input.group - null for the main shelf, 'hidden', or a custom shelf id.
|
|
444
|
+
* @param {boolean} input.showWhole - whether unpinned whole books are shown on the main shelf.
|
|
445
|
+
* @param {boolean} input.showLoose - whether hand-named split books are shown on the main shelf.
|
|
446
|
+
* @param {string[]} input.wholeAlways - whole-form keys pinned to always show.
|
|
447
|
+
* @param {string} input.hiddenLabel - localized name of the hidden shelf.
|
|
448
|
+
* @returns {{ group: string | null, scope: string, shelf: object | null, groupName: string | null, explicit: boolean, members: object[], visibleBooks: object[], collections: object[], counts: { whole: number, loose: number, pinned: number }, empty: boolean }} the shelf's view.
|
|
449
|
+
*/
|
|
450
|
+
function shelfView(input) {
|
|
451
|
+
const source = input === null || input === undefined ? {} : input
|
|
452
|
+
const list = Array.isArray(source.books) ? source.books : []
|
|
453
|
+
const groups = source.groups === null || source.groups === undefined ? {} : source.groups
|
|
454
|
+
const hidden = Array.isArray(groups.hidden) ? groups.hidden : []
|
|
455
|
+
const shelves = Array.isArray(groups.shelves) ? groups.shelves : []
|
|
456
|
+
const group = source.group === undefined ? null : source.group
|
|
457
|
+
const showWhole = source.showWhole === true
|
|
458
|
+
const showLoose = source.showLoose === true
|
|
459
|
+
const wholeAlways = Array.isArray(source.wholeAlways) ? source.wholeAlways : []
|
|
460
|
+
const hiddenLabel = typeof source.hiddenLabel === 'string' ? source.hiddenLabel : ''
|
|
461
|
+
const hiddenIds = new Set(hidden)
|
|
462
|
+
const shelved = new Set()
|
|
463
|
+
for (const item of shelves) for (const id of Array.isArray(item.books) ? item.books : []) shelved.add(id)
|
|
464
|
+
const shelf = group === null || group === 'hidden'
|
|
465
|
+
? null
|
|
466
|
+
: shelves.find(item => item.id === group) ?? null
|
|
467
|
+
const shelfBooks = shelf === null || !Array.isArray(shelf.books) ? [] : shelf.books
|
|
468
|
+
const explicit = group !== null
|
|
469
|
+
const members = group === 'hidden'
|
|
470
|
+
? list.filter(item => hiddenIds.has(item.id))
|
|
471
|
+
: shelf !== null
|
|
472
|
+
? list.filter(item => shelfBooks.includes(item.id) && !hiddenIds.has(item.id))
|
|
473
|
+
: list.filter(item => !hiddenIds.has(item.id) && !shelved.has(item.id))
|
|
474
|
+
const collections = [
|
|
475
|
+
...(group !== null || hidden.length === 0
|
|
476
|
+
? []
|
|
477
|
+
: [{
|
|
478
|
+
id: 'hidden',
|
|
479
|
+
name: hiddenLabel,
|
|
480
|
+
count: hidden.filter(id => list.some(item => item.id === id)).length,
|
|
481
|
+
}]),
|
|
482
|
+
...shelves
|
|
483
|
+
.filter(item => (item.parent ?? null) === group)
|
|
484
|
+
.map(item => ({
|
|
485
|
+
id: item.id,
|
|
486
|
+
name: item.name,
|
|
487
|
+
count: (Array.isArray(item.books) ? item.books : [])
|
|
488
|
+
.filter(id => !hiddenIds.has(id) && list.some(book => book.id === id)).length,
|
|
489
|
+
})),
|
|
490
|
+
]
|
|
491
|
+
const visibleBooks = explicit
|
|
492
|
+
? members
|
|
493
|
+
: members.filter(book => {
|
|
494
|
+
// A pinned whole form shows whatever the switch says; the rest follow it.
|
|
495
|
+
if (book.whole === true) return showWhole || wholeAlways.includes(wholeBaseId(book.id))
|
|
496
|
+
if (book.loose === true) return showLoose
|
|
497
|
+
return true
|
|
498
|
+
})
|
|
499
|
+
return {
|
|
500
|
+
group,
|
|
501
|
+
scope: group === 'hidden' ? 'hidden' : group === null ? 'main' : 'custom',
|
|
502
|
+
shelf,
|
|
503
|
+
groupName: group === 'hidden' ? hiddenLabel : shelf === null ? null : shelf.name,
|
|
504
|
+
explicit,
|
|
505
|
+
members,
|
|
506
|
+
visibleBooks,
|
|
507
|
+
collections,
|
|
508
|
+
// The switches count every catalog book, not just this shelf's members:
|
|
509
|
+
// they describe the main shelf even while a book page is open.
|
|
510
|
+
counts: {
|
|
511
|
+
whole: list.filter(item => item.whole === true && !wholeAlways.includes(wholeBaseId(item.id))).length,
|
|
512
|
+
loose: list.filter(item => item.loose === true && item.whole !== true).length,
|
|
513
|
+
pinned: wholeAlways.length,
|
|
514
|
+
},
|
|
515
|
+
empty: members.length === 0 && collections.length === 0,
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Put books into one shelf. Existing ids keep their order and are not
|
|
521
|
+
* repeated; the caller learns whether anything was added. Filing the
|
|
522
|
+
* selection, an imported PDF and the books a split just wrote all go
|
|
523
|
+
* through here, so those paths cannot disagree about membership.
|
|
524
|
+
* @param {{ hidden?: string[], shelves?: object[] }} groups - stored groups.
|
|
525
|
+
* @param {string} shelfId - target shelf id.
|
|
526
|
+
* @param {string[]} ids - book ids to add.
|
|
527
|
+
* @returns {{ groups: object, shelf: object, added: number } | null} the next groups, or null when the shelf is unknown or already holds every id.
|
|
528
|
+
*/
|
|
529
|
+
function shelfAddBooks(groups, shelfId, ids) {
|
|
530
|
+
const current = groups === null || groups === undefined ? {} : groups
|
|
531
|
+
const shelves = Array.isArray(current.shelves) ? current.shelves : []
|
|
532
|
+
const shelf = shelves.find(item => item.id === shelfId)
|
|
533
|
+
if (shelf === undefined) return null
|
|
534
|
+
const held = Array.isArray(shelf.books) ? shelf.books : []
|
|
535
|
+
const next = [...new Set([...held, ...(Array.isArray(ids) ? ids : [])])]
|
|
536
|
+
if (next.length === held.length) return null
|
|
537
|
+
return {
|
|
538
|
+
shelf,
|
|
539
|
+
added: next.length - held.length,
|
|
540
|
+
groups: {
|
|
541
|
+
hidden: Array.isArray(current.hidden) ? current.hidden : [],
|
|
542
|
+
shelves: shelves.map(item => (item.id === shelfId ? { ...item, books: next } : item)),
|
|
543
|
+
},
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Put the same books into several shelves with one resulting groups object,
|
|
549
|
+
* so a split can join every shelf that already held the whole book without
|
|
550
|
+
* writing the shelf file once per shelf.
|
|
551
|
+
* @param {{ hidden?: string[], shelves?: object[] }} groups - stored groups.
|
|
552
|
+
* @param {string[]} shelfIds - target shelf ids.
|
|
553
|
+
* @param {string[]} ids - book ids to add.
|
|
554
|
+
* @returns {{ groups: object, shelves: object[], added: number } | null} the next groups, or null when nothing was added anywhere.
|
|
555
|
+
*/
|
|
556
|
+
function shelfAddBooksTo(groups, shelfIds, ids) {
|
|
557
|
+
let current = groups
|
|
558
|
+
let added = 0
|
|
559
|
+
const shelves = []
|
|
560
|
+
for (const shelfId of Array.isArray(shelfIds) ? shelfIds : []) {
|
|
561
|
+
const result = shelfAddBooks(current, shelfId, ids)
|
|
562
|
+
if (result === null) continue
|
|
563
|
+
current = result.groups
|
|
564
|
+
added += result.added
|
|
565
|
+
shelves.push(result.shelf)
|
|
566
|
+
}
|
|
567
|
+
return added > 0 ? { groups: current, added, shelves } : null
|
|
568
|
+
}
|
|
569
|
+
|
|
275
570
|
/** Opt-in for Host-created reader sessions (model at creation). */
|
|
276
571
|
const HOST_SESSION_KEY = 'pdfdesk:ai-session-host'
|
|
277
572
|
|
|
@@ -392,18 +687,26 @@ window.__ModuleLoader__.load({
|
|
|
392
687
|
}
|
|
393
688
|
|
|
394
689
|
/**
|
|
395
|
-
* Remember the split-tool conversation of one library.
|
|
690
|
+
* Remember the split-tool conversation of one library. The pointer carries
|
|
691
|
+
* its own kind and library folder so a later click can prove it names this
|
|
692
|
+
* library's conversation before reopening anything.
|
|
396
693
|
* @param {string} libraryId - library id.
|
|
397
694
|
* @param {string} sessionId - the conversation.
|
|
398
695
|
* @param {string} workspaceId - its workspace.
|
|
696
|
+
* @param {string} [cwd] - the library folder the conversation serves.
|
|
399
697
|
* @returns {void}
|
|
400
698
|
*/
|
|
401
|
-
function writeStoredSplitSession(libraryId, sessionId, workspaceId) {
|
|
699
|
+
function writeStoredSplitSession(libraryId, sessionId, workspaceId, cwd) {
|
|
402
700
|
if (typeof libraryId !== 'string' || libraryId === '' || typeof sessionId !== 'string' || sessionId === '') return
|
|
403
701
|
// Remember it even when storage is unavailable: this visit must not reuse it.
|
|
404
702
|
splitSessionIds.add(sessionId)
|
|
405
703
|
try {
|
|
406
|
-
window.localStorage.setItem(`${SPLIT_SESSION_STORAGE}${libraryId}`, JSON.stringify({
|
|
704
|
+
window.localStorage.setItem(`${SPLIT_SESSION_STORAGE}${libraryId}`, JSON.stringify({
|
|
705
|
+
kind: 'split',
|
|
706
|
+
sessionId,
|
|
707
|
+
workspaceId,
|
|
708
|
+
cwd: typeof cwd === 'string' ? cwd : '',
|
|
709
|
+
}))
|
|
407
710
|
} catch {
|
|
408
711
|
// storage unavailable
|
|
409
712
|
}
|
|
@@ -719,6 +1022,59 @@ window.__ModuleLoader__.load({
|
|
|
719
1022
|
}
|
|
720
1023
|
}
|
|
721
1024
|
|
|
1025
|
+
/**
|
|
1026
|
+
* One block that tells a new conversation which question marks already exist
|
|
1027
|
+
* in the chapter. A mark stores a page and a rectangle; the picture is what
|
|
1028
|
+
* lets the model see the framed region even on a scanned page.
|
|
1029
|
+
* @param {object[]} questions - the chapter's marks.
|
|
1030
|
+
* @returns {string} the block, or '' when the chapter has no marks.
|
|
1031
|
+
*/
|
|
1032
|
+
function questionsSeedText(questions) {
|
|
1033
|
+
const rows = (Array.isArray(questions) ? questions : [])
|
|
1034
|
+
.map(question => {
|
|
1035
|
+
const name = question !== null && question !== undefined ? question.name : ''
|
|
1036
|
+
return {
|
|
1037
|
+
name: String(name ?? '').trim(),
|
|
1038
|
+
page: Math.max(0, Math.round(Number(question !== null && question !== undefined ? question.page : 0) || 0)),
|
|
1039
|
+
image: typeof (question === null || question === undefined ? undefined : question.image) === 'string'
|
|
1040
|
+
? question.image.trim()
|
|
1041
|
+
: '',
|
|
1042
|
+
}
|
|
1043
|
+
})
|
|
1044
|
+
.filter(row => row.name !== '' && row.page > 0)
|
|
1045
|
+
if (rows.length === 0) return ''
|
|
1046
|
+
const list = rows.map(row => `- ${row.name}(第 ${row.page} 页)${row.image === '' ? '' : `\n 图片:${row.image}`}`).join('\n')
|
|
1047
|
+
return `本章疑问标记(用户标在 PDF 上的位置,不是正文;用户说「看到疑问…」时指这些):\n${list}`
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* The chapter's question marks as seed text. Missing or unreadable marks
|
|
1052
|
+
* simply add nothing: the session must still open. The Host renders one
|
|
1053
|
+
* crop per mark (and reuses cached ones), so existing marks get pictures too.
|
|
1054
|
+
* @param {string} bookId - book id.
|
|
1055
|
+
* @param {string} code - chapter code.
|
|
1056
|
+
* @returns {Promise<string>} the block, or ''.
|
|
1057
|
+
*/
|
|
1058
|
+
async function chapterQuestionsBrief(bookId, code) {
|
|
1059
|
+
try {
|
|
1060
|
+
const payload = await loadChapterQuestions(bookId, code)
|
|
1061
|
+
const images = new Map()
|
|
1062
|
+
try {
|
|
1063
|
+
const crops = await request('POST', 'question-crops', { book: bookId, code })
|
|
1064
|
+
for (const item of Array.isArray(crops === null || crops === undefined ? undefined : crops.items) ? crops.items : []) {
|
|
1065
|
+
if (typeof item.id === 'string' && typeof item.path === 'string') images.set(item.id, item.path)
|
|
1066
|
+
}
|
|
1067
|
+
} catch {
|
|
1068
|
+
// No pictures is still better than failing the session seed.
|
|
1069
|
+
}
|
|
1070
|
+
return questionsSeedText(payload.questions.map(question => (
|
|
1071
|
+
images.has(question.id) ? { ...question, image: images.get(question.id) } : question
|
|
1072
|
+
)))
|
|
1073
|
+
} catch {
|
|
1074
|
+
return ''
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
722
1078
|
/**
|
|
723
1079
|
* The session the main area currently shows, if any. The workspace keeps the
|
|
724
1080
|
* main session retained while a global panel (this workbench) is in front,
|
|
@@ -741,11 +1097,13 @@ window.__ModuleLoader__.load({
|
|
|
741
1097
|
const injectedQuestions = new Set()
|
|
742
1098
|
|
|
743
1099
|
/**
|
|
744
|
-
* Append `看到疑问:<name
|
|
745
|
-
*
|
|
1100
|
+
* Append `看到疑问:<name>(第 N 页)` to the conversation that is open, if
|
|
1101
|
+
* any. The page is what lets the model find the mark: a mark is a position
|
|
1102
|
+
* on the PDF, not a line of text in the chapter. This writes the composer
|
|
1103
|
+
* only: no session is created, opened or sent.
|
|
746
1104
|
* @param {string} bookId - book id.
|
|
747
1105
|
* @param {string} code - chapter code.
|
|
748
|
-
* @param {{ id: string, name: string }} question - the created mark.
|
|
1106
|
+
* @param {{ id: string, name: string, page?: number, image?: string }} question - the created mark.
|
|
749
1107
|
* @returns {Promise<boolean>} whether the line was written.
|
|
750
1108
|
*/
|
|
751
1109
|
async function injectQuestionLine(bookId, code, question) {
|
|
@@ -755,7 +1113,12 @@ window.__ModuleLoader__.load({
|
|
|
755
1113
|
const key = `${sessionId}|${bookId}|${code}|${question.id}`
|
|
756
1114
|
if (injectedQuestions.has(key)) return false
|
|
757
1115
|
injectedQuestions.add(key)
|
|
758
|
-
const
|
|
1116
|
+
const page = Math.round(Number(question.page))
|
|
1117
|
+
const where = Number.isFinite(page) && page > 0 ? `(第 ${page} 页)` : ''
|
|
1118
|
+
const image = typeof question.image === 'string' && question.image !== ''
|
|
1119
|
+
? `\n图片(框选区域):${question.image}\n请先 read_image 这张图片,看清框里的内容。`
|
|
1120
|
+
: ''
|
|
1121
|
+
const prefill = await beginPrefill(sessionId, `看到疑问:${question.name}${where}${image}`, 'append')
|
|
759
1122
|
if (prefill.reference !== null) {
|
|
760
1123
|
try { prefill.reference.release() } catch { /* already released */ }
|
|
761
1124
|
}
|
|
@@ -907,6 +1270,7 @@ window.__ModuleLoader__.load({
|
|
|
907
1270
|
aiPromptCopied: '提示词已复制',
|
|
908
1271
|
splitToolStart: '打开拆分会话',
|
|
909
1272
|
splitToolCardHint: '在当前书库中创建拆分会话,按命名规则整理章节。',
|
|
1273
|
+
splitStaysWhole: '手动拆开的 PDF 仍属于整本:在「拆分会话」里处理(改名、校验)之前,不会生成章节名,也不会作为分片显示。',
|
|
910
1274
|
splitPdfTitle: '按页拆分整本 PDF',
|
|
911
1275
|
wholePdfCardTitle: '整本 PDF',
|
|
912
1276
|
wholePdfCardHint: '导入整本 PDF,或放进书库的「整本」目录。',
|
|
@@ -942,6 +1306,12 @@ window.__ModuleLoader__.load({
|
|
|
942
1306
|
importSplitAsk: '《{title}》已导入 整本\\。现在按页拆分成章节吗?',
|
|
943
1307
|
importSplitNow: '现在拆分',
|
|
944
1308
|
importSplitLater: '以后再说',
|
|
1309
|
+
importSplitRemember: '记住这个选择,以后不再询问',
|
|
1310
|
+
settingsImportSplit: '导入后是否拆分',
|
|
1311
|
+
settingsImportSplitHint: '记住「现在拆分」后,导入 PDF 会直接打开拆分面板;记住「以后再说」则不再弹窗。在这里可以改回每次询问。',
|
|
1312
|
+
importSplitChoiceAsk: '每次询问',
|
|
1313
|
+
importSplitChoiceSplit: '直接拆分',
|
|
1314
|
+
importSplitChoiceLater: '不询问',
|
|
945
1315
|
splitPrompt: '你是数学书库整理助手。**拆分由用户手动作,按章节拆**(一章一个 PDF,页范围看目录);你的工作是按命名规则重命名、校验、整理目录,不要整本 OCR/拆分。\n书库根目录:{dir}\n目标目录:{dir}\\分片\\<书 id>\\(书 id 是这本书的简写,例如 概率论)\n工具:{dir}\\工具\\ 下的 rename_chapters.py(批量改名)、pdfkit.py(split/verify/render)、auto_chapters.py;规则:{dir}\\工具\\README.md 与 {dir}\\工具\\规范\\。\n要点:目录页必须在 c00;一章一个 PDF,命名 <书 id>_cNN_第X章_章名_p起-止.pdf;缺目录就先请用户补,不要自己猜。\n流程:确认书 id 与已有分片 → 改名/校验 → 报告结果和缺的章。',
|
|
946
1316
|
splitFailed: '拆分工具没启动:确认库目录可写后重试',
|
|
947
1317
|
librariesTitleHint: '双击标题回到书库',
|
|
@@ -1159,6 +1529,7 @@ window.__ModuleLoader__.load({
|
|
|
1159
1529
|
splitFragmentDir: '分片/<书id>/',
|
|
1160
1530
|
splitUntitled: '未命名',
|
|
1161
1531
|
splitCutHint: '在这里切开',
|
|
1532
|
+
splitJumpTo: '跳到第 {n} 页',
|
|
1162
1533
|
splitUncutHint: '取消这个拆点',
|
|
1163
1534
|
splitCutMarked: '已切开',
|
|
1164
1535
|
splitRestored: '已恢复上次的 {n} 个拆点',
|
|
@@ -1166,6 +1537,18 @@ window.__ModuleLoader__.load({
|
|
|
1166
1537
|
splitStart: '开始拆分',
|
|
1167
1538
|
splitBusy: '正在拆分…',
|
|
1168
1539
|
splitDone: '已拆成 {files} 份',
|
|
1540
|
+
splitResultTitle: '拆分完成',
|
|
1541
|
+
splitResultBody: '已拆成 {files} 份,结果在 分片\\{book}\\。',
|
|
1542
|
+
splitResultRemoveAsk: '是否移除整本形式的书?',
|
|
1543
|
+
splitResultRemoveHint: '原始整本 PDF 移到 回收站\\,拆分出的章节保留。',
|
|
1544
|
+
splitResultOpenAsk: '是否打开拆分会话?',
|
|
1545
|
+
splitResultOpenHint: '回到这个书库的拆书对话,继续核对和重命名章节。',
|
|
1546
|
+
splitResultOpenFailed: '打开拆分会话失败,请确认工作区可用后重试。',
|
|
1547
|
+
splitPromptMissing: '拆分会话已打开,但提示词没有自动填入;请关掉后重新点一次,或直接把书库需求告诉它。',
|
|
1548
|
+
splitResultFinish: '完成',
|
|
1549
|
+
splitResultLater: '以后再说',
|
|
1550
|
+
splitResultFailed: '操作失败',
|
|
1551
|
+
splitResultRemoved: '已移除整本 PDF,可在 回收站\\ 恢复',
|
|
1169
1552
|
splitFailed: '拆分失败',
|
|
1170
1553
|
translateStorageHint: '另外,每一页的图会存进 DSH 附件库作为模型输入(约 0.3 MB/页;本章 {pages} 页约 {mb} MB),目前不会自动清理。',
|
|
1171
1554
|
translating: '翻译中…',
|
|
@@ -1272,6 +1655,8 @@ window.__ModuleLoader__.load({
|
|
|
1272
1655
|
hideLocalPath: '隐藏本机路径',
|
|
1273
1656
|
tipsLeftClick: '左键:书卡单击选中/取消,双击打开;章节名单击展开/收起。',
|
|
1274
1657
|
tipsRightClick: '右键:产物可转 PDF/删除,会话可归档;书卡与章节没有右键菜单。',
|
|
1658
|
+
tipsDelete: '删除 PDF:单击书卡选中 →「隐藏所选」→ 打开「隐藏书籍」→ 选中该书 →「删除所选(移入回收站)」;要彻底删除,去 设置 → 数据 → 清空回收站。',
|
|
1659
|
+
tipsCopyright: '版权:本插件不提供任何书籍内容;请只导入你有权使用的 PDF,拆分与翻译结果仅供个人学习,请勿传播或商用。',
|
|
1275
1660
|
tipsTitle: '使用提示',
|
|
1276
1661
|
splitToolTitle: '分片工具',
|
|
1277
1662
|
importToolTitle: '导入文件',
|
|
@@ -1282,6 +1667,11 @@ window.__ModuleLoader__.load({
|
|
|
1282
1667
|
envOff: '未安装(点击下载)',
|
|
1283
1668
|
envPython: 'Python 3',
|
|
1284
1669
|
envPythonSize: '约 25 MB',
|
|
1670
|
+
envPipPackages: 'PyMuPDF + Pillow',
|
|
1671
|
+
envPipHint: '拆分 / 翻译 / 导出需要,只阅读不需要 Python',
|
|
1672
|
+
envPipCommand: 'py -m pip install pymupdf pillow',
|
|
1673
|
+
envPipCopy: '复制命令',
|
|
1674
|
+
envPipCopied: '已复制',
|
|
1285
1675
|
envTex: 'TeX Live(xelatex + ctex)',
|
|
1286
1676
|
envTexSize: '约 5 GB',
|
|
1287
1677
|
envEngine: '排版引擎',
|
|
@@ -1351,7 +1741,12 @@ window.__ModuleLoader__.load({
|
|
|
1351
1741
|
shelfShown: ':显示',
|
|
1352
1742
|
shelfHidden: ':隐藏',
|
|
1353
1743
|
shelfWholeHint: '点一下切换:整本、未拆分的 PDF 是否出现在书库',
|
|
1354
|
-
shelfLooseHint: '
|
|
1744
|
+
shelfLooseHint: '点一下切换:已拆成多份但书名/章名尚未按拆分规则命名的 PDF 是否出现在书库',
|
|
1745
|
+
shelfWholePinForm: '一直显示整本',
|
|
1746
|
+
shelfWholeUnpinForm: '取消一直显示',
|
|
1747
|
+
shelfWholeFormHint: '对选中的书:它的整本 PDF 形式一直显示,不受「整本书」总开关影响;再点一次取消',
|
|
1748
|
+
shelfWholeReset: '取消固定整本({n})',
|
|
1749
|
+
shelfWholeResetHint: '清除所有「一直显示整本」的设置,整本 PDF 重新跟随总开关',
|
|
1355
1750
|
settingsNotesTitle: '笔记与备份',
|
|
1356
1751
|
sharedPrefixClear: '清除章节共享前缀',
|
|
1357
1752
|
sharedPrefixClearHint: '删除各章提取文本、基础会话与模式分支映射(.pdfdesk/cache);PDF、笔记和已有会话不受影响',
|
|
@@ -1556,7 +1951,7 @@ window.__ModuleLoader__.load({
|
|
|
1556
1951
|
envGuideOk: '知道了',
|
|
1557
1952
|
envGuideSettings: '打开设置',
|
|
1558
1953
|
envInlineMissing: '翻译不可用:缺 Python / TeX 或可读图的模型',
|
|
1559
|
-
envGuideWhyPython: '用来把 PDF 转文字、整理块、生成读版/叠加 PDF',
|
|
1954
|
+
envGuideWhyPython: '用来把 PDF 转文字、整理块、生成读版/叠加 PDF;需要 PyMuPDF 与 Pillow(py -m pip install pymupdf pillow)',
|
|
1560
1955
|
envGuideWhyTex: '没有 Typst 时用它排版;导出与旧缓存回退也要它',
|
|
1561
1956
|
envGuideWhyTypst: '默认排版引擎:叠加与读版 PDF,比 TeX 快约 9 倍',
|
|
1562
1957
|
envGuideWhyModel: '整章翻译要读页面图,必须选一个支持图片输入的模型',
|
|
@@ -1628,13 +2023,14 @@ window.__ModuleLoader__.load({
|
|
|
1628
2023
|
workspaceCreateFailed: '创建工作区失败',
|
|
1629
2024
|
workspaceRequired: '请先选择或新建一个工作区,再开始会话。',
|
|
1630
2025
|
envDownload: '下载 TeX Live(约 5 GB)',
|
|
1631
|
-
envHint: '需要 TeX Live(xelatex、ctex)与 Python 3;装好后把 TeX 的 bin 加进 PATH 并重启 DSH',
|
|
2026
|
+
envHint: '需要 TeX Live(xelatex、ctex)与 Python 3,并执行 py -m pip install pymupdf pillow;装好后把 TeX 的 bin 加进 PATH 并重启 DSH',
|
|
1632
2027
|
updateChecking: '检查中…',
|
|
1633
2028
|
updateHint: '只在你点击时访问 GitHub releases',
|
|
1634
2029
|
updateLatest: '已是最新版本(v{version})',
|
|
1635
2030
|
updateNew: '发现新版本 {version}(当前 {current}),可以立即更新',
|
|
1636
2031
|
updateNow: '立即更新',
|
|
1637
2032
|
updateDownloadOnly: '市场未管理这个插件,点击会下载 zip;解压后在 DSH 插件页更新',
|
|
2033
|
+
aboutCopyright: '本插件只提供阅读、拆分与翻译工具:不提供、不内置、不分发任何书籍内容。导入的 PDF 需由你确认有权使用;拆分、翻译与导出结果仅供个人学习研究,请勿传播或商用。',
|
|
1638
2034
|
updateMarketStarting: '正在通过插件市场更新…',
|
|
1639
2035
|
updateMarketProgress: '正在更新:{state}',
|
|
1640
2036
|
updateMarketDone: '已更新到 v{version};重启 DSH 后生效',
|
|
@@ -1653,6 +2049,18 @@ window.__ModuleLoader__.load({
|
|
|
1653
2049
|
shelfCount: '{n} 本',
|
|
1654
2050
|
shelfSelected: '已选 {n} 本',
|
|
1655
2051
|
shelfNew: '新建书架',
|
|
2052
|
+
shelfAddTo: '加入书架',
|
|
2053
|
+
shelfAddToTitle: '加入哪个书架',
|
|
2054
|
+
shelfAddToHint: '把选中的 {n} 本书加入:',
|
|
2055
|
+
shelfAddToEmpty: '还没有书架,先点「新建书架」',
|
|
2056
|
+
shelfBookCount: '{n} 本',
|
|
2057
|
+
shelfAddedTo: '已加入「{name}」:{n} 本',
|
|
2058
|
+
shelfAlreadyIn: '「{name}」里已经有这些书了',
|
|
2059
|
+
shelfAddPdf: '添加 PDF',
|
|
2060
|
+
shelfAddPdfOn: ':开',
|
|
2061
|
+
shelfAddPdfOff: ':关',
|
|
2062
|
+
shelfAddPdfOnHint: '书架里显示「添加 PDF」卡片;点一下关闭',
|
|
2063
|
+
shelfAddPdfOffHint: '书架里不显示「添加 PDF」卡片;点一下打开',
|
|
1656
2064
|
shelfName: '书架名称',
|
|
1657
2065
|
shelfCreate: '创建',
|
|
1658
2066
|
shelfHide: '隐藏所选',
|
|
@@ -1824,6 +2232,7 @@ window.__ModuleLoader__.load({
|
|
|
1824
2232
|
aiPromptCopied: 'Prompt copied',
|
|
1825
2233
|
splitToolStart: 'Open the split conversation',
|
|
1826
2234
|
splitToolCardHint: 'Start a split conversation in this library and arrange chapters by the naming rule.',
|
|
2235
|
+
splitStaysWhole: 'Manually split PDFs still belong to the whole book: until the split conversation processes them (rename + verify), they have no chapter names and do not appear as fragments.',
|
|
1827
2236
|
splitPdfTitle: 'Split a whole PDF by page',
|
|
1828
2237
|
wholePdfCardTitle: 'Whole PDF',
|
|
1829
2238
|
wholePdfCardHint: 'Import a whole PDF, or drop it into the 整本/ folder of the library.',
|
|
@@ -1859,6 +2268,12 @@ window.__ModuleLoader__.load({
|
|
|
1859
2268
|
importSplitAsk: '《{title}》 was imported into 整本\\. Split it into chapters by page now?',
|
|
1860
2269
|
importSplitNow: 'Split now',
|
|
1861
2270
|
importSplitLater: 'Not now',
|
|
2271
|
+
importSplitRemember: 'Remember this choice and do not ask again',
|
|
2272
|
+
settingsImportSplit: 'Split after import',
|
|
2273
|
+
settingsImportSplitHint: 'Remembering "Split now" opens the split panel right after an import; "Not now" stops the question. Reset it to asking here.',
|
|
2274
|
+
importSplitChoiceAsk: 'Ask every time',
|
|
2275
|
+
importSplitChoiceSplit: 'Split automatically',
|
|
2276
|
+
importSplitChoiceLater: 'Do not ask',
|
|
1862
2277
|
splitPrompt: 'You organize a math library. **The user splits by hand, one chapter per PDF** (page ranges from the contents); your job is renaming, verifying and organizing — never OCR or split the whole book.\nLibrary root: {dir}\nTarget: {dir}\\分片\\<book id>\\ (a short id like 概率论)\nTools: {dir}\\工具\\ with rename_chapters.py (batch rename), pdfkit.py (split/verify/render), auto_chapters.py; rules: {dir}\\工具\\README.md and {dir}\\工具\\规范\\.\nPoints: the contents must be in c00; one PDF per chapter, named <book id>_cNN_第X章_章名_p起-止.pdf; if the contents are missing, ask the user — do not guess.\nFlow: confirm the book id and existing splits → rename/verify → report the result and missing chapters.',
|
|
1863
2278
|
splitFailed: 'The split conversation did not start — check that the library folder is writable',
|
|
1864
2279
|
librariesTitleHint: 'Double-click the title for the libraries',
|
|
@@ -2077,6 +2492,7 @@ window.__ModuleLoader__.load({
|
|
|
2077
2492
|
splitFragmentDir: '分片/<book id>/',
|
|
2078
2493
|
splitUntitled: 'Untitled',
|
|
2079
2494
|
splitCutHint: 'Cut here',
|
|
2495
|
+
splitJumpTo: 'Jump to page {n}',
|
|
2080
2496
|
splitUncutHint: 'Remove this cut',
|
|
2081
2497
|
splitCutMarked: 'Cut added',
|
|
2082
2498
|
splitRestored: 'Restored {n} saved cut(s)',
|
|
@@ -2084,6 +2500,18 @@ window.__ModuleLoader__.load({
|
|
|
2084
2500
|
splitStart: 'Start splitting',
|
|
2085
2501
|
splitBusy: 'Splitting…',
|
|
2086
2502
|
splitDone: 'Split into {files} files',
|
|
2503
|
+
splitResultTitle: 'Split finished',
|
|
2504
|
+
splitResultBody: 'Split into {files} files in 分片\\{book}\\.',
|
|
2505
|
+
splitResultRemoveAsk: 'Remove the whole-book copy?',
|
|
2506
|
+
splitResultRemoveHint: 'Moves the original whole PDF to 回收站\\; the split chapters stay.',
|
|
2507
|
+
splitResultOpenAsk: 'Open the split conversation?',
|
|
2508
|
+
splitResultOpenHint: 'Return to this library\'s split conversation to verify and rename chapters.',
|
|
2509
|
+
splitResultOpenFailed: 'Could not open the split conversation — check the workspace and try again.',
|
|
2510
|
+
splitPromptMissing: 'The split conversation opened, but the prompt could not be inserted; close it and try again, or tell it about the library directly.',
|
|
2511
|
+
splitResultFinish: 'Done',
|
|
2512
|
+
splitResultLater: 'Later',
|
|
2513
|
+
splitResultFailed: 'Action failed',
|
|
2514
|
+
splitResultRemoved: 'Whole PDF moved to 回收站\\ and can be restored',
|
|
2087
2515
|
splitFailed: 'Splitting failed',
|
|
2088
2516
|
translating: 'Translating…',
|
|
2089
2517
|
translateDone: 'Created',
|
|
@@ -2190,6 +2618,8 @@ window.__ModuleLoader__.load({
|
|
|
2190
2618
|
hideLocalPath: 'Hide local path',
|
|
2191
2619
|
tipsLeftClick: 'Left click: a cover selects/deselects, double click opens the book; a chapter row expands/collapses',
|
|
2192
2620
|
tipsRightClick: 'Right click: artifacts can convert or delete, sessions can be archived; books and chapters have no menu',
|
|
2621
|
+
tipsDelete: 'Delete a PDF: click its cover to select it → Hide selected → open Hidden books → select it → Delete selected (to recycle bin). To erase permanently, use Settings → Data → Empty recycle bin.',
|
|
2622
|
+
tipsCopyright: 'Copyright: this plugin ships no book content. Import only PDFs you may use; split and translated output is for personal study—do not redistribute it.',
|
|
2193
2623
|
tipsTitle: 'Interaction tips',
|
|
2194
2624
|
splitToolTitle: 'Split toolkit',
|
|
2195
2625
|
importToolTitle: 'Import files',
|
|
@@ -2200,6 +2630,11 @@ window.__ModuleLoader__.load({
|
|
|
2200
2630
|
envOff: 'missing (click to download)',
|
|
2201
2631
|
envPython: 'Python 3',
|
|
2202
2632
|
envPythonSize: '~25 MB',
|
|
2633
|
+
envPipPackages: 'PyMuPDF + Pillow',
|
|
2634
|
+
envPipHint: 'needed for split / translate / export; reading needs no Python',
|
|
2635
|
+
envPipCommand: 'py -m pip install pymupdf pillow',
|
|
2636
|
+
envPipCopy: 'Copy command',
|
|
2637
|
+
envPipCopied: 'Copied',
|
|
2203
2638
|
envTex: 'TeX Live (xelatex + ctex)',
|
|
2204
2639
|
envTexSize: '~5 GB',
|
|
2205
2640
|
envEngine: 'Typesetting engine',
|
|
@@ -2269,7 +2704,12 @@ window.__ModuleLoader__.load({
|
|
|
2269
2704
|
shelfShown: ': shown',
|
|
2270
2705
|
shelfHidden: ': hidden',
|
|
2271
2706
|
shelfWholeHint: 'Click to switch whether whole, unsplit PDFs appear in the library',
|
|
2272
|
-
shelfLooseHint: 'Click to switch whether PDFs split into chapters but named
|
|
2707
|
+
shelfLooseHint: 'Click to switch whether PDFs split into chapters but not yet named per the split rule appear in the library',
|
|
2708
|
+
shelfWholePinForm: 'Always show whole form',
|
|
2709
|
+
shelfWholeUnpinForm: 'Stop always showing',
|
|
2710
|
+
shelfWholeFormHint: 'For the selected books: keep their whole-PDF form visible whatever the "whole books" switch says; click again to stop',
|
|
2711
|
+
shelfWholeReset: 'Unpin whole forms ({n})',
|
|
2712
|
+
shelfWholeResetHint: 'Clear every "always show whole form" choice so whole PDFs follow the shelf switch again',
|
|
2273
2713
|
settingsNotesTitle: 'Notes and backup',
|
|
2274
2714
|
sharedPrefixClear: 'Clear chapter shared prefix',
|
|
2275
2715
|
sharedPrefixClearHint: 'Delete extracted text, base-session and branch maps (.pdfdesk/cache). PDFs, notes and existing sessions stay.',
|
|
@@ -2474,7 +2914,7 @@ window.__ModuleLoader__.load({
|
|
|
2474
2914
|
envGuideOk: 'Got it',
|
|
2475
2915
|
envGuideSettings: 'Open settings',
|
|
2476
2916
|
envInlineMissing: 'Translation unavailable: Python / TeX or an image-capable model is missing',
|
|
2477
|
-
envGuideWhyPython: 'Turns PDFs into text, keeps block geometry, and builds the reading/overlay PDFs',
|
|
2917
|
+
envGuideWhyPython: 'Turns PDFs into text, keeps block geometry, and builds the reading/overlay PDFs; needs PyMuPDF and Pillow (py -m pip install pymupdf pillow)',
|
|
2478
2918
|
envGuideWhyTex: 'Typesets when Typst is absent; export and older caches still need it',
|
|
2479
2919
|
envGuideWhyTypst: 'Default typesetter for the overlay and reading PDFs, about 9× faster than TeX',
|
|
2480
2920
|
envGuideWhyModel: 'Chapter translation reads page images, so the model must accept images',
|
|
@@ -2546,13 +2986,14 @@ window.__ModuleLoader__.load({
|
|
|
2546
2986
|
workspaceCreateFailed: 'Could not create the workspace',
|
|
2547
2987
|
workspaceRequired: 'Choose or create a workspace before starting a conversation.',
|
|
2548
2988
|
envDownload: 'Download TeX Live (~5 GB)',
|
|
2549
|
-
envHint: 'Needs TeX Live (xelatex, ctex) and Python 3; add TeX bin to PATH and restart DSH',
|
|
2989
|
+
envHint: 'Needs TeX Live (xelatex, ctex) and Python 3, then run py -m pip install pymupdf pillow; add TeX bin to PATH and restart DSH',
|
|
2550
2990
|
updateChecking: 'Checking…',
|
|
2551
2991
|
updateHint: 'Only contacts GitHub releases on click',
|
|
2552
2992
|
updateLatest: 'Up to date (v{version})',
|
|
2553
2993
|
updateNew: 'Version {version} is available (you have {current}) — update now',
|
|
2554
2994
|
updateNow: 'Update now',
|
|
2555
2995
|
updateDownloadOnly: 'The market does not manage this plugin; the button downloads the zip. Unzip it and update in the DSH plugin page.',
|
|
2996
|
+
aboutCopyright: 'This plugin is a reading, splitting and translation tool: it ships and distributes no book content. Only import PDFs you have the right to use; split, translation and export output is for personal study—do not redistribute it.',
|
|
2556
2997
|
updateMarketStarting: 'Updating through the plugin market…',
|
|
2557
2998
|
updateMarketProgress: 'Updating: {state}',
|
|
2558
2999
|
updateMarketDone: 'Updated to v{version}; restart DSH to apply',
|
|
@@ -2571,6 +3012,18 @@ window.__ModuleLoader__.load({
|
|
|
2571
3012
|
shelfCount: '{n} books',
|
|
2572
3013
|
shelfSelected: '{n} selected',
|
|
2573
3014
|
shelfNew: 'New shelf',
|
|
3015
|
+
shelfAddTo: 'Add to shelf',
|
|
3016
|
+
shelfAddToTitle: 'Add to which shelf?',
|
|
3017
|
+
shelfAddToHint: 'Add the {n} selected book(s) to:',
|
|
3018
|
+
shelfAddToEmpty: 'No shelves yet — create one first',
|
|
3019
|
+
shelfBookCount: '{n} book(s)',
|
|
3020
|
+
shelfAddedTo: 'Added {n} book(s) to "{name}"',
|
|
3021
|
+
shelfAlreadyIn: '"{name}" already has these books',
|
|
3022
|
+
shelfAddPdf: 'Add PDF',
|
|
3023
|
+
shelfAddPdfOn: ': on',
|
|
3024
|
+
shelfAddPdfOff: ': off',
|
|
3025
|
+
shelfAddPdfOnHint: 'Show the add-PDF card in this shelf; click to turn it off',
|
|
3026
|
+
shelfAddPdfOffHint: 'Hide the add-PDF card in this shelf; click to turn it on',
|
|
2574
3027
|
shelfName: 'Shelf name',
|
|
2575
3028
|
shelfCreate: 'Create',
|
|
2576
3029
|
shelfHide: 'Hide selected',
|
|
@@ -3635,17 +4088,18 @@ window.__ModuleLoader__.load({
|
|
|
3635
4088
|
* it; the caller must release it.
|
|
3636
4089
|
* @param {string} sessionId - the session that will hold the draft.
|
|
3637
4090
|
* @param {string} text - the outline Markdown.
|
|
3638
|
-
* @
|
|
4091
|
+
* @param {'append' | 'keep' | 'replace'} [whenDraftExists] - how an existing draft is treated.
|
|
4092
|
+
* @returns {Promise<{ applied: boolean, status: 'applied' | 'preserved' | 'blocked' | 'unavailable', reference: object | null }>} the result and the held retention.
|
|
3639
4093
|
*/
|
|
3640
4094
|
async function beginPrefill(sessionId, text, whenDraftExists = 'append') {
|
|
3641
4095
|
const sessions = sessionService()
|
|
3642
4096
|
const conversation = clientContext === null ? null : clientContext.get('conversation')
|
|
3643
4097
|
if (sessions === null || sessions === undefined || conversation === null || conversation === undefined) {
|
|
3644
|
-
return { applied: false, reference: null }
|
|
4098
|
+
return { applied: false, status: 'unavailable', reference: null }
|
|
3645
4099
|
}
|
|
3646
4100
|
if (typeof sessions.retain !== 'function' || conversation.input === undefined
|
|
3647
4101
|
|| typeof conversation.input.requestDraftInitialization !== 'function') {
|
|
3648
|
-
return { applied: false, reference: null }
|
|
4102
|
+
return { applied: false, status: 'unavailable', reference: null }
|
|
3649
4103
|
}
|
|
3650
4104
|
let reference = null
|
|
3651
4105
|
try {
|
|
@@ -3657,24 +4111,32 @@ window.__ModuleLoader__.load({
|
|
|
3657
4111
|
// draft; resuming uses keep so an existing draft is never duplicated.
|
|
3658
4112
|
whenDraftExists,
|
|
3659
4113
|
})
|
|
3660
|
-
|
|
4114
|
+
const status = result === 'applied' || result === 'preserved' || result === 'blocked' ? result : 'blocked'
|
|
4115
|
+
return { applied: status === 'applied', status, reference }
|
|
3661
4116
|
} catch {
|
|
3662
4117
|
if (reference !== null) {
|
|
3663
4118
|
try { reference.release() } catch { /* already released */ }
|
|
3664
4119
|
}
|
|
3665
|
-
return { applied: false, reference: null }
|
|
4120
|
+
return { applied: false, status: 'blocked', reference: null }
|
|
3666
4121
|
}
|
|
3667
4122
|
}
|
|
3668
4123
|
|
|
3669
4124
|
/**
|
|
3670
|
-
* Open a Session in the host Conversation, leaving the workbench.
|
|
4125
|
+
* Open a Session in the host Conversation, leaving the workbench. An empty
|
|
4126
|
+
* or malformed id is refused here: handing it to the host would reveal
|
|
4127
|
+
* whatever conversation is current, which reads as "an unrelated session".
|
|
3671
4128
|
* @param {string} sessionId - target Session.
|
|
3672
|
-
* @returns {boolean} false when the workspace service is unavailable.
|
|
4129
|
+
* @returns {boolean} false when the id is unusable, the workspace service is unavailable, or opening threw.
|
|
3673
4130
|
*/
|
|
3674
4131
|
function openHostSession(sessionId) {
|
|
4132
|
+
if (typeof sessionId !== 'string' || sessionId === '') return false
|
|
3675
4133
|
const uiWorkspace = clientContext === null ? null : clientContext.get('uiWorkspace')
|
|
3676
4134
|
if (uiWorkspace === null || uiWorkspace === undefined || typeof uiWorkspace.openSession !== 'function') return false
|
|
3677
|
-
|
|
4135
|
+
try {
|
|
4136
|
+
uiWorkspace.openSession(sessionId)
|
|
4137
|
+
} catch {
|
|
4138
|
+
return false
|
|
4139
|
+
}
|
|
3678
4140
|
return true
|
|
3679
4141
|
}
|
|
3680
4142
|
|
|
@@ -5185,7 +5647,9 @@ window.__ModuleLoader__.load({
|
|
|
5185
5647
|
useEffect(() => {
|
|
5186
5648
|
void request('GET', 'engine').then(setEngine).catch(() => setEngine({ engine: '', source: 'missing' }))
|
|
5187
5649
|
}, [])
|
|
5188
|
-
const row = (label, ok, hint, action) => h('div', {
|
|
5650
|
+
const row = (label, ok, hint, action) => h('div', {
|
|
5651
|
+
className: `md-settings-row md-env-row ${ok ? 'md-env-row-ok' : 'md-env-row-missing'}`,
|
|
5652
|
+
},
|
|
5189
5653
|
h('span', null, `${ok ? '✓' : '✗'} ${label}`),
|
|
5190
5654
|
h('span', { className: 'md-shelf-sub' }, hint),
|
|
5191
5655
|
action === null ? null : action)
|
|
@@ -5198,6 +5662,7 @@ window.__ModuleLoader__.load({
|
|
|
5198
5662
|
}
|
|
5199
5663
|
return h(KitModal, {
|
|
5200
5664
|
title: format('envGuideTitle'),
|
|
5665
|
+
className: 'md-env-guide-modal',
|
|
5201
5666
|
onClose: props.onClose,
|
|
5202
5667
|
children: h('div', { className: 'md-env-guide' },
|
|
5203
5668
|
h('p', { className: 'md-shelf-sub' }, format('envGuideIntro')),
|
|
@@ -5284,6 +5749,33 @@ window.__ModuleLoader__.load({
|
|
|
5284
5749
|
)
|
|
5285
5750
|
}
|
|
5286
5751
|
|
|
5752
|
+
/**
|
|
5753
|
+
* The Python packages the bundled tools need, with the exact pip command and
|
|
5754
|
+
* a copy button. Shown on the library page and in Settings → 环境: a missing
|
|
5755
|
+
* package used to surface only as a traceback from a tool.
|
|
5756
|
+
* @returns {import('react').ReactElement} the row.
|
|
5757
|
+
*/
|
|
5758
|
+
function PipPackagesRow() {
|
|
5759
|
+
const [note, setNote] = useState('')
|
|
5760
|
+
const copy = () => {
|
|
5761
|
+
const text = format('envPipCommand')
|
|
5762
|
+
try {
|
|
5763
|
+
void navigator.clipboard.writeText(text)
|
|
5764
|
+
.then(() => setNote(format('envPipCopied')))
|
|
5765
|
+
.catch(() => setNote(text))
|
|
5766
|
+
} catch {
|
|
5767
|
+
setNote(text)
|
|
5768
|
+
}
|
|
5769
|
+
window.setTimeout(() => setNote(''), 1800)
|
|
5770
|
+
}
|
|
5771
|
+
return h('div', { className: 'md-settings-row' },
|
|
5772
|
+
h('span', null, `${format('envPipPackages')}:${format('envPipHint')}`),
|
|
5773
|
+
h('code', { className: 'md-path' }, format('envPipCommand')),
|
|
5774
|
+
h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: copy }, format('envPipCopy')),
|
|
5775
|
+
note === '' ? null : h('span', { className: 'md-shelf-sub' }, note)
|
|
5776
|
+
)
|
|
5777
|
+
}
|
|
5778
|
+
|
|
5287
5779
|
/**
|
|
5288
5780
|
* One page thumbnail: paints on demand when it scrolls near the viewport.
|
|
5289
5781
|
* The bitmap is sized in device pixels (CSS width × device pixel ratio) so a
|
|
@@ -5303,6 +5795,30 @@ window.__ModuleLoader__.load({
|
|
|
5303
5795
|
await page.render({ canvasContext: canvas.getContext('2d'), viewport }).promise
|
|
5304
5796
|
}
|
|
5305
5797
|
|
|
5798
|
+
/** Width of a split-panel thumbnail, in CSS pixels; 240 stays sharp at 2×. */
|
|
5799
|
+
const SPLIT_THUMB_WIDTH = 240
|
|
5800
|
+
|
|
5801
|
+
/**
|
|
5802
|
+
* One cached split-panel page image. `version` is the PDF identity hash the
|
|
5803
|
+
* Host returned, so a re-imported file gets new URLs instead of old pages.
|
|
5804
|
+
* @param {string} bookId - book id.
|
|
5805
|
+
* @param {string} code - chapter code.
|
|
5806
|
+
* @param {number} page - 1-based page.
|
|
5807
|
+
* @param {number} width - CSS width.
|
|
5808
|
+
* @param {string} version - Host cache version.
|
|
5809
|
+
* @returns {string} absolute image URL.
|
|
5810
|
+
*/
|
|
5811
|
+
function splitThumbUrl(bookId, code, page, width, version) {
|
|
5812
|
+
const query = new URLSearchParams({
|
|
5813
|
+
book: bookId,
|
|
5814
|
+
code,
|
|
5815
|
+
page: String(page),
|
|
5816
|
+
w: String(width),
|
|
5817
|
+
})
|
|
5818
|
+
if (typeof version === 'string' && version !== '') query.set('v', version)
|
|
5819
|
+
return new URL(`pdfdesk/pdf-thumb?${query.toString()}`, document.baseURI).href
|
|
5820
|
+
}
|
|
5821
|
+
|
|
5306
5822
|
/**
|
|
5307
5823
|
* 书库「+」与 设置 → 数据 共用的导入向导:选 PDF 包(ZIP)与可选笔记包,
|
|
5308
5824
|
* Host 解析成逐本书;已有相同 PDF 的书自动勾选并置灰(PDF 不重复导入),
|
|
@@ -5558,8 +6074,18 @@ window.__ModuleLoader__.load({
|
|
|
5558
6074
|
const book = props.book
|
|
5559
6075
|
const chapters = Array.isArray(book.chapters) ? book.chapters : []
|
|
5560
6076
|
const chapter = chapters.find(item => item.whole === true) ?? chapters[0]
|
|
6077
|
+
const bookId = typeof book.id === 'string' ? book.id : ''
|
|
6078
|
+
const chapterCode = chapter === undefined || typeof chapter.code !== 'string' ? '' : chapter.code
|
|
5561
6079
|
const [doc, setDoc] = useState(null)
|
|
5562
6080
|
const [count, setCount] = useState(0)
|
|
6081
|
+
// The Host renders thumbnails with PyMuPDF in milliseconds and caches
|
|
6082
|
+
// them, so the panel never has to parse a 90 MB PDF in the browser.
|
|
6083
|
+
// `pdfjs` stays as the fallback when Python/PyMuPDF is unavailable.
|
|
6084
|
+
const [thumbMode, setThumbMode] = useState('pending')
|
|
6085
|
+
const [layout, setLayout] = useState(null)
|
|
6086
|
+
const [thumbUrls, setThumbUrls] = useState({})
|
|
6087
|
+
const thumbUrlsRef = useRef({})
|
|
6088
|
+
thumbUrlsRef.current = thumbUrls
|
|
5563
6089
|
const [cuts, setCuts] = useState(() => new Set())
|
|
5564
6090
|
const [busy, setBusy] = useState(false)
|
|
5565
6091
|
const [note, setNote] = useState('')
|
|
@@ -5602,6 +6128,100 @@ window.__ModuleLoader__.load({
|
|
|
5602
6128
|
}
|
|
5603
6129
|
const scroller = useRef(null)
|
|
5604
6130
|
const attach = useRef(new Map())
|
|
6131
|
+
// Host-thumbnail bookkeeping: pages waiting for their first image, and one
|
|
6132
|
+
// debounced batch request at a time so scrolling cannot spawn a render
|
|
6133
|
+
// per page.
|
|
6134
|
+
const hostPending = useRef(new Set())
|
|
6135
|
+
const hostTimer = useRef(null)
|
|
6136
|
+
const hostBusy = useRef(false)
|
|
6137
|
+
const [flashPage, setFlashPage] = useState(0)
|
|
6138
|
+
const flashTimer = useRef(null)
|
|
6139
|
+
useEffect(() => () => {
|
|
6140
|
+
if (flashTimer.current !== null) clearTimeout(flashTimer.current)
|
|
6141
|
+
if (hostTimer.current !== null) clearTimeout(hostTimer.current)
|
|
6142
|
+
}, [])
|
|
6143
|
+
|
|
6144
|
+
/**
|
|
6145
|
+
* Ask the Host for the page geometry and one thumbnail range. The first
|
|
6146
|
+
* call also creates the cache; later calls for the same pages return
|
|
6147
|
+
* immediately from disk.
|
|
6148
|
+
* @param {number} from - first page.
|
|
6149
|
+
* @param {number} to - last page.
|
|
6150
|
+
* @returns {Promise<number | null>} page count, or null when the Host path is unavailable.
|
|
6151
|
+
*/
|
|
6152
|
+
const prepareHostThumbs = useCallback(async (from, to) => {
|
|
6153
|
+
if (bookId === '' || chapterCode === '') return null
|
|
6154
|
+
try {
|
|
6155
|
+
const payload = await request('POST', 'pdf-layout', {
|
|
6156
|
+
book: bookId,
|
|
6157
|
+
code: chapterCode,
|
|
6158
|
+
from,
|
|
6159
|
+
to,
|
|
6160
|
+
w: SPLIT_THUMB_WIDTH,
|
|
6161
|
+
}, 30000)
|
|
6162
|
+
if (payload === null || typeof payload !== 'object' || payload.ok !== true) return null
|
|
6163
|
+
const pages = Number(payload.pages)
|
|
6164
|
+
if (!Number.isFinite(pages) || pages <= 0) return null
|
|
6165
|
+
const version = typeof payload.v === 'string' ? payload.v : ''
|
|
6166
|
+
const pageWidth = Number(payload.pageWidth)
|
|
6167
|
+
const pageHeight = Number(payload.pageHeight)
|
|
6168
|
+
setLayout(current => {
|
|
6169
|
+
if (current !== null && current.v === version && current.pages === pages) return current
|
|
6170
|
+
return {
|
|
6171
|
+
pages,
|
|
6172
|
+
v: version,
|
|
6173
|
+
pageWidth: Number.isFinite(pageWidth) && pageWidth > 0 ? pageWidth : 0,
|
|
6174
|
+
pageHeight: Number.isFinite(pageHeight) && pageHeight > 0 ? pageHeight : 0,
|
|
6175
|
+
}
|
|
6176
|
+
})
|
|
6177
|
+
setCount(pages)
|
|
6178
|
+
const rendered = Array.isArray(payload.rendered) ? payload.rendered : []
|
|
6179
|
+
if (rendered.length > 0) {
|
|
6180
|
+
setThumbUrls(current => {
|
|
6181
|
+
let changed = false
|
|
6182
|
+
const next = { ...current }
|
|
6183
|
+
for (const page of rendered) {
|
|
6184
|
+
if (!Number.isInteger(page) || page < 1) continue
|
|
6185
|
+
const url = splitThumbUrl(bookId, chapterCode, page, SPLIT_THUMB_WIDTH, version)
|
|
6186
|
+
if (next[page] !== url) {
|
|
6187
|
+
next[page] = url
|
|
6188
|
+
changed = true
|
|
6189
|
+
}
|
|
6190
|
+
}
|
|
6191
|
+
return changed ? next : current
|
|
6192
|
+
})
|
|
6193
|
+
}
|
|
6194
|
+
return pages
|
|
6195
|
+
} catch {
|
|
6196
|
+
return null
|
|
6197
|
+
}
|
|
6198
|
+
}, [bookId, chapterCode])
|
|
6199
|
+
|
|
6200
|
+
/** Debounce one batch for the pages that just scrolled into range. */
|
|
6201
|
+
const scheduleHostThumbs = () => {
|
|
6202
|
+
if (hostTimer.current !== null) clearTimeout(hostTimer.current)
|
|
6203
|
+
hostTimer.current = window.setTimeout(() => {
|
|
6204
|
+
hostTimer.current = null
|
|
6205
|
+
void flushHostThumbs()
|
|
6206
|
+
}, 120)
|
|
6207
|
+
}
|
|
6208
|
+
|
|
6209
|
+
/** Render the pending page window (at most one batch in flight). */
|
|
6210
|
+
const flushHostThumbs = async () => {
|
|
6211
|
+
if (hostBusy.current) return
|
|
6212
|
+
const pages = [...hostPending.current].sort((left, right) => left - right)
|
|
6213
|
+
if (pages.length === 0) return
|
|
6214
|
+
const from = pages[0]
|
|
6215
|
+
const to = Math.min(from + 59, pages[pages.length - 1])
|
|
6216
|
+
for (const page of pages) if (page <= to) hostPending.current.delete(page)
|
|
6217
|
+
hostBusy.current = true
|
|
6218
|
+
try {
|
|
6219
|
+
await prepareHostThumbs(from, to)
|
|
6220
|
+
} finally {
|
|
6221
|
+
hostBusy.current = false
|
|
6222
|
+
}
|
|
6223
|
+
if (hostPending.current.size > 0) scheduleHostThumbs()
|
|
6224
|
+
}
|
|
5605
6225
|
|
|
5606
6226
|
useEffect(() => {
|
|
5607
6227
|
if (typeof window === 'undefined') return undefined
|
|
@@ -5610,7 +6230,25 @@ window.__ModuleLoader__.load({
|
|
|
5610
6230
|
return () => window.removeEventListener('keydown', onKey, true)
|
|
5611
6231
|
}, [])
|
|
5612
6232
|
|
|
6233
|
+
// Try the Host thumbnails first: page geometry arrives with the first
|
|
6234
|
+
// visible images, no PDF parsing in the browser. When Python/PyMuPDF is
|
|
6235
|
+
// missing the old in-browser pdf.js path takes over unchanged.
|
|
6236
|
+
useEffect(() => {
|
|
6237
|
+
if (chapterCode === '') {
|
|
6238
|
+
setThumbMode('pdfjs')
|
|
6239
|
+
return undefined
|
|
6240
|
+
}
|
|
6241
|
+
let alive = true
|
|
6242
|
+
void (async () => {
|
|
6243
|
+
const pages = await prepareHostThumbs(1, 12)
|
|
6244
|
+
if (!alive) return
|
|
6245
|
+
setThumbMode(pages === null ? 'pdfjs' : 'host')
|
|
6246
|
+
})()
|
|
6247
|
+
return () => { alive = false }
|
|
6248
|
+
}, [chapterCode, prepareHostThumbs])
|
|
6249
|
+
|
|
5613
6250
|
useEffect(() => {
|
|
6251
|
+
if (thumbMode !== 'pdfjs') return undefined
|
|
5614
6252
|
let alive = true
|
|
5615
6253
|
void (async () => {
|
|
5616
6254
|
try {
|
|
@@ -5626,16 +6264,14 @@ window.__ModuleLoader__.load({
|
|
|
5626
6264
|
}
|
|
5627
6265
|
})()
|
|
5628
6266
|
return () => { alive = false }
|
|
5629
|
-
}, [])
|
|
6267
|
+
}, [thumbMode])
|
|
5630
6268
|
|
|
5631
|
-
// One
|
|
5632
|
-
//
|
|
5633
|
-
//
|
|
5634
|
-
// another IntersectionObserver that re-rasterised the visible column on
|
|
5635
|
-
// every cut toggle — that was "thumbnails load too slowly".
|
|
6269
|
+
// One page frame per page. In Host mode the frame is observed so its
|
|
6270
|
+
// thumbnail can be requested; in the pdf.js fallback the canvas inside it
|
|
6271
|
+
// is painted once when the frame comes near the viewport.
|
|
5636
6272
|
const refCache = useRef(new Map())
|
|
5637
6273
|
const observerRef = useRef(null)
|
|
5638
|
-
const
|
|
6274
|
+
const thumbRef = number => {
|
|
5639
6275
|
let callback = refCache.current.get(number)
|
|
5640
6276
|
if (callback === undefined) {
|
|
5641
6277
|
callback = node => {
|
|
@@ -5652,16 +6288,28 @@ window.__ModuleLoader__.load({
|
|
|
5652
6288
|
return callback
|
|
5653
6289
|
}
|
|
5654
6290
|
useEffect(() => {
|
|
5655
|
-
if (
|
|
6291
|
+
if (typeof IntersectionObserver !== 'function') return undefined
|
|
6292
|
+
if (thumbMode === 'pending') return undefined
|
|
6293
|
+
if (thumbMode === 'pdfjs' && doc === null) return undefined
|
|
5656
6294
|
const observer = new IntersectionObserver(entries => {
|
|
5657
6295
|
for (const entry of entries) {
|
|
5658
6296
|
if (!entry.isIntersecting) continue
|
|
5659
6297
|
const node = entry.target
|
|
6298
|
+
if (thumbMode === 'host') {
|
|
6299
|
+
const page = Number(node.dataset.page)
|
|
6300
|
+
if (!Number.isInteger(page) || page < 1) continue
|
|
6301
|
+
if (thumbUrlsRef.current[page] !== undefined) continue
|
|
6302
|
+
hostPending.current.add(page)
|
|
6303
|
+
scheduleHostThumbs()
|
|
6304
|
+
continue
|
|
6305
|
+
}
|
|
5660
6306
|
if (node.dataset.painted === '1') continue
|
|
6307
|
+
const canvas = node.querySelector('canvas')
|
|
6308
|
+
if (canvas === null) continue
|
|
5661
6309
|
node.dataset.painted = '1'
|
|
5662
6310
|
observer.unobserve(node)
|
|
5663
6311
|
void doc.getPage(Number(node.dataset.page))
|
|
5664
|
-
.then(page => paintSplitThumb(page,
|
|
6312
|
+
.then(page => paintSplitThumb(page, canvas))
|
|
5665
6313
|
.catch(() => { node.dataset.painted = '0' })
|
|
5666
6314
|
}
|
|
5667
6315
|
}, { root: scroller.current, rootMargin: '600px' })
|
|
@@ -5671,7 +6319,7 @@ window.__ModuleLoader__.load({
|
|
|
5671
6319
|
observer.disconnect()
|
|
5672
6320
|
observerRef.current = null
|
|
5673
6321
|
}
|
|
5674
|
-
}, [doc])
|
|
6322
|
+
}, [doc, thumbMode])
|
|
5675
6323
|
|
|
5676
6324
|
const sorted = [...cuts].sort((first, second) => first - second)
|
|
5677
6325
|
const ranges = []
|
|
@@ -5685,7 +6333,12 @@ window.__ModuleLoader__.load({
|
|
|
5685
6333
|
if (start <= count) ranges.push([start, count])
|
|
5686
6334
|
const spec = ranges.map(([from, to]) => (from === to ? String(from) : `${from}-${to}`)).join(',')
|
|
5687
6335
|
const preview = ranges.slice(0, 6).map(([from, to], index) => `${book.id}_c${String(index).padStart(2, '0')}_${format('splitUntitled')}_p${String(from).padStart(3, '0')}-${String(to).padStart(3, '0')}.pdf`)
|
|
5688
|
-
|
|
6336
|
+
// Reserve each cell's height before its image arrives: a grid that grows
|
|
6337
|
+
// as thumbnails load re-lays out the whole book and is the main source of
|
|
6338
|
+
// scroll jank on large files.
|
|
6339
|
+
const pageAspect = layout !== null && layout.pageWidth > 0 && layout.pageHeight > 0
|
|
6340
|
+
? `${layout.pageWidth} / ${layout.pageHeight}`
|
|
6341
|
+
: undefined
|
|
5689
6342
|
const toggleCut = index => {
|
|
5690
6343
|
const next = new Set(cuts)
|
|
5691
6344
|
if (next.has(index)) next.delete(index)
|
|
@@ -5695,6 +6348,29 @@ window.__ModuleLoader__.load({
|
|
|
5695
6348
|
setRestored(0)
|
|
5696
6349
|
}
|
|
5697
6350
|
|
|
6351
|
+
/**
|
|
6352
|
+
* Scroll the thumbnail grid to one page and outline it for a moment. The
|
|
6353
|
+
* range line above the plans is the only place a long book's pages are
|
|
6354
|
+
* named, so its numbers are the jump entry. Never touches the cut plan.
|
|
6355
|
+
* @param {number} number - 1-based page to land on.
|
|
6356
|
+
* @returns {void}
|
|
6357
|
+
*/
|
|
6358
|
+
const jumpToPage = number => {
|
|
6359
|
+
const target = Math.max(1, Math.min(count > 0 ? count : 1, Math.round(Number(number) || 1)))
|
|
6360
|
+
const panel = scroller.current
|
|
6361
|
+
const node = attach.current.get(target)
|
|
6362
|
+
if (panel === null || node === undefined) return
|
|
6363
|
+
const rect = node.getBoundingClientRect()
|
|
6364
|
+
const top = rect.top - panel.getBoundingClientRect().top + panel.scrollTop - 8
|
|
6365
|
+
panel.scrollTo({ top: Math.max(0, Math.round(top)), behavior: 'smooth' })
|
|
6366
|
+
setFlashPage(target)
|
|
6367
|
+
if (flashTimer.current !== null) clearTimeout(flashTimer.current)
|
|
6368
|
+
flashTimer.current = window.setTimeout(() => {
|
|
6369
|
+
flashTimer.current = null
|
|
6370
|
+
setFlashPage(0)
|
|
6371
|
+
}, 1200)
|
|
6372
|
+
}
|
|
6373
|
+
|
|
5698
6374
|
useEffect(() => {
|
|
5699
6375
|
if (count === 0 || restoredOnce.current) return
|
|
5700
6376
|
restoredOnce.current = true
|
|
@@ -5708,7 +6384,7 @@ window.__ModuleLoader__.load({
|
|
|
5708
6384
|
try {
|
|
5709
6385
|
const result = await request('POST', 'split', { book: book.id, ranges: spec }, 300000)
|
|
5710
6386
|
setNote(format('splitDone', { files: ranges.length }))
|
|
5711
|
-
if (typeof props.onDone === 'function') props.onDone(result)
|
|
6387
|
+
if (typeof props.onDone === 'function') props.onDone({ ...(result ?? {}), files: ranges.length })
|
|
5712
6388
|
} catch (error) {
|
|
5713
6389
|
setNote(`${format('splitFailed')}:${String(error && error.message ? error.message : error)}`)
|
|
5714
6390
|
} finally {
|
|
@@ -5747,9 +6423,36 @@ window.__ModuleLoader__.load({
|
|
|
5747
6423
|
: Array.from({ length: count }, (_, index) => {
|
|
5748
6424
|
const number = index + 1
|
|
5749
6425
|
const cut = cuts.has(number)
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
6426
|
+
const hostGrid = thumbMode !== 'pdfjs'
|
|
6427
|
+
const thumbUrl = hostGrid ? thumbUrls[number] : undefined
|
|
6428
|
+
const frameClass = hostGrid ? 'md-split-page md-split-page-host' : 'md-split-page'
|
|
6429
|
+
return h('div', { key: number, className: number === flashPage ? 'md-split-item md-split-flash' : 'md-split-item' },
|
|
6430
|
+
h('div', {
|
|
6431
|
+
className: frameClass,
|
|
6432
|
+
ref: thumbRef(number),
|
|
6433
|
+
style: hostGrid && pageAspect !== undefined ? { aspectRatio: pageAspect } : undefined,
|
|
6434
|
+
},
|
|
6435
|
+
hostGrid
|
|
6436
|
+
? (thumbUrl === undefined
|
|
6437
|
+
? h('span', { className: 'md-split-thumb-wait', 'aria-hidden': true })
|
|
6438
|
+
: h('img', {
|
|
6439
|
+
className: 'md-split-thumb',
|
|
6440
|
+
src: thumbUrl,
|
|
6441
|
+
alt: '',
|
|
6442
|
+
loading: 'lazy',
|
|
6443
|
+
decoding: 'async',
|
|
6444
|
+
onError: () => {
|
|
6445
|
+
setThumbUrls(current => {
|
|
6446
|
+
if (current[number] === undefined) return current
|
|
6447
|
+
const next = { ...current }
|
|
6448
|
+
delete next[number]
|
|
6449
|
+
return next
|
|
6450
|
+
})
|
|
6451
|
+
hostPending.current.add(number)
|
|
6452
|
+
scheduleHostThumbs()
|
|
6453
|
+
},
|
|
6454
|
+
}))
|
|
6455
|
+
: h('canvas', null),
|
|
5753
6456
|
h('span', { className: cut ? 'md-split-num md-split-num-on' : 'md-split-num' }, number)),
|
|
5754
6457
|
number < count
|
|
5755
6458
|
? h('button', {
|
|
@@ -5766,9 +6469,30 @@ window.__ModuleLoader__.load({
|
|
|
5766
6469
|
})),
|
|
5767
6470
|
h('div', { className: 'md-split-side' },
|
|
5768
6471
|
h('h4', { className: 'md-settings-heading' }, format('splitRanges')),
|
|
5769
|
-
|
|
6472
|
+
// The numbers are the jump entry: clicking one scrolls the grid to
|
|
6473
|
+
// that page and outlines it. Long books are only browsable this way.
|
|
6474
|
+
h('p', { className: 'md-shelf-sub md-split-range' }, ranges.length === 0
|
|
5770
6475
|
? format('splitNeedCuts')
|
|
5771
|
-
: ranges.map(([from, to]) => (
|
|
6476
|
+
: ranges.map(([from, to], index) => h(React.Fragment, { key: `${from}-${to}-${index}` },
|
|
6477
|
+
index > 0 ? ' ' : null,
|
|
6478
|
+
h('button', {
|
|
6479
|
+
type: 'button',
|
|
6480
|
+
className: 'md-split-jump',
|
|
6481
|
+
title: format('splitJumpTo', { n: from }),
|
|
6482
|
+
onClick: () => jumpToPage(from),
|
|
6483
|
+
}, String(from)),
|
|
6484
|
+
to === from
|
|
6485
|
+
? null
|
|
6486
|
+
: [
|
|
6487
|
+
h('span', { key: 'dash', className: 'md-split-range-dash', 'aria-hidden': true }, '–'),
|
|
6488
|
+
h('button', {
|
|
6489
|
+
key: 'to',
|
|
6490
|
+
type: 'button',
|
|
6491
|
+
className: 'md-split-jump',
|
|
6492
|
+
title: format('splitJumpTo', { n: to }),
|
|
6493
|
+
onClick: () => jumpToPage(to),
|
|
6494
|
+
}, String(to)),
|
|
6495
|
+
]))),
|
|
5772
6496
|
restored > 0
|
|
5773
6497
|
? h('p', { className: 'md-settings-note' }, format('splitRestored', { n: restored }))
|
|
5774
6498
|
: null,
|
|
@@ -5794,6 +6518,90 @@ window.__ModuleLoader__.load({
|
|
|
5794
6518
|
}, busy ? format('splitBusy') : format('splitStart'))))))))
|
|
5795
6519
|
}
|
|
5796
6520
|
|
|
6521
|
+
/**
|
|
6522
|
+
* Post-split choices: remove the original whole-book PDF and/or return to
|
|
6523
|
+
* this library's split conversation. Both are real actions: the first moves
|
|
6524
|
+
* the PDF to 回收站, the second reopens (or creates) the split assistant.
|
|
6525
|
+
* @param {{ book: object, result: object, onClose: Function, onOpenConversation: Function, onRemoved: Function }} props - the whole book and the split result.
|
|
6526
|
+
* @returns {import('react').ReactElement} the dialog.
|
|
6527
|
+
*/
|
|
6528
|
+
function SplitResultDialog(props) {
|
|
6529
|
+
const book = props.book
|
|
6530
|
+
const bookId = String(book === null || book === undefined ? '' : book.id ?? '')
|
|
6531
|
+
const chapters = Array.isArray(book === null || book === undefined ? undefined : book.chapters) ? book.chapters : []
|
|
6532
|
+
const whole = chapters.find(chapter => chapter.whole === true) ?? chapters[0]
|
|
6533
|
+
const wholeFile = whole !== undefined && typeof whole.file === 'string' ? whole.file : bookId
|
|
6534
|
+
const files = Number(props.result === null || props.result === undefined ? 0 : props.result.files) || 0
|
|
6535
|
+
// The two answers survive a reload; a cancelled "以后再说" never writes.
|
|
6536
|
+
const [removeWhole, setRemoveWhole] = useState(() => readSplitResultChoice().removeWhole)
|
|
6537
|
+
const [openConversation, setOpenConversation] = useState(() => readSplitResultChoice().openConversation)
|
|
6538
|
+
const [busy, setBusy] = useState(false)
|
|
6539
|
+
const [error, setError] = useState('')
|
|
6540
|
+
const finish = async () => {
|
|
6541
|
+
if (busy) return
|
|
6542
|
+
setBusy(true)
|
|
6543
|
+
setError('')
|
|
6544
|
+
try {
|
|
6545
|
+
if (removeWhole) {
|
|
6546
|
+
await request('POST', 'trash-book', { book: bookId, file: wholeFile, whole: true })
|
|
6547
|
+
if (typeof props.onRemoved === 'function') await props.onRemoved()
|
|
6548
|
+
}
|
|
6549
|
+
if (openConversation) {
|
|
6550
|
+
const opened = typeof props.onOpenConversation === 'function'
|
|
6551
|
+
? await props.onOpenConversation()
|
|
6552
|
+
: false
|
|
6553
|
+
if (opened === false) {
|
|
6554
|
+
setError(format('splitResultOpenFailed'))
|
|
6555
|
+
setBusy(false)
|
|
6556
|
+
return
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6559
|
+
writeSplitResultChoice({ removeWhole, openConversation })
|
|
6560
|
+
props.onClose()
|
|
6561
|
+
} catch (failure) {
|
|
6562
|
+
setError(`${format('splitResultFailed')}:${String(failure && failure.message ? failure.message : failure)}`)
|
|
6563
|
+
setBusy(false)
|
|
6564
|
+
}
|
|
6565
|
+
}
|
|
6566
|
+
return h(KitModal, {
|
|
6567
|
+
title: format('splitResultTitle'),
|
|
6568
|
+
onClose: props.onClose,
|
|
6569
|
+
children: h(React.Fragment, null,
|
|
6570
|
+
h('p', { className: 'md-env-body' }, format('splitResultBody', { files, book: bookId })),
|
|
6571
|
+
h('div', { className: 'md-settings-row' },
|
|
6572
|
+
h('label', null,
|
|
6573
|
+
h('input', {
|
|
6574
|
+
type: 'checkbox',
|
|
6575
|
+
checked: removeWhole,
|
|
6576
|
+
disabled: busy,
|
|
6577
|
+
onChange: event => setRemoveWhole(event.target.checked),
|
|
6578
|
+
}),
|
|
6579
|
+
` ${format('splitResultRemoveAsk')}`)),
|
|
6580
|
+
h('p', { className: 'md-shelf-sub' }, format('splitResultRemoveHint')),
|
|
6581
|
+
h('div', { className: 'md-settings-row' },
|
|
6582
|
+
h('label', null,
|
|
6583
|
+
h('input', {
|
|
6584
|
+
type: 'checkbox',
|
|
6585
|
+
checked: openConversation,
|
|
6586
|
+
disabled: busy,
|
|
6587
|
+
onChange: event => setOpenConversation(event.target.checked),
|
|
6588
|
+
}),
|
|
6589
|
+
` ${format('splitResultOpenAsk')}`)),
|
|
6590
|
+
h('p', { className: 'md-shelf-sub' }, format('splitResultOpenHint')),
|
|
6591
|
+
error === '' ? null : h('p', { className: 'md-settings-note' }, error)),
|
|
6592
|
+
footer: [
|
|
6593
|
+
h(KitButton, {
|
|
6594
|
+
key: 'later', variant: 'ghost', disabled: busy,
|
|
6595
|
+
onClick: props.onClose,
|
|
6596
|
+
}, format('splitResultLater')),
|
|
6597
|
+
h(KitButton, {
|
|
6598
|
+
key: 'done', variant: 'primary', disabled: busy,
|
|
6599
|
+
onClick: () => { void finish() },
|
|
6600
|
+
}, busy ? format('dataWorking') : format('splitResultFinish')),
|
|
6601
|
+
],
|
|
6602
|
+
})
|
|
6603
|
+
}
|
|
6604
|
+
|
|
5797
6605
|
/**
|
|
5798
6606
|
* Modal adapter: host Modal owns the portal, focus trap, Escape and scrim;
|
|
5799
6607
|
* the fallback keeps the workbench shell.
|
|
@@ -5953,6 +6761,74 @@ window.__ModuleLoader__.load({
|
|
|
5953
6761
|
&& book.chapters.some(chapter => String(chapter.file ?? '') === stem)) ?? null
|
|
5954
6762
|
}
|
|
5955
6763
|
|
|
6764
|
+
/**
|
|
6765
|
+
* Every shelf a split book belongs in. A shelf that already holds the whole
|
|
6766
|
+
* book is where its split pieces belong, no matter where the split panel was
|
|
6767
|
+
* opened from; the shelf the split started in is included too, and the
|
|
6768
|
+
* hidden list is never a target (it is a filter, not a place).
|
|
6769
|
+
* @param {{ hidden?: string[], shelves?: object[] }} groups - stored groups.
|
|
6770
|
+
* @param {string} bookId - the whole book that was split.
|
|
6771
|
+
* @param {string | null} group - the group that was open when the split started.
|
|
6772
|
+
* @returns {string[]} target shelf ids, in shelf order.
|
|
6773
|
+
*/
|
|
6774
|
+
function splitTargetShelves(groups, bookId, group) {
|
|
6775
|
+
const shelves = groups !== null && groups !== undefined && Array.isArray(groups.shelves) ? groups.shelves : []
|
|
6776
|
+
const base = typeof bookId === 'string' ? wholeBaseId(bookId) : ''
|
|
6777
|
+
const targets = []
|
|
6778
|
+
for (const shelf of shelves) {
|
|
6779
|
+
if (shelf === null || shelf === undefined || shelf.id === 'hidden') continue
|
|
6780
|
+
if (base === '') continue
|
|
6781
|
+
const held = Array.isArray(shelf.books) ? shelf.books : []
|
|
6782
|
+
// Both sides drop a possible `@hash` suffix: the whole card and its
|
|
6783
|
+
// shelf entry can be the same file keyed slightly differently.
|
|
6784
|
+
if (!held.some(id => typeof id === 'string' && wholeBaseId(id) === base)) continue
|
|
6785
|
+
if (!targets.includes(shelf.id)) targets.push(shelf.id)
|
|
6786
|
+
}
|
|
6787
|
+
const started = group !== null && group !== undefined && group !== 'hidden' ? group : ''
|
|
6788
|
+
if (started !== '' && !targets.includes(started)) targets.push(started)
|
|
6789
|
+
return targets
|
|
6790
|
+
}
|
|
6791
|
+
|
|
6792
|
+
/**
|
|
6793
|
+
* The books one split wrote: split chapters whose `dir` is the whole book's
|
|
6794
|
+
* id. A split book's own id comes from the file names, so the folder is the
|
|
6795
|
+
* only reliable link back; the whole row carries `whole: true` and is not a
|
|
6796
|
+
* split result.
|
|
6797
|
+
* @param {object[]} books - catalog rows, freshly read.
|
|
6798
|
+
* @param {string} wholeId - id of the book that was split.
|
|
6799
|
+
* @returns {string[]} ids of the new split books.
|
|
6800
|
+
*/
|
|
6801
|
+
function splitBookIds(books, wholeId) {
|
|
6802
|
+
if (typeof wholeId !== 'string' || wholeId === '' || !Array.isArray(books)) return []
|
|
6803
|
+
return books.filter(item => item.dir === wholeId && item.whole !== true).map(item => item.id)
|
|
6804
|
+
}
|
|
6805
|
+
|
|
6806
|
+
/**
|
|
6807
|
+
* The split completion: wait for the refresh that lists the new folders,
|
|
6808
|
+
* find the books the split wrote, and file them into every shelf that held
|
|
6809
|
+
* the whole book (plus the shelf the split started from). The result dialog
|
|
6810
|
+
* opens only after this settles, so it never reads the stale catalog; a
|
|
6811
|
+
* failed or empty refresh still settles, as [].
|
|
6812
|
+
* @param {object} options - the whole book, its shelves and the workbench's refresh/store functions.
|
|
6813
|
+
* @param {object} options.book - the whole book that was split.
|
|
6814
|
+
* @param {string | null} options.group - the group that was open when the split started.
|
|
6815
|
+
* @param {{ hidden?: string[], shelves?: object[] }} options.groups - shelf groups as the split started.
|
|
6816
|
+
* @param {Function} options.reload - resolves with the refreshed catalog books.
|
|
6817
|
+
* @param {Function} options.saveShelfGroups - persists the next groups.
|
|
6818
|
+
* @returns {Promise<{ shelfIds: string[], ids: string[], added: number }>} the target shelves and what was filed.
|
|
6819
|
+
*/
|
|
6820
|
+
async function fileSplitBooks(options) {
|
|
6821
|
+
const freshBooks = await options.reload()
|
|
6822
|
+
const bookId = options.book === null || options.book === undefined ? '' : options.book.id
|
|
6823
|
+
const ids = splitBookIds(freshBooks, bookId)
|
|
6824
|
+
const targets = splitTargetShelves(options.groups, bookId, options.group)
|
|
6825
|
+
if (targets.length === 0 || ids.length === 0) return { shelfIds: targets, ids, added: 0 }
|
|
6826
|
+
const result = shelfAddBooksTo(options.groups, targets, ids)
|
|
6827
|
+
if (result === null) return { shelfIds: targets, ids, added: 0 }
|
|
6828
|
+
await options.saveShelfGroups(result.groups)
|
|
6829
|
+
return { shelfIds: targets, ids, added: result.added }
|
|
6830
|
+
}
|
|
6831
|
+
|
|
5956
6832
|
/**
|
|
5957
6833
|
* The shared "split a whole PDF by page" entry: pick a whole-book PDF and open
|
|
5958
6834
|
* the split panel, plus an optional "import a PDF and split it" shortcut. The
|
|
@@ -6007,6 +6883,9 @@ window.__ModuleLoader__.load({
|
|
|
6007
6883
|
// check, and the about/update row. Tabs keep it from becoming a long scroll.
|
|
6008
6884
|
const [tab, setTab] = useState(props.initialTab ?? 'reading')
|
|
6009
6885
|
const [pageCacheLimit, setPageCacheLimit] = useState(() => readPageCacheLimit())
|
|
6886
|
+
// Same value the import dialog's "remember" checkbox writes; the row here
|
|
6887
|
+
// is how the user gets the question back.
|
|
6888
|
+
const [importSplitChoice, setImportSplitChoice] = useState(() => readImportSplitChoice())
|
|
6010
6889
|
// Reading/AI mode: daily (short answers) or quality (expanded), plus the
|
|
6011
6890
|
// editable style instruction each mode puts into a new session's seed.
|
|
6012
6891
|
const [aiMode, setAiMode] = useState(() => readAiMode())
|
|
@@ -6554,6 +7433,19 @@ window.__ModuleLoader__.load({
|
|
|
6554
7433
|
onClick: props.onRailSide,
|
|
6555
7434
|
}, props.railSide === 'left' ? format('railLeft') : format('railRight'))
|
|
6556
7435
|
),
|
|
7436
|
+
h('div', { className: 'md-settings-row' },
|
|
7437
|
+
h('span', { title: format('settingsImportSplitHint') }, format('settingsImportSplit')),
|
|
7438
|
+
h('select', {
|
|
7439
|
+
className: 'md-settings-input',
|
|
7440
|
+
value: importSplitChoice,
|
|
7441
|
+
'aria-label': format('settingsImportSplit'),
|
|
7442
|
+
onChange: event => setImportSplitChoice(writeImportSplitChoice(event.target.value)),
|
|
7443
|
+
},
|
|
7444
|
+
h('option', { value: 'ask' }, format('importSplitChoiceAsk')),
|
|
7445
|
+
h('option', { value: 'split' }, format('importSplitChoiceSplit')),
|
|
7446
|
+
h('option', { value: 'later' }, format('importSplitChoiceLater')))
|
|
7447
|
+
),
|
|
7448
|
+
h('p', { className: 'md-shelf-sub' }, format('settingsImportSplitHint')),
|
|
6557
7449
|
h('div', { className: 'md-settings-row' },
|
|
6558
7450
|
h('span', { title: format('readCacheLimitHint') }, format('readCacheLimit')),
|
|
6559
7451
|
h('select', {
|
|
@@ -6742,6 +7634,9 @@ window.__ModuleLoader__.load({
|
|
|
6742
7634
|
h('span', null, `${format('envPython')}:${envTools.python ? format('envOn') : format('envOff')}(${format('envPythonSize')})`),
|
|
6743
7635
|
envTools.python ? null : h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink('https://www.python.org/downloads/windows/') }, format('envDownload'))
|
|
6744
7636
|
),
|
|
7637
|
+
// The two pip packages every bundled tool needs (split, text, raster,
|
|
7638
|
+
// overlay): same row as the library page, with the command to copy.
|
|
7639
|
+
h(PipPackagesRow),
|
|
6745
7640
|
h('div', { className: 'md-settings-row' },
|
|
6746
7641
|
h('span', null, `${format('envTex')}:${envTools.tex ? format('envOn') : format('envOff')}(${format('envTexSize')})`),
|
|
6747
7642
|
envTools.tex ? null : h(KitButton, { type: 'button', className: 'md-btn md-btn-small', onClick: () => openLink(TEXLIVE_URL) }, format('envDownload'))
|
|
@@ -6816,7 +7711,8 @@ window.__ModuleLoader__.load({
|
|
|
6816
7711
|
props.updateOperation === null
|
|
6817
7712
|
? null
|
|
6818
7713
|
: h('p', { className: 'md-settings-note', role: 'status' }, props.updateOperation.message),
|
|
6819
|
-
h('p', { className: 'md-shelf-sub' }, hostUi !== null ? format('hostUiLoaded') : format('hostUiFallback'))
|
|
7714
|
+
h('p', { className: 'md-shelf-sub' }, hostUi !== null ? format('hostUiLoaded') : format('hostUiFallback')),
|
|
7715
|
+
h('p', { className: 'md-settings-note' }, format('aboutCopyright'))
|
|
6820
7716
|
)
|
|
6821
7717
|
// Which measured folder each row stands for; the Host only sends keys.
|
|
6822
7718
|
const storageLabel = {
|
|
@@ -7621,6 +8517,7 @@ window.__ModuleLoader__.load({
|
|
|
7621
8517
|
h('li', null, format('manualNaming1')),
|
|
7622
8518
|
h('li', null, format('manualNaming2')),
|
|
7623
8519
|
h('li', null, format('manualNaming3')),
|
|
8520
|
+
h('li', null, format('splitStaysWhole')),
|
|
7624
8521
|
h('li', null, format('manualSessionLine'))
|
|
7625
8522
|
)
|
|
7626
8523
|
),
|
|
@@ -7712,6 +8609,7 @@ window.__ModuleLoader__.load({
|
|
|
7712
8609
|
h('div', { className: 'md-tool-card' },
|
|
7713
8610
|
h('h3', { className: 'md-subheading' }, format('splitToolTitle')),
|
|
7714
8611
|
h('p', { className: 'md-shelf-sub' }, format('splitToolCardHint')),
|
|
8612
|
+
h('p', { className: 'md-shelf-sub' }, format('splitStaysWhole')),
|
|
7715
8613
|
h('p', { className: 'md-shelf-sub' }, `${format('splitWorkspace')}:${props.workspaceLabel === '' ? format('workspaceNotChosen') : props.workspaceLabel}`),
|
|
7716
8614
|
h('div', { className: 'md-library-tools' },
|
|
7717
8615
|
h(KitButton, {
|
|
@@ -7737,6 +8635,10 @@ window.__ModuleLoader__.load({
|
|
|
7737
8635
|
h('div', { className: 'md-tool-card', id: 'md-env-card' },
|
|
7738
8636
|
h('h3', { className: 'md-subheading' }, format('envTitle')),
|
|
7739
8637
|
h('p', { className: 'md-shelf-sub' }, `${format('envPython')}:${envTools.python ? format('envOn') : format('envOff')} · ${format('envTex')}:${envTools.tex ? format('envOn') : format('envOff')}`),
|
|
8638
|
+
// Everything that has to be installed, with its channel, on the page a
|
|
8639
|
+
// new user lands on: Python + the pip packages, the typesetter, TeX.
|
|
8640
|
+
PipPackagesRow(),
|
|
8641
|
+
h(EngineStatusRow),
|
|
7740
8642
|
h('div', { className: 'md-library-tools' },
|
|
7741
8643
|
envTools.python ? null : h(KitButton, {
|
|
7742
8644
|
type: 'button', className: 'md-btn md-btn-small',
|
|
@@ -7802,16 +8704,20 @@ window.__ModuleLoader__.load({
|
|
|
7802
8704
|
}, props.text)
|
|
7803
8705
|
}
|
|
7804
8706
|
|
|
8707
|
+
/**
|
|
8708
|
+
* The shelf grid, its selection marquee and the per-shelf actions. Which
|
|
8709
|
+
* books belong here, which are shown and how many there are arrives as
|
|
8710
|
+
* `view` from `shelfView`; this component only renders it and handles the
|
|
8711
|
+
* pointer.
|
|
8712
|
+
* @param {{ view: object, showWhole: boolean, showLoose: boolean, onToggleWhole: Function, onToggleLoose: Function, cardRefs: object, selected: Set<string>, covers: Set<string>, group: string | null, showAddPdf: boolean, canAddToShelf: boolean, wholeFormApplicable: boolean, wholeFormAllPinned: boolean, onSelect: Function, onToggle: Function, onOpen: Function, registerRef: Function, onOpenGroup: Function, onDeleteGroup: Function, onCreateShelf: Function, onAddToShelf: Function, onHide: Function, onUnhide: Function, onRemoveFromShelf: Function, onWholeForm: Function, onResetWholeForms: Function, onTrashSelected: Function, onClear: Function, onImportPdf?: Function }} props - the view and the workbench's actions.
|
|
8713
|
+
* @returns {import('react').ReactElement} the shelf.
|
|
8714
|
+
*/
|
|
7805
8715
|
function Shelf(props) {
|
|
8716
|
+
const view = props.view
|
|
7806
8717
|
const surfaceRef = useRef(null)
|
|
7807
8718
|
const startRef = useRef(null)
|
|
7808
8719
|
const boxRef = useRef(null)
|
|
7809
8720
|
const [box, setBox] = useState(null)
|
|
7810
|
-
// Two independent switches: whole, unsplit books, and books that were split
|
|
7811
|
-
// but named by hand. Both default to shown — a readable PDF must not
|
|
7812
|
-
// vanish from the library because of its file name.
|
|
7813
|
-
const [showWhole, setShowWhole] = useState(() => readShelfFlag(SHOW_WHOLE_KEY))
|
|
7814
|
-
const [showLoose, setShowLoose] = useState(() => readShelfFlag(SHOW_LOOSE_KEY))
|
|
7815
8721
|
const boundsOf = () => (surfaceRef.current === null ? null : surfaceRef.current.getBoundingClientRect())
|
|
7816
8722
|
const onPointerDown = event => {
|
|
7817
8723
|
if (event.button !== 0) return
|
|
@@ -7862,14 +8768,14 @@ window.__ModuleLoader__.load({
|
|
|
7862
8768
|
}
|
|
7863
8769
|
props.onSelect(ids, start.additive)
|
|
7864
8770
|
}
|
|
7865
|
-
const empty =
|
|
7866
|
-
const
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
const
|
|
7872
|
-
|
|
8771
|
+
const empty = view.empty
|
|
8772
|
+
const wholeTotal = view.counts.whole
|
|
8773
|
+
const looseTotal = view.counts.loose
|
|
8774
|
+
const wholeAlwaysTotal = view.counts.pinned
|
|
8775
|
+
// The add-PDF card belongs to the main shelf and to a custom shelf whose
|
|
8776
|
+
// header switch is on; the hidden shelf never offers it.
|
|
8777
|
+
const importTile = typeof props.onImportPdf === 'function'
|
|
8778
|
+
&& (props.group === null || (props.group !== 'hidden' && props.showAddPdf !== false))
|
|
7873
8779
|
return h('div', {
|
|
7874
8780
|
className: 'md-shelf',
|
|
7875
8781
|
ref: surfaceRef,
|
|
@@ -7877,54 +8783,52 @@ window.__ModuleLoader__.load({
|
|
|
7877
8783
|
onPointerMove,
|
|
7878
8784
|
onPointerUp,
|
|
7879
8785
|
},
|
|
7880
|
-
|
|
8786
|
+
// The switches describe the main shelf; explicit shelves show all contents.
|
|
8787
|
+
view.explicit || (wholeTotal === 0 && looseTotal === 0 && wholeAlwaysTotal === 0)
|
|
7881
8788
|
? null
|
|
7882
8789
|
: h('div', { className: 'md-shelf-loose' },
|
|
7883
8790
|
wholeTotal === 0 ? null : h(KitButton, {
|
|
7884
8791
|
type: 'button', className: 'md-btn md-btn-small',
|
|
7885
8792
|
title: format('shelfWholeHint'),
|
|
7886
|
-
'aria-pressed': showWhole ? 'true' : 'false',
|
|
7887
|
-
onClick:
|
|
7888
|
-
|
|
7889
|
-
setShowWhole(next)
|
|
7890
|
-
writeShelfFlag(SHOW_WHOLE_KEY, next)
|
|
7891
|
-
},
|
|
7892
|
-
}, `${format('shelfWhole')}${showWhole ? format('shelfShown') : format('shelfHidden')} (${wholeTotal})`),
|
|
8793
|
+
'aria-pressed': props.showWhole ? 'true' : 'false',
|
|
8794
|
+
onClick: props.onToggleWhole,
|
|
8795
|
+
}, `${format('shelfWhole')}${props.showWhole ? format('shelfShown') : format('shelfHidden')} (${wholeTotal})`),
|
|
7893
8796
|
looseTotal === 0 ? null : h(KitButton, {
|
|
7894
8797
|
type: 'button', className: 'md-btn md-btn-small',
|
|
7895
8798
|
title: format('shelfLooseHint'),
|
|
7896
|
-
'aria-pressed': showLoose ? 'true' : 'false',
|
|
7897
|
-
onClick:
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
8799
|
+
'aria-pressed': props.showLoose ? 'true' : 'false',
|
|
8800
|
+
onClick: props.onToggleLoose,
|
|
8801
|
+
}, `${format('shelfLoose')}${props.showLoose ? format('shelfShown') : format('shelfHidden')} (${looseTotal})`),
|
|
8802
|
+
wholeAlwaysTotal === 0 ? null : h(KitButton, {
|
|
8803
|
+
type: 'button', className: 'md-btn md-btn-small md-btn-ghost',
|
|
8804
|
+
title: format('shelfWholeResetHint'),
|
|
8805
|
+
onClick: props.onResetWholeForms,
|
|
8806
|
+
}, format('shelfWholeReset', { n: wholeAlwaysTotal }))
|
|
7903
8807
|
),
|
|
7904
8808
|
empty
|
|
7905
8809
|
? h('div', { className: 'md-empty' },
|
|
7906
8810
|
h('div', { className: 'md-empty-title' }, format('shelfEmpty')),
|
|
7907
8811
|
h('div', { className: 'md-empty-hint' }, format('emptyHint')),
|
|
7908
|
-
|
|
7909
|
-
?
|
|
7910
|
-
: h('div', { className: 'md-empty-actions' },
|
|
8812
|
+
importTile
|
|
8813
|
+
? h('div', { className: 'md-empty-actions' },
|
|
7911
8814
|
h(KitButton, {
|
|
7912
8815
|
type: 'button', className: 'md-btn',
|
|
7913
8816
|
onClick: props.onImportPdf,
|
|
7914
8817
|
}, format('importTileTitle')))
|
|
8818
|
+
: null
|
|
7915
8819
|
)
|
|
7916
|
-
: visibleBooks.length === 0 &&
|
|
8820
|
+
: view.visibleBooks.length === 0 && view.collections.length === 0
|
|
7917
8821
|
? h('div', { className: 'md-empty' },
|
|
7918
8822
|
h('div', { className: 'md-empty-title' }, format('looseOnlyEmpty')))
|
|
7919
8823
|
: h('div', { className: 'md-grid' },
|
|
7920
|
-
|
|
8824
|
+
view.collections.map(item => h(CollectionCard, {
|
|
7921
8825
|
key: item.id,
|
|
7922
8826
|
name: item.name,
|
|
7923
8827
|
count: item.count,
|
|
7924
8828
|
onOpen: () => props.onOpenGroup(item.id),
|
|
7925
8829
|
onDelete: () => props.onDeleteGroup(item.id),
|
|
7926
8830
|
})),
|
|
7927
|
-
visibleBooks.map(book => h(BookCard, {
|
|
8831
|
+
view.visibleBooks.map(book => h(BookCard, {
|
|
7928
8832
|
key: book.id,
|
|
7929
8833
|
book,
|
|
7930
8834
|
selected: props.selected.has(book.id),
|
|
@@ -7933,11 +8837,10 @@ window.__ModuleLoader__.load({
|
|
|
7933
8837
|
onOpen: props.onOpen,
|
|
7934
8838
|
registerRef: props.registerRef,
|
|
7935
8839
|
})),
|
|
7936
|
-
// The import tile
|
|
7937
|
-
//
|
|
7938
|
-
|
|
7939
|
-
?
|
|
7940
|
-
: h(KitButton, {
|
|
8840
|
+
// The import tile ends the main shelf and a custom shelf (its header
|
|
8841
|
+
// switch decides); the imported file still lands in 整本\.
|
|
8842
|
+
importTile
|
|
8843
|
+
? h(KitButton, {
|
|
7941
8844
|
key: '__import',
|
|
7942
8845
|
type: 'button', className: 'md-card md-card-add',
|
|
7943
8846
|
title: format('importTileHint'),
|
|
@@ -7948,6 +8851,7 @@ window.__ModuleLoader__.load({
|
|
|
7948
8851
|
h('span', { className: 'md-card-body' },
|
|
7949
8852
|
h('span', { className: 'md-card-title' }, format('importTileTitle')),
|
|
7950
8853
|
h('span', { className: 'md-card-sub' }, format('importTileHint'))))
|
|
8854
|
+
: null
|
|
7951
8855
|
),
|
|
7952
8856
|
box === null
|
|
7953
8857
|
? null
|
|
@@ -7964,6 +8868,15 @@ window.__ModuleLoader__.load({
|
|
|
7964
8868
|
type: 'button', className: 'md-btn md-btn-small',
|
|
7965
8869
|
onClick: props.onCreateShelf,
|
|
7966
8870
|
}, format('shelfNew')),
|
|
8871
|
+
// Second way to file a selection: join a shelf that already exists.
|
|
8872
|
+
props.group === 'hidden'
|
|
8873
|
+
? null
|
|
8874
|
+
: h(KitButton, {
|
|
8875
|
+
type: 'button', className: 'md-btn md-btn-small',
|
|
8876
|
+
disabled: props.canAddToShelf !== true,
|
|
8877
|
+
title: props.canAddToShelf === true ? undefined : format('shelfAddToEmpty'),
|
|
8878
|
+
onClick: props.onAddToShelf,
|
|
8879
|
+
}, format('shelfAddTo')),
|
|
7967
8880
|
props.group === 'hidden'
|
|
7968
8881
|
? h(KitButton, {
|
|
7969
8882
|
type: 'button', className: 'md-btn md-btn-small',
|
|
@@ -7973,6 +8886,17 @@ window.__ModuleLoader__.load({
|
|
|
7973
8886
|
type: 'button', className: 'md-btn md-btn-small',
|
|
7974
8887
|
onClick: props.onHide,
|
|
7975
8888
|
}, format('shelfHide')),
|
|
8889
|
+
// Next to "hide": pin this book's whole-PDF form so the global
|
|
8890
|
+
// switch cannot hide it, or unpin it again. The card stays visible
|
|
8891
|
+
// either way, so the choice can always be undone.
|
|
8892
|
+
props.group === 'hidden'
|
|
8893
|
+
? null
|
|
8894
|
+
: h(KitButton, {
|
|
8895
|
+
type: 'button', className: 'md-btn md-btn-small',
|
|
8896
|
+
title: format('shelfWholeFormHint'),
|
|
8897
|
+
disabled: props.wholeFormApplicable !== true,
|
|
8898
|
+
onClick: props.onWholeForm,
|
|
8899
|
+
}, props.wholeFormAllPinned === true ? format('shelfWholeUnpinForm') : format('shelfWholePinForm')),
|
|
7976
8900
|
props.group === 'hidden'
|
|
7977
8901
|
? h(KitButton, {
|
|
7978
8902
|
type: 'button', className: 'md-btn md-btn-small',
|
|
@@ -8020,6 +8944,34 @@ window.__ModuleLoader__.load({
|
|
|
8020
8944
|
})
|
|
8021
8945
|
}
|
|
8022
8946
|
|
|
8947
|
+
/**
|
|
8948
|
+
* Pick which existing shelf the selected books join. One row per shelf, the
|
|
8949
|
+
* same row shape the import picker uses.
|
|
8950
|
+
* @param {{ shelves: object[], count: number, onPick: Function, onClose: Function }} props - shelves, selection size and handlers.
|
|
8951
|
+
* @returns {import('react').ReactElement} the dialog.
|
|
8952
|
+
*/
|
|
8953
|
+
function ShelfPickDialog(props) {
|
|
8954
|
+
const shelves = Array.isArray(props.shelves) ? props.shelves : []
|
|
8955
|
+
return h(KitModal, {
|
|
8956
|
+
title: format('shelfAddToTitle'),
|
|
8957
|
+
onClose: props.onClose,
|
|
8958
|
+
children: h('div', { className: 'md-picker' },
|
|
8959
|
+
h('div', { className: 'md-picker-sub' }, format('shelfAddToHint', { n: props.count })),
|
|
8960
|
+
shelves.length === 0
|
|
8961
|
+
? h('div', { className: 'md-picker-empty' }, format('shelfAddToEmpty'))
|
|
8962
|
+
: h('ul', { className: 'md-picker-list' }, shelves.map(shelf => h('li', { key: shelf.id },
|
|
8963
|
+
h(KitButton, {
|
|
8964
|
+
type: 'button',
|
|
8965
|
+
className: 'md-picker-row',
|
|
8966
|
+
onClick: () => props.onPick(shelf.id),
|
|
8967
|
+
},
|
|
8968
|
+
h('span', { className: 'md-picker-name' }, shelf.name),
|
|
8969
|
+
h('span', { className: 'md-picker-time' }, format('shelfBookCount', { n: shelf.books.length })))))),
|
|
8970
|
+
),
|
|
8971
|
+
footer: [h(KitButton, { key: 'close', variant: 'ghost', onClick: props.onClose }, format('previewClose'))],
|
|
8972
|
+
})
|
|
8973
|
+
}
|
|
8974
|
+
|
|
8023
8975
|
/**
|
|
8024
8976
|
* The three session groups, their per-group New and Import buttons, and the
|
|
8025
8977
|
* inline rename/unlink actions on each row inside one chapter.
|
|
@@ -10988,6 +11940,90 @@ window.__ModuleLoader__.load({
|
|
|
10988
11940
|
}
|
|
10989
11941
|
}
|
|
10990
11942
|
|
|
11943
|
+
/* ------------------------------------------------ import split ask -- */
|
|
11944
|
+
|
|
11945
|
+
/** Where the remembered "split it now?" answer lives. */
|
|
11946
|
+
const IMPORT_SPLIT_KEY = 'pdfdesk:import-split'
|
|
11947
|
+
|
|
11948
|
+
/** The three answers: ask every time, split by itself, never ask. */
|
|
11949
|
+
const IMPORT_SPLIT_CHOICES = ['ask', 'split', 'later']
|
|
11950
|
+
|
|
11951
|
+
/**
|
|
11952
|
+
* The remembered answer to "split it now?" after an import.
|
|
11953
|
+
* @returns {'ask'|'split'|'later'} the stored choice (`ask` when nothing is stored).
|
|
11954
|
+
*/
|
|
11955
|
+
function readImportSplitChoice() {
|
|
11956
|
+
try {
|
|
11957
|
+
const raw = window.localStorage.getItem(IMPORT_SPLIT_KEY)
|
|
11958
|
+
return IMPORT_SPLIT_CHOICES.includes(raw) ? raw : 'ask'
|
|
11959
|
+
} catch {
|
|
11960
|
+
return 'ask'
|
|
11961
|
+
}
|
|
11962
|
+
}
|
|
11963
|
+
|
|
11964
|
+
/**
|
|
11965
|
+
* Remember the answer; `ask` is what the settings row writes to restore the
|
|
11966
|
+
* question.
|
|
11967
|
+
* @param {string} value - `ask`, `split` or `later`.
|
|
11968
|
+
* @returns {'ask'|'split'|'later'} the stored choice.
|
|
11969
|
+
*/
|
|
11970
|
+
function writeImportSplitChoice(value) {
|
|
11971
|
+
const next = IMPORT_SPLIT_CHOICES.includes(value) ? value : 'ask'
|
|
11972
|
+
try {
|
|
11973
|
+
window.localStorage.setItem(IMPORT_SPLIT_KEY, next)
|
|
11974
|
+
} catch {
|
|
11975
|
+
// storage unavailable
|
|
11976
|
+
}
|
|
11977
|
+
return next
|
|
11978
|
+
}
|
|
11979
|
+
|
|
11980
|
+
/* --------------------------------------------- split result memory -- */
|
|
11981
|
+
|
|
11982
|
+
/** Where the two post-split choices are remembered. */
|
|
11983
|
+
const SPLIT_RESULT_KEY = 'pdfdesk:split-result'
|
|
11984
|
+
|
|
11985
|
+
/** Default before the reader has finished a split: keep the whole, open the conversation. */
|
|
11986
|
+
const SPLIT_RESULT_DEFAULT = Object.freeze({ removeWhole: false, openConversation: true })
|
|
11987
|
+
|
|
11988
|
+
/**
|
|
11989
|
+
* The remembered post-split choices. Missing, malformed or non-boolean
|
|
11990
|
+
* storage falls back to the defaults instead of leaking a stale value in.
|
|
11991
|
+
* @returns {{ removeWhole: boolean, openConversation: boolean }} the choices.
|
|
11992
|
+
*/
|
|
11993
|
+
function readSplitResultChoice() {
|
|
11994
|
+
try {
|
|
11995
|
+
const raw = window.localStorage.getItem(SPLIT_RESULT_KEY)
|
|
11996
|
+
if (raw === null || raw === '') return { ...SPLIT_RESULT_DEFAULT }
|
|
11997
|
+
const parsed = JSON.parse(raw)
|
|
11998
|
+
if (parsed === null || typeof parsed !== 'object') return { ...SPLIT_RESULT_DEFAULT }
|
|
11999
|
+
return {
|
|
12000
|
+
removeWhole: parsed.removeWhole === true,
|
|
12001
|
+
openConversation: parsed.openConversation !== false,
|
|
12002
|
+
}
|
|
12003
|
+
} catch {
|
|
12004
|
+
return { ...SPLIT_RESULT_DEFAULT }
|
|
12005
|
+
}
|
|
12006
|
+
}
|
|
12007
|
+
|
|
12008
|
+
/**
|
|
12009
|
+
* Remember the choices applied by "完成". "以后再说" closes the dialog
|
|
12010
|
+
* without writing, so cancelling never overwrites the last applied choice.
|
|
12011
|
+
* @param {{ removeWhole: boolean, openConversation: boolean }} choice - applied choices.
|
|
12012
|
+
* @returns {{ removeWhole: boolean, openConversation: boolean }} what was stored.
|
|
12013
|
+
*/
|
|
12014
|
+
function writeSplitResultChoice(choice) {
|
|
12015
|
+
const next = {
|
|
12016
|
+
removeWhole: choice !== null && choice !== undefined && choice.removeWhole === true,
|
|
12017
|
+
openConversation: choice === null || choice === undefined || choice.openConversation !== false,
|
|
12018
|
+
}
|
|
12019
|
+
try {
|
|
12020
|
+
window.localStorage.setItem(SPLIT_RESULT_KEY, JSON.stringify(next))
|
|
12021
|
+
} catch {
|
|
12022
|
+
// storage unavailable: the choice still applies to this dialog
|
|
12023
|
+
}
|
|
12024
|
+
return next
|
|
12025
|
+
}
|
|
12026
|
+
|
|
10991
12027
|
/** How much chapter context a new session gets: `daily` (web-chat-like) or `quality` (whole chapter). */
|
|
10992
12028
|
const AI_MODE_KEY = 'pdfdesk:ai-mode'
|
|
10993
12029
|
|
|
@@ -12125,7 +13161,11 @@ window.__ModuleLoader__.load({
|
|
|
12125
13161
|
void props.doc.getPage(props.pageNumber).then(page => {
|
|
12126
13162
|
const height = page.getViewport({ scale: 1 }).height
|
|
12127
13163
|
cache.set(props.pageNumber, height)
|
|
12128
|
-
if (
|
|
13164
|
+
if (cancelled) return
|
|
13165
|
+
setBaseHeight(height)
|
|
13166
|
+
// The column caches this for its ghost slots; the write alone does not
|
|
13167
|
+
// re-render them, so say so.
|
|
13168
|
+
if (typeof props.onMeasured === 'function') props.onMeasured()
|
|
12129
13169
|
}).catch(() => {})
|
|
12130
13170
|
return () => { cancelled = true }
|
|
12131
13171
|
}, [props.doc, props.pageNumber])
|
|
@@ -12233,6 +13273,10 @@ window.__ModuleLoader__.load({
|
|
|
12233
13273
|
// off-centre and left no paper to move into on the left.
|
|
12234
13274
|
const columnRef = useRef(null)
|
|
12235
13275
|
const [pageWidth, setPageWidth] = useState(0)
|
|
13276
|
+
// Bumped when a mounted page caches its real height: the ghost slots below
|
|
13277
|
+
// need that number, and the WeakMap write itself does not re-render.
|
|
13278
|
+
const [, setHeightVersion] = useState(0)
|
|
13279
|
+
const noteHeight = useCallback(() => setHeightVersion(value => value + 1), [])
|
|
12236
13280
|
useEffect(() => {
|
|
12237
13281
|
const column = columnRef.current
|
|
12238
13282
|
const canvas = column === null ? null : column.querySelector('.md-reader-canvas')
|
|
@@ -12264,6 +13308,66 @@ window.__ModuleLoader__.load({
|
|
|
12264
13308
|
// cheap ghosts until the reader approaches them.
|
|
12265
13309
|
const from = Math.max(1, current - 12)
|
|
12266
13310
|
const to = Math.min(total, current + 12)
|
|
13311
|
+
// Height one ghost must reserve. A ghost used to be 240px tall while a real
|
|
13312
|
+
// page is ~1000px, so every time the mounted window moved, the pages that
|
|
13313
|
+
// left it collapsed and pulled the column thousands of pixels up: a normal
|
|
13314
|
+
// scroll landed outside the mounted band, where nothing is mounted to
|
|
13315
|
+
// report a new page — the column stayed blank. Reserving a measured page's
|
|
13316
|
+
// real height keeps the column's total height stable while the window
|
|
13317
|
+
// moves. Cheap enough: a WeakMap lookup, no extra getPage.
|
|
13318
|
+
const measuredHeights = pageHeightCache.get(props.doc)
|
|
13319
|
+
const measuredBase = measuredHeights === undefined
|
|
13320
|
+
? 0
|
|
13321
|
+
: (measuredHeights.get(current) ?? measuredHeights.values().next().value ?? 0)
|
|
13322
|
+
const ghostHeight = measuredBase > 0 ? Math.round(measuredBase * props.scale) : 0
|
|
13323
|
+
// The mounted window follows page reports, and a report only comes from a
|
|
13324
|
+
// mounted page. A scrollbar drag, a wheel fling or Page Down can therefore
|
|
13325
|
+
// leave the viewport below (or above) the whole band with no mounted page
|
|
13326
|
+
// under it: nothing reports, the window never moves, and the reader looks
|
|
13327
|
+
// at blank paper for ever. When the viewport leaves the band, publish the
|
|
13328
|
+
// page it is actually on; the window recentres there on the next render.
|
|
13329
|
+
// `onFollow` lets a view whose page reports are deliberately coarse (the
|
|
13330
|
+
// right preview, which must not publish every 50% crossing) still hand the
|
|
13331
|
+
// window a page.
|
|
13332
|
+
const follow = typeof props.onFollow === 'function' ? props.onFollow : props.onVisible
|
|
13333
|
+
// A programmatic scroll (page jump, mode switch, zoom) crosses the ghost
|
|
13334
|
+
// band on purpose; while one is settling its pages must not be published.
|
|
13335
|
+
const settling = typeof props.isSettling === 'function' ? props.isSettling : null
|
|
13336
|
+
useEffect(() => {
|
|
13337
|
+
const root = props.rootRef === null || props.rootRef === undefined ? null : props.rootRef.current
|
|
13338
|
+
if (root === null || root === undefined || typeof follow !== 'function') return undefined
|
|
13339
|
+
let timer = null
|
|
13340
|
+
const onScroll = () => {
|
|
13341
|
+
if (timer !== null) clearTimeout(timer)
|
|
13342
|
+
timer = setTimeout(() => {
|
|
13343
|
+
timer = null
|
|
13344
|
+
const column = columnRef.current
|
|
13345
|
+
if (column === null) return
|
|
13346
|
+
if (settling !== null && settling()) return
|
|
13347
|
+
const slots = column.querySelectorAll('.md-reader-slot')
|
|
13348
|
+
if (slots.length === 0) return
|
|
13349
|
+
const edge = root.getBoundingClientRect().top + 24
|
|
13350
|
+
const first = slots[0].getBoundingClientRect()
|
|
13351
|
+
const last = slots[slots.length - 1].getBoundingClientRect()
|
|
13352
|
+
const step = (ghostHeight > 0 ? ghostHeight : 900) + 18
|
|
13353
|
+
let target = 0
|
|
13354
|
+
if (last.bottom < edge) {
|
|
13355
|
+
// Scrolled past the band: count the ghost pages between its end and
|
|
13356
|
+
// the viewport's top edge.
|
|
13357
|
+
target = Math.min(total, to + 1 + Math.floor((edge - last.bottom) / step))
|
|
13358
|
+
} else if (first.top > edge) {
|
|
13359
|
+
// Scrolled above the band: count the ghost pages above it.
|
|
13360
|
+
target = Math.max(1, from - 1 - Math.floor((first.top - edge) / step))
|
|
13361
|
+
}
|
|
13362
|
+
if (target > 0 && target !== current) follow(target)
|
|
13363
|
+
}, 140)
|
|
13364
|
+
}
|
|
13365
|
+
root.addEventListener('scroll', onScroll, { passive: true })
|
|
13366
|
+
return () => {
|
|
13367
|
+
root.removeEventListener('scroll', onScroll)
|
|
13368
|
+
if (timer !== null) clearTimeout(timer)
|
|
13369
|
+
}
|
|
13370
|
+
}, [props.doc, props.rootRef, follow, settling, current, from, to, ghostHeight, total])
|
|
12267
13371
|
const pages = []
|
|
12268
13372
|
// The plane's margins at the ends of the column: blank paper where the
|
|
12269
13373
|
// reader may write above the first page and below the last one.
|
|
@@ -12272,7 +13376,11 @@ window.__ModuleLoader__.load({
|
|
|
12272
13376
|
if (topPad > 0) pages.push(h('div', { key: 'pad-top', className: 'md-reader-plane-pad', style: { height: `${topPad}px` } }))
|
|
12273
13377
|
for (let page = 1; page <= total; page += 1) {
|
|
12274
13378
|
if (page < from || page > to) {
|
|
12275
|
-
pages.push(h('div', {
|
|
13379
|
+
pages.push(h('div', {
|
|
13380
|
+
key: page,
|
|
13381
|
+
className: 'md-reader-slot md-reader-ghost',
|
|
13382
|
+
style: ghostHeight > 0 ? { minHeight: `${ghostHeight}px` } : undefined,
|
|
13383
|
+
},
|
|
12276
13384
|
h('span', { className: 'md-reader-page-no', 'aria-hidden': true }, String(page))))
|
|
12277
13385
|
continue
|
|
12278
13386
|
}
|
|
@@ -12290,6 +13398,7 @@ window.__ModuleLoader__.load({
|
|
|
12290
13398
|
rootRef: props.rootRef,
|
|
12291
13399
|
onVisible: props.onVisible,
|
|
12292
13400
|
registerSlot: props.registerSlot,
|
|
13401
|
+
onMeasured: noteHeight,
|
|
12293
13402
|
showBlocks: props.showBlocks,
|
|
12294
13403
|
bookId: props.bookId,
|
|
12295
13404
|
code: props.code,
|
|
@@ -12815,6 +13924,8 @@ window.__ModuleLoader__.load({
|
|
|
12815
13924
|
bookId: props.bookId,
|
|
12816
13925
|
code: props.code,
|
|
12817
13926
|
onVisible: props.onVisible,
|
|
13927
|
+
onFollow: props.onFollow,
|
|
13928
|
+
isSettling: props.isSettling,
|
|
12818
13929
|
registerSlot: props.registerSlot,
|
|
12819
13930
|
onError: props.onError,
|
|
12820
13931
|
// The current page reports its box for pointer measurement.
|
|
@@ -13109,6 +14220,8 @@ window.__ModuleLoader__.load({
|
|
|
13109
14220
|
// Until this timestamp a programmatic jump is still settling: the pages it
|
|
13110
14221
|
// crosses must not report themselves as the page being read.
|
|
13111
14222
|
const jumpingUntil = useRef(0)
|
|
14223
|
+
// Same question for the continuous column's far-scroll follower.
|
|
14224
|
+
const isSettling = useCallback(() => switchingMode.current || Date.now() < jumpingUntil.current, [])
|
|
13112
14225
|
const visibleTimer = useRef(null)
|
|
13113
14226
|
const [dual, setDual] = useState(false)
|
|
13114
14227
|
const [rightScale, setRightScale] = useState(null)
|
|
@@ -15982,6 +17095,10 @@ window.__ModuleLoader__.load({
|
|
|
15982
17095
|
// visible" while it is still off screen. The bilingual column
|
|
15983
17096
|
// keeps the observer's report.
|
|
15984
17097
|
onVisible: null,
|
|
17098
|
+
// A far scroll outside the mounted band still has to tell the
|
|
17099
|
+
// column where the reader is, or the band never follows.
|
|
17100
|
+
onFollow: props.onVisible,
|
|
17101
|
+
isSettling,
|
|
15985
17102
|
registerSlot,
|
|
15986
17103
|
onError: props.onError,
|
|
15987
17104
|
pan: extended ? inkPan : null,
|
|
@@ -16692,6 +17809,44 @@ body[data-ds-dark-theme] .md-root:has(.md-home) { background: var(--dsw-alias-bg
|
|
|
16692
17809
|
.md-env-title { margin: 0; font-size: 15px; }
|
|
16693
17810
|
.md-env-body { margin: 0; font-size: 13px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
|
|
16694
17811
|
.md-env-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
|
|
17812
|
+
/* "开始前检查" only. Host Modal portals outside .md-root, so the pdf tokens
|
|
17813
|
+
are re-declared on its card; nothing else reads these classes. */
|
|
17814
|
+
.md-env-guide-modal.md-env-guide-modal {
|
|
17815
|
+
--pdf-bg: var(--dsw-alias-bg-base);
|
|
17816
|
+
--pdf-bg-sub: var(--dsw-alias-bg-layer-1);
|
|
17817
|
+
--pdf-surface: var(--dsw-alias-bg-layer-2);
|
|
17818
|
+
--pdf-border: var(--dsw-alias-border-l2);
|
|
17819
|
+
--pdf-border-strong: var(--dsw-alias-border-l3);
|
|
17820
|
+
--pdf-text: var(--dsw-alias-label-primary);
|
|
17821
|
+
--pdf-text-sub: var(--dsw-alias-label-secondary);
|
|
17822
|
+
--pdf-accent: var(--dsw-static-blue-600);
|
|
17823
|
+
--pdf-danger: var(--dsw-alias-state-error-primary);
|
|
17824
|
+
--pdf-shadow: var(--dsw-elevation-soft);
|
|
17825
|
+
--pdf-radius: var(--dsw-radius-md);
|
|
17826
|
+
width: min(440px, 100%);
|
|
17827
|
+
}
|
|
17828
|
+
body[data-ds-dark-theme] .md-env-guide-modal.md-env-guide-modal { --pdf-accent: var(--dsw-static-blue-400); }
|
|
17829
|
+
.md-env-guide { display: flex; flex-direction: column; max-height: min(64vh, 520px); overflow-y: auto; }
|
|
17830
|
+
.md-env-guide > .md-shelf-sub { margin: 0 0 4px; font-size: 12.5px; line-height: 1.6; color: var(--pdf-text-sub); }
|
|
17831
|
+
.md-env-guide .md-env-row {
|
|
17832
|
+
display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-start;
|
|
17833
|
+
gap: 4px 12px; padding: 12px 0 12px 10px; margin: 0;
|
|
17834
|
+
border-top: 1px solid var(--pdf-border); border-left: 3px solid transparent;
|
|
17835
|
+
font-size: 13px;
|
|
17836
|
+
}
|
|
17837
|
+
.md-env-guide .md-env-row > span:first-child {
|
|
17838
|
+
flex: 1 1 auto; min-width: 0; font-weight: 600; line-height: 1.5; color: var(--pdf-text);
|
|
17839
|
+
}
|
|
17840
|
+
.md-env-guide .md-env-row-missing > span:first-child { color: var(--pdf-danger); }
|
|
17841
|
+
.md-env-guide .md-env-row > .md-shelf-sub {
|
|
17842
|
+
flex: 1 1 100%; min-width: 0; margin: 0; font-size: 12px; line-height: 1.6; color: var(--pdf-text-sub);
|
|
17843
|
+
}
|
|
17844
|
+
.md-env-guide .md-env-row > .md-btn { flex: 0 0 auto; margin-left: auto; align-self: center; }
|
|
17845
|
+
.md-env-guide .md-env-row-ok { border-left-color: color-mix(in srgb, var(--pdf-accent) 45%, transparent); }
|
|
17846
|
+
.md-env-guide .md-env-row-missing { border-left-color: var(--pdf-danger); }
|
|
17847
|
+
.md-env-guide > .md-shelf-sub:last-child {
|
|
17848
|
+
margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--pdf-border);
|
|
17849
|
+
}
|
|
16695
17850
|
.md-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
16696
17851
|
.md-modal-body { display: flex; flex-direction: column; gap: 12px; }
|
|
16697
17852
|
.md-modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
|
|
@@ -16752,6 +17907,8 @@ body[data-ds-dark-theme] .md-root:has(.md-home) { background: var(--dsw-alias-bg
|
|
|
16752
17907
|
.md-btn-ghost { background: transparent; border-color: transparent; }
|
|
16753
17908
|
.md-btn-ghost:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); border-color: transparent; }
|
|
16754
17909
|
.md-crumbs { flex: none; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dsw-alias-label-secondary); padding-bottom: 14px; border-bottom: 1px solid var(--dsw-alias-border-l2); }
|
|
17910
|
+
/* A shelf's own add-PDF switch, parked at the right end of the crumb row. */
|
|
17911
|
+
.md-crumbs-toggle { margin-left: auto; }
|
|
16755
17912
|
.md-crumb { font: inherit; font-size: 13px; color: var(--dsw-alias-label-secondary); background: none; border: 0; padding: 2px 4px; border-radius: 6px; cursor: pointer; }
|
|
16756
17913
|
.md-crumb:hover:not(:disabled) { color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
|
|
16757
17914
|
.md-crumb-sep { opacity: .5; }
|
|
@@ -16958,6 +18115,12 @@ body[data-ds-dark-theme] .md-root:has(.md-home) { background: var(--dsw-alias-bg
|
|
|
16958
18115
|
.md-home .md-library-toolscroll > .md-subheading { display: none; }
|
|
16959
18116
|
.md-home .md-tool-card { min-width: 0; display: flex; flex-direction: column; gap: 8px; padding: 16px; border: 1px solid var(--pdf-border); border-radius: var(--pdf-radius); background: var(--pdf-surface); }
|
|
16960
18117
|
.md-home .md-tool-card .md-btn { align-self: flex-start; margin-top: auto; }
|
|
18118
|
+
.md-home .md-library-toolscroll > #md-env-card { grid-column: span 2; }
|
|
18119
|
+
.md-home #md-env-card .md-settings-row { display: flex; align-items: center; justify-content: flex-start; gap: 8px; flex-wrap: wrap; min-width: 0; font-size: 14px; line-height: 1.6; }
|
|
18120
|
+
.md-home #md-env-card .md-settings-row > span:first-child { flex: 1 1 100%; min-width: 0; color: var(--pdf-text-sub); }
|
|
18121
|
+
.md-home #md-env-card .md-settings-row > .md-path { flex: 1 1 280px; min-width: 0; width: auto; max-width: 100%; box-sizing: border-box; align-self: stretch; padding: 8px 12px; font-size: 12px; line-height: 1.6; white-space: normal; word-break: normal; overflow-wrap: anywhere; color: var(--pdf-text); background: var(--pdf-bg); border-color: var(--pdf-border); }
|
|
18122
|
+
.md-home #md-env-card .md-settings-row > .md-btn { flex: 0 0 auto; align-self: center; margin-top: 0; min-width: 96px; min-height: 36px; box-sizing: border-box; padding: 4px 12px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
|
|
18123
|
+
.md-home #md-env-card .md-settings-row > .md-shelf-sub { flex: 1 1 100%; min-width: 0; }
|
|
16961
18124
|
.md-home .md-manual { border-radius: var(--pdf-radius); padding: 0; overflow: hidden; border: 1px solid var(--pdf-border); background: var(--pdf-surface); }
|
|
16962
18125
|
.md-home .md-manual-summary { gap: 12px; padding: 16px; }
|
|
16963
18126
|
.md-home .md-manual-summary-main { gap: 4px; }
|
|
@@ -16974,6 +18137,7 @@ body[data-ds-dark-theme] .md-root:has(.md-home) { background: var(--dsw-alias-bg
|
|
|
16974
18137
|
.md-home .md-manual-heading { margin: 0; font-size: 14px; font-weight: 600; color: var(--pdf-text); }
|
|
16975
18138
|
.md-home .md-manual-text, .md-home .md-manual-list { font-size: 14px; line-height: 1.6; color: var(--pdf-text-sub); }
|
|
16976
18139
|
.md-home .md-manual-actions, .md-home .md-library-tools { gap: 8px; }
|
|
18140
|
+
.md-home .md-library-tools .md-settings-input { flex: 1 1 280px; min-width: 0; max-width: 100%; height: 40px; box-sizing: border-box; padding: 8px 12px; border: 1px solid var(--pdf-border); border-radius: 6px; background: var(--pdf-bg); color: var(--pdf-text); font-size: 14px; }
|
|
16977
18141
|
.md-home .md-manual-tree { padding: 12px 16px; font-size: 12px; line-height: 1.6; color: var(--pdf-text); background: var(--pdf-bg-sub); border: 1px solid var(--pdf-border); border-radius: 6px; }
|
|
16978
18142
|
.md-home details.md-manual-sub { padding: 12px; border: 1px solid var(--pdf-border); border-radius: var(--pdf-radius); }
|
|
16979
18143
|
.md-home .md-manual-sub-summary { font-size: 12px; color: var(--pdf-text); }
|
|
@@ -16990,6 +18154,7 @@ body[data-ds-dark-theme] .md-root:has(.md-home) { background: var(--dsw-alias-bg
|
|
|
16990
18154
|
.md-home .md-add-name { flex: 1 1 160px; width: auto; }
|
|
16991
18155
|
.md-home .md-add-submit { margin-left: 0; }
|
|
16992
18156
|
.md-home .md-manual-grid { grid-template-columns: minmax(0, 1fr); }
|
|
18157
|
+
.md-home .md-library-toolscroll > #md-env-card { grid-column: 1 / -1; }
|
|
16993
18158
|
}
|
|
16994
18159
|
.md-manual-summary { list-style: none; display: flex; align-items: center; gap: 16px; padding: 18px 22px; cursor: pointer; }
|
|
16995
18160
|
.md-manual-summary::-webkit-details-marker { display: none; }
|
|
@@ -17257,9 +18422,12 @@ details.md-manual-sub { margin-top: 4px; padding: 10px 14px; border: 1px solid v
|
|
|
17257
18422
|
is on the page edge, with a short fade/slide so it does not pop. */
|
|
17258
18423
|
.md-rail-wrap { position: absolute; top: 0; bottom: 0; z-index: 40; width: 30px; display: flex; align-items: center; justify-content: center; pointer-events: auto; }
|
|
17259
18424
|
.md-rail-tab { position: absolute; top: 50%; transform: translateY(-50%); width: 18px; height: 58px; border-radius: 6px 0 0 6px; display: flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1; color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-base); border: 1px solid var(--dsw-alias-border-l3); border-right: none; box-shadow: var(--dsw-elevation-soft); opacity: .9; z-index: 39; pointer-events: none; transition: opacity .18s ease; }
|
|
17260
|
-
.md-rail-tab[data-side="right"] { right:
|
|
18425
|
+
.md-rail-tab[data-side="right"] { right: 20px; }
|
|
17261
18426
|
.md-rail-tab[data-side="left"] { left: 0; border-radius: 0 6px 6px 0; border-right: 1px solid var(--dsw-alias-border-l3); border-left: none; }
|
|
17262
|
-
|
|
18427
|
+
/* The rail sits 20px in from the edge on the right: that strip is the
|
|
18428
|
+
scrollbar's lane, and a rail flush with the edge swallowed its pointer events
|
|
18429
|
+
(the bar showed but could not be dragged). */
|
|
18430
|
+
.md-rail-wrap[data-side="right"] { right: 20px; }
|
|
17263
18431
|
.md-rail-wrap[data-side="left"] { left: 0; }
|
|
17264
18432
|
.md-rail { display: flex; flex-direction: column; gap: 4px; padding: 6px 4px; max-height: 78vh; overflow-y: auto; background: color-mix(in srgb, var(--dsw-alias-bg-base) 92%, transparent); border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px; box-shadow: var(--dsw-elevation-prominent); opacity: 0; transform: translateX(10px); transition: opacity .18s ease, transform .18s ease; pointer-events: none; }
|
|
17265
18433
|
.md-rail-wrap[data-side="left"] .md-rail { transform: translateX(-10px); }
|
|
@@ -17280,7 +18448,7 @@ details.md-manual-sub { margin-top: 4px; padding: 10px 14px; border: 1px solid v
|
|
|
17280
18448
|
.md-reader[data-rail="right"] .md-reader-stage { padding-right: 58px; }
|
|
17281
18449
|
.md-reader[data-rail="left"] .md-reader-stage { padding-left: 58px; }
|
|
17282
18450
|
.md-rail-panel { position: absolute; top: 50%; transform: translateY(-50%); width: 260px; max-height: calc(100vh - 110px); overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; background: color-mix(in srgb, var(--dsw-alias-bg-base) 96%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--dsw-alias-border-l3); border-radius: 12px; box-shadow: var(--dsw-elevation-prominent); z-index: 42; pointer-events: auto; }
|
|
17283
|
-
.md-rail-panel[data-side="right"] { right:
|
|
18451
|
+
.md-rail-panel[data-side="right"] { right: 48px; }
|
|
17284
18452
|
.md-rail-panel[data-side="left"] { left: 28px; }
|
|
17285
18453
|
.md-rail-panel-title { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); padding-bottom: 8px; border-bottom: 1px solid var(--dsw-alias-border-l2); }
|
|
17286
18454
|
.md-rail-panel-hint { margin: 0; font-size: 12px; line-height: 1.7; color: var(--dsw-alias-label-secondary); }
|
|
@@ -17437,6 +18605,11 @@ details.md-manual-sub { margin-top: 4px; padding: 10px 14px; border: 1px solid v
|
|
|
17437
18605
|
.md-split-item { position: relative; display: flex; flex-direction: column; min-width: 0; }
|
|
17438
18606
|
.md-split-page { position: relative; width: 100%; border: 1px solid var(--dsw-alias-border-l3); border-radius: 6px; overflow: hidden; background: #fff; box-shadow: var(--dsw-elevation-soft); }
|
|
17439
18607
|
.md-split-page canvas { display: block; width: 100%; height: auto; }
|
|
18608
|
+
/* Host-rendered thumbnails: the frame reserves the page shape and the image
|
|
18609
|
+
fills it, so rows never change height while scrolling. */
|
|
18610
|
+
.md-split-page-host { background: var(--pdf-bg-sub); box-shadow: none; }
|
|
18611
|
+
.md-split-thumb { display: block; width: 100%; height: 100%; object-fit: contain; background: #fff; }
|
|
18612
|
+
.md-split-thumb-wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
17440
18613
|
.md-split-num { position: absolute; left: 5px; bottom: 5px; font-size: 12px; color: #444; background: rgba(255, 255, 255, 0.9); border-radius: 3px; padding: 0 5px; }
|
|
17441
18614
|
.md-split-num-on { color: #fff; background: #dc2626; }
|
|
17442
18615
|
.md-split-cut { position: absolute; top: 0; bottom: 0; right: -9px; width: 18px; display: flex; flex-direction: column; align-items: center; padding: 0; border: 0; background: transparent; color: #64748b; cursor: pointer; z-index: 2; }
|
|
@@ -17450,6 +18623,14 @@ details.md-manual-sub { margin-top: 4px; padding: 10px 14px; border: 1px solid v
|
|
|
17450
18623
|
.md-split-cut-on .md-split-cut-line { border-left-style: solid; border-left-color: #dc2626; }
|
|
17451
18624
|
.md-split-cut-on .md-split-cut-btn { border: 1px solid #dc2626; border-style: solid; background: #dc2626; color: #fff; }
|
|
17452
18625
|
.md-split-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
18626
|
+
/* The range line doubles as the page jump: its numbers are buttons, and the page
|
|
18627
|
+
a jump landed on is outlined for a moment. Paper stays white in dark mode. */
|
|
18628
|
+
.md-split-range { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; }
|
|
18629
|
+
.md-split-range-dash { color: var(--pdf-text-sub); }
|
|
18630
|
+
.md-split-jump { font: inherit; font-size: 12px; line-height: 1.6; padding: 0 4px; border: 0; border-radius: 6px; background: transparent; color: var(--pdf-accent); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
|
|
18631
|
+
.md-split-jump:hover { background: var(--pdf-bg-sub); text-decoration: none; }
|
|
18632
|
+
.md-split-jump:focus-visible { outline: 2px solid var(--pdf-accent); outline-offset: 1px; }
|
|
18633
|
+
.md-split-item.md-split-flash .md-split-page { outline: 2px solid var(--pdf-accent); outline-offset: 2px; }
|
|
17453
18634
|
.md-split-preview { margin: 0; padding-left: 16px; font-size: 11px; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
17454
18635
|
.md-wizard-backdrop { position: fixed; inset: 0; z-index: 92; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 23, 42, 0.45); }
|
|
17455
18636
|
.md-wizard-panel { width: min(860px, 94vw); max-height: min(840px, 92vh); display: flex; flex-direction: column; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); overflow: hidden; }
|
|
@@ -17515,7 +18696,7 @@ details.md-manual-sub { margin-top: 4px; padding: 10px 14px; border: 1px solid v
|
|
|
17515
18696
|
moving when the page grows a scrollbar. */
|
|
17516
18697
|
.md-side-body .md-reader-stage { padding: 8px 10px 16px; scrollbar-gutter: stable; }
|
|
17517
18698
|
.md-side-body > .md-reader-stage-host { flex: 1 1 auto; min-height: 0; display: flex; }
|
|
17518
|
-
.md-side .md-side-body .md-reader-stage { padding-right:
|
|
18699
|
+
.md-side .md-side-body .md-reader-stage { padding-right: 48px; }
|
|
17519
18700
|
/* The developer readout (Ctrl+Alt+D): one small overlay, never takes a click. */
|
|
17520
18701
|
.md-hud { position: absolute; left: 8px; bottom: 8px; z-index: 60; margin: 0; padding: 6px 8px; max-width: calc(100% - 16px); overflow: hidden; white-space: pre-wrap; font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-base)); border: 1px solid var(--dsw-alias-border-l3); border-radius: 6px; pointer-events: none; opacity: 0.94; }
|
|
17521
18702
|
/* The preview's action list when the shared context menu service is absent. */
|
|
@@ -18521,15 +19702,52 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
18521
19702
|
// The chapter owns the page: this end only asks for the move.
|
|
18522
19703
|
setChapterPage(bookId, code, 'side', number, 'navigate')
|
|
18523
19704
|
}, [bookId, code])
|
|
18524
|
-
|
|
18525
|
-
//
|
|
18526
|
-
const
|
|
18527
|
-
if (
|
|
18528
|
-
|
|
18529
|
-
if (jumping.current) return
|
|
18530
|
-
reportChapterPage(bookId, code, 'side', number)
|
|
18531
|
-
}, 350)
|
|
19705
|
+
// One way for this preview to report the page it is on: the scroll listener
|
|
19706
|
+
// below and the column's own far-scroll follower both use it.
|
|
19707
|
+
const reportSide = useCallback(page => {
|
|
19708
|
+
if (bookId === '' || code === '') return
|
|
19709
|
+
reportChapterPage(bookId, code, 'side', page)
|
|
18532
19710
|
}, [bookId, code])
|
|
19711
|
+
// While this preview scrolls itself to a page, its places on the way are
|
|
19712
|
+
// not where the reader is: the far-scroll follower stays quiet.
|
|
19713
|
+
const isSettling = useCallback(() => jumping.current, [])
|
|
19714
|
+
|
|
19715
|
+
// In continuous mode the page is the one at the viewport's top edge, not
|
|
19716
|
+
// the page whose center crossed 50%: the latter reports the next/previous
|
|
19717
|
+
// page while the current one is still being read, which made the shared
|
|
19718
|
+
// page number and this preview drift by one.
|
|
19719
|
+
useEffect(() => {
|
|
19720
|
+
if (mode !== 'continuous' || phase !== 'ready') return undefined
|
|
19721
|
+
const scrollport = stage.current
|
|
19722
|
+
if (scrollport === null || scrollport === undefined) return undefined
|
|
19723
|
+
const onScroll = () => {
|
|
19724
|
+
if (visibleTimer.current !== null) clearTimeout(visibleTimer.current)
|
|
19725
|
+
visibleTimer.current = setTimeout(() => {
|
|
19726
|
+
visibleTimer.current = null
|
|
19727
|
+
if (jumping.current) return
|
|
19728
|
+
const edge = scrollport.getBoundingClientRect().top + 24
|
|
19729
|
+
let best = null
|
|
19730
|
+
let first = null
|
|
19731
|
+
slots.current.forEach((node, number) => {
|
|
19732
|
+
if (node === null || node === undefined) return
|
|
19733
|
+
if (first === null || number < first) first = number
|
|
19734
|
+
if (node.getBoundingClientRect().top <= edge && (best === null || number > best)) best = number
|
|
19735
|
+
})
|
|
19736
|
+
// A drag far past the mounted window leaves no slot above the edge;
|
|
19737
|
+
// fall back to the topmost mounted page so the window can follow.
|
|
19738
|
+
const chosen = best === null ? first : best
|
|
19739
|
+
if (chosen !== null && chosen !== pageRef.current) reportSide(chosen)
|
|
19740
|
+
}, 180)
|
|
19741
|
+
}
|
|
19742
|
+
scrollport.addEventListener('scroll', onScroll, { passive: true })
|
|
19743
|
+
return () => {
|
|
19744
|
+
scrollport.removeEventListener('scroll', onScroll)
|
|
19745
|
+
if (visibleTimer.current !== null) {
|
|
19746
|
+
clearTimeout(visibleTimer.current)
|
|
19747
|
+
visibleTimer.current = null
|
|
19748
|
+
}
|
|
19749
|
+
}
|
|
19750
|
+
}, [mode, phase, bookId, code])
|
|
18533
19751
|
|
|
18534
19752
|
const scrollToPage = useCallback(number => {
|
|
18535
19753
|
jumping.current = true
|
|
@@ -18748,7 +19966,9 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
18748
19966
|
|
|
18749
19967
|
// The editing surface: an invisible page-sized layer that only takes pointer
|
|
18750
19968
|
// events while a tool is picked, so scrolling stays untouched otherwise.
|
|
18751
|
-
|
|
19969
|
+
// The question tool is excluded: its own marks layer handles the drag, and
|
|
19970
|
+
// this layer would swallow every press before it (the reader does the same).
|
|
19971
|
+
const editLayer = tool === '' || tool === 'hand' || tool === 'question'
|
|
18752
19972
|
? null
|
|
18753
19973
|
: h('div', {
|
|
18754
19974
|
className: 'md-annot md-annot-edit',
|
|
@@ -18877,20 +20097,46 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
18877
20097
|
onFailure: () => { notifySide(format('questionSaveFailed')) },
|
|
18878
20098
|
})
|
|
18879
20099
|
const commitQuestions = (list, next, record = true) => { questionCommitting.commit(list, next, record) }
|
|
20100
|
+
/**
|
|
20101
|
+
* Announce a new mark with the picture of its framed region, so the model
|
|
20102
|
+
* reads the exact content even when the page is a scan with no text layer.
|
|
20103
|
+
* The Host renders the crop; the PNG sits beside the question store.
|
|
20104
|
+
* @param {{ id: string, name: string, page: number, rect: object }} question - the created mark.
|
|
20105
|
+
* @returns {Promise<void>} completion (best effort).
|
|
20106
|
+
*/
|
|
20107
|
+
const announceQuestionImage = async question => {
|
|
20108
|
+
let image = ''
|
|
20109
|
+
try {
|
|
20110
|
+
const crop = await request('POST', 'question-crop', {
|
|
20111
|
+
book: bookId,
|
|
20112
|
+
code,
|
|
20113
|
+
id: question.id,
|
|
20114
|
+
page: question.page,
|
|
20115
|
+
rect: question.rect,
|
|
20116
|
+
})
|
|
20117
|
+
if (crop !== null && crop !== undefined && typeof crop.path === 'string') image = crop.path
|
|
20118
|
+
} catch {
|
|
20119
|
+
// A failed crop still leaves the page-number announcement.
|
|
20120
|
+
}
|
|
20121
|
+
await injectQuestionLine(bookId, code, image === '' ? question : { ...question, image })
|
|
20122
|
+
}
|
|
18880
20123
|
const createQuestion = rect => {
|
|
18881
20124
|
// Same gap-filling number as the reader: one numbering rule for both.
|
|
18882
20125
|
const number = nextQuestionNumber(questionsRef.current)
|
|
18883
20126
|
const question = {
|
|
18884
20127
|
id: createQuestionId(),
|
|
18885
20128
|
name: `疑问 ${number}`,
|
|
18886
|
-
page:
|
|
20129
|
+
// The chapter page, not the clamped document page: a translated file
|
|
20130
|
+
// with fewer pages must not rename the page the mark belongs to.
|
|
20131
|
+
page,
|
|
18887
20132
|
rect,
|
|
18888
20133
|
createdAt: Date.now(),
|
|
18889
20134
|
}
|
|
18890
20135
|
commitQuestions([...questionsRef.current, question], Math.max(questionsNext.current, number + 1))
|
|
18891
|
-
// This column is the PDF beside the conversation
|
|
18892
|
-
//
|
|
18893
|
-
|
|
20136
|
+
// This column is the PDF beside the conversation: render the framed
|
|
20137
|
+
// region to an image and announce that, so the model sees exactly what
|
|
20138
|
+
// the user boxed (scanned pages have no text to quote).
|
|
20139
|
+
void announceQuestionImage(question)
|
|
18894
20140
|
}
|
|
18895
20141
|
const flashQuestion = id => {
|
|
18896
20142
|
setQuestionFlash(id)
|
|
@@ -18948,7 +20194,9 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
18948
20194
|
}, [undoCount, redoCount])
|
|
18949
20195
|
|
|
18950
20196
|
const questionLayer = h(QuestionMarks, {
|
|
18951
|
-
|
|
20197
|
+
// Annotations read by the chapter page too; the displayed page may be
|
|
20198
|
+
// clamped when the translated file has fewer pages.
|
|
20199
|
+
questions: questions.filter(item => Number(item.page) === page),
|
|
18952
20200
|
active: tool === 'question',
|
|
18953
20201
|
create: tool === 'question',
|
|
18954
20202
|
reading: tool === '',
|
|
@@ -19260,9 +20508,13 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19260
20508
|
showBlocks: false,
|
|
19261
20509
|
bookId,
|
|
19262
20510
|
code,
|
|
19263
|
-
onVisible,
|
|
19264
20511
|
registerSlot,
|
|
19265
20512
|
onError,
|
|
20513
|
+
// A far scroll (scrollbar drag / fling) lands outside the mounted
|
|
20514
|
+
// window; this preview's own 180 ms listener would only nudge the
|
|
20515
|
+
// window 12 pages at a time, so let the column report the page.
|
|
20516
|
+
onFollow: reportSide,
|
|
20517
|
+
isSettling,
|
|
19266
20518
|
pan: mode === 'single' ? sidePan : null,
|
|
19267
20519
|
panNeeds: null,
|
|
19268
20520
|
margins: planeMargins,
|
|
@@ -19372,6 +20624,10 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19372
20624
|
if (found === undefined) return
|
|
19373
20625
|
goPage(found.page)
|
|
19374
20626
|
flashQuestion(found.id)
|
|
20627
|
+
// Picking a mark to discuss also sends its picture: an existing
|
|
20628
|
+
// mark predates the crop feature, and the model still needs to see
|
|
20629
|
+
// the framed region.
|
|
20630
|
+
void announceQuestionImage(found)
|
|
19375
20631
|
},
|
|
19376
20632
|
}),
|
|
19377
20633
|
h(KitButton, {
|
|
@@ -19720,6 +20976,9 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19720
20976
|
// instead so a click always has a visible answer.
|
|
19721
20977
|
const [translateAsk, setTranslateAsk] = useState(null)
|
|
19722
20978
|
const [splitBook, setSplitBook] = useState(null)
|
|
20979
|
+
// The whole book and the split result, held while the post-split choices
|
|
20980
|
+
// are open. Both actions in that dialog are real (trash / open the book).
|
|
20981
|
+
const [splitResult, setSplitResult] = useState(null)
|
|
19723
20982
|
const [guideClosed, setGuideClosed] = useState(false)
|
|
19724
20983
|
// The settings page can bring the checklist back even when nothing is
|
|
19725
20984
|
// missing; the flag lives only for that one open.
|
|
@@ -19738,6 +20997,10 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19738
20997
|
const workspaceRequest = useRef(null)
|
|
19739
20998
|
const inFlightSessions = useRef(new Set())
|
|
19740
20999
|
const [reloadKey, setReloadKey] = useState(0)
|
|
21000
|
+
// Callers that need the refreshed catalog (the split result adds the new
|
|
21001
|
+
// chapter files to the shelf) wait on the next bootstrap response instead
|
|
21002
|
+
// of racing it.
|
|
21003
|
+
const reloadWaiters = useRef([])
|
|
19741
21004
|
// A chapter the right column asked to open, held until the catalog knows it.
|
|
19742
21005
|
const [deskRequest, setDeskRequest] = useState(null)
|
|
19743
21006
|
// A 提取/答疑/习题 conversation the right column asked for, same deal.
|
|
@@ -19891,6 +21154,8 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19891
21154
|
// book to appear instead of guessing from the file name.
|
|
19892
21155
|
const importPdfStem = useRef('')
|
|
19893
21156
|
const [importAsk, setImportAsk] = useState(null)
|
|
21157
|
+
// The dialog's "remember this choice" box; cleared each time it opens.
|
|
21158
|
+
const [rememberImportSplit, setRememberImportSplit] = useState(false)
|
|
19894
21159
|
const [bookWizard, setBookWizard] = useState(null)
|
|
19895
21160
|
// A whole-book PDF over 64 MB is still importable, but not without saying
|
|
19896
21161
|
// twice what it costs: the whole book's pages enter conversations, so the
|
|
@@ -19915,11 +21180,32 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
19915
21180
|
if (typeof resolve === 'function') resolve(confirmed)
|
|
19916
21181
|
}
|
|
19917
21182
|
const [shelfGroups, setShelfGroups] = useState({ hidden: [], shelves: [] })
|
|
21183
|
+
// Whole-PDF forms pinned to always show, per book and per library. A view
|
|
21184
|
+
// choice like the "whole books" switch (localStorage), not part of the
|
|
21185
|
+
// library's hidden list: the files stay where they are. Pinned cards stay
|
|
21186
|
+
// selectable, so the choice is always reversible.
|
|
21187
|
+
const activeLibraryId = catalog === null || typeof catalog.libraryId !== 'string' ? '' : catalog.libraryId
|
|
21188
|
+
const [wholeAlways, setWholeAlways] = useState(() => readWholeAlways(activeLibraryId))
|
|
21189
|
+
useEffect(() => {
|
|
21190
|
+
setWholeAlways(readWholeAlways(activeLibraryId))
|
|
21191
|
+
}, [activeLibraryId])
|
|
21192
|
+
// Shelves whose add-PDF card is switched off in the shelf header.
|
|
21193
|
+
const [addPdfOff, setAddPdfOff] = useState(() => readShelfAddPdfOff(activeLibraryId))
|
|
21194
|
+
useEffect(() => {
|
|
21195
|
+
setAddPdfOff(readShelfAddPdfOff(activeLibraryId))
|
|
21196
|
+
}, [activeLibraryId])
|
|
19918
21197
|
const [group, setGroup] = useState(null)
|
|
19919
21198
|
const groupRef = useRef(null)
|
|
19920
21199
|
groupRef.current = group
|
|
21200
|
+
// The two shelf switches: whole/unsplit books, and split books named by
|
|
21201
|
+
// hand. They live with the view, not inside the grid, so one `shelfView`
|
|
21202
|
+
// call decides both what the main shelf shows and what its counters say.
|
|
21203
|
+
const [showWhole, setShowWhole] = useState(() => readShelfFlag(SHOW_WHOLE_KEY))
|
|
21204
|
+
const [showLoose, setShowLoose] = useState(() => readShelfFlag(SHOW_LOOSE_KEY))
|
|
19921
21205
|
const [selected, setSelected] = useState(() => new Set())
|
|
19922
21206
|
const [shelfName, setShelfName] = useState(null)
|
|
21207
|
+
// Open while the user picks which existing shelf the selection joins.
|
|
21208
|
+
const [shelfPick, setShelfPick] = useState(false)
|
|
19923
21209
|
const [marquee, setMarquee] = useState(null)
|
|
19924
21210
|
const bootstrapSeq = useRef(0)
|
|
19925
21211
|
const digestRef = useRef(false)
|
|
@@ -20059,11 +21345,33 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
20059
21345
|
return persist(current, false)
|
|
20060
21346
|
}, [persist])
|
|
20061
21347
|
|
|
21348
|
+
/**
|
|
21349
|
+
* Refresh the catalog. The returned promise resolves with the next
|
|
21350
|
+
* bootstrap's books, so a caller that has just written files (the split
|
|
21351
|
+
* result) can add the new rows without racing the refresh. A failed or
|
|
21352
|
+
* abandoned refresh resolves with an empty list.
|
|
21353
|
+
* @returns {Promise<object[]>} the refreshed books.
|
|
21354
|
+
*/
|
|
20062
21355
|
const reload = useCallback(() => {
|
|
20063
21356
|
setPreview(null)
|
|
20064
|
-
|
|
21357
|
+
return new Promise(resolve => {
|
|
21358
|
+
reloadWaiters.current.push(resolve)
|
|
21359
|
+
const bump = () => setReloadKey(key => key + 1)
|
|
21360
|
+
try {
|
|
21361
|
+
void flushSave().then(bump, bump)
|
|
21362
|
+
} catch {
|
|
21363
|
+
bump()
|
|
21364
|
+
}
|
|
21365
|
+
})
|
|
20065
21366
|
}, [flushSave])
|
|
20066
21367
|
|
|
21368
|
+
// A page that closes mid-refresh must not leave a split caller waiting.
|
|
21369
|
+
useEffect(() => () => {
|
|
21370
|
+
const waiters = reloadWaiters.current
|
|
21371
|
+
reloadWaiters.current = []
|
|
21372
|
+
for (const resolve of waiters) resolve([])
|
|
21373
|
+
}, [])
|
|
21374
|
+
|
|
20067
21375
|
/**
|
|
20068
21376
|
* Read one chapter's produced files. A chapter already read (or being
|
|
20069
21377
|
* read) is left alone unless `force` asks again. A response that arrives
|
|
@@ -21036,9 +22344,15 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
21036
22344
|
countsState.current = { pending: new Set(), tried: new Set() }
|
|
21037
22345
|
setArtifacts({})
|
|
21038
22346
|
setCounts({})
|
|
22347
|
+
const waiters = reloadWaiters.current
|
|
22348
|
+
reloadWaiters.current = []
|
|
22349
|
+
for (const resolve of waiters) resolve(books)
|
|
21039
22350
|
setPhase('ready')
|
|
21040
22351
|
}).catch(reason => {
|
|
21041
22352
|
if (!alive) return
|
|
22353
|
+
const waiters = reloadWaiters.current
|
|
22354
|
+
reloadWaiters.current = []
|
|
22355
|
+
for (const resolve of waiters) resolve([])
|
|
21042
22356
|
setPhase('error')
|
|
21043
22357
|
setError(errorText(reason))
|
|
21044
22358
|
})
|
|
@@ -21604,6 +22918,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
21604
22918
|
// The shared-prefix base session already read this chapter; no brief is
|
|
21605
22919
|
// injected into the conversation any more.
|
|
21606
22920
|
const cachePart = ''
|
|
22921
|
+
const questionPart = mode === GENERAL_MODE ? '' : await chapterQuestionsBrief(book.id, chapter.code)
|
|
21607
22922
|
const draft = mode === GENERAL_MODE
|
|
21608
22923
|
? [
|
|
21609
22924
|
`${format('generalSeedBook')}:${book.title === '' ? book.id : `${book.title}(${book.id})`}`,
|
|
@@ -21612,7 +22927,7 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
21612
22927
|
paths.pdfPath === '' ? '' : `${format('generalSeedPdf')}:${paths.pdfPath}`,
|
|
21613
22928
|
cachePart,
|
|
21614
22929
|
].filter(Boolean).join('\n')
|
|
21615
|
-
: [seedFor(book, chapter, paths, persona), cachePart, format('sessionQuestionLead')].filter(Boolean).join('\n\n')
|
|
22930
|
+
: [seedFor(book, chapter, paths, persona), questionPart, cachePart, format('sessionQuestionLead')].filter(Boolean).join('\n\n')
|
|
21616
22931
|
const prefill = await beginPrefill(sessionId, draft, 'keep')
|
|
21617
22932
|
if (prefill.applied && persona !== '') {
|
|
21618
22933
|
try { window.localStorage.setItem(`pdfdesk:qa-persona:${sessionId}`, '1') } catch { /* storage unavailable */ }
|
|
@@ -21829,6 +23144,8 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
21829
23144
|
}
|
|
21830
23145
|
}
|
|
21831
23146
|
const parts = [seedFor(book, chapter, paths, persona)]
|
|
23147
|
+
const questionPart = await chapterQuestionsBrief(book.id, chapter.code)
|
|
23148
|
+
if (questionPart !== '') parts.push(questionPart)
|
|
21832
23149
|
if (cachePart !== '') parts.push(cachePart)
|
|
21833
23150
|
if (artifact !== '') parts.push(`产物:${artifact}(本章产物区里的这个文件)`)
|
|
21834
23151
|
if (continuation >= 2) {
|
|
@@ -22254,10 +23571,16 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22254
23571
|
}
|
|
22255
23572
|
}, [format, marketUpdate, updateBusy, updateInfo])
|
|
22256
23573
|
|
|
22257
|
-
/**
|
|
23574
|
+
/**
|
|
23575
|
+
* Persist hidden books / shelves for the active library. Returns the
|
|
23576
|
+
* write promise so a caller that immediately reloads (the split result)
|
|
23577
|
+
* cannot read the old group back before this write lands.
|
|
23578
|
+
* @param {{ hidden: string[], shelves: object[] }} next - groups to store.
|
|
23579
|
+
* @returns {Promise<void>} completion, including a failed write.
|
|
23580
|
+
*/
|
|
22258
23581
|
const saveShelfGroups = useCallback(next => {
|
|
22259
23582
|
setShelfGroups(next)
|
|
22260
|
-
|
|
23583
|
+
return request('POST', 'shelves', next).catch(() => {})
|
|
22261
23584
|
}, [])
|
|
22262
23585
|
|
|
22263
23586
|
const toggleSelect = useCallback(id => {
|
|
@@ -22319,6 +23642,40 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22319
23642
|
setSelected(new Set())
|
|
22320
23643
|
}, [saveShelfGroups, selected, shelfGroups])
|
|
22321
23644
|
|
|
23645
|
+
/** Whether this shelf shows its add-PDF card (the main shelf always does). */
|
|
23646
|
+
const shelfAddPdfOn = group === null || group === 'hidden' ? true : !addPdfOff.includes(group)
|
|
23647
|
+
const toggleShelfAddPdf = useCallback(() => {
|
|
23648
|
+
if (group === null || group === 'hidden') return
|
|
23649
|
+
const current = new Set(addPdfOff)
|
|
23650
|
+
if (current.has(group)) current.delete(group)
|
|
23651
|
+
else current.add(group)
|
|
23652
|
+
const next = [...current]
|
|
23653
|
+
setAddPdfOff(next)
|
|
23654
|
+
writeShelfAddPdfOff(activeLibraryId, next)
|
|
23655
|
+
}, [activeLibraryId, addPdfOff, group])
|
|
23656
|
+
|
|
23657
|
+
/**
|
|
23658
|
+
* Put the selected books into an existing shelf. Books already there are
|
|
23659
|
+
* not duplicated; a shelf that holds all of them says so instead of
|
|
23660
|
+
* claiming it added something.
|
|
23661
|
+
* @param {string} shelfId - target shelf id.
|
|
23662
|
+
* @returns {void}
|
|
23663
|
+
*/
|
|
23664
|
+
const addSelectedToShelf = useCallback(shelfId => {
|
|
23665
|
+
if (selected.size === 0) return
|
|
23666
|
+
const result = shelfAddBooks(shelfGroups, shelfId, [...selected])
|
|
23667
|
+
if (result === null) {
|
|
23668
|
+
const shelf = shelfGroups.shelves.find(item => item.id === shelfId)
|
|
23669
|
+
if (shelf === undefined) return
|
|
23670
|
+
showNotice(format('shelfAlreadyIn', { name: shelf.name }))
|
|
23671
|
+
} else {
|
|
23672
|
+
saveShelfGroups(result.groups)
|
|
23673
|
+
showNotice(format('shelfAddedTo', { n: result.added, name: result.shelf.name }))
|
|
23674
|
+
}
|
|
23675
|
+
setShelfPick(false)
|
|
23676
|
+
setSelected(new Set())
|
|
23677
|
+
}, [saveShelfGroups, selected, shelfGroups, showNotice])
|
|
23678
|
+
|
|
22322
23679
|
const unhideSelected = useCallback(() => {
|
|
22323
23680
|
if (selected.size === 0) return
|
|
22324
23681
|
const hidden = shelfGroups.hidden.filter(id => !selected.has(id))
|
|
@@ -22326,6 +23683,59 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22326
23683
|
setSelected(new Set())
|
|
22327
23684
|
}, [saveShelfGroups, selected, shelfGroups])
|
|
22328
23685
|
|
|
23686
|
+
/** The whole-form keys the current selection would pin or unpin. */
|
|
23687
|
+
const selectedWholeForms = [...selected]
|
|
23688
|
+
.map(id => books.find(item => item.id === id))
|
|
23689
|
+
.filter(item => item !== undefined)
|
|
23690
|
+
.map(wholeFormKey)
|
|
23691
|
+
.filter(key => key !== '')
|
|
23692
|
+
const selectedWholeAllPinned = selectedWholeForms.length > 0
|
|
23693
|
+
&& selectedWholeForms.every(key => wholeAlways.includes(key))
|
|
23694
|
+
// Pinning only means something for a book that still has a whole PDF.
|
|
23695
|
+
const wholeFormApplicable = selectedWholeForms.some(key => books.some(item => item.whole === true && wholeBaseId(item.id) === key))
|
|
23696
|
+
|
|
23697
|
+
/**
|
|
23698
|
+
* Pin (or unpin) the selected books' whole-PDF forms. A pinned whole card
|
|
23699
|
+
* stays visible whatever the "whole books" switch says, and both cards of
|
|
23700
|
+
* one book resolve to the same key, so pinning from either one works. The
|
|
23701
|
+
* split chapters and the files themselves are untouched.
|
|
23702
|
+
*/
|
|
23703
|
+
const toggleWholeForms = useCallback(() => {
|
|
23704
|
+
const picked = [...selected]
|
|
23705
|
+
.map(id => books.find(item => item.id === id))
|
|
23706
|
+
.filter(item => item !== undefined)
|
|
23707
|
+
.map(wholeFormKey)
|
|
23708
|
+
.filter(key => key !== '')
|
|
23709
|
+
if (picked.length === 0) return
|
|
23710
|
+
const current = new Set(wholeAlways)
|
|
23711
|
+
const allPinned = picked.every(key => current.has(key))
|
|
23712
|
+
if (allPinned) for (const key of picked) current.delete(key)
|
|
23713
|
+
else for (const key of picked) current.add(key)
|
|
23714
|
+
const next = [...current]
|
|
23715
|
+
setWholeAlways(next)
|
|
23716
|
+
writeWholeAlways(activeLibraryId, next)
|
|
23717
|
+
}, [activeLibraryId, books, selected, wholeAlways])
|
|
23718
|
+
|
|
23719
|
+
/** Unpin every book: whole PDFs follow the shelf switch again. */
|
|
23720
|
+
const resetWholeForms = useCallback(() => {
|
|
23721
|
+
setWholeAlways([])
|
|
23722
|
+
writeWholeAlways(activeLibraryId, [])
|
|
23723
|
+
}, [activeLibraryId])
|
|
23724
|
+
|
|
23725
|
+
/** Flip the main shelf's "whole books" switch and remember it. */
|
|
23726
|
+
const toggleShowWhole = useCallback(() => {
|
|
23727
|
+
const next = !showWhole
|
|
23728
|
+
setShowWhole(next)
|
|
23729
|
+
writeShelfFlag(SHOW_WHOLE_KEY, next)
|
|
23730
|
+
}, [showWhole])
|
|
23731
|
+
|
|
23732
|
+
/** Flip the main shelf's "split by hand" switch and remember it. */
|
|
23733
|
+
const toggleShowLoose = useCallback(() => {
|
|
23734
|
+
const next = !showLoose
|
|
23735
|
+
setShowLoose(next)
|
|
23736
|
+
writeShelfFlag(SHOW_LOOSE_KEY, next)
|
|
23737
|
+
}, [showLoose])
|
|
23738
|
+
|
|
22329
23739
|
const removeFromShelf = useCallback(() => {
|
|
22330
23740
|
if (group === null || group === 'hidden' || selected.size === 0) return
|
|
22331
23741
|
const shelves = shelfGroups.shelves.map(shelf => (shelf.id === group
|
|
@@ -22490,11 +23900,18 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22490
23900
|
return
|
|
22491
23901
|
}
|
|
22492
23902
|
const name = imported !== null ? String(imported.name) : String(duplicate.existing)
|
|
23903
|
+
const stem = name.replace(/\.pdf$/i, '')
|
|
23904
|
+
// Imported from inside a shelf: the book joins that shelf right away, so
|
|
23905
|
+
// it lands where the user is looking (the file still goes to 整本\).
|
|
23906
|
+
if (group !== null && group !== 'hidden') {
|
|
23907
|
+
const filed = shelfAddBooks(shelfGroups, group, [stem])
|
|
23908
|
+
if (filed !== null) saveShelfGroups(filed.groups)
|
|
23909
|
+
}
|
|
22493
23910
|
if (imported === null) {
|
|
22494
23911
|
showNotice(format('importDuplicate', { name }))
|
|
22495
23912
|
return
|
|
22496
23913
|
}
|
|
22497
|
-
importPdfStem.current =
|
|
23914
|
+
importPdfStem.current = stem
|
|
22498
23915
|
showNotice(format('importPdfDone', { name }))
|
|
22499
23916
|
setReloadKey(key => key + 1)
|
|
22500
23917
|
} catch (error) {
|
|
@@ -22502,16 +23919,25 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22502
23919
|
} finally {
|
|
22503
23920
|
setImportBusy(false)
|
|
22504
23921
|
}
|
|
22505
|
-
}, [showNotice])
|
|
23922
|
+
}, [group, saveShelfGroups, shelfGroups, showNotice])
|
|
22506
23923
|
|
|
22507
23924
|
// Ask "split it now?" once the imported PDF shows up as a whole book. A miss
|
|
22508
|
-
// keeps the stem: the next catalog reload may still list it.
|
|
23925
|
+
// keeps the stem: the next catalog reload may still list it. A remembered
|
|
23926
|
+
// answer replaces the question: "split" opens the panel, "later" says
|
|
23927
|
+
// nothing. The dialog's checkbox writes the same value.
|
|
22509
23928
|
useEffect(() => {
|
|
22510
23929
|
const stem = importPdfStem.current
|
|
22511
23930
|
if (stem === '' || catalog === null) return
|
|
22512
23931
|
const found = wholeBookByFileStem(catalog.books, stem)
|
|
22513
23932
|
if (found === null) return
|
|
22514
23933
|
importPdfStem.current = ''
|
|
23934
|
+
const choice = readImportSplitChoice()
|
|
23935
|
+
if (choice === 'later') return
|
|
23936
|
+
if (choice === 'split') {
|
|
23937
|
+
setSplitBook(found)
|
|
23938
|
+
return
|
|
23939
|
+
}
|
|
23940
|
+
setRememberImportSplit(false)
|
|
22515
23941
|
setImportAsk(found)
|
|
22516
23942
|
}, [catalog])
|
|
22517
23943
|
|
|
@@ -22642,56 +24068,69 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22642
24068
|
|
|
22643
24069
|
/**
|
|
22644
24070
|
* Copy the split toolkit into the active library and open a conversation
|
|
22645
|
-
* with a prepared prompt — the workflow the library was built with.
|
|
22646
|
-
*
|
|
24071
|
+
* with a prepared prompt — the workflow the library was built with. A
|
|
24072
|
+
* remembered conversation is reopened only when every check in
|
|
24073
|
+
* `splitSessionReusable` passes; anything else creates a new one, and its
|
|
24074
|
+
* pointer is stored only after the conversation actually opened.
|
|
24075
|
+
* @returns {Promise<boolean>} whether a split conversation was opened.
|
|
22647
24076
|
*/
|
|
22648
24077
|
const startSplitSession = useCallback(async () => {
|
|
22649
|
-
if (libBusy || catalog === null) return
|
|
24078
|
+
if (libBusy || catalog === null) return false
|
|
22650
24079
|
setLibBusy(true)
|
|
22651
24080
|
setLibError('')
|
|
22652
24081
|
try {
|
|
22653
24082
|
const target = await ensureWorkspaceTarget()
|
|
22654
|
-
if (target === null) return
|
|
24083
|
+
if (target === null) return false
|
|
22655
24084
|
const libraryId = library === null ? catalog.libraryId : library.id
|
|
24085
|
+
const libraryDir = library === null ? catalog.libraryDir : library.libraryDir
|
|
24086
|
+
const dir = typeof libraryDir === 'string' ? libraryDir : ''
|
|
24087
|
+
const sessions = sessionService()
|
|
24088
|
+
const list = sessions === null || sessions.list === undefined ? null : sessions.list.getSnapshot()
|
|
24089
|
+
const workspaces = workspacesService()
|
|
24090
|
+
const archived = workspaces === null || workspaces.list === undefined
|
|
24091
|
+
? new Set()
|
|
24092
|
+
: new Set(workspaces.list.getSnapshot().archivedSessionIds ?? [])
|
|
22656
24093
|
const stored = readStoredSplitSession(libraryId)
|
|
22657
|
-
if (stored
|
|
22658
|
-
|
|
22659
|
-
|
|
22660
|
-
|
|
22661
|
-
const archived = workspaces === null || workspaces.list === undefined
|
|
22662
|
-
? new Set()
|
|
22663
|
-
: new Set(workspaces.list.getSnapshot().archivedSessionIds ?? [])
|
|
22664
|
-
const known = list === null || list.phase !== 'ready' ? undefined : list.byId?.[stored.sessionId]
|
|
22665
|
-
if (!archived.has(stored.sessionId) && (known !== undefined || list === null || list.phase !== 'ready')) {
|
|
22666
|
-
if (openHostSession(stored.sessionId)) {
|
|
22667
|
-
showNotice(format('splitReopened'))
|
|
22668
|
-
return
|
|
22669
|
-
}
|
|
24094
|
+
if (splitSessionReusable({ stored, target, list, archived, cwd: dir })) {
|
|
24095
|
+
if (openHostSession(stored.sessionId)) {
|
|
24096
|
+
showNotice(format('splitReopened'))
|
|
24097
|
+
return true
|
|
22670
24098
|
}
|
|
24099
|
+
clearStoredSplitSession(libraryId)
|
|
22671
24100
|
}
|
|
22672
24101
|
try {
|
|
22673
24102
|
await request('POST', 'toolkit/install', {})
|
|
22674
24103
|
} catch {
|
|
22675
24104
|
// Without the copy the conversation can still guide the user.
|
|
22676
24105
|
}
|
|
22677
|
-
const
|
|
22678
|
-
|
|
22679
|
-
|
|
22680
|
-
const prefill = await beginPrefill(sessionId, format('splitPrompt', {
|
|
22681
|
-
dir: library === null ? catalog.libraryDir : library.libraryDir,
|
|
22682
|
-
}))
|
|
24106
|
+
const sessionId = await createSessionId({ workspaceId: target.workspaceId, cwd: target.cwd })
|
|
24107
|
+
if (typeof sessionId !== 'string' || sessionId === '') throw new Error('session service returned no id')
|
|
24108
|
+
const prefill = await beginPrefill(sessionId, format('splitPrompt', { dir }))
|
|
22683
24109
|
if (!openHostSession(sessionId)) {
|
|
22684
|
-
|
|
24110
|
+
clearStoredSplitSession(libraryId)
|
|
24111
|
+
showNotice(format('splitResultOpenFailed'))
|
|
22685
24112
|
if (prefill.reference !== null) prefill.reference.release()
|
|
22686
|
-
return
|
|
24113
|
+
return false
|
|
24114
|
+
}
|
|
24115
|
+
// Only a conversation that is actually on screen may be remembered;
|
|
24116
|
+
// a failed open must never leave a pointer for later "reopening".
|
|
24117
|
+
writeStoredSplitSession(libraryId, sessionId, target.workspaceId, dir)
|
|
24118
|
+
if (!prefill.applied) {
|
|
24119
|
+
// The blank exists and is known to this visit (chapter New must not
|
|
24120
|
+
// adopt it), but it cannot prove a split conversation next time.
|
|
24121
|
+
clearStoredSplitSession(libraryId)
|
|
24122
|
+
showNotice(format('splitPromptMissing'))
|
|
22687
24123
|
}
|
|
22688
24124
|
if (prefill.reference !== null) {
|
|
22689
24125
|
window.setTimeout(() => {
|
|
22690
24126
|
try { prefill.reference.release() } catch { /* already released */ }
|
|
22691
24127
|
}, 500)
|
|
22692
24128
|
}
|
|
24129
|
+
return true
|
|
22693
24130
|
} catch (reason) {
|
|
22694
24131
|
setLibError(`${format('splitFailed')} (${errorText(reason)})`)
|
|
24132
|
+
showNotice(format('splitResultOpenFailed'))
|
|
24133
|
+
return false
|
|
22695
24134
|
} finally {
|
|
22696
24135
|
setLibBusy(false)
|
|
22697
24136
|
}
|
|
@@ -22842,6 +24281,18 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22842
24281
|
? (typeof catalog.target.cwd === 'string' ? catalog.target.cwd : '')
|
|
22843
24282
|
: '')
|
|
22844
24283
|
: (activeWorkspace.title === '' ? activeWorkspace.path : activeWorkspace.title)
|
|
24284
|
+
// One shelf view for the grid and the breadcrumb: membership, counters and
|
|
24285
|
+
// visibility come from `shelfView`, not from copies at the call sites.
|
|
24286
|
+
const hiddenLabel = format('hiddenShelf')
|
|
24287
|
+
const shelfPage = useMemo(() => shelfView({
|
|
24288
|
+
books,
|
|
24289
|
+
groups: shelfGroups,
|
|
24290
|
+
group,
|
|
24291
|
+
showWhole,
|
|
24292
|
+
showLoose,
|
|
24293
|
+
wholeAlways,
|
|
24294
|
+
hiddenLabel,
|
|
24295
|
+
}), [books, group, hiddenLabel, shelfGroups, showWhole, showLoose, wholeAlways])
|
|
22845
24296
|
let body
|
|
22846
24297
|
if (blockingError !== '' && (catalog === null || work === null)) {
|
|
22847
24298
|
body = h('div', { className: 'md-state md-state-error', role: 'alert' },
|
|
@@ -22941,36 +24392,14 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22941
24392
|
registerFileRef,
|
|
22942
24393
|
})
|
|
22943
24394
|
} else {
|
|
22944
|
-
const hiddenSet = new Set(shelfGroups.hidden)
|
|
22945
|
-
const shelved = new Set()
|
|
22946
|
-
for (const shelf of shelfGroups.shelves) for (const id of shelf.books) shelved.add(id)
|
|
22947
|
-
const activeShelf = group === null || group === 'hidden'
|
|
22948
|
-
? null
|
|
22949
|
-
: shelfGroups.shelves.find(shelf => shelf.id === group) ?? null
|
|
22950
|
-
const visibleBooks = group === 'hidden'
|
|
22951
|
-
? books.filter(item => hiddenSet.has(item.id))
|
|
22952
|
-
: activeShelf !== null
|
|
22953
|
-
? books.filter(item => activeShelf.books.includes(item.id))
|
|
22954
|
-
: books.filter(item => !hiddenSet.has(item.id) && !shelved.has(item.id))
|
|
22955
|
-
const groupNameForShelf = group === 'hidden'
|
|
22956
|
-
? format('hiddenShelf')
|
|
22957
|
-
: activeShelf === null ? null : activeShelf.name
|
|
22958
|
-
const collections = [
|
|
22959
|
-
...(group !== null || shelfGroups.hidden.length === 0
|
|
22960
|
-
? []
|
|
22961
|
-
: [{ id: 'hidden', name: format('hiddenShelf'), count: shelfGroups.hidden.filter(id => books.some(book => book.id === id)).length }]),
|
|
22962
|
-
...shelfGroups.shelves
|
|
22963
|
-
.filter(shelf => (shelf.parent ?? null) === group)
|
|
22964
|
-
.map(shelf => ({ id: shelf.id, name: shelf.name, count: shelf.books.filter(id => books.some(book => book.id === id)).length })),
|
|
22965
|
-
]
|
|
22966
24395
|
body = h(Shelf, {
|
|
22967
|
-
|
|
22968
|
-
|
|
22969
|
-
|
|
24396
|
+
view: shelfPage,
|
|
24397
|
+
showWhole,
|
|
24398
|
+
showLoose,
|
|
24399
|
+
onToggleWhole: toggleShowWhole,
|
|
24400
|
+
onToggleLoose: toggleShowLoose,
|
|
22970
24401
|
covers: catalog.covers,
|
|
22971
24402
|
group,
|
|
22972
|
-
groupName: groupNameForShelf,
|
|
22973
|
-
collections,
|
|
22974
24403
|
selected,
|
|
22975
24404
|
cardRefs,
|
|
22976
24405
|
onSelect: selectMany,
|
|
@@ -22982,9 +24411,16 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22982
24411
|
onTrashBook: trashBook,
|
|
22983
24412
|
onTrashSelected: trashSelected,
|
|
22984
24413
|
onCreateShelf: () => setShelfName(''),
|
|
24414
|
+
onAddToShelf: () => setShelfPick(true),
|
|
24415
|
+
canAddToShelf: shelfGroups.shelves.length > 0,
|
|
24416
|
+
showAddPdf: shelfAddPdfOn,
|
|
22985
24417
|
onHide: hideSelected,
|
|
22986
24418
|
onUnhide: unhideSelected,
|
|
22987
24419
|
onRemoveFromShelf: removeFromShelf,
|
|
24420
|
+
onWholeForm: toggleWholeForms,
|
|
24421
|
+
onResetWholeForms: resetWholeForms,
|
|
24422
|
+
wholeFormAllPinned: selectedWholeAllPinned,
|
|
24423
|
+
wholeFormApplicable,
|
|
22988
24424
|
onClear: clearSelection,
|
|
22989
24425
|
onImportPdf: () => pdfInput.current?.click(),
|
|
22990
24426
|
})
|
|
@@ -22996,11 +24432,8 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
22996
24432
|
const covered = (narrow && preview !== null) || picker !== null || reader !== null || digest !== null || shelfName !== null || settingsOpen
|
|
22997
24433
|
// The crumbs render before the catalog arrives; `work` is still null then.
|
|
22998
24434
|
const librariesView = work !== null && work.view === 'libraries'
|
|
22999
|
-
|
|
23000
|
-
|
|
23001
|
-
: group === null
|
|
23002
|
-
? null
|
|
23003
|
-
: (shelfGroups.shelves.find(shelf => shelf.id === group) ?? { name: null }).name
|
|
24435
|
+
// The crumbs name the open shelf from the same view the grid renders.
|
|
24436
|
+
const groupName = shelfPage.groupName
|
|
23004
24437
|
const libraryName = library === null || typeof library.name !== 'string' || library.name === ''
|
|
23005
24438
|
? format('shelf')
|
|
23006
24439
|
: library.name
|
|
@@ -23101,7 +24534,17 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
23101
24534
|
onClick: () => openGroup(group),
|
|
23102
24535
|
}, groupName),
|
|
23103
24536
|
book === null || librariesView ? null : h('span', { className: 'md-crumb-sep', 'aria-hidden': true }, '/'),
|
|
23104
|
-
book === null || librariesView ? null : h('span', { className: 'md-crumb-current', 'aria-current': 'page' }, book.title)
|
|
24537
|
+
book === null || librariesView ? null : h('span', { className: 'md-crumb-current', 'aria-current': 'page' }, book.title),
|
|
24538
|
+
// Inside one custom shelf: the add-PDF card's own switch, remembered
|
|
24539
|
+
// per shelf. The main shelf always offers the card.
|
|
24540
|
+
book === null && group !== null && group !== 'hidden'
|
|
24541
|
+
? h(KitButton, {
|
|
24542
|
+
type: 'button', className: 'md-btn md-btn-small md-btn-ghost md-crumbs-toggle',
|
|
24543
|
+
'aria-pressed': shelfAddPdfOn ? 'true' : 'false',
|
|
24544
|
+
title: shelfAddPdfOn ? format('shelfAddPdfOnHint') : format('shelfAddPdfOffHint'),
|
|
24545
|
+
onClick: toggleShelfAddPdf,
|
|
24546
|
+
}, `${format('shelfAddPdf')}${shelfAddPdfOn ? format('shelfAddPdfOn') : format('shelfAddPdfOff')}`)
|
|
24547
|
+
: null
|
|
23105
24548
|
),
|
|
23106
24549
|
inlineError === '' ? null : h('div', { className: 'md-alert', role: 'alert', inert: covered ? '' : undefined },
|
|
23107
24550
|
h('span', { className: 'md-alert-text' }, inlineError),
|
|
@@ -23130,7 +24573,9 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
23130
24573
|
work === null || (work.view !== 'shelf' && work.view !== 'book') ? null : h('details', { className: 'md-details md-tips' },
|
|
23131
24574
|
h('summary', { className: 'md-details-summary' }, format('tipsTitle')),
|
|
23132
24575
|
h('div', { className: 'md-tips-line' }, format('tipsLeftClick')),
|
|
23133
|
-
h('div', { className: 'md-tips-line' }, format('tipsRightClick'))
|
|
24576
|
+
h('div', { className: 'md-tips-line' }, format('tipsRightClick')),
|
|
24577
|
+
h('div', { className: 'md-tips-line' }, format('tipsDelete')),
|
|
24578
|
+
h('div', { className: 'md-tips-line' }, format('tipsCopyright'))
|
|
23134
24579
|
),
|
|
23135
24580
|
catalog === null || blockingError !== '' || work === null || work.view === 'libraries' ? null : h('details', { className: 'md-details', style: { order: 4 } },
|
|
23136
24581
|
h('summary', { className: 'md-details-summary' }, format('diagnosticsTitle')),
|
|
@@ -23287,6 +24732,14 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
23287
24732
|
onConfirm: createShelf,
|
|
23288
24733
|
onClose: () => setShelfName(null),
|
|
23289
24734
|
}),
|
|
24735
|
+
shelfPick
|
|
24736
|
+
? h(ShelfPickDialog, {
|
|
24737
|
+
shelves: shelfGroups.shelves,
|
|
24738
|
+
count: selected.size,
|
|
24739
|
+
onPick: addSelectedToShelf,
|
|
24740
|
+
onClose: () => setShelfPick(false),
|
|
24741
|
+
})
|
|
24742
|
+
: null,
|
|
23290
24743
|
reader === null
|
|
23291
24744
|
? null
|
|
23292
24745
|
: h(ReaderView, {
|
|
@@ -23424,7 +24877,24 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
23424
24877
|
: h(SplitDialog, {
|
|
23425
24878
|
book: splitBook,
|
|
23426
24879
|
onClose: () => setSplitBook(null),
|
|
23427
|
-
onDone:
|
|
24880
|
+
onDone: async result => {
|
|
24881
|
+
const doneBook = splitBook
|
|
24882
|
+
// A split started from a custom shelf belongs in that shelf right
|
|
24883
|
+
// away; `fileSplitBooks` waits for the refresh, matches the folder
|
|
24884
|
+
// and files the new books before the result dialog opens.
|
|
24885
|
+
setSplitBook(null)
|
|
24886
|
+
await fileSplitBooks({ book: doneBook, group, groups: shelfGroups, reload, saveShelfGroups })
|
|
24887
|
+
setSplitResult({ book: doneBook, result })
|
|
24888
|
+
},
|
|
24889
|
+
}),
|
|
24890
|
+
splitResult === null
|
|
24891
|
+
? null
|
|
24892
|
+
: h(SplitResultDialog, {
|
|
24893
|
+
book: splitResult.book,
|
|
24894
|
+
result: splitResult.result,
|
|
24895
|
+
onClose: () => setSplitResult(null),
|
|
24896
|
+
onRemoved: () => reload(),
|
|
24897
|
+
onOpenConversation: () => startSplitSession(),
|
|
23428
24898
|
}),
|
|
23429
24899
|
// Asked right after a PDF lands in 整本\: the file is already imported, so
|
|
23430
24900
|
// "later" costs nothing and the answer is never a blocking dialog.
|
|
@@ -23433,12 +24903,27 @@ html[data-platform='darwin'] .md-head { padding-top: calc(var(--dsh-frame-top-cl
|
|
|
23433
24903
|
: h(KitModal, {
|
|
23434
24904
|
title: format('importSplitAskTitle'),
|
|
23435
24905
|
onClose: () => setImportAsk(null),
|
|
23436
|
-
children: h(
|
|
24906
|
+
children: h(React.Fragment, null,
|
|
24907
|
+
h('p', { className: 'md-env-body' }, format('importSplitAsk', { title: importAsk.title })),
|
|
24908
|
+
h('label', { className: 'md-settings-row' },
|
|
24909
|
+
h('input', {
|
|
24910
|
+
type: 'checkbox',
|
|
24911
|
+
checked: rememberImportSplit,
|
|
24912
|
+
onChange: event => setRememberImportSplit(event.target.checked),
|
|
24913
|
+
}),
|
|
24914
|
+
h('span', null, format('importSplitRemember')))),
|
|
23437
24915
|
footer: [
|
|
23438
|
-
h(KitButton, {
|
|
24916
|
+
h(KitButton, {
|
|
24917
|
+
key: 'later', variant: 'ghost',
|
|
24918
|
+
onClick: () => {
|
|
24919
|
+
if (rememberImportSplit) writeImportSplitChoice('later')
|
|
24920
|
+
setImportAsk(null)
|
|
24921
|
+
},
|
|
24922
|
+
}, format('importSplitLater')),
|
|
23439
24923
|
h(KitButton, {
|
|
23440
24924
|
key: 'split', variant: 'primary',
|
|
23441
24925
|
onClick: () => {
|
|
24926
|
+
if (rememberImportSplit) writeImportSplitChoice('split')
|
|
23442
24927
|
const book = importAsk
|
|
23443
24928
|
setImportAsk(null)
|
|
23444
24929
|
setSplitBook(book)
|