@raystack/chronicle 0.1.0-canary.49fe67c → 0.1.0-canary.4a4a3f8

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.
@@ -2,59 +2,33 @@ import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
2
2
  import { Flex } from '@raystack/apsara';
3
3
  import { useMemo } from 'react';
4
4
  import { Link as RouterLink, useLocation } from 'react-router';
5
+ import { getBreadcrumbItems } from 'fumadocs-core/breadcrumb';
6
+ import { flattenTree } from 'fumadocs-core/page-tree';
5
7
  import { Search } from '@/components/ui/search';
6
- import type { PageTreeItem, ThemePageProps } from '@/types';
8
+ import type { ThemePageProps } from '@/types';
7
9
  import styles from './Page.module.css';
8
10
  import { ReadingProgress } from './ReadingProgress';
9
11
 
10
- function flattenTree(items: PageTreeItem[]): PageTreeItem[] {
11
- const result: PageTreeItem[] = [];
12
- for (const item of items) {
13
- if (item.type === 'page' && item.url) result.push(item);
14
- if (item.children) result.push(...flattenTree(item.children));
15
- }
16
- return result;
17
- }
18
-
19
- function findBreadcrumb(
20
- items: PageTreeItem[],
21
- slug: string[]
22
- ): { label: string; href: string }[] {
23
- const result: { label: string; href: string }[] = [];
24
- for (let i = 0; i < slug.length; i++) {
25
- const path = '/' + slug.slice(0, i + 1).join('/');
26
- const found = findInTree(items, path);
27
- result.push({ label: found?.name ?? slug[i], href: path });
28
- }
29
- return result;
30
- }
31
-
32
- function findInTree(
33
- items: PageTreeItem[],
34
- path: string
35
- ): PageTreeItem | undefined {
36
- for (const item of items) {
37
- if (item.url === path) return item;
38
- if (item.children) {
39
- const found = findInTree(item.children, path);
40
- if (found) return found;
41
- }
42
- }
43
- return undefined;
44
- }
45
-
46
12
  export function Page({ page, config, tree }: ThemePageProps) {
47
13
  const { pathname } = useLocation();
48
14
 
49
15
  const { prev, next, crumbs } = useMemo(() => {
50
16
  const pages = flattenTree(tree.children);
51
17
  const currentIndex = pages.findIndex(p => p.url === pathname);
18
+ const breadcrumbItems = getBreadcrumbItems(
19
+ pathname,
20
+ tree,
21
+ { includePage: true }
22
+ );
52
23
  return {
53
24
  prev: currentIndex > 0 ? pages[currentIndex - 1] : null,
54
25
  next: currentIndex < pages.length - 1 ? pages[currentIndex + 1] : null,
55
- crumbs: findBreadcrumb(tree.children, page.slug)
26
+ crumbs: breadcrumbItems.map(item => ({
27
+ label: item.name,
28
+ href: item.url ?? pathname,
29
+ })),
56
30
  };
57
- }, [tree, pathname, page.slug]);
31
+ }, [tree, pathname]);
58
32
 
59
33
  return (
60
34
  <>
@@ -63,7 +37,7 @@ export function Page({ page, config, tree }: ThemePageProps) {
63
37
  <Flex align='center' gap='small' className={styles.navLeft}>
64
38
  {prev ? (
65
39
  <RouterLink
66
- to={prev.url!}
40
+ to={prev.url}
67
41
  className={styles.arrow}
68
42
  aria-label='Previous page'
69
43
  >
@@ -80,7 +54,7 @@ export function Page({ page, config, tree }: ThemePageProps) {
80
54
  )}
81
55
  {next ? (
82
56
  <RouterLink
83
- to={next.url!}
57
+ to={next.url}
84
58
  className={styles.arrow}
85
59
  aria-label='Next page'
86
60
  >
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { cx } from 'class-variance-authority';
4
4
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import type { TocItem } from '@/types';
5
+ import type { TOCItemType } from 'fumadocs-core/toc';
6
6
  import styles from './ReadingProgress.module.css';
7
7
 
8
8
  interface Heading {
@@ -68,7 +68,7 @@ function resolveOverlaps(headings: Heading[], maxPosition: number): Heading[] {
68
68
  }
69
69
 
70
70
  interface ReadingProgressProps {
71
- items: TocItem[];
71
+ items: TOCItemType[];
72
72
  }
73
73
 
74
74
  export function ReadingProgress({ items }: ReadingProgressProps) {
@@ -1,4 +1,8 @@
1
1
  import type { ReactNode } from 'react'
2
+ import type { TableOfContents } from 'fumadocs-core/toc'
3
+
4
+ export type { Root, Node, Item, Folder, Separator } from 'fumadocs-core/page-tree'
5
+ export type { TOCItemType, TableOfContents } from 'fumadocs-core/toc'
2
6
 
3
7
  export interface Frontmatter {
4
8
  title: string
@@ -12,25 +16,5 @@ export interface Page {
12
16
  slug: string[]
13
17
  frontmatter: Frontmatter
14
18
  content: ReactNode
15
- toc: TocItem[]
16
- }
17
-
18
- export interface TocItem {
19
- title: string
20
- url: string
21
- depth: number
22
- }
23
-
24
- export interface PageTreeItem {
25
- type: 'page' | 'folder' | 'separator'
26
- name: string
27
- url?: string
28
- order?: number
29
- icon?: string
30
- children?: PageTreeItem[]
31
- }
32
-
33
- export interface PageTree {
34
- name: string
35
- children: PageTreeItem[]
19
+ toc: TableOfContents
36
20
  }
@@ -1,4 +1,3 @@
1
1
  // Vite build-time constants (injected via define in vite-config.ts)
2
2
  declare const __CHRONICLE_CONTENT_DIR__: string
3
3
  declare const __CHRONICLE_PROJECT_ROOT__: string
4
- declare const __CHRONICLE_PACKAGE_ROOT__: string
@@ -1,18 +1,19 @@
1
1
  import type { ReactNode } from 'react'
2
+ import type { Root } from 'fumadocs-core/page-tree'
2
3
  import type { ChronicleConfig } from './config'
3
- import type { Page, PageTree } from './content'
4
+ import type { Page } from './content'
4
5
 
5
6
  export interface ThemeLayoutProps {
6
7
  children: ReactNode
7
8
  config: ChronicleConfig
8
- tree: PageTree
9
+ tree: Root
9
10
  classNames?: { layout?: string; body?: string; sidebar?: string; content?: string }
10
11
  }
11
12
 
12
13
  export interface ThemePageProps {
13
14
  page: Page
14
15
  config: ChronicleConfig
15
- tree: PageTree
16
+ tree: Root
16
17
  }
17
18
 
18
19
  export interface Theme {