@lincyaw/workbench 0.2.0-rc.12 → 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.
- package/README.md +1 -1
- package/package.json +5 -4
- package/src/AgentActivityBar.tsx +25 -0
- package/src/MediaClipEditor.tsx +7 -6
- package/src/StepProductionEditor.tsx +16 -7
- package/src/agent-activity-messages.ts +14 -0
- package/src/agent-activity.ts +38 -0
- package/src/approvals.tsx +6 -1
- package/src/audio-recording-messages.ts +5 -5
- package/src/audio-recording.ts +27 -5
- package/src/authoring-client.ts +10 -10
- package/src/authoring-draft-fragment.ts +3 -1
- package/src/authoring-window.ts +100 -0
- package/src/base-controls.tsx +28 -7
- package/src/body-draft-actions.ts +60 -0
- package/src/caption-timing-drafts.ts +20 -3
- package/src/caption-timing-messages.ts +2 -2
- package/src/caption-timing.ts +2 -2
- package/src/component-draft-actions.ts +1 -1
- package/src/component-properties.ts +3 -3
- package/src/component-property-drafts.ts +6 -6
- package/src/components.tsx +43 -38
- package/src/container-layout.ts +21 -0
- package/src/context.tsx +5 -3
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +30 -21
- package/src/document-editing.ts +485 -0
- package/src/document-editor/BlockNoteSurface.tsx +40 -14
- package/src/document-editor/CommentComposer.tsx +24 -0
- package/src/document-editor/ComponentMaterials.tsx +4 -10
- package/src/document-editor/ComponentPropertiesDialog.tsx +12 -12
- package/src/document-editor/DocumentBlockFallback.tsx +4 -3
- package/src/document-editor/DocumentBlockPreview.tsx +11 -4
- package/src/document-editor/DocumentComments.tsx +87 -17
- package/src/document-editor/DocumentEditor.tsx +66 -14
- package/src/document-editor/DocumentStepNarration.tsx +39 -27
- package/src/document-editor/NarrationEditor.tsx +55 -21
- package/src/document-editor/NewCommentDrafts.tsx +120 -37
- package/src/document-editor/PlaceComment.tsx +252 -0
- package/src/document-editor/agent-targets.ts +34 -0
- package/src/document-editor/blocknote-messages.ts +2 -0
- package/src/document-editor/comment-draft-actions.ts +40 -20
- package/src/document-editor/comment-draft-inspection.ts +2 -2
- package/src/document-editor/comment-drafts.ts +75 -27
- package/src/document-editor/comments.ts +34 -14
- package/src/document-editor/component-label.ts +11 -0
- package/src/document-editor/file-input.ts +2 -2
- package/src/document-editor/focus.ts +0 -2
- package/src/document-editor/inline.ts +1 -0
- package/src/document-editor/insertion-place.ts +60 -0
- package/src/document-editor/messages.ts +3 -3
- package/src/document-editor/narration-schema.tsx +12 -6
- package/src/document-editor/narration.ts +19 -3
- package/src/document-editor/page-body.ts +60 -0
- package/src/document-editor/popover.tsx +4 -2
- package/src/document-editor/projection.ts +21 -19
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +8 -3
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-preview.ts +3 -2
- package/src/document-production.ts +492 -0
- package/src/document-return-point.ts +2 -2
- package/src/document-session.ts +216 -67
- package/src/document-timing-drafts.ts +26 -6
- package/src/effective-settings.ts +12 -0
- package/src/history.ts +5 -5
- package/src/import-messages.ts +40 -0
- package/src/index.ts +11 -5
- package/src/jobs.ts +1 -1
- package/src/mcp-settings-messages.ts +39 -0
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +39 -18
- package/src/outline.ts +5 -5
- package/src/panels/DocumentImportDialog.tsx +59 -0
- package/src/panels/DocumentNarrationPanel.tsx +2 -2
- package/src/panels/DocumentView.tsx +106 -77
- package/src/panels/DocumentVoiceDialog.tsx +29 -12
- package/src/panels/DocumentVoiceField.tsx +3 -2
- package/src/panels/ExportPanel.tsx +2 -10
- package/src/panels/HistoryPanel.tsx +36 -10
- package/src/panels/HomePanel.tsx +12 -1
- package/src/panels/McpSettingsPanel.tsx +86 -0
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +4 -7
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +12 -9
- package/src/panels/ProductionMediaClips.tsx +25 -9
- package/src/panels/ProductionPanel.tsx +21 -17
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +26 -23
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +8 -6
- package/src/panels/SourceDocumentPanel.tsx +24 -40
- package/src/panels/SpeechSettingsPanel.tsx +2 -2
- package/src/panels/TranscriptionAdoption.tsx +42 -36
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoicePreviewDialog.tsx +1 -1
- package/src/panels/VoiceScopeField.tsx +2 -2
- package/src/panels/VoiceoverDialog.tsx +11 -10
- package/src/places.ts +1 -36
- package/src/preview-playback.ts +1 -1
- package/src/production-draft-actions.ts +37 -0
- package/src/production-messages.ts +6 -0
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/recording-adoption.ts +4 -4
- package/src/sha256.ts +9 -0
- package/src/speech-settings-messages.ts +6 -6
- package/src/step-production.ts +4 -4
- package/src/styles.css +43 -92
- package/src/transcription-drafts.ts +124 -0
- package/src/use-recording-adoption.ts +5 -4
- package/src/voice-drafts.ts +32 -8
- package/src/voice-messages.ts +9 -9
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +159 -0
- package/src/workbench.ts +323 -956
- package/src/workspace-client.ts +41 -12
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { useContainerLayout } from '../container-layout.ts'
|
|
2
4
|
import { keyBelongsToTarget, PRODUCTION_PLAYBACK_RATES, sameProductionBinding, watchFocusSource } from '@lincyaw/kernel'
|
|
3
5
|
import type { ProductionPlaybackCommand } from '@lincyaw/kernel'
|
|
4
6
|
import { PmBadge, PmButton, PmCard, PmDialog, PmEmpty, PmIconButton, PmNotice, PmPanelHeader, PmPopover, PmSearchList, PmSelect, PmSegmented, PmSplitGroup, PmSplitHandle, PmSplitPanel, PmTabs, PmTabPanel, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
@@ -6,18 +8,20 @@ import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
|
6
8
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
7
9
|
import { PRODUCTION_MESSAGES, productionFailure } from '../production-messages.ts'
|
|
8
10
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
9
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
10
|
-
import type { PlaybackKey } from '../workbench.ts'
|
|
11
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
12
|
+
import type { PlaybackKey } from '../workbench-state.ts'
|
|
11
13
|
import { DocumentVoiceField } from './DocumentVoiceField.tsx'
|
|
12
14
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
13
15
|
import { PreviewPanel } from './PreviewPanel.tsx'
|
|
14
16
|
import { VoiceoverDialog } from './VoiceoverDialog.tsx'
|
|
17
|
+
import { ProductionCaptionSize } from './ProductionCaptionSize.tsx'
|
|
15
18
|
import { ProductionCaptionTiming } from './ProductionCaptionTiming.tsx'
|
|
16
19
|
import { ProductionTimeline } from './ProductionTimeline.tsx'
|
|
17
20
|
import { ProductionMediaClips } from './ProductionMediaClips.tsx'
|
|
18
21
|
import { ProductionRecording } from './ProductionRecording.tsx'
|
|
19
22
|
import { ProductionTranscription } from './ProductionTranscription.tsx'
|
|
20
23
|
import { useProductionVoicePlayback } from '../production-voice-playback.ts'
|
|
24
|
+
import { effectiveOf } from '../effective-settings.ts'
|
|
21
25
|
|
|
22
26
|
const clockTime = (value?: number) => {
|
|
23
27
|
if (value === undefined || !Number.isFinite(value)) return '--:--.---'
|
|
@@ -32,7 +36,7 @@ const PLAYBACK_KEYS: Record<string, PlaybackKey> = { ' ': 'play-pause', ArrowLef
|
|
|
32
36
|
* While it is `active`, Space plays or pauses and the left and right arrows select the previous or next step, from the
|
|
33
37
|
* workbench and from its preview alike; text entry, menus, dialogs and controls the keyboard moved to keep their keys.
|
|
34
38
|
*/
|
|
35
|
-
export function ProductionPanel({ onClose, closing, active = true }: { onClose(): void, closing: boolean, active?: boolean }) {
|
|
39
|
+
export function ProductionPanel({ onClose, closing, active = true, actions }: { onClose(): void, closing: boolean, active?: boolean, actions?: ReactNode }) {
|
|
36
40
|
const workbench = useWorkbench(), t = useMessages(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
|
|
37
41
|
const voicePlayback = useProductionVoicePlayback()
|
|
38
42
|
const serviceVersion = useWorkbenchState(state => state.voiceServiceVersion)
|
|
@@ -45,7 +49,8 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
45
49
|
const captionDraftSteps = useWorkbenchState(state => state.captionTimingDraftSteps), captionStorageFailure = useWorkbenchState(state => state.captionTimingDraftStorageFailure)
|
|
46
50
|
const frameCurrent = useWorkbenchState(state => Boolean(state.presentationSnapshot && state.previewIrRevision === state.presentationSnapshot.revision))
|
|
47
51
|
const blocked = useWorkbenchState(state => Boolean(state.authoring?.loading || state.authoring?.composing) || isAgentChanging(state))
|
|
48
|
-
const
|
|
52
|
+
const container = useContainerLayout(), wide = container.productionWide
|
|
53
|
+
const [tab, setTab] = useState('preview')
|
|
49
54
|
const [libraryTab, setLibraryTab] = useState('pages'), [inspectorTab, setInspectorTab] = useState('script'), [outputsOpen, setOutputsOpen] = useState(false)
|
|
50
55
|
const [generateStep, setGenerateStep] = useState<string>(), [failure, setFailure] = useState<string>()
|
|
51
56
|
const [planBusy, setPlanBusy] = useState(false), [planFailure, setPlanFailure] = useState<string>(), [planReload, setPlanReload] = useState(0)
|
|
@@ -56,7 +61,7 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
56
61
|
const transcriptionSelection = useRef(0)
|
|
57
62
|
const owner = useRef({ active: true, generation: 0 }), initial = useRef(false)
|
|
58
63
|
const document = source?.content, sectionId = position && document?.sections[position.section] ? position.section : document?.sectionOrder[0]
|
|
59
|
-
const declared = Boolean(document?.metadata.plugins?.includes('@lincyaw/addon-lecture'))
|
|
64
|
+
const declared = Boolean(effectiveOf(document, source?.inherited)?.metadata.plugins?.includes('@lincyaw/addon-lecture'))
|
|
60
65
|
const section = sectionId ? document?.sections[sectionId] : undefined
|
|
61
66
|
const stepId = section?.stepOrder[position && position.section === sectionId ? position.step : 0] ?? section?.stepOrder[0]
|
|
62
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)
|
|
@@ -68,11 +73,6 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
68
73
|
const canPlay = Boolean(playbackConnected && plan?.canPreview && live?.status === 'ready' && !timingDraft)
|
|
69
74
|
const backgroundBody = !wide && tab === 'timeline', backgroundVisuals = !wide && tab !== 'preview'
|
|
70
75
|
useEffect(() => workbench.observeVoiceoverJobs(), [workbench, source?.identity])
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
const media = matchMedia('(min-width: 1100px)'), update = () => setWide(media.matches)
|
|
73
|
-
media.addEventListener('change', update)
|
|
74
|
-
return () => media.removeEventListener('change', update)
|
|
75
|
-
}, [])
|
|
76
76
|
useEffect(() => () => { owner.current.active = false; owner.current.generation++; controlRequest.current?.abort(); workbench.closeProduction(); workbench.cancelPreviewPreparation() }, [workbench])
|
|
77
77
|
useEffect(() => {
|
|
78
78
|
const controller = new AbortController()
|
|
@@ -177,10 +177,11 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
177
177
|
const mediaEditor = <ProductionMediaClips key={`${source.identity}:${stepId}`} identity={source.identity} version={source.version ?? ''} document={document} sectionId={sectionId} stepId={stepId}
|
|
178
178
|
binding={planCurrent ? plan?.binding : undefined} stepDurationMs={(() => { const step = planCurrent ? plan?.pages.find(page => page.sectionId === sectionId)?.steps.find(step => step.stepId === stepId) : undefined; return step?.timing === 'confirmed' && step.startMs !== undefined && step.endMs !== undefined ? step.endMs - step.startMs : undefined })()}
|
|
179
179
|
disabled={blocked || closing || !declared || !source.version || Boolean(source.dirty || source.saving || source.restored || source.error)} onChanged={() => setMediaRefresh(true)} />
|
|
180
|
-
return <section className="pmw-production" aria-label={p.title}>
|
|
181
|
-
<PmPanelHeader title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
180
|
+
return <section ref={container.ref} className="pmw-production" aria-label={p.title}>
|
|
181
|
+
<PmPanelHeader variant="workspace" title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
182
182
|
leading={<PmIconButton small icon="arrow-left" label={p.back} loading={closing} onClick={onClose} />}
|
|
183
183
|
actions={<>
|
|
184
|
+
{actions}
|
|
184
185
|
<PmBadge tone={sourceCurrent && frameCurrent ? 'ok' : preparing || sourceCurrent ? 'accent' : 'warn'}>{sourceCurrent && frameCurrent ? p.current : preparing || sourceCurrent ? p.preparing : p.outdated}</PmBadge>
|
|
185
186
|
{issueCount > 0 && <PmPopover open={issuesOpen} onOpenChange={setIssuesOpen} label={p.issues(issueCount)} trigger={wide ? <PmButton small icon="warning" title={summary} aria-label={p.issues(issueCount)}>{p.issueCount(issueCount)}</PmButton> : <PmIconButton small icon="warning" label={p.issues(issueCount)} hint={summary} />}>
|
|
186
187
|
<div className="pmw-production__feedback">
|
|
@@ -196,12 +197,12 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
196
197
|
</div>
|
|
197
198
|
</PmPopover>}
|
|
198
199
|
<PmIconButton small icon="refresh" label={p.prepare} loading={preparing} disabled={blocked || closing} onClick={() => void compile()} />
|
|
199
|
-
{wide ? <PmButton small variant="
|
|
200
|
+
{wide ? <PmButton small variant="primary" icon="export" disabled={closing} onClick={openOutputs}>{p.outputs}</PmButton>
|
|
200
201
|
: <PmIconButton small icon="export" label={p.outputs} disabled={closing} onClick={openOutputs} />}
|
|
201
202
|
</>} />
|
|
202
|
-
{!declared && <PmNotice tone="accent"
|
|
203
|
+
{!declared && <PmNotice tone="accent" action={<PmButton small loading={enabling} disabled={blocked || closing} onClick={() => void enable()}>{p.enable}</PmButton>}>{p.enableHint}</PmNotice>}
|
|
203
204
|
{!wide && <PmSegmented label={p.title} value={tab} options={[{ value: 'library', label: p.library }, { value: 'preview', label: p.preview }, { value: 'properties', label: p.properties }, { value: 'timeline', label: p.timeline }]} onChange={setTab} />}
|
|
204
|
-
{voicePlayback.failure && <PmNotice tone="danger"
|
|
205
|
+
{voicePlayback.failure && <PmNotice tone="danger" action={workbench.client.openSpeechSettings && <PmButton small variant="ghost" icon="sliders" onClick={() => { voicePlayback.stop(); workbench.client.openSpeechSettings?.() }}>{p.serviceSettings}</PmButton>}>{voicePlayback.failure}</PmNotice>}
|
|
205
206
|
{voicePlayback.busy && <div role="status"><PmNotice>{voicePlayback.progress ? p.generatingProgress(voicePlayback.progress.completed, voicePlayback.progress.total) : p.generatingPlayback}</PmNotice></div>}
|
|
206
207
|
<PmSplitGroup orientation="vertical" disabled={!wide} className="pmw-production__workarea">
|
|
207
208
|
<PmSplitPanel id="production-main" defaultSize="71%" minSize={wide ? '32%' : 0} className="pmw-production__main" background={backgroundBody}>
|
|
@@ -243,7 +244,7 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
243
244
|
</div></PmTabPanel>
|
|
244
245
|
<PmTabPanel value="voice" keepMounted><div className="pmw-production__fields">
|
|
245
246
|
<DocumentVoiceField key={`${source.identity}:${stepId}`} stepId={stepId} disabled={blocked || closing} onGenerate={() => { voicePlayback.stop(); workbench.stopAuditions(); setGenerateStep(stepId) }} />
|
|
246
|
-
<ProductionRecording key={source.identity} identity={source.identity} sectionId={sectionId} stepId={stepId} active={!outputsOpen && (wide || tab === 'properties') && inspectorTab === 'voice'} disabled={blocked || closing}
|
|
247
|
+
<ProductionRecording key={source.identity} identity={source.identity} sectionId={sectionId} stepId={stepId} active={!outputsOpen && (wide || tab === 'properties') && inspectorTab === 'voice'} available={active && !outputsOpen} onReveal={() => { setInspectorTab('voice'); setTab('properties') }} disabled={blocked || closing}
|
|
247
248
|
onImportStarted={() => transcriptionSelection.current}
|
|
248
249
|
onImported={(assetId, selection) => {
|
|
249
250
|
setMediaRefresh(true)
|
|
@@ -254,7 +255,10 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
254
255
|
selectedAsset={transcriptionAsset?.identity === source.identity ? transcriptionAsset : undefined}
|
|
255
256
|
onSelectAsset={() => { transcriptionSelection.current++; setTranscriptionAsset(undefined) }} />
|
|
256
257
|
</div></PmTabPanel>
|
|
257
|
-
<PmTabPanel value="captions" keepMounted><
|
|
258
|
+
<PmTabPanel value="captions" keepMounted><div className="pmw-production__fields">
|
|
259
|
+
<ProductionCaptionSize identity={source.identity} document={effectiveOf(document, source.inherited)} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
260
|
+
<ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
261
|
+
</div></PmTabPanel>
|
|
258
262
|
</PmTabs>
|
|
259
263
|
</PmSplitPanel>
|
|
260
264
|
</PmSplitGroup>
|
|
@@ -8,13 +8,14 @@ import { AUDIO_RECORDING_MESSAGES } from '../audio-recording-messages.ts'
|
|
|
8
8
|
import { PmButton, PmCard, PmDialog, PmNotice, PmSelect } from '../components.tsx'
|
|
9
9
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
10
10
|
import { mediaFailure } from '../media-messages.ts'
|
|
11
|
+
import type { AuthoringClientActionType } from '@lincyaw/kernel'
|
|
11
12
|
import { ProductionRecordingRange } from './ProductionRecordingRange.tsx'
|
|
12
13
|
|
|
13
|
-
interface Props { identity: string, sectionId: string, stepId: string, active: boolean, disabled: boolean, onImportStarted(): number, onImported(assetId: string, selection: number): void, onAdopted(): void }
|
|
14
|
+
interface Props { identity: string, sectionId: string, stepId: string, active: boolean, available: boolean, disabled: boolean, onReveal(): void, onImportStarted(): number, onImported(assetId: string, selection: number): void, onAdopted(): void }
|
|
14
15
|
const elapsed = (ms: number) => `${String(Math.floor(ms / 60000)).padStart(2, '0')}:${String(Math.floor(ms / 1000) % 60).padStart(2, '0')}`
|
|
15
16
|
|
|
16
17
|
/** Video-only microphone material. The document actor and existing binary transaction still own every save. */
|
|
17
|
-
export function ProductionRecording({ identity, sectionId, stepId, active, disabled, onImportStarted, onImported, onAdopted }: Props) {
|
|
18
|
+
export function ProductionRecording({ identity, sectionId, stepId, active, available, disabled, onReveal, onImportStarted, onImported, onAdopted }: Props) {
|
|
18
19
|
const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), t = AUDIO_RECORDING_MESSAGES[locale]
|
|
19
20
|
const source = useWorkbenchState(state => state.authoring)
|
|
20
21
|
const [recording] = useState(() => documentRecording(workbench, identity))
|
|
@@ -36,14 +37,15 @@ export function ProductionRecording({ identity, sectionId, stepId, active, disab
|
|
|
36
37
|
if (!active) { recording.stop(); audition.current?.stop() }
|
|
37
38
|
if (candidate?.assetId && source?.identity === identity && source.content && !source.content.assets[candidate.assetId]) recording.forgetImport(candidate.assetId)
|
|
38
39
|
}, [active, candidate?.assetId, source?.content, source?.identity, identity, recording])
|
|
39
|
-
const start = () => {
|
|
40
|
+
const start = (signal?: AbortSignal) => {
|
|
40
41
|
setFailure(undefined)
|
|
41
|
-
|
|
42
|
+
return recording.start(async signal => {
|
|
42
43
|
workbench.stopAuditions()
|
|
43
44
|
await workbench.pausePlayback(true)
|
|
45
|
+
signal.throwIfAborted()
|
|
44
46
|
if (!current() || !active) throw new Error('recording-failed')
|
|
45
47
|
return workbench.registerAudioCapture(() => recording.stop())
|
|
46
|
-
})
|
|
48
|
+
}, signal)
|
|
47
49
|
}
|
|
48
50
|
const listen = () => {
|
|
49
51
|
if (!candidate) return
|
|
@@ -54,9 +56,12 @@ export function ProductionRecording({ identity, sectionId, stepId, active, disab
|
|
|
54
56
|
if (listening.status === 'playing' || listening.status === 'loading') audition.current.stop()
|
|
55
57
|
else void audition.current.play(async () => ({ audio: candidate.file }))
|
|
56
58
|
}
|
|
57
|
-
const save = async () => {
|
|
59
|
+
const save = async (signal?: AbortSignal) => {
|
|
58
60
|
if (!candidate || saving || !current()) return
|
|
59
61
|
const file = candidate.file, selection = adoption.revision(), transcriptionSelection = onImportStarted(), controller = new AbortController()
|
|
62
|
+
const abort = () => controller.abort(signal?.reason)
|
|
63
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
64
|
+
if (signal?.aborted) abort()
|
|
60
65
|
request.current = controller; setSaving(true); setFailure(undefined)
|
|
61
66
|
const owns = () => current() && !controller.signal.aborted && request.current === controller && recording.snapshot().candidate?.file === file
|
|
62
67
|
try {
|
|
@@ -64,15 +69,87 @@ export function ProductionRecording({ identity, sectionId, stepId, active, disab
|
|
|
64
69
|
if (!owns()) return
|
|
65
70
|
const currentSource = workbench.getState().authoring
|
|
66
71
|
if (!currentSource?.version || currentSource.identity !== identity || currentSource.dirty || currentSource.saving || currentSource.composing || currentSource.restored || currentSource.error) throw new Error('production-source-changed')
|
|
67
|
-
const answer = await workbench.
|
|
72
|
+
const answer = await workbench.production.ensureAudio(file, { identity, version: currentSource.version }, controller.signal)
|
|
68
73
|
if (!owns()) return
|
|
69
74
|
recording.imported(file, answer.inspection.assetId); adoption.imported(answer.inspection.assetId, selection); onImported(answer.inspection.assetId, transcriptionSelection)
|
|
70
75
|
} catch (error) {
|
|
71
76
|
if (owns()) setFailure(`${t.saveFailed} ${mediaFailure(error, locale)}`)
|
|
72
77
|
} finally {
|
|
78
|
+
signal?.removeEventListener('abort', abort)
|
|
73
79
|
if (request.current === controller) { request.current = undefined; if (current()) setSaving(false) }
|
|
74
80
|
}
|
|
75
81
|
}
|
|
82
|
+
const controls = useRef({ start, save, disabled, saving, active, available, onReveal })
|
|
83
|
+
controls.current = { start, save, disabled, saving, active, available, onReveal }
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!available) return
|
|
86
|
+
const owns = () => current() && controls.current.available && workbench.getState().authoring?.identity === identity
|
|
87
|
+
return workbench.registerAuthoringClientControls({ identity,
|
|
88
|
+
actions: () => {
|
|
89
|
+
if (!owns()) return []
|
|
90
|
+
const actual = recording.snapshot(), take = actual.candidate, player = audition.current?.snapshot()
|
|
91
|
+
const capturing = ['requesting', 'recording', 'stopping'].includes(actual.phase)
|
|
92
|
+
const source = workbench.getState().authoring, clean = source && !source.loading && !source.dirty && !source.saving && !source.composing && !source.restored && !source.error
|
|
93
|
+
const actions: AuthoringClientActionType[] = []
|
|
94
|
+
if (capturing) actions.push('recording.cancel', 'recording.stop')
|
|
95
|
+
if (player?.status === 'playing' || player?.status === 'loading') actions.push('recording.pause')
|
|
96
|
+
if (!controls.current.disabled && !controls.current.saving && clean) {
|
|
97
|
+
if (!capturing && !recordingUnavailable()) actions.push('recording.start')
|
|
98
|
+
if (take && !capturing) actions.push('recording.discard', 'recording.listen', ...!take.assetId ? ['recording.save' as const] : [])
|
|
99
|
+
}
|
|
100
|
+
return actions
|
|
101
|
+
},
|
|
102
|
+
snapshot: () => {
|
|
103
|
+
const actual = recording.snapshot(), take = actual.candidate, player = audition.current?.snapshot()
|
|
104
|
+
return { recording: { phase: actual.phase, elapsedMs: actual.elapsedMs,
|
|
105
|
+
...take ? { candidate: { byteLength: take.file.size, mime: take.file.type, ...take.assetId ? { assetId: take.assetId } : {} } } : {},
|
|
106
|
+
...actual.error ? { error: actual.error } : {}, audition: player?.status ?? 'idle' } }
|
|
107
|
+
},
|
|
108
|
+
execute: async (action, _source, signal) => {
|
|
109
|
+
const owned = () => { signal.throwIfAborted(); if (!owns()) throw new Error('client-recording-unavailable') }
|
|
110
|
+
owned()
|
|
111
|
+
if (!controls.current.active) {
|
|
112
|
+
controls.current.onReveal()
|
|
113
|
+
await workbench.waitForAuthoringClientState(() => { owned(); return controls.current.active }, signal)
|
|
114
|
+
}
|
|
115
|
+
if (action.type === 'recording.start') {
|
|
116
|
+
await controls.current.start(signal); owned()
|
|
117
|
+
if (recording.snapshot().phase !== 'recording') throw new Error(`client-${recording.snapshot().error ?? 'recording-unavailable'}`)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (action.type === 'recording.stop' || action.type === 'recording.cancel') {
|
|
121
|
+
action.type === 'recording.cancel' ? recording.cancelTake() : recording.stop()
|
|
122
|
+
await workbench.waitForAuthoringClientState(() => { owned(); return !['requesting', 'recording', 'stopping'].includes(recording.snapshot().phase) }, signal)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
if (action.type === 'recording.discard') {
|
|
126
|
+
audition.current?.stop(); recording.discard(); setFailure(undefined)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
if (action.type === 'recording.pause') { audition.current?.stop(); return }
|
|
130
|
+
const take = recording.snapshot().candidate
|
|
131
|
+
if (!take) throw new Error('client-recording-unavailable')
|
|
132
|
+
if (action.type === 'recording.save') {
|
|
133
|
+
await controls.current.save(signal); owned()
|
|
134
|
+
if (recording.snapshot().candidate?.file !== take.file || !recording.snapshot().candidate?.assetId) throw new Error('client-recording-save-unverified')
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
if (action.type === 'recording.listen') {
|
|
138
|
+
if (!audition.current) {
|
|
139
|
+
const player = audition.current = new Audition(workbench)
|
|
140
|
+
player.subscribe(() => { if (current()) setListening(player.snapshot()) })
|
|
141
|
+
}
|
|
142
|
+
const player = audition.current, stop = () => player.stop()
|
|
143
|
+
signal.addEventListener('abort', stop, { once: true })
|
|
144
|
+
try { await player.play(async () => ({ audio: take.file })); owned(); if (player.snapshot().status !== 'playing') throw new Error('client-recording-listen-unverified') }
|
|
145
|
+
finally { signal.removeEventListener('abort', stop) }
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
throw new Error('client-action-unavailable')
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
}, [workbench, identity, available, recording])
|
|
152
|
+
useEffect(() => workbench.refreshAuthoringClientControls(), [workbench, state.phase, state.error, candidate?.file, candidate?.assetId, saving, disabled, active, available, listening.status])
|
|
76
153
|
return <PmCard className="pmw-audio-recording" data-recording={state.phase}>
|
|
77
154
|
<strong>{t.title}</strong>
|
|
78
155
|
{status && !(status === t.imported && adoption.adopted && candidate?.assetId === adoption.selected) && <span className="pm-ui-hint"><span role="status">{saving ? t.saving : status}</span>{state.phase === 'recording' && <span aria-hidden="true"> · {elapsed(state.elapsedMs)}</span>}</span>}
|
|
@@ -80,12 +157,12 @@ export function ProductionRecording({ identity, sectionId, stepId, active, disab
|
|
|
80
157
|
{failure && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
81
158
|
{listening.status === 'failed' && <PmNotice tone="warn">{t.failures[listening.error ?? 'audition-request'] ?? t.failures['audition-request']}</PmNotice>}
|
|
82
159
|
<div className="pmw-voice__actions">
|
|
83
|
-
{!capturing && !candidate && <PmButton small variant="primary" disabled={disabled || saving || !active || Boolean(unavailable)} onClick={start}>{t.start}</PmButton>}
|
|
160
|
+
{!capturing && !candidate && <PmButton small variant="primary" disabled={disabled || saving || !active || Boolean(unavailable)} onClick={() => void start()}>{t.start}</PmButton>}
|
|
84
161
|
{state.phase === 'requesting' && <PmButton small onClick={() => recording.cancelTake()}>{t.cancel}</PmButton>}
|
|
85
162
|
{state.phase === 'recording' && <><PmButton small onClick={() => recording.stop()}>{t.stop}</PmButton><PmButton small onClick={() => recording.cancelTake()}>{t.cancelTake}</PmButton></>}
|
|
86
163
|
{candidate && !capturing && <PmButton small disabled={!active || saving} loading={listening.status === 'loading'} onClick={listen}>{listening.status === 'playing' ? t.stopAudition : t.audition}</PmButton>}
|
|
87
164
|
{candidate && !candidate.assetId && !capturing && <PmButton small variant="primary" disabled={disabled || !active} loading={saving} onClick={() => void save()}>{failure ? t.retry : t.save}</PmButton>}
|
|
88
|
-
{candidate && !capturing && <PmButton small disabled={disabled || saving || !active || Boolean(unavailable)} onClick={start}>{t.rerecord}</PmButton>}
|
|
165
|
+
{candidate && !capturing && <PmButton small disabled={disabled || saving || !active || Boolean(unavailable)} onClick={() => void start()}>{t.rerecord}</PmButton>}
|
|
89
166
|
{saving && <PmButton small onClick={() => { request.current?.abort(); setSaving(false) }}>{t.cancelSave}</PmButton>}
|
|
90
167
|
{candidate && !capturing && !saving && <PmButton small onClick={() => setDiscard(true)}>{t.discard}</PmButton>}
|
|
91
168
|
</div>
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState } from 'react'
|
|
2
|
-
import { recordingSourceRange } from '@lincyaw/kernel'
|
|
3
|
-
import type { DocumentRecordingAdoption, ProductionAssetInspection
|
|
2
|
+
import { randomUUID, recordingSourceRange } from '@lincyaw/kernel'
|
|
3
|
+
import type { DocumentRecordingAdoption, ProductionAssetInspection } from '@lincyaw/kernel'
|
|
4
4
|
import { PmButton, PmInput, PmNotice } from '../components.tsx'
|
|
5
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
6
|
import { AUDIO_RECORDING_MESSAGES } from '../audio-recording-messages.ts'
|
|
7
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
|
-
|
|
11
|
-
|
|
12
|
-
interface RangeDraft { version: string, voice: RecordingSource, range?: TimeRange, startText?: string, endText?: string }
|
|
10
|
+
import type { RecordingRangeDraft as RangeDraft } from '../document-production.ts'
|
|
11
|
+
import { effectiveOf } from '../effective-settings.ts'
|
|
13
12
|
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
|
|
14
13
|
|
|
15
14
|
/** Video-only pending input; the existing recording transaction and source actor own every write. */
|
|
@@ -18,10 +17,10 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
18
17
|
}) {
|
|
19
18
|
const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), source = useWorkbenchState(state => state.authoring)
|
|
20
19
|
const t = MEDIA_MESSAGES[locale], r = AUDIO_RECORDING_MESSAGES[locale]
|
|
21
|
-
const document = source?.identity === identity ? source.content : undefined
|
|
20
|
+
const document = source?.identity === identity ? effectiveOf(source.content, source.inherited) : undefined
|
|
22
21
|
const effective = document?.production.stepOverrides[stepId]?.voiceSource ?? document?.production.sectionOverrides?.[sectionId]?.voiceSource ?? document?.production.defaults.voiceSource
|
|
23
22
|
const voice = effective?.type === 'recording' ? effective : undefined, key = JSON.stringify([stepId, voice?.assetId])
|
|
24
|
-
const drafts =
|
|
23
|
+
const drafts = workbench.production.recordingRangeDrafts(identity), mounted = useRef(true), request = useRef<AbortController>()
|
|
25
24
|
const [inspection, setInspection] = useState<{ version: string, value: ProductionAssetInspection }>(), [loading, setLoading] = useState(false)
|
|
26
25
|
const [busy, setBusy] = useState(false), [failure, setFailure] = useState<string>(), [reload, setReload] = useState(0), [, render] = useState(0)
|
|
27
26
|
const rangeErrorId = useId()
|
|
@@ -34,7 +33,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
34
33
|
const latest = useRef({ key, active, disabled, onChanged }); latest.current = { key, active, disabled, onChanged }
|
|
35
34
|
const current = () => mounted.current && workbench.getState().authoring?.identity === identity
|
|
36
35
|
const inspected = inspection && inspection.version === source?.version && inspection.value.assetId === voice?.assetId ? inspection.value : undefined
|
|
37
|
-
const draft = drafts.
|
|
36
|
+
const draft = drafts.get(key) ?? (voice ? { version: source?.version ?? '', voice } : undefined)
|
|
38
37
|
const range = draft?.range ?? (draft && inspected ? recordingSourceRange(draft.voice, inspected.durationMs) : undefined)
|
|
39
38
|
const start = draft ? mediaTimeValue(draft.startText, range?.startMs ?? draft.voice.sourceRange?.startMs ?? 0) : undefined
|
|
40
39
|
const end = draft ? mediaTimeValue(draft.endText, range?.endMs ?? draft.voice.sourceRange?.endMs ?? 0) : undefined
|
|
@@ -45,25 +44,29 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
45
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 }
|
|
46
45
|
const settle = () => {
|
|
47
46
|
const value = sent.current, actual = clean(), step = value && actual?.content?.steps[value.request.stepId]
|
|
48
|
-
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)
|
|
49
48
|
if (!value || !actual?.version || saved?.type !== 'recording' || saved.assetId !== value.request.assetId || !same(saved.sourceRange, value.request.sourceRange)
|
|
50
49
|
|| actual.content?.assets[saved.assetId]?.fingerprint !== `sha256:${value.request.sha256}`) return false
|
|
51
|
-
const pending = drafts.
|
|
52
|
-
if (pending === value.draft)
|
|
53
|
-
else if (pending?.version === value.draft.version && same(pending.voice, value.draft.voice))
|
|
54
|
-
if (current()) { setFailure(undefined); render(value => value + 1) }
|
|
50
|
+
const pending = drafts.get(value.key)
|
|
51
|
+
if (pending === value.draft) workbench.production.setRecordingRangeDraft(identity, value.key, undefined)
|
|
52
|
+
else if (pending?.version === value.draft.version && same(pending.voice, value.draft.voice)) workbench.production.setRecordingRangeDraft(identity, value.key, { ...pending, version: actual.version, voice: structuredClone(saved) })
|
|
53
|
+
if (current()) { workbench.refreshAuthoringClientControls(); setFailure(undefined); render(value => value + 1) }
|
|
55
54
|
if (latest.current.key === value.key && latest.current.active && !latest.current.disabled && reported.current !== value.request.id) {
|
|
56
55
|
reported.current = value.request.id; latest.current.onChanged()
|
|
57
56
|
}
|
|
58
57
|
return true
|
|
59
58
|
}
|
|
59
|
+
useEffect(() => workbench.registerNavigationGuard(() => current() && (composing.current || Boolean(request.current))), [workbench, identity])
|
|
60
|
+
useEffect(() => workbench.production.registerDraftView({ identity, kind: 'recording-range', has: target => current() && target === latest.current.key,
|
|
61
|
+
blocked: () => composing.current || Boolean(request.current), clear: () => { setFailure(undefined); render(value => value + 1) } }), [workbench, identity])
|
|
62
|
+
useEffect(() => { workbench.refreshAuthoringClientControls() }, [workbench, busy, key, active])
|
|
60
63
|
useEffect(() => () => { mounted.current = false; request.current?.abort() }, [])
|
|
61
64
|
useEffect(() => { request.current?.abort(); request.current = undefined; setBusy(false); setFailure(undefined) }, [key, active])
|
|
62
65
|
useEffect(() => {
|
|
63
66
|
const version = source?.version, assetId = voice?.assetId, controller = new AbortController()
|
|
64
67
|
if (!active || !version || !assetId || disabled) { setLoading(false); return }
|
|
65
68
|
setLoading(true)
|
|
66
|
-
void workbench.
|
|
69
|
+
void workbench.production.inspectAudio(assetId, { identity, version }, controller.signal).then(answer => {
|
|
67
70
|
if (!controller.signal.aborted && current() && latest.current.key === key) setInspection({ version: answer.version, value: answer.inspection })
|
|
68
71
|
}, error => { if (!controller.signal.aborted && current() && latest.current.key === key) setFailure(failureText(error)) })
|
|
69
72
|
.finally(() => { if (!controller.signal.aborted && current() && latest.current.key === key) setLoading(false) })
|
|
@@ -72,7 +75,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
72
75
|
useEffect(() => { settle() }, [source?.version, source?.content, source?.loading, source?.dirty, source?.saving, source?.composing, source?.restored, source?.error, active, disabled, key])
|
|
73
76
|
const edit = (patch: Partial<RangeDraft>) => {
|
|
74
77
|
if (!draft) return
|
|
75
|
-
|
|
78
|
+
workbench.production.setRecordingRangeDraft(identity, key, { ...draft, ...range ? { range: { ...range } } : {}, ...patch }); workbench.refreshAuthoringClientControls(); setFailure(undefined); render(value => value + 1)
|
|
76
79
|
}
|
|
77
80
|
const apply = async () => {
|
|
78
81
|
if (!voice || !draft || !inspected || !valid || !changed || busy || disabled || !active || composing.current || !current()) return
|
|
@@ -81,11 +84,11 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
81
84
|
const controller = new AbortController(), proposed = { startMs: start!, endMs: end! }
|
|
82
85
|
const previous = sent.current?.request
|
|
83
86
|
const change: DocumentRecordingAdoption = previous && previous.source.version === source.version && previous.stepId === stepId && previous.assetId === voice.assetId && previous.sha256 === inspected.sha256 && same(previous.sourceRange, proposed)
|
|
84
|
-
? previous : { id:
|
|
85
|
-
const stored = drafts.
|
|
86
|
-
|
|
87
|
+
? previous : { id: randomUUID(), source: { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, stepId, assetId: voice.assetId, sha256: inspected.sha256, sourceRange: proposed }
|
|
88
|
+
const stored = drafts.get(key) ?? draft
|
|
89
|
+
workbench.production.setRecordingRangeDraft(identity, key, stored); sent.current = { key, draft: stored, request: change }; request.current = controller
|
|
87
90
|
setBusy(true); setFailure(undefined)
|
|
88
|
-
try { await workbench.
|
|
91
|
+
try { await workbench.production.adoptRecording(change, { identity, version: source.version }, controller.signal); if (current()) settle() }
|
|
89
92
|
catch (error) { if (current() && request.current === controller && !settle() && !controller.signal.aborted) setFailure(failureText(error)) }
|
|
90
93
|
finally { if (request.current === controller) { request.current = undefined; if (current()) setBusy(false) } }
|
|
91
94
|
}
|
|
@@ -95,7 +98,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
95
98
|
const trimmed = Boolean(canonicalRange && inspected && (canonicalRange.startMs > 0 || canonicalRange.endMs < inspected.durationMs))
|
|
96
99
|
const hasCaptions = document?.steps[stepId]?.narrationIds.some(id => document.narrations[id]?.content.some(node => node.type !== 'cue' && (node.type === 'text' ? node.text : node.display).trim()))
|
|
97
100
|
return <section className="pm-ui-media-clip-editor" aria-label={r.trim} onFocusCapture={() => { if (!disabled) void workbench.pausePlayback() }}
|
|
98
|
-
onCompositionStart={() => { composing.current = true }} onCompositionEnd={() => { composing.current = false }}
|
|
101
|
+
onCompositionStart={() => { composing.current = true; workbench.refreshAuthoringClientControls() }} onCompositionEnd={() => { composing.current = false; workbench.refreshAuthoringClientControls() }}
|
|
99
102
|
onKeyDown={event => { event.stopPropagation(); if (event.key === 'Enter' && event.target instanceof HTMLInputElement && !event.nativeEvent.isComposing && !composing.current) { event.preventDefault(); void apply() } }}>
|
|
100
103
|
<strong>{r.trim}</strong>
|
|
101
104
|
<span>{document?.assets[voice.assetId]?.title || r.title}</span>
|
|
@@ -110,9 +113,9 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
110
113
|
<PmButton small disabled={disabled || !inspected} onClick={() => edit({ range: { startMs: 0, endMs: inspected!.durationMs }, startText: undefined, endText: undefined })}>{t.restore}</PmButton>
|
|
111
114
|
{busy && <PmButton small onClick={() => { request.current?.abort(); request.current = undefined; setBusy(false) }}>{AUDIO_RECORDING_MESSAGES[locale].cancelAdoption}</PmButton>}
|
|
112
115
|
</div>
|
|
113
|
-
{review && <PmNotice tone="warn"
|
|
116
|
+
{review && <PmNotice tone="warn" action={<PmButton small disabled={disabled || !inspected || busy} onClick={() => edit({ version: source!.version!, voice: structuredClone(voice) })}>{t.check}</PmButton>}>{t.review}</PmNotice>}
|
|
114
117
|
{trimmed && hasCaptions && <PmNotice tone="warn">{r.captionReview}</PmNotice>}
|
|
115
|
-
{failure && <PmNotice tone="danger"
|
|
116
|
-
{drafts.
|
|
118
|
+
{failure && <PmNotice tone="danger" action={<PmButton small disabled={disabled || busy} onClick={() => { setInspection(undefined); setFailure(undefined); setReload(value => value + 1) }}>{t.retry}</PmButton>}>{failure}</PmNotice>}
|
|
119
|
+
{drafts.has(key) && <span className="pm-ui-field__hint" role="status">{t.pending}</span>}
|
|
117
120
|
</section>
|
|
118
121
|
}
|
|
@@ -36,6 +36,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
|
|
|
36
36
|
}, [workbench, directory, plan, sectionId, active, current])
|
|
37
37
|
const document = source?.content, section = document?.sections[sectionId]
|
|
38
38
|
const page = current ? plan?.pages.find(page => page.sectionId === sectionId) : undefined
|
|
39
|
+
// The current plan lists every page of the lecture; a page of the document it lacks is left out of the lecture.
|
|
40
|
+
const excluded = Boolean(current && plan && section && !page)
|
|
41
|
+
// On a page of the lecture, a step it leaves out is missing from the page's steps.
|
|
42
|
+
const stepLeftOut = Boolean(page && !page.steps.some(step => step.stepId === stepId))
|
|
39
43
|
const start = page?.startMs, end = page?.endMs, duration = start !== undefined && end !== undefined ? Math.max(0, end - start) : undefined
|
|
40
44
|
const position = plan && current && playback && sameProductionBinding(playback.binding, plan.binding) && playback.position?.sectionId === sectionId && start !== undefined ? Math.max(0, playback.position.timeMs - start) : undefined
|
|
41
45
|
const tracks: TimelineTrack[] = page && plan ? plan.tracks.map(track => ({ id: track.kind, label: p.tracks[track.kind], segments: track.segments.filter(segment => segment.sectionId === sectionId).map(segment => {
|
|
@@ -49,9 +53,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
|
|
|
49
53
|
statusLabel: [status, track.kind === 'caption' && p.alignmentStatus[segment.alignment ?? 'none'], segment.audio && (wave === false ? p.waveformUnavailable : wave === undefined ? p.waveformLoading : undefined)].filter(Boolean).join(' · '),
|
|
50
54
|
waveform: wave ? wave.peaks : undefined,
|
|
51
55
|
}
|
|
52
|
-
}) })) : [{ id: 'visual', label: p.tracks.visual, segments: section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
|
|
56
|
+
}) })) : [{ id: 'visual', label: p.tracks.visual, segments: excluded ? [] : section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
|
|
53
57
|
const captionChoices = current ? plan?.tracks.find(track => track.kind === 'caption')?.segments.filter(segment => segment.stepId === stepId && (segment.alignment === 'words' || segment.alignment === 'manual') && segment.timing === 'confirmed').map(segment => segment.id) ?? [] : []
|
|
54
58
|
return <PmTimeline variant="editor" label={p.timeline} tracks={tracks} labels={p.timelineLabels} durationMs={duration} durationStatus={page?.timing ?? 'unknown'} currentTimeMs={position} selectedStepId={stepId} showSteps={false}
|
|
59
|
+
excluded={excluded ? { status: p.notInLecture, notice: p.notInLectureHint } : undefined} notice={stepLeftOut ? p.notInLectureStep : undefined}
|
|
55
60
|
segmentPicker={{ track: 'caption', ids: captionChoices, label: p.captionSegment, placeholder: p.chooseCaptionSegment }}
|
|
56
61
|
zoom={zoom} onZoomChange={setZoom} disabled={disabled} loading={loading} seeking={seeking} seekDisabled={!seekEnabled || start === undefined}
|
|
57
62
|
onSelectStep={onSelectStep} onSelectSegment={(track, selected) => {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
2
|
-
import type { DocumentTranscriptionRequest,
|
|
2
|
+
import type { DocumentTranscriptionRequest, PresmiumDocument, TranscriptionCapabilities, TranscriptionListAnswer, TranscriptionRevision, TranscriptionTask } from '@lincyaw/kernel'
|
|
3
|
+
import { randomUUID } from '@lincyaw/kernel'
|
|
3
4
|
import { PmBadge, PmButton, PmCard, PmDialog, PmField, PmIconButton, PmNotice, PmSelect } from '../components.tsx'
|
|
4
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
6
|
import { documentTranscriptionSession } from '../transcription-session.ts'
|
|
6
7
|
import { TRANSCRIPTION_MESSAGES, transcriptionFailure } from '../transcription-messages.ts'
|
|
7
8
|
import { TranscriptionAdoption } from './TranscriptionAdoption.tsx'
|
|
9
|
+
import { effectiveOf } from '../effective-settings.ts'
|
|
8
10
|
|
|
9
|
-
interface Props { identity: string, directory: string, document:
|
|
11
|
+
interface Props { identity: string, directory: string, document: PresmiumDocument, sectionId: string, stepId: string, disabled: boolean, active: boolean, selectedAsset?: { id: string, revision: number }, onSelectAsset(): void }
|
|
10
12
|
|
|
11
13
|
/** ASR creates material; a separate, source-bound review is the only script write. */
|
|
12
14
|
export function ProductionTranscription({ identity, directory, document, sectionId, stepId, disabled, active, selectedAsset, onSelectAsset }: Props) {
|
|
@@ -81,7 +83,7 @@ export function ProductionTranscription({ identity, directory, document, section
|
|
|
81
83
|
const controller = new AbortController(); importRequest.current = controller; setImporting(true); setFailure(undefined)
|
|
82
84
|
pendingFile.current = value
|
|
83
85
|
try {
|
|
84
|
-
const answer = await workbench.
|
|
86
|
+
const answer = await workbench.production.ensureAudio(value, { identity, version: now.version }, controller.signal)
|
|
85
87
|
if (current() && !controller.signal.aborted) { setAssetId(answer.inspection.assetId); pendingFile.current = undefined }
|
|
86
88
|
} catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
|
|
87
89
|
finally { if (importRequest.current === controller) { importRequest.current = undefined; if (current()) setImporting(false) } }
|
|
@@ -92,10 +94,10 @@ export function ProductionTranscription({ identity, directory, document, section
|
|
|
92
94
|
const controller = new AbortController(); inspectionRequest.current = controller; setInspecting(true)
|
|
93
95
|
setFailure(undefined)
|
|
94
96
|
try {
|
|
95
|
-
const expected = { identity, version: now.version }, audio = await workbench.
|
|
97
|
+
const expected = { identity, version: now.version }, audio = await workbench.production.inspectAudio(assetId, expected, controller.signal)
|
|
96
98
|
if (!current() || controller.signal.aborted) return
|
|
97
|
-
const request: DocumentTranscriptionRequest = { intent: `transcription_${
|
|
98
|
-
await session.start(request, () => workbench.
|
|
99
|
+
const request: DocumentTranscriptionRequest = { intent: `transcription_${randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: effectiveOf(now.content, now.inherited).metadata.lang, confirmed: true }
|
|
100
|
+
await session.start(request, () => workbench.production.startTranscription(request, expected))
|
|
99
101
|
} catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
|
|
100
102
|
finally { if (inspectionRequest.current === controller) { inspectionRequest.current = undefined; if (current()) setInspecting(false) } }
|
|
101
103
|
}
|