@supatent/supatent-docs 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 (46) hide show
  1. package/dist/chunk-QVZFIUSH.js +13777 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.js +75 -0
  4. package/dist/next-config.d.ts +20 -0
  5. package/dist/next-config.js +305 -0
  6. package/dist/types-Cf4pRODK.d.ts +60 -0
  7. package/package.json +49 -0
  8. package/runtime/middleware.ts +52 -0
  9. package/runtime/src/app/[locale]/docs-internal/[[...slug]]/page.tsx +91 -0
  10. package/runtime/src/app/[locale]/docs-internal/ai/all/route.ts +52 -0
  11. package/runtime/src/app/[locale]/docs-internal/ai/index/route.ts +52 -0
  12. package/runtime/src/app/[locale]/docs-internal/markdown/[...slug]/route.ts +50 -0
  13. package/runtime/src/app/globals.css +1082 -0
  14. package/runtime/src/app/layout.tsx +37 -0
  15. package/runtime/src/app/page.tsx +26 -0
  16. package/runtime/src/components/code-group-enhancer.tsx +128 -0
  17. package/runtime/src/components/docs-shell.tsx +140 -0
  18. package/runtime/src/components/header-dropdown.tsx +138 -0
  19. package/runtime/src/components/icons.tsx +58 -0
  20. package/runtime/src/components/locale-switcher.tsx +97 -0
  21. package/runtime/src/components/mobile-docs-menu.tsx +208 -0
  22. package/runtime/src/components/site-header.tsx +44 -0
  23. package/runtime/src/components/site-search.tsx +358 -0
  24. package/runtime/src/components/theme-toggle.tsx +74 -0
  25. package/runtime/src/docs.config.ts +91 -0
  26. package/runtime/src/framework/config.ts +76 -0
  27. package/runtime/src/framework/errors.ts +34 -0
  28. package/runtime/src/framework/locales.ts +45 -0
  29. package/runtime/src/framework/markdown-search-text.ts +11 -0
  30. package/runtime/src/framework/navigation.ts +58 -0
  31. package/runtime/src/framework/next-config.ts +160 -0
  32. package/runtime/src/framework/rendering.ts +445 -0
  33. package/runtime/src/framework/repository.ts +255 -0
  34. package/runtime/src/framework/runtime-locales.ts +85 -0
  35. package/runtime/src/framework/search-index-types.ts +34 -0
  36. package/runtime/src/framework/search-index.ts +271 -0
  37. package/runtime/src/framework/service.ts +302 -0
  38. package/runtime/src/framework/settings.ts +43 -0
  39. package/runtime/src/framework/site-title.ts +54 -0
  40. package/runtime/src/framework/theme.ts +17 -0
  41. package/runtime/src/framework/types.ts +66 -0
  42. package/runtime/src/framework/url.ts +78 -0
  43. package/runtime/src/supatent/client.ts +2 -0
  44. package/src/index.ts +11 -0
  45. package/src/next-config.ts +5 -0
  46. package/src/next.ts +10 -0
@@ -0,0 +1,43 @@
1
+ import type { DocsSettings } from "./types";
2
+
3
+ const siteTitlePaths = [
4
+ "siteTitle",
5
+ "site-title",
6
+ "site_title",
7
+ "title",
8
+ "name",
9
+ "site.title",
10
+ "site.name",
11
+ ] as const;
12
+
13
+ function readValueAtPath(input: unknown, path: string): unknown {
14
+ const keys = path.split(".");
15
+ let current: unknown = input;
16
+
17
+ for (const key of keys) {
18
+ if (!current || typeof current !== "object") {
19
+ return null;
20
+ }
21
+
22
+ current = (current as Record<string, unknown>)[key];
23
+ }
24
+
25
+ return current;
26
+ }
27
+
28
+ export function resolveSiteTitleFromSettings(
29
+ settings: DocsSettings | null,
30
+ ): string | null {
31
+ if (!settings) {
32
+ return null;
33
+ }
34
+
35
+ for (const path of siteTitlePaths) {
36
+ const value = readValueAtPath(settings, path);
37
+ if (typeof value === "string" && value.trim()) {
38
+ return value.trim();
39
+ }
40
+ }
41
+
42
+ return null;
43
+ }
@@ -0,0 +1,54 @@
1
+ import { cache } from "react";
2
+ import { docsConfig } from "../docs.config";
3
+ import { resolveLocaleCandidates } from "./locales";
4
+ import { createSupatentDocsRepository } from "./repository";
5
+ import { getRuntimeLocales } from "./runtime-locales";
6
+ import { resolveSiteTitleFromSettings } from "./settings";
7
+
8
+ const getConfiguredSiteTitle = cache(async (requestedLocale: string): Promise<string | null> => {
9
+ const runtimeLocales = await getRuntimeLocales({
10
+ dataMode: docsConfig.supatent.dataMode,
11
+ });
12
+ const repository = createSupatentDocsRepository(docsConfig, {
13
+ dataMode: docsConfig.supatent.dataMode,
14
+ });
15
+ const localeConfig = {
16
+ defaultLocale: runtimeLocales.defaultLocale,
17
+ locales: runtimeLocales.locales,
18
+ fallbackMode: docsConfig.routing.fallbackMode,
19
+ };
20
+ const candidates = requestedLocale
21
+ ? resolveLocaleCandidates(requestedLocale, localeConfig)
22
+ : [localeConfig.defaultLocale];
23
+
24
+ let lastError: unknown = null;
25
+
26
+ for (const locale of candidates) {
27
+ try {
28
+ const settings = await repository.getSettings(locale);
29
+ const siteTitle = resolveSiteTitleFromSettings(settings);
30
+ if (siteTitle) {
31
+ return siteTitle;
32
+ }
33
+ } catch (error) {
34
+ lastError = error;
35
+ }
36
+ }
37
+
38
+ if (lastError) {
39
+ const reason = lastError instanceof Error
40
+ ? lastError.message
41
+ : "Unknown settings fetch failure";
42
+ console.warn(
43
+ `[supatent-docs] Settings fetch failed (${reason}). No site title resolved.`,
44
+ );
45
+ }
46
+
47
+ return null;
48
+ });
49
+
50
+ export async function getSiteTitle(
51
+ requestedLocale?: string | null,
52
+ ): Promise<string | null> {
53
+ return getConfiguredSiteTitle(requestedLocale?.trim() || "");
54
+ }
@@ -0,0 +1,17 @@
1
+ export const docsThemeTokens = {
2
+ background: "#fcf9f2",
3
+ foreground: "#1f1f1a",
4
+ mutedForeground: "#5a5a4e",
5
+ border: "#dad4c5",
6
+ accent: "#004e64",
7
+ accentForeground: "#f4f9fb",
8
+ navBackground: "#f4efe2",
9
+ codeBackground: "#ece6d7",
10
+ maxWidth: "1100px",
11
+ navWidth: "290px",
12
+ radius: "10px",
13
+ fontBody: "'IBM Plex Sans', system-ui, sans-serif",
14
+ fontHeading: "'Fraunces', Georgia, serif",
15
+ fontMono: "'IBM Plex Mono', ui-monospace, monospace",
16
+ } as const;
17
+
@@ -0,0 +1,66 @@
1
+ export type LocaleFallbackMode = "none" | "defaultLocale";
2
+ export type DocsDataMode = "published" | "draft";
3
+
4
+ export type DocsFrameworkConfig = {
5
+ supatent: {
6
+ baseUrl: string;
7
+ apiKey?: string;
8
+ dataMode: DocsDataMode;
9
+ projectSlug: string;
10
+ cache: {
11
+ maxAge: number;
12
+ staleWhileRevalidate: number;
13
+ };
14
+ };
15
+ schemas: {
16
+ settings: string;
17
+ page: string;
18
+ category: string;
19
+ };
20
+ routing: {
21
+ basePath: string;
22
+ defaultLocale: string;
23
+ locales: string[];
24
+ fallbackMode: LocaleFallbackMode;
25
+ };
26
+ };
27
+
28
+ export type DocsPage = {
29
+ slug: string;
30
+ title: string;
31
+ body: string;
32
+ category: string;
33
+ order: number;
34
+ locale: string;
35
+ };
36
+
37
+ export type DocsSettings = Record<string, unknown>;
38
+
39
+ export type DocsCategory = {
40
+ slug: string;
41
+ title: string;
42
+ order: number;
43
+ locale: string;
44
+ };
45
+
46
+ export type DocsNavNode = {
47
+ id: string;
48
+ title: string;
49
+ slug: string | null;
50
+ path: string | null;
51
+ order: number;
52
+ children: DocsNavNode[];
53
+ };
54
+
55
+ export type DocsPageResolution = {
56
+ page: DocsPage;
57
+ requestedLocale: string;
58
+ resolvedLocale: string;
59
+ usedFallback: boolean;
60
+ };
61
+
62
+ export type DocsLocaleRuntimeConfig = {
63
+ defaultLocale: string;
64
+ locales: string[];
65
+ fallbackMode: LocaleFallbackMode;
66
+ };
@@ -0,0 +1,78 @@
1
+ import type { DocsFrameworkConfig } from "./types";
2
+
3
+ export const INTERNAL_DOCS_SEGMENT = "docs-internal";
4
+
5
+ function trimSlashes(value: string): string {
6
+ return value.replace(/^\/+|\/+$/g, "");
7
+ }
8
+
9
+ function joinSegments(...segments: Array<string | undefined>): string {
10
+ const cleaned = segments
11
+ .filter((segment): segment is string => Boolean(segment))
12
+ .map(trimSlashes)
13
+ .filter(Boolean);
14
+
15
+ return `/${cleaned.join("/")}`;
16
+ }
17
+
18
+ export function normalizeSlug(slugSegments?: string[]): string {
19
+ if (!slugSegments || slugSegments.length === 0) {
20
+ return "";
21
+ }
22
+
23
+ return slugSegments.map(trimSlashes).filter(Boolean).join("/");
24
+ }
25
+
26
+ export function toDocsPagePath(
27
+ config: DocsFrameworkConfig,
28
+ locale: string,
29
+ slug = "",
30
+ ): string {
31
+ return joinSegments(locale, config.routing.basePath, slug);
32
+ }
33
+
34
+ export function toDocsMarkdownPath(
35
+ config: DocsFrameworkConfig,
36
+ locale: string,
37
+ slug: string,
38
+ ): string {
39
+ return joinSegments(locale, config.routing.basePath, slug, "markdown");
40
+ }
41
+
42
+ export function toDocsAiIndexPath(
43
+ config: DocsFrameworkConfig,
44
+ locale: string,
45
+ ): string {
46
+ return joinSegments(locale, config.routing.basePath, "ai", "index");
47
+ }
48
+
49
+ export function toDocsAiAllPath(config: DocsFrameworkConfig, locale: string): string {
50
+ return joinSegments(locale, config.routing.basePath, "ai", "all");
51
+ }
52
+
53
+ export function toInternalDocsPath(pathname: string, config: DocsFrameworkConfig): string | null {
54
+ const segments = pathname.split("/").filter(Boolean);
55
+ if (segments.length < 2) {
56
+ return null;
57
+ }
58
+
59
+ const [locale, ...rest] = segments;
60
+
61
+ const basePathSegments = config.routing.basePath.split("/").filter(Boolean);
62
+ const pathMatchesBase =
63
+ rest.length >= basePathSegments.length &&
64
+ basePathSegments.every((segment, index) => rest[index] === segment);
65
+
66
+ if (!pathMatchesBase) {
67
+ return null;
68
+ }
69
+
70
+ const tail = rest.slice(basePathSegments.length);
71
+
72
+ if (tail.length >= 2 && tail[tail.length - 1] === "markdown") {
73
+ const slug = tail.slice(0, -1).join("/");
74
+ return joinSegments(locale, INTERNAL_DOCS_SEGMENT, "markdown", slug);
75
+ }
76
+
77
+ return joinSegments(locale, INTERNAL_DOCS_SEGMENT, tail.join("/"));
78
+ }
@@ -0,0 +1,2 @@
1
+ export * from "@supatent/client";
2
+
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { defineDocsConfig } from "../runtime/src/framework/config";
2
+ export type {
3
+ DocsCategory,
4
+ DocsDataMode,
5
+ DocsFrameworkConfig,
6
+ DocsLocaleRuntimeConfig,
7
+ DocsNavNode,
8
+ DocsPage,
9
+ DocsPageResolution,
10
+ LocaleFallbackMode,
11
+ } from "../runtime/src/framework/types";
@@ -0,0 +1,5 @@
1
+ export {
2
+ withSupatentDocs,
3
+ type SupatentDocsNextConfigOptions,
4
+ type SupatentDocsSearchIndexOptions,
5
+ } from "../runtime/src/framework/next-config";
package/src/next.ts ADDED
@@ -0,0 +1,10 @@
1
+ export { metadata as docsMetadata } from "../runtime/src/app/layout";
2
+ export { default as DocsRootLayout } from "../runtime/src/app/layout";
3
+ export { default as DocsHomePage } from "../runtime/src/app/page";
4
+
5
+ export { default as DocsInternalPage } from "../runtime/src/app/[locale]/docs-internal/[[...slug]]/page";
6
+ export { GET as getDocsAiIndex } from "../runtime/src/app/[locale]/docs-internal/ai/index/route";
7
+ export { GET as getDocsAiAll } from "../runtime/src/app/[locale]/docs-internal/ai/all/route";
8
+ export { GET as getDocsMarkdownPage } from "../runtime/src/app/[locale]/docs-internal/markdown/[...slug]/route";
9
+
10
+ export { middleware as docsMiddleware } from "../runtime/middleware";