@lincyaw/workbench 0.2.0-rc.93 → 0.2.0-rc.94
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/AgentActivityBar.tsx +25 -0
- package/src/agent-activity-messages.ts +14 -0
- package/src/agent-activity.ts +38 -0
- package/src/components.tsx +12 -5
- package/src/container-layout.ts +21 -0
- package/src/document-editor/DocumentEditor.tsx +12 -0
- package/src/document-editor/DocumentStepNarration.tsx +4 -1
- package/src/document-editor/agent-targets.ts +34 -0
- package/src/index.ts +2 -0
- package/src/panels/DocumentNarrationPanel.tsx +2 -2
- package/src/panels/DocumentView.tsx +23 -35
- package/src/panels/ExportPanel.tsx +2 -5
- package/src/panels/HistoryPanel.tsx +2 -5
- package/src/panels/HomePanel.tsx +3 -1
- package/src/panels/ProductionPanel.tsx +8 -9
- package/src/panels/SourceDocumentPanel.tsx +4 -2
- package/src/styles.css +23 -37
- package/src/workbench-state.ts +2 -0
- package/src/workbench.ts +36 -0
- package/src/workspace-client.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workbench",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.94",
|
|
4
4
|
"description": "Presmium's workbench panels in React (the documents, a document edited on its rendered page with comments and version history) with the workspace service's client and the preview protocol's workbench side; @lincyaw/dsh places them in presmium studio (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@tiptap/pm": "3.32.0",
|
|
56
56
|
"katex": "0.18.10",
|
|
57
57
|
"react-resizable-panels": "4.14.5",
|
|
58
|
-
"@lincyaw/
|
|
59
|
-
"@lincyaw/
|
|
58
|
+
"@lincyaw/design": "1.0.0-rc.94",
|
|
59
|
+
"@lincyaw/kernel": "1.0.0-rc.94"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": "^18.3.1",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"@types/react-dom": "18.3.7",
|
|
68
68
|
"react": "^18.3.1",
|
|
69
69
|
"react-dom": "^18.3.1",
|
|
70
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
70
|
+
"@lincyaw/compiler": "1.0.0-rc.94"
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PmAgentActivity, PmIconButton, PmTooltip } from './components.tsx'
|
|
2
|
+
import { useWorkbench, useWorkbenchState } from './context.tsx'
|
|
3
|
+
import { latestAgentActivity } from './agent-activity.ts'
|
|
4
|
+
import { AGENT_ACTIVITY_MESSAGES } from './agent-activity-messages.ts'
|
|
5
|
+
|
|
6
|
+
/** A compact presence row, not a second activity log or an editor lock. */
|
|
7
|
+
export function AgentActivityBar() {
|
|
8
|
+
const workbench = useWorkbench(), state = useWorkbenchState(value => value)
|
|
9
|
+
const activity = latestAgentActivity(state.agentActivities), t = AGENT_ACTIVITY_MESSAGES[state.locale]
|
|
10
|
+
if (!activity) return null
|
|
11
|
+
const title = state.documents?.documents.find(doc => doc.dir === activity.document)?.title
|
|
12
|
+
const content = state.document === activity.document ? state.authoring?.content : undefined, target = activity.targets[0]
|
|
13
|
+
const section = target?.section ?? (target?.step ? content?.steps[target.step]?.sectionId : undefined)
|
|
14
|
+
const page = section ? content?.sections[section]?.title : undefined
|
|
15
|
+
const location = [title, page].filter(Boolean).join(' · ')
|
|
16
|
+
const label = `${activity.state === 'running' ? t[activity.operation] : t[activity.state]}${location ? ` · ${location}` : ''}`
|
|
17
|
+
const count = state.agentActivities?.filter(value => value.state === 'running').length ?? 0
|
|
18
|
+
const detail = `${label}${count > 1 ? ` · ${t.concurrent(count)}` : ''}${!state.agentFollowing ? ` · ${t.paused}` : ''}`
|
|
19
|
+
const short = activity.state === 'running' ? t.compact[activity.operation] : t.compact[activity.state]
|
|
20
|
+
return <span className="pmw-agent-activity" data-agent-activity-controls="">
|
|
21
|
+
<PmTooltip label={detail}><span className="pmw-agent-activity__label"><PmAgentActivity compact state={activity.state} label={short} detail={detail} /></span></PmTooltip>
|
|
22
|
+
<PmIconButton small icon={state.agentFollowing ? 'pause' : 'fit'} label={state.agentFollowing ? t.pauseLabel : t.followLabel}
|
|
23
|
+
aria-pressed={Boolean(state.agentFollowing)} onClick={() => workbench.setAgentFollowing(!state.agentFollowing)} />
|
|
24
|
+
</span>
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const AGENT_ACTIVITY_MESSAGES = {
|
|
2
|
+
'zh-CN': {
|
|
3
|
+
compact: { read: '查看中', edit: '编辑中', navigate: '定位中', preview: '预览中', build: '构建中', voice: '配音中', workspace: '整理中', done: '已完成', failed: '失败', cancelled: '已取消' },
|
|
4
|
+
read: 'AI 助手正在查看', edit: 'AI 助手正在编辑', navigate: 'AI 助手正在定位', preview: 'AI 助手正在查看预览', build: 'AI 助手正在构建', voice: 'AI 助手正在处理配音', workspace: 'AI 助手正在整理工作区',
|
|
5
|
+
done: 'AI 助手已完成', failed: 'AI 助手操作失败', cancelled: 'AI 助手已取消', following: '正在跟随', resume: '跟随 AI 助手', paused: '跟随已暂停',
|
|
6
|
+
followLabel: '跟随 AI 助手的操作位置', pauseLabel: '暂停跟随 AI 助手', concurrent: (count: number) => `${count} 项操作进行中`,
|
|
7
|
+
},
|
|
8
|
+
en: {
|
|
9
|
+
compact: { read: 'Reading', edit: 'Editing', navigate: 'Locating', preview: 'Previewing', build: 'Building', voice: 'Voicing', workspace: 'Organizing', done: 'Done', failed: 'Failed', cancelled: 'Canceled' },
|
|
10
|
+
read: 'AI Assistant is reading', edit: 'AI Assistant is editing', navigate: 'AI Assistant is navigating', preview: 'AI Assistant is inspecting the preview', build: 'AI Assistant is building', voice: 'AI Assistant is working on voiceover', workspace: 'AI Assistant is updating the workspace',
|
|
11
|
+
done: 'AI Assistant finished', failed: 'AI Assistant operation failed', cancelled: 'AI Assistant canceled', following: 'Following', resume: 'Follow AI Assistant', paused: 'Following paused',
|
|
12
|
+
followLabel: 'Follow the AI Assistant’s location', pauseLabel: 'Pause following the AI Assistant', concurrent: (count: number) => `${count} operations running`,
|
|
13
|
+
},
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AgentActivity } from '@lincyaw/kernel'
|
|
2
|
+
import type { Workbench } from './workbench.ts'
|
|
3
|
+
|
|
4
|
+
export const latestAgentActivity = (activities: readonly AgentActivity[] = []) => [...activities].sort((a, b) => Number(b.state === 'running') - Number(a.state === 'running') || b.startedAt - a.startedAt)[0]
|
|
5
|
+
|
|
6
|
+
/** One root-lifetime subscription; reconnect resets observations, and human gestures always win navigation. */
|
|
7
|
+
export function connectAgentActivity(workbench: Workbench): () => void {
|
|
8
|
+
const subscribe = workbench.client.subscribeAgentActivity
|
|
9
|
+
if (!subscribe) return () => {}
|
|
10
|
+
let closed = false, followed: string | undefined, following: AbortController | undefined
|
|
11
|
+
let navigating: { document?: string, controller: AbortController } | undefined
|
|
12
|
+
workbench.setAgentFollowing(true)
|
|
13
|
+
const follow = () => {
|
|
14
|
+
if (closed || !workbench.state.agentFollowing) { following?.abort(); followed = undefined; return }
|
|
15
|
+
const activity = latestAgentActivity(workbench.state.agentActivities)
|
|
16
|
+
if (!activity || activity.id === followed) return
|
|
17
|
+
if (navigating && navigating.document === activity.document && !navigating.controller.signal.aborted) return
|
|
18
|
+
followed = activity.id; following?.abort(); following = new AbortController()
|
|
19
|
+
const task = { document: activity.document, controller: following }; navigating = task
|
|
20
|
+
void workbench.followAgentActivity(activity, following.signal).catch(() => {}).finally(() => {
|
|
21
|
+
if (navigating === task) { navigating = undefined; follow() }
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
const stop = subscribe(snapshot => { if (!closed) { workbench.setAgentActivities(snapshot.activities); follow() } }, () => {
|
|
25
|
+
following?.abort(); followed = undefined; workbench.setAgentActivities([])
|
|
26
|
+
})
|
|
27
|
+
const stopState = workbench.subscribe(follow)
|
|
28
|
+
const interrupt = (event: Event) => {
|
|
29
|
+
if (!workbench.state.agentActivities?.length || event.target instanceof Element && event.target.closest('[data-agent-activity-controls]')) return
|
|
30
|
+
if (event instanceof KeyboardEvent && !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End', 'Escape'].includes(event.key)) return
|
|
31
|
+
following?.abort(); workbench.setAgentFollowing(false)
|
|
32
|
+
}
|
|
33
|
+
document.addEventListener('pointerdown', interrupt, true); document.addEventListener('input', interrupt, true); document.addEventListener('wheel', interrupt, true); document.addEventListener('keydown', interrupt, true)
|
|
34
|
+
return () => {
|
|
35
|
+
closed = true; following?.abort(); stop(); stopState(); workbench.setAgentActivities([])
|
|
36
|
+
document.removeEventListener('pointerdown', interrupt, true); document.removeEventListener('input', interrupt, true); document.removeEventListener('wheel', interrupt, true); document.removeEventListener('keydown', interrupt, true)
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/components.tsx
CHANGED
|
@@ -32,17 +32,17 @@ export function PmSplitHandle({ label, className, ...props }: ComponentProps<typ
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** Shared chrome for docked editors; content and actions remain owned by the caller. */
|
|
35
|
-
export function PmPanelHeader({ title, meta, leading, actions }: { title: string, meta?: ReactNode, leading?: ReactNode, actions?: ReactNode }) {
|
|
36
|
-
return <header className=
|
|
37
|
-
{leading}<h2 className="pm-ui-panel-header__title">{title}</h2>
|
|
35
|
+
export function PmPanelHeader({ title, titleId, meta, leading, actions, variant = 'dock', className }: { title: string, titleId?: string, meta?: ReactNode, leading?: ReactNode, actions?: ReactNode, variant?: 'workspace' | 'dock', className?: string }) {
|
|
36
|
+
return <header className={cls('pm-ui-panel-header', className)} data-variant={variant}>
|
|
37
|
+
{leading}<h2 id={titleId} className="pm-ui-panel-header__title">{title}</h2>
|
|
38
38
|
{meta && <span className="pm-ui-panel-header__meta">{meta}</span>}
|
|
39
39
|
{actions && <div className="pm-ui-panel-header__actions">{actions}</div>}
|
|
40
40
|
</header>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/** One tab stop, with arrow/Home/End navigation supplied by Radix. */
|
|
44
|
-
export function PmToolbar({ label, children, className, scroll }: { label: string, children: ReactNode, className?: string, scroll?: boolean }) {
|
|
45
|
-
return <Toolbar.Root className={cls(scroll && 'pm-ui-toolbar-scroll', className)} aria-label={label} loop>{children}</Toolbar.Root>
|
|
44
|
+
export function PmToolbar({ label, children, className, scroll, variant = 'inline' }: { label: string, children: ReactNode, className?: string, scroll?: boolean, variant?: 'workspace' | 'inline' }) {
|
|
45
|
+
return <Toolbar.Root className={cls('pm-ui-toolbar', scroll && 'pm-ui-toolbar-scroll', className)} data-variant={variant} aria-label={label} loop>{children}</Toolbar.Root>
|
|
46
46
|
}
|
|
47
47
|
export const PmToolbarButton = Toolbar.Button
|
|
48
48
|
|
|
@@ -149,6 +149,13 @@ export function PmSearchList({ label, searchLabel, searchPlaceholder, items, val
|
|
|
149
149
|
|
|
150
150
|
export type Tone = 'neutral' | 'accent' | 'ok' | 'warn' | 'danger' | 'outline'
|
|
151
151
|
|
|
152
|
+
/** Labelled presence: the dot breathes only while a real operation is running. */
|
|
153
|
+
export function PmAgentActivity({ state, label, compact, detail }: { state: 'running' | 'done' | 'failed' | 'cancelled', label: string, compact?: boolean, detail?: string }) {
|
|
154
|
+
return <span className="pm-ui-agent-activity" data-state={state} data-compact={compact || undefined} role="status" aria-label={detail} aria-live="polite" aria-atomic="true">
|
|
155
|
+
<span className="pm-ui-agent-activity__dot" aria-hidden="true" /><span className="pm-ui-agent-activity__label">{label}</span>
|
|
156
|
+
</span>
|
|
157
|
+
}
|
|
158
|
+
|
|
152
159
|
export function PmBadge({ tone = 'neutral', pill, children }: { tone?: Tone, pill?: boolean, children?: ReactNode }) {
|
|
153
160
|
return <span className={cls('pm-ui-badge', tone !== 'neutral' && `pm-ui-badge--${tone}`, pill && 'pm-ui-badge--pill')}>{children}</span>
|
|
154
161
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useState } from 'react'
|
|
2
|
+
import { designLength } from '@lincyaw/design'
|
|
3
|
+
|
|
4
|
+
/** Layout belongs to the available pane, which can be much narrower than the application window. */
|
|
5
|
+
export function useContainerLayout() {
|
|
6
|
+
const [element, setElement] = useState<HTMLElement | null>(null)
|
|
7
|
+
const ref = useCallback((node: HTMLElement | null) => setElement(node), [])
|
|
8
|
+
const [layout, setLayout] = useState({ measured: false, narrow: true, roomy: false, productionWide: false })
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
if (!element) return
|
|
11
|
+
const update = () => {
|
|
12
|
+
const width = element.getBoundingClientRect().width
|
|
13
|
+
if (!width) return
|
|
14
|
+
const next = { measured: true, narrow: width < designLength('--pm-layout-narrow-width', element), roomy: width >= designLength('--pm-layout-roomy-width', element), productionWide: width >= designLength('--pm-production-wide-width', element) }
|
|
15
|
+
setLayout(previous => Object.keys(next).every(key => previous[key as keyof typeof next] === next[key as keyof typeof next]) ? previous : next)
|
|
16
|
+
}
|
|
17
|
+
const observer = new ResizeObserver(update); observer.observe(element); update()
|
|
18
|
+
return () => observer.disconnect()
|
|
19
|
+
}, [element])
|
|
20
|
+
return { ...layout, ref }
|
|
21
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from 'react'
|
|
2
|
+
import { markAgentTargets } from './agent-targets.ts'
|
|
2
3
|
import type { Transaction } from '@tiptap/pm/state'
|
|
3
4
|
import { TextSelection } from '@tiptap/pm/state'
|
|
4
5
|
import { closeHistory } from '@tiptap/pm/history'
|
|
@@ -35,6 +36,7 @@ export interface DocumentEditorCommands {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface DocumentEditorProps {
|
|
39
|
+
agentActivities?: import('@lincyaw/kernel').AgentActivity[]
|
|
38
40
|
identity: string
|
|
39
41
|
document: TeachingDocument
|
|
40
42
|
version?: string
|
|
@@ -98,6 +100,16 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
98
100
|
}
|
|
99
101
|
active.current = projection
|
|
100
102
|
current.current = props
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const root = editor.current?.prosemirrorView.dom
|
|
105
|
+
if (!root || !props.agentActivities?.length) return
|
|
106
|
+
let unmark = () => {}
|
|
107
|
+
const paint = () => { unmark(); unmark = markAgentTargets(root, active.current, current.current.document, current.current.agentActivities ?? []) }
|
|
108
|
+
paint()
|
|
109
|
+
const observer = new MutationObserver(paint)
|
|
110
|
+
observer.observe(root, { childList: true, subtree: true })
|
|
111
|
+
return () => { observer.disconnect(); unmark() }
|
|
112
|
+
}, [props.agentActivities, projection, props.version])
|
|
101
113
|
const cancelFocus = () => { if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current); focusFrame.current = undefined }
|
|
102
114
|
const reportPosition = () => {
|
|
103
115
|
const value = editor.current
|
|
@@ -4,6 +4,7 @@ import { randomUUID } from '@lincyaw/kernel'
|
|
|
4
4
|
import { PmIconButton } from '../components.tsx'
|
|
5
5
|
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
6
|
import { isAgentChanging } from '../workbench-state.ts'
|
|
7
|
+
import { latestAgentActivity } from '../agent-activity.ts'
|
|
7
8
|
import { NarrationEditor } from './NarrationEditor.tsx'
|
|
8
9
|
import { DOCUMENT_EDITOR_MESSAGES } from './messages.ts'
|
|
9
10
|
import { narrationFieldFocus, narrationsToNative, nativeToNarrations } from './narration.ts'
|
|
@@ -62,6 +63,8 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
|
|
|
62
63
|
const locale = useWorkbenchState(state => state.locale), t = DOCUMENT_EDITOR_MESSAGES[locale]
|
|
63
64
|
const readOnly = useWorkbenchState(state => workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.loading) || isAgentChanging(state))
|
|
64
65
|
const timingStorageFailure = useWorkbenchState(state => state.documentTimingDraftStorageFailure)
|
|
66
|
+
const activities = useWorkbenchState(state => state.agentActivities)
|
|
67
|
+
const activity = latestAgentActivity(activities?.filter(value => value.document === source?.directory && value.targets.some(target => target.step === stepId)))
|
|
65
68
|
if (workbench.client.capabilities?.narration === false) return null
|
|
66
69
|
const document = source?.content, section = document?.sections[sectionId], step = document?.steps[stepId]
|
|
67
70
|
if (!source?.identity || !document || !section || !step) return null
|
|
@@ -72,7 +75,7 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
|
|
|
72
75
|
const id = section.stepOrder[index + offset]
|
|
73
76
|
if (id) { onPause(); workbench.selectDocumentStep(sectionId, id) }
|
|
74
77
|
}
|
|
75
|
-
return <section className="pm-ui-block-preview__narration" aria-label={fieldLabel} data-step-narration={stepId}>
|
|
78
|
+
return <section className="pm-ui-block-preview__narration" aria-label={fieldLabel} data-step-narration={stepId} data-pm-agent-target={activity?.state}>
|
|
76
79
|
<header className="pm-ui-block-preview__narration-header">
|
|
77
80
|
<span className="pm-ui-block-preview__step-label">{label}</span>
|
|
78
81
|
<span className="pm-ui-block-preview__actions">
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AgentActivity, TeachingDocument } from '@lincyaw/kernel'
|
|
2
|
+
import type { DocumentProjection } from './projection.ts'
|
|
3
|
+
|
|
4
|
+
/** Decorative attributes only: canonical IDs resolve through the editor's existing projection. */
|
|
5
|
+
export function markAgentTargets(root: HTMLElement, projection: DocumentProjection, document: TeachingDocument, activities: readonly AgentActivity[]): () => void {
|
|
6
|
+
const marked = new Set<HTMLElement>()
|
|
7
|
+
const mark = (element: HTMLElement | null, state: AgentActivity['state']) => {
|
|
8
|
+
if (!element || marked.has(element)) return
|
|
9
|
+
element.dataset.pmAgentTarget = state; marked.add(element)
|
|
10
|
+
}
|
|
11
|
+
for (const activity of [...activities].sort((a, b) => Number(b.state === 'running') - Number(a.state === 'running'))) {
|
|
12
|
+
let found = false
|
|
13
|
+
for (const target of activity.targets) {
|
|
14
|
+
let targetFound = false
|
|
15
|
+
if (target.block) for (const [native, owner] of projection.owners) {
|
|
16
|
+
if (owner !== target.block) continue
|
|
17
|
+
const element = root.querySelector<HTMLElement>(`[data-id="${CSS.escape(native)}"]`)
|
|
18
|
+
if (element) { mark(element, activity.state); targetFound = true }
|
|
19
|
+
}
|
|
20
|
+
if (target.step) {
|
|
21
|
+
const field = root.querySelector<HTMLElement>(`[data-step-narration="${CSS.escape(target.step)}"]`)
|
|
22
|
+
if (field) targetFound = true // The shared narration component owns its decorative attribute.
|
|
23
|
+
}
|
|
24
|
+
const section = target.section ?? (target.step ? document.steps[target.step]?.sectionId : undefined)
|
|
25
|
+
if (!targetFound && section) {
|
|
26
|
+
const heading = root.querySelector<HTMLElement>(`[data-document-section="${CSS.escape(section)}"]`)
|
|
27
|
+
if (heading) { mark(heading, activity.state); targetFound = true }
|
|
28
|
+
}
|
|
29
|
+
found ||= targetFound
|
|
30
|
+
}
|
|
31
|
+
if (!found) mark(root, activity.state)
|
|
32
|
+
}
|
|
33
|
+
return () => { for (const element of marked) delete element.dataset.pmAgentTarget }
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -34,4 +34,6 @@ export { SpeechSettingsPanel } from './panels/SpeechSettingsPanel.tsx'
|
|
|
34
34
|
export { SPEECH_SETTINGS_MESSAGES } from './speech-settings-messages.ts'
|
|
35
35
|
export { connectAuthoringClient } from './authoring-client.ts'
|
|
36
36
|
export { connectAuthoringWindow } from './authoring-window.ts'
|
|
37
|
+
export { connectAgentActivity } from './agent-activity.ts'
|
|
38
|
+
export { AgentActivityBar } from './AgentActivityBar.tsx'
|
|
37
39
|
export { SHORTCUTS } from './shortcuts.ts'
|
|
@@ -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,6 +1,7 @@
|
|
|
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 { PmBadge, PmButton, PmDialog, PmIcon, PmIconButton, PmMenu, PmNotice, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
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'
|
|
@@ -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
|
|
|
@@ -60,18 +47,20 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
60
47
|
const previousView = useRef({ document, workspace, view, active })
|
|
61
48
|
const currentScope = useRef({ document, active })
|
|
62
49
|
currentScope.current = { document, active }
|
|
63
|
-
const [navigation, setNavigation] = useState(
|
|
64
|
-
const
|
|
65
|
-
const previousRoomy = useRef(
|
|
50
|
+
const [navigation, setNavigation] = useState(false)
|
|
51
|
+
const container = useContainerLayout(), { roomy, narrow } = container
|
|
52
|
+
const previousRoomy = useRef<boolean>()
|
|
66
53
|
useEffect(() => {
|
|
67
|
-
if (
|
|
54
|
+
if (!container.measured) return
|
|
55
|
+
if (!roomy) setNavigation(false)
|
|
56
|
+
else if (previousRoomy.current === undefined) setNavigation(true)
|
|
68
57
|
previousRoomy.current = roomy
|
|
69
|
-
}, [roomy])
|
|
58
|
+
}, [roomy, container.measured])
|
|
70
59
|
// Where the pane covers the page, another document opens with it closed, so its body is not hidden.
|
|
71
60
|
const [navigationDocument, setNavigationDocument] = useState(document)
|
|
72
61
|
if (navigationDocument !== document) {
|
|
73
62
|
setNavigationDocument(document)
|
|
74
|
-
if (navigation &&
|
|
63
|
+
if (navigation && !roomy) setNavigation(false)
|
|
75
64
|
}
|
|
76
65
|
const compilePresentation = async (ready?: () => void, forReading = false, signal?: AbortSignal, deadline?: number): Promise<void> => {
|
|
77
66
|
if (preparing.current || workbench.getState().isPreparingPresentation) return
|
|
@@ -218,14 +207,15 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
218
207
|
return () => window.removeEventListener('keydown', escape, true)
|
|
219
208
|
}, [active, presenting])
|
|
220
209
|
return (
|
|
221
|
-
<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}>
|
|
222
|
-
{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}>
|
|
223
212
|
<span className="pmw-toolbar__title">{t.readDocument}</span>
|
|
213
|
+
{actions}
|
|
224
214
|
<PmToolbarButton asChild><PmIconButton small icon="edit" label={t.editDocument} disabled={changingView} onClick={() => void exitPresent()} /></PmToolbarButton>
|
|
225
215
|
<PmToolbarButton asChild><PmIconButton small icon="refresh" label={t.reloadPreview} loading={changingView} onClick={() => void compilePresentation(() => workbench.reloadPreview(), true)} /></PmToolbarButton>
|
|
226
216
|
<PmToolbarButton asChild><PmIconButton small icon="slides" label={t.present} disabled={changingView} onClick={() => void compilePresentation(() => { workbench.setWebView('present'); setWorkspace('presentation') })} /></PmToolbarButton>
|
|
227
217
|
</PmToolbar>}
|
|
228
|
-
{!producing && !presenting && !reading && <DocumentToolbar presentButton={presentButton} framed={framed} onBack={onBack} actions={actions} aside={aside} navigation={navigation} changingView={changingView} onProduction={() => void openProduction()} onRead={() => void compilePresentation(() => {
|
|
218
|
+
{!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(() => {
|
|
229
219
|
workbench.setMode('viewing')
|
|
230
220
|
workbench.setWebView('document')
|
|
231
221
|
setWorkspace('reading')
|
|
@@ -233,15 +223,15 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
|
|
|
233
223
|
workbench.setMode('viewing')
|
|
234
224
|
workbench.setWebView('present')
|
|
235
225
|
setWorkspace('presentation')
|
|
236
|
-
})} onNavigation={() => { setNavigation(shown => !shown); if (!navigation &&
|
|
226
|
+
})} onNavigation={() => { setNavigation(shown => !shown); if (!navigation && !roomy) setAside(null) }} onAside={next => { setAside(current => (current === next ? null : next)); if (!roomy) setNavigation(false) }} />}
|
|
237
227
|
{viewFailure && <PmNotice tone="danger">{viewFailure}</PmNotice>}
|
|
238
228
|
<DocumentNotices />
|
|
239
229
|
<div className="pmw-document__body" role="region" aria-label={producing ? PRODUCTION_MESSAGES[workbench.getState().locale].title : presenting ? t.presentationPreview : reading ? t.readDocument : t.documentEditor}>
|
|
240
|
-
{!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (
|
|
241
|
-
<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 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>
|
|
230
|
+
{!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (!roomy) setNavigation(false) }} />}
|
|
231
|
+
<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>
|
|
242
232
|
{!presenting && !producing && !reading && aside && (
|
|
243
233
|
<aside className="pmw-document__aside pm-ui-block-editor" aria-label={{ narration: t.documentNarration, comments: t.comments, export: t.exportPane, history: t.versionHistory }[aside]}>
|
|
244
|
-
{aside === 'comments' ? <section className="pmw-pane"><
|
|
234
|
+
{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} />}
|
|
245
235
|
</aside>
|
|
246
236
|
)}
|
|
247
237
|
</div>
|
|
@@ -296,11 +286,10 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
|
|
|
296
286
|
}
|
|
297
287
|
return (
|
|
298
288
|
<nav className="pmw-navigation" aria-label={t.navigation}>
|
|
299
|
-
<
|
|
300
|
-
<h2 className="pmw-pane__title">{editing ? t.pages : slides ? t.renderers.slides : t.navigation}</h2>
|
|
289
|
+
<PmPanelHeader className="pmw-pane__header" title={editing ? t.pages : slides ? t.renderers.slides : t.navigation} actions={<>
|
|
301
290
|
{editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }} />}
|
|
302
291
|
<PmIconButton icon="close" label={t.closeNavigation} small onClick={onClose} />
|
|
303
|
-
|
|
292
|
+
</>} />
|
|
304
293
|
{failure && !renaming && !deleting && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
305
294
|
{items.length === 0 && loading ? <div className="pmw-navigation__empty"><PmSkeleton shape="list" label={t.loadingPages} /></div>
|
|
306
295
|
: items.length === 0
|
|
@@ -356,7 +345,7 @@ function StatusBar() {
|
|
|
356
345
|
)
|
|
357
346
|
}
|
|
358
347
|
|
|
359
|
-
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 }) {
|
|
348
|
+
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 }) {
|
|
360
349
|
const t = useMessages()
|
|
361
350
|
const workbench = useWorkbench()
|
|
362
351
|
const p = PRODUCTION_MESSAGES[useWorkbenchState(state => state.locale)]
|
|
@@ -372,7 +361,6 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
372
361
|
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)))
|
|
373
362
|
const openComments = useWorkbenchState(state => Object.values(state.authoring?.content?.comments ?? {}).filter(comment => !comment.resolved && !comment.deletedAt).length)
|
|
374
363
|
const hasStep = useWorkbenchState(state => !state.authoring?.loading && Boolean(state.authoring?.content?.sectionOrder.length))
|
|
375
|
-
const narrow = useMediaQuery(NARROW)
|
|
376
364
|
const capabilities = workbench.client.capabilities
|
|
377
365
|
const compactCommands = narrow && !framed
|
|
378
366
|
const undoDisabled = Boolean(capabilities?.readOnly || !editorHistory?.undo && (editorHistory?.field || !history?.undo && !dirty) || busy)
|
|
@@ -380,7 +368,7 @@ function DocumentToolbar({ presentButton, framed, onBack, actions, aside, naviga
|
|
|
380
368
|
const commentsLabel = openComments ? `${t.comments} (${openComments})` : t.comments
|
|
381
369
|
const historyLabel = draftReadFailure ? `${t.versionHistory} · ${t.documentDraftUnreadable}` : draftCount ? t.historyWithDrafts(draftCount) : t.versionHistory
|
|
382
370
|
return (
|
|
383
|
-
<PmToolbar className={framed ? 'pmw-toolbar' : 'pmw-toolbar pmw-toolbar--document'} label={t.commands}>
|
|
371
|
+
<PmToolbar variant="workspace" className={framed ? 'pmw-toolbar' : 'pmw-toolbar pmw-toolbar--document'} label={t.commands}>
|
|
384
372
|
{!framed && <div className="pmw-toolbar__document">
|
|
385
373
|
<PmToolbarButton asChild><PmIconButton icon="arrow-left" label={t.back} small onClick={() => onBack ? onBack() : workbench.closeDocument()} /></PmToolbarButton>
|
|
386
374
|
<h1 className="pmw-toolbar__title" title={title}>{title}</h1>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
2
|
import type { CompileJob, OutputTarget } from '@lincyaw/kernel'
|
|
3
3
|
import type { IconName } from '@lincyaw/design'
|
|
4
|
-
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../components.tsx'
|
|
4
|
+
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmNotice, PmPanelHeader } from '../components.tsx'
|
|
5
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
6
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
7
7
|
|
|
@@ -42,10 +42,7 @@ export function ExportPanel({ documentOnly = false, embedded = false, onClose }:
|
|
|
42
42
|
const busy = (id: string) => jobs.some(job => job.target === id && (job.state === 'queued' || job.state === 'running'))
|
|
43
43
|
return (
|
|
44
44
|
<section className="pmw-pane" aria-labelledby={embedded ? undefined : 'pmw-export-title'} aria-label={embedded ? t.exportPane : undefined}>
|
|
45
|
-
{!embedded && <
|
|
46
|
-
<h2 id="pmw-export-title" className="pmw-pane__title">{documentOnly ? t.documentExport : t.exportPane}</h2>
|
|
47
|
-
<PmIconButton small icon="close" label={t.close} onClick={onClose} />
|
|
48
|
-
</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} />} />}
|
|
49
46
|
{failure && <PmNotice tone="danger">{t.outputFailed(t.jobFailureReasons[failure] ?? failureReason(t, failure))}</PmNotice>}
|
|
50
47
|
{preparing && <PmNotice>{preparing.canCancel ? t.outputConfirmingSave : t.outputStarting} {preparing.canCancel && <PmButton small onClick={() => workbench.cancelJobPreparation()}>{t.cancelOutput}</PmButton>}</PmNotice>}
|
|
51
48
|
{!embedded && <h3 id="pmw-export-make" className="pmw-export__subtitle">{t.makeLabel}</h3>}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasRole } from '@lincyaw/kernel'
|
|
2
2
|
import type { HistoryRevision } from '@lincyaw/kernel'
|
|
3
|
-
import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../components.tsx'
|
|
3
|
+
import { PmBadge, PmButton, PmEmpty, PmIcon, PmIconButton, PmNotice, PmPanelHeader } from '../components.tsx'
|
|
4
4
|
import type { IconName } from '@lincyaw/design'
|
|
5
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
6
|
import { timeAgo } from '../messages.ts'
|
|
@@ -43,10 +43,7 @@ export function HistoryPanel({ onClose, revisionAction }: HistoryPanelProps) {
|
|
|
43
43
|
const icon = (revision: HistoryRevision): IconName => (revision.origin.kind === 'agent' ? 'sparkle' : revision.origin.kind === 'document' ? 'document' : 'edit')
|
|
44
44
|
return (
|
|
45
45
|
<section className="pmw-pane" aria-labelledby="pmw-history-title">
|
|
46
|
-
<
|
|
47
|
-
<h2 id="pmw-history-title" className="pmw-pane__title">{t.versionHistory}</h2>
|
|
48
|
-
<PmIconButton small icon="close" label={t.close} onClick={onClose} />
|
|
49
|
-
</header>
|
|
46
|
+
<PmPanelHeader className="pmw-pane__header" titleId="pmw-history-title" title={t.versionHistory} actions={<PmIconButton small icon="close" label={t.close} onClick={onClose} />} />
|
|
50
47
|
{outside && outside.length > 0 && (
|
|
51
48
|
<PmNotice tone="warn">
|
|
52
49
|
<span>{t.outside(outside.length)}</span>
|
package/src/panels/HomePanel.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
2
3
|
import { errorMessage } from '@lincyaw/kernel'
|
|
3
4
|
import type { DocumentSummary, ProjectPlan } from '@lincyaw/kernel'
|
|
4
5
|
import { PmButton, PmDialog, PmEmpty, PmInput, PmSelect, PmIcon, PmMenu, PmNotice } from '../components.tsx'
|
|
@@ -10,7 +11,7 @@ type Editing =
|
|
|
10
11
|
| { op: 'rename' | 'delete', doc: DocumentSummary }
|
|
11
12
|
|
|
12
13
|
/** The documents of the workspace: open one, make a new one, rename, copy or delete one. */
|
|
13
|
-
export function HomePanel() {
|
|
14
|
+
export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
|
|
14
15
|
const t = useMessages()
|
|
15
16
|
const workbench = useWorkbench()
|
|
16
17
|
const answer = useWorkbenchState(state => state.documents)
|
|
@@ -46,6 +47,7 @@ export function HomePanel() {
|
|
|
46
47
|
<section className="pmw-home" aria-labelledby="pmw-home-title">
|
|
47
48
|
<header className="pmw-home__bar">
|
|
48
49
|
<h1 id="pmw-home-title" className="pmw-home__title">{answer?.title ?? t.documents}</h1>
|
|
50
|
+
{actions}
|
|
49
51
|
{operable && <PmButton variant="primary" icon="plus" disabled={working} onClick={() => { handingOff.current = false; setError(undefined); setEditing({ op: 'create' }) }}>{t.newDocument}</PmButton>}
|
|
50
52
|
</header>
|
|
51
53
|
{failure && <PmNotice tone="danger">{bundleDisabled ? t.bundleDisabled : failure}</PmNotice>}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { useContainerLayout } from '../container-layout.ts'
|
|
2
4
|
import { keyBelongsToTarget, PRODUCTION_PLAYBACK_RATES, sameProductionBinding, watchFocusSource } from '@lincyaw/kernel'
|
|
3
5
|
import type { ProductionPlaybackCommand } from '@lincyaw/kernel'
|
|
4
6
|
import { PmBadge, PmButton, PmCard, PmDialog, PmEmpty, PmIconButton, PmNotice, PmPanelHeader, PmPopover, PmSearchList, PmSelect, PmSegmented, PmSplitGroup, PmSplitHandle, PmSplitPanel, PmTabs, PmTabPanel, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
@@ -33,7 +35,7 @@ const PLAYBACK_KEYS: Record<string, PlaybackKey> = { ' ': 'play-pause', ArrowLef
|
|
|
33
35
|
* While it is `active`, Space plays or pauses and the left and right arrows select the previous or next step, from the
|
|
34
36
|
* workbench and from its preview alike; text entry, menus, dialogs and controls the keyboard moved to keep their keys.
|
|
35
37
|
*/
|
|
36
|
-
export function ProductionPanel({ onClose, closing, active = true }: { onClose(): void, closing: boolean, active?: boolean }) {
|
|
38
|
+
export function ProductionPanel({ onClose, closing, active = true, actions }: { onClose(): void, closing: boolean, active?: boolean, actions?: ReactNode }) {
|
|
37
39
|
const workbench = useWorkbench(), t = useMessages(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
|
|
38
40
|
const voicePlayback = useProductionVoicePlayback()
|
|
39
41
|
const serviceVersion = useWorkbenchState(state => state.voiceServiceVersion)
|
|
@@ -46,7 +48,8 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
46
48
|
const captionDraftSteps = useWorkbenchState(state => state.captionTimingDraftSteps), captionStorageFailure = useWorkbenchState(state => state.captionTimingDraftStorageFailure)
|
|
47
49
|
const frameCurrent = useWorkbenchState(state => Boolean(state.presentationSnapshot && state.previewIrRevision === state.presentationSnapshot.revision))
|
|
48
50
|
const blocked = useWorkbenchState(state => Boolean(state.authoring?.loading || state.authoring?.composing) || isAgentChanging(state))
|
|
49
|
-
const
|
|
51
|
+
const container = useContainerLayout(), wide = container.productionWide
|
|
52
|
+
const [tab, setTab] = useState('preview')
|
|
50
53
|
const [libraryTab, setLibraryTab] = useState('pages'), [inspectorTab, setInspectorTab] = useState('script'), [outputsOpen, setOutputsOpen] = useState(false)
|
|
51
54
|
const [generateStep, setGenerateStep] = useState<string>(), [failure, setFailure] = useState<string>()
|
|
52
55
|
const [planBusy, setPlanBusy] = useState(false), [planFailure, setPlanFailure] = useState<string>(), [planReload, setPlanReload] = useState(0)
|
|
@@ -69,11 +72,6 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
69
72
|
const canPlay = Boolean(playbackConnected && plan?.canPreview && live?.status === 'ready' && !timingDraft)
|
|
70
73
|
const backgroundBody = !wide && tab === 'timeline', backgroundVisuals = !wide && tab !== 'preview'
|
|
71
74
|
useEffect(() => workbench.observeVoiceoverJobs(), [workbench, source?.identity])
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const media = matchMedia('(min-width: 1100px)'), update = () => setWide(media.matches)
|
|
74
|
-
media.addEventListener('change', update)
|
|
75
|
-
return () => media.removeEventListener('change', update)
|
|
76
|
-
}, [])
|
|
77
75
|
useEffect(() => () => { owner.current.active = false; owner.current.generation++; controlRequest.current?.abort(); workbench.closeProduction(); workbench.cancelPreviewPreparation() }, [workbench])
|
|
78
76
|
useEffect(() => {
|
|
79
77
|
const controller = new AbortController()
|
|
@@ -178,10 +176,11 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
178
176
|
const mediaEditor = <ProductionMediaClips key={`${source.identity}:${stepId}`} identity={source.identity} version={source.version ?? ''} document={document} sectionId={sectionId} stepId={stepId}
|
|
179
177
|
binding={planCurrent ? plan?.binding : undefined} stepDurationMs={(() => { const step = planCurrent ? plan?.pages.find(page => page.sectionId === sectionId)?.steps.find(step => step.stepId === stepId) : undefined; return step?.timing === 'confirmed' && step.startMs !== undefined && step.endMs !== undefined ? step.endMs - step.startMs : undefined })()}
|
|
180
178
|
disabled={blocked || closing || !declared || !source.version || Boolean(source.dirty || source.saving || source.restored || source.error)} onChanged={() => setMediaRefresh(true)} />
|
|
181
|
-
return <section className="pmw-production" aria-label={p.title}>
|
|
182
|
-
<PmPanelHeader title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
179
|
+
return <section ref={container.ref} className="pmw-production" aria-label={p.title}>
|
|
180
|
+
<PmPanelHeader variant="workspace" title={p.title} meta={wide ? document.metadata.title : undefined}
|
|
183
181
|
leading={<PmIconButton small icon="arrow-left" label={p.back} loading={closing} onClick={onClose} />}
|
|
184
182
|
actions={<>
|
|
183
|
+
{actions}
|
|
185
184
|
<PmBadge tone={sourceCurrent && frameCurrent ? 'ok' : preparing || sourceCurrent ? 'accent' : 'warn'}>{sourceCurrent && frameCurrent ? p.current : preparing || sourceCurrent ? p.preparing : p.outdated}</PmBadge>
|
|
186
185
|
{issueCount > 0 && <PmPopover open={issuesOpen} onOpenChange={setIssuesOpen} label={p.issues(issueCount)} trigger={wide ? <PmButton small icon="warning" title={summary} aria-label={p.issues(issueCount)}>{p.issueCount(issueCount)}</PmButton> : <PmIconButton small icon="warning" label={p.issues(issueCount)} hint={summary} />}>
|
|
187
186
|
<div className="pmw-production__feedback">
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react'
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react'
|
|
2
2
|
import { hasRole } from '@lincyaw/kernel'
|
|
3
3
|
import { PmButton, PmNotice, PmSkeleton } from '../components.tsx'
|
|
4
4
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
@@ -15,6 +15,8 @@ import { isAgentChanging } from '../workbench-state.ts'
|
|
|
15
15
|
export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
|
|
16
16
|
const workbench = useWorkbench(), t = useMessages()
|
|
17
17
|
const source = useWorkbenchState(state => state.authoring)
|
|
18
|
+
const activities = useWorkbenchState(state => state.agentActivities)
|
|
19
|
+
const agentActivities = useMemo(() => activities?.filter(activity => activity.document === source?.directory), [activities, source?.directory])
|
|
18
20
|
const sourceAcknowledged = () => {
|
|
19
21
|
const current = workbench.getState().authoring
|
|
20
22
|
return Boolean(current && current.identity === source?.identity && current.reset === source?.reset
|
|
@@ -158,7 +160,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
|
|
|
158
160
|
{!source?.content || !source.identity ? source?.loading
|
|
159
161
|
? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
|
|
160
162
|
: <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div className="pmw-source-document__sheet">
|
|
161
|
-
<DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
|
|
163
|
+
<DocumentEditor agentActivities={agentActivities} acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
|
|
162
164
|
getDocumentVersion={() => { const current = workbench.getState().authoring; return current && current.identity === source.identity && current.reset === source.reset ? current.version : undefined }} reset={source.reset} locale={locale} readOnly={readOnly}
|
|
163
165
|
uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
|
|
164
166
|
getPositionToken={() => workbench.getState().documentPositionToken}
|
package/src/styles.css
CHANGED
|
@@ -171,15 +171,7 @@
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
.pmw-toolbar {
|
|
174
|
-
display: flex;
|
|
175
|
-
flex: none;
|
|
176
|
-
align-items: center;
|
|
177
|
-
gap: var(--pm-space-px);
|
|
178
|
-
min-height: var(--pm-toolbar-height);
|
|
179
|
-
padding: var(--pm-space-1) var(--pm-space-2);
|
|
180
174
|
overflow-x: auto;
|
|
181
|
-
border-bottom: var(--pm-size-hairline) solid var(--pm-color-line);
|
|
182
|
-
background: var(--pm-color-chrome);
|
|
183
175
|
scrollbar-width: none;
|
|
184
176
|
}
|
|
185
177
|
|
|
@@ -188,8 +180,8 @@
|
|
|
188
180
|
max-width: calc(var(--pm-navigation-width) * 1.5);
|
|
189
181
|
margin: 0 var(--pm-space-2) 0 var(--pm-space-1);
|
|
190
182
|
overflow: hidden;
|
|
191
|
-
font-size: var(--pm-text-
|
|
192
|
-
font-weight:
|
|
183
|
+
font-size: var(--pm-text-sm);
|
|
184
|
+
font-weight: var(--pm-weight-semibold);
|
|
193
185
|
text-overflow: ellipsis;
|
|
194
186
|
white-space: nowrap;
|
|
195
187
|
}
|
|
@@ -555,13 +547,6 @@
|
|
|
555
547
|
position: sticky;
|
|
556
548
|
top: 0;
|
|
557
549
|
z-index: 1;
|
|
558
|
-
display: flex;
|
|
559
|
-
flex: none;
|
|
560
|
-
align-items: center;
|
|
561
|
-
gap: var(--pm-space-2);
|
|
562
|
-
min-height: var(--pm-pane-header-height);
|
|
563
|
-
padding: 0 var(--pm-space-2) 0 var(--pm-space-3);
|
|
564
|
-
background: var(--pm-color-chrome);
|
|
565
550
|
}
|
|
566
551
|
|
|
567
552
|
.pmw-pane__title {
|
|
@@ -886,25 +871,21 @@
|
|
|
886
871
|
|
|
887
872
|
/* Narrow: labels go, icons stay; the side pane covers the document. */
|
|
888
873
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
.pmw-document__body { position: relative; }
|
|
892
|
-
.pmw-navigation {
|
|
874
|
+
.pmw-document:not([data-roomy]) .pmw-document__body { position: relative; }
|
|
875
|
+
.pmw-document:not([data-roomy]) .pmw-navigation {
|
|
893
876
|
position: absolute;
|
|
894
877
|
inset: 0 auto 0 0;
|
|
895
878
|
z-index: 6;
|
|
896
879
|
width: min(100%, var(--pm-navigation-width));
|
|
897
880
|
box-shadow: var(--pm-shadow-float);
|
|
898
881
|
}
|
|
899
|
-
|
|
882
|
+
.pmw-document:not([data-roomy]) .pmw-document__aside {
|
|
900
883
|
position: absolute;
|
|
901
884
|
inset: 0 0 0 auto;
|
|
902
885
|
z-index: 6;
|
|
903
886
|
width: min(100%, 24rem);
|
|
904
887
|
box-shadow: var(--pm-shadow-float);
|
|
905
888
|
}
|
|
906
|
-
}
|
|
907
|
-
|
|
908
889
|
/* Per-step speech: compact step strip and two tracks, alongside either document or presentation. */
|
|
909
890
|
.pmw-narration { min-height: 0; overflow: auto; }
|
|
910
891
|
.pmw-narration__body { display: grid; gap: var(--pm-space-3); padding: var(--pm-space-3); }
|
|
@@ -942,19 +923,17 @@
|
|
|
942
923
|
.pmw-step-timeline__steps { display: flex; gap: var(--pm-space-1); overflow-x: auto; padding: var(--pm-space-1); }
|
|
943
924
|
.pmw-step-timeline__steps > * { flex: none; }
|
|
944
925
|
.pmw-toolbar--present { justify-content: flex-end; }
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
.pmw-step-timeline { padding: var(--pm-space-2); }
|
|
957
|
-
}
|
|
926
|
+
.pmw-document[data-narrow] .pmw-source-document { padding: var(--pm-space-2); }
|
|
927
|
+
.pmw-document[data-narrow] .pmw-toolbar--document { flex-wrap: wrap; }
|
|
928
|
+
.pmw-document[data-narrow] .pmw-toolbar--document .pmw-toolbar__document { display: flex; flex: 1 0 100%; align-items: center; gap: var(--pm-space-px); min-width: 0; }
|
|
929
|
+
.pmw-document[data-narrow] .pmw-toolbar--document .pmw-toolbar__title { flex: 1; max-width: none; }
|
|
930
|
+
.pmw-document[data-narrow] .pmw-toolbar--document .pmw-toolbar__status { flex: 1 1 0; }
|
|
931
|
+
.pmw-document[data-narrow] .pmw-toolbar--document > .pmw-spacer { display: none; }
|
|
932
|
+
.pmw-document[data-narrow] .pmw-toolbar__status { flex: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
933
|
+
.pmw-document[data-narrow] .pmw-toolbar__status-full:has(+ .pmw-toolbar__status-short) { display: none; }
|
|
934
|
+
.pmw-document[data-narrow] .pmw-toolbar__status-short { display: inline; }
|
|
935
|
+
.pmw-document[data-narrow] .pmw-document__aside { width: 100%; }
|
|
936
|
+
.pmw-document[data-narrow] .pmw-step-timeline { padding: var(--pm-space-2); }
|
|
958
937
|
|
|
959
938
|
/* Production owns pane layout; controls and dock chrome live in the shared design layer. */
|
|
960
939
|
.pmw-speech-settings { min-width: 0; }
|
|
@@ -1001,3 +980,10 @@
|
|
|
1001
980
|
.pmw-approvals .pmw-muted { margin: 0; }
|
|
1002
981
|
.pmw-approvals__detail { max-height: 30vh; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1003
982
|
.pmw-approvals__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--pm-space-2); }
|
|
983
|
+
.pmw-agent-activity {
|
|
984
|
+
display: inline-flex;
|
|
985
|
+
align-items: center;
|
|
986
|
+
flex: none;
|
|
987
|
+
gap: var(--pm-space-1);
|
|
988
|
+
}
|
|
989
|
+
.pmw-agent-activity__label { min-width: 0; }
|
package/src/workbench-state.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface AgentAnswer {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export interface WorkbenchState {
|
|
57
|
+
agentActivities?: import('@lincyaw/kernel').AgentActivity[]
|
|
58
|
+
agentFollowing?: boolean
|
|
57
59
|
locale: Locale
|
|
58
60
|
authoring?: DocumentSessionState
|
|
59
61
|
/** Unaccepted numeric form input is retained separately from saved canonical timing. */
|
package/src/workbench.ts
CHANGED
|
@@ -382,6 +382,42 @@ export class Workbench {
|
|
|
382
382
|
for (const listener of this.#listeners) listener()
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
+
setAgentActivities(activities: import('@lincyaw/kernel').AgentActivity[]): void { this.#set({ agentActivities: activities }) }
|
|
386
|
+
setAgentFollowing(following: boolean): void { this.#set({ agentFollowing: following }) }
|
|
387
|
+
|
|
388
|
+
/** Presence never owns drafts or playback. Human input aborts this read-only navigation. */
|
|
389
|
+
async followAgentActivity(activity: import('@lincyaw/kernel').AgentActivity, signal: AbortSignal): Promise<void> {
|
|
390
|
+
const state = this.#state, source = state.authoring
|
|
391
|
+
if (activity.document === undefined || !state.agentFollowing || state.mode !== 'editing' || source?.loading || source?.dirty || source?.saving || source?.composing || source?.recovering || source?.restored || source?.error
|
|
392
|
+
|| !this.authoringWindowSnapshot(0).actions.includes('document.open')) return
|
|
393
|
+
signal.throwIfAborted()
|
|
394
|
+
let navigationScope: number | undefined
|
|
395
|
+
const cancel = () => {
|
|
396
|
+
if (navigationScope !== undefined && navigationScope === this.#documentScope && this.#state.document === activity.document
|
|
397
|
+
&& (this.#state.authoring?.loading || !this.#state.authoring?.content)) this.closeDocument()
|
|
398
|
+
}
|
|
399
|
+
signal.addEventListener('abort', cancel, { once: true })
|
|
400
|
+
try {
|
|
401
|
+
const opening = this.openDocument(activity.document, { signal })
|
|
402
|
+
navigationScope = this.#documentScope
|
|
403
|
+
await opening
|
|
404
|
+
} finally { signal.removeEventListener('abort', cancel) }
|
|
405
|
+
signal.throwIfAborted()
|
|
406
|
+
if (!this.#state.agentFollowing || this.#state.document !== activity.document) return
|
|
407
|
+
const content = this.#state.authoring?.content, target = activity.targets[0]
|
|
408
|
+
if (!content || !target) return
|
|
409
|
+
const contains = (ids: string[], block: string): boolean => ids.some(id => {
|
|
410
|
+
const value = content.blocks[id]
|
|
411
|
+
return id === block || Boolean(value && 'children' in value && value.children && contains(value.children, block))
|
|
412
|
+
})
|
|
413
|
+
const section = target.section ?? (target.step ? content.steps[target.step]?.sectionId : undefined)
|
|
414
|
+
?? (target.block ? content.sectionOrder.find(id => contains(content.sections[id]!.children, target.block!)) : undefined)
|
|
415
|
+
if (section && content.sections[section]) {
|
|
416
|
+
if (target.step && content.steps[target.step]?.sectionId === section) await this.selectDocumentStep(section, target.step)
|
|
417
|
+
else this.goToSection(section)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
385
421
|
get #messages() {
|
|
386
422
|
return MESSAGES[this.#state.locale]
|
|
387
423
|
}
|
package/src/workspace-client.ts
CHANGED
|
@@ -65,6 +65,7 @@ export interface WorkspaceCapabilities {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export interface WorkspaceClient {
|
|
68
|
+
subscribeAgentActivity?(received: (snapshot: import('@lincyaw/kernel').AgentActivitySnapshot) => void, failed: () => void): () => void
|
|
68
69
|
readSpeechSettings?(signal?: AbortSignal): Promise<SpeechSettingsAnswer>
|
|
69
70
|
changeSpeechSettings?(change: SpeechSettingsChange, signal?: AbortSignal): Promise<SpeechSettingsAnswer>
|
|
70
71
|
openSpeechSettings?(): boolean
|
|
@@ -337,6 +338,7 @@ export function workspaceClient(base = 'api/presmium/', subscription?: Workspace
|
|
|
337
338
|
}
|
|
338
339
|
const projectIntents = new Map<string, { id: string, plan?: ProjectPlan }>()
|
|
339
340
|
return client = {
|
|
341
|
+
subscribeAgentActivity: (received, failed) => subscribe(url('agent-activity/events', ''), 'agent-activity', received, failed),
|
|
340
342
|
...subscription?.openAuthoringClient ? { openAuthoringClient: subscription.openAuthoringClient } : {},
|
|
341
343
|
...subscription?.openAuthoringWindow ? { openAuthoringWindow: subscription.openAuthoringWindow } : {},
|
|
342
344
|
...subscription ? { subscribePreviewEvents: ((target, received) => {
|