Article.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // ─────────────────────────────────────────────
  2. // Props
  3. // ─────────────────────────────────────────────
  4. import type { ArticleMode } from "../../api/article";
  5. import type { IChannel } from "../../api/channel";
  6. import AnthologyTocTree from "../../components/anthology/AnthologyTocTree";
  7. import TypeArticle from "../../components/article/TypeArticle";
  8. import Editor from "../../components/editor";
  9. export interface ArticleEditorProps {
  10. articleId?: string;
  11. anthologyId?: string;
  12. /** 来自 query param "anthology"(无 anthologyId 路由参数时的备用) */
  13. anthology?: string | null;
  14. mode?: ArticleMode;
  15. channelId?: string | null;
  16. // ── 路由事件回调(由 page 层处理导航)──
  17. /** 点击目录树中的文章时触发 */
  18. onArticleClick?: (
  19. anthologyId: string,
  20. articleId: string,
  21. target?: string
  22. ) => void;
  23. /** 选择了新的 anthology 时触发 */
  24. onAnthologySelect?: (anthologyId: string) => void;
  25. /** 文章内部触发跳转(type: 'article' | 'anthology' 等) */
  26. onArticleChange?: (type: string, id: string) => void;
  27. onChannelSelect?: (selected: IChannel[]) => void;
  28. }
  29. // ─────────────────────────────────────────────
  30. // Component
  31. // ─────────────────────────────────────────────
  32. export default function ArticleEditor({
  33. articleId,
  34. anthologyId,
  35. anthology,
  36. mode = "read",
  37. channelId,
  38. onArticleClick,
  39. onAnthologySelect,
  40. onArticleChange,
  41. onChannelSelect,
  42. }: ArticleEditorProps) {
  43. const channels = channelId ? channelId.split("_") : undefined;
  44. return (
  45. <Editor
  46. sidebarTitle="table of content"
  47. sidebar={
  48. anthologyId ? (
  49. <AnthologyTocTree
  50. anthologyId={anthologyId}
  51. channels={channels}
  52. onClick={(tocAnthology, article, target) => {
  53. onArticleClick?.(tocAnthology, article, target);
  54. }}
  55. />
  56. ) : undefined
  57. }
  58. articleId={articleId}
  59. anthologyId={anthologyId}
  60. articleType={"article"}
  61. channelId={channelId}
  62. onChannelSelect={onChannelSelect}
  63. >
  64. {({ expandButton }) => (
  65. <TypeArticle
  66. articleId={articleId}
  67. mode={mode}
  68. anthologyId={anthologyId ?? anthology ?? undefined}
  69. channelId={channelId}
  70. headerExtra={expandButton}
  71. onAnthologySelect={onAnthologySelect}
  72. onArticleChange={onArticleChange}
  73. />
  74. )}
  75. </Editor>
  76. );
  77. }