@lincyaw/workbench 0.2.0-rc.12 → 0.2.0-rc.120
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/README.md +1 -1
- package/package.json +5 -4
- package/src/AgentActivityBar.tsx +25 -0
- package/src/MediaClipEditor.tsx +7 -6
- package/src/StepProductionEditor.tsx +16 -7
- package/src/agent-activity-messages.ts +14 -0
- package/src/agent-activity.ts +38 -0
- package/src/approvals.tsx +6 -1
- package/src/audio-recording-messages.ts +5 -5
- 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/base-controls.tsx +28 -7
- package/src/body-draft-actions.ts +60 -0
- package/src/caption-timing-drafts.ts +20 -3
- package/src/caption-timing-messages.ts +2 -2
- package/src/caption-timing.ts +2 -2
- package/src/component-draft-actions.ts +1 -1
- package/src/component-properties.ts +3 -3
- package/src/component-property-drafts.ts +6 -6
- package/src/components.tsx +43 -38
- package/src/container-layout.ts +21 -0
- package/src/context.tsx +5 -3
- package/src/diagnostics.ts +1 -1
- package/src/document-draft-store.ts +45 -18
- package/src/document-drafts.ts +30 -21
- package/src/document-editing.ts +485 -0
- package/src/document-editor/BlockNoteSurface.tsx +40 -14
- package/src/document-editor/CommentComposer.tsx +24 -0
- package/src/document-editor/ComponentMaterials.tsx +4 -10
- package/src/document-editor/ComponentPropertiesDialog.tsx +12 -12
- package/src/document-editor/DocumentBlockFallback.tsx +4 -3
- package/src/document-editor/DocumentBlockPreview.tsx +11 -4
- package/src/document-editor/DocumentComments.tsx +87 -17
- package/src/document-editor/DocumentEditor.tsx +66 -14
- package/src/document-editor/DocumentStepNarration.tsx +39 -27
- package/src/document-editor/NarrationEditor.tsx +55 -21
- package/src/document-editor/NewCommentDrafts.tsx +120 -37
- package/src/document-editor/PlaceComment.tsx +252 -0
- package/src/document-editor/agent-targets.ts +34 -0
- package/src/document-editor/blocknote-messages.ts +2 -0
- package/src/document-editor/comment-draft-actions.ts +40 -20
- package/src/document-editor/comment-draft-inspection.ts +2 -2
- package/src/document-editor/comment-drafts.ts +75 -27
- package/src/document-editor/comments.ts +34 -14
- 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/inline.ts +1 -0
- package/src/document-editor/insertion-place.ts +60 -0
- package/src/document-editor/messages.ts +3 -3
- package/src/document-editor/narration-schema.tsx +12 -6
- package/src/document-editor/narration.ts +19 -3
- package/src/document-editor/page-body.ts +60 -0
- package/src/document-editor/popover.tsx +4 -2
- package/src/document-editor/projection.ts +21 -19
- package/src/document-editor/rich-text.ts +3 -2
- package/src/document-editor/selection.ts +13 -0
- package/src/document-editor/style.css +8 -3
- package/src/document-editor/table-identities.ts +2 -1
- package/src/document-preview.ts +3 -2
- package/src/document-production.ts +492 -0
- package/src/document-return-point.ts +2 -2
- package/src/document-session.ts +216 -67
- package/src/document-timing-drafts.ts +26 -6
- package/src/effective-settings.ts +12 -0
- package/src/history.ts +5 -5
- package/src/import-messages.ts +40 -0
- package/src/index.ts +11 -5
- package/src/jobs.ts +1 -1
- package/src/mcp-settings-messages.ts +39 -0
- package/src/media-drafts.ts +43 -1
- package/src/messages.ts +39 -18
- package/src/outline.ts +5 -5
- package/src/panels/DocumentImportDialog.tsx +59 -0
- package/src/panels/DocumentNarrationPanel.tsx +2 -2
- package/src/panels/DocumentView.tsx +106 -77
- package/src/panels/DocumentVoiceDialog.tsx +29 -12
- package/src/panels/DocumentVoiceField.tsx +3 -2
- package/src/panels/ExportPanel.tsx +2 -10
- package/src/panels/HistoryPanel.tsx +36 -10
- package/src/panels/HomePanel.tsx +12 -1
- package/src/panels/McpSettingsPanel.tsx +86 -0
- package/src/panels/PageDeleteDialog.tsx +4 -4
- package/src/panels/PageRenameDialog.tsx +1 -1
- package/src/panels/PreviewPanel.tsx +4 -7
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionCaptionTiming.tsx +12 -9
- package/src/panels/ProductionMediaClips.tsx +25 -9
- package/src/panels/ProductionPanel.tsx +21 -17
- package/src/panels/ProductionRecording.tsx +86 -9
- package/src/panels/ProductionRecordingRange.tsx +26 -23
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/panels/ProductionTranscription.tsx +8 -6
- package/src/panels/SourceDocumentPanel.tsx +24 -40
- package/src/panels/SpeechSettingsPanel.tsx +2 -2
- package/src/panels/TranscriptionAdoption.tsx +42 -36
- package/src/panels/VoiceCloneDialog.tsx +2 -1
- package/src/panels/VoicePreviewDialog.tsx +1 -1
- package/src/panels/VoiceScopeField.tsx +2 -2
- package/src/panels/VoiceoverDialog.tsx +11 -10
- package/src/places.ts +1 -36
- package/src/preview-playback.ts +1 -1
- package/src/production-draft-actions.ts +37 -0
- package/src/production-messages.ts +6 -0
- package/src/production-playback.ts +1 -1
- package/src/production-voice-playback.ts +3 -2
- package/src/recording-adoption.ts +4 -4
- package/src/sha256.ts +9 -0
- package/src/speech-settings-messages.ts +6 -6
- package/src/step-production.ts +4 -4
- package/src/styles.css +43 -92
- package/src/transcription-drafts.ts +124 -0
- package/src/use-recording-adoption.ts +5 -4
- package/src/voice-drafts.ts +32 -8
- package/src/voice-messages.ts +9 -9
- package/src/voiceover-jobs.ts +1 -1
- package/src/workbench-state.ts +159 -0
- package/src/workbench.ts +323 -956
- package/src/workspace-client.ts +41 -12
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createExtension } from '@blocknote/core'
|
|
2
|
+
import { Plugin, TextSelection } from '@tiptap/pm/state'
|
|
3
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
4
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view'
|
|
5
|
+
import type { Node } from '@tiptap/pm/model'
|
|
6
|
+
import type { NativeDocumentEditor } from './schema.tsx'
|
|
7
|
+
|
|
8
|
+
// Pages are top-level blocks: doc > blockGroup > blockContainer > (content, children?).
|
|
9
|
+
function emptyParagraph(container: Node | null | undefined): boolean {
|
|
10
|
+
return container?.childCount === 1 && container.firstChild!.type.name === 'paragraph' && container.firstChild!.content.size === 0
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function pageEnds(doc: Node, placeholder: string): DecorationSet {
|
|
14
|
+
const group = doc.firstChild, found: Decoration[] = []
|
|
15
|
+
if (!group) return DecorationSet.empty
|
|
16
|
+
group.forEach((container, offset, index) => {
|
|
17
|
+
const next = index + 1 < group.childCount ? group.child(index + 1) : undefined
|
|
18
|
+
if (!emptyParagraph(container) || next && next.firstChild?.type.name !== 'presmiumPage') return
|
|
19
|
+
const start = 1 + offset + 1
|
|
20
|
+
found.push(Decoration.node(start, start + container.firstChild!.nodeSize, { 'data-page-end': '', 'data-placeholder': placeholder }))
|
|
21
|
+
})
|
|
22
|
+
return DecorationSet.create(doc, found)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A page's empty last paragraph shows the editor's placeholder even without the caret, so an empty body is visible;
|
|
27
|
+
* Enter at the end of a title goes into that paragraph instead of adding another one before it.
|
|
28
|
+
*/
|
|
29
|
+
export const documentPageBodies = createExtension(({ editor }: { editor: NativeDocumentEditor }) => ({
|
|
30
|
+
key: 'presmium-document-page-bodies',
|
|
31
|
+
prosemirrorPlugins: [new Plugin<DecorationSet>({
|
|
32
|
+
state: {
|
|
33
|
+
init: (_, state: EditorState) => pageEnds(state.doc, editor.dictionary.placeholders.default ?? ''),
|
|
34
|
+
apply: (transaction, value) => transaction.docChanged ? pageEnds(transaction.doc, editor.dictionary.placeholders.default ?? '') : value,
|
|
35
|
+
},
|
|
36
|
+
props: { decorations(state) { return editor.isEditable ? this.getState(state) : undefined } },
|
|
37
|
+
})],
|
|
38
|
+
keyboardShortcuts: {
|
|
39
|
+
Enter: () => {
|
|
40
|
+
const { selection } = editor.prosemirrorState, { $head } = selection
|
|
41
|
+
if (!editor.isEditable || !selection.empty || $head.parent.type.name !== 'presmiumPage' || $head.parentOffset !== $head.parent.content.size) return false
|
|
42
|
+
const after = $head.after($head.depth - 1)
|
|
43
|
+
if (!emptyParagraph(editor.prosemirrorState.doc.resolve(after).nodeAfter)) return false
|
|
44
|
+
editor.transact(transaction => transaction.setSelection(TextSelection.create(transaction.doc, after + 2)).scrollIntoView())
|
|
45
|
+
return true
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}))
|
|
49
|
+
|
|
50
|
+
/** The caret at the end of the document: in its empty last paragraph, or in a new one after the last block. */
|
|
51
|
+
export function focusDocumentEnd(editor: NativeDocumentEditor): void {
|
|
52
|
+
const last = editor.document.at(-1)
|
|
53
|
+
if (!last) return
|
|
54
|
+
editor.transact(transaction => {
|
|
55
|
+
if (last.type === 'paragraph' && !last.children.length && !last.content.length) editor.setTextCursorPosition(last, 'end')
|
|
56
|
+
else editor.setTextCursorPosition(editor.insertBlocks([{ type: 'paragraph' }], last, 'after')[0]!, 'start')
|
|
57
|
+
transaction.scrollIntoView()
|
|
58
|
+
})
|
|
59
|
+
editor.focus()
|
|
60
|
+
}
|
|
@@ -2,7 +2,7 @@ import { useLayoutEffect } from 'react'
|
|
|
2
2
|
import { Menu } from '@mantine/core'
|
|
3
3
|
import { components } from '@blocknote/mantine'
|
|
4
4
|
import type { ComponentProps, FloatingUIOptions } from '@blocknote/react'
|
|
5
|
-
import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/react'
|
|
5
|
+
import { autoUpdate, computePosition, flip, offset, shift, size } from '@floating-ui/react'
|
|
6
6
|
|
|
7
7
|
/** A length token in CSS pixels, for positioning code that only takes numbers. */
|
|
8
8
|
function tokenPixels(name: string, element: Element = document.documentElement): number {
|
|
@@ -73,7 +73,9 @@ export function commentFloating(line?: () => DOMRect | undefined): NonNullable<F
|
|
|
73
73
|
const padding = edge()
|
|
74
74
|
return {
|
|
75
75
|
...line ? { placement: 'bottom-start' as const } : {},
|
|
76
|
-
middleware: [...line ? [commentLine(line)] : [], offset(COMMENT_GAP), flip({ padding, flipAlignment: false }), shift({ padding })
|
|
76
|
+
middleware: [...line ? [commentLine(line)] : [], offset(COMMENT_GAP), flip({ padding, flipAlignment: false }), shift({ padding }), size({ padding, apply: ({ availableHeight, elements }) => {
|
|
77
|
+
elements.floating.style.setProperty('--pm-comment-available-height', `${Math.max(0, availableHeight)}px`)
|
|
78
|
+
} })],
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { documentPageDefaults, DOCUMENT_PAGE_DEFAULT_TIMING } from '@lincyaw/kernel'
|
|
2
|
-
import type { DocumentBlock, DocumentPageIds, NarrationNode, RichTextNode, Section,
|
|
1
|
+
import { documentPageDefaults, DOCUMENT_PAGE_DEFAULT_TIMING, randomUUID } from '@lincyaw/kernel'
|
|
2
|
+
import type { DocumentBlock, DocumentPageIds, NarrationNode, RichTextNode, Section, PresmiumDocument, TextBlock } from '@lincyaw/kernel'
|
|
3
3
|
import { productInlineToNative } from './inline.ts'
|
|
4
4
|
import { captureRichBaseline, createRichProjection, nativeRichTextToProduct, productRichTextToNative } from './rich-text.ts'
|
|
5
5
|
import type { RichProjection } from './rich-text.ts'
|
|
@@ -9,15 +9,17 @@ export interface DocumentProjection extends RichProjection {
|
|
|
9
9
|
owners: Map<string, string>
|
|
10
10
|
pages: Map<string, string>
|
|
11
11
|
blockSections: Map<string, string>
|
|
12
|
-
document:
|
|
12
|
+
document: PresmiumDocument
|
|
13
13
|
content: DocumentEditorInput[]
|
|
14
14
|
structure?: string
|
|
15
15
|
structures: Map<string, Pick<DocumentProjection, 'document' | 'rich' | 'owners' | 'pages' | 'baseline'>>
|
|
16
16
|
createdPages: Map<string, NativePageCreation>
|
|
17
17
|
componentConfiguration: Map<string, string>
|
|
18
|
+
/** The plugins the document has, inherited ones included: they decide which code is drawn as a diagram. */
|
|
19
|
+
plugins?: readonly string[]
|
|
18
20
|
}
|
|
19
21
|
export type NativePageCreation = DocumentPageIds
|
|
20
|
-
const newId = () =>
|
|
22
|
+
const newId = () => randomUUID()
|
|
21
23
|
export const pageId = (sectionId: string) => `page:${sectionId}`
|
|
22
24
|
function plain(nodes: readonly { type: string, text?: string, children?: readonly unknown[] }[]): string {
|
|
23
25
|
return nodes.map(node => node.type === 'text' ? node.text ?? '' : node.type === 'break' ? '\n' : node.children ? plain(node.children as Parameters<typeof plain>[0]) : '').join('')
|
|
@@ -26,13 +28,13 @@ function plain(nodes: readonly { type: string, text?: string, children?: readonl
|
|
|
26
28
|
* Code the published document draws as a picture is generated content: authors see its preview, not its source.
|
|
27
29
|
* The viewer draws Mermaid; the content add-on's compiler pass turns PlantUML into an image.
|
|
28
30
|
*/
|
|
29
|
-
export function isDiagram(block: DocumentBlock,
|
|
31
|
+
export function isDiagram(block: DocumentBlock, plugins: readonly string[] | undefined): boolean {
|
|
30
32
|
if (block.type !== 'code') return false
|
|
31
|
-
return block.language === 'mermaid' || /^(?:plantuml|puml)$/i.test(block.language) && Boolean(
|
|
33
|
+
return block.language === 'mermaid' || /^(?:plantuml|puml)$/i.test(block.language) && Boolean(plugins?.includes('@lincyaw/addon-content'))
|
|
32
34
|
}
|
|
33
|
-
/** Blocks the editor shows through their read-only runtime preview. */
|
|
34
|
-
export function hasBlockPreview(block: DocumentBlock,
|
|
35
|
-
return block.type === 'component' || isDiagram(block,
|
|
35
|
+
/** Blocks the editor shows through their read-only runtime preview; `plugins` are the document's effective ones. */
|
|
36
|
+
export function hasBlockPreview(block: DocumentBlock, plugins: readonly string[] | undefined): boolean {
|
|
37
|
+
return block.type === 'component' || isDiagram(block, plugins)
|
|
36
38
|
}
|
|
37
39
|
function register(blocks: readonly DocumentEditorInput[], owner: string, context: DocumentProjection): void {
|
|
38
40
|
for (const block of blocks) { if (block.id) context.owners.set(block.id, owner); if (block.children) register(block.children, owner, context) }
|
|
@@ -50,12 +52,12 @@ function productBlock(blockId: string, context: DocumentProjection, sectionId: s
|
|
|
50
52
|
context.owners.set(block.id, block.id)
|
|
51
53
|
if (block.type === 'container') return [{ id: block.id, type: 'presmiumContainer', props: { entityId: block.id, layout: block.layout, title: block.properties.title ?? '' }, children: block.children.flatMap(child => productBlock(child, context, sectionId)) }]
|
|
52
54
|
if (block.type === 'image') return [{ id: block.id, type: 'image', props: { url: block.assetId ? document.assets[block.assetId]?.location ?? '' : '', caption: plain(block.caption ?? []), name: block.alt, textAlignment: block.alignment ?? 'left', ...block.width !== undefined ? { previewWidth: block.width } : {} } }]
|
|
53
|
-
if (block.type === 'code' && block.value !== undefined && !isDiagram(block,
|
|
54
|
-
return [{ id: block.id, type: 'presmiumAtom', props: { entityId: block.id, kind: block.type, label: block.type === 'code' ? block.title ?? block.origin?.anchor ?? block.language : document.definitions[block.definitionId]?.kind ?? block.definitionId }, ...block.type === 'component' && block.children ? { children: block.children.flatMap(child => productBlock(child, context, sectionId)) } : {} }]
|
|
55
|
+
if (block.type === 'code' && block.value !== undefined && !isDiagram(block, context.plugins)) return [{ id: block.id, type: 'codeBlock', props: { language: block.language }, content: block.value }]
|
|
56
|
+
return [{ id: block.id, type: 'presmiumAtom', props: { entityId: block.id, kind: block.type, label: block.type === 'code' ? block.title ?? block.origin?.anchor ?? block.language : block.type === 'embed' ? block.source.document : document.definitions[block.definitionId]?.kind ?? block.definitionId }, ...block.type === 'component' && block.children ? { children: block.children.flatMap(child => productBlock(child, context, sectionId)) } : {} }]
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
export function createDocumentProjection(document:
|
|
58
|
-
const context: DocumentProjection = { ...createRichProjection(), owners: new Map(), pages: new Map(), blockSections: new Map(), structures: new Map(), createdPages: new Map(), componentConfiguration: new Map(), document: structuredClone(document), content: [] }
|
|
59
|
+
export function createDocumentProjection(document: PresmiumDocument, plugins: readonly string[] | undefined = document.metadata.plugins): DocumentProjection {
|
|
60
|
+
const context: DocumentProjection = { ...createRichProjection(), owners: new Map(), pages: new Map(), blockSections: new Map(), structures: new Map(), createdPages: new Map(), componentConfiguration: new Map(), document: structuredClone(document), content: [], ...plugins ? { plugins } : {} }
|
|
59
61
|
context.content = document.sectionOrder.flatMap(sectionId => {
|
|
60
62
|
const section = document.sections[sectionId]!
|
|
61
63
|
context.pages.set(pageId(sectionId), sectionId)
|
|
@@ -80,7 +82,7 @@ export function rememberDocumentStructure(blocks: readonly DocumentEditorBlock[]
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/** Source-owned component configuration also accompanies a missing node in native structural history. */
|
|
83
|
-
export function rememberComponentConfiguration(context: DocumentProjection, source:
|
|
85
|
+
export function rememberComponentConfiguration(context: DocumentProjection, source: PresmiumDocument): void {
|
|
84
86
|
const changed = new Set<string>()
|
|
85
87
|
const overrides = new Map<string, unknown[]>()
|
|
86
88
|
for (const step of Object.values(source.steps)) for (const visual of step.visuals) if (visual.parameters) {
|
|
@@ -150,7 +152,7 @@ function isEntity(block: DocumentEditorBlock, context: DocumentProjection): bool
|
|
|
150
152
|
if (block.type === 'presmiumContainer' || block.type === 'image') return true
|
|
151
153
|
return block.type === 'codeBlock' && context.document.blocks[context.owners.get(block.id) ?? block.id]?.type !== 'text' && !context.rich.has(block.id)
|
|
152
154
|
}
|
|
153
|
-
function nativeChildren(native: readonly DocumentEditorBlock[], context: DocumentProjection, next:
|
|
155
|
+
function nativeChildren(native: readonly DocumentEditorBlock[], context: DocumentProjection, next: PresmiumDocument, usedListIds: Set<string>): string[] {
|
|
154
156
|
const children: string[] = []
|
|
155
157
|
let buffer: DocumentEditorBlock[] = [], owner: string | undefined
|
|
156
158
|
const flush = () => {
|
|
@@ -214,7 +216,7 @@ function nativeChildren(native: readonly DocumentEditorBlock[], context: Documen
|
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
/** A plain text transaction keeps the teaching graph and untouched rich nodes by identity. */
|
|
217
|
-
function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest:
|
|
219
|
+
function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest: PresmiumDocument): PresmiumDocument | undefined {
|
|
218
220
|
const changed: { native: DocumentEditorBlock, serialized: string, owner: TextBlock }[] = []
|
|
219
221
|
const visit = (blocks: readonly DocumentEditorBlock[]): boolean => blocks.every(block => {
|
|
220
222
|
const serialized = JSON.stringify(block)
|
|
@@ -239,7 +241,7 @@ function projectTextEdits(blocks: readonly DocumentEditorBlock[], context: Docum
|
|
|
239
241
|
}
|
|
240
242
|
|
|
241
243
|
/** Reconstruct the normalized product tree without visiting or reparsing Markdown. */
|
|
242
|
-
export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest = context.document):
|
|
244
|
+
export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[], context: DocumentProjection, latest = context.document): PresmiumDocument {
|
|
243
245
|
const targetStructure = structureOf(blocks, context)
|
|
244
246
|
if (targetStructure === context.structure) {
|
|
245
247
|
const edited = projectTextEdits(blocks, context, latest)
|
|
@@ -373,7 +375,7 @@ export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[],
|
|
|
373
375
|
if (next.production.cueTimings) delete next.production.cueTimings[node.id]
|
|
374
376
|
return false
|
|
375
377
|
})
|
|
376
|
-
context.document = share(context.document, structuredClone(next)) as
|
|
378
|
+
context.document = share(context.document, structuredClone(next)) as PresmiumDocument
|
|
377
379
|
context.blockSections = sectionOf
|
|
378
380
|
for (const block of Object.values(context.document.blocks)) if (block.type === 'text') rememberRich(block.content, context)
|
|
379
381
|
context.baseline.clear(); captureRichBaseline(blocks, context)
|
|
@@ -382,7 +384,7 @@ export function nativeDocumentToProduct(blocks: readonly DocumentEditorBlock[],
|
|
|
382
384
|
}
|
|
383
385
|
|
|
384
386
|
/** Only an untouched, unreferenced creation default is removed with its native insertion. */
|
|
385
|
-
function untouchedPageCreation(document:
|
|
387
|
+
function untouchedPageCreation(document: PresmiumDocument, created: NativePageCreation): boolean {
|
|
386
388
|
const { sectionId, blockId, stepId } = created, section = document.sections[sectionId]
|
|
387
389
|
if (section?.stepOrder.length !== 1 || section.stepOrder[0] !== stepId
|
|
388
390
|
|| JSON.stringify(document.steps[stepId]) !== JSON.stringify(documentPageDefaults(created, '').step)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InlineNode, JsonValue, ListItemNode, RichTextNode, TableNode } from '@lincyaw/kernel'
|
|
2
|
+
import { randomUUID } from '@lincyaw/kernel'
|
|
2
3
|
import type { TableCellProps } from '@blocknote/core'
|
|
3
4
|
import { nativeInlineToProduct, nativeTextStyleToProduct, productInlineToNative, productTextStyleToNative } from './inline.ts'
|
|
4
5
|
import type { InlineProjectionContext, NativeInline } from './inline.ts'
|
|
@@ -27,12 +28,12 @@ export interface RichProjection extends InlineProjectionContext {
|
|
|
27
28
|
tables: Map<string, { id: string, cells: string[] }[]>
|
|
28
29
|
}
|
|
29
30
|
export function createRichProjection(): RichProjection {
|
|
30
|
-
return { rich: new Map(), baseline: new Map(), tables: new Map(), opaqueInline: new Map(), newInlineId: () =>
|
|
31
|
+
return { rich: new Map(), baseline: new Map(), tables: new Map(), opaqueInline: new Map(), newInlineId: () => randomUUID() }
|
|
31
32
|
}
|
|
32
33
|
export function captureRichBaseline(blocks: readonly DocumentEditorBlock[], context: RichProjection): void {
|
|
33
34
|
for (const block of blocks) { context.baseline.set(block.id, JSON.stringify(block)); captureRichBaseline(block.children, context) }
|
|
34
35
|
}
|
|
35
|
-
const id = () =>
|
|
36
|
+
const id = () => randomUUID()
|
|
36
37
|
const atom = (node: RichTextNode): DocumentEditorInput => ({ id: node.id, type: 'presmiumAtom', props: { entityId: node.id, kind: `rich:${node.type}`, label: node.type === 'extension' ? fallbackText(node.fallback) : fallbackText(node) } })
|
|
37
38
|
|
|
38
39
|
/** The projection records structural identities; the saved document owns all content. */
|
|
@@ -120,6 +120,19 @@ export function nativeTextPosition(editor: NativeDocumentEditor, point: { blockI
|
|
|
120
120
|
return nativeTextPositionInDocument(editor.prosemirrorState.doc, point)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** The native range of a block's whole inline text, to select it. */
|
|
124
|
+
export function nativeBlockText(editor: NativeDocumentEditor, blockId: string): { from: number, to: number } | undefined {
|
|
125
|
+
let range: { from: number, to: number } | undefined
|
|
126
|
+
editor.prosemirrorState.doc.descendants((node, beforePos) => {
|
|
127
|
+
if (range) return false
|
|
128
|
+
if (node.attrs.id !== blockId) return
|
|
129
|
+
const info = getBlockInfoFromNode(node, beforePos)
|
|
130
|
+
if (info.hasContent && info.contentKind === 'inline') range = { from: info.contentStart, to: info.contentEnd }
|
|
131
|
+
return false
|
|
132
|
+
})
|
|
133
|
+
return range
|
|
134
|
+
}
|
|
135
|
+
|
|
123
136
|
/** Stable anchor lookup against a captured native transaction’s input document. */
|
|
124
137
|
export function nativeTextPositionInDocument(document: ProseMirrorNode, point: { blockId: string, offset: number }): number | undefined {
|
|
125
138
|
let position: number | undefined
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
.pm-document-editor { min-width: 0; }
|
|
2
|
-
|
|
3
|
-
.pm-document-
|
|
1
|
+
.pm-document-editor { display: flex; flex: 1 0 auto; flex-direction: column; min-width: 0; }
|
|
2
|
+
/* The page below the last block, down to the sheet's end: a press there continues the document at its end. */
|
|
3
|
+
.pm-document-editor__end { flex: 1 0 auto; min-height: var(--pm-space-4); }
|
|
4
|
+
.pm-document-editor__end[data-editable] { cursor: text; }
|
|
5
|
+
.pm-document-editor .bn-block-content[data-page-end]:has(.ProseMirror-trailingBreak:only-child)::after { content: attr(data-placeholder); }
|
|
6
|
+
.pm-document-editor__file-errors { margin: 0; padding-inline-start: var(--pm-space-4); overflow-wrap: anywhere; }
|
|
4
7
|
.pm-document-editor .pm-document-editor__page-title { margin-block: var(--pm-space-5) var(--pm-space-3); font-family: var(--pm-font-sans); font-size: var(--pm-text-title); font-weight: var(--pm-weight-semibold); line-height: var(--pm-leading-tight); }
|
|
5
8
|
.pm-document-editor__atom { flex: 1; width: 100%; min-width: 0; }
|
|
6
9
|
.pm-document-editor .bn-block-content[data-content-type='presmiumAtom'] > * { flex: 1; width: 100%; min-width: 0; }
|
|
7
10
|
.pm-document-editor__fallback { display: grid; gap: var(--pm-space-2); min-width: 0; }
|
|
8
11
|
.pm-document-editor__fallback p { margin: 0; white-space: pre-wrap; }
|
|
9
12
|
.pm-document-editor__comment-tools { position: sticky; top: var(--pm-space-2); z-index: var(--pm-z-site-header); width: fit-content; margin-inline-start: var(--pm-space-5); }
|
|
13
|
+
|
|
14
|
+
.pm-document-place-comment__trigger { display: inline-flex; align-items: center; gap: var(--pm-space-1); }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createExtension, getBlockInfoNearPos, getNodeId } from '@blocknote/core'
|
|
2
2
|
import { Extension } from '@tiptap/core'
|
|
3
3
|
import { Plugin } from '@tiptap/pm/state'
|
|
4
|
+
import { randomUUID } from '@lincyaw/kernel'
|
|
4
5
|
import type { NativeDocumentEditor } from './schema.tsx'
|
|
5
6
|
import type { RichProjection } from './rich-text.ts'
|
|
6
7
|
|
|
@@ -24,7 +25,7 @@ export const tableIdentityExtension = createExtension({
|
|
|
24
25
|
after.doc.descendants((node, position) => {
|
|
25
26
|
if (!TYPES.includes(node.type.name)) return
|
|
26
27
|
let id = node.attrs[ATTR] as string | null
|
|
27
|
-
if (!id || used.has(id)) { id =
|
|
28
|
+
if (!id || used.has(id)) { id = randomUUID(); transaction.setNodeMarkup(position, undefined, { ...node.attrs, [ATTR]: id }) }
|
|
28
29
|
used.add(id)
|
|
29
30
|
})
|
|
30
31
|
if (transaction.steps.length) return transaction.setMeta('addToHistory', false)
|
package/src/document-preview.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DOCUMENT_ENTRY } from '@lincyaw/kernel'
|
|
1
2
|
import { WorkspaceServerError } from './workspace-client.ts'
|
|
2
3
|
import type { WorkspaceClient, WorkspaceRequestEvent } from './workspace-client.ts'
|
|
3
4
|
import type { IrAnswer, PreviewAnswer, PreviewRenderer } from '@lincyaw/kernel'
|
|
@@ -52,7 +53,7 @@ export function waitForPreviewRequest<T>(work: Promise<T>, signal?: AbortSignal)
|
|
|
52
53
|
|
|
53
54
|
/** Speech preflights need a confirmed source snapshot without building a visual output. */
|
|
54
55
|
export async function readDocumentSnapshot(client: WorkspaceClient, source: Pick<PreviewSource, 'directory' | 'version' | 'fingerprint'>, signal?: AbortSignal): Promise<IrAnswer> {
|
|
55
|
-
const entry = source.directory ? `${source.directory}
|
|
56
|
+
const entry = source.directory ? `${source.directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY, started = Date.now()
|
|
56
57
|
for (;;) {
|
|
57
58
|
signal?.throwIfAborted()
|
|
58
59
|
const ir = await waitForPreviewRequest(client.readIr(source.directory), signal)
|
|
@@ -64,7 +65,7 @@ export async function readDocumentSnapshot(client: WorkspaceClient, source: Pick
|
|
|
64
65
|
|
|
65
66
|
/** The explicit request owner can abort while the compiler confirms one exact source snapshot. */
|
|
66
67
|
export async function compileDocumentPreview(client: WorkspaceClient, source: PreviewSource, signal?: AbortSignal, feedbackOwner?: WorkspaceRequestEvent['feedbackOwner'], onPreparing?: () => void): Promise<CompiledDocumentPreview> {
|
|
67
|
-
const { directory, fingerprint } = source, entry = directory ? `${directory}
|
|
68
|
+
const { directory, fingerprint } = source, entry = directory ? `${directory}/${DOCUMENT_ENTRY}` : DOCUMENT_ENTRY
|
|
68
69
|
let started = Date.now()
|
|
69
70
|
for (;;) {
|
|
70
71
|
signal?.throwIfAborted()
|