@lincyaw/workbench 0.2.0-rc.1 → 0.2.0-rc.100
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/AgentActivityBar.tsx +25 -0
- package/src/MediaClipEditor.tsx +4 -3
- package/src/StepProductionEditor.tsx +13 -4
- package/src/agent-activity-messages.ts +14 -0
- package/src/agent-activity.ts +38 -0
- package/src/approvals.tsx +6 -1
- package/src/audio-recording.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 +34 -36
- package/src/container-layout.ts +21 -0
- package/src/context.tsx +5 -3
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +28 -19
- package/src/document-editing.ts +484 -0
- package/src/document-editor/BlockNoteSurface.tsx +25 -9
- package/src/document-editor/CommentComposer.tsx +24 -0
- package/src/document-editor/ComponentMaterials.tsx +3 -9
- package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
- package/src/document-editor/DocumentBlockPreview.tsx +11 -4
- package/src/document-editor/DocumentComments.tsx +85 -14
- package/src/document-editor/DocumentEditor.tsx +56 -7
- package/src/document-editor/DocumentStepNarration.tsx +37 -26
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +120 -37
- package/src/document-editor/PlaceComment.tsx +252 -0
- package/src/document-editor/agent-targets.ts +34 -0
- package/src/document-editor/blocknote-messages.ts +2 -0
- package/src/document-editor/comment-draft-actions.ts +40 -20
- package/src/document-editor/comment-draft-inspection.ts +2 -2
- package/src/document-editor/comment-drafts.ts +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/popover.tsx +4 -2
- 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 +7 -1
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-production.ts +491 -0
- package/src/document-session.ts +202 -56
- package/src/document-timing-drafts.ts +22 -2
- package/src/history.ts +5 -5
- package/src/index.ts +8 -5
- package/src/jobs.ts +1 -1
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +31 -14
- package/src/panels/DocumentNarrationPanel.tsx +2 -2
- package/src/panels/DocumentView.tsx +93 -61
- package/src/panels/DocumentVoiceDialog.tsx +25 -9
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/ExportPanel.tsx +2 -10
- package/src/panels/HistoryPanel.tsx +34 -7
- package/src/panels/HomePanel.tsx +3 -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 +16 -13
- 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 +18 -36
- 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 +43 -79
- 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 +159 -0
- package/src/workbench.ts +294 -951
- package/src/workspace-client.ts +23 -11
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -4,14 +4,14 @@ import { PmButton, PmDialog, PmField, PmInput, PmNotice, PmSearchList, PmSegment
|
|
|
4
4
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
5
|
import { documentVoiceStepIds, previewDocumentVoiceChange, resolveDocumentStepVoice } from '../document-voices.ts'
|
|
6
6
|
import type { DocumentVoiceImpact } from '../document-voices.ts'
|
|
7
|
-
import {
|
|
7
|
+
import { readVoiceDraft, voiceDraftStorageStatus } from '../voice-drafts.ts'
|
|
8
8
|
import type { VoiceDraft } from '../voice-drafts.ts'
|
|
9
9
|
import { PRODUCTION_MESSAGES } from '../production-messages.ts'
|
|
10
10
|
import { VOICE_CLONE_MESSAGES } from '../voice-clone-messages.ts'
|
|
11
11
|
import { VOICE_MESSAGES, voiceFailure } from '../voice-messages.ts'
|
|
12
12
|
import { prepareVoiceSnapshot, voiceSnapshotCurrent } from '../voice-snapshot.ts'
|
|
13
13
|
import type { VoiceSnapshot } from '../voice-snapshot.ts'
|
|
14
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
14
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
15
15
|
import { VoiceCloneDialog } from './VoiceCloneDialog.tsx'
|
|
16
16
|
import { VoicePreviewDialog } from './VoicePreviewDialog.tsx'
|
|
17
17
|
import { VoiceScopeField } from './VoiceScopeField.tsx'
|
|
@@ -26,13 +26,14 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
26
26
|
const t = VOICE_MESSAGES[locale], p = PRODUCTION_MESSAGES[locale], c = VOICE_CLONE_MESSAGES[locale]
|
|
27
27
|
const serviceVersion = useWorkbenchState(state => state.voiceServiceVersion)
|
|
28
28
|
const identity = useRef(actor!.identity!).current, directory = useRef(actor!.directory).current
|
|
29
|
-
const [restored] = useState(() => readVoiceDraft(workbench.client, identity, stepId))
|
|
29
|
+
const [restored, setRestored] = useState(() => readVoiceDraft(workbench.client, identity, stepId))
|
|
30
30
|
const [draft, setDraft] = useState<VoiceDraft>(() => restored ?? { version: actor!.version!, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(actor!.content!, stepId).value ?? null, replaceOverrides: false })
|
|
31
31
|
const [storageFailed, setStorageFailed] = useState(() => voiceDraftStorageStatus(workbench.client, identity, stepId) !== 'available')
|
|
32
32
|
const [engineFilter, setEngineFilter] = useState(draft.source?.type === 'tts' ? draft.source.voice.engine : undefined)
|
|
33
33
|
const [language, setLanguage] = useState(''), [query, setQuery] = useState(''), [catalog, setCatalog] = useState<VoiceCatalogAnswer>()
|
|
34
34
|
const [catalogBusy, setCatalogBusy] = useState(true), [catalogFailure, setCatalogFailure] = useState<string>(), [reload, setReload] = useState(0)
|
|
35
|
-
const
|
|
35
|
+
const pending = useRef(false), composing = useRef(false)
|
|
36
|
+
const [busy, renderBusy] = useState(false), [failure, setFailure] = useState<string>(), [review, setReview] = useState<Review>()
|
|
36
37
|
const [preview, setPreview] = useState<{ quote: VoicePreviewQuote, snapshot: VoiceSnapshot }>(), [cloning, setCloning] = useState(false)
|
|
37
38
|
const owner = useRef({ active: true, generation: 0 }), request = useRef<AbortController>()
|
|
38
39
|
useEffect(() => () => { owner.current.active = false; owner.current.generation++; request.current?.abort() }, [])
|
|
@@ -57,10 +58,25 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
57
58
|
const rateInvalid = draft.rateInput !== undefined && normalizedRate !== undefined && normalizedRate.length > 0 && (!rateRange || !/^\d+(?:\.\d+)?$/.test(normalizedRate) || !Number.isFinite(rate) || rate! < rateRange.min || rate! > rateRange.max)
|
|
58
59
|
const sourceType = draft.source === null ? 'inherit' : draft.source.type
|
|
59
60
|
const current = () => owner.current.active && workbench.getState().authoring?.identity === identity
|
|
61
|
+
const unavailable = useRef(false)
|
|
62
|
+
unavailable.current = blocked || cloning || Boolean(preview)
|
|
63
|
+
const setBusy = (value: boolean) => { pending.current = value; renderBusy(value); workbench.refreshAuthoringClientControls() }
|
|
64
|
+
useEffect(() => workbench.production.registerDraftView({ identity, kind: 'voice', has: key => current() && key === stepId,
|
|
65
|
+
blocked: () => composing.current || pending.current || unavailable.current,
|
|
66
|
+
clear: () => {
|
|
67
|
+
const actual = workbench.getState().authoring, content = workbench.getDocument(identity)
|
|
68
|
+
if (!actual?.version || !content) return
|
|
69
|
+
owner.current.generation++; request.current?.abort(); request.current = undefined
|
|
70
|
+
const value: VoiceDraft = { version: actual.version, scope: { kind: 'step', stepId }, source: resolveDocumentStepVoice(content, stepId).value ?? null, replaceOverrides: false }
|
|
71
|
+
setDraft(value); setRestored(undefined); setStorageFailed(false); setReview(undefined); setFailure(undefined)
|
|
72
|
+
setEngineFilter(value.source?.type === 'tts' ? value.source.voice.engine : undefined); setLanguage(''); setQuery('')
|
|
73
|
+
} }), [workbench, identity, stepId])
|
|
74
|
+
useEffect(() => workbench.registerNavigationGuard(() => current() && (composing.current || pending.current || unavailable.current)), [workbench, identity])
|
|
75
|
+
useEffect(() => { workbench.refreshAuthoringClientControls() }, [workbench, blocked, busy, preview, cloning])
|
|
60
76
|
const edit = (value: VoiceDraft) => {
|
|
61
77
|
request.current?.abort(); owner.current.generation++
|
|
62
78
|
setBusy(false); setFailure(undefined); setReview(undefined); setPreview(undefined); workbench.stopAuditions()
|
|
63
|
-
setDraft(value); setStorageFailed(!keepVoiceDraft(
|
|
79
|
+
setDraft(value); setStorageFailed(!workbench.production.keepVoiceDraft(identity, stepId, value))
|
|
64
80
|
}
|
|
65
81
|
const checkedDraft = (value: VoiceDraft): VoiceDraft => ({ ...value, version: workbench.getState().authoring!.version! })
|
|
66
82
|
const checkScope = async (value = draft) => {
|
|
@@ -73,7 +89,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
73
89
|
const source = workbench.getState().authoring, latest = workbench.getDocument(identity)
|
|
74
90
|
if (!source?.version || !source.fingerprint || !latest || source.dirty || source.saving || source.error || source.restored || source.composing) throw new Error('voice-context-changed')
|
|
75
91
|
const proposal = checkedDraft(value), impact = previewDocumentVoiceChange(latest, proposal.scope, proposal.source, { replaceOverrides: proposal.replaceOverrides })
|
|
76
|
-
setDraft(proposal); setStorageFailed(!keepVoiceDraft(
|
|
92
|
+
setDraft(proposal); setStorageFailed(!workbench.production.keepVoiceDraft(identity, stepId, proposal))
|
|
77
93
|
const targets = documentVoiceStepIds(latest, proposal.scope).map(id => { const step = latest.steps[id]!, page = latest.sections[step.sectionId]!; return `${page.title} · ${t.step(latest.sectionOrder.indexOf(page.id) + 1, page.stepOrder.indexOf(id) + 1)}` })
|
|
78
94
|
setReview({ draft: proposal, impact, scopeLabel: t.scopes[proposal.scope.kind], targets, expected: { identity, version: source.version, fingerprint: source.fingerprint } })
|
|
79
95
|
} catch (error) { if (current() && generation === owner.current.generation) setFailure(voiceFailure(error, locale)) }
|
|
@@ -84,10 +100,10 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
84
100
|
const confirmation = review, generation = ++owner.current.generation
|
|
85
101
|
setBusy(true); setFailure(undefined)
|
|
86
102
|
try {
|
|
87
|
-
const saved = await workbench.
|
|
103
|
+
const saved = await workbench.production.applyVoice(confirmation.draft.scope, confirmation.draft.source, { replaceOverrides: confirmation.draft.replaceOverrides }, confirmation.expected)
|
|
88
104
|
if (!current() || generation !== owner.current.generation) return
|
|
89
105
|
if (!saved) throw new Error('voice-context-changed')
|
|
90
|
-
if (!clearVoiceDraft(
|
|
106
|
+
if (!workbench.production.clearVoiceDraft(identity, stepId, confirmation.draft)) { setStorageFailed(true); setReview(undefined); return }
|
|
91
107
|
onClose()
|
|
92
108
|
} catch (error) { if (current() && generation === owner.current.generation) { setReview(undefined); setFailure(voiceFailure(error, locale)) } }
|
|
93
109
|
finally { if (current() && generation === owner.current.generation) setBusy(false) }
|
|
@@ -109,7 +125,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
109
125
|
if (!document || !validTarget) return <PmDialog open label={t.settings} closeLabel={t.close} onClose={onClose}><PmNotice tone="warn">{p.draftChanged}</PmNotice></PmDialog>
|
|
110
126
|
return <>
|
|
111
127
|
<PmDialog open label={t.settings} closeLabel={t.close} onClose={onClose} footer={<><PmButton onClick={onClose}>{t.close}</PmButton><PmButton loading={busy} disabled={blocked || rateInvalid || draft.source?.type === 'tts' && !draft.source.voice.voice.trim() || draft.scope.kind === 'steps' && !draft.scope.stepIds.length} variant="primary" onClick={() => void checkScope()}>{t.check}</PmButton></>}>
|
|
112
|
-
<div className="pmw-voice__form">
|
|
128
|
+
<div className="pmw-voice__form" onCompositionStartCapture={() => { composing.current = true; workbench.refreshAuthoringClientControls() }} onCompositionEndCapture={() => { composing.current = false; workbench.refreshAuthoringClientControls() }}>
|
|
113
129
|
{restored && <PmNotice tone="accent">{t.draftRecovered}</PmNotice>}
|
|
114
130
|
{storageFailed && <PmNotice tone="warn">{t.recoveryFailed}</PmNotice>}
|
|
115
131
|
{failure && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
@@ -3,7 +3,7 @@ import { PmButton, PmField } from '../components.tsx'
|
|
|
3
3
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
4
4
|
import { resolveDocumentStepVoice } from '../document-voices.ts'
|
|
5
5
|
import { PRODUCTION_MESSAGES } from '../production-messages.ts'
|
|
6
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
6
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
7
7
|
import { DocumentVoiceDialog } from './DocumentVoiceDialog.tsx'
|
|
8
8
|
|
|
9
9
|
/** One current voice and selector, shared by document captions and production. */
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
|
-
import type { CSSProperties } from 'react'
|
|
3
2
|
import type { CompileJob, OutputTarget } from '@lincyaw/kernel'
|
|
4
3
|
import type { IconName } from '@lincyaw/design'
|
|
5
|
-
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton,
|
|
4
|
+
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmNotice, PmPanelHeader } from '../components.tsx'
|
|
6
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
7
6
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
8
7
|
|
|
@@ -43,10 +42,7 @@ export function ExportPanel({ documentOnly = false, embedded = false, onClose }:
|
|
|
43
42
|
const busy = (id: string) => jobs.some(job => job.target === id && (job.state === 'queued' || job.state === 'running'))
|
|
44
43
|
return (
|
|
45
44
|
<section className="pmw-pane" aria-labelledby={embedded ? undefined : 'pmw-export-title'} aria-label={embedded ? t.exportPane : undefined}>
|
|
46
|
-
{!embedded && <
|
|
47
|
-
<h2 id="pmw-export-title" className="pmw-pane__title">{documentOnly ? t.documentExport : t.exportPane}</h2>
|
|
48
|
-
<PmIconButton small icon="close" label={t.close} onClick={onClose} />
|
|
49
|
-
</header>}
|
|
45
|
+
{!embedded && <PmPanelHeader className="pmw-pane__header" titleId="pmw-export-title" title={documentOnly ? t.documentExport : t.exportPane} actions={<PmIconButton small icon="close" label={t.close} onClick={onClose} />} />}
|
|
50
46
|
{failure && <PmNotice tone="danger">{t.outputFailed(t.jobFailureReasons[failure] ?? failureReason(t, failure))}</PmNotice>}
|
|
51
47
|
{preparing && <PmNotice>{preparing.canCancel ? t.outputConfirmingSave : t.outputStarting} {preparing.canCancel && <PmButton small onClick={() => workbench.cancelJobPreparation()}>{t.cancelOutput}</PmButton>}</PmNotice>}
|
|
52
48
|
{!embedded && <h3 id="pmw-export-make" className="pmw-export__subtitle">{t.makeLabel}</h3>}
|
|
@@ -105,10 +101,6 @@ function JobItem({ job, label, current, onPlay }: { job: CompileJob, label: stri
|
|
|
105
101
|
</p>
|
|
106
102
|
{job.state === 'running' && progress && (
|
|
107
103
|
<div className="pmw-job__progress">
|
|
108
|
-
{/* the kitten runs along the bar to how far the job has come; with no total yet it walks at the start */}
|
|
109
|
-
<span className="pmw-job__runner" style={{ '--pmw-job-done': progress.total ? Math.min(1, (progress.done ?? 0) / progress.total) : 0 } as CSSProperties}>
|
|
110
|
-
<PmMascot size="small" action={progress.total ? 'run' : 'walk'} />
|
|
111
|
-
</span>
|
|
112
104
|
<progress max={progress.total ?? 1} value={progress.total ? progress.done ?? 0 : undefined} aria-label={label} />
|
|
113
105
|
<span>{t.jobProgress(t.jobPhases[progress.phase] ?? t.outputLabels[progress.phase] ?? progress.phase, progress.done, progress.total)}</span>
|
|
114
106
|
</div>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { hasRole } from '@lincyaw/kernel'
|
|
1
2
|
import type { HistoryRevision } from '@lincyaw/kernel'
|
|
2
|
-
import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../components.tsx'
|
|
3
|
+
import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice, PmPanelHeader } from '../components.tsx'
|
|
3
4
|
import type { IconName } from '@lincyaw/design'
|
|
4
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
6
|
import { timeAgo } from '../messages.ts'
|
|
6
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
7
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
7
8
|
|
|
8
9
|
/** A host-owned operation on a version, such as restoring an entire saved snapshot. This never replaces selective undo. */
|
|
9
10
|
export interface HistoryRevisionAction {
|
|
@@ -26,11 +27,15 @@ export function HistoryPanel({ onClose, revisionAction }: HistoryPanelProps) {
|
|
|
26
27
|
const workbench = useWorkbench()
|
|
27
28
|
const history = useWorkbenchState(state => state.history)
|
|
28
29
|
const outside = useWorkbenchState(state => state.outside)
|
|
30
|
+
const source = useWorkbenchState(state => state.authoring)
|
|
29
31
|
const changing = useWorkbenchState(state => state.isHistoryBusy || state.isHistoryPreparing || isAgentChanging(state))
|
|
30
|
-
const busy = changing || revisionAction?.pendingRevision !== undefined
|
|
32
|
+
const busy = changing || revisionAction?.pendingRevision !== undefined || Boolean(source?.recovering)
|
|
31
33
|
const readOnly = workbench.client.capabilities?.readOnly === true
|
|
32
34
|
const locale = useWorkbenchState(state => state.locale)
|
|
33
35
|
const memberId = useWorkbenchState(state => state.authoring?.member?.id)
|
|
36
|
+
const drafts = source?.recoveryDrafts ?? []
|
|
37
|
+
const draftBusy = busy || readOnly || Boolean(source?.member && !hasRole(source.member, 'editor'))
|
|
38
|
+
|| !source?.identity || Boolean(source.loading || source.saving || source.composing || source.recovering)
|
|
34
39
|
const revisions = history?.revisions ?? []
|
|
35
40
|
// Undoing and redoing are not versions of their own: they mark the change they act on.
|
|
36
41
|
const changes = revisions.filter(revision => !revision.reverts)
|
|
@@ -38,16 +43,38 @@ export function HistoryPanel({ onClose, revisionAction }: HistoryPanelProps) {
|
|
|
38
43
|
const icon = (revision: HistoryRevision): IconName => (revision.origin.kind === 'agent' ? 'sparkle' : revision.origin.kind === 'document' ? 'document' : 'edit')
|
|
39
44
|
return (
|
|
40
45
|
<section className="pmw-pane" aria-labelledby="pmw-history-title">
|
|
41
|
-
<
|
|
42
|
-
<h2 id="pmw-history-title" className="pmw-pane__title">{t.versionHistory}</h2>
|
|
43
|
-
<PmIconButton small icon="close" label={t.close} onClick={onClose} />
|
|
44
|
-
</header>
|
|
46
|
+
<PmPanelHeader className="pmw-pane__header" titleId="pmw-history-title" title={t.versionHistory} actions={<PmIconButton small icon="close" label={t.close} onClick={onClose} />} />
|
|
45
47
|
{outside && outside.length > 0 && (
|
|
46
48
|
<PmNotice tone="warn">
|
|
47
49
|
<span>{t.outside(outside.length)}</span>
|
|
48
50
|
<PmButton small disabled={busy} onClick={() => void workbench.recordOutsideChanges()}>{t.recordOutside}</PmButton>
|
|
49
51
|
</PmNotice>
|
|
50
52
|
)}
|
|
53
|
+
{source?.recoveryReadFailure && <PmNotice tone="warn">{t.documentDraftUnreadable}</PmNotice>}
|
|
54
|
+
{source?.recoveryChanged && <PmNotice tone="accent">{t.documentDraftChanged}</PmNotice>}
|
|
55
|
+
{drafts.length > 0 && <section className="pmw-history-group" aria-labelledby="pmw-history-drafts">
|
|
56
|
+
<header className="pmw-history-group__header">
|
|
57
|
+
<h3 id="pmw-history-drafts" className="pmw-pane__title">{t.documentDrafts} <PmBadge>{drafts.length}</PmBadge></h3>
|
|
58
|
+
{drafts.length > 1 && <PmButton small disabled={draftBusy} onClick={() => { if (source?.identity) workbench.forgetDocumentDrafts(drafts, source.identity) }}>{t.documentDraftDiscardAll}</PmButton>}
|
|
59
|
+
</header>
|
|
60
|
+
<ol className="pmw-versions">
|
|
61
|
+
{drafts.map((draft, index) => <li key={JSON.stringify([draft.id, draft.revision, draft.token])} className="pmw-version">
|
|
62
|
+
<span className="pmw-version__icon" aria-hidden="true"><PmIcon name="edit" /></span>
|
|
63
|
+
<div className="pmw-version__body">
|
|
64
|
+
<p className="pmw-version__summary">{t.documentDraftName(index + 1)}</p>
|
|
65
|
+
<p className="pmw-version__meta">
|
|
66
|
+
<span>{t.unsaved}</span><span>·</span>
|
|
67
|
+
<time dateTime={new Date(draft.updatedAt).toISOString()} title={new Date(draft.updatedAt).toLocaleString(locale)}>{timeAgo(new Date(draft.updatedAt).toISOString(), locale)}</time>
|
|
68
|
+
</p>
|
|
69
|
+
</div>
|
|
70
|
+
<div className="pmw-version__actions">
|
|
71
|
+
<PmButton small disabled={draftBusy} onClick={() => { if (source?.identity) void workbench.recoverDocumentDraft(draft, source.identity) }}>{t.documentDraftRestore}</PmButton>
|
|
72
|
+
<PmButton small disabled={draftBusy} onClick={() => { if (source?.identity) workbench.forgetDocumentDrafts([draft], source.identity) }}>{t.narrationDiscard}</PmButton>
|
|
73
|
+
</div>
|
|
74
|
+
</li>)}
|
|
75
|
+
</ol>
|
|
76
|
+
</section>}
|
|
77
|
+
{drafts.length > 0 && <div className="pmw-history-group__header"><h3 className="pmw-pane__title">{t.historySavedVersions}</h3></div>}
|
|
51
78
|
{changes.length === 0
|
|
52
79
|
? <PmEmpty icon="versions">{t.noHistory}</PmEmpty>
|
|
53
80
|
: (
|
package/src/panels/HomePanel.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
2
3
|
import { errorMessage } from '@lincyaw/kernel'
|
|
3
4
|
import type { DocumentSummary, ProjectPlan } from '@lincyaw/kernel'
|
|
4
5
|
import { PmButton, PmDialog, PmEmpty, PmInput, PmSelect, PmIcon, PmMenu, PmNotice } from '../components.tsx'
|
|
@@ -10,7 +11,7 @@ type Editing =
|
|
|
10
11
|
| { op: 'rename' | 'delete', doc: DocumentSummary }
|
|
11
12
|
|
|
12
13
|
/** The documents of the workspace: open one, make a new one, rename, copy or delete one. */
|
|
13
|
-
export function HomePanel() {
|
|
14
|
+
export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
|
|
14
15
|
const t = useMessages()
|
|
15
16
|
const workbench = useWorkbench()
|
|
16
17
|
const answer = useWorkbenchState(state => state.documents)
|
|
@@ -46,6 +47,7 @@ export function HomePanel() {
|
|
|
46
47
|
<section className="pmw-home" aria-labelledby="pmw-home-title">
|
|
47
48
|
<header className="pmw-home__bar">
|
|
48
49
|
<h1 id="pmw-home-title" className="pmw-home__title">{answer?.title ?? t.documents}</h1>
|
|
50
|
+
{actions}
|
|
49
51
|
{operable && <PmButton variant="primary" icon="plus" disabled={working} onClick={() => { handingOff.current = false; setError(undefined); setEditing({ op: 'create' }) }}>{t.newDocument}</PmButton>}
|
|
50
52
|
</header>
|
|
51
53
|
{failure && <PmNotice tone="danger">{bundleDisabled ? t.bundleDisabled : failure}</PmNotice>}
|
|
@@ -12,7 +12,7 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
let current = true
|
|
14
14
|
setLoading(true); setError(undefined)
|
|
15
|
-
void workbench.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
|
|
15
|
+
void workbench.editing.preparePageDeletion(section).then(answer => { if (current) setPlan(answer) }, () => { if (current) setError(t.pageEditRequestFailed) }).finally(() => { if (current) setLoading(false) })
|
|
16
16
|
return () => { current = false }
|
|
17
17
|
}, [workbench, section, attempt])
|
|
18
18
|
return <PmDialog open label={t.pageDeleteTitle(title)} description={plan ? t.pageDeleteHint(plan.counts.steps, plan.counts.narration) : t.pageDeleteLoading} busy={busy} closeLabel={t.close} onClose={onClose} onCloseAutoFocus={event => {
|
|
@@ -21,12 +21,12 @@ export function PageDeleteDialog({ section, title, trigger, onClose }: { section
|
|
|
21
21
|
}}>
|
|
22
22
|
<div className="pmw-operation">
|
|
23
23
|
{plan?.last && <PmNotice>{t.pageDeleteLast}</PmNotice>}
|
|
24
|
-
{plan && !plan.allowed && <PmNotice tone="warn">{workbench.
|
|
24
|
+
{plan && !plan.allowed && <PmNotice tone="warn">{workbench.editing.deletionMessage(plan.reason ?? 'page-boundary')}</PmNotice>}
|
|
25
25
|
{(error || failure) && <PmNotice tone="danger">{error || failure}</PmNotice>}
|
|
26
26
|
<div className="pmw-operation__actions">
|
|
27
27
|
<PmButton disabled={busy} onClick={onClose}>{t.cancel}</PmButton>
|
|
28
|
-
{error || failure ? <PmButton disabled={busy} onClick={() => { workbench.
|
|
29
|
-
: <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
|
|
28
|
+
{error || failure ? <PmButton disabled={busy} onClick={() => { workbench.editing.clearFailure(); setAttempt(value => value + 1) }}>{t.retry}</PmButton>
|
|
29
|
+
: <PmButton variant="danger" loading={loading || busy} disabled={!plan?.allowed || loading} onClick={() => { if (plan) void workbench.editing.deletePage(plan).then(saved => { if (saved) onClose() }) }}>{t.pageDelete}</PmButton>}
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
32
|
</PmDialog>
|
|
@@ -15,7 +15,7 @@ export function PageRenameDialog({ section, title: original, trigger, onClose }:
|
|
|
15
15
|
}} onSubmit={event => {
|
|
16
16
|
event.preventDefault()
|
|
17
17
|
if (busy || !title.trim()) return
|
|
18
|
-
void workbench.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
|
|
18
|
+
void workbench.editing.renamePage(section, title.trim()).then(saved => { if (saved) onClose() })
|
|
19
19
|
}}>
|
|
20
20
|
<PmInput label={t.pageTitle} density="regular" value={title} error={failure} required autoFocus readOnly={busy} onChange={event => setTitle(event.target.value)} />
|
|
21
21
|
<div className="pmw-operation__actions">
|
|
@@ -6,7 +6,6 @@ import { PmButton, PmNotice } from '../components.tsx'
|
|
|
6
6
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
7
7
|
import { slideAspect } from '../workbench.ts'
|
|
8
8
|
import { failureReason } from '../messages.ts'
|
|
9
|
-
import { PreviewChangeTrail } from './ChangeTrail.tsx'
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* The open document as its readers see it (the web form or the slides), with the tools for what the author points at.
|
|
@@ -29,7 +28,6 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
|
|
|
29
28
|
const reload = useWorkbenchState(state => state.previewReload)
|
|
30
29
|
const aspect = useWorkbenchState(state => (state.previewRenderer === 'slides' ? slideAspect(state.ir) : undefined))
|
|
31
30
|
const container = useRef<HTMLDivElement>(null)
|
|
32
|
-
const stage = useRef<HTMLDivElement>(null)
|
|
33
31
|
const pool = useRef<ReturnType<typeof createPreviewPool>>()
|
|
34
32
|
const [loads, setLoads] = useState(0)
|
|
35
33
|
const [{ ready, mismatch, identityFailure, handshakeFailure, canvasGate }, setStatus] = useState<PreviewFrameStatus>({ ready: false })
|
|
@@ -70,9 +68,8 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
|
|
|
70
68
|
{failure && <PmNotice tone="danger"><span>{t.previewFailed(failureReason(t, failure))}</span><PmButton small onClick={() => workbench.retryPreview()}>{t.retry}</PmButton></PmNotice>}
|
|
71
69
|
{(!ready || !snapshotMatches) && !failure && !handshakeFailure && !(renderer === 'slides' && preview && !preview.slides) && <p className="pmw-muted pmw-preview__loading">{presentation && ready && !snapshotMatches && !preparing ? t.presentationOutdated : address ? t.previewLoading : t.previewPreparing}</p>}
|
|
72
70
|
{renderer === 'slides' && preview && !preview.slides && <p className="pmw-muted pmw-preview__loading">{t.noSlides}</p>}
|
|
73
|
-
<div
|
|
71
|
+
<div className="pmw-preview__stage">
|
|
74
72
|
<div ref={container} className="pmw-preview__frames" data-renderer={renderer} data-pending-snapshot={!snapshotMatches || undefined} data-presentation-gated={presentation && canvasGate || undefined} style={aspect === undefined ? undefined : { '--pmw-slide-aspect': aspect } as CSSProperties} />
|
|
75
|
-
{!presentation && <PreviewChangeTrail stage={stage} frames={container} />}
|
|
76
73
|
</div>
|
|
77
74
|
</section>
|
|
78
75
|
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
|
|
3
|
+
import type { TeachingDocument } from '@lincyaw/kernel'
|
|
4
|
+
import { PmField, PmRange } from '../components.tsx'
|
|
5
|
+
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
|
+
import { PRODUCTION_MESSAGES } from '../production-messages.ts'
|
|
7
|
+
|
|
8
|
+
/** The document's caption size in percent steps of ten; a released drag or a key records it once. */
|
|
9
|
+
export function ProductionCaptionSize({ identity, document, disabled, onChanged }: { identity: string, document: TeachingDocument, disabled: boolean, onChanged(): void }) {
|
|
10
|
+
const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
|
|
11
|
+
const [preview, setPreview] = useState<number>()
|
|
12
|
+
const percent = Math.round(captionScale(document.production) * 100)
|
|
13
|
+
return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
|
|
14
|
+
<div className="pm-ui-range-row">
|
|
15
|
+
<PmRange label={p.captionSize} value={percent} min={Math.round(CAPTION_SCALE_MIN * 100)} max={Math.round(CAPTION_SCALE_MAX * 100)} step={10} disabled={disabled} valueText={value => `${Math.round(value)}%`}
|
|
16
|
+
onPreviewChange={setPreview} onValueCommit={value => { workbench.production.setCaptionScale(value / 100, identity); onChanged() }} />
|
|
17
|
+
<output>{Math.round(preview ?? percent)}%</output>
|
|
18
|
+
</div>
|
|
19
|
+
</PmField>
|
|
20
|
+
}
|
|
@@ -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) } : {} }) }}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { useContainerLayout } from '../container-layout.ts'
|
|
2
4
|
import { keyBelongsToTarget, PRODUCTION_PLAYBACK_RATES, sameProductionBinding, watchFocusSource } from '@lincyaw/kernel'
|
|
3
5
|
import type { ProductionPlaybackCommand } from '@lincyaw/kernel'
|
|
4
6
|
import { PmBadge, PmButton, PmCard, PmDialog, PmEmpty, PmIconButton, PmNotice, PmPanelHeader, PmPopover, PmSearchList, PmSelect, PmSegmented, PmSplitGroup, PmSplitHandle, PmSplitPanel, PmTabs, PmTabPanel, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
@@ -6,12 +8,13 @@ import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
|
6
8
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
7
9
|
import { PRODUCTION_MESSAGES, productionFailure } from '../production-messages.ts'
|
|
8
10
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
9
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
10
|
-
import type { PlaybackKey } from '../workbench.ts'
|
|
11
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
12
|
+
import type { PlaybackKey } from '../workbench-state.ts'
|
|
11
13
|
import { DocumentVoiceField } from './DocumentVoiceField.tsx'
|
|
12
14
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
13
15
|
import { PreviewPanel } from './PreviewPanel.tsx'
|
|
14
16
|
import { VoiceoverDialog } from './VoiceoverDialog.tsx'
|
|
17
|
+
import { ProductionCaptionSize } from './ProductionCaptionSize.tsx'
|
|
15
18
|
import { ProductionCaptionTiming } from './ProductionCaptionTiming.tsx'
|
|
16
19
|
import { ProductionTimeline } from './ProductionTimeline.tsx'
|
|
17
20
|
import { ProductionMediaClips } from './ProductionMediaClips.tsx'
|
|
@@ -32,7 +35,7 @@ const PLAYBACK_KEYS: Record<string, PlaybackKey> = { ' ': 'play-pause', ArrowLef
|
|
|
32
35
|
* While it is `active`, Space plays or pauses and the left and right arrows select the previous or next step, from the
|
|
33
36
|
* workbench and from its preview alike; text entry, menus, dialogs and controls the keyboard moved to keep their keys.
|
|
34
37
|
*/
|
|
35
|
-
export function ProductionPanel({ onClose, closing, active = true }: { onClose(): void, closing: boolean, active?: boolean }) {
|
|
38
|
+
export function ProductionPanel({ onClose, closing, active = true, actions }: { onClose(): void, closing: boolean, active?: boolean, actions?: ReactNode }) {
|
|
36
39
|
const workbench = useWorkbench(), t = useMessages(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
|
|
37
40
|
const voicePlayback = useProductionVoicePlayback()
|
|
38
41
|
const serviceVersion = useWorkbenchState(state => state.voiceServiceVersion)
|
|
@@ -45,7 +48,8 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
45
48
|
const captionDraftSteps = useWorkbenchState(state => state.captionTimingDraftSteps), captionStorageFailure = useWorkbenchState(state => state.captionTimingDraftStorageFailure)
|
|
46
49
|
const frameCurrent = useWorkbenchState(state => Boolean(state.presentationSnapshot && state.previewIrRevision === state.presentationSnapshot.revision))
|
|
47
50
|
const blocked = useWorkbenchState(state => Boolean(state.authoring?.loading || state.authoring?.composing) || isAgentChanging(state))
|
|
48
|
-
const
|
|
51
|
+
const container = useContainerLayout(), wide = container.productionWide
|
|
52
|
+
const [tab, setTab] = useState('preview')
|
|
49
53
|
const [libraryTab, setLibraryTab] = useState('pages'), [inspectorTab, setInspectorTab] = useState('script'), [outputsOpen, setOutputsOpen] = useState(false)
|
|
50
54
|
const [generateStep, setGenerateStep] = useState<string>(), [failure, setFailure] = useState<string>()
|
|
51
55
|
const [planBusy, setPlanBusy] = useState(false), [planFailure, setPlanFailure] = useState<string>(), [planReload, setPlanReload] = useState(0)
|
|
@@ -68,11 +72,6 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
68
72
|
const canPlay = Boolean(playbackConnected && plan?.canPreview && live?.status === 'ready' && !timingDraft)
|
|
69
73
|
const backgroundBody = !wide && tab === 'timeline', backgroundVisuals = !wide && tab !== 'preview'
|
|
70
74
|
useEffect(() => workbench.observeVoiceoverJobs(), [workbench, source?.identity])
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
const media = matchMedia('(min-width: 1100px)'), update = () => setWide(media.matches)
|
|
73
|
-
media.addEventListener('change', update)
|
|
74
|
-
return () => media.removeEventListener('change', update)
|
|
75
|
-
}, [])
|
|
76
75
|
useEffect(() => () => { owner.current.active = false; owner.current.generation++; controlRequest.current?.abort(); workbench.closeProduction(); workbench.cancelPreviewPreparation() }, [workbench])
|
|
77
76
|
useEffect(() => {
|
|
78
77
|
const controller = new AbortController()
|
|
@@ -177,10 +176,11 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
177
176
|
const mediaEditor = <ProductionMediaClips key={`${source.identity}:${stepId}`} identity={source.identity} version={source.version ?? ''} document={document} sectionId={sectionId} stepId={stepId}
|
|
178
177
|
binding={planCurrent ? plan?.binding : undefined} stepDurationMs={(() => { const step = planCurrent ? plan?.pages.find(page => page.sectionId === sectionId)?.steps.find(step => step.stepId === stepId) : undefined; return step?.timing === 'confirmed' && step.startMs !== undefined && step.endMs !== undefined ? step.endMs - step.startMs : undefined })()}
|
|
179
178
|
disabled={blocked || closing || !declared || !source.version || Boolean(source.dirty || source.saving || source.restored || source.error)} onChanged={() => setMediaRefresh(true)} />
|
|
180
|
-
return <section className="pmw-production" aria-label={p.title}>
|
|
181
|
-
<PmPanelHeader title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
179
|
+
return <section ref={container.ref} className="pmw-production" aria-label={p.title}>
|
|
180
|
+
<PmPanelHeader variant="workspace" title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
182
181
|
leading={<PmIconButton small icon="arrow-left" label={p.back} loading={closing} onClick={onClose} />}
|
|
183
182
|
actions={<>
|
|
183
|
+
{actions}
|
|
184
184
|
<PmBadge tone={sourceCurrent && frameCurrent ? 'ok' : preparing || sourceCurrent ? 'accent' : 'warn'}>{sourceCurrent && frameCurrent ? p.current : preparing || sourceCurrent ? p.preparing : p.outdated}</PmBadge>
|
|
185
185
|
{issueCount > 0 && <PmPopover open={issuesOpen} onOpenChange={setIssuesOpen} label={p.issues(issueCount)} trigger={wide ? <PmButton small icon="warning" title={summary} aria-label={p.issues(issueCount)}>{p.issueCount(issueCount)}</PmButton> : <PmIconButton small icon="warning" label={p.issues(issueCount)} hint={summary} />}>
|
|
186
186
|
<div className="pmw-production__feedback">
|
|
@@ -243,7 +243,7 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
243
243
|
</div></PmTabPanel>
|
|
244
244
|
<PmTabPanel value="voice" keepMounted><div className="pmw-production__fields">
|
|
245
245
|
<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}
|
|
246
|
+
<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
247
|
onImportStarted={() => transcriptionSelection.current}
|
|
248
248
|
onImported={(assetId, selection) => {
|
|
249
249
|
setMediaRefresh(true)
|
|
@@ -254,7 +254,10 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
254
254
|
selectedAsset={transcriptionAsset?.identity === source.identity ? transcriptionAsset : undefined}
|
|
255
255
|
onSelectAsset={() => { transcriptionSelection.current++; setTranscriptionAsset(undefined) }} />
|
|
256
256
|
</div></PmTabPanel>
|
|
257
|
-
<PmTabPanel value="captions" keepMounted><
|
|
257
|
+
<PmTabPanel value="captions" keepMounted><div className="pmw-production__fields">
|
|
258
|
+
<ProductionCaptionSize identity={source.identity} document={document} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
259
|
+
<ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
260
|
+
</div></PmTabPanel>
|
|
258
261
|
</PmTabs>
|
|
259
262
|
</PmSplitPanel>
|
|
260
263
|
</PmSplitGroup>
|