Skip to content

Commit 0335b87

Browse files
authored
Merge pull request #137 from code0-tech/feat/#136
Function representation as Flow Node
2 parents 74de385 + 80733a5 commit 0335b87

4 files changed

Lines changed: 145 additions & 25 deletions

File tree

app/[...slug]/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {getMDXComponents} from '@/mdx-components';
66
import { AutoTypeTable, type AutoTypeTableProps } from 'fumadocs-typescript/ui';
77
import type {ComponentProps, FC} from 'react';
88
import {createGenerator} from "fumadocs-typescript";
9+
import FunctionCard from "@/src/components/FunctionCard";
910

1011
export default async function Page(props: {
1112
params: Promise<{ slug?: string[] }>;
@@ -26,6 +27,9 @@ export default async function Page(props: {
2627
<DocsBody>
2728
<MDXContent
2829
components={getMDXComponents({
30+
FunctionCard: (props) => (
31+
<FunctionCard {...props}/>
32+
),
2933
AutoTypeTable: (props: Partial<AutoTypeTableProps>) => (
3034
<AutoTypeTable {...props} generator={createGenerator()}/>
3135
),

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
"postinstall": "fumadocs-mdx"
1010
},
1111
"dependencies": {
12-
"@tabler/icons-react": "^3.41.0",
12+
"@code0-tech/sagittarius-graphql-types": "^0.0.0-experimental-2414125487-fbc8a5ec8a2dd07cc76957d4315281c246e98d57",
13+
"@tabler/icons-react": "^3.40.0",
1314
"fumadocs-core": "^16.7.7",
1415
"fumadocs-mdx": "^14.2.11",
15-
"fumadocs-ui": "^16.7.7",
1616
"fumadocs-typescript": "^5.2.0",
17+
"fumadocs-ui": "^16.7.7",
18+
"js-md5": "^0.8.3",
1719
"next": "16.1.7",
1820
"react": "^19.1.0",
1921
"react-dom": "^19.1.0"

src/components/FunctionCard.tsx

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import {FunctionDefinition} from "@code0-tech/sagittarius-graphql-types";
2+
import React from "react";
3+
import {Card as FumaCard} from "fumadocs-ui/components/card";
4+
import {IconNote, IconX} from "@tabler/icons-react";
5+
import {md5} from "js-md5";
6+
7+
export interface FunctionCardProps {
8+
definition?: FunctionDefinition
9+
}
10+
11+
const GOLDEN_ANGLE = 137.50776405003785
12+
13+
const extractIdNumber = (s: string) => {
14+
const m = s.match(/\/(\d+)\s*$/)
15+
return m ? Number(m[1]) : null
16+
}
17+
18+
export const hashToColor = (s: string, from: number = 25, to: number = 320): string => {
19+
const range = to - from;
20+
const n = extractIdNumber(s);
21+
if (n != null) {
22+
const hue = from + ((n * GOLDEN_ANGLE) % range);
23+
return `hsl(${hue}, 100%, 72%)`;
24+
}
25+
26+
const h = md5(md5(s));
27+
const a = parseInt(h.slice(0, 8), 16);
28+
return `hsl(${from + (a % range)}, 100%, 72%)`;
29+
}
30+
31+
const FunctionCard: React.FC<FunctionCardProps> = (props) => {
32+
33+
const {definition} = props
34+
35+
const splitTemplate = (str: string) =>
36+
str
37+
.split(/(\$\{[^}]+\})/)
38+
.filter(Boolean)
39+
.flatMap(part =>
40+
part.startsWith("${")
41+
? [part.slice(2, -1)] // variable name ohne ${}
42+
: part.split(/(\s*,\s*)/) // Kommas einzeln extrahieren
43+
.filter(Boolean)
44+
.flatMap(p => p.trim() === "," ? [","] : p.trim() ? [p.trim()] : [])
45+
);
46+
47+
48+
const displayMessage = splitTemplate(definition?.displayMessages?.[0].content ?? "Some ${example} function")
49+
const renderedMessage = displayMessage.map((part, index) => {
50+
if (definition?.parameterDefinitions?.nodes?.find(pd => pd?.identifier === part)) {
51+
return <span style={{
52+
background: "#191825",
53+
padding: ".116667rem .35rem",
54+
borderRadius: "1rem",
55+
boxShadow: "inset 0 1px 1px #bfbfbf1a"
56+
}}>
57+
{part}
58+
</span>
59+
}
60+
61+
return <span>{part}</span>
62+
})
63+
64+
console.log(definition)
65+
66+
return <FumaCard title={""} key={"function-card-" + definition?.identifier}>
67+
<div style={{gap: "1rem", display: "flex", justifyContent: "space-between", alignItems: "center"}}>
68+
<FumaCard title={""} style={{textWrap: "nowrap", background: "#070514", borderRadius: "1rem", padding: "0.35rem 0.7rem", border: "1px solid #bfbfbf1a"}}>
69+
<div style={{gap: "0.35rem", display: "flex", alignItems: "center", justifyContent: "center"}}>
70+
<IconNote color={hashToColor(definition?.identifier ?? "")} size={16}/>
71+
{renderedMessage}
72+
</div>
73+
</FumaCard>
74+
<FumaCard title={""} style={{background: "#070514", border: "none"}}>
75+
<div style={{
76+
background: "#2c2a36",
77+
padding: ".35rem .7rem",
78+
borderRadius: "1rem",
79+
boxShadow: "inset 0 1px 1px #bfbfbf1a",
80+
width: "fit-content",
81+
display: "flex",
82+
gap: "0.35rem",
83+
alignItems: "center",
84+
fontSize: "12px",
85+
marginBottom: "1rem",
86+
}}>
87+
<IconNote color={hashToColor(definition?.identifier ?? "")} size={13}/>
88+
{definition?.names?.[0].content}
89+
<IconX size={13}/>
90+
</div>
91+
<div style={{flexDirection: "column", gap: "1rem", display: "flex"}}>
92+
{definition?.parameterDefinitions?.nodes?.map(pd => (
93+
<div key={"param-" + pd?.identifier}>
94+
<span>{pd?.names?.[0].content}</span>
95+
<p style={{margin: "0", paddingTop: "0.7rem"}}> {pd?.descriptions?.[0].content}</p>
96+
<div style={{
97+
marginTop: "0.7rem",
98+
background: "#191825",
99+
borderRadius: "1rem",
100+
boxShadow: "inset 0 1px 1px #bfbfbf1a",
101+
height: "40px",
102+
width: "100%",
103+
position: "relative",
104+
display: "block"
105+
}}/>
106+
</div>
107+
))}
108+
</div>
109+
</FumaCard>
110+
</div>
111+
</FumaCard>
112+
}
113+
114+
export default FunctionCard;

0 commit comments

Comments
 (0)