@lincyaw/workbench 0.2.0-rc.23 → 0.2.0-rc.24
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/components.tsx +0 -23
- package/src/index.ts +0 -3
- package/src/messages.ts +0 -2
- package/src/panels/DocumentView.tsx +1 -3
- package/src/panels/ExportPanel.tsx +1 -6
- package/src/panels/PreviewPanel.tsx +1 -4
- package/src/panels/SourceDocumentPanel.tsx +1 -4
- package/src/places.ts +1 -36
- package/src/styles.css +1 -31
- package/src/workbench.ts +1 -16
- package/src/assistant-mascot.ts +0 -62
- package/src/mascot-preference.ts +0 -37
- package/src/panels/ChangeTrail.tsx +0 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workbench",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.24",
|
|
4
4
|
"description": "Presmium's workbench panels in React (the documents, a document edited on its rendered page with comments and version history) with the workspace service's client and the preview protocol's workbench side; @lincyaw/dsh places them in presmium studio (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@tiptap/pm": "3.32.0",
|
|
55
55
|
"katex": "0.18.10",
|
|
56
56
|
"react-resizable-panels": "4.14.5",
|
|
57
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
58
|
-
"@lincyaw/design": "1.0.0-rc.
|
|
57
|
+
"@lincyaw/kernel": "1.0.0-rc.25",
|
|
58
|
+
"@lincyaw/design": "1.0.0-rc.25"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "^18.3.1",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@types/react-dom": "18.3.7",
|
|
67
67
|
"react": "^18.3.1",
|
|
68
68
|
"react-dom": "^18.3.1",
|
|
69
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
69
|
+
"@lincyaw/compiler": "1.0.0-rc.25"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/components.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
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'
|
|
@@ -11,7 +9,6 @@ import { forwardRef, 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'
|
|
@@ -413,26 +410,6 @@ export function PmNotice({ tone = 'neutral', children }: { tone?: 'neutral' | 'a
|
|
|
413
410
|
return <div className={cls('pm-ui-notice', tone !== 'neutral' && `pm-ui-notice--${tone}`)} role={tone === 'danger' ? 'alert' : 'status'}>{children}</div>
|
|
414
411
|
}
|
|
415
412
|
|
|
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
|
-
}
|
|
422
|
-
|
|
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" />
|
|
434
|
-
}
|
|
435
|
-
|
|
436
413
|
export interface RangeProps {
|
|
437
414
|
label: string
|
|
438
415
|
value: number
|
package/src/index.ts
CHANGED
|
@@ -26,9 +26,6 @@ export { HistoryPanel } from './panels/HistoryPanel.tsx'
|
|
|
26
26
|
export type { HistoryPanelProps, HistoryRevisionAction } from './panels/HistoryPanel.tsx'
|
|
27
27
|
export { HomePanel } from './panels/HomePanel.tsx'
|
|
28
28
|
export { WorkbenchApprovals } from './approvals.tsx'
|
|
29
|
-
export { assistantMascotAction, useAssistantMascot } from './assistant-mascot.ts'
|
|
30
|
-
export type { AssistantActivity } from './assistant-mascot.ts'
|
|
31
|
-
export { mascotEnabled, setMascotEnabled, useMascotEnabled } from './mascot-preference.ts'
|
|
32
29
|
export { PreviewPanel } from './panels/PreviewPanel.tsx'
|
|
33
30
|
export { SpeechSettingsPanel } from './panels/SpeechSettingsPanel.tsx'
|
|
34
31
|
export { SPEECH_SETTINGS_MESSAGES } from './speech-settings-messages.ts'
|
package/src/messages.ts
CHANGED
|
@@ -330,7 +330,6 @@ const zh = {
|
|
|
330
330
|
'history-result-no-longer-current': '之前的结果已不是当前版本,请查看最新的历史。',
|
|
331
331
|
'authoring-review-required': '有修改等待你审阅,请先接受或放弃。',
|
|
332
332
|
} as Record<string, string>,
|
|
333
|
-
agentWorking: 'AI 正在修改文稿…',
|
|
334
333
|
agentWaiting: (n: number) => `AI 修改了 ${n} 处内容,要接受这些修改吗?`,
|
|
335
334
|
accept: '接受',
|
|
336
335
|
reject: '拒绝',
|
|
@@ -700,7 +699,6 @@ const en: WorkbenchMessages = {
|
|
|
700
699
|
'history-result-no-longer-current': 'The earlier result is no longer the current version. Review the latest history.',
|
|
701
700
|
'authoring-review-required': 'Changes are waiting for your review. Accept or discard them first.',
|
|
702
701
|
},
|
|
703
|
-
agentWorking: 'The AI is editing the document…',
|
|
704
702
|
agentWaiting: (n: number) => `The AI changed ${n} file${n === 1 ? '' : 's'}. Accept the changes?`,
|
|
705
703
|
accept: 'Accept',
|
|
706
704
|
reject: 'Reject',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
2
2
|
import type { ReactNode, RefObject } from 'react'
|
|
3
|
-
import { PmButton, PmDialog, PmIconButton,
|
|
3
|
+
import { PmButton, PmDialog, PmIconButton, PmMenu, PmNotice, PmSkeleton, PmSortableList, PmToolbar, PmToolbarButton } from '../components.tsx'
|
|
4
4
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
5
5
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
6
6
|
import { SHORTCUTS } from '../shortcuts.ts'
|
|
@@ -409,10 +409,8 @@ function DocumentNotices() {
|
|
|
409
409
|
const askFailure = useWorkbenchState(state => (state.pointer ? undefined : state.askFailure))
|
|
410
410
|
return (
|
|
411
411
|
<div className="pmw-notices">
|
|
412
|
-
{review?.running && <PmNotice tone="accent"><PmMascot size="small" action={review.changes.length > 0 ? 'write' : 'read'} />{t.agentWorking}</PmNotice>}
|
|
413
412
|
{review && !review.running && review.changes.length > 0 && (
|
|
414
413
|
<PmNotice tone="accent">
|
|
415
|
-
<PmMascot size="small" action="ask" />
|
|
416
414
|
<span>{t.agentWaiting(review.changes.length)}</span>
|
|
417
415
|
<span className="pmw-notice__actions">
|
|
418
416
|
<PmButton small onClick={() => void workbench.rejectReview()}>{t.reject}</PmButton>
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
|
-
import type { CSSProperties } from 'react'
|
|
3
2
|
import type { CompileJob, OutputTarget } from '@lincyaw/kernel'
|
|
4
3
|
import type { IconName } from '@lincyaw/design'
|
|
5
|
-
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton,
|
|
4
|
+
import { PmBadge, PmButton, PmDialog, PmEmpty, PmIcon, PmIconButton, PmNotice } from '../components.tsx'
|
|
6
5
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
7
6
|
import { failureReason, timeAgo } from '../messages.ts'
|
|
8
7
|
|
|
@@ -105,10 +104,6 @@ function JobItem({ job, label, current, onPlay }: { job: CompileJob, label: stri
|
|
|
105
104
|
</p>
|
|
106
105
|
{job.state === 'running' && progress && (
|
|
107
106
|
<div className="pmw-job__progress">
|
|
108
|
-
{/* the kitten runs along the bar to how far the job has come; with no total yet it walks at the start */}
|
|
109
|
-
<span className="pmw-job__runner" style={{ '--pmw-job-done': progress.total ? Math.min(1, (progress.done ?? 0) / progress.total) : 0 } as CSSProperties}>
|
|
110
|
-
<PmMascot size="small" action={progress.total ? 'run' : 'walk'} />
|
|
111
|
-
</span>
|
|
112
107
|
<progress max={progress.total ?? 1} value={progress.total ? progress.done ?? 0 : undefined} aria-label={label} />
|
|
113
108
|
<span>{t.jobProgress(t.jobPhases[progress.phase] ?? t.outputLabels[progress.phase] ?? progress.phase, progress.done, progress.total)}</span>
|
|
114
109
|
</div>
|
|
@@ -6,7 +6,6 @@ import { PmButton, PmNotice } from '../components.tsx'
|
|
|
6
6
|
import { useMessages, useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
7
7
|
import { slideAspect } from '../workbench.ts'
|
|
8
8
|
import { failureReason } from '../messages.ts'
|
|
9
|
-
import { PreviewChangeTrail } from './ChangeTrail.tsx'
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* The open document as its readers see it (the web form or the slides), with the tools for what the author points at.
|
|
@@ -29,7 +28,6 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
|
|
|
29
28
|
const reload = useWorkbenchState(state => state.previewReload)
|
|
30
29
|
const aspect = useWorkbenchState(state => (state.previewRenderer === 'slides' ? slideAspect(state.ir) : undefined))
|
|
31
30
|
const container = useRef<HTMLDivElement>(null)
|
|
32
|
-
const stage = useRef<HTMLDivElement>(null)
|
|
33
31
|
const pool = useRef<ReturnType<typeof createPreviewPool>>()
|
|
34
32
|
const [loads, setLoads] = useState(0)
|
|
35
33
|
const [{ ready, mismatch, identityFailure, handshakeFailure, canvasGate }, setStatus] = useState<PreviewFrameStatus>({ ready: false })
|
|
@@ -70,9 +68,8 @@ export function PreviewPanel({ active = true, onPresentationAction, presentation
|
|
|
70
68
|
{failure && <PmNotice tone="danger"><span>{t.previewFailed(failureReason(t, failure))}</span><PmButton small onClick={() => workbench.retryPreview()}>{t.retry}</PmButton></PmNotice>}
|
|
71
69
|
{(!ready || !snapshotMatches) && !failure && !handshakeFailure && !(renderer === 'slides' && preview && !preview.slides) && <p className="pmw-muted pmw-preview__loading">{presentation && ready && !snapshotMatches && !preparing ? t.presentationOutdated : address ? t.previewLoading : t.previewPreparing}</p>}
|
|
72
70
|
{renderer === 'slides' && preview && !preview.slides && <p className="pmw-muted pmw-preview__loading">{t.noSlides}</p>}
|
|
73
|
-
<div
|
|
71
|
+
<div className="pmw-preview__stage">
|
|
74
72
|
<div ref={container} className="pmw-preview__frames" data-renderer={renderer} data-pending-snapshot={!snapshotMatches || undefined} data-presentation-gated={presentation && canvasGate || undefined} style={aspect === undefined ? undefined : { '--pmw-slide-aspect': aspect } as CSSProperties} />
|
|
75
|
-
{!presentation && <PreviewChangeTrail stage={stage} frames={container} />}
|
|
76
73
|
</div>
|
|
77
74
|
</section>
|
|
78
75
|
)
|
|
@@ -10,7 +10,6 @@ import { nativeEditingCursor } from '../document-editor/selection.ts'
|
|
|
10
10
|
import { hasBlockPreview } from '../document-editor/projection.ts'
|
|
11
11
|
import type { NativeDocumentEditor } from '../document-editor/schema.tsx'
|
|
12
12
|
import { isAgentChanging } from '../workbench.ts'
|
|
13
|
-
import { EditorChangeTrail } from './ChangeTrail.tsx'
|
|
14
13
|
|
|
15
14
|
/** Source editing is available before the first successful runtime compilation. */
|
|
16
15
|
export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: { commentsPortal?: HTMLElement | null, onCommentDraftRestore?(): void }) {
|
|
@@ -26,7 +25,6 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
26
25
|
const navigation = useWorkbenchState(state => state.documentNavigation)
|
|
27
26
|
const readOnly = useWorkbenchState(state => state.mode !== 'editing' || workbench.client.capabilities?.readOnly === true || Boolean(state.authoring?.member && !hasRole(state.authoring.member, 'editor')) || Boolean(state.authoring?.loading) || isAgentChanging(state))
|
|
28
27
|
const container = useRef<HTMLElement>(null)
|
|
29
|
-
const sheet = useRef<HTMLDivElement>(null)
|
|
30
28
|
const consumedNavigation = useRef<string>()
|
|
31
29
|
const bodyEditor = useRef<NativeDocumentEditor>()
|
|
32
30
|
const editingPosition = useRef<{ nativeBlockId: string, sectionId: string, position: number, editor: NativeDocumentEditor, identity: string, reset: number | undefined }>()
|
|
@@ -176,8 +174,7 @@ export function SourceDocumentPanel({ commentsPortal, onCommentDraftRestore }: {
|
|
|
176
174
|
{source?.issues.length ? <div className="pmw-source-document__diagnostics"><PmNotice tone="warn"><details><summary>{messages.diagnostics(source.issues.length)}</summary><ul>{source.issues.map((issue, index) => <li key={`${issue.path}:${index}`}><code>{issue.path}</code> {issue.message}</li>)}</ul></details></PmNotice></div> : null}
|
|
177
175
|
{!source?.content || !source.identity ? source?.loading
|
|
178
176
|
? <div className="pmw-source-document__sheet pmw-source-document__sheet--loading"><PmSkeleton label={messages.loading} /></div>
|
|
179
|
-
: <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div
|
|
180
|
-
<EditorChangeTrail sheet={sheet} />
|
|
177
|
+
: <PmNotice tone="warn"><span>{messages.unavailable}</span><span className="pmw-notice__actions"><PmButton small onClick={() => void workbench.retryDocument()}>{t.retry}</PmButton></span></PmNotice> : <div className="pmw-source-document__sheet">
|
|
181
178
|
<DocumentEditor acknowledged={sourceAcknowledged()} getDocumentAcknowledged={sourceAcknowledged} onCommentDraftRestore={onCommentDraftRestore} commentDrafts={workbench.documentCommentDrafts(source.identity)} identity={source.identity} document={source.content} version={source.version} member={source.member} getDocument={() => workbench.getDocument(source.identity)}
|
|
182
179
|
getDocumentVersion={() => { const current = workbench.getState().authoring; return current && current.identity === source.identity && current.reset === source.reset ? current.version : undefined }} reset={source.reset} locale={locale} readOnly={readOnly}
|
|
183
180
|
uploadImage={(file, signal) => workbench.importDocumentImage(file, source.identity!, signal)}
|
package/src/places.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { irBlocks } from '@lincyaw/kernel'
|
|
2
|
-
import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos
|
|
2
|
+
import type { IRDocument, PreviewAnchor, ReviewChange, SourcePos } from '@lincyaw/kernel'
|
|
3
3
|
|
|
4
4
|
const CHANGED_PLACES = 100
|
|
5
5
|
|
|
@@ -65,38 +65,3 @@ export function changedPlaces(doc: IRDocument, changes: readonly ReviewChange[])
|
|
|
65
65
|
}
|
|
66
66
|
return [...places.values()].slice(0, CHANGED_PLACES)
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The places that differ between two versions of a document: each block whose content changed or that is new (with
|
|
71
|
-
* its page), each page whose title changed or that is new, and the block of each step whose narration or settings
|
|
72
|
-
* changed, at most CHANGED_PLACES.
|
|
73
|
-
*/
|
|
74
|
-
export function changedBlocks(before: TeachingDocument, after: TeachingDocument): PreviewAnchor[] {
|
|
75
|
-
const places: PreviewAnchor[] = []
|
|
76
|
-
const visit = (section: string, ids: readonly string[]) => {
|
|
77
|
-
for (const id of ids) {
|
|
78
|
-
const block = after.blocks[id]
|
|
79
|
-
if (!block) continue
|
|
80
|
-
if (JSON.stringify(block) !== JSON.stringify(before.blocks[id])) places.push({ section, block: id })
|
|
81
|
-
if ('children' in block && Array.isArray(block.children)) visit(section, block.children as string[])
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
for (const id of after.sectionOrder) {
|
|
85
|
-
const section = after.sections[id]
|
|
86
|
-
if (!section) continue
|
|
87
|
-
if (before.sections[id]?.title !== section.title) places.push({ section: id })
|
|
88
|
-
visit(id, section.children)
|
|
89
|
-
}
|
|
90
|
-
// A changed step, or a changed narration of it, shows at the block the step plays (else at its page).
|
|
91
|
-
const seen = new Set(places.map(place => `${place.section}\0${place.block ?? ''}`))
|
|
92
|
-
for (const step of Object.values(after.steps)) {
|
|
93
|
-
const narrated = step.narrationIds.some(id => JSON.stringify(after.narrations[id]) !== JSON.stringify(before.narrations[id]))
|
|
94
|
-
if (!narrated && JSON.stringify(step) === JSON.stringify(before.steps[step.id])) continue
|
|
95
|
-
// the component the step plays, where its narration shows, else any block it shows
|
|
96
|
-
const block = step.visuals.find(visual => after.blocks[visual.blockId]?.type === 'component')?.blockId ?? step.visuals.find(visual => visual.visible)?.blockId ?? step.visuals[0]?.blockId
|
|
97
|
-
const place = { section: step.sectionId, ...block ? { block } : {} }
|
|
98
|
-
const key = `${place.section}\0${place.block ?? ''}`
|
|
99
|
-
if (!seen.has(key)) { seen.add(key); places.push(place) }
|
|
100
|
-
}
|
|
101
|
-
return places.slice(0, CHANGED_PLACES)
|
|
102
|
-
}
|
package/src/styles.css
CHANGED
|
@@ -824,17 +824,6 @@
|
|
|
824
824
|
accent-color: var(--pm-color-accent);
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
-
/* The kitten above the bar, as far along it as the job has come (`--pmw-job-done`, 0 to 1), never past its ends. */
|
|
828
|
-
.pmw-job__runner {
|
|
829
|
-
display: block;
|
|
830
|
-
margin-left: calc((100% - var(--pm-size-mascot-sm)) * var(--pmw-job-done));
|
|
831
|
-
line-height: 0;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
.pmw-job__runner:empty {
|
|
835
|
-
display: none;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
827
|
.pmw-job__error {
|
|
839
828
|
margin: 0;
|
|
840
829
|
color: var(--pm-color-danger);
|
|
@@ -936,7 +925,7 @@
|
|
|
936
925
|
.pmw-source-document__recovery-actions { display: flex; flex-wrap: wrap; gap: var(--pm-space-2); }
|
|
937
926
|
.pmw-source-document__diagnostics { margin-block-end: var(--pm-space-3); }
|
|
938
927
|
/* Its end margin is the editor's own end area, which fills the rest of the sheet and takes the presses below the last block. */
|
|
939
|
-
.pmw-source-document__sheet {
|
|
928
|
+
.pmw-source-document__sheet { display: flex; flex-direction: column; max-width: var(--pm-sheet-width); min-height: 100%; margin-inline: auto; padding-block-start: var(--pm-space-4); background: var(--pm-color-surface); box-shadow: var(--pm-shadow-page); }
|
|
940
929
|
/* Opening: the page's own margins, so that the placeholder lines sit where the text will. */
|
|
941
930
|
.pmw-source-document__sheet--loading { box-sizing: border-box; padding: var(--pm-space-10) var(--pm-space-12); }
|
|
942
931
|
.pmw-voice__filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--pm-space-3); }
|
|
@@ -1009,22 +998,3 @@
|
|
|
1009
998
|
.pmw-approvals .pmw-muted { margin: 0; }
|
|
1010
999
|
.pmw-approvals__detail { max-height: 30vh; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1011
1000
|
.pmw-approvals__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--pm-space-2); }
|
|
1012
|
-
|
|
1013
|
-
/* The kitten walking over the preview to the blocks the AI changed: its ground line meets the block's lower left. */
|
|
1014
|
-
.pmw-change-trail {
|
|
1015
|
-
position: absolute;
|
|
1016
|
-
top: 0;
|
|
1017
|
-
left: 0;
|
|
1018
|
-
z-index: 1;
|
|
1019
|
-
pointer-events: none;
|
|
1020
|
-
transform: translate(calc(var(--pmw-trail-x) - 45%), calc(var(--pmw-trail-y) - 89%));
|
|
1021
|
-
transition: transform var(--pm-duration-walk) linear, opacity var(--pm-duration-slow);
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
.pmw-change-trail[data-phase='done'] {
|
|
1025
|
-
opacity: 0.9;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
.pmw-change-trail__facing[data-facing='left'] {
|
|
1029
|
-
transform: scaleX(-1);
|
|
1030
|
-
}
|
package/src/workbench.ts
CHANGED
|
@@ -49,7 +49,7 @@ import { DocumentJobs } from './jobs.ts'
|
|
|
49
49
|
import { VoiceoverJobs } from './voiceover-jobs.ts'
|
|
50
50
|
import { contentText, localeOf, MESSAGES } from './messages.ts'
|
|
51
51
|
import type { AgentPlace, Locale } from './messages.ts'
|
|
52
|
-
import {
|
|
52
|
+
import { changedPlaces, findPlaceAtLine, findPlaceSource } from './places.ts'
|
|
53
53
|
import { OperationLog } from './telemetry.ts'
|
|
54
54
|
import type { OperationValue } from './telemetry.ts'
|
|
55
55
|
import { PreviewPlayback } from './preview-playback.ts'
|
|
@@ -169,10 +169,6 @@ export interface WorkbenchState {
|
|
|
169
169
|
isRepairingDiagnostics: boolean
|
|
170
170
|
diagnosticsRepairFailure?: string
|
|
171
171
|
pointer?: Pointer
|
|
172
|
-
/** Where the blocks the AI just changed are in the preview, for the kitten to walk to; `id` is new for each change. */
|
|
173
|
-
changeTrail?: { id: number, rects: PreviewRect[] }
|
|
174
|
-
/** The places the AI just changed, for the kitten in the editor to walk to; `id` is new for each change. */
|
|
175
|
-
changedPlaces?: { id: number, targets: PreviewAnchor[] }
|
|
176
172
|
save: SaveState
|
|
177
173
|
/** What the conversation's agent is told the author points at. */
|
|
178
174
|
focus: FocusReport[]
|
|
@@ -337,7 +333,6 @@ export class Workbench {
|
|
|
337
333
|
#pendingReveal?: PreviewAnchor
|
|
338
334
|
/** The AI's changes to show on the document once the preview has them. */
|
|
339
335
|
#pendingFlash?: ReviewChange[]
|
|
340
|
-
#trail = 0
|
|
341
336
|
#lastPosition?: string
|
|
342
337
|
#awaitingView?: WebView
|
|
343
338
|
/** The forms asked for ahead of the author (`web:<dir>`, `slides:<dir>`), and the wait before asking for the slides. */
|
|
@@ -424,12 +419,6 @@ export class Workbench {
|
|
|
424
419
|
&& previous?.identity === authoring.identity && Boolean(previous?.version && authoring.version)
|
|
425
420
|
&& (previous?.version !== authoring.version || previous?.fingerprint !== authoring.fingerprint)
|
|
426
421
|
if (!authoring.dirty && previous?.dirty || acknowledgedSourceChanged) { void this.#history.read(authoring.directory); void this.loadDocuments() }
|
|
427
|
-
// The source changed under an author with nothing unsaved while the AI holds a review: the AI changed it. The
|
|
428
|
-
// editor's kitten walks to the blocks whose content differs.
|
|
429
|
-
if (acknowledgedSourceChanged && !previous?.dirty && !previous?.saving && this.#state.review && previous?.content && authoring.content) {
|
|
430
|
-
const targets = changedBlocks(previous.content, authoring.content)
|
|
431
|
-
if (targets.length) this.#set({ changedPlaces: { id: ++this.#trail, targets } })
|
|
432
|
-
}
|
|
433
422
|
})
|
|
434
423
|
this.#diagnostics = new DocumentDiagnostics(this.client, store)
|
|
435
424
|
this.#jobs = new DocumentJobs(this.client, store)
|
|
@@ -804,7 +793,6 @@ export class Workbench {
|
|
|
804
793
|
this.#pendingFlash = undefined
|
|
805
794
|
const targets = changedPlaces(ir.doc, changes)
|
|
806
795
|
if (targets.length === 0) return
|
|
807
|
-
this.#trail++
|
|
808
796
|
this.#broadcast({ type: 'flash', targets })
|
|
809
797
|
this.#record('ai.change.shown', { 'presmium.places': targets.map(target => [target.section, target.block].filter(Boolean).join(':')).join('\n') })
|
|
810
798
|
}
|
|
@@ -2289,9 +2277,6 @@ export class Workbench {
|
|
|
2289
2277
|
} else if (this.#state.pointer?.quote) this.point(undefined)
|
|
2290
2278
|
break
|
|
2291
2279
|
}
|
|
2292
|
-
case 'flashed':
|
|
2293
|
-
if (this.#trail) this.#set({ changeTrail: { id: this.#trail, rects: report.rects } })
|
|
2294
|
-
break
|
|
2295
2280
|
case 'rect':
|
|
2296
2281
|
if (this.#state.pointer) this.#set({ pointer: { ...this.#state.pointer, rect: report.rect ?? undefined, obstacles: report.obstacles } })
|
|
2297
2282
|
break
|
package/src/assistant-mascot.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// What the kitten beside the assistant does, from what the assistant is doing: asking the author to approve
|
|
2
|
-
// something, reading the document it was asked about, writing into it, thinking, just finished, or idle (sitting,
|
|
3
|
-
// then lying down, then asleep the longer nothing happens).
|
|
4
|
-
import { useEffect, useState } from 'react'
|
|
5
|
-
import type { MascotAction } from '@lincyaw/design/mascot'
|
|
6
|
-
import { useWorkbench, useWorkbenchState } from './context.tsx'
|
|
7
|
-
|
|
8
|
-
const DONE_MS = 2400
|
|
9
|
-
const LOAF_MS = 90_000
|
|
10
|
-
const SLEEP_MS = 300_000
|
|
11
|
-
|
|
12
|
-
export interface AssistantActivity {
|
|
13
|
-
/** The assistant's turn is running. */
|
|
14
|
-
running: boolean
|
|
15
|
-
/** It holds a review of the open document: still working in it, and how many changes it has made. */
|
|
16
|
-
review?: { running: boolean, changes: number }
|
|
17
|
-
/** Operations wait for the author's approval. */
|
|
18
|
-
approvals: number
|
|
19
|
-
/** How long ago the assistant last stopped, in milliseconds (Infinity if it has not run). */
|
|
20
|
-
sinceStopped: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function assistantMascotAction(a: AssistantActivity): MascotAction {
|
|
24
|
-
if (a.approvals > 0) return 'ask'
|
|
25
|
-
if (a.review?.running) return a.review.changes > 0 ? 'write' : 'read'
|
|
26
|
-
if (a.running) return 'think'
|
|
27
|
-
if (a.review && a.review.changes > 0) return 'ask'
|
|
28
|
-
if (a.sinceStopped < DONE_MS) return 'done'
|
|
29
|
-
if (a.sinceStopped > SLEEP_MS) return 'sleep'
|
|
30
|
-
if (a.sinceStopped > LOAF_MS) return 'loaf'
|
|
31
|
-
return 'sit'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** The kitten's action for the assistant, given whether its turn is running; follows the workbench's review and the
|
|
35
|
-
* operations waiting for approval, and moves on by itself as time passes. */
|
|
36
|
-
export function useAssistantMascot(running: boolean): MascotAction {
|
|
37
|
-
const { client } = useWorkbench()
|
|
38
|
-
// two plain values rather than one object, so the selection compares equal while nothing changes
|
|
39
|
-
const reviewRunning = useWorkbenchState(state => state.review?.running)
|
|
40
|
-
const changes = useWorkbenchState(state => state.review?.changes.length)
|
|
41
|
-
const review = reviewRunning === undefined ? undefined : { running: reviewRunning, changes: changes ?? 0 }
|
|
42
|
-
const [approvals, setApprovals] = useState<string[]>([])
|
|
43
|
-
const [stoppedAt, setStoppedAt] = useState<number>(() => performance.now() - LOAF_MS / 2)
|
|
44
|
-
const [, setNow] = useState(0)
|
|
45
|
-
const busy = running || Boolean(review?.running)
|
|
46
|
-
useEffect(() => client.subscribeApprovals(event => {
|
|
47
|
-
if (event.type === 'reset') setApprovals([])
|
|
48
|
-
else if (event.type === 'settled') setApprovals(list => list.filter(id => id !== event.id))
|
|
49
|
-
else setApprovals(list => list.includes(event.id) ? list : [...list, event.id])
|
|
50
|
-
}), [client])
|
|
51
|
-
useEffect(() => { if (!busy) setStoppedAt(performance.now()) }, [busy])
|
|
52
|
-
// Wake up at the next moment the idle kitten changes what it does.
|
|
53
|
-
const since = performance.now() - stoppedAt
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (busy) return
|
|
56
|
-
const next = [DONE_MS, LOAF_MS, SLEEP_MS].find(ms => ms > since)
|
|
57
|
-
if (next === undefined) return
|
|
58
|
-
const timer = setTimeout(() => setNow(performance.now()), next - since + 50)
|
|
59
|
-
return () => clearTimeout(timer)
|
|
60
|
-
}, [busy, since])
|
|
61
|
-
return assistantMascotAction({ running, review, approvals: approvals.length, sinceStopped: busy ? 0 : since })
|
|
62
|
-
}
|
package/src/mascot-preference.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Whether the author wants the kitten: one choice for every place it shows, kept in this browser and followed by
|
|
2
|
-
// every open tab. It is on until the author turns it off.
|
|
3
|
-
import { useSyncExternalStore } from 'react'
|
|
4
|
-
|
|
5
|
-
const KEY = 'presmium.mascot'
|
|
6
|
-
const listeners = new Set<() => void>()
|
|
7
|
-
|
|
8
|
-
function read(): boolean {
|
|
9
|
-
try { return localStorage.getItem(KEY) !== 'off' } catch { return true }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let enabled = typeof localStorage === 'undefined' ? true : read()
|
|
13
|
-
|
|
14
|
-
function subscribe(listener: () => void): () => void {
|
|
15
|
-
listeners.add(listener)
|
|
16
|
-
const storage = (event: StorageEvent) => {
|
|
17
|
-
if (event.key !== KEY) return
|
|
18
|
-
enabled = read()
|
|
19
|
-
for (const each of listeners) each()
|
|
20
|
-
}
|
|
21
|
-
window.addEventListener('storage', storage)
|
|
22
|
-
return () => { listeners.delete(listener); window.removeEventListener('storage', storage) }
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function mascotEnabled(): boolean {
|
|
26
|
-
return enabled
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function setMascotEnabled(on: boolean): void {
|
|
30
|
-
enabled = on
|
|
31
|
-
try { localStorage.setItem(KEY, on ? 'on' : 'off') } catch { /* The choice holds for this page only. */ }
|
|
32
|
-
for (const listener of listeners) listener()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function useMascotEnabled(): boolean {
|
|
36
|
-
return useSyncExternalStore(subscribe, mascotEnabled, () => true)
|
|
37
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
import type { CSSProperties, RefObject } from 'react'
|
|
3
|
-
import type { MascotAction } from '@lincyaw/design/mascot'
|
|
4
|
-
import { PmMascot } from '../components.tsx'
|
|
5
|
-
import { useMascotEnabled } from '../mascot-preference.ts'
|
|
6
|
-
import { useWorkbenchState } from '../context.tsx'
|
|
7
|
-
import { pageId, richNodeIds } from '../document-editor/projection.ts'
|
|
8
|
-
|
|
9
|
-
/** How long the kitten walks from one changed place to the next, pats it, and stays when it is done (ms). */
|
|
10
|
-
const WALK_MS = 700, PAT_MS = 900, DONE_MS = 2200
|
|
11
|
-
/** At most this many changed places are visited. */
|
|
12
|
-
const STOPS = 6
|
|
13
|
-
|
|
14
|
-
type Point = { x: number, y: number }
|
|
15
|
-
type Phase = 'walk' | 'pat' | 'done' | 'gone'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The kitten visiting a list of points in its host (each the lower left of a changed place): it walks to each, pats it,
|
|
19
|
-
* hops when it is done and leaves. A new `id` starts it again from the first point; `where(i)` is asked on every
|
|
20
|
-
* render, so the kitten follows the places as the host lays out again. Nothing shows when the kitten is turned off.
|
|
21
|
-
*/
|
|
22
|
-
function KittenTrail({ id, count, where }: { id: number | undefined, count: number, where(index: number): Point | undefined }) {
|
|
23
|
-
const enabled = useMascotEnabled()
|
|
24
|
-
const [step, setStep] = useState<{ id: number, stop: number, phase: Phase }>()
|
|
25
|
-
const facing = useRef<'left' | 'right'>('right'), last = useRef<Point>()
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (id !== undefined && count > 0) setStep(current => current?.id === id ? current : { id, stop: 0, phase: 'walk' })
|
|
28
|
-
}, [id, count])
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (!step || step.phase === 'gone') return
|
|
31
|
-
const stops = Math.min(STOPS, count)
|
|
32
|
-
const next: typeof step = step.phase === 'walk' ? { ...step, phase: 'pat' }
|
|
33
|
-
: step.phase === 'pat' ? (step.stop + 1 < stops ? { ...step, stop: step.stop + 1, phase: 'walk' } : { ...step, phase: 'done' })
|
|
34
|
-
: { ...step, phase: 'gone' }
|
|
35
|
-
const timer = setTimeout(() => setStep(next), step.phase === 'walk' ? WALK_MS : step.phase === 'pat' ? PAT_MS : DONE_MS)
|
|
36
|
-
return () => clearTimeout(timer)
|
|
37
|
-
}, [step, count])
|
|
38
|
-
if (!enabled || !step || step.phase === 'gone' || step.id !== id) return null
|
|
39
|
-
const point = where(Math.min(step.stop, count - 1))
|
|
40
|
-
if (!point) return null
|
|
41
|
-
if (last.current && Math.abs(point.x - last.current.x) > 2 && step.phase === 'walk') facing.current = point.x < last.current.x ? 'left' : 'right'
|
|
42
|
-
if (step.phase === 'walk') last.current = point
|
|
43
|
-
const action: MascotAction = step.phase === 'walk' ? 'walk' : step.phase === 'pat' ? 'write' : 'done'
|
|
44
|
-
return (
|
|
45
|
-
<div className="pmw-change-trail" data-phase={step.phase} style={{ '--pmw-trail-x': `${point.x}px`, '--pmw-trail-y': `${point.y}px` } as CSSProperties}>
|
|
46
|
-
<div className="pmw-change-trail__facing" data-facing={facing.current}><PmMascot size="small" action={action} /></div>
|
|
47
|
-
</div>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** In the preview: the blocks the preview reports blinking, in the active frame's viewport. */
|
|
52
|
-
export function PreviewChangeTrail({ stage, frames }: { stage: RefObject<HTMLDivElement | null>, frames: RefObject<HTMLDivElement | null> }) {
|
|
53
|
-
const trail = useWorkbenchState(state => state.changeTrail)
|
|
54
|
-
return <KittenTrail id={trail?.id} count={trail?.rects.length ?? 0} where={index => {
|
|
55
|
-
const rect = trail?.rects[index]
|
|
56
|
-
const frame = frames.current?.querySelector<HTMLIFrameElement>('iframe[data-active="true"]:not([hidden])')
|
|
57
|
-
const host = stage.current
|
|
58
|
-
if (!rect || !frame || !host) return undefined
|
|
59
|
-
const offset = frame.getBoundingClientRect(), origin = host.getBoundingClientRect()
|
|
60
|
-
return { x: offset.left - origin.left + rect.x, y: offset.top - origin.top + rect.y + rect.height }
|
|
61
|
-
}} />
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** In the editor: each changed block (a text block by its first paragraph), else its page's title, on the sheet. */
|
|
65
|
-
export function EditorChangeTrail({ sheet }: { sheet: RefObject<HTMLDivElement | null> }) {
|
|
66
|
-
const places = useWorkbenchState(state => state.changedPlaces)
|
|
67
|
-
const content = useWorkbenchState(state => state.authoring?.content)
|
|
68
|
-
return <KittenTrail id={places?.id} count={places?.targets.length ?? 0} where={index => {
|
|
69
|
-
const target = places?.targets[index], host = sheet.current
|
|
70
|
-
if (!target || !host) return undefined
|
|
71
|
-
const block = target.block ? content?.blocks[target.block] : undefined
|
|
72
|
-
const ids = [...target.block ? [target.block] : [], ...block?.type === 'text' ? richNodeIds(block.content) : [], pageId(target.section)]
|
|
73
|
-
const element = ids.map(id => host.querySelector<HTMLElement>(`[data-id="${CSS.escape(id)}"]`)).find(Boolean)
|
|
74
|
-
if (!element) return undefined
|
|
75
|
-
const box = element.getBoundingClientRect(), origin = host.getBoundingClientRect()
|
|
76
|
-
// the kitten stands on the place's first line, at its left edge
|
|
77
|
-
return { x: box.left - origin.left, y: box.top - origin.top + Math.min(box.height, 28) }
|
|
78
|
-
}} />
|
|
79
|
-
}
|