Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ff0181d96 | ||
|
|
2480d1d8d5 | ||
|
|
8a769c535b | ||
|
|
09a3ca4680 | ||
|
|
09ad92972c |
No files matched your search
@@ -65,6 +65,7 @@ import { CLUE_PREFS_ID, CLUE_WINDOW_SURFACE_SETTING, type SidebarPrefs } from '.
|
|||||||
import { api } from './api.ts'
|
import { api } from './api.ts'
|
||||||
import { parsePrefs, syncClueWindowSurface } from './prefs.ts'
|
import { parsePrefs, syncClueWindowSurface } from './prefs.ts'
|
||||||
import { AddPluginModal, type PluginKind } from './add-plugin-modal.tsx'
|
import { AddPluginModal, type PluginKind } from './add-plugin-modal.tsx'
|
||||||
|
import { CollapsedPanelsSetting } from './collapsed-panels-setting.tsx'
|
||||||
import { t } from './locales.ts'
|
import { t } from './locales.ts'
|
||||||
import type { SidebarStore } from './state.ts'
|
import type { SidebarStore } from './state.ts'
|
||||||
import { mergeGuideEntries, type NativeGuideCatalog, type NativeGuideEntry } from './native/guide-catalog.ts'
|
import { mergeGuideEntries, type NativeGuideCatalog, type NativeGuideEntry } from './native/guide-catalog.ts'
|
||||||
@@ -1890,6 +1891,12 @@ export function SideCardSection(props: SideCardSectionInjected & Partial<PropsRu
|
|||||||
{group === 'general' && (
|
{group === 'general' && (
|
||||||
<div className={css.group}>
|
<div className={css.group}>
|
||||||
<h2 className={css.groupHeading}>{t('settingsGeneralTitle')}</h2>
|
<h2 className={css.groupHeading}>{t('settingsGeneralTitle')}</h2>
|
||||||
|
{/* 侧栏入口折叠: which left-sidebar entries stay out of the way.
|
||||||
|
The host folds an entry into its More menu when the entry's
|
||||||
|
panel id is in the host's pin storage; this block is where the
|
||||||
|
user picks that set. */}
|
||||||
|
<CollapsedPanelsSetting />
|
||||||
|
|
||||||
<SettingRow label={t('settingsOpenToolsTitle')} description={t('settingsOpenToolsDesc')} className={css.row}>
|
<SettingRow label={t('settingsOpenToolsTitle')} description={t('settingsOpenToolsDesc')} className={css.row}>
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
aria-label={t('settingsOpenToolsTitle')}
|
aria-label={t('settingsOpenToolsTitle')}
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
* The "folded sidebar entries" setting.
|
||||||
|
*
|
||||||
|
* The host's left sidebar folds an entry away when its panel id is listed in
|
||||||
|
* `unpinned` (localStorage `dsh-desktop.sidebar.panel-pins`); the folded
|
||||||
|
* entries move into the host's own More menu, where the user can pin any of
|
||||||
|
* them back. This block lists the entries we know of and writes that list —
|
||||||
|
* so which entries stay out of the way is the user's choice, not a constant
|
||||||
|
* in our source.
|
||||||
|
*
|
||||||
|
* Writing the list also marks it as "taken over" (`…:collapsed-defaults` =
|
||||||
|
* `custom`), which tells our startup helper to stop merging the default
|
||||||
|
* set back in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { t } from './locales.ts'
|
||||||
|
import { Checkbox, SettingRow } from './ui/index.ts'
|
||||||
|
|
||||||
|
/** The host's pin storage: `{ unpinned: string[] }`. */
|
||||||
|
const PIN_KEY = 'dsh-desktop.sidebar.panel-pins'
|
||||||
|
/** Our marker key: the default set we already applied, or `custom`. */
|
||||||
|
const MARK_KEY = 'dsh-apes-sidebar:collapsed-defaults'
|
||||||
|
|
||||||
|
/** The marker value that means "the user manages this list now". */
|
||||||
|
const CUSTOM_MARK = 'custom'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entries this setting can fold.
|
||||||
|
*
|
||||||
|
* The ids are the panel ids the registering plugins use; an entry that is
|
||||||
|
* not installed simply does not appear in the sidebar.
|
||||||
|
*/
|
||||||
|
const CANDIDATE_PANELS = [
|
||||||
|
{ id: 'dsh-market', label: '插件市场' },
|
||||||
|
{ id: 'dsh-context', label: '上下文洞察' },
|
||||||
|
{ id: 'task-board', label: '任务看板' },
|
||||||
|
{ id: 'forge-review', label: '代码评审' },
|
||||||
|
] as const
|
||||||
|
|
||||||
|
/** The entries currently folded away. */
|
||||||
|
function readUnpinned(): string[] {
|
||||||
|
if (typeof localStorage === 'undefined') return []
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(PIN_KEY)
|
||||||
|
if (raw === null) return []
|
||||||
|
const value = JSON.parse(raw) as { unpinned?: unknown }
|
||||||
|
return Array.isArray(value.unpinned) ? value.unpinned.filter((id): id is string => typeof id === 'string') : []
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the folded set and reload, so the host's pin store picks it up.
|
||||||
|
*
|
||||||
|
* @param ids - the panel ids to fold away.
|
||||||
|
*/
|
||||||
|
function writeUnpinned(ids: string[]): void {
|
||||||
|
if (typeof localStorage === 'undefined') return
|
||||||
|
try {
|
||||||
|
localStorage.setItem(PIN_KEY, JSON.stringify({ unpinned: ids }))
|
||||||
|
localStorage.setItem(MARK_KEY, CUSTOM_MARK)
|
||||||
|
location.reload()
|
||||||
|
} catch {
|
||||||
|
// A storage that refuses the write keeps the current layout.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setting block: one checkbox per known entry plus an apply button.
|
||||||
|
*
|
||||||
|
* @returns the setting rows.
|
||||||
|
*/
|
||||||
|
export function CollapsedPanelsSetting(): React.ReactNode {
|
||||||
|
const [selected, setSelected] = useState<string[]>([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelected(readUnpinned())
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function toggle(id: string, next: boolean): void {
|
||||||
|
setSelected(current => (next ? [...current.filter(entry => entry !== id), id] : current.filter(entry => entry !== id)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div data-apesi-collapsed-panels="setting">
|
||||||
|
<div className="css.subHeading" style={{ color: 'var(--dsw-alias-label-primary, inherit)' }}>{t('settingsCollapsedPanelsTitle')}</div>
|
||||||
|
{CANDIDATE_PANELS.map(panel => (
|
||||||
|
<SettingRow
|
||||||
|
key={panel.id}
|
||||||
|
label={panel.label}
|
||||||
|
description={t('settingsCollapsedPanelsDesc')}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
aria-label={panel.label}
|
||||||
|
checked={selected.includes(panel.id)}
|
||||||
|
onChange={event => toggle(panel.id, event.currentTarget.checked)}
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
))}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => writeUnpinned(selected)}
|
||||||
|
style={{
|
||||||
|
marginTop: '8px',
|
||||||
|
padding: '6px 14px',
|
||||||
|
borderRadius: '6px',
|
||||||
|
border: '1px solid var(--dsw-alias-border-l1, rgba(0,0,0,0.12))',
|
||||||
|
background: 'var(--dsw-alias-bg-container, transparent)',
|
||||||
|
color: 'var(--dsw-alias-label-primary, inherit)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('settingsCollapsedPanelsApply')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
* mermaid libraries arrive as lazy chunks).
|
* mermaid libraries arrive as lazy chunks).
|
||||||
*/
|
*/
|
||||||
import { createElement, Fragment } from 'react'
|
import { createElement, Fragment } from 'react'
|
||||||
|
import { OfficeView } from './office-view.tsx'
|
||||||
import { createRoot, type Root } from 'react-dom/client'
|
import { createRoot, type Root } from 'react-dom/client'
|
||||||
import type { Context } from '../context-types.ts'
|
import type { Context } from '../context-types.ts'
|
||||||
import { createSidebarStore } from './state.ts'
|
import { createSidebarStore } from './state.ts'
|
||||||
@@ -82,11 +83,65 @@ export const inject = ['slots', 'sessions', 'locale', 'modules', 'connection', '
|
|||||||
* per-tab scope (Sidebar.tsx) catches viewer/editor crashes first; this root
|
* per-tab scope (Sidebar.tsx) catches viewer/editor crashes first; this root
|
||||||
* boundary stays as the last resort for Workbench/shell errors.
|
* boundary stays as the last resort for Workbench/shell errors.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 宿主左栏的「取消固定」状态:localStorage `dsh-desktop.sidebar.panel-pins`
|
||||||
|
* 形如 `{ unpinned: string[] }`。未被固定的入口会从左栏隐藏,收进宿主自带的
|
||||||
|
* 「更多」菜单(`sidebar.panellist.actions` → entry-customization)。
|
||||||
|
*
|
||||||
|
* 我们在**首次见到该键**时写入默认折叠清单(插件市场 / 上下文洞察 / 任务看板),
|
||||||
|
* 让左栏只留常用入口;用户之后手动 pin / unpin 的选择不再被覆盖。
|
||||||
|
* `plugins`(宿主内置的插件管理入口)是固定项,不可折叠。
|
||||||
|
*/
|
||||||
|
const PANEL_PIN_KEY = 'dsh-desktop.sidebar.panel-pins'
|
||||||
|
const DEFAULT_COLLAPSED_PANELS = ['dsh-market', 'dsh-context', 'task-board', 'forge-review']
|
||||||
|
const PANEL_PIN_MARK_KEY = 'dsh-apes-sidebar:collapsed-defaults'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入默认折叠清单(仅当用户从未做过 pin 选择、或默认集合升级时补齐缺项)。
|
||||||
|
*
|
||||||
|
* 宿主的 pin store 在它自己的模块初始化时读取该键,我们的 bundle 加载更晚,
|
||||||
|
* 因此写入后刷新一次页面让折叠生效;标记键记录我们已写过的默认集合,
|
||||||
|
* 之后用户手动 pin / unpin 的结果不再被改动。
|
||||||
|
*/
|
||||||
|
function ensureDefaultCollapsedPanels(): void {
|
||||||
|
if (typeof localStorage === 'undefined') return
|
||||||
|
try {
|
||||||
|
const mark = localStorage.getItem(PANEL_PIN_MARK_KEY)
|
||||||
|
// `custom` = the user manages the folded set in the settings block; the
|
||||||
|
// default set must not creep back in.
|
||||||
|
if (mark === 'custom') return
|
||||||
|
if (mark === DEFAULT_COLLAPSED_PANELS.join(',')) return
|
||||||
|
const raw = localStorage.getItem(PANEL_PIN_KEY)
|
||||||
|
const current = raw === null ? [] : (JSON.parse(raw)?.unpinned ?? [])
|
||||||
|
if (!Array.isArray(current)) return
|
||||||
|
// 只补齐缺项:用户手动 pin 回来的入口,若不在默认集合里则保持不变。
|
||||||
|
const merged = [...current]
|
||||||
|
for (const id of DEFAULT_COLLAPSED_PANELS) if (!merged.includes(id)) merged.push(id)
|
||||||
|
localStorage.setItem(PANEL_PIN_KEY, JSON.stringify({ unpinned: merged }))
|
||||||
|
localStorage.setItem(PANEL_PIN_MARK_KEY, DEFAULT_COLLAPSED_PANELS.join(','))
|
||||||
|
console.info('[dsh-apes-sidebar] 已写入默认折叠的侧栏入口,刷新后生效')
|
||||||
|
location.reload()
|
||||||
|
} catch {
|
||||||
|
// 存储不可用(隐私模式 / 配额满)时保持宿主默认,不阻断插件装载。
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client plugin body.
|
* Client plugin body.
|
||||||
* @param ctx - the client cordis context (slots, sessions).
|
* @param ctx - the client cordis context (slots, sessions).
|
||||||
*/
|
*/
|
||||||
export function apply(ctx: Context): void {
|
export function apply(ctx: Context): void {
|
||||||
|
ensureDefaultCollapsedPanels()
|
||||||
|
// The ApeSi session view: the current session's Office document list, placed
|
||||||
|
// AFTER the host's own views (上下文 order 20 / 编队 order 30 → ours is 40).
|
||||||
|
// The host renders every `conversation.view` registration into the session
|
||||||
|
// header tab strip, and passes the session it renders.
|
||||||
|
ctx.slots.inject('conversation.view', () =>
|
||||||
|
ctx.slots.register(
|
||||||
|
{ name: 'conversation.view', id: 'apesi-office', order: 40, label: () => 'Office' },
|
||||||
|
(viewProps: { sessionId?: string }) => createElement(OfficeView, { ...viewProps, ctx }),
|
||||||
|
),
|
||||||
|
)
|
||||||
// The sidebar follows the DSH i18n system: attach the locale service so
|
// The sidebar follows the DSH i18n system: attach the locale service so
|
||||||
// the module-level t()/isZh() resolve the Host-backed language preference
|
// the module-level t()/isZh() resolve the Host-backed language preference
|
||||||
// (and switch live — the Sidebar root subscribes to it), and register the
|
// (and switch live — the Sidebar root subscribes to it), and register the
|
||||||
|
|||||||
@@ -506,6 +506,9 @@ export const zh = {
|
|||||||
settingsMobileTreeTitle: '窄屏时任务页默认树状图',
|
settingsMobileTreeTitle: '窄屏时任务页默认树状图',
|
||||||
settingsMobileTreeDesc: '手机 / 窄屏下任务页默认用经典树,而不是工作流图;页内切换仍可临时改成图',
|
settingsMobileTreeDesc: '手机 / 窄屏下任务页默认用经典树,而不是工作流图;页内切换仍可临时改成图',
|
||||||
settingsGeneralTitle: '常规',
|
settingsGeneralTitle: '常规',
|
||||||
|
settingsCollapsedPanelsTitle: '折叠的侧栏入口',
|
||||||
|
settingsCollapsedPanelsDesc: '勾选后该入口从左侧栏收进「更多」菜单,随时可在那里钉回。',
|
||||||
|
settingsCollapsedPanelsApply: '应用并刷新',
|
||||||
settingsPopup: '功能设置',
|
settingsPopup: '功能设置',
|
||||||
settingsViewerCatchAll: '兜底:任意文件',
|
settingsViewerCatchAll: '兜底:任意文件',
|
||||||
viewerMarkdown: 'Markdown',
|
viewerMarkdown: 'Markdown',
|
||||||
@@ -1779,6 +1782,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|||||||
settingsMobileTreeTitle: 'Default the Tasks page to the tree',
|
settingsMobileTreeTitle: 'Default the Tasks page to the tree',
|
||||||
settingsMobileTreeDesc: "On a phone / narrow viewport the Tasks page opens as the classic tree instead of the workflow graph; the in-page toggle still switches it ad hoc",
|
settingsMobileTreeDesc: "On a phone / narrow viewport the Tasks page opens as the classic tree instead of the workflow graph; the in-page toggle still switches it ad hoc",
|
||||||
settingsGeneralTitle: 'General',
|
settingsGeneralTitle: 'General',
|
||||||
|
settingsCollapsedPanelsTitle: 'Folded sidebar entries',
|
||||||
|
settingsCollapsedPanelsDesc: 'Checked entries move out of the left sidebar into the More menu; pin them back from there.',
|
||||||
|
settingsCollapsedPanelsApply: 'Apply and refresh',
|
||||||
settingsPopup: 'Feature settings',
|
settingsPopup: 'Feature settings',
|
||||||
settingsViewerCatchAll: 'Catch-all: any file',
|
settingsViewerCatchAll: 'Catch-all: any file',
|
||||||
viewerMarkdown: 'Markdown',
|
viewerMarkdown: 'Markdown',
|
||||||
|
|||||||
@@ -0,0 +1,232 @@
|
|||||||
|
/**
|
||||||
|
* The ApeSi session view: the current session's Office document list.
|
||||||
|
*
|
||||||
|
* The list is served by the `dsh-apesi-dshoffice` bridge (`POST /office/api/files`);
|
||||||
|
* a click opens the file in DSH's NATIVE right sidebar, where the preview and the
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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'
|
||||||
|
import { addressBaseOf } from './address-base.ts'
|
||||||
|
import { hostRouteUrl } from './host-route-url.ts'
|
||||||
|
import { fileAddressFor } from './resource-address.ts'
|
||||||
|
import type { Context } from '../context-types.ts'
|
||||||
|
|
||||||
|
/** One row of the Office list, as the bridge returns it. */
|
||||||
|
interface OfficeFile {
|
||||||
|
name?: string
|
||||||
|
path?: string
|
||||||
|
size?: number
|
||||||
|
updatedAt?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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.
|
||||||
|
*
|
||||||
|
* The bridge answers `{ items, files }`: `items` is the flat document list this
|
||||||
|
* view renders, `files` the directory tree its own page uses. A bridge that is
|
||||||
|
* not installed answers with an error object — that reads as an empty list.
|
||||||
|
*/
|
||||||
|
function normalizeList(payload: unknown): OfficeFile[] {
|
||||||
|
if (payload === null || typeof payload !== 'object') return []
|
||||||
|
const data = payload as { items?: unknown; files?: unknown }
|
||||||
|
const raw = Array.isArray(data.items) ? data.items : Array.isArray(data.files) ? data.files : []
|
||||||
|
return raw.filter((entry): entry is OfficeFile => entry !== null && typeof entry === 'object')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The row's display name: the file name, or the tail of its path. */
|
||||||
|
function displayName(file: OfficeFile): string {
|
||||||
|
if (typeof file.name === 'string' && file.name !== '') return file.name
|
||||||
|
if (typeof file.path === 'string') {
|
||||||
|
const parts = file.path.split(/[\\/]/).filter(part => part !== '')
|
||||||
|
return parts[parts.length - 1] ?? file.path
|
||||||
|
}
|
||||||
|
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 (the host sends none) and our client context.
|
||||||
|
* @returns the list view (idle / loading / empty / rows).
|
||||||
|
*/
|
||||||
|
export function OfficeView(props: OfficeViewProps): ReactNode {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
let cancelled = false
|
||||||
|
fetch(hostRouteUrl('office/api/files').href, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'content-type': 'application/json' },
|
||||||
|
body: JSON.stringify({ sessionId }),
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(payload => {
|
||||||
|
if (cancelled) return
|
||||||
|
setFiles(normalizeList(payload))
|
||||||
|
setFailed(false)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (cancelled) return
|
||||||
|
// The bridge is absent or unreachable: the view stays, empty.
|
||||||
|
setFiles([])
|
||||||
|
setFailed(true)
|
||||||
|
})
|
||||||
|
return () => {
|
||||||
|
cancelled = true
|
||||||
|
}
|
||||||
|
}, [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 SidebarRightFace | undefined
|
||||||
|
const address = fileAddressFor(sessionId, addressBaseOf(ctx, sessionId), file.path)
|
||||||
|
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 panel(createElement('span', { style: { opacity: 0.7 } }, '加载中…'), 'loading')
|
||||||
|
}
|
||||||
|
if (files.length === 0) {
|
||||||
|
return panel(
|
||||||
|
createElement(
|
||||||
|
'span',
|
||||||
|
{ style: { opacity: 0.7 } },
|
||||||
|
failed ? 'Office 桥接不可用(dsh-apesi-dshoffice 未安装)' : '本会话暂无 Office 文档',
|
||||||
|
),
|
||||||
|
failed ? 'failed' : 'empty',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return panel(
|
||||||
|
[
|
||||||
|
createElement(
|
||||||
|
'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