@lincyaw/workbench 0.2.0-rc.121 → 0.2.0-rc.123

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 (39) hide show
  1. package/package.json +4 -4
  2. package/src/StepProductionEditor.tsx +13 -8
  3. package/src/components.tsx +24 -4
  4. package/src/context.tsx +30 -0
  5. package/src/document-editor/BlockNoteSurface.tsx +4 -1
  6. package/src/document-editor/DocumentBlockFallback.tsx +0 -1
  7. package/src/document-editor/DocumentEditor.tsx +7 -1
  8. package/src/document-editor/DocumentStepNarration.tsx +4 -2
  9. package/src/document-editor/authoring.tsx +15 -0
  10. package/src/document-editor/inline.ts +5 -0
  11. package/src/document-editor/insertion-place.ts +2 -2
  12. package/src/document-editor/messages.ts +2 -2
  13. package/src/document-editor/projection.ts +6 -4
  14. package/src/document-editor/references.tsx +352 -0
  15. package/src/document-editor/schema.tsx +39 -2
  16. package/src/document-editor/style.css +10 -0
  17. package/src/document-production.ts +8 -0
  18. package/src/document-session.ts +5 -3
  19. package/src/document-tree.ts +271 -0
  20. package/src/import-messages.ts +1 -1
  21. package/src/index.ts +6 -1
  22. package/src/knowledge-components.tsx +574 -0
  23. package/src/knowledge.css +354 -0
  24. package/src/messages.ts +12 -0
  25. package/src/panels/DocumentPeekPanel.tsx +190 -0
  26. package/src/panels/DocumentView.tsx +46 -23
  27. package/src/panels/DocumentVoiceField.tsx +3 -2
  28. package/src/panels/HomePanel.tsx +12 -3
  29. package/src/panels/MaterialsDialog.tsx +67 -0
  30. package/src/panels/ProductionCaptionSize.tsx +8 -3
  31. package/src/panels/ReferencesPanel.tsx +115 -0
  32. package/src/panels/SourceDocumentPanel.tsx +21 -3
  33. package/src/panels/WorkspaceHome.tsx +109 -0
  34. package/src/panels/WorkspaceSidebar.tsx +331 -0
  35. package/src/styles.css +20 -0
  36. package/src/tree-messages.ts +345 -0
  37. package/src/workbench-state.ts +21 -0
  38. package/src/workbench.ts +76 -3
  39. package/src/workspace-client.ts +35 -1
@@ -1,8 +1,9 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react'
2
2
  import { useContainerLayout } from '../container-layout.ts'
3
3
  import type { ReactNode, RefObject } from 'react'
4
- import { PmBadge, PmButton, PmDialog, PmIcon, PmIconButton, PmMenu, PmNotice, PmPanelHeader, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
5
- import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
4
+ import { PmBadge, PmButton, PmDialog, PmIcon, PmIconButton, PmMenu, PmNotice, PmPanelHeader, PmSkeleton, PmSortableList, PmTabs, PmToolbar, PmToolbarButton } from '../components.tsx'
5
+ import { useMessages, useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
6
+ import { ReferencesPanel, ReferencesSummary } from './ReferencesPanel.tsx'
6
7
  import { failureReason, timeAgo } from '../messages.ts'
7
8
  import { SHORTCUTS } from '../shortcuts.ts'
8
9
  import { DocumentOutline, DocumentWordCounter } from '../outline.ts'
@@ -17,10 +18,16 @@ import { PageRenameDialog } from './PageRenameDialog.tsx'
17
18
  import { PageDeleteDialog } from './PageDeleteDialog.tsx'
18
19
  import { SourceDocumentPanel } from './SourceDocumentPanel.tsx'
19
20
  import { DocumentNarrationPanel } from './DocumentNarrationPanel.tsx'
21
+ import { DocumentPeekPanel } from './DocumentPeekPanel.tsx'
20
22
 
21
- export type DocumentAside = 'comments' | 'history' | 'export' | 'narration'
23
+ export type DocumentAside = 'outline' | 'references' | 'comments' | 'history' | 'export' | 'narration' | 'peek'
24
+ /** The right pane's tabs: the page outline, the references and the comments. */
25
+ const RAIL_TABS: readonly DocumentAside[] = ['outline', 'references', 'comments']
26
+ const isRail = (aside: DocumentAside | null): aside is 'outline' | 'references' | 'comments' => aside !== null && RAIL_TABS.includes(aside)
22
27
 
23
28
  const isTyping = (target: EventTarget | null) => target instanceof HTMLElement && (target.isContentEditable || target.closest('input, textarea, select, [contenteditable]') !== null)
29
+ // Keys pressed in the document's page (the editor, its references, synced blocks and previews) belong to the editor.
30
+ const inDocument = (target: EventTarget | null) => target instanceof Element && target.closest('.pmw-document__source') !== null
24
31
 
25
32
  // Esc belongs to the topmost dialog or menu first; only then does it leave the presentation.
26
33
  const hasOpenLayer = () => document.querySelector('[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]') !== null
@@ -41,27 +48,31 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
41
48
  const presentButton = useRef<HTMLButtonElement>(null)
42
49
  const [commentsPortal, setCommentsPortal] = useState<HTMLDivElement | null>(null)
43
50
  const t = useMessages()
51
+ const tt = useTreeMessages()
44
52
  const document = useWorkbenchState(state => state.document)
45
53
  const sourceIdentity = useWorkbenchState(state => state.authoring?.identity)
46
54
  const view = useWorkbenchState(state => state.webView)
47
55
  const previousView = useRef({ document, workspace, view, active })
48
56
  const currentScope = useRef({ document, active })
49
57
  currentScope.current = { document, active }
50
- const [navigation, setNavigation] = useState(false)
51
58
  const container = useContainerLayout(), { roomy, narrow } = container
52
59
  const previousRoomy = useRef<boolean>()
60
+ // A roomy layout opens with the outline in the right pane; where the pane would cover the page it starts closed.
53
61
  useEffect(() => {
54
62
  if (!container.measured) return
55
- if (!roomy) setNavigation(false)
56
- else if (previousRoomy.current === undefined) setNavigation(true)
63
+ if (!roomy) setAside(current => isRail(current) ? null : current)
64
+ else if (previousRoomy.current === undefined) setAside(current => current ?? 'outline')
57
65
  previousRoomy.current = roomy
58
66
  }, [roomy, container.measured])
59
- // Where the pane covers the page, another document opens with it closed, so its body is not hidden.
60
- const [navigationDocument, setNavigationDocument] = useState(document)
61
- if (navigationDocument !== document) {
62
- setNavigationDocument(document)
63
- if (navigation && !roomy) setNavigation(false)
64
- }
67
+ const navigation = isRail(aside)
68
+ // "Open on the Side" puts another document in the right pane; closing it brings back what the pane showed before.
69
+ const peek = useWorkbenchState(state => state.documentPeek)
70
+ const beforePeek = useRef<DocumentAside | null>(null)
71
+ useEffect(() => {
72
+ if (peek) setAside(current => { if (current !== 'peek') beforePeek.current = current; return 'peek' })
73
+ else setAside(current => current === 'peek' ? beforePeek.current : current)
74
+ }, [peek])
75
+ useEffect(() => { if (aside !== 'peek') workbench.tree.closePeek() }, [aside])
65
76
  const compilePresentation = async (ready?: () => void, forReading = false, signal?: AbortSignal, deadline?: number): Promise<void> => {
66
77
  if (preparing.current || workbench.getState().isPreparingPresentation) return
67
78
  preparing.current = true
@@ -153,7 +164,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
153
164
  transition.current++; exiting.current = undefined
154
165
  setWorkspace('document')
155
166
  setChangingView(false); setViewFailure(undefined)
156
- setAside(null)
167
+ setAside(current => isRail(current) && roomy ? current : null)
157
168
  }, [document])
158
169
  useEffect(() => { if (!active) { transition.current++; exiting.current = undefined; setChangingView(false) } }, [active])
159
170
  useEffect(() => () => { transition.current++ }, [])
@@ -181,7 +192,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
181
192
  if (!event.repeat) void workbench.flushPendingEdits().catch(() => {})
182
193
  }
183
194
  const keys = (event: KeyboardEvent) => {
184
- if (event.defaultPrevented || isTyping(event.target) || !(event.ctrlKey || event.metaKey) || event.altKey) return
195
+ if (event.defaultPrevented || isTyping(event.target) || inDocument(event.target) || !(event.ctrlKey || event.metaKey) || event.altKey) return
185
196
  const key = event.key.toLowerCase()
186
197
  if (key === 'z' && !event.shiftKey) {
187
198
  event.preventDefault()
@@ -224,15 +235,24 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
224
235
  workbench.setMode('viewing')
225
236
  workbench.setWebView('present')
226
237
  setWorkspace('presentation')
227
- })} onNavigation={() => { setNavigation(shown => !shown); if (!navigation && !roomy) setAside(null) }} onAside={next => { setAside(current => (current === next ? null : next)); if (!roomy) setNavigation(false) }} />}
238
+ })} onNavigation={() => setAside(current => isRail(current) ? null : 'outline')} onAside={next => setAside(current => (current === next ? null : next))} />}
228
239
  {viewFailure && <PmNotice tone="danger">{viewFailure}</PmNotice>}
229
240
  <DocumentNotices />
230
241
  <div className="pmw-document__body" role="region" aria-label={producing ? PRODUCTION_MESSAGES[workbench.getState().locale].title : presenting ? t.presentationPreview : reading ? t.readDocument : t.documentEditor}>
231
- {!presenting && !producing && !reading && navigation && <NavigationPane onClose={() => setNavigation(false)} onSelect={() => { if (!roomy) setNavigation(false) }} />}
232
- <div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} onOpenComments={() => setAside('comments')} /></div>{producing && <ProductionPanel actions={actions} active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
242
+ <div className="pmw-document__main"><div className="pmw-document__source" hidden={presenting || producing || reading}><SourceDocumentPanel commentsPortal={commentsPortal} onCommentDraftRestore={() => setAside(current => current === 'comments' ? null : current)} onOpenComments={() => setAside('comments')} after={narrow ? <ReferencesSummary /> : undefined} /></div>{producing && <ProductionPanel actions={actions} active={active} closing={changingView} onClose={() => void exitPresent()} />}{presenting && <PreviewPanel presentation active={active} onPresentationAction={action => { if (action === 'refresh') void compilePresentation(); else void exitPresent() }} />}{reading && <PreviewPanel active={active} />}</div>
233
243
  {!presenting && !producing && !reading && aside && (
234
- <aside className="pmw-document__aside pm-ui-block-editor" aria-label={{ narration: t.documentNarration, comments: t.comments, export: t.exportPane, history: t.versionHistory }[aside]}>
235
- {aside === 'comments' ? <section className="pmw-pane"><PmPanelHeader className="pmw-pane__header" title={t.comments} actions={<PmIconButton small icon="close" label={t.close} onClick={() => setAside(null)} />} /><div ref={setCommentsPortal} /></section> : aside === 'narration' ? <DocumentNarrationPanel onClose={() => setAside(null)} /> : aside === 'export' ? <ExportPanel documentOnly onClose={() => setAside(null)} /> : <HistoryPanel onClose={() => setAside(null)} revisionAction={historyRevisionAction} />}
244
+ <aside className="pmw-document__aside pm-ui-block-editor" aria-label={{ outline: tt.outline, references: tt.references, narration: t.documentNarration, comments: t.comments, export: t.exportPane, history: t.versionHistory, peek: tt.peekLabel }[aside]}>
245
+ {isRail(aside) ? <section className="pmw-pane pmw-rail">
246
+ <div className="pmw-rail__header">
247
+ <PmTabs variant="dock" value={aside} label={tt.rail} tabs={[{ value: 'outline', label: tt.outline }, { value: 'references', label: tt.references }, { value: 'comments', label: t.comments }]} onValueChange={value => setAside(value as DocumentAside)} />
248
+ <PmIconButton small icon="close" label={t.close} onClick={() => setAside(null)} />
249
+ </div>
250
+ <div className="pmw-rail__body">
251
+ {aside === 'outline' && <NavigationPane embedded onClose={() => setAside(null)} onSelect={() => { if (!roomy) setAside(null) }} />}
252
+ {aside === 'references' && <ReferencesPanel />}
253
+ {aside === 'comments' && <div ref={setCommentsPortal} />}
254
+ </div>
255
+ </section> : aside === 'peek' ? peek && <DocumentPeekPanel target={peek} /> : aside === 'narration' ? <DocumentNarrationPanel onClose={() => setAside(null)} /> : aside === 'export' ? <ExportPanel documentOnly onClose={() => setAside(null)} /> : <HistoryPanel onClose={() => setAside(null)} revisionAction={historyRevisionAction} />}
236
256
  </aside>
237
257
  )}
238
258
  </div>
@@ -242,7 +262,7 @@ export function DocumentView({ active = true, framed = false, onBack, actions, h
242
262
  }
243
263
 
244
264
  /** The document's sections, or its slides: where the preview is, and a click to go to another. */
245
- function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): void }) {
265
+ function NavigationPane({ embedded, onClose, onSelect }: { embedded?: boolean, onClose(): void, onSelect(): void }) {
246
266
  const t = useMessages()
247
267
  const workbench = useWorkbench()
248
268
  const outline = useMemo(() => new DocumentOutline(), [])
@@ -287,10 +307,12 @@ function NavigationPane({ onClose, onSelect }: { onClose(): void, onSelect(): vo
287
307
  }
288
308
  return (
289
309
  <nav className="pmw-navigation" aria-label={t.navigation}>
290
- <PmPanelHeader className="pmw-pane__header" title={editing ? t.pages : slides ? t.renderers.slides : t.navigation} actions={<>
310
+ {embedded ? editing && <div className="pmw-rail__actions">
311
+ <PmButton small variant="ghost" icon="plus" loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }}>{t.newPage}</PmButton>
312
+ </div> : <PmPanelHeader className="pmw-pane__header" title={editing ? t.pages : slides ? t.renderers.slides : t.navigation} actions={<>
291
313
  {editing && <PmIconButton icon="plus" label={t.newPage} small loading={creating} disabled={!canCreate || pageBusy || !items.length} onClick={() => { if (workbench.editing.createPage()) onSelect() }} />}
292
314
  <PmIconButton icon="close" label={t.closeNavigation} small onClick={onClose} />
293
- </>} />
315
+ </>} />}
294
316
  {failure && !renaming && !deleting && <PmNotice tone="danger">{failure}</PmNotice>}
295
317
  {items.length === 0 && loading ? <div className="pmw-navigation__empty"><PmSkeleton shape="list" label={t.loadingPages} /></div>
296
318
  : items.length === 0
@@ -348,6 +370,7 @@ function StatusBar() {
348
370
 
349
371
  function DocumentToolbar({ narrow, presentButton, framed, onBack, actions, aside, navigation, changingView, onProduction, onRead, onPresent, onNavigation, onAside }: { narrow: boolean, presentButton: RefObject<HTMLButtonElement>, framed: boolean, onBack?(): void, actions?: ReactNode, aside: DocumentAside | null, navigation: boolean, changingView: boolean, onProduction(): void, onRead(): void, onPresent(): void, onNavigation(): void, onAside(aside: DocumentAside): void }) {
350
372
  const t = useMessages()
373
+ const tt = useTreeMessages()
351
374
  const workbench = useWorkbench()
352
375
  const p = PRODUCTION_MESSAGES[useWorkbenchState(state => state.locale)]
353
376
  const title = useWorkbenchState(state => state.authoring?.content?.metadata.title ?? state.documents?.documents.find(doc => doc.dir === state.document)?.title ?? '')
@@ -374,7 +397,7 @@ function DocumentToolbar({ narrow, presentButton, framed, onBack, actions, aside
374
397
  <PmToolbarButton asChild><PmIconButton icon="arrow-left" label={t.back} small onClick={() => onBack ? onBack() : workbench.closeDocument()} /></PmToolbarButton>
375
398
  <h1 className="pmw-toolbar__title" title={title}>{title}</h1>
376
399
  </div>}
377
- <PmToolbarButton asChild><PmIconButton small icon="navigation" label={t.navigationPane} aria-pressed={navigation} onClick={onNavigation} /></PmToolbarButton>
400
+ <PmToolbarButton asChild><PmIconButton small icon="rail" label={tt.rail} aria-pressed={navigation} onClick={onNavigation} /></PmToolbarButton>
378
401
  {!compactCommands && <>
379
402
  <PmToolbarButton asChild><PmIconButton small icon="undo" label={t.undo} shortcut={SHORTCUTS.undo} disabled={undoDisabled} onClick={() => void workbench.undo()} /></PmToolbarButton>
380
403
  <PmToolbarButton asChild><PmIconButton small icon="redo" label={t.redo} shortcut={SHORTCUTS.redo} disabled={redoDisabled} onClick={() => void workbench.redo()} /></PmToolbarButton>
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from 'react'
2
2
  import { PmButton, PmField } from '../components.tsx'
3
- import { useWorkbench, useWorkbenchState } from '../context.tsx'
3
+ import { useInheritedFrom, useWorkbench, useWorkbenchState } from '../context.tsx'
4
4
  import { resolveDocumentStepVoice } from '../document-voices.ts'
5
5
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
6
6
  import { isAgentChanging } from '../workbench-state.ts'
@@ -14,6 +14,7 @@ export function DocumentVoiceField({ stepId, disabled = false, onGenerate }: { s
14
14
  const locale = useWorkbenchState(state => state.locale)
15
15
  const blocked = useWorkbenchState(state => Boolean(state.authoring?.loading || state.authoring?.composing) || isAgentChanging(state))
16
16
  const [open, setOpen] = useState(false)
17
+ const inheritedFrom = useInheritedFrom('production.defaults.voiceSource')
17
18
  useEffect(() => { setOpen(false) }, [source?.identity, stepId])
18
19
  const document = source?.content, step = document?.steps[stepId], p = PRODUCTION_MESSAGES[locale]
19
20
  if (!document || !step || !source?.identity) return null
@@ -23,7 +24,7 @@ export function DocumentVoiceField({ stepId, disabled = false, onGenerate }: { s
23
24
  : voice.value?.type === 'none' ? p.none
24
25
  : voice.value?.type === 'recording' ? recording?.title || p.recording : p.unset
25
26
  return <>
26
- <PmField group label={p.voice} hint={p.inherited[voice.inheritedFrom]}>
27
+ <PmField group label={p.voice} hint={voice.inheritedFrom === 'document' && !document.production.defaults.voiceSource && source.inherited?.production?.defaults?.voiceSource && inheritedFrom || p.inherited[voice.inheritedFrom]}>
27
28
  <span>{label}</span>
28
29
  <div className="pmw-voice__actions">
29
30
  <PmButton small icon="audio" disabled={disabled || blocked} onClick={() => { workbench.pauseDocumentStep(step.sectionId, stepId); workbench.stopAuditions(); setOpen(true) }}>{p.choose}</PmButton>
@@ -3,7 +3,8 @@ import type { ReactNode } from 'react'
3
3
  import { errorMessage } from '@lincyaw/kernel'
4
4
  import type { DocumentSummary, ProjectPlan } from '@lincyaw/kernel'
5
5
  import { PmButton, PmDialog, PmEmpty, PmInput, PmSelect, PmIcon, PmMenu, PmNotice } from '../components.tsx'
6
- import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
6
+ import { useMessages, useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
7
+ import { WorkspaceHome } from './WorkspaceHome.tsx'
7
8
  import { contentText } from '../messages.ts'
8
9
  import { IMPORT_MESSAGES } from '../import-messages.ts'
9
10
  import { DocumentImportDialog } from './DocumentImportDialog.tsx'
@@ -14,7 +15,15 @@ type Editing =
14
15
 
15
16
  /** The documents of the workspace: open one, make a new one, rename, copy or delete one. */
16
17
  export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
18
+ const workbench = useWorkbench()
19
+ const tree = useWorkbenchState(state => state.documentTree)
20
+ return workbench.tree.available && tree ? <WorkspaceHome actions={actions} /> : <DocumentListHome actions={actions} />
21
+ }
22
+
23
+ /** A workspace without the tree routes (or before its tree is read): the flat list with its operations. */
24
+ function DocumentListHome({ actions }: { actions?: ReactNode }) {
17
25
  const t = useMessages()
26
+ const tt = useTreeMessages()
18
27
  const workbench = useWorkbench()
19
28
  const answer = useWorkbenchState(state => state.documents)
20
29
  const failure = useWorkbenchState(state => state.documentsFailure)
@@ -59,7 +68,7 @@ export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
59
68
  {done && <PmNotice tone="ok">{done}</PmNotice>}
60
69
  {error && !editing && <PmNotice tone="danger">{error}</PmNotice>}
61
70
  {answer && !answer.git && !answer.single && <PmNotice tone="warn">{t.notGit}</PmNotice>}
62
- {answer?.migration && workbench.client.migrateWorkspace && <PmNotice tone="warn" action={<PmButton disabled={working} onClick={() => void run(async () => t.upgraded((await workbench.migrateWorkspace()).documents.length))}>{t.upgrade}</PmButton>}>{t.formatUpgrade}</PmNotice>}
71
+ {answer?.migration && workbench.client.migrateWorkspace && <PmNotice tone="warn" action={<PmButton disabled={working} onClick={() => void run(async () => t.upgraded((await workbench.migrateWorkspace()).documents.length))}>{t.upgrade}</PmButton>}>{answer.migration.documents.length ? tt.upgradePending(answer.migration.documents.length) : t.formatUpgrade}</PmNotice>}
63
72
  <div className="pmw-home__heading-row">
64
73
  <h2 className="pmw-home__heading">{t.allDocuments}</h2>
65
74
  {documents.length > 6 && (
@@ -67,7 +76,7 @@ export function HomePanel({ actions }: { actions?: ReactNode } = {}) {
67
76
  )}
68
77
  </div>
69
78
  {answer && documents.length === 0
70
- ? <PmEmpty icon="document" title={t.noDocuments} />
79
+ ? !answer.migration?.documents.length && <PmEmpty icon="document" title={t.noDocuments} />
71
80
  : shown.length === 0 && query
72
81
  ? <p className="pmw-muted">{t.noMatch}</p>
73
82
  : (
@@ -0,0 +1,67 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import { DOCUMENT_MATERIALS_MAX_BYTES, DOCUMENT_MATERIALS_MAX_FILES } from '@lincyaw/kernel'
3
+ import { PmButton, PmDialog, PmNotice, PmTextarea } from '../components.tsx'
4
+ import { useMessages, useTreeMessages, useWorkbench } from '../context.tsx'
5
+ import { WorkspaceServerError } from '../workspace-client.ts'
6
+
7
+ const MEBIBYTES = DOCUMENT_MATERIALS_MAX_BYTES / (1 << 20)
8
+ const ACCEPTED = '.pdf,.md,.markdown,.txt,.docx,.doc,.pptx,.ppt,.key,.odt,.odp,.rtf,.html,.htm,.csv,.json,.tex,.bib,image/*'
9
+
10
+ /**
11
+ * Write from Source Material: the author chooses files and may say what they want; the workbench creates the document,
12
+ * keeps the files in its folder, opens it and hands the AI the request.
13
+ */
14
+ export function MaterialsDialog({ onClose }: { onClose(): void }) {
15
+ const t = useMessages()
16
+ const tt = useTreeMessages()
17
+ const workbench = useWorkbench()
18
+ const [files, setFiles] = useState<File[]>([])
19
+ const [note, setNote] = useState('')
20
+ const [working, setWorking] = useState(false)
21
+ const [failure, setFailure] = useState<string>()
22
+ const input = useRef<HTMLInputElement>(null)
23
+ const controller = useRef<AbortController>()
24
+ useEffect(() => () => controller.current?.abort(), [])
25
+ const select = (list: FileList | null) => {
26
+ const selected = [...list ?? []]
27
+ if (selected.length > DOCUMENT_MATERIALS_MAX_FILES || selected.reduce((sum, file) => sum + file.size, 0) > DOCUMENT_MATERIALS_MAX_BYTES) {
28
+ setFailure(tt.materialsLimit(DOCUMENT_MATERIALS_MAX_FILES, MEBIBYTES)); setFiles([])
29
+ } else { setFiles(selected); setFailure(undefined) }
30
+ }
31
+ const submit = async () => {
32
+ if (working || !files.length) return
33
+ const pending = controller.current = new AbortController()
34
+ setWorking(true); setFailure(undefined)
35
+ try {
36
+ const { asked } = await workbench.writeFromMaterials(files, note, pending.signal)
37
+ onClose()
38
+ workbench.tree.toast(asked ? tt.materialsSent : tt.materialsNotSent)
39
+ } catch (error) {
40
+ if (pending.signal.aborted) return
41
+ setFailure(error instanceof WorkspaceServerError && error.status === 413 ? tt.materialsLimit(DOCUMENT_MATERIALS_MAX_FILES, MEBIBYTES) : tt.materialsFailed)
42
+ setWorking(false)
43
+ }
44
+ }
45
+ return (
46
+ <PmDialog open label={tt.fromMaterials} closeLabel={t.close} name="pmw-operation" busy={working} onClose={onClose}>
47
+ <form className="pmw-operation" onSubmit={(event) => { event.preventDefault(); void submit() }}>
48
+ <p>{tt.materialsDescription}</p>
49
+ <p className="pmw-muted">{tt.materialsLimits(DOCUMENT_MATERIALS_MAX_FILES, MEBIBYTES)}</p>
50
+ <input ref={input} type="file" multiple hidden accept={ACCEPTED} onChange={(event) => { select(event.currentTarget.files); event.currentTarget.value = '' }} />
51
+ <div className="pmw-operation__actions">
52
+ <PmButton icon="upload" disabled={working} onClick={() => input.current?.click()}>{tt.materialsChoose}</PmButton>
53
+ </div>
54
+ {files.length > 0 && <>
55
+ <p>{tt.materialsSelected(files.length)}</p>
56
+ <ul className="pmw-materials__files">{files.map((file, index) => <li key={`${file.name}-${index}`}>{file.name}</li>)}</ul>
57
+ </>}
58
+ <PmTextarea label={tt.materialsNote} placeholder={tt.materialsNotePlaceholder} rows={3} value={note} disabled={working} maxLength={2000} onChange={event => setNote(event.target.value)} />
59
+ {failure && <PmNotice tone="danger">{failure}</PmNotice>}
60
+ <div className="pmw-operation__actions">
61
+ <PmButton disabled={working} onClick={onClose}>{t.cancel}</PmButton>
62
+ <PmButton type="submit" variant="primary" loading={working} disabled={!files.length}>{tt.materialsSubmit}</PmButton>
63
+ </div>
64
+ </form>
65
+ </PmDialog>
66
+ )
67
+ }
@@ -1,8 +1,8 @@
1
1
  import { useState } from 'react'
2
2
  import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
3
3
  import type { PresmiumDocument } from '@lincyaw/kernel'
4
- import { PmField, PmRange } from '../components.tsx'
5
- import { useWorkbench, useWorkbenchState } from '../context.tsx'
4
+ import { PmButton, PmField, PmRange } from '../components.tsx'
5
+ import { useInheritedFrom, useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
6
6
  import { PRODUCTION_MESSAGES } from '../production-messages.ts'
7
7
 
8
8
  /** The document's caption size in percent steps of ten; a released drag or a key records it once. */
@@ -10,11 +10,16 @@ export function ProductionCaptionSize({ identity, document, disabled, onChanged
10
10
  const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
11
11
  const [preview, setPreview] = useState<number>()
12
12
  const percent = Math.round(captionScale(document.production) * 100)
13
- return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
13
+ // `document` has its inherited settings filled in; the source says whether the size is the document's own.
14
+ const own = useWorkbenchState(state => state.authoring?.identity === identity ? state.authoring.content?.production.captions?.scale !== undefined : true)
15
+ const inherits = useWorkbenchState(state => state.authoring?.identity === identity && state.authoring.inherited?.production?.captions?.scale !== undefined)
16
+ const inheritedFrom = useInheritedFrom('production.captions'), tt = useTreeMessages()
17
+ return <PmField label={p.captionSize} group hint={own || !inheritedFrom ? p.captionSizeHint : `${inheritedFrom} · ${p.captionSizeHint}`}>
14
18
  <div className="pm-ui-range-row">
15
19
  <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
20
  onPreviewChange={setPreview} onValueCommit={value => { workbench.production.setCaptionScale(value / 100, identity); onChanged() }} />
17
21
  <output>{Math.round(preview ?? percent)}%</output>
22
+ {own && inherits && <PmButton small variant="text" disabled={disabled} onClick={() => { workbench.production.inheritCaptionScale(identity); onChanged() }}>{tt.useInherited}</PmButton>}
18
23
  </div>
19
24
  </PmField>
20
25
  }
@@ -0,0 +1,115 @@
1
+ import { useEffect, useState } from 'react'
2
+ import type { DocumentCitation, DocumentLinks, OutgoingLink } from '@lincyaw/kernel/contracts'
3
+ import { PmBacklinkItem, PmButton, PmIcon, PmNotice, PmSkeleton } from '../components.tsx'
4
+ import { useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
+
6
+ type Links = { state: 'loading' } | { state: 'failed' } | { state: 'unavailable' } | { state: 'ready', links: DocumentLinks }
7
+
8
+ /** The open document's links (`document/links`), read again when it is saved or the tree changes. */
9
+ export function useDocumentLinks(): { links: Links, retry(): void } {
10
+ const workbench = useWorkbench()
11
+ const id = useWorkbenchState(state => state.authoring?.content?.id)
12
+ const version = useWorkbenchState(state => state.authoring?.version)
13
+ const tree = useWorkbenchState(state => state.documentTree)
14
+ const [links, setLinks] = useState<Links>({ state: 'loading' })
15
+ const [attempt, setAttempt] = useState(0)
16
+ useEffect(() => {
17
+ if (!id) return
18
+ if (!workbench.client.readDocumentLinks) { setLinks({ state: 'unavailable' }); return }
19
+ const controller = new AbortController()
20
+ setLinks(current => current.state === 'ready' && current.links.document === id ? current : { state: 'loading' })
21
+ workbench.client.readDocumentLinks(id, controller.signal).then(answer => setLinks({ state: 'ready', links: answer }), () => { if (!controller.signal.aborted) setLinks({ state: 'failed' }) })
22
+ return () => controller.abort()
23
+ }, [workbench, id, version, tree, attempt])
24
+ return { links, retry: () => setAttempt(n => n + 1) }
25
+ }
26
+
27
+ /** The places one document cites this one, together, in the order the service gives them. */
28
+ function groupCitations(citations: readonly DocumentCitation[]): { document: string, title: string, citations: DocumentCitation[] }[] {
29
+ const groups = new Map<string, { document: string, title: string, citations: DocumentCitation[] }>()
30
+ for (const citation of citations) {
31
+ let group = groups.get(citation.document)
32
+ if (!group) groups.set(citation.document, group = { document: citation.document, title: citation.title, citations: [] })
33
+ group.citations.push(citation)
34
+ }
35
+ return [...groups.values()]
36
+ }
37
+
38
+ /** Several references to one target are one row with their count. */
39
+ function sameTargets(links: readonly OutgoingLink[]): { link: OutgoingLink, count: number }[] {
40
+ const rows = new Map<string, { link: OutgoingLink, count: number }>()
41
+ for (const link of links) {
42
+ const key = JSON.stringify([link.target.document, link.target.section ?? '', link.target.block ?? ''])
43
+ const row = rows.get(key)
44
+ if (row) row.count++
45
+ else rows.set(key, { link, count: 1 })
46
+ }
47
+ return [...rows.values()]
48
+ }
49
+
50
+ function OutgoingItem({ link, count }: { link: OutgoingLink, count: number }) {
51
+ const t = useTreeMessages()
52
+ const workbench = useWorkbench()
53
+ const gone = link.missing || link.trashed
54
+ return <li>
55
+ <button type="button" className="pm-ui-nav-item pmw-references__link" title={link.title} disabled={link.missing} aria-disabled={gone || undefined} onClick={() => void workbench.tree.openPlace(link.target)}>
56
+ <PmIcon name={link.kind === 'embed' ? 'synced' : 'document'} />
57
+ <span className="pmw-references__title">{link.title}</span>
58
+ {gone ? <span className="pm-ui-nav-item__count">{link.missing ? t.missingTarget : t.trashedTarget}</span> : count > 1 && <span className="pm-ui-nav-item__count">{t.placeCount(count)}</span>}
59
+ </button>
60
+ </li>
61
+ }
62
+
63
+ /** Who cites this document (with the sentence around it), what it references, and the synced blocks it shows. */
64
+ export function ReferencesPanel() {
65
+ return <ReferencesView read={useDocumentLinks()} />
66
+ }
67
+
68
+ function ReferencesView({ read }: { read: ReturnType<typeof useDocumentLinks> }) {
69
+ const t = useTreeMessages()
70
+ const workbench = useWorkbench()
71
+ const { links, retry } = read
72
+ if (links.state === 'loading') return <div className="pmw-references"><PmSkeleton shape="list" label={t.referencesLoading} /></div>
73
+ if (links.state === 'unavailable') return <div className="pmw-references"><p className="pmw-muted">{t.referencesUnavailable}</p></div>
74
+ if (links.state === 'failed') return <div className="pmw-references"><PmNotice tone="danger" action={<PmButton small onClick={retry}>{t.retry}</PmButton>}>{t.referencesFailed}</PmNotice></div>
75
+ const { incoming, outgoing } = links.links
76
+ const references = sameTargets(outgoing.filter(link => link.kind === 'reference'))
77
+ const synced = sameTargets(outgoing.filter(link => link.kind === 'embed'))
78
+ return (
79
+ <div className="pmw-references">
80
+ <section className="pmw-references__group" aria-labelledby="pmw-references-incoming">
81
+ <h3 className="pmw-references__heading" id="pmw-references-incoming">{t.citedBy} · {incoming.length}</h3>
82
+ {incoming.length ? <ul className="pmw-references__list">{groupCitations(incoming).map(group => (
83
+ <li key={group.document}>
84
+ <PmBacklinkItem title={group.title} count={group.citations.length > 1 ? t.placeCount(group.citations.length) : undefined} syncedLabel={t.syncedLabel}
85
+ places={group.citations.map((citation, index) => ({ id: String(index), excerpt: citation.excerpt, synced: citation.kind === 'embed',
86
+ meta: group.citations.length > 1 ? `${citation.kind === 'embed' ? t.syncedLabel : t.referenceLabel} · ${t.placeIndex(index + 1)}` : undefined }))}
87
+ onActivate={id => { const citation = group.citations[Number(id)]!; void workbench.tree.openPlace({ document: citation.document, ...citation.section ? { section: citation.section } : {}, block: citation.block }) }} />
88
+ </li>
89
+ ))}</ul> : <p className="pmw-muted">{t.noCitations}</p>}
90
+ </section>
91
+ <section className="pmw-references__group" aria-labelledby="pmw-references-outgoing">
92
+ <h3 className="pmw-references__heading" id="pmw-references-outgoing">{t.outgoing} · {references.length}</h3>
93
+ {references.length ? <ul className="pmw-references__links">{references.map(({ link, count }, index) => <OutgoingItem key={index} link={link} count={count} />)}</ul> : <p className="pmw-muted">{t.noOutgoing}</p>}
94
+ </section>
95
+ <section className="pmw-references__group" aria-labelledby="pmw-references-synced">
96
+ <h3 className="pmw-references__heading" id="pmw-references-synced">{t.syncedBlocks} · {synced.length}</h3>
97
+ {synced.length ? <ul className="pmw-references__links">{synced.map(({ link, count }, index) => <OutgoingItem key={index} link={link} count={count} />)}</ul> : <p className="pmw-muted">{t.noSynced}</p>}
98
+ </section>
99
+ </div>
100
+ )
101
+ }
102
+
103
+ /** On a narrow screen the references are one collapsed row at the end of the document. */
104
+ export function ReferencesSummary() {
105
+ const t = useTreeMessages()
106
+ const read = useDocumentLinks()
107
+ const links = read.links
108
+ if (links.state !== 'ready') return null
109
+ return (
110
+ <details className="pmw-references-summary">
111
+ <summary className="pmw-references-summary__row">{t.referencesSummary(links.links.incoming.length, links.links.outgoing.filter(link => link.kind === 'reference').length)}<PmIcon name="chevron-right" /></summary>
112
+ <ReferencesView read={read} />
113
+ </details>
114
+ )
115
+ }
@@ -1,7 +1,9 @@
1
1
  import { useEffect, useMemo, useRef } from 'react'
2
+ import type { ReactNode } from 'react'
2
3
  import { hasRole } from '@lincyaw/kernel'
3
4
  import { PmButton, PmNotice, PmSkeleton } from '../components.tsx'
4
- import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
+ import { useMessages, useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
6
+ import { DocumentReference, insertSyncedBlock, parseSyncedLink, ReferenceEditorTools, referenceSlashItems, SyncedBlock } from '../document-editor/references.tsx'
5
7
  import { DocumentEditor } from '../document-editor/DocumentEditor.tsx'
6
8
  import { DOCUMENT_EDITOR_MESSAGES } from '../document-editor/messages.ts'
7
9
  import { DocumentBlockFallback } from '../document-editor/DocumentBlockFallback.tsx'
@@ -13,7 +15,7 @@ import { isAgentChanging } from '../workbench-state.ts'
13
15
  import { effectiveOf } from '../effective-settings.ts'
14
16
 
15
17
  /** Source editing is available before the first successful runtime compilation. */
16
- export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void }) {
18
+ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onOpenComments, after }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void, onOpenComments?(): void, /** Shown below the page (the references on a narrow screen). */ after?: ReactNode }) {
17
19
  const workbench = useWorkbench(), t = useMessages()
18
20
  const source = useWorkbenchState(state => state.authoring)
19
21
  const activities = useWorkbenchState(state => state.agentActivities)
@@ -25,6 +27,8 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
25
27
  }
26
28
  const positionFailure = useWorkbenchState(state => state.documentPositionFailure)
27
29
  const locale = useWorkbenchState(state => state.locale), messages = DOCUMENT_EDITOR_MESSAGES[locale]
30
+ const tt = useTreeMessages()
31
+ const syncedPicker = useMemo<{ open?: (editor: NativeDocumentEditor) => void }>(() => ({}), [])
28
32
  const navigation = useWorkbenchState(state => state.documentNavigation)
29
33
  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))
30
34
  const container = useRef<HTMLElement>(null)
@@ -180,7 +184,20 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
180
184
  const effective = effectiveOf(source.content, source.inherited)
181
185
  const fallback = <DocumentBlockFallback block={block} document={effective} locale={locale} />
182
186
  return hasBlockPreview(block, effective.metadata.plugins) ? <DocumentBlockPreview blockId={id} fallback={fallback} /> : fallback
183
- } }}
187
+ },
188
+ renderReference: (target, label, fallback) => <DocumentReference document={target.document} section={target.section} block={target.block} label={label} fallback={fallback} />,
189
+ renderEmbed: (id, embed) => <SyncedBlock id={id} document={embed.document} block={embed.block} />,
190
+ ...workbench.tree.available ? {
191
+ slashItems: editor => readOnly ? [] : referenceSlashItems(editor, tt, tt.documents, workbench, () => syncedPicker.open?.(editor)),
192
+ editorChildren: editor => readOnly ? null : <ReferenceEditorTools editor={editor} picker={syncedPicker} />,
193
+ pasteText: (text, editor) => {
194
+ const source = parseSyncedLink(text)
195
+ if (!source || readOnly) return false
196
+ insertSyncedBlock(editor, source)
197
+ return true
198
+ },
199
+ copySyncedLink: link => { void navigator.clipboard.writeText(link).then(() => workbench.tree.toast(tt.linkCopied), () => workbench.tree.toast(tt.copyFailed, 'danger')) },
200
+ } : {} }}
184
201
  commentsPortal={commentsPortal} onChange={document => workbench.recordDocument(document)} onReady={(editor, commands) => {
185
202
  bodyEditor.current = editor
186
203
  editingPosition.current = undefined
@@ -195,5 +212,6 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore, onO
195
212
  }}
196
213
  onComposition={composing => workbench.documentComposition(composing, 'body', source.identity)} onError={() => workbench.documentError(new Error(messages.adapterError))} />
197
214
  </div>}
215
+ {source?.content && after}
198
216
  </section>
199
217
  }
@@ -0,0 +1,109 @@
1
+ import { useState } from 'react'
2
+ import type { ReactNode } from 'react'
3
+ import { PmButton, PmCard, PmIcon, PmNotice } from '../components.tsx'
4
+ import { useMessages, useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
5
+ import { IMPORT_MESSAGES } from '../import-messages.ts'
6
+ import { timeAgo } from '../messages.ts'
7
+ import { DocumentImportDialog } from './DocumentImportDialog.tsx'
8
+ import { MaterialsDialog } from './MaterialsDialog.tsx'
9
+ import { SearchDialog } from './WorkspaceSidebar.tsx'
10
+
11
+ /**
12
+ * The workspace's home when it has a document tree: start a document (blank or imported), what needs attention, and
13
+ * the documents opened recently. The tree in the sidebar is the way to every other document.
14
+ */
15
+ export function WorkspaceHome({ actions }: { actions?: ReactNode }) {
16
+ const t = useMessages()
17
+ const tt = useTreeMessages()
18
+ const workbench = useWorkbench()
19
+ const answer = useWorkbenchState(state => state.documents)
20
+ const tree = useWorkbenchState(state => state.documentTree)!
21
+ const recent = useWorkbenchState(state => state.recentDocuments ?? [])
22
+ const locale = useWorkbenchState(state => state.locale)
23
+ const busy = useWorkbenchState(state => Boolean(state.isDocumentTreeBusy))
24
+ const failure = useWorkbenchState(state => state.documentsFailure)
25
+ const attention = useWorkbenchState(state => state.workspaceAttention)
26
+ const canAskAgent = useWorkbenchState(state => Boolean(state.canAskAgent))
27
+ const needsModel = useWorkbenchState(state => state.agentReadiness === 'missing')
28
+ const importMessages = IMPORT_MESSAGES[locale]
29
+ const [importing, setImporting] = useState(false)
30
+ const [searching, setSearching] = useState(false)
31
+ const [upgrading, setUpgrading] = useState(false)
32
+ const [writing, setWriting] = useState(false)
33
+ const readOnly = workbench.client.capabilities?.readOnly === true
34
+ const canImport = Boolean(answer?.git && !answer.single && workbench.client.importDocuments && !readOnly)
35
+ // Only the AI writes from source material: without a conversation there is no card, without a model it says so.
36
+ const canWrite = Boolean(canAskAgent && !answer?.single && workbench.client.addDocumentMaterials && workbench.tree.available && !readOnly)
37
+ const count = Object.keys(tree.nodes).length
38
+ const issues = Object.values(tree.nodes).filter(node => node.issues?.length)
39
+ const pending = answer?.migration?.documents.length ?? 0
40
+ const shown = recent.filter(entry => tree.nodes[entry.id]).slice(0, 8)
41
+ const { references: brokenReferences, embeds: brokenSynced } = attention ?? {}
42
+ const create = () => void workbench.tree.create(null)
43
+ const upgrade = async () => {
44
+ setUpgrading(true)
45
+ try { workbench.tree.toast(tt.upgraded((await workbench.migrateWorkspace()).documents.length)) } catch { workbench.tree.toast(tt.operationFailed(tt.failureGeneric), 'danger') } finally { setUpgrading(false) }
46
+ }
47
+ return (
48
+ <section className="pmw-home pmw-workspace-home" aria-labelledby="pmw-home-title">
49
+ <header className="pmw-home__bar">
50
+ <h1 id="pmw-home-title" className="pmw-home__title">{answer?.title ?? t.documents}</h1>
51
+ {actions}
52
+ {canImport && <PmButton icon="upload" onClick={() => setImporting(true)}>{importMessages.title}</PmButton>}
53
+ {!readOnly && <PmButton variant="primary" icon="plus" loading={busy} onClick={create}>{tt.newDocument}</PmButton>}
54
+ </header>
55
+ <p className="pmw-muted pmw-workspace-home__meta">{tt.documentCount(count)}</p>
56
+ {failure && <PmNotice tone="danger">{failure}</PmNotice>}
57
+ {!readOnly && <ul className="pmw-workspace-home__start">
58
+ <li><PmCard variant="interactive">
59
+ <span className="pm-ui-card__icon"><PmIcon name="document" /></span>
60
+ <button type="button" className="pm-ui-card__cover" disabled={busy} onClick={create}>{tt.blankDocument}</button>
61
+ <p className="pm-ui-card__hint">{tt.blankDocumentHint}</p>
62
+ </PmCard></li>
63
+ {canImport && <li><PmCard variant="interactive">
64
+ <span className="pm-ui-card__icon"><PmIcon name="upload" /></span>
65
+ <button type="button" className="pm-ui-card__cover" onClick={() => setImporting(true)}>{importMessages.title}</button>
66
+ <p className="pm-ui-card__hint">{tt.importHint}</p>
67
+ </PmCard></li>}
68
+ {canWrite && <li><PmCard variant="interactive">
69
+ <span className="pm-ui-card__icon"><PmIcon name="sparkle" /></span>
70
+ <button type="button" className="pm-ui-card__cover" disabled={busy} onClick={() => needsModel ? workbench.openAgentSetup() : setWriting(true)}>{tt.fromMaterials}</button>
71
+ <p className="pm-ui-card__hint">{needsModel ? tt.fromMaterialsNeedsModel : tt.fromMaterialsHint}</p>
72
+ </PmCard></li>}
73
+ </ul>}
74
+ {(pending > 0 || issues.length > 0 || brokenReferences || brokenSynced) && <>
75
+ <div className="pmw-home__heading-row"><h2 className="pmw-home__heading">{tt.needsAttention}</h2></div>
76
+ <div className="pmw-workspace-home__attention">
77
+ {pending > 0 && workbench.client.migrateWorkspace && <PmNotice tone="warn" action={<PmButton small loading={upgrading} onClick={() => void upgrade()}>{tt.upgrade}</PmButton>}>{tt.upgradePending(pending)}</PmNotice>}
78
+ {issues.length > 0 && <PmNotice tone="warn" action={<PmButton small onClick={() => void workbench.tree.openPlace({ document: issues[0]!.id })}>{tt.show}</PmButton>}>{tt.treeIssues(issues.length)}</PmNotice>}
79
+ {brokenReferences && <PmNotice tone="warn" action={<PmButton small onClick={() => void workbench.tree.openPlace(brokenReferences.first)}>{tt.show}</PmButton>}>{tt.brokenReferences(brokenReferences.places, brokenReferences.documents)}</PmNotice>}
80
+ {brokenSynced && <PmNotice tone="warn" action={<PmButton small onClick={() => void workbench.tree.openPlace(brokenSynced.first)}>{tt.show}</PmButton>}>{tt.brokenSynced(brokenSynced.places, brokenSynced.documents)}</PmNotice>}
81
+ </div>
82
+ </>}
83
+ <div className="pmw-home__heading-row">
84
+ <h2 className="pmw-home__heading">{tt.recent}</h2>
85
+ {count > 0 && <PmButton small variant="text" onClick={() => setSearching(true)}>{tt.searchTitle}</PmButton>}
86
+ </div>
87
+ {shown.length === 0
88
+ ? <p className="pmw-muted">{count === 0 && !pending ? tt.treeEmpty : tt.recentEmpty}</p>
89
+ : <ul className="pmw-home__cards" aria-label={tt.recent}>
90
+ {shown.map(entry => {
91
+ const node = tree.nodes[entry.id]!
92
+ return <li key={entry.id} className="pmw-home__card">
93
+ <button type="button" className="pmw-home__open" onClick={() => void workbench.tree.openPlace({ document: entry.id })}>
94
+ <span className="pmw-home__doc-icon" aria-hidden="true"><PmIcon name="document" /></span>
95
+ <span className="pmw-home__doc-title">{node.title || tt.untitled}</span>
96
+ <span className="pmw-workspace-home__path">{workbench.tree.ancestors(entry.id).map(item => item.title).join(' › ')}</span>
97
+ <span className="pmw-workspace-home__time">{timeAgo(entry.at, locale)}</span>
98
+ </button>
99
+ </li>
100
+ })}
101
+ </ul>}
102
+ {importing && <DocumentImportDialog onClose={() => setImporting(false)} onImported={result => {
103
+ setImporting(false); workbench.tree.toast(importMessages.done(result.documents.length, result.unresolved, result.warnings)); void workbench.tree.load()
104
+ }} />}
105
+ {writing && <MaterialsDialog onClose={() => setWriting(false)} />}
106
+ {searching && <SearchDialog onClose={() => setSearching(false)} onOpen={(id, section, block) => { setSearching(false); void workbench.tree.openPlace({ document: id, ...section ? { section } : {}, ...block ? { block } : {} }) }} />}
107
+ </section>
108
+ )
109
+ }