@deepseek-ai/dsh-client-ui-sidebar-documentpreview 0.1.5-alpha.2
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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +92 -0
- package/README.zh.md +92 -0
- package/lib/client.js +26957 -0
- package/lib/index.js +6 -0
- package/lib/types/client/LoadingIndicator.d.ts +8 -0
- package/lib/types/client/TextPreview.d.ts +23 -0
- package/lib/types/client/TextTitle.d.ts +14 -0
- package/lib/types/client/code/CodeBody.d.ts +9 -0
- package/lib/types/client/code/index.d.ts +5 -0
- package/lib/types/client/code/languages.d.ts +9 -0
- package/lib/types/client/code/locales.d.ts +19 -0
- package/lib/types/client/definition.d.ts +32 -0
- package/lib/types/client/document/contract.d.ts +55 -0
- package/lib/types/client/document/registry.d.ts +55 -0
- package/lib/types/client/face.d.ts +72 -0
- package/lib/types/client/failure-line.d.ts +17 -0
- package/lib/types/client/html/HtmlBody.d.ts +16 -0
- package/lib/types/client/html/bootstrap.d.ts +20 -0
- package/lib/types/client/html/bytes.d.ts +14 -0
- package/lib/types/client/html/index.d.ts +17 -0
- package/lib/types/client/html/locales.d.ts +23 -0
- package/lib/types/client/html/pack.d.ts +21 -0
- package/lib/types/client/html/read-relative.d.ts +21 -0
- package/lib/types/client/icons.d.ts +14 -0
- package/lib/types/client/image/ImageBody.d.ts +31 -0
- package/lib/types/client/image/index.d.ts +19 -0
- package/lib/types/client/image/locales.d.ts +25 -0
- package/lib/types/client/index.d.ts +51 -0
- package/lib/types/client/locales.d.ts +52 -0
- package/lib/types/client/markdown/MarkdownBody.d.ts +12 -0
- package/lib/types/client/markdown/index.d.ts +17 -0
- package/lib/types/client/markdown/locales.d.ts +23 -0
- package/lib/types/client/pdf/PdfBody.d.ts +24 -0
- package/lib/types/client/pdf/assets.d.ts +26 -0
- package/lib/types/client/pdf/document.d.ts +32 -0
- package/lib/types/client/pdf/errors.d.ts +8 -0
- package/lib/types/client/pdf/index.d.ts +14 -0
- package/lib/types/client/pdf/locales.d.ts +33 -0
- package/lib/types/client/pdf/runtime.d.ts +14 -0
- package/lib/types/client/pdf/store.d.ts +26 -0
- package/lib/types/client/rpc.d.ts +77 -0
- package/lib/types/client/store.d.ts +90 -0
- package/lib/types/client/text/TextBody.d.ts +6 -0
- package/lib/types/client/text/index.d.ts +14 -0
- package/lib/types/client/text/lines.d.ts +31 -0
- package/lib/types/index.d.ts +4 -0
- package/package.json +78 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sidebarDocumentPreview` namespace dictionaries.
|
|
3
|
+
*
|
|
4
|
+
* The failure lines are the point of this file: a preview that cannot show a
|
|
5
|
+
* page has to say which of several different things went wrong, and each one
|
|
6
|
+
* suggests a different next step for the reader.
|
|
7
|
+
*/
|
|
8
|
+
/** Simplified Chinese dictionary and key-set source of truth. */
|
|
9
|
+
export declare const zh: {
|
|
10
|
+
loading: string;
|
|
11
|
+
loadMore: string;
|
|
12
|
+
changed: string;
|
|
13
|
+
reloadNow: string;
|
|
14
|
+
reload: string;
|
|
15
|
+
'wrap.enable': string;
|
|
16
|
+
'wrap.disable': string;
|
|
17
|
+
'wrap.aria': string;
|
|
18
|
+
openWith: string;
|
|
19
|
+
'viewer.text': string;
|
|
20
|
+
resourceUnavailable: string;
|
|
21
|
+
rendererUnavailable: string;
|
|
22
|
+
'error.notFound': string;
|
|
23
|
+
'error.tooLarge': string;
|
|
24
|
+
'error.notText': string;
|
|
25
|
+
'error.notRegularFile': string;
|
|
26
|
+
'error.unavailable': string;
|
|
27
|
+
retry: string;
|
|
28
|
+
};
|
|
29
|
+
/** Text-preview dictionary key union. */
|
|
30
|
+
export type SidebarDocumentPreviewKey = keyof typeof zh;
|
|
31
|
+
/** English dictionary, checked against the Chinese key set. */
|
|
32
|
+
export declare const en: {
|
|
33
|
+
loading: string;
|
|
34
|
+
loadMore: string;
|
|
35
|
+
changed: string;
|
|
36
|
+
reloadNow: string;
|
|
37
|
+
reload: string;
|
|
38
|
+
'wrap.enable': string;
|
|
39
|
+
'wrap.disable': string;
|
|
40
|
+
'wrap.aria': string;
|
|
41
|
+
openWith: string;
|
|
42
|
+
'viewer.text': string;
|
|
43
|
+
resourceUnavailable: string;
|
|
44
|
+
rendererUnavailable: string;
|
|
45
|
+
'error.notFound': string;
|
|
46
|
+
'error.tooLarge': string;
|
|
47
|
+
'error.notText': string;
|
|
48
|
+
'error.notRegularFile': string;
|
|
49
|
+
'error.unavailable': string;
|
|
50
|
+
retry: string;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
3
|
+
import type { DocumentPreviewProps } from '../document/contract.ts';
|
|
4
|
+
/** Standard document inputs and this implementation's locale. */
|
|
5
|
+
export type MarkdownBodyProps = DocumentPreviewProps & PropsLocale<'documentMarkdown'>;
|
|
6
|
+
/**
|
|
7
|
+
* Render one accumulated document; EOF completes the primitive's full parse.
|
|
8
|
+
* @param props - owner-loaded contents and localized primitive labels.
|
|
9
|
+
* @returns Markdown content, or nothing for a non-text delivery.
|
|
10
|
+
*/
|
|
11
|
+
export declare function MarkdownBody({ content, t }: MarkdownBodyProps): ReactNode;
|
|
12
|
+
//# sourceMappingURL=MarkdownBody.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Builtin Markdown metadata and keyed document-body registration. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { DocumentPreviewDefinition } from '../document/registry.ts';
|
|
4
|
+
/** Implementation identity shared by metadata and the document slot. */
|
|
5
|
+
export declare const MARKDOWN_BODY_ID = "@deepseek-ai/dsh-client-ui-sidebar-documentpreview/markdown";
|
|
6
|
+
/**
|
|
7
|
+
* Describe the Markdown implementation without taking ownership of loading.
|
|
8
|
+
* @param title - locale-owned implementation name.
|
|
9
|
+
* @returns builtin Markdown registration metadata.
|
|
10
|
+
*/
|
|
11
|
+
export declare function markdownDefinition(title: () => string): DocumentPreviewDefinition;
|
|
12
|
+
/**
|
|
13
|
+
* Register locale, metadata, and the document body for the owning plugin lifetime.
|
|
14
|
+
* @param ctx - plugin context carrying locale, document registry, and slots.
|
|
15
|
+
*/
|
|
16
|
+
export declare function apply(ctx: Context): void;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Markdown implementation labels and primitive chrome. */
|
|
2
|
+
export declare const zh: {
|
|
3
|
+
'viewer.label': string;
|
|
4
|
+
'code.copy': string;
|
|
5
|
+
'code.copied': string;
|
|
6
|
+
footnotes: string;
|
|
7
|
+
};
|
|
8
|
+
/** Markdown namespace keys. */
|
|
9
|
+
export type MarkdownPreviewKey = keyof typeof zh;
|
|
10
|
+
/** English labels, paired with the Chinese key set. */
|
|
11
|
+
export declare const en: {
|
|
12
|
+
'viewer.label': string;
|
|
13
|
+
'code.copy': string;
|
|
14
|
+
'code.copied': string;
|
|
15
|
+
footnotes: string;
|
|
16
|
+
};
|
|
17
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
18
|
+
interface LocaleNamespaceMap {
|
|
19
|
+
/** Markdown document renderer and its code/footnote controls. */
|
|
20
|
+
documentMarkdown: MarkdownPreviewKey;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** PDF page presentation; binary content and tab information come from the document owner. */
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import type { PropsLocale, PropsStore } from '@deepseek-ai/dsh-client-ui-slots';
|
|
4
|
+
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit';
|
|
5
|
+
import type { DocumentPreviewProps } from '../document/contract.ts';
|
|
6
|
+
import { type PdfStore } from './store.ts';
|
|
7
|
+
/** A record's viewing preferences survive body unmounts and leave with the tab. */
|
|
8
|
+
export interface PdfBodyInjected {
|
|
9
|
+
/**
|
|
10
|
+
* Retain viewing preferences until the tab record ends.
|
|
11
|
+
* @param tabId - owning tab.
|
|
12
|
+
* @param signal - tab-record lifetime, not body visibility.
|
|
13
|
+
*/
|
|
14
|
+
readonly retainTab: (tabId: TabId, signal: AbortSignal) => void;
|
|
15
|
+
}
|
|
16
|
+
/** Standard document props plus the PDF entry's locale, viewing store, and lifetime callback. */
|
|
17
|
+
export type PdfBodyProps = DocumentPreviewProps & PropsLocale<'sidebarPdf'> & PropsStore<PdfStore> & PdfBodyInjected;
|
|
18
|
+
/**
|
|
19
|
+
* Present a PDF with tab-local viewing preferences and component-owned rendering resources.
|
|
20
|
+
* @param props - complete bytes and framework-owned tab/store/locale seats.
|
|
21
|
+
* @returns the PDF reader.
|
|
22
|
+
*/
|
|
23
|
+
export declare function PdfBody(props: PdfBodyProps): ReactNode;
|
|
24
|
+
//# sourceMappingURL=PdfBody.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Build-owned, same-version PDF.js resources; all binary assets are decoded locally. */
|
|
2
|
+
import workerSource from 'pdfjs-dist/build/pdf.worker.min.mjs?raw';
|
|
3
|
+
export { workerSource };
|
|
4
|
+
/** Resource kinds used by PDF.js 6's BinaryDataFactory requests. */
|
|
5
|
+
export type PdfAssetKind = 'cMapUrl' | 'standardFontDataUrl' | 'wasmUrl';
|
|
6
|
+
/** Original filenames mapped to base64, in the same PDF.js version as the worker. */
|
|
7
|
+
export type PdfAssetMap = Readonly<Record<PdfAssetKind, Readonly<Record<string, string>>>>;
|
|
8
|
+
declare global {
|
|
9
|
+
/** Inline artifact data supplied by the package-local build configuration. */
|
|
10
|
+
const __DSH_PDFJS_ASSETS__: PdfAssetMap;
|
|
11
|
+
}
|
|
12
|
+
/** Public methods required by PDF.js's BinaryDataFactory option. */
|
|
13
|
+
export interface PdfBinaryDataFactory {
|
|
14
|
+
/** @param request - PDF.js resource kind and exact filename. @returns independent transferable resource bytes. */
|
|
15
|
+
fetch(request: {
|
|
16
|
+
readonly kind: PdfAssetKind;
|
|
17
|
+
readonly filename: string;
|
|
18
|
+
}): Promise<Uint8Array>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Capture this build's binary assets without network fallbacks.
|
|
22
|
+
* @param assets - build-inlined base64 resources, read only when a PDF is opened.
|
|
23
|
+
* @returns the constructor passed to PDF.js getDocument.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createPdfBinaryDataFactory(assets?: PdfAssetMap): new () => PdfBinaryDataFactory;
|
|
26
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Canvas rendering with cancellation and page cleanup, shared by the PDF body and real-library smoke. */
|
|
2
|
+
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
|
3
|
+
/** The document operations used by one mounted PDF body. */
|
|
4
|
+
export type PdfDocument = Pick<PDFDocumentProxy, 'numPages' | 'getPage'>;
|
|
5
|
+
/** One in-flight PDF load and its complete cleanup operation. */
|
|
6
|
+
export interface PdfSession {
|
|
7
|
+
readonly document: Promise<PdfDocument>;
|
|
8
|
+
/**
|
|
9
|
+
* Cancel loading and rendering, destroy the document, and release its worker.
|
|
10
|
+
* Library teardown failures are logged after native resources are released.
|
|
11
|
+
* @returns cleanup completion without rejection.
|
|
12
|
+
*/
|
|
13
|
+
dispose(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/** Page geometry expressed in CSS pixels. */
|
|
16
|
+
export interface PdfPageSize {
|
|
17
|
+
readonly width: number;
|
|
18
|
+
readonly height: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Render one page into an exclusively owned canvas. Cancellation cannot write
|
|
22
|
+
* dimensions after a delayed getPage; active render tasks are cancelled and
|
|
23
|
+
* awaited before the page is cleaned up.
|
|
24
|
+
* @param document - loaded pdfjs document.
|
|
25
|
+
* @param pageNumber - 1-based selected page.
|
|
26
|
+
* @param canvas - canvas owned by this render only.
|
|
27
|
+
* @param signal - render lifetime.
|
|
28
|
+
* @param pixelRatio - display pixel ratio.
|
|
29
|
+
* @returns the page's CSS dimensions after rendering completes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderPdfPage(document: PdfDocument, pageNumber: number, canvas: HTMLCanvasElement, signal: AbortSignal, pixelRatio: number): Promise<PdfPageSize>;
|
|
32
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Structured PDF worker failures; the renderer's locale owns visible explanations. */
|
|
2
|
+
export declare class PdfWorkerFailure extends Error {
|
|
3
|
+
/** Distinguishes Worker startup/transport failures from document parsing errors. */
|
|
4
|
+
readonly kind = "worker";
|
|
5
|
+
/** @param cause - native error or messageerror event, retained for diagnostics. */
|
|
6
|
+
constructor(cause: Event);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Builtin PDF registration through document metadata and the keyed body slot. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { DocumentPreviewDefinition } from '../document/registry.ts';
|
|
4
|
+
/** PDF metadata and keyed body share this package-local implementation identity. */
|
|
5
|
+
export declare const PDF_BODY_ID = "@deepseek-ai/dsh-client-ui-sidebar-documentpreview/pdf";
|
|
6
|
+
/**
|
|
7
|
+
* Describe the builtin PDF renderer independently from its keyed body slot.
|
|
8
|
+
* @param title - locale-owned implementation name.
|
|
9
|
+
* @returns the complete-file PDF registration.
|
|
10
|
+
*/
|
|
11
|
+
export declare function pdfBodyDefinition(title: () => string): DocumentPreviewDefinition;
|
|
12
|
+
/** @param ctx - context carrying the locale, document registry, and slot registry. */
|
|
13
|
+
export declare function apply(ctx: Context): void;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Copy owned by the PDF renderer. */
|
|
2
|
+
export declare const zh: {
|
|
3
|
+
title: string;
|
|
4
|
+
pageImage: string;
|
|
5
|
+
loading: string;
|
|
6
|
+
rendering: string;
|
|
7
|
+
failed: string;
|
|
8
|
+
password: string;
|
|
9
|
+
workerFailed: string;
|
|
10
|
+
unsupported: string;
|
|
11
|
+
retry: string;
|
|
12
|
+
};
|
|
13
|
+
/** PDF translation keys shared by both dictionaries. */
|
|
14
|
+
export type PdfLocaleKey = keyof typeof zh;
|
|
15
|
+
/** English PDF-renderer dictionary. */
|
|
16
|
+
export declare const en: {
|
|
17
|
+
title: string;
|
|
18
|
+
pageImage: string;
|
|
19
|
+
loading: string;
|
|
20
|
+
rendering: string;
|
|
21
|
+
failed: string;
|
|
22
|
+
password: string;
|
|
23
|
+
workerFailed: string;
|
|
24
|
+
unsupported: string;
|
|
25
|
+
retry: string;
|
|
26
|
+
};
|
|
27
|
+
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
28
|
+
interface LocaleNamespaceMap {
|
|
29
|
+
/** PDF page, loading, and failure messages. */
|
|
30
|
+
sidebarPdf: PdfLocaleKey;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=locales.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PdfSession } from './document.ts';
|
|
2
|
+
import { PdfWorkerFailure } from './errors.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Open complete PDF bytes with an explicitly owned Worker. Startup failure
|
|
5
|
+
* never falls back to main-thread PDF parsing. Disposal keeps the Worker alive
|
|
6
|
+
* for PDF.js teardown, except after a fatal worker error, then terminates the
|
|
7
|
+
* native Worker and revokes its source URL.
|
|
8
|
+
* @param data - complete PDF bytes retained by the preview; the worker receives a copy.
|
|
9
|
+
* @param signal - document/body lifetime.
|
|
10
|
+
* @param reportFailure - reports a fatal Worker failure, including failures after document loading.
|
|
11
|
+
* @returns the pending document and idempotent asynchronous cleanup.
|
|
12
|
+
*/
|
|
13
|
+
export declare function openPdf(data: Uint8Array<ArrayBuffer>, signal: AbortSignal, reportFailure: (error: PdfWorkerFailure) => void): PdfSession;
|
|
14
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Restorable PDF viewing preferences; document objects and canvases remain component-local. */
|
|
2
|
+
import { type EngineStoreHandle } from '@deepseek-ai/dsh-client-store';
|
|
3
|
+
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit';
|
|
4
|
+
/** One tab's last visible page. */
|
|
5
|
+
export interface PdfView {
|
|
6
|
+
readonly page: number;
|
|
7
|
+
}
|
|
8
|
+
/** Initial viewing position before a tab reaches another page. */
|
|
9
|
+
export declare const DEFAULT_PDF_VIEW: PdfView;
|
|
10
|
+
/** Page state isolated by the owning tab record. */
|
|
11
|
+
export interface PdfState {
|
|
12
|
+
byTab: Record<TabId, PdfView>;
|
|
13
|
+
}
|
|
14
|
+
type PdfActions = {
|
|
15
|
+
page: (draft: PdfState, tabId: TabId, page: number) => void;
|
|
16
|
+
forget: (draft: PdfState, tabId: TabId) => void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Declare the last visible page isolated by tab identity.
|
|
20
|
+
* @returns a store declaration instantiated by the document slot for each Session.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPdfStore(): EngineStoreHandle<PdfState, PdfActions>;
|
|
23
|
+
/** Store declaration used by the PDF body registration. */
|
|
24
|
+
export type PdfStore = ReturnType<typeof createPdfStore>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paged read this type performs, bound to the Client Remote.
|
|
3
|
+
*
|
|
4
|
+
* Content is the consumer's business: the `file` resource carries metadata only,
|
|
5
|
+
* and the text arrives here one page of lines at a time. The endpoint takes a
|
|
6
|
+
* session and a workspace path while a tab carries a `dsh-resource://file/`
|
|
7
|
+
* session address, so this module also owns that translation.
|
|
8
|
+
*/
|
|
9
|
+
import type { RemoteResult } from '@deepseek-ai/dsh-api-remotes/client';
|
|
10
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
11
|
+
import type { WorkspaceFileBytes, WorkspaceFileRange, WorkspaceFileText } from '@deepseek-ai/dsh-api-workspace-files/types';
|
|
12
|
+
/** The slice of the Client Remote this package calls. */
|
|
13
|
+
export interface WorkspaceFilesReadRemote {
|
|
14
|
+
readonly workspaceFiles: {
|
|
15
|
+
/**
|
|
16
|
+
* Read one page of lines.
|
|
17
|
+
* @param sessionId - the session whose workspace resolves `path`.
|
|
18
|
+
* @param path - workspace path, absolute or relative to the workspace root.
|
|
19
|
+
* @param range - 1-based start line; the Host's page cap applies when `limit` is absent.
|
|
20
|
+
* @param signal - cancels the call.
|
|
21
|
+
* @returns the page, or the failure the Host declares.
|
|
22
|
+
*/
|
|
23
|
+
read(sessionId: SessionId, path: string, range: WorkspaceFileRange, signal?: AbortSignal): Promise<RemoteResult<WorkspaceFileText>>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The read one page performs, injected so the face stays host-free.
|
|
28
|
+
*
|
|
29
|
+
* The session travels with the call because the endpoint resolves the workspace
|
|
30
|
+
* root from it: the same path means different files in different sessions. A
|
|
31
|
+
* Remote call does not reject: the result carries the failure.
|
|
32
|
+
*/
|
|
33
|
+
export type ReadWorkspaceFilePage = (sessionId: SessionId, path: string, offset: number, signal: AbortSignal) => Promise<RemoteResult<WorkspaceFileText>>;
|
|
34
|
+
/** The file one tab reads: the session the read runs under and the path handed to the Host. */
|
|
35
|
+
export interface SessionFile {
|
|
36
|
+
/** The Session whose workspace resolves relative paths. */
|
|
37
|
+
readonly sessionId: SessionId;
|
|
38
|
+
/** The path the Host receives, absolute or relative to the addressed Session's workspace. */
|
|
39
|
+
readonly path: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The session and path one `dsh-resource://file/…` address names.
|
|
43
|
+
*
|
|
44
|
+
* A `session` address names its own session and a relative or absolute path, so
|
|
45
|
+
* a tab addressed into another session reads from that session. An `absolute`
|
|
46
|
+
* address carries no session and cannot be read here. The registry routes only
|
|
47
|
+
* session-scoped `file` addresses to this type, so an address `parseFileAddress`
|
|
48
|
+
* rejects or that carries no session is a programming error and throws.
|
|
49
|
+
* @param address - a tab's `dsh-resource://file/…` address.
|
|
50
|
+
* @returns the session and the path to hand the endpoint.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hostFileOf(address: string): SessionFile;
|
|
53
|
+
/**
|
|
54
|
+
* Bind the paged read to one Remote face. The page length is the Host's
|
|
55
|
+
* configured cap, so no `limit` travels.
|
|
56
|
+
* @param remote - the Client Remote carrying the `workspaceFiles` namespace.
|
|
57
|
+
* @returns the read the face performs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createReadPage(remote: WorkspaceFilesReadRemote): ReadWorkspaceFilePage;
|
|
60
|
+
/** Complete document bytes borrowed read-only by renderers; copy before transferring to a Worker. */
|
|
61
|
+
export type DocumentFileBytes = Omit<WorkspaceFileBytes, 'data'> & {
|
|
62
|
+
readonly data: Uint8Array<ArrayBuffer>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Read a complete file through the Host endpoint.
|
|
66
|
+
* @param file - Session and path decoded from the tab address.
|
|
67
|
+
* @param signal - owning tab lifetime.
|
|
68
|
+
* @returns complete wire bytes, including declared failures.
|
|
69
|
+
*/
|
|
70
|
+
export type ReadDocumentBytes = (file: SessionFile, signal: AbortSignal) => Promise<RemoteResult<WorkspaceFileBytes>>;
|
|
71
|
+
/**
|
|
72
|
+
* Decode one successful Remote byte result for document renderers.
|
|
73
|
+
* @param file - Host byte result with base64 data.
|
|
74
|
+
* @returns the same metadata with native bytes; malformed base64 throws.
|
|
75
|
+
*/
|
|
76
|
+
export declare function documentFileBytes(file: WorkspaceFileBytes): DocumentFileBytes;
|
|
77
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preview's own state: the pages it has read, and how the reader views them.
|
|
3
|
+
*
|
|
4
|
+
* The `file` resource carries metadata only, so the text is this type's to fetch
|
|
5
|
+
* and keep — page by page, keyed by the 1-based line each page starts at. The
|
|
6
|
+
* view state (scroll offset, wrap, the navigation already answered) must outlive
|
|
7
|
+
* the body: a tab switched away from unmounts its body and must come back where
|
|
8
|
+
* it was rather than re-read or jump to its opening line again. Bucketed by tab
|
|
9
|
+
* id because two tabs of one file scroll independently.
|
|
10
|
+
*
|
|
11
|
+
* A bucket lives as long as its tab record: the face's first read of a tab arms
|
|
12
|
+
* one listener on the owner's `signal` that forgets the bucket when the record
|
|
13
|
+
* ends, and a tab that never read has no bucket to forget.
|
|
14
|
+
*/
|
|
15
|
+
import type { RemoteFailure } from '@deepseek-ai/dsh-api-remotes/client';
|
|
16
|
+
import { type EngineStoreHandle } from '@deepseek-ai/dsh-client-store';
|
|
17
|
+
import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit';
|
|
18
|
+
import type { WorkspaceFileText } from '@deepseek-ai/dsh-api-workspace-files/types';
|
|
19
|
+
import type { DocumentFileBytes } from './rpc.ts';
|
|
20
|
+
import type { DocumentLoadMode } from './document/registry.ts';
|
|
21
|
+
/**
|
|
22
|
+
* One page as the store keeps it: its text and the Host's line count, which
|
|
23
|
+
* tells a page past the file's last line (`lines: 0`) from a page holding one
|
|
24
|
+
* empty line (`lines: 1`, `text: ''`).
|
|
25
|
+
*/
|
|
26
|
+
export interface TextPage {
|
|
27
|
+
readonly text: string;
|
|
28
|
+
readonly lines: number;
|
|
29
|
+
}
|
|
30
|
+
/** One tab's pages and view. */
|
|
31
|
+
export interface TextTabState {
|
|
32
|
+
/** Explicit viewer choice for this tab; absence follows automatic matching. */
|
|
33
|
+
rendererId?: string;
|
|
34
|
+
/** Current display-loading mode; absent before the first read. */
|
|
35
|
+
mode?: DocumentLoadMode;
|
|
36
|
+
/** Full byte result used by complete-file renderers. */
|
|
37
|
+
complete?: DocumentFileBytes;
|
|
38
|
+
/** The file version the loaded pages belong to; absent before the first page. */
|
|
39
|
+
version: string | undefined;
|
|
40
|
+
/** Metadata version observed when this tab began its current read generation. */
|
|
41
|
+
observedVersion: string | undefined;
|
|
42
|
+
/** Pages by the 1-based line each starts at. */
|
|
43
|
+
pages: Record<number, TextPage>;
|
|
44
|
+
/** Whether the last loaded page reached the end of the file. */
|
|
45
|
+
eof: boolean;
|
|
46
|
+
/** A page read is in flight. */
|
|
47
|
+
loading: boolean;
|
|
48
|
+
/** Why the last page read failed; cleared by the next page. */
|
|
49
|
+
failure: RemoteFailure | undefined;
|
|
50
|
+
/** Scroll offset of the body, in px. */
|
|
51
|
+
scrollTop: number;
|
|
52
|
+
/** Whether long lines wrap instead of scrolling horizontally; on until the reader turns it off. */
|
|
53
|
+
wrap: boolean;
|
|
54
|
+
/** The `navigation.revision` the body already answered; absent before the first. */
|
|
55
|
+
revision: number | undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Every tab's state, keyed by tab id. */
|
|
58
|
+
export interface TextState {
|
|
59
|
+
byTab: Record<TabId, TextTabState>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A tab's state before it reads, scrolls, toggles, or answers anything.
|
|
63
|
+
* @returns the empty bucket.
|
|
64
|
+
*/
|
|
65
|
+
export declare function fresh(): TextTabState;
|
|
66
|
+
/** The preview store's write set; every action names the tab it writes. */
|
|
67
|
+
type TextActions = {
|
|
68
|
+
selected: (draft: TextState, tabId: TabId, rendererId: string | undefined) => void;
|
|
69
|
+
loading: (draft: TextState, tabId: TabId, mode?: DocumentLoadMode, observedVersion?: string) => void;
|
|
70
|
+
complete: (draft: TextState, tabId: TabId, file: DocumentFileBytes) => void;
|
|
71
|
+
page: (draft: TextState, tabId: TabId, page: WorkspaceFileText) => void;
|
|
72
|
+
failed: (draft: TextState, tabId: TabId, failure: RemoteFailure) => void;
|
|
73
|
+
reset: (draft: TextState, tabId: TabId) => void;
|
|
74
|
+
scrolled: (draft: TextState, tabId: TabId, scrollTop: number) => void;
|
|
75
|
+
toggledWrap: (draft: TextState, tabId: TabId) => void;
|
|
76
|
+
navigated: (draft: TextState, tabId: TabId, revision: number) => void;
|
|
77
|
+
forget: (draft: TextState, tabId: TabId) => void;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Declare the preview's store.
|
|
81
|
+
*
|
|
82
|
+
* Constructed once in apply and shared by the body and the tools registrations,
|
|
83
|
+
* which the slot runtime allows because both are session-scoped.
|
|
84
|
+
* @returns the store handle to declare on both registrations.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createTextStore(): EngineStoreHandle<TextState, TextActions>;
|
|
87
|
+
/** The store handle type both registrations declare. */
|
|
88
|
+
export type TextStore = ReturnType<typeof createTextStore>;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Plain source display for files without a more specific document renderer. */
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { DocumentPreviewProps } from '../document/contract.ts';
|
|
4
|
+
/** @param props - document contents and standard tab information. @returns source lines with navigation targets. */
|
|
5
|
+
export declare function TextBody({ content, useTabInfo }: DocumentPreviewProps): ReactNode;
|
|
6
|
+
//# sourceMappingURL=TextBody.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Plain text implementation registered through the same document extension points as other viewers. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { DocumentPreviewDefinition } from '../document/registry.ts';
|
|
4
|
+
/** Stable plain-text implementation identity within this package. */
|
|
5
|
+
export declare const PLAIN_BODY_ID = "@deepseek-ai/dsh-client-ui-sidebar-documentpreview/text";
|
|
6
|
+
/**
|
|
7
|
+
* Describe the plain-text fallback.
|
|
8
|
+
* @param title - locale-owned implementation name.
|
|
9
|
+
* @returns plain-text registration metadata.
|
|
10
|
+
*/
|
|
11
|
+
export declare function textBodyDefinition(title: () => string): DocumentPreviewDefinition;
|
|
12
|
+
/** @param ctx - owning plugin context. Register the fallback metadata and keyed body. */
|
|
13
|
+
export declare function apply(ctx: Context): void;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Source-line helpers shared by the plain renderer and the document scroller. */
|
|
2
|
+
import type { DocumentTextPage } from '../document/contract.ts';
|
|
3
|
+
import type { TextPage } from '../store.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Split a loaded page into its source lines.
|
|
6
|
+
* @param page - source page.
|
|
7
|
+
* @returns its lines, preserving one empty line but excluding a zero-line page.
|
|
8
|
+
*/
|
|
9
|
+
export declare function linesOf(page: TextPage): string[];
|
|
10
|
+
/** Loaded source page with its 1-based start position. */
|
|
11
|
+
export type LoadedPage = DocumentTextPage;
|
|
12
|
+
/**
|
|
13
|
+
* Order loaded pages by source position.
|
|
14
|
+
* @param pages - stored page table.
|
|
15
|
+
* @returns pages in source order.
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadedPages(pages: Readonly<Record<number, TextPage>>): LoadedPage[];
|
|
18
|
+
/**
|
|
19
|
+
* Find the end of the loaded source prefix.
|
|
20
|
+
* @param pages - ordered pages.
|
|
21
|
+
* @returns the last loaded source line, or zero.
|
|
22
|
+
*/
|
|
23
|
+
export declare function lastLineLoaded(pages: readonly LoadedPage[]): number;
|
|
24
|
+
/**
|
|
25
|
+
* Reveal a plain-text or highlighted source line.
|
|
26
|
+
* @param body - scrolling document body.
|
|
27
|
+
* @param line - 1-based source line to reveal.
|
|
28
|
+
* @returns Whether the current renderer exposes that line.
|
|
29
|
+
*/
|
|
30
|
+
export declare function scrollToLine(body: HTMLElement, line: number): boolean;
|
|
31
|
+
//# sourceMappingURL=lines.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-client-ui-sidebar-documentpreview",
|
|
3
|
+
"description": "Extensible document previews for Sidebar files: Markdown, highlighted code, images, PDF, HTML, and plain text",
|
|
4
|
+
"version": "0.1.5-alpha.2",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/client/ui-sidebar-documentpreview"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./client": {
|
|
22
|
+
"types": "./lib/types/client/index.d.ts",
|
|
23
|
+
"default": "./lib/client.js"
|
|
24
|
+
},
|
|
25
|
+
"./src/*": "./src/*",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dsh": {
|
|
29
|
+
"client": {
|
|
30
|
+
"inject": [
|
|
31
|
+
"@deepseek-ai/dsh-api-gateway",
|
|
32
|
+
"@deepseek-ai/dsh-api-workspace-files",
|
|
33
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
34
|
+
"@deepseek-ai/dsh-client-ui-session",
|
|
35
|
+
"@deepseek-ai/dsh-api-remotes"
|
|
36
|
+
],
|
|
37
|
+
"platform": "web"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@deepseek-ai/cordis": "^4.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@testing-library/react": "^16.1.0",
|
|
46
|
+
"@types/react": "~18.3.1",
|
|
47
|
+
"@types/react-dom": "~18.3.0",
|
|
48
|
+
"clsx": "^2.0.0",
|
|
49
|
+
"pdfjs-dist": "6.3.289",
|
|
50
|
+
"react": "^18.2.0",
|
|
51
|
+
"react-dom": "^18.2.0",
|
|
52
|
+
"@deepseek-ai/dsh-api-remotes": "^0.1.5-alpha.2",
|
|
53
|
+
"@deepseek-ai/dsh-api-workspace-files": "^0.1.5-alpha.2",
|
|
54
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.5-alpha.2",
|
|
55
|
+
"@deepseek-ai/dsh-client-resources": "^0.1.5-alpha.2",
|
|
56
|
+
"@deepseek-ai/dsh-client-store": "^0.1.5-alpha.2",
|
|
57
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
58
|
+
"@deepseek-ai/dsh-client-test-runtime": "^0.1.5-alpha.2",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-dockkit": "^0.1.5-alpha.2",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.5-alpha.2",
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.5-alpha.2",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-session": "^0.1.5-alpha.2",
|
|
63
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right": "^0.1.5-alpha.2",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.5-alpha.2",
|
|
65
|
+
"@deepseek-ai/dsh-util-workspace-path": "^0.1.5-alpha.2",
|
|
66
|
+
"@deepseek-ai/dsh-session": "^0.1.5-alpha.2",
|
|
67
|
+
"@deepseek-ai/dsh-api-gateway": "^0.1.5-alpha.2"
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"lib/index.js",
|
|
71
|
+
"lib/client.js",
|
|
72
|
+
"lib/types/**/*.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"scripts": {
|
|
75
|
+
"bundle": "tsdown",
|
|
76
|
+
"watch": "tsdown --watch"
|
|
77
|
+
}
|
|
78
|
+
}
|