@nikala-ui/folio 0.13.2 → 0.14.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.
- package/dist/cli/commands/init.js +16 -0
- package/dist/components/mdx-components.jsx +4 -1
- package/dist/components/ui/package-manager-tabs.jsx +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/search/provider.d.ts +16 -4
- package/dist/search/provider.js +28 -3
- package/dist/server/index.js +4 -0
- package/dist/themes/default/layout.jsx +3 -2
- package/dist/themes/default/overlays/search-dialog.jsx +23 -8
- package/dist/themes/types.d.ts +2 -2
- package/dist/types.d.ts +2 -1
- package/dist/vendor/docs-src/components/mdx-components.tsx +4 -1
- package/dist/vendor/docs-src/components/ui/package-manager-tabs.tsx +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -1
|
@@ -15,6 +15,18 @@ async function listSourceFiles(dir) {
|
|
|
15
15
|
}
|
|
16
16
|
return result;
|
|
17
17
|
}
|
|
18
|
+
async function stripSourceMapComments(dir) {
|
|
19
|
+
if (!(await fs.pathExists(dir)))
|
|
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
|
+
}
|
|
29
|
+
}
|
|
18
30
|
async function resolveRegistryDir() {
|
|
19
31
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
20
32
|
const bundledRegistry = path.resolve(commandDir, "../../registry");
|
|
@@ -201,6 +213,7 @@ async function copyCustomTheme(root) {
|
|
|
201
213
|
.replace(/from "\.\.\/\.\.\/client\/page-actions\.js"/g, 'from "./runtime/page-actions.js"')
|
|
202
214
|
.replace(/from "\.\.\/\.\.\/navigation\/repository-links\.js"/g, 'from "./runtime/repository-links.js"')
|
|
203
215
|
.replace(/from "\.\.\/\.\.\/search\/provider\.js"/g, 'from "./runtime/search-provider.js"')
|
|
216
|
+
.replace(/from "\.\.\/\.\.\/\.\.\/search\/provider\.js"/g, 'from "../runtime/search-provider.js"')
|
|
204
217
|
.replace(/from "\.\.\/\.\.\/\.\.\/navigation\/sidebar-state\.js"/g, 'from "./sidebar-state.js"')
|
|
205
218
|
.replace(/from "(?:\.\.\/)+types\.js"/g, 'from "@nikala-ui/folio"')
|
|
206
219
|
.replace(/from "(\.\.\/|\.\/)[^"]+\.(?:jsx|tsx|js)"/g, (match) => match.replace(/\.(?:jsx|tsx|js)"$/, '"'))
|
|
@@ -231,6 +244,9 @@ async function copyCustomTheme(root) {
|
|
|
231
244
|
.replace(/from "\.\.\/types\.js"/g, 'from "@nikala-ui/folio"');
|
|
232
245
|
await fs.outputFile(path.join(target, "navigation/sidebar-state.ts"), navigationContent, "utf-8");
|
|
233
246
|
}
|
|
247
|
+
// Remove stale references left by older generated themes so upgrading and
|
|
248
|
+
// re-running init is enough to silence Vite's missing-map warnings.
|
|
249
|
+
await stripSourceMapComments(target);
|
|
234
250
|
}
|
|
235
251
|
async function copyDefaultAssets(root) {
|
|
236
252
|
const commandDir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -91,7 +91,10 @@ export function MdxCode(props) {
|
|
|
91
91
|
return <code class={cn(inline() ? "rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground font-normal border border-border/50" : "font-mono text-xs", local.class)} {...rest}>{local.children}</code>;
|
|
92
92
|
}
|
|
93
93
|
function isPackageCommand(code, language) {
|
|
94
|
-
|
|
94
|
+
const packageCommand = /^(?:(?:bun|npm|pnpm|yarn)\s+(?:add|install|i|create|run)\s+|(?:bunx|npx|pnpm\s+dlx|yarn\s+dlx)\s+)/i;
|
|
95
|
+
return /^(bash|sh|shell|zsh)$/i.test(language)
|
|
96
|
+
&& !code.includes("\n")
|
|
97
|
+
&& packageCommand.test(code.trim());
|
|
95
98
|
}
|
|
96
99
|
/** Preserve Shiki's server-rendered children while using Nikala's code chrome. */
|
|
97
100
|
export function MdxPre(props) {
|
|
@@ -11,6 +11,14 @@ import { cn } from "@/lib/cn";
|
|
|
11
11
|
function resolvePmCommand(manager, command) {
|
|
12
12
|
const trimmed = command.trim();
|
|
13
13
|
const pm = manager.toLowerCase();
|
|
14
|
+
// 0. Package scripts (e.g. "bun run dev")
|
|
15
|
+
const runMatch = trimmed.match(/^(?:bun|npm|pnpm|yarn)\s+run\s+(.+)$/);
|
|
16
|
+
if (runMatch) {
|
|
17
|
+
const script = runMatch[1];
|
|
18
|
+
if (pm === "yarn")
|
|
19
|
+
return `yarn ${script}`;
|
|
20
|
+
return `${pm} run ${script}`;
|
|
21
|
+
}
|
|
14
22
|
// 1. "create" command
|
|
15
23
|
const createMatch = trimmed.match(/^(?:bun|npm|npx|pnpm|yarn|deno)?\s*create\s+(.*)$/);
|
|
16
24
|
if (createMatch) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./types.js";
|
|
2
|
+
export type { SearchAdapter, SearchContext } from "./search/provider.js";
|
|
2
3
|
export * from "./navigation/index.js";
|
|
3
4
|
export * from "./config.js";
|
|
4
5
|
export * from "./core/content-scanner.js";
|
|
@@ -8,5 +9,6 @@ export * from "./mdx/highlighter.js";
|
|
|
8
9
|
export * from "./components/mdx-components.js";
|
|
9
10
|
export * from "./themes/index.js";
|
|
10
11
|
export * from "./server/index.js";
|
|
12
|
+
export * from "./search/provider.js";
|
|
11
13
|
import { nikalaDocsPlugin } from "./server/plugin.js";
|
|
12
14
|
export declare const nikalaDocs: typeof nikalaDocsPlugin;
|
package/dist/index.js
CHANGED
|
@@ -9,5 +9,6 @@ export * from "./mdx/highlighter.js";
|
|
|
9
9
|
export * from "./components/mdx-components.js";
|
|
10
10
|
export * from "./themes/index.js";
|
|
11
11
|
export * from "./server/index.js";
|
|
12
|
+
export * from "./search/provider.js";
|
|
12
13
|
import { nikalaDocsPlugin } from "./server/plugin.js";
|
|
13
14
|
export const nikalaDocs = nikalaDocsPlugin;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import type { DocsConfig } from "../types.js";
|
|
2
|
-
export
|
|
1
|
+
import type { DocsConfig, PageData } from "../types.js";
|
|
2
|
+
export declare const LOCAL_SEARCH_PROVIDER = "local";
|
|
3
|
+
export interface SearchContext {
|
|
4
|
+
query: string;
|
|
5
|
+
pages: PageData[];
|
|
6
|
+
}
|
|
7
|
+
export interface SearchAdapter {
|
|
8
|
+
name: string;
|
|
9
|
+
search: (context: SearchContext) => PageData[] | Promise<PageData[]>;
|
|
10
|
+
}
|
|
11
|
+
export type ConfiguredSearchProvider = NonNullable<DocsConfig["search"]>["provider"];
|
|
3
12
|
export interface ResolvedSearchProvider {
|
|
4
|
-
requested:
|
|
5
|
-
active:
|
|
13
|
+
requested: string;
|
|
14
|
+
active: string;
|
|
6
15
|
fallback: boolean;
|
|
16
|
+
implementation: SearchAdapter;
|
|
7
17
|
}
|
|
18
|
+
export declare const localSearchAdapter: SearchAdapter;
|
|
8
19
|
/**
|
|
9
20
|
* Resolve the configured search provider to an implementation available in
|
|
10
21
|
* the default theme. External indexes can be added later without changing
|
|
11
22
|
* the configuration contract or leaving the search dialog non-functional.
|
|
12
23
|
*/
|
|
13
24
|
export declare function resolveSearchProvider(search?: DocsConfig["search"]): ResolvedSearchProvider;
|
|
25
|
+
export declare function searchPages(provider: ResolvedSearchProvider, query: string, pages: PageData[]): PageData[] | Promise<PageData[]>;
|
package/dist/search/provider.js
CHANGED
|
@@ -1,13 +1,38 @@
|
|
|
1
|
+
export const LOCAL_SEARCH_PROVIDER = "local";
|
|
2
|
+
export const localSearchAdapter = {
|
|
3
|
+
name: LOCAL_SEARCH_PROVIDER,
|
|
4
|
+
search({ query, pages }) {
|
|
5
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
6
|
+
if (!normalizedQuery)
|
|
7
|
+
return pages;
|
|
8
|
+
return pages.filter((page) => [page.title, page.url, page.description]
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.some((value) => value.toLowerCase().includes(normalizedQuery)));
|
|
11
|
+
},
|
|
12
|
+
};
|
|
1
13
|
/**
|
|
2
14
|
* Resolve the configured search provider to an implementation available in
|
|
3
15
|
* the default theme. External indexes can be added later without changing
|
|
4
16
|
* the configuration contract or leaving the search dialog non-functional.
|
|
5
17
|
*/
|
|
6
18
|
export function resolveSearchProvider(search) {
|
|
7
|
-
const
|
|
19
|
+
const configuredProvider = search?.provider;
|
|
20
|
+
if (configuredProvider && typeof configuredProvider !== "string") {
|
|
21
|
+
return {
|
|
22
|
+
requested: configuredProvider.name,
|
|
23
|
+
active: configuredProvider.name,
|
|
24
|
+
fallback: false,
|
|
25
|
+
implementation: configuredProvider,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const requested = configuredProvider?.trim() || LOCAL_SEARCH_PROVIDER;
|
|
8
29
|
return {
|
|
9
30
|
requested,
|
|
10
|
-
active:
|
|
11
|
-
fallback: requested !==
|
|
31
|
+
active: LOCAL_SEARCH_PROVIDER,
|
|
32
|
+
fallback: requested !== LOCAL_SEARCH_PROVIDER,
|
|
33
|
+
implementation: localSearchAdapter,
|
|
12
34
|
};
|
|
13
35
|
}
|
|
36
|
+
export function searchPages(provider, query, pages) {
|
|
37
|
+
return provider.implementation.search({ query, pages });
|
|
38
|
+
}
|
package/dist/server/index.js
CHANGED
|
@@ -125,6 +125,10 @@ function getSharedConfig(options, isDev = false, isSSR = false) {
|
|
|
125
125
|
aliases.push({ find: "@/lib", replacement: libSource }, { find: "@/providers", replacement: providersSource }, { find: /^@\/components\/ui\/(.*)$/, replacement: path.join(componentsSrc, "$1") }, { find: /^@\/hooks\/(.*)$/, replacement: path.join(hooksSource, "$1") });
|
|
126
126
|
return {
|
|
127
127
|
root: clientDir,
|
|
128
|
+
// The consuming documentation project owns its public Vite environment
|
|
129
|
+
// variables (for example VITE_ALGOLIA_*). Vite's root is the packaged
|
|
130
|
+
// Folio client, so point env loading back at the consumer project.
|
|
131
|
+
envDir: root,
|
|
128
132
|
publicDir: fs.existsSync(publicDir) ? publicDir : path.join(clientDir, "public"),
|
|
129
133
|
resolve: {
|
|
130
134
|
alias: aliases,
|
|
@@ -36,6 +36,7 @@ export const DocsLayout = (props) => {
|
|
|
36
36
|
]);
|
|
37
37
|
const [searchOpen, setSearchOpen] = createSignal(false);
|
|
38
38
|
const pageClipboard = createClipboard();
|
|
39
|
+
const searchEnabled = () => local.config.search?.enabled !== false;
|
|
39
40
|
const searchProvider = () => resolveSearchProvider(local.config.search);
|
|
40
41
|
const currentUrl = () => local.currentPage?.url;
|
|
41
42
|
const landingPage = () => local.currentPage?.url === "/" && local.config.home?.layout === "landing";
|
|
@@ -144,7 +145,7 @@ export const DocsLayout = (props) => {
|
|
|
144
145
|
</Container>
|
|
145
146
|
</Show>
|
|
146
147
|
</Container>
|
|
147
|
-
<DocsSearchDialog open={searchOpen()} onOpenChange={setSearchOpen} pages={local.pages} provider={searchProvider().
|
|
148
|
+
<DocsSearchDialog open={searchOpen()} onOpenChange={setSearchOpen} pages={local.pages} provider={searchEnabled() ? searchProvider().implementation : undefined}/>
|
|
148
149
|
</SidebarInset>);
|
|
149
150
|
const landingContent = () => (<SidebarInset class={cn("min-w-0", local.class)} {...rest}>
|
|
150
151
|
<Container as="main" size="2xl" class="min-w-0 max-w-full flex-1 py-8 sm:py-12 lg:py-16">
|
|
@@ -162,7 +163,7 @@ export const DocsLayout = (props) => {
|
|
|
162
163
|
</Show>
|
|
163
164
|
</Container>
|
|
164
165
|
</Container>
|
|
165
|
-
<DocsSearchDialog open={searchOpen()} onOpenChange={setSearchOpen} pages={local.pages} provider={searchProvider().
|
|
166
|
+
<DocsSearchDialog open={searchOpen()} onOpenChange={setSearchOpen} pages={local.pages} provider={searchEnabled() ? searchProvider().implementation : undefined}/>
|
|
166
167
|
</SidebarInset>);
|
|
167
168
|
return (<SidebarProvider defaultOpen={true} class="min-h-screen w-full items-stretch">
|
|
168
169
|
<Show when={landingPage()} fallback={<Show when={sidebarLayout()} fallback={<div class="flex min-h-screen min-w-0 flex-1 flex-col">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/docs/src/themes/default/overlays/search-dialog.tsx
|
|
2
|
-
import { For, Show } from "solid-js";
|
|
2
|
+
import { createEffect, createSignal, For, Show } from "solid-js";
|
|
3
3
|
import { CommandDialog } from "@/components/ui/command";
|
|
4
4
|
import { CommandInput } from "@/components/ui/command";
|
|
5
5
|
import { CommandList } from "@/components/ui/command";
|
|
@@ -7,6 +7,7 @@ import { CommandEmpty } from "@/components/ui/command";
|
|
|
7
7
|
import { CommandGroup } from "@/components/ui/command";
|
|
8
8
|
import { CommandItem } from "@/components/ui/command";
|
|
9
9
|
import { FileText } from "lucide-solid";
|
|
10
|
+
import { resolveSearchProvider, searchPages } from "../../../search/provider.js";
|
|
10
11
|
export const DocsSearchDialog = (props) => {
|
|
11
12
|
const handleOpenChange = (open) => {
|
|
12
13
|
props.onOpenChange(open);
|
|
@@ -25,19 +26,33 @@ export const DocsSearchDialog = (props) => {
|
|
|
25
26
|
window.requestAnimationFrame(() => {
|
|
26
27
|
document.querySelector("#docs-search-input")?.focus();
|
|
27
28
|
});
|
|
28
|
-
}} enableHotkey={
|
|
29
|
+
}} enableHotkey={props.provider !== undefined}>
|
|
29
30
|
{({ search }) => {
|
|
30
|
-
const query = () => search().trim()
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const query = () => search().trim();
|
|
32
|
+
const resolvedProvider = () => resolveSearchProvider({ provider: props.provider });
|
|
33
|
+
const [filteredPages, setFilteredPages] = createSignal(props.pages || []);
|
|
34
|
+
const [searching, setSearching] = createSignal(false);
|
|
35
|
+
let requestId = 0;
|
|
36
|
+
createEffect(() => {
|
|
37
|
+
const currentRequest = ++requestId;
|
|
38
|
+
setSearching(true);
|
|
39
|
+
Promise.resolve(searchPages(resolvedProvider(), query(), props.pages || []))
|
|
40
|
+
.then((results) => {
|
|
41
|
+
if (currentRequest === requestId)
|
|
42
|
+
setFilteredPages(results);
|
|
43
|
+
})
|
|
44
|
+
.finally(() => {
|
|
45
|
+
if (currentRequest === requestId)
|
|
46
|
+
setSearching(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
34
49
|
return (<>
|
|
35
50
|
<CommandInput id="docs-search-input" placeholder="Search documentation..."/>
|
|
36
51
|
<CommandList>
|
|
37
|
-
<Show when={query().length > 0 && filteredPages().length === 0}>
|
|
52
|
+
<Show when={!searching() && query().length > 0 && filteredPages().length === 0}>
|
|
38
53
|
<CommandEmpty>No matching documents found.</CommandEmpty>
|
|
39
54
|
</Show>
|
|
40
|
-
<Show when={filteredPages().length > 0}>
|
|
55
|
+
<Show when={!searching() && filteredPages().length > 0}>
|
|
41
56
|
<CommandGroup heading="Pages">
|
|
42
57
|
<For each={filteredPages()}>
|
|
43
58
|
{(page) => (<CommandItem title={page.title} subtitle={page.url} description={page.description} icon={FileText} shouldFilter={false} onSelect={() => handleSelect(page.url)}/>)}
|
package/dist/themes/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Component, JSX, ParentComponent } from "solid-js";
|
|
2
2
|
import type { DocsConfig, NavItem, PageData, TocItem, SidebarItem } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SearchAdapter } from "../search/provider.js";
|
|
4
4
|
export type BreadcrumbItemData = {
|
|
5
5
|
title: string;
|
|
6
6
|
href?: string;
|
|
@@ -52,7 +52,7 @@ export interface DocsSearchDialogProps {
|
|
|
52
52
|
onOpenChange: (open: boolean) => void;
|
|
53
53
|
pages?: PageData[];
|
|
54
54
|
onSelectPage?: (url: string) => void;
|
|
55
|
-
provider?:
|
|
55
|
+
provider?: string | SearchAdapter;
|
|
56
56
|
}
|
|
57
57
|
export interface DocsLayoutProps {
|
|
58
58
|
config: DocsConfig;
|
package/dist/types.d.ts
CHANGED
|
@@ -126,6 +126,7 @@ export interface DocsConfig {
|
|
|
126
126
|
shiki?: ShikiConfig;
|
|
127
127
|
search?: {
|
|
128
128
|
enabled?: boolean;
|
|
129
|
-
provider
|
|
129
|
+
/** A provider name or a configured adapter instance. */
|
|
130
|
+
provider?: string | import("./search/provider.js").SearchAdapter;
|
|
130
131
|
};
|
|
131
132
|
}
|
|
@@ -97,7 +97,10 @@ export function MdxCode(props: HtmlProps<HTMLElement>) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function isPackageCommand(code: string, language: string) {
|
|
100
|
-
|
|
100
|
+
const packageCommand = /^(?:(?:bun|npm|pnpm|yarn)\s+(?:add|install|i|create|run)\s+|(?:bunx|npx|pnpm\s+dlx|yarn\s+dlx)\s+)/i;
|
|
101
|
+
return /^(bash|sh|shell|zsh)$/i.test(language)
|
|
102
|
+
&& !code.includes("\n")
|
|
103
|
+
&& packageCommand.test(code.trim());
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/** Preserve Shiki's server-rendered children while using Nikala's code chrome. */
|
|
@@ -42,6 +42,14 @@ function resolvePmCommand(manager: string, command: string): string {
|
|
|
42
42
|
const trimmed = command.trim();
|
|
43
43
|
const pm = manager.toLowerCase();
|
|
44
44
|
|
|
45
|
+
// 0. Package scripts (e.g. "bun run dev")
|
|
46
|
+
const runMatch = trimmed.match(/^(?:bun|npm|pnpm|yarn)\s+run\s+(.+)$/);
|
|
47
|
+
if (runMatch) {
|
|
48
|
+
const script = runMatch[1];
|
|
49
|
+
if (pm === "yarn") return `yarn ${script}`;
|
|
50
|
+
return `${pm} run ${script}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
// 1. "create" command
|
|
46
54
|
const createMatch = trimmed.match(/^(?:bun|npm|npx|pnpm|yarn|deno)?\s*create\s+(.*)$/);
|
|
47
55
|
if (createMatch) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const FOLIO_VERSION = "0.
|
|
1
|
+
export declare const FOLIO_VERSION = "0.14.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const FOLIO_VERSION = "0.
|
|
1
|
+
export const FOLIO_VERSION = "0.14.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nikala-ui/folio",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Zero-config, fast, and elegant documentation engine for SolidJS, built on Nikala UI and Tailwind CSS v4",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"types": "./dist/server/plugin.d.ts",
|
|
19
19
|
"import": "./dist/server/plugin.js"
|
|
20
20
|
},
|
|
21
|
+
"./config": {
|
|
22
|
+
"types": "./dist/config.d.ts",
|
|
23
|
+
"import": "./dist/config.js"
|
|
24
|
+
},
|
|
25
|
+
"./content": {
|
|
26
|
+
"types": "./dist/core/content-scanner.d.ts",
|
|
27
|
+
"import": "./dist/core/content-scanner.js"
|
|
28
|
+
},
|
|
21
29
|
"./theme": {
|
|
22
30
|
"types": "./dist/themes/default/index.d.ts",
|
|
23
31
|
"import": "./dist/themes/default/index.js"
|