Skip to content

Commit

Permalink
chore: update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Nov 10, 2023
1 parent 4a69baa commit 420e7ce
Show file tree
Hide file tree
Showing 32 changed files with 691 additions and 73 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@shlab/fabric": "^1.2.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react-syntax-highlighter": "^15.5.10",
"@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.16",
"daisyui": "^3.9.3",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 13 additions & 25 deletions src/components/markdown-with-highlight/index.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
import SyntaxHighlighter from 'react-syntax-highlighter';
import 'react-syntax-highlighter/dist/esm/styles/hljs/night-owl';
import { githubGist } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import React from 'react';
import type { MDXComponents, MergeComponents } from '@mdx-js/react/lib';

function code({ className, ...props }: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>) {
const match = /language-(\w+)/.exec(className || '');

return match ? (
<SyntaxHighlighter language={match[1]} PreTag="div" {...props} />
<SyntaxHighlighter
lineNumberStyle={{
color: '#999',
}}
showLineNumbers
language={match[1]}
PreTag="div"
// @ts-ignore
style={githubGist}
{...props}
/>
) : (
<code className={className} {...props} />
);
}

function getAnchor(text: string) {
return text
.toLowerCase()
.replace(/[^a-z0-9\u4e00-\u9fa5 ]/g, '')
.replace(/[ ]/g, '-');
}

function h2({ children }: React.PropsWithChildren) {
const anchor = getAnchor(children as string);
const link = `#${anchor}`;

return (
<h2 id={anchor}>
<a href={link} className="anchor-link">
§
</a>
&nbsp;
{children as string}
</h2>
);
}

interface ExtraProps {
components: Readonly<MDXComponents> | MergeComponents | null | undefined;
}

export default function MarkdownWithHighlight({ children }: React.PropsWithChildren) {
const childrenWithExtraProp = React.Children.map(children, (child) => {
if (React.isValidElement<ExtraProps>(child)) {
return React.cloneElement(child, { components: { code, h2 } });
return React.cloneElement(child, { components: { code } });
}

return child;
Expand Down
7 changes: 6 additions & 1 deletion src/components/schema-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ const JsonSchemaTable: FC<JsonSchemaTableProps> = ({ schema }) => {
if (value.additionalProperties && expandedFields.includes(fullKey)) {
if (value.additionalProperties.anyOf) {
rows.push(
...generateRows({ '[string]': { type: ['number', 'string'] } }, requiredFields, `${fullKey}.`, true),
...generateRows(
{ '[string]': { type: value.additionalProperties.anyOf.map((item) => item.type as unknown as string) } },
requiredFields,
`${fullKey}.`,
true,
),
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/layouts/main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Link, Outlet, useLocation, useMatch, useNavigate } from 'react-router-dom';
import { useEffect } from 'react';
import { BiLinkExternal } from '@react-icons/all-files/bi/BiLinkExternal';
import { BiBookContent } from '@react-icons/all-files/bi/BiBookContent';
import { BiCodeCurly } from '@react-icons/all-files/bi/BiCodeCurly';
import { AiOutlineGithub } from '@react-icons/all-files/ai/AiOutlineGithub';
import { HiTranslate } from '@react-icons/all-files/hi/HiTranslate';
import clsx from 'clsx';
Expand All @@ -16,17 +18,17 @@ const links = [
{
title: i18nLocale.t('guide'),
path: 'guide',
icon: null,
icon: <BiBookContent />,
},
{
title: i18nLocale.t('schema'),
path: 'schema',
icon: null,
icon: <BiCodeCurly />,
},
{
title: 'LabelU-kit',
path: 'https://github.com/opendatalab/labelU-kit#readme',
icon: <BiLinkExternal />,
icon: null,
type: 'external',
},
];
Expand Down Expand Up @@ -115,7 +117,8 @@ export default function Layout() {
'sm:flex': type === 'external',
})}
>
{title} {icon}
<span className="text-xl">{icon}</span> {title}
{type === 'external' && <BiLinkExternal />}
</Link>
))}
</div>
Expand Down
34 changes: 34 additions & 0 deletions src/pages/schema.audio.frame/example.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import jsonschema from './schema.json';
import JsonSchemaTable from '../../components/schema-table';

## Audio Timestamp Schema

<JsonSchemaTable schema={jsonschema} />

## Example

```json filename="index.json"
{
"toolName": "audioFrameTool",
"result": [
{
"id": "cbqbst6gj5f",
"time": 5.6555891238670695,
"label": "label-1",
"order": 3,
"attributes": {
"contains": "Hello"
}
},
{
"id": "c8il22ceipi",
"time": 7.917824773413897,
"label": "label-1",
"order": 4,
"attributes": {
"contains": "Human"
}
}
]
}
```
11 changes: 11 additions & 0 deletions src/pages/schema.audio.frame/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MarkdownWithHighlight from '@/components/markdown-with-highlight';

import Markdown from './example.mdx';

export default function AudioFrameSchema() {
return (
<MarkdownWithHighlight>
<Markdown />
</MarkdownWithHighlight>
);
}
42 changes: 42 additions & 0 deletions src/pages/schema.audio.frame/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "唯一标识"
},
"time": {
"type": "number",
"description": "时间点"
},
"order": {
"type": "integer",
"description": "标注顺序",
"minimum": 0
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
},
"attributes": {
"type": "object",
"description": "类别属性,键值对",
"additionalProperties": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
},
"required": ["x", "y", "width", "height", "id", "order", "label"]
}
36 changes: 36 additions & 0 deletions src/pages/schema.audio.segment/example.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import jsonschema from './schema.json';
import JsonSchemaTable from '../../components/schema-table';

## Audio Segment Schema

<JsonSchemaTable schema={jsonschema} />

## Example

```json
{
"toolName": "audioSegmentTool",
"result": [
{
"id": "58gz4irdvip",
"start": 4.2634441087613295,
"end": 8.845921,
"order": 1,
"label": "label-1",
"attributes": {
"car": ["bmw"]
}
},
{
"id": "dtgvrzgfgcp",
"start": 5.713595166163143,
"end": 9.89003,
"order": 2,
"label": "label-1",
"attributes": {
"car": ["bmw"]
}
}
]
}
```
11 changes: 11 additions & 0 deletions src/pages/schema.audio.segment/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MarkdownWithHighlight from '@/components/markdown-with-highlight';

import Markdown from './example.mdx';

export default function AudioSegmentSchema() {
return (
<MarkdownWithHighlight>
<Markdown />
</MarkdownWithHighlight>
);
}
46 changes: 46 additions & 0 deletions src/pages/schema.audio.segment/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "唯一标识"
},
"start": {
"type": "number",
"description": "起始时间"
},
"end": {
"type": "number",
"description": "结束时间"
},
"order": {
"type": "integer",
"description": "标注顺序",
"minimum": 0
},
"label": {
"type": "string",
"description": "标注类别",
"default": "none"
},
"attributes": {
"type": "object",
"description": "类别属性,键值对",
"additionalProperties": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
}
},
"required": ["x", "y", "width", "height", "id", "order", "label"]
}
Loading

0 comments on commit 420e7ce

Please sign in to comment.