polen 0.0.2 → 0.0.4
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/build/_exports.d.ts +1 -0
- package/build/_exports.js +1 -0
- package/build/_namespace.d.ts +1 -0
- package/build/_namespace.js +1 -0
- package/build/app-template/components/ArgumentAnnotation.d.ts +9 -0
- package/build/app-template/components/ArgumentAnnotation.jsx +15 -0
- package/build/app-template/components/ArgumentList.d.ts +6 -0
- package/build/app-template/components/ArgumentList.jsx +15 -0
- package/build/app-template/components/ArgumentListAnnotation.d.ts +6 -0
- package/build/app-template/components/ArgumentListAnnotation.jsx +22 -0
- package/build/app-template/components/ColumnView.d.ts +6 -0
- package/build/app-template/components/ColumnView.jsx +26 -0
- package/build/app-template/components/DeprecationReason.d.ts +5 -0
- package/build/app-template/components/DeprecationReason.jsx +9 -0
- package/build/app-template/components/Description.d.ts +6 -0
- package/build/app-template/components/Description.jsx +9 -0
- package/build/app-template/components/Field.d.ts +7 -0
- package/build/app-template/components/Field.jsx +19 -0
- package/build/app-template/components/FieldList.d.ts +6 -0
- package/build/app-template/components/FieldList.jsx +13 -0
- package/build/app-template/components/FieldListSection.d.ts +6 -0
- package/build/app-template/components/FieldListSection.jsx +14 -0
- package/build/app-template/components/Link.d.ts +3 -0
- package/build/app-template/components/Link.jsx +5 -0
- package/build/app-template/components/Markdown.d.ts +4 -0
- package/build/app-template/components/Markdown.jsx +13 -0
- package/build/app-template/components/NamedType.d.ts +6 -0
- package/build/app-template/components/NamedType.jsx +15 -0
- package/build/app-template/components/RadixLink.d.ts +1 -0
- package/build/app-template/components/RadixLink.jsx +1 -0
- package/build/app-template/components/TypeAnnotation.d.ts +9 -0
- package/build/app-template/components/TypeAnnotation.jsx +42 -0
- package/build/app-template/components/TypeFieldsLinkList.d.ts +6 -0
- package/build/app-template/components/TypeFieldsLinkList.jsx +16 -0
- package/build/app-template/entry.client.d.ts +1 -0
- package/build/app-template/entry.client.jsx +22 -0
- package/build/app-template/entry.server.d.ts +3 -0
- package/build/app-template/entry.server.jsx +96 -0
- package/build/app-template/routes/index.d.ts +1 -0
- package/build/app-template/routes/index.jsx +6 -0
- package/build/app-template/routes/reference.$type.$field.d.ts +4 -0
- package/build/app-template/routes/reference.$type.$field.jsx +24 -0
- package/build/app-template/routes/reference.$type.d.ts +4 -0
- package/build/app-template/routes/reference.$type.jsx +18 -0
- package/build/app-template/routes/reference.d.ts +12 -0
- package/build/app-template/routes/reference.jsx +34 -0
- package/build/app-template/routes/root.d.ts +17 -0
- package/build/app-template/routes/root.jsx +33 -0
- package/build/app-template/routes.d.ts +2 -0
- package/build/app-template/routes.jsx +4 -0
- package/build/lib/code-builder/_exports.d.ts +7 -0
- package/build/lib/code-builder/_exports.js +11 -0
- package/build/lib/code-builder/_namespace.d.ts +1 -0
- package/build/lib/code-builder/_namespace.js +1 -0
- package/build/lib/debug/_namespace.d.ts +1 -0
- package/build/lib/debug/_namespace.js +1 -0
- package/build/lib/debug/debug.d.ts +4 -0
- package/build/lib/debug/debug.js +37 -0
- package/build/lib/fs/_namespace.d.ts +1 -0
- package/build/lib/fs/_namespace.js +1 -0
- package/build/lib/fs/main.d.ts +3 -0
- package/build/lib/fs/main.js +17 -0
- package/build/lib/grafaid/helpers.d.ts +62 -0
- package/build/lib/grafaid/helpers.js +140 -0
- package/build/lib/grafaid/index.d.ts +7 -0
- package/build/lib/grafaid/index.js +9 -0
- package/build/lib/hono/_exports.d.ts +2 -0
- package/build/lib/hono/_exports.js +2 -0
- package/build/lib/hono/_namespace.d.ts +1 -0
- package/build/lib/hono/_namespace.js +1 -0
- package/build/lib/hono/ssg.d.ts +1 -0
- package/build/lib/hono/ssg.js +1 -0
- package/build/lib/path/_namespace.d.ts +1 -0
- package/build/lib/path/_namespace.js +1 -0
- package/build/lib/path/main.d.ts +9 -0
- package/build/lib/path/main.js +14 -0
- package/build/lib/prelude/main.d.ts +3 -0
- package/build/lib/prelude/main.js +3 -0
- package/build/lib/react/_namespace.d.ts +2 -0
- package/build/lib/react/_namespace.js +2 -0
- package/build/lib/react-dom-client/_namespace.d.ts +2 -0
- package/build/lib/react-dom-client/_namespace.js +2 -0
- package/build/lib/react-dom-server/_namespace.d.ts +2 -0
- package/build/lib/react-dom-server/_namespace.js +2 -0
- package/build/lib/react-router/_namespace.d.ts +1 -0
- package/build/lib/react-router/_namespace.js +1 -0
- package/build/lib/react-router-helpers.d.ts +4 -0
- package/build/lib/react-router-helpers.js +13 -0
- package/build/lib/rollup/_namespace.d.ts +1 -0
- package/build/lib/rollup/_namespace.js +1 -0
- package/build/lib/vite/_exports.d.ts +21 -0
- package/build/lib/vite/_exports.js +18 -0
- package/build/lib/vite/_namespace.d.ts +1 -0
- package/build/lib/vite/_namespace.js +1 -0
- package/build/lib/vite/virtual-identifier.d.ts +21 -0
- package/build/lib/vite/virtual-identifier.js +94 -0
- package/build/lib/vite-plugins/_exports.d.ts +2 -0
- package/build/lib/vite-plugins/_exports.js +2 -0
- package/build/lib/vite-plugins/_namespace.d.ts +4 -0
- package/build/lib/vite-plugins/_namespace.js +4 -0
- package/build/lib/vite-plugins/build-logger.d.ts +2 -0
- package/build/lib/vite-plugins/build-logger.js +30 -0
- package/build/lib/vite-plugins/output-logger.d.ts +2 -0
- package/build/lib/vite-plugins/output-logger.js +12 -0
- package/build/vite-plugin/_exports.d.ts +3 -0
- package/build/vite-plugin/_exports.js +81 -0
- package/build/vite-plugin/build.d.ts +5 -0
- package/build/vite-plugin/build.js +144 -0
- package/build/vite-plugin/configurator/_namespace.d.ts +1 -0
- package/build/vite-plugin/configurator/_namespace.js +1 -0
- package/build/vite-plugin/configurator/main.d.ts +35 -0
- package/build/vite-plugin/configurator/main.js +36 -0
- package/build/vite-plugin/helpers.d.ts +2 -0
- package/build/vite-plugin/helpers.js +2 -0
- package/package.json +7 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VitePlugin } from './vite-plugin/_exports.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VitePlugin } from './vite-plugin/_exports.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Polen from './_exports.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Polen from './_exports.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Box, Flex, Text } from '@radix-ui/themes';
|
|
2
|
+
import { TypeAnnotation } from './TypeAnnotation.jsx';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a single GraphQL argument in SDL syntax
|
|
5
|
+
*/
|
|
6
|
+
export const ArgumentAnnotation = ({ data }) => {
|
|
7
|
+
return (<Box as="div">
|
|
8
|
+
<Flex>
|
|
9
|
+
<Text>{data.name}</Text>
|
|
10
|
+
<Text>: </Text>
|
|
11
|
+
|
|
12
|
+
<TypeAnnotation type={data.type}/>
|
|
13
|
+
</Flex>
|
|
14
|
+
</Box>);
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Box, Flex, Heading, Text } from '@radix-ui/themes';
|
|
2
|
+
import { TypeAnnotation } from './TypeAnnotation.jsx';
|
|
3
|
+
export const ArgumentsList = ({ args }) => {
|
|
4
|
+
if (args.length === 0)
|
|
5
|
+
return null;
|
|
6
|
+
return (<Flex direction="column">
|
|
7
|
+
<Heading size="1" weight="bold">Arguments</Heading>
|
|
8
|
+
{args.map(arg => (<Box key={arg.name}>
|
|
9
|
+
<Text>{arg.name}</Text>
|
|
10
|
+
<Text>:</Text>
|
|
11
|
+
<TypeAnnotation type={arg.type}/>
|
|
12
|
+
{arg.description && <Text as="p" size="2" color="gray">{arg.description}</Text>}
|
|
13
|
+
</Box>))}
|
|
14
|
+
</Flex>);
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Box, Text } from '@radix-ui/themes';
|
|
2
|
+
import { ArgumentAnnotation } from './ArgumentAnnotation.jsx';
|
|
3
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
4
|
+
import { FieldList } from './FieldList.jsx';
|
|
5
|
+
export const ArgumentListAnnotation = ({ field }) => {
|
|
6
|
+
if (field.args.length === 0)
|
|
7
|
+
return null;
|
|
8
|
+
const inputObject = Grafaid.getIAP(field);
|
|
9
|
+
const inputObjectFields = inputObject
|
|
10
|
+
? (<Box pl="3" style={{ borderLeft: `1px solid var(--gray-6)` }}>
|
|
11
|
+
<FieldList data={inputObject}/>
|
|
12
|
+
</Box>)
|
|
13
|
+
: null;
|
|
14
|
+
return (<>
|
|
15
|
+
<Text>(</Text>
|
|
16
|
+
<Box ml="2">
|
|
17
|
+
{field.args.map(arg => <ArgumentAnnotation key={arg.name} data={arg}/>)}
|
|
18
|
+
{inputObjectFields}
|
|
19
|
+
</Box>
|
|
20
|
+
<Text>)</Text>
|
|
21
|
+
</>);
|
|
22
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Box, Flex, Heading } from '@radix-ui/themes';
|
|
2
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
3
|
+
import { Link } from './Link.jsx';
|
|
4
|
+
import { entries } from '../../lib/prelude/main.js';
|
|
5
|
+
export const ColumnView = ({ schema }) => {
|
|
6
|
+
const kindMap = Grafaid.getKindMap(schema);
|
|
7
|
+
const sections = entries(kindMap.list);
|
|
8
|
+
return (<Flex direction="column" gap="6">
|
|
9
|
+
{sections.map(([title, types]) => <TypeSection key={title} title={title} types={types}/>)}
|
|
10
|
+
</Flex>);
|
|
11
|
+
};
|
|
12
|
+
const TypeSection = ({ title, types }) => {
|
|
13
|
+
return (<Box>
|
|
14
|
+
<Heading size="3">{title}</Heading>
|
|
15
|
+
<TypeList types={types}/>
|
|
16
|
+
</Box>);
|
|
17
|
+
};
|
|
18
|
+
const TypeList = ({ types }) => {
|
|
19
|
+
return ((<Box>
|
|
20
|
+
{types.map(type => (<Box key={type.name}>
|
|
21
|
+
<Link to={`/reference/${type.name}`}>
|
|
22
|
+
{type.name}
|
|
23
|
+
</Link>
|
|
24
|
+
</Box>))}
|
|
25
|
+
</Box>));
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Text } from '@radix-ui/themes';
|
|
2
|
+
import { Markdown } from './Markdown.jsx';
|
|
3
|
+
export const DeprecationReason = ({ data }) => {
|
|
4
|
+
if (!data.deprecationReason)
|
|
5
|
+
return null;
|
|
6
|
+
return (<Text as="div" color="red">
|
|
7
|
+
<Markdown>{data.deprecationReason}</Markdown>
|
|
8
|
+
</Text>);
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Text } from '@radix-ui/themes';
|
|
2
|
+
import { Markdown } from './Markdown.jsx';
|
|
3
|
+
export const Description = ({ data }) => {
|
|
4
|
+
if (!data.description)
|
|
5
|
+
return null;
|
|
6
|
+
return (<Text as="div" color="gray">
|
|
7
|
+
<Markdown>{data.description}</Markdown>
|
|
8
|
+
</Text>);
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Box, Text } from '@radix-ui/themes';
|
|
2
|
+
import { ArgumentListAnnotation } from './ArgumentListAnnotation.jsx';
|
|
3
|
+
import { TypeAnnotation } from './TypeAnnotation.jsx';
|
|
4
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
5
|
+
import { DeprecationReason } from './DeprecationReason.jsx';
|
|
6
|
+
import { Description } from './Description.jsx';
|
|
7
|
+
export const Field = ({ data, ...boxProps }) => {
|
|
8
|
+
const argumentList = Grafaid.isOutputField(data) ? <ArgumentListAnnotation field={data}/> : null;
|
|
9
|
+
return (<Box {...boxProps}>
|
|
10
|
+
<Description data={data}/>
|
|
11
|
+
<DeprecationReason data={data}/>
|
|
12
|
+
<Text weight="medium">{data.name}</Text>
|
|
13
|
+
<Text>
|
|
14
|
+
{argumentList}
|
|
15
|
+
:{` `}
|
|
16
|
+
<TypeAnnotation type={data.type}/>
|
|
17
|
+
</Text>
|
|
18
|
+
</Box>);
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Box } from '@radix-ui/themes';
|
|
2
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
3
|
+
import { Field } from './Field.jsx';
|
|
4
|
+
export const FieldList = ({ data }) => {
|
|
5
|
+
if (!Grafaid.isTypeWithFields(data))
|
|
6
|
+
return null;
|
|
7
|
+
const fields = Grafaid.getFields(data);
|
|
8
|
+
if (fields.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
return (<Box>
|
|
11
|
+
{fields.map(field => (<Field mt="3" key={field.name} data={field}/>))}
|
|
12
|
+
</Box>);
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Box, Heading } from '@radix-ui/themes';
|
|
2
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
3
|
+
import { FieldList } from './FieldList.jsx';
|
|
4
|
+
export const FieldListSection = ({ data }) => {
|
|
5
|
+
if (!Grafaid.isTypeWithFields(data))
|
|
6
|
+
return null;
|
|
7
|
+
const fields = Grafaid.getFields(data);
|
|
8
|
+
if (fields.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
return (<Box>
|
|
11
|
+
<Heading>Fields</Heading>
|
|
12
|
+
<FieldList data={data}/>
|
|
13
|
+
</Box>);
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Marked from 'marked';
|
|
2
|
+
export const Markdown = ({ children }) => {
|
|
3
|
+
const html = Marked.parse(children);
|
|
4
|
+
return (<div dangerouslySetInnerHTML={{ __html: html }}></div>
|
|
5
|
+
// <ReactMarkdown
|
|
6
|
+
// components={{
|
|
7
|
+
// p: ({ node: _, ...props }) => <p className="rt-Text" {...props} />,
|
|
8
|
+
// }}
|
|
9
|
+
// >
|
|
10
|
+
// {children}
|
|
11
|
+
// </ReactMarkdown>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Box, Heading, Text } from '@radix-ui/themes';
|
|
2
|
+
import { Markdown } from './Markdown.jsx';
|
|
3
|
+
import { FieldListSection } from './FieldListSection.jsx';
|
|
4
|
+
export const NamedType = ({ data }) => {
|
|
5
|
+
const description = data.description
|
|
6
|
+
? (<Text as="div" color="gray">
|
|
7
|
+
<Markdown>{data.description}</Markdown>
|
|
8
|
+
</Text>)
|
|
9
|
+
: null;
|
|
10
|
+
return (<Box>
|
|
11
|
+
<Heading size="8">{data.name}</Heading>
|
|
12
|
+
{description}
|
|
13
|
+
<FieldListSection data={data}/>
|
|
14
|
+
</Box>);
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Link as LinkRadix } from '@radix-ui/themes';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Link as LinkRadix } from '@radix-ui/themes';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isInputObjectType, isListType, isNamedType, isNonNullType, isScalarType } from 'graphql';
|
|
2
|
+
import { Text } from '@radix-ui/themes';
|
|
3
|
+
import { Link } from './Link.jsx';
|
|
4
|
+
/**
|
|
5
|
+
* Renders a GraphQL type recursively, with links for named types
|
|
6
|
+
*/
|
|
7
|
+
export const TypeAnnotation = ({ type }) => {
|
|
8
|
+
// Handle NonNull type wrapper
|
|
9
|
+
if (isNonNullType(type)) {
|
|
10
|
+
return (<>
|
|
11
|
+
<TypeAnnotation type={type.ofType}/>
|
|
12
|
+
<Text color="gray">!</Text>
|
|
13
|
+
</>);
|
|
14
|
+
}
|
|
15
|
+
// Handle List type wrapper
|
|
16
|
+
if (isListType(type)) {
|
|
17
|
+
return (<>
|
|
18
|
+
<Text color="gray">[</Text>
|
|
19
|
+
<TypeAnnotation type={type.ofType}/>
|
|
20
|
+
<Text color="gray">]</Text>
|
|
21
|
+
</>);
|
|
22
|
+
}
|
|
23
|
+
// Handle named types
|
|
24
|
+
if (isNamedType(type)) {
|
|
25
|
+
const namedType = type;
|
|
26
|
+
// Handle input object types
|
|
27
|
+
if (isInputObjectType(namedType)) {
|
|
28
|
+
return (<Link to={`/reference/${namedType.name}`}>
|
|
29
|
+
<Text color="green">{namedType.name}</Text>
|
|
30
|
+
</Link>);
|
|
31
|
+
}
|
|
32
|
+
// If it's an expandable type (object or interface), make it a link
|
|
33
|
+
// if (Grafaid.isExpandableType(namedType)) {
|
|
34
|
+
return (<Link to="/reference/${namedType.name}">
|
|
35
|
+
<Text color={isScalarType(namedType) ? `purple` : `blue`}>{namedType.name}</Text>
|
|
36
|
+
</Link>);
|
|
37
|
+
// For scalar and other non-expandable types, just render the name
|
|
38
|
+
// return <Text color="purple">{namedType.name}</Text>
|
|
39
|
+
}
|
|
40
|
+
// Fallback for any other case (shouldn't happen in standard GraphQL usage)
|
|
41
|
+
return <Text>{String(type)}</Text>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Box, Flex, Heading } from '@radix-ui/themes';
|
|
2
|
+
import { Link } from './Link.jsx';
|
|
3
|
+
export const TypeFieldsLinkList = ({ type }) => {
|
|
4
|
+
return ((<Box>
|
|
5
|
+
<Heading>{type.name}</Heading>
|
|
6
|
+
<Flex direction="column">
|
|
7
|
+
{Object.values(type.getFields()).map(field => {
|
|
8
|
+
return ((<Box key={field.name}>
|
|
9
|
+
<Link to={`/reference/${type.name}/${field.name}`}>
|
|
10
|
+
{field.name}
|
|
11
|
+
</Link>
|
|
12
|
+
</Box>));
|
|
13
|
+
})}
|
|
14
|
+
</Flex>
|
|
15
|
+
</Box>));
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@radix-ui/themes/styles.css';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// TODO it seems more logical to have this asset imported in the server entry.
|
|
2
|
+
// But then, we won't get it from the client manifest. But we could get it from the server manifest. Should we do that?
|
|
3
|
+
// But then, that wouldn't work for SPA. Does that matter? Just put a conditional here e.g. if (import.meta.env.PROD) ...?
|
|
4
|
+
import '@radix-ui/themes/styles.css';
|
|
5
|
+
import { RouterProvider, createBrowserRouter } from 'react-router';
|
|
6
|
+
import { routes } from './routes.jsx';
|
|
7
|
+
import { ReactDomClient } from '../lib/react-dom-client/_namespace.js';
|
|
8
|
+
import { StrictMode } from 'react';
|
|
9
|
+
// SPA
|
|
10
|
+
// const router = createBrowserRouter(routes)
|
|
11
|
+
// createRoot(document).render(
|
|
12
|
+
// <RouterProvider router={router} />,
|
|
13
|
+
// )
|
|
14
|
+
// SSR
|
|
15
|
+
const router = createBrowserRouter(routes, {
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
hydrationData: window.__staticRouterHydrationData,
|
|
19
|
+
});
|
|
20
|
+
ReactDomClient.hydrateRoot(document, (<StrictMode>
|
|
21
|
+
<RouterProvider router={router}/>
|
|
22
|
+
</StrictMode>));
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import viteClientAssetManifest from 'virtual:polen/vite/client/manifest';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import { StaticRouterProvider, createStaticHandler, createStaticRouter } from 'react-router';
|
|
4
|
+
import { routes } from './routes.jsx';
|
|
5
|
+
import { ReactDomServer } from '../lib/react-dom-server/_namespace.js';
|
|
6
|
+
import { StrictMode } from 'react';
|
|
7
|
+
import { debug } from '../lib/debug/debug.js';
|
|
8
|
+
const getRouteHeaders = (context) => {
|
|
9
|
+
const leaf = context.matches[context.matches.length - 1];
|
|
10
|
+
if (!leaf)
|
|
11
|
+
return new Headers();
|
|
12
|
+
const actionHeaders = context.actionHeaders[leaf.route.id];
|
|
13
|
+
const loaderHeaders = context.loaderHeaders[leaf.route.id];
|
|
14
|
+
const headers = new Headers(actionHeaders);
|
|
15
|
+
if (loaderHeaders) {
|
|
16
|
+
for (const [key, value] of loaderHeaders.entries()) {
|
|
17
|
+
headers.append(key, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return headers;
|
|
21
|
+
};
|
|
22
|
+
const getAssetHtmlTags = (manifest) => {
|
|
23
|
+
// TODO: We could inline this into the generated server.
|
|
24
|
+
// TODO: this only applies in production
|
|
25
|
+
// Insert links to assets
|
|
26
|
+
const css = [];
|
|
27
|
+
const js = [];
|
|
28
|
+
for (const manifestChunk of Object.values(manifest)) {
|
|
29
|
+
if (manifestChunk.isEntry) {
|
|
30
|
+
js.push(`<script type="module" src="/${manifestChunk.file}"></script>`);
|
|
31
|
+
}
|
|
32
|
+
for (const cssItem of manifestChunk.css ?? []) {
|
|
33
|
+
css.push(`<link rel="stylesheet" href="/${cssItem}">`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
css,
|
|
38
|
+
js,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const injectAssetHtmlTags = (html, htmlTags) => {
|
|
42
|
+
if (htmlTags.css.length > 0) {
|
|
43
|
+
html = html.replace(`</head>`, `${htmlTags.css.join(``)}</head>`);
|
|
44
|
+
}
|
|
45
|
+
if (htmlTags.js.length > 0) {
|
|
46
|
+
html = html.replace(`</body>`, `${htmlTags.js.join(``)}</body>`);
|
|
47
|
+
}
|
|
48
|
+
return html;
|
|
49
|
+
};
|
|
50
|
+
const app = new Hono();
|
|
51
|
+
const staticHandler = createStaticHandler(routes);
|
|
52
|
+
app.get(`*`, async (ctx) => {
|
|
53
|
+
const staticHandlerContext = await staticHandler.query(ctx.req.raw);
|
|
54
|
+
// console.log(staticHandlerContext)
|
|
55
|
+
if (staticHandlerContext instanceof Response) {
|
|
56
|
+
return staticHandlerContext;
|
|
57
|
+
}
|
|
58
|
+
const router = createStaticRouter(staticHandler.dataRoutes, staticHandlerContext);
|
|
59
|
+
let html = ``;
|
|
60
|
+
try {
|
|
61
|
+
html = ReactDomServer.renderToString((<StrictMode>
|
|
62
|
+
<StaticRouterProvider router={router} context={staticHandlerContext}/>
|
|
63
|
+
</StrictMode>));
|
|
64
|
+
}
|
|
65
|
+
catch (cause) {
|
|
66
|
+
throw new Error(`Failed to server side render the HTML`, { cause });
|
|
67
|
+
}
|
|
68
|
+
if (import.meta.env.PROD) {
|
|
69
|
+
const htmlTags = getAssetHtmlTags(viteClientAssetManifest);
|
|
70
|
+
html = injectAssetHtmlTags(html, htmlTags);
|
|
71
|
+
}
|
|
72
|
+
if (import.meta.env.DEV) {
|
|
73
|
+
debug(`transformIndexHtml`);
|
|
74
|
+
// @see https://github.com/honojs/vite-plugins/issues/141
|
|
75
|
+
html = transformIndexHtml(html);
|
|
76
|
+
}
|
|
77
|
+
const headers = getRouteHeaders(staticHandlerContext);
|
|
78
|
+
headers.set(`Content-Type`, `text/html; charset=utf-8`);
|
|
79
|
+
return new Response(`<!DOCTYPE html>${html}`, {
|
|
80
|
+
status: staticHandlerContext.statusCode,
|
|
81
|
+
headers,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
const transformIndexHtml = (html) => {
|
|
85
|
+
const REACT_FAST_REFRESH_PREAMBLE = `import RefreshRuntime from '/@react-refresh'
|
|
86
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
|
87
|
+
window.$RefreshReg$ = () => {}
|
|
88
|
+
window.$RefreshSig$ = () => (type) => type
|
|
89
|
+
window.__vite_plugin_react_preamble_installed__ = true`;
|
|
90
|
+
const scripts = `` +
|
|
91
|
+
`<script type="module" src="/@vite/client"></script>` +
|
|
92
|
+
`<script type="module" async>${REACT_FAST_REFRESH_PREAMBLE}</script>`;
|
|
93
|
+
html = html.replace(`</body>`, `${scripts}</body>`);
|
|
94
|
+
return html;
|
|
95
|
+
};
|
|
96
|
+
export default app;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const index: import("react-router").IndexRouteObject;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { buildASTSchema } from 'graphql';
|
|
2
|
+
import { Grafaid } from '../../lib/grafaid/index.js';
|
|
3
|
+
import { Field } from '../components/Field.jsx';
|
|
4
|
+
import { createRoute } from '../../lib/react-router-helpers.js';
|
|
5
|
+
import { useParams, useRouteLoaderData } from 'react-router';
|
|
6
|
+
const Component = () => {
|
|
7
|
+
const params = useParams();
|
|
8
|
+
const data = useRouteLoaderData(`/reference`);
|
|
9
|
+
const schema = buildASTSchema(data.documentNode);
|
|
10
|
+
const type = schema.getType(params.type);
|
|
11
|
+
if (!type)
|
|
12
|
+
return `Could not find type ${params.type}`;
|
|
13
|
+
if (!Grafaid.isTypeWithFields(type))
|
|
14
|
+
return `Type ${params.type} does not have fields`;
|
|
15
|
+
const fields = type.getFields();
|
|
16
|
+
const field = fields[params.field];
|
|
17
|
+
if (!field)
|
|
18
|
+
return `Could not find field ${params.field} on type ${params.type}`;
|
|
19
|
+
return <Field data={field}/>;
|
|
20
|
+
};
|
|
21
|
+
export const reference$type$field = createRoute({
|
|
22
|
+
path: `:type/:field`,
|
|
23
|
+
Component,
|
|
24
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRoute } from '../../lib/react-router-helpers.js';
|
|
2
|
+
import { useParams, useRouteLoaderData } from 'react-router';
|
|
3
|
+
import { buildASTSchema } from 'graphql';
|
|
4
|
+
import { NamedType } from '../components/NamedType.jsx';
|
|
5
|
+
const Component = () => {
|
|
6
|
+
const params = useParams();
|
|
7
|
+
const data = useRouteLoaderData(`/reference`);
|
|
8
|
+
// const data = reference$type.parentRoute.useLoaderData()
|
|
9
|
+
const schema = buildASTSchema(data.documentNode);
|
|
10
|
+
const type = schema.getType(params.type);
|
|
11
|
+
if (!type)
|
|
12
|
+
return `Could not find type ${params.type}`;
|
|
13
|
+
return <NamedType data={type}/>;
|
|
14
|
+
};
|
|
15
|
+
export const reference$type = createRoute({
|
|
16
|
+
path: `:type`,
|
|
17
|
+
Component,
|
|
18
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DocumentNode } from 'graphql';
|
|
2
|
+
export declare const reference: {
|
|
3
|
+
path: string;
|
|
4
|
+
loader: () => {
|
|
5
|
+
documentNode: DocumentNode;
|
|
6
|
+
};
|
|
7
|
+
Component: () => import("react").JSX.Element;
|
|
8
|
+
children: {
|
|
9
|
+
path: string;
|
|
10
|
+
Component: () => string | import("react").JSX.Element;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { buildASTSchema, parse } from 'graphql';
|
|
2
|
+
import { ColumnView } from '../components/ColumnView.jsx';
|
|
3
|
+
import { Box, Flex } from '@radix-ui/themes';
|
|
4
|
+
import { Outlet, useLoaderData } from 'react-router';
|
|
5
|
+
// import { reference$type$field } from './reference.$type.$field.jsx'
|
|
6
|
+
import schemaFileContent from 'virtual:polen/assets/graphql-schema';
|
|
7
|
+
import { createRoute } from '../../lib/react-router-helpers.js';
|
|
8
|
+
import { reference$type } from './reference.$type.jsx';
|
|
9
|
+
const loader = () => {
|
|
10
|
+
const documentNode = parse(schemaFileContent);
|
|
11
|
+
// console.log(`running loader`, documentNode)
|
|
12
|
+
return {
|
|
13
|
+
documentNode,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const Component = () => {
|
|
17
|
+
const data = useLoaderData();
|
|
18
|
+
const schema = buildASTSchema(data.documentNode);
|
|
19
|
+
return (<Flex direction="row" align="start">
|
|
20
|
+
<ColumnView schema={schema}/>
|
|
21
|
+
<Box width="40rem">
|
|
22
|
+
<Outlet />
|
|
23
|
+
</Box>
|
|
24
|
+
</Flex>);
|
|
25
|
+
};
|
|
26
|
+
export const reference = createRoute({
|
|
27
|
+
path: `/reference`,
|
|
28
|
+
loader,
|
|
29
|
+
Component,
|
|
30
|
+
children: [
|
|
31
|
+
reference$type,
|
|
32
|
+
// reference$type$field,
|
|
33
|
+
],
|
|
34
|
+
});
|