@lincyaw/workbench 0.2.0-rc.4 → 0.2.0-rc.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/package.json +5 -4
  2. package/src/MediaClipEditor.tsx +1 -1
  3. package/src/authoring-client.ts +3 -3
  4. package/src/authoring-draft-fragment.ts +3 -1
  5. package/src/component-property-drafts.ts +5 -5
  6. package/src/components.tsx +10 -28
  7. package/src/context.tsx +2 -1
  8. package/src/diagnostics.ts +1 -1
  9. package/src/document-drafts.ts +6 -7
  10. package/src/document-editing.ts +484 -0
  11. package/src/document-editor/BlockNoteSurface.tsx +25 -9
  12. package/src/document-editor/ComponentMaterials.tsx +3 -9
  13. package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
  14. package/src/document-editor/DocumentBlockPreview.tsx +4 -2
  15. package/src/document-editor/DocumentComments.tsx +58 -9
  16. package/src/document-editor/DocumentEditor.tsx +44 -7
  17. package/src/document-editor/DocumentStepNarration.tsx +30 -25
  18. package/src/document-editor/NarrationEditor.tsx +54 -20
  19. package/src/document-editor/NewCommentDrafts.tsx +4 -3
  20. package/src/document-editor/PlaceComment.tsx +150 -0
  21. package/src/document-editor/comment-drafts.ts +16 -14
  22. package/src/document-editor/comments.ts +30 -10
  23. package/src/document-editor/component-label.ts +11 -0
  24. package/src/document-editor/file-input.ts +2 -2
  25. package/src/document-editor/focus.ts +0 -2
  26. package/src/document-editor/insertion-place.ts +60 -0
  27. package/src/document-editor/messages.ts +3 -3
  28. package/src/document-editor/narration-schema.tsx +12 -6
  29. package/src/document-editor/narration.ts +19 -3
  30. package/src/document-editor/page-body.ts +60 -0
  31. package/src/document-editor/projection.ts +2 -2
  32. package/src/document-editor/rich-text.ts +3 -2
  33. package/src/document-editor/selection.ts +13 -0
  34. package/src/document-editor/style.css +12 -1
  35. package/src/document-editor/table-identities.ts +2 -1
  36. package/src/document-production.ts +331 -0
  37. package/src/document-session.ts +50 -16
  38. package/src/history.ts +3 -3
  39. package/src/index.ts +5 -5
  40. package/src/jobs.ts +1 -1
  41. package/src/messages.ts +19 -4
  42. package/src/panels/DocumentView.tsx +21 -21
  43. package/src/panels/DocumentVoiceDialog.tsx +2 -2
  44. package/src/panels/DocumentVoiceField.tsx +1 -1
  45. package/src/panels/ExportPanel.tsx +1 -6
  46. package/src/panels/HistoryPanel.tsx +1 -1
  47. package/src/panels/PageDeleteDialog.tsx +4 -4
  48. package/src/panels/PageRenameDialog.tsx +1 -1
  49. package/src/panels/PreviewPanel.tsx +1 -4
  50. package/src/panels/ProductionCaptionSize.tsx +20 -0
  51. package/src/panels/ProductionCaptionTiming.tsx +7 -7
  52. package/src/panels/ProductionMediaClips.tsx +6 -5
  53. package/src/panels/ProductionPanel.tsx +7 -3
  54. package/src/panels/ProductionRecording.tsx +1 -1
  55. package/src/panels/ProductionRecordingRange.tsx +4 -4
  56. package/src/panels/ProductionTimeline.tsx +6 -1
  57. package/src/panels/ProductionTranscription.tsx +5 -4
  58. package/src/panels/SourceDocumentPanel.tsx +12 -15
  59. package/src/panels/TranscriptionAdoption.tsx +9 -8
  60. package/src/panels/VoiceoverDialog.tsx +1 -1
  61. package/src/places.ts +1 -36
  62. package/src/preview-playback.ts +1 -1
  63. package/src/production-messages.ts +6 -0
  64. package/src/production-playback.ts +1 -1
  65. package/src/production-voice-playback.ts +3 -2
  66. package/src/sha256.ts +9 -0
  67. package/src/styles.css +16 -41
  68. package/src/use-recording-adoption.ts +2 -2
  69. package/src/voiceover-jobs.ts +1 -1
  70. package/src/workbench-state.ts +157 -0
  71. package/src/workbench.ts +101 -932
  72. package/src/workspace-client.ts +2 -1
  73. package/src/assistant-mascot.ts +0 -62
  74. package/src/mascot-preference.ts +0 -37
  75. package/src/panels/ChangeTrail.tsx +0 -79
@@ -1,8 +1,9 @@
1
- import { hasRole, validateDocument } from '@lincyaw/kernel'
1
+ import { hasRole, isRecord, randomUUID, validateDocument } from '@lincyaw/kernel'
2
2
  import type { DocumentAnswer, DocumentChangeAnswer, DocumentImageImportAnswer, DocumentIssue, Member, TeachingDocument } from '@lincyaw/kernel'
3
3
  import { WorkspaceServerError } from './workspace-client.ts'
4
4
  import type { WorkspaceClient } from './workspace-client.ts'
5
5
  import { DocumentDrafts } from './document-drafts.ts'
6
+ import { sha256 } from './sha256.ts'
6
7
  import type { DocumentDraftChoice, DocumentDraftCommit, DocumentDraftReference, StoredDocumentDraft } from './document-drafts.ts'
7
8
 
8
9
  export interface DocumentSessionState {
@@ -34,6 +35,7 @@ interface Slot {
34
35
  compositions: Set<string>
35
36
  input: number
36
37
  baseHash: string
38
+ baseContent: TeachingDocument
37
39
  storage: string
38
40
  drafts: DocumentDrafts
39
41
  backup?: DocumentDraftCommit
@@ -88,10 +90,21 @@ function keepsEditorContent(before: TeachingDocument, after: TeachingDocument):
88
90
  }
89
91
 
90
92
  async function digest(value: TeachingDocument): Promise<string> {
91
- const text = serialize(value)
92
- if (!globalThis.crypto?.subtle) return `json:${text}`
93
- const bytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))
94
- return [...new Uint8Array(bytes)].map(value => value.toString(16).padStart(2, '0')).join('')
93
+ return sha256(serialize(value))
94
+ }
95
+
96
+ /** Replay pending author input on a newer saved document; an overlapping value belongs to the author. */
97
+ function rebaseDocument(base: TeachingDocument, local: TeachingDocument, remote: TeachingDocument): TeachingDocument {
98
+ const merge = (before: unknown, author: unknown, saved: unknown): unknown => {
99
+ if (serialize(author) === serialize(before)) return structuredClone(saved)
100
+ if (serialize(saved) === serialize(before) || serialize(author) === serialize(saved)) return structuredClone(author)
101
+ if (isRecord(before) && isRecord(author) && isRecord(saved)) return Object.fromEntries([...new Set([...Object.keys(before), ...Object.keys(author), ...Object.keys(saved)])]
102
+ .map(key => [key, merge(before[key], author[key], saved[key])] as const).filter(([, value]) => value !== undefined))
103
+ return structuredClone(author)
104
+ }
105
+ const merged = validateDocument(merge(base, local, remote))
106
+ // A structural conflict is one document operation: preserve the author's valid complete document.
107
+ return merged.document && !merged.issues.some(issue => issue.severity === 'error') ? merged.document : structuredClone(local)
95
108
  }
96
109
 
97
110
  /** One source actor per document. Runtime compilation and iframe lifecycle never own its input. */
@@ -142,7 +155,7 @@ export class DocumentSession {
142
155
  const baseHash = await digest(answer.content)
143
156
  if (this.#disposed || this.#active !== directory || opening !== this.#opening) return
144
157
  const drafts = new DocumentDrafts(() => { if (slot && !this.#disposed) void this.#readDrafts(slot) })
145
- slot = { input: 0, read: 0, compositions: new Set(), drafts, baseHash, storage: `presmium.document.v1:${JSON.stringify([info.root, answer.content.id])}`, state: { directory, member: info.member, identity: JSON.stringify([info.root, answer.content.id]), content: answer.content, version: answer.version, fingerprint: answer.fingerprint, loading: true, dirty: false, saving: false, restored: false, composing: false, storageFailure: false, reset: 0, issues: answer.issues } }
158
+ slot = { input: 0, read: 0, compositions: new Set(), drafts, baseHash, baseContent: structuredClone(answer.content), storage: `presmium.document.v1:${JSON.stringify([info.root, answer.content.id])}`, state: { directory, member: info.member, identity: JSON.stringify([info.root, answer.content.id]), content: answer.content, version: answer.version, fingerprint: answer.fingerprint, loading: true, dirty: false, saving: false, restored: false, composing: false, storageFailure: false, reset: 0, issues: answer.issues } }
146
159
  this.#slots.set(directory, slot)
147
160
  await this.#restore(slot, answer)
148
161
  } else {
@@ -235,11 +248,19 @@ export class DocumentSession {
235
248
  slot.baseHash = remoteHash; slot.pendingHash = undefined
236
249
  slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, error: undefined, issues: answer.issues }
237
250
  } else if (remoteHash === slot.baseHash) slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, issues: answer.issues }
238
- else slot.state = { ...slot.state, error: 'document-version-changed', issues: answer.issues }
251
+ else if (!slot.state.composing) {
252
+ const content = rebaseDocument(slot.baseContent, slot.state.content!, answer.content)
253
+ const reset = slot.state.reset + (keepsEditorContent(slot.state.content!, content) ? 0 : 1)
254
+ slot.baseHash = remoteHash
255
+ slot.pendingHash = undefined
256
+ slot.state = { ...slot.state, content, reset, version: answer.version, fingerprint: answer.fingerprint, error: undefined, dirty: true, issues: answer.issues }
257
+ }
258
+ if (slot.state.version === answer.version) slot.baseContent = structuredClone(answer.content)
239
259
  return
240
260
  }
241
261
  const reset = slot.state.reset + (keepsEditorContent(slot.state.content!, answer.content) ? 0 : 1)
242
262
  slot.baseHash = remoteHash
263
+ slot.baseContent = structuredClone(answer.content)
243
264
  slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, content: answer.content, reset, error: undefined, issues: answer.issues }
244
265
  }
245
266
 
@@ -288,7 +309,7 @@ export class DocumentSession {
288
309
  else if (slot.timer !== undefined) return
289
310
  if (this.#readOnly(slot) || slot.flight || slot.assetFlight || !slot.state.dirty || slot.state.composing || slot.state.restored || slot.state.error || !slot.state.content || !slot.state.version) return
290
311
  slot.read++
291
- const flight = { id: crypto.randomUUID(), input: slot.input, content: structuredClone(slot.state.content), baseVersion: slot.state.version, hash: undefined as string | undefined }
312
+ const flight = { id: randomUUID(), input: slot.input, content: structuredClone(slot.state.content), baseVersion: slot.state.version, hash: undefined as string | undefined }
292
313
  slot.flight = flight
293
314
  slot.state = { ...slot.state, saving: true }; this.#emit(slot)
294
315
  try {
@@ -299,7 +320,12 @@ export class DocumentSession {
299
320
  if (answer.changeId !== flight.id || answer.document !== slot.state.directory || answer.content.id !== flight.content.id) throw new Error('document-confirmation')
300
321
  this.#ack(slot, flight, answer)
301
322
  } catch (error) {
302
- slot.state = { ...slot.state, saving: false, error: this.#error(error), issues: this.#issues(error) }
323
+ if (this.#error(error) === 'document-version-changed' && !slot.state.composing) {
324
+ try {
325
+ await this.#adopt(slot, await this.#client.readDocument(slot.state.directory))
326
+ slot.state = { ...slot.state, saving: false }
327
+ } catch (refreshError) { slot.state = { ...slot.state, saving: false, error: this.#error(refreshError), issues: this.#issues(refreshError) } }
328
+ } else slot.state = { ...slot.state, saving: false, error: this.#error(error), issues: this.#issues(error) }
303
329
  } finally {
304
330
  if (slot.flight === flight) slot.flight = undefined
305
331
  this.#persist(slot); this.#emit(slot)
@@ -310,6 +336,7 @@ export class DocumentSession {
310
336
  }
311
337
  #ack(slot: Slot, flight: NonNullable<Slot['flight']>, answer: DocumentChangeAnswer): void {
312
338
  slot.baseHash = flight.hash!
339
+ slot.baseContent = structuredClone(answer.content)
313
340
  slot.pendingHash = undefined
314
341
  const same = slot.input === flight.input
315
342
  slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, ...(same ? { content: answer.content } : {}), dirty: !same, saving: false, error: undefined, issues: answer.issues }
@@ -328,6 +355,7 @@ export class DocumentSession {
328
355
  const same = slot.input === input, content = same ? answer.content : structuredClone(current)
329
356
  if (!same) for (const [id, asset] of added) content.assets[id] = structuredClone(asset)
330
357
  slot.baseHash = baseHash
358
+ slot.baseContent = structuredClone(answer.content)
331
359
  slot.state = { ...slot.state, content, version: answer.version, fingerprint: answer.fingerprint, dirty: !same, error: undefined, issues: answer.issues }
332
360
  return true
333
361
  }
@@ -342,6 +370,7 @@ export class DocumentSession {
342
370
  const checked = validateDocument(content)
343
371
  if (!checked.document || checked.issues.some(issue => issue.severity === 'error')) return false
344
372
  slot.baseHash = baseHash
373
+ slot.baseContent = structuredClone(answer.content)
345
374
  slot.pendingHash = undefined
346
375
  slot.state = { ...slot.state, content: structuredClone(checked.document), version: answer.version, fingerprint: answer.fingerprint,
347
376
  dirty: slot.input !== input || slot.state.composing || serialize(content) !== serialize(answer.content), error: undefined, issues: answer.issues }
@@ -406,7 +435,7 @@ export class DocumentSession {
406
435
  const before = structuredClone(slot.state.content), input = slot.input, version = slot.state.version
407
436
  let request = this.#imageImports.get(file)
408
437
  if (!request || request.identity !== identity || request.version !== version) {
409
- request = { identity, version, id: crypto.randomUUID() }
438
+ request = { identity, version, id: randomUUID() }
410
439
  this.#imageImports.set(file, request)
411
440
  }
412
441
  const read = ++slot.read
@@ -609,7 +638,12 @@ export class DocumentSession {
609
638
  const answer = await this.#client.readDocument(slot.state.directory)
610
639
  if (!current()) return
611
640
  if (answer.document !== slot.state.directory || answer.content.id !== documentId) { slot.state = { ...slot.state, error: 'document-identity-changed' }; return }
612
- const [localHash, remoteHash] = await Promise.all([digest(candidate.content), digest(answer.content)])
641
+ // Older LAN HTTP drafts stored canonical JSON in place of a SHA-256 fingerprint.
642
+ const [localHash, remoteHash, candidateBaseHash, pendingHash] = await Promise.all([
643
+ digest(candidate.content), digest(answer.content),
644
+ candidate.baseHash.startsWith('json:') ? sha256(candidate.baseHash.slice(5)) : candidate.baseHash,
645
+ candidate.pendingHash?.startsWith('json:') ? sha256(candidate.pendingHash.slice(5)) : candidate.pendingHash,
646
+ ])
613
647
  if (!current()) return
614
648
  const origins = [...new Map([...(candidate.origins ?? []), { id: candidate.id, revision: candidate.revision, token: candidate.token }].map(value => [JSON.stringify([value.id, value.revision, value.token]), value])).values()]
615
649
  if (localHash === remoteHash && !candidate.composing) {
@@ -618,16 +652,16 @@ export class DocumentSession {
618
652
  slot.persistFailure = !settled
619
653
  return
620
654
  }
621
- const conflict = answer.version !== candidate.baseVersion && remoteHash !== candidate.baseHash && remoteHash !== candidate.pendingHash
622
- const version = remoteHash === candidate.pendingHash || remoteHash === candidate.baseHash ? answer.version : candidate.baseVersion
623
- const baseHash = remoteHash === candidate.pendingHash ? remoteHash : candidate.baseHash
655
+ const conflict = answer.version !== candidate.baseVersion && remoteHash !== candidateBaseHash && remoteHash !== pendingHash
656
+ const version = remoteHash === pendingHash || remoteHash === candidateBaseHash ? answer.version : candidate.baseVersion
657
+ const baseHash = remoteHash === pendingHash ? remoteHash : candidateBaseHash
624
658
  const record = await slot.drafts.fork(identity, { content: candidate.content, baseVersion: version, baseHash, input: input + 1,
625
- pendingHash: candidate.pendingHash, composing: Boolean(candidate.composing), origins })
659
+ pendingHash, composing: Boolean(candidate.composing), origins })
626
660
  if (!current()) { if (record) slot.drafts.archive(record); return }
627
661
  if (!record) { slot.persistFailure = true; slot.state = { ...slot.state, storageFailure: true }; return }
628
662
  clearTimeout(slot.timer); slot.timer = undefined
629
663
  if (slot.draft) slot.drafts.archive(slot.draft)
630
- slot.input = input + 1; slot.baseHash = baseHash; slot.pendingHash = candidate.pendingHash; slot.draft = record; slot.draftOrigins = origins
664
+ slot.input = input + 1; slot.baseHash = baseHash; slot.pendingHash = pendingHash; slot.draft = record; slot.draftOrigins = origins
631
665
  slot.backup = undefined; slot.persistFailure = false
632
666
  adopted = true
633
667
  slot.compositions.clear()
package/src/history.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { errorMessage } from '@lincyaw/kernel'
1
+ import { errorMessage, randomUUID } from '@lincyaw/kernel'
2
2
  import type { RevertResult, ReviewChange, ReviewSnapshot, ReviewUpdate } from '@lincyaw/kernel'
3
- import type { WorkbenchStore } from './workbench.ts'
3
+ import type { WorkbenchStore } from './workbench-state.ts'
4
4
  import { WorkspaceServerError } from './workspace-client.ts'
5
5
  import type { WorkspaceClient } from './workspace-client.ts'
6
6
 
@@ -129,7 +129,7 @@ export class DocumentHistory {
129
129
  #change(which: 'undo' | 'redo' | 'revertRevision', expect: string | undefined): Promise<boolean> {
130
130
  const binding = this.#store.state.history?.historyBinding
131
131
  if (!binding || !expect) return Promise.resolve(false)
132
- const request = { id: crypto.randomUUID(), ...binding, expect }
132
+ const request = { id: randomUUID(), ...binding, expect }
133
133
  return this.#run(dir => this.#client[which](dir, request))
134
134
  }
135
135
 
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { DocumentEditing } from './document-editing.ts'
2
+ export { DocumentProduction } from './document-production.ts'
1
3
  export * from './components.tsx'
2
4
  export { PmSchemaForm, schemaFormPropertyNames } from './schema-form/PmSchemaForm.tsx'
3
5
  export type { PmSchemaFormProps } from './schema-form/PmSchemaForm.tsx'
@@ -14,8 +16,9 @@ export { findPlaceAtLine, findPlaceSource } from './places.ts'
14
16
  export type { PlaceWithSource } from './places.ts'
15
17
  export { connectPreview } from './preview.ts'
16
18
  export type { PreviewConnection, PreviewHandlers } from './preview.ts'
17
- export { documentDirFor, hasSlides, isAgentChanging, selectedDocument, Workbench } from './workbench.ts'
18
- export type { AgentAnswer, AgentRequest, Pointer, PreviewSink, SaveState, WebView, WorkbenchMode, WorkbenchState } from './workbench.ts'
19
+ export { documentDirFor, hasSlides, Workbench } from './workbench.ts'
20
+ export { isAgentChanging, selectedDocument } from './workbench-state.ts'
21
+ export type { AgentAnswer, AgentRequest, Pointer, PreviewSink, SaveState, WebView, WorkbenchMode, WorkbenchState } from './workbench-state.ts'
19
22
  export { OperationLog } from './telemetry.ts'
20
23
  export type { OperationBatch, OperationValue } from './telemetry.ts'
21
24
  export { isObservedWorkspaceFailure, workspaceClient, WorkspaceServerError } from './workspace-client.ts'
@@ -26,9 +29,6 @@ export { HistoryPanel } from './panels/HistoryPanel.tsx'
26
29
  export type { HistoryPanelProps, HistoryRevisionAction } from './panels/HistoryPanel.tsx'
27
30
  export { HomePanel } from './panels/HomePanel.tsx'
28
31
  export { WorkbenchApprovals } from './approvals.tsx'
29
- export { assistantMascotAction, useAssistantMascot } from './assistant-mascot.ts'
30
- export type { AssistantActivity } from './assistant-mascot.ts'
31
- export { mascotEnabled, setMascotEnabled, useMascotEnabled } from './mascot-preference.ts'
32
32
  export { PreviewPanel } from './panels/PreviewPanel.tsx'
33
33
  export { SpeechSettingsPanel } from './panels/SpeechSettingsPanel.tsx'
34
34
  export { SPEECH_SETTINGS_MESSAGES } from './speech-settings-messages.ts'
package/src/jobs.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { errorMessage } from '@lincyaw/kernel'
2
2
  import type { CompileJob, JobSource } from '@lincyaw/kernel'
3
- import type { WorkbenchStore } from './workbench.ts'
3
+ import type { WorkbenchStore } from './workbench-state.ts'
4
4
  import type { WorkspaceClient } from './workspace-client.ts'
5
5
 
6
6
  /** Of two copies of a job (an event and an answer cross on the way), the one of the later change. */
package/src/messages.ts CHANGED
@@ -12,6 +12,11 @@ export interface AgentPlace {
12
12
 
13
13
  // A Latin word or a number set after Chinese text is spaced from it (docs/glossary.md 2).
14
14
  const spaced = (text: string) => (/^[A-Za-z0-9]/.test(text) ? ` ${text}` : text)
15
+ // The start of a passage, enough to recognize it.
16
+ const excerpt = (text: string, length: number) => [...text].length > length ? `${[...text].slice(0, length).join('').trimEnd()}…` : text
17
+
18
+ /** Where on a page the author asks for new content: after a passage (its text, '' for content without text), at the start (none) or at the end. */
19
+ interface AgentInsertion { after?: string, end: boolean }
15
20
 
16
21
  // Names of commands follow Microsoft Word's (撤消/Undo, 新建批注/New Comment, 版本历史/Version History…).
17
22
  const zh = {
@@ -325,11 +330,11 @@ const zh = {
325
330
  'history-result-no-longer-current': '之前的结果已不是当前版本,请查看最新的历史。',
326
331
  'authoring-review-required': '有修改等待你审阅,请先接受或放弃。',
327
332
  } as Record<string, string>,
328
- agentWorking: 'AI 正在修改文稿…',
329
333
  agentWaiting: (n: number) => `AI 修改了 ${n} 处内容,要接受这些修改吗?`,
330
334
  accept: '接受',
331
335
  reject: '拒绝',
332
- problems: (n: number) => `有 ${n} 处内容无法正确显示。`,
336
+ problems: (n: number) => `文稿有 ${n} 个问题需要处理。`,
337
+ problemsTitle: '文稿中的问题',
333
338
  fixWithAi: '用 AI 修复',
334
339
  fixing: '正在发送给 AI…',
335
340
  fixFailed: (reason: string) => `无法发送给 AI。${reason}`,
@@ -356,6 +361,11 @@ const zh = {
356
361
  place.quote ? `\n原文:“${place.quote}”` : '',
357
362
  ].join('')).filter(Boolean),
358
363
  ].join('\n\n'),
364
+ animationRequest: (page: number, title: string, place: AgentInsertion) => {
365
+ const at = `第 ${page} 页${title ? `“${title}”` : ''}`
366
+ return place.end ? `在${at}的末尾加一个动画:` : place.after === undefined ? `在${at}的开头加一个动画:`
367
+ : place.after ? `在${at}中“${excerpt(place.after, 16)}”这一段之后加一个动画:` : `在${at}的这个位置加一个动画:`
368
+ },
359
369
  commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
360
370
  comments.length === 1 ? '我在文稿上写了一条批注:' : `我在文稿上写了 ${comments.length} 条批注:`,
361
371
  ...comments.map((comment, i) => [
@@ -689,11 +699,11 @@ const en: WorkbenchMessages = {
689
699
  'history-result-no-longer-current': 'The earlier result is no longer the current version. Review the latest history.',
690
700
  'authoring-review-required': 'Changes are waiting for your review. Accept or discard them first.',
691
701
  },
692
- agentWorking: 'The AI is editing the document…',
693
702
  agentWaiting: (n: number) => `The AI changed ${n} file${n === 1 ? '' : 's'}. Accept the changes?`,
694
703
  accept: 'Accept',
695
704
  reject: 'Reject',
696
- problems: (n: number) => `${n} item${n === 1 ? '' : 's'} can’t be displayed correctly.`,
705
+ problems: (n: number) => `The document has ${n} problem${n === 1 ? '' : 's'} to fix.`,
706
+ problemsTitle: 'Problems in the Document',
697
707
  fixWithAi: 'Fix with AI',
698
708
  fixing: 'Sending to the AI…',
699
709
  fixFailed: (reason: string) => `Couldn’t send to the AI. ${reason}`,
@@ -720,6 +730,11 @@ const en: WorkbenchMessages = {
720
730
  place.quote ? `\nText: “${place.quote}”` : '',
721
731
  ].join('')).filter(Boolean),
722
732
  ].join('\n\n'),
733
+ animationRequest: (page: number, title: string, place: AgentInsertion) => {
734
+ const at = `page ${page}${title ? `, “${title}”` : ''}`
735
+ return place.end ? `Add an animation at the end of ${at}: ` : place.after === undefined ? `Add an animation at the start of ${at}: `
736
+ : place.after ? `Add an animation on ${at}, after the paragraph “${excerpt(place.after, 40)}”: ` : `Add an animation at this point on ${at}: `
737
+ },
723
738
  commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
724
739
  comments.length === 1 ? 'I left a comment on the document:' : `I left ${comments.length} comments on the document:`,
725
740
  ...comments.map((comment, i) => [
@@ -1,11 +1,11 @@
1
1
  import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
2
2
  import type { ReactNode, RefObject } from 'react'
3
- import { PmButton, PmIconButton, PmMascot, PmMenu, PmNotice, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
3
+ import { PmButton, PmDialog, PmIconButton, PmMenu, PmNotice, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
4
4
  import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
5
  import { failureReason, timeAgo } from '../messages.ts'
6
6
  import { SHORTCUTS } from '../shortcuts.ts'
7
7
  import { DocumentOutline, DocumentWordCounter } from '../outline.ts'
8
- import { isAgentChanging } from '../workbench.ts'
8
+ import { isAgentChanging } from '../workbench-state.ts'
9
9
  import { ExportPanel } from './ExportPanel.tsx'
10
10
  import { HistoryPanel } from './HistoryPanel.tsx'
11
11
  import type { HistoryRevisionAction } from './HistoryPanel.tsx'
@@ -198,7 +198,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
198
198
  <DocumentNotices />
199
199
  <div className="pmw-document__body" role="region" aria-label={producing ? PRODUCTION_MESSAGES[workbench.getState().locale].title : presenting ? t.presentationPreview : reading ? t.readDocument : t.documentEditor}>
200
200
  {!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (matchMedia('(max-width: 1279px)').matches) setNavigation(false) }} />}
201
- <div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} /></div>{producing && <ProductionPanel active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
201
+ <div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} onOpenComments={() => setAside('comments')} /></div>{producing && <ProductionPanel active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
202
202
  {!presenting && !producing && !reading && aside && (
203
203
  <aside className="pmw-document__aside pm-ui-block-editor" aria-label={{ narration: t.documentNarration, comments: t.comments, export: t.exportPane, history: t.versionHistory }[aside]}>
204
204
  {aside === 'comments' ? <section className="pmw-pane"><header className="pmw-pane__header"><h2 className="pmw-pane__title">{t.comments}</h2><PmIconButton small icon="close" label={t.close} onClick={() => setAside(null)} /></header><div ref={setCommentsPortal} /></section> : aside === 'narration' ? <DocumentNarrationPanel onClose={() => setAside(null)} /> : aside === 'export' ? <ExportPanel documentOnly onClose={() => setAside(null)} /> : <HistoryPanel onClose={() => setAside(null)} revisionAction={historyRevisionAction} />}
@@ -238,7 +238,7 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
238
238
  const pages = editing || slides
239
239
  const top = Math.min(...items.map(item => Math.max(1, item.depth)))
240
240
  const pageActions = (item: typeof items[number], index: number) => {
241
- const capability = workbench.pageEditCapability(item.id), previousPeer = index > 0, nextPeer = index < items.length - 1
241
+ const capability = workbench.editing.pageCapability(item.id), previousPeer = index > 0, nextPeer = index < items.length - 1
242
242
  return <PmMenu label={t.pageMore(item.title)} description={capability.reason} triggerRef={node => { if (node) menuTriggers.current.set(item.id, node); else menuTriggers.current.delete(item.id) }} items={[
243
243
  { id: 'rename', label: t.rename, icon: 'edit', disabled: !capability.rename || !canCreate || pageBusy || creating },
244
244
  { id: 'copy', label: t.pageCopy, icon: 'copy', disabled: !canCreate || pageBusy || creating },
@@ -246,19 +246,19 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
246
246
  { id: 'down', label: t.movePageDown, disabled: !capability.move || !canCreate || pageBusy || creating || !nextPeer },
247
247
  ...(canDelete ? [{ id: 'delete', label: t.pageDelete, icon: 'trash' as const, danger: true, separator: true, disabled: !canCreate || pageBusy || creating }] : []),
248
248
  ]} onSelect={id => {
249
- workbench.clearPageEditFailure()
249
+ workbench.editing.clearFailure()
250
250
  if (id === 'rename') setRenaming({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
251
- else if (id === 'copy') void workbench.duplicatePage(item.id)
251
+ else if (id === 'copy') void workbench.editing.duplicatePage(item.id)
252
252
  else if (id === 'delete') setDeleting({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
253
- else if (id === 'up' && index > 0) void workbench.movePage(item.id, items[index - 1]!.id)
254
- else if (id === 'down') void workbench.movePage(item.id, items[index + 2]?.id ?? null)
253
+ else if (id === 'up' && index > 0) void workbench.editing.movePage(item.id, items[index - 1]!.id)
254
+ else if (id === 'down') void workbench.editing.movePage(item.id, items[index + 2]?.id ?? null)
255
255
  }} />
256
256
  }
257
257
  return (
258
258
  <nav className="pmw-navigation" aria-label={t.navigation}>
259
259
  <header className="pmw-pane__header">
260
260
  <h2 className="pmw-pane__title">{editing ? t.pages : slides ? t.renderers.slides : t.navigation}</h2>
261
- {editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.createPage()) onSelect() }} />}
261
+ {editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }} />}
262
262
  <PmIconButton icon="close" label={t.closeNavigation} small onClick={onClose} />
263
263
  </header>
264
264
  {failure && !renaming && !deleting && <PmNotice tone="danger">{failure}</PmNotice>}
@@ -266,13 +266,13 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
266
266
  : items.length === 0
267
267
  ? <p className="pmw-muted pmw-navigation__empty">{t.noSections}</p>
268
268
  : editing ? <PmSortableList label={t.pages} scopeKey={JSON.stringify([identity, documentId, document])} resetKey={reset} className="pmw-navigation__list" locale={locale}
269
- items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.pageEditCapability(item.id).move, actions: pageActions(item, index) }))}
269
+ items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.editing.pageCapability(item.id).move, actions: pageActions(item, index) }))}
270
270
  value={current} reorderDisabled={reorderDisabled} loading={pageBusy || creating}
271
271
  onSelect={id => { workbench.goToSection(id); onSelect() }}
272
272
  onMove={async (id, before) => {
273
273
  const state = workbench.getState()
274
274
  if (state.document !== document || state.authoring?.identity !== identity || state.authoring?.content?.id !== documentId) return
275
- if (!await workbench.movePage(id, before)) throw new Error('page-reorder-failed')
275
+ if (!await workbench.editing.movePage(id, before)) throw new Error('page-reorder-failed')
276
276
  }} /> : (
277
277
  <ol className="pmw-navigation__list" data-kind={pages ? 'slides' : 'headings'}>
278
278
  {items.map(item => (
@@ -291,8 +291,8 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
291
291
  ))}
292
292
  </ol>
293
293
  )}
294
- {renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.clearPageEditFailure() }} />}
295
- {deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.clearPageEditFailure() }} />}
294
+ {renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.editing.clearFailure() }} />}
295
+ {deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.editing.clearFailure() }} />}
296
296
  </nav>
297
297
  )
298
298
  }
@@ -409,10 +409,8 @@ function DocumentNotices() {
409
409
  const askFailure = useWorkbenchState(state => (state.pointer ? undefined : state.askFailure))
410
410
  return (
411
411
  <div className="pmw-notices">
412
- {review?.running && <PmNotice tone="accent"><PmMascot size="small" action={review.changes.length > 0 ? 'write' : 'read'} />{t.agentWorking}</PmNotice>}
413
412
  {review && !review.running && review.changes.length > 0 && (
414
413
  <PmNotice tone="accent">
415
- <PmMascot size="small" action="ask" />
416
414
  <span>{t.agentWaiting(review.changes.length)}</span>
417
415
  <span className="pmw-notice__actions">
418
416
  <PmButton small onClick={() => void workbench.rejectReview()}>{t.reject}</PmButton>
@@ -431,7 +429,7 @@ function DocumentNotices() {
431
429
  )
432
430
  }
433
431
 
434
- /** Content that did not display, said plainly, with the AI to fix it and the details for whoever wants them. */
432
+ /** The document's problems in one line above the page, with the AI to fix them; the list itself opens in a dialog. */
435
433
  function ProblemsNotice() {
436
434
  const t = useMessages()
437
435
  const workbench = useWorkbench()
@@ -440,23 +438,25 @@ function ProblemsNotice() {
440
438
  const canRepair = useWorkbenchState(state => state.canRepairDiagnostics)
441
439
  const repairing = useWorkbenchState(state => state.isRepairingDiagnostics)
442
440
  const repairFailure = useWorkbenchState(state => state.diagnosticsRepairFailure)
441
+ const [open, setOpen] = useState(false)
443
442
  if (workbench.client.capabilities?.diagnostics === 'none') return null
444
443
  const problems = (snapshot?.diagnostics ?? []).filter(diagnostic => diagnostic.severity === 'error' && !diagnostic.checkId.startsWith('presmium.workbench.'))
445
444
  if (unavailable) return <PmNotice tone="warn"><span>{t.diagnosticsUnavailable}</span><PmButton small onClick={() => workbench.retryDiagnostics()}>{t.retry}</PmButton></PmNotice>
446
445
  if (problems.length === 0) return repairFailure ? <PmNotice tone="danger">{t.fixFailed(failureReason(t, repairFailure))}</PmNotice> : null
446
+ const repair = canRepair && <PmButton small variant="accent" icon="sparkle" disabled={repairing} onClick={() => void workbench.requestRepairDiagnostics()}>{repairing ? t.fixing : t.fixWithAi}</PmButton>
447
447
  return (
448
448
  <PmNotice tone="warn">
449
449
  <div className="pmw-problems">
450
450
  <div className="pmw-problems__summary">
451
451
  <span>{t.problems(problems.length)}</span>
452
- {canRepair && <PmButton small variant="accent" icon="sparkle" disabled={repairing} onClick={() => void workbench.requestRepairDiagnostics()}>{repairing ? t.fixing : t.fixWithAi}</PmButton>}
452
+ <PmButton small variant="ghost" onClick={() => setOpen(true)}>{t.details}</PmButton>
453
+ {repair}
453
454
  </div>
454
455
  {repairFailure && <p className="pmw-problems__failure">{t.fixFailed(failureReason(t, repairFailure))}</p>}
455
- <details className="pmw-problems__details">
456
- <summary>{t.details}</summary>
457
- <ul>{problems.map(problem => <li key={problem.id}>{problem.message}</li>)}</ul>
458
- </details>
459
456
  </div>
457
+ <PmDialog open={open} label={t.problemsTitle} closeLabel={t.close} actions={repair || undefined} onClose={() => setOpen(false)}>
458
+ <ul className="pmw-problems__list">{problems.map(problem => <li key={problem.id}><p>{problem.message}</p>{problem.hint && <p className="pmw-problems__hint">{problem.hint}</p>}</li>)}</ul>
459
+ </PmDialog>
460
460
  </PmNotice>
461
461
  )
462
462
  }
@@ -11,7 +11,7 @@ import { VOICE_CLONE_MESSAGES } from '../voice-clone-messages.ts'
11
11
  import { VOICE_MESSAGES, voiceFailure } from '../voice-messages.ts'
12
12
  import { prepareVoiceSnapshot, voiceSnapshotCurrent } from '../voice-snapshot.ts'
13
13
  import type { VoiceSnapshot } from '../voice-snapshot.ts'
14
- import { isAgentChanging } from '../workbench.ts'
14
+ import { isAgentChanging } from '../workbench-state.ts'
15
15
  import { VoiceCloneDialog } from './VoiceCloneDialog.tsx'
16
16
  import { VoicePreviewDialog } from './VoicePreviewDialog.tsx'
17
17
  import { VoiceScopeField } from './VoiceScopeField.tsx'
@@ -84,7 +84,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
84
84
  const confirmation = review, generation = ++owner.current.generation
85
85
  setBusy(true); setFailure(undefined)
86
86
  try {
87
- const saved = await workbench.applyDocumentVoice(confirmation.draft.scope, confirmation.draft.source, { replaceOverrides: confirmation.draft.replaceOverrides }, confirmation.expected)
87
+ const saved = await workbench.production.applyVoice(confirmation.draft.scope, confirmation.draft.source, { replaceOverrides: confirmation.draft.replaceOverrides }, confirmation.expected)
88
88
  if (!current() || generation !== owner.current.generation) return
89
89
  if (!saved) throw new Error('voice-context-changed')
90
90
  if (!clearVoiceDraft(workbench.client, identity, stepId, confirmation.draft)) { setStorageFailed(true); setReview(undefined); return }
@@ -3,7 +3,7 @@ import { PmButton, PmField } from '../components.tsx'
3
3
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
4
4
  import { resolveDocumentStepVoice } from '../document-voices.ts'
5
5
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
6
- import { isAgentChanging } from '../workbench.ts'
6
+ import { isAgentChanging } from '../workbench-state.ts'
7
7
  import { DocumentVoiceDialog } from './DocumentVoiceDialog.tsx'
8
8
 
9
9
  /** One current voice and selector, shared by document captions and production. */
@@ -1,8 +1,7 @@
1
1
  import { useEffect, useState } from 'react'
2
- import type { CSSProperties } from 'react'
3
2
  import type { CompileJob, OutputTarget } from '@lincyaw/kernel'
4
3
  import type { IconName } from '@lincyaw/design'
5
- import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmMascot, PmNotice } from '../components.tsx'
4
+ import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../components.tsx'
6
5
  import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
7
6
  import { failureReason, timeAgo } from '../messages.ts'
8
7
 
@@ -105,10 +104,6 @@ function JobItem({ job, label, current, onPlay }: { job: CompileJob, label: stri
105
104
  </p>
106
105
  {job.state === 'running' && progress && (
107
106
  <div className="pmw-job__progress">
108
- {/* the kitten runs along the bar to how far the job has come; with no total yet it walks at the start */}
109
- <span className="pmw-job__runner" style={{ '--pmw-job-done': progress.total ? Math.min(1, (progress.done ?? 0) / progress.total) : 0 } as CSSProperties}>
110
- <PmMascot size="small" action={progress.total ? 'run' : 'walk'} />
111
- </span>
112
107
  <progress max={progress.total ?? 1} value={progress.total ? progress.done ?? 0 : undefined} aria-label={label} />
113
108
  <span>{t.jobProgress(t.jobPhases[progress.phase] ?? t.outputLabels[progress.phase] ?? progress.phase, progress.done, progress.total)}</span>
114
109
  </div>
@@ -3,7 +3,7 @@ import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../c
3
3
  import type { IconName } from '@lincyaw/design'
4
4
  import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
5
  import { timeAgo } from '../messages.ts'
6
- import { isAgentChanging } from '../workbench.ts'
6
+ import { isAgentChanging } from '../workbench-state.ts'
7
7
 
8
8
  /** A host-owned operation on a version, such as restoring an entire saved snapshot. This never replaces selective undo. */
9
9
  export interface HistoryRevisionAction {
@@ -12,7 +12,7 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
12
12
  useEffect(() => {
13
13
  let current = true
14
14
  setLoading(true); setError(undefined)
15
- void workbench.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
15
+ void workbench.editing.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
16
16
  return () => { current = false }
17
17
  }, [workbench, section, attempt])
18
18
  return <PmDialog open label={t.pageDeleteTitle(title)} description={plan ? t.pageDeleteHint(plan.counts.steps, plan.counts.narration) : t.pageDeleteLoading} busy={busy} closeLabel={t.close} onClose={onClose} onCloseAutoFocus={event => {
@@ -21,12 +21,12 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
21
21
  }}>
22
22
  <div className="pmw-operation">
23
23
  {plan?.last && <PmNotice>{t.pageDeleteLast}</PmNotice>}
24
- {plan && !plan.allowed && <PmNotice tone="warn">{workbench.pageDeleteMessage(plan.reason ?? 'page-boundary')}</PmNotice>}
24
+ {plan && !plan.allowed && <PmNotice tone="warn">{workbench.editing.deletionMessage(plan.reason ?? 'page-boundary')}</PmNotice>}
25
25
  {(error || failure) && <PmNotice tone="danger">{error || failure}</PmNotice>}
26
26
  <div className="pmw-operation__actions">
27
27
  <PmButton disabled={busy} onClick={onClose}>{t.cancel}</PmButton>
28
- {error || failure ? <PmButton disabled={busy} onClick={() => { workbench.clearPageEditFailure(); setAttempt(value => value + 1) }}>{t.retry}</PmButton>
29
- : <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
28
+ {error || failure ? <PmButton disabled={busy} onClick={() => { workbench.editing.clearFailure(); setAttempt(value => value + 1) }}>{t.retry}</PmButton>
29
+ : <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.editing.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
30
30
  </div>
31
31
  </div>
32
32
  </PmDialog>
@@ -15,7 +15,7 @@ export function PageRenameDialog({ section, title: original, trigger, onClose }:
15
15
  }} onSubmit={event => {
16
16
  event.preventDefault()
17
17
  if (busy || !title.trim()) return
18
- void workbench.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
18
+ void workbench.editing.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
19
19
  }}>
20
20
  <PmInput label={t.pageTitle} density="regular" value={title} error={failure} required autoFocus readOnly={busy} onChange={event => setTitle(event.target.value)} />
21
21
  <div className="pmw-operation__actions">
@@ -6,7 +6,6 @@ import { PmButton, PmNotice } from '../components.tsx'
6
6
  import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
7
7
  import { slideAspect } from '../workbench.ts'
8
8
  import { failureReason } from '../messages.ts'
9
- import { PreviewChangeTrail } from './ChangeTrail.tsx'
10
9
 
11
10
  /**
12
11
  * The open document as its readers see it (the web form or the slides), with the tools for what the author points at.
@@ -29,7 +28,6 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
29
28
  const reload = useWorkbenchState(state => state.previewReload)
30
29
  const aspect = useWorkbenchState(state => (state.previewRenderer === 'slides' ? slideAspect(state.ir) : undefined))
31
30
  const container = useRef<HTMLDivElement>(null)
32
- const stage = useRef<HTMLDivElement>(null)
33
31
  const pool = useRef<ReturnType<typeof createPreviewPool>>()
34
32
  const [loads, setLoads] = useState(0)
35
33
  const [{ ready, mismatch, identityFailure, handshakeFailure, canvasGate }, setStatus] = useState<PreviewFrameStatus>({ ready: false })
@@ -70,9 +68,8 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
70
68
  {failure && <PmNotice tone="danger"><span>{t.previewFailed(failureReason(t, failure))}</span><PmButton small onClick={() => workbench.retryPreview()}>{t.retry}</PmButton></PmNotice>}
71
69
  {(!ready || !snapshotMatches) && !failure && !handshakeFailure && !(renderer === 'slides' && preview && !preview.slides) && <p className="pmw-muted pmw-preview__loading">{presentation && ready && !snapshotMatches && !preparing ? t.presentationOutdated : address ? t.previewLoading : t.previewPreparing}</p>}
72
70
  {renderer === 'slides' && preview && !preview.slides && <p className="pmw-muted pmw-preview__loading">{t.noSlides}</p>}
73
- <div ref={stage} className="pmw-preview__stage">
71
+ <div className="pmw-preview__stage">
74
72
  <div ref={container} className="pmw-preview__frames" data-renderer={renderer} data-pending-snapshot={!snapshotMatches || undefined} data-presentation-gated={presentation && canvasGate || undefined} style={aspect === undefined ? undefined : { '--pmw-slide-aspect': aspect } as CSSProperties} />
75
- {!presentation && <PreviewChangeTrail stage={stage} frames={container} />}
76
73
  </div>
77
74
  </section>
78
75
  )
@@ -0,0 +1,20 @@
1
+ import { useState } from 'react'
2
+ import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
3
+ import type { TeachingDocument } from '@lincyaw/kernel'
4
+ import { PmField, PmRange } from '../components.tsx'
5
+ import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
+ import { PRODUCTION_MESSAGES } from '../production-messages.ts'
7
+
8
+ /** The document's caption size in percent steps of ten; a released drag or a key records it once. */
9
+ export function ProductionCaptionSize({ identity, document, disabled, onChanged }: { identity: string, document: TeachingDocument, disabled: boolean, onChanged(): void }) {
10
+ const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
11
+ const [preview, setPreview] = useState<number>()
12
+ const percent = Math.round(captionScale(document.production) * 100)
13
+ return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
14
+ <div className="pm-ui-range-row">
15
+ <PmRange label={p.captionSize} value={percent} min={Math.round(CAPTION_SCALE_MIN * 100)} max={Math.round(CAPTION_SCALE_MAX * 100)} step={10} disabled={disabled} valueText={value => `${Math.round(value)}%`}
16
+ onPreviewChange={setPreview} onValueCommit={value => { workbench.production.setCaptionScale(value / 100, identity); onChanged() }} />
17
+ <output>{Math.round(preview ?? percent)}%</output>
18
+ </div>
19
+ </PmField>
20
+ }