Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ff0181d96 | ||
|
|
2480d1d8d5 |
+129
-31
@@ -6,10 +6,17 @@
|
||||
* editor already live (the bridge moved them there in v0.7). This view only lists
|
||||
* and hands over — it never renders an editor of its own.
|
||||
*
|
||||
* Registered as a `conversation.view`, so it appears in the session header tab
|
||||
* strip next to the host's own views (对话 / 上下文 / 编队 / 轨迹 …). The host
|
||||
* passes the session it renders; `order` places it after the context/fleet
|
||||
* views (20 / 30) instead of at the front of the strip.
|
||||
* Which session the view belongs to: the host renders every `conversation.view`
|
||||
* registration into the session header tab strip, but it passes NONE of the
|
||||
* session identity to the view component (only `inspectCall` / `viewRequest` /
|
||||
* `openView` / `completeViewRequest`). The sanctioned feed for "which session's
|
||||
* seat is on screen" is `ctx.sidebarRight.mounted` — the session list carries no
|
||||
* "current" id since DSH 0.1.7 — so the view reads the mounted seat and follows
|
||||
* it when the user switches conversations.
|
||||
*
|
||||
* The list is pulled ON DEMAND: the bridge scans the session's workspace, which
|
||||
* takes seconds. The host restores the last active view when a session opens,
|
||||
* so a view that fetched on mount would pay that scan for every session.
|
||||
*/
|
||||
|
||||
import { createElement, useEffect, useState, type ReactNode } from 'react'
|
||||
@@ -26,12 +33,18 @@ interface OfficeFile {
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
/** The view's props: the host's session plus our own client context. */
|
||||
/** The view's props: the host's session id (unused — the host sends none) and our client context. */
|
||||
export interface OfficeViewProps {
|
||||
sessionId?: string
|
||||
ctx: Context
|
||||
}
|
||||
|
||||
/** The slice of the native right-sidebar controller this view needs. */
|
||||
interface SidebarRightFace {
|
||||
mounted?: { getSnapshot(): string | undefined; subscribe(listener: () => void): () => void }
|
||||
openResource?(address: string, options?: { revealIfOpened?: boolean; preferNewPane?: boolean }): void
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the file list out of the bridge's answer.
|
||||
*
|
||||
@@ -56,18 +69,79 @@ function displayName(file: OfficeFile): string {
|
||||
return '(unnamed)'
|
||||
}
|
||||
|
||||
/** The view's shell: a padded panel with a heading, so it reads as a page, not a tooltip. */
|
||||
function panel(children: ReactNode, state: string): ReactNode {
|
||||
return createElement(
|
||||
'div',
|
||||
{
|
||||
className: 'apesi-office-view',
|
||||
'data-apesi-office': state,
|
||||
style: {
|
||||
padding: '12px 16px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '8px',
|
||||
alignItems: 'flex-start',
|
||||
color: 'var(--dsw-alias-label-primary, inherit)',
|
||||
font: 'var(--dsw-font-body, inherit)',
|
||||
},
|
||||
},
|
||||
children,
|
||||
)
|
||||
}
|
||||
|
||||
/** A plain action button in the plugin's own skin tokens. */
|
||||
function action(label: string, onClick: () => void): ReactNode {
|
||||
return createElement(
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
onClick,
|
||||
style: {
|
||||
padding: '6px 14px',
|
||||
borderRadius: '6px',
|
||||
border: '1px solid var(--dsw-alias-border-l1, rgba(127,127,127,0.35))',
|
||||
background: 'var(--dsw-alias-bg-container, transparent)',
|
||||
color: 'var(--dsw-alias-label-primary, inherit)',
|
||||
font: 'inherit',
|
||||
cursor: 'pointer',
|
||||
},
|
||||
},
|
||||
label,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The session's Office documents.
|
||||
*
|
||||
* @param props - the host's session id and our client context.
|
||||
* @returns the list view (loading / empty / rows).
|
||||
* @param props - the host's session id (the host sends none) and our client context.
|
||||
* @returns the list view (idle / loading / empty / rows).
|
||||
*/
|
||||
export function OfficeView(props: OfficeViewProps): ReactNode {
|
||||
const { sessionId, ctx } = props
|
||||
const { ctx } = props
|
||||
const [sessionId, setSessionId] = useState<string | undefined>(undefined)
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
const [reload, setReload] = useState(0)
|
||||
const [files, setFiles] = useState<OfficeFile[] | null>(null)
|
||||
const [failed, setFailed] = useState(false)
|
||||
|
||||
// Follow the mounted seat: the host sends no session identity to the view.
|
||||
useEffect(() => {
|
||||
const surface = ctx.get('sidebarRight') as SidebarRightFace | undefined
|
||||
const mounted = surface?.mounted
|
||||
if (mounted === undefined) return
|
||||
setSessionId(mounted.getSnapshot())
|
||||
return mounted.subscribe(() => {
|
||||
const next = mounted.getSnapshot()
|
||||
setSessionId(previous => (previous === next ? previous : next))
|
||||
// A different conversation means a different document set.
|
||||
setLoaded(false)
|
||||
setFiles(null)
|
||||
})
|
||||
}, [ctx])
|
||||
|
||||
useEffect(() => {
|
||||
if (!loaded) return
|
||||
if (sessionId === undefined) {
|
||||
setFiles([])
|
||||
return
|
||||
@@ -93,42 +167,66 @@ export function OfficeView(props: OfficeViewProps): ReactNode {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [sessionId])
|
||||
}, [loaded, reload, sessionId])
|
||||
|
||||
/** Open the file in the native right sidebar (preview / edit live there). */
|
||||
function open(file: OfficeFile): void {
|
||||
if (sessionId === undefined || typeof file.path !== 'string') return
|
||||
const surface = ctx.get('sidebarRight') as
|
||||
| { openResource?: (input: { sessionId: string; address: string; revealIfOpened: boolean }) => void }
|
||||
| undefined
|
||||
const surface = ctx.get('sidebarRight') as SidebarRightFace | undefined
|
||||
const address = fileAddressFor(sessionId, addressBaseOf(ctx, sessionId), file.path)
|
||||
surface?.openResource?.({ sessionId, address, revealIfOpened: true })
|
||||
surface?.openResource?.(address, { revealIfOpened: true })
|
||||
}
|
||||
|
||||
if (sessionId === undefined) {
|
||||
return panel(createElement('span', { style: { opacity: 0.7 } }, '没有已挂载的会话'), 'no-session')
|
||||
}
|
||||
if (!loaded) {
|
||||
return panel(action('加载本会话的 Office 文档', () => setLoaded(true)), 'idle')
|
||||
}
|
||||
if (files === null) {
|
||||
return createElement('div', { className: 'apesi-office-view', 'data-apesi-office': 'loading' }, '加载中…')
|
||||
return panel(createElement('span', { style: { opacity: 0.7 } }, '加载中…'), 'loading')
|
||||
}
|
||||
if (files.length === 0) {
|
||||
return createElement(
|
||||
'div',
|
||||
{ className: 'apesi-office-view', 'data-apesi-office': failed ? 'failed' : 'empty' },
|
||||
failed ? 'Office 桥接不可用(dsh-apesi-dshoffice 未安装)' : '本会话暂无 Office 文档',
|
||||
return panel(
|
||||
createElement(
|
||||
'span',
|
||||
{ style: { opacity: 0.7 } },
|
||||
failed ? 'Office 桥接不可用(dsh-apesi-dshoffice 未安装)' : '本会话暂无 Office 文档',
|
||||
),
|
||||
failed ? 'failed' : 'empty',
|
||||
)
|
||||
}
|
||||
return createElement(
|
||||
'div',
|
||||
{ className: 'apesi-office-view', 'data-apesi-office': 'list' },
|
||||
files.map((file, index) =>
|
||||
return panel(
|
||||
[
|
||||
createElement(
|
||||
'button',
|
||||
{
|
||||
key: `${file.path ?? ''}:${index}`,
|
||||
type: 'button',
|
||||
className: 'apesi-office-row',
|
||||
onClick: () => open(file),
|
||||
},
|
||||
createElement('span', { className: 'apesi-office-name' }, displayName(file)),
|
||||
'div',
|
||||
{ style: { display: 'flex', gap: '8px', alignItems: 'center' } },
|
||||
action('刷新', () => {
|
||||
setFiles(null)
|
||||
setReload(value => value + 1)
|
||||
}),
|
||||
),
|
||||
),
|
||||
...files.map((file, index) =>
|
||||
createElement(
|
||||
'button',
|
||||
{
|
||||
key: `${file.path ?? ''}:${index}`,
|
||||
type: 'button',
|
||||
onClick: () => open(file),
|
||||
style: {
|
||||
padding: '4px 8px',
|
||||
border: 'none',
|
||||
background: 'transparent',
|
||||
color: 'var(--dsw-alias-label-primary, inherit)',
|
||||
font: 'inherit',
|
||||
textAlign: 'left',
|
||||
cursor: 'pointer',
|
||||
},
|
||||
},
|
||||
displayName(file),
|
||||
),
|
||||
),
|
||||
],
|
||||
'list',
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user