@lincyaw/workbench 0.2.0-rc.10 → 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
package/src/media-drafts.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { MediaClipDraft } from './MediaClipEditor.tsx'
|
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
5
|
|
|
6
6
|
export interface MediaDrafts { selectedClipId?: string, entries: Record<string, MediaClipDraft> }
|
|
7
|
-
interface Entry { value: MediaDrafts, failed: boolean, volatile: boolean, unreadable?: string }
|
|
7
|
+
interface Entry { value: MediaDrafts, failed: boolean, volatile: boolean, unreadable?: string, raw?: string | null }
|
|
8
8
|
const memory = new WeakMap<WorkspaceClient, Map<string, Entry>>()
|
|
9
9
|
const prefix = 'presmium.media-drafts.v1:', limit = 64
|
|
10
10
|
const keyOf = (identity: string, stepId: string) => prefix + JSON.stringify([identity, stepId])
|
|
@@ -38,6 +38,7 @@ function load(client: WorkspaceClient, key: string): Entry {
|
|
|
38
38
|
const entry: Entry = { value: { entries: {} }, failed: false, volatile: false }
|
|
39
39
|
try {
|
|
40
40
|
const raw = sessionStorage.getItem(key)
|
|
41
|
+
entry.raw = raw
|
|
41
42
|
if (raw !== null) {
|
|
42
43
|
entry.unreadable = raw
|
|
43
44
|
if (raw.length > 131072) throw new Error('media-drafts-size')
|
|
@@ -68,6 +69,7 @@ export function keepMediaDrafts(client: WorkspaceClient, identity: string, stepI
|
|
|
68
69
|
if (raw.length > 131072) throw new Error('media-drafts-size')
|
|
69
70
|
if (entry.unreadable !== undefined) sessionStorage.setItem(`${key}:unreadable`, entry.unreadable)
|
|
70
71
|
sessionStorage.setItem(key, raw)
|
|
72
|
+
entry.raw = raw
|
|
71
73
|
const keys = Array.from({ length: sessionStorage.length }, (_, index) => sessionStorage.key(index)!).filter(name => name.startsWith(prefix) && !name.endsWith(':unreadable') && name !== key)
|
|
72
74
|
let excess = keys.length - limit + 1
|
|
73
75
|
for (const old of keys) {
|
|
@@ -81,3 +83,43 @@ export function keepMediaDrafts(client: WorkspaceClient, identity: string, stepI
|
|
|
81
83
|
return true
|
|
82
84
|
} catch { entry.failed = true; trim(known); return false }
|
|
83
85
|
}
|
|
86
|
+
|
|
87
|
+
/** This is the same step/form bank used when the author reopens Media, including session-only input. */
|
|
88
|
+
export function mediaDraftSnapshot(client: WorkspaceClient, identity: string): { entries: { stepId: string, value: MediaDrafts, persisted: boolean }[], partial: boolean } {
|
|
89
|
+
const scoped = `${prefix}${JSON.stringify([identity]).slice(0, -1)},`
|
|
90
|
+
const keys = new Set([...store(client).keys()].filter(key => key.startsWith(scoped)))
|
|
91
|
+
let partial = false
|
|
92
|
+
try {
|
|
93
|
+
for (let index = 0; index < sessionStorage.length; index++) {
|
|
94
|
+
const key = sessionStorage.key(index)
|
|
95
|
+
if (key?.startsWith(scoped) && !key.endsWith(':unreadable')) keys.add(key)
|
|
96
|
+
}
|
|
97
|
+
} catch { partial = true }
|
|
98
|
+
const entries: { stepId: string, value: MediaDrafts, persisted: boolean }[] = []
|
|
99
|
+
for (const key of keys) {
|
|
100
|
+
let target: unknown
|
|
101
|
+
try { target = JSON.parse(key.slice(prefix.length)) } catch { partial = true; continue }
|
|
102
|
+
if (!Array.isArray(target) || target.length !== 2 || target[0] !== identity || typeof target[1] !== 'string') { partial = true; continue }
|
|
103
|
+
const entry = load(client, key)
|
|
104
|
+
let persisted = false
|
|
105
|
+
try { const raw = sessionStorage.getItem(key); persisted = !entry.failed && raw === entry.raw; if (raw !== entry.raw) partial = true } catch { partial = true }
|
|
106
|
+
if (entry.unreadable !== undefined || entry.raw === undefined) partial = true
|
|
107
|
+
if (Object.keys(entry.value.entries).length) entries.push({ stepId: target[1], value: structuredClone(entry.value), persisted })
|
|
108
|
+
}
|
|
109
|
+
return { entries, partial }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Retire one exact clip proposal, preserving sibling forms and any independently changed storage. */
|
|
113
|
+
export function discardMediaDraft(client: WorkspaceClient, identity: string, stepId: string, name: string, expected: MediaDrafts): boolean {
|
|
114
|
+
const key = keyOf(identity, stepId), entry = load(client, key)
|
|
115
|
+
if (!Object.hasOwn(expected.entries, name) || JSON.stringify(entry.value) !== JSON.stringify(expected)) return false
|
|
116
|
+
try {
|
|
117
|
+
if (entry.raw === undefined || entry.unreadable !== undefined || sessionStorage.getItem(key) !== entry.raw) return false
|
|
118
|
+
const next = structuredClone(entry.value)
|
|
119
|
+
delete next.entries[name]
|
|
120
|
+
const raw = JSON.stringify(next)
|
|
121
|
+
sessionStorage.setItem(key, raw)
|
|
122
|
+
entry.value = next; entry.raw = raw; entry.failed = false; entry.volatile = false
|
|
123
|
+
return true
|
|
124
|
+
} catch { entry.failed = true; return false }
|
|
125
|
+
}
|
package/src/messages.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface AgentPlace {
|
|
|
12
12
|
|
|
13
13
|
// A Latin word or a number set after Chinese text is spaced from it (docs/glossary.md 2).
|
|
14
14
|
const spaced = (text: string) => (/^[A-Za-z0-9]/.test(text) ? ` ${text}` : text)
|
|
15
|
+
// The start of a passage, enough to recognize it.
|
|
16
|
+
const excerpt = (text: string, length: number) => [...text].length > length ? `${[...text].slice(0, length).join('').trimEnd()}…` : text
|
|
17
|
+
|
|
18
|
+
/** Where on a page the author asks for new content: after a passage (its text, '' for content without text), at the start (none) or at the end. */
|
|
19
|
+
interface AgentInsertion { after?: string, end: boolean }
|
|
15
20
|
|
|
16
21
|
// Names of commands follow Microsoft Word's (撤消/Undo, 新建批注/New Comment, 版本历史/Version History…).
|
|
17
22
|
const zh = {
|
|
@@ -106,14 +111,13 @@ const zh = {
|
|
|
106
111
|
narrationAutosave: '自动保存;切换步骤会保留未完成的草稿。',
|
|
107
112
|
narrationDiscard: '放弃草稿',
|
|
108
113
|
narrationRecoveryUnavailable: '浏览器无法在本机保留草稿。草稿仍在本次会话中,请保存后再关闭窗口。',
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
documentDrafts: '本地草稿',
|
|
115
|
+
documentDraftName: (index: number) => `草稿 ${index}`,
|
|
116
|
+
documentDraftDiscardAll: '全部放弃',
|
|
112
117
|
documentDraftRestore: '恢复草稿',
|
|
113
|
-
documentDraftChanged: '
|
|
118
|
+
documentDraftChanged: '本地草稿已更新,请查看最新列表。',
|
|
114
119
|
documentDraftUnreadable: '部分本地草稿无法读取。',
|
|
115
120
|
documentDraftBackingUp: '正在备份…',
|
|
116
|
-
documentDraftOption: (index: number, date: string, source: 'durable' | 'rescue') => `${date} · ${source === 'rescue' ? '临时副本' : '草稿'} ${index}`,
|
|
117
121
|
narrationCompositionInterrupted: '输入法组字未完成,草稿已保留。请检查文字后保存或继续编辑。',
|
|
118
122
|
narrationRefresh: '讲稿已写入,但画面尚未完成更新。草稿已保留,请等待预览恢复后重试。',
|
|
119
123
|
narrationDuring: '与动画同步',
|
|
@@ -241,6 +245,8 @@ const zh = {
|
|
|
241
245
|
formattedEdit: '这一处带有格式或特殊内容,不能直接修改文字。要用 AI 改写吗?',
|
|
242
246
|
rewriteEdit: '用 AI 改写',
|
|
243
247
|
versionHistory: '版本历史',
|
|
248
|
+
historyWithDrafts: (count: number) => `版本历史(${count} 份本地草稿)`,
|
|
249
|
+
historySavedVersions: '已保存版本',
|
|
244
250
|
historyNewer: '较新版本',
|
|
245
251
|
historyOlder: '更早版本',
|
|
246
252
|
exportPane: '导出',
|
|
@@ -325,11 +331,11 @@ const zh = {
|
|
|
325
331
|
'history-result-no-longer-current': '之前的结果已不是当前版本,请查看最新的历史。',
|
|
326
332
|
'authoring-review-required': '有修改等待你审阅,请先接受或放弃。',
|
|
327
333
|
} as Record<string, string>,
|
|
328
|
-
agentWorking: 'AI 正在修改文稿…',
|
|
329
334
|
agentWaiting: (n: number) => `AI 修改了 ${n} 处内容,要接受这些修改吗?`,
|
|
330
335
|
accept: '接受',
|
|
331
336
|
reject: '拒绝',
|
|
332
|
-
problems: (n: number) =>
|
|
337
|
+
problems: (n: number) => `文稿有 ${n} 个问题需要处理。`,
|
|
338
|
+
problemsTitle: '文稿中的问题',
|
|
333
339
|
fixWithAi: '用 AI 修复',
|
|
334
340
|
fixing: '正在发送给 AI…',
|
|
335
341
|
fixFailed: (reason: string) => `无法发送给 AI。${reason}`,
|
|
@@ -356,6 +362,11 @@ const zh = {
|
|
|
356
362
|
place.quote ? `\n原文:“${place.quote}”` : '',
|
|
357
363
|
].join('')).filter(Boolean),
|
|
358
364
|
].join('\n\n'),
|
|
365
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
366
|
+
const at = `第 ${page} 页${title ? `“${title}”` : ''}`
|
|
367
|
+
return place.end ? `在${at}的末尾加一个动画:` : place.after === undefined ? `在${at}的开头加一个动画:`
|
|
368
|
+
: place.after ? `在${at}中“${excerpt(place.after, 16)}”这一段之后加一个动画:` : `在${at}的这个位置加一个动画:`
|
|
369
|
+
},
|
|
359
370
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
360
371
|
comments.length === 1 ? '我在文稿上写了一条批注:' : `我在文稿上写了 ${comments.length} 条批注:`,
|
|
361
372
|
...comments.map((comment, i) => [
|
|
@@ -470,14 +481,13 @@ const en: WorkbenchMessages = {
|
|
|
470
481
|
narrationAutosave: 'Saved automatically. Switching steps keeps unfinished drafts.',
|
|
471
482
|
narrationDiscard: 'Discard Draft',
|
|
472
483
|
narrationRecoveryUnavailable: 'This browser can’t keep drafts on this device. Your draft stays in this session; save before closing the window.',
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
484
|
+
documentDrafts: 'Local Drafts',
|
|
485
|
+
documentDraftName: (index: number) => `Draft ${index}`,
|
|
486
|
+
documentDraftDiscardAll: 'Discard All',
|
|
476
487
|
documentDraftRestore: 'Recover Draft',
|
|
477
|
-
documentDraftChanged: '
|
|
488
|
+
documentDraftChanged: 'Drafts on this device changed. Check the updated list.',
|
|
478
489
|
documentDraftUnreadable: 'Couldn’t read some drafts on this device.',
|
|
479
490
|
documentDraftBackingUp: 'Backing up…',
|
|
480
|
-
documentDraftOption: (index: number, date: string, source: 'durable' | 'rescue') => `${date} · ${source === 'rescue' ? 'Temporary copy' : 'Draft'} ${index}`,
|
|
481
491
|
narrationCompositionInterrupted: 'Typing with the input method was interrupted. Your draft is kept; review it before saving, or keep editing.',
|
|
482
492
|
narrationRefresh: 'The script was written, but the preview has not updated yet. Your draft is kept; retry after the preview recovers.',
|
|
483
493
|
narrationDuring: 'During animation',
|
|
@@ -605,6 +615,8 @@ const en: WorkbenchMessages = {
|
|
|
605
615
|
formattedEdit: 'This text has formatting or special content and can’t be edited directly. Rewrite it with AI?',
|
|
606
616
|
rewriteEdit: 'Rewrite with AI',
|
|
607
617
|
versionHistory: 'Version History',
|
|
618
|
+
historyWithDrafts: (count: number) => `Version History (${count} local ${count === 1 ? 'draft' : 'drafts'})`,
|
|
619
|
+
historySavedVersions: 'Saved Versions',
|
|
608
620
|
historyNewer: 'Newer versions',
|
|
609
621
|
historyOlder: 'Older versions',
|
|
610
622
|
exportPane: 'Export',
|
|
@@ -689,11 +701,11 @@ const en: WorkbenchMessages = {
|
|
|
689
701
|
'history-result-no-longer-current': 'The earlier result is no longer the current version. Review the latest history.',
|
|
690
702
|
'authoring-review-required': 'Changes are waiting for your review. Accept or discard them first.',
|
|
691
703
|
},
|
|
692
|
-
agentWorking: 'The AI is editing the document…',
|
|
693
704
|
agentWaiting: (n: number) => `The AI changed ${n} file${n === 1 ? '' : 's'}. Accept the changes?`,
|
|
694
705
|
accept: 'Accept',
|
|
695
706
|
reject: 'Reject',
|
|
696
|
-
problems: (n: number) =>
|
|
707
|
+
problems: (n: number) => `The document has ${n} problem${n === 1 ? '' : 's'} to fix.`,
|
|
708
|
+
problemsTitle: 'Problems in the Document',
|
|
697
709
|
fixWithAi: 'Fix with AI',
|
|
698
710
|
fixing: 'Sending to the AI…',
|
|
699
711
|
fixFailed: (reason: string) => `Couldn’t send to the AI. ${reason}`,
|
|
@@ -720,6 +732,11 @@ const en: WorkbenchMessages = {
|
|
|
720
732
|
place.quote ? `\nText: “${place.quote}”` : '',
|
|
721
733
|
].join('')).filter(Boolean),
|
|
722
734
|
].join('\n\n'),
|
|
735
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
736
|
+
const at = `page ${page}${title ? `, “${title}”` : ''}`
|
|
737
|
+
return place.end ? `Add an animation at the end of ${at}: ` : place.after === undefined ? `Add an animation at the start of ${at}: `
|
|
738
|
+
: place.after ? `Add an animation on ${at}, after the paragraph “${excerpt(place.after, 40)}”: ` : `Add an animation at this point on ${at}: `
|
|
739
|
+
},
|
|
723
740
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
724
741
|
comments.length === 1 ? 'I left a comment on the document:' : `I left ${comments.length} comments on the document:`,
|
|
725
742
|
...comments.map((comment, i) => [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useId } from 'react'
|
|
2
|
-
import { PmEmpty, PmIconButton } from '../components.tsx'
|
|
2
|
+
import { PmEmpty, PmIconButton, PmPanelHeader } from '../components.tsx'
|
|
3
3
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
4
4
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ export function DocumentNarrationPanel({ onClose }: { onClose(): void }) {
|
|
|
18
18
|
}
|
|
19
19
|
useEffect(() => { pause() }, [workbench, source?.identity])
|
|
20
20
|
return <section className="pmw-pane" aria-labelledby={panelId}>
|
|
21
|
-
<
|
|
21
|
+
<PmPanelHeader className="pmw-pane__header" titleId={panelId} title={t.documentNarration} actions={<PmIconButton small icon="close" label={t.close} onClick={onClose} />} />
|
|
22
22
|
{section && sectionId && stepId ? <>
|
|
23
23
|
<p className="pmw-pane__footer">{section.title}</p>
|
|
24
24
|
<DocumentStepNarration sectionId={sectionId} stepId={stepId} expanded showLabel={false} panelId={`${panelId}-fields`} onPause={pause} />
|
|
@@ -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' : 'document')
|
|
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,14 +207,16 @@ 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
221
|
workbench.setWebView('document')
|
|
191
222
|
setWorkspace('reading')
|
|
@@ -193,15 +224,15 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
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>
|
|
@@ -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
|
}
|
|
@@ -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>
|
|
@@ -354,7 +386,7 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
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
|
}
|