@nikala-ui/folio 0.15.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.
- package/dist/cli/commands/init.js +89 -54
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/search/provider.d.ts +9 -0
- package/dist/search/provider.js +4 -2
- package/dist/server/plugin/virtual-modules.js +34 -1
- package/dist/templates/env.d.ts +26 -0
- package/dist/templates/locales/en.json +77 -0
- package/dist/themes/default/components/docs-landing-body.d.ts +17 -0
- package/dist/themes/default/components/docs-landing-body.jsx +17 -0
- package/dist/themes/default/components/docs-page-body.d.ts +21 -0
- package/dist/themes/default/components/docs-page-body.jsx +36 -0
- package/dist/themes/default/components/page-actions.d.ts +15 -0
- package/dist/themes/default/components/page-actions.jsx +60 -0
- package/dist/themes/default/components/page-header.d.ts +7 -0
- package/dist/themes/default/components/page-header.jsx +3 -0
- package/dist/themes/default/components/sidebar-footer.d.ts +6 -0
- package/dist/themes/default/components/sidebar-footer.jsx +12 -0
- package/dist/themes/default/components/sidebar-header.d.ts +8 -0
- package/dist/themes/default/components/sidebar-header.jsx +17 -0
- package/dist/themes/default/components/sidebar-mobile-nav.d.ts +7 -0
- package/dist/themes/default/components/sidebar-mobile-nav.jsx +17 -0
- package/dist/themes/default/components/sidebar-promo.d.ts +8 -0
- package/dist/themes/default/components/sidebar-promo.jsx +20 -0
- package/dist/themes/default/hooks/use-page-copy.d.ts +6 -0
- package/dist/themes/default/hooks/use-page-copy.js +26 -0
- package/dist/themes/default/layout.jsx +23 -147
- package/dist/themes/default/lib/layout-visibility.d.ts +8 -0
- package/dist/themes/default/lib/layout-visibility.js +24 -0
- package/dist/themes/default/navigation/mobile-table-of-contents.jsx +2 -2
- package/dist/themes/default/sidebar.jsx +17 -47
- package/dist/vendor/docs-src/client/page-actions.ts +69 -0
- package/dist/vendor/docs-src/navigation/index.ts +2 -0
- package/dist/vendor/docs-src/navigation/repository-links.ts +43 -0
- package/dist/vendor/docs-src/navigation/sidebar-state.ts +22 -0
- package/dist/vendor/docs-src/navigation/sidebar-tree.ts +15 -0
- package/dist/vendor/docs-src/search/provider.ts +83 -0
- package/dist/vendor/docs-src/themes/default/components/docs-landing-body.tsx +30 -0
- package/dist/vendor/docs-src/themes/default/components/docs-page-body.tsx +53 -0
- package/dist/vendor/docs-src/themes/default/components/page-actions.tsx +105 -0
- package/dist/vendor/docs-src/themes/default/components/page-header.tsx +31 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-footer.tsx +21 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-header.tsx +30 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-mobile-nav.tsx +33 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-promo.tsx +37 -0
- package/dist/vendor/docs-src/themes/default/content/breadcrumbs.tsx +43 -0
- package/dist/vendor/docs-src/themes/default/content/pager.tsx +19 -0
- package/dist/vendor/docs-src/themes/default/content/table-of-contents.tsx +32 -0
- package/dist/vendor/docs-src/themes/default/hooks/use-page-copy.ts +29 -0
- package/dist/vendor/docs-src/themes/default/icons.ts +16 -0
- package/dist/vendor/docs-src/themes/default/index.ts +46 -0
- package/dist/vendor/docs-src/themes/default/layout.tsx +176 -0
- package/dist/vendor/docs-src/themes/default/lib/layout-visibility.ts +39 -0
- package/dist/vendor/docs-src/themes/default/navbar.tsx +130 -0
- package/dist/vendor/docs-src/themes/default/navigation/mobile-table-of-contents.tsx +61 -0
- package/dist/vendor/docs-src/themes/default/navigation/sidebar-tree.tsx +202 -0
- package/dist/vendor/docs-src/themes/default/overlays/search-dialog.tsx +106 -0
- package/dist/vendor/docs-src/themes/default/sidebar.tsx +86 -0
- package/dist/vendor/docs-src/themes/index.ts +4 -0
- package/dist/vendor/docs-src/themes/types.ts +87 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -15,17 +15,8 @@ async function listSourceFiles(dir) {
|
|
|
15
15
|
}
|
|
16
16
|
return result;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
for (const sourceFile of await listSourceFiles(dir)) {
|
|
22
|
-
if (!/\.(?:d\.ts|[cm]?[jt]sx?)$/.test(sourceFile))
|
|
23
|
-
continue;
|
|
24
|
-
const content = await fs.readFile(sourceFile, "utf-8");
|
|
25
|
-
const cleaned = content.replace(/\s*\/\/[#@]\s*sourceMappingURL=.*$/gm, "");
|
|
26
|
-
if (cleaned !== content)
|
|
27
|
-
await fs.writeFile(sourceFile, cleaned, "utf-8");
|
|
28
|
-
}
|
|
18
|
+
function isAuthoredSourceFile(file) {
|
|
19
|
+
return /\.(?:ts|tsx)$/.test(file) && !file.endsWith(".d.ts");
|
|
29
20
|
}
|
|
30
21
|
async function resolveRegistryDir() {
|
|
31
22
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -79,7 +70,7 @@ async function copyRegistrySource(root) {
|
|
|
79
70
|
].filter((file) => fs.existsSync(file));
|
|
80
71
|
const projectFiles = [
|
|
81
72
|
...(await listSourceFiles(path.join(root, "docs"))),
|
|
82
|
-
...(await listSourceFiles(path.join(root, "src/themes/default"))),
|
|
73
|
+
...(await listSourceFiles(path.join(root, "src/themes/default"))).filter(isAuthoredSourceFile),
|
|
83
74
|
...docsComponentSources,
|
|
84
75
|
];
|
|
85
76
|
const projectSource = (await Promise.all(projectFiles.map((file) => fs.readFile(file, "utf-8")))).join("\n");
|
|
@@ -152,7 +143,8 @@ async function copyRegistrySource(root) {
|
|
|
152
143
|
: file.path.startsWith("ui/")
|
|
153
144
|
? path.join(componentsDir, relative)
|
|
154
145
|
: path.join(hooksDir, relative);
|
|
155
|
-
await fs.
|
|
146
|
+
if (!(await fs.pathExists(destination)))
|
|
147
|
+
await fs.outputFile(destination, file.content, "utf-8");
|
|
156
148
|
if (file.path.startsWith("hooks/"))
|
|
157
149
|
hookFiles.push(relative.replace(/\.(tsx?|jsx?)$/, ""));
|
|
158
150
|
else if (file.path.startsWith("ui/"))
|
|
@@ -167,10 +159,12 @@ async function copyRegistrySource(root) {
|
|
|
167
159
|
];
|
|
168
160
|
const internalComponentsSource = internalComponentCandidates.find((directory) => fs.existsSync(directory));
|
|
169
161
|
if (internalComponentsSource) {
|
|
170
|
-
for (const name of ["theme-toggle"]) {
|
|
162
|
+
for (const name of ["theme-toggle", "sidebar", "section-heading", "command"]) {
|
|
171
163
|
const source = path.join(internalComponentsSource, `${name}.tsx`);
|
|
172
164
|
if (await fs.pathExists(source)) {
|
|
173
|
-
|
|
165
|
+
const destination = path.join(componentsDir, `${name}.tsx`);
|
|
166
|
+
if (!(await fs.pathExists(destination)))
|
|
167
|
+
await fs.copy(source, destination);
|
|
174
168
|
componentFiles.push(name);
|
|
175
169
|
}
|
|
176
170
|
}
|
|
@@ -180,91 +174,105 @@ async function copyRegistrySource(root) {
|
|
|
180
174
|
path.resolve(commandDir, "../../vendor/docs-src/lib/cn.ts"),
|
|
181
175
|
];
|
|
182
176
|
const cnSource = cnCandidates.find((candidate) => fs.existsSync(candidate));
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
const cnDestination = path.join(root, "src/lib/cn.ts");
|
|
178
|
+
if (cnSource && !(await fs.pathExists(cnDestination))) {
|
|
179
|
+
await fs.outputFile(cnDestination, await fs.readFile(cnSource, "utf-8"), "utf-8");
|
|
180
|
+
}
|
|
185
181
|
return { componentFiles, hookFiles, dependencies: [...dependencies].sort() };
|
|
186
182
|
}
|
|
187
183
|
async function copyPluginSources(root) {
|
|
188
184
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
189
185
|
const sourceCandidates = [
|
|
190
186
|
path.resolve(commandDir, "../../../src/plugins"),
|
|
191
|
-
path.resolve(commandDir, "../../plugins"),
|
|
187
|
+
path.resolve(commandDir, "../../vendor/docs-src/plugins"),
|
|
192
188
|
];
|
|
193
189
|
const source = sourceCandidates.find((candidate) => fs.existsSync(candidate));
|
|
194
190
|
if (!source)
|
|
195
191
|
throw new Error("Folio plugin sources are missing from the package");
|
|
196
|
-
for (const sourceFile of await listSourceFiles(source)) {
|
|
192
|
+
for (const sourceFile of (await listSourceFiles(source)).filter(isAuthoredSourceFile)) {
|
|
197
193
|
const relative = path.relative(source, sourceFile);
|
|
198
194
|
const destination = path.join(root, "src/plugins", relative);
|
|
199
195
|
const content = (await fs.readFile(sourceFile, "utf-8"))
|
|
200
196
|
.replace(/from "(?:\.\.\/)+plugin\.js"/g, 'from "@nikala-ui/folio"')
|
|
201
|
-
.replace(/from "(?:\.\.\/)+types\.js"/g, 'from "@nikala-ui/folio"')
|
|
202
|
-
|
|
197
|
+
.replace(/from "(?:\.\.\/)+types\.js"/g, 'from "@nikala-ui/folio"')
|
|
198
|
+
.replace(/(from "(?:\.\/|\.\.\/)[^"]+)\.jsx"/g, "$1.tsx\"")
|
|
199
|
+
.replace(/(from "(?:\.\/|\.\.\/)[^"]+)\.js"/g, "$1.ts\"");
|
|
200
|
+
if (!(await fs.pathExists(destination)))
|
|
201
|
+
await fs.outputFile(destination, content, "utf-8");
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
204
|
async function copyCustomTheme(root) {
|
|
206
205
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
207
|
-
const sourceCandidates = [
|
|
206
|
+
const sourceCandidates = [
|
|
207
|
+
path.resolve(commandDir, "../../../src/themes/default"),
|
|
208
|
+
path.resolve(commandDir, "../../vendor/docs-src/themes/default"),
|
|
209
|
+
];
|
|
208
210
|
const source = sourceCandidates.find((candidate) => fs.existsSync(candidate));
|
|
209
211
|
const target = path.join(root, "src/themes/default");
|
|
210
212
|
if (!source) {
|
|
211
|
-
|
|
213
|
+
const destination = path.join(target, "index.ts");
|
|
214
|
+
if (!(await fs.pathExists(destination)))
|
|
215
|
+
await fs.outputFile(destination, `export { defaultTheme as default } from "@nikala-ui/folio";
|
|
212
216
|
`, "utf-8");
|
|
213
217
|
return;
|
|
214
218
|
}
|
|
215
219
|
for (const sourceFile of await listSourceFiles(source)) {
|
|
216
220
|
const basename = path.basename(sourceFile);
|
|
217
|
-
|
|
218
|
-
const isPublishedThemeFile = /\.jsx?$/.test(sourceFile);
|
|
219
|
-
if ((!isSourceFile && !isPublishedThemeFile) || basename !== basename.toLowerCase())
|
|
221
|
+
if (!isAuthoredSourceFile(sourceFile) || basename !== basename.toLowerCase())
|
|
220
222
|
continue;
|
|
221
223
|
const relative = path.relative(source, sourceFile)
|
|
222
224
|
.replace(/\.jsx?$/, ".tsx")
|
|
223
225
|
.replace(/index\.tsx$/, "index.ts");
|
|
224
226
|
const destination = path.join(target, relative);
|
|
227
|
+
const runtimePrefix = relative.includes(path.sep) ? "../" : "./";
|
|
225
228
|
let content = await fs.readFile(sourceFile, "utf-8");
|
|
226
229
|
content = content
|
|
227
230
|
.replace(/\s*\/\/[#@]\s*sourceMappingURL=.*$/gm, "")
|
|
228
231
|
.replace(/from "@nikala-ui\/core\/ui\//g, 'from "@/components/ui/')
|
|
229
232
|
.replace(/from "@nikala-ui\/core"/g, 'from "@/components/ui"')
|
|
230
233
|
.replace(/from "@nikala-ui\/hooks"/g, 'from "@/hooks"')
|
|
231
|
-
.replace(/from "
|
|
232
|
-
.replace(/from "
|
|
233
|
-
.replace(/from "
|
|
234
|
-
.replace(/from "\.\.\/\.\.\/\.\.\/search\/provider\.js"/g, 'from "../runtime/search-provider.js"')
|
|
234
|
+
.replace(/from "(?:\.\.\/)+client\/page-actions\.js"/g, `from "${runtimePrefix}runtime/page-actions.js"`)
|
|
235
|
+
.replace(/from "(?:\.\.\/)+navigation\/repository-links\.js"/g, `from "${runtimePrefix}runtime/repository-links.js"`)
|
|
236
|
+
.replace(/from "(?:\.\.\/)+search\/provider\.js"/g, `from "${runtimePrefix}runtime/search-provider.js"`)
|
|
235
237
|
.replace(/from "\.\.\/\.\.\/\.\.\/navigation\/sidebar-state\.js"/g, 'from "./sidebar-state.js"')
|
|
236
238
|
.replace(/from "(?:\.\.\/)+types\.js"/g, 'from "@nikala-ui/folio"')
|
|
239
|
+
.replace(/import\("(?:\.\.\/)+types\.js"\)/g, 'import("@nikala-ui/folio")')
|
|
237
240
|
.replace(/from "(\.\.\/|\.\/)[^"]+\.(?:jsx|tsx|js)"/g, (match) => match.replace(/\.(?:jsx|tsx|js)"$/, '"'))
|
|
238
241
|
.replace(/export \* from "(\.\.\/|\.\/)[^"]+\.(?:jsx|tsx|js)"/g, (match) => match.replace(/\.(?:jsx|tsx|js)"$/, '"'));
|
|
239
|
-
await fs.
|
|
242
|
+
if (!(await fs.pathExists(destination)))
|
|
243
|
+
await fs.outputFile(destination, content, "utf-8");
|
|
240
244
|
}
|
|
241
245
|
const runtimeSources = [
|
|
242
|
-
["../../client/page-actions.
|
|
243
|
-
["../../navigation/repository-links.
|
|
244
|
-
["../../search/provider.
|
|
246
|
+
[["../../../src/client/page-actions.ts", "../../vendor/docs-src/client/page-actions.ts"], "runtime/page-actions.ts"],
|
|
247
|
+
[["../../../src/navigation/repository-links.ts", "../../vendor/docs-src/navigation/repository-links.ts"], "runtime/repository-links.ts"],
|
|
248
|
+
[["../../../src/search/provider.ts", "../../vendor/docs-src/search/provider.ts"], "runtime/search-provider.ts"],
|
|
245
249
|
];
|
|
246
|
-
for (const [
|
|
247
|
-
const sourceFile =
|
|
248
|
-
|
|
250
|
+
for (const [relativeSources, relativeDestination] of runtimeSources) {
|
|
251
|
+
const sourceFile = relativeSources
|
|
252
|
+
.map((relativeSource) => path.resolve(commandDir, relativeSource))
|
|
253
|
+
.find((candidate) => fs.existsSync(candidate));
|
|
254
|
+
if (!sourceFile)
|
|
249
255
|
continue;
|
|
250
256
|
const destination = path.join(target, relativeDestination);
|
|
251
|
-
|
|
252
|
-
.
|
|
253
|
-
|
|
257
|
+
if (!(await fs.pathExists(destination))) {
|
|
258
|
+
const content = (await fs.readFile(sourceFile, "utf-8"))
|
|
259
|
+
.replace(/\s*\/\/[#@]\s*sourceMappingURL=.*$/gm, "")
|
|
260
|
+
.replace(/from "\.\.\/types\.js"/g, 'from "@nikala-ui/folio"');
|
|
261
|
+
await fs.outputFile(destination, content, "utf-8");
|
|
262
|
+
}
|
|
254
263
|
}
|
|
255
264
|
const navigationCandidates = [
|
|
256
265
|
path.resolve(commandDir, "../../../src/navigation/sidebar-state.ts"),
|
|
257
|
-
path.resolve(commandDir, "../../navigation/sidebar-state.
|
|
266
|
+
path.resolve(commandDir, "../../vendor/docs-src/navigation/sidebar-state.ts"),
|
|
258
267
|
];
|
|
259
268
|
const navigationSource = navigationCandidates.find((candidate) => fs.existsSync(candidate));
|
|
260
269
|
if (navigationSource) {
|
|
261
270
|
const navigationContent = (await fs.readFile(navigationSource, "utf-8"))
|
|
262
271
|
.replace(/from "\.\.\/types\.js"/g, 'from "@nikala-ui/folio"');
|
|
263
|
-
|
|
272
|
+
const navigationTarget = path.join(target, "navigation/sidebar-state.ts");
|
|
273
|
+
if (!(await fs.pathExists(navigationTarget)))
|
|
274
|
+
await fs.outputFile(navigationTarget, navigationContent, "utf-8");
|
|
264
275
|
}
|
|
265
|
-
// Remove stale references left by older generated themes so upgrading and
|
|
266
|
-
// re-running init is enough to silence Vite's missing-map warnings.
|
|
267
|
-
await stripSourceMapComments(target);
|
|
268
276
|
}
|
|
269
277
|
async function copyDefaultAssets(root) {
|
|
270
278
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -280,11 +288,15 @@ async function copyDefaultAssets(root) {
|
|
|
280
288
|
await fs.copy(source, destination);
|
|
281
289
|
}
|
|
282
290
|
async function writeProjectFiles(root, registryDependencies) {
|
|
291
|
+
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
283
292
|
const docsConfigPath = path.join(root, "docs.config.ts");
|
|
284
293
|
if (!(await fs.pathExists(docsConfigPath)))
|
|
285
|
-
await fs.outputFile(docsConfigPath, `
|
|
294
|
+
await fs.outputFile(docsConfigPath, `import { createI18nPlugin } from "./src/plugins/i18n/index.ts";
|
|
295
|
+
|
|
296
|
+
export default {
|
|
297
|
+
plugins: [createI18nPlugin({ defaultLocale: "en", locales: ["en"] })],
|
|
286
298
|
title: "My Project Docs",
|
|
287
|
-
description: "Documentation built with Folio
|
|
299
|
+
description: "Documentation built with Folio",
|
|
288
300
|
favicon: "/favicon.ico",
|
|
289
301
|
contentDir: "docs",
|
|
290
302
|
css: "src/index.css",
|
|
@@ -294,6 +306,17 @@ async function writeProjectFiles(root, registryDependencies) {
|
|
|
294
306
|
search: { enabled: true },
|
|
295
307
|
};
|
|
296
308
|
`, "utf-8");
|
|
309
|
+
const localeTemplate = path.resolve(commandDir, "../../templates/locales/en.json");
|
|
310
|
+
const localePath = path.join(root, "locales/en.json");
|
|
311
|
+
if (!(await fs.pathExists(localePath)) && await fs.pathExists(localeTemplate)) {
|
|
312
|
+
await fs.ensureDir(path.dirname(localePath));
|
|
313
|
+
await fs.copyFile(localeTemplate, localePath);
|
|
314
|
+
}
|
|
315
|
+
const environmentTemplate = path.resolve(commandDir, "../../templates/env.d.ts");
|
|
316
|
+
const environmentPath = path.join(root, "src/env.d.ts");
|
|
317
|
+
if (!(await fs.pathExists(environmentPath)) && await fs.pathExists(environmentTemplate)) {
|
|
318
|
+
await fs.copyFile(environmentTemplate, environmentPath);
|
|
319
|
+
}
|
|
297
320
|
const nikalaConfigPath = path.join(root, "nikala.config.json");
|
|
298
321
|
if (!(await fs.pathExists(nikalaConfigPath))) {
|
|
299
322
|
await fs.writeJson(nikalaConfigPath, {
|
|
@@ -309,7 +332,6 @@ async function writeProjectFiles(root, registryDependencies) {
|
|
|
309
332
|
}, { spaces: 2 });
|
|
310
333
|
}
|
|
311
334
|
const packagePath = path.join(root, "package.json");
|
|
312
|
-
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
313
335
|
const docsPackageRoot = path.resolve(commandDir, "../../..");
|
|
314
336
|
const workspaceRoot = path.resolve(docsPackageRoot, "../..");
|
|
315
337
|
const workspaceManifestPath = path.join(workspaceRoot, "package.json");
|
|
@@ -322,7 +344,12 @@ async function writeProjectFiles(root, registryDependencies) {
|
|
|
322
344
|
private: true,
|
|
323
345
|
type: "module",
|
|
324
346
|
scripts: { dev: "bunx @nikala-ui/folio dev", build: "bunx @nikala-ui/folio build", preview: "bunx @nikala-ui/folio preview" },
|
|
325
|
-
dependencies: {},
|
|
347
|
+
dependencies: { "fs-extra": "^11.3.6" },
|
|
348
|
+
devDependencies: {
|
|
349
|
+
"@types/fs-extra": "latest",
|
|
350
|
+
"@types/node": "latest",
|
|
351
|
+
typescript: "latest",
|
|
352
|
+
},
|
|
326
353
|
};
|
|
327
354
|
const existingPackageJson = await fs.pathExists(packagePath) ? await fs.readJson(packagePath) : {};
|
|
328
355
|
const packageJson = {
|
|
@@ -350,11 +377,18 @@ async function writeProjectFiles(root, registryDependencies) {
|
|
|
350
377
|
.filter((dependency) => !packageJson.dependencies?.[dependency])
|
|
351
378
|
.map((dependency) => [dependency, "latest"])),
|
|
352
379
|
};
|
|
380
|
+
packageJson.devDependencies = {
|
|
381
|
+
...defaultPackageJson.devDependencies,
|
|
382
|
+
...existingPackageJson.devDependencies,
|
|
383
|
+
};
|
|
353
384
|
await fs.writeJson(packagePath, packageJson, { spaces: 2 });
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
385
|
+
const tsconfigPath = path.join(root, "tsconfig.json");
|
|
386
|
+
if (!(await fs.pathExists(tsconfigPath))) {
|
|
387
|
+
await fs.outputFile(tsconfigPath, JSON.stringify({
|
|
388
|
+
compilerOptions: { target: "ES2022", module: "ESNext", moduleResolution: "Bundler", jsx: "preserve", jsxImportSource: "solid-js", allowImportingTsExtensions: true, strict: true, skipLibCheck: true, paths: { "@/*": ["./src/*"], "@/components/*": ["./src/components/*"], "@/components/ui/*": ["./src/components/ui/*"], "@/hooks/*": ["./src/hooks/*"], "@/plugins/*": ["./src/plugins/*"] } },
|
|
389
|
+
include: ["src/**/*", "docs.config.ts"],
|
|
390
|
+
}, null, 2) + "\n", "utf-8");
|
|
391
|
+
}
|
|
358
392
|
}
|
|
359
393
|
export async function runInitCommand(targetDir = ".") {
|
|
360
394
|
const root = path.resolve(process.cwd(), targetDir);
|
|
@@ -363,7 +397,8 @@ export async function runInitCommand(targetDir = ".") {
|
|
|
363
397
|
console.log(pc.dim(` Initializing copy-paste documentation project in ${pc.bold(root)}...`));
|
|
364
398
|
console.log();
|
|
365
399
|
await fs.ensureDir(root);
|
|
366
|
-
|
|
400
|
+
if (!(await fs.pathExists(path.join(root, "src/lib/cn.ts"))))
|
|
401
|
+
runNikalaInit(root);
|
|
367
402
|
await writeProjectFiles(root, []);
|
|
368
403
|
const indexPath = path.join(root, "docs/index.mdx");
|
|
369
404
|
if (!(await fs.pathExists(indexPath)))
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export * from "./types.js";
|
|
2
|
+
export * from "./themes/types.js";
|
|
2
3
|
export type { FolioBuildResult, FolioPage, FolioPlugin, FolioPluginConfig, FolioPluginContext, FolioPluginFactory, FolioPluginLogger, } from "./plugin.js";
|
|
3
4
|
export { createFolioPlugin, defineFolioPlugin, validateFolioPlugin, validateFolioPlugins, } from "./plugin.js";
|
|
4
5
|
export { createFolioPluginLifecycleManager, FolioPluginHookError, FolioPluginLifecycleManager, } from "./core/plugin/index.js";
|
|
5
6
|
export type { FolioPluginHookMetadata, FolioPluginLifecycleOptions, } from "./core/plugin/index.js";
|
|
6
|
-
export type { SearchAdapter, SearchContext } from "./search/provider.js";
|
|
7
|
+
export type { SearchAdapter, SearchAdapterRuntime, SearchContext } from "./search/provider.js";
|
|
7
8
|
export * from "./navigation/index.js";
|
|
8
9
|
export * from "./config.js";
|
|
9
10
|
export * from "./core/content-scanner.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/docs/src/index.ts
|
|
2
2
|
export * from "./types.js";
|
|
3
|
+
export * from "./themes/types.js";
|
|
3
4
|
export { createFolioPlugin, defineFolioPlugin, validateFolioPlugin, validateFolioPlugins, } from "./plugin.js";
|
|
4
5
|
export { createFolioPluginLifecycleManager, FolioPluginHookError, FolioPluginLifecycleManager, } from "./core/plugin/index.js";
|
|
5
6
|
export * from "./navigation/index.js";
|
|
@@ -4,9 +4,18 @@ export interface SearchContext {
|
|
|
4
4
|
query: string;
|
|
5
5
|
pages: PageData[];
|
|
6
6
|
}
|
|
7
|
+
export interface SearchAdapterRuntime {
|
|
8
|
+
/** Browser module that exports the adapter factory. */
|
|
9
|
+
module: string;
|
|
10
|
+
/** Named export containing a factory that receives the optional adapter options. */
|
|
11
|
+
exportName: string;
|
|
12
|
+
/** JSON-serializable options passed to the browser adapter factory. */
|
|
13
|
+
options?: unknown;
|
|
14
|
+
}
|
|
7
15
|
export interface SearchAdapter {
|
|
8
16
|
name: string;
|
|
9
17
|
search: (context: SearchContext) => PageData[] | Promise<PageData[]>;
|
|
18
|
+
runtime?: SearchAdapterRuntime;
|
|
10
19
|
}
|
|
11
20
|
export type ConfiguredSearchProvider = NonNullable<DocsConfig["search"]>["provider"];
|
|
12
21
|
export interface ResolvedSearchProvider {
|
package/dist/search/provider.js
CHANGED
|
@@ -17,7 +17,7 @@ export const localSearchAdapter = {
|
|
|
17
17
|
*/
|
|
18
18
|
export function resolveSearchProvider(search) {
|
|
19
19
|
const configuredProvider = search?.provider;
|
|
20
|
-
if (configuredProvider && typeof configuredProvider !== "string") {
|
|
20
|
+
if (configuredProvider && typeof configuredProvider !== "string" && typeof configuredProvider.search === "function") {
|
|
21
21
|
return {
|
|
22
22
|
requested: configuredProvider.name,
|
|
23
23
|
active: configuredProvider.name,
|
|
@@ -25,7 +25,9 @@ export function resolveSearchProvider(search) {
|
|
|
25
25
|
implementation: configuredProvider,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
const requested = configuredProvider
|
|
28
|
+
const requested = typeof configuredProvider === "string"
|
|
29
|
+
? configuredProvider.trim() || LOCAL_SEARCH_PROVIDER
|
|
30
|
+
: configuredProvider?.name || LOCAL_SEARCH_PROVIDER;
|
|
29
31
|
return {
|
|
30
32
|
requested,
|
|
31
33
|
active: LOCAL_SEARCH_PROVIDER,
|
|
@@ -6,6 +6,25 @@ import { buildConfiguredSidebarTree, buildSidebarTree } from "../../core/route-t
|
|
|
6
6
|
import { serializeModuleValue } from "../module-serialization.js";
|
|
7
7
|
import { collectComponentExports, collectStaticComponentFiles, getComponentSourceDir, toLucideComponentName } from "./components.js";
|
|
8
8
|
import { RESOLVED_COMPONENTS_ID, RESOLVED_CONFIG_ID, RESOLVED_ICONS_ID, RESOLVED_ROUTES_ID, RESOLVED_SHIKI_ID, RESOLVED_SOURCES_ID, RESOLVED_THEME_ID, RESOLVED_TREE_ID, } from "./constants.js";
|
|
9
|
+
function getSearchAdapterRuntime(provider) {
|
|
10
|
+
if (!provider || typeof provider !== "object" || !provider.runtime)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (typeof provider.runtime !== "object" || Array.isArray(provider.runtime)) {
|
|
13
|
+
throw new Error("[folio] Search adapter runtime must be an object");
|
|
14
|
+
}
|
|
15
|
+
const runtime = provider.runtime;
|
|
16
|
+
if (typeof runtime.module !== "string" || typeof runtime.exportName !== "string") {
|
|
17
|
+
throw new Error("[folio] Search adapter runtime requires module and exportName");
|
|
18
|
+
}
|
|
19
|
+
if (!runtime.module.trim() || !runtime.exportName.trim()) {
|
|
20
|
+
throw new Error("[folio] Search adapter runtime requires module and exportName");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
module: runtime.module,
|
|
24
|
+
exportName: runtime.exportName,
|
|
25
|
+
options: runtime.options,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
9
28
|
export function createVirtualModuleLoader(state, moduleDir) {
|
|
10
29
|
return async function load(id) {
|
|
11
30
|
const current = state();
|
|
@@ -18,7 +37,21 @@ export const bundledThemes = {};
|
|
|
18
37
|
export default { createHighlighter, bundledLanguages, bundledThemes };
|
|
19
38
|
`;
|
|
20
39
|
if (id === RESOLVED_CONFIG_ID) {
|
|
21
|
-
|
|
40
|
+
const serializedConfig = serializeModuleValue(resolvedConfig);
|
|
41
|
+
const runtime = getSearchAdapterRuntime(resolvedConfig.search?.provider);
|
|
42
|
+
if (!runtime)
|
|
43
|
+
return `export default ${serializedConfig};`;
|
|
44
|
+
return `import * as searchRuntime from ${serializeModuleValue(runtime.module)};
|
|
45
|
+
const config = ${serializedConfig};
|
|
46
|
+
const provider = config.search?.provider;
|
|
47
|
+
const createAdapter = searchRuntime[${serializeModuleValue(runtime.exportName)}];
|
|
48
|
+
if (provider?.runtime) {
|
|
49
|
+
if (typeof createAdapter !== "function") {
|
|
50
|
+
throw new Error(${serializeModuleValue(`[folio] Search adapter runtime export "${runtime.exportName}" was not found in "${runtime.module}"`)});
|
|
51
|
+
}
|
|
52
|
+
config.search = { ...config.search, provider: createAdapter(provider.runtime.options) };
|
|
53
|
+
}
|
|
54
|
+
export default config;`;
|
|
22
55
|
}
|
|
23
56
|
if (id === RESOLVED_TREE_ID) {
|
|
24
57
|
const pages = [...await lifecycleSession.pages()];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module "*.css";
|
|
4
|
+
|
|
5
|
+
declare module "virtual:folio-config" {
|
|
6
|
+
const config: any;
|
|
7
|
+
export default config;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module "virtual:folio-tree" {
|
|
11
|
+
export const pages: any[];
|
|
12
|
+
export const tree: any[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module "virtual:folio-routes" {
|
|
16
|
+
export const routes: Record<string, () => Promise<any>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module "virtual:folio-components" {
|
|
20
|
+
const components: Record<string, any>;
|
|
21
|
+
export default components;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module "virtual:folio-icons" {
|
|
25
|
+
export const icons: Record<string, any>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"navigation.search": "Search docs...",
|
|
3
|
+
"navigation.searchLabel": "Search documentation",
|
|
4
|
+
"navigation.toggleSidebar": "Toggle documentation sidebar",
|
|
5
|
+
"navigation.closeSidebar": "Close documentation sidebar",
|
|
6
|
+
"navigation.documentation": "Documentation",
|
|
7
|
+
"navigation.primary": "Primary navigation",
|
|
8
|
+
"navigation.github": "GitHub",
|
|
9
|
+
"navigation.chooseLanguage": "Choose language",
|
|
10
|
+
"navigation.toggleNavigation": "Toggle navigation",
|
|
11
|
+
"navigation.toggleSidebarRail": "Toggle sidebar rail",
|
|
12
|
+
"navigation.sidebar": "Sidebar",
|
|
13
|
+
"navigation.collapse": "Collapse",
|
|
14
|
+
"navigation.expand": "Expand",
|
|
15
|
+
"navigation.breadcrumb": "Breadcrumb",
|
|
16
|
+
"actions.viewSource": "View source",
|
|
17
|
+
"actions.copyPage": "Copy page",
|
|
18
|
+
"actions.copyAsMarkdown": "Copy as Markdown",
|
|
19
|
+
"actions.learnMore": "Learn more",
|
|
20
|
+
"actions.copyDocumentationPage": "Copy documentation page",
|
|
21
|
+
"actions.openInProvider": "Open in {provider}",
|
|
22
|
+
"actions.copied": "Copied",
|
|
23
|
+
"actions.prompt": "Prompt",
|
|
24
|
+
"actions.copyContext": "Copy context",
|
|
25
|
+
"actions.copyCliCommand": "Copy CLI command",
|
|
26
|
+
"actions.copyCode": "Copy code",
|
|
27
|
+
"actions.exitFullscreen": "Exit fullscreen",
|
|
28
|
+
"actions.expandFullscreen": "Expand fullscreen",
|
|
29
|
+
"tableOfContents.title": "On this page",
|
|
30
|
+
"search.placeholder": "Search documentation...",
|
|
31
|
+
"search.empty": "No matching documents found.",
|
|
32
|
+
"search.pages": "Pages",
|
|
33
|
+
"search.by": "Search by",
|
|
34
|
+
"search.commandPlaceholder": "Search commands...",
|
|
35
|
+
"search.noResults": "No results found for {query}.",
|
|
36
|
+
"pagination.previous": "Previous",
|
|
37
|
+
"pagination.next": "Next",
|
|
38
|
+
"theme.toggle": "Toggle theme",
|
|
39
|
+
"theme.light": "Light",
|
|
40
|
+
"theme.dark": "Dark",
|
|
41
|
+
"theme.system": "System",
|
|
42
|
+
"theme.mode": "Theme mode",
|
|
43
|
+
"theme.brandAccentColor": "Brand accent color",
|
|
44
|
+
"theme.borderRadius": "Border radius",
|
|
45
|
+
"viewer.preview": "Preview",
|
|
46
|
+
"viewer.code": "Code",
|
|
47
|
+
"viewer.desktopViewport": "Desktop viewport",
|
|
48
|
+
"viewer.tabletViewport": "Tablet viewport",
|
|
49
|
+
"viewer.mobileViewport": "Mobile viewport",
|
|
50
|
+
"viewer.desktopSize": "Desktop size",
|
|
51
|
+
"viewer.tabletSize": "Tablet size",
|
|
52
|
+
"viewer.mobileSize": "Mobile size",
|
|
53
|
+
"viewer.toggleBackgroundGrid": "Toggle background grid",
|
|
54
|
+
"viewer.canvasGrid": "Canvas grid",
|
|
55
|
+
"viewer.resetPreviewCanvas": "Reset preview canvas",
|
|
56
|
+
"viewer.resetCanvas": "Reset canvas",
|
|
57
|
+
"viewer.copyAiContext": "Copy AI context",
|
|
58
|
+
"viewer.copyCodeForAi": "Copy code for AI",
|
|
59
|
+
"viewer.copyCliInstallation": "Copy CLI installation",
|
|
60
|
+
"viewer.fullscreenPreview": "Fullscreen preview",
|
|
61
|
+
"viewer.exitFullscreen": "Exit fullscreen",
|
|
62
|
+
"code.copied": "Code copied",
|
|
63
|
+
"code.copy": "Copy code",
|
|
64
|
+
"command.navigate": "Navigate",
|
|
65
|
+
"command.select": "Select",
|
|
66
|
+
"command.close": "Close",
|
|
67
|
+
"image.avatar": "Avatar",
|
|
68
|
+
"status.loading": "Loading...",
|
|
69
|
+
"status.loadingLabel": "Loading",
|
|
70
|
+
"accessibility.callout": "Callout",
|
|
71
|
+
"errors.pageNotFound": "Page not found",
|
|
72
|
+
"errors.pageNotFoundDescription": "The requested documentation page could not be found.",
|
|
73
|
+
"apiTable.property": "Property",
|
|
74
|
+
"apiTable.type": "Type",
|
|
75
|
+
"apiTable.default": "Default",
|
|
76
|
+
"apiTable.description": "Description"
|
|
77
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Component, type JSX } from "solid-js";
|
|
2
|
+
import type { BreadcrumbItemData } from "../../types.js";
|
|
3
|
+
export interface DocsLandingBodyProps {
|
|
4
|
+
breadcrumbs?: BreadcrumbItemData[];
|
|
5
|
+
showBreadcrumbs: boolean;
|
|
6
|
+
showPager: boolean;
|
|
7
|
+
prev?: {
|
|
8
|
+
title: string;
|
|
9
|
+
href: string;
|
|
10
|
+
};
|
|
11
|
+
next?: {
|
|
12
|
+
title: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
children?: JSX.Element;
|
|
16
|
+
}
|
|
17
|
+
export declare const DocsLandingBody: Component<DocsLandingBodyProps>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { Container } from "@/components/ui/container";
|
|
3
|
+
import { DocsBreadcrumbs } from "../content/breadcrumbs.jsx";
|
|
4
|
+
import { DocsPager } from "../content/pager.jsx";
|
|
5
|
+
export const DocsLandingBody = (props) => (<Container as="main" size="2xl" class="min-w-0 max-w-full flex-1 py-8 sm:py-12 lg:py-16">
|
|
6
|
+
<Container as="article" size="xl" class="mx-auto min-w-0 px-0 sm:px-4">
|
|
7
|
+
<Show when={props.showBreadcrumbs && props.breadcrumbs && props.breadcrumbs.length > 0}>
|
|
8
|
+
<DocsBreadcrumbs items={props.breadcrumbs} class="mb-6"/>
|
|
9
|
+
</Show>
|
|
10
|
+
<Container as="div" size="full" class="prose prose-zinc dark:prose-invert max-w-none px-0" data-docs-page-content>
|
|
11
|
+
{props.children}
|
|
12
|
+
</Container>
|
|
13
|
+
<Show when={props.showPager && (props.prev || props.next)}>
|
|
14
|
+
<DocsPager prev={props.prev} next={props.next}/>
|
|
15
|
+
</Show>
|
|
16
|
+
</Container>
|
|
17
|
+
</Container>);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Component, type JSX } from "solid-js";
|
|
2
|
+
import type { BreadcrumbItemData } from "../../types.js";
|
|
3
|
+
import type { PageData, TocItem } from "../../../types.js";
|
|
4
|
+
export interface DocsPageBodyProps {
|
|
5
|
+
breadcrumbs?: BreadcrumbItemData[];
|
|
6
|
+
currentPage?: PageData;
|
|
7
|
+
toc?: TocItem[];
|
|
8
|
+
prev?: {
|
|
9
|
+
title: string;
|
|
10
|
+
href: string;
|
|
11
|
+
};
|
|
12
|
+
next?: {
|
|
13
|
+
title: string;
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
showToc: boolean;
|
|
17
|
+
pageActions: JSX.Element;
|
|
18
|
+
sidebarPromo?: NonNullable<NonNullable<import("../../../types.js").DocsNavigationConfig["sidebar"]>["promo"]>;
|
|
19
|
+
children?: JSX.Element;
|
|
20
|
+
}
|
|
21
|
+
export declare const DocsPageBody: Component<DocsPageBodyProps>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { Container } from "@/components/ui/container";
|
|
3
|
+
import { DocsBreadcrumbs } from "../content/breadcrumbs.jsx";
|
|
4
|
+
import { DocsPager } from "../content/pager.jsx";
|
|
5
|
+
import { DocsTableOfContents } from "../content/table-of-contents.jsx";
|
|
6
|
+
import { DocsMobileTableOfContents } from "../navigation/mobile-table-of-contents.jsx";
|
|
7
|
+
import { SidebarPromo } from "./sidebar-promo.jsx";
|
|
8
|
+
export const DocsPageBody = (props) => (<Container as="main" size="2xl" class="min-w-0 w-full max-w-[96rem] flex-1 grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_16rem] items-start gap-4 sm:gap-8 py-6 sm:py-8">
|
|
9
|
+
<Container as="article" size="full" class="min-w-0 max-w-none mx-0 px-0 sm:px-4 w-full">
|
|
10
|
+
<Show when={props.breadcrumbs && props.breadcrumbs.length > 0}>
|
|
11
|
+
<DocsBreadcrumbs items={props.breadcrumbs} class="mb-6"/>
|
|
12
|
+
</Show>
|
|
13
|
+
<Show when={props.currentPage?.title}>
|
|
14
|
+
{props.pageActions}
|
|
15
|
+
</Show>
|
|
16
|
+
<Show when={props.showToc}>
|
|
17
|
+
<DocsMobileTableOfContents items={props.toc} class="mb-6"/>
|
|
18
|
+
</Show>
|
|
19
|
+
<Container as="div" size="full" class="prose prose-zinc dark:prose-invert max-w-none px-0 sm:px-0 lg:px-0" data-docs-page-content>
|
|
20
|
+
{props.children}
|
|
21
|
+
</Container>
|
|
22
|
+
<Show when={props.prev || props.next}>
|
|
23
|
+
<DocsPager prev={props.prev} next={props.next}/>
|
|
24
|
+
</Show>
|
|
25
|
+
</Container>
|
|
26
|
+
<Show when={props.showToc && props.currentPage?.url} keyed>
|
|
27
|
+
<Container as="aside" size="sm" class="hidden xl:block w-64 shrink-0 self-start px-0 sticky top-14 z-10 h-fit max-h-[calc(100vh-3.5rem)] overflow-y-auto bg-background">
|
|
28
|
+
<div class="flex flex-col gap-5">
|
|
29
|
+
<DocsTableOfContents items={props.toc} class="max-h-none"/>
|
|
30
|
+
<Show when={props.sidebarPromo}>
|
|
31
|
+
{(promo) => <SidebarPromo promo={promo()}/>}
|
|
32
|
+
</Show>
|
|
33
|
+
</div>
|
|
34
|
+
</Container>
|
|
35
|
+
</Show>
|
|
36
|
+
</Container>);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Accessor, type Component } from "solid-js";
|
|
2
|
+
import type { DocsAiProvider, DocsPageAction } from "../../../types.js";
|
|
3
|
+
export interface PageActionsProps {
|
|
4
|
+
sourceUrl?: string;
|
|
5
|
+
pageActions: readonly DocsPageAction[];
|
|
6
|
+
aiProviders: readonly DocsAiProvider[];
|
|
7
|
+
copyPageEnabled: boolean;
|
|
8
|
+
copyMarkdownEnabled: boolean;
|
|
9
|
+
pageUrl?: string;
|
|
10
|
+
pageTitle?: string;
|
|
11
|
+
markdown: Accessor<string>;
|
|
12
|
+
onCopyPage: () => void;
|
|
13
|
+
onCopyMarkdown: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const PageActions: Component<PageActionsProps>;
|