@lincyaw/workbench 0.2.0-rc.5 → 0.2.0-rc.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/MediaClipEditor.tsx +1 -1
- package/src/audio-recording.ts +27 -5
- package/src/authoring-client.ts +10 -10
- package/src/authoring-draft-fragment.ts +3 -1
- package/src/body-draft-actions.ts +60 -0
- package/src/component-property-drafts.ts +5 -5
- package/src/components.tsx +10 -28
- package/src/context.tsx +2 -1
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +28 -19
- package/src/document-editing.ts +484 -0
- package/src/document-editor/BlockNoteSurface.tsx +25 -9
- package/src/document-editor/ComponentMaterials.tsx +3 -9
- package/src/document-editor/ComponentPropertiesDialog.tsx +4 -4
- package/src/document-editor/DocumentBlockPreview.tsx +4 -2
- package/src/document-editor/DocumentComments.tsx +58 -9
- package/src/document-editor/DocumentEditor.tsx +44 -7
- package/src/document-editor/DocumentStepNarration.tsx +30 -25
- package/src/document-editor/NarrationEditor.tsx +54 -20
- package/src/document-editor/NewCommentDrafts.tsx +4 -3
- package/src/document-editor/PlaceComment.tsx +150 -0
- package/src/document-editor/comment-drafts.ts +16 -14
- package/src/document-editor/comments.ts +30 -10
- package/src/document-editor/component-label.ts +11 -0
- package/src/document-editor/file-input.ts +2 -2
- package/src/document-editor/focus.ts +0 -2
- package/src/document-editor/insertion-place.ts +60 -0
- package/src/document-editor/messages.ts +3 -3
- package/src/document-editor/narration-schema.tsx +12 -6
- package/src/document-editor/narration.ts +19 -3
- package/src/document-editor/page-body.ts +60 -0
- package/src/document-editor/projection.ts +2 -2
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +12 -1
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-production.ts +331 -0
- package/src/document-session.ts +190 -51
- package/src/history.ts +3 -3
- package/src/index.ts +5 -5
- package/src/jobs.ts +1 -1
- package/src/messages.ts +19 -4
- package/src/panels/DocumentView.tsx +66 -26
- package/src/panels/DocumentVoiceDialog.tsx +2 -2
- package/src/panels/DocumentVoiceField.tsx +1 -1
- package/src/panels/ExportPanel.tsx +1 -6
- package/src/panels/HistoryPanel.tsx +1 -1
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +1 -4
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +7 -7
- package/src/panels/ProductionMediaClips.tsx +6 -5
- package/src/panels/ProductionPanel.tsx +8 -4
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +4 -4
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +5 -4
- package/src/panels/SourceDocumentPanel.tsx +12 -15
- package/src/panels/TranscriptionAdoption.tsx +9 -8
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoiceoverDialog.tsx +1 -1
- package/src/places.ts +1 -36
- package/src/preview-playback.ts +1 -1
- package/src/production-messages.ts +6 -0
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/sha256.ts +9 -0
- package/src/styles.css +16 -41
- package/src/use-recording-adoption.ts +2 -2
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +157 -0
- package/src/workbench.ts +177 -943
- package/src/workspace-client.ts +6 -5
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { forwardRef, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import type { ForwardRefExoticComponent, ReactNode, RefAttributes } from 'react'
|
|
3
|
+
import { randomUUID } from '@lincyaw/kernel'
|
|
3
4
|
import { filterSuggestionItems } from '@blocknote/core'
|
|
4
5
|
import { BlockNoteView, components } from '@blocknote/mantine'
|
|
5
6
|
import { AddCommentButton, BasicTextStyleButton, BlockNoteViewEditor, BlockTypeSelect, ComponentsContext, CreateLinkButton, FormattingToolbar, FormattingToolbarController, getDefaultReactSlashMenuItems, LinkToolbarController, NestBlockButton, RenderInPortalElement, SideMenuController, SuggestionMenuController, TableCellMergeButton, TableHandlesController, TextAlignButton, UnnestBlockButton, useBlockNoteEditor, useCreateBlockNote, useEditorState } from '@blocknote/react'
|
|
6
7
|
import type { ComponentProps, FormattingToolbarProps } from '@blocknote/react'
|
|
7
8
|
import { useMediaQuery } from '@mantine/hooks'
|
|
8
9
|
import type { Locale } from '../messages.ts'
|
|
9
|
-
import { PmIconButton, PmNotice, PmTooltip } from '../components.tsx'
|
|
10
|
+
import { PmIcon, PmIconButton, PmNotice, PmTooltip } from '../components.tsx'
|
|
10
11
|
import { DOCUMENT_NODE_VIEWS, documentEditorSchema } from './schema.tsx'
|
|
11
12
|
import type { DocumentEditorBlock, DocumentEditorInput, DocumentNodeViews, NativeDocumentEditor } from './schema.tsx'
|
|
12
13
|
import { documentSelection } from './selection.ts'
|
|
@@ -16,6 +17,7 @@ import { blockNoteDictionary } from './blocknote-messages.ts'
|
|
|
16
17
|
import { imageFileInput } from './file-input.ts'
|
|
17
18
|
import type { ImageImportFailure } from './file-input.ts'
|
|
18
19
|
import { nativeTextClipboard } from './clipboard.ts'
|
|
20
|
+
import { documentPageBodies, focusDocumentEnd } from './page-body.ts'
|
|
19
21
|
import { documentBlockColors } from './colors.ts'
|
|
20
22
|
import { DOCUMENT_EDITOR_LOCALE } from './math.tsx'
|
|
21
23
|
import { DOCUMENT_LINKS, DocumentColorButton, DocumentLinkToolbar, DocumentSideMenu, DocumentTableCellButton, DocumentTableHandle, FormulaToolbarButton, formulaSlashItems, openDocumentLink } from './authoring.tsx'
|
|
@@ -80,10 +82,14 @@ export interface BlockNoteSurfaceProps {
|
|
|
80
82
|
commentsPortal?: HTMLElement | null
|
|
81
83
|
getPositionToken?(): string | undefined
|
|
82
84
|
onCommentDraftRestore?(): void
|
|
85
|
+
/** The author asked to see the comments pane, e.g. after saving a place comment. */
|
|
86
|
+
onOpenComments?(): void
|
|
83
87
|
onReady?(editor: NativeDocumentEditor | undefined): void
|
|
84
88
|
onComposition?(composing: boolean): void
|
|
85
89
|
/** Shows a page of this document from an in-document link; false when none matches. */
|
|
86
90
|
onSectionLink?(sectionId: string): boolean
|
|
91
|
+
/** The slash menu's request to the AI for an animation where it was opened: it inserts nothing itself. */
|
|
92
|
+
animationRequest?: { available(): boolean, request(editor: NativeDocumentEditor): void }
|
|
87
93
|
children?: ReactNode
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -113,10 +119,11 @@ function PlainContentComments({ editor }: { editor: NativeDocumentEditor }) {
|
|
|
113
119
|
return show && editor.getExtension('comments') ? <div className="pm-document-editor__comment-tools"><FormattingToolbar><AddCommentButton /></FormattingToolbar></div> : null
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
// Added items join the end of their group (formulas the one that holds tables, the animation request the one that holds
|
|
123
|
+
// pictures) so the menu keeps one heading per group.
|
|
124
|
+
function withGroupItems<Item extends { group?: string }>(items: Item[], added: Item[]): Item[] {
|
|
125
|
+
const index = items.findLastIndex(item => item.group === added[0]?.group)
|
|
126
|
+
return index < 0 ? [...items, ...added] : [...items.slice(0, index + 1), ...added, ...items.slice(index + 1)]
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
/** One native editor owns selection, transactions and history across the complete document. */
|
|
@@ -156,7 +163,7 @@ export function BlockNoteSurface(props: BlockNoteSurfaceProps) {
|
|
|
156
163
|
dictionary, tables: { splitCells: true, cellBackgroundColor: true, cellTextColor: true, headers: true },
|
|
157
164
|
// The surface's own click handler opens links in editable and read-only states alike.
|
|
158
165
|
links: { onClick: () => true },
|
|
159
|
-
extensions: [nativeTextClipboard, documentBlockColors, imageFileInput({
|
|
166
|
+
extensions: [nativeTextClipboard, documentBlockColors, documentPageBodies(), imageFileInput({
|
|
160
167
|
onStart: () => { if (current.current.identity === props.identity) setFileErrors(undefined) },
|
|
161
168
|
onFailure: failure => { if (current.current.identity === props.identity) setFileErrors(value => ({ identity: props.identity, failures: [...(value?.identity === props.identity ? value.failures : []), failure] })) },
|
|
162
169
|
}), ...props.comments ? [nativeCommentSelection(), nativeComments(props.comments, t.author)] : []],
|
|
@@ -171,7 +178,7 @@ export function BlockNoteSurface(props: BlockNoteSurfaceProps) {
|
|
|
171
178
|
stopCommentHistory?.(); current.current.onReady?.(undefined)
|
|
172
179
|
}
|
|
173
180
|
}, [editor])
|
|
174
|
-
return <DOCUMENT_EDITOR_LOCALE.Provider value={props.locale}><DOCUMENT_LINKS.Provider value={links}><DOCUMENT_NODE_VIEWS.Provider value={props.nodeViews ?? {}}><COMMENT_EDITOR_CONTEXT.Provider value={props.comments ? { store: props.comments, locale: props.locale, sidebar: Boolean(props.commentsPortal), getPositionToken: () => current.current.getPositionToken?.(), onDraftRestore: () => current.current.onCommentDraftRestore?.() } : undefined}>
|
|
181
|
+
return <DOCUMENT_EDITOR_LOCALE.Provider value={props.locale}><DOCUMENT_LINKS.Provider value={links}><DOCUMENT_NODE_VIEWS.Provider value={props.nodeViews ?? {}}><COMMENT_EDITOR_CONTEXT.Provider value={props.comments ? { store: props.comments, locale: props.locale, sidebar: Boolean(props.commentsPortal), readOnly: Boolean(props.readOnly), getPositionToken: () => current.current.getPositionToken?.(), onDraftRestore: () => current.current.onCommentDraftRestore?.(), openComments: () => current.current.onOpenComments?.() } : undefined}>
|
|
175
182
|
<div className="pm-document-editor pm-ui-block-editor pm-ui" data-document-editor={props.identity}
|
|
176
183
|
onDragEnter={event => { if (event.dataTransfer.types.includes('Files')) event.stopPropagation() }}
|
|
177
184
|
onDragOver={event => { if (event.dataTransfer.types.includes('Files')) event.stopPropagation() }}
|
|
@@ -196,14 +203,23 @@ export function BlockNoteSurface(props: BlockNoteSurfaceProps) {
|
|
|
196
203
|
<LinkToolbarController linkToolbar={DocumentLinkToolbar} floatingUIOptions={linkToolbarOptions} />
|
|
197
204
|
<SideMenuController sideMenu={DocumentSideMenu} />
|
|
198
205
|
<TableHandlesController tableHandle={DocumentTableHandle} tableCellHandle={DocumentTableCellButton} />
|
|
199
|
-
<SuggestionMenuController triggerCharacter="/" getItems={async query => editor.getTextCursorPosition().block.type === 'presmiumPage' ? [] : filterSuggestionItems([...
|
|
206
|
+
<SuggestionMenuController triggerCharacter="/" getItems={async query => editor.getTextCursorPosition().block.type === 'presmiumPage' ? [] : filterSuggestionItems([...withGroupItems(withGroupItems(getDefaultReactSlashMenuItems(editor), formulaSlashItems(editor, props.locale, dictionary.slash_menu.table.group)), current.current.animationRequest?.available() ? [{
|
|
207
|
+
title: t.animateWithAI, subtext: t.animateWithAIHint, group: dictionary.slash_menu.image.group, icon: <PmIcon name="sparkle" />, aliases: slashAliases('animateWithAIAliases'),
|
|
208
|
+
// The menu has already taken back the typed “/” and query; the AI is asked, the document stays as it was.
|
|
209
|
+
onItemClick: () => current.current.animationRequest?.request(editor),
|
|
210
|
+
}] : []), {
|
|
200
211
|
title: t.page, aliases: slashAliases('pageAliases'), group: t.document,
|
|
201
|
-
onItemClick: () => { const current = editor.getTextCursorPosition().block; editor.insertBlocks([{ type: 'presmiumPage', props: { sectionId:
|
|
212
|
+
onItemClick: () => { const current = editor.getTextCursorPosition().block; editor.insertBlocks([{ type: 'presmiumPage', props: { sectionId: randomUUID() }, content: t.untitledPage }], current, 'after') },
|
|
202
213
|
}], query)} />
|
|
203
214
|
{props.children}
|
|
204
215
|
</NewCommentDraftProvider></BlockNoteViewEditor>
|
|
205
216
|
</ComponentsContext.Provider>
|
|
206
217
|
</BlockNoteView>
|
|
218
|
+
<div className="pm-document-editor__end" aria-hidden="true" data-editable={props.readOnly ? undefined : ''} onMouseDown={event => {
|
|
219
|
+
if (event.button !== 0 || !editor.isEditable || editor.prosemirrorView.composing) return
|
|
220
|
+
event.preventDefault()
|
|
221
|
+
focusDocumentEnd(editor)
|
|
222
|
+
}} />
|
|
207
223
|
</div>
|
|
208
224
|
</COMMENT_EDITOR_CONTEXT.Provider></DOCUMENT_NODE_VIEWS.Provider></DOCUMENT_LINKS.Provider></DOCUMENT_EDITOR_LOCALE.Provider>
|
|
209
225
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { useMemo } from 'react'
|
|
2
2
|
import { applyDocumentComponentAction } from '@lincyaw/kernel'
|
|
3
|
-
import type {
|
|
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
|
|
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:
|
|
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:
|
|
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 {
|
|
@@ -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 }
|
|
@@ -29,8 +30,8 @@ export function DocumentBlockPreview({ blockId, fallback }: { blockId: string, f
|
|
|
29
30
|
const sectionId = source?.content && documentBlockSection(source.content, blockId)
|
|
30
31
|
const section = sectionId ? source?.content?.sections[sectionId] : undefined
|
|
31
32
|
const stepId = section?.stepOrder[position && position.section === sectionId ? position.step : 0] ?? section?.stepOrder[0]
|
|
32
|
-
const [narrationOpen, setNarrationOpen] = useState(() => Boolean(workbench.
|
|
33
|
-
|| source?.identity && stepId && (workbench.
|
|
33
|
+
const [narrationOpen, setNarrationOpen] = useState(() => Boolean(workbench.editing.pendingField(blockId, source?.identity)
|
|
34
|
+
|| source?.identity && stepId && (workbench.production.timingDraft(stepId, 'minimumHoldMs', source.identity, source.reset) || workbench.production.timingDraft(stepId, 'trailingPauseMs', source.identity, source.reset)))), narrationPanel = useId()
|
|
34
35
|
const root = useRef<HTMLElement>(null), viewport = useRef<HTMLDivElement>(null), frame = useRef<HTMLIFrameElement | null>(null)
|
|
35
36
|
const mountFrame = useCallback((element: HTMLIFrameElement | null) => {
|
|
36
37
|
frame.current = element
|
|
@@ -216,6 +217,7 @@ export function DocumentBlockPreview({ blockId, fallback }: { blockId: string, f
|
|
|
216
217
|
return <section ref={root} className="pm-ui-block-preview" data-block-preview={blockId} data-status={state.status} contentEditable={false}>
|
|
217
218
|
<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
219
|
<span className="pm-ui-block-preview__actions">
|
|
220
|
+
{sectionId && stepId && <PlaceCommentButton blockId={blockId} sectionId={sectionId} stepId={stepId} stepIndex={section ? section.stepOrder.indexOf(stepId) + 1 : 1} onPause={pause} />}
|
|
219
221
|
{source?.content?.blocks[blockId]?.type === 'component' && <PmIconButton small icon="sliders" label={COMPONENT_PROPERTY_MESSAGES[locale].properties}
|
|
220
222
|
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
223
|
{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={() => {
|
|
@@ -1,22 +1,26 @@
|
|
|
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 { useWorkbenchState } from '../context.tsx'
|
|
9
12
|
import { enterSubmits } from './comments.ts'
|
|
10
13
|
import type { DocumentCommentEditorHandle, DocumentThreadStore } from './comments.ts'
|
|
11
14
|
import type { CommentDrafts, CommentDraftCandidate, CommentDraftRecord, CommentDraftReference, CommentDraftOperation } from './comment-drafts.ts'
|
|
12
15
|
import { isNewCommentDraft, sameCommentDraftTarget } from './comment-drafts.ts'
|
|
13
|
-
import { createRichProjection, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
|
|
16
|
+
import { createRichProjection, fallbackText, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
|
|
14
17
|
import { commentEditorSchema } from './schema.tsx'
|
|
15
18
|
import type { DocumentEditorBlock } from './schema.tsx'
|
|
16
19
|
import { DOCUMENT_EDITOR_MESSAGES } from './messages.ts'
|
|
20
|
+
import { componentDefinitionLabel } from './component-label.ts'
|
|
17
21
|
import { commentFloating } from './popover.tsx'
|
|
18
22
|
|
|
19
|
-
export const COMMENT_EDITOR_CONTEXT = createContext<{ store: DocumentThreadStore, locale: Locale, sidebar: boolean, getPositionToken?(): string | undefined, onDraftRestore?(): void } | undefined>(undefined)
|
|
23
|
+
export const COMMENT_EDITOR_CONTEXT = createContext<{ store: DocumentThreadStore, locale: Locale, sidebar: boolean, readOnly?: boolean, getPositionToken?(): string | undefined, onDraftRestore?(): void, openComments?(): void } | undefined>(undefined)
|
|
20
24
|
const THREAD_CONTEXT = createContext<string | undefined>(undefined)
|
|
21
25
|
const emptySubscribe = () => () => {}
|
|
22
26
|
const emptyState = { candidates: [], pending: false, failed: false, reading: false } as const
|
|
@@ -32,12 +36,14 @@ export function DocumentCommentThread(props: ThreadProps) {
|
|
|
32
36
|
|
|
33
37
|
/** Keep the native controller and reply editor while body selection owns the pointer. */
|
|
34
38
|
export function DocumentFloatingThreadController() {
|
|
35
|
-
const editor = useBlockNoteEditor(), { selectedThreadId } = useExtensionState(CommentsExtension)
|
|
39
|
+
const editor = useBlockNoteEditor(), { selectedThreadId, threadPositions } = useExtensionState(CommentsExtension)
|
|
36
40
|
const empty = useEditorState({ editor, on: 'selection', selector: ({ editor }) => editor.prosemirrorState.selection.empty })
|
|
37
41
|
const [selecting, setSelecting] = useState(false)
|
|
38
42
|
const blocked = selecting || !empty
|
|
43
|
+
// A place thread has no text mark; it belongs to the sidebar only and must not open a floating card.
|
|
44
|
+
const positioned = Boolean(selectedThreadId && threadPositions.has(selectedThreadId))
|
|
39
45
|
const shown = useRef(false), thread = useRef(selectedThreadId)
|
|
40
|
-
shown.current =
|
|
46
|
+
shown.current = positioned && !blocked
|
|
41
47
|
thread.current = selectedThreadId
|
|
42
48
|
// The pointer that last pressed commented text, and the line of the thread chosen from it (the first line without one).
|
|
43
49
|
const point = useRef<{ x: number, y: number }>(), line = useRef<{ thread: string, index: number }>()
|
|
@@ -101,16 +107,60 @@ export function DocumentFloatingThreadController() {
|
|
|
101
107
|
return rects[Math.min(line.current.index, rects.length - 1)]
|
|
102
108
|
}), [editor])
|
|
103
109
|
return <FloatingThreadController floatingThread={DocumentCommentThread} floatingUIOptions={{
|
|
104
|
-
useFloatingOptions: { ...floating, open:
|
|
110
|
+
useFloatingOptions: { ...floating, open: positioned && !blocked },
|
|
105
111
|
elementProps: { className: blocked ? 'pm-ui-comment-hidden' : undefined },
|
|
106
112
|
}} />
|
|
107
113
|
}
|
|
108
114
|
|
|
115
|
+
function placeReference(document: TeachingDocument | undefined, anchor: DocumentPlaceAnchor, t: typeof DOCUMENT_EDITOR_MESSAGES['zh-CN']): string {
|
|
116
|
+
if (!document) return ''
|
|
117
|
+
const block = document.blocks[anchor.blockId]
|
|
118
|
+
let label: string
|
|
119
|
+
if (block?.type === 'component') {
|
|
120
|
+
const definition = document.definitions[block.definitionId]
|
|
121
|
+
const author = typeof block.parameters.title === 'string' ? block.parameters.title.trim() : ''
|
|
122
|
+
const data = definition?.data && typeof definition.data.title === 'string' ? definition.data.title.trim() : ''
|
|
123
|
+
const schema = definition && typeof definition.parameterSchema === 'object' && typeof definition.parameterSchema.title === 'string' ? definition.parameterSchema.title.trim() : ''
|
|
124
|
+
const name = author || data || schema || (definition ? componentDefinitionLabel(definition) : block.definitionId)
|
|
125
|
+
label = definition?.kind === 'scene' ? t.animation(name) : t.component(name)
|
|
126
|
+
} else if (block?.type === 'code') label = t.codeReference(block.title ?? block.origin?.anchor ?? block.language)
|
|
127
|
+
else if (block?.type === 'image') label = block.alt || t.block
|
|
128
|
+
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
|
|
129
|
+
else if (block?.type === 'container') label = block.properties.title || t.block
|
|
130
|
+
else label = t.block
|
|
131
|
+
if (anchor.stepId === undefined) return t.placeCommentReference(label)
|
|
132
|
+
const step = document.steps[anchor.stepId], section = step ? document.sections[step.sectionId] : undefined
|
|
133
|
+
return t.placeCommentReference(label, step && section ? section.stepOrder.indexOf(step.id) + 1 : 0)
|
|
134
|
+
}
|
|
135
|
+
|
|
109
136
|
/** Native Thread composition, with the same public focus/blur and position ordering as the sidebar. */
|
|
110
137
|
export function DocumentThreadsSidebar({ children }: { children?: ReactNode }) {
|
|
111
138
|
const editor = useBlockNoteEditor(), comments = useExtension(CommentsExtension), threads = useThreads()
|
|
112
139
|
const { selectedThreadId, threadPositions } = useExtensionState(CommentsExtension)
|
|
113
|
-
const
|
|
140
|
+
const context = useContext(COMMENT_EDITOR_CONTEXT), t = DOCUMENT_EDITOR_MESSAGES[context?.locale ?? 'en']
|
|
141
|
+
const document = useWorkbenchState(state => state.authoring?.content) ?? context?.store.document
|
|
142
|
+
const places = useMemo(() => document ? documentAnchorOrder(document) : new Map<string, number>(), [document])
|
|
143
|
+
const place = (threadId: string): number => {
|
|
144
|
+
const anchor = context?.store.anchorOf(threadId)
|
|
145
|
+
if (!anchor) return Number.MAX_VALUE
|
|
146
|
+
if (isDocumentPlaceAnchor(anchor)) {
|
|
147
|
+
const order = places.get(anchor.blockId)
|
|
148
|
+
const step = anchor.stepId === undefined ? undefined : document?.steps[anchor.stepId]
|
|
149
|
+
const section = step && document ? document.sections[step.sectionId] : undefined
|
|
150
|
+
return order === undefined ? Number.MAX_VALUE : order * 1_000_000 + (step && section ? section.stepOrder.indexOf(step.id) : 0)
|
|
151
|
+
}
|
|
152
|
+
const order = places.get(anchor.from.blockId)
|
|
153
|
+
return order === undefined ? Number.MAX_VALUE : order * 1_000_000 + Math.min(999_999, anchor.from.offset)
|
|
154
|
+
}
|
|
155
|
+
const reference = (threadId: string): string | undefined => {
|
|
156
|
+
const anchor = context?.store.anchorOf(threadId)
|
|
157
|
+
return anchor && isDocumentPlaceAnchor(anchor) ? placeReference(document, anchor, t) : getReferenceText(editor, threadPositions.get(threadId))
|
|
158
|
+
}
|
|
159
|
+
const orphaned = (threadId: string): boolean => {
|
|
160
|
+
const anchor = context?.store.anchorOf(threadId)
|
|
161
|
+
return !(anchor && isDocumentPlaceAnchor(anchor)) && !threadPositions.has(threadId)
|
|
162
|
+
}
|
|
163
|
+
const ordered = [...threads.values()].sort((a, b) => place(a.id) - place(b.id) || a.createdAt.getTime() - b.createdAt.getTime())
|
|
114
164
|
const focus = (id: string, event: FocusEvent) => { if (!(event.target as HTMLElement).closest('.bn-action-toolbar')) comments.selectThread(id) }
|
|
115
165
|
const blur = (event: FocusEvent) => {
|
|
116
166
|
const next = event.relatedTarget
|
|
@@ -118,9 +168,8 @@ export function DocumentThreadsSidebar({ children }: { children?: ReactNode }) {
|
|
|
118
168
|
const parent = next.closest('.bn-thread')
|
|
119
169
|
if (!parent || !(event.target instanceof Node) || !parent.contains(event.target)) comments.selectThread(undefined)
|
|
120
170
|
}
|
|
121
|
-
const context = useContext(COMMENT_EDITOR_CONTEXT), t = DOCUMENT_EDITOR_MESSAGES[context?.locale ?? 'en']
|
|
122
171
|
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={
|
|
172
|
+
selected={selectedThreadId === thread.id} orphaned={orphaned(thread.id)} referenceText={reference(thread.id)}
|
|
124
173
|
onFocus={event => focus(thread.id, event)} onBlur={blur} tabIndex={0} />)}</div>
|
|
125
174
|
}
|
|
126
175
|
|
|
@@ -174,7 +223,7 @@ export function DocumentCommentEditor(props: ComponentProps['Comments']['Editor'
|
|
|
174
223
|
return value
|
|
175
224
|
}, [props.editor, drafts])
|
|
176
225
|
const rich = useMemo(() => ({ current: record.rich }), [record])
|
|
177
|
-
const composerId = useRef(
|
|
226
|
+
const composerId = useRef(randomUUID())
|
|
178
227
|
const state = useSyncExternalStore(drafts?.subscribe ?? emptySubscribe, drafts?.snapshot ?? (() => emptyState))
|
|
179
228
|
useLayoutEffect(() => {
|
|
180
229
|
if (!context || !threadId) return
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from 'react'
|
|
2
2
|
import type { Transaction } from '@tiptap/pm/state'
|
|
3
|
+
import { TextSelection } from '@tiptap/pm/state'
|
|
3
4
|
import { closeHistory } from '@tiptap/pm/history'
|
|
4
|
-
import { allocateDocumentPage } from '@lincyaw/kernel'
|
|
5
|
+
import { allocateDocumentPage, randomUUID } from '@lincyaw/kernel'
|
|
5
6
|
import type { Member, TeachingDocument } from '@lincyaw/kernel'
|
|
6
7
|
import type { Locale } from '../messages.ts'
|
|
7
8
|
import { BlockNoteSurface } from './BlockNoteSurface.tsx'
|
|
@@ -12,17 +13,25 @@ import type { NativePageCreation } from './projection.ts'
|
|
|
12
13
|
import { captureRichBaseline } from './rich-text.ts'
|
|
13
14
|
import { captureTableIdentities, seedTableIdentities } from './table-identities.ts'
|
|
14
15
|
import type { DocumentNodeViews, NativeDocumentEditor } from './schema.tsx'
|
|
15
|
-
import { nativeEditingCursor } from './selection.ts'
|
|
16
|
-
import type { NativeDocumentSelection } from './selection.ts'
|
|
16
|
+
import { nativeEditingCursor, nativeTextPoint, nativeTextPosition } from './selection.ts'
|
|
17
|
+
import type { NativeDocumentSelection, NativeTextPoint } from './selection.ts'
|
|
18
|
+
import { documentInsertionPlace } from './insertion-place.ts'
|
|
19
|
+
import type { DocumentInsertionPlace } from './insertion-place.ts'
|
|
17
20
|
|
|
18
21
|
export interface DocumentEditingPosition {
|
|
19
22
|
nativeBlockId: string
|
|
20
23
|
sectionId: string
|
|
21
24
|
position: number
|
|
22
25
|
}
|
|
26
|
+
/** Who takes the slash menu's request for an animation where it was opened; while none is available the menu has no such item. */
|
|
27
|
+
export interface DocumentAnimationRequests {
|
|
28
|
+
available(): boolean
|
|
29
|
+
request(place: DocumentInsertionPlace): void
|
|
30
|
+
}
|
|
23
31
|
export interface DocumentEditorCommands {
|
|
24
32
|
insertPage(after: string | undefined, title: string): NativePageCreation
|
|
25
33
|
rememberComponentConfiguration(document: TeachingDocument): void
|
|
34
|
+
handleAnimationRequests(requests: DocumentAnimationRequests | undefined): void
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
export interface DocumentEditorProps {
|
|
@@ -56,6 +65,7 @@ export interface DocumentEditorProps {
|
|
|
56
65
|
onError?(error: Error): void
|
|
57
66
|
commentsPortal?: HTMLElement | null
|
|
58
67
|
onCommentDraftRestore?(): void
|
|
68
|
+
onOpenComments?(): void
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
/** A source version reset replaces the editor; its own save receipts never replace it. */
|
|
@@ -73,11 +83,19 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
73
83
|
return () => comments.close()
|
|
74
84
|
}, [comments])
|
|
75
85
|
const current = useRef(props), editor = useRef<NativeDocumentEditor>(), unsubscribe = useRef<() => void>()
|
|
86
|
+
const animationRequests = useRef<DocumentAnimationRequests>()
|
|
76
87
|
const projectedDocument = useRef<NativeDocumentEditor['prosemirrorState']['doc']>()
|
|
77
88
|
const pendingTransaction = useRef<Transaction>()
|
|
78
89
|
const focusFrame = useRef<number>()
|
|
79
90
|
const binding = useRef(projection)
|
|
80
91
|
const active = useRef(projection)
|
|
92
|
+
const editorIdentity = useRef(props.identity)
|
|
93
|
+
const retainedSelection = useRef<{ from: NativeTextPoint, to: NativeTextPoint }>()
|
|
94
|
+
const previous = editor.current
|
|
95
|
+
if (binding.current !== projection && editorIdentity.current === props.identity && previous?.isFocused() && !previous.prosemirrorView.composing) {
|
|
96
|
+
const from = nativeTextPoint(previous, previous.prosemirrorState.selection.anchor), to = nativeTextPoint(previous, previous.prosemirrorState.selection.head)
|
|
97
|
+
if (from && to) retainedSelection.current = { from, to }
|
|
98
|
+
}
|
|
81
99
|
active.current = projection
|
|
82
100
|
current.current = props
|
|
83
101
|
const cancelFocus = () => { if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current); focusFrame.current = undefined }
|
|
@@ -113,7 +131,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
113
131
|
if (!latest || current.current.getDocumentVersion && current.current.getDocumentVersion() === undefined) return
|
|
114
132
|
syncComments()
|
|
115
133
|
const document = nativeDocumentToProduct(editor.current.document, projection, latest)
|
|
116
|
-
const threads = comments.snapshot(editor.current)
|
|
134
|
+
const threads = comments.snapshot(editor.current, document)
|
|
117
135
|
if (Object.keys(threads).length) document.comments = threads
|
|
118
136
|
else delete document.comments
|
|
119
137
|
current.current.onChange(document)
|
|
@@ -125,7 +143,16 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
125
143
|
}
|
|
126
144
|
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
145
|
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}
|
|
146
|
+
comments={comments} commentsPortal={props.commentsPortal} onCommentDraftRestore={() => current.current.onCommentDraftRestore?.()} onOpenComments={() => current.current.onOpenComments?.()} nodeViews={props.nodeViews} onComposition={props.onComposition} onSelection={props.onSelection}
|
|
147
|
+
animationRequest={{
|
|
148
|
+
available: () => !current.current.readOnly && binding.current === projection && active.current === projection && Boolean(animationRequests.current?.available()),
|
|
149
|
+
request: value => {
|
|
150
|
+
if (value !== editor.current || binding.current !== projection || active.current !== projection) return
|
|
151
|
+
const place = documentInsertionPlace(value, projection)
|
|
152
|
+
if (place) animationRequests.current?.request(place)
|
|
153
|
+
},
|
|
154
|
+
}}
|
|
155
|
+
onSectionLink={sectionId => {
|
|
129
156
|
if (!current.current.onSectionLink?.(sectionId)) return false
|
|
130
157
|
// The click placed the caret in the link; it follows the reader to the page they asked for.
|
|
131
158
|
const value = editor.current
|
|
@@ -147,7 +174,17 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
147
174
|
comments.restoreAnchors(value)
|
|
148
175
|
binding.current = projection
|
|
149
176
|
editor.current = value
|
|
177
|
+
editorIdentity.current = props.identity
|
|
150
178
|
projectedDocument.current = value.prosemirrorState.doc
|
|
179
|
+
const selection = retainedSelection.current
|
|
180
|
+
retainedSelection.current = undefined
|
|
181
|
+
if (selection) {
|
|
182
|
+
const from = nativeTextPosition(value, selection.from), to = nativeTextPosition(value, selection.to)
|
|
183
|
+
if (from !== undefined && to !== undefined) {
|
|
184
|
+
value.transact(transaction => transaction.setSelection(TextSelection.create(transaction.doc, from, to)).setMeta('addToHistory', false))
|
|
185
|
+
value.focus()
|
|
186
|
+
}
|
|
187
|
+
}
|
|
151
188
|
const stopBefore = value.onBeforeChange(({ tr }) => { if (!comments.synchronizing && tr.docChanged) pendingTransaction.current = tr })
|
|
152
189
|
const stopComments = comments.subscribe(emit)
|
|
153
190
|
const stopSelection = value.onSelectionChange(() => { cancelFocus(); reportPosition() })
|
|
@@ -162,7 +199,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
162
199
|
})
|
|
163
200
|
unsubscribe.current = () => { stopBefore(); stopComments(); stopSelection(); stopFocus(); cancelFocus() }
|
|
164
201
|
}
|
|
165
|
-
const commands: DocumentEditorCommands | undefined = value ? { rememberComponentConfiguration: document => {
|
|
202
|
+
const commands: DocumentEditorCommands | undefined = value ? { handleAnimationRequests: requests => { animationRequests.current = requests }, rememberComponentConfiguration: document => {
|
|
166
203
|
if (editor.current === value && active.current === projection && binding.current === projection && !value.prosemirrorView.isDestroyed) rememberComponentConfiguration(projection, document)
|
|
167
204
|
}, insertPage: (after, title) => {
|
|
168
205
|
if (current.current.readOnly || editor.current !== value || active.current !== projection || binding.current !== projection || value.prosemirrorView.isDestroyed) throw new Error('page-context-changed')
|
|
@@ -171,7 +208,7 @@ export function DocumentEditor(props: DocumentEditorProps) {
|
|
|
171
208
|
const next = after ? blocks.slice(index + 1).find(block => block.type === 'presmiumPage') : undefined
|
|
172
209
|
const latest = current.current.getDocument ? current.current.getDocument() : current.current.document
|
|
173
210
|
if (!latest) throw new Error('page-context-changed')
|
|
174
|
-
const creation = allocateDocumentPage(latest, () =>
|
|
211
|
+
const creation = allocateDocumentPage(latest, () => randomUUID())
|
|
175
212
|
projection.createdPages.set(creation.sectionId, creation)
|
|
176
213
|
try {
|
|
177
214
|
value.transact(transaction => {
|
|
@@ -1,11 +1,12 @@
|
|
|
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'
|
|
6
7
|
import { NarrationEditor } from './NarrationEditor.tsx'
|
|
7
8
|
import { DOCUMENT_EDITOR_MESSAGES } from './messages.ts'
|
|
8
|
-
import { narrationFieldFocus } from './narration.ts'
|
|
9
|
+
import { narrationFieldFocus, narrationsToNative, nativeToNarrations } from './narration.ts'
|
|
9
10
|
import type { NativeNarrationEditor } from './narration-schema.tsx'
|
|
10
11
|
import { StepProductionEditor } from '../StepProductionEditor.tsx'
|
|
11
12
|
|
|
@@ -23,28 +24,32 @@ export function narrationDisplay(content: readonly NarrationNode[]): string {
|
|
|
23
24
|
return content.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function NarrationField({ identity, reset, blockId, stepId,
|
|
27
|
-
identity: string, reset: number, blockId?: string, stepId: string,
|
|
27
|
+
function NarrationField({ identity, reset, blockId, stepId, content, readOnly, advanced, onPause }: {
|
|
28
|
+
identity: string, reset: number, blockId?: string, stepId: string, content: Narration[], readOnly: boolean, advanced: boolean, onPause(): void,
|
|
28
29
|
}) {
|
|
29
30
|
const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale)
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
const id = narrationId ?? reservedId
|
|
36
|
-
const target = () => narrationId ?? workbench.getDocument(identity)?.steps[stepId]?.narrationIds[slot] ?? id
|
|
31
|
+
const [emptyId] = useState(() => randomUUID())
|
|
32
|
+
const read = () => {
|
|
33
|
+
const document = workbench.getDocument(identity), step = document?.steps[stepId]
|
|
34
|
+
return step ? step.narrationIds.map(id => ({ id, content: document!.narrations[id]!.content })) : undefined
|
|
35
|
+
}
|
|
37
36
|
const registration = useRef<() => void>()
|
|
38
37
|
const fieldEditor = useRef<NativeNarrationEditor>()
|
|
39
|
-
const owner = `narration:${identity}:${reset}:${JSON.stringify(blockId ?? null)}:${stepId}
|
|
40
|
-
return <NarrationEditor identity={identity} reset={reset}
|
|
41
|
-
getContent={
|
|
38
|
+
const owner = `narration:${identity}:${reset}:${JSON.stringify(blockId ?? null)}:${stepId}`
|
|
39
|
+
return <NarrationEditor identity={identity} reset={reset} fieldId={stepId} content={content} locale={locale} readOnly={readOnly} advanced={advanced} blockMenu
|
|
40
|
+
getContent={read} toNative={value => narrationsToNative(value, emptyId)} fromNative={nativeToNarrations}
|
|
41
|
+
cueOwners={() => {
|
|
42
|
+
const document = workbench.getDocument(identity)
|
|
43
|
+
const retained = new Set(Object.values(document?.steps ?? {}).filter(step => step.id !== stepId).flatMap(step => step.narrationIds))
|
|
44
|
+
return new Map([...retained].flatMap(id => document!.narrations[id]!.content.flatMap(node => node.type === 'cue' ? [[node.id, id] as const] : [])))
|
|
45
|
+
}}
|
|
46
|
+
onCueCopy={(from, to) => workbench.production.copyNarrationCueTiming(from, to, identity)}
|
|
42
47
|
onReady={editor => {
|
|
43
48
|
registration.current?.()
|
|
44
49
|
fieldEditor.current = editor
|
|
45
|
-
registration.current = editor ? workbench.
|
|
50
|
+
registration.current = editor ? workbench.editing.registerField({ identity, reset, blockId, stepId, focus: narrationFieldFocus(editor), editor }) : undefined
|
|
46
51
|
}}
|
|
47
|
-
onFocus={() => { workbench.
|
|
52
|
+
onFocus={() => { workbench.editing.interact(); if (fieldEditor.current) workbench.editing.activateHistory(fieldEditor.current); onPause() }} onChange={value => workbench.production.setNarrations(stepId, value, identity)}
|
|
48
53
|
onComposition={composing => workbench.documentComposition(composing, owner, identity)}
|
|
49
54
|
onError={error => workbench.documentError(error)} />
|
|
50
55
|
}
|
|
@@ -78,15 +83,15 @@ export function DocumentStepNarration({ blockId, sectionId, stepId, expanded, ad
|
|
|
78
83
|
{!expanded && text && <p className="pm-ui-block-preview__caption" data-step-caption={stepId}>{text}</p>}
|
|
79
84
|
{expanded && <div id={panelId} className="pm-ui-block-preview__narration-fields">
|
|
80
85
|
{showLabel && <span className="pm-ui-block-preview__step-label">{fieldLabel}</span>}
|
|
81
|
-
|
|
82
|
-
identity={source.identity!} reset={source.reset} blockId={blockId} stepId={stepId}
|
|
83
|
-
content={id
|
|
84
|
-
<StepProductionEditor key={
|
|
85
|
-
onPause={onPause} onInteraction={() => workbench.
|
|
86
|
-
onChange={patch => workbench.
|
|
87
|
-
drafts={{ minimumHoldMs: workbench.
|
|
86
|
+
<NarrationField key={`narration:${source.identity}:${source.reset}:${stepId}`}
|
|
87
|
+
identity={source.identity!} reset={source.reset} blockId={blockId} stepId={stepId}
|
|
88
|
+
content={ids.map(id => ({ id, content: document.narrations[id]!.content }))} readOnly={readOnly} advanced={advanced} onPause={onPause} />
|
|
89
|
+
<StepProductionEditor key={`timing:${source.identity}:${source.reset}:${stepId}`} document={document} stepId={stepId} locale={locale} readOnly={readOnly} advanced={advanced}
|
|
90
|
+
onPause={onPause} onInteraction={() => workbench.editing.interact()}
|
|
91
|
+
onChange={patch => workbench.production.setStepTiming(stepId, patch, source.identity)}
|
|
92
|
+
drafts={{ minimumHoldMs: workbench.production.timingDraft(stepId, 'minimumHoldMs', source.identity, source.reset), trailingPauseMs: workbench.production.timingDraft(stepId, 'trailingPauseMs', source.identity, source.reset) }}
|
|
88
93
|
draftStorageFailure={timingStorageFailure}
|
|
89
|
-
onDraft={(key, draft) => workbench.
|
|
94
|
+
onDraft={(key, draft) => workbench.production.setTimingDraft(stepId, key, draft, source.identity!, source.reset)}
|
|
90
95
|
onComposition={(key, composing) => workbench.documentComposition(composing, `production:${source.identity}:${source.reset}:${blockId}:${stepId}:${key}`, source.identity)} />
|
|
91
96
|
</div>}
|
|
92
97
|
</section>
|