@lincyaw/workbench 0.2.0-rc.119 → 0.2.0-rc.120

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 (48) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -4
  3. package/src/StepProductionEditor.tsx +2 -2
  4. package/src/caption-timing-drafts.ts +2 -2
  5. package/src/caption-timing.ts +2 -2
  6. package/src/component-draft-actions.ts +1 -1
  7. package/src/component-properties.ts +3 -3
  8. package/src/component-property-drafts.ts +1 -1
  9. package/src/document-drafts.ts +2 -2
  10. package/src/document-editing.ts +7 -6
  11. package/src/document-editor/ComponentMaterials.tsx +2 -2
  12. package/src/document-editor/ComponentPropertiesDialog.tsx +2 -2
  13. package/src/document-editor/DocumentBlockFallback.tsx +4 -3
  14. package/src/document-editor/DocumentComments.tsx +2 -2
  15. package/src/document-editor/DocumentEditor.tsx +10 -7
  16. package/src/document-editor/DocumentStepNarration.tsx +4 -3
  17. package/src/document-editor/agent-targets.ts +2 -2
  18. package/src/document-editor/comment-drafts.ts +4 -4
  19. package/src/document-editor/comments.ts +7 -7
  20. package/src/document-editor/inline.ts +1 -0
  21. package/src/document-editor/messages.ts +2 -2
  22. package/src/document-editor/projection.ts +19 -17
  23. package/src/document-preview.ts +3 -2
  24. package/src/document-production.ts +7 -6
  25. package/src/document-return-point.ts +2 -2
  26. package/src/document-session.ts +19 -16
  27. package/src/document-timing-drafts.ts +4 -4
  28. package/src/effective-settings.ts +12 -0
  29. package/src/messages.ts +6 -0
  30. package/src/outline.ts +5 -5
  31. package/src/panels/DocumentVoiceDialog.tsx +4 -3
  32. package/src/panels/DocumentVoiceField.tsx +2 -1
  33. package/src/panels/HomePanel.tsx +1 -0
  34. package/src/panels/ProductionCaptionSize.tsx +2 -2
  35. package/src/panels/ProductionMediaClips.tsx +2 -2
  36. package/src/panels/ProductionPanel.tsx +3 -2
  37. package/src/panels/ProductionRecordingRange.tsx +3 -2
  38. package/src/panels/ProductionTranscription.tsx +4 -3
  39. package/src/panels/SourceDocumentPanel.tsx +5 -3
  40. package/src/panels/TranscriptionAdoption.tsx +2 -2
  41. package/src/panels/VoiceScopeField.tsx +2 -2
  42. package/src/panels/VoiceoverDialog.tsx +9 -8
  43. package/src/recording-adoption.ts +4 -4
  44. package/src/speech-settings-messages.ts +1 -1
  45. package/src/step-production.ts +4 -4
  46. package/src/use-recording-adoption.ts +3 -2
  47. package/src/workbench.ts +14 -6
  48. package/src/workspace-client.ts +3 -0
@@ -1,5 +1,5 @@
1
1
  import { documentPageDefaults, DOCUMENT_PAGE_DEFAULT_TIMING, randomUUID } from '@lincyaw/kernel'
2
- import type { DocumentBlock, DocumentPageIds, NarrationNode, RichTextNode, Section, TeachingDocument, TextBlock } from '@lincyaw/kernel'
2
+ import type { DocumentBlock, DocumentPageIds, NarrationNode, RichTextNode, Section, PresmiumDocument, TextBlock } from '@lincyaw/kernel'
3
3
  import { productInlineToNative } from './inline.ts'
4
4
  import { captureRichBaseline, createRichProjection, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
5
5
  import type { RichProjection } from './rich-text.ts'
@@ -9,12 +9,14 @@ export interface DocumentProjection extends RichProjection {
9
9
  owners: Map<string, string>
10
10
  pages: Map<string, string>
11
11
  blockSections: Map<string, string>
12
- document: TeachingDocument
12
+ document: PresmiumDocument
13
13
  content: DocumentEditorInput[]
14
14
  structure?: string
15
15
  structures: Map<string, Pick<DocumentProjection, 'document' | 'rich' | 'owners' | 'pages' | 'baseline'>>
16
16
  createdPages: Map<string, NativePageCreation>
17
17
  componentConfiguration: Map<string, string>
18
+ /** The plugins the document has, inherited ones included: they decide which code is drawn as a diagram. */
19
+ plugins?: readonly string[]
18
20
  }
19
21
  export type NativePageCreation = DocumentPageIds
20
22
  const newId = () => randomUUID()
@@ -26,13 +28,13 @@ function plain(nodes: readonly { type: string, text?: string, children?: readonl
26
28
  * Code the published document draws as a picture is generated content: authors see its preview, not its source.
27
29
  * The viewer draws Mermaid; the content add-on's compiler pass turns PlantUML into an image.
28
30
  */
29
- export function isDiagram(block: DocumentBlock, document: TeachingDocument): boolean {
31
+ export function isDiagram(block: DocumentBlock, plugins: readonly string[] | undefined): boolean {
30
32
  if (block.type !== 'code') return false
31
- return block.language === 'mermaid' || /^(?:plantuml|puml)$/i.test(block.language) && Boolean(document.metadata.plugins?.includes('@lincyaw/addon-content'))
33
+ return block.language === 'mermaid' || /^(?:plantuml|puml)$/i.test(block.language) && Boolean(plugins?.includes('@lincyaw/addon-content'))
32
34
  }
33
- /** Blocks the editor shows through their read-only runtime preview. */
34
- export function hasBlockPreview(block: DocumentBlock, document: TeachingDocument): boolean {
35
- return block.type === 'component' || isDiagram(block, document)
35
+ /** Blocks the editor shows through their read-only runtime preview; `plugins` are the document's effective ones. */
36
+ export function hasBlockPreview(block: DocumentBlock, plugins: readonly string[] | undefined): boolean {
37
+ return block.type === 'component' || isDiagram(block, plugins)
36
38
  }
37
39
  function register(blocks: readonly DocumentEditorInput[], owner: string, context: DocumentProjection): void {
38
40
  for (const block of blocks) { if (block.id) context.owners.set(block.id, owner); if (block.children) register(block.children, owner, context) }
@@ -50,12 +52,12 @@ function productBlock(blockId: string, context: DocumentProjection, sectionId: s
50
52
  context.owners.set(block.id, block.id)
51
53
  if (block.type === 'container') return [{ id: block.id, type: 'presmiumContainer', props: { entityId: block.id, layout: block.layout, title: block.properties.title ?? '' }, children: block.children.flatMap(child => productBlock(child, context, sectionId)) }]
52
54
  if (block.type === 'image') return [{ id: block.id, type: 'image', props: { url: block.assetId ? document.assets[block.assetId]?.location ?? '' : '', caption: plain(block.caption ?? []), name: block.alt, textAlignment: block.alignment ?? 'left', ...block.width !== undefined ? { previewWidth: block.width } : {} } }]
53
- if (block.type === 'code' && block.value !== undefined && !isDiagram(block, document)) return [{ id: block.id, type: 'codeBlock', props: { language: block.language }, content: block.value }]
54
- return [{ id: block.id, type: 'presmiumAtom', props: { entityId: block.id, kind: block.type, label: block.type === 'code' ? block.title ?? block.origin?.anchor ?? block.language : document.definitions[block.definitionId]?.kind ?? block.definitionId }, ...block.type === 'component' && block.children ? { children: block.children.flatMap(child => productBlock(child, context, sectionId)) } : {} }]
55
+ if (block.type === 'code' && block.value !== undefined && !isDiagram(block, context.plugins)) return [{ id: block.id, type: 'codeBlock', props: { language: block.language }, content: block.value }]
56
+ return [{ id: block.id, type: 'presmiumAtom', props: { entityId: block.id, kind: block.type, label: block.type === 'code' ? block.title ?? block.origin?.anchor ?? block.language : block.type === 'embed' ? block.source.document : document.definitions[block.definitionId]?.kind ?? block.definitionId }, ...block.type === 'component' && block.children ? { children: block.children.flatMap(child => productBlock(child, context, sectionId)) } : {} }]
55
57
  }
56
58
 
57
- export function createDocumentProjection(document: TeachingDocument): DocumentProjection {
58
- const context: DocumentProjection = { ...createRichProjection(), owners: new Map(), pages: new Map(), blockSections: new Map(), structures: new Map(), createdPages: new Map(), componentConfiguration: new Map(), document: structuredClone(document), content: [] }
59
+ export function createDocumentProjection(document: PresmiumDocument, plugins: readonly string[] | undefined = document.metadata.plugins): DocumentProjection {
60
+ const context: DocumentProjection = { ...createRichProjection(), owners: new Map(), pages: new Map(), blockSections: new Map(), structures: new Map(), createdPages: new Map(), componentConfiguration: new Map(), document: structuredClone(document), content: [], ...plugins ? { plugins } : {} }
59
61
  context.content = document.sectionOrder.flatMap(sectionId => {
60
62
  const section = document.sections[sectionId]!
61
63
  context.pages.set(pageId(sectionId), sectionId)
@@ -80,7 +82,7 @@ export function rememberDocumentStructure(blocks: readonly DocumentEditorBlock[]
80
82
  }
81
83
 
82
84
  /** Source-owned component configuration also accompanies a missing node in native structural history. */
83
- export function rememberComponentConfiguration(context: DocumentProjection, source: TeachingDocument): void {
85
+ export function rememberComponentConfiguration(context: DocumentProjection, source: PresmiumDocument): void {
84
86
  const changed = new Set<string>()
85
87
  const overrides = new Map<string, unknown[]>()
86
88
  for (const step of Object.values(source.steps)) for (const visual of step.visuals) if (visual.parameters) {
@@ -150,7 +152,7 @@ function isEntity(block: DocumentEditorBlock, context: DocumentProjection): bool
150
152
  if (block.type === 'presmiumContainer' || block.type === 'image') return true
151
153
  return block.type === 'codeBlock' && context.document.blocks[context.owners.get(block.id) ?? block.id]?.type !== 'text' && !context.rich.has(block.id)
152
154
  }
153
- function nativeChildren(native: readonly DocumentEditorBlock[], context: DocumentProjection, next: TeachingDocument, usedListIds: Set<string>): string[] {
155
+ function nativeChildren(native: readonly DocumentEditorBlock[], context: DocumentProjection, next: PresmiumDocument, usedListIds: Set<string>): string[] {
154
156
  const children: string[] = []
155
157
  let buffer: DocumentEditorBlock[] = [], owner: string | undefined
156
158
  const flush = () => {
@@ -214,7 +216,7 @@ function nativeChildren(native: readonly DocumentEditorBlock[], context: Documen
214
216
  }
215
217
 
216
218
  /** A plain text transaction keeps the teaching graph and untouched rich nodes by identity. */
217
- function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest: TeachingDocument): TeachingDocument | undefined {
219
+ function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest: PresmiumDocument): PresmiumDocument | undefined {
218
220
  const changed: { native: DocumentEditorBlock, serialized: string, owner: TextBlock }[] = []
219
221
  const visit = (blocks: readonly DocumentEditorBlock[]): boolean => blocks.every(block => {
220
222
  const serialized = JSON.stringify(block)
@@ -239,7 +241,7 @@ function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: Docum
239
241
  }
240
242
 
241
243
  /** Reconstruct the normalized product tree without visiting or reparsing Markdown. */
242
- export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest = context.document): TeachingDocument {
244
+ export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest = context.document): PresmiumDocument {
243
245
  const targetStructure = structureOf(blocks, context)
244
246
  if (targetStructure === context.structure) {
245
247
  const edited = projectTextEdits(blocks, context, latest)
@@ -373,7 +375,7 @@ export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[],
373
375
  if (next.production.cueTimings) delete next.production.cueTimings[node.id]
374
376
  return false
375
377
  })
376
- context.document = share(context.document, structuredClone(next)) as TeachingDocument
378
+ context.document = share(context.document, structuredClone(next)) as PresmiumDocument
377
379
  context.blockSections = sectionOf
378
380
  for (const block of Object.values(context.document.blocks)) if (block.type === 'text') rememberRich(block.content, context)
379
381
  context.baseline.clear(); captureRichBaseline(blocks, context)
@@ -382,7 +384,7 @@ export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[],
382
384
  }
383
385
 
384
386
  /** Only an untouched, unreferenced creation default is removed with its native insertion. */
385
- function untouchedPageCreation(document: TeachingDocument, created: NativePageCreation): boolean {
387
+ function untouchedPageCreation(document: PresmiumDocument, created: NativePageCreation): boolean {
386
388
  const { sectionId, blockId, stepId } = created, section = document.sections[sectionId]
387
389
  if (section?.stepOrder.length !== 1 || section.stepOrder[0] !== stepId
388
390
  || JSON.stringify(document.steps[stepId]) !== JSON.stringify(documentPageDefaults(created, '').step)
@@ -1,3 +1,4 @@
1
+ import { DOCUMENT_ENTRY } from '@lincyaw/kernel'
1
2
  import { WorkspaceServerError } from './workspace-client.ts'
2
3
  import type { WorkspaceClient, WorkspaceRequestEvent } from './workspace-client.ts'
3
4
  import type { IrAnswer, PreviewAnswer, PreviewRenderer } from '@lincyaw/kernel'
@@ -52,7 +53,7 @@ export function waitForPreviewRequest<T>(work: Promise<T>, signal?: AbortSignal)
52
53
 
53
54
  /** Speech preflights need a confirmed source snapshot without building a visual output. */
54
55
  export async function readDocumentSnapshot(client: WorkspaceClient, source: Pick<PreviewSource, 'directory' | 'version' | 'fingerprint'>, signal?: AbortSignal): Promise<IrAnswer> {
55
- const entry = source.directory ? `${source.directory}/lecture.json` : 'lecture.json', started = Date.now()
56
+ const entry = source.directory ? `${source.directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY, started = Date.now()
56
57
  for (;;) {
57
58
  signal?.throwIfAborted()
58
59
  const ir = await waitForPreviewRequest(client.readIr(source.directory), signal)
@@ -64,7 +65,7 @@ export async function readDocumentSnapshot(client: WorkspaceClient, source: Pick
64
65
 
65
66
  /** The explicit request owner can abort while the compiler confirms one exact source snapshot. */
66
67
  export async function compileDocumentPreview(client: WorkspaceClient, source: PreviewSource, signal?: AbortSignal, feedbackOwner?: WorkspaceRequestEvent['feedbackOwner'], onPreparing?: () => void): Promise<CompiledDocumentPreview> {
67
- const { directory, fingerprint } = source, entry = directory ? `${directory}/lecture.json` : 'lecture.json'
68
+ const { directory, fingerprint } = source, entry = directory ? `${directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY
68
69
  let started = Date.now()
69
70
  for (;;) {
70
71
  signal?.throwIfAborted()
@@ -1,5 +1,5 @@
1
- import { applyDocumentCaptionTiming, changeDocumentCaptionScale, DOCUMENT_AUDIO_MAX_BYTES, randomUUID, replaceStepNarrations, sameProductionBinding, validateDocument } from '@lincyaw/kernel'
2
- import type { DocumentAudioImportAnswer, DocumentAudioInspectionAnswer, DocumentCaptionTimingAction, DocumentChangeAnswer, DocumentRecordingAdoption, DocumentTranscriptionRequest, MediaClip, Narration, ProductionBinding, TeachingDocument, TimeRange, TranscriptionAdoptionAnswer, TranscriptionAdoptionApply, TranscriptionAdoptionDraft, TranscriptionAdoptionPlan, TranscriptionTask, VerifiedDocumentRecordingAdoption, VoiceSource } from '@lincyaw/kernel'
1
+ import { applyDocumentCaptionTiming, changeDocumentCaptionScale, DOCUMENT_AUDIO_MAX_BYTES, randomUUID, replaceStepNarrations, sameProductionBinding, validateDocument, DOCUMENT_ENTRY } from '@lincyaw/kernel'
2
+ import type { DocumentAudioImportAnswer, DocumentAudioInspectionAnswer, DocumentCaptionTimingAction, DocumentChangeAnswer, DocumentRecordingAdoption, DocumentTranscriptionRequest, MediaClip, Narration, ProductionBinding, PresmiumDocument, TimeRange, TranscriptionAdoptionAnswer, TranscriptionAdoptionApply, TranscriptionAdoptionDraft, TranscriptionAdoptionPlan, TranscriptionTask, VerifiedDocumentRecordingAdoption, VoiceSource } from '@lincyaw/kernel'
3
3
  import { isAgentChanging } from './workbench-state.ts'
4
4
  import type { WorkbenchStore } from './workbench-state.ts'
5
5
  import type { DocumentSession, DocumentSessionState } from './document-session.ts'
@@ -23,13 +23,14 @@ import { discardMediaDraft, keepMediaDrafts, mediaDraftSnapshot } from './media-
23
23
  import type { MediaDrafts } from './media-drafts.ts'
24
24
  import { TranscriptionCorrections } from './transcription-drafts.ts'
25
25
  import type { TranscriptionCorrection, TranscriptionCorrectionTarget } from './transcription-drafts.ts'
26
+ import { effectiveOf } from './effective-settings.ts'
26
27
 
27
28
  interface ProductionOptions {
28
29
  store: WorkbenchStore
29
30
  session: DocumentSession
30
31
  client: WorkspaceClient
31
32
  scope(): number
32
- document(identity?: string): TeachingDocument | undefined
33
+ document(identity?: string): PresmiumDocument | undefined
33
34
  flush(signal?: AbortSignal): Promise<void>
34
35
  pause(): Promise<void>
35
36
  stopAuditions(): void
@@ -387,7 +388,7 @@ export class DocumentProduction {
387
388
  return { ...actual, changeId: id, files: receipt.files }
388
389
  }, (before, answer, current) => reconcileCaptionTiming(action, before, answer, current), signal)
389
390
  } catch (error) {
390
- const current = this.#options.store.state.authoring, file = plan.files.find(file => file.path === (source.directory ? `${source.directory}/lecture.json` : 'lecture.json'))
391
+ const current = this.#options.store.state.authoring, file = plan.files.find(file => file.path === (source.directory ? `${source.directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY))
391
392
  // Lost ACK was independently read by commitExternal; only the exact predicted saved version can settle it.
392
393
  if (scope === this.#options.scope() && current?.identity === expected.identity && current.content && current.version === file?.version && current.fingerprint && !current.error) {
393
394
  try {
@@ -416,13 +417,13 @@ export class DocumentProduction {
416
417
  }
417
418
  timingDraft(stepId: string, key: StepDurationKey, identity: string, reset: number): StepDurationDraft | undefined {
418
419
  const document = this.#options.document(identity)
419
- return document && this.#options.store.state.authoring?.reset === reset ? this.#documentTimingDrafts.get(identity, document, stepId, key) : undefined
420
+ return document && this.#options.store.state.authoring?.reset === reset ? this.#documentTimingDrafts.get(identity, effectiveOf(document, this.#options.store.state.authoring.inherited), stepId, key) : undefined
420
421
  }
421
422
  /** Retains unaccepted numeric input by stable target; it is not authoring content or a second timing source. */
422
423
  setTimingDraft(stepId: string, key: StepDurationKey, draft: StepDurationDraft | undefined, identity: string, reset: number): void {
423
424
  const source = this.#options.store.state.authoring, document = this.#options.document(identity)
424
425
  if (!document?.steps[stepId] || source?.reset !== reset || isAgentChanging(this.#options.store.state)) return
425
- if (!this.#documentTimingDrafts.set(identity, document, stepId, key, draft)) return
426
+ if (!this.#documentTimingDrafts.set(identity, effectiveOf(document, source.inherited), stepId, key, draft)) return
426
427
  this.#draftRevision++
427
428
  this.#options.store.set({ authoring: { ...source }, hasDocumentTimingDrafts: this.#documentTimingDrafts.has(identity, document), documentTimingDraftStorageFailure: this.#documentTimingDrafts.failed })
428
429
  }
@@ -1,4 +1,4 @@
1
- import type { TeachingDocument } from '@lincyaw/kernel'
1
+ import type { PresmiumDocument } from '@lincyaw/kernel'
2
2
 
3
3
  export interface DocumentReturnPoint {
4
4
  sectionId: string
@@ -38,7 +38,7 @@ export class DocumentReturnPoints {
38
38
  }
39
39
  }
40
40
 
41
- export function documentReturnStep(document: TeachingDocument, point: DocumentReturnPoint): number | undefined {
41
+ export function documentReturnStep(document: PresmiumDocument, point: DocumentReturnPoint): number | undefined {
42
42
  const section = document.sections[point.sectionId]
43
43
  if (!section || !document.sectionOrder.includes(point.sectionId)) return
44
44
  if (point.stepId === undefined) return section.stepOrder.length === 0 ? 0 : undefined
@@ -1,5 +1,5 @@
1
1
  import { hasRole, isRecord, randomUUID, validateDocument } from '@lincyaw/kernel'
2
- import type { CanonicalSource, ClientBodyDraftReference, DocumentAnswer, DocumentChangeAnswer, DocumentImageImportAnswer, DocumentIssue, Member, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { CanonicalSource, ClientBodyDraftReference, DocumentAnswer, DocumentChangeAnswer, DocumentImageImportAnswer, DocumentIssue, Member, PresmiumDocument, DocumentDefaults } from '@lincyaw/kernel'
3
3
  import { WorkspaceServerError } from './workspace-client.ts'
4
4
  import type { WorkspaceClient } from './workspace-client.ts'
5
5
  import { waitForDraft } from './document-draft-store.ts'
@@ -11,7 +11,9 @@ export interface DocumentSessionState {
11
11
  directory: string
12
12
  member?: Member
13
13
  identity?: string
14
- content?: TeachingDocument
14
+ content?: PresmiumDocument
15
+ /** What the document inherits from its ancestors and the workspace defaults; `effectiveOf` fills it into `content`. */
16
+ inherited?: DocumentDefaults
15
17
  version?: string
16
18
  fingerprint?: string
17
19
  projectRevision?: number
@@ -31,7 +33,7 @@ export interface DocumentSessionState {
31
33
  recoveryChanged?: boolean
32
34
  }
33
35
  export interface DocumentDraftOperation { signal: AbortSignal, guard(): void, source: CanonicalSource, localDraft?: true }
34
- export interface BodyDraftCandidate { draft: DocumentDraftReference & { current: boolean }, content: TeachingDocument, storage: 'durable' | 'rescue' | 'session', updatedAt: number, baseVersion: string, composing: boolean, pendingSubmission: boolean }
36
+ export interface BodyDraftCandidate { draft: DocumentDraftReference & { current: boolean }, content: PresmiumDocument, storage: 'durable' | 'rescue' | 'session', updatedAt: number, baseVersion: string, composing: boolean, pendingSubmission: boolean }
35
37
  interface Slot {
36
38
  observedSource?: CanonicalSource
37
39
  state: DocumentSessionState
@@ -39,7 +41,7 @@ interface Slot {
39
41
  compositions: Set<string>
40
42
  input: number
41
43
  baseHash: string
42
- baseContent: TeachingDocument
44
+ baseContent: PresmiumDocument
43
45
  storage: string
44
46
  drafts: DocumentDrafts
45
47
  backup?: DocumentDraftCommit
@@ -50,7 +52,7 @@ interface Slot {
50
52
  legacyFailure?: 'read' | 'write'
51
53
  persistFailure?: boolean
52
54
  recoveryOperation?: number
53
- flight?: { id: string, input: number, content: TeachingDocument, baseVersion: string, hash?: string }
55
+ flight?: { id: string, input: number, content: PresmiumDocument, baseVersion: string, hash?: string }
54
56
  assetFlight?: Promise<DocumentChangeAnswer>
55
57
  timer?: ReturnType<typeof setTimeout>
56
58
  refreshed?: boolean
@@ -62,8 +64,8 @@ interface Slot {
62
64
  const serialize = (value: unknown) => JSON.stringify(value, (_, entry) => entry && typeof entry === 'object' && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))) : entry)
63
65
  const sameSource = (a: CanonicalSource | undefined, b: CanonicalSource) => a?.documentId === b.documentId && a.version === b.version && a.fingerprint === b.fingerprint
64
66
  /** Non-body authoring changes keep native selection, comment drafts and body history. */
65
- function keepsEditorContent(before: TeachingDocument, after: TeachingDocument): boolean {
66
- const editing = ({ assets: _assets, production: _production, comments: _comments, definitions: _definitions, ...document }: TeachingDocument) => {
67
+ function keepsEditorContent(before: PresmiumDocument, after: PresmiumDocument): boolean {
68
+ const editing = ({ assets: _assets, production: _production, comments: _comments, definitions: _definitions, ...document }: PresmiumDocument) => {
67
69
  const resolved = new Map<string, Map<string, { blockId: string, visible: boolean, state?: string }>>()
68
70
  const visiting = new Set<string>()
69
71
  const visuals = (id?: string): Map<string, { blockId: string, visible: boolean, state?: string }> => {
@@ -94,12 +96,12 @@ function keepsEditorContent(before: TeachingDocument, after: TeachingDocument):
94
96
  && Object.entries(before.assets).every(([id, asset]) => Object.hasOwn(after.assets, id) && serialize(asset) === serialize(after.assets[id]))
95
97
  }
96
98
 
97
- async function digest(value: TeachingDocument): Promise<string> {
99
+ async function digest(value: PresmiumDocument): Promise<string> {
98
100
  return sha256(serialize(value))
99
101
  }
100
102
 
101
103
  /** Replay pending author input on a newer saved document; an overlapping value belongs to the author. */
102
- function rebaseDocument(base: TeachingDocument, local: TeachingDocument, remote: TeachingDocument): TeachingDocument {
104
+ function rebaseDocument(base: PresmiumDocument, local: PresmiumDocument, remote: PresmiumDocument): PresmiumDocument {
103
105
  const merge = (before: unknown, author: unknown, saved: unknown): unknown => {
104
106
  if (serialize(author) === serialize(before)) return structuredClone(saved)
105
107
  if (serialize(saved) === serialize(before) || serialize(author) === serialize(saved)) return structuredClone(author)
@@ -160,7 +162,7 @@ export class DocumentSession {
160
162
  const baseHash = await digest(answer.content)
161
163
  if (this.#disposed || this.#active !== directory || opening !== this.#opening) return
162
164
  const drafts = new DocumentDrafts(() => { if (slot && !this.#disposed) void this.#readDrafts(slot) })
163
- slot = { observedSource: this.#source(answer), 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 } }
165
+ slot = { observedSource: this.#source(answer), 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, ...answer.inherited ? { inherited: answer.inherited } : {}, version: answer.version, fingerprint: answer.fingerprint, loading: true, dirty: false, saving: false, restored: false, composing: false, storageFailure: false, reset: 0, issues: answer.issues } }
164
166
  this.#slots.set(directory, slot)
165
167
  await this.#restore(slot, answer)
166
168
  } else {
@@ -289,6 +291,7 @@ export class DocumentSession {
289
291
  async #adopt(slot: Slot, answer: DocumentAnswer, current = () => true): Promise<void> {
290
292
  if (!current()) return
291
293
  if (answer.content.id !== slot.state.content?.id) { slot.state = { ...slot.state, error: 'document-identity-changed' }; return }
294
+ if (answer.inherited) slot.state = { ...slot.state, inherited: answer.inherited }
292
295
  slot.observedSource = this.#source(answer)
293
296
  if (answer.version === slot.state.version) {
294
297
  if (answer.fingerprint !== slot.state.fingerprint) slot.state = { ...slot.state, fingerprint: answer.fingerprint, issues: answer.issues }
@@ -325,7 +328,7 @@ export class DocumentSession {
325
328
  slot.state = { ...slot.state, version: answer.version, fingerprint: answer.fingerprint, content: answer.content, reset, error: undefined, issues: answer.issues }
326
329
  }
327
330
 
328
- record(content: TeachingDocument): void {
331
+ record(content: PresmiumDocument): void {
329
332
  const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
330
333
  if (!slot || this.#readOnly(slot) || content.id !== slot.state.content?.id) return
331
334
  slot.input++
@@ -340,7 +343,7 @@ export class DocumentSession {
340
343
  if (slot.state.dirty && !slot.state.restored && !slot.state.error && !slot.state.composing) slot.timer = setTimeout(() => { slot.timer = undefined; void this.#save(slot) }, 600)
341
344
  }
342
345
 
343
- replace(content: TeachingDocument): void {
346
+ replace(content: PresmiumDocument): void {
344
347
  const current = this.#active === undefined ? undefined : this.#slots.get(this.#active)
345
348
  if (current && this.#readOnly(current)) return
346
349
  this.record(content)
@@ -416,8 +419,8 @@ export class DocumentSession {
416
419
  }
417
420
 
418
421
  /** Adopt a verified asset-only transaction without replacing later native text. */
419
- async #adoptImportedAssets(slot: Slot, before: TeachingDocument, input: number, answer: DocumentAnswer, owns: () => boolean): Promise<boolean> {
420
- const withoutAssets = ({ assets: _assets, ...content }: TeachingDocument) => serialize(content)
422
+ async #adoptImportedAssets(slot: Slot, before: PresmiumDocument, input: number, answer: DocumentAnswer, owns: () => boolean): Promise<boolean> {
423
+ const withoutAssets = ({ assets: _assets, ...content }: PresmiumDocument) => serialize(content)
421
424
  if (!owns() || answer.document !== slot.state.directory || withoutAssets(before) !== withoutAssets(answer.content)
422
425
  || !Object.entries(before.assets).every(([id, asset]) => serialize(asset) === serialize(answer.content.assets[id]))) return false
423
426
  const baseHash = await digest(answer.content)
@@ -434,7 +437,7 @@ export class DocumentSession {
434
437
  return true
435
438
  }
436
439
 
437
- async #adoptExternal(slot: Slot, before: TeachingDocument, input: number, answer: DocumentAnswer, owns: () => boolean, reconcile: (before: TeachingDocument, answer: DocumentAnswer, current: TeachingDocument) => TeachingDocument | undefined): Promise<boolean> {
440
+ async #adoptExternal(slot: Slot, before: PresmiumDocument, input: number, answer: DocumentAnswer, owns: () => boolean, reconcile: (before: PresmiumDocument, answer: DocumentAnswer, current: PresmiumDocument) => PresmiumDocument | undefined): Promise<boolean> {
438
441
  if (!owns() || answer.document !== slot.state.directory || answer.content.id !== before.id || !slot.state.content) return false
439
442
  if (!reconcile(before, answer, slot.state.content)) return false
440
443
  const baseHash = await digest(answer.content)
@@ -453,7 +456,7 @@ export class DocumentSession {
453
456
  }
454
457
 
455
458
  /** Reconcile an external source transaction without replacing later native input. */
456
- async commitExternal<T extends DocumentChangeAnswer>(expected: { identity: string, version: string }, submit: (before: TeachingDocument, signal?: AbortSignal) => Promise<T>, reconcile: (before: TeachingDocument, answer: DocumentAnswer, current: TeachingDocument) => TeachingDocument | undefined, signal?: AbortSignal): Promise<T> {
459
+ async commitExternal<T extends DocumentChangeAnswer>(expected: { identity: string, version: string }, submit: (before: PresmiumDocument, signal?: AbortSignal) => Promise<T>, reconcile: (before: PresmiumDocument, answer: DocumentAnswer, current: PresmiumDocument) => PresmiumDocument | undefined, signal?: AbortSignal): Promise<T> {
457
460
  signal?.throwIfAborted()
458
461
  const slot = this.#active === undefined ? undefined : this.#slots.get(this.#active)
459
462
  if (slot && this.#readOnly(slot)) throw new WorkspaceServerError(403, { error: 'permission-denied' })
@@ -1,4 +1,4 @@
1
- import type { TeachingDocument } from '@lincyaw/kernel'
1
+ import type { PresmiumDocument } from '@lincyaw/kernel'
2
2
  import { stepTimingValue } from './step-production.ts'
3
3
  import type { ProductionSource, StepDurationDraft, StepDurationKey } from './step-production.ts'
4
4
 
@@ -39,13 +39,13 @@ export class DocumentTimingDrafts {
39
39
  }
40
40
  return values
41
41
  }
42
- get(identity: string, document: TeachingDocument, stepId: string, key: StepDurationKey): StepDurationDraft | undefined {
42
+ get(identity: string, document: PresmiumDocument, stepId: string, key: StepDurationKey): StepDurationDraft | undefined {
43
43
  const draft = this.#load(identity).get(JSON.stringify([stepId, key]))
44
44
  if (!draft) return undefined
45
45
  const actual = stepTimingValue(document, stepId, key)
46
46
  return { text: draft.text, error: draft.error, review: draft.review || draft.baseValue !== actual.value || draft.baseSource !== actual.source }
47
47
  }
48
- has(identity: string, document: TeachingDocument): boolean {
48
+ has(identity: string, document: PresmiumDocument): boolean {
49
49
  return [...this.#load(identity).keys()].some(target => Object.hasOwn(document.steps, JSON.parse(target)[0]))
50
50
  }
51
51
  partial(identity: string): boolean { this.#load(identity); try { return this.#unreadable.has(identity) || sessionStorage.getItem(this.#storage(identity)) !== this.#stored.get(identity) } catch { return true } }
@@ -64,7 +64,7 @@ export class DocumentTimingDrafts {
64
64
  return true
65
65
  } catch { this.failed = true; return false }
66
66
  }
67
- set(identity: string, document: TeachingDocument, stepId: string, key: StepDurationKey, draft: StepDurationDraft | undefined): boolean {
67
+ set(identity: string, document: PresmiumDocument, stepId: string, key: StepDurationKey, draft: StepDurationDraft | undefined): boolean {
68
68
  const values = this.#load(identity), target = JSON.stringify([stepId, key]), previous = values.get(target), actual = stepTimingValue(document, stepId, key)
69
69
  if (draft && draft.text.length > 256 || draft && !previous && values.size >= 512) { this.failed = true; return true }
70
70
  if (previous?.text === draft?.text && previous?.error === draft?.error && !previous?.review && (!previous || previous.baseValue === actual.value && previous.baseSource === actual.source)) return false
@@ -0,0 +1,12 @@
1
+ import { withInheritedSettings } from '@lincyaw/kernel'
2
+ import type { DocumentDefaults, EffectiveDocument, PresmiumDocument } from '@lincyaw/kernel'
3
+
4
+ /**
5
+ * The edited document with what it inherits from its ancestors and the workspace defaults filled in, for decisions
6
+ * (content language, plugins, the document's voice and timing); never saved.
7
+ */
8
+ export function effectiveOf(document: PresmiumDocument, inherited?: DocumentDefaults): EffectiveDocument
9
+ export function effectiveOf(document: PresmiumDocument | undefined, inherited?: DocumentDefaults): EffectiveDocument | undefined
10
+ export function effectiveOf(document: PresmiumDocument | undefined, inherited?: DocumentDefaults): EffectiveDocument | undefined {
11
+ return document && withInheritedSettings(document, inherited)
12
+ }
package/src/messages.ts CHANGED
@@ -140,6 +140,9 @@ const zh = {
140
140
  noMatch: '没有找到匹配的文稿。',
141
141
  newDocument: '新建文稿',
142
142
  noDocuments: '还没有文稿。点“新建文稿”开始。',
143
+ formatUpgrade: '这个工作区使用旧的文稿格式。升级后才能打开与编辑其中的文稿;每份文稿的升级都记入版本历史。',
144
+ upgrade: '升级',
145
+ upgraded: (count: number) => `已升级 ${count} 份文稿。`,
143
146
  notGit: '工作区的版本历史未能准备好,暂时无法新建或修改文稿。请重新打开工作区;仍未恢复时请查看诊断。',
144
147
  bundleDisabled: '无法加载文稿:Presmium 的扩展在“插件”页中被关闭了。请从“更多”打开“插件”,重新开启 Presmium,然后重新加载页面。',
145
148
  more: (title: string) => `“${title}”的更多操作`,
@@ -509,6 +512,9 @@ const en: WorkbenchMessages = {
509
512
  noMatch: 'No matching documents.',
510
513
  newDocument: 'New Document',
511
514
  noDocuments: 'No documents yet. Choose New Document to start.',
515
+ formatUpgrade: 'This workspace uses an older document format. Upgrade it to open and edit its documents; each document’s upgrade is recorded in its history.',
516
+ upgrade: 'Upgrade',
517
+ upgraded: (count: number) => `Upgraded ${count} ${count === 1 ? 'document' : 'documents'}.`,
512
518
  notGit: 'Workspace history could not be prepared, so documents cannot be created or edited yet. Reopen the workspace; if this continues, check Diagnostics.',
513
519
  bundleDisabled: 'Couldn’t load the documents: the Presmium extension was turned off on the Plugins page. Open Plugins from More, turn Presmium on again, then reload the page.',
514
520
  more: (title: string) => `More Actions for “${title}”`,
package/src/outline.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IRDocument, MdastNode, TeachingDocument } from '@lincyaw/kernel'
1
+ import type { IRDocument, MdastNode, PresmiumDocument } from '@lincyaw/kernel'
2
2
 
3
3
  /** A section as the navigation pane lists it: in the slides each section is one slide, numbered from 1. */
4
4
  export interface OutlineItem {
@@ -8,7 +8,7 @@ export interface OutlineItem {
8
8
  number: number
9
9
  }
10
10
 
11
- export function documentOutline(doc: IRDocument | TeachingDocument | undefined): OutlineItem[] {
11
+ export function documentOutline(doc: IRDocument | PresmiumDocument | undefined): OutlineItem[] {
12
12
  if (doc && 'schemaVersion' in doc) return doc.sectionOrder.map((id, index) => ({ id, title: doc.sections[id]!.title, depth: doc.sections[id]!.level ?? 1, number: index + 1 }))
13
13
  return (doc?.sections ?? []).map((section, i) => ({ id: section.id, title: section.title, depth: section.depth, number: i + 1 }))
14
14
  }
@@ -18,7 +18,7 @@ export class DocumentOutline {
18
18
  #identity?: string
19
19
  #items: readonly OutlineItem[] = []
20
20
 
21
- read(document: TeachingDocument | undefined, identity = document?.id): readonly OutlineItem[] {
21
+ read(document: PresmiumDocument | undefined, identity = document?.id): readonly OutlineItem[] {
22
22
  const items = documentOutline(document)
23
23
  if (identity !== this.#identity || items.length !== this.#items.length || items.some((item, index) => {
24
24
  const previous = this.#items[index]!
@@ -55,7 +55,7 @@ function richTextParts(value: unknown, parts: string[] = []): string[] {
55
55
  }
56
56
 
57
57
  /** Counts authored titles and rich text; code, components and separate narration are excluded. */
58
- export function countWords(doc: IRDocument | TeachingDocument | undefined): number {
58
+ export function countWords(doc: IRDocument | PresmiumDocument | undefined): number {
59
59
  if (doc && 'schemaVersion' in doc) {
60
60
  return doc.sectionOrder.reduce((sum, id) => sum + countText(doc.sections[id]!.title), 0) + Object.values(doc.blocks).reduce((sum, block) => sum + (block.type === 'text' ? richTextParts(block.content).reduce((sum, text) => sum + countText(text), 0) : 0), 0)
61
61
  }
@@ -72,7 +72,7 @@ export class DocumentWordCounter {
72
72
  #identity?: string
73
73
  readonly #counts = new Map<string, { signature: string, words: number }>()
74
74
 
75
- count(doc: TeachingDocument | undefined, identity = doc?.id): number {
75
+ count(doc: PresmiumDocument | undefined, identity = doc?.id): number {
76
76
  if (identity !== this.#identity || !doc) { this.#counts.clear(); this.#identity = identity }
77
77
  if (!doc) return 0
78
78
  const unused = new Set(this.#counts.keys())
@@ -15,6 +15,7 @@ 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'
18
+ import { effectiveOf } from '../effective-settings.ts'
18
19
 
19
20
  interface Review { draft: VoiceDraft, impact: DocumentVoiceImpact, scopeLabel: string, targets: string[], expected: { identity: string, version: string, fingerprint: string } }
20
21
  const supportsLanguage = (languages: string[], lang: string) => !languages.length || languages.some(value => value.toLowerCase().split('-')[0] === lang.toLowerCase().split('-')[0])
@@ -27,7 +28,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
27
28
  const serviceVersion = useWorkbenchState(state => state.voiceServiceVersion)
28
29
  const identity = useRef(actor!.identity!).current, directory = useRef(actor!.directory).current
29
30
  const [restored, setRestored] = useState(() => readVoiceDraft(workbench.client, identity, stepId))
30
- const [draft, setDraft] = useState<VoiceDraft>(() => restored ?? { version: actor!.version!, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(actor!.content!, stepId).value ?? null, replaceOverrides: false })
31
+ const [draft, setDraft] = useState<VoiceDraft>(() => restored ?? { version: actor!.version!, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(effectiveOf(actor!.content!, actor!.inherited), stepId).value ?? null, replaceOverrides: false })
31
32
  const [storageFailed, setStorageFailed] = useState(() => voiceDraftStorageStatus(workbench.client, identity, stepId) !== 'available')
32
33
  const [engineFilter, setEngineFilter] = useState(draft.source?.type === 'tts' ? draft.source.voice.engine : undefined)
33
34
  const [language, setLanguage] = useState(''), [query, setQuery] = useState(''), [catalog, setCatalog] = useState<VoiceCatalogAnswer>()
@@ -50,7 +51,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
50
51
  const engines = catalog?.engines.filter(engine => engine.tts) ?? []
51
52
  const engine: SpeechEngineInfo | undefined = engines.find(engine => engine.id === (draft.source?.type === 'tts' ? draft.source.voice.engine ?? engineId : engineId))
52
53
  const voices = catalog?.catalog.status === 'available' ? catalog.catalog.voices : []
53
- const lang = document?.metadata.lang ?? 'zh-CN'
54
+ const lang = effectiveOf(document, actor?.inherited)?.metadata.lang ?? 'zh-CN'
54
55
  const languages = [...new Set(voices.flatMap(voice => voice.lang))].sort()
55
56
  const rateRange = engine?.parameters?.rate, styles = engine?.parameters?.styles
56
57
  const normalizedRate = draft.rateInput?.normalize('NFKC').trim()
@@ -67,7 +68,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
67
68
  const actual = workbench.getState().authoring, content = workbench.getDocument(identity)
68
69
  if (!actual?.version || !content) return
69
70
  owner.current.generation++; request.current?.abort(); request.current = undefined
70
- const value: VoiceDraft = { version: actual.version, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(content, stepId).value ?? null, replaceOverrides: false }
71
+ const value: VoiceDraft = { version: actual.version, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(effectiveOf(content, actual.inherited), stepId).value ?? null, replaceOverrides: false }
71
72
  setDraft(value); setRestored(undefined); setStorageFailed(false); setReview(undefined); setFailure(undefined)
72
73
  setEngineFilter(value.source?.type === 'tts' ? value.source.voice.engine : undefined); setLanguage(''); setQuery('')
73
74
  } }), [workbench, identity, stepId])
@@ -5,6 +5,7 @@ import { resolveDocumentStepVoice } from '../document-voices.ts'
5
5
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
6
6
  import { isAgentChanging } from '../workbench-state.ts'
7
7
  import { DocumentVoiceDialog } from './DocumentVoiceDialog.tsx'
8
+ import { effectiveOf } from '../effective-settings.ts'
8
9
 
9
10
  /** One current voice and selector, shared by document captions and production. */
10
11
  export function DocumentVoiceField({ stepId, disabled = false, onGenerate }: { stepId: string, disabled?: boolean, onGenerate?(): void }) {
@@ -16,7 +17,7 @@ export function DocumentVoiceField({ stepId, disabled = false, onGenerate }: { s
16
17
  useEffect(() => { setOpen(false) }, [source?.identity, stepId])
17
18
  const document = source?.content, step = document?.steps[stepId], p = PRODUCTION_MESSAGES[locale]
18
19
  if (!document || !step || !source?.identity) return null
19
- const voice = resolveDocumentStepVoice(document, stepId)
20
+ const voice = resolveDocumentStepVoice(effectiveOf(document, source.inherited), stepId)
20
21
  const recording = voice.value?.type === 'recording' ? document.assets[voice.value.assetId] : undefined
21
22
  const label = voice.value?.type === 'tts' ? voice.value.voice.voice
22
23
  : voice.value?.type === 'none' ? p.none
@@ -59,6 +59,7 @@ export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
59
59
  {done && <PmNotice tone="ok">{done}</PmNotice>}
60
60
  {error && !editing && <PmNotice tone="danger">{error}</PmNotice>}
61
61
  {answer && !answer.git && !answer.single && <PmNotice tone="warn">{t.notGit}</PmNotice>}
62
+ {answer?.migration && workbench.client.migrateWorkspace && <PmNotice tone="warn" action={<PmButton disabled={working} onClick={() => void run(async () => t.upgraded((await workbench.migrateWorkspace()).documents.length))}>{t.upgrade}</PmButton>}>{t.formatUpgrade}</PmNotice>}
62
63
  <div className="pmw-home__heading-row">
63
64
  <h2 className="pmw-home__heading">{t.allDocuments}</h2>
64
65
  {documents.length > 6 && (
@@ -1,12 +1,12 @@
1
1
  import { useState } from 'react'
2
2
  import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
3
- import type { TeachingDocument } from '@lincyaw/kernel'
3
+ import type { PresmiumDocument } from '@lincyaw/kernel'
4
4
  import { PmField, PmRange } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
6
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
7
7
 
8
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 }) {
9
+ export function ProductionCaptionSize({ identity, document, disabled, onChanged }: { identity: string, document: PresmiumDocument, disabled: boolean, onChanged(): void }) {
10
10
  const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
11
11
  const [preview, setPreview] = useState<number>()
12
12
  const percent = Math.round(captionScale(document.production) * 100)
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
- import type { DocumentChangeAnswer, MediaClip, ProductionAssetInspection, ProductionBinding, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { DocumentChangeAnswer, MediaClip, ProductionAssetInspection, ProductionBinding, PresmiumDocument } from '@lincyaw/kernel'
3
3
  import { randomUUID } from '@lincyaw/kernel'
4
4
  import { MediaClipEditor } from '../MediaClipEditor.tsx'
5
5
  import type { MediaClipDraft } from '../MediaClipEditor.tsx'
@@ -11,7 +11,7 @@ import { MEDIA_MESSAGES, mediaFailure } from '../media-messages.ts'
11
11
  interface Props {
12
12
  identity: string
13
13
  version: string
14
- document: TeachingDocument
14
+ document: PresmiumDocument
15
15
  sectionId: string
16
16
  stepId: string
17
17
  binding?: ProductionBinding
@@ -21,6 +21,7 @@ import { ProductionMediaClips } from './ProductionMediaClips.tsx'
21
21
  import { ProductionRecording } from './ProductionRecording.tsx'
22
22
  import { ProductionTranscription } from './ProductionTranscription.tsx'
23
23
  import { useProductionVoicePlayback } from '../production-voice-playback.ts'
24
+ import { effectiveOf } from '../effective-settings.ts'
24
25
 
25
26
  const clockTime = (value?: number) => {
26
27
  if (value === undefined || !Number.isFinite(value)) return '--:--.---'
@@ -60,7 +61,7 @@ export function ProductionPanel({ onClose, closing, active = true, actions }: {
60
61
  const transcriptionSelection = useRef(0)
61
62
  const owner = useRef({ active: true, generation: 0 }), initial = useRef(false)
62
63
  const document = source?.content, sectionId = position && document?.sections[position.section] ? position.section : document?.sectionOrder[0]
63
- const declared = Boolean(document?.metadata.plugins?.includes('@lincyaw/addon-lecture'))
64
+ const declared = Boolean(effectiveOf(document, source?.inherited)?.metadata.plugins?.includes('@lincyaw/addon-lecture'))
64
65
  const section = sectionId ? document?.sections[sectionId] : undefined
65
66
  const stepId = section?.stepOrder[position && position.section === sectionId ? position.step : 0] ?? section?.stepOrder[0]
66
67
  const sourceCurrent = Boolean(source && stamp && source.version === stamp.version && source.fingerprint === stamp.fingerprint && (source.projectRevision ?? 0) === stamp.project && !source.dirty && !source.saving && !source.error)
@@ -255,7 +256,7 @@ export function ProductionPanel({ onClose, closing, active = true, actions }: {
255
256
  onSelectAsset={() => { transcriptionSelection.current++; setTranscriptionAsset(undefined) }} />
256
257
  </div></PmTabPanel>
257
258
  <PmTabPanel value="captions" keepMounted><div className="pmw-production__fields">
258
- <ProductionCaptionSize identity={source.identity} document={document} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
259
+ <ProductionCaptionSize identity={source.identity} document={effectiveOf(document, source.inherited)} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
259
260
  <ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
260
261
  </div></PmTabPanel>
261
262
  </PmTabs>
@@ -8,6 +8,7 @@ import { MEDIA_MESSAGES, mediaFailure } from '../media-messages.ts'
8
8
  import { mediaTime, mediaTimeValue } from '../media-time.ts'
9
9
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
10
10
  import type { RecordingRangeDraft as RangeDraft } from '../document-production.ts'
11
+ import { effectiveOf } from '../effective-settings.ts'
11
12
  const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
12
13
 
13
14
  /** Video-only pending input; the existing recording transaction and source actor own every write. */
@@ -16,7 +17,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
16
17
  }) {
17
18
  const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), source = useWorkbenchState(state => state.authoring)
18
19
  const t = MEDIA_MESSAGES[locale], r = AUDIO_RECORDING_MESSAGES[locale]
19
- const document = source?.identity === identity ? source.content : undefined
20
+ const document = source?.identity === identity ? effectiveOf(source.content, source.inherited) : undefined
20
21
  const effective = document?.production.stepOverrides[stepId]?.voiceSource ?? document?.production.sectionOverrides?.[sectionId]?.voiceSource ?? document?.production.defaults.voiceSource
21
22
  const voice = effective?.type === 'recording' ? effective : undefined, key = JSON.stringify([stepId, voice?.assetId])
22
23
  const drafts = workbench.production.recordingRangeDrafts(identity), mounted = useRef(true), request = useRef<AbortController>()
@@ -43,7 +44,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
43
44
  const clean = () => { const value = workbench.getState().authoring; return value?.identity === identity && !value.loading && !value.dirty && !value.saving && !value.composing && !value.restored && !value.recovering && !value.error ? value : undefined }
44
45
  const settle = () => {
45
46
  const value = sent.current, actual = clean(), step = value && actual?.content?.steps[value.request.stepId]
46
- const saved = step && (actual!.content!.production.stepOverrides[step.id]?.voiceSource ?? actual!.content!.production.sectionOverrides?.[step.sectionId]?.voiceSource ?? actual!.content!.production.defaults.voiceSource)
47
+ const saved = step && (actual!.content!.production.stepOverrides[step.id]?.voiceSource ?? actual!.content!.production.sectionOverrides?.[step.sectionId]?.voiceSource ?? effectiveOf(actual!.content!, actual!.inherited).production.defaults.voiceSource)
47
48
  if (!value || !actual?.version || saved?.type !== 'recording' || saved.assetId !== value.request.assetId || !same(saved.sourceRange, value.request.sourceRange)
48
49
  || actual.content?.assets[saved.assetId]?.fingerprint !== `sha256:${value.request.sha256}`) return false
49
50
  const pending = drafts.get(value.key)