Skip to content

Commit 68d2673

Browse files
committed
docs: update documentation
1 parent 8f42654 commit 68d2673

30 files changed

+1760
-1855
lines changed

packages/react-ui/src/hooks/use-element-transition-status/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { type FloatingContext, useTransitionStatus, type UseTransitionStatusProps } from "@floating-ui/react";
2-
import { useState } from "react";
2+
import { useCallback, useState } from "react";
33

44
export const useElementTransitionStatus = <E extends HTMLElement = HTMLElement>(
55
open: boolean,
66
props?: UseTransitionStatusProps,
77
) => {
88
const [elementState, setElementState] = useState<E | null>(null);
99

10-
const setElement = (node: E | null) => {
10+
const setElement = useCallback((node: E | null) => {
1111
setElementState(node);
12-
};
12+
}, []);
1313

1414
const { isMounted, status } = useTransitionStatus(
1515
{

website/.env.development

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_GIT_COMMIT_SHA="5fa7f68"

website/plugins/remark-docgen.js

+40-196
Original file line numberDiff line numberDiff line change
@@ -17,210 +17,54 @@ export default function ({ sourceRoot }) {
1717

1818
mkdirSync(virtualDir, { recursive: true });
1919

20-
const usageVirtualDir = join(cwd(), ".resolid", "code-demos");
20+
return (tree) => {
21+
visit(tree, { type: "leafDirective", name: "PropsTable" }, (node, index, parent) => {
22+
if (parent === undefined || index === undefined) {
23+
return;
24+
}
2125

22-
mkdirSync(usageVirtualDir, { recursive: true });
26+
const componentFile = node.attributes["file"];
2327

24-
return (tree, vfile) => {
25-
const pageName = vfile.basename.replace(vfile.extname, "");
28+
if (!componentFile) {
29+
throw new Error(`Invalid componentFile prop for ${node.name}.`);
30+
}
2631

27-
let usageIndex = 1;
32+
const componentName = (parse(componentFile).name.match(kebabCaseRegex) || [])
33+
.map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
34+
.join("");
2835

29-
const usageMdx = [];
36+
if (!propsTables[componentName]) {
37+
const componentProps = getComponentProps(virtualDir, join(sourceRoot, componentFile), componentName);
3038

31-
visit(
32-
tree,
33-
[
34-
{ type: "leafDirective", name: "PropsTable" },
35-
{ type: "containerDirective", name: "UsageBlock" },
36-
],
37-
(node, index, parent) => {
38-
const componentFile = node.attributes["file"];
39-
40-
if (!componentFile) {
41-
throw new Error(`Invalid componentFile prop for ${node.name}.`);
39+
if (componentProps) {
40+
propsTables[componentName] = componentProps;
4241
}
43-
44-
const componentName = (parse(componentFile).name.match(kebabCaseRegex) || [])
45-
.map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
46-
.join("");
47-
48-
if (!propsTables[componentName]) {
49-
const componentProps = getComponentProps(virtualDir, join(sourceRoot, componentFile), componentName);
50-
51-
if (componentProps) {
52-
propsTables[componentName] = componentProps;
53-
}
54-
}
55-
56-
if (propsTables[componentName]) {
57-
const propsJSON = JSON.stringify(propsTables[componentName]);
58-
59-
if (parent === undefined || index === undefined) {
60-
return;
61-
}
62-
63-
if (node.name === "UsageBlock") {
64-
const usageId = `_${pageName}_u_${usageIndex++}`;
65-
const usageName = `U_${usageId.replace("-", "_")}`;
66-
const virtualModulePath = join(usageVirtualDir, `${usageId}.tsx`);
67-
68-
usageMdx.push({
69-
type: "mdxjsEsm",
70-
value: `import ${usageName} from ${JSON.stringify(virtualModulePath)}`,
71-
data: {
72-
estree: {
73-
type: "Program",
74-
sourceType: "module",
75-
body: [
76-
{
77-
type: "ImportDeclaration",
78-
specifiers: [
79-
{
80-
type: "ImportDefaultSpecifier",
81-
local: { type: "Identifier", name: usageName },
82-
},
83-
],
84-
source: {
85-
type: "Literal",
86-
value: virtualModulePath,
87-
raw: `${JSON.stringify(virtualModulePath)}`,
88-
},
89-
},
90-
],
42+
}
43+
44+
if (propsTables[componentName]) {
45+
const propsJSON = JSON.stringify(propsTables[componentName]);
46+
47+
parent.children[index] = {
48+
type: "mdxJsxFlowElement",
49+
name: "PropsTable",
50+
attributes: [
51+
{
52+
type: "mdxJsxAttribute",
53+
name: "props",
54+
value: {
55+
type: "mdxJsxAttributeValueExpression",
56+
value: `(${propsJSON})`,
57+
data: {
58+
estree: fromJs(`(${propsJSON})`, {
59+
module: true,
60+
}),
9161
},
9262
},
93-
});
94-
95-
const ignoresJson = JSON.stringify(node.attributes["ignores"]?.split(",") ?? []);
96-
const code = node.children.map((child) => child.value).join("\n");
97-
98-
parent.children[index] = {
99-
type: "mdxJsxFlowElement",
100-
name: "UsageBlock",
101-
attributes: [
102-
{
103-
type: "mdxJsxAttribute",
104-
name: "props",
105-
value: {
106-
type: "mdxJsxAttributeValueExpression",
107-
value: `(${propsJSON})`,
108-
data: {
109-
estree: fromJs(`(${propsJSON})`, {
110-
module: true,
111-
}),
112-
},
113-
},
114-
},
115-
{
116-
type: "mdxJsxAttribute",
117-
name: "ignores",
118-
value: {
119-
type: "mdxJsxAttributeValueExpression",
120-
value: `(${ignoresJson})`,
121-
data: {
122-
estree: fromJs(`(${ignoresJson})`, {
123-
module: true,
124-
}),
125-
},
126-
},
127-
},
128-
],
129-
children: [
130-
{
131-
type: "mdxFlowExpression",
132-
value: `(props) => <${usageName} {...props} />`,
133-
data: {
134-
estree: {
135-
type: "Program",
136-
body: [
137-
{
138-
type: "ExpressionStatement",
139-
expression: {
140-
type: "ArrowFunctionExpression",
141-
id: null,
142-
expression: true,
143-
generator: false,
144-
async: false,
145-
params: [
146-
{
147-
type: "Identifier",
148-
name: "props",
149-
},
150-
],
151-
body: {
152-
type: "JSXElement",
153-
openingElement: {
154-
type: "JSXOpeningElement",
155-
attributes: [
156-
{
157-
type: "JSXSpreadAttribute",
158-
argument: {
159-
type: "Identifier",
160-
name: "props",
161-
},
162-
},
163-
],
164-
name: {
165-
type: "JSXIdentifier",
166-
name: usageName,
167-
},
168-
selfClosing: true,
169-
},
170-
closingElement: null,
171-
children: [],
172-
data: {
173-
_mdxExplicitJsx: true,
174-
},
175-
},
176-
},
177-
},
178-
],
179-
sourceType: "module",
180-
comments: [],
181-
},
182-
},
183-
},
184-
],
185-
};
186-
187-
if (existsSync(virtualModulePath)) {
188-
const content = readFileSync(virtualModulePath, "utf8");
189-
190-
if (content === code) {
191-
return;
192-
}
193-
}
194-
195-
writeFileSync(virtualModulePath, code, "utf8");
196-
}
197-
198-
if (node.name === "PropsTable") {
199-
parent.children[index] = {
200-
type: "mdxJsxFlowElement",
201-
name: "PropsTable",
202-
attributes: [
203-
{
204-
type: "mdxJsxAttribute",
205-
name: "props",
206-
value: {
207-
type: "mdxJsxAttributeValueExpression",
208-
value: `(${propsJSON})`,
209-
data: {
210-
estree: fromJs(`(${propsJSON})`, {
211-
module: true,
212-
}),
213-
},
214-
},
215-
},
216-
],
217-
};
218-
}
219-
}
220-
},
221-
);
222-
223-
tree.children.unshift(...usageMdx);
63+
},
64+
],
65+
};
66+
}
67+
});
22468
};
22569
}
22670

website/src/assets/sandbox/index.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</style>
1212
</head>
1313
<body class="min-h-screen">
14-
<div id="root" class="p-8 min-h-[calc(100vh-5em)]"></div>
14+
<div id="root" class="p-8 flex flex-col items-center gap-3 min-h-[calc(100vh-5em)]"></div>
1515
<div class="p-5 text-sm flex item-center border-t gap-3 border-bd-normal">
1616
<span>${name} 组件</span>
1717
<a class="text-link" href="https://ui.resolid.tech" rel="noreferrer" target="_blank">Resolid UI</a>

website/src/components/stackblitz-button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const sandbox = import.meta.glob<string>(
1717

1818
const commitSha = import.meta.env.VITE_VERCEL_GIT_COMMIT_SHA
1919
? import.meta.env.VITE_VERCEL_GIT_COMMIT_SHA.slice(0, 8)
20-
: "c0df27e";
20+
: import.meta.env.VITE_GIT_COMMIT_SHA.slice(0, 8);
2121

2222
const createHiddenInput = (name: string, value: string) => {
2323
const input = document.createElement("input");

0 commit comments

Comments
 (0)