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
|
* 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.
|
* and hands over — it never renders an editor of its own.
|
||||||
*
|
*
|
||||||
* Registered as a `conversation.view`, so it appears in the session header tab
|
* Which session the view belongs to: the host renders every `conversation.view`
|
||||||
* strip next to the host's own views (对话 / 上下文 / 编队 / 轨迹 …). The host
|
* registration into the session header tab strip, but it passes NONE of the
|
||||||
* passes the session it renders; `order` places it after the context/fleet
|
* session identity to the view component (only `inspectCall` / `viewRequest` /
|
||||||
* views (20 / 30) instead of at the front of the strip.
|
* `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'
|
import { createElement, useEffect, useState, type ReactNode } from 'react'
|
||||||
@@ -26,12 +33,18 @@ interface OfficeFile {
|
|||||||
updatedAt?: string
|
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 {
|
export interface OfficeViewProps {
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
ctx: Context
|
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.
|
* Read the file list out of the bridge's answer.
|
||||||
*
|
*
|
||||||
@@ -56,18 +69,79 @@ function displayName(file: OfficeFile): string {
|
|||||||
return '(unnamed)'
|
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.
|
* The session's Office documents.
|
||||||
*
|
*
|
||||||
* @param props - the host's session id and our client context.
|
* @param props - the host's session id (the host sends none) and our client context.
|
||||||
* @returns the list view (loading / empty / rows).
|
* @returns the list view (idle / loading / empty / rows).
|
||||||
*/
|
*/
|
||||||
export function OfficeView(props: OfficeViewProps): ReactNode {
|
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 [files, setFiles] = useState<OfficeFile[] | null>(null)
|
||||||
const [failed, setFailed] = useState(false)
|
const [failed, setFailed] = useState(false)
|
||||||
|
|
||||||
|
// Follow the mounted seat: the host sends no session identity to the view.
|
||||||
useEffect(() => {
|
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) {
|
if (sessionId === undefined) {
|
||||||
setFiles([])
|
setFiles([])
|
||||||
return
|
return
|
||||||
@@ -93,42 +167,66 @@ export function OfficeView(props: OfficeViewProps): ReactNode {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true
|
cancelled = true
|
||||||
}
|
}
|
||||||
}, [sessionId])
|
}, [loaded, reload, sessionId])
|
||||||
|
|
||||||
/** Open the file in the native right sidebar (preview / edit live there). */
|
/** Open the file in the native right sidebar (preview / edit live there). */
|
||||||
function open(file: OfficeFile): void {
|
function open(file: OfficeFile): void {
|
||||||
if (sessionId === undefined || typeof file.path !== 'string') return
|
if (sessionId === undefined || typeof file.path !== 'string') return
|
||||||
const surface = ctx.get('sidebarRight') as
|
const surface = ctx.get('sidebarRight') as SidebarRightFace | undefined
|
||||||
| { openResource?: (input: { sessionId: string; address: string; revealIfOpened: boolean }) => void }
|
|
||||||
| undefined
|
|
||||||
const address = fileAddressFor(sessionId, addressBaseOf(ctx, sessionId), file.path)
|
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) {
|
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) {
|
if (files.length === 0) {
|
||||||
return createElement(
|
return panel(
|
||||||
'div',
|
createElement(
|
||||||
{ className: 'apesi-office-view', 'data-apesi-office': failed ? 'failed' : 'empty' },
|
'span',
|
||||||
failed ? 'Office 桥接不可用(dsh-apesi-dshoffice 未安装)' : '本会话暂无 Office 文档',
|
{ style: { opacity: 0.7 } },
|
||||||
|
failed ? 'Office 桥接不可用(dsh-apesi-dshoffice 未安装)' : '本会话暂无 Office 文档',
|
||||||
|
),
|
||||||
|
failed ? 'failed' : 'empty',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return createElement(
|
return panel(
|
||||||
'div',
|
[
|
||||||
{ className: 'apesi-office-view', 'data-apesi-office': 'list' },
|
|
||||||
files.map((file, index) =>
|
|
||||||
createElement(
|
createElement(
|
||||||
'button',
|
'div',
|
||||||
{
|
{ style: { display: 'flex', gap: '8px', alignItems: 'center' } },
|
||||||
key: `${file.path ?? ''}:${index}`,
|
action('刷新', () => {
|
||||||
type: 'button',
|
setFiles(null)
|
||||||
className: 'apesi-office-row',
|
setReload(value => value + 1)
|
||||||
onClick: () => open(file),
|
}),
|
||||||
},
|
|
||||||
createElement('span', { className: 'apesi-office-name' }, displayName(file)),
|
|
||||||
),
|
),
|
||||||
),
|
...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