@xyd-js/apidocs-demo 0.0.1-build.73

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/app/const.ts ADDED
@@ -0,0 +1,2 @@
1
+ // TODO: IN THE FUTURE BETTER cuz should also work without prefix
2
+ export const DOCS_PREFIX = "/docs/api"
@@ -0,0 +1,52 @@
1
+ import { createContext, useContext, useState, useEffect } from 'react';
2
+ import type { Reference } from '@xyd-js/uniform';
3
+ import type { Settings } from '@xyd-js/core';
4
+ import type { FwSidebarItemProps } from '@xyd-js/framework/react';
5
+ import { SETTINGS } from './settings';
6
+
7
+ interface GlobalStateActionData {
8
+ references: Reference[];
9
+ settings: Settings
10
+ groups: FwSidebarItemProps[]
11
+ exampleType: "openapi" | "graphql"
12
+ }
13
+
14
+ // Create a context for the global state
15
+ export const GlobalStateContext = createContext<{
16
+ actionData: GlobalStateActionData | null;
17
+ setActionData: (data: GlobalStateActionData) => void;
18
+ }>({
19
+ actionData: null,
20
+ setActionData: () => { },
21
+ });
22
+
23
+ // Create a provider component
24
+ export function GlobalStateProvider({ children }: { children: React.ReactNode }) {
25
+ const [actionData, setActionData] = useState<any>({
26
+ references: [],
27
+ settings: SETTINGS,
28
+ groups: [],
29
+ exampleType: ""
30
+ });
31
+
32
+ const handleSetActionData = (data: any) => {
33
+ setActionData(data);
34
+ };
35
+
36
+ return (
37
+ <GlobalStateContext.Provider value={{ actionData, setActionData: handleSetActionData }}>
38
+ {children}
39
+ </GlobalStateContext.Provider>
40
+ );
41
+ }
42
+
43
+ // Custom hook for using the global state
44
+ export function useGlobalState() {
45
+ const context = useContext(GlobalStateContext);
46
+ if (context === undefined) {
47
+ throw new Error('useGlobalState must be used within a GlobalStateProvider');
48
+ }
49
+ return context;
50
+ }
51
+
52
+ export const UrlContext = createContext({})
package/app/index.css ADDED
@@ -0,0 +1,58 @@
1
+ :root {
2
+ --xyd-nav-height: 0px !important;
3
+ }
4
+ [data-color-scheme="dark"] {
5
+ --color-text-default: var(--black);
6
+ }
7
+ /* System Dark Mode Support */
8
+ @media (prefers-color-scheme: dark) {
9
+ :root:not([data-color-scheme="light"]):not([data-color-scheme="dark"]) {
10
+ --color-text-default: var(--black);
11
+ }
12
+ }
13
+
14
+ /* FIX IMPORANT */
15
+ xyd-layout-primary {
16
+ [part=sidebar], atlas-apiref-samples {
17
+ top: 50px !important;
18
+ }
19
+ }
20
+
21
+
22
+ xyd-banner {
23
+ background: none;
24
+ border-bottom: 1px solid var(--dark32);
25
+ justify-content: normal;
26
+ }
27
+
28
+ xyd-layout-primary > header {
29
+ display: none
30
+ }
31
+ xyd-layout-primary > main {
32
+ top: 100px
33
+ }
34
+
35
+ .banner-container {
36
+ display: flex;
37
+ flex-direction: row;
38
+ justify-content: space-between;
39
+ align-items: center;
40
+ width: 100%;
41
+ position: fixed;
42
+ top: 0;
43
+ z-index: 5;
44
+ background: var(--white);
45
+ border-bottom: 1px solid var(--dark32);
46
+ padding: 15px;
47
+
48
+ .banner-left {
49
+ display: flex;
50
+ align-items: center;
51
+ gap: 10px;
52
+ padding-left: 20px;
53
+ }
54
+
55
+ .banner-right {
56
+ padding-right: 20px;
57
+ }
58
+ }
package/app/root.tsx ADDED
@@ -0,0 +1,106 @@
1
+ import {
2
+ isRouteErrorResponse,
3
+ Links,
4
+ Meta,
5
+ Outlet,
6
+ Scripts,
7
+ ScrollRestoration,
8
+ } from "react-router";
9
+ import React, { } from 'react';
10
+
11
+ import { GlobalStateProvider } from './context';
12
+ import type { Route } from "./+types/root";
13
+ import { SETTINGS } from "./settings";
14
+
15
+ import gestaltCss from 'gestalt/dist/gestalt.css?url';
16
+ import poetryCss from '@xyd-js/theme-poetry/index.css?url';
17
+ import openerCss from '@xyd-js/theme-opener/index.css?url';
18
+ import cosmoCss from '@xyd-js/theme-cosmo/index.css?url';
19
+ import picassoCss from '@xyd-js/theme-picasso/index.css?url';
20
+ import gustoCss from '@xyd-js/theme-gusto/index.css?url';
21
+ import solarCss from '@xyd-js/theme-solar/index.css?url';
22
+
23
+ import indexCss from './index.css?url';
24
+
25
+ export const links: Route.LinksFunction = () => {
26
+ const links = [
27
+ { rel: "stylesheet", href: gestaltCss },
28
+ { rel: "stylesheet", href: indexCss },
29
+ ]
30
+
31
+ switch (SETTINGS?.theme?.name) {
32
+ case "poetry":
33
+ links.push({ rel: "stylesheet", href: poetryCss });
34
+ break;
35
+ case "opener":
36
+ links.push({ rel: "stylesheet", href: openerCss });
37
+ break;
38
+ case "cosmo":
39
+ links.push({ rel: "stylesheet", href: cosmoCss });
40
+ break;
41
+ case "picasso":
42
+ links.push({ rel: "stylesheet", href: picassoCss, "data-xyd-theme-default": "true" });
43
+ case "gusto":
44
+ links.push({ rel: "stylesheet", href: gustoCss });
45
+ break;
46
+ case "solar":
47
+ links.push({ rel: "stylesheet", href: solarCss });
48
+ break;
49
+ }
50
+
51
+ return links;
52
+ }
53
+
54
+ export function Layout({ children }: { children: React.ReactNode }) {
55
+ return (
56
+ <html lang="en">
57
+ <head>
58
+ <meta charSet="utf-8" />
59
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
60
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
61
+ <Meta />
62
+ <Links />
63
+ </head>
64
+ <body>
65
+ <GlobalStateProvider>
66
+ {children}
67
+ <ScrollRestoration />
68
+ <Scripts />
69
+ </GlobalStateProvider>
70
+ </body>
71
+ </html>
72
+ );
73
+ }
74
+
75
+ export default function App() {
76
+ return <Outlet />;
77
+ }
78
+
79
+ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
80
+ let message = "Oops!";
81
+ let details = "An unexpected error occurred.";
82
+ let stack: string | undefined;
83
+
84
+ if (isRouteErrorResponse(error)) {
85
+ message = error.status === 404 ? "404" : "Error";
86
+ details =
87
+ error.status === 404
88
+ ? "The requested page could not be found."
89
+ : error.statusText || details;
90
+ } else if (import.meta.env.DEV && error && error instanceof Error) {
91
+ details = error.message;
92
+ stack = error.stack;
93
+ }
94
+
95
+ return (
96
+ <main className="pt-16 p-4 container mx-auto">
97
+ <h1>{message}</h1>
98
+ <p>{details}</p>
99
+ {stack && (
100
+ <pre className="w-full p-4 overflow-x-auto">
101
+ <code>{stack}</code>
102
+ </pre>
103
+ )}
104
+ </main>
105
+ );
106
+ }