@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.
Files changed (124) hide show
  1. package/README.md +1 -1
  2. package/package.json +5 -4
  3. package/src/AgentActivityBar.tsx +25 -0
  4. package/src/MediaClipEditor.tsx +7 -6
  5. package/src/StepProductionEditor.tsx +16 -7
  6. package/src/agent-activity-messages.ts +14 -0
  7. package/src/agent-activity.ts +38 -0
  8. package/src/approvals.tsx +6 -1
  9. package/src/audio-recording-messages.ts +5 -5
  10. package/src/audio-recording.ts +27 -5
  11. package/src/authoring-client.ts +10 -10
  12. package/src/authoring-draft-fragment.ts +3 -1
  13. package/src/authoring-window.ts +100 -0
  14. package/src/base-controls.tsx +28 -7
  15. package/src/body-draft-actions.ts +60 -0
  16. package/src/caption-timing-drafts.ts +20 -3
  17. package/src/caption-timing-messages.ts +2 -2
  18. package/src/caption-timing.ts +2 -2
  19. package/src/component-draft-actions.ts +1 -1
  20. package/src/component-properties.ts +3 -3
  21. package/src/component-property-drafts.ts +6 -6
  22. package/src/components.tsx +43 -38
  23. package/src/container-layout.ts +21 -0
  24. package/src/context.tsx +5 -3
  25. package/src/diagnostics.ts +1 -1
  26. package/src/document-draft-store.ts +45 -18
  27. package/src/document-drafts.ts +30 -21
  28. package/src/document-editing.ts +485 -0
  29. package/src/document-editor/BlockNoteSurface.tsx +40 -14
  30. package/src/document-editor/CommentComposer.tsx +24 -0
  31. package/src/document-editor/ComponentMaterials.tsx +4 -10
  32. package/src/document-editor/ComponentPropertiesDialog.tsx +12 -12
  33. package/src/document-editor/DocumentBlockFallback.tsx +4 -3
  34. package/src/document-editor/DocumentBlockPreview.tsx +11 -4
  35. package/src/document-editor/DocumentComments.tsx +87 -17
  36. package/src/document-editor/DocumentEditor.tsx +66 -14
  37. package/src/document-editor/DocumentStepNarration.tsx +39 -27
  38. package/src/document-editor/NarrationEditor.tsx +55 -21
  39. package/src/document-editor/NewCommentDrafts.tsx +120 -37
  40. package/src/document-editor/PlaceComment.tsx +252 -0
  41. package/src/document-editor/agent-targets.ts +34 -0
  42. package/src/document-editor/blocknote-messages.ts +2 -0
  43. package/src/document-editor/comment-draft-actions.ts +40 -20
  44. package/src/document-editor/comment-draft-inspection.ts +2 -2
  45. package/src/document-editor/comment-drafts.ts +75 -27
  46. package/src/document-editor/comments.ts +34 -14
  47. package/src/document-editor/component-label.ts +11 -0
  48. package/src/document-editor/file-input.ts +2 -2
  49. package/src/document-editor/focus.ts +0 -2
  50. package/src/document-editor/inline.ts +1 -0
  51. package/src/document-editor/insertion-place.ts +60 -0
  52. package/src/document-editor/messages.ts +3 -3
  53. package/src/document-editor/narration-schema.tsx +12 -6
  54. package/src/document-editor/narration.ts +19 -3
  55. package/src/document-editor/page-body.ts +60 -0
  56. package/src/document-editor/popover.tsx +4 -2
  57. package/src/document-editor/projection.ts +21 -19
  58. package/src/document-editor/rich-text.ts +3 -2
  59. package/src/document-editor/selection.ts +13 -0
  60. package/src/document-editor/style.css +8 -3
  61. package/src/document-editor/table-identities.ts +2 -1
  62. package/src/document-preview.ts +3 -2
  63. package/src/document-production.ts +492 -0
  64. package/src/document-return-point.ts +2 -2
  65. package/src/document-session.ts +216 -67
  66. package/src/document-timing-drafts.ts +26 -6
  67. package/src/effective-settings.ts +12 -0
  68. package/src/history.ts +5 -5
  69. package/src/import-messages.ts +40 -0
  70. package/src/index.ts +11 -5
  71. package/src/jobs.ts +1 -1
  72. package/src/mcp-settings-messages.ts +39 -0
  73. package/src/media-drafts.ts +43 -1
  74. package/src/messages.ts +39 -18
  75. package/src/outline.ts +5 -5
  76. package/src/panels/DocumentImportDialog.tsx +59 -0
  77. package/src/panels/DocumentNarrationPanel.tsx +2 -2
  78. package/src/panels/DocumentView.tsx +106 -77
  79. package/src/panels/DocumentVoiceDialog.tsx +29 -12
  80. package/src/panels/DocumentVoiceField.tsx +3 -2
  81. package/src/panels/ExportPanel.tsx +2 -10
  82. package/src/panels/HistoryPanel.tsx +36 -10
  83. package/src/panels/HomePanel.tsx +12 -1
  84. package/src/panels/McpSettingsPanel.tsx +86 -0
  85. package/src/panels/PageDeleteDialog.tsx +4 -4
  86. package/src/panels/PageRenameDialog.tsx +1 -1
  87. package/src/panels/PreviewPanel.tsx +4 -7
  88. package/src/panels/ProductionCaptionSize.tsx +20 -0
  89. package/src/panels/ProductionCaptionTiming.tsx +12 -9
  90. package/src/panels/ProductionMediaClips.tsx +25 -9
  91. package/src/panels/ProductionPanel.tsx +21 -17
  92. package/src/panels/ProductionRecording.tsx +86 -9
  93. package/src/panels/ProductionRecordingRange.tsx +26 -23
  94. package/src/panels/ProductionTimeline.tsx +6 -1
  95. package/src/panels/ProductionTranscription.tsx +8 -6
  96. package/src/panels/SourceDocumentPanel.tsx +24 -40
  97. package/src/panels/SpeechSettingsPanel.tsx +2 -2
  98. package/src/panels/TranscriptionAdoption.tsx +42 -36
  99. package/src/panels/VoiceCloneDialog.tsx +2 -1
  100. package/src/panels/VoicePreviewDialog.tsx +1 -1
  101. package/src/panels/VoiceScopeField.tsx +2 -2
  102. package/src/panels/VoiceoverDialog.tsx +11 -10
  103. package/src/places.ts +1 -36
  104. package/src/preview-playback.ts +1 -1
  105. package/src/production-draft-actions.ts +37 -0
  106. package/src/production-messages.ts +6 -0
  107. package/src/production-playback.ts +1 -1
  108. package/src/production-voice-playback.ts +3 -2
  109. package/src/recording-adoption.ts +4 -4
  110. package/src/sha256.ts +9 -0
  111. package/src/speech-settings-messages.ts +6 -6
  112. package/src/step-production.ts +4 -4
  113. package/src/styles.css +43 -92
  114. package/src/transcription-drafts.ts +124 -0
  115. package/src/use-recording-adoption.ts +5 -4
  116. package/src/voice-drafts.ts +32 -8
  117. package/src/voice-messages.ts +9 -9
  118. package/src/voiceover-jobs.ts +1 -1
  119. package/src/workbench-state.ts +159 -0
  120. package/src/workbench.ts +323 -956
  121. package/src/workspace-client.ts +41 -12
  122. package/src/assistant-mascot.ts +0 -62
  123. package/src/mascot-preference.ts +0 -37
  124. package/src/panels/ChangeTrail.tsx +0 -79
@@ -1,7 +1,7 @@
1
1
  import { ICONS } from '@lincyaw/design'
2
2
  import type { IconName } from '@lincyaw/design'
3
3
  import * as Tooltip from '@radix-ui/react-tooltip'
4
- import { createElement, forwardRef } from 'react'
4
+ import { createElement, forwardRef, useEffect, useRef, useState } from 'react'
5
5
  import type { ButtonHTMLAttributes, ReactNode } from 'react'
6
6
 
7
7
  const cls = (...names: (string | false | undefined | null)[]) => names.filter(Boolean).join(' ')
@@ -14,13 +14,13 @@ export function PmIcon({ name, size: _size, strokeWidth = 1.7 }: { name: IconNam
14
14
  )
15
15
  }
16
16
 
17
- export type ButtonVariant = 'default' | 'primary' | 'accent' | 'ghost' | 'danger'
17
+ export type ButtonVariant = 'default' | 'primary' | 'ghost' | 'text' | 'danger'
18
18
 
19
19
  export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & { type?: 'button' | 'submit' | 'reset' }
20
20
  export type ControlDensity = 'compact' | 'regular' | 'touch'
21
21
  export type ControlProps = { density?: ControlDensity, loading?: boolean }
22
22
 
23
- export const PmButton = forwardRef<HTMLButtonElement, ButtonProps & ControlProps & { variant?: ButtonVariant, small?: boolean, icon?: IconName }>(function PmButton({ variant = 'default', small, density = small ? 'compact' : 'regular', loading, icon, type = 'button', className, children, disabled, ...rest }, ref) {
23
+ export const PmButton = forwardRef<HTMLButtonElement, ButtonProps & ControlProps & { variant?: ButtonVariant, small?: boolean, icon?: IconName }>(function PmButton({ variant = 'default', small, density = 'compact', loading, icon, type = 'button', className, children, disabled, ...rest }, ref) {
24
24
  return (
25
25
  <button {...rest} ref={ref} type={type} data-density={density} aria-busy={loading || undefined} disabled={disabled || loading || rest['aria-disabled'] === true || rest['aria-disabled'] === 'true'} className={cls('pm-ui-button', variant !== 'default' && `pm-ui-button--${variant}`, className)}>
26
26
  <span className={cls('pm-ui-button__content', !icon && loading !== undefined && 'pm-ui-button__content--loading-text')}>{(icon || loading !== undefined) && <span aria-hidden="true" className={cls('pm-ui-button__icon', loading && 'pm-ui-loading')}>{loading ? <PmIcon name="loading" /> : icon && <PmIcon name={icon} />}</span>}{children}</span>
@@ -28,18 +28,39 @@ export const PmButton = forwardRef<HTMLButtonElement, ButtonProps & ControlProps
28
28
  )
29
29
  })
30
30
 
31
- /** Radix opens on keyboard focus immediately; pointer hover uses the I11 delay. */
31
+ const TOOLTIP_DELAY = 500
32
+ const TOOLTIP_SKIP = 300
33
+ let tooltipClosedAt = 0
34
+
35
+ /** A pointer shows the tooltip after 500 ms, keyboard focus at once; within 300 ms of one closing, the next opens at
36
+ * once, so moving along a toolbar does not wait again. The timing is shared by every tooltip on the page. */
32
37
  export function PmTooltip({ label, shortcut, children }: { label: string, shortcut?: string, children: ReactNode }) {
38
+ const [open, setOpen] = useState(false)
39
+ const shown = useRef(false)
40
+ const pointer = useRef(false)
41
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
42
+ useEffect(() => () => clearTimeout(timer.current), [])
43
+ const change = (next: boolean) => {
44
+ clearTimeout(timer.current)
45
+ if (!next) {
46
+ if (shown.current) tooltipClosedAt = Date.now()
47
+ shown.current = false
48
+ setOpen(false)
49
+ return
50
+ }
51
+ const wait = pointer.current && Date.now() - tooltipClosedAt > TOOLTIP_SKIP ? TOOLTIP_DELAY : 0
52
+ timer.current = setTimeout(() => { shown.current = true; setOpen(true) }, wait)
53
+ }
33
54
  return (
34
- <Tooltip.Provider delayDuration={300} skipDelayDuration={0}>
35
- <Tooltip.Root><Tooltip.Trigger asChild>{children}</Tooltip.Trigger><Tooltip.Portal><div className="pm-ui-tooltip-layer"><Tooltip.Content className="pm-ui-tooltip pm-ui" side="bottom" sideOffset={6} collisionPadding={8}>
55
+ <Tooltip.Provider delayDuration={0} skipDelayDuration={0}>
56
+ <Tooltip.Root open={open} onOpenChange={change}><Tooltip.Trigger asChild onPointerEnter={() => { pointer.current = true }} onPointerLeave={() => { pointer.current = false }}>{children}</Tooltip.Trigger><Tooltip.Portal><div className="pm-ui-tooltip-layer"><Tooltip.Content className="pm-ui-tooltip pm-ui" side="bottom" sideOffset={6} collisionPadding={8}>
36
57
  {label}{shortcut && <kbd className="pm-ui-shortcut">{shortcut}</kbd>}
37
58
  </Tooltip.Content></div></Tooltip.Portal></Tooltip.Root>
38
59
  </Tooltip.Provider>
39
60
  )
40
61
  }
41
62
 
42
- export const PmIconButton = forwardRef<HTMLButtonElement, ButtonProps & ControlProps & { icon: IconName, label: string, hint?: string, shortcut?: string, small?: boolean, tooltip?: boolean }>(function PmIconButton({ icon, label, hint, shortcut, small, tooltip = true, density = small ? 'compact' : 'regular', loading, className, disabled, ...rest }, ref) {
63
+ export const PmIconButton = forwardRef<HTMLButtonElement, ButtonProps & ControlProps & { icon: IconName, label: string, hint?: string, shortcut?: string, small?: boolean, tooltip?: boolean }>(function PmIconButton({ icon, label, hint, shortcut, small, tooltip = true, density = 'compact', loading, className, disabled, ...rest }, ref) {
43
64
  const button = <button {...rest} ref={ref} type="button" data-density={density} aria-label={label} aria-busy={loading || undefined} disabled={disabled || loading || rest['aria-disabled'] === true || rest['aria-disabled'] === 'true'} className={cls('pm-ui-icon-button', className)}>
44
65
  <span className={cls('pm-ui-button__content', loading && 'pm-ui-loading')}><PmIcon name={loading ? 'loading' : icon} /></span>
45
66
  </button>
@@ -0,0 +1,60 @@
1
+ import type { AuthoringClientAction, AuthoringClientActionResult, ClientBodyDraftMetadata } from '@lincyaw/kernel'
2
+ import { authoringDraftFragment, draftContentHash } from './authoring-draft-fragment.ts'
3
+ import type { BodyDraftCandidate, DocumentDraftOperation, DocumentSession, DocumentSessionState } from './document-session.ts'
4
+
5
+ type BodyAction = Extract<AuthoringClientAction, { type: `body-drafts.${string}` }>
6
+ /** Explicit draft inspection never sends owner IDs, base hashes or body text in metadata. */
7
+ const metadata = (value: BodyDraftCandidate, version: string): ClientBodyDraftMetadata => ({
8
+ draft: value.draft.token, current: value.draft.current, storage: value.storage, updatedAt: value.updatedAt, baseVersion: value.baseVersion, baseObserved: value.baseVersion === version,
9
+ composing: value.composing, pendingSubmission: value.pendingSubmission,
10
+ })
11
+ export async function executeBodyDraftAction(session: DocumentSession, state: () => DocumentSessionState | undefined, action: BodyAction, operation: DocumentDraftOperation, fits: (result: AuthoringClientActionResult) => boolean): Promise<AuthoringClientActionResult> {
12
+ const read = await session.readBodyDrafts(operation.signal, 'draft' in action ? action.draft : undefined)
13
+ const guard = () => { operation.guard(); read.guard() }
14
+ guard()
15
+ if (action.type === 'body-drafts.inspect') {
16
+ const values = read.candidates.map(value => metadata(value, operation.source.version)), token = await draftContentHash(JSON.stringify({ values, coverage: read.coverage }))
17
+ guard()
18
+ if (action.cursor && action.cursor.token !== token) throw new Error('client-body-drafts-changed')
19
+ const start = action.cursor ? values.findIndex(value => value.draft === action.cursor!.after) + 1 : 0
20
+ if (action.cursor && start === 0) throw new Error('client-body-drafts-changed')
21
+ const result: Extract<AuthoringClientActionResult, { type: 'body-drafts.inspect' }> = { type: action.type, family: 'body', coverage: read.coverage, token, drafts: [] }
22
+ for (const value of values.slice(start, start + (action.limit ?? 10))) {
23
+ const next = { ...result, drafts: [...result.drafts, value], ...start + result.drafts.length + 1 < values.length ? { next: { after: value.draft, token } } : {} }
24
+ if (!fits(next)) break
25
+ result.drafts.push(value)
26
+ }
27
+ if (start < values.length && !result.drafts.length) throw new Error('client-body-metadata-too-large')
28
+ if (start + result.drafts.length < values.length) result.next = { after: result.drafts.at(-1)!.draft, token }
29
+ if (!fits(result)) throw new Error('client-body-metadata-too-large')
30
+ guard(); return result
31
+ }
32
+ const value = read.candidates[0]!
33
+ if (action.type === 'body-drafts.read') return authoringDraftFragment({ text: JSON.stringify(value.content), base: { type: action.type, family: 'body', draft: value.draft.token, storage: value.storage, format: 'presmium-document-json-v1' }, offset: action.offset, maxChars: action.maxChars }, guard, fits)
34
+ if (!session.bodyDraftCapabilities().mutate || value.composing || value.pendingSubmission || action.type === 'body-drafts.restore' && value.draft.current || action.type === 'body-drafts.retry' && !value.draft.current) throw new Error('client-body-draft-needs-human')
35
+ const result = (outcome: Extract<AuthoringClientActionResult, { family: 'body', outcome: string }>['outcome']): Extract<AuthoringClientActionResult, { family: 'body', outcome: string }> => {
36
+ const now = state()
37
+ return { type: action.type, family: 'body', draft: value.draft.token, outcome, dirty: Boolean(now?.dirty), conflicted: Boolean(now?.error), ...now?.backupPending ? { backupPending: true as const } : {}, ...now?.storageFailure ? { backupRetained: true as const } : {} }
38
+ }
39
+ if (!fits({ ...result(action.type === 'body-drafts.restore' ? 'restored' : action.type === 'body-drafts.retry' ? 'saved' : value.draft.current ? 'source-restored' : 'backup-discarded'), backupPending: true, backupRetained: true })) throw new Error('client-body-result-too-large')
40
+ guard()
41
+ let outcome: 'restored' | 'already-saved' | 'source-restored' | 'backup-discarded' | 'saved'
42
+ if (action.type === 'body-drafts.restore') {
43
+ const restored = await session.recoverDraft(value.draft, operation)
44
+ if (!restored) throw new Error('client-body-drafts-changed')
45
+ outcome = restored
46
+ } else if (action.type === 'body-drafts.discard') {
47
+ const done = value.draft.current ? await session.discard(operation) : await session.forgetDraft(value.draft, operation)
48
+ if (!done) throw new Error('client-body-drafts-changed')
49
+ outcome = value.draft.current ? 'source-restored' : 'backup-discarded'
50
+ } else {
51
+ await session.retry(operation)
52
+ if (state()?.error || state()?.saving || state()?.restored) throw new Error('client-body-save-unverified')
53
+ outcome = 'saved'
54
+ }
55
+ operation.signal.throwIfAborted()
56
+ // A successful retry may finish at a new canonical version. The transport checks that saved source.
57
+ const answer = result(outcome)
58
+ if (!fits(answer)) throw new Error('client-body-result-too-large')
59
+ return answer
60
+ }
@@ -1,9 +1,9 @@
1
- import type { CaptionTimingSource, TeachingDocument } from '@lincyaw/kernel'
1
+ import type { CaptionTimingSource, PresmiumDocument } from '@lincyaw/kernel'
2
2
 
3
3
  export interface CaptionTimingRow { id: string, from: number, to: number, start: string, end: string }
4
4
  export interface CaptionTimingDraft { version: string, text: string, basis: CaptionTimingSource, rows: CaptionTimingRow[] }
5
5
  type Scope = { identity: string, memberId: string }
6
- interface Entry { values: Map<string, CaptionTimingDraft>, failed: boolean, unreadable: boolean }
6
+ interface Entry { raw?: string | null, values: Map<string, CaptionTimingDraft>, failed: boolean, unreadable: boolean }
7
7
  const MAX_CHARS = 1 << 20
8
8
  const MAX_TARGETS = 512
9
9
  const valid = (value: unknown): value is CaptionTimingDraft => {
@@ -32,6 +32,7 @@ export class CaptionTimingDrafts {
32
32
  const result: Entry = { values: new Map(), failed: false, unreadable: false }; this.#entries.set(key, result)
33
33
  try {
34
34
  const raw = sessionStorage.getItem(key)
35
+ result.raw = raw
35
36
  if (raw === null) return result
36
37
  if (raw.length > MAX_CHARS) throw new Error('caption-draft-limit')
37
38
  const data: unknown = JSON.parse(raw)
@@ -44,7 +45,22 @@ export class CaptionTimingDrafts {
44
45
  return result
45
46
  }
46
47
  get(scope: Scope, stepId: string): CaptionTimingDraft | undefined { return this.#entry(scope).values.get(stepId) }
47
- steps(scope: Scope, document: TeachingDocument): string[] { return [...this.#entry(scope).values.keys()].filter(id => Object.hasOwn(document.steps, id)) }
48
+ entries(scope: Scope): readonly (readonly [string, CaptionTimingDraft])[] { return [...this.#entry(scope).values] }
49
+ partial(scope: Scope): boolean { const entry = this.#entry(scope); try { return entry.unreadable || sessionStorage.getItem(this.#key(scope)) !== entry.raw } catch { return true } }
50
+ discard(scope: Scope, stepId: string): boolean {
51
+ const entry = this.#entry(scope)
52
+ if (entry.unreadable || !entry.values.has(stepId)) return false
53
+ try {
54
+ const next = [...entry.values].filter(([target]) => target !== stepId), key = this.#key(scope)
55
+ if (sessionStorage.getItem(key) !== entry.raw) { entry.failed = true; return false }
56
+ if (next.length) sessionStorage.setItem(key, JSON.stringify(next))
57
+ else sessionStorage.removeItem(key)
58
+ entry.raw = next.length ? JSON.stringify(next) : null
59
+ entry.values.delete(stepId); entry.failed = false
60
+ return true
61
+ } catch { entry.failed = true; return false }
62
+ }
63
+ steps(scope: Scope, document: PresmiumDocument): string[] { return [...this.#entry(scope).values.keys()].filter(id => Object.hasOwn(document.steps, id)) }
48
64
  failed(scope: Scope): boolean { return this.#entry(scope).failed }
49
65
  set(scope: Scope, stepId: string, value: CaptionTimingDraft | undefined): void {
50
66
  const entry = this.#entry(scope)
@@ -54,6 +70,7 @@ export class CaptionTimingDrafts {
54
70
  const key = this.#key(scope), raw = JSON.stringify([...entry.values])
55
71
  if (raw.length > MAX_CHARS || entry.values.size > MAX_TARGETS || [...entry.values.values()].some(draft => !valid(draft))) throw new Error('caption-draft-limit')
56
72
  if (entry.values.size) sessionStorage.setItem(key, raw); else sessionStorage.removeItem(key)
73
+ entry.raw = entry.values.size ? raw : null
57
74
  entry.failed = false
58
75
  } catch { entry.failed = true }
59
76
  }
@@ -1,12 +1,12 @@
1
1
  export const CAPTION_TIMING_MESSAGES = {
2
2
  'zh-CN': {
3
- title: '手动字幕时间', open: '设置字幕时间', cancel: '取消', done: '完成', apply: '应用', automatic: '使用自动时间', split: '按换行分段',
3
+ title: '手动字幕时间', open: '字幕时间', cancel: '取消', done: '完成', apply: '应用', automatic: '自动时间', split: '按换行分段',
4
4
  start: '开始(秒)', end: '结束(秒)', step: '本步骤 · 时间从步骤起点计算', invalid: '时间须递增且不超出本步骤。',
5
5
  loading: '正在加载字幕时间…', prepare: '请先准备当前步骤。', unavailable: '当前步骤的字幕时间不可用。', changed: '讲稿或音频已变化。', recheck: '再次检查', saved: '字幕时间已保存到当前步骤。',
6
6
  failed: '无法确认字幕时间已保存。输入已保留,请重试。', storageFailed: '无法备份字幕时间,请保持此页面打开。', discard: '放弃修改', limit: '本次最多设置 32 段。', segment: (n: number) => `字幕 ${n}`,
7
7
  },
8
8
  en: {
9
- title: 'Manual Caption Timing', open: 'Set Caption Times', cancel: 'Cancel', done: 'Done', apply: 'Apply', automatic: 'Use Automatic Times', split: 'Split at Line Breaks',
9
+ title: 'Manual Caption Timing', open: 'Caption Timing', cancel: 'Cancel', done: 'Done', apply: 'Apply', automatic: 'Auto Timing', split: 'Split at Line Breaks',
10
10
  start: 'Start (seconds)', end: 'End (seconds)', step: 'Current step · Times start at the step boundary', invalid: 'Times must increase and fit inside this step.',
11
11
  loading: 'Loading caption times…', prepare: 'Prepare the current step first.', unavailable: 'Caption timing is unavailable for this step.', changed: 'The script or audio has changed.', recheck: 'Check Again', saved: 'Caption times saved to this step.',
12
12
  failed: 'Couldn’t confirm that caption times were saved. Your input is kept; try again.', storageFailed: 'Couldn’t back up caption times. Keep this page open.', discard: 'Discard Changes', limit: 'Set no more than 32 segments at once.', segment: (n: number) => `Caption ${n}`,
@@ -1,9 +1,9 @@
1
1
  import { applyDocumentCaptionTiming, captionSourceFingerprint } from '@lincyaw/kernel'
2
- import type { DocumentAnswer, DocumentCaptionTimingAction, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { DocumentAnswer, DocumentCaptionTimingAction, PresmiumDocument } from '@lincyaw/kernel'
3
3
 
4
4
  const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
5
5
  /** The source actor adopts only this caption slot; later native body input remains owned by the editor. */
6
- export function reconcileCaptionTiming(action: DocumentCaptionTimingAction, before: TeachingDocument, answer: DocumentAnswer, current: TeachingDocument): TeachingDocument | undefined {
6
+ export function reconcileCaptionTiming(action: DocumentCaptionTimingAction, before: PresmiumDocument, answer: DocumentAnswer, current: PresmiumDocument): PresmiumDocument | undefined {
7
7
  try {
8
8
  if (before.id !== answer.content.id || before.id !== current.id || !same(applyDocumentCaptionTiming(before, action).content, answer.content)) return
9
9
  if (!current.steps[action.stepId]) return current
@@ -6,7 +6,7 @@ import type { ComponentPropertyDraft, ComponentPropertyDrafts } from './componen
6
6
  export const sameComponentDraftReference = (a: ClientComponentDraftReference | null, b: ClientComponentDraftReference | null): boolean => a === null || b === null ? a === b
7
7
  : a.id === b.id && a.revision === b.revision && a.token === b.token && a.blockId === b.blockId && a.stepId === b.stepId
8
8
 
9
- /** Explicit form actions reuse the human bank; they never apply parameters to lecture.json. */
9
+ /** Explicit form actions reuse the human bank; they never apply parameters to index.pmd. */
10
10
  export async function mutateComponentDrafts(bank: ComponentPropertyDrafts, context: { identity: string, memberId: string, source: CanonicalSource }, action: Extract<AuthoringClientAction, { type: 'component-drafts.restore' | 'component-drafts.discard' }>, signal: AbortSignal, owned: (draft?: ComponentPropertyDraft) => void, fits: (result: AuthoringClientActionResult) => boolean): Promise<AuthoringClientActionResult> {
11
11
  const read = await bank.readForAgent(context, signal, action.draft)
12
12
  owned()
@@ -1,5 +1,5 @@
1
1
  import { applyDocumentComponentAction, createDocumentParameterChanges, effectiveComponentParameters } from '@lincyaw/kernel'
2
- import type { CanonicalSource, DocumentAnswer, DocumentComponentAction, JsonObject, TeachingDocument } from '@lincyaw/kernel'
2
+ import type { CanonicalSource, DocumentAnswer, DocumentComponentAction, JsonObject, PresmiumDocument } from '@lincyaw/kernel'
3
3
  import type { ComponentPropertyDraft } from './component-property-drafts.ts'
4
4
 
5
5
  export const sameComponentSource = (a: CanonicalSource, b: CanonicalSource) => a.documentId === b.documentId && a.version === b.version && a.fingerprint === b.fingerprint
@@ -15,7 +15,7 @@ export function componentPropertyAction(draft: ComponentPropertyDraft): Document
15
15
  }
16
16
 
17
17
  /** A checked rebase borrows the same reducer as the service, preserving unrelated current data. */
18
- export function rebaseComponentPropertyDraft(document: TeachingDocument, draft: ComponentPropertyDraft): JsonObject {
18
+ export function rebaseComponentPropertyDraft(document: PresmiumDocument, draft: ComponentPropertyDraft): JsonObject {
19
19
  const block = document.blocks[draft.target.blockId]
20
20
  if (block?.type !== 'component' || block.definitionId !== draft.definitionId) throw new Error('component-definition-changed')
21
21
  const action = componentPropertyAction(draft)
@@ -24,7 +24,7 @@ export function rebaseComponentPropertyDraft(document: TeachingDocument, draft:
24
24
  }
25
25
 
26
26
  /** An external acknowledgement owns its parameter paths, never a later body tree or sibling form. */
27
- export function reconcileComponentAction(action: DocumentComponentAction, before: TeachingDocument, answer: DocumentAnswer, current: TeachingDocument): TeachingDocument | undefined {
27
+ export function reconcileComponentAction(action: DocumentComponentAction, before: PresmiumDocument, answer: DocumentAnswer, current: PresmiumDocument): PresmiumDocument | undefined {
28
28
  try {
29
29
  if (answer.content.id !== before.id || current.id !== before.id) return
30
30
  const expected = applyDocumentComponentAction(before, action).content
@@ -1,6 +1,7 @@
1
- import { isRecord } from '@lincyaw/kernel'
1
+ import { isRecord, randomUUID } from '@lincyaw/kernel'
2
2
  import type { CanonicalSource, ClientComponentDraftReference, JsonObject } from '@lincyaw/kernel'
3
3
  import { DocumentDraftStore } from './document-draft-store.ts'
4
+ import { sha256 as tokenOf } from './sha256.ts'
4
5
  import type { DraftStoreCommit } from './document-draft-store.ts'
5
6
 
6
7
  export interface ComponentPropertyTarget { identity: string, memberId: string, blockId: string, stepId?: string }
@@ -32,7 +33,6 @@ const scopedPrefix = (kind: string, identity: string, memberId: string) => `${ki
32
33
  const markerOf = (target: ComponentPropertyTarget, reference: { id: string, revision: number, token: string }) => `${markerPrefix(target)}${JSON.stringify([reference.id, reference.revision, reference.token])}`
33
34
  const marker = (backup: ComponentPropertyBackup) => markerOf(backup.record.target, { id: backup.record.id, revision: backup.record.revision, token: backup.token })
34
35
  const keyOf = (record: ComponentPropertyDraft) => `${prefix(record.target)}${record.id}`
35
- const tokenOf = async (raw: string) => [...new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(raw)))].map(byte => byte.toString(16).padStart(2, '0')).join('')
36
36
 
37
37
  function valid(value: unknown, target: ComponentPropertyTarget): value is ComponentPropertyDraft {
38
38
  return isRecord(value) && value.format === 1 && typeof value.id === 'string' && value.id.length > 0
@@ -43,14 +43,14 @@ function valid(value: unknown, target: ComponentPropertyTarget): value is Compon
43
43
  && typeof value.reset === 'boolean' && typeof value.composing === 'boolean' && typeof value.updatedAt === 'string' && Number.isFinite(Date.parse(value.updatedAt))
44
44
  }
45
45
 
46
- /** Unapplied form input borrows the existing strict backup actor; only lecture.json is authoring content. */
46
+ /** Unapplied form input borrows the existing strict backup actor; only index.pmd is authoring content. */
47
47
  export class ComponentPropertyDrafts {
48
48
  readonly #entries = new Map<string, Entry>()
49
49
  readonly #listeners = new Set<() => void>()
50
50
  readonly #revisions = new Map<string, number>()
51
51
  readonly #settling = new Map<string, number>()
52
52
  #agentReader?: { identity: string, memberId: string, store: DocumentDraftStore }
53
- readonly #writerOwner = crypto.randomUUID()
53
+ readonly #writerOwner = randomUUID()
54
54
  #revision = 0
55
55
  #closed = false
56
56
  readonly #leave = (event: BeforeUnloadEvent) => {
@@ -149,7 +149,7 @@ export class ComponentPropertyDrafts {
149
149
  if (this.#closed) throw new Error('component-draft-closed')
150
150
  const key = targetKey(target), previous = this.#entries.get(key)
151
151
  if (!previous && this.#entries.size >= 512) throw new Error('component-draft-limit')
152
- const record: ComponentPropertyDraft = { format: 1, id: previous?.record.id ?? crypto.randomUUID(), revision: (previous?.record.revision ?? 0) + 1,
152
+ const record: ComponentPropertyDraft = { format: 1, id: previous?.record.id ?? randomUUID(), revision: (previous?.record.revision ?? 0) + 1,
153
153
  target: structuredClone(target), source: structuredClone(value.source), definitionId: value.definitionId, baseline: structuredClone(value.baseline), value: structuredClone(value.value),
154
154
  reset: Boolean(value.reset), composing: Boolean(value.composing), updatedAt: new Date().toISOString() }
155
155
  const entry: Entry = previous ?? { record, store: new DocumentDraftStore(scope(target), undefined, { owner: this.#writerOwner, family: 'component' }), failed: false, origins: [] }
@@ -213,7 +213,7 @@ export class ComponentPropertyDrafts {
213
213
  try { value = JSON.parse(raw) } catch { return false }
214
214
  if (!valid(value, target) || backup.key !== keyOf(value)) return false
215
215
  guard?.()
216
- const record: ComponentPropertyDraft = { ...structuredClone(value), id: crypto.randomUUID(), revision: 1, composing: false, updatedAt: new Date().toISOString() }
216
+ const record: ComponentPropertyDraft = { ...structuredClone(value), id: randomUUID(), revision: 1, composing: false, updatedAt: new Date().toISOString() }
217
217
  const fork = JSON.stringify(record)
218
218
  if (fork.length > MAX_CHARS) return false
219
219
  const operation = store.put(keyOf(record), fork)
@@ -1,17 +1,14 @@
1
1
  import type { IconName } from '@lincyaw/design'
2
- import { mountMascot } from '@lincyaw/design/mascot'
3
- import type { MascotAction } from '@lincyaw/design/mascot'
4
2
  import * as Dialog from '@radix-ui/react-dialog'
5
3
  import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
6
4
  import * as Popover from '@radix-ui/react-popover'
7
5
  import * as Tabs from '@radix-ui/react-tabs'
8
6
  import * as Toolbar from '@radix-ui/react-toolbar'
9
7
  import * as RadioGroup from '@radix-ui/react-radio-group'
10
- import { forwardRef, useEffect, useId, useMemo, useRef, useState } from 'react'
8
+ import { createContext, forwardRef, useContext, useEffect, useId, useMemo, useRef, useState } from 'react'
11
9
  import type { ComponentProps, CSSProperties, InputHTMLAttributes, ReactNode, Ref, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react'
12
10
  import { Group as ResizableGroup, Panel as ResizablePanel, Separator as ResizableSeparator } from 'react-resizable-panels'
13
11
  import { PmButton, PmIcon, PmIconButton, PmTooltip } from './base-controls.tsx'
14
- import { useMascotEnabled } from './mascot-preference.ts'
15
12
  import type { ControlDensity } from './base-controls.tsx'
16
13
  export { PmButton, PmIcon, PmIconButton, PmTooltip } from './base-controls.tsx'
17
14
  export type { ButtonVariant, ControlDensity } from './base-controls.tsx'
@@ -35,17 +32,17 @@ export function PmSplitHandle({ label, className, ...props }: ComponentProps<typ
35
32
  }
36
33
 
37
34
  /** Shared chrome for docked editors; content and actions remain owned by the caller. */
38
- export function PmPanelHeader({ title, meta, leading, actions }: { title: string, meta?: ReactNode, leading?: ReactNode, actions?: ReactNode }) {
39
- return <header className="pm-ui-panel-header">
40
- {leading}<h2 className="pm-ui-panel-header__title">{title}</h2>
35
+ export function PmPanelHeader({ title, titleId, meta, leading, actions, variant = 'dock', className }: { title: string, titleId?: string, meta?: ReactNode, leading?: ReactNode, actions?: ReactNode, variant?: 'workspace' | 'dock', className?: string }) {
36
+ return <header className={cls('pm-ui-panel-header', className)} data-variant={variant}>
37
+ {leading}<h2 id={titleId} className="pm-ui-panel-header__title">{title}</h2>
41
38
  {meta && <span className="pm-ui-panel-header__meta">{meta}</span>}
42
39
  {actions && <div className="pm-ui-panel-header__actions">{actions}</div>}
43
40
  </header>
44
41
  }
45
42
 
46
43
  /** One tab stop, with arrow/Home/End navigation supplied by Radix. */
47
- export function PmToolbar({ label, children, className, scroll }: { label: string, children: ReactNode, className?: string, scroll?: boolean }) {
48
- return <Toolbar.Root className={cls(scroll && 'pm-ui-toolbar-scroll', className)} aria-label={label} loop>{children}</Toolbar.Root>
44
+ export function PmToolbar({ label, children, className, scroll, variant = 'inline' }: { label: string, children: ReactNode, className?: string, scroll?: boolean, variant?: 'workspace' | 'inline' }) {
45
+ return <Toolbar.Root className={cls('pm-ui-toolbar', scroll && 'pm-ui-toolbar-scroll', className)} data-variant={variant} aria-label={label} loop>{children}</Toolbar.Root>
49
46
  }
50
47
  export const PmToolbarButton = Toolbar.Button
51
48
 
@@ -152,6 +149,13 @@ export function PmSearchList({ label, searchLabel, searchPlaceholder, items, val
152
149
 
153
150
  export type Tone = 'neutral' | 'accent' | 'ok' | 'warn' | 'danger' | 'outline'
154
151
 
152
+ /** Labelled presence: the dot breathes only while a real operation is running. */
153
+ export function PmAgentActivity({ state, label, compact, detail }: { state: 'running' | 'done' | 'failed' | 'cancelled', label: string, compact?: boolean, detail?: string }) {
154
+ return <span className="pm-ui-agent-activity" data-state={state} data-compact={compact || undefined} role="status" aria-label={detail} aria-live="polite" aria-atomic="true">
155
+ <span className="pm-ui-agent-activity__dot" aria-hidden="true" /><span className="pm-ui-agent-activity__label">{label}</span>
156
+ </span>
157
+ }
158
+
155
159
  export function PmBadge({ tone = 'neutral', pill, children }: { tone?: Tone, pill?: boolean, children?: ReactNode }) {
156
160
  return <span className={cls('pm-ui-badge', tone !== 'neutral' && `pm-ui-badge--${tone}`, pill && 'pm-ui-badge--pill')}>{children}</span>
157
161
  }
@@ -289,8 +293,13 @@ export function PmWorkspaceSwitcher({ label, value, items, onValueChange, placeh
289
293
  export type PopoverPlacement = 'below-end' | 'below-start' | 'above-end' | 'above-start'
290
294
  const placementOf = (placement: PopoverPlacement) => ({ side: placement.startsWith('above') ? 'top' as const : 'bottom' as const, align: placement.endsWith('start') ? 'start' as const : 'end' as const })
291
295
 
296
+ /** Host controls remain reachable inside the active modal without weakening its focus boundary. */
297
+ export const PmDialogActionsContext = createContext<ReactNode>(undefined)
298
+ const PmDialogLayerContext = createContext(false)
299
+
292
300
  export function PmDialog({ open, label, closeLabel, name, actions, description, footer, busy, onClose, onOpenAutoFocus, onCloseAutoFocus, children }: { open: boolean, label: string, closeLabel: string, name?: string, actions?: ReactNode, description?: string, footer?: ReactNode, busy?: boolean, onClose(): void, onOpenAutoFocus?(event: Event): void, onCloseAutoFocus?(event: Event): void, children?: ReactNode }) {
293
301
  const id = useId()
302
+ const hostActions = useContext(PmDialogActionsContext)
294
303
  // A descendant's React autoFocus runs before Radix's open-focus event.
295
304
  const trigger = useRef<HTMLElement | null>(typeof document === 'undefined' ? null : document.activeElement as HTMLElement)
296
305
  useEffect(() => {
@@ -321,14 +330,17 @@ export function PmDialog({ open, label, closeLabel, name, actions, description,
321
330
  const target = available(trigger.current) ? trigger.current : [...document.querySelectorAll<HTMLElement>('[role="toolbar"] button, main button')].find(available)
322
331
  target?.focus()
323
332
  }}>
333
+ <PmDialogLayerContext.Provider value>
324
334
  <div className="pm-ui-dialog__header">
325
335
  <Dialog.Title className="pm-ui-dialog__title">{label}</Dialog.Title>
326
336
  {actions}
337
+ {hostActions}
327
338
  <Dialog.Close asChild><PmIconButton icon="close" label={closeLabel} small disabled={busy} /></Dialog.Close>
328
339
  </div>
329
340
  {description && <Dialog.Description className="pm-ui-dialog__description">{description}</Dialog.Description>}
330
341
  <div className="pm-ui-dialog__body">{children}</div>
331
342
  {footer && <div className="pm-ui-dialog__footer">{footer}</div>}
343
+ </PmDialogLayerContext.Provider>
332
344
  </Dialog.Content>
333
345
  </Dialog.Portal>
334
346
  </Dialog.Root>
@@ -336,12 +348,13 @@ export function PmDialog({ open, label, closeLabel, name, actions, description,
336
348
  }
337
349
 
338
350
  /** A non-modal floating panel on its trigger, with the shared `pm-ui-popover` surface (host's PmPopover for React pages). */
339
- export function PmPopover({ open, label, name, placement = 'below-end', trigger, onOpenChange, children }: { open: boolean, label: string, name?: string, placement?: PopoverPlacement, trigger: ReactNode, onOpenChange(open: boolean): void, children?: ReactNode }) {
351
+ export function PmPopover({ open, label, name, placement = 'below-end', trigger, onOpenChange, onInteractOutside, children }: { open: boolean, label: string, name?: string, placement?: PopoverPlacement, trigger: ReactNode, onOpenChange(open: boolean): void, onInteractOutside?: ComponentProps<typeof Popover.Content>['onInteractOutside'], children?: ReactNode }) {
352
+ const inDialog = useContext(PmDialogLayerContext)
340
353
  return (
341
354
  <Popover.Root open={open} onOpenChange={onOpenChange}>
342
355
  <Popover.Trigger asChild>{trigger}</Popover.Trigger>
343
356
  <Popover.Portal>
344
- <Popover.Content className={cls('pm-ui-popover', 'pm-ui-floating', 'pm-ui', name)} aria-label={label} {...placementOf(placement)} sideOffset={6} collisionPadding={16} onEscapeKeyDown={event => event.stopPropagation()}>
357
+ <Popover.Content className={cls('pm-ui-popover', 'pm-ui-floating', 'pm-ui', name)} data-layer={inDialog ? 'dialog' : undefined} aria-label={label} {...placementOf(placement)} sideOffset={6} collisionPadding={16} onInteractOutside={onInteractOutside} onEscapeKeyDown={event => event.stopPropagation()}>
345
358
  {children}
346
359
  </Popover.Content>
347
360
  </Popover.Portal>
@@ -409,28 +422,15 @@ export function PmSkeleton({ label, shape = 'document' }: { label: string, shape
409
422
  )
410
423
  }
411
424
 
412
- export function PmNotice({ tone = 'neutral', children }: { tone?: 'neutral' | 'accent' | 'ok' | 'warn' | 'danger', children?: ReactNode }) {
413
- return <div className={cls('pm-ui-notice', tone !== 'neutral' && `pm-ui-notice--${tone}`)} role={tone === 'danger' ? 'alert' : 'status'}>{children}</div>
414
- }
415
-
416
- /** The Presmium kitten acting out what the assistant or a long task is doing. It is decoration: the text beside it
417
- * says the same thing for everyone, so it is hidden from assistive technology. Nothing shows when the author turned
418
- * the kitten off in Settings. */
419
- export function PmMascot(props: { action: MascotAction, size?: 'small' | 'regular' }) {
420
- return useMascotEnabled() ? <MascotPlayer {...props} /> : null
421
- }
425
+ const NOTICE_ICONS = { neutral: 'info', accent: 'info', ok: 'check', warn: 'warning', danger: 'warning' } as const satisfies Record<string, IconName>
422
426
 
423
- function MascotPlayer({ action, size = 'regular' }: { action: MascotAction, size?: 'small' | 'regular' }) {
424
- const ref = useRef<HTMLSpanElement>(null)
425
- const player = useRef<ReturnType<typeof mountMascot>>(undefined)
426
- const first = useRef(action)
427
- useEffect(() => {
428
- const mounted = mountMascot(ref.current!, first.current)
429
- player.current = mounted
430
- return () => mounted.stop()
431
- }, [])
432
- useEffect(() => { player.current?.set(action) }, [action])
433
- return <span ref={ref} className={cls('pm-ui-mascot', size === 'small' && 'pm-ui-mascot--sm')} data-pm-mascot={action} aria-hidden="true" />
427
+ /** A tone icon, the message, and an optional action at the end (a button or a group of buttons). */
428
+ export function PmNotice({ tone = 'neutral', action, children }: { tone?: keyof typeof NOTICE_ICONS, action?: ReactNode, children?: ReactNode }) {
429
+ return <div className={cls('pm-ui-notice', tone !== 'neutral' && `pm-ui-notice--${tone}`)} role={tone === 'danger' ? 'alert' : 'status'}>
430
+ <span className="pm-ui-notice__icon"><PmIcon name={NOTICE_ICONS[tone]} /></span>
431
+ <div className="pm-ui-notice__message">{children}</div>
432
+ {action && <div className="pm-ui-notice__action">{action}</div>}
433
+ </div>
434
434
  }
435
435
 
436
436
  export interface RangeProps {
@@ -526,6 +526,10 @@ export interface TimelineProps {
526
526
  showSteps?: boolean
527
527
  /** A flush docked editor, with status and zoom in the same tool row. */
528
528
  variant?: 'default' | 'editor'
529
+ /** The page has no place on this timeline (the lecture leaves it out): its status and notice say so, with no tracks to seek. */
530
+ excluded?: { status: string, notice: string }
531
+ /** A note about the selected step, under the tracks. */
532
+ notice?: string
529
533
  }
530
534
 
531
535
  const timelineTime = (ms: number) => `${String(Math.floor(ms / 60000)).padStart(2, '0')}:${(ms % 60000 / 1000).toFixed(3).padStart(6, '0')}`
@@ -540,11 +544,11 @@ function waveformPath(samples: readonly number[] | undefined): string | undefine
540
544
  }
541
545
 
542
546
  /** Data-only timeline; source, playback, seeking authority and all labels remain with its caller. */
543
- export function PmTimeline({ label, tracks, labels, durationMs, durationStatus, currentTimeMs, selectedStepId, zoom, onZoomChange, onSelectStep, onSelectSegment, segmentPicker, onSeek, seekDisabled, disabled, loading, seeking, density = 'compact', showSteps = true, variant = 'default' }: TimelineProps) {
547
+ export function PmTimeline({ label, tracks, labels, durationMs, durationStatus, currentTimeMs, selectedStepId, zoom, onZoomChange, onSelectStep, onSelectSegment, segmentPicker, onSeek, seekDisabled, disabled, loading, seeking, density = 'compact', showSteps = true, variant = 'default', excluded, notice }: TimelineProps) {
544
548
  const hintId = useId()
545
549
  const viewport = useRef<HTMLDivElement>(null), tick = useRef<HTMLSpanElement>(null), composing = useRef(false)
546
550
  const [width, setWidth] = useState(0), [tickWidth, setTickWidth] = useState(1), [localZoom, setLocalZoom] = useState(1), [raw, setRaw] = useState<string>(), [previewTime, setPreviewTime] = useState<number>()
547
- const span = Number.isFinite(durationMs) && durationMs! >= 0 ? durationMs : undefined
551
+ const span = !excluded && Number.isFinite(durationMs) && durationMs! >= 0 ? durationMs : undefined
548
552
  const timing = durationStatus ?? (span === undefined ? 'unknown' : 'confirmed')
549
553
  const timed = span !== undefined && span > 0 && timing !== 'unknown'
550
554
  const blocked = Boolean(disabled || loading), cannotSeek = Boolean(blocked || seeking || seekDisabled || !timed || timing !== 'confirmed')
@@ -585,10 +589,10 @@ export function PmTimeline({ label, tracks, labels, durationMs, durationStatus,
585
589
  const marks = Array.from({ length: Math.min(200, Math.floor(span / unit) + 1) }, (_, index) => index * unit)
586
590
  return [0, ...marks.filter(time => time > 0 && time < span && Math.min(time, span - time) / span * width * scale >= tickWidth), span]
587
591
  }, [span, timed, width, scale, tickWidth])
588
- const status = <div className="pm-ui-timeline__status" role="status">{loading ? labels.loading : timing === 'unknown' || span === undefined ? labels.unknown : `${timing === 'estimated' ? `${labels.estimated} · ` : ''}${timelineTime(span)}`}</div>
592
+ const status = <div className="pm-ui-timeline__status" role="status">{loading ? labels.loading : excluded ? excluded.status : timing === 'unknown' || span === undefined ? labels.unknown : `${timing === 'estimated' ? `${labels.estimated} · ` : ''}${timelineTime(span)}`}</div>
589
593
  return <section className="pm-ui-timeline" data-variant={variant} data-density={density} data-disabled={blocked || undefined} data-segment-picker={segmentPicker?.track} aria-label={label} aria-busy={loading || seeking || undefined}>
590
594
  <div className="pm-ui-timeline__tools">
591
- <PmInput label={`${labels.position} (${labels.seconds})`} labelHidden={variant === 'editor'} width="time" density={density} inputMode="decimal" maxLength={32} value={raw ?? (position === undefined ? '' : (position / 1000).toFixed(3))} placeholder={labels.unknown} error={invalid ? labels.invalidPosition : undefined} disabled={cannotSeek}
595
+ <PmInput label={`${labels.position} (${labels.seconds})`} labelHidden={variant === 'editor'} width="time" density={density} inputMode="decimal" maxLength={32} value={raw ?? (position === undefined ? '' : (position / 1000).toFixed(3))} placeholder={excluded ? undefined : labels.unknown} error={invalid ? labels.invalidPosition : undefined} disabled={cannotSeek}
592
596
  onChange={event => setRaw(event.target.value)} onBlur={commitPosition}
593
597
  onCompositionStart={() => { composing.current = true }} onCompositionEnd={() => { composing.current = false }}
594
598
  onKeyDown={event => { if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return; if (event.key === 'Enter') { event.preventDefault(); commitPosition() } else if (event.key === 'Escape') setRaw(undefined) }} />
@@ -624,8 +628,9 @@ export function PmTimeline({ label, tracks, labels, durationMs, durationStatus,
624
628
  onChange={event => { const segment = pickerSegments.find(segment => segment.id === event.target.value); if (segment && !cannotSeek) onSelectSegment?.(segmentPicker.track, segment) }}>
625
629
  <option value="">{segmentPicker.placeholder}</option>{pickerSegments.map(segment => <option key={segment.id} value={segment.id} disabled={segment.disabled}>{timelineTime(segment.startMs!)} · {segment.label}</option>)}
626
630
  </PmSelect></div>}
627
- {showSteps && <div className="pm-ui-timeline__steps">{steps.map(segment => <PmButton key={segment.stepId} density={density} disabled={blocked || segment.disabled} aria-pressed={segment.stepId === selectedStepId} variant={segment.stepId === selectedStepId ? 'accent' : 'default'} onClick={() => onSelectStep(segment.stepId!)}>{segment.label}</PmButton>)}</div>}
628
- {!tracks.some(track => track.segments.length) && <PmNotice>{labels.empty}</PmNotice>}
631
+ {showSteps && <div className="pm-ui-timeline__steps">{steps.map(segment => <PmButton key={segment.stepId} density={density} disabled={blocked || segment.disabled} aria-pressed={segment.stepId === selectedStepId} onClick={() => onSelectStep(segment.stepId!)}>{segment.label}</PmButton>)}</div>}
632
+ {(excluded || !tracks.some(track => track.segments.length)) && <PmNotice>{excluded?.notice ?? labels.empty}</PmNotice>}
633
+ {notice && <PmNotice>{notice}</PmNotice>}
629
634
  <p id={hintId} className="pm-ui-sr-only">{labels.seekHint}</p>
630
635
  </section>
631
636
  }
@@ -0,0 +1,21 @@
1
+ import { useCallback, useLayoutEffect, useState } from 'react'
2
+ import { designLength } from '@lincyaw/design'
3
+
4
+ /** Layout belongs to the available pane, which can be much narrower than the application window. */
5
+ export function useContainerLayout() {
6
+ const [element, setElement] = useState<HTMLElement | null>(null)
7
+ const ref = useCallback((node: HTMLElement | null) => setElement(node), [])
8
+ const [layout, setLayout] = useState({ measured: false, narrow: true, roomy: false, productionWide: false })
9
+ useLayoutEffect(() => {
10
+ if (!element) return
11
+ const update = () => {
12
+ const width = element.getBoundingClientRect().width
13
+ if (!width) return
14
+ const next = { measured: true, narrow: width < designLength('--pm-layout-narrow-width', element), roomy: width >= designLength('--pm-layout-roomy-width', element), productionWide: width >= designLength('--pm-production-wide-width', element) }
15
+ setLayout(previous => Object.keys(next).every(key => previous[key as keyof typeof next] === next[key as keyof typeof next]) ? previous : next)
16
+ }
17
+ const observer = new ResizeObserver(update); observer.observe(element); update()
18
+ return () => observer.disconnect()
19
+ }, [element])
20
+ return { ...layout, ref }
21
+ }
package/src/context.tsx CHANGED
@@ -2,13 +2,15 @@ import { createContext, useContext, useSyncExternalStore } from 'react'
2
2
  import type { ReactNode } from 'react'
3
3
  import { MESSAGES } from './messages.ts'
4
4
  import type { WorkbenchMessages } from './messages.ts'
5
- import type { Workbench, WorkbenchState } from './workbench.ts'
5
+ import type { Workbench } from './workbench.ts'
6
+ import type { WorkbenchState } from './workbench-state.ts'
7
+ import { PmDialogActionsContext } from './components.tsx'
6
8
 
7
9
  const WORKBENCH = createContext<Workbench | undefined>(undefined)
8
10
 
9
11
  /** Gives the panels drawn in it one workbench. */
10
- export function WorkbenchProvider({ workbench, children }: { workbench: Workbench, children?: ReactNode }) {
11
- return <WORKBENCH.Provider value={workbench}>{children}</WORKBENCH.Provider>
12
+ export function WorkbenchProvider({ workbench, children, dialogActions }: { workbench: Workbench, children?: ReactNode, dialogActions?: ReactNode }) {
13
+ return <WORKBENCH.Provider value={workbench}>{dialogActions === undefined ? children : <PmDialogActionsContext.Provider value={dialogActions}>{children}</PmDialogActionsContext.Provider>}</WORKBENCH.Provider>
12
14
  }
13
15
 
14
16
  export function useWorkbench(): Workbench {
@@ -1,6 +1,6 @@
1
1
  import { errorMessage } from '@lincyaw/kernel'
2
2
  import type { Diagnostic, DiagnosticSnapshot, PreviewDiagnostics } 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
  type Repairer = (diagnostics: readonly Diagnostic[]) => void | Promise<void>