@lincyaw/workbench 0.2.0-rc.3 → 0.2.0-rc.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/package.json +5 -4
  2. package/src/MediaClipEditor.tsx +1 -1
  3. package/src/authoring-client.ts +3 -3
  4. package/src/authoring-draft-fragment.ts +3 -1
  5. package/src/component-property-drafts.ts +5 -5
  6. package/src/components.tsx +10 -28
  7. package/src/document-drafts.ts +6 -7
  8. package/src/document-editor/BlockNoteSurface.tsx +25 -9
  9. package/src/document-editor/ComponentMaterials.tsx +3 -9
  10. package/src/document-editor/ComponentPropertiesDialog.tsx +3 -3
  11. package/src/document-editor/DocumentBlockPreview.tsx +2 -0
  12. package/src/document-editor/DocumentComments.tsx +58 -9
  13. package/src/document-editor/DocumentEditor.tsx +44 -7
  14. package/src/document-editor/DocumentStepNarration.tsx +2 -1
  15. package/src/document-editor/NewCommentDrafts.tsx +4 -3
  16. package/src/document-editor/PlaceComment.tsx +150 -0
  17. package/src/document-editor/comment-drafts.ts +16 -14
  18. package/src/document-editor/comments.ts +30 -10
  19. package/src/document-editor/component-label.ts +11 -0
  20. package/src/document-editor/file-input.ts +2 -2
  21. package/src/document-editor/insertion-place.ts +60 -0
  22. package/src/document-editor/messages.ts +3 -3
  23. package/src/document-editor/narration-schema.tsx +3 -2
  24. package/src/document-editor/page-body.ts +60 -0
  25. package/src/document-editor/projection.ts +2 -2
  26. package/src/document-editor/rich-text.ts +3 -2
  27. package/src/document-editor/selection.ts +13 -0
  28. package/src/document-editor/style.css +12 -1
  29. package/src/document-editor/table-identities.ts +2 -1
  30. package/src/document-session.ts +50 -16
  31. package/src/history.ts +2 -2
  32. package/src/index.ts +0 -3
  33. package/src/messages.ts +19 -4
  34. package/src/panels/DocumentView.tsx +10 -10
  35. package/src/panels/ExportPanel.tsx +1 -6
  36. package/src/panels/PreviewPanel.tsx +1 -4
  37. package/src/panels/ProductionCaptionSize.tsx +20 -0
  38. package/src/panels/ProductionCaptionTiming.tsx +3 -3
  39. package/src/panels/ProductionMediaClips.tsx +2 -1
  40. package/src/panels/ProductionPanel.tsx +5 -1
  41. package/src/panels/ProductionRecordingRange.tsx +2 -2
  42. package/src/panels/ProductionTimeline.tsx +6 -1
  43. package/src/panels/ProductionTranscription.tsx +2 -1
  44. package/src/panels/SourceDocumentPanel.tsx +3 -6
  45. package/src/panels/TranscriptionAdoption.tsx +4 -4
  46. package/src/places.ts +1 -36
  47. package/src/production-messages.ts +6 -0
  48. package/src/sha256.ts +9 -0
  49. package/src/styles.css +16 -41
  50. package/src/workbench.ts +80 -33
  51. package/src/workspace-client.ts +2 -1
  52. package/src/assistant-mascot.ts +0 -62
  53. package/src/mascot-preference.ts +0 -37
  54. package/src/panels/ChangeTrail.tsx +0 -79
@@ -0,0 +1,20 @@
1
+ import { useState } from 'react'
2
+ import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
3
+ import type { TeachingDocument } from '@lincyaw/kernel'
4
+ import { PmField, PmRange } from '../components.tsx'
5
+ import { useWorkbench, useWorkbenchState } from '../context.tsx'
6
+ import { PRODUCTION_MESSAGES } from '../production-messages.ts'
7
+
8
+ /** The document's caption size in percent steps of ten; a released drag or a key records it once. */
9
+ export function ProductionCaptionSize({ identity, document, disabled, onChanged }: { identity: string, document: TeachingDocument, disabled: boolean, onChanged(): void }) {
10
+ const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
11
+ const [preview, setPreview] = useState<number>()
12
+ const percent = Math.round(captionScale(document.production) * 100)
13
+ return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
14
+ <div className="pm-ui-range-row">
15
+ <PmRange label={p.captionSize} value={percent} min={Math.round(CAPTION_SCALE_MIN * 100)} max={Math.round(CAPTION_SCALE_MAX * 100)} step={10} disabled={disabled} valueText={value => `${Math.round(value)}%`}
16
+ onPreviewChange={setPreview} onValueCommit={value => { workbench.setDocumentCaptionScale(value / 100, identity); onChanged() }} />
17
+ <output>{Math.round(preview ?? percent)}%</output>
18
+ </div>
19
+ </PmField>
20
+ }
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
- import { CAPTION_TIMING_MAX_SEGMENTS, captionSourceFingerprint, captionTimingProblem, stepCaptionText } from '@lincyaw/kernel'
2
+ import { CAPTION_TIMING_MAX_SEGMENTS, captionSourceFingerprint, captionTimingProblem, randomUUID, stepCaptionText } from '@lincyaw/kernel'
3
3
  import type { CaptionTiming, CaptionTimingSource, DocumentCaptionTimingAction, ProductionPlan } from '@lincyaw/kernel'
4
4
  import { PmButton, PmCard, PmDialog, PmInput, PmNotice } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
@@ -23,7 +23,7 @@ function lineRows(text: string): Row[] {
23
23
  else if (ranges.length && !text.slice(ranges.at(-1)!.from, ranges.at(-1)!.to).trim()) ranges[ranges.length - 1]!.to = to
24
24
  else ranges.push({ from, to })
25
25
  }
26
- return ranges.map(range => ({ ...range, id: crypto.randomUUID(), start: '', end: '' }))
26
+ return ranges.map(range => ({ ...range, id: randomUUID(), start: '', end: '' }))
27
27
  }
28
28
  function valueOf(draft: Draft): CaptionTiming | undefined {
29
29
  if (!draft.basis.available || !draft.basis.playbackFingerprint || draft.basis.durationMs === undefined) return
@@ -72,7 +72,7 @@ export function ProductionCaptionTiming({ identity, stepId, plan, current, loadi
72
72
  const action: DocumentCaptionTimingAction = automatic ? { type: 'caption.timing.reset', stepId } : { type: 'caption.timing.set', stepId, value: value! }
73
73
  request.current = controller; setBusy(true); setFailure(undefined)
74
74
  try {
75
- const answer = await workbench.applyDocumentCaptionTiming(action, crypto.randomUUID(), expected, controller.signal)
75
+ const answer = await workbench.applyDocumentCaptionTiming(action, randomUUID(), expected, controller.signal)
76
76
  needsRefresh.current = true
77
77
  if (!alive.current || workbench.getState().authoring?.identity !== identity) return
78
78
  const ownsInput = drafts.current.get(target) === sent
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
2
  import type { DocumentChangeAnswer, MediaClip, ProductionAssetInspection, ProductionBinding, TeachingDocument } from '@lincyaw/kernel'
3
+ import { randomUUID } from '@lincyaw/kernel'
3
4
  import { MediaClipEditor } from '../MediaClipEditor.tsx'
4
5
  import type { MediaClipDraft } from '../MediaClipEditor.tsx'
5
6
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
@@ -18,7 +19,7 @@ interface Props {
18
19
  disabled: boolean
19
20
  onChanged(): void
20
21
  }
21
- const newDraft = (version: string, stepId: string): MediaClipDraft => ({ version, clip: { id: `clip_${crypto.randomUUID().replaceAll('-', '')}`, assetId: '', sourceRange: { startMs: 0, endMs: 0 }, attachment: { stepId, offsetMs: 0 }, volume: 1, muted: false } })
22
+ const newDraft = (version: string, stepId: string): MediaClipDraft => ({ version, clip: { id: `clip_${randomUUID().replaceAll('-', '')}`, assetId: '', sourceRange: { startMs: 0, endMs: 0 }, attachment: { stepId, offsetMs: 0 }, volume: 1, muted: false } })
22
23
  const fromClip = (version: string, clip: MediaClip): MediaClipDraft => ({ version, clip: structuredClone(clip), baseClip: structuredClone(clip) })
23
24
  const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
24
25
  const draftKey = (clipId?: string) => clipId === undefined ? 'new' : `clip:${clipId}`
@@ -12,6 +12,7 @@ import { DocumentVoiceField } from './DocumentVoiceField.tsx'
12
12
  import { ExportPanel } from './ExportPanel.tsx'
13
13
  import { PreviewPanel } from './PreviewPanel.tsx'
14
14
  import { VoiceoverDialog } from './VoiceoverDialog.tsx'
15
+ import { ProductionCaptionSize } from './ProductionCaptionSize.tsx'
15
16
  import { ProductionCaptionTiming } from './ProductionCaptionTiming.tsx'
16
17
  import { ProductionTimeline } from './ProductionTimeline.tsx'
17
18
  import { ProductionMediaClips } from './ProductionMediaClips.tsx'
@@ -254,7 +255,10 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
254
255
  selectedAsset={transcriptionAsset?.identity === source.identity ? transcriptionAsset : undefined}
255
256
  onSelectAsset={() => { transcriptionSelection.current++; setTranscriptionAsset(undefined) }} />
256
257
  </div></PmTabPanel>
257
- <PmTabPanel value="captions" keepMounted><ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} /></PmTabPanel>
258
+ <PmTabPanel value="captions" keepMounted><div className="pmw-production__fields">
259
+ <ProductionCaptionSize identity={source.identity} document={document} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
260
+ <ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
261
+ </div></PmTabPanel>
258
262
  </PmTabs>
259
263
  </PmSplitPanel>
260
264
  </PmSplitGroup>
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useId, useRef, useState } from 'react'
2
- import { recordingSourceRange } from '@lincyaw/kernel'
2
+ import { randomUUID, recordingSourceRange } from '@lincyaw/kernel'
3
3
  import type { DocumentRecordingAdoption, ProductionAssetInspection, TimeRange, VoiceSource } from '@lincyaw/kernel'
4
4
  import { PmButton, PmInput, PmNotice } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
@@ -81,7 +81,7 @@ export function ProductionRecordingRange({ identity, sectionId, stepId, active,
81
81
  const controller = new AbortController(), proposed = { startMs: start!, endMs: end! }
82
82
  const previous = sent.current?.request
83
83
  const change: DocumentRecordingAdoption = previous && previous.source.version === source.version && previous.stepId === stepId && previous.assetId === voice.assetId && previous.sha256 === inspected.sha256 && same(previous.sourceRange, proposed)
84
- ? previous : { id: crypto.randomUUID(), source: { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, stepId, assetId: voice.assetId, sha256: inspected.sha256, sourceRange: proposed }
84
+ ? previous : { id: randomUUID(), source: { documentId: source.content.id, version: source.version, fingerprint: source.fingerprint }, stepId, assetId: voice.assetId, sha256: inspected.sha256, sourceRange: proposed }
85
85
  const stored = drafts.current.get(key) ?? draft
86
86
  drafts.current.set(key, stored); sent.current = { key, draft: stored, request: change }; request.current = controller
87
87
  setBusy(true); setFailure(undefined)
@@ -36,6 +36,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
36
36
  }, [workbench, directory, plan, sectionId, active, current])
37
37
  const document = source?.content, section = document?.sections[sectionId]
38
38
  const page = current ? plan?.pages.find(page => page.sectionId === sectionId) : undefined
39
+ // The current plan lists every page of the lecture; a page of the document it lacks is left out of the lecture.
40
+ const excluded = Boolean(current && plan && section && !page)
41
+ // On a page of the lecture, a step it leaves out is missing from the page's steps.
42
+ const stepLeftOut = Boolean(page && !page.steps.some(step => step.stepId === stepId))
39
43
  const start = page?.startMs, end = page?.endMs, duration = start !== undefined && end !== undefined ? Math.max(0, end - start) : undefined
40
44
  const position = plan && current && playback && sameProductionBinding(playback.binding, plan.binding) && playback.position?.sectionId === sectionId && start !== undefined ? Math.max(0, playback.position.timeMs - start) : undefined
41
45
  const tracks: TimelineTrack[] = page && plan ? plan.tracks.map(track => ({ id: track.kind, label: p.tracks[track.kind], segments: track.segments.filter(segment => segment.sectionId === sectionId).map(segment => {
@@ -49,9 +53,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
49
53
  statusLabel: [status, track.kind === 'caption' && p.alignmentStatus[segment.alignment ?? 'none'], segment.audio && (wave === false ? p.waveformUnavailable : wave === undefined ? p.waveformLoading : undefined)].filter(Boolean).join(' · '),
50
54
  waveform: wave ? wave.peaks : undefined,
51
55
  }
52
- }) })) : [{ id: 'visual', label: p.tracks.visual, segments: section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
56
+ }) })) : [{ id: 'visual', label: p.tracks.visual, segments: excluded ? [] : section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
53
57
  const captionChoices = current ? plan?.tracks.find(track => track.kind === 'caption')?.segments.filter(segment => segment.stepId === stepId && (segment.alignment === 'words' || segment.alignment === 'manual') && segment.timing === 'confirmed').map(segment => segment.id) ?? [] : []
54
58
  return <PmTimeline variant="editor" label={p.timeline} tracks={tracks} labels={p.timelineLabels} durationMs={duration} durationStatus={page?.timing ?? 'unknown'} currentTimeMs={position} selectedStepId={stepId} showSteps={false}
59
+ excluded={excluded ? { status: p.notInLecture, notice: p.notInLectureHint } : undefined} notice={stepLeftOut ? p.notInLectureStep : undefined}
55
60
  segmentPicker={{ track: 'caption', ids: captionChoices, label: p.captionSegment, placeholder: p.chooseCaptionSegment }}
56
61
  zoom={zoom} onZoomChange={setZoom} disabled={disabled} loading={loading} seeking={seeking} seekDisabled={!seekEnabled || start === undefined}
57
62
  onSelectStep={onSelectStep} onSelectSegment={(track, selected) => {
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
2
2
  import type { DocumentTranscriptionRequest, TeachingDocument, TranscriptionCapabilities, TranscriptionListAnswer, TranscriptionRevision, TranscriptionTask } from '@lincyaw/kernel'
3
+ import { randomUUID } from '@lincyaw/kernel'
3
4
  import { PmBadge, PmButton, PmCard, PmDialog, PmField, PmIconButton, PmNotice, PmSelect } from '../components.tsx'
4
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
5
6
  import { documentTranscriptionSession } from '../transcription-session.ts'
@@ -94,7 +95,7 @@ export function ProductionTranscription({ identity, directory, document, section
94
95
  try {
95
96
  const expected = { identity, version: now.version }, audio = await workbench.inspectDocumentAudio(assetId, expected, controller.signal)
96
97
  if (!current() || controller.signal.aborted) return
97
- const request: DocumentTranscriptionRequest = { intent: `transcription_${crypto.randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: now.content.metadata.lang, confirmed: true }
98
+ const request: DocumentTranscriptionRequest = { intent: `transcription_${randomUUID()}`, source: { documentId: now.content.id, version: now.version, fingerprint: now.fingerprint }, assetId, audioSha256: audio.inspection.sha256, engine, lang: now.content.metadata.lang, confirmed: true }
98
99
  await session.start(request, () => workbench.startDocumentTranscription(request, expected))
99
100
  } catch (error) { if (current() && !controller.signal.aborted) setFailure(transcriptionFailure(error, locale)) }
100
101
  finally { if (inspectionRequest.current === controller) { inspectionRequest.current = undefined; if (current()) setInspecting(false) } }
@@ -10,10 +10,9 @@ import { nativeEditingCursor } from '../document-editor/selection.ts'
10
10
  import { hasBlockPreview } from '../document-editor/projection.ts'
11
11
  import type { NativeDocumentEditor } from '../document-editor/schema.tsx'
12
12
  import { isAgentChanging } from '../workbench.ts'
13
- import { EditorChangeTrail } from './ChangeTrail.tsx'
14
13
 
15
14
  /** Source editing is available before the first successful runtime compilation. */
16
- export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void }) {
15
+ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
17
16
  const workbench = useWorkbench(), t = useMessages()
18
17
  const source = useWorkbenchState(state => state.authoring)
19
18
  const sourceAcknowledged = () => {
@@ -26,7 +25,6 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
26
25
  const navigation = useWorkbenchState(state => state.documentNavigation)
27
26
  const readOnly = useWorkbenchState(state => state.mode !== 'editing' || workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.member && !hasRole(state.authoring.member, 'editor')) || Boolean(state.authoring?.loading) || isAgentChanging(state))
28
27
  const container = useRef<HTMLElement>(null)
29
- const sheet = useRef<HTMLDivElement>(null)
30
28
  const consumedNavigation = useRef<string>()
31
29
  const bodyEditor = useRef<NativeDocumentEditor>()
32
30
  const editingPosition = useRef<{ nativeBlockId: string, sectionId: string, position: number, editor: NativeDocumentEditor, identity: string, reset: number | undefined }>()
@@ -176,9 +174,8 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
176
174
  {source?.issues.length ? <div className="pmw-source-document__diagnostics"><PmNotice tone="warn"><details><summary>{messages.diagnostics(source.issues.length)}</summary><ul>{source.issues.map((issue, index) => <li key={`${issue.path}:${index}`}><code>{issue.path}</code> {issue.message}</li>)}</ul></details></PmNotice></div> : null}
177
175
  {!source?.content || !source.identity ? source?.loading
178
176
  ? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
179
- : <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div ref={sheet} className="pmw-source-document__sheet">
180
- <EditorChangeTrail sheet={sheet} />
181
- <DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
177
+ : <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div className="pmw-source-document__sheet">
178
+ <DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} onOpenComments={onOpenComments} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
182
179
  getDocumentVersion={() => { const current = workbench.getState().authoring; return current && current.identity === source.identity && current.reset === source.reset ? current.version : undefined }} reset={source.reset} locale={locale} readOnly={readOnly}
183
180
  uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
184
181
  getPositionToken={() => workbench.getState().documentPositionToken}
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react'
2
- import { prepareTranscriptionAdoption } from '@lincyaw/kernel'
2
+ import { prepareTranscriptionAdoption, randomUUID } from '@lincyaw/kernel'
3
3
  import type { CanonicalSource, NarrationNode, TeachingDocument, TranscriptionRevision, TranscriptionAdoptionDraft, TranscriptionAdoptionPart, TranscriptionAdoptionPlan } from '@lincyaw/kernel'
4
4
  import { PmBadge, PmButton, PmDialog, PmField, PmNotice, PmSelect, PmTextarea } from '../components.tsx'
5
5
  import { useWorkbench, useWorkbenchState } from '../context.tsx'
@@ -14,7 +14,7 @@ const ordered = (value: unknown): unknown => Array.isArray(value) ? value.map(or
14
14
  const same = (a: unknown, b: unknown) => JSON.stringify(ordered(a)) === JSON.stringify(ordered(b))
15
15
  const displayed = (nodes: readonly NarrationNode[]) => nodes.map(node => node.type === 'text' ? node.text : node.type === 'pronunciation' ? node.display : '').join('')
16
16
  function restore(key: string): { draft: Draft, failed: boolean } {
17
- const fallback = () => ({ draft: { id: crypto.randomUUID(), revision: 0, discarded: [], shared: 'fork' as const }, failed: false })
17
+ const fallback = () => ({ draft: { id: randomUUID(), revision: 0, discarded: [], shared: 'fork' as const }, failed: false })
18
18
  try {
19
19
  const raw = localStorage.getItem(key)
20
20
  if (!raw) return fallback()
@@ -83,7 +83,7 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
83
83
  const now = workbench.getState().authoring
84
84
  if (disabled || reviewing || applying || composing || !sourceReady || !now?.version || !now.fingerprint || parsed.invalid) return
85
85
  pause()
86
- if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id: crypto.randomUUID(), baseVersion: now.version })
86
+ if (latest.current.baseVersion && latest.current.baseVersion !== now.version) change({ id: randomUUID(), baseVersion: now.version })
87
87
  else if (!latest.current.baseVersion) change({ baseVersion: now.version })
88
88
  const value = latest.current, request = ++generation.current, normalized = content()
89
89
  const retainsOriginal = references.length > 1 && value.shared === 'fork'
@@ -104,7 +104,7 @@ function AdoptionTarget({ identity, candidate, document, sectionId, stepId, disa
104
104
  try {
105
105
  const answer = await workbench.adoptDocumentTranscription({ planId, source: sent.source, candidate: sent.candidate, draftRevision: sent.draftRevision }, { identity, version: sent.source.version })
106
106
  if (latest.current.id === sent.changeId && latest.current.revision === sent.draftRevision) {
107
- const next: Draft = { ...latest.current, id: crypto.randomUUID(), revision: 0, discarded: [], baseVersion: answer.version, applied: true }
107
+ const next: Draft = { ...latest.current, id: randomUUID(), revision: 0, discarded: [], baseVersion: answer.version, applied: true }
108
108
  latest.current = next; setDraft(next)
109
109
  try { localStorage.setItem(key, JSON.stringify(next)); setStorageFailed(false) } catch { setStorageFailed(true) }
110
110
  }
package/src/places.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { irBlocks } from '@lincyaw/kernel'
2
- import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos } from '@lincyaw/kernel'
3
3
 
4
4
  const CHANGED_PLACES = 100
5
5
 
@@ -65,38 +65,3 @@ export function changedPlaces(doc: IRDocument, changes: readonly ReviewChange[])
65
65
  }
66
66
  return [...places.values()].slice(0, CHANGED_PLACES)
67
67
  }
68
-
69
- /**
70
- * The places that differ between two versions of a document: each block whose content changed or that is new (with
71
- * its page), each page whose title changed or that is new, and the block of each step whose narration or settings
72
- * changed, at most CHANGED_PLACES.
73
- */
74
- export function changedBlocks(before: TeachingDocument, after: TeachingDocument): PreviewAnchor[] {
75
- const places: PreviewAnchor[] = []
76
- const visit = (section: string, ids: readonly string[]) => {
77
- for (const id of ids) {
78
- const block = after.blocks[id]
79
- if (!block) continue
80
- if (JSON.stringify(block) !== JSON.stringify(before.blocks[id])) places.push({ section, block: id })
81
- if ('children' in block && Array.isArray(block.children)) visit(section, block.children as string[])
82
- }
83
- }
84
- for (const id of after.sectionOrder) {
85
- const section = after.sections[id]
86
- if (!section) continue
87
- if (before.sections[id]?.title !== section.title) places.push({ section: id })
88
- visit(id, section.children)
89
- }
90
- // A changed step, or a changed narration of it, shows at the block the step plays (else at its page).
91
- const seen = new Set(places.map(place => `${place.section}\0${place.block ?? ''}`))
92
- for (const step of Object.values(after.steps)) {
93
- const narrated = step.narrationIds.some(id => JSON.stringify(after.narrations[id]) !== JSON.stringify(before.narrations[id]))
94
- if (!narrated && JSON.stringify(step) === JSON.stringify(before.steps[step.id])) continue
95
- // the component the step plays, where its narration shows, else any block it shows
96
- const block = step.visuals.find(visual => after.blocks[visual.blockId]?.type === 'component')?.blockId ?? step.visuals.find(visual => visual.visible)?.blockId ?? step.visuals[0]?.blockId
97
- const place = { section: step.sectionId, ...block ? { block } : {} }
98
- const key = `${place.section}\0${place.block ?? ''}`
99
- if (!seen.has(key)) { seen.add(key); places.push(place) }
100
- }
101
- return places.slice(0, CHANGED_PLACES)
102
- }
@@ -57,6 +57,9 @@ const zh = {
57
57
  alignmentStatus: { manual: '手动时间', words: '词时码', proportional: '比例估时', none: '未对齐' },
58
58
  segmentStatus: { recorded: '原音频', cached: '已有配音', silent: '静音', missing: '配音待生成', blocked: '暂不可用' },
59
59
  waveformLoading: '正在加载波形…', waveformUnavailable: '波形不可用', stepNumber: (index: number) => `步骤 ${index + 1}`,
60
+ notInLecture: '不在讲授中', notInLectureHint: '这一页的内容都限定在其他形态,又没有讲稿与音频,讲授视频中没有这一页。',
61
+ notInLectureStep: '这一步不在讲授中:它的内容都限定在其他形态,又没有讲稿与音频。',
62
+ captionSize: '字幕大小', captionSizeHint: '整个文稿的字幕:放映中显示的与导出视频中烧录的都按这个大小。',
60
63
  timelineLabels: { position: '位置', seconds: '秒', seek: '播放头位置', zoomIn: '放大时间线', zoomOut: '缩小时间线', fit: '适配本页', estimated: '估计时长', unknown: '时长未知', loading: '正在加载时间线…', empty: '当前页暂无时间线片段', seekHint: '选择步骤,或用时间尺、方向键和精确时间定位;定位会先暂停播放。', invalidPosition: '请输入本页时长范围内的秒数。' },
61
64
  failures: {
62
65
  'production-source-changed': '文稿已更新,旧播放请求已停止。请重新准备当前版本。',
@@ -129,6 +132,9 @@ export const PRODUCTION_MESSAGES: Record<Locale, typeof zh> = {
129
132
  alignmentStatus: { manual: 'Manual timing', words: 'Word timing', proportional: 'Proportional timing', none: 'Unaligned' },
130
133
  segmentStatus: { recorded: 'Original audio', cached: 'Voiceover cached', silent: 'Silent', missing: 'Voiceover needed', blocked: 'Unavailable' },
131
134
  waveformLoading: 'Loading waveform…', waveformUnavailable: 'Waveform unavailable', stepNumber: index => `Step ${index + 1}`,
135
+ notInLecture: 'Not in the lecture', notInLectureHint: 'Everything on this page is limited to other forms and it has no script or audio, so the lecture video leaves it out.',
136
+ notInLectureStep: 'This step is not in the lecture: everything on it is limited to other forms and it has no script or audio.',
137
+ captionSize: 'Caption size', captionSizeHint: 'For the whole document: captions shown in the presentation and burned into an exported video use this size.',
132
138
  timelineLabels: { position: 'Position', seconds: 'seconds', seek: 'Playhead position', zoomIn: 'Zoom In Timeline', zoomOut: 'Zoom Out Timeline', fit: 'Fit Page', estimated: 'Estimated duration', unknown: 'Unknown duration', loading: 'Loading the timeline…', empty: 'This page has no timeline segments', seekHint: 'Select a step, or use the ruler, arrow keys, or an exact time to seek. Seeking pauses playback first.', invalidPosition: 'Enter a time in seconds within this page’s duration.' },
133
139
  failures: {
134
140
  'production-source-changed': 'The document changed and the old playback request stopped. Prepare the current version.',
package/src/sha256.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { sha256 as hash } from '@noble/hashes/sha2.js'
2
+ import { bytesToHex } from '@noble/hashes/utils.js'
3
+
4
+ /** The same SHA-256 fingerprint on HTTPS, localhost and LAN HTTP. */
5
+ export async function sha256(value: string | ArrayBuffer): Promise<string> {
6
+ const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : new Uint8Array(value)
7
+ const subtle = globalThis.crypto?.subtle
8
+ return bytesToHex(subtle ? new Uint8Array(await subtle.digest('SHA-256', bytes)) : hash(bytes))
9
+ }
package/src/styles.css CHANGED
@@ -265,20 +265,24 @@
265
265
  color: var(--pm-color-danger);
266
266
  }
267
267
 
268
- .pmw-problems__details summary {
269
- color: var(--pm-color-muted);
270
- font-size: var(--pm-text-xs);
271
- cursor: pointer;
272
- }
273
-
274
- .pmw-problems__details ul {
275
- margin: var(--pm-space-1) 0 0;
268
+ .pmw-problems__list {
269
+ display: flex;
270
+ flex-direction: column;
271
+ gap: var(--pm-space-3);
272
+ margin: 0;
276
273
  padding-left: var(--pm-space-4);
277
- font-family: var(--pm-font-mono);
278
- font-size: var(--pm-text-xs);
279
274
  overflow-wrap: anywhere;
280
275
  }
281
276
 
277
+ .pmw-problems__list p {
278
+ margin: 0;
279
+ }
280
+
281
+ .pmw-problems__hint {
282
+ color: var(--pm-color-muted);
283
+ font-size: var(--pm-text-sm);
284
+ }
285
+
282
286
  .pmw-document__body {
283
287
  display: flex;
284
288
  flex: 1;
@@ -820,17 +824,6 @@
820
824
  accent-color: var(--pm-color-accent);
821
825
  }
822
826
 
823
- /* The kitten above the bar, as far along it as the job has come (`--pmw-job-done`, 0 to 1), never past its ends. */
824
- .pmw-job__runner {
825
- display: block;
826
- margin-left: calc((100% - var(--pm-size-mascot-sm)) * var(--pmw-job-done));
827
- line-height: 0;
828
- }
829
-
830
- .pmw-job__runner:empty {
831
- display: none;
832
- }
833
-
834
827
  .pmw-job__error {
835
828
  margin: 0;
836
829
  color: var(--pm-color-danger);
@@ -931,7 +924,8 @@
931
924
  .pmw-source-document__recovery { display: grid; gap: var(--pm-space-2); min-width: 0; }
932
925
  .pmw-source-document__recovery-actions { display: flex; flex-wrap: wrap; gap: var(--pm-space-2); }
933
926
  .pmw-source-document__diagnostics { margin-block-end: var(--pm-space-3); }
934
- .pmw-source-document__sheet { position: relative; max-width: var(--pm-sheet-width); min-height: 100%; margin-inline: auto; padding-block: var(--pm-space-4); background: var(--pm-color-surface); box-shadow: var(--pm-shadow-page); }
927
+ /* Its end margin is the editor's own end area, which fills the rest of the sheet and takes the presses below the last block. */
928
+ .pmw-source-document__sheet { display: flex; flex-direction: column; max-width: var(--pm-sheet-width); min-height: 100%; margin-inline: auto; padding-block-start: var(--pm-space-4); background: var(--pm-color-surface); box-shadow: var(--pm-shadow-page); }
935
929
  /* Opening: the page's own margins, so that the placeholder lines sit where the text will. */
936
930
  .pmw-source-document__sheet--loading { box-sizing: border-box; padding: var(--pm-space-10) var(--pm-space-12); }
937
931
  .pmw-voice__filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--pm-space-3); }
@@ -1004,22 +998,3 @@
1004
998
  .pmw-approvals .pmw-muted { margin: 0; }
1005
999
  .pmw-approvals__detail { max-height: 30vh; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
1006
1000
  .pmw-approvals__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--pm-space-2); }
1007
-
1008
- /* The kitten walking over the preview to the blocks the AI changed: its ground line meets the block's lower left. */
1009
- .pmw-change-trail {
1010
- position: absolute;
1011
- top: 0;
1012
- left: 0;
1013
- z-index: 1;
1014
- pointer-events: none;
1015
- transform: translate(calc(var(--pmw-trail-x) - 45%), calc(var(--pmw-trail-y) - 89%));
1016
- transition: transform var(--pm-duration-walk) linear, opacity var(--pm-duration-slow);
1017
- }
1018
-
1019
- .pmw-change-trail[data-phase='done'] {
1020
- opacity: 0.9;
1021
- }
1022
-
1023
- .pmw-change-trail__facing[data-facing='left'] {
1024
- transform: scaleX(-1);
1025
- }