@lincyaw/workbench 0.2.0-rc.6 → 0.2.0-rc.61
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/package.json +5 -4
- package/src/MediaClipEditor.tsx +4 -3
- package/src/StepProductionEditor.tsx +13 -4
- package/src/approvals.tsx +6 -1
- 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/body-draft-actions.ts +60 -0
- package/src/caption-timing-drafts.ts +18 -1
- package/src/component-property-drafts.ts +5 -5
- package/src/components.tsx +22 -31
- 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 +28 -19
- package/src/document-editing.ts +484 -0
- package/src/document-editor/BlockNoteSurface.tsx +25 -9
- package/src/document-editor/ComponentMaterials.tsx +3 -9
- package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
- package/src/document-editor/DocumentBlockPreview.tsx +4 -2
- package/src/document-editor/DocumentComments.tsx +85 -14
- package/src/document-editor/DocumentEditor.tsx +44 -7
- package/src/document-editor/DocumentStepNarration.tsx +33 -25
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +114 -31
- package/src/document-editor/PlaceComment.tsx +228 -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 +73 -25
- package/src/document-editor/comments.ts +30 -10
- 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/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/projection.ts +2 -2
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +12 -1
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-production.ts +491 -0
- package/src/document-session.ts +193 -53
- package/src/document-timing-drafts.ts +22 -2
- package/src/history.ts +5 -5
- package/src/index.ts +6 -5
- package/src/jobs.ts +1 -1
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +19 -4
- package/src/panels/DocumentView.tsx +66 -26
- package/src/panels/DocumentVoiceDialog.tsx +25 -9
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/ExportPanel.tsx +1 -6
- package/src/panels/HistoryPanel.tsx +1 -1
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +1 -4
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +12 -9
- package/src/panels/ProductionMediaClips.tsx +23 -7
- package/src/panels/ProductionPanel.tsx +8 -4
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +21 -19
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +5 -4
- package/src/panels/SourceDocumentPanel.tsx +12 -15
- package/src/panels/TranscriptionAdoption.tsx +40 -34
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoiceoverDialog.tsx +1 -1
- 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/sha256.ts +9 -0
- package/src/styles.css +16 -41
- package/src/transcription-drafts.ts +124 -0
- package/src/use-recording-adoption.ts +2 -2
- package/src/voice-drafts.ts +32 -8
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +254 -950
- package/src/workspace-client.ts +21 -11
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
import { CAPTION_TIMING_MAX_SEGMENTS, captionSourceFingerprint, captionTimingProblem, stepCaptionText } from '@lincyaw/kernel'
|
|
2
|
+
import { CAPTION_TIMING_MAX_SEGMENTS, captionSourceFingerprint, captionTimingProblem, randomUUID, stepCaptionText } from '@lincyaw/kernel'
|
|
3
3
|
import type { CaptionTiming, CaptionTimingSource, DocumentCaptionTimingAction, ProductionPlan } from '@lincyaw/kernel'
|
|
4
4
|
import { PmButton, PmCard, PmDialog, PmInput, PmNotice } from '../components.tsx'
|
|
5
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
@@ -23,7 +23,7 @@ function lineRows(text: string): Row[] {
|
|
|
23
23
|
else if (ranges.length && !text.slice(ranges.at(-1)!.from, ranges.at(-1)!.to).trim()) ranges[ranges.length - 1]!.to = to
|
|
24
24
|
else ranges.push({ from, to })
|
|
25
25
|
}
|
|
26
|
-
return ranges.map(range => ({ ...range, id:
|
|
26
|
+
return ranges.map(range => ({ ...range, id: randomUUID(), start: '', end: '' }))
|
|
27
27
|
}
|
|
28
28
|
function valueOf(draft: Draft): CaptionTiming | undefined {
|
|
29
29
|
if (!draft.basis.available || !draft.basis.playbackFingerprint || draft.basis.durationMs === undefined) return
|
|
@@ -43,14 +43,17 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
43
43
|
const pendingSteps = useWorkbenchState(state => state.captionTimingDraftSteps), storageFailure = useWorkbenchState(state => state.captionTimingDraftStorageFailure)
|
|
44
44
|
const [open, setOpen] = useState(false), [busy, setBusy] = useState(false), [failure, setFailure] = useState<string>(), [saved, setSaved] = useState(false), [, render] = useState(0)
|
|
45
45
|
const drafts = useRef(new Map<string, Draft>()), alive = useRef(true), request = useRef<AbortController>(), needsRefresh = useRef(false), openRef = useRef(false), composing = useRef(false)
|
|
46
|
+
useEffect(() => workbench.production.registerDraftView({ identity, kind: 'caption-timing', has: target => drafts.current.has(target),
|
|
47
|
+
blocked: () => composing.current || Boolean(request.current), clear: target => { drafts.current.delete(target); setSaved(false); setFailure(undefined); render(n => n + 1) } }), [workbench, identity])
|
|
48
|
+
useEffect(() => workbench.refreshAuthoringClientControls(), [workbench, open, busy, stepId, disabled])
|
|
46
49
|
const latest = useRef({ stepId, onChanged }); latest.current = { stepId, onChanged }
|
|
47
|
-
if (!drafts.current.has(stepId)) { const savedDraft = workbench.captionTimingDraft(stepId, identity); if (savedDraft) drafts.current.set(stepId, savedDraft) }
|
|
50
|
+
if (!drafts.current.has(stepId)) { const savedDraft = workbench.production.captionTimingDraft(stepId, identity); if (savedDraft) drafts.current.set(stepId, savedDraft) }
|
|
48
51
|
const draft = drafts.current.get(stepId), value = draft && valueOf(draft), canonical = document?.production.captionTimings?.[stepId], hasDraft = Boolean(pendingSteps?.includes(stepId))
|
|
49
52
|
const changed = draft && source?.version !== draft.version || draft && basis && (!same(draft.basis, basis) || draft.text !== (document && stepCaptionText(document, stepId)))
|
|
50
53
|
const writable = Boolean(source?.version && source.fingerprint && !source.loading && !source.dirty && !source.saving && !source.composing && !source.restored && !source.recovering && !source.error && !disabled)
|
|
51
54
|
useEffect(() => { alive.current = true; return () => { alive.current = false; request.current?.abort() } }, [])
|
|
52
55
|
useEffect(() => { request.current?.abort(); openRef.current = false; setOpen(false); setBusy(false); setFailure(undefined); setSaved(false) }, [stepId])
|
|
53
|
-
const pending = (next: Draft, changedByAuthor = true) => { drafts.current.set(stepId, next); if (changedByAuthor) workbench.setCaptionTimingDraft(stepId, next, identity); setSaved(false); setFailure(undefined); render(n => n + 1) }
|
|
56
|
+
const pending = (next: Draft, changedByAuthor = true) => { drafts.current.set(stepId, next); if (changedByAuthor) workbench.production.setCaptionTimingDraft(stepId, next, identity); setSaved(false); setFailure(undefined); render(n => n + 1) }
|
|
54
57
|
const initialize = () => {
|
|
55
58
|
if (!document || !source?.version || !basis) return
|
|
56
59
|
const text = stepCaptionText(document, stepId), existing = document.production.captionTimings?.[stepId]
|
|
@@ -61,7 +64,7 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
61
64
|
// A plan may arrive after opening. Step/close effects fence the original opening;
|
|
62
65
|
// an existing target draft always wins over this passive initialization.
|
|
63
66
|
if (open && openRef.current && !saved && current && basis && source?.identity === identity && !drafts.current.has(stepId)) initialize()
|
|
64
|
-
}, [open, saved, current, basis, source?.identity, source?.version, identity, stepId])
|
|
67
|
+
}, [open, saved, current, basis, source?.identity, source?.version, identity, stepId, hasDraft])
|
|
65
68
|
const close = () => {
|
|
66
69
|
request.current?.abort(); setBusy(false); openRef.current = false; setOpen(false)
|
|
67
70
|
if (needsRefresh.current) { needsRefresh.current = false; latest.current.onChanged() }
|
|
@@ -72,12 +75,12 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
72
75
|
const action: DocumentCaptionTimingAction = automatic ? { type: 'caption.timing.reset', stepId } : { type: 'caption.timing.set', stepId, value: value! }
|
|
73
76
|
request.current = controller; setBusy(true); setFailure(undefined)
|
|
74
77
|
try {
|
|
75
|
-
const answer = await workbench.
|
|
78
|
+
const answer = await workbench.production.applyCaptionTiming(action, randomUUID(), expected, controller.signal)
|
|
76
79
|
needsRefresh.current = true
|
|
77
80
|
if (!alive.current || workbench.getState().authoring?.identity !== identity) return
|
|
78
81
|
const ownsInput = drafts.current.get(target) === sent
|
|
79
82
|
if (ownsInput) {
|
|
80
|
-
workbench.setCaptionTimingDraft(target, undefined, identity)
|
|
83
|
+
workbench.production.setCaptionTimingDraft(target, undefined, identity)
|
|
81
84
|
if (automatic) drafts.current.delete(target)
|
|
82
85
|
else if (sent) drafts.current.set(target, { ...sent, version: answer.version })
|
|
83
86
|
}
|
|
@@ -94,7 +97,7 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
94
97
|
<PmButton small onClick={close}>{saved ? t.done : t.cancel}</PmButton>
|
|
95
98
|
<PmButton small variant="primary" loading={busy} disabled={!writable || !current || !value || Boolean(changed) || same(value, canonical)} onClick={() => void apply()}>{t.apply}</PmButton>
|
|
96
99
|
</>}>
|
|
97
|
-
<div className="pmw-caption-times" onCompositionStart={() => { composing.current = true }} onCompositionEnd={() => { composing.current = false }}>
|
|
100
|
+
<div className="pmw-caption-times" onCompositionStart={() => { composing.current = true; workbench.refreshAuthoringClientControls() }} onCompositionEnd={() => { composing.current = false; workbench.refreshAuthoringClientControls() }}>
|
|
98
101
|
<span>{t.step}</span>
|
|
99
102
|
{!saved && basis?.available === false && <PmNotice tone="warn">{t.unavailable}</PmNotice>}
|
|
100
103
|
{!saved && !basis && <PmNotice>{loading ? t.loading : t.prepare}</PmNotice>}
|
|
@@ -111,7 +114,7 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
|
|
|
111
114
|
<div className="pmw-caption-times__actions">
|
|
112
115
|
<PmButton small disabled={!basis?.available || busy || !writable} onClick={() => { if (document && basis && source?.version) pending({ version: source.version, text: stepCaptionText(document, stepId), basis: structuredClone(basis), rows: lineRows(stepCaptionText(document, stepId)) }) }}>{t.split}</PmButton>
|
|
113
116
|
<PmButton small disabled={!canonical || busy || !writable} onClick={() => void apply(true)}>{t.automatic}</PmButton>
|
|
114
|
-
{hasDraft && <PmButton small disabled={busy} onClick={() => { workbench.
|
|
117
|
+
{hasDraft && <PmButton small disabled={busy} onClick={() => { if (workbench.production.discardCaptionTimingDraft(stepId, identity)) { drafts.current.delete(stepId); initialize() } }}>{t.discard}</PmButton>}
|
|
115
118
|
</div>
|
|
116
119
|
{storageFailure && <PmNotice tone="warn">{t.storageFailed}</PmNotice>}
|
|
117
120
|
{saved && <PmNotice tone="ok">{t.saved}</PmNotice>}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
2
|
import type { DocumentChangeAnswer, MediaClip, ProductionAssetInspection, ProductionBinding, TeachingDocument } from '@lincyaw/kernel'
|
|
3
|
+
import { randomUUID } from '@lincyaw/kernel'
|
|
3
4
|
import { MediaClipEditor } from '../MediaClipEditor.tsx'
|
|
4
5
|
import type { MediaClipDraft } from '../MediaClipEditor.tsx'
|
|
5
6
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
|
-
import {
|
|
7
|
+
import { mediaDraftStorageFailed, readMediaDrafts } from '../media-drafts.ts'
|
|
7
8
|
import type { MediaDrafts } from '../media-drafts.ts'
|
|
8
9
|
import { MEDIA_MESSAGES, mediaFailure } from '../media-messages.ts'
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ interface Props {
|
|
|
18
19
|
disabled: boolean
|
|
19
20
|
onChanged(): void
|
|
20
21
|
}
|
|
21
|
-
const newDraft = (version: string, stepId: string): MediaClipDraft => ({ version, clip: { id: `clip_${
|
|
22
|
+
const newDraft = (version: string, stepId: string): MediaClipDraft => ({ version, clip: { id: `clip_${randomUUID().replaceAll('-', '')}`, assetId: '', sourceRange: { startMs: 0, endMs: 0 }, attachment: { stepId, offsetMs: 0 }, volume: 1, muted: false } })
|
|
22
23
|
const fromClip = (version: string, clip: MediaClip): MediaClipDraft => ({ version, clip: structuredClone(clip), baseClip: structuredClone(clip) })
|
|
23
24
|
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
|
|
24
25
|
const draftKey = (clipId?: string) => clipId === undefined ? 'new' : `clip:${clipId}`
|
|
@@ -41,9 +42,23 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
41
42
|
snapshot.current = draft; selected.current = key; latest.current = session
|
|
42
43
|
const assets = Object.values(document.assets).filter(asset => asset.kind === 'audio').map(asset => ({ id: asset.id, label: asset.title || asset.location.split('/').at(-1) || asset.id }))
|
|
43
44
|
const active = () => owner.current.active && workbench.getState().authoring?.identity === identity
|
|
45
|
+
const interacting = useRef(false), unavailable = useRef(false)
|
|
46
|
+
unavailable.current = disabled || Boolean(busy)
|
|
47
|
+
useEffect(() => workbench.production.registerDraftView({ identity, kind: 'media-clip', has: target => {
|
|
48
|
+
const [ownerStep, name] = JSON.parse(target) as [string, string]
|
|
49
|
+
return active() && ownerStep === stepId && Object.hasOwn(latest.current.entries, name)
|
|
50
|
+
}, blocked: () => interacting.current || Boolean(request.current) || unavailable.current,
|
|
51
|
+
clear: () => {
|
|
52
|
+
owner.current.revision++
|
|
53
|
+
const value = readMediaDrafts(workbench.client, identity, stepId)
|
|
54
|
+
latest.current = value; setSession(value); setStorageFailed(false); setFailure(undefined); setStatus(undefined)
|
|
55
|
+
blank.current = newDraft(workbench.getState().authoring?.version ?? version, stepId)
|
|
56
|
+
} }), [workbench, identity, stepId])
|
|
57
|
+
useEffect(() => workbench.registerNavigationGuard(() => active() && (interacting.current || Boolean(request.current))), [workbench, identity])
|
|
58
|
+
useEffect(() => { workbench.refreshAuthoringClientControls() }, [workbench, disabled, busy])
|
|
44
59
|
const remember = (value: MediaDrafts) => {
|
|
45
60
|
latest.current = value; setSession(value)
|
|
46
|
-
setStorageFailed(!keepMediaDrafts(
|
|
61
|
+
setStorageFailed(!workbench.production.keepMediaDrafts(identity, stepId, value))
|
|
47
62
|
}
|
|
48
63
|
const edit = (value: MediaClipDraft) => {
|
|
49
64
|
owner.current.revision++; setFailure(undefined); setStatus(undefined)
|
|
@@ -55,7 +70,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
55
70
|
const assetId = draft.clip.assetId, controller = new AbortController(), requestKey = key
|
|
56
71
|
if (!assetId || disabled || !version || inspection?.version === version && inspection.value.assetId === assetId) { setLoading(false); return }
|
|
57
72
|
setLoading(true)
|
|
58
|
-
void workbench.
|
|
73
|
+
void workbench.production.inspectAudio(assetId, { identity, version }, controller.signal).then(answer => {
|
|
59
74
|
if (controller.signal.aborted || !active()) return
|
|
60
75
|
setInspection({ version: answer.version, value: answer.inspection })
|
|
61
76
|
const current = ownDraft(latest.current.entries, requestKey)
|
|
@@ -84,7 +99,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
84
99
|
if (!sent) return
|
|
85
100
|
file.current = value; setRetryImport(false)
|
|
86
101
|
try {
|
|
87
|
-
const answer = await workbench.
|
|
102
|
+
const answer = await workbench.production.ensureAudio(value, sent.expected, sent.controller.signal)
|
|
88
103
|
if (!active() || sent.controller.signal.aborted) return
|
|
89
104
|
const next = acknowledge(answer, sent.expected.version)
|
|
90
105
|
if (owner.current.revision === sent.revision && selected.current === sent.key) {
|
|
@@ -102,7 +117,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
102
117
|
const sent = start('apply')
|
|
103
118
|
if (!sent) return
|
|
104
119
|
try {
|
|
105
|
-
const answer = await workbench.
|
|
120
|
+
const answer = await workbench.production.applyMediaClip(clip, { ...sent.expected, binding }, sent.controller.signal)
|
|
106
121
|
if (!active() || sent.controller.signal.aborted) return
|
|
107
122
|
const next = acknowledge(answer, sent.expected.version), current = ownDraft(latest.current.entries, sent.key)
|
|
108
123
|
if (sent.key === 'new') blank.current = newDraft(answer.version, stepId)
|
|
@@ -122,7 +137,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
122
137
|
const sent = start('remove')
|
|
123
138
|
if (!sent) return
|
|
124
139
|
try {
|
|
125
|
-
const answer = await workbench.
|
|
140
|
+
const answer = await workbench.production.removeMediaClip(canonical.id, sent.expected, sent.controller.signal)
|
|
126
141
|
if (!active() || sent.controller.signal.aborted) return
|
|
127
142
|
const next = acknowledge(answer, sent.expected.version), current = ownDraft(latest.current.entries, sent.key)
|
|
128
143
|
if (!current || same(current, sent.draft)) {
|
|
@@ -137,6 +152,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
137
152
|
return <MediaClipEditor locale={locale} assets={assets} clips={clips} selectedClipId={selectedClipId} draft={draft} inspection={inspectCurrent} stepDurationMs={stepDurationMs}
|
|
138
153
|
disabled={disabled} canApply={Boolean(binding && stepDurationMs !== undefined)} loading={loading} busy={busy} pending={Boolean(ownDraft(session.entries, key))} review={Boolean(ownDraft(session.entries, key) && draft.version !== version)}
|
|
139
154
|
failure={failure} storageFailed={storageFailed} status={status} retryImport={retryImport}
|
|
155
|
+
onInteraction={value => { if (value === interacting.current) return; interacting.current = value; workbench.refreshAuthoringClientControls() }}
|
|
140
156
|
onEditStart={pause} onChange={edit} onImport={value => void importAudio(value)} onRetryImport={() => { if (file.current) void importAudio(file.current) }}
|
|
141
157
|
onRead={() => { setFailure(undefined); setInspection(undefined); setReload(value => value + 1) }}
|
|
142
158
|
onReview={() => { if (inspectCurrent && (!draft.baseClip || canonical)) edit({ ...draft, version, ...canonical ? { baseClip: structuredClone(canonical) } : {} }) }}
|
|
@@ -6,12 +6,13 @@ import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
|
6
6
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
7
7
|
import { PRODUCTION_MESSAGES, productionFailure } from '../production-messages.ts'
|
|
8
8
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
9
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
10
|
-
import type { PlaybackKey } from '../workbench.ts'
|
|
9
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
10
|
+
import type { PlaybackKey } from '../workbench-state.ts'
|
|
11
11
|
import { DocumentVoiceField } from './DocumentVoiceField.tsx'
|
|
12
12
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
13
13
|
import { PreviewPanel } from './PreviewPanel.tsx'
|
|
14
14
|
import { VoiceoverDialog } from './VoiceoverDialog.tsx'
|
|
15
|
+
import { ProductionCaptionSize } from './ProductionCaptionSize.tsx'
|
|
15
16
|
import { ProductionCaptionTiming } from './ProductionCaptionTiming.tsx'
|
|
16
17
|
import { ProductionTimeline } from './ProductionTimeline.tsx'
|
|
17
18
|
import { ProductionMediaClips } from './ProductionMediaClips.tsx'
|
|
@@ -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={document} 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,13 @@
|
|
|
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
|
-
type RecordingSource = Extract<VoiceSource, { type: 'recording' }>
|
|
12
|
-
interface RangeDraft { version: string, voice: RecordingSource, range?: TimeRange, startText?: string, endText?: string }
|
|
10
|
+
import type { RecordingRangeDraft as RangeDraft } from '../document-production.ts'
|
|
13
11
|
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
|
|
14
12
|
|
|
15
13
|
/** Video-only pending input; the existing recording transaction and source actor own every write. */
|
|
@@ -21,7 +19,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
21
19
|
const document = source?.identity === identity ? source.content : undefined
|
|
22
20
|
const effective = document?.production.stepOverrides[stepId]?.voiceSource ?? document?.production.sectionOverrides?.[sectionId]?.voiceSource ?? document?.production.defaults.voiceSource
|
|
23
21
|
const voice = effective?.type === 'recording' ? effective : undefined, key = JSON.stringify([stepId, voice?.assetId])
|
|
24
|
-
const drafts =
|
|
22
|
+
const drafts = workbench.production.recordingRangeDrafts(identity), mounted = useRef(true), request = useRef<AbortController>()
|
|
25
23
|
const [inspection, setInspection] = useState<{ version: string, value: ProductionAssetInspection }>(), [loading, setLoading] = useState(false)
|
|
26
24
|
const [busy, setBusy] = useState(false), [failure, setFailure] = useState<string>(), [reload, setReload] = useState(0), [, render] = useState(0)
|
|
27
25
|
const rangeErrorId = useId()
|
|
@@ -34,7 +32,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
34
32
|
const latest = useRef({ key, active, disabled, onChanged }); latest.current = { key, active, disabled, onChanged }
|
|
35
33
|
const current = () => mounted.current && workbench.getState().authoring?.identity === identity
|
|
36
34
|
const inspected = inspection && inspection.version === source?.version && inspection.value.assetId === voice?.assetId ? inspection.value : undefined
|
|
37
|
-
const draft = drafts.
|
|
35
|
+
const draft = drafts.get(key) ?? (voice ? { version: source?.version ?? '', voice } : undefined)
|
|
38
36
|
const range = draft?.range ?? (draft && inspected ? recordingSourceRange(draft.voice, inspected.durationMs) : undefined)
|
|
39
37
|
const start = draft ? mediaTimeValue(draft.startText, range?.startMs ?? draft.voice.sourceRange?.startMs ?? 0) : undefined
|
|
40
38
|
const end = draft ? mediaTimeValue(draft.endText, range?.endMs ?? draft.voice.sourceRange?.endMs ?? 0) : undefined
|
|
@@ -48,22 +46,26 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
48
46
|
const saved = step && (actual!.content!.production.stepOverrides[step.id]?.voiceSource ?? actual!.content!.production.sectionOverrides?.[step.sectionId]?.voiceSource ?? actual!.content!.production.defaults.voiceSource)
|
|
49
47
|
if (!value || !actual?.version || saved?.type !== 'recording' || saved.assetId !== value.request.assetId || !same(saved.sourceRange, value.request.sourceRange)
|
|
50
48
|
|| 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) }
|
|
49
|
+
const pending = drafts.get(value.key)
|
|
50
|
+
if (pending === value.draft) workbench.production.setRecordingRangeDraft(identity, value.key, undefined)
|
|
51
|
+
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) })
|
|
52
|
+
if (current()) { workbench.refreshAuthoringClientControls(); setFailure(undefined); render(value => value + 1) }
|
|
55
53
|
if (latest.current.key === value.key && latest.current.active && !latest.current.disabled && reported.current !== value.request.id) {
|
|
56
54
|
reported.current = value.request.id; latest.current.onChanged()
|
|
57
55
|
}
|
|
58
56
|
return true
|
|
59
57
|
}
|
|
58
|
+
useEffect(() => workbench.registerNavigationGuard(() => current() && (composing.current || Boolean(request.current))), [workbench, identity])
|
|
59
|
+
useEffect(() => workbench.production.registerDraftView({ identity, kind: 'recording-range', has: target => current() && target === latest.current.key,
|
|
60
|
+
blocked: () => composing.current || Boolean(request.current), clear: () => { setFailure(undefined); render(value => value + 1) } }), [workbench, identity])
|
|
61
|
+
useEffect(() => { workbench.refreshAuthoringClientControls() }, [workbench, busy, key, active])
|
|
60
62
|
useEffect(() => () => { mounted.current = false; request.current?.abort() }, [])
|
|
61
63
|
useEffect(() => { request.current?.abort(); request.current = undefined; setBusy(false); setFailure(undefined) }, [key, active])
|
|
62
64
|
useEffect(() => {
|
|
63
65
|
const version = source?.version, assetId = voice?.assetId, controller = new AbortController()
|
|
64
66
|
if (!active || !version || !assetId || disabled) { setLoading(false); return }
|
|
65
67
|
setLoading(true)
|
|
66
|
-
void workbench.
|
|
68
|
+
void workbench.production.inspectAudio(assetId, { identity, version }, controller.signal).then(answer => {
|
|
67
69
|
if (!controller.signal.aborted && current() && latest.current.key === key) setInspection({ version: answer.version, value: answer.inspection })
|
|
68
70
|
}, error => { if (!controller.signal.aborted && current() && latest.current.key === key) setFailure(failureText(error)) })
|
|
69
71
|
.finally(() => { if (!controller.signal.aborted && current() && latest.current.key === key) setLoading(false) })
|
|
@@ -72,7 +74,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
72
74
|
useEffect(() => { settle() }, [source?.version, source?.content, source?.loading, source?.dirty, source?.saving, source?.composing, source?.restored, source?.error, active, disabled, key])
|
|
73
75
|
const edit = (patch: Partial<RangeDraft>) => {
|
|
74
76
|
if (!draft) return
|
|
75
|
-
|
|
77
|
+
workbench.production.setRecordingRangeDraft(identity, key, { ...draft, ...range ? { range: { ...range } } : {}, ...patch }); workbench.refreshAuthoringClientControls(); setFailure(undefined); render(value => value + 1)
|
|
76
78
|
}
|
|
77
79
|
const apply = async () => {
|
|
78
80
|
if (!voice || !draft || !inspected || !valid || !changed || busy || disabled || !active || composing.current || !current()) return
|
|
@@ -81,11 +83,11 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
81
83
|
const controller = new AbortController(), proposed = { startMs: start!, endMs: end! }
|
|
82
84
|
const previous = sent.current?.request
|
|
83
85
|
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
|
-
|
|
86
|
+
? previous : { id: randomUUID(), source: { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, stepId, assetId: voice.assetId, sha256: inspected.sha256, sourceRange: proposed }
|
|
87
|
+
const stored = drafts.get(key) ?? draft
|
|
88
|
+
workbench.production.setRecordingRangeDraft(identity, key, stored); sent.current = { key, draft: stored, request: change }; request.current = controller
|
|
87
89
|
setBusy(true); setFailure(undefined)
|
|
88
|
-
try { await workbench.
|
|
90
|
+
try { await workbench.production.adoptRecording(change, { identity, version: source.version }, controller.signal); if (current()) settle() }
|
|
89
91
|
catch (error) { if (current() && request.current === controller && !settle() && !controller.signal.aborted) setFailure(failureText(error)) }
|
|
90
92
|
finally { if (request.current === controller) { request.current = undefined; if (current()) setBusy(false) } }
|
|
91
93
|
}
|
|
@@ -95,7 +97,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
95
97
|
const trimmed = Boolean(canonicalRange && inspected && (canonicalRange.startMs > 0 || canonicalRange.endMs < inspected.durationMs))
|
|
96
98
|
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
99
|
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 }}
|
|
100
|
+
onCompositionStart={() => { composing.current = true; workbench.refreshAuthoringClientControls() }} onCompositionEnd={() => { composing.current = false; workbench.refreshAuthoringClientControls() }}
|
|
99
101
|
onKeyDown={event => { event.stopPropagation(); if (event.key === 'Enter' && event.target instanceof HTMLInputElement && !event.nativeEvent.isComposing && !composing.current) { event.preventDefault(); void apply() } }}>
|
|
100
102
|
<strong>{r.trim}</strong>
|
|
101
103
|
<span>{document?.assets[voice.assetId]?.title || r.title}</span>
|
|
@@ -113,6 +115,6 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
113
115
|
{review && <PmNotice tone="warn">{t.review}<PmButton small disabled={disabled || !inspected || busy} onClick={() => edit({ version: source!.version!, voice: structuredClone(voice) })}>{t.check}</PmButton></PmNotice>}
|
|
114
116
|
{trimmed && hasCaptions && <PmNotice tone="warn">{r.captionReview}</PmNotice>}
|
|
115
117
|
{failure && <PmNotice tone="danger">{failure}<PmButton small disabled={disabled || busy} onClick={() => { setInspection(undefined); setFailure(undefined); setReload(value => value + 1) }}>{t.retry}</PmButton></PmNotice>}
|
|
116
|
-
{drafts.
|
|
118
|
+
{drafts.has(key) && <span className="pm-ui-field__hint" role="status">{t.pending}</span>}
|
|
117
119
|
</section>
|
|
118
120
|
}
|
|
@@ -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,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
2
2
|
import type { DocumentTranscriptionRequest, TeachingDocument, 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'
|
|
@@ -81,7 +82,7 @@ export function ProductionTranscription({ identity, directory, document, section
|
|
|
81
82
|
const controller = new AbortController(); importRequest.current = controller; setImporting(true); setFailure(undefined)
|
|
82
83
|
pendingFile.current = value
|
|
83
84
|
try {
|
|
84
|
-
const answer = await workbench.
|
|
85
|
+
const answer = await workbench.production.ensureAudio(value, { identity, version: now.version }, controller.signal)
|
|
85
86
|
if (current() && !controller.signal.aborted) { setAssetId(answer.inspection.assetId); pendingFile.current = undefined }
|
|
86
87
|
} catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
|
|
87
88
|
finally { if (importRequest.current === controller) { importRequest.current = undefined; if (current()) setImporting(false) } }
|
|
@@ -92,10 +93,10 @@ export function ProductionTranscription({ identity, directory, document, section
|
|
|
92
93
|
const controller = new AbortController(); inspectionRequest.current = controller; setInspecting(true)
|
|
93
94
|
setFailure(undefined)
|
|
94
95
|
try {
|
|
95
|
-
const expected = { identity, version: now.version }, audio = await workbench.
|
|
96
|
+
const expected = { identity, version: now.version }, audio = await workbench.production.inspectAudio(assetId, expected, controller.signal)
|
|
96
97
|
if (!current() || controller.signal.aborted) return
|
|
97
|
-
const request: DocumentTranscriptionRequest = { intent: `transcription_${
|
|
98
|
-
await session.start(request, () => workbench.
|
|
98
|
+
const request: DocumentTranscriptionRequest = { intent: `transcription_${randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: now.content.metadata.lang, confirmed: true }
|
|
99
|
+
await session.start(request, () => workbench.production.startTranscription(request, expected))
|
|
99
100
|
} catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
|
|
100
101
|
finally { if (inspectionRequest.current === controller) { inspectionRequest.current = undefined; if (current()) setInspecting(false) } }
|
|
101
102
|
}
|