Skip to content

Commit

Permalink
chore(website): update code preview
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Feb 1, 2024
1 parent 4756439 commit f806ff6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 53 deletions.
12 changes: 7 additions & 5 deletions src/components/schema-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';

interface SchemaProp {
[key: string]: {
required?: string[];
type: string | string[];
description?: string;
default?: string | number | boolean;
Expand Down Expand Up @@ -48,7 +49,7 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
};

// Recursively generate rows
const generateRows = (properties: SchemaProp, requiredFields: string[], parentKey = '', isChild?: boolean) => {
const generateRows = (properties: SchemaProp, requiredFields: string[], parentKey = '', isChild?: boolean, depth = 0) => {
return Object.entries(properties).flatMap(([key, value]) => {
const fullKey = parentKey + key;

Expand All @@ -60,9 +61,9 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
})}
>
<td
className={clsx({
'pl-14': isChild,
})}
style={{
paddingLeft: `${1 * (depth + 1)}rem`,
}}
>
<div className="flex items-center gap-2">
{key}
Expand Down Expand Up @@ -99,7 +100,7 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
) {
const nestedProperties = value.type === 'array' ? value.items!.properties : value.properties;

rows.push(...generateRows(nestedProperties!, requiredFields, `${fullKey}.`, true));
rows.push(...generateRows(nestedProperties!, value.required ?? [], `${fullKey}.`, true, depth + 1));
}

if (value.additionalProperties && expandedFields.includes(fullKey)) {
Expand All @@ -110,6 +111,7 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
requiredFields,
`${fullKey}.`,
true,
depth + 1,
),
);
}
Expand Down
47 changes: 0 additions & 47 deletions src/pages/schema.image.cuboid/example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,6 @@ import CodePreview from '../../components/code-preview';
"order": 2,
"attributes": {},
"attribute": "car"
},
{
"id": "b450e778-5827-4f9e-b682-e35fc4f4102f",
"direction": "back",
"front": {
"tl": {
"x": 808.3596159774789,
"y": 556.6227111705573
},
"tr": {
"x": 1007.4019287782886,
"y": 556.6227111705573
},
"br": {
"x": 1007.4019287782886,
"y": 792.9625801907306
},
"bl": {
"x": 808.3596159774789,
"y": 792.9625801907306
}
},
"back": {
"tl": {
"x": 1053.4631980019385,
"y": 586.4163468211026
},
"tr": {
"x": 1188.14135121785,
"y": 586.4163468211026
},
"br": {
"x": 1188.14135121785,
"y": 746.331174191405
},
"bl": {
"x": 1053.4631980019385,
"y": 746.331174191405
}
},
"order": 1,
"attributes": {
"color": [
"white"
]
},
"attribute": "suv"
}
]
}} />
8 changes: 8 additions & 0 deletions src/pages/schema.image.cuboid/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"properties": {
"tl": {
"type": "object",
"description": "左上角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -32,6 +33,7 @@
},
"tr": {
"type": "object",
"description": "右上角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -47,6 +49,7 @@
},
"br": {
"type": "object",
"description": "右下角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -62,6 +65,7 @@
},
"bl": {
"type": "object",
"description": "左下角坐标",
"properties": {
"x": {
"type": "number"
Expand Down Expand Up @@ -89,6 +93,7 @@
"properties": {
"tl": {
"type": "object",
"description": "左上角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -104,6 +109,7 @@
},
"tr": {
"type": "object",
"description": "右上角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -119,6 +125,7 @@
},
"br": {
"type": "object",
"description": "右下角坐标",
"properties": {
"x": {
"type": "number"
Expand All @@ -134,6 +141,7 @@
},
"bl": {
"type": "object",
"description": "左下角坐标",
"properties": {
"x": {
"type": "number"
Expand Down
2 changes: 1 addition & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ a {
}

.prose pre {
padding: 0;
padding: .6rem .8rem;
background: transparent;
border: 1px solid #ebebeb;
color: inherit !important;
Expand Down

0 comments on commit f806ff6

Please sign in to comment.