@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PresmiumDocument } from '@lincyaw/kernel'
|
|
2
2
|
import { stepTimingValue } from './step-production.ts'
|
|
3
3
|
import type { ProductionSource, StepDurationDraft, StepDurationKey } from './step-production.ts'
|
|
4
4
|
|
|
@@ -8,6 +8,8 @@ const KEYS = ['minimumHoldMs', 'trailingPauseMs'] as const
|
|
|
8
8
|
/** Only unaccepted form strings live here. Accepted timing remains in the document actor. */
|
|
9
9
|
export class DocumentTimingDrafts {
|
|
10
10
|
readonly #documents = new Map<string, Map<string, StoredDraft>>()
|
|
11
|
+
readonly #stored = new Map<string, string | null>()
|
|
12
|
+
readonly #unreadable = new Set<string>()
|
|
11
13
|
failed = false
|
|
12
14
|
#storage(identity: string): string { return `presmium.document-timing.v1:${identity}` }
|
|
13
15
|
#load(identity: string): Map<string, StoredDraft> {
|
|
@@ -18,6 +20,7 @@ export class DocumentTimingDrafts {
|
|
|
18
20
|
let raw: string | null = null
|
|
19
21
|
try {
|
|
20
22
|
raw = sessionStorage.getItem(this.#storage(identity))
|
|
23
|
+
this.#stored.set(identity, raw)
|
|
21
24
|
const entries: unknown = JSON.parse(raw ?? '[]')
|
|
22
25
|
if (!Array.isArray(entries) || entries.length > 512) throw new Error('document-timing-draft-data')
|
|
23
26
|
for (const entry of entries) {
|
|
@@ -27,25 +30,41 @@ export class DocumentTimingDrafts {
|
|
|
27
30
|
values.set(entry[0], { text: value.text, error: true, review: true, baseValue: value.baseValue, baseSource: value.baseSource })
|
|
28
31
|
}
|
|
29
32
|
} catch {
|
|
30
|
-
this.failed = true
|
|
33
|
+
this.failed = true; this.#unreadable.add(identity)
|
|
31
34
|
if (raw !== null) try { sessionStorage.setItem(`${this.#storage(identity)}:unreadable`, raw) } catch { /* Keep the original slot untouched when storage is unavailable. */ }
|
|
32
35
|
}
|
|
33
36
|
if (!this.failed) for (const key of this.#documents.keys()) {
|
|
34
37
|
if (this.#documents.size <= 8) break
|
|
35
|
-
if (key !== identity) this.#documents.delete(key)
|
|
38
|
+
if (key !== identity) { this.#documents.delete(key); this.#stored.delete(key) }
|
|
36
39
|
}
|
|
37
40
|
return values
|
|
38
41
|
}
|
|
39
|
-
get(identity: string, document:
|
|
42
|
+
get(identity: string, document: PresmiumDocument, stepId: string, key: StepDurationKey): StepDurationDraft | undefined {
|
|
40
43
|
const draft = this.#load(identity).get(JSON.stringify([stepId, key]))
|
|
41
44
|
if (!draft) return undefined
|
|
42
45
|
const actual = stepTimingValue(document, stepId, key)
|
|
43
46
|
return { text: draft.text, error: draft.error, review: draft.review || draft.baseValue !== actual.value || draft.baseSource !== actual.source }
|
|
44
47
|
}
|
|
45
|
-
has(identity: string, document:
|
|
48
|
+
has(identity: string, document: PresmiumDocument): boolean {
|
|
46
49
|
return [...this.#load(identity).keys()].some(target => Object.hasOwn(document.steps, JSON.parse(target)[0]))
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
partial(identity: string): boolean { this.#load(identity); try { return this.#unreadable.has(identity) || sessionStorage.getItem(this.#storage(identity)) !== this.#stored.get(identity) } catch { return true } }
|
|
52
|
+
entries(identity: string): readonly (readonly [string, StoredDraft])[] { return [...this.#load(identity)] }
|
|
53
|
+
/** Retire only after the original session slot accepted the removal. */
|
|
54
|
+
discard(identity: string, key: string): boolean {
|
|
55
|
+
const values = this.#load(identity)
|
|
56
|
+
if (this.#unreadable.has(identity) || !values.has(key)) return false
|
|
57
|
+
try {
|
|
58
|
+
if (sessionStorage.getItem(this.#storage(identity)) !== this.#stored.get(identity)) { this.failed = true; return false }
|
|
59
|
+
const next = [...values].filter(([target]) => target !== key)
|
|
60
|
+
if (next.length) sessionStorage.setItem(this.#storage(identity), JSON.stringify(next))
|
|
61
|
+
else sessionStorage.removeItem(this.#storage(identity))
|
|
62
|
+
this.#stored.set(identity, next.length ? JSON.stringify(next) : null)
|
|
63
|
+
values.delete(key); this.failed = false
|
|
64
|
+
return true
|
|
65
|
+
} catch { this.failed = true; return false }
|
|
66
|
+
}
|
|
67
|
+
set(identity: string, document: PresmiumDocument, stepId: string, key: StepDurationKey, draft: StepDurationDraft | undefined): boolean {
|
|
49
68
|
const values = this.#load(identity), target = JSON.stringify([stepId, key]), previous = values.get(target), actual = stepTimingValue(document, stepId, key)
|
|
50
69
|
if (draft && draft.text.length > 256 || draft && !previous && values.size >= 512) { this.failed = true; return true }
|
|
51
70
|
if (previous?.text === draft?.text && previous?.error === draft?.error && !previous?.review && (!previous || previous.baseValue === actual.value && previous.baseSource === actual.source)) return false
|
|
@@ -54,6 +73,7 @@ export class DocumentTimingDrafts {
|
|
|
54
73
|
try {
|
|
55
74
|
if (values.size) sessionStorage.setItem(this.#storage(identity), JSON.stringify([...values]))
|
|
56
75
|
else sessionStorage.removeItem(this.#storage(identity))
|
|
76
|
+
this.#stored.set(identity, values.size ? JSON.stringify([...values]) : null)
|
|
57
77
|
this.failed = false
|
|
58
78
|
} catch { this.failed = true }
|
|
59
79
|
return true
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { withInheritedSettings } from '@lincyaw/kernel'
|
|
2
|
+
import type { DocumentDefaults, EffectiveDocument, PresmiumDocument } from '@lincyaw/kernel'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The edited document with what it inherits from its ancestors and the workspace defaults filled in, for decisions
|
|
6
|
+
* (content language, plugins, the document's voice and timing); never saved.
|
|
7
|
+
*/
|
|
8
|
+
export function effectiveOf(document: PresmiumDocument, inherited?: DocumentDefaults): EffectiveDocument
|
|
9
|
+
export function effectiveOf(document: PresmiumDocument | undefined, inherited?: DocumentDefaults): EffectiveDocument | undefined
|
|
10
|
+
export function effectiveOf(document: PresmiumDocument | undefined, inherited?: DocumentDefaults): EffectiveDocument | undefined {
|
|
11
|
+
return document && withInheritedSettings(document, inherited)
|
|
12
|
+
}
|
package/src/history.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { errorMessage } from '@lincyaw/kernel'
|
|
1
|
+
import { errorMessage, randomUUID } from '@lincyaw/kernel'
|
|
2
2
|
import type { RevertResult, ReviewChange, ReviewSnapshot, ReviewUpdate } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import { WorkspaceServerError } from './workspace-client.ts'
|
|
5
5
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
6
6
|
|
|
@@ -42,13 +42,13 @@ export class DocumentHistory {
|
|
|
42
42
|
this.#review = undefined
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async read(dir: string): Promise<void> {
|
|
45
|
+
async read(dir: string, signal?: AbortSignal): Promise<void> {
|
|
46
46
|
this.#offsets = [0]
|
|
47
47
|
this.#page = 0
|
|
48
48
|
const read = ++this.#reads, scope = this.#scope
|
|
49
49
|
const current = () => this.#store.state.document === dir && read === this.#reads && scope === this.#scope
|
|
50
50
|
try {
|
|
51
|
-
const [history, { files }] = await Promise.all([this.#client.readRevisions(dir), this.#client.readChanges(dir)])
|
|
51
|
+
const [history, { files }] = await Promise.all([this.#client.readRevisions(dir, undefined, signal), this.#client.readChanges(dir, signal)])
|
|
52
52
|
if (current()) {
|
|
53
53
|
const historyFailure = this.#store.state.historyFailure
|
|
54
54
|
this.#store.set({ history, outside: files, ...this.#readFailure === historyFailure ? { historyFailure: undefined } : {} })
|
|
@@ -129,7 +129,7 @@ export class DocumentHistory {
|
|
|
129
129
|
#change(which: 'undo' | 'redo' | 'revertRevision', expect: string | undefined): Promise<boolean> {
|
|
130
130
|
const binding = this.#store.state.history?.historyBinding
|
|
131
131
|
if (!binding || !expect) return Promise.resolve(false)
|
|
132
|
-
const request = { id:
|
|
132
|
+
const request = { id: randomUUID(), ...binding, expect }
|
|
133
133
|
return this.#run(dir => this.#client[which](dir, request))
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const IMPORT_MESSAGES = {
|
|
2
|
+
'zh-CN': {
|
|
3
|
+
title: '导入文档', files: '选择文件', folder: '选择文件夹', submit: '导入',
|
|
4
|
+
description: '支持 Markdown(.md、.markdown)和 Word(.docx)。每个文件生成一份文稿,保留目录层级;一级、二级标题分成页面。',
|
|
5
|
+
images: '含本地图片或文件间链接的 Markdown,请导入所在文件夹。Word 保留标题、段落、列表、表格、强调、链接和内嵌图片。',
|
|
6
|
+
limits: '最多 1000 个文件,合计 32 MiB。导入后可在工作区中继续编辑。',
|
|
7
|
+
selected: (count: number) => `已选择 ${count} 个文件`,
|
|
8
|
+
done: (count: number, unresolved: number, warnings: number) => `已导入 ${count} 份文稿${unresolved ? `,${unresolved} 个链接或图片需要检查` : ''}${warnings ? `,${warnings} 项 Word 格式转换提示需要检查` : ''}。`,
|
|
9
|
+
failed: '导入未完成,请检查文件后重试。',
|
|
10
|
+
errors: {
|
|
11
|
+
'document-import-invalid': '文件路径或选择无效,请重新选择文件或文件夹。',
|
|
12
|
+
'document-import-limit': '文件或转换后的内容超过 1000 个文件、合计 32 MiB 的限制,请分批导入。',
|
|
13
|
+
'document-import-conversion': '文件未能转换,请检查 Markdown 编码或 Word 文件是否完整。',
|
|
14
|
+
'document-import-empty': '没有找到 .md、.markdown 或 .docx 文件。',
|
|
15
|
+
'document-import-unavailable': '请在多文档工作区中导入文件。',
|
|
16
|
+
'document-import-forbidden': '当前工作区不允许导入文件。',
|
|
17
|
+
'document-import-configuration': '工作区配置无效,请先修复配置。',
|
|
18
|
+
'document-import-changed': '工作区在导入期间发生变化,请刷新并检查导入结果。',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
en: {
|
|
22
|
+
title: 'Import Documents', files: 'Choose Files', folder: 'Choose Folder', submit: 'Import',
|
|
23
|
+
description: 'Import Markdown (.md, .markdown) and Word (.docx). Each file becomes a document, keeping its folder hierarchy. Level 1 and 2 headings start pages.',
|
|
24
|
+
images: 'For Markdown with local images or links between files, choose its folder. Word keeps headings, paragraphs, lists, tables, emphasis, links and embedded images.',
|
|
25
|
+
limits: 'Up to 1000 files and 32 MiB in total. Edit the imported documents in this workspace.',
|
|
26
|
+
selected: (count: number) => `${count} files selected`,
|
|
27
|
+
done: (count: number, unresolved: number, warnings: number) => `Imported ${count} documents${unresolved ? `; check ${unresolved} links or images` : ''}${warnings ? `; check ${warnings} Word conversion notices` : ''}.`,
|
|
28
|
+
failed: 'Import did not finish. Check the files and try again.',
|
|
29
|
+
errors: {
|
|
30
|
+
'document-import-invalid': 'Invalid file paths or selection. Choose the files or folder again.',
|
|
31
|
+
'document-import-limit': 'The files or converted content exceed 1000 files or 32 MiB. Import them in smaller batches.',
|
|
32
|
+
'document-import-conversion': 'Conversion failed. Check the Markdown encoding or whether the Word file is complete.',
|
|
33
|
+
'document-import-empty': 'No .md, .markdown or .docx files were found.',
|
|
34
|
+
'document-import-unavailable': 'Open a workspace with multiple documents to import files.',
|
|
35
|
+
'document-import-forbidden': 'This workspace does not allow importing files.',
|
|
36
|
+
'document-import-configuration': 'Fix the workspace configuration before importing.',
|
|
37
|
+
'document-import-changed': 'The workspace changed during import. Refresh and check the imported documents.',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { DocumentEditing } from './document-editing.ts'
|
|
2
|
+
export { DocumentProduction } from './document-production.ts'
|
|
1
3
|
export * from './components.tsx'
|
|
2
4
|
export { PmSchemaForm, schemaFormPropertyNames } from './schema-form/PmSchemaForm.tsx'
|
|
3
5
|
export type { PmSchemaFormProps } from './schema-form/PmSchemaForm.tsx'
|
|
@@ -14,8 +16,9 @@ export { findPlaceAtLine, findPlaceSource } from './places.ts'
|
|
|
14
16
|
export type { PlaceWithSource } from './places.ts'
|
|
15
17
|
export { connectPreview } from './preview.ts'
|
|
16
18
|
export type { PreviewConnection, PreviewHandlers } from './preview.ts'
|
|
17
|
-
export { documentDirFor, hasSlides,
|
|
18
|
-
export
|
|
19
|
+
export { documentDirFor, hasSlides, Workbench } from './workbench.ts'
|
|
20
|
+
export { isAgentChanging, selectedDocument } from './workbench-state.ts'
|
|
21
|
+
export type { AgentAnswer, AgentRequest, Pointer, PreviewSink, SaveState, WebView, WorkbenchMode, WorkbenchState } from './workbench-state.ts'
|
|
19
22
|
export { OperationLog } from './telemetry.ts'
|
|
20
23
|
export type { OperationBatch, OperationValue } from './telemetry.ts'
|
|
21
24
|
export { isObservedWorkspaceFailure, workspaceClient, WorkspaceServerError } from './workspace-client.ts'
|
|
@@ -26,11 +29,14 @@ export { HistoryPanel } from './panels/HistoryPanel.tsx'
|
|
|
26
29
|
export type { HistoryPanelProps, HistoryRevisionAction } from './panels/HistoryPanel.tsx'
|
|
27
30
|
export { HomePanel } from './panels/HomePanel.tsx'
|
|
28
31
|
export { WorkbenchApprovals } from './approvals.tsx'
|
|
29
|
-
export { assistantMascotAction, useAssistantMascot } from './assistant-mascot.ts'
|
|
30
|
-
export type { AssistantActivity } from './assistant-mascot.ts'
|
|
31
|
-
export { mascotEnabled, setMascotEnabled, useMascotEnabled } from './mascot-preference.ts'
|
|
32
32
|
export { PreviewPanel } from './panels/PreviewPanel.tsx'
|
|
33
33
|
export { SpeechSettingsPanel } from './panels/SpeechSettingsPanel.tsx'
|
|
34
34
|
export { SPEECH_SETTINGS_MESSAGES } from './speech-settings-messages.ts'
|
|
35
35
|
export { connectAuthoringClient } from './authoring-client.ts'
|
|
36
|
+
export { connectAuthoringWindow } from './authoring-window.ts'
|
|
37
|
+
export { connectAgentActivity } from './agent-activity.ts'
|
|
38
|
+
export { AgentActivityBar } from './AgentActivityBar.tsx'
|
|
36
39
|
export { SHORTCUTS } from './shortcuts.ts'
|
|
40
|
+
|
|
41
|
+
export { McpSettingsPanel } from './panels/McpSettingsPanel.tsx'
|
|
42
|
+
export { MCP_SETTINGS_MESSAGES } from './mcp-settings-messages.ts'
|
package/src/jobs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorMessage } from '@lincyaw/kernel'
|
|
2
2
|
import type { CompileJob, JobSource } from '@lincyaw/kernel'
|
|
3
|
-
import type { WorkbenchStore } from './workbench.ts'
|
|
3
|
+
import type { WorkbenchStore } from './workbench-state.ts'
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
5
|
|
|
6
6
|
/** Of two copies of a job (an event and an answer cross on the way), the one of the later change. */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const zh = {
|
|
2
|
+
title: 'MCP 连接', description: '让 AI 连接当前工作区,操作会实时显示在应用中。',
|
|
3
|
+
transport: '连接方式', stdio: 'stdio(推荐)', http: 'HTTP',
|
|
4
|
+
stdioHint: 'AI 客户端按需启动连接,无需预留端口。与桌面应用共享同一个工作区服务。',
|
|
5
|
+
httpHint: '为外部 AI 开启本机 HTTP 连接。更改端口不会改变编辑器地址。',
|
|
6
|
+
local: '这些配置用于运行 Presmium 的这台电脑。远程使用时,请在 AI 所在电脑安装 Presmium 后配置 stdio,或通过受保护的转发使用 HTTP。',
|
|
7
|
+
port: '端口', portHint: '填 0 自动分配可用端口;也可填写 1–65535 的固定端口。',
|
|
8
|
+
address: '当前连接地址', save: '应用', saved: '配置已应用。', loading: '正在加载连接配置…',
|
|
9
|
+
copyConfig: '复制配置', copyPrompt: '复制提示词', copied: '已复制。',
|
|
10
|
+
output: '复制内容', manualCopy: '无法自动复制,请从下面的文本框手动复制。',
|
|
11
|
+
unavailable: '暂时无法读取连接配置,请重试。', retry: '重试', failed: '配置未能应用,当前连接仍可使用。',
|
|
12
|
+
outdatedService: '当前工作区仍在使用旧版后台服务。请将 AI 中的 Presmium 连接更新为桌面应用提供的版本,重新连接后再打开工作区。',
|
|
13
|
+
portBusy: '该端口无法使用,请选择其他端口,或填 0 自动分配。',
|
|
14
|
+
conflict: '配置已在其他窗口更新,请重新读取后再修改。', invalid: '请输入 0–65535 的整数端口。',
|
|
15
|
+
noCommand: '当前服务没有可用的本机启动命令,请使用 HTTP 连接。',
|
|
16
|
+
applyFirst: '先应用修改,再复制与当前连接一致的配置。',
|
|
17
|
+
prompt: '请帮我为当前 AI 客户端配置 Presmium MCP。保留已有 MCP 服务,只新增或更新名为 presmium 的连接;先找到客户端的官方配置格式,将下面的通用 MCP 配置转换后写入,再验证连接和读取工作区。不要扩大操作权限,也不要提交凭据。工作区:{root}。',
|
|
18
|
+
httpPrompt: '使用 Streamable HTTP,地址:{url}。在运行 Presmium 的本机读取 {stateFile},仅使用其中 token 字段作为 Authorization: Bearer 的值,不要使用 launcherToken。不要把凭据输出到对话或提交到仓库。此地址需要 Presmium 工作区服务运行;服务重启后如端口或访问令牌变化,请重新读取配置。',
|
|
19
|
+
}
|
|
20
|
+
const en: typeof zh = {
|
|
21
|
+
title: 'MCP Connection', description: 'Connect AI to this workspace and see its actions live in the app.',
|
|
22
|
+
transport: 'Transport', stdio: 'stdio (recommended)', http: 'HTTP',
|
|
23
|
+
stdioHint: 'The AI client starts its connection on demand without reserving a port. It shares the workspace service with the desktop app.',
|
|
24
|
+
httpHint: 'Enable a local HTTP connection for external AI clients. Changing its port leaves the editor address unchanged.',
|
|
25
|
+
local: 'These settings are for the computer running Presmium. For remote use, install Presmium on the AI client computer for stdio, or use protected forwarding for HTTP.',
|
|
26
|
+
port: 'Port', portHint: 'Use 0 to choose an available port, or 1–65535 for a fixed port.',
|
|
27
|
+
address: 'Current endpoint', save: 'Apply', saved: 'Settings applied.', loading: 'Loading connection settings…',
|
|
28
|
+
copyConfig: 'Copy Config', copyPrompt: 'Copy Prompt', copied: 'Copied.',
|
|
29
|
+
output: 'Copy Content', manualCopy: 'Automatic copying failed. Copy the text below manually.',
|
|
30
|
+
unavailable: 'Connection settings are unavailable. Please retry.', retry: 'Retry', failed: 'Settings could not be applied. The current connection remains available.',
|
|
31
|
+
outdatedService: 'This workspace is still using an older background service. Update the Presmium connection in your AI client to the desktop app’s bundled version, reconnect, then reopen the workspace.',
|
|
32
|
+
portBusy: 'This port is unavailable. Choose another port or use 0 to assign one automatically.',
|
|
33
|
+
conflict: 'Another window updated these settings. Reload before editing.', invalid: 'Enter an integer port from 0 to 65535.',
|
|
34
|
+
noCommand: 'This service has no local launch command. Use HTTP instead.',
|
|
35
|
+
applyFirst: 'Apply your changes before copying the current connection configuration.',
|
|
36
|
+
prompt: 'Configure Presmium MCP for this AI client. Preserve existing MCP servers and only add or update the connection named presmium. Find the official client configuration format, adapt the generic MCP configuration below, save it, then verify the connection and read the workspace. Do not broaden permissions or save credentials in the repository. Workspace: {root}.',
|
|
37
|
+
httpPrompt: 'Use Streamable HTTP at {url}. On the computer running Presmium, read {stateFile} and use only its token field as Authorization: Bearer; never use launcherToken. Do not print credentials in the chat or save them in the repository. The Presmium workspace service must be running. If the port or token changes after a restart, read the settings again.',
|
|
38
|
+
}
|
|
39
|
+
export const MCP_SETTINGS_MESSAGES = { 'zh-CN': zh, en }
|
package/src/media-drafts.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { MediaClipDraft } from './MediaClipEditor.tsx'
|
|
|
4
4
|
import type { WorkspaceClient } from './workspace-client.ts'
|
|
5
5
|
|
|
6
6
|
export interface MediaDrafts { selectedClipId?: string, entries: Record<string, MediaClipDraft> }
|
|
7
|
-
interface Entry { value: MediaDrafts, failed: boolean, volatile: boolean, unreadable?: string }
|
|
7
|
+
interface Entry { value: MediaDrafts, failed: boolean, volatile: boolean, unreadable?: string, raw?: string | null }
|
|
8
8
|
const memory = new WeakMap<WorkspaceClient, Map<string, Entry>>()
|
|
9
9
|
const prefix = 'presmium.media-drafts.v1:', limit = 64
|
|
10
10
|
const keyOf = (identity: string, stepId: string) => prefix + JSON.stringify([identity, stepId])
|
|
@@ -38,6 +38,7 @@ function load(client: WorkspaceClient, key: string): Entry {
|
|
|
38
38
|
const entry: Entry = { value: { entries: {} }, failed: false, volatile: false }
|
|
39
39
|
try {
|
|
40
40
|
const raw = sessionStorage.getItem(key)
|
|
41
|
+
entry.raw = raw
|
|
41
42
|
if (raw !== null) {
|
|
42
43
|
entry.unreadable = raw
|
|
43
44
|
if (raw.length > 131072) throw new Error('media-drafts-size')
|
|
@@ -68,6 +69,7 @@ export function keepMediaDrafts(client: WorkspaceClient, identity: string, stepI
|
|
|
68
69
|
if (raw.length > 131072) throw new Error('media-drafts-size')
|
|
69
70
|
if (entry.unreadable !== undefined) sessionStorage.setItem(`${key}:unreadable`, entry.unreadable)
|
|
70
71
|
sessionStorage.setItem(key, raw)
|
|
72
|
+
entry.raw = raw
|
|
71
73
|
const keys = Array.from({ length: sessionStorage.length }, (_, index) => sessionStorage.key(index)!).filter(name => name.startsWith(prefix) && !name.endsWith(':unreadable') && name !== key)
|
|
72
74
|
let excess = keys.length - limit + 1
|
|
73
75
|
for (const old of keys) {
|
|
@@ -81,3 +83,43 @@ export function keepMediaDrafts(client: WorkspaceClient, identity: string, stepI
|
|
|
81
83
|
return true
|
|
82
84
|
} catch { entry.failed = true; trim(known); return false }
|
|
83
85
|
}
|
|
86
|
+
|
|
87
|
+
/** This is the same step/form bank used when the author reopens Media, including session-only input. */
|
|
88
|
+
export function mediaDraftSnapshot(client: WorkspaceClient, identity: string): { entries: { stepId: string, value: MediaDrafts, persisted: boolean }[], partial: boolean } {
|
|
89
|
+
const scoped = `${prefix}${JSON.stringify([identity]).slice(0, -1)},`
|
|
90
|
+
const keys = new Set([...store(client).keys()].filter(key => key.startsWith(scoped)))
|
|
91
|
+
let partial = false
|
|
92
|
+
try {
|
|
93
|
+
for (let index = 0; index < sessionStorage.length; index++) {
|
|
94
|
+
const key = sessionStorage.key(index)
|
|
95
|
+
if (key?.startsWith(scoped) && !key.endsWith(':unreadable')) keys.add(key)
|
|
96
|
+
}
|
|
97
|
+
} catch { partial = true }
|
|
98
|
+
const entries: { stepId: string, value: MediaDrafts, persisted: boolean }[] = []
|
|
99
|
+
for (const key of keys) {
|
|
100
|
+
let target: unknown
|
|
101
|
+
try { target = JSON.parse(key.slice(prefix.length)) } catch { partial = true; continue }
|
|
102
|
+
if (!Array.isArray(target) || target.length !== 2 || target[0] !== identity || typeof target[1] !== 'string') { partial = true; continue }
|
|
103
|
+
const entry = load(client, key)
|
|
104
|
+
let persisted = false
|
|
105
|
+
try { const raw = sessionStorage.getItem(key); persisted = !entry.failed && raw === entry.raw; if (raw !== entry.raw) partial = true } catch { partial = true }
|
|
106
|
+
if (entry.unreadable !== undefined || entry.raw === undefined) partial = true
|
|
107
|
+
if (Object.keys(entry.value.entries).length) entries.push({ stepId: target[1], value: structuredClone(entry.value), persisted })
|
|
108
|
+
}
|
|
109
|
+
return { entries, partial }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Retire one exact clip proposal, preserving sibling forms and any independently changed storage. */
|
|
113
|
+
export function discardMediaDraft(client: WorkspaceClient, identity: string, stepId: string, name: string, expected: MediaDrafts): boolean {
|
|
114
|
+
const key = keyOf(identity, stepId), entry = load(client, key)
|
|
115
|
+
if (!Object.hasOwn(expected.entries, name) || JSON.stringify(entry.value) !== JSON.stringify(expected)) return false
|
|
116
|
+
try {
|
|
117
|
+
if (entry.raw === undefined || entry.unreadable !== undefined || sessionStorage.getItem(key) !== entry.raw) return false
|
|
118
|
+
const next = structuredClone(entry.value)
|
|
119
|
+
delete next.entries[name]
|
|
120
|
+
const raw = JSON.stringify(next)
|
|
121
|
+
sessionStorage.setItem(key, raw)
|
|
122
|
+
entry.value = next; entry.raw = raw; entry.failed = false; entry.volatile = false
|
|
123
|
+
return true
|
|
124
|
+
} catch { entry.failed = true; return false }
|
|
125
|
+
}
|
package/src/messages.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface AgentPlace {
|
|
|
12
12
|
|
|
13
13
|
// A Latin word or a number set after Chinese text is spaced from it (docs/glossary.md 2).
|
|
14
14
|
const spaced = (text: string) => (/^[A-Za-z0-9]/.test(text) ? ` ${text}` : text)
|
|
15
|
+
// The start of a passage, enough to recognize it.
|
|
16
|
+
const excerpt = (text: string, length: number) => [...text].length > length ? `${[...text].slice(0, length).join('').trimEnd()}…` : text
|
|
17
|
+
|
|
18
|
+
/** Where on a page the author asks for new content: after a passage (its text, '' for content without text), at the start (none) or at the end. */
|
|
19
|
+
interface AgentInsertion { after?: string, end: boolean }
|
|
15
20
|
|
|
16
21
|
// Names of commands follow Microsoft Word's (撤消/Undo, 新建批注/New Comment, 版本历史/Version History…).
|
|
17
22
|
const zh = {
|
|
@@ -106,14 +111,13 @@ const zh = {
|
|
|
106
111
|
narrationAutosave: '自动保存;切换步骤会保留未完成的草稿。',
|
|
107
112
|
narrationDiscard: '放弃草稿',
|
|
108
113
|
narrationRecoveryUnavailable: '浏览器无法在本机保留草稿。草稿仍在本次会话中,请保存后再关闭窗口。',
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
documentDrafts: '本地草稿',
|
|
115
|
+
documentDraftName: (index: number) => `草稿 ${index}`,
|
|
116
|
+
documentDraftDiscardAll: '全部放弃',
|
|
112
117
|
documentDraftRestore: '恢复草稿',
|
|
113
|
-
documentDraftChanged: '
|
|
118
|
+
documentDraftChanged: '本地草稿已更新,请查看最新列表。',
|
|
114
119
|
documentDraftUnreadable: '部分本地草稿无法读取。',
|
|
115
120
|
documentDraftBackingUp: '正在备份…',
|
|
116
|
-
documentDraftOption: (index: number, date: string, source: 'durable' | 'rescue') => `${date} · ${source === 'rescue' ? '临时副本' : '草稿'} ${index}`,
|
|
117
121
|
narrationCompositionInterrupted: '输入法组字未完成,草稿已保留。请检查文字后保存或继续编辑。',
|
|
118
122
|
narrationRefresh: '讲稿已写入,但画面尚未完成更新。草稿已保留,请等待预览恢复后重试。',
|
|
119
123
|
narrationDuring: '与动画同步',
|
|
@@ -136,7 +140,10 @@ const zh = {
|
|
|
136
140
|
noMatch: '没有找到匹配的文稿。',
|
|
137
141
|
newDocument: '新建文稿',
|
|
138
142
|
noDocuments: '还没有文稿。点“新建文稿”开始。',
|
|
139
|
-
|
|
143
|
+
formatUpgrade: '这个工作区使用旧的文稿格式。升级后才能打开与编辑其中的文稿;每份文稿的升级都记入版本历史。',
|
|
144
|
+
upgrade: '升级',
|
|
145
|
+
upgraded: (count: number) => `已升级 ${count} 份文稿。`,
|
|
146
|
+
notGit: '工作区的版本历史未能准备好,暂时无法新建或修改文稿。请重新打开工作区;仍未恢复时请查看诊断。',
|
|
140
147
|
bundleDisabled: '无法加载文稿:Presmium 的扩展在“插件”页中被关闭了。请从“更多”打开“插件”,重新开启 Presmium,然后重新加载页面。',
|
|
141
148
|
more: (title: string) => `“${title}”的更多操作`,
|
|
142
149
|
open: '打开',
|
|
@@ -199,7 +206,6 @@ const zh = {
|
|
|
199
206
|
readDocument: '阅读与运行',
|
|
200
207
|
editDocument: '返回编辑',
|
|
201
208
|
readingFailed: '无法准备文稿阅读视图。请确认文稿已保存,并查看诊断后重试。',
|
|
202
|
-
video: '视频',
|
|
203
209
|
videoHint: '讲授视频的效果:幻灯片、配音、字幕与动画按时间播放,修改内容后随即更新',
|
|
204
210
|
videoFile: '视频文件',
|
|
205
211
|
noVideoFile: '尚未导出',
|
|
@@ -241,6 +247,8 @@ const zh = {
|
|
|
241
247
|
formattedEdit: '这一处带有格式或特殊内容,不能直接修改文字。要用 AI 改写吗?',
|
|
242
248
|
rewriteEdit: '用 AI 改写',
|
|
243
249
|
versionHistory: '版本历史',
|
|
250
|
+
historyWithDrafts: (count: number) => `版本历史(${count} 份本地草稿)`,
|
|
251
|
+
historySavedVersions: '已保存版本',
|
|
244
252
|
historyNewer: '较新版本',
|
|
245
253
|
historyOlder: '更早版本',
|
|
246
254
|
exportPane: '导出',
|
|
@@ -325,11 +333,11 @@ const zh = {
|
|
|
325
333
|
'history-result-no-longer-current': '之前的结果已不是当前版本,请查看最新的历史。',
|
|
326
334
|
'authoring-review-required': '有修改等待你审阅,请先接受或放弃。',
|
|
327
335
|
} as Record<string, string>,
|
|
328
|
-
agentWorking: 'AI 正在修改文稿…',
|
|
329
336
|
agentWaiting: (n: number) => `AI 修改了 ${n} 处内容,要接受这些修改吗?`,
|
|
330
337
|
accept: '接受',
|
|
331
338
|
reject: '拒绝',
|
|
332
|
-
problems: (n: number) =>
|
|
339
|
+
problems: (n: number) => `文稿有 ${n} 个问题需要处理。`,
|
|
340
|
+
problemsTitle: '文稿中的问题',
|
|
333
341
|
fixWithAi: '用 AI 修复',
|
|
334
342
|
fixing: '正在发送给 AI…',
|
|
335
343
|
fixFailed: (reason: string) => `无法发送给 AI。${reason}`,
|
|
@@ -356,6 +364,11 @@ const zh = {
|
|
|
356
364
|
place.quote ? `\n原文:“${place.quote}”` : '',
|
|
357
365
|
].join('')).filter(Boolean),
|
|
358
366
|
].join('\n\n'),
|
|
367
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
368
|
+
const at = `第 ${page} 页${title ? `“${title}”` : ''}`
|
|
369
|
+
return place.end ? `在${at}的末尾加一个动画:` : place.after === undefined ? `在${at}的开头加一个动画:`
|
|
370
|
+
: place.after ? `在${at}中“${excerpt(place.after, 16)}”这一段之后加一个动画:` : `在${at}的这个位置加一个动画:`
|
|
371
|
+
},
|
|
359
372
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
360
373
|
comments.length === 1 ? '我在文稿上写了一条批注:' : `我在文稿上写了 ${comments.length} 条批注:`,
|
|
361
374
|
...comments.map((comment, i) => [
|
|
@@ -470,14 +483,13 @@ const en: WorkbenchMessages = {
|
|
|
470
483
|
narrationAutosave: 'Saved automatically. Switching steps keeps unfinished drafts.',
|
|
471
484
|
narrationDiscard: 'Discard Draft',
|
|
472
485
|
narrationRecoveryUnavailable: 'This browser can’t keep drafts on this device. Your draft stays in this session; save before closing the window.',
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
486
|
+
documentDrafts: 'Local Drafts',
|
|
487
|
+
documentDraftName: (index: number) => `Draft ${index}`,
|
|
488
|
+
documentDraftDiscardAll: 'Discard All',
|
|
476
489
|
documentDraftRestore: 'Recover Draft',
|
|
477
|
-
documentDraftChanged: '
|
|
490
|
+
documentDraftChanged: 'Drafts on this device changed. Check the updated list.',
|
|
478
491
|
documentDraftUnreadable: 'Couldn’t read some drafts on this device.',
|
|
479
492
|
documentDraftBackingUp: 'Backing up…',
|
|
480
|
-
documentDraftOption: (index: number, date: string, source: 'durable' | 'rescue') => `${date} · ${source === 'rescue' ? 'Temporary copy' : 'Draft'} ${index}`,
|
|
481
493
|
narrationCompositionInterrupted: 'Typing with the input method was interrupted. Your draft is kept; review it before saving, or keep editing.',
|
|
482
494
|
narrationRefresh: 'The script was written, but the preview has not updated yet. Your draft is kept; retry after the preview recovers.',
|
|
483
495
|
narrationDuring: 'During animation',
|
|
@@ -500,7 +512,10 @@ const en: WorkbenchMessages = {
|
|
|
500
512
|
noMatch: 'No matching documents.',
|
|
501
513
|
newDocument: 'New Document',
|
|
502
514
|
noDocuments: 'No documents yet. Choose New Document to start.',
|
|
503
|
-
|
|
515
|
+
formatUpgrade: 'This workspace uses an older document format. Upgrade it to open and edit its documents; each document’s upgrade is recorded in its history.',
|
|
516
|
+
upgrade: 'Upgrade',
|
|
517
|
+
upgraded: (count: number) => `Upgraded ${count} ${count === 1 ? 'document' : 'documents'}.`,
|
|
518
|
+
notGit: 'Workspace history could not be prepared, so documents cannot be created or edited yet. Reopen the workspace; if this continues, check Diagnostics.',
|
|
504
519
|
bundleDisabled: 'Couldn’t load the documents: the Presmium extension was turned off on the Plugins page. Open Plugins from More, turn Presmium on again, then reload the page.',
|
|
505
520
|
more: (title: string) => `More Actions for “${title}”`,
|
|
506
521
|
open: 'Open',
|
|
@@ -563,7 +578,6 @@ const en: WorkbenchMessages = {
|
|
|
563
578
|
readDocument: 'Read and Run',
|
|
564
579
|
editDocument: 'Back to Editing',
|
|
565
580
|
readingFailed: 'Couldn’t prepare the document reading view. Confirm the document is saved, check the diagnostics, then try again.',
|
|
566
|
-
video: 'Video',
|
|
567
581
|
videoHint: 'The lecture video as it will look: the slides, voiceover, captions, and animations on its timeline, updated as you edit',
|
|
568
582
|
videoFile: 'Video file',
|
|
569
583
|
noVideoFile: 'Not exported yet',
|
|
@@ -605,6 +619,8 @@ const en: WorkbenchMessages = {
|
|
|
605
619
|
formattedEdit: 'This text has formatting or special content and can’t be edited directly. Rewrite it with AI?',
|
|
606
620
|
rewriteEdit: 'Rewrite with AI',
|
|
607
621
|
versionHistory: 'Version History',
|
|
622
|
+
historyWithDrafts: (count: number) => `Version History (${count} local ${count === 1 ? 'draft' : 'drafts'})`,
|
|
623
|
+
historySavedVersions: 'Saved Versions',
|
|
608
624
|
historyNewer: 'Newer versions',
|
|
609
625
|
historyOlder: 'Older versions',
|
|
610
626
|
exportPane: 'Export',
|
|
@@ -689,11 +705,11 @@ const en: WorkbenchMessages = {
|
|
|
689
705
|
'history-result-no-longer-current': 'The earlier result is no longer the current version. Review the latest history.',
|
|
690
706
|
'authoring-review-required': 'Changes are waiting for your review. Accept or discard them first.',
|
|
691
707
|
},
|
|
692
|
-
agentWorking: 'The AI is editing the document…',
|
|
693
708
|
agentWaiting: (n: number) => `The AI changed ${n} file${n === 1 ? '' : 's'}. Accept the changes?`,
|
|
694
709
|
accept: 'Accept',
|
|
695
710
|
reject: 'Reject',
|
|
696
|
-
problems: (n: number) =>
|
|
711
|
+
problems: (n: number) => `The document has ${n} problem${n === 1 ? '' : 's'} to fix.`,
|
|
712
|
+
problemsTitle: 'Problems in the Document',
|
|
697
713
|
fixWithAi: 'Fix with AI',
|
|
698
714
|
fixing: 'Sending to the AI…',
|
|
699
715
|
fixFailed: (reason: string) => `Couldn’t send to the AI. ${reason}`,
|
|
@@ -720,6 +736,11 @@ const en: WorkbenchMessages = {
|
|
|
720
736
|
place.quote ? `\nText: “${place.quote}”` : '',
|
|
721
737
|
].join('')).filter(Boolean),
|
|
722
738
|
].join('\n\n'),
|
|
739
|
+
animationRequest: (page: number, title: string, place: AgentInsertion) => {
|
|
740
|
+
const at = `page ${page}${title ? `, “${title}”` : ''}`
|
|
741
|
+
return place.end ? `Add an animation at the end of ${at}: ` : place.after === undefined ? `Add an animation at the start of ${at}: `
|
|
742
|
+
: place.after ? `Add an animation on ${at}, after the paragraph “${excerpt(place.after, 40)}”: ` : `Add an animation at this point on ${at}: `
|
|
743
|
+
},
|
|
723
744
|
commentsRequest: (comments: (AgentPlace & { text: string })[]) => [
|
|
724
745
|
comments.length === 1 ? 'I left a comment on the document:' : `I left ${comments.length} comments on the document:`,
|
|
725
746
|
...comments.map((comment, i) => [
|
package/src/outline.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IRDocument, MdastNode,
|
|
1
|
+
import type { IRDocument, MdastNode, PresmiumDocument } from '@lincyaw/kernel'
|
|
2
2
|
|
|
3
3
|
/** A section as the navigation pane lists it: in the slides each section is one slide, numbered from 1. */
|
|
4
4
|
export interface OutlineItem {
|
|
@@ -8,7 +8,7 @@ export interface OutlineItem {
|
|
|
8
8
|
number: number
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function documentOutline(doc: IRDocument |
|
|
11
|
+
export function documentOutline(doc: IRDocument | PresmiumDocument | undefined): OutlineItem[] {
|
|
12
12
|
if (doc && 'schemaVersion' in doc) return doc.sectionOrder.map((id, index) => ({ id, title: doc.sections[id]!.title, depth: doc.sections[id]!.level ?? 1, number: index + 1 }))
|
|
13
13
|
return (doc?.sections ?? []).map((section, i) => ({ id: section.id, title: section.title, depth: section.depth, number: i + 1 }))
|
|
14
14
|
}
|
|
@@ -18,7 +18,7 @@ export class DocumentOutline {
|
|
|
18
18
|
#identity?: string
|
|
19
19
|
#items: readonly OutlineItem[] = []
|
|
20
20
|
|
|
21
|
-
read(document:
|
|
21
|
+
read(document: PresmiumDocument | undefined, identity = document?.id): readonly OutlineItem[] {
|
|
22
22
|
const items = documentOutline(document)
|
|
23
23
|
if (identity !== this.#identity || items.length !== this.#items.length || items.some((item, index) => {
|
|
24
24
|
const previous = this.#items[index]!
|
|
@@ -55,7 +55,7 @@ function richTextParts(value: unknown, parts: string[] = []): string[] {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** Counts authored titles and rich text; code, components and separate narration are excluded. */
|
|
58
|
-
export function countWords(doc: IRDocument |
|
|
58
|
+
export function countWords(doc: IRDocument | PresmiumDocument | undefined): number {
|
|
59
59
|
if (doc && 'schemaVersion' in doc) {
|
|
60
60
|
return doc.sectionOrder.reduce((sum, id) => sum + countText(doc.sections[id]!.title), 0) + Object.values(doc.blocks).reduce((sum, block) => sum + (block.type === 'text' ? richTextParts(block.content).reduce((sum, text) => sum + countText(text), 0) : 0), 0)
|
|
61
61
|
}
|
|
@@ -72,7 +72,7 @@ export class DocumentWordCounter {
|
|
|
72
72
|
#identity?: string
|
|
73
73
|
readonly #counts = new Map<string, { signature: string, words: number }>()
|
|
74
74
|
|
|
75
|
-
count(doc:
|
|
75
|
+
count(doc: PresmiumDocument | undefined, identity = doc?.id): number {
|
|
76
76
|
if (identity !== this.#identity || !doc) { this.#counts.clear(); this.#identity = identity }
|
|
77
77
|
if (!doc) return 0
|
|
78
78
|
const unused = new Set(this.#counts.keys())
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { DOCUMENT_IMPORT_MAX_BYTES, DOCUMENT_IMPORT_MAX_FILES } from '@lincyaw/kernel'
|
|
3
|
+
import type { DocumentImportAnswer } from '@lincyaw/kernel'
|
|
4
|
+
import { PmButton, PmDialog, PmNotice } from '../components.tsx'
|
|
5
|
+
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
|
+
import { IMPORT_MESSAGES } from '../import-messages.ts'
|
|
7
|
+
import { WorkspaceServerError } from '../workspace-client.ts'
|
|
8
|
+
|
|
9
|
+
/** File objects stay local to the dialog until the author submits one import. */
|
|
10
|
+
export function DocumentImportDialog({ onClose, onImported }: { onClose(): void, onImported(answer: DocumentImportAnswer): void }) {
|
|
11
|
+
const t = useMessages()
|
|
12
|
+
const m = IMPORT_MESSAGES[useWorkbenchState(state => state.locale)]
|
|
13
|
+
const workbench = useWorkbench()
|
|
14
|
+
const [files, setFiles] = useState<File[]>([])
|
|
15
|
+
const [working, setWorking] = useState(false)
|
|
16
|
+
const [failure, setFailure] = useState<string>()
|
|
17
|
+
const input = useRef<HTMLInputElement>(null), directory = useRef<HTMLInputElement | null>(null)
|
|
18
|
+
const controller = useRef<AbortController>()
|
|
19
|
+
useEffect(() => () => controller.current?.abort(), [])
|
|
20
|
+
const select = (list: FileList | null) => {
|
|
21
|
+
const selected = [...list ?? []].filter(file => !(file.webkitRelativePath || file.name).split('/').some(part => ['.git', '.presmium', 'node_modules', 'dist'].includes(part)))
|
|
22
|
+
if (selected.length > DOCUMENT_IMPORT_MAX_FILES || selected.reduce((sum, file) => sum + file.size, 0) > DOCUMENT_IMPORT_MAX_BYTES) {
|
|
23
|
+
setFailure(m.errors['document-import-limit']); setFiles([])
|
|
24
|
+
} else { setFiles(selected); setFailure(undefined) }
|
|
25
|
+
}
|
|
26
|
+
const submit = async () => {
|
|
27
|
+
if (working || !files.length) return
|
|
28
|
+
const pending = controller.current = new AbortController()
|
|
29
|
+
setWorking(true); setFailure(undefined)
|
|
30
|
+
try {
|
|
31
|
+
const answer = await workbench.importDocuments(files, pending.signal)
|
|
32
|
+
onImported(answer)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!pending.signal.aborted) {
|
|
35
|
+
const code = error instanceof WorkspaceServerError ? error.answer.error : error instanceof Error ? error.message : undefined
|
|
36
|
+
setFailure(code ? (m.errors as Record<string, string>)[code] ?? m.failed : m.failed)
|
|
37
|
+
}
|
|
38
|
+
} finally { if (!pending.signal.aborted) setWorking(false) }
|
|
39
|
+
}
|
|
40
|
+
return (
|
|
41
|
+
<PmDialog open label={m.title} closeLabel={t.close} name="pmw-operation" busy={working} onClose={onClose}>
|
|
42
|
+
<form className="pmw-operation" onSubmit={event => { event.preventDefault(); void submit() }}>
|
|
43
|
+
<p>{m.description}</p><p className="pmw-muted">{m.images}</p><p className="pmw-muted">{m.limits}</p>
|
|
44
|
+
<input ref={input} type="file" multiple hidden accept=".md,.markdown,.docx,image/*" onChange={event => { select(event.currentTarget.files); event.currentTarget.value = '' }} />
|
|
45
|
+
<input ref={element => { directory.current = element; element?.setAttribute('webkitdirectory', '') }} type="file" multiple hidden onChange={event => { select(event.currentTarget.files); event.currentTarget.value = '' }} />
|
|
46
|
+
<div className="pmw-operation__actions">
|
|
47
|
+
<PmButton icon="upload" disabled={working} onClick={() => input.current?.click()}>{m.files}</PmButton>
|
|
48
|
+
<PmButton icon="folder" disabled={working} onClick={() => directory.current?.click()}>{m.folder}</PmButton>
|
|
49
|
+
</div>
|
|
50
|
+
{files.length > 0 && <p>{m.selected(files.length)}</p>}
|
|
51
|
+
{failure && <PmNotice tone="danger">{failure}</PmNotice>}
|
|
52
|
+
<div className="pmw-operation__actions">
|
|
53
|
+
<PmButton disabled={working} onClick={onClose}>{t.cancel}</PmButton>
|
|
54
|
+
<PmButton type="submit" variant="primary" loading={working} disabled={!files.length}>{m.submit}</PmButton>
|
|
55
|
+
</div>
|
|
56
|
+
</form>
|
|
57
|
+
</PmDialog>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useId } from 'react'
|
|
2
|
-
import { PmEmpty, PmIconButton } from '../components.tsx'
|
|
2
|
+
import { PmEmpty, PmIconButton, PmPanelHeader } from '../components.tsx'
|
|
3
3
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
4
4
|
import { DocumentStepNarration } from '../document-editor/DocumentStepNarration.tsx'
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ export function DocumentNarrationPanel({ onClose }: { onClose(): void }) {
|
|
|
18
18
|
}
|
|
19
19
|
useEffect(() => { pause() }, [workbench, source?.identity])
|
|
20
20
|
return <section className="pmw-pane" aria-labelledby={panelId}>
|
|
21
|
-
<
|
|
21
|
+
<PmPanelHeader className="pmw-pane__header" titleId={panelId} title={t.documentNarration} actions={<PmIconButton small icon="close" label={t.close} onClick={onClose} />} />
|
|
22
22
|
{section && sectionId && stepId ? <>
|
|
23
23
|
<p className="pmw-pane__footer">{section.title}</p>
|
|
24
24
|
<DocumentStepNarration sectionId={sectionId} stepId={stepId} expanded showLabel={false} panelId={`${panelId}-fields`} onPause={pause} />
|