inline.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import type { ReactNode, RefObject } from "react";
  2. import type { DocKind, DocumentInfo } from "#office/contract.ts";
  3. import type { Strings } from "#ui/i18n.ts";
  4. import { Icon } from "#ui/icons.tsx";
  5. import { baseName } from "#ui/rpc.ts";
  6. import { ErrorState, Skeleton } from "#ui/shell/panes.tsx";
  7. import type { Failure } from "#ui/shell/state.ts";
  8. /**
  9. * 内联(对话内嵌)模式的面板:只读预览,点击任意处切到侧栏全屏。
  10. * 从 main.tsx 的 Shell 拆出以控制单文件规模;查看器元素与各 ref 仍由 Shell 持有并传入。
  11. */
  12. export function InlineShell({
  13. appRef,
  14. canvasRef,
  15. t,
  16. path,
  17. info,
  18. kind,
  19. showSkeleton,
  20. failure,
  21. nothing,
  22. onExpand,
  23. children,
  24. }: {
  25. appRef: RefObject<HTMLDivElement | null>;
  26. canvasRef: RefObject<HTMLDivElement | null>;
  27. t: Strings;
  28. path: string | null;
  29. info: DocumentInfo | undefined;
  30. kind: DocKind | null;
  31. showSkeleton: boolean;
  32. failure: Failure | null;
  33. nothing: boolean;
  34. onExpand(): void;
  35. children: ReactNode;
  36. }) {
  37. return (
  38. <div ref={appRef} className="app inline">
  39. <header className="docbar">
  40. <div className="doctitle static" title={path ?? undefined}>
  41. <span className="name">{path ? baseName(path) : t.title}</span>
  42. {info && t.meta[info.kind](info.units) ? (
  43. <span className="meta">{t.meta[info.kind](info.units)}</span>
  44. ) : null}
  45. </div>
  46. <span className="spacer" />
  47. <button type="button" className="btn sm" title={t.sidePanel} onClick={onExpand}>
  48. <Icon name="maximize-2" size={12} />
  49. {t.sidePanel}
  50. </button>
  51. </header>
  52. <div className="stage">
  53. <div ref={canvasRef} className="canvas">
  54. {children}
  55. {showSkeleton ? <Skeleton kind={kind} /> : null}
  56. {failure ? (
  57. <ErrorState
  58. t={t}
  59. title={failure.title}
  60. detail={failure.detail}
  61. onOpenAnother={onExpand}
  62. />
  63. ) : null}
  64. {nothing ? <div className="failed muted">{t.openTitle}</div> : null}
  65. <button
  66. type="button"
  67. className="glance-cover"
  68. aria-label={t.sidePanel}
  69. onClick={onExpand}
  70. />
  71. </div>
  72. </div>
  73. </div>
  74. );
  75. }