react-docs-module 0.1.0

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.
Files changed (100) hide show
  1. package/README.md +279 -0
  2. package/ai-chat.tsx +222 -0
  3. package/chat-api.ts +90 -0
  4. package/cn.ts +15 -0
  5. package/config.ts +29 -0
  6. package/dist/ai-chat.d.ts +12 -0
  7. package/dist/ai-chat.js +72 -0
  8. package/dist/ai-chat.js.map +1 -0
  9. package/dist/chat-api.d.ts +16 -0
  10. package/dist/chat-api.js +62 -0
  11. package/dist/chat-api.js.map +1 -0
  12. package/dist/cn.d.ts +4 -0
  13. package/dist/cn.js +14 -0
  14. package/dist/cn.js.map +1 -0
  15. package/dist/config.d.ts +14 -0
  16. package/dist/config.js +15 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/doc-pagination.d.ts +13 -0
  19. package/dist/doc-pagination.js +8 -0
  20. package/dist/doc-pagination.js.map +1 -0
  21. package/dist/docs-index.d.ts +7 -0
  22. package/dist/docs-index.js +11 -0
  23. package/dist/docs-index.js.map +1 -0
  24. package/dist/docs-page.d.ts +15 -0
  25. package/dist/docs-page.js +38 -0
  26. package/dist/docs-page.js.map +1 -0
  27. package/dist/docs-sidebar.d.ts +18 -0
  28. package/dist/docs-sidebar.d.ts.map +1 -0
  29. package/dist/docs-sidebar.js +27 -0
  30. package/dist/docs-sidebar.js.map +1 -0
  31. package/dist/documentation-layout.d.ts +15 -0
  32. package/dist/documentation-layout.js +20 -0
  33. package/dist/documentation-layout.js.map +1 -0
  34. package/dist/heading.d.ts +10 -0
  35. package/dist/heading.js +16 -0
  36. package/dist/heading.js.map +1 -0
  37. package/dist/index.d.ts +18 -0
  38. package/dist/index.js +19 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/mdx/callouts.d.ts +8 -0
  41. package/dist/mdx/callouts.js +8 -0
  42. package/dist/mdx/callouts.js.map +1 -0
  43. package/dist/mdx/code-block.d.ts +8 -0
  44. package/dist/mdx/code-block.js +29 -0
  45. package/dist/mdx/code-block.js.map +1 -0
  46. package/dist/mdx/components.d.ts +13 -0
  47. package/dist/mdx/components.js +21 -0
  48. package/dist/mdx/components.js.map +1 -0
  49. package/dist/mdx.d.ts +20 -0
  50. package/dist/mdx.js +109 -0
  51. package/dist/mdx.js.map +1 -0
  52. package/dist/search-index.d.ts +10 -0
  53. package/dist/search-index.js +38 -0
  54. package/dist/search-index.js.map +1 -0
  55. package/dist/search.d.ts +6 -0
  56. package/dist/search.js +142 -0
  57. package/dist/search.js.map +1 -0
  58. package/dist/table-of-contents-provider.d.ts +4 -0
  59. package/dist/table-of-contents-provider.js +30 -0
  60. package/dist/table-of-contents-provider.js.map +1 -0
  61. package/dist/table-of-contents.d.ts +11 -0
  62. package/dist/table-of-contents.js +9 -0
  63. package/dist/table-of-contents.js.map +1 -0
  64. package/dist/theme-context.d.ts +20 -0
  65. package/dist/theme-context.js +28 -0
  66. package/dist/theme-context.js.map +1 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -0
  68. package/dist/ui/button.d.ts +12 -0
  69. package/dist/ui/button.js +34 -0
  70. package/dist/ui/button.js.map +1 -0
  71. package/dist/ui/dialog.d.ts +17 -0
  72. package/dist/ui/dialog.js +22 -0
  73. package/dist/ui/dialog.js.map +1 -0
  74. package/dist/ui/input.d.ts +4 -0
  75. package/dist/ui/input.js +9 -0
  76. package/dist/ui/input.js.map +1 -0
  77. package/dist/util.d.ts +59 -0
  78. package/dist/util.js +96 -0
  79. package/dist/util.js.map +1 -0
  80. package/doc-pagination.tsx +67 -0
  81. package/docs-index.tsx +17 -0
  82. package/docs-page.tsx +68 -0
  83. package/docs-sidebar.tsx +165 -0
  84. package/documentation-layout.tsx +99 -0
  85. package/heading.tsx +63 -0
  86. package/index.ts +28 -0
  87. package/mdx/callouts.tsx +29 -0
  88. package/mdx/code-block.tsx +89 -0
  89. package/mdx/components.tsx +55 -0
  90. package/mdx.ts +138 -0
  91. package/package.json +99 -0
  92. package/search-index.ts +52 -0
  93. package/search.tsx +273 -0
  94. package/table-of-contents-provider.tsx +43 -0
  95. package/table-of-contents.tsx +44 -0
  96. package/theme-context.tsx +57 -0
  97. package/ui/button.tsx +56 -0
  98. package/ui/dialog.tsx +108 -0
  99. package/ui/input.tsx +22 -0
  100. package/util.ts +169 -0
package/util.ts ADDED
@@ -0,0 +1,169 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import matter from "gray-matter";
4
+ import { ReactDocsConfig } from "./config";
5
+
6
+ interface DocPage {
7
+ slug: string;
8
+ title: string;
9
+ icon?: string;
10
+ isExternal?: boolean;
11
+ }
12
+
13
+ interface DocSection {
14
+ group: string;
15
+ pages: DocPage[];
16
+ }
17
+
18
+ export interface DocsJsonConfig {
19
+ theme: string;
20
+ name: string;
21
+ description?: string;
22
+ navigation: {
23
+ groups?: {
24
+ group: string;
25
+ pages: string[];
26
+ }[];
27
+ anchors?: {
28
+ name: string;
29
+ icon: string;
30
+ url: string;
31
+ }[];
32
+ pages?: string[];
33
+ };
34
+ colors: {
35
+ primary: string;
36
+ light?: string;
37
+ dark?: string;
38
+ };
39
+ logo?: {
40
+ dark?: string;
41
+ light?: string;
42
+ };
43
+ favicon?: string;
44
+ navbar?: {
45
+ cta?: {
46
+ type: string;
47
+ url: string;
48
+ };
49
+ };
50
+ footer?: {
51
+ socials?: Record<string, string>;
52
+ };
53
+ feedback?: {
54
+ thumbsRating?: boolean;
55
+ };
56
+ }
57
+
58
+ export function getDocsSidebar(config: ReactDocsConfig) {
59
+ const docsDirectory = path.join(process.cwd(), config.contentPath);
60
+ const docsJsonPath = path.join(process.cwd(), config.contentPath, "docs.json");
61
+
62
+ if (!fs.existsSync(docsJsonPath)) {
63
+ throw new Error(`docs.json configuration file not found at ${config.contentPath}/docs.json`);
64
+ }
65
+
66
+ const docsConfig: DocsJsonConfig = JSON.parse(fs.readFileSync(docsJsonPath, 'utf8'));
67
+
68
+ const navigation: DocSection[] = [];
69
+
70
+ // Add anchors as the first section if they exist
71
+ if (docsConfig.navigation.anchors && docsConfig.navigation.anchors.length > 0) {
72
+ navigation.push({
73
+ group: "Links",
74
+ pages: docsConfig.navigation.anchors.map(anchor => ({
75
+ slug: anchor.url,
76
+ title: anchor.name,
77
+ icon: anchor.icon,
78
+ isExternal: true
79
+ }))
80
+ });
81
+ }
82
+
83
+ // Handle groups navigation
84
+ if (docsConfig.navigation.groups) {
85
+ docsConfig.navigation.groups.forEach(section => {
86
+ const pages: DocPage[] = [];
87
+
88
+ section.pages.forEach(pagePath => {
89
+ const fullPath = path.join(docsDirectory, `${pagePath}.mdx`);
90
+ if (fs.existsSync(fullPath)) {
91
+ const fileContents = fs.readFileSync(fullPath, 'utf8');
92
+ const { data: frontmatter } = matter(fileContents);
93
+
94
+ pages.push({
95
+ slug: pagePath,
96
+ title: frontmatter.title || pagePath.split('/').pop()?.replace(/-/g, ' ') || '',
97
+ });
98
+ }
99
+ });
100
+
101
+ if (pages.length > 0) {
102
+ navigation.push({
103
+ group: section.group,
104
+ pages,
105
+ });
106
+ }
107
+ });
108
+ }
109
+
110
+ // Handle direct pages navigation (if no groups)
111
+ if (docsConfig.navigation.pages && !docsConfig.navigation.groups) {
112
+ const pages: DocPage[] = [];
113
+
114
+ docsConfig.navigation.pages.forEach(pagePath => {
115
+ const fullPath = path.join(docsDirectory, `${pagePath}.mdx`);
116
+ if (fs.existsSync(fullPath)) {
117
+ const fileContents = fs.readFileSync(fullPath, 'utf8');
118
+ const { data: frontmatter } = matter(fileContents);
119
+
120
+ pages.push({
121
+ slug: pagePath,
122
+ title: frontmatter.title || pagePath.split('/').pop()?.replace(/-/g, ' ') || '',
123
+ });
124
+ }
125
+ });
126
+
127
+ if (pages.length > 0) {
128
+ navigation.push({
129
+ group: "Documentation",
130
+ pages,
131
+ });
132
+ }
133
+ }
134
+
135
+ return { navigation, config: docsConfig };
136
+ }
137
+
138
+ export function getAllDocSlugs(config: ReactDocsConfig) {
139
+ const docsDirectory = path.join(process.cwd(), config.contentPath);
140
+ const fileNames = fs.readdirSync(docsDirectory);
141
+
142
+ return fileNames
143
+ .filter((fileName) => fileName.endsWith(".mdx"))
144
+ .map((fileName) => ({
145
+ slug: fileName.replace(/\.mdx$/, ""),
146
+ }));
147
+ }
148
+
149
+ // Helper function to recursively read all MDX files from a directory
150
+ function getAllDocs(dir: string): string[] {
151
+ const files = fs.readdirSync(dir);
152
+
153
+ return files.flatMap(file => {
154
+ const filePath = path.join(dir, file);
155
+ const stats = fs.statSync(filePath);
156
+
157
+ if (stats.isDirectory()) {
158
+ return getAllDocs(filePath);
159
+ }
160
+
161
+ if (file.endsWith('.mdx')) {
162
+ const fileContents = fs.readFileSync(filePath, 'utf8');
163
+ const { content } = matter(fileContents);
164
+ return content;
165
+ }
166
+
167
+ return [];
168
+ });
169
+ }