@alauda/doom 0.2.0 → 0.2.1
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/lib/runtime/components/Directive.d.ts +11 -0
- package/lib/runtime/components/Directive.js +17 -0
- package/lib/runtime/components/K8sCrd.d.ts +15 -1
- package/lib/runtime/components/K8sCrd.js +62 -2
- package/lib/runtime/components/_Markdown.js +1 -1
- package/lib/runtime/hooks/index.d.ts +1 -0
- package/lib/runtime/hooks/index.js +1 -0
- package/lib/runtime/hooks/useTranslation.d.ts +1 -0
- package/lib/runtime/hooks/useTranslation.js +8 -0
- package/lib/runtime/index.d.ts +1 -0
- package/lib/runtime/index.js +1 -0
- package/lib/runtime/translation.d.ts +13 -0
- package/lib/runtime/translation.js +11 -0
- package/package.json +2 -1
- package/styles/global.scss +33 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface DirectiveProps {
|
|
3
|
+
type?: 'danger' | 'details' | 'info' | 'note' | 'tip' | 'warning';
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
title?: ReactNode;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
onToggle?: (open: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const Directive: ({ className, type, title, children, open, onToggle, }: DirectiveProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default Directive;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { upperCase } from 'es-toolkit';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
export const Directive = ({ className, type = 'info', title, children, open, onToggle, }) => {
|
|
6
|
+
const rootClassName = clsx('rspress-directive', type, className);
|
|
7
|
+
const titleNode = title || upperCase(type);
|
|
8
|
+
const contentNode = (_jsx("div", { className: "rspress-directive-content", children: children }));
|
|
9
|
+
const handleToggle = useCallback((ev) => {
|
|
10
|
+
onToggle?.(ev.currentTarget.open);
|
|
11
|
+
}, [onToggle]);
|
|
12
|
+
if (type === 'details') {
|
|
13
|
+
return (_jsxs("details", { className: rootClassName, open: open, onToggle: handleToggle, children: [_jsx("summary", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
|
|
14
|
+
}
|
|
15
|
+
return (_jsxs("div", { className: rootClassName, children: [_jsx("div", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
|
|
16
|
+
};
|
|
17
|
+
export default Directive;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modified based on @see https://github.com/crdsdev/doc/blob/main/template/doc.html
|
|
3
|
+
*/
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
1
5
|
export interface K8sCrdProps {
|
|
2
6
|
name: string;
|
|
3
7
|
}
|
|
4
|
-
export declare const
|
|
8
|
+
export declare const K8sCrdSchemaPart: ({ name, parent, schema: property, openAll, }: {
|
|
9
|
+
name: string;
|
|
10
|
+
parent: OpenAPIV3_1.SchemaObject;
|
|
11
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
12
|
+
openAll: boolean;
|
|
13
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const K8sCrdSchema: ({ schema, version, }: {
|
|
15
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
16
|
+
version: string;
|
|
17
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export declare const K8sCrd: ({ name }: K8sCrdProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
5
19
|
export default K8sCrd;
|
|
@@ -1,5 +1,65 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* modified based on @see https://github.com/crdsdev/doc/blob/main/template/doc.html
|
|
4
|
+
*/
|
|
5
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
6
|
+
import { Badge, Button, getCustomMDXComponent } from '@rspress/core/theme';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { useTranslation } from '../hooks/index.js';
|
|
9
|
+
import { Markdown } from './_Markdown.js';
|
|
10
|
+
import Directive from './Directive.js';
|
|
11
|
+
const X = getCustomMDXComponent();
|
|
12
|
+
export const K8sCrdSchemaPart = ({ name, parent, schema: property, openAll, }) => {
|
|
13
|
+
const [open, setOpen] = useState(openAll);
|
|
14
|
+
const onToggle = useCallback((open) => {
|
|
15
|
+
setOpen(open);
|
|
16
|
+
}, []);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setOpen(openAll);
|
|
19
|
+
}, [openAll]);
|
|
20
|
+
const [props, required, type, schema] = useMemo(() => {
|
|
21
|
+
let schema = property;
|
|
22
|
+
let props = property.properties;
|
|
23
|
+
let type = property.type;
|
|
24
|
+
if (property.type === 'array') {
|
|
25
|
+
const itemsSchema = property.items;
|
|
26
|
+
if (itemsSchema.type === 'object') {
|
|
27
|
+
schema = itemsSchema;
|
|
28
|
+
props = itemsSchema.properties;
|
|
29
|
+
type = `[]object`;
|
|
30
|
+
}
|
|
31
|
+
else if (itemsSchema.type) {
|
|
32
|
+
type = `[]${itemsSchema.type}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let required = false;
|
|
36
|
+
if (parent.required?.includes(name)) {
|
|
37
|
+
required = true;
|
|
38
|
+
}
|
|
39
|
+
return [props, required, type, schema];
|
|
40
|
+
}, [name, parent, property]);
|
|
41
|
+
return (_jsx(_Fragment, { children: _jsxs(Directive, { type: "details", title: _jsxs(_Fragment, { children: [name, type && _jsx(X.code, { children: type }), required && _jsx(Badge, { children: "required" })] }), open: open, onToggle: onToggle, children: [_jsx(Markdown, { children: schema.description }), props &&
|
|
42
|
+
Object.entries(props).map(([name, subSchema]) => (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, openAll: openAll }, name)))] }) }));
|
|
43
|
+
};
|
|
44
|
+
export const K8sCrdSchema = ({ schema, version, }) => {
|
|
45
|
+
const { description, properties } = schema;
|
|
46
|
+
const t = useTranslation();
|
|
47
|
+
const [openAll, setOpenAll] = useState(false);
|
|
48
|
+
const expandAll = useCallback(() => {
|
|
49
|
+
setOpenAll(true);
|
|
50
|
+
}, []);
|
|
51
|
+
const collapseAll = useCallback(() => {
|
|
52
|
+
setOpenAll(false);
|
|
53
|
+
}, []);
|
|
54
|
+
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx(X.code, { children: version }), _jsx(Badge, { children: "version" })] }), properties != null && (_jsxs("div", { className: "ml-auto", children: [_jsx(Button, { className: "doom-btn", type: "button", text: _jsxs("span", { onClick: collapseAll, children: ["- ", t('collapse_all')] }), size: "medium", theme: "alt" }), _jsx(Button, { className: "doom-btn ml-2", type: "button", text: _jsxs("span", { onClick: expandAll, children: ["+ ", t('expand_all')] }), size: "medium", theme: "alt" })] }))] }), properties == null ? (_jsx(Directive, { type: "warning", children: t('crd_no_schema') })) : (_jsx("div", { className: "doom-collapse-group", children: Object.entries(properties).map(([name, subSchema]) => (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, openAll: openAll }, name))) }))] }));
|
|
55
|
+
};
|
|
2
56
|
export const K8sCrd = ({ name }) => {
|
|
3
|
-
|
|
57
|
+
const { page } = usePageData();
|
|
58
|
+
const crd = useMemo(() => Object.values(page.crdsMap || {}).find((crd) => crd.metadata.name === name), [page]);
|
|
59
|
+
if (!crd) {
|
|
60
|
+
console.error(`No CustomResourceDefinition found for ${name}`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return (_jsxs(_Fragment, { children: [_jsxs(X.p, { children: [_jsx(X.code, { children: crd.spec.group }), _jsx(Badge, { children: "group" })] }), crd.spec.versions.map((version) => (_jsx(K8sCrdSchema, { schema: version.schema.openAPIV3Schema, version: version.name })))] }));
|
|
4
64
|
};
|
|
5
65
|
export default K8sCrd;
|
|
@@ -3,4 +3,4 @@ import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
|
3
3
|
import ReactMarkdown from 'react-markdown';
|
|
4
4
|
import remarkGfm from 'remark-gfm';
|
|
5
5
|
const components = getCustomMDXComponent();
|
|
6
|
-
export const Markdown = ({ children }) => children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: components, skipHtml: true,
|
|
6
|
+
export const Markdown = ({ children }) => children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: components, skipHtml: true, children: children }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTranslation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTranslation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useTranslation: () => (key: "collapse_all" | "expand_all" | "crd_no_schema") => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useLang } from '@rspress/core/runtime';
|
|
2
|
+
import { TRANSLATIONS } from '../translation.js';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
export const useTranslation = () => {
|
|
5
|
+
const lang = (useLang() || 'zh');
|
|
6
|
+
const translations = TRANSLATIONS[lang];
|
|
7
|
+
return useCallback((key) => translations[key], []);
|
|
8
|
+
};
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const TRANSLATIONS: {
|
|
2
|
+
en: {
|
|
3
|
+
collapse_all: string;
|
|
4
|
+
expand_all: string;
|
|
5
|
+
crd_no_schema: string;
|
|
6
|
+
};
|
|
7
|
+
zh: {
|
|
8
|
+
collapse_all: string;
|
|
9
|
+
expand_all: string;
|
|
10
|
+
crd_no_schema: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type Locale = keyof typeof TRANSLATIONS;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const en = {
|
|
2
|
+
collapse_all: 'Collapse All',
|
|
3
|
+
expand_all: 'Expand All',
|
|
4
|
+
crd_no_schema: 'This CRD has an empty or unspecified schema.',
|
|
5
|
+
};
|
|
6
|
+
const zh = {
|
|
7
|
+
collapse_all: '全部收起',
|
|
8
|
+
expand_all: '全部展开',
|
|
9
|
+
crd_no_schema: '此 CRD 未定义或定义为空。',
|
|
10
|
+
};
|
|
11
|
+
export const TRANSLATIONS = { en, zh };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"@rspress/core": "^1.37.4",
|
|
41
41
|
"@rspress/plugin-preview": "^1.37.4",
|
|
42
42
|
"chokidar": "^4.0.1",
|
|
43
|
+
"clsx": "^2.1.1",
|
|
43
44
|
"commander": "^12.1.0",
|
|
44
45
|
"es-toolkit": "^1.29.0",
|
|
45
46
|
"react-markdown": "^8.0.7",
|
package/styles/global.scss
CHANGED
|
@@ -4,3 +4,36 @@ td {
|
|
|
4
4
|
display: inline-block;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
.doom-btn {
|
|
9
|
+
position: relative;
|
|
10
|
+
padding: 0 !important;
|
|
11
|
+
|
|
12
|
+
> span {
|
|
13
|
+
display: block;
|
|
14
|
+
padding: 0 20px;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.doom-collapse-group {
|
|
19
|
+
.rspress-directive {
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
padding-top: 10px;
|
|
22
|
+
padding-bottom: 10px;
|
|
23
|
+
border-radius: 0;
|
|
24
|
+
|
|
25
|
+
&:first-child {
|
|
26
|
+
border-top-left-radius: var(--rp-radius-small);
|
|
27
|
+
border-top-right-radius: var(--rp-radius-small);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:last-child {
|
|
31
|
+
border-bottom-left-radius: var(--rp-radius-small);
|
|
32
|
+
border-bottom-right-radius: var(--rp-radius-small);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
+ .rspress-directive {
|
|
36
|
+
margin-top: -1px;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|