@xyd-js/apidocs-demo 0.0.0-build

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.
@@ -0,0 +1,80 @@
1
+ import { useLocation, useNavigate, useNavigation } from "react-router";
2
+ import { useContext, useEffect, useMemo, memo } from "react";
3
+
4
+ import { Atlas } from "@xyd-js/atlas";
5
+
6
+ import { UrlContext, useGlobalState } from "~/context";
7
+ import { DOCS_PREFIX } from "~/const";
8
+ import { Spinner } from "gestalt";
9
+
10
+ export default function Url() {
11
+ const { actionData: globalActionData } = useGlobalState();
12
+ const location = useLocation()
13
+
14
+ if (!globalActionData?.references?.length) {
15
+ return null
16
+ }
17
+
18
+ const findRef = globalActionData?.references?.find(ref => {
19
+ let canonical = ref.canonical.startsWith("/") ? ref.canonical : `/${ref.canonical}`
20
+ if (canonical.endsWith("/")) {
21
+ canonical = canonical.slice(0, -1)
22
+ }
23
+ canonical = canonical.startsWith(DOCS_PREFIX) ? canonical : `${DOCS_PREFIX}${canonical}`
24
+
25
+ return canonical === location.pathname
26
+ })
27
+
28
+ if (!findRef) {
29
+ return null
30
+ }
31
+
32
+ const references = [findRef]
33
+
34
+ return <AtlasContent canonical={findRef.canonical} references={references} />
35
+ }
36
+
37
+ const AtlasContent = memo(({ canonical, references }: { canonical: string, references: any[] }) => {
38
+ const { BaseThemePage } = useContext(UrlContext)
39
+
40
+ return (
41
+ <BaseThemePage>
42
+ <Loader/>
43
+ <Atlas
44
+ kind="primary"
45
+ references={references}
46
+ />
47
+ </BaseThemePage>
48
+ )
49
+ }, (prevProps, nextProps) => prevProps.canonical === nextProps.canonical)
50
+
51
+
52
+ function Loader() {
53
+ const navigation = useNavigation()
54
+
55
+ const loading = navigation.state === "loading"
56
+
57
+ if (!loading) {
58
+ return null
59
+ }
60
+ return <div style={{
61
+ position: "absolute",
62
+ top: 0,
63
+ left: 0,
64
+ right: 0,
65
+ bottom: 0,
66
+ width: "100%",
67
+ height: "100%",
68
+ display: "flex",
69
+ justifyContent: "center",
70
+ alignItems: "center",
71
+ zIndex: 1000,
72
+ background: "var(--white)"
73
+ }}>
74
+ <Spinner
75
+ accessibilityLabel="Loading..."
76
+ label="Loading..."
77
+ show={true}
78
+ />
79
+ </div>
80
+ }
package/app/routes.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { type RouteConfig, index, layout, route } from "@react-router/dev/routes";
2
+
3
+ export default [
4
+ // route("", "./routes/layout.tsx", [
5
+ // route("*", "./routes/url.tsx"),
6
+ // ]),
7
+ index("./routes/layout.tsx", {id: "index"}),
8
+ layout("./routes/layout.tsx", [
9
+ route("/docs/*", "./routes/url.tsx"),
10
+ ]),
11
+ route("api/try", "./api/try.ts"),
12
+ ] satisfies RouteConfig;
@@ -0,0 +1,47 @@
1
+ export const SETTINGS = Object.freeze({
2
+ "theme": {
3
+ "name": "picasso",
4
+ "icons": {
5
+ "library": [
6
+ {
7
+ "name": "lucide",
8
+ "default": true
9
+ },
10
+ "./icons/iconify.json"
11
+ ]
12
+ }
13
+ },
14
+ "integrations": {
15
+ "search": {
16
+ "orama": true
17
+ },
18
+ "apps": {
19
+ "githubStar": {
20
+ "title": "Star",
21
+ "label": "Show your support! Star us on GitHub ⭐️",
22
+ "href": "https://github.com/livesession/xyd",
23
+ "dataIcon": "octicon-star",
24
+ "dataSize": "large",
25
+ "dataShowCount": true,
26
+ "ariaLabel": "Star livesession/xyd on GitHub"
27
+ }
28
+ }
29
+ },
30
+ "navigation": {
31
+ "header": [],
32
+ "subheader": [],
33
+ "sidebar": [
34
+ {
35
+ "route": "/docs/api",
36
+ "pages": [
37
+ {
38
+ "group": "Endpoints",
39
+ "pages": [
40
+
41
+ ]
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ }
47
+ })
@@ -0,0 +1,123 @@
1
+ import { mapSettingsToProps } from "@xyd-js/framework/hydration"
2
+ import uniform, { pluginNavigation, type OpenAPIReferenceContext, type Reference } from "@xyd-js/uniform"
3
+ import { gqlSchemaToReferences } from "@xyd-js/gql"
4
+ import { deferencedOpenAPI, oapSchemaToReferences } from "@xyd-js/openapi"
5
+
6
+ import { SETTINGS } from "../settings"
7
+ import { uniformOpenAIMeta } from "../api/pluginOasOpenAPI";
8
+
9
+ export async function toUniform(
10
+ prefix: string,
11
+ example: string,
12
+ type: string,
13
+ value: string,
14
+ currentSettings?: any
15
+ ) {
16
+ let references: Reference[] = []
17
+
18
+ if (!type) {
19
+ const extension = example.split(".").pop()
20
+ if (extension === "json" || extension === "yaml" || extension === "yml") {
21
+ type = "openapi"
22
+ } else if (extension === "graphql" || extension === "gql" || extension === "gqls" || extension === "graphqls") {
23
+ type = "graphql"
24
+ } else if (example.startsWith('http://') || example.startsWith('https://')) {
25
+ try {
26
+ const response = await fetch(example)
27
+ const contentType = response.headers.get('content-type')
28
+
29
+ if (contentType?.includes('application/json') || contentType?.includes('text/json')) {
30
+ type = "openapi"
31
+ } else if (contentType?.includes('text/yaml') || contentType?.includes('application/x-yaml')) {
32
+ type = "openapi"
33
+ } else if (contentType?.includes('text/plain')) {
34
+ // For plain text, we might need to check the content itself
35
+ const text = await response.text()
36
+ if (text.trim().startsWith('{') || text.trim().startsWith('[')) {
37
+ type = "openapi"
38
+ } else if (text.includes('---') || text.includes('yaml')) {
39
+ type = "openapi"
40
+ }
41
+ }
42
+ } catch (error) {
43
+ console.error('Error fetching URL:', error)
44
+ }
45
+ }
46
+ }
47
+
48
+ switch (type) {
49
+ case "openapi": {
50
+ const openApiSpec = await deferencedOpenAPI(example as string)
51
+ references = await oapSchemaToReferences(openApiSpec)
52
+ break
53
+ }
54
+
55
+ case "graphql": {
56
+ references = await gqlSchemaToReferences(example as string)
57
+ }
58
+ }
59
+
60
+ const uniformPlugins = [
61
+ pluginNavigation(JSON.parse(JSON.stringify(SETTINGS)) as any, {
62
+ urlPrefix: prefix
63
+ }),
64
+ ]
65
+
66
+ if (value === "openai") {
67
+ uniformPlugins.push(uniformOpenAIMeta)
68
+ }
69
+
70
+ const uniformData = await uniform(references || [], {
71
+ plugins: uniformPlugins,
72
+ })
73
+
74
+ if (uniformData?.references) {
75
+ references = uniformData.references
76
+ }
77
+
78
+ const settings = JSON.parse(JSON.stringify(currentSettings || SETTINGS))
79
+ const apisidebar = settings?.navigation?.sidebar.find(sidebar => sidebar.route === prefix) || null
80
+
81
+ if (uniformData?.out?.sidebar?.length && apisidebar?.pages) {
82
+ apisidebar.pages[0].pages.push(...uniformData?.out?.sidebar || [])
83
+ }
84
+
85
+ const frontmatter = uniformData?.out?.pageFrontMatter || {}
86
+
87
+ for (const ref of references) {
88
+ const frontmatter = uniformData?.out?.pageFrontMatter || {}
89
+ let canonical = ref.canonical
90
+ canonical = canonical.startsWith("/") ? canonical : `/${canonical}`
91
+ if (canonical.endsWith("/")) {
92
+ canonical = canonical.slice(0, -1)
93
+ }
94
+
95
+ const meta = frontmatter[`${prefix}${canonical}`] || {}
96
+ if (!meta) {
97
+ continue
98
+ }
99
+
100
+ const ctx = ref.context as OpenAPIReferenceContext
101
+
102
+ if (ctx.method && ctx.path) {
103
+ meta.openapi = `#${ctx.method?.toUpperCase()} ${ctx.path}`
104
+ }
105
+ }
106
+
107
+ const props = await mapSettingsToProps(
108
+ settings,
109
+ {},
110
+ prefix + (references?.[0]?.canonical || ""),
111
+ frontmatter
112
+ )
113
+
114
+ return {
115
+ groups: props?.groups || [],
116
+ settings,
117
+ example,
118
+ references,
119
+ sidebar: uniformData?.out?.sidebar || [],
120
+ pageFrontMatter: uniformData?.out?.pageFrontMatter || {},
121
+ exampleType: type
122
+ }
123
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@xyd-js/apidocs-demo",
3
+ "type": "module",
4
+ "version": "0.0.0-build+6952c2c-20250813013245",
5
+ "dependencies": {
6
+ "@netlify/vite-plugin-react-router": "^1.0.1",
7
+ "@primer/primitives": "^10.7.0",
8
+ "@primer/react": "^37.26.0",
9
+ "@react-router/node": "^7.7.1",
10
+ "@react-router/serve": "^7.7.1",
11
+ "gestalt": "^177.0.0",
12
+ "isbot": "^5.1.27",
13
+ "react": "^19.1.0",
14
+ "react-dom": "^19.1.0",
15
+ "react-router": "^7.7.1",
16
+ "styled-components": "^6.1.18",
17
+ "@xyd-js/components": "0.0.0-build+6952c2c-20250813013245",
18
+ "@xyd-js/atlas": "0.0.0-build+6952c2c-20250813013245",
19
+ "@xyd-js/core": "0.0.0-build+6952c2c-20250813013245",
20
+ "@xyd-js/framework": "0.0.0-build+6952c2c-20250813013245",
21
+ "@xyd-js/gql": "0.0.0-build+6952c2c-20250813013245",
22
+ "@xyd-js/openapi": "0.0.0-build+6952c2c-20250813013245",
23
+ "@xyd-js/theme-opener": "0.0.0-build+6952c2c-20250813013245",
24
+ "@xyd-js/theme-cosmo": "0.0.0-build+6952c2c-20250813013245",
25
+ "@xyd-js/theme-poetry": "0.0.0-build+6952c2c-20250813013245",
26
+ "@xyd-js/theme-picasso": "0.0.0-build+6952c2c-20250813013245",
27
+ "@xyd-js/theme-gusto": "0.0.0-build+6952c2c-20250813013245",
28
+ "@xyd-js/theme-solar": "0.0.0-build+6952c2c-20250813013245",
29
+ "@xyd-js/themes": "0.0.0-build+6952c2c-20250813013245",
30
+ "@xyd-js/ui": "0.0.0-build+6952c2c-20250813013245",
31
+ "@xyd-js/uniform": "0.0.0-build+6952c2c-20250813013245"
32
+ },
33
+ "devDependencies": {
34
+ "@react-router/dev": "^7.7.1",
35
+ "@tailwindcss/vite": "^4.1.4",
36
+ "@types/node": "^20",
37
+ "@types/react": "^19.1.2",
38
+ "@types/react-dom": "^19.1.2",
39
+ "tailwindcss": "^4.1.4",
40
+ "typescript": "^5.8.3",
41
+ "vite": "^6.3.3",
42
+ "vite-tsconfig-paths": "^5.1.4"
43
+ },
44
+ "scripts": {
45
+ "build": "react-router build",
46
+ "dev": "react-router dev",
47
+ "start": "react-router-serve ./build/server/index.js",
48
+ "typecheck": "react-router typegen && tsc"
49
+ }
50
+ }
@@ -0,0 +1,10 @@
1
+ <svg width="64" height="18" viewBox="0 0 64 18" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_3_18)">
3
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M12.9447 14.7921H10.6636L14.2428 9.73069L10.8861 4.9901H13.1857L14.9846 7.69901C15.0712 7.84158 15.1577 7.99307 15.2443 8.15347C15.2649 8.1918 15.2854 8.23023 15.3057 8.26877C15.3598 8.37166 15.4048 8.46149 15.4407 8.53824C15.4432 8.54364 15.4458 8.54904 15.4483 8.55446C15.4611 8.51802 15.4751 8.482 15.4904 8.44646C15.5265 8.36139 15.5743 8.26372 15.6337 8.15347C15.7203 7.99307 15.8068 7.84158 15.8934 7.69901L17.6923 4.9901H19.9919L16.6352 9.74852L20.1959 14.7921H17.8963L15.9119 11.8515C15.8254 11.7089 15.7388 11.5485 15.6523 11.3703C15.6317 11.328 15.6113 11.2857 15.5909 11.2434C15.551 11.1606 15.516 11.0873 15.4861 11.0237C15.4734 10.9967 15.4608 10.9696 15.4483 10.9426C15.3988 11.0495 15.3277 11.1921 15.235 11.3703C15.1851 11.4666 15.1319 11.5613 15.0755 11.6542C15.0349 11.7212 14.9922 11.7869 14.9476 11.8515L12.9447 14.7921ZM26.2973 18H24.1831L25.6482 14.2218L21.8464 4.9901H24.0533L26.186 10.5149C26.2523 10.6968 26.3186 10.9065 26.3848 11.1441C26.4058 11.2194 26.426 11.2947 26.4457 11.3703C26.5322 11.703 26.6064 11.9762 26.6682 12.1901C26.7125 11.9988 26.7716 11.76 26.8455 11.4737C26.8544 11.4392 26.8633 11.4047 26.8722 11.3703C26.9588 11.0376 27.0453 10.7525 27.1318 10.5149L29.1347 4.9901H31.2675L26.2973 18ZM33.5671 11.2812V8.51881C33.5671 8.5099 33.5671 8.50099 33.5671 8.49208C33.5713 7.51129 33.8055 6.70741 34.2698 6.08044C34.3394 5.98635 34.4144 5.89603 34.4943 5.8099C35.1125 5.14455 35.9347 4.81188 36.9609 4.81188C37.2432 4.80978 37.5248 4.83873 37.8002 4.89814C38.2353 4.98873 38.637 5.18972 38.9638 5.4802C39.4583 5.92574 39.7056 6.53465 39.7056 7.30693L39.279 6.86139H39.7427L39.687 4.5802V1.78218H41.6899V14.7921H39.7056V12.9208H39.279L39.7056 12.4752C39.7079 12.7346 39.6757 12.9931 39.6097 13.2446C39.5048 13.6495 39.2805 14.0166 38.9638 14.302C38.637 14.5925 38.2353 14.7935 37.8002 14.884C37.5248 14.9435 37.2432 14.9724 36.9609 14.9703C36.5745 14.9741 36.19 14.9196 35.8213 14.8087C35.3085 14.6502 34.8499 14.3611 34.4943 13.9723C33.8762 13.3069 33.5671 12.4099 33.5671 11.2812ZM2.07708 16.7525H0L6.52796 0H8.60504L2.07708 16.7525ZM64 9.92673L55.8771 13.7228V11.905L61.4222 9.35644C61.5629 9.29538 61.7054 9.23815 61.8495 9.18481C61.9412 9.15093 62.0337 9.11902 62.1269 9.08911C62.3475 9.01842 62.5134 8.97113 62.6247 8.94725C62.6257 8.94701 62.6267 8.94677 62.6276 8.94653C62.5884 8.93886 62.5495 8.93007 62.5108 8.92016C62.4265 8.89877 62.3263 8.86931 62.2102 8.83176C62.1731 8.81976 62.136 8.80752 62.0991 8.79505C61.8704 8.71782 61.6447 8.62574 61.4222 8.51881L55.8771 5.9703V4.11683L64 7.91287V9.92673ZM39.687 11.1743V8.60792C39.6886 8.39594 39.6672 8.18438 39.6231 7.97667C39.5654 7.71481 39.4687 7.48414 39.3328 7.28465C39.2758 7.20072 39.2112 7.12171 39.14 7.04852C38.8659 6.76894 38.503 6.58461 38.1083 6.52438C37.956 6.49891 37.8016 6.48645 37.6471 6.48713C37.4323 6.48547 37.218 6.50802 37.0087 6.55432C36.6672 6.62705 36.3545 6.79238 36.1078 7.03069C35.9021 7.23549 35.7516 7.48556 35.6696 7.75907C35.6117 7.94145 35.5751 8.14248 35.5598 8.36216C35.5541 8.44397 35.5514 8.52593 35.5514 8.60792V11.1743C35.55 11.3795 35.5691 11.5844 35.6086 11.7861C35.6563 12.0212 35.734 12.2299 35.8419 12.4122C35.9147 12.5359 36.0041 12.65 36.1078 12.7515C36.3578 12.9928 36.6752 13.1594 37.0217 13.2309C37.2269 13.2751 37.4367 13.2966 37.6471 13.2951C37.8632 13.2969 38.0786 13.2714 38.2878 13.2193C38.6141 13.1386 38.9098 12.9701 39.14 12.7337C39.4759 12.389 39.6571 11.9209 39.6837 11.3295C39.686 11.2778 39.6871 11.226 39.687 11.1743Z" fill="black" stroke="black" stroke-width="0.944882" stroke-linecap="round"/>
4
+ </g>
5
+ <defs>
6
+ <clipPath id="clip0_3_18">
7
+ <rect width="64" height="18" fill="white"/>
8
+ </clipPath>
9
+ </defs>
10
+ </svg>
@@ -0,0 +1,7 @@
1
+ import type { Config } from "@react-router/dev/config";
2
+
3
+ export default {
4
+ // Config options...
5
+ // Server-side render by default, to enable SPA mode set this to `false`
6
+ ssr: true,
7
+ } satisfies Config;
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "include": [
3
+ "**/*",
4
+ "**/.server/**/*",
5
+ "**/.client/**/*",
6
+ ".react-router/types/**/*"
7
+ ],
8
+ "compilerOptions": {
9
+ "lib": ["DOM", "DOM.Iterable", "ES2022"],
10
+ "types": ["node", "vite/client"],
11
+ "target": "ES2022",
12
+ "module": "ES2022",
13
+ "moduleResolution": "bundler",
14
+ "jsx": "react-jsx",
15
+ "rootDirs": [".", "./.react-router/types"],
16
+ "baseUrl": ".",
17
+ "paths": {
18
+ "~/*": ["./app/*"]
19
+ },
20
+ "esModuleInterop": true,
21
+ "verbatimModuleSyntax": true,
22
+ "noEmit": true,
23
+ "resolveJsonModule": true,
24
+ "skipLibCheck": true,
25
+ "strict": true
26
+ }
27
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import path from "node:path";
2
+
3
+ import { reactRouter } from "@react-router/dev/vite";
4
+ import { defineConfig, PluginOption as VitePluginOption } from "vite";
5
+ // import { createServer,, Plugin as VitePlugin } from "vite";
6
+ import tsconfigPaths from "vite-tsconfig-paths";
7
+ import netlifyPlugin from '@netlify/vite-plugin-react-router'
8
+
9
+ export default defineConfig({
10
+ plugins: [
11
+ reactRouter(),
12
+ tsconfigPaths(),
13
+ virtualComponentsPlugin(),
14
+ netlifyPlugin()
15
+ ],
16
+ ssr: {
17
+ external: ["@xyd-js/framework/hydration", "fs"]
18
+ }
19
+ });
20
+
21
+
22
+ export function virtualComponentsPlugin(): VitePluginOption {
23
+ return {
24
+ name: 'xyd-plugin-virtual-components',
25
+ enforce: 'pre',
26
+ config: () => {
27
+ const componentsDist = path.resolve(".", "./node_modules/@xyd-js/components/dist")
28
+
29
+ return {
30
+ resolve: {
31
+ alias: {
32
+ // TODO: type-safe virtual-components
33
+ 'virtual-component:Search': path.resolve(componentsDist, "system.js")
34
+ }
35
+ }
36
+ }
37
+ },
38
+ }
39
+ }