@lincyaw/workbench 0.2.0-rc.11 → 0.2.0-rc.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/package.json +5 -4
  2. package/src/AgentActivityBar.tsx +25 -0
  3. package/src/MediaClipEditor.tsx +4 -3
  4. package/src/StepProductionEditor.tsx +13 -4
  5. package/src/agent-activity-messages.ts +14 -0
  6. package/src/agent-activity.ts +38 -0
  7. package/src/approvals.tsx +6 -1
  8. package/src/audio-recording-messages.ts +5 -5
  9. package/src/audio-recording.ts +27 -5
  10. package/src/authoring-client.ts +10 -10
  11. package/src/authoring-draft-fragment.ts +3 -1
  12. package/src/authoring-window.ts +100 -0
  13. package/src/base-controls.tsx +2 -2
  14. package/src/body-draft-actions.ts +60 -0
  15. package/src/caption-timing-drafts.ts +18 -1
  16. package/src/caption-timing-messages.ts +2 -2
  17. package/src/component-property-drafts.ts +5 -5
  18. package/src/components.tsx +34 -36
  19. package/src/container-layout.ts +21 -0
  20. package/src/context.tsx +5 -3
  21. package/src/diagnostics.ts +1 -1
  22. package/src/document-draft-store.ts +45 -18
  23. package/src/document-drafts.ts +28 -19
  24. package/src/document-editing.ts +484 -0
  25. package/src/document-editor/BlockNoteSurface.tsx +39 -13
  26. package/src/document-editor/CommentComposer.tsx +24 -0
  27. package/src/document-editor/ComponentMaterials.tsx +3 -9
  28. package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
  29. package/src/document-editor/DocumentBlockPreview.tsx +11 -4
  30. package/src/document-editor/DocumentComments.tsx +85 -14
  31. package/src/document-editor/DocumentEditor.tsx +56 -7
  32. package/src/document-editor/DocumentStepNarration.tsx +37 -26
  33. package/src/document-editor/NarrationEditor.tsx +54 -20
  34. package/src/document-editor/NewCommentDrafts.tsx +120 -37
  35. package/src/document-editor/PlaceComment.tsx +252 -0
  36. package/src/document-editor/agent-targets.ts +34 -0
  37. package/src/document-editor/blocknote-messages.ts +2 -0
  38. package/src/document-editor/comment-draft-actions.ts +40 -20
  39. package/src/document-editor/comment-draft-inspection.ts +2 -2
  40. package/src/document-editor/comment-drafts.ts +73 -25
  41. package/src/document-editor/comments.ts +30 -10
  42. package/src/document-editor/component-label.ts +11 -0
  43. package/src/document-editor/file-input.ts +2 -2
  44. package/src/document-editor/focus.ts +0 -2
  45. package/src/document-editor/insertion-place.ts +60 -0
  46. package/src/document-editor/messages.ts +3 -3
  47. package/src/document-editor/narration-schema.tsx +12 -6
  48. package/src/document-editor/narration.ts +19 -3
  49. package/src/document-editor/page-body.ts +60 -0
  50. package/src/document-editor/popover.tsx +4 -2
  51. package/src/document-editor/projection.ts +2 -2
  52. package/src/document-editor/rich-text.ts +3 -2
  53. package/src/document-editor/selection.ts +13 -0
  54. package/src/document-editor/style.css +7 -1
  55. package/src/document-editor/table-identities.ts +2 -1
  56. package/src/document-production.ts +491 -0
  57. package/src/document-session.ts +202 -56
  58. package/src/document-timing-drafts.ts +22 -2
  59. package/src/history.ts +5 -5
  60. package/src/index.ts +11 -5
  61. package/src/jobs.ts +1 -1
  62. package/src/mcp-settings-messages.ts +39 -0
  63. package/src/media-drafts.ts +43 -1
  64. package/src/messages.ts +33 -16
  65. package/src/panels/DocumentNarrationPanel.tsx +2 -2
  66. package/src/panels/DocumentView.tsx +97 -65
  67. package/src/panels/DocumentVoiceDialog.tsx +25 -9
  68. package/src/panels/DocumentVoiceField.tsx +1 -1
  69. package/src/panels/ExportPanel.tsx +2 -10
  70. package/src/panels/HistoryPanel.tsx +34 -7
  71. package/src/panels/HomePanel.tsx +3 -1
  72. package/src/panels/McpSettingsPanel.tsx +86 -0
  73. package/src/panels/PageDeleteDialog.tsx +4 -4
  74. package/src/panels/PageRenameDialog.tsx +1 -1
  75. package/src/panels/PreviewPanel.tsx +1 -4
  76. package/src/panels/ProductionCaptionSize.tsx +20 -0
  77. package/src/panels/ProductionCaptionTiming.tsx +12 -9
  78. package/src/panels/ProductionMediaClips.tsx +23 -7
  79. package/src/panels/ProductionPanel.tsx +16 -13
  80. package/src/panels/ProductionRecording.tsx +86 -9
  81. package/src/panels/ProductionRecordingRange.tsx +21 -19
  82. package/src/panels/ProductionTimeline.tsx +6 -1
  83. package/src/panels/ProductionTranscription.tsx +5 -4
  84. package/src/panels/SourceDocumentPanel.tsx +18 -36
  85. package/src/panels/SpeechSettingsPanel.tsx +1 -1
  86. package/src/panels/TranscriptionAdoption.tsx +40 -34
  87. package/src/panels/VoiceCloneDialog.tsx +2 -1
  88. package/src/panels/VoiceoverDialog.tsx +1 -1
  89. package/src/places.ts +1 -36
  90. package/src/preview-playback.ts +1 -1
  91. package/src/production-draft-actions.ts +37 -0
  92. package/src/production-messages.ts +6 -0
  93. package/src/production-playback.ts +1 -1
  94. package/src/production-voice-playback.ts +3 -2
  95. package/src/sha256.ts +9 -0
  96. package/src/speech-settings-messages.ts +5 -5
  97. package/src/styles.css +43 -79
  98. package/src/transcription-drafts.ts +124 -0
  99. package/src/use-recording-adoption.ts +2 -2
  100. package/src/voice-drafts.ts +32 -8
  101. package/src/voice-messages.ts +9 -9
  102. package/src/voiceover-jobs.ts +1 -1
  103. package/src/workbench-state.ts +159 -0
  104. package/src/workbench.ts +303 -952
  105. package/src/workspace-client.ts +30 -11
  106. package/src/assistant-mascot.ts +0 -62
  107. package/src/mascot-preference.ts +0 -37
  108. package/src/panels/ChangeTrail.tsx +0 -79
@@ -1,17 +1,11 @@
1
1
  import { useMemo } from 'react'
2
2
  import { applyDocumentComponentAction } from '@lincyaw/kernel'
3
- import type { Definition, TeachingDocument } from '@lincyaw/kernel'
3
+ import type { TeachingDocument } from '@lincyaw/kernel'
4
4
  import { PmButton, PmMenu, PmSearchList } from '../components.tsx'
5
5
  import type { ComponentPropertyMessages } from '../component-property-messages.ts'
6
+ import { componentDefinitionLabel } from './component-label.ts'
6
7
 
7
- export function componentDefinitionLabel(definition: Definition): string {
8
- const title = typeof definition.parameterSchema === 'object' && typeof definition.parameterSchema.title === 'string' ? definition.parameterSchema.title.trim() : ''
9
- if (title) return Array.from(title).slice(0, 80).join('')
10
- const implementation = definition.implementation
11
- const name = implementation.type === 'file' ? implementation.path.split('/').at(-1)?.replace(/\.(tsx?|jsx?|mjs|cjs)$/, '')
12
- : implementation.type === 'plugin' ? implementation.name : implementation.specifier.split('/').at(-1)
13
- return Array.from(name || definition.kind).slice(0, 80).join('')
14
- }
8
+ export { componentDefinitionLabel } from './component-label.ts'
15
9
 
16
10
  /** Selection is a proposal; only the caller's source-bound Apply changes a binding. */
17
11
  export function ComponentMaterials({ document, blockId, selected, onSelect, onLocate, disabled, messages: t }: {
@@ -1,9 +1,9 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
2
- import { applyDocumentComponentAction, effectiveComponentParameters, isRecord, validateDocumentParameters } from '@lincyaw/kernel'
2
+ import { applyDocumentComponentAction, effectiveComponentParameters, isRecord, randomUUID, validateDocumentParameters } from '@lincyaw/kernel'
3
3
  import type { CanonicalSource, DocumentComponentAction, DocumentParameterValidation, JsonObject, TeachingDocument } from '@lincyaw/kernel'
4
4
  import { PmButton, PmDialog, PmNotice, PmSelect } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
- import { isAgentChanging } from '../workbench.ts'
6
+ import { isAgentChanging } from '../workbench-state.ts'
7
7
  import { COMPONENT_PROPERTY_MESSAGES } from '../component-property-messages.ts'
8
8
  import type { ComponentPropertyMessages } from '../component-property-messages.ts'
9
9
  import { componentPropertyAction, componentSource, rebaseComponentPropertyDraft, sameComponentSource } from '../component-properties.ts'
@@ -17,7 +17,7 @@ function fresh(document: TeachingDocument, source: CanonicalSource, target: Comp
17
17
  const block = document.blocks[target.blockId]
18
18
  if (block?.type !== 'component') throw new Error('component-block-missing')
19
19
  const value = effectiveComponentParameters(document, block.id, target.stepId).parameters
20
- return { format: 1, id: crypto.randomUUID(), revision: 0, target, source, definitionId: block.definitionId, baseline: value, value,
20
+ return { format: 1, id: randomUUID(), revision: 0, target, source, definitionId: block.definitionId, baseline: value, value,
21
21
  composing: false, reset: false, updatedAt: new Date().toISOString() }
22
22
  }
23
23
  function message(error: unknown, t: ComponentPropertyMessages): string {
@@ -164,7 +164,7 @@ export function ComponentPropertiesDialog({ identity, blockId, stepId, onClose }
164
164
  const submit = async (action: DocumentComponentAction, submitted?: ComponentPropertyDraft) => {
165
165
  if (!canonical || !source?.version || !clean || current.current.busy) return
166
166
  const expected = { identity, version: source.version, fingerprint: source.fingerprint! }, signature = JSON.stringify([canonical, action])
167
- if (!intent.current || intent.current.signature !== signature || intent.current.draft !== submitted) intent.current = { signature, draft: submitted, id: crypto.randomUUID() }
167
+ if (!intent.current || intent.current.signature !== signature || intent.current.draft !== submitted) intent.current = { signature, draft: submitted, id: randomUUID() }
168
168
  const captured = intent.current, controller = new AbortController(), submittedKey = key
169
169
  flight.current = controller; current.current.busy = true; setBusy(true); setError(undefined)
170
170
  try {
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useId, useRef, useState } from 'react'
1
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
2
2
  import type { CSSProperties, ReactNode } from 'react'
3
3
  import type { BlockPreviewCommand } from '@lincyaw/kernel'
4
4
  import { toBlockPreviewPlaybackCancelled, toBlockPreviewPlaybackRequest, toBlockPreviewPosition } from '@lincyaw/kernel'
@@ -10,6 +10,7 @@ import { BLOCK_PREVIEW_MESSAGES } from './block-preview-messages.ts'
10
10
  import { documentBlockSection, DocumentStepNarration } from './DocumentStepNarration.tsx'
11
11
  import { DocumentBlockPlayback } from './block-playback.ts'
12
12
  import { ComponentPropertiesDialog } from './ComponentPropertiesDialog.tsx'
13
+ import { PlaceCommentButton } from './PlaceComment.tsx'
13
14
  import { COMPONENT_PROPERTY_MESSAGES } from '../component-property-messages.ts'
14
15
 
15
16
  interface Snapshot { address: string, revision: string }
@@ -26,11 +27,13 @@ export function DocumentBlockPreview({ blockId, fallback }: { blockId: string, f
26
27
  const position = useWorkbenchState(state => state.position)
27
28
  const navigation = useWorkbenchState(state => state.documentPositionToken)
28
29
  const navigationIntent = useWorkbenchState(state => state.documentPositionIntent)
30
+ const block = source?.content?.blocks[blockId]
31
+ const definition = block?.type === 'component' ? source?.content?.definitions[block.definitionId] : undefined
29
32
  const sectionId = source?.content && documentBlockSection(source.content, blockId)
30
33
  const section = sectionId ? source?.content?.sections[sectionId] : undefined
31
34
  const stepId = section?.stepOrder[position && position.section === sectionId ? position.step : 0] ?? section?.stepOrder[0]
32
- const [narrationOpen, setNarrationOpen] = useState(() => Boolean(workbench.pendingDocumentField(blockId, source?.identity)
33
- || source?.identity && stepId && (workbench.documentTimingDraft(stepId, 'minimumHoldMs', source.identity, source.reset) || workbench.documentTimingDraft(stepId, 'trailingPauseMs', source.identity, source.reset)))), narrationPanel = useId()
35
+ const [narrationOpen, setNarrationOpen] = useState(() => Boolean(workbench.editing.pendingField(blockId, source?.identity)
36
+ || source?.identity && stepId && (workbench.production.timingDraft(stepId, 'minimumHoldMs', source.identity, source.reset) || workbench.production.timingDraft(stepId, 'trailingPauseMs', source.identity, source.reset)))), narrationPanel = useId()
34
37
  const root = useRef<HTMLElement>(null), viewport = useRef<HTMLDivElement>(null), frame = useRef<HTMLIFrameElement | null>(null)
35
38
  const mountFrame = useCallback((element: HTMLIFrameElement | null) => {
36
39
  frame.current = element
@@ -106,6 +109,9 @@ export function DocumentBlockPreview({ blockId, fallback }: { blockId: string, f
106
109
  // A saved version changes only the runtime frame; it never resets the native editor.
107
110
  address?.searchParams.set('presmium-block-version', loadedVersion ?? '')
108
111
  address?.searchParams.set('presmium-block-refresh', `${loadedProject}:${loadedAttempt}`)
112
+ // Pin the first cursor to this frame's lifetime; playback and step selection keep the same URL.
113
+ const initialStep = useMemo(() => stepId, [address?.href, enabled])
114
+ if (initialStep) address?.searchParams.set('presmium-block-step', initialStep)
109
115
  const src = address?.href, origin = address?.origin
110
116
  const command = useCallback((action: 'seek' | 'pause', at?: 'start' | 'end', token = navigation) => {
111
117
  if (!origin || !state.snapshot || !sectionId || !stepId) return
@@ -216,7 +222,8 @@ export function DocumentBlockPreview({ blockId, fallback }: { blockId: string, f
216
222
  return <section ref={root} className="pm-ui-block-preview" data-block-preview={blockId} data-status={state.status} contentEditable={false}>
217
223
  <header className="pm-ui-block-preview__header"><span className="pm-ui-block-preview__label" role={state.status === 'failed' ? 'status' : undefined}><PmIcon name="slides" />{state.status === 'failed' ? t.previewFailure : old && state.snapshot ? t.previewPrevious : state.status === 'preparing' ? p.preparing : state.status === 'loading' ? t.previewLoading : t.previewSnapshot}</span>
218
224
  <span className="pm-ui-block-preview__actions">
219
- {source?.content?.blocks[blockId]?.type === 'component' && <PmIconButton small icon="sliders" label={COMPONENT_PROPERTY_MESSAGES[locale].properties}
225
+ {sectionId && stepId && <PlaceCommentButton blockId={blockId} sectionId={sectionId} stepId={stepId} stepIndex={section ? section.stepOrder.indexOf(stepId) + 1 : 1} onPause={pause} />}
226
+ {source && block?.type === 'component' && definition?.kind !== 'scene' && <PmIconButton small icon="sliders" label={COMPONENT_PROPERTY_MESSAGES[locale].properties}
220
227
  data-component-properties={blockId} disabled={!source.identity || workbench.client.capabilities?.readOnly} onClick={() => { if (source.identity && !workbench.client.capabilities?.readOnly) setProperties({ identity: source.identity, stepId }) }} />}
221
228
  {workbench.client.capabilities?.narration !== false && <PmIconButton small icon="captions" label={t.stepCaptions} aria-expanded={narrationOpen} aria-controls={narrationOpen ? narrationPanel : undefined} aria-pressed={narrationOpen} disabled={!stepId} onClick={() => {
222
229
  pause()
@@ -1,22 +1,29 @@
1
1
  import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
2
2
  import type { FocusEvent, ReactNode } from 'react'
3
+ import { documentAnchorOrder, isDocumentPlaceAnchor, randomUUID } from '@lincyaw/kernel'
4
+ import type { DocumentPlaceAnchor, TeachingDocument } from '@lincyaw/kernel'
3
5
  import { CommentEditorSubmitExtension, CommentsExtension } from '@blocknote/core/comments'
4
6
  import { components } from '@blocknote/mantine'
5
7
  import { FloatingThreadController, getReferenceText, Thread, useBlockNoteEditor, useCreateBlockNote, useEditorState, useExtension, useExtensionState, useThreads } from '@blocknote/react'
6
8
  import type { ComponentProps, ThreadProps } from '@blocknote/react'
7
9
  import type { Locale } from '../messages.ts'
8
10
  import { PmButton, PmEmpty, PmNotice, PmSelect } from '../components.tsx'
11
+ import { isApprovalTarget } from '../approvals.tsx'
12
+ import { useWorkbenchState } from '../context.tsx'
9
13
  import { enterSubmits } from './comments.ts'
10
14
  import type { DocumentCommentEditorHandle, DocumentThreadStore } from './comments.ts'
11
15
  import type { CommentDrafts, CommentDraftCandidate, CommentDraftRecord, CommentDraftReference, CommentDraftOperation } from './comment-drafts.ts'
12
- import { isNewCommentDraft, sameCommentDraftTarget } from './comment-drafts.ts'
13
- import { createRichProjection, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
16
+ import { commentDraftBaseline, isNewCommentDraft, sameCommentDraftTarget } from './comment-drafts.ts'
17
+ import { discardNativeCommentDraft } from './comment-draft-actions.ts'
18
+ import { waitForDraft } from '../document-draft-store.ts'
19
+ import { createRichProjection, fallbackText, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
14
20
  import { commentEditorSchema } from './schema.tsx'
15
21
  import type { DocumentEditorBlock } from './schema.tsx'
16
22
  import { DOCUMENT_EDITOR_MESSAGES } from './messages.ts'
23
+ import { componentDefinitionLabel } from './component-label.ts'
17
24
  import { commentFloating } from './popover.tsx'
18
25
 
19
- export const COMMENT_EDITOR_CONTEXT = createContext<{ store: DocumentThreadStore, locale: Locale, sidebar: boolean, getPositionToken?(): string | undefined, onDraftRestore?(): void } | undefined>(undefined)
26
+ export const COMMENT_EDITOR_CONTEXT = createContext<{ store: DocumentThreadStore, locale: Locale, sidebar: boolean, readOnly?: boolean, getPositionToken?(): string | undefined, onDraftRestore?(): void, openComments?(): void } | undefined>(undefined)
20
27
  const THREAD_CONTEXT = createContext<string | undefined>(undefined)
21
28
  const emptySubscribe = () => () => {}
22
29
  const emptyState = { candidates: [], pending: false, failed: false, reading: false } as const
@@ -32,12 +39,14 @@ export function DocumentCommentThread(props: ThreadProps) {
32
39
 
33
40
  /** Keep the native controller and reply editor while body selection owns the pointer. */
34
41
  export function DocumentFloatingThreadController() {
35
- const editor = useBlockNoteEditor(), { selectedThreadId } = useExtensionState(CommentsExtension)
42
+ const editor = useBlockNoteEditor(), { selectedThreadId, threadPositions } = useExtensionState(CommentsExtension)
36
43
  const empty = useEditorState({ editor, on: 'selection', selector: ({ editor }) => editor.prosemirrorState.selection.empty })
37
44
  const [selecting, setSelecting] = useState(false)
38
45
  const blocked = selecting || !empty
46
+ // A place thread has no text mark; it belongs to the sidebar only and must not open a floating card.
47
+ const positioned = Boolean(selectedThreadId && threadPositions.has(selectedThreadId))
39
48
  const shown = useRef(false), thread = useRef(selectedThreadId)
40
- shown.current = Boolean(selectedThreadId) && !blocked
49
+ shown.current = positioned && !blocked
41
50
  thread.current = selectedThreadId
42
51
  // The pointer that last pressed commented text, and the line of the thread chosen from it (the first line without one).
43
52
  const point = useRef<{ x: number, y: number }>(), line = useRef<{ thread: string, index: number }>()
@@ -101,26 +110,69 @@ export function DocumentFloatingThreadController() {
101
110
  return rects[Math.min(line.current.index, rects.length - 1)]
102
111
  }), [editor])
103
112
  return <FloatingThreadController floatingThread={DocumentCommentThread} floatingUIOptions={{
104
- useFloatingOptions: { ...floating, open: Boolean(selectedThreadId) && !blocked },
113
+ useFloatingOptions: { ...floating, open: positioned && !blocked },
105
114
  elementProps: { className: blocked ? 'pm-ui-comment-hidden' : undefined },
106
115
  }} />
107
116
  }
108
117
 
118
+ export function placeReference(document: TeachingDocument | undefined, anchor: DocumentPlaceAnchor, t: typeof DOCUMENT_EDITOR_MESSAGES['zh-CN']): string {
119
+ if (!document) return ''
120
+ const block = document.blocks[anchor.blockId]
121
+ let label: string
122
+ if (block?.type === 'component') {
123
+ const definition = document.definitions[block.definitionId]
124
+ const author = typeof block.parameters.title === 'string' ? block.parameters.title.trim() : ''
125
+ const data = definition?.data && typeof definition.data.title === 'string' ? definition.data.title.trim() : ''
126
+ const schema = definition && typeof definition.parameterSchema === 'object' && typeof definition.parameterSchema.title === 'string' ? definition.parameterSchema.title.trim() : ''
127
+ const name = author || data || schema || (definition ? componentDefinitionLabel(definition) : block.definitionId)
128
+ label = definition?.kind === 'scene' ? t.animation(name) : t.component(name)
129
+ } else if (block?.type === 'code') label = t.codeReference(block.title ?? block.origin?.anchor ?? block.language)
130
+ else if (block?.type === 'image') label = block.alt || t.block
131
+ else if (block?.type === 'text') label = (block.content[0] ? Array.from(fallbackText(block.content[0]).replace(/\s+/g, ' ').trim()).slice(0, 40).join('') : '') || t.block
132
+ else if (block?.type === 'container') label = block.properties.title || t.block
133
+ else label = t.block
134
+ if (anchor.stepId === undefined) return t.placeCommentReference(label)
135
+ const step = document.steps[anchor.stepId], section = step ? document.sections[step.sectionId] : undefined
136
+ return t.placeCommentReference(label, step && section ? section.stepOrder.indexOf(step.id) + 1 : 0)
137
+ }
138
+
109
139
  /** Native Thread composition, with the same public focus/blur and position ordering as the sidebar. */
110
140
  export function DocumentThreadsSidebar({ children }: { children?: ReactNode }) {
111
141
  const editor = useBlockNoteEditor(), comments = useExtension(CommentsExtension), threads = useThreads()
112
142
  const { selectedThreadId, threadPositions } = useExtensionState(CommentsExtension)
113
- const ordered = [...threads.values()].sort((a, b) => (threadPositions.get(a.id)?.from ?? Number.MAX_VALUE) - (threadPositions.get(b.id)?.from ?? Number.MAX_VALUE))
143
+ const context = useContext(COMMENT_EDITOR_CONTEXT), t = DOCUMENT_EDITOR_MESSAGES[context?.locale ?? 'en']
144
+ const document = useWorkbenchState(state => state.authoring?.content) ?? context?.store.document
145
+ const places = useMemo(() => document ? documentAnchorOrder(document) : new Map<string, number>(), [document])
146
+ const place = (threadId: string): number => {
147
+ const anchor = context?.store.anchorOf(threadId)
148
+ if (!anchor) return Number.MAX_VALUE
149
+ if (isDocumentPlaceAnchor(anchor)) {
150
+ const order = places.get(anchor.blockId)
151
+ const step = anchor.stepId === undefined ? undefined : document?.steps[anchor.stepId]
152
+ const section = step && document ? document.sections[step.sectionId] : undefined
153
+ return order === undefined ? Number.MAX_VALUE : order * 1_000_000 + (step && section ? section.stepOrder.indexOf(step.id) : 0)
154
+ }
155
+ const order = places.get(anchor.from.blockId)
156
+ return order === undefined ? Number.MAX_VALUE : order * 1_000_000 + Math.min(999_999, anchor.from.offset)
157
+ }
158
+ const reference = (threadId: string): string | undefined => {
159
+ const anchor = context?.store.anchorOf(threadId)
160
+ return anchor && isDocumentPlaceAnchor(anchor) ? placeReference(document, anchor, t) : getReferenceText(editor, threadPositions.get(threadId))
161
+ }
162
+ const orphaned = (threadId: string): boolean => {
163
+ const anchor = context?.store.anchorOf(threadId)
164
+ return !(anchor && isDocumentPlaceAnchor(anchor)) && !threadPositions.has(threadId)
165
+ }
166
+ const ordered = [...threads.values()].sort((a, b) => place(a.id) - place(b.id) || a.createdAt.getTime() - b.createdAt.getTime())
114
167
  const focus = (id: string, event: FocusEvent) => { if (!(event.target as HTMLElement).closest('.bn-action-toolbar')) comments.selectThread(id) }
115
168
  const blur = (event: FocusEvent) => {
116
169
  const next = event.relatedTarget
117
- if (!next || next.closest('.bn-action-toolbar')) return
170
+ if (!next || isApprovalTarget(next) || next.closest('.bn-action-toolbar')) return
118
171
  const parent = next.closest('.bn-thread')
119
172
  if (!parent || !(event.target instanceof Node) || !parent.contains(event.target)) comments.selectThread(undefined)
120
173
  }
121
- const context = useContext(COMMENT_EDITOR_CONTEXT), t = DOCUMENT_EDITOR_MESSAGES[context?.locale ?? 'en']
122
174
  return <div className="bn-threads-sidebar">{children}<CommentDraftRetrieval />{!ordered.length && <PmEmpty icon="comment">{t.commentsEmpty}</PmEmpty>}{ordered.map(thread => <DocumentCommentThread key={thread.id} thread={thread}
123
- selected={selectedThreadId === thread.id} orphaned={!threadPositions.has(thread.id)} referenceText={getReferenceText(editor, threadPositions.get(thread.id))}
175
+ selected={selectedThreadId === thread.id} orphaned={orphaned(thread.id)} referenceText={reference(thread.id)}
124
176
  onFocus={event => focus(thread.id, event)} onBlur={blur} tabIndex={0} />)}</div>
125
177
  }
126
178
 
@@ -174,7 +226,7 @@ export function DocumentCommentEditor(props: ComponentProps['Comments']['Editor'
174
226
  return value
175
227
  }, [props.editor, drafts])
176
228
  const rich = useMemo(() => ({ current: record.rich }), [record])
177
- const composerId = useRef(crypto.randomUUID())
229
+ const composerId = useRef(randomUUID())
178
230
  const state = useSyncExternalStore(drafts?.subscribe ?? emptySubscribe, drafts?.snapshot ?? (() => emptyState))
179
231
  useLayoutEffect(() => {
180
232
  if (!context || !threadId) return
@@ -242,7 +294,7 @@ export function DocumentCommentEditor(props: ComponentProps['Comments']['Editor'
242
294
  || props.editor.prosemirrorState.selection !== native.selection || context.getPositionToken?.() !== position || record.current !== own
243
295
  || context.store.draftTargetState(target) === 'unavailable') throw new Error('client-comment-composer-changed')
244
296
  }
245
- if (own && !await drafts.confirm(own)) return
297
+ if (own && !await waitForDraft(drafts.confirm(own), operation?.signal)) return
246
298
  owns()
247
299
  const value = await drafts.recover(candidate, target, version, { signal: operation?.signal, guard: owns })
248
300
  if (!value) return
@@ -258,11 +310,30 @@ export function DocumentCommentEditor(props: ComponentProps['Comments']['Editor'
258
310
  if (!operation) await drafts.discard(candidate)
259
311
  return value
260
312
  }
313
+ const discardActive = async (candidate: CommentDraftCandidate, operation?: CommentDraftOperation): Promise<boolean> => {
314
+ const own = record.current, version = context?.store.version, before = input.current, native = props.editor.prosemirrorState, position = context?.getPositionToken?.()
315
+ if (!drafts || !context || !target || !version || !own || own.id !== candidate.id || own.revision !== candidate.revision) return false
316
+ const guard = () => {
317
+ context.store.beforeAction?.()
318
+ if (!active.current || !current.current.editable || context.store.version !== version || composing.current || submitting.current || input.current !== before || record.current !== own
319
+ || props.editor.prosemirrorView.isDestroyed || props.editor.prosemirrorView.composing || props.editor.prosemirrorState.doc !== native.doc
320
+ || props.editor.prosemirrorState.selection !== native.selection || context.getPositionToken?.() !== position) throw new Error('client-comment-composer-changed')
321
+ }
322
+ const saved = target.commentId ? context.store.threadSnapshot(target.threadId)?.comments.find(value => value.id === target.commentId && !value.deletedAt) : undefined
323
+ if (target.commentId && !saved?.content) return false
324
+ return discardNativeCommentDraft(drafts, candidate, operation, guard, () => {
325
+ suppress.current = true
326
+ try {
327
+ props.editor.replaceBlocks(props.editor.document, saved?.content ? productRichTextToNative(saved.content, rich.current) : [{ type: 'paragraph', content: [] }])
328
+ record.current = undefined; input.current++; handle?.restoreBaseline(saved ? commentDraftBaseline(saved) : undefined); setRevision(value => value + 1)
329
+ } finally { suppress.current = false }
330
+ })
331
+ }
261
332
  useLayoutEffect(() => {
262
333
  if (!drafts || !target || !props.editable) return
263
334
  return drafts.registerComposer({ id: composerId.current, target,
264
335
  snapshot: () => { const available = active.current && current.current.editable && !submitting.current && !props.editor.prosemirrorView.isDestroyed; return { record: record.current, composing: composing.current || available && props.editor.prosemirrorView.composing, available } },
265
- targetState: () => context?.store.draftTargetState(target) ?? 'unavailable', restore: recover })
336
+ targetState: () => context?.store.draftTargetState(target) ?? 'unavailable', restore: recover, discard: discardActive })
266
337
  }, [drafts, handle, props.editor, props.editable])
267
338
  const composition = (value: boolean) => {
268
339
  composing.current = value
@@ -276,7 +347,7 @@ export function DocumentCommentEditor(props: ComponentProps['Comments']['Editor'
276
347
  <MantineCommentEditor {...props} />
277
348
  {recoveryFailure && <PmNotice tone="warn">{t.commentRecoveryChanged}</PmNotice>}
278
349
  {failure && <PmNotice tone="danger">{failure === 'changed' ? t.commentChanged : t.commentUnavailable}</PmNotice>}
279
- {drafts && props.editable && <DraftChoices candidates={candidates} disabled={composing.current || submitting.current} onRecover={async candidate => { const captured = handle, owner = recoveryOwner.current; setRecoveryFailure(false); try { await recover(candidate) } catch { if (active.current && current.current.editable && currentHandle.current === captured && recoveryOwner.current === owner) setRecoveryFailure(true) } }} onDiscard={async candidate => { await drafts.discard(candidate) }} />}
350
+ {drafts && props.editable && <DraftChoices candidates={candidates} disabled={composing.current || submitting.current} onRecover={async candidate => { const captured = handle, owner = recoveryOwner.current; setRecoveryFailure(false); try { await recover(candidate) } catch { if (active.current && current.current.editable && currentHandle.current === captured && recoveryOwner.current === owner) setRecoveryFailure(true) } }} onDiscard={async candidate => { await drafts.discardProposal(candidate) }} />}
280
351
  {drafts && props.editable && state.failed && !context?.sidebar && <PmNotice tone="warn">{t.commentBackupFailed}</PmNotice>}
281
352
  </div>
282
353
  }
@@ -1,7 +1,9 @@
1
1
  import { useEffect, useMemo, useRef } from 'react'
2
+ import { markAgentTargets } from './agent-targets.ts'
2
3
  import type { Transaction } from '@tiptap/pm/state'
4
+ import { TextSelection } from '@tiptap/pm/state'
3
5
  import { closeHistory } from '@tiptap/pm/history'
4
- import { allocateDocumentPage } from '@lincyaw/kernel'
6
+ import { allocateDocumentPage, randomUUID } from '@lincyaw/kernel'
5
7
  import type { Member, TeachingDocument } from '@lincyaw/kernel'
6
8
  import type { Locale } from '../messages.ts'
7
9
  import { BlockNoteSurface } from './BlockNoteSurface.tsx'
@@ -12,20 +14,29 @@ import type { NativePageCreation } from './projection.ts'
12
14
  import { captureRichBaseline } from './rich-text.ts'
13
15
  import { captureTableIdentities, seedTableIdentities } from './table-identities.ts'
14
16
  import type { DocumentNodeViews, NativeDocumentEditor } from './schema.tsx'
15
- import { nativeEditingCursor } from './selection.ts'
16
- import type { NativeDocumentSelection } from './selection.ts'
17
+ import { nativeEditingCursor, nativeTextPoint, nativeTextPosition } from './selection.ts'
18
+ import type { NativeDocumentSelection, NativeTextPoint } from './selection.ts'
19
+ import { documentInsertionPlace } from './insertion-place.ts'
20
+ import type { DocumentInsertionPlace } from './insertion-place.ts'
17
21
 
18
22
  export interface DocumentEditingPosition {
19
23
  nativeBlockId: string
20
24
  sectionId: string
21
25
  position: number
22
26
  }
27
+ /** Who takes the slash menu's request for an animation where it was opened; while none is available the menu has no such item. */
28
+ export interface DocumentAnimationRequests {
29
+ available(): boolean
30
+ request(place: DocumentInsertionPlace): void
31
+ }
23
32
  export interface DocumentEditorCommands {
24
33
  insertPage(after: string | undefined, title: string): NativePageCreation
25
34
  rememberComponentConfiguration(document: TeachingDocument): void
35
+ handleAnimationRequests(requests: DocumentAnimationRequests | undefined): void
26
36
  }
27
37
 
28
38
  export interface DocumentEditorProps {
39
+ agentActivities?: import('@lincyaw/kernel').AgentActivity[]
29
40
  identity: string
30
41
  document: TeachingDocument
31
42
  version?: string
@@ -56,6 +67,7 @@ export interface DocumentEditorProps {
56
67
  onError?(error: Error): void
57
68
  commentsPortal?: HTMLElement | null
58
69
  onCommentDraftRestore?(): void
70
+ onOpenComments?(): void
59
71
  }
60
72
 
61
73
  /** A source version reset replaces the editor; its own save receipts never replace it. */
@@ -73,13 +85,31 @@ export function DocumentEditor(props: DocumentEditorProps) {
73
85
  return () => comments.close()
74
86
  }, [comments])
75
87
  const current = useRef(props), editor = useRef<NativeDocumentEditor>(), unsubscribe = useRef<() => void>()
88
+ const animationRequests = useRef<DocumentAnimationRequests>()
76
89
  const projectedDocument = useRef<NativeDocumentEditor['prosemirrorState']['doc']>()
77
90
  const pendingTransaction = useRef<Transaction>()
78
91
  const focusFrame = useRef<number>()
79
92
  const binding = useRef(projection)
80
93
  const active = useRef(projection)
94
+ const editorIdentity = useRef(props.identity)
95
+ const retainedSelection = useRef<{ from: NativeTextPoint, to: NativeTextPoint }>()
96
+ const previous = editor.current
97
+ if (binding.current !== projection && editorIdentity.current === props.identity && previous?.isFocused() && !previous.prosemirrorView.composing) {
98
+ const from = nativeTextPoint(previous, previous.prosemirrorState.selection.anchor), to = nativeTextPoint(previous, previous.prosemirrorState.selection.head)
99
+ if (from && to) retainedSelection.current = { from, to }
100
+ }
81
101
  active.current = projection
82
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])
83
113
  const cancelFocus = () => { if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current); focusFrame.current = undefined }
84
114
  const reportPosition = () => {
85
115
  const value = editor.current
@@ -113,7 +143,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
113
143
  if (!latest || current.current.getDocumentVersion && current.current.getDocumentVersion() === undefined) return
114
144
  syncComments()
115
145
  const document = nativeDocumentToProduct(editor.current.document, projection, latest)
116
- const threads = comments.snapshot(editor.current)
146
+ const threads = comments.snapshot(editor.current, document)
117
147
  if (Object.keys(threads).length) document.comments = threads
118
148
  else delete document.comments
119
149
  current.current.onChange(document)
@@ -125,7 +155,16 @@ export function DocumentEditor(props: DocumentEditorProps) {
125
155
  }
126
156
  return <BlockNoteSurface identity={props.identity} reset={props.reset} initialContent={projection.content} locale={props.locale} contentLang={props.document.metadata.lang || 'zh-CN'} readOnly={props.readOnly}
127
157
  resolveAssetURL={props.resolveAssetURL} uploadImage={props.uploadImage}
128
- comments={comments} commentsPortal={props.commentsPortal} onCommentDraftRestore={() => current.current.onCommentDraftRestore?.()} nodeViews={props.nodeViews} onComposition={props.onComposition} onSelection={props.onSelection} onSectionLink={sectionId => {
158
+ comments={comments} commentsPortal={props.commentsPortal} onCommentDraftRestore={() => current.current.onCommentDraftRestore?.()} onOpenComments={() => current.current.onOpenComments?.()} nodeViews={props.nodeViews} onComposition={props.onComposition} onSelection={props.onSelection}
159
+ animationRequest={{
160
+ available: () => !current.current.readOnly && binding.current === projection && active.current === projection && Boolean(animationRequests.current?.available()),
161
+ request: value => {
162
+ if (value !== editor.current || binding.current !== projection || active.current !== projection) return
163
+ const place = documentInsertionPlace(value, projection)
164
+ if (place) animationRequests.current?.request(place)
165
+ },
166
+ }}
167
+ onSectionLink={sectionId => {
129
168
  if (!current.current.onSectionLink?.(sectionId)) return false
130
169
  // The click placed the caret in the link; it follows the reader to the page they asked for.
131
170
  const value = editor.current
@@ -147,7 +186,17 @@ export function DocumentEditor(props: DocumentEditorProps) {
147
186
  comments.restoreAnchors(value)
148
187
  binding.current = projection
149
188
  editor.current = value
189
+ editorIdentity.current = props.identity
150
190
  projectedDocument.current = value.prosemirrorState.doc
191
+ const selection = retainedSelection.current
192
+ retainedSelection.current = undefined
193
+ if (selection) {
194
+ const from = nativeTextPosition(value, selection.from), to = nativeTextPosition(value, selection.to)
195
+ if (from !== undefined && to !== undefined) {
196
+ value.transact(transaction => transaction.setSelection(TextSelection.create(transaction.doc, from, to)).setMeta('addToHistory', false))
197
+ value.focus()
198
+ }
199
+ }
151
200
  const stopBefore = value.onBeforeChange(({ tr }) => { if (!comments.synchronizing && tr.docChanged) pendingTransaction.current = tr })
152
201
  const stopComments = comments.subscribe(emit)
153
202
  const stopSelection = value.onSelectionChange(() => { cancelFocus(); reportPosition() })
@@ -162,7 +211,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
162
211
  })
163
212
  unsubscribe.current = () => { stopBefore(); stopComments(); stopSelection(); stopFocus(); cancelFocus() }
164
213
  }
165
- const commands: DocumentEditorCommands | undefined = value ? { rememberComponentConfiguration: document => {
214
+ const commands: DocumentEditorCommands | undefined = value ? { handleAnimationRequests: requests => { animationRequests.current = requests }, rememberComponentConfiguration: document => {
166
215
  if (editor.current === value && active.current === projection && binding.current === projection && !value.prosemirrorView.isDestroyed) rememberComponentConfiguration(projection, document)
167
216
  }, insertPage: (after, title) => {
168
217
  if (current.current.readOnly || editor.current !== value || active.current !== projection || binding.current !== projection || value.prosemirrorView.isDestroyed) throw new Error('page-context-changed')
@@ -171,7 +220,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
171
220
  const next = after ? blocks.slice(index + 1).find(block => block.type === 'presmiumPage') : undefined
172
221
  const latest = current.current.getDocument ? current.current.getDocument() : current.current.document
173
222
  if (!latest) throw new Error('page-context-changed')
174
- const creation = allocateDocumentPage(latest, () => crypto.randomUUID())
223
+ const creation = allocateDocumentPage(latest, () => randomUUID())
175
224
  projection.createdPages.set(creation.sectionId, creation)
176
225
  try {
177
226
  value.transact(transaction => {
@@ -1,11 +1,13 @@
1
1
  import { useRef, useState } from 'react'
2
- import type { NarrationNode, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { Narration, NarrationNode, TeachingDocument } from '@lincyaw/kernel'
3
+ import { randomUUID } from '@lincyaw/kernel'
3
4
  import { PmIconButton } from '../components.tsx'
4
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
5
- import { isAgentChanging } from '../workbench.ts'
6
+ import { isAgentChanging } from '../workbench-state.ts'
7
+ import { latestAgentActivity } from '../agent-activity.ts'
6
8
  import { NarrationEditor } from './NarrationEditor.tsx'
7
9
  import { DOCUMENT_EDITOR_MESSAGES } from './messages.ts'
8
- import { narrationFieldFocus } from './narration.ts'
10
+ import { narrationFieldFocus, narrationsToNative, nativeToNarrations } from './narration.ts'
9
11
  import type { NativeNarrationEditor } from './narration-schema.tsx'
10
12
  import { StepProductionEditor } from '../StepProductionEditor.tsx'
11
13
 
@@ -23,28 +25,32 @@ export function narrationDisplay(content: readonly NarrationNode[]): string {
23
25
  return content.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
24
26
  }
25
27
 
26
- function NarrationField({ identity, reset, blockId, stepId, slot, narrationId, content, readOnly, advanced, onPause }: {
27
- identity: string, reset: number, blockId?: string, stepId: string, slot: number, narrationId?: string, content: NarrationNode[], readOnly: boolean, advanced: boolean, onPause(): void,
28
+ function NarrationField({ identity, reset, blockId, stepId, content, readOnly, advanced, onPause }: {
29
+ identity: string, reset: number, blockId?: string, stepId: string, content: Narration[], readOnly: boolean, advanced: boolean, onPause(): void,
28
30
  }) {
29
31
  const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale)
30
- // Reserving an identity does not create an entity. The first actual input commits it.
31
- const [reservedId] = useState(() => {
32
- const pending = workbench.pendingDocumentField(blockId, identity)
33
- return narrationId ?? (pending?.stepId === stepId ? pending.narrationId : undefined) ?? crypto.randomUUID()
34
- })
35
- const id = narrationId ?? reservedId
36
- const target = () => narrationId ?? workbench.getDocument(identity)?.steps[stepId]?.narrationIds[slot] ?? id
32
+ const [emptyId] = useState(() => randomUUID())
33
+ const read = () => {
34
+ const document = workbench.getDocument(identity), step = document?.steps[stepId]
35
+ return step ? step.narrationIds.map(id => ({ id, content: document!.narrations[id]!.content })) : undefined
36
+ }
37
37
  const registration = useRef<() => void>()
38
38
  const fieldEditor = useRef<NativeNarrationEditor>()
39
- const owner = `narration:${identity}:${reset}:${JSON.stringify(blockId ?? null)}:${stepId}:${slot}:${id}`
40
- return <NarrationEditor identity={identity} reset={reset} narrationId={id} content={content} locale={locale} readOnly={readOnly} advanced={advanced}
41
- getContent={() => { const document = workbench.getDocument(identity); return document ? document.narrations[target()]?.content ?? [] : undefined }}
39
+ const owner = `narration:${identity}:${reset}:${JSON.stringify(blockId ?? null)}:${stepId}`
40
+ return <NarrationEditor identity={identity} reset={reset} fieldId={stepId} content={content} locale={locale} readOnly={readOnly} advanced={advanced} blockMenu
41
+ getContent={read} toNative={value => narrationsToNative(value, emptyId)} fromNative={nativeToNarrations}
42
+ cueOwners={() => {
43
+ const document = workbench.getDocument(identity)
44
+ const retained = new Set(Object.values(document?.steps ?? {}).filter(step => step.id !== stepId).flatMap(step => step.narrationIds))
45
+ return new Map([...retained].flatMap(id => document!.narrations[id]!.content.flatMap(node => node.type === 'cue' ? [[node.id, id] as const] : [])))
46
+ }}
47
+ onCueCopy={(from, to) => workbench.production.copyNarrationCueTiming(from, to, identity)}
42
48
  onReady={editor => {
43
49
  registration.current?.()
44
50
  fieldEditor.current = editor
45
- registration.current = editor ? workbench.registerDocumentField({ identity, reset, blockId, stepId, narrationId: id, slot, focus: narrationFieldFocus(editor), editor }) : undefined
51
+ registration.current = editor ? workbench.editing.registerField({ identity, reset, blockId, stepId, focus: narrationFieldFocus(editor), editor }) : undefined
46
52
  }}
47
- onFocus={() => { workbench.documentInteraction(); if (fieldEditor.current) workbench.activateDocumentHistory(fieldEditor.current); onPause() }} onChange={value => workbench.setDocumentNarration(stepId, target(), value, identity)}
53
+ onFocus={() => { workbench.editing.interact(); if (fieldEditor.current) workbench.editing.activateHistory(fieldEditor.current); onPause() }} onChange={value => workbench.production.setNarrations(stepId, value, identity)}
48
54
  onComposition={composing => workbench.documentComposition(composing, owner, identity)}
49
55
  onError={error => workbench.documentError(error)} />
50
56
  }
@@ -57,6 +63,8 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
57
63
  const locale = useWorkbenchState(state => state.locale), t = DOCUMENT_EDITOR_MESSAGES[locale]
58
64
  const readOnly = useWorkbenchState(state => workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.loading) || isAgentChanging(state))
59
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)))
60
68
  if (workbench.client.capabilities?.narration === false) return null
61
69
  const document = source?.content, section = document?.sections[sectionId], step = document?.steps[stepId]
62
70
  if (!source?.identity || !document || !section || !step) return null
@@ -67,7 +75,7 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
67
75
  const id = section.stepOrder[index + offset]
68
76
  if (id) { onPause(); workbench.selectDocumentStep(sectionId, id) }
69
77
  }
70
- 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}>
71
79
  <header className="pm-ui-block-preview__narration-header">
72
80
  <span className="pm-ui-block-preview__step-label">{label}</span>
73
81
  <span className="pm-ui-block-preview__actions">
@@ -78,15 +86,18 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
78
86
  {!expanded && text && <p className="pm-ui-block-preview__caption" data-step-caption={stepId}>{text}</p>}
79
87
  {expanded && <div id={panelId} className="pm-ui-block-preview__narration-fields">
80
88
  {showLabel && <span className="pm-ui-block-preview__step-label">{fieldLabel}</span>}
81
- {(ids.length ? ids : [undefined]).map((id, slot) => <NarrationField key={`${source.identity}:${source.reset}:${stepId}:${slot}`}
82
- identity={source.identity!} reset={source.reset} blockId={blockId} stepId={stepId} slot={slot} narrationId={id}
83
- content={id ? document.narrations[id]?.content ?? [] : []} readOnly={readOnly} advanced={advanced} onPause={onPause} />)}
84
- <StepProductionEditor key={`${source.identity}:${source.reset}:${stepId}`} document={document} stepId={stepId} locale={locale} readOnly={readOnly} advanced={advanced}
85
- onPause={onPause} onInteraction={() => workbench.documentInteraction()}
86
- onChange={patch => workbench.setDocumentStepProduction(stepId, patch, source.identity)}
87
- drafts={{ minimumHoldMs: workbench.documentTimingDraft(stepId, 'minimumHoldMs', source.identity, source.reset), trailingPauseMs: workbench.documentTimingDraft(stepId, 'trailingPauseMs', source.identity, source.reset) }}
89
+ <NarrationField key={`narration:${source.identity}:${source.reset}:${stepId}`}
90
+ identity={source.identity!} reset={source.reset} blockId={blockId} stepId={stepId}
91
+ content={ids.map(id => ({ id, content: document.narrations[id]!.content }))} readOnly={readOnly} advanced={advanced} onPause={onPause} />
92
+ <StepProductionEditor key={`timing:${source.identity}:${source.reset}:${stepId}`} document={document} stepId={stepId} locale={locale} readOnly={readOnly} advanced={advanced}
93
+ onPause={onPause} onInteraction={() => workbench.editing.interact()}
94
+ onChange={patch => workbench.production.setStepTiming(stepId, patch, source.identity)}
95
+ drafts={{ minimumHoldMs: workbench.production.timingDraft(stepId, 'minimumHoldMs', source.identity, source.reset), trailingPauseMs: workbench.production.timingDraft(stepId, 'trailingPauseMs', source.identity, source.reset) }}
88
96
  draftStorageFailure={timingStorageFailure}
89
- onDraft={(key, draft) => workbench.setDocumentTimingDraft(stepId, key, draft, source.identity!, source.reset)}
97
+ onDraft={(key, draft) => workbench.production.setTimingDraft(stepId, key, draft, source.identity!, source.reset)}
98
+ draftControlKey={JSON.stringify([source.identity, source.reset, stepId])}
99
+ registerDraftControl={(key, control) => workbench.production.registerDraftView({ identity: source.identity!, kind: 'step-timing',
100
+ has: target => target === JSON.stringify([stepId, key]), blocked: () => control.composing(), clear: () => control.clear() })}
90
101
  onComposition={(key, composing) => workbench.documentComposition(composing, `production:${source.identity}:${source.reset}:${blockId}:${stepId}:${key}`, source.identity)} />
91
102
  </div>}
92
103
  </section>