@lincyaw/workbench 0.2.0-rc.5 → 0.2.0-rc.50
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 +1 -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/body-draft-actions.ts +60 -0
- package/src/component-property-drafts.ts +5 -5
- package/src/components.tsx +10 -28
- package/src/context.tsx +2 -1
- 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 +58 -9
- package/src/document-editor/DocumentEditor.tsx +44 -7
- package/src/document-editor/DocumentStepNarration.tsx +30 -25
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +4 -3
- package/src/document-editor/PlaceComment.tsx +150 -0
- package/src/document-editor/comment-drafts.ts +16 -14
- 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 +331 -0
- package/src/document-session.ts +190 -51
- package/src/history.ts +3 -3
- package/src/index.ts +5 -5
- package/src/jobs.ts +1 -1
- package/src/messages.ts +19 -4
- package/src/panels/DocumentView.tsx +66 -26
- package/src/panels/DocumentVoiceDialog.tsx +2 -2
- 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 +7 -7
- package/src/panels/ProductionMediaClips.tsx +6 -5
- package/src/panels/ProductionPanel.tsx +8 -4
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +4 -4
- 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 +9 -8
- 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-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/use-recording-adoption.ts +2 -2
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +177 -943
- package/src/workspace-client.ts +6 -5
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState } from 'react'
|
|
2
|
-
import { recordingSourceRange } from '@lincyaw/kernel'
|
|
2
|
+
import { randomUUID, recordingSourceRange } from '@lincyaw/kernel'
|
|
3
3
|
import type { DocumentRecordingAdoption, ProductionAssetInspection, TimeRange, VoiceSource } from '@lincyaw/kernel'
|
|
4
4
|
import { PmButton, PmInput, PmNotice } from '../components.tsx'
|
|
5
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
@@ -63,7 +63,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
63
63
|
const version = source?.version, assetId = voice?.assetId, controller = new AbortController()
|
|
64
64
|
if (!active || !version || !assetId || disabled) { setLoading(false); return }
|
|
65
65
|
setLoading(true)
|
|
66
|
-
void workbench.
|
|
66
|
+
void workbench.production.inspectAudio(assetId, { identity, version }, controller.signal).then(answer => {
|
|
67
67
|
if (!controller.signal.aborted && current() && latest.current.key === key) setInspection({ version: answer.version, value: answer.inspection })
|
|
68
68
|
}, error => { if (!controller.signal.aborted && current() && latest.current.key === key) setFailure(failureText(error)) })
|
|
69
69
|
.finally(() => { if (!controller.signal.aborted && current() && latest.current.key === key) setLoading(false) })
|
|
@@ -81,11 +81,11 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
|
|
|
81
81
|
const controller = new AbortController(), proposed = { startMs: start!, endMs: end! }
|
|
82
82
|
const previous = sent.current?.request
|
|
83
83
|
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:
|
|
84
|
+
? previous : { id: randomUUID(), source: { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, stepId, assetId: voice.assetId, sha256: inspected.sha256, sourceRange: proposed }
|
|
85
85
|
const stored = drafts.current.get(key) ?? draft
|
|
86
86
|
drafts.current.set(key, stored); sent.current = { key, draft: stored, request: change }; request.current = controller
|
|
87
87
|
setBusy(true); setFailure(undefined)
|
|
88
|
-
try { await workbench.
|
|
88
|
+
try { await workbench.production.adoptRecording(change, { identity, version: source.version }, controller.signal); if (current()) settle() }
|
|
89
89
|
catch (error) { if (current() && request.current === controller && !settle() && !controller.signal.aborted) setFailure(failureText(error)) }
|
|
90
90
|
finally { if (request.current === controller) { request.current = undefined; if (current()) setBusy(false) } }
|
|
91
91
|
}
|
|
@@ -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
|
}
|
|
@@ -9,11 +9,10 @@ import { DocumentBlockPreview } from '../document-editor/DocumentBlockPreview.ts
|
|
|
9
9
|
import { nativeEditingCursor } from '../document-editor/selection.ts'
|
|
10
10
|
import { hasBlockPreview } from '../document-editor/projection.ts'
|
|
11
11
|
import type { NativeDocumentEditor } from '../document-editor/schema.tsx'
|
|
12
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
13
|
-
import { EditorChangeTrail } from './ChangeTrail.tsx'
|
|
12
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
14
13
|
|
|
15
14
|
/** Source editing is available before the first successful runtime compilation. */
|
|
16
|
-
export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void }) {
|
|
15
|
+
export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
|
|
17
16
|
const workbench = useWorkbench(), t = useMessages()
|
|
18
17
|
const source = useWorkbenchState(state => state.authoring)
|
|
19
18
|
const sourceAcknowledged = () => {
|
|
@@ -26,7 +25,6 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
26
25
|
const navigation = useWorkbenchState(state => state.documentNavigation)
|
|
27
26
|
const readOnly = useWorkbenchState(state => state.mode !== 'editing' || workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.member && !hasRole(state.authoring.member, 'editor')) || Boolean(state.authoring?.loading) || isAgentChanging(state))
|
|
28
27
|
const container = useRef<HTMLElement>(null)
|
|
29
|
-
const sheet = useRef<HTMLDivElement>(null)
|
|
30
28
|
const consumedNavigation = useRef<string>()
|
|
31
29
|
const bodyEditor = useRef<NativeDocumentEditor>()
|
|
32
30
|
const editingPosition = useRef<{ nativeBlockId: string, sectionId: string, position: number, editor: NativeDocumentEditor, identity: string, reset: number | undefined }>()
|
|
@@ -39,10 +37,10 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
39
37
|
const recoveryDisabled = readOnly || source?.saving || source?.composing || source?.recovering
|
|
40
38
|
useEffect(() => {
|
|
41
39
|
const element = container.current
|
|
42
|
-
if (element && source?.identity && source.content) return workbench.
|
|
40
|
+
if (element && source?.identity && source.content) return workbench.editing.attachViewport(element, source.identity)
|
|
43
41
|
}, [workbench, source?.identity, Boolean(source?.content)])
|
|
44
42
|
// The editor applies `readOnly` while committing, so it is editable by the time this runs.
|
|
45
|
-
useEffect(() => { if (!readOnly) workbench.
|
|
43
|
+
useEffect(() => { if (!readOnly) workbench.editing.editorEditable() }, [workbench, readOnly])
|
|
46
44
|
useEffect(() => {
|
|
47
45
|
if (!navigation) return
|
|
48
46
|
const request = JSON.stringify([source?.identity, navigation.request])
|
|
@@ -71,7 +69,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
71
69
|
const viewport = measure(), state = workbench.getState()
|
|
72
70
|
if (gesture.generation !== state.documentPositionToken || !sameGeometry(gesture.viewport, viewport) || gesture.viewport.top !== viewport.top) return
|
|
73
71
|
if (!state.authoring?.loading && !isAgentChanging(state)) {
|
|
74
|
-
const field = workbench.
|
|
72
|
+
const field = workbench.editing.focusedField(), root = field?.editor.prosemirrorView.dom.getRootNode()
|
|
75
73
|
if (field && root instanceof ShadowRoot && element.contains(root.host)) {
|
|
76
74
|
try {
|
|
77
75
|
const point = field.editor.prosemirrorView.coordsAtPos(field.editor.prosemirrorState.selection.head), bounds = element.getBoundingClientRect()
|
|
@@ -115,17 +113,17 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
115
113
|
const scroll = (event: Event) => {
|
|
116
114
|
const viewport = measure(), previous = baseline
|
|
117
115
|
baseline = viewport
|
|
118
|
-
if (workbench.
|
|
116
|
+
if (workbench.editing.consumeReturnScroll(element)) { cancel(); return }
|
|
119
117
|
// Native scroll chaining from an iframe has no parent wheel event.
|
|
120
118
|
if (!event.isTrusted) return
|
|
121
119
|
if (!sameGeometry(previous, viewport)) { cancel(); return }
|
|
122
120
|
if (viewport.top === previous.top) return
|
|
123
|
-
workbench.
|
|
121
|
+
workbench.editing.interact()
|
|
124
122
|
queue(viewport)
|
|
125
123
|
}
|
|
126
124
|
const interact = (event: Event) => {
|
|
127
125
|
if (!event.isTrusted) return
|
|
128
|
-
workbench.
|
|
126
|
+
workbench.editing.interact()
|
|
129
127
|
baseline = measure()
|
|
130
128
|
queue(baseline)
|
|
131
129
|
}
|
|
@@ -136,7 +134,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
136
134
|
if (['Home', 'End'].includes(event.key) && target instanceof HTMLElement && target.isContentEditable && !event.ctrlKey && !event.metaKey) return
|
|
137
135
|
interact(event)
|
|
138
136
|
}
|
|
139
|
-
const pointer = () => { cancel(); workbench.
|
|
137
|
+
const pointer = () => { cancel(); workbench.editing.interact() }
|
|
140
138
|
element.addEventListener('scroll', scroll, { passive: true })
|
|
141
139
|
element.addEventListener('wheel', interact, { passive: true })
|
|
142
140
|
element.addEventListener('touchmove', interact, { passive: true })
|
|
@@ -176,9 +174,8 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
176
174
|
{source?.issues.length ? <div className="pmw-source-document__diagnostics"><PmNotice tone="warn"><details><summary>{messages.diagnostics(source.issues.length)}</summary><ul>{source.issues.map((issue, index) => <li key={`${issue.path}:${index}`}><code>{issue.path}</code> {issue.message}</li>)}</ul></details></PmNotice></div> : null}
|
|
177
175
|
{!source?.content || !source.identity ? source?.loading
|
|
178
176
|
? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
|
|
179
|
-
: <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div
|
|
180
|
-
<
|
|
181
|
-
<DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
|
|
177
|
+
: <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div className="pmw-source-document__sheet">
|
|
178
|
+
<DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
|
|
182
179
|
getDocumentVersion={() => { const current = workbench.getState().authoring; return current && current.identity === source.identity && current.reset === source.reset ? current.version : undefined }} reset={source.reset} locale={locale} readOnly={readOnly}
|
|
183
180
|
uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
|
|
184
181
|
getPositionToken={() => workbench.getState().documentPositionToken}
|
|
@@ -200,7 +197,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
200
197
|
commentsPortal={commentsPortal} onChange={document => workbench.recordDocument(document)} onReady={(editor, commands) => {
|
|
201
198
|
bodyEditor.current = editor
|
|
202
199
|
editingPosition.current = undefined
|
|
203
|
-
workbench.
|
|
200
|
+
workbench.editing.attachEditor(editor, commands, { identity: source.identity!, reset: source.reset })
|
|
204
201
|
}}
|
|
205
202
|
onEditingPosition={(position, editor) => {
|
|
206
203
|
const state = workbench.getState(), current = state.authoring
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import { prepareTranscriptionAdoption } from '@lincyaw/kernel'
|
|
2
|
+
import { prepareTranscriptionAdoption, randomUUID } from '@lincyaw/kernel'
|
|
3
3
|
import type { CanonicalSource, NarrationNode, TeachingDocument, TranscriptionRevision, TranscriptionAdoptionDraft, TranscriptionAdoptionPart, TranscriptionAdoptionPlan } from '@lincyaw/kernel'
|
|
4
4
|
import { PmBadge, PmButton, PmDialog, PmField, PmNotice, PmSelect, PmTextarea } from '../components.tsx'
|
|
5
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
6
|
import { NarrationEditor } from '../document-editor/NarrationEditor.tsx'
|
|
7
|
-
import { narrationToNative } from '../document-editor/narration.ts'
|
|
7
|
+
import { narrationToNative, nativeToNarration } from '../document-editor/narration.ts'
|
|
8
8
|
import type { NativeNarrationEditor } from '../document-editor/narration-schema.tsx'
|
|
9
9
|
import { TRANSCRIPTION_MESSAGES } from '../transcription-messages.ts'
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ const ordered = (value: unknown): unknown => Array.isArray(value) ? value.map(or
|
|
|
14
14
|
const same = (a: unknown, b: unknown) => JSON.stringify(ordered(a)) === JSON.stringify(ordered(b))
|
|
15
15
|
const displayed = (nodes: readonly NarrationNode[]) => nodes.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
|
|
16
16
|
function restore(key: string): { draft: Draft, failed: boolean } {
|
|
17
|
-
const fallback = () => ({ draft: { id:
|
|
17
|
+
const fallback = () => ({ draft: { id: randomUUID(), revision: 0, discarded: [], shared: 'fork' as const }, failed: false })
|
|
18
18
|
try {
|
|
19
19
|
const raw = localStorage.getItem(key)
|
|
20
20
|
if (!raw) return fallback()
|
|
@@ -83,7 +83,7 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
|
|
|
83
83
|
const now = workbench.getState().authoring
|
|
84
84
|
if (disabled || reviewing || applying || composing || !sourceReady || !now?.version || !now.fingerprint || parsed.invalid) return
|
|
85
85
|
pause()
|
|
86
|
-
if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id:
|
|
86
|
+
if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id: randomUUID(), baseVersion: now.version })
|
|
87
87
|
else if (!latest.current.baseVersion) change({ baseVersion: now.version })
|
|
88
88
|
const value = latest.current, request = ++generation.current, normalized = content()
|
|
89
89
|
const retainsOriginal = references.length > 1 && value.shared === 'fork'
|
|
@@ -91,7 +91,7 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
|
|
|
91
91
|
const sent: TranscriptionAdoptionDraft = { id: value.id, source: { documentId: document.id, version: now.version, fingerprint: now.fingerprint }, candidate: { id: candidate.transcriptionId, revision: candidate.revision }, draftRevision: value.revision, targets: [{ ...target, content: normalized.parts, discardAtoms: value.discarded.filter(key => atoms.some(atom => atom.key === key)) }], ...removeCueTimings.length ? { removeCueTimings } : {} }
|
|
92
92
|
setReviewing(true); setFailure(undefined)
|
|
93
93
|
try {
|
|
94
|
-
const answer = await workbench.
|
|
94
|
+
const answer = await workbench.production.planTranscription(sent, { identity, version: now.version })
|
|
95
95
|
if (request !== generation.current || latest.current.revision !== sent.draftRevision) return
|
|
96
96
|
setPlan(answer); setOpen(true)
|
|
97
97
|
} catch { if (request === generation.current) setFailure(t.previewFailed) }
|
|
@@ -102,9 +102,9 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
|
|
|
102
102
|
const sent = plan, planId = plan.planId
|
|
103
103
|
setApplying(true); setFailure(undefined)
|
|
104
104
|
try {
|
|
105
|
-
const answer = await workbench.
|
|
105
|
+
const answer = await workbench.production.adoptTranscription({ planId, source: sent.source, candidate: sent.candidate, draftRevision: sent.draftRevision }, { identity, version: sent.source.version })
|
|
106
106
|
if (latest.current.id === sent.changeId && latest.current.revision === sent.draftRevision) {
|
|
107
|
-
const next: Draft = { ...latest.current, id:
|
|
107
|
+
const next: Draft = { ...latest.current, id: randomUUID(), revision: 0, discarded: [], baseVersion: answer.version, applied: true }
|
|
108
108
|
latest.current = next; setDraft(next)
|
|
109
109
|
try { localStorage.setItem(key, JSON.stringify(next)); setStorageFailed(false) } catch { setStorageFailed(true) }
|
|
110
110
|
}
|
|
@@ -114,7 +114,8 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
|
|
|
114
114
|
}
|
|
115
115
|
if (!displayed(nodes).trim() && !atoms.length) return <span>{t.empty}</span>
|
|
116
116
|
return <>
|
|
117
|
-
<PmField label={t.text} group><NarrationEditor identity={key}
|
|
117
|
+
<PmField label={t.text} group><NarrationEditor identity={key} fieldId={original?.outputNarrationId ?? draft.id} content={nodes} getContent={() => latest.current.nodes ?? nodes} locale={locale} advanced={false} readOnly={disabled || applying}
|
|
118
|
+
toNative={value => narrationToNative(original?.outputNarrationId ?? draft.id, value)} fromNative={nativeToNarration}
|
|
118
119
|
onReady={value => { editor.current = value }} onComposition={setComposing} onFocus={pause} onChange={value => {
|
|
119
120
|
const used = new Set<string>()
|
|
120
121
|
for (const node of value) { const atom = atoms.find(atom => !used.has(atom.key) && same(atom.node, node)); if (atom) used.add(atom.key) }
|
|
@@ -40,9 +40,10 @@ function RecordingSlot({ label, hint, value, disabled, onChange }: { label: stri
|
|
|
40
40
|
const capturing = ['requesting', 'recording', 'stopping'].includes(state.phase)
|
|
41
41
|
const start = () => {
|
|
42
42
|
setFailure(undefined)
|
|
43
|
-
void recording.start(async
|
|
43
|
+
void recording.start(async signal => {
|
|
44
44
|
workbench.stopAuditions()
|
|
45
45
|
await workbench.pausePlayback()
|
|
46
|
+
signal.throwIfAborted()
|
|
46
47
|
return workbench.registerAudioCapture(() => recording.stop())
|
|
47
48
|
})
|
|
48
49
|
}
|
|
@@ -8,7 +8,7 @@ import type { DocumentVoiceScope } from '../document-voices.ts'
|
|
|
8
8
|
import { VOICE_MESSAGES, voiceFailure } from '../voice-messages.ts'
|
|
9
9
|
import { prepareVoiceSnapshot, runtimeVoiceScope, voiceSnapshotCurrent } from '../voice-snapshot.ts'
|
|
10
10
|
import type { VoiceSnapshot } from '../voice-snapshot.ts'
|
|
11
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
11
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
12
12
|
import { VoiceScopeField } from './VoiceScopeField.tsx'
|
|
13
13
|
|
|
14
14
|
interface CheckedVoice { snapshot: VoiceSnapshot, document: TeachingDocument }
|
package/src/places.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { irBlocks } from '@lincyaw/kernel'
|
|
2
|
-
import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos
|
|
2
|
+
import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos } from '@lincyaw/kernel'
|
|
3
3
|
|
|
4
4
|
const CHANGED_PLACES = 100
|
|
5
5
|
|
|
@@ -65,38 +65,3 @@ export function changedPlaces(doc: IRDocument, changes: readonly ReviewChange[])
|
|
|
65
65
|
}
|
|
66
66
|
return [...places.values()].slice(0, CHANGED_PLACES)
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The places that differ between two versions of a document: each block whose content changed or that is new (with
|
|
71
|
-
* its page), each page whose title changed or that is new, and the block of each step whose narration or settings
|
|
72
|
-
* changed, at most CHANGED_PLACES.
|
|
73
|
-
*/
|
|
74
|
-
export function changedBlocks(before: TeachingDocument, after: TeachingDocument): PreviewAnchor[] {
|
|
75
|
-
const places: PreviewAnchor[] = []
|
|
76
|
-
const visit = (section: string, ids: readonly string[]) => {
|
|
77
|
-
for (const id of ids) {
|
|
78
|
-
const block = after.blocks[id]
|
|
79
|
-
if (!block) continue
|
|
80
|
-
if (JSON.stringify(block) !== JSON.stringify(before.blocks[id])) places.push({ section, block: id })
|
|
81
|
-
if ('children' in block && Array.isArray(block.children)) visit(section, block.children as string[])
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (const id of after.sectionOrder) {
|
|
85
|
-
const section = after.sections[id]
|
|
86
|
-
if (!section) continue
|
|
87
|
-
if (before.sections[id]?.title !== section.title) places.push({ section: id })
|
|
88
|
-
visit(id, section.children)
|
|
89
|
-
}
|
|
90
|
-
// A changed step, or a changed narration of it, shows at the block the step plays (else at its page).
|
|
91
|
-
const seen = new Set(places.map(place => `${place.section}\0${place.block ?? ''}`))
|
|
92
|
-
for (const step of Object.values(after.steps)) {
|
|
93
|
-
const narrated = step.narrationIds.some(id => JSON.stringify(after.narrations[id]) !== JSON.stringify(before.narrations[id]))
|
|
94
|
-
if (!narrated && JSON.stringify(step) === JSON.stringify(before.steps[step.id])) continue
|
|
95
|
-
// the component the step plays, where its narration shows, else any block it shows
|
|
96
|
-
const block = step.visuals.find(visual => after.blocks[visual.blockId]?.type === 'component')?.blockId ?? step.visuals.find(visual => visual.visible)?.blockId ?? step.visuals[0]?.blockId
|
|
97
|
-
const place = { section: step.sectionId, ...block ? { block } : {} }
|
|
98
|
-
const key = `${place.section}\0${place.block ?? ''}`
|
|
99
|
-
if (!seen.has(key)) { seen.add(key); places.push(place) }
|
|
100
|
-
}
|
|
101
|
-
return places.slice(0, CHANGED_PLACES)
|
|
102
|
-
}
|
package/src/preview-playback.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PreviewReport } from '@lincyaw/kernel'
|
|
2
|
-
import type { PreviewSink } from './workbench.ts'
|
|
2
|
+
import type { PreviewSink } from './workbench-state.ts'
|
|
3
3
|
|
|
4
4
|
interface PlaybackContext { document?: string, scope: number, sinks: ReadonlySet<PreviewSink> }
|
|
5
5
|
interface PendingPause {
|
|
@@ -57,6 +57,9 @@ const zh = {
|
|
|
57
57
|
alignmentStatus: { manual: '手动时间', words: '词时码', proportional: '比例估时', none: '未对齐' },
|
|
58
58
|
segmentStatus: { recorded: '原音频', cached: '已有配音', silent: '静音', missing: '配音待生成', blocked: '暂不可用' },
|
|
59
59
|
waveformLoading: '正在加载波形…', waveformUnavailable: '波形不可用', stepNumber: (index: number) => `步骤 ${index + 1}`,
|
|
60
|
+
notInLecture: '不在讲授中', notInLectureHint: '这一页的内容都限定在其他形态,又没有讲稿与音频,讲授视频中没有这一页。',
|
|
61
|
+
notInLectureStep: '这一步不在讲授中:它的内容都限定在其他形态,又没有讲稿与音频。',
|
|
62
|
+
captionSize: '字幕大小', captionSizeHint: '整个文稿的字幕:放映中显示的与导出视频中烧录的都按这个大小。',
|
|
60
63
|
timelineLabels: { position: '位置', seconds: '秒', seek: '播放头位置', zoomIn: '放大时间线', zoomOut: '缩小时间线', fit: '适配本页', estimated: '估计时长', unknown: '时长未知', loading: '正在加载时间线…', empty: '当前页暂无时间线片段', seekHint: '选择步骤,或用时间尺、方向键和精确时间定位;定位会先暂停播放。', invalidPosition: '请输入本页时长范围内的秒数。' },
|
|
61
64
|
failures: {
|
|
62
65
|
'production-source-changed': '文稿已更新,旧播放请求已停止。请重新准备当前版本。',
|
|
@@ -129,6 +132,9 @@ export const PRODUCTION_MESSAGES: Record<Locale, typeof zh> = {
|
|
|
129
132
|
alignmentStatus: { manual: 'Manual timing', words: 'Word timing', proportional: 'Proportional timing', none: 'Unaligned' },
|
|
130
133
|
segmentStatus: { recorded: 'Original audio', cached: 'Voiceover cached', silent: 'Silent', missing: 'Voiceover needed', blocked: 'Unavailable' },
|
|
131
134
|
waveformLoading: 'Loading waveform…', waveformUnavailable: 'Waveform unavailable', stepNumber: index => `Step ${index + 1}`,
|
|
135
|
+
notInLecture: 'Not in the lecture', notInLectureHint: 'Everything on this page is limited to other forms and it has no script or audio, so the lecture video leaves it out.',
|
|
136
|
+
notInLectureStep: 'This step is not in the lecture: everything on it is limited to other forms and it has no script or audio.',
|
|
137
|
+
captionSize: 'Caption size', captionSizeHint: 'For the whole document: captions shown in the presentation and burned into an exported video use this size.',
|
|
132
138
|
timelineLabels: { position: 'Position', seconds: 'seconds', seek: 'Playhead position', zoomIn: 'Zoom In Timeline', zoomOut: 'Zoom Out Timeline', fit: 'Fit Page', estimated: 'Estimated duration', unknown: 'Unknown duration', loading: 'Loading the timeline…', empty: 'This page has no timeline segments', seekHint: 'Select a step, or use the ruler, arrow keys, or an exact time to seek. Seeking pauses playback first.', invalidPosition: 'Enter a time in seconds within this page’s duration.' },
|
|
133
139
|
failures: {
|
|
134
140
|
'production-source-changed': 'The document changed and the old playback request stopped. Prepare the current version.',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PreviewReport, ProductionBinding, ProductionPlaybackCommand, ProductionPlaybackState } from '@lincyaw/kernel'
|
|
2
2
|
import { sameProductionBinding } from '@lincyaw/kernel'
|
|
3
|
-
import type { PreviewSink } from './workbench.ts'
|
|
3
|
+
import type { PreviewSink } from './workbench-state.ts'
|
|
4
4
|
|
|
5
5
|
interface Context {
|
|
6
6
|
document?: string
|
|
@@ -4,8 +4,9 @@ import type { ProductionPlan, ProductionPlaybackPosition, VoiceoverJob } from '@
|
|
|
4
4
|
import { useWorkbench, useWorkbenchState } from './context.tsx'
|
|
5
5
|
import { prepareVoiceSnapshot, voiceSnapshotCurrent } from './voice-snapshot.ts'
|
|
6
6
|
import { voiceFailure } from './voice-messages.ts'
|
|
7
|
-
import type { Workbench
|
|
8
|
-
import {
|
|
7
|
+
import type { Workbench } from './workbench.ts'
|
|
8
|
+
import type { WorkbenchState } from './workbench-state.ts'
|
|
9
|
+
import { isAgentChanging } from './workbench-state.ts'
|
|
9
10
|
|
|
10
11
|
const running = (job: VoiceoverJob) => ['queued', 'running', 'cancelling'].includes(job.state)
|
|
11
12
|
|
package/src/sha256.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { sha256 as hash } from '@noble/hashes/sha2.js'
|
|
2
|
+
import { bytesToHex } from '@noble/hashes/utils.js'
|
|
3
|
+
|
|
4
|
+
/** The same SHA-256 fingerprint on HTTPS, localhost and LAN HTTP. */
|
|
5
|
+
export async function sha256(value: string | ArrayBuffer): Promise<string> {
|
|
6
|
+
const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : new Uint8Array(value)
|
|
7
|
+
const subtle = globalThis.crypto?.subtle
|
|
8
|
+
return bytesToHex(subtle ? new Uint8Array(await subtle.digest('SHA-256', bytes)) : hash(bytes))
|
|
9
|
+
}
|