contract.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /** Document renderer slot: the owner supplies shared file state, renderers own their presentation. */
  2. import type { PropsRuntime, SlotHookFactory } from '@deepseek-ai/dsh-client-ui-slots'
  3. import type { UseSidebarRightTabInfo } from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
  4. import type { RefCallback } from 'react'
  5. /** One loaded text window, retaining source line positions. */
  6. export interface DocumentTextPage {
  7. readonly offset: number
  8. readonly text: string
  9. readonly lines: number
  10. }
  11. /**
  12. * Contents prepared by the preview owner using ordinary file reads.
  13. * Byte arrays are transient UI input, never persisted layout or Session data.
  14. */
  15. export type DocumentContent =
  16. | { readonly kind: 'text'; readonly text: string; readonly pages: readonly DocumentTextPage[]; readonly eof: boolean }
  17. | { readonly kind: 'bytes'; readonly data: Uint8Array<ArrayBuffer> }
  18. declare module '@deepseek-ai/dsh-client-ui-slots' {
  19. interface SlotMap {
  20. /** Document body selected by a registered implementation id. */
  21. 'sidebar.right.tab.document': {
  22. kind: 'keyed'
  23. scope: 'session'
  24. owner: {
  25. /** Original file address, also readable through the standard useResource hook. */
  26. readonly resourceAddress: string
  27. /** Loaded content; text is an accumulated prefix until eof. */
  28. readonly content: DocumentContent
  29. /** The document toolbar's current wrapping preference. */
  30. readonly wrap: boolean
  31. /** Report a renderer-owned scrollport; passing `null` restores the shared body as the owner. */
  32. readonly scrollportRef: RefCallback<HTMLElement>
  33. }
  34. hookContext: UseSidebarRightTabInfo
  35. inject: {
  36. hooks: {
  37. tabInfo: SlotHookFactory<'sidebar.right.tab.document', UseSidebarRightTabInfo>
  38. }
  39. }
  40. }
  41. }
  42. }
  43. /** Standard input for every document body; entry-local stores and locale props can be intersected with it. */
  44. export type DocumentPreviewProps = PropsRuntime<'sidebar.right.tab.document'>
  45. /**
  46. * Forward the framework's tab reader to the selected document body.
  47. * @param _standard - framework standard props.
  48. * @param useTabInfo - enclosing tab's bound reader.
  49. * @returns the same reader, without another subscription adapter.
  50. */
  51. export const documentTabInfoFactory: SlotHookFactory<'sidebar.right.tab.document', UseSidebarRightTabInfo> =
  52. (_standard, useTabInfo) => useTabInfo