@lincyaw/workbench 0.2.0-rc.11 → 0.2.0-rc.111
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-messages.ts +5 -5
- package/src/audio-recording.ts +27 -5
- package/src/authoring-client.ts +10 -10
- package/src/authoring-draft-fragment.ts +3 -1
- package/src/authoring-window.ts +100 -0
- package/src/base-controls.tsx +2 -2
- package/src/body-draft-actions.ts +60 -0
- package/src/caption-timing-drafts.ts +18 -1
- package/src/caption-timing-messages.ts +2 -2
- 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 +39 -13
- 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 +11 -5
- package/src/jobs.ts +1 -1
- package/src/mcp-settings-messages.ts +39 -0
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +33 -16
- package/src/panels/DocumentNarrationPanel.tsx +2 -2
- package/src/panels/DocumentView.tsx +97 -65
- 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/McpSettingsPanel.tsx +86 -0
- 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/SpeechSettingsPanel.tsx +1 -1
- 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/speech-settings-messages.ts +5 -5
- 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/voice-messages.ts +9 -9
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +159 -0
- package/src/workbench.ts +303 -952
- package/src/workspace-client.ts +30 -11
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import { useContainerLayout } from '../container-layout.ts'
|
|
2
3
|
import type { ReactNode, RefObject } from 'react'
|
|
3
|
-
import { PmButton,
|
|
4
|
+
import { PmBadge, PmButton, PmDialog, PmIcon, PmIconButton, PmMenu, PmNotice, PmPanelHeader, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
4
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
6
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
6
7
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
7
8
|
import { DocumentOutline, DocumentWordCounter } from '../outline.ts'
|
|
8
|
-
import { isAgentChanging } from '../workbench.ts'
|
|
9
|
+
import { isAgentChanging } from '../workbench-state.ts'
|
|
9
10
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
10
11
|
import { HistoryPanel } from './HistoryPanel.tsx'
|
|
11
12
|
import type { HistoryRevisionAction } from './HistoryPanel.tsx'
|
|
@@ -21,20 +22,6 @@ export type DocumentAside = 'comments' | 'history' | 'export' | 'narration'
|
|
|
21
22
|
|
|
22
23
|
const isTyping = (target: EventTarget | null) => target instanceof HTMLElement && (target.isContentEditable || target.closest('input, textarea, select, [contenteditable]') !== null)
|
|
23
24
|
|
|
24
|
-
// The navigation pane starts open where there is room for it beside the page.
|
|
25
|
-
const ROOMY = '(min-width: 1280px)'
|
|
26
|
-
// Below this width the command bar keeps one row: its less frequent commands move into its "More" menu.
|
|
27
|
-
const NARROW = '(max-width: 767px)'
|
|
28
|
-
|
|
29
|
-
function useMediaQuery(query: string): boolean {
|
|
30
|
-
return useSyncExternalStore(changed => {
|
|
31
|
-
if (typeof matchMedia !== 'function') return () => {}
|
|
32
|
-
const list = matchMedia(query)
|
|
33
|
-
list.addEventListener('change', changed)
|
|
34
|
-
return () => list.removeEventListener('change', changed)
|
|
35
|
-
}, () => typeof matchMedia === 'function' && matchMedia(query).matches, () => false)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
25
|
// Esc belongs to the topmost dialog or menu first; only then does it leave the presentation.
|
|
39
26
|
const hasOpenLayer = () => document.querySelector('[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]') !== null
|
|
40
27
|
|
|
@@ -55,24 +42,27 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
55
42
|
const [commentsPortal, setCommentsPortal] = useState<HTMLDivElement | null>(null)
|
|
56
43
|
const t = useMessages()
|
|
57
44
|
const document = useWorkbenchState(state => state.document)
|
|
45
|
+
const sourceIdentity = useWorkbenchState(state => state.authoring?.identity)
|
|
58
46
|
const view = useWorkbenchState(state => state.webView)
|
|
59
47
|
const previousView = useRef({ document, workspace, view, active })
|
|
60
48
|
const currentScope = useRef({ document, active })
|
|
61
49
|
currentScope.current = { document, active }
|
|
62
|
-
const [navigation, setNavigation] = useState(
|
|
63
|
-
const
|
|
64
|
-
const previousRoomy = useRef(
|
|
50
|
+
const [navigation, setNavigation] = useState(false)
|
|
51
|
+
const container = useContainerLayout(), { roomy, narrow } = container
|
|
52
|
+
const previousRoomy = useRef<boolean>()
|
|
65
53
|
useEffect(() => {
|
|
66
|
-
if (
|
|
54
|
+
if (!container.measured) return
|
|
55
|
+
if (!roomy) setNavigation(false)
|
|
56
|
+
else if (previousRoomy.current === undefined) setNavigation(true)
|
|
67
57
|
previousRoomy.current = roomy
|
|
68
|
-
}, [roomy])
|
|
58
|
+
}, [roomy, container.measured])
|
|
69
59
|
// Where the pane covers the page, another document opens with it closed, so its body is not hidden.
|
|
70
60
|
const [navigationDocument, setNavigationDocument] = useState(document)
|
|
71
61
|
if (navigationDocument !== document) {
|
|
72
62
|
setNavigationDocument(document)
|
|
73
|
-
if (navigation &&
|
|
63
|
+
if (navigation && !roomy) setNavigation(false)
|
|
74
64
|
}
|
|
75
|
-
const compilePresentation = async (ready?: () => void, forReading = false): Promise<void> => {
|
|
65
|
+
const compilePresentation = async (ready?: () => void, forReading = false, signal?: AbortSignal, deadline?: number): Promise<void> => {
|
|
76
66
|
if (preparing.current || workbench.getState().isPreparingPresentation) return
|
|
77
67
|
preparing.current = true
|
|
78
68
|
const generation = ++transition.current, identity = workbench.getState().authoring?.identity
|
|
@@ -80,34 +70,39 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
80
70
|
setChangingView(true)
|
|
81
71
|
const current = () => generation === transition.current && currentScope.current.active && currentScope.current.document === document && workbench.getState().authoring?.identity === identity
|
|
82
72
|
try {
|
|
83
|
-
const prepared = await workbench.preparePresentation()
|
|
73
|
+
const prepared = await workbench.preparePresentation(signal, deadline)
|
|
74
|
+
signal?.throwIfAborted()
|
|
84
75
|
if (!current()) return
|
|
85
76
|
if (prepared) ready?.()
|
|
86
77
|
else setViewFailure(forReading ? t.readingFailed : workbench.getState().presentationFailure)
|
|
87
78
|
} catch { if (current()) setViewFailure(forReading ? t.readingFailed : t.presentationCompileFailed) }
|
|
88
79
|
finally { preparing.current = false; if (current()) setChangingView(false) }
|
|
89
80
|
}
|
|
90
|
-
const openProduction = async () => {
|
|
81
|
+
const openProduction = async (signal?: AbortSignal) => {
|
|
91
82
|
if (changingView || workbench.client.capabilities?.production === false) return
|
|
92
83
|
const generation = ++transition.current, identity = workbench.getState().authoring?.identity
|
|
93
84
|
const current = () => generation === transition.current && currentScope.current.active && currentScope.current.document === document && workbench.getState().authoring?.identity === identity
|
|
94
85
|
setChangingView(true); setViewFailure(undefined)
|
|
95
86
|
try {
|
|
87
|
+
signal?.throwIfAborted()
|
|
96
88
|
await workbench.pausePlayback()
|
|
97
|
-
await workbench.flushPendingEdits()
|
|
89
|
+
await workbench.flushPendingEdits(signal)
|
|
90
|
+
signal?.throwIfAborted()
|
|
98
91
|
if (current()) { workbench.setMode('editing'); setWorkspace('production') }
|
|
99
92
|
} catch { if (current()) setViewFailure(t.presentationPending) }
|
|
100
93
|
finally { if (current()) setChangingView(false) }
|
|
101
94
|
}
|
|
102
|
-
const exitPresent = (): Promise<void> => {
|
|
95
|
+
const exitPresent = (signal?: AbortSignal): Promise<void> => {
|
|
103
96
|
if (exiting.current) return exiting.current
|
|
104
97
|
const generation = ++transition.current, identity = workbench.getState().authoring?.identity
|
|
105
98
|
setChangingView(true); setViewFailure(undefined)
|
|
106
99
|
const current = () => generation === transition.current && currentScope.current.active && currentScope.current.document === document && workbench.getState().authoring?.identity === identity
|
|
107
100
|
const work = Promise.resolve().then(async () => {
|
|
108
101
|
try {
|
|
102
|
+
signal?.throwIfAborted()
|
|
109
103
|
// The child flushes its latest position before acknowledging this pause.
|
|
110
104
|
await workbench.pausePlayback()
|
|
105
|
+
signal?.throwIfAborted()
|
|
111
106
|
if (!current()) return
|
|
112
107
|
setWorkspace('document')
|
|
113
108
|
workbench.setMode('editing')
|
|
@@ -120,6 +115,40 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
120
115
|
exiting.current = work
|
|
121
116
|
return work
|
|
122
117
|
}
|
|
118
|
+
const controls = useRef({ workspace, changingView, viewFailure, generation: transition.current, compilePresentation, openProduction, exitPresent, setWorkspace })
|
|
119
|
+
controls.current = { workspace, changingView, viewFailure, generation: transition.current, compilePresentation, openProduction, exitPresent, setWorkspace }
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!active || !sourceIdentity) return
|
|
122
|
+
return workbench.registerAuthoringClientControls({ identity: sourceIdentity,
|
|
123
|
+
actions: () => {
|
|
124
|
+
const state = workbench.getState(), source = state.authoring
|
|
125
|
+
return currentScope.current.active && source?.identity === sourceIdentity && !controls.current.changingView
|
|
126
|
+
&& !source.loading && !source.dirty && !source.saving && !source.composing && !source.restored && !source.error && !isAgentChanging(state)
|
|
127
|
+
&& !state.isCreatingPage && !state.isEditingPage && !state.isHistoryBusy && !state.isHistoryPreparing ? ['view.set'] : []
|
|
128
|
+
},
|
|
129
|
+
snapshot: () => ({ mode: controls.current.workspace }),
|
|
130
|
+
execute: async (action, _source, signal, deadline) => {
|
|
131
|
+
if (action.type !== 'view.set') throw new Error('client-action-unavailable')
|
|
132
|
+
if (preparing.current || controls.current.changingView) throw new Error('client-action-unavailable')
|
|
133
|
+
if (action.view !== controls.current.workspace) {
|
|
134
|
+
if (action.view === 'document') await controls.current.exitPresent(signal)
|
|
135
|
+
else if (action.view === 'production') await controls.current.openProduction(signal)
|
|
136
|
+
else await controls.current.compilePresentation(() => {
|
|
137
|
+
workbench.setMode('viewing'); workbench.setWebView(action.view === 'presentation' ? 'present' : 'scrolly')
|
|
138
|
+
controls.current.setWorkspace(action.view)
|
|
139
|
+
}, action.view === 'reading', signal, deadline)
|
|
140
|
+
}
|
|
141
|
+
const generation = transition.current
|
|
142
|
+
await workbench.waitForAuthoringClientState(() => {
|
|
143
|
+
if (!currentScope.current.active || workbench.getState().authoring?.identity !== sourceIdentity) throw new Error('client-document-changed')
|
|
144
|
+
if (generation !== transition.current) throw new Error('client-view-changed')
|
|
145
|
+
if (controls.current.generation === generation && controls.current.viewFailure && controls.current.workspace !== action.view) throw new Error('client-view-not-verified')
|
|
146
|
+
return controls.current.workspace === action.view && !controls.current.changingView
|
|
147
|
+
}, signal)
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
}, [workbench, active, sourceIdentity])
|
|
151
|
+
useEffect(() => workbench.refreshAuthoringClientControls(), [workbench, active, sourceIdentity, workspace, changingView])
|
|
123
152
|
useEffect(() => {
|
|
124
153
|
transition.current++; exiting.current = undefined
|
|
125
154
|
setWorkspace('document')
|
|
@@ -178,30 +207,32 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
178
207
|
return () => window.removeEventListener('keydown', escape, true)
|
|
179
208
|
}, [active, presenting])
|
|
180
209
|
return (
|
|
181
|
-
<div className="pmw-document" data-workspace={producing ? 'production' : presenting ? 'presentation' : reading ? 'reading' : 'content'} data-presenting={presenting || undefined} data-aside={aside ?? undefined} data-navigation={navigation || undefined}>
|
|
182
|
-
{reading && <PmToolbar className="pmw-toolbar" label={t.commands}>
|
|
210
|
+
<div ref={container.ref} className="pmw-document" data-roomy={roomy || undefined} data-narrow={narrow || undefined} data-workspace={producing ? 'production' : presenting ? 'presentation' : reading ? 'reading' : 'content'} data-presenting={presenting || undefined} data-aside={aside ?? undefined} data-navigation={navigation || undefined}>
|
|
211
|
+
{reading && <PmToolbar variant="workspace" className="pmw-toolbar" label={t.commands}>
|
|
183
212
|
<span className="pmw-toolbar__title">{t.readDocument}</span>
|
|
213
|
+
<span className="pmw-spacer" />
|
|
184
214
|
<PmToolbarButton asChild><PmIconButton small icon="edit" label={t.editDocument} disabled={changingView} onClick={() => void exitPresent()} /></PmToolbarButton>
|
|
185
215
|
<PmToolbarButton asChild><PmIconButton small icon="refresh" label={t.reloadPreview} loading={changingView} onClick={() => void compilePresentation(() => workbench.reloadPreview(), true)} /></PmToolbarButton>
|
|
186
216
|
<PmToolbarButton asChild><PmIconButton small icon="slides" label={t.present} disabled={changingView} onClick={() => void compilePresentation(() => { workbench.setWebView('present'); setWorkspace('presentation') })} /></PmToolbarButton>
|
|
217
|
+
{actions}
|
|
187
218
|
</PmToolbar>}
|
|
188
|
-
{!producing && !presenting && !reading && <DocumentToolbar presentButton={presentButton} framed={framed} onBack={onBack} actions={actions} aside={aside} navigation={navigation} changingView={changingView} onProduction={() => void openProduction()} onRead={() => void compilePresentation(() => {
|
|
219
|
+
{!producing && !presenting && !reading && <DocumentToolbar narrow={narrow} presentButton={presentButton} framed={framed} onBack={onBack} actions={actions} aside={aside} navigation={navigation} changingView={changingView} onProduction={() => void openProduction()} onRead={() => void compilePresentation(() => {
|
|
189
220
|
workbench.setMode('viewing')
|
|
190
|
-
workbench.setWebView('
|
|
221
|
+
workbench.setWebView('scrolly')
|
|
191
222
|
setWorkspace('reading')
|
|
192
223
|
}, true)} onPresent={() => void compilePresentation(() => {
|
|
193
224
|
workbench.setMode('viewing')
|
|
194
225
|
workbench.setWebView('present')
|
|
195
226
|
setWorkspace('presentation')
|
|
196
|
-
})} onNavigation={() => { setNavigation(shown => !shown); if (!navigation &&
|
|
227
|
+
})} onNavigation={() => { setNavigation(shown => !shown); if (!navigation && !roomy) setAside(null) }} onAside={next => { setAside(current => (current === next ? null : next)); if (!roomy) setNavigation(false) }} />}
|
|
197
228
|
{viewFailure && <PmNotice tone="danger">{viewFailure}</PmNotice>}
|
|
198
229
|
<DocumentNotices />
|
|
199
230
|
<div className="pmw-document__body" role="region" aria-label={producing ? PRODUCTION_MESSAGES[workbench.getState().locale].title : presenting ? t.presentationPreview : reading ? t.readDocument : t.documentEditor}>
|
|
200
|
-
{!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (
|
|
201
|
-
<div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} /></div>{producing && <ProductionPanel active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
|
|
231
|
+
{!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (!roomy) setNavigation(false) }} />}
|
|
232
|
+
<div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} onOpenComments={() => setAside('comments')} /></div>{producing && <ProductionPanel actions={actions} active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
|
|
202
233
|
{!presenting && !producing && !reading && aside && (
|
|
203
234
|
<aside className="pmw-document__aside pm-ui-block-editor" aria-label={{ narration: t.documentNarration, comments: t.comments, export: t.exportPane, history: t.versionHistory }[aside]}>
|
|
204
|
-
{aside === 'comments' ? <section className="pmw-pane"><
|
|
235
|
+
{aside === 'comments' ? <section className="pmw-pane"><PmPanelHeader className="pmw-pane__header" title={t.comments} actions={<PmIconButton small icon="close" label={t.close} onClick={() => setAside(null)} />} /><div ref={setCommentsPortal} /></section> : aside === 'narration' ? <DocumentNarrationPanel onClose={() => setAside(null)} /> : aside === 'export' ? <ExportPanel documentOnly onClose={() => setAside(null)} /> : <HistoryPanel onClose={() => setAside(null)} revisionAction={historyRevisionAction} />}
|
|
205
236
|
</aside>
|
|
206
237
|
)}
|
|
207
238
|
</div>
|
|
@@ -220,7 +251,7 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
220
251
|
const documentId = useWorkbenchState(state => state.authoring?.content?.id)
|
|
221
252
|
const reset = useWorkbenchState(state => state.authoring?.reset)
|
|
222
253
|
const locale = useWorkbenchState(state => state.locale)
|
|
223
|
-
const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView
|
|
254
|
+
const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView === 'present')
|
|
224
255
|
const current = useWorkbenchState(state => state.position?.section)
|
|
225
256
|
const editing = useWorkbenchState(state => state.mode === 'editing' && workbench.client.capabilities?.readOnly !== true)
|
|
226
257
|
const creating = useWorkbenchState(state => Boolean(state.isCreatingPage))
|
|
@@ -238,7 +269,7 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
238
269
|
const pages = editing || slides
|
|
239
270
|
const top = Math.min(...items.map(item => Math.max(1, item.depth)))
|
|
240
271
|
const pageActions = (item: typeof items[number], index: number) => {
|
|
241
|
-
const capability = workbench.
|
|
272
|
+
const capability = workbench.editing.pageCapability(item.id), previousPeer = index > 0, nextPeer = index < items.length - 1
|
|
242
273
|
return <PmMenu label={t.pageMore(item.title)} description={capability.reason} triggerRef={node => { if (node) menuTriggers.current.set(item.id, node); else menuTriggers.current.delete(item.id) }} items={[
|
|
243
274
|
{ id: 'rename', label: t.rename, icon: 'edit', disabled: !capability.rename || !canCreate || pageBusy || creating },
|
|
244
275
|
{ id: 'copy', label: t.pageCopy, icon: 'copy', disabled: !canCreate || pageBusy || creating },
|
|
@@ -246,33 +277,32 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
246
277
|
{ id: 'down', label: t.movePageDown, disabled: !capability.move || !canCreate || pageBusy || creating || !nextPeer },
|
|
247
278
|
...(canDelete ? [{ id: 'delete', label: t.pageDelete, icon: 'trash' as const, danger: true, separator: true, disabled: !canCreate || pageBusy || creating }] : []),
|
|
248
279
|
]} onSelect={id => {
|
|
249
|
-
workbench.
|
|
280
|
+
workbench.editing.clearFailure()
|
|
250
281
|
if (id === 'rename') setRenaming({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
|
|
251
|
-
else if (id === 'copy') void workbench.duplicatePage(item.id)
|
|
282
|
+
else if (id === 'copy') void workbench.editing.duplicatePage(item.id)
|
|
252
283
|
else if (id === 'delete') setDeleting({ id: item.id, title: item.title, trigger: menuTriggers.current.get(item.id) })
|
|
253
|
-
else if (id === 'up' && index > 0) void workbench.movePage(item.id, items[index - 1]!.id)
|
|
254
|
-
else if (id === 'down') void workbench.movePage(item.id, items[index + 2]?.id ?? null)
|
|
284
|
+
else if (id === 'up' && index > 0) void workbench.editing.movePage(item.id, items[index - 1]!.id)
|
|
285
|
+
else if (id === 'down') void workbench.editing.movePage(item.id, items[index + 2]?.id ?? null)
|
|
255
286
|
}} />
|
|
256
287
|
}
|
|
257
288
|
return (
|
|
258
289
|
<nav className="pmw-navigation" aria-label={t.navigation}>
|
|
259
|
-
<
|
|
260
|
-
<
|
|
261
|
-
{editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.createPage()) onSelect() }} />}
|
|
290
|
+
<PmPanelHeader className="pmw-pane__header" title={editing ? t.pages : slides ? t.renderers.slides : t.navigation} actions={<>
|
|
291
|
+
{editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }} />}
|
|
262
292
|
<PmIconButton icon="close" label={t.closeNavigation} small onClick={onClose} />
|
|
263
|
-
|
|
293
|
+
</>} />
|
|
264
294
|
{failure && !renaming && !deleting && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
265
295
|
{items.length === 0 && loading ? <div className="pmw-navigation__empty"><PmSkeleton shape="list" label={t.loadingPages} /></div>
|
|
266
296
|
: items.length === 0
|
|
267
297
|
? <p className="pmw-muted pmw-navigation__empty">{t.noSections}</p>
|
|
268
298
|
: editing ? <PmSortableList label={t.pages} scopeKey={JSON.stringify([identity, documentId, document])} resetKey={reset} className="pmw-navigation__list" locale={locale}
|
|
269
|
-
items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.
|
|
299
|
+
items={items.map((item, index) => ({ id: item.id, label: item.title, prefix: item.number, reorderDisabled: !workbench.editing.pageCapability(item.id).move, actions: pageActions(item, index) }))}
|
|
270
300
|
value={current} reorderDisabled={reorderDisabled} loading={pageBusy || creating}
|
|
271
301
|
onSelect={id => { workbench.goToSection(id); onSelect() }}
|
|
272
302
|
onMove={async (id, before) => {
|
|
273
303
|
const state = workbench.getState()
|
|
274
304
|
if (state.document !== document || state.authoring?.identity !== identity || state.authoring?.content?.id !== documentId) return
|
|
275
|
-
if (!await workbench.movePage(id, before)) throw new Error('page-reorder-failed')
|
|
305
|
+
if (!await workbench.editing.movePage(id, before)) throw new Error('page-reorder-failed')
|
|
276
306
|
}} /> : (
|
|
277
307
|
<ol className="pmw-navigation__list" data-kind={pages ? 'slides' : 'headings'}>
|
|
278
308
|
{items.map(item => (
|
|
@@ -291,8 +321,8 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
291
321
|
))}
|
|
292
322
|
</ol>
|
|
293
323
|
)}
|
|
294
|
-
{renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.
|
|
295
|
-
{deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.
|
|
324
|
+
{renaming && <PageRenameDialog section={renaming.id} title={renaming.title} trigger={renaming.trigger} onClose={() => { setRenaming(undefined); workbench.editing.clearFailure() }} />}
|
|
325
|
+
{deleting && <PageDeleteDialog section={deleting.id} title={deleting.title} trigger={deleting.trigger} onClose={() => { setDeleting(undefined); workbench.editing.clearFailure() }} />}
|
|
296
326
|
</nav>
|
|
297
327
|
)
|
|
298
328
|
}
|
|
@@ -302,7 +332,7 @@ function StatusBar() {
|
|
|
302
332
|
const t = useMessages()
|
|
303
333
|
const doc = useWorkbenchState(state => state.authoring?.content)
|
|
304
334
|
const identity = useWorkbenchState(state => state.authoring?.identity)
|
|
305
|
-
const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView
|
|
335
|
+
const slides = useWorkbenchState(state => state.previewRenderer === 'slides' || state.webView === 'present')
|
|
306
336
|
const section = useWorkbenchState(state => state.position?.section)
|
|
307
337
|
const counter = useMemo(() => new DocumentWordCounter(), [])
|
|
308
338
|
const words = useMemo(() => counter.count(doc, identity), [counter, doc, identity])
|
|
@@ -316,7 +346,7 @@ function StatusBar() {
|
|
|
316
346
|
)
|
|
317
347
|
}
|
|
318
348
|
|
|
319
|
-
function DocumentToolbar({ presentButton, framed, onBack, actions, aside, navigation, changingView, onProduction, onRead, onPresent, onNavigation, onAside }: { presentButton: RefObject<HTMLButtonElement>, framed: boolean, onBack?(): void, actions?: ReactNode, aside: DocumentAside | null, navigation: boolean, changingView: boolean, onProduction(): void, onRead(): void, onPresent(): void, onNavigation(): void, onAside(aside: DocumentAside): void }) {
|
|
349
|
+
function DocumentToolbar({ narrow, presentButton, framed, onBack, actions, aside, navigation, changingView, onProduction, onRead, onPresent, onNavigation, onAside }: { narrow: boolean, presentButton: RefObject<HTMLButtonElement>, framed: boolean, onBack?(): void, actions?: ReactNode, aside: DocumentAside | null, navigation: boolean, changingView: boolean, onProduction(): void, onRead(): void, onPresent(): void, onNavigation(): void, onAside(aside: DocumentAside): void }) {
|
|
320
350
|
const t = useMessages()
|
|
321
351
|
const workbench = useWorkbench()
|
|
322
352
|
const p = PRODUCTION_MESSAGES[useWorkbenchState(state => state.locale)]
|
|
@@ -324,20 +354,22 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
324
354
|
const history = useWorkbenchState(state => state.history)
|
|
325
355
|
const editorHistory = useWorkbenchState(state => state.editorHistory)
|
|
326
356
|
const dirty = useWorkbenchState(state => Boolean(state.authoring?.dirty))
|
|
357
|
+
const draftCount = useWorkbenchState(state => state.authoring?.recoveryDrafts?.length ?? 0)
|
|
358
|
+
const draftReadFailure = useWorkbenchState(state => Boolean(state.authoring?.recoveryReadFailure))
|
|
327
359
|
const busy = useWorkbenchState(state => state.isHistoryBusy || state.isHistoryPreparing || Boolean(state.isCreatingPage) || Boolean(state.isEditingPage || state.authoring?.composing) || isAgentChanging(state))
|
|
328
360
|
const timingDrafts = useWorkbenchState(state => state.hasDocumentTimingDrafts)
|
|
329
361
|
const preparing = useWorkbenchState(state => Boolean(state.isPreparingPresentation))
|
|
330
362
|
const blocked = useWorkbenchState(state => Boolean(!state.authoring?.content || state.authoring.loading || state.authoring.dirty || state.authoring.saving || state.authoring.restored || state.authoring.error || state.authoring.composing || state.hasDocumentTimingDrafts || state.isEditingPage || state.isCreatingPage || isAgentChanging(state)))
|
|
331
363
|
const openComments = useWorkbenchState(state => Object.values(state.authoring?.content?.comments ?? {}).filter(comment => !comment.resolved && !comment.deletedAt).length)
|
|
332
364
|
const hasStep = useWorkbenchState(state => !state.authoring?.loading && Boolean(state.authoring?.content?.sectionOrder.length))
|
|
333
|
-
const narrow = useMediaQuery(NARROW)
|
|
334
365
|
const capabilities = workbench.client.capabilities
|
|
335
366
|
const compactCommands = narrow && !framed
|
|
336
367
|
const undoDisabled = Boolean(capabilities?.readOnly || !editorHistory?.undo && (editorHistory?.field || !history?.undo && !dirty) || busy)
|
|
337
368
|
const redoDisabled = Boolean(capabilities?.readOnly || !editorHistory?.redo && (editorHistory?.field || dirty || !history?.redo) || busy)
|
|
338
369
|
const commentsLabel = openComments ? `${t.comments} (${openComments})` : t.comments
|
|
370
|
+
const historyLabel = draftReadFailure ? `${t.versionHistory} · ${t.documentDraftUnreadable}` : draftCount ? t.historyWithDrafts(draftCount) : t.versionHistory
|
|
339
371
|
return (
|
|
340
|
-
<PmToolbar className={framed ? 'pmw-toolbar' : 'pmw-toolbar pmw-toolbar--document'} label={t.commands}>
|
|
372
|
+
<PmToolbar variant="workspace" className={framed ? 'pmw-toolbar' : 'pmw-toolbar pmw-toolbar--document'} label={t.commands}>
|
|
341
373
|
{!framed && <div className="pmw-toolbar__document">
|
|
342
374
|
<PmToolbarButton asChild><PmIconButton icon="arrow-left" label={t.back} small onClick={() => onBack ? onBack() : workbench.closeDocument()} /></PmToolbarButton>
|
|
343
375
|
<h1 className="pmw-toolbar__title" title={title}>{title}</h1>
|
|
@@ -350,11 +382,11 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
350
382
|
<SaveStatus />
|
|
351
383
|
<span className="pmw-spacer" />
|
|
352
384
|
{!narrow && <>
|
|
353
|
-
{capabilities?.production !== false && <PmToolbarButton asChild><PmButton small icon="arrange" loading={changingView} disabled={busy || !hasStep} onClick={onProduction}>{
|
|
385
|
+
{capabilities?.production !== false && <PmToolbarButton asChild><PmButton small icon="arrange" loading={changingView} disabled={busy || !hasStep} onClick={onProduction}>{t.video}</PmButton></PmToolbarButton>}
|
|
354
386
|
{capabilities?.narration !== false && <PmToolbarButton asChild><PmIconButton small icon="captions" label={t.documentNarration} hint={t.documentNarrationHint} aria-pressed={aside === 'narration'} disabled={!hasStep} onClick={() => onAside('narration')} /></PmToolbarButton>}
|
|
355
387
|
</>}
|
|
356
388
|
{!compactCommands && <PmToolbarButton asChild><PmIconButton small icon="comment" label={commentsLabel} aria-pressed={aside === 'comments'} onClick={() => onAside('comments')} /></PmToolbarButton>}
|
|
357
|
-
{!narrow && <PmToolbarButton asChild><PmIconButton small icon="versions" label={
|
|
389
|
+
{!narrow && <span className="pmw-toolbar__history"><PmToolbarButton asChild><PmIconButton small icon="versions" label={historyLabel} aria-pressed={aside === 'history'} onClick={() => onAside('history')} /></PmToolbarButton>{(draftCount > 0 || draftReadFailure) && <PmBadge tone={draftReadFailure ? 'warn' : 'neutral'}>{draftCount || <PmIcon name="warning" />}</PmBadge>}</span>}
|
|
358
390
|
<span className="pmw-toolbar__divider" aria-hidden="true" />
|
|
359
391
|
<PmToolbarButton asChild><PmIconButton small icon="eye" label={t.readDocument} disabled={blocked || changingView} onClick={onRead} /></PmToolbarButton>
|
|
360
392
|
<PmToolbarButton asChild><PmIconButton ref={presentButton} small icon="slides" label={t.present} hint={preparing || changingView ? t.presentationPreparing : timingDrafts ? t.timingDraftPending : blocked ? t.presentationPending : t.presentHint} loading={preparing || changingView} disabled={blocked || changingView} onClick={onPresent} /></PmToolbarButton>
|
|
@@ -368,7 +400,7 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
368
400
|
] : [],
|
|
369
401
|
...capabilities?.production !== false ? [{ id: 'production', label: p.title, icon: 'arrange' as const, disabled: busy || !hasStep || changingView }] : [],
|
|
370
402
|
...capabilities?.narration !== false ? [{ id: 'narration', label: t.documentNarration, icon: 'captions' as const, disabled: !hasStep }] : [],
|
|
371
|
-
{ id: 'history', label:
|
|
403
|
+
{ id: 'history', label: historyLabel, icon: 'versions' },
|
|
372
404
|
]} onSelect={id => { if (id === 'undo') void workbench.undo(); else if (id === 'redo') void workbench.redo(); else if (id === 'production') onProduction(); else onAside(id as DocumentAside) }} />}
|
|
373
405
|
</PmToolbar>
|
|
374
406
|
)
|
|
@@ -409,10 +441,8 @@ function DocumentNotices() {
|
|
|
409
441
|
const askFailure = useWorkbenchState(state => (state.pointer ? undefined : state.askFailure))
|
|
410
442
|
return (
|
|
411
443
|
<div className="pmw-notices">
|
|
412
|
-
{review?.running && <PmNotice tone="accent"><PmMascot size="small" action={review.changes.length > 0 ? 'write' : 'read'} />{t.agentWorking}</PmNotice>}
|
|
413
444
|
{review && !review.running && review.changes.length > 0 && (
|
|
414
445
|
<PmNotice tone="accent">
|
|
415
|
-
<PmMascot size="small" action="ask" />
|
|
416
446
|
<span>{t.agentWaiting(review.changes.length)}</span>
|
|
417
447
|
<span className="pmw-notice__actions">
|
|
418
448
|
<PmButton small onClick={() => void workbench.rejectReview()}>{t.reject}</PmButton>
|
|
@@ -431,7 +461,7 @@ function DocumentNotices() {
|
|
|
431
461
|
)
|
|
432
462
|
}
|
|
433
463
|
|
|
434
|
-
/**
|
|
464
|
+
/** The document's problems in one line above the page, with the AI to fix them; the list itself opens in a dialog. */
|
|
435
465
|
function ProblemsNotice() {
|
|
436
466
|
const t = useMessages()
|
|
437
467
|
const workbench = useWorkbench()
|
|
@@ -440,23 +470,25 @@ function ProblemsNotice() {
|
|
|
440
470
|
const canRepair = useWorkbenchState(state => state.canRepairDiagnostics)
|
|
441
471
|
const repairing = useWorkbenchState(state => state.isRepairingDiagnostics)
|
|
442
472
|
const repairFailure = useWorkbenchState(state => state.diagnosticsRepairFailure)
|
|
473
|
+
const [open, setOpen] = useState(false)
|
|
443
474
|
if (workbench.client.capabilities?.diagnostics === 'none') return null
|
|
444
475
|
const problems = (snapshot?.diagnostics ?? []).filter(diagnostic => diagnostic.severity === 'error' && !diagnostic.checkId.startsWith('presmium.workbench.'))
|
|
445
476
|
if (unavailable) return <PmNotice tone="warn"><span>{t.diagnosticsUnavailable}</span><PmButton small onClick={() => workbench.retryDiagnostics()}>{t.retry}</PmButton></PmNotice>
|
|
446
477
|
if (problems.length === 0) return repairFailure ? <PmNotice tone="danger">{t.fixFailed(failureReason(t, repairFailure))}</PmNotice> : null
|
|
478
|
+
const repair = canRepair && <PmButton small variant="accent" icon="sparkle" disabled={repairing} onClick={() => void workbench.requestRepairDiagnostics()}>{repairing ? t.fixing : t.fixWithAi}</PmButton>
|
|
447
479
|
return (
|
|
448
480
|
<PmNotice tone="warn">
|
|
449
481
|
<div className="pmw-problems">
|
|
450
482
|
<div className="pmw-problems__summary">
|
|
451
483
|
<span>{t.problems(problems.length)}</span>
|
|
452
|
-
|
|
484
|
+
<PmButton small variant="ghost" onClick={() => setOpen(true)}>{t.details}</PmButton>
|
|
485
|
+
{repair}
|
|
453
486
|
</div>
|
|
454
487
|
{repairFailure && <p className="pmw-problems__failure">{t.fixFailed(failureReason(t, repairFailure))}</p>}
|
|
455
|
-
<details className="pmw-problems__details">
|
|
456
|
-
<summary>{t.details}</summary>
|
|
457
|
-
<ul>{problems.map(problem => <li key={problem.id}>{problem.message}</li>)}</ul>
|
|
458
|
-
</details>
|
|
459
488
|
</div>
|
|
489
|
+
<PmDialog open={open} label={t.problemsTitle} closeLabel={t.close} actions={repair || undefined} onClose={() => setOpen(false)}>
|
|
490
|
+
<ul className="pmw-problems__list">{problems.map(problem => <li key={problem.id}><p>{problem.message}</p>{problem.hint && <p className="pmw-problems__hint">{problem.hint}</p>}</li>)}</ul>
|
|
491
|
+
</PmDialog>
|
|
460
492
|
</PmNotice>
|
|
461
493
|
)
|
|
462
494
|
}
|
|
@@ -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
|
: (
|