@lincyaw/workbench 0.2.0-rc.5 → 0.2.0-rc.51
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/authoring-window.ts +100 -0
- 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 +339 -0
- package/src/document-session.ts +193 -53
- package/src/history.ts +5 -5
- package/src/index.ts +6 -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 +19 -19
- 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 +246 -948
- package/src/workspace-client.ts +21 -11
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -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>
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { createRoot } from 'react-dom/client'
|
|
3
|
-
import type { NarrationNode } from '@lincyaw/kernel'
|
|
4
3
|
import { blockNoteDictionary } from './blocknote-messages.ts'
|
|
5
4
|
import { BlockNoteView } from '@blocknote/mantine'
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { SideMenuExtension } from '@blocknote/core/extensions'
|
|
6
|
+
import { DragHandleMenu, RemoveBlockItem, SideMenu, SideMenuController, useBlockNoteEditor, useComponentsContext, useCreateBlockNote, useDictionary, useExtension, useExtensionState, usePortalElement } from '@blocknote/react'
|
|
7
|
+
import type { SideMenuProps } from '@blocknote/react'
|
|
8
|
+
import { PmButton, PmDialog, PmIcon, PmInput } from '../components.tsx'
|
|
8
9
|
import type { Locale } from '../messages.ts'
|
|
9
10
|
import { DOCUMENT_EDITOR_THEME } from './BlockNoteSurface.tsx'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import type { NativeNarrationEditor } from './narration-schema.tsx'
|
|
11
|
+
import { NARRATION_CONTEXT, NARRATION_MESSAGES, createNarrationExtensions, narrationSchema } from './narration-schema.tsx'
|
|
12
|
+
import type { NativeNarrationBlock, NativeNarrationEditor, NativeNarrationInput } from './narration-schema.tsx'
|
|
13
13
|
|
|
14
|
-
export interface NarrationEditorProps {
|
|
14
|
+
export interface NarrationEditorProps<T> {
|
|
15
15
|
identity: string
|
|
16
|
-
|
|
17
|
-
content:
|
|
18
|
-
getContent?():
|
|
16
|
+
fieldId: string
|
|
17
|
+
content: T
|
|
18
|
+
getContent?(): T | undefined
|
|
19
|
+
toNative(content: T): NativeNarrationInput[]
|
|
20
|
+
fromNative(blocks: readonly NativeNarrationBlock[]): T
|
|
21
|
+
blockMenu?: boolean
|
|
22
|
+
cueOwners?(): ReadonlyMap<string, string>
|
|
23
|
+
onCueCopy?(from: string, to: string): void
|
|
19
24
|
locale: Locale
|
|
20
25
|
reset?: number
|
|
21
26
|
readOnly?: boolean
|
|
22
27
|
advanced?: boolean
|
|
23
|
-
onChange(content:
|
|
28
|
+
onChange(content: T): void
|
|
24
29
|
onComposition?(composing: boolean): void
|
|
25
30
|
onFocus?(): void
|
|
26
31
|
onError?(error: Error): void
|
|
@@ -28,7 +33,7 @@ export interface NarrationEditorProps {
|
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/** A native field can live inside an opaque body node without sharing its DOM event root. */
|
|
31
|
-
export function NarrationEditor(props: NarrationEditorProps) {
|
|
36
|
+
export function NarrationEditor<T>(props: NarrationEditorProps<T>) {
|
|
32
37
|
const mount = useRef<HTMLDivElement>(null), root = useRef<ReturnType<typeof createRoot>>(), current = useRef(props)
|
|
33
38
|
current.current = props
|
|
34
39
|
useEffect(() => {
|
|
@@ -50,14 +55,40 @@ export function NarrationEditor(props: NarrationEditorProps) {
|
|
|
50
55
|
}
|
|
51
56
|
}, [])
|
|
52
57
|
useEffect(() => { root.current?.render(<NarrationSurface {...props} />) })
|
|
53
|
-
return <div ref={mount} contentEditable={false} data-narration-editor={props.
|
|
58
|
+
return <div ref={mount} contentEditable={false} data-narration-editor={props.fieldId} />
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
function
|
|
61
|
+
function NarrationBlockMenu() {
|
|
62
|
+
const components = useComponentsContext()!, dictionary = useDictionary(), portalElement = usePortalElement()
|
|
63
|
+
const sideMenu = useExtension(SideMenuExtension)
|
|
64
|
+
return <components.Generic.Menu.Root position="left" portalElement={portalElement} onOpenChange={open => {
|
|
65
|
+
if (open) sideMenu.freezeMenu()
|
|
66
|
+
else sideMenu.unfreezeMenu()
|
|
67
|
+
}}>
|
|
68
|
+
<components.Generic.Menu.Trigger><components.SideMenu.Button label={dictionary.side_menu.drag_handle_label} icon={<PmIcon name="more" />} /></components.Generic.Menu.Trigger>
|
|
69
|
+
<DragHandleMenu><RemoveBlockItem>{dictionary.drag_handle.delete_menuitem}</RemoveBlockItem></DragHandleMenu>
|
|
70
|
+
</components.Generic.Menu.Root>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function InsertNarrationBlock() {
|
|
74
|
+
const editor = useBlockNoteEditor(), components = useComponentsContext()!, dictionary = useDictionary()
|
|
75
|
+
const block = useExtensionState(SideMenuExtension, { selector: state => state?.block })
|
|
76
|
+
if (!block) return null
|
|
77
|
+
return <components.SideMenu.Button label={dictionary.side_menu.add_block_label} icon={<PmIcon name="plus" />} onClick={() => {
|
|
78
|
+
const [inserted] = editor.insertBlocks([{ type: 'paragraph' }], block, 'after')
|
|
79
|
+
editor.setTextCursorPosition(inserted!, 'start'); editor.focus()
|
|
80
|
+
}} />
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function NarrationSideMenu(props: SideMenuProps) {
|
|
84
|
+
return <SideMenu {...props}><InsertNarrationBlock /><NarrationBlockMenu /></SideMenu>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function NarrationSurface<T>(props: NarrationEditorProps<T>) {
|
|
57
88
|
const current = useRef(props), pending = useRef<string[]>([])
|
|
58
89
|
current.current = props
|
|
59
90
|
const canonical = props.getContent?.() ?? props.content
|
|
60
|
-
const incoming = JSON.stringify(canonical), sourceKey = JSON.stringify([props.identity, props.
|
|
91
|
+
const incoming = JSON.stringify(canonical), sourceKey = JSON.stringify([props.identity, props.fieldId, props.reset])
|
|
61
92
|
const version = useRef({ key: sourceKey, incoming, epoch: 0 })
|
|
62
93
|
if (version.current.key !== sourceKey) {
|
|
63
94
|
version.current.epoch++; version.current.key = sourceKey; pending.current = []
|
|
@@ -70,10 +101,11 @@ function NarrationSurface(props: NarrationEditorProps) {
|
|
|
70
101
|
const instance = useMemo(() => ({ content: structuredClone(canonical), emitted: incoming }), [sourceKey, version.current.epoch])
|
|
71
102
|
const active = useRef(instance); active.current = instance
|
|
72
103
|
const t = NARRATION_MESSAGES[props.locale]
|
|
73
|
-
const editor = useCreateBlockNote({ schema: narrationSchema, initialContent:
|
|
104
|
+
const editor = useCreateBlockNote({ schema: narrationSchema, initialContent: props.toNative(instance.content),
|
|
74
105
|
trailingBlock: false,
|
|
75
106
|
dictionary: { ...blockNoteDictionary(props.locale), placeholders: { ...blockNoteDictionary(props.locale).placeholders, default: props.advanced === false ? t.emptyCaptions : t.empty } },
|
|
76
|
-
extensions:
|
|
107
|
+
extensions: createNarrationExtensions(() => current.current.cueOwners?.() ?? new Map(), (from, to) => current.current.onCueCopy?.(from, to)),
|
|
108
|
+
domAttributes: { editor: { 'aria-label': props.advanced === false ? t.captions : t.field } },
|
|
77
109
|
}, [instance, props.advanced])
|
|
78
110
|
const baseline = useMemo(() => JSON.stringify(editor.document), [editor])
|
|
79
111
|
const [open, setOpen] = useState(false), [display, setDisplay] = useState(''), [spoken, setSpoken] = useState('')
|
|
@@ -85,7 +117,7 @@ function NarrationSurface(props: NarrationEditorProps) {
|
|
|
85
117
|
if (active.current !== instance) return
|
|
86
118
|
if (current.current.getContent && current.current.getContent() === undefined) return
|
|
87
119
|
try {
|
|
88
|
-
const content = JSON.stringify(editor.document) === baseline ? structuredClone(instance.content) :
|
|
120
|
+
const content = JSON.stringify(editor.document) === baseline ? structuredClone(instance.content) : current.current.fromNative(editor.document)
|
|
89
121
|
const serialized = JSON.stringify(content)
|
|
90
122
|
if (serialized === instance.emitted) return
|
|
91
123
|
instance.emitted = serialized; pending.current.push(serialized)
|
|
@@ -93,10 +125,12 @@ function NarrationSurface(props: NarrationEditorProps) {
|
|
|
93
125
|
} catch (error) { current.current.onError?.(error instanceof Error ? error : new Error(String(error))) }
|
|
94
126
|
}
|
|
95
127
|
return <NARRATION_CONTEXT.Provider value={{ locale: props.locale, readOnly: props.readOnly, advanced: props.advanced }}>
|
|
96
|
-
<div className="pm-ui-narration-editor pm-ui-block-editor pm-ui" onFocus={() => current.current.onFocus?.()}
|
|
128
|
+
<div className="pm-ui-narration-editor pm-ui-block-editor pm-ui" data-block-menu={props.blockMenu || undefined} onFocus={() => current.current.onFocus?.()}
|
|
97
129
|
onCompositionStart={() => current.current.onComposition?.(true)}
|
|
98
130
|
onCompositionEnd={() => queueMicrotask(() => { if (active.current === instance) current.current.onComposition?.(false) })}>
|
|
99
|
-
<BlockNoteView editor={editor} editable={!props.readOnly} theme={DOCUMENT_EDITOR_THEME} formattingToolbar={false} sideMenu={false} slashMenu={false} linkToolbar={false} comments={false} onChange={change}
|
|
131
|
+
<BlockNoteView editor={editor} editable={!props.readOnly} theme={DOCUMENT_EDITOR_THEME} formattingToolbar={false} sideMenu={false} slashMenu={false} linkToolbar={false} comments={false} onChange={change}>
|
|
132
|
+
{props.blockMenu && <SideMenuController sideMenu={NarrationSideMenu} />}
|
|
133
|
+
</BlockNoteView>
|
|
100
134
|
{props.advanced !== false && <div className="pm-ui-narration-editor__actions"><PmButton small variant="ghost" disabled={props.readOnly} onClick={() => { setDisplay(editor.getSelectedText()); setSpoken(''); setOpen(true) }}>{t.pronunciation}</PmButton></div>}
|
|
101
135
|
<PmDialog open={open} label={t.pronunciation} closeLabel={t.cancel} onClose={() => setOpen(false)} actions={<>
|
|
102
136
|
<PmButton small onClick={() => setOpen(false)}>{t.cancel}</PmButton>
|
|
@@ -5,6 +5,7 @@ import { components } from '@blocknote/mantine'
|
|
|
5
5
|
import { ComponentsContext, FloatingComposer, PositionPopover, useBlockNoteEditor, useComponentsContext, useCreateBlockNote, useDictionary, useEditorState, useExtension, useExtensionState } from '@blocknote/react'
|
|
6
6
|
import type { ComponentProps } from '@blocknote/react'
|
|
7
7
|
import type { BlockNoteEditor } from '@blocknote/core'
|
|
8
|
+
import { isDocumentPlaceAnchor, randomUUID } from '@lincyaw/kernel'
|
|
8
9
|
import { TextSelection } from '@tiptap/pm/state'
|
|
9
10
|
import { COMMENT_EDITOR_CONTEXT, DraftChoices } from './DocumentComments.tsx'
|
|
10
11
|
import { isNewCommentDraft, sameCommentDraftTarget } from './comment-drafts.ts'
|
|
@@ -60,7 +61,7 @@ export function NewCommentDraftProvider({ children }: { children?: ReactNode })
|
|
|
60
61
|
&& editor.prosemirrorState.doc === native.doc && editor.prosemirrorState.selection === native.selection && comments.store.state === extensionState
|
|
61
62
|
&& (!binding || latest.current === binding && binding.input === input && binding.record === record && !binding.composing)
|
|
62
63
|
if (record && !await drafts.confirm(record) || !owns()) return
|
|
63
|
-
const nextTarget = { ...target, intentId:
|
|
64
|
+
const nextTarget = { ...target, intentId: randomUUID() }, next = await drafts.recover(candidate, nextTarget, version)
|
|
64
65
|
store.beforeAction?.()
|
|
65
66
|
if (!next || !owns()) return
|
|
66
67
|
const positions = store.newDraftPositions(nextTarget, editor)
|
|
@@ -185,7 +186,7 @@ function NewCommentEditor(props: ComponentProps['Comments']['Editor']) {
|
|
|
185
186
|
})
|
|
186
187
|
return () => { stop(); stopEnter(); if (original && guarded && !props.editor.prosemirrorView.isDestroyed && props.editor.getExtension(CommentEditorSubmitExtension) === guarded) props.editor.replaceExtension(guarded, original) }
|
|
187
188
|
}, [binding, drafts, props.editor])
|
|
188
|
-
const composerId = useRef(
|
|
189
|
+
const composerId = useRef(randomUUID())
|
|
189
190
|
useLayoutEffect(() => {
|
|
190
191
|
if (!binding || !drafts || !context) return
|
|
191
192
|
return drafts.registerComposer({ id: composerId.current, target: binding.target,
|
|
@@ -211,7 +212,7 @@ export function DocumentNewCommentRecovery() {
|
|
|
211
212
|
const active = useRef(true)
|
|
212
213
|
useLayoutEffect(() => { active.current = true; return () => { active.current = false } }, [owner?.editor])
|
|
213
214
|
const state = useSyncExternalStore(drafts?.subscribe ?? emptySubscribe, drafts?.snapshot ?? (() => emptyState)), t = DOCUMENT_EDITOR_MESSAGES[context?.locale ?? 'en']
|
|
214
|
-
const candidates = state.candidates.filter(value => isNewCommentDraft(value.target))
|
|
215
|
+
const candidates = state.candidates.filter(value => isNewCommentDraft(value.target) && !(value.target.anchor && isDocumentPlaceAnchor(value.target.anchor)))
|
|
215
216
|
if (!drafts || !owner) return null
|
|
216
217
|
return <>{owner.failure && <PmNotice tone="warn">{t.commentTargetUnavailable}</PmNotice>}<DraftChoices candidates={candidates} preview
|
|
217
218
|
canRecover={candidate => isNewCommentDraft(candidate.target) && Boolean(context?.store.newDraftPositions(candidate.target, owner.editor))}
|