@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.
- package/package.json +4 -4
- package/src/StepProductionEditor.tsx +13 -8
- package/src/components.tsx +24 -4
- package/src/context.tsx +30 -0
- package/src/document-editor/BlockNoteSurface.tsx +4 -1
- package/src/document-editor/DocumentBlockFallback.tsx +0 -1
- package/src/document-editor/DocumentEditor.tsx +7 -1
- package/src/document-editor/DocumentStepNarration.tsx +4 -2
- package/src/document-editor/authoring.tsx +15 -0
- package/src/document-editor/inline.ts +5 -0
- package/src/document-editor/insertion-place.ts +2 -2
- package/src/document-editor/messages.ts +2 -2
- package/src/document-editor/projection.ts +6 -4
- package/src/document-editor/references.tsx +352 -0
- package/src/document-editor/schema.tsx +39 -2
- package/src/document-editor/style.css +10 -0
- package/src/document-production.ts +8 -0
- package/src/document-session.ts +5 -3
- package/src/document-tree.ts +271 -0
- package/src/import-messages.ts +1 -1
- package/src/index.ts +6 -1
- package/src/knowledge-components.tsx +574 -0
- package/src/knowledge.css +354 -0
- package/src/messages.ts +12 -0
- package/src/panels/DocumentPeekPanel.tsx +190 -0
- package/src/panels/DocumentView.tsx +46 -23
- package/src/panels/DocumentVoiceField.tsx +3 -2
- package/src/panels/HomePanel.tsx +12 -3
- package/src/panels/MaterialsDialog.tsx +67 -0
- package/src/panels/ProductionCaptionSize.tsx +8 -3
- package/src/panels/ReferencesPanel.tsx +115 -0
- package/src/panels/SourceDocumentPanel.tsx +21 -3
- package/src/panels/WorkspaceHome.tsx +109 -0
- package/src/panels/WorkspaceSidebar.tsx +331 -0
- package/src/styles.css +20 -0
- package/src/tree-messages.ts +345 -0
- package/src/workbench-state.ts +21 -0
- package/src/workbench.ts +76 -3
- package/src/workspace-client.ts +35 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import type { DocumentSearchHit, DocumentTree, TrashEntry } from '@lincyaw/kernel/contracts'
|
|
3
|
+
import { PmButton, PmDialog, PmDocTree, PmEmpty, PmIcon, PmIconButton, PmNotice, PmPopover, PmSearchList, PmSelect, PmSkeleton, PmToast } from '../components.tsx'
|
|
4
|
+
import type { DocTreeNode, MenuItem } from '../components.tsx'
|
|
5
|
+
import { useTreeMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
|
+
import { timeAgo } from '../messages.ts'
|
|
7
|
+
|
|
8
|
+
/** Typing waits this long before it searches; the previous results stay while the next arrive. */
|
|
9
|
+
const SEARCH_DEBOUNCE = 100
|
|
10
|
+
|
|
11
|
+
export interface DocumentTreeView {
|
|
12
|
+
roots: string[]
|
|
13
|
+
nodes: Record<string, DocTreeNode>
|
|
14
|
+
/** The tree comes from the workspace's tree route and can be changed; otherwise it is read from the document list. */
|
|
15
|
+
editable: boolean
|
|
16
|
+
trash: TrashEntry[]
|
|
17
|
+
loading: boolean
|
|
18
|
+
failed: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The tree to draw: the workspace's, or (on a host without one) the document list's parents. */
|
|
22
|
+
export function useDocumentTreeView(): DocumentTreeView {
|
|
23
|
+
const tree = useWorkbenchState(state => state.documentTree)
|
|
24
|
+
const failure = useWorkbenchState(state => state.documentTreeFailure)
|
|
25
|
+
const loading = useWorkbenchState(state => Boolean(state.isDocumentTreeLoading))
|
|
26
|
+
const documents = useWorkbenchState(state => state.documents)
|
|
27
|
+
const t = useTreeMessages()
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
if (tree) return { ...fromTree(tree, t.treeIssue), editable: true, trash: tree.trash, loading: false, failed: false }
|
|
30
|
+
const list = documents?.documents ?? []
|
|
31
|
+
const nodes: Record<string, DocTreeNode> = {}
|
|
32
|
+
const roots: string[] = []
|
|
33
|
+
for (const doc of list) nodes[doc.id ?? doc.dir] = { id: doc.id ?? doc.dir, title: doc.title, children: [] }
|
|
34
|
+
for (const doc of list) {
|
|
35
|
+
const id = doc.id ?? doc.dir
|
|
36
|
+
const parent = doc.parent ? nodes[doc.parent] : undefined
|
|
37
|
+
if (parent) (parent.children as string[]).push(id); else roots.push(id)
|
|
38
|
+
}
|
|
39
|
+
return { roots, nodes, editable: false, trash: [], loading: loading || (!documents && !failure), failed: Boolean(failure && failure !== 'tree-unavailable' && !documents) }
|
|
40
|
+
}, [tree, documents, failure, loading, t])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function fromTree(tree: DocumentTree, issue: string): { roots: string[], nodes: Record<string, DocTreeNode> } {
|
|
44
|
+
const nodes: Record<string, DocTreeNode> = {}
|
|
45
|
+
for (const node of Object.values(tree.nodes)) nodes[node.id] = { id: node.id, title: node.title, children: node.children, ...node.issues?.length ? { warning: issue } : {} }
|
|
46
|
+
return { roots: tree.roots, nodes }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The workspace's sidebar: its name, search (Ctrl+K), Home, Recent, the document tree with New Document, and the
|
|
51
|
+
* trash. `onNavigate` closes a drawer that holds it.
|
|
52
|
+
*/
|
|
53
|
+
export function WorkspaceSidebar({ onHome, onNavigate, closeLabel, onClose }: { onHome(): void, onNavigate?(): void, closeLabel?: string, onClose?(): void }) {
|
|
54
|
+
const t = useTreeMessages()
|
|
55
|
+
const workbench = useWorkbench()
|
|
56
|
+
const view = useDocumentTreeView()
|
|
57
|
+
const title = useWorkbenchState(state => state.documents?.title)
|
|
58
|
+
const open = useWorkbenchState(state => state.document)
|
|
59
|
+
const renaming = useWorkbenchState(state => state.renamingDocument)
|
|
60
|
+
const busy = useWorkbenchState(state => Boolean(state.isDocumentTreeBusy))
|
|
61
|
+
const readOnly = workbench.client.capabilities?.readOnly === true
|
|
62
|
+
const atHome = open === undefined
|
|
63
|
+
const selected = workbench.tree.idOf(open)
|
|
64
|
+
const [expanded, setExpanded] = useState<ReadonlySet<string>>(() => new Set())
|
|
65
|
+
const [searching, setSearching] = useState(false)
|
|
66
|
+
const [trashOpen, setTrashOpen] = useState(false)
|
|
67
|
+
const [moving, setMoving] = useState<string>()
|
|
68
|
+
const [recentOpen, setRecentOpen] = useState(false)
|
|
69
|
+
const editable = view.editable && !readOnly
|
|
70
|
+
const labels = useMemo(() => ({ expand: t.expand, collapse: t.collapse, newChild: t.newChildIn, more: t.more, renameField: t.renameField, untitled: t.untitled }), [t])
|
|
71
|
+
const count = Object.keys(view.nodes).length
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const key = (event: KeyboardEvent) => {
|
|
75
|
+
if (event.defaultPrevented || event.isComposing || !(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== 'k') return
|
|
76
|
+
event.preventDefault()
|
|
77
|
+
setSearching(true)
|
|
78
|
+
}
|
|
79
|
+
window.addEventListener('keydown', key)
|
|
80
|
+
return () => window.removeEventListener('keydown', key)
|
|
81
|
+
}, [])
|
|
82
|
+
|
|
83
|
+
const openDocument = (id: string) => { void workbench.tree.openPlace({ document: id }); onNavigate?.() }
|
|
84
|
+
const menu = (id: string): MenuItem[] => [
|
|
85
|
+
{ id: 'rename', label: t.rename, icon: 'edit', disabled: busy },
|
|
86
|
+
{ id: 'child', label: t.newChild, icon: 'document-add', disabled: busy },
|
|
87
|
+
{ id: 'duplicate', label: t.duplicate, icon: 'copy', disabled: busy },
|
|
88
|
+
{ id: 'move', label: t.moveTo, icon: 'move', disabled: busy || count < 2 },
|
|
89
|
+
{ id: 'trash', label: t.moveToTrash, icon: 'trash', danger: true, separator: true, disabled: busy },
|
|
90
|
+
]
|
|
91
|
+
const onMenu = (id: string, action: string) => {
|
|
92
|
+
if (action === 'rename') workbench.tree.startRenaming(id)
|
|
93
|
+
else if (action === 'child') void createChild(id)
|
|
94
|
+
else if (action === 'duplicate') void workbench.tree.duplicate(id)
|
|
95
|
+
else if (action === 'move') setMoving(id)
|
|
96
|
+
else if (action === 'trash') void workbench.tree.trash(id)
|
|
97
|
+
}
|
|
98
|
+
const createChild = async (parent: string | null) => {
|
|
99
|
+
if (parent) setExpanded(current => new Set(current).add(parent))
|
|
100
|
+
await workbench.tree.create(parent)
|
|
101
|
+
onNavigate?.()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<nav className="pmw-sidebar" aria-label={t.sidebar}>
|
|
106
|
+
<header className="pmw-sidebar__header">
|
|
107
|
+
<span className="pmw-sidebar__mark" aria-hidden="true">{(title ?? '').trim().slice(0, 1) || <PmIcon name="folder" />}</span>
|
|
108
|
+
<span className="pmw-sidebar__workspace">
|
|
109
|
+
<span className="pmw-sidebar__name" title={title}>{title ?? ''}</span>
|
|
110
|
+
<span className="pmw-sidebar__meta">{t.documentCount(count)}</span>
|
|
111
|
+
</span>
|
|
112
|
+
{onClose && closeLabel && <PmIconButton icon="close" small label={closeLabel} onClick={onClose} />}
|
|
113
|
+
</header>
|
|
114
|
+
<button type="button" className="pm-ui-search-trigger pmw-sidebar__search" onClick={() => setSearching(true)}>
|
|
115
|
+
<PmIcon name="search" /><span className="pm-ui-search-trigger__label">{t.search}</span><kbd className="pm-ui-shortcut">{t.searchShortcut}</kbd>
|
|
116
|
+
</button>
|
|
117
|
+
<ul className="pmw-sidebar__places">
|
|
118
|
+
<li><button type="button" className="pm-ui-nav-item" aria-current={atHome ? 'page' : undefined} onClick={() => { onHome(); onNavigate?.() }}><PmIcon name="home" />{t.home}</button></li>
|
|
119
|
+
<li>
|
|
120
|
+
<PmPopover open={recentOpen} label={t.recent} placement="below-start" onOpenChange={setRecentOpen}
|
|
121
|
+
trigger={<button type="button" className="pm-ui-nav-item" aria-expanded={recentOpen}><PmIcon name="recent" />{t.recent}</button>}>
|
|
122
|
+
<RecentList onOpen={id => { setRecentOpen(false); openDocument(id) }} />
|
|
123
|
+
</PmPopover>
|
|
124
|
+
</li>
|
|
125
|
+
</ul>
|
|
126
|
+
<div className="pmw-sidebar__section">
|
|
127
|
+
<h2 className="pmw-sidebar__heading" id="pmw-sidebar-tree">{t.documents}</h2>
|
|
128
|
+
{editable && <PmIconButton icon="plus" small label={t.newDocument} loading={busy} onClick={() => void createChild(null)} />}
|
|
129
|
+
</div>
|
|
130
|
+
<div className="pmw-sidebar__tree">
|
|
131
|
+
{view.loading ? <PmSkeleton shape="list" label={t.treeLoading} />
|
|
132
|
+
: view.failed ? <PmNotice tone="danger" action={<PmButton small onClick={() => void workbench.loadDocuments()}>{t.retry}</PmButton>}>{t.treeFailed}</PmNotice>
|
|
133
|
+
: view.roots.length === 0 ? <MigrationOrEmpty />
|
|
134
|
+
: <PmDocTree
|
|
135
|
+
label={t.tree}
|
|
136
|
+
roots={view.roots}
|
|
137
|
+
nodes={view.nodes}
|
|
138
|
+
selected={selected}
|
|
139
|
+
expanded={expanded}
|
|
140
|
+
onExpandedChange={(id, next) => setExpanded(current => { const value = new Set(current); if (next) value.add(id); else value.delete(id); return value })}
|
|
141
|
+
onOpen={openDocument}
|
|
142
|
+
labels={labels}
|
|
143
|
+
renaming={renaming}
|
|
144
|
+
onRenamingChange={id => workbench.tree.startRenaming(id)}
|
|
145
|
+
disabled={!editable}
|
|
146
|
+
{...editable ? {
|
|
147
|
+
onRename: (id: string, value: string) => void workbench.tree.rename(id, value),
|
|
148
|
+
onCreateChild: (id: string) => void createChild(id),
|
|
149
|
+
onTrash: (id: string) => void workbench.tree.trash(id),
|
|
150
|
+
onMove: (id: string, parent: string | null, after: string | null) => void workbench.tree.move(id, parent, after),
|
|
151
|
+
menu, onMenu,
|
|
152
|
+
} : {}}
|
|
153
|
+
/>}
|
|
154
|
+
</div>
|
|
155
|
+
{view.editable && <button type="button" className="pm-ui-nav-item pmw-sidebar__trash" onClick={() => setTrashOpen(true)}>
|
|
156
|
+
<PmIcon name="trash" />{t.trash}{view.trash.length > 0 && <span className="pm-ui-nav-item__count">{view.trash.length}</span>}
|
|
157
|
+
</button>}
|
|
158
|
+
{searching && <SearchDialog onClose={() => setSearching(false)} onOpen={(id, section, block) => { setSearching(false); void workbench.tree.openPlace({ document: id, ...section ? { section } : {}, ...block ? { block } : {} }); onNavigate?.() }} />}
|
|
159
|
+
{trashOpen && <TrashDialog entries={view.trash} onClose={() => setTrashOpen(false)} />}
|
|
160
|
+
{moving && <MoveDialog id={moving} view={view} onClose={() => setMoving(undefined)} />}
|
|
161
|
+
</nav>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** While documents wait for the upgrade the list is not empty: it says how many and offers Upgrade. */
|
|
166
|
+
function MigrationOrEmpty() {
|
|
167
|
+
const t = useTreeMessages()
|
|
168
|
+
const workbench = useWorkbench()
|
|
169
|
+
const migration = useWorkbenchState(state => state.documents?.migration)
|
|
170
|
+
const [working, setWorking] = useState(false)
|
|
171
|
+
if (migration?.documents.length && workbench.client.migrateWorkspace) return <PmNotice tone="warn" action={<PmButton small loading={working} onClick={async () => {
|
|
172
|
+
setWorking(true)
|
|
173
|
+
try { const answer = await workbench.migrateWorkspace(); workbench.tree.toast(t.upgraded(answer.documents.length)) } catch { workbench.tree.toast(t.operationFailed(t.failureGeneric), 'danger') } finally { setWorking(false) }
|
|
174
|
+
}}>{t.upgrade}</PmButton>}>{t.upgradePending(migration.documents.length)}</PmNotice>
|
|
175
|
+
return <p className="pmw-muted pmw-sidebar__empty">{t.treeEmpty}</p>
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function RecentList({ onOpen }: { onOpen(id: string): void }) {
|
|
179
|
+
const t = useTreeMessages()
|
|
180
|
+
const workbench = useWorkbench()
|
|
181
|
+
const recent = useWorkbenchState(state => state.recentDocuments ?? [])
|
|
182
|
+
const locale = useWorkbenchState(state => state.locale)
|
|
183
|
+
useWorkbenchState(state => state.documentTree)
|
|
184
|
+
const known = recent.filter(entry => workbench.tree.title(entry.id) !== undefined)
|
|
185
|
+
if (!known.length) return <p className="pmw-muted pmw-recent__empty">{t.recentEmpty}</p>
|
|
186
|
+
return <ul className="pmw-recent">{known.map(entry => (
|
|
187
|
+
<li key={entry.id}><button type="button" className="pm-ui-nav-item pmw-recent__item" onClick={() => onOpen(entry.id)}>
|
|
188
|
+
<PmIcon name="document" /><span className="pmw-recent__title" title={workbench.tree.title(entry.id)}>{workbench.tree.title(entry.id)}</span>
|
|
189
|
+
<span className="pmw-recent__path">{workbench.tree.ancestors(entry.id).map(item => item.title).join(' › ')}</span>
|
|
190
|
+
<span className="pmw-recent__time">{timeAgo(entry.at, locale)}</span>
|
|
191
|
+
</button></li>
|
|
192
|
+
))}</ul>
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Search across the workspace's titles and text (`documents/search`); Enter opens the result at its place. */
|
|
196
|
+
export function SearchDialog({ onClose, onOpen }: { onClose(): void, onOpen(id: string, section?: string, block?: string): void }) {
|
|
197
|
+
const t = useTreeMessages()
|
|
198
|
+
const workbench = useWorkbench()
|
|
199
|
+
const [query, setQuery] = useState('')
|
|
200
|
+
const [hits, setHits] = useState<DocumentSearchHit[]>([])
|
|
201
|
+
const [loading, setLoading] = useState(false)
|
|
202
|
+
const [failed, setFailed] = useState(false)
|
|
203
|
+
const [value, setValue] = useState('')
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
const text = query.trim()
|
|
206
|
+
if (!text || !workbench.client.searchDocuments) { setHits([]); setLoading(false); return }
|
|
207
|
+
const controller = new AbortController()
|
|
208
|
+
setLoading(true); setFailed(false)
|
|
209
|
+
const timer = setTimeout(() => {
|
|
210
|
+
workbench.client.searchDocuments!(text, 20, controller.signal).then(answer => { setHits(answer); setValue(answer[0] ? key(answer[0]) : '') }, () => { if (!controller.signal.aborted) setFailed(true) })
|
|
211
|
+
.finally(() => { if (!controller.signal.aborted) setLoading(false) })
|
|
212
|
+
}, SEARCH_DEBOUNCE)
|
|
213
|
+
return () => { clearTimeout(timer); controller.abort() }
|
|
214
|
+
}, [query, workbench])
|
|
215
|
+
const key = (hit: DocumentSearchHit) => `${hit.id}\0${hit.section ?? ''}\0${hit.block ?? ''}`
|
|
216
|
+
const items = hits.map(hit => ({ value: key(hit), label: hit.title, icon: 'document' as const,
|
|
217
|
+
description: [hit.ancestors.join(' › '), hit.match === 'content' && hit.excerpt ? t.contentMatch(hit.excerpt) : ''].filter(Boolean).join(' · ') }))
|
|
218
|
+
const activate = (selected: string) => {
|
|
219
|
+
const hit = hits.find(item => key(item) === selected)
|
|
220
|
+
if (hit) onOpen(hit.id, hit.section, hit.block)
|
|
221
|
+
}
|
|
222
|
+
return (
|
|
223
|
+
<PmDialog open label={t.searchTitle} closeLabel={t.close} name="pmw-search" onClose={onClose}>
|
|
224
|
+
<PmSearchList label={t.documents} searchLabel={t.searchField} searchPlaceholder={t.searchPlaceholder} items={items} value={value} filter={false}
|
|
225
|
+
query={query} onQueryChange={setQuery} onValueChange={setValue} onActivate={activate} autoFocus
|
|
226
|
+
resultsLabel={t.searchResults} emptyLabel={query.trim() ? t.searchEmpty : ''} loadingLabel={t.searching} loading={loading} error={failed ? t.searchFailed : undefined} />
|
|
227
|
+
</PmDialog>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The trash: restore a document (with its children) or delete it permanently after a warning. */
|
|
232
|
+
function TrashDialog({ entries, onClose }: { entries: TrashEntry[], onClose(): void }) {
|
|
233
|
+
const t = useTreeMessages()
|
|
234
|
+
const workbench = useWorkbench()
|
|
235
|
+
const locale = useWorkbenchState(state => state.locale)
|
|
236
|
+
const busy = useWorkbenchState(state => Boolean(state.isDocumentTreeBusy))
|
|
237
|
+
const [purging, setPurging] = useState<TrashEntry>()
|
|
238
|
+
const readOnly = workbench.client.capabilities?.readOnly === true
|
|
239
|
+
return (
|
|
240
|
+
<PmDialog open label={t.trashTitle} closeLabel={t.close} name="pmw-trash" description={t.trashHint} busy={busy} onClose={onClose}>
|
|
241
|
+
{entries.length === 0 ? <PmEmpty icon="trash" title={t.trashEmpty} />
|
|
242
|
+
: <ul className="pmw-trash">{entries.map(entry => (
|
|
243
|
+
<li key={entry.id} className="pmw-trash__item">
|
|
244
|
+
<PmIcon name="document" />
|
|
245
|
+
<span className="pmw-trash__text">
|
|
246
|
+
<span className="pmw-trash__title">{entry.title}</span>
|
|
247
|
+
<span className="pmw-trash__meta">{[t.deletedAt(timeAgo(entry.deletedAt, locale)), entry.children.length ? t.childCount(entry.children.length) : '', entry.parentTrashed ? t.parentTrashed : ''].filter(Boolean).join(' · ')}</span>
|
|
248
|
+
</span>
|
|
249
|
+
<PmButton small icon="restore" disabled={busy || readOnly} onClick={() => void workbench.tree.restore(entry.id)}>{t.restore}</PmButton>
|
|
250
|
+
<PmButton small variant="text" disabled={busy || readOnly} onClick={() => setPurging(entry)}>{t.deletePermanently}</PmButton>
|
|
251
|
+
</li>
|
|
252
|
+
))}</ul>}
|
|
253
|
+
{purging && <PmDialog open label={t.deletePermanentlyTitle} closeLabel={t.close} busy={busy} onClose={() => setPurging(undefined)}
|
|
254
|
+
footer={<>
|
|
255
|
+
<PmButton disabled={busy} onClick={() => setPurging(undefined)}>{t.cancel}</PmButton>
|
|
256
|
+
<PmButton variant="danger" loading={busy} onClick={async () => { if (await workbench.tree.purge(purging.id)) setPurging(undefined) }}>{t.deleteAction}</PmButton>
|
|
257
|
+
</>}>
|
|
258
|
+
<p>{t.deleteConfirm(purging.title)}</p>
|
|
259
|
+
<PmNotice tone="warn">{t.deleteSynced}</PmNotice>
|
|
260
|
+
</PmDialog>}
|
|
261
|
+
</PmDialog>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Move To…: choose the new parent; the document goes last among its children. */
|
|
266
|
+
function MoveDialog({ id, view, onClose }: { id: string, view: DocumentTreeView, onClose(): void }) {
|
|
267
|
+
const t = useTreeMessages()
|
|
268
|
+
const workbench = useWorkbench()
|
|
269
|
+
const busy = useWorkbenchState(state => Boolean(state.isDocumentTreeBusy))
|
|
270
|
+
const node = view.nodes[id]
|
|
271
|
+
const parentOf = (child: string) => Object.values(view.nodes).find(item => item.children.includes(child))?.id ?? ''
|
|
272
|
+
const [target, setTarget] = useState(parentOf(id))
|
|
273
|
+
const choices = useMemo(() => {
|
|
274
|
+
const list: { id: string, label: string }[] = []
|
|
275
|
+
const visit = (ids: readonly string[], depth: number) => ids.forEach(child => {
|
|
276
|
+
if (child === id) return
|
|
277
|
+
const item = view.nodes[child]
|
|
278
|
+
if (!item) return
|
|
279
|
+
list.push({ id: child, label: `${' '.repeat(depth)}${item.title || t.untitled}` })
|
|
280
|
+
visit(item.children, depth + 1)
|
|
281
|
+
})
|
|
282
|
+
visit(view.roots, 0)
|
|
283
|
+
return list
|
|
284
|
+
}, [view, id, t])
|
|
285
|
+
const select = useRef<HTMLSelectElement>(null)
|
|
286
|
+
if (!node) return null
|
|
287
|
+
return (
|
|
288
|
+
<PmDialog open label={t.moveTitle(node.title)} closeLabel={t.close} busy={busy} onClose={onClose}
|
|
289
|
+
footer={<>
|
|
290
|
+
<PmButton disabled={busy} onClick={onClose}>{t.cancel}</PmButton>
|
|
291
|
+
<PmButton variant="primary" loading={busy} onClick={async () => {
|
|
292
|
+
const parent = target || null
|
|
293
|
+
const siblings = (parent ? view.nodes[parent]?.children ?? [] : view.roots).filter(child => child !== id)
|
|
294
|
+
await workbench.tree.move(id, parent, siblings.at(-1) ?? null)
|
|
295
|
+
onClose()
|
|
296
|
+
}}>{t.move}</PmButton>
|
|
297
|
+
</>}>
|
|
298
|
+
<PmSelect ref={select} label={t.moveTarget} density="regular" value={target} onChange={event => setTarget(event.target.value)}>
|
|
299
|
+
<option value="">{t.topLevel}</option>
|
|
300
|
+
{choices.map(choice => <option key={choice.id} value={choice.id}>{choice.label}</option>)}
|
|
301
|
+
</PmSelect>
|
|
302
|
+
</PmDialog>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** The open document's ancestors in the app bar, each one a way to open it (items of the bar's place list). */
|
|
307
|
+
export function DocumentBreadcrumb({ compact }: { compact?: boolean }) {
|
|
308
|
+
const t = useTreeMessages()
|
|
309
|
+
const workbench = useWorkbench()
|
|
310
|
+
const open = useWorkbenchState(state => state.document)
|
|
311
|
+
useWorkbenchState(state => state.documentTree)
|
|
312
|
+
useWorkbenchState(state => state.documents)
|
|
313
|
+
const id = workbench.tree.idOf(open)
|
|
314
|
+
const trail = id ? workbench.tree.ancestors(id) : []
|
|
315
|
+
const shown = compact ? trail.slice(-1) : trail
|
|
316
|
+
return <>{shown.map(item => (
|
|
317
|
+
<li key={item.id} className="pmw-appbar__ancestor">
|
|
318
|
+
<button type="button" className="pmw-appbar__place" title={item.title} aria-label={`${t.location}: ${item.title}`} onClick={() => void workbench.tree.openPlace({ document: item.id })}>
|
|
319
|
+
<span className="pmw-appbar__label">{item.title}</span>
|
|
320
|
+
</button>
|
|
321
|
+
</li>
|
|
322
|
+
))}</>
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** The workbench's one toast (what a tree operation did, with Undo). */
|
|
326
|
+
export function WorkbenchToast() {
|
|
327
|
+
const t = useTreeMessages()
|
|
328
|
+
const workbench = useWorkbench()
|
|
329
|
+
const toast = useWorkbenchState(state => state.toast)
|
|
330
|
+
return <PmToast toast={toast} closeLabel={t.close} onClose={workbench.tree.closeToast} />
|
|
331
|
+
}
|
package/src/styles.css
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
@import './step-production.css';
|
|
5
5
|
@import './component-properties.css';
|
|
6
6
|
@import './caption-timing.css';
|
|
7
|
+
@import './knowledge.css';
|
|
7
8
|
|
|
8
9
|
.pmw-preview__frames[data-pending-snapshot]:not([data-presentation-gated]) { visibility: hidden; }
|
|
9
10
|
|
|
@@ -159,6 +160,25 @@
|
|
|
159
160
|
gap: var(--pm-space-2);
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
/* The files chosen as source material: a short list that scrolls when long, each name on one line. */
|
|
164
|
+
.pmw-materials__files {
|
|
165
|
+
display: grid;
|
|
166
|
+
gap: var(--pm-space-1);
|
|
167
|
+
max-height: var(--pm-materials-list-max-height);
|
|
168
|
+
margin: 0;
|
|
169
|
+
padding: 0;
|
|
170
|
+
overflow: auto;
|
|
171
|
+
color: var(--pm-color-muted);
|
|
172
|
+
font-size: var(--pm-text-sm);
|
|
173
|
+
list-style: none;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.pmw-materials__files li {
|
|
177
|
+
overflow: hidden;
|
|
178
|
+
text-overflow: ellipsis;
|
|
179
|
+
white-space: nowrap;
|
|
180
|
+
}
|
|
181
|
+
|
|
162
182
|
/* The open document, as an editor shows it: the command bar, the panes, the page on its canvas, the status bar. */
|
|
163
183
|
|
|
164
184
|
.pmw-document {
|