@nikala-ui/folio 0.14.0 → 0.15.1

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 (160) hide show
  1. package/README.md +16 -0
  2. package/dist/cli/commands/init.js +105 -51
  3. package/dist/client/app.jsx +6 -3
  4. package/dist/client/components/docs-layout-shell.d.ts +1 -0
  5. package/dist/client/components/docs-layout-shell.jsx +1 -1
  6. package/dist/client/components/docs-page-content.jsx +9 -5
  7. package/dist/client/navigation/page-navigation.js +10 -27
  8. package/dist/client/public/algolia-logo.svg +15 -0
  9. package/dist/client/public/favicon.ico +0 -0
  10. package/dist/client/public/logo.svg +11 -0
  11. package/dist/client/routing/use-docs-router.d.ts +1 -0
  12. package/dist/client/routing/use-docs-router.js +12 -3
  13. package/dist/client/style.css +139 -55
  14. package/dist/components/ui/api-table.jsx +6 -4
  15. package/dist/components/ui/code-block.jsx +6 -4
  16. package/dist/components/ui/command.jsx +9 -5
  17. package/dist/components/ui/list.jsx +3 -1
  18. package/dist/components/ui/logo.d.ts +4 -1
  19. package/dist/components/ui/logo.jsx +8 -22
  20. package/dist/components/ui/package-manager-tabs.jsx +4 -2
  21. package/dist/components/ui/pager.jsx +4 -2
  22. package/dist/components/ui/section-heading.jsx +1 -1
  23. package/dist/components/ui/sidebar.jsx +6 -3
  24. package/dist/components/ui/spinner.jsx +3 -1
  25. package/dist/components/ui/theme-toggle.jsx +14 -12
  26. package/dist/config.d.ts +1 -0
  27. package/dist/config.js +84 -29
  28. package/dist/core/content-scanner.d.ts +2 -1
  29. package/dist/core/content-scanner.js +2 -9
  30. package/dist/core/plugin/index.d.ts +2 -0
  31. package/dist/core/plugin/index.js +1 -0
  32. package/dist/core/plugin/lifecycle-error.d.ts +19 -0
  33. package/dist/core/plugin/lifecycle-error.js +28 -0
  34. package/dist/core/plugin/lifecycle-snapshot.d.ts +1 -0
  35. package/dist/core/plugin/lifecycle-snapshot.js +156 -0
  36. package/dist/core/plugin/lifecycle.d.ts +34 -0
  37. package/dist/core/plugin/lifecycle.js +170 -0
  38. package/dist/core/route-tree.d.ts +3 -2
  39. package/dist/core/route-tree.js +40 -10
  40. package/dist/index.d.ts +7 -4
  41. package/dist/index.js +4 -3
  42. package/dist/plugin.d.ts +60 -0
  43. package/dist/plugin.js +51 -0
  44. package/dist/plugins/i18n/components/site-language-switcher.d.ts +10 -0
  45. package/dist/plugins/i18n/components/site-language-switcher.jsx +39 -0
  46. package/dist/plugins/i18n/constants.d.ts +1 -0
  47. package/dist/plugins/i18n/constants.js +1 -0
  48. package/dist/plugins/i18n/index.d.ts +11 -0
  49. package/dist/plugins/i18n/index.js +89 -0
  50. package/dist/plugins/i18n/navigation.d.ts +5 -0
  51. package/dist/plugins/i18n/navigation.js +33 -0
  52. package/dist/plugins/i18n/runtime.d.ts +19 -0
  53. package/dist/plugins/i18n/runtime.jsx +65 -0
  54. package/dist/plugins/i18n/site-locale.d.ts +12 -0
  55. package/dist/plugins/i18n/site-locale.js +119 -0
  56. package/dist/search/provider.d.ts +9 -0
  57. package/dist/search/provider.js +4 -2
  58. package/dist/server/index.d.ts +4 -1
  59. package/dist/server/index.js +69 -33
  60. package/dist/server/module-serialization.d.ts +6 -0
  61. package/dist/server/module-serialization.js +26 -0
  62. package/dist/server/plugin/components.d.ts +7 -0
  63. package/dist/server/plugin/components.js +82 -0
  64. package/dist/server/plugin/constants.d.ts +17 -0
  65. package/dist/server/plugin/constants.js +21 -0
  66. package/dist/server/{plugin.d.ts → plugin/index.d.ts} +3 -1
  67. package/dist/server/plugin/index.js +166 -0
  68. package/dist/server/plugin/lifecycle.d.ts +32 -0
  69. package/dist/server/plugin/lifecycle.js +110 -0
  70. package/dist/server/plugin/styles.d.ts +3 -0
  71. package/dist/server/plugin/styles.js +22 -0
  72. package/dist/server/plugin/virtual-modules.d.ts +11 -0
  73. package/dist/server/plugin/virtual-modules.js +121 -0
  74. package/dist/server/seo.d.ts +4 -0
  75. package/dist/server/seo.js +87 -0
  76. package/dist/templates/env.d.ts +26 -0
  77. package/dist/templates/locales/en.json +77 -0
  78. package/dist/themes/default/components/docs-landing-body.d.ts +17 -0
  79. package/dist/themes/default/components/docs-landing-body.jsx +17 -0
  80. package/dist/themes/default/components/docs-page-body.d.ts +21 -0
  81. package/dist/themes/default/components/docs-page-body.jsx +36 -0
  82. package/dist/themes/default/components/page-actions.d.ts +15 -0
  83. package/dist/themes/default/components/page-actions.jsx +60 -0
  84. package/dist/themes/default/components/page-header.d.ts +7 -0
  85. package/dist/themes/default/components/page-header.jsx +3 -0
  86. package/dist/themes/default/components/sidebar-footer.d.ts +6 -0
  87. package/dist/themes/default/components/sidebar-footer.jsx +12 -0
  88. package/dist/themes/default/components/sidebar-header.d.ts +8 -0
  89. package/dist/themes/default/components/sidebar-header.jsx +17 -0
  90. package/dist/themes/default/components/sidebar-mobile-nav.d.ts +7 -0
  91. package/dist/themes/default/components/sidebar-mobile-nav.jsx +17 -0
  92. package/dist/themes/default/components/sidebar-promo.d.ts +8 -0
  93. package/dist/themes/default/components/sidebar-promo.jsx +20 -0
  94. package/dist/themes/default/content/breadcrumbs.jsx +5 -2
  95. package/dist/themes/default/content/table-of-contents.jsx +3 -1
  96. package/dist/themes/default/hooks/use-page-copy.d.ts +6 -0
  97. package/dist/themes/default/hooks/use-page-copy.js +26 -0
  98. package/dist/themes/default/layout.jsx +30 -127
  99. package/dist/themes/default/lib/layout-visibility.d.ts +8 -0
  100. package/dist/themes/default/lib/layout-visibility.js +24 -0
  101. package/dist/themes/default/navbar.jsx +14 -7
  102. package/dist/themes/default/navigation/mobile-table-of-contents.jsx +5 -3
  103. package/dist/themes/default/navigation/sidebar-tree.d.ts +2 -0
  104. package/dist/themes/default/navigation/sidebar-tree.jsx +11 -2
  105. package/dist/themes/default/overlays/search-dialog.jsx +14 -3
  106. package/dist/themes/default/sidebar.jsx +21 -49
  107. package/dist/themes/types.d.ts +5 -0
  108. package/dist/types.d.ts +36 -0
  109. package/dist/utils/format-title.d.ts +1 -0
  110. package/dist/utils/format-title.js +11 -0
  111. package/dist/vendor/docs-src/client/page-actions.ts +69 -0
  112. package/dist/vendor/docs-src/components/ui/api-table.tsx +6 -4
  113. package/dist/vendor/docs-src/components/ui/code-block.tsx +6 -4
  114. package/dist/vendor/docs-src/components/ui/command.tsx +9 -5
  115. package/dist/vendor/docs-src/components/ui/list.tsx +4 -2
  116. package/dist/vendor/docs-src/components/ui/logo.tsx +19 -48
  117. package/dist/vendor/docs-src/components/ui/package-manager-tabs.tsx +4 -2
  118. package/dist/vendor/docs-src/components/ui/pager.tsx +4 -2
  119. package/dist/vendor/docs-src/components/ui/section-heading.tsx +5 -1
  120. package/dist/vendor/docs-src/components/ui/sidebar.tsx +7 -4
  121. package/dist/vendor/docs-src/components/ui/spinner.tsx +3 -1
  122. package/dist/vendor/docs-src/components/ui/theme-toggle.tsx +15 -13
  123. package/dist/vendor/docs-src/navigation/index.ts +2 -0
  124. package/dist/vendor/docs-src/navigation/repository-links.ts +43 -0
  125. package/dist/vendor/docs-src/navigation/sidebar-state.ts +22 -0
  126. package/dist/vendor/docs-src/navigation/sidebar-tree.ts +15 -0
  127. package/dist/vendor/docs-src/plugins/i18n/components/site-language-switcher.tsx +56 -0
  128. package/dist/vendor/docs-src/plugins/i18n/constants.ts +1 -0
  129. package/dist/vendor/docs-src/plugins/i18n/index.ts +110 -0
  130. package/dist/vendor/docs-src/plugins/i18n/navigation.ts +49 -0
  131. package/dist/vendor/docs-src/plugins/i18n/runtime.tsx +91 -0
  132. package/dist/vendor/docs-src/plugins/i18n/site-locale.ts +140 -0
  133. package/dist/vendor/docs-src/search/provider.ts +83 -0
  134. package/dist/vendor/docs-src/themes/default/components/docs-landing-body.tsx +30 -0
  135. package/dist/vendor/docs-src/themes/default/components/docs-page-body.tsx +53 -0
  136. package/dist/vendor/docs-src/themes/default/components/page-actions.tsx +105 -0
  137. package/dist/vendor/docs-src/themes/default/components/page-header.tsx +31 -0
  138. package/dist/vendor/docs-src/themes/default/components/sidebar-footer.tsx +21 -0
  139. package/dist/vendor/docs-src/themes/default/components/sidebar-header.tsx +30 -0
  140. package/dist/vendor/docs-src/themes/default/components/sidebar-mobile-nav.tsx +33 -0
  141. package/dist/vendor/docs-src/themes/default/components/sidebar-promo.tsx +37 -0
  142. package/dist/vendor/docs-src/themes/default/content/breadcrumbs.tsx +43 -0
  143. package/dist/vendor/docs-src/themes/default/content/pager.tsx +19 -0
  144. package/dist/vendor/docs-src/themes/default/content/table-of-contents.tsx +32 -0
  145. package/dist/vendor/docs-src/themes/default/hooks/use-page-copy.ts +29 -0
  146. package/dist/vendor/docs-src/themes/default/icons.ts +16 -0
  147. package/dist/vendor/docs-src/themes/default/index.ts +46 -0
  148. package/dist/vendor/docs-src/themes/default/layout.tsx +176 -0
  149. package/dist/vendor/docs-src/themes/default/lib/layout-visibility.ts +39 -0
  150. package/dist/vendor/docs-src/themes/default/navbar.tsx +130 -0
  151. package/dist/vendor/docs-src/themes/default/navigation/mobile-table-of-contents.tsx +61 -0
  152. package/dist/vendor/docs-src/themes/default/navigation/sidebar-tree.tsx +202 -0
  153. package/dist/vendor/docs-src/themes/default/overlays/search-dialog.tsx +106 -0
  154. package/dist/vendor/docs-src/themes/default/sidebar.tsx +86 -0
  155. package/dist/vendor/docs-src/themes/index.ts +4 -0
  156. package/dist/vendor/docs-src/themes/types.ts +87 -0
  157. package/dist/version.d.ts +1 -1
  158. package/dist/version.js +1 -1
  159. package/package.json +11 -4
  160. package/dist/server/plugin.js +0 -521
@@ -5,6 +5,7 @@ import { runThemeTransition, } from "../../providers/theme-transitions";
5
5
  import { Button } from "./button";
6
6
  import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, } from "./dropdown-menu";
7
7
  import { cn } from "@/lib/cn";
8
+ import { useSiteLocale } from "../../plugins/i18n/runtime.jsx";
8
9
  const ACCENT_OPTIONS = [
9
10
  { name: "yellow", label: "Yellow", color: "bg-yellow-500" },
10
11
  { name: "red", label: "Red", color: "bg-red-500" },
@@ -24,6 +25,7 @@ const RADIUS_OPTIONS = [
24
25
  * Interactive UI theme switcher supporting button, mini (dropdown), and max (customizer panel) modes with View Transition animations.
25
26
  */
26
27
  export const ThemeToggle = (props) => {
28
+ const siteLocale = useSiteLocale();
27
29
  const [local, rest] = splitProps(props, ["mode", "effect", "variant", "size", "class"]);
28
30
  const { theme, setTheme, accent, setAccent, radius, setRadius } = useTheme();
29
31
  const mode = () => local.mode || "mini";
@@ -51,11 +53,11 @@ export const ThemeToggle = (props) => {
51
53
  };
52
54
  return (<Show when={mode() !== "button"} fallback={
53
55
  /* Button Mode: Direct 1-click Dark/Light switcher without dropdown */
54
- <Button variant={local.variant || "ghost"} size={local.size || "icon"} onClick={handleToggleClick} class={cn("relative cursor-pointer", local.class)} aria-label="Toggle theme" {...rest}>
56
+ <Button variant={local.variant || "ghost"} size={local.size || "icon"} onClick={handleToggleClick} class={cn("relative cursor-pointer", local.class)} aria-label={siteLocale.t("theme.toggle")} {...rest}>
55
57
  <Show when={isDarkMode()} fallback={<Sun class="h-4 w-4 text-foreground transition-transform"/>}>
56
58
  <Moon class="h-4 w-4 text-foreground transition-transform"/>
57
59
  </Show>
58
- <span class="sr-only">Toggle theme</span>
60
+ <span class="sr-only">{siteLocale.t("theme.toggle")}</span>
59
61
  </Button>}>
60
62
  <DropdownMenu placement="bottom-end">
61
63
  <DropdownMenuTrigger as={Button} variant={local.variant || "ghost"} size={local.size || "icon"} class={cn("relative cursor-pointer", local.class)} {...rest}>
@@ -63,7 +65,7 @@ export const ThemeToggle = (props) => {
63
65
  <Show when={isDarkMode()} fallback={<Sun class="h-4 w-4 text-foreground transition-transform"/>}>
64
66
  <Moon class="h-4 w-4 text-foreground transition-transform"/>
65
67
  </Show>
66
- <span class="sr-only">Toggle theme</span>
68
+ <span class="sr-only">{siteLocale.t("theme.toggle")}</span>
67
69
  </DropdownMenuTrigger>
68
70
 
69
71
  <Show when={mode() === "max"} fallback={
@@ -71,17 +73,17 @@ export const ThemeToggle = (props) => {
71
73
  <DropdownMenuContent>
72
74
  <DropdownMenuItem onClick={(e) => changeThemeWithEffect("light", e)}>
73
75
  <Sun class="mr-2 h-4 w-4 text-muted-foreground"/>
74
- Light
76
+ {siteLocale.t("theme.light")}
75
77
  </DropdownMenuItem>
76
78
 
77
79
  <DropdownMenuItem onClick={(e) => changeThemeWithEffect("dark", e)}>
78
80
  <Moon class="mr-2 h-4 w-4 text-muted-foreground"/>
79
- Dark
81
+ {siteLocale.t("theme.dark")}
80
82
  </DropdownMenuItem>
81
83
 
82
84
  <DropdownMenuItem onClick={(e) => changeThemeWithEffect("system", e)}>
83
85
  <Monitor class="mr-2 h-4 w-4 text-muted-foreground"/>
84
- System
86
+ {siteLocale.t("theme.system")}
85
87
  </DropdownMenuItem>
86
88
  </DropdownMenuContent>}>
87
89
  {/* Max Mode: Full Theme Customizer Panel */}
@@ -89,17 +91,17 @@ export const ThemeToggle = (props) => {
89
91
  <div class="p-2 space-y-2">
90
92
  <DropdownMenuGroup>
91
93
  <DropdownMenuLabel class="px-0 pt-0 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
92
- Theme Mode
94
+ {siteLocale.t("theme.mode")}
93
95
  </DropdownMenuLabel>
94
96
  <div class="grid grid-cols-3 gap-1 my-1.5">
95
97
  <Button variant={theme() === "light" ? "default" : "outline"} size="sm" onClick={(e) => changeThemeWithEffect("light", e)} class="h-8 text-xs cursor-pointer">
96
- Light
98
+ {siteLocale.t("theme.light")}
97
99
  </Button>
98
100
  <Button variant={theme() === "dark" ? "default" : "outline"} size="sm" onClick={(e) => changeThemeWithEffect("dark", e)} class="h-8 text-xs cursor-pointer">
99
- Dark
101
+ {siteLocale.t("theme.dark")}
100
102
  </Button>
101
103
  <Button variant={theme() === "system" ? "default" : "outline"} size="sm" onClick={(e) => changeThemeWithEffect("system", e)} class="h-8 text-xs cursor-pointer">
102
- System
104
+ {siteLocale.t("theme.system")}
103
105
  </Button>
104
106
  </div>
105
107
  </DropdownMenuGroup>
@@ -108,7 +110,7 @@ export const ThemeToggle = (props) => {
108
110
 
109
111
  <DropdownMenuGroup>
110
112
  <DropdownMenuLabel class="px-0 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
111
- Brand Accent Color
113
+ {siteLocale.t("theme.brandAccentColor")}
112
114
  </DropdownMenuLabel>
113
115
  <div class="flex flex-wrap gap-1.5 my-1.5">
114
116
  <For each={ACCENT_OPTIONS}>
@@ -123,7 +125,7 @@ export const ThemeToggle = (props) => {
123
125
 
124
126
  <DropdownMenuGroup>
125
127
  <DropdownMenuLabel class="px-0 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
126
- Border Radius
128
+ {siteLocale.t("theme.borderRadius")}
127
129
  </DropdownMenuLabel>
128
130
  <div class="grid grid-cols-5 gap-1 my-1.5">
129
131
  <For each={RADIUS_OPTIONS}>
package/dist/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { DocsConfig } from "./types.js";
2
2
  export declare const DEFAULT_DOCS_CONFIG: Required<Pick<DocsConfig, "title" | "description" | "contentDir">> & DocsConfig;
3
3
  export declare function defineDocsConfig(config: DocsConfig): DocsConfig;
4
+ export declare function resolvePluginConfig(config: DocsConfig): DocsConfig;
4
5
  export declare const loadConfig: typeof resolveDocsConfig;
5
6
  export declare function resolveDocsConfig(cwd?: string): Promise<DocsConfig>;
package/dist/config.js CHANGED
@@ -2,6 +2,8 @@
2
2
  import path from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import fs from "fs-extra";
5
+ import { validateFolioPlugins } from "./plugin.js";
6
+ import { loadSiteTranslations } from "./plugins/i18n/site-locale.js";
5
7
  export const DEFAULT_DOCS_CONFIG = {
6
8
  title: "Folio",
7
9
  description: "Documentation built with Nikala UI",
@@ -41,10 +43,31 @@ export const DEFAULT_DOCS_CONFIG = {
41
43
  enabled: true,
42
44
  provider: "local",
43
45
  },
46
+ uiLocale: {
47
+ defaultLocale: "en",
48
+ directory: "locales",
49
+ locale: "en",
50
+ },
44
51
  };
45
52
  export function defineDocsConfig(config) {
53
+ validateFolioPlugins(config.plugins);
54
+ if (config.uiLocale !== undefined) {
55
+ throw new Error("[folio] Configure site translations through createI18nPlugin() in DocsConfig.plugins");
56
+ }
46
57
  return config;
47
58
  }
59
+ export function resolvePluginConfig(config) {
60
+ validateFolioPlugins(config.plugins);
61
+ const pluginConfig = config.plugins?.reduce((merged, plugin) => ({ ...merged, ...(plugin.config || {}) }), {}) || {};
62
+ return {
63
+ ...config,
64
+ ...pluginConfig,
65
+ uiLocale: {
66
+ ...(config.uiLocale || {}),
67
+ ...(pluginConfig.uiLocale || {}),
68
+ },
69
+ };
70
+ }
48
71
  const CONFIG_FILENAMES = [
49
72
  "docs.config.ts",
50
73
  "docs.config.js",
@@ -56,6 +79,7 @@ const CONFIG_FILENAMES = [
56
79
  "nikala.config.ts",
57
80
  "nikala.config.js",
58
81
  ];
82
+ let configReloadRevision = 0;
59
83
  export const loadConfig = resolveDocsConfig;
60
84
  export async function resolveDocsConfig(cwd = process.cwd()) {
61
85
  for (const filename of CONFIG_FILENAMES) {
@@ -64,41 +88,72 @@ export async function resolveDocsConfig(cwd = process.cwd()) {
64
88
  try {
65
89
  // Config is reloaded by the dev watcher without restarting the
66
90
  // process. Bust Bun/Node's ESM module cache so changed values apply.
67
- const mod = await import(`${pathToFileURL(fullPath).href}?t=${Date.now()}`);
68
- const resolvedUserConfig = mod.default || mod.config || {};
69
- return {
70
- ...DEFAULT_DOCS_CONFIG,
71
- ...resolvedUserConfig,
72
- theme: {
73
- ...DEFAULT_DOCS_CONFIG.theme,
74
- ...resolvedUserConfig.theme,
75
- },
76
- navigation: {
77
- ...DEFAULT_DOCS_CONFIG.navigation,
78
- ...resolvedUserConfig.navigation,
79
- sidebar: {
80
- ...DEFAULT_DOCS_CONFIG.navigation?.sidebar,
81
- ...resolvedUserConfig.navigation?.sidebar,
91
+ const cacheKey = `${Date.now()}-${++configReloadRevision}`;
92
+ let importPath = fullPath;
93
+ let temporaryConfigPath;
94
+ if (process.versions.bun) {
95
+ temporaryConfigPath = path.join(path.dirname(fullPath), `.folio-config-${cacheKey}-${path.basename(fullPath)}`);
96
+ await fs.copyFile(fullPath, temporaryConfigPath);
97
+ importPath = temporaryConfigPath;
98
+ }
99
+ try {
100
+ const mod = await import(`${pathToFileURL(importPath).href}?t=${cacheKey}`);
101
+ const resolvedUserConfig = mod.default || mod.config || {};
102
+ if (resolvedUserConfig.uiLocale !== undefined) {
103
+ throw new Error("[folio] Configure site translations through createI18nPlugin() in DocsConfig.plugins");
104
+ }
105
+ const resolvedPluginConfig = resolvePluginConfig(resolvedUserConfig);
106
+ const pluginConfig = resolvedPluginConfig;
107
+ const mergedConfig = {
108
+ ...DEFAULT_DOCS_CONFIG,
109
+ ...pluginConfig,
110
+ ...resolvedUserConfig,
111
+ theme: {
112
+ ...DEFAULT_DOCS_CONFIG.theme,
113
+ ...resolvedUserConfig.theme,
114
+ },
115
+ navigation: {
116
+ ...DEFAULT_DOCS_CONFIG.navigation,
117
+ ...resolvedUserConfig.navigation,
118
+ sidebar: {
119
+ ...DEFAULT_DOCS_CONFIG.navigation?.sidebar,
120
+ ...resolvedUserConfig.navigation?.sidebar,
121
+ },
122
+ },
123
+ shiki: {
124
+ ...DEFAULT_DOCS_CONFIG.shiki,
125
+ ...resolvedUserConfig.shiki,
126
+ themes: {
127
+ ...DEFAULT_DOCS_CONFIG.shiki?.themes,
128
+ ...resolvedUserConfig.shiki?.themes,
129
+ },
130
+ },
131
+ seo: {
132
+ ...resolvedUserConfig.seo,
133
+ },
134
+ search: {
135
+ ...DEFAULT_DOCS_CONFIG.search,
136
+ ...resolvedUserConfig.search,
82
137
  },
83
- },
84
- shiki: {
85
- ...DEFAULT_DOCS_CONFIG.shiki,
86
- ...resolvedUserConfig.shiki,
87
- themes: {
88
- ...DEFAULT_DOCS_CONFIG.shiki?.themes,
89
- ...resolvedUserConfig.shiki?.themes,
138
+ uiLocale: {
139
+ ...DEFAULT_DOCS_CONFIG.uiLocale,
140
+ ...pluginConfig.uiLocale,
90
141
  },
91
- },
92
- search: {
93
- ...DEFAULT_DOCS_CONFIG.search,
94
- ...resolvedUserConfig.search,
95
- },
96
- };
142
+ };
143
+ mergedConfig.uiLocale = await loadSiteTranslations(cwd, mergedConfig.uiLocale);
144
+ return mergedConfig;
145
+ }
146
+ finally {
147
+ if (temporaryConfigPath)
148
+ await fs.remove(temporaryConfigPath);
149
+ }
97
150
  }
98
151
  catch (error) {
152
+ if (error instanceof Error && error.message.startsWith("[folio]"))
153
+ throw error;
99
154
  console.warn(`[folio] Failed to load config from ${filename}:`, error);
100
155
  }
101
156
  }
102
157
  }
103
- return DEFAULT_DOCS_CONFIG;
158
+ return { ...DEFAULT_DOCS_CONFIG, uiLocale: await loadSiteTranslations(cwd, DEFAULT_DOCS_CONFIG.uiLocale) };
104
159
  }
@@ -1,9 +1,10 @@
1
1
  import type { PageData, TocItem } from "../types.js";
2
+ import { formatTitleFromFilename } from "../utils/format-title.js";
3
+ export { formatTitleFromFilename };
2
4
  export declare function slugify(text: string): string;
3
5
  export declare function extractToc(content: string): TocItem[];
4
6
  export declare function extractTitle(content: string, fallback: string): string;
5
7
  export declare function filePathToUrl(relativeFilePath: string): string;
6
- export declare function formatTitleFromFilename(filename: string): string;
7
8
  export declare function parseMdxFile(filePath: string, contentDir: string): Promise<PageData>;
8
9
  export declare function scanContent(contentDir: string): Promise<PageData[]>;
9
10
  export declare function scanContentDirectories(contentDir: string): Promise<string[]>;
@@ -2,6 +2,8 @@
2
2
  import path from "node:path";
3
3
  import fs from "fs-extra";
4
4
  import matter from "gray-matter";
5
+ import { formatTitleFromFilename } from "../utils/format-title.js";
6
+ export { formatTitleFromFilename };
5
7
  function isWhitespace(character) {
6
8
  if (!character)
7
9
  return false;
@@ -142,15 +144,6 @@ export function filePathToUrl(relativeFilePath) {
142
144
  }
143
145
  return cleanPath.startsWith("/") ? cleanPath : `/${cleanPath}`;
144
146
  }
145
- export function formatTitleFromFilename(filename) {
146
- const base = path.basename(filename, path.extname(filename));
147
- if (base === "index")
148
- return "Overview";
149
- return base
150
- .split(/[-_]/)
151
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
152
- .join(" ");
153
- }
154
147
  export async function parseMdxFile(filePath, contentDir) {
155
148
  const raw = await fs.readFile(filePath, "utf-8");
156
149
  const parsed = matter(raw);
@@ -0,0 +1,2 @@
1
+ export { createFolioPluginLifecycleManager, FolioPluginHookError, FolioPluginLifecycleManager, } from "./lifecycle.js";
2
+ export type { FolioPluginHookMetadata, FolioPluginLifecycleOptions, LifecycleHook, } from "./lifecycle.js";
@@ -0,0 +1 @@
1
+ export { createFolioPluginLifecycleManager, FolioPluginHookError, FolioPluginLifecycleManager, } from "./lifecycle.js";
@@ -0,0 +1,19 @@
1
+ import type { FolioPage, FolioPluginContext } from "../../plugin.js";
2
+ export type LifecycleHook = "configResolved" | "buildStart" | "pagesGenerated" | "pageCollected" | "pageTransformed" | "pageActions" | "generate" | "buildEnd";
3
+ export interface FolioPluginHookMetadata {
4
+ pluginName: string;
5
+ hook: LifecycleHook;
6
+ mode: FolioPluginContext["mode"];
7
+ pageRoute?: string;
8
+ sourcePath?: string;
9
+ }
10
+ export declare class FolioPluginHookError extends Error {
11
+ readonly pluginName: string;
12
+ readonly hook: LifecycleHook;
13
+ readonly mode: FolioPluginContext["mode"];
14
+ readonly pageRoute?: string;
15
+ readonly sourcePath?: string;
16
+ readonly metadata: FolioPluginHookMetadata;
17
+ readonly cause: unknown;
18
+ constructor(pluginName: string, hook: LifecycleHook, cause: unknown, mode?: FolioPluginContext["mode"], page?: FolioPage);
19
+ }
@@ -0,0 +1,28 @@
1
+ export class FolioPluginHookError extends Error {
2
+ pluginName;
3
+ hook;
4
+ mode;
5
+ pageRoute;
6
+ sourcePath;
7
+ metadata;
8
+ cause;
9
+ constructor(pluginName, hook, cause, mode = "production", page) {
10
+ const detail = cause instanceof Error ? cause.message : String(cause);
11
+ const pageRoute = page?.url;
12
+ const sourcePath = page?.sourcePath ?? page?.filePath;
13
+ const location = [
14
+ pageRoute && `route "${pageRoute}"`,
15
+ sourcePath && `source "${sourcePath}"`,
16
+ `mode "${mode}"`,
17
+ ].join(", ");
18
+ super(`[folio] Plugin "${pluginName}" hook "${hook}" failed (${location}): ${detail}`, { cause });
19
+ this.name = "FolioPluginHookError";
20
+ this.pluginName = pluginName;
21
+ this.hook = hook;
22
+ this.mode = mode;
23
+ this.pageRoute = pageRoute;
24
+ this.sourcePath = sourcePath;
25
+ this.metadata = { pluginName, hook, mode, pageRoute, sourcePath };
26
+ this.cause = cause;
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ export declare function snapshot<T>(value: T): Readonly<T>;
@@ -0,0 +1,156 @@
1
+ const IMMUTABLE_MESSAGE = "Cannot mutate an immutable plugin snapshot";
2
+ class ImmutableMap extends Map {
3
+ constructor(entries) {
4
+ super();
5
+ for (const [key, value] of entries)
6
+ Map.prototype.set.call(this, key, value);
7
+ }
8
+ set() { throw new TypeError(IMMUTABLE_MESSAGE); }
9
+ delete() { throw new TypeError(IMMUTABLE_MESSAGE); }
10
+ clear() { throw new TypeError(IMMUTABLE_MESSAGE); }
11
+ }
12
+ class ImmutableSet extends Set {
13
+ constructor(values) {
14
+ super();
15
+ for (const value of values)
16
+ Set.prototype.add.call(this, value);
17
+ }
18
+ add() { throw new TypeError(IMMUTABLE_MESSAGE); }
19
+ delete() { throw new TypeError(IMMUTABLE_MESSAGE); }
20
+ clear() { throw new TypeError(IMMUTABLE_MESSAGE); }
21
+ }
22
+ function isPlainObject(value) {
23
+ const prototype = Object.getPrototypeOf(value);
24
+ return prototype === Object.prototype || prototype === null;
25
+ }
26
+ function immutableObject(value, seen) {
27
+ if (seen.has(value))
28
+ return seen.get(value);
29
+ let proxy;
30
+ proxy = new Proxy(value, {
31
+ get(target, property) {
32
+ const result = Reflect.get(target, property, target);
33
+ if (typeof result === "function")
34
+ return result.bind(proxy);
35
+ return clone(result, seen);
36
+ },
37
+ set() { throw new TypeError(IMMUTABLE_MESSAGE); },
38
+ deleteProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
39
+ defineProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
40
+ });
41
+ seen.set(value, proxy);
42
+ return proxy;
43
+ }
44
+ const dateMutators = new Set([
45
+ "setDate", "setFullYear", "setHours", "setMilliseconds", "setMinutes", "setMonth",
46
+ "setSeconds", "setTime", "setUTCDate", "setUTCFullYear", "setUTCHours",
47
+ "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "setYear",
48
+ ]);
49
+ function immutableDate(value, seen) {
50
+ const target = new Date(value.getTime());
51
+ const proxy = new Proxy(target, {
52
+ get(current, property) {
53
+ const result = Reflect.get(current, property, current);
54
+ if (typeof result !== "function")
55
+ return clone(result, seen);
56
+ if (typeof property === "string" && dateMutators.has(property)) {
57
+ return () => { throw new TypeError(IMMUTABLE_MESSAGE); };
58
+ }
59
+ return result.bind(current);
60
+ },
61
+ set() { throw new TypeError(IMMUTABLE_MESSAGE); },
62
+ deleteProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
63
+ defineProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
64
+ });
65
+ seen.set(value, proxy);
66
+ Object.freeze(target);
67
+ return proxy;
68
+ }
69
+ function immutableRegExp(value, seen) {
70
+ const target = new RegExp(value.source, value.flags);
71
+ target.lastIndex = value.lastIndex;
72
+ const proxy = new Proxy(target, {
73
+ get(current, property) {
74
+ const result = Reflect.get(current, property, current);
75
+ if (typeof result !== "function")
76
+ return clone(result, seen);
77
+ if (property === "compile")
78
+ return () => { throw new TypeError(IMMUTABLE_MESSAGE); };
79
+ return (...args) => {
80
+ const working = new RegExp(current.source, current.flags);
81
+ working.lastIndex = current.lastIndex;
82
+ return Reflect.apply(result, working, args);
83
+ };
84
+ },
85
+ set() { throw new TypeError(IMMUTABLE_MESSAGE); },
86
+ deleteProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
87
+ defineProperty() { throw new TypeError(IMMUTABLE_MESSAGE); },
88
+ });
89
+ seen.set(value, proxy);
90
+ Object.freeze(target);
91
+ return proxy;
92
+ }
93
+ function clone(value, seen) {
94
+ if (value === null || typeof value !== "object")
95
+ return value;
96
+ if (seen.has(value))
97
+ return seen.get(value);
98
+ if (value instanceof Date)
99
+ return immutableDate(value, seen);
100
+ if (value instanceof RegExp)
101
+ return immutableRegExp(value, seen);
102
+ if (value instanceof Map) {
103
+ const copy = new ImmutableMap([]);
104
+ seen.set(value, copy);
105
+ for (const [key, child] of value) {
106
+ Map.prototype.set.call(copy, clone(key, seen), clone(child, seen));
107
+ }
108
+ return copy;
109
+ }
110
+ if (value instanceof Set) {
111
+ const copy = new ImmutableSet([]);
112
+ seen.set(value, copy);
113
+ for (const child of value)
114
+ Set.prototype.add.call(copy, clone(child, seen));
115
+ return copy;
116
+ }
117
+ if (!Array.isArray(value) && !isPlainObject(value))
118
+ return immutableObject(value, seen);
119
+ const copy = Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value));
120
+ seen.set(value, copy);
121
+ for (const key of Reflect.ownKeys(value)) {
122
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
123
+ if (descriptor && "value" in descriptor) {
124
+ Object.defineProperty(copy, key, { ...descriptor, value: clone(descriptor.value, seen) });
125
+ }
126
+ }
127
+ return copy;
128
+ }
129
+ function freeze(value, seen = new WeakSet()) {
130
+ if (value === null || typeof value !== "object" || seen.has(value))
131
+ return value;
132
+ if (!Array.isArray(value) && !isPlainObject(value) && !(value instanceof Map) && !(value instanceof Set))
133
+ return value;
134
+ seen.add(value);
135
+ if (value instanceof Map) {
136
+ for (const [key, child] of value) {
137
+ freeze(key, seen);
138
+ freeze(child, seen);
139
+ }
140
+ }
141
+ else if (value instanceof Set) {
142
+ for (const child of value)
143
+ freeze(child, seen);
144
+ }
145
+ else {
146
+ for (const key of Reflect.ownKeys(value)) {
147
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
148
+ if (descriptor && "value" in descriptor)
149
+ freeze(descriptor.value, seen);
150
+ }
151
+ }
152
+ return Object.freeze(value);
153
+ }
154
+ export function snapshot(value) {
155
+ return freeze(clone(value, new WeakMap()));
156
+ }
@@ -0,0 +1,34 @@
1
+ import type { FolioBuildResult, FolioPage, FolioPlugin, FolioPluginContext, FolioPluginLogger } from "../../plugin.js";
2
+ import type { DocsConfig } from "../../types.js";
3
+ export type { FolioPluginHookMetadata, LifecycleHook } from "./lifecycle-error.js";
4
+ export { FolioPluginHookError } from "./lifecycle-error.js";
5
+ export interface FolioPluginLifecycleOptions {
6
+ plugins?: readonly FolioPlugin[];
7
+ config: DocsConfig;
8
+ rootDir: string;
9
+ contentDir: string;
10
+ outputDir?: string;
11
+ mode: FolioPluginContext["mode"];
12
+ logger: FolioPluginLogger;
13
+ pages?: readonly FolioPage[];
14
+ }
15
+ export declare class FolioPluginLifecycleManager {
16
+ private readonly plugins;
17
+ private readonly options;
18
+ private pages;
19
+ constructor(options: FolioPluginLifecycleOptions);
20
+ getPages(): readonly FolioPage[];
21
+ configResolved(): Promise<void>;
22
+ buildStart(): Promise<void>;
23
+ pagesGenerated(pages: readonly FolioPage[]): Promise<readonly FolioPage[]>;
24
+ pageCollected(page: FolioPage): Promise<void>;
25
+ pageTransformed(page: FolioPage): Promise<FolioPage>;
26
+ pageActions(page: FolioPage): Promise<FolioPage>;
27
+ generate(): Promise<void>;
28
+ buildEnd(result: FolioBuildResult): Promise<void>;
29
+ private context;
30
+ private runContextHook;
31
+ private validateGeneratedPages;
32
+ private wrap;
33
+ }
34
+ export declare function createFolioPluginLifecycleManager(options: FolioPluginLifecycleOptions): FolioPluginLifecycleManager;