@lincyaw/workbench 0.2.0-rc.53 → 0.2.0-rc.55
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 +4 -4
- package/src/MediaClipEditor.tsx +3 -2
- package/src/approvals.tsx +6 -1
- package/src/components.tsx +12 -3
- package/src/context.tsx +3 -2
- package/src/document-editor/DocumentComments.tsx +27 -5
- package/src/document-editor/NewCommentDrafts.tsx +111 -29
- package/src/document-editor/PlaceComment.tsx +97 -19
- 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 +57 -11
- package/src/document-production.ts +28 -2
- package/src/media-drafts.ts +43 -1
- package/src/panels/DocumentVoiceDialog.tsx +23 -7
- package/src/panels/ProductionMediaClips.tsx +17 -2
- package/src/voice-drafts.ts +32 -8
- package/src/workbench.ts +2 -2
|
@@ -4,7 +4,7 @@ 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'
|
|
@@ -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)) }
|
|
@@ -87,7 +103,7 @@ export function DocumentVoiceDialog({ stepId, onClose }: { stepId: string, onClo
|
|
|
87
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>}
|
|
@@ -4,7 +4,7 @@ import { randomUUID } from '@lincyaw/kernel'
|
|
|
4
4
|
import { MediaClipEditor } from '../MediaClipEditor.tsx'
|
|
5
5
|
import type { MediaClipDraft } from '../MediaClipEditor.tsx'
|
|
6
6
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
7
|
-
import {
|
|
7
|
+
import { mediaDraftStorageFailed, readMediaDrafts } from '../media-drafts.ts'
|
|
8
8
|
import type { MediaDrafts } from '../media-drafts.ts'
|
|
9
9
|
import { MEDIA_MESSAGES, mediaFailure } from '../media-messages.ts'
|
|
10
10
|
|
|
@@ -42,9 +42,23 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
42
42
|
snapshot.current = draft; selected.current = key; latest.current = session
|
|
43
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 }))
|
|
44
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])
|
|
45
59
|
const remember = (value: MediaDrafts) => {
|
|
46
60
|
latest.current = value; setSession(value)
|
|
47
|
-
setStorageFailed(!keepMediaDrafts(
|
|
61
|
+
setStorageFailed(!workbench.production.keepMediaDrafts(identity, stepId, value))
|
|
48
62
|
}
|
|
49
63
|
const edit = (value: MediaClipDraft) => {
|
|
50
64
|
owner.current.revision++; setFailure(undefined); setStatus(undefined)
|
|
@@ -138,6 +152,7 @@ export function ProductionMediaClips({ identity, version, document, sectionId, s
|
|
|
138
152
|
return <MediaClipEditor locale={locale} assets={assets} clips={clips} selectedClipId={selectedClipId} draft={draft} inspection={inspectCurrent} stepDurationMs={stepDurationMs}
|
|
139
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)}
|
|
140
154
|
failure={failure} storageFailed={storageFailed} status={status} retryImport={retryImport}
|
|
155
|
+
onInteraction={value => { if (value === interacting.current) return; interacting.current = value; workbench.refreshAuthoringClientControls() }}
|
|
141
156
|
onEditStart={pause} onChange={edit} onImport={value => void importAudio(value)} onRetryImport={() => { if (file.current) void importAudio(file.current) }}
|
|
142
157
|
onRead={() => { setFailure(undefined); setInspection(undefined); setReload(value => value + 1) }}
|
|
143
158
|
onReview={() => { if (inspectCurrent && (!draft.baseClip || canonical)) edit({ ...draft, version, ...canonical ? { baseClip: structuredClone(canonical) } : {} }) }}
|
package/src/voice-drafts.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { WorkspaceClient } from './workspace-client.ts'
|
|
|
5
5
|
|
|
6
6
|
export interface VoiceDraft { version: string, scope: DocumentVoiceScope, source: VoiceSource | null, replaceOverrides: boolean, rateInput?: string }
|
|
7
7
|
export type VoiceDraftStorageStatus = 'available' | 'unavailable' | 'corrupt'
|
|
8
|
-
interface StoredDraft { draft?: VoiceDraft, status: VoiceDraftStorageStatus, unreadable?: string }
|
|
8
|
+
interface StoredDraft { draft?: VoiceDraft, status: VoiceDraftStorageStatus, unreadable?: string, raw?: string | null }
|
|
9
9
|
const drafts = new WeakMap<WorkspaceClient, Map<string, StoredDraft>>()
|
|
10
10
|
const keyOf = (identity: string, stepId: string) => JSON.stringify([identity, stepId])
|
|
11
11
|
const storageKey = (key: string) => `presmium.voice-draft.v2:${key}`
|
|
@@ -36,6 +36,7 @@ function load(client: WorkspaceClient, key: string): StoredDraft {
|
|
|
36
36
|
known.set(key, entry)
|
|
37
37
|
try {
|
|
38
38
|
const raw = sessionStorage.getItem(storageKey(key))
|
|
39
|
+
entry.raw = raw
|
|
39
40
|
if (raw !== null) {
|
|
40
41
|
entry.unreadable = raw
|
|
41
42
|
const value: unknown = JSON.parse(raw)
|
|
@@ -64,7 +65,9 @@ export function keepVoiceDraft(client: WorkspaceClient, identity: string, stepId
|
|
|
64
65
|
entry.draft = structuredClone(value)
|
|
65
66
|
try {
|
|
66
67
|
if (entry.unreadable !== undefined) sessionStorage.setItem(`${storageKey(key)}:unreadable`, entry.unreadable)
|
|
67
|
-
|
|
68
|
+
const raw = JSON.stringify(entry.draft)
|
|
69
|
+
sessionStorage.setItem(storageKey(key), raw)
|
|
70
|
+
entry.raw = raw
|
|
68
71
|
entry.status = 'available'; delete entry.unreadable
|
|
69
72
|
return true
|
|
70
73
|
} catch { entry.status = 'unavailable'; return false }
|
|
@@ -76,14 +79,35 @@ export function clearVoiceDraft(client: WorkspaceClient, identity: string, stepI
|
|
|
76
79
|
if (expected && JSON.stringify(entry.draft) !== JSON.stringify(expected)) return false
|
|
77
80
|
try {
|
|
78
81
|
const raw = sessionStorage.getItem(storageKey(key))
|
|
79
|
-
if (expected && raw !==
|
|
80
|
-
let persisted: unknown
|
|
81
|
-
try { persisted = JSON.parse(raw) } catch { entry.status = 'corrupt'; entry.unreadable = raw; return false }
|
|
82
|
-
if (!valid(persisted)) { entry.status = 'corrupt'; entry.unreadable = raw; return false }
|
|
83
|
-
if (JSON.stringify(persisted) !== JSON.stringify(expected)) return false
|
|
84
|
-
}
|
|
82
|
+
if (expected && (entry.unreadable !== undefined || raw !== entry.raw)) return false
|
|
85
83
|
sessionStorage.removeItem(storageKey(key))
|
|
84
|
+
entry.raw = null
|
|
86
85
|
delete entry.draft; delete entry.unreadable; entry.status = 'available'
|
|
87
86
|
return true
|
|
88
87
|
} catch { entry.status = 'unavailable'; return false }
|
|
89
88
|
}
|
|
89
|
+
|
|
90
|
+
/** Enumerate this native bank, including offscreen forms; callers receive no second persisted copy. */
|
|
91
|
+
export function voiceDraftSnapshot(client: WorkspaceClient, identity: string): { entries: { stepId: string, value: VoiceDraft, persisted: boolean }[], partial: boolean } {
|
|
92
|
+
const keys = new Set([...store(client).keys()].filter(key => key.startsWith(`${JSON.stringify([identity]).slice(0, -1)},`)))
|
|
93
|
+
let partial = false
|
|
94
|
+
try {
|
|
95
|
+
const prefix = `presmium.voice-draft.v2:${JSON.stringify([identity]).slice(0, -1)},`
|
|
96
|
+
for (let index = 0; index < sessionStorage.length; index++) {
|
|
97
|
+
const key = sessionStorage.key(index)
|
|
98
|
+
if (key?.startsWith(prefix) && !key.endsWith(':unreadable')) keys.add(key.slice('presmium.voice-draft.v2:'.length))
|
|
99
|
+
}
|
|
100
|
+
} catch { partial = true }
|
|
101
|
+
const entries: { stepId: string, value: VoiceDraft, persisted: boolean }[] = []
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
let target: unknown
|
|
104
|
+
try { target = JSON.parse(key) } catch { partial = true; continue }
|
|
105
|
+
if (!Array.isArray(target) || target.length !== 2 || target[0] !== identity || typeof target[1] !== 'string') { partial = true; continue }
|
|
106
|
+
const entry = load(client, key)
|
|
107
|
+
let persisted = false
|
|
108
|
+
try { const raw = sessionStorage.getItem(storageKey(key)); persisted = entry.status === 'available' && raw === entry.raw; if (raw !== entry.raw) partial = true } catch { partial = true }
|
|
109
|
+
if (entry.status === 'corrupt' || entry.raw === undefined) partial = true
|
|
110
|
+
if (entry.draft) entries.push({ stepId: target[1], value: structuredClone(entry.draft), persisted })
|
|
111
|
+
}
|
|
112
|
+
return { entries, partial }
|
|
113
|
+
}
|
package/src/workbench.ts
CHANGED
|
@@ -870,7 +870,7 @@ export class Workbench {
|
|
|
870
870
|
...bodyDrafts.mutate && !locked && !state.isCreatingPage && !state.isEditingPage && !state.isHistoryBusy && !state.isHistoryPreparing && !state.hasDocumentTimingDrafts
|
|
871
871
|
? ['body-drafts.restore' as const, 'body-drafts.discard' as const, ...bodyDrafts.current ? ['body-drafts.retry' as const] : []] : [],
|
|
872
872
|
...commentDrafts?.readable ? ['comment-drafts.inspect' as const, 'comment-drafts.read' as const] : [],
|
|
873
|
-
...clean && !state.isHistoryBusy && !state.isHistoryPreparing && commentDrafts?.readable && commentDrafts.ownersKnown ? ['comment-drafts.discard' as const, ...state.webView === 'document' && commentDrafts.hasRestoreComposer() ? ['comment-drafts.restore' as const] : []] : [],
|
|
873
|
+
...this.client.capabilities?.readOnly !== true && clean && !state.isHistoryBusy && !state.isHistoryPreparing && commentDrafts?.readable && commentDrafts.ownersKnown ? ['comment-drafts.discard' as const, ...state.webView === 'document' && commentDrafts.hasRestoreComposer() ? ['comment-drafts.restore' as const] : []] : [],
|
|
874
874
|
...source.member?.id && this.#componentPropertyDrafts.readable(source.identity, source.member.id) ? ['component-drafts.inspect' as const, 'component-drafts.read' as const] : [],
|
|
875
875
|
...clean && !state.isHistoryBusy && !state.isHistoryPreparing && source.member?.id && this.#componentPropertyDrafts.readable(source.identity, source.member.id) ? ['component-drafts.restore' as const, 'component-drafts.discard' as const] : [],
|
|
876
876
|
...this.#canPreparePresentation() ? ['preview.prepare' as const] : [],
|
|
@@ -924,7 +924,7 @@ export class Workbench {
|
|
|
924
924
|
const guard = () => {
|
|
925
925
|
owned()
|
|
926
926
|
const state = this.#state, source = state.authoring
|
|
927
|
-
if (!source?.content || source.member?.id !== memberId || !source.version || !source.fingerprint
|
|
927
|
+
if (this.client.capabilities?.readOnly === true || !source?.content || source.member?.id !== memberId || !source.version || !source.fingerprint
|
|
928
928
|
|| !sameSource({ documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, expected)
|
|
929
929
|
|| source.loading || source.dirty || source.saving || source.composing || source.restored || source.recovering || source.error || isAgentChanging(state)
|
|
930
930
|
|| state.isCreatingPage || state.isEditingPage || state.isHistoryBusy || state.isHistoryPreparing || state.hasDocumentTimingDrafts
|