@vx-oss/docs-story 1.0.6 → 1.0.8
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/dist/client/arg-form.js +3 -3
- package/dist/client/compiled.d.ts +1 -1
- package/dist/client/compiled.js +1 -1
- package/dist/client/with-control.js +3 -3
- package/dist/i18n.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/next/index.js +2 -2
- package/dist/node_modules/.pnpm/{@ungap_structured-clone@1.3.4 → @ungap_structured-clone@1.4.0}/node_modules/@ungap/structured-clone/esm/deserialize.js +2 -1
- package/dist/node_modules/.pnpm/{@ungap_structured-clone@1.3.4 → @ungap_structured-clone@1.4.0}/node_modules/@ungap/structured-clone/esm/json.js +1 -1
- package/dist/node_modules/.pnpm/{@ungap_structured-clone@1.3.4 → @ungap_structured-clone@1.4.0}/node_modules/@ungap/structured-clone/esm/serialize.js +5 -2
- package/dist/node_modules/.pnpm/{react-error-boundary@6.1.3_@types_react@19.2.18_react@19.2.8 → react-error-boundary@6.1.5_@types_react@19.2.18_react@19.2.8}/node_modules/react-error-boundary/dist/react-error-boundary.js +4 -4
- package/dist/type-tree/builder.d.ts +5 -1
- package/dist/type-tree/builder.js +63 -48
- package/dist/utils/cn.js +1 -1
- package/dist/utils/generate.js +30 -17
- package/dist/utils/parse.js +21 -10
- package/dist/utils/project.js +85 -0
- package/dist/utils/serialization.js +1 -1
- package/dist/utils/transform.js +49 -16
- package/dist/vite/index.js +1 -1
- package/dist/webpack/story.js +1 -1
- package/package.json +19 -18
package/dist/client/arg-form.js
CHANGED
|
@@ -7,11 +7,11 @@ import { typeToString } from "../type-tree/stringify.js";
|
|
|
7
7
|
import { formatDateForInput } from "../utils/date.js";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { useState } from "react";
|
|
10
|
-
import { useArray, useDataEngine, useFieldValue, useNamespace, useObject } from "@
|
|
10
|
+
import { useArray, useDataEngine, useFieldValue, useNamespace, useObject } from "@fumari/stf";
|
|
11
11
|
import { ChevronRight, Plus, Trash2, X } from "lucide-react";
|
|
12
12
|
import { cva } from "class-variance-authority";
|
|
13
|
-
import { buttonVariants } from "
|
|
14
|
-
import { stringifyFieldKey } from "@
|
|
13
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
14
|
+
import { stringifyFieldKey } from "@fumari/stf/lib/utils";
|
|
15
15
|
import { useTranslations } from "@fuma-translate/react";
|
|
16
16
|
//#region src/client/arg-form.tsx
|
|
17
17
|
const labelVariants = cva("text-xs font-mono font-medium text-fd-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
|
|
@@ -10,7 +10,7 @@ interface StoryOptions<C extends FC<any>> {
|
|
|
10
10
|
*/
|
|
11
11
|
args?: ArgsOptions<C> | (ArgsOptions<C> & VariantInfo)[];
|
|
12
12
|
/**
|
|
13
|
-
* Controls & data generated at build time by `@
|
|
13
|
+
* Controls & data generated at build time by `@fumadocs/story/vite` or `@fumadocs/story/next`.
|
|
14
14
|
*
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
package/dist/client/compiled.js
CHANGED
|
@@ -24,7 +24,7 @@ function defineStoryFactory() {
|
|
|
24
24
|
else if (_generated) {
|
|
25
25
|
generatedControls ??= deserialize(_generated.controls);
|
|
26
26
|
controls = generatedControls;
|
|
27
|
-
} else throw new Error(`[@
|
|
27
|
+
} else throw new Error(`[@fumadocs/story] No generated data for story, make sure the Vite plugin or Turbopack loader is configured correctly`);
|
|
28
28
|
return {
|
|
29
29
|
variant: preset.variant,
|
|
30
30
|
description: preset.description,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../utils/cn.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./components/select.js";
|
|
4
|
-
import { ErrorBoundary as m } from "../node_modules/.pnpm/react-error-boundary@6.1.
|
|
4
|
+
import { ErrorBoundary as m } from "../node_modules/.pnpm/react-error-boundary@6.1.5_@types_react@19.2.18_react@19.2.8/node_modules/react-error-boundary/dist/react-error-boundary.js";
|
|
5
5
|
import { FieldSet } from "./arg-form.js";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { Suspense, createElement, useDeferredValue, useRef, useState } from "react";
|
|
8
|
-
import { StfProvider, useDataEngine, useListener, useStf } from "@
|
|
8
|
+
import { StfProvider, useDataEngine, useListener, useStf } from "@fumari/stf";
|
|
9
9
|
import { AlertCircle } from "lucide-react";
|
|
10
|
-
import { buttonVariants } from "
|
|
10
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
11
11
|
import { useTranslations } from "@fuma-translate/react";
|
|
12
12
|
//#region src/client/with-control.tsx
|
|
13
13
|
function WithControl({ presets, displayName, Component }) {
|
package/dist/i18n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Translations } from "./.translations/index.js";
|
|
2
|
-
import { TranslationExtension } from "
|
|
2
|
+
import { TranslationExtension } from "fumadocs-core/i18n";
|
|
3
3
|
//#region src/i18n.d.ts
|
|
4
4
|
declare function storyTranslations(): TranslationExtension<keyof Translations>;
|
|
5
5
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ function defineStoryFactory(factoryOptions = {}) {
|
|
|
26
26
|
const fileContent = await fs$1.readFile(filePath, "utf-8");
|
|
27
27
|
return cached(cache, getHash(`controls:${filePath}:${name}:${fileContent}`), async () => {
|
|
28
28
|
const project = await initProject();
|
|
29
|
-
return generateControls("@
|
|
29
|
+
return generateControls("@fumadocs/story/next/client", project, filePath, name, fileContent);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
return { defineStory(urlOrPath, { Component, name = "story", displayName, args = {} }) {
|
package/dist/next/index.js
CHANGED
|
@@ -9,7 +9,7 @@ function createNextStory(createOptions = {}) {
|
|
|
9
9
|
rules: {
|
|
10
10
|
...nextConfig.turbopack?.rules,
|
|
11
11
|
[filter]: { loaders: [{
|
|
12
|
-
loader: "@
|
|
12
|
+
loader: "@fumadocs/story/webpack/story",
|
|
13
13
|
options: loaderOptions
|
|
14
14
|
}] }
|
|
15
15
|
}
|
|
@@ -24,7 +24,7 @@ function createNextStory(createOptions = {}) {
|
|
|
24
24
|
test: filter,
|
|
25
25
|
enforce: "pre",
|
|
26
26
|
use: [{
|
|
27
|
-
loader: "@
|
|
27
|
+
loader: "@fumadocs/story/webpack/story",
|
|
28
28
|
options: loaderOptions
|
|
29
29
|
}]
|
|
30
30
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.
|
|
1
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/deserialize.js
|
|
2
2
|
const { defineProperty } = Object;
|
|
3
3
|
const env = typeof self === "object" ? self : globalThis;
|
|
4
4
|
const guard = (name, init) => {
|
|
@@ -68,6 +68,7 @@ const deserializer = ($, _) => {
|
|
|
68
68
|
const { buffer } = new Uint8Array(value);
|
|
69
69
|
return as(new DataView(buffer), value);
|
|
70
70
|
}
|
|
71
|
+
case "-0": return -0;
|
|
71
72
|
}
|
|
72
73
|
return as(guard(type, value), index);
|
|
73
74
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deserialize } from "./deserialize.js";
|
|
2
2
|
import { serialize } from "./serialize.js";
|
|
3
|
-
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.
|
|
3
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/json.js
|
|
4
4
|
/*! (c) Andrea Giammarchi - ISC */
|
|
5
5
|
const { parse: $parse, stringify: $stringify } = JSON;
|
|
6
6
|
const options = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.
|
|
1
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/serialize.js
|
|
2
2
|
const EMPTY = "";
|
|
3
3
|
const { toString } = {};
|
|
4
|
-
const { keys } = Object;
|
|
4
|
+
const { keys, is } = Object;
|
|
5
5
|
const typeOf = (value) => {
|
|
6
6
|
const type = typeof value;
|
|
7
7
|
if (type !== "object" || !value) return [0, type];
|
|
@@ -37,6 +37,9 @@ const serializer = (strict, json, $, _) => {
|
|
|
37
37
|
TYPE = 8;
|
|
38
38
|
entry = value.toString();
|
|
39
39
|
break;
|
|
40
|
+
case "number":
|
|
41
|
+
if (!value && is(value, -0)) return _.push(["-0"]) - 1;
|
|
42
|
+
break;
|
|
40
43
|
case "function":
|
|
41
44
|
case "symbol":
|
|
42
45
|
if (strict) throw new TypeError("unable to serialize " + type);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Component, createContext, createElement } from "react";
|
|
3
|
-
//#region ../../node_modules/.pnpm/react-error-boundary@6.1.
|
|
3
|
+
//#region ../../node_modules/.pnpm/react-error-boundary@6.1.5_@types+react@19.2.18_react@19.2.8/node_modules/react-error-boundary/dist/react-error-boundary.js
|
|
4
4
|
const h = createContext(null);
|
|
5
5
|
const c = {
|
|
6
6
|
didCatch: !1,
|
|
@@ -17,8 +17,8 @@ var m = class extends Component {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
resetErrorBoundary(...e) {
|
|
20
|
-
const {
|
|
21
|
-
t
|
|
20
|
+
const { didCatch: t } = this.state;
|
|
21
|
+
t && (this.props.onReset?.({
|
|
22
22
|
args: e,
|
|
23
23
|
reason: "imperative-api"
|
|
24
24
|
}), this.setState(c));
|
|
@@ -28,7 +28,7 @@ var m = class extends Component {
|
|
|
28
28
|
}
|
|
29
29
|
componentDidUpdate(e, t) {
|
|
30
30
|
const { didCatch: o } = this.state, { resetKeys: s } = this.props;
|
|
31
|
-
o && t.
|
|
31
|
+
o && t.didCatch && C(e.resetKeys, s) && (this.props.onReset?.({
|
|
32
32
|
next: s,
|
|
33
33
|
prev: e.resetKeys,
|
|
34
34
|
reason: "keys"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TypeNode, UnionNode } from "./types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Project, Type } from "typescript/unstable/sync";
|
|
3
|
+
import { Node } from "typescript/unstable/ast";
|
|
3
4
|
//#region src/type-tree/builder.d.ts
|
|
4
5
|
declare enum TypeToNodeFlag {
|
|
5
6
|
None = 0,
|
|
@@ -13,6 +14,9 @@ type Handler = (options: {
|
|
|
13
14
|
location: Node;
|
|
14
15
|
flag: TypeToNodeFlag;
|
|
15
16
|
builder: TypeTreeBuilder;
|
|
17
|
+
/**
|
|
18
|
+
* The TypeScript project (from `typescript/unstable/sync`) of the type, use `project.checker` for type checking.
|
|
19
|
+
*/
|
|
16
20
|
project: Project;
|
|
17
21
|
cache: Map<TypeToNodeFlag, WeakMap<Type, TypeNode>>;
|
|
18
22
|
getCache: () => TypeNode | undefined;
|
|
@@ -1,34 +1,56 @@
|
|
|
1
1
|
import { validate } from "./validator.js";
|
|
2
|
-
import {
|
|
2
|
+
import { NodeBuilderFlags, SignatureKind, SymbolFlags, TypeFlags, isBigIntLiteralType, isBooleanLiteralType, isIntersectionType, isLiteralType, isObjectType, isTypeReference, isUnionType } from "typescript/unstable/sync";
|
|
3
|
+
import { SyntaxKind, isEnumDeclaration, isNumericLiteral, isStringLiteral } from "typescript/unstable/ast";
|
|
3
4
|
//#region src/type-tree/builder.ts
|
|
4
5
|
let TypeToNodeFlag = /* @__PURE__ */ function(TypeToNodeFlag) {
|
|
5
6
|
TypeToNodeFlag[TypeToNodeFlag["None"] = 0] = "None";
|
|
6
7
|
TypeToNodeFlag[TypeToNodeFlag["NoIntersection"] = 1] = "NoIntersection";
|
|
7
8
|
return TypeToNodeFlag;
|
|
8
9
|
}({});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Private class members (`#name`) are exposed with their escaped name (`__#1@#name`) by TypeScript.
|
|
12
|
+
*/
|
|
13
|
+
function isPrivateName(name) {
|
|
14
|
+
return name.startsWith("#") || name.startsWith("__#");
|
|
15
|
+
}
|
|
16
|
+
function getLiteralValue(checker, type) {
|
|
17
|
+
if (isBooleanLiteralType(type)) return typeof type.value === "boolean" ? type.value : checker.typeToString(type) === "true";
|
|
18
|
+
if (isBigIntLiteralType(type)) {
|
|
19
|
+
const value = type.value;
|
|
20
|
+
if (typeof value === "bigint") return value;
|
|
21
|
+
if (typeof value === "object" && value !== null && "base10Value" in value) {
|
|
22
|
+
const { negative, base10Value } = value;
|
|
23
|
+
return BigInt(`${negative ? "-" : ""}${base10Value}`);
|
|
24
|
+
}
|
|
25
|
+
return BigInt(value);
|
|
26
|
+
}
|
|
27
|
+
return type.value ?? checker.typeToString(type);
|
|
28
|
+
}
|
|
29
|
+
const baseHandler = ({ type, flag, location, project, setCache, root }) => {
|
|
30
|
+
const { checker } = project;
|
|
31
|
+
const { flags } = type;
|
|
32
|
+
if (flags & TypeFlags.String) return { type: "string" };
|
|
33
|
+
if (flags & TypeFlags.Number) return { type: "number" };
|
|
34
|
+
if (flags & TypeFlags.Boolean) return { type: "boolean" };
|
|
35
|
+
if (flags & TypeFlags.BigInt) return { type: "bigint" };
|
|
14
36
|
const symbol = type.getSymbol();
|
|
15
|
-
if (symbol && symbol.
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
if (
|
|
19
|
-
if (
|
|
20
|
-
if (type
|
|
37
|
+
if (symbol && symbol.name === "Date") return { type: "date" };
|
|
38
|
+
if (flags & TypeFlags.Undefined) return { type: "undefined" };
|
|
39
|
+
if (flags & TypeFlags.Unknown) return { type: "unknown" };
|
|
40
|
+
if (flags & TypeFlags.Null) return { type: "null" };
|
|
41
|
+
if (flags & TypeFlags.Never || checker.getSignaturesOfType(type, SignatureKind.Call).length > 0) return { type: "never" };
|
|
42
|
+
if (isUnionType(type)) {
|
|
21
43
|
const result = {
|
|
22
44
|
type: "union",
|
|
23
45
|
types: []
|
|
24
46
|
};
|
|
25
47
|
setCache(result);
|
|
26
|
-
for (const t of type.
|
|
48
|
+
for (const t of type.getTypes()) result.types.push(root(t, flag));
|
|
27
49
|
Object.assign(result, unwrapUnion(result));
|
|
28
50
|
return result;
|
|
29
51
|
}
|
|
30
|
-
if (type
|
|
31
|
-
const intersectionTypes = type.
|
|
52
|
+
if (isIntersectionType(type) && (flag & 1) === 0) {
|
|
53
|
+
const intersectionTypes = type.getTypes();
|
|
32
54
|
const result = {
|
|
33
55
|
type: "intersection",
|
|
34
56
|
members: [],
|
|
@@ -42,18 +64,12 @@ const baseHandler = ({ type, flag, location, setCache, root }) => {
|
|
|
42
64
|
}
|
|
43
65
|
return result;
|
|
44
66
|
}
|
|
45
|
-
if (type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
type: "literal",
|
|
52
|
-
value
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (type.isArray() || type.isReadonlyArray()) {
|
|
56
|
-
const elementType = type.getArrayElementType();
|
|
67
|
+
if (isLiteralType(type)) return {
|
|
68
|
+
type: "literal",
|
|
69
|
+
value: getLiteralValue(checker, type)
|
|
70
|
+
};
|
|
71
|
+
if (checker.isArrayType(type)) {
|
|
72
|
+
const elementType = isTypeReference(type) ? checker.getTypeArguments(type)[0] : void 0;
|
|
57
73
|
const result = {
|
|
58
74
|
type: "array",
|
|
59
75
|
elementType: { type: "never" }
|
|
@@ -62,8 +78,8 @@ const baseHandler = ({ type, flag, location, setCache, root }) => {
|
|
|
62
78
|
result.elementType = elementType ? root(elementType, flag) : { type: "unknown" };
|
|
63
79
|
return result;
|
|
64
80
|
}
|
|
65
|
-
if (
|
|
66
|
-
const elements = type.
|
|
81
|
+
if (checker.isTupleType(type)) {
|
|
82
|
+
const elements = isTypeReference(type) ? checker.getTypeArguments(type) : [];
|
|
67
83
|
if (elements.length === 0) return {
|
|
68
84
|
type: "array",
|
|
69
85
|
elementType: { type: "unknown" }
|
|
@@ -79,20 +95,19 @@ const baseHandler = ({ type, flag, location, setCache, root }) => {
|
|
|
79
95
|
});
|
|
80
96
|
return result;
|
|
81
97
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (enumDeclaration && Node.isEnumDeclaration(enumDeclaration)) return {
|
|
98
|
+
if (symbol && symbol.flags & SymbolFlags.Enum) {
|
|
99
|
+
const enumDeclaration = symbol.valueDeclaration?.resolve(project);
|
|
100
|
+
if (enumDeclaration && isEnumDeclaration(enumDeclaration)) return {
|
|
86
101
|
type: "enum",
|
|
87
|
-
members: enumDeclaration.
|
|
88
|
-
const name = member.
|
|
89
|
-
const initializer = member.
|
|
102
|
+
members: enumDeclaration.members.map((member) => {
|
|
103
|
+
const name = member.name.getText();
|
|
104
|
+
const initializer = member.initializer;
|
|
90
105
|
let value = name;
|
|
91
106
|
if (initializer) {
|
|
92
|
-
if (
|
|
93
|
-
else if (
|
|
94
|
-
else if (
|
|
95
|
-
else if (
|
|
107
|
+
if (isStringLiteral(initializer)) value = initializer.getText().slice(1, -1);
|
|
108
|
+
else if (isNumericLiteral(initializer)) value = Number.parseFloat(initializer.getText());
|
|
109
|
+
else if (initializer.kind === SyntaxKind.TrueKeyword) value = true;
|
|
110
|
+
else if (initializer.kind === SyntaxKind.FalseKeyword) value = false;
|
|
96
111
|
}
|
|
97
112
|
return {
|
|
98
113
|
label: name,
|
|
@@ -101,35 +116,35 @@ const baseHandler = ({ type, flag, location, setCache, root }) => {
|
|
|
101
116
|
})
|
|
102
117
|
};
|
|
103
118
|
}
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
const properties = checker.getPropertiesOfType(type);
|
|
120
|
+
if (isObjectType(type) || properties.length > 0) {
|
|
106
121
|
const alias = type.getAliasSymbol();
|
|
107
122
|
const aliasTypeArguments = type.getAliasTypeArguments();
|
|
108
123
|
const result = {
|
|
109
124
|
type: "object",
|
|
110
|
-
displayName: alias && aliasTypeArguments.length === 0 ? alias.
|
|
125
|
+
displayName: alias && aliasTypeArguments.length === 0 ? alias.name : void 0,
|
|
111
126
|
properties: []
|
|
112
127
|
};
|
|
113
128
|
setCache(result);
|
|
114
129
|
for (const prop of properties) {
|
|
115
|
-
if (prop.
|
|
116
|
-
let child = root(
|
|
130
|
+
if (isPrivateName(prop.name)) continue;
|
|
131
|
+
let child = root(checker.getTypeOfSymbolAtLocation(prop, location), flag, prop.valueDeclaration?.resolve(project));
|
|
117
132
|
if (child.type === "union") child = unwrapUnion({
|
|
118
133
|
...child,
|
|
119
134
|
types: child.types.filter((t) => t.type !== "undefined")
|
|
120
135
|
});
|
|
121
136
|
else if (child.type === "undefined") continue;
|
|
122
137
|
if (child.type !== "never") result.properties.push({
|
|
123
|
-
name: prop.
|
|
138
|
+
name: prop.name,
|
|
124
139
|
type: child,
|
|
125
|
-
required:
|
|
140
|
+
required: (prop.flags & SymbolFlags.Optional) === 0
|
|
126
141
|
});
|
|
127
142
|
}
|
|
128
143
|
return result;
|
|
129
144
|
}
|
|
130
145
|
return {
|
|
131
146
|
type: "never",
|
|
132
|
-
displayName:
|
|
147
|
+
displayName: checker.typeToString(type, location, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope)
|
|
133
148
|
};
|
|
134
149
|
};
|
|
135
150
|
const literalEnumHandler = ({ type, flag, next }) => {
|
package/dist/utils/cn.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { cn } from "
|
|
1
|
+
import { cn } from "cn";
|
|
2
2
|
export { cn };
|
package/dist/utils/generate.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
import { createTypeTreeBuilder, literalEnumHandler } from "../type-tree/builder.js";
|
|
2
|
+
import { createProject } from "./project.js";
|
|
2
3
|
//#region src/utils/generate.ts
|
|
3
4
|
async function createControlsProject(tsconfigPath) {
|
|
4
|
-
|
|
5
|
-
return new Project({
|
|
6
|
-
tsConfigFilePath: tsconfigPath,
|
|
7
|
-
skipAddingFilesFromTsConfig: true
|
|
8
|
-
});
|
|
5
|
+
return createProject(tsconfigPath);
|
|
9
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* The type alias declaration to append to story files, for resolving the props of a story.
|
|
9
|
+
*/
|
|
10
|
+
function getControlsAlias(mode, exportName) {
|
|
11
|
+
const name = `_StoryProps_${exportName}_`;
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
code: `export type ${name} = import('${mode}').GetProps<typeof ${exportName}>;`
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate controls for an exported story.
|
|
19
|
+
*
|
|
20
|
+
* @param content - content of the story file, the alias declaration of `getControlsAlias()` is appended when missing.
|
|
21
|
+
*/
|
|
10
22
|
function generateControls(mode, project, filePath, exportName, content) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const declaration =
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const alias = getControlsAlias(mode, exportName);
|
|
24
|
+
if (!content.includes(alias.code)) content = `${content}\n${alias.code}`;
|
|
25
|
+
const loaded = project.getSourceFile(filePath, content);
|
|
26
|
+
if (!loaded) throw new Error(`Failed to load "${filePath}" into TypeScript project`);
|
|
27
|
+
const { project: tsProject, sourceFile } = loaded;
|
|
28
|
+
const { checker } = tsProject;
|
|
29
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
30
|
+
const exports = moduleSymbol ? checker.getExportsOfModule(moduleSymbol) : [];
|
|
31
|
+
const declaration = exports.find((symbol) => symbol.name === alias.name)?.declarations[0]?.resolve(tsProject);
|
|
32
|
+
const type = declaration ? checker.getTypeAtLocation(declaration) : void 0;
|
|
33
|
+
if (!declaration || !type || !exports.some((symbol) => symbol.name === exportName)) throw new Error(`Export "${exportName}" not found in file "${filePath}"`);
|
|
34
|
+
return createTypeTreeBuilder(tsProject, [literalEnumHandler]).typeToNode(type, declaration);
|
|
22
35
|
}
|
|
23
36
|
//#endregion
|
|
24
|
-
export { createControlsProject, generateControls };
|
|
37
|
+
export { createControlsProject, generateControls, getControlsAlias };
|
package/dist/utils/parse.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SymbolFlags } from "typescript/unstable/sync";
|
|
2
|
+
import { isCallExpression, isVariableDeclaration } from "typescript/unstable/ast";
|
|
2
3
|
//#region src/utils/parse.ts
|
|
3
4
|
function isDefineStoryCall(text) {
|
|
4
5
|
return text === "defineStory" || text.endsWith(".defineStory");
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Find `defineStory()` calls exported from the source file.
|
|
9
|
+
*/
|
|
10
|
+
function findDefineStoryCalls(project, sourceFile) {
|
|
11
|
+
const { checker } = project;
|
|
7
12
|
const stories = [];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
14
|
+
if (!moduleSymbol) return stories;
|
|
15
|
+
for (const exported of checker.getExportsOfModule(moduleSymbol)) {
|
|
16
|
+
const symbol = (exported.flags & SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(exported) : exported;
|
|
17
|
+
for (const handle of symbol.declarations) {
|
|
18
|
+
const decl = handle.resolve(project);
|
|
19
|
+
if (!decl || !isVariableDeclaration(decl) || decl.getSourceFile() !== sourceFile) continue;
|
|
20
|
+
const call = decl.initializer;
|
|
21
|
+
if (!call || !isCallExpression(call) || !isDefineStoryCall(call.expression.getText())) continue;
|
|
22
|
+
stories.push({
|
|
23
|
+
call,
|
|
24
|
+
exportName: exported.name
|
|
25
|
+
});
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
28
|
return stories;
|
|
18
29
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { API } from "typescript/unstable/sync";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utils/project.ts
|
|
5
|
+
function normalizePath(p) {
|
|
6
|
+
let out = path.resolve(p).replaceAll("\\", "/");
|
|
7
|
+
if (process.platform === "win32" && /^[A-Z]:/.test(out)) out = out[0].toLowerCase() + out.slice(1);
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
function readDiskFile(filePath) {
|
|
11
|
+
try {
|
|
12
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function createProject(tsconfigPath) {
|
|
18
|
+
tsconfigPath = normalizePath(tsconfigPath);
|
|
19
|
+
if (!fs.existsSync(tsconfigPath)) throw new Error(`tsconfig file not found: ${tsconfigPath}`);
|
|
20
|
+
const dir = path.posix.dirname(tsconfigPath);
|
|
21
|
+
/** in-memory files, overriding the file system */
|
|
22
|
+
const virtualFiles = /* @__PURE__ */ new Map();
|
|
23
|
+
/** root files of the generated tsconfig */
|
|
24
|
+
const rootFiles = /* @__PURE__ */ new Set();
|
|
25
|
+
let snapshot;
|
|
26
|
+
let configPath = `${dir}/tsconfig.fumadocs-story.json`;
|
|
27
|
+
for (let i = 0; fs.existsSync(configPath); i++) configPath = `${dir}/tsconfig.fumadocs-story.${i}.json`;
|
|
28
|
+
function writeConfig() {
|
|
29
|
+
virtualFiles.set(configPath, JSON.stringify({
|
|
30
|
+
extends: `./${path.posix.basename(tsconfigPath)}`,
|
|
31
|
+
include: [],
|
|
32
|
+
files: Array.from(rootFiles)
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
const api = new API({
|
|
36
|
+
cwd: dir,
|
|
37
|
+
fs: { readFile: (fileName) => virtualFiles.get(normalizePath(fileName)) }
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
api,
|
|
41
|
+
tsconfigPath,
|
|
42
|
+
getSourceFile(filePath, content) {
|
|
43
|
+
const key = normalizePath(filePath);
|
|
44
|
+
const changed = [];
|
|
45
|
+
const created = [];
|
|
46
|
+
if (content !== void 0) {
|
|
47
|
+
const current = virtualFiles.has(key) ? virtualFiles.get(key) : readDiskFile(key);
|
|
48
|
+
if (current !== content) {
|
|
49
|
+
virtualFiles.set(key, content);
|
|
50
|
+
if (current !== void 0) changed.push(key);
|
|
51
|
+
else created.push(key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!rootFiles.has(key)) {
|
|
55
|
+
rootFiles.add(key);
|
|
56
|
+
writeConfig();
|
|
57
|
+
changed.push(configPath);
|
|
58
|
+
}
|
|
59
|
+
if (!snapshot) snapshot = api.updateSnapshot({ openProjects: [configPath] });
|
|
60
|
+
else if (changed.length > 0 || created.length > 0) {
|
|
61
|
+
const prev = snapshot;
|
|
62
|
+
snapshot = api.updateSnapshot({ fileChanges: {
|
|
63
|
+
changed: changed.length > 0 ? changed : void 0,
|
|
64
|
+
created: created.length > 0 ? created : void 0
|
|
65
|
+
} });
|
|
66
|
+
prev.dispose();
|
|
67
|
+
}
|
|
68
|
+
const project = snapshot.getProject(configPath);
|
|
69
|
+
if (!project) return;
|
|
70
|
+
const sourceFile = project.program.getSourceFile(key);
|
|
71
|
+
if (!sourceFile) return;
|
|
72
|
+
return {
|
|
73
|
+
project,
|
|
74
|
+
sourceFile
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
close() {
|
|
78
|
+
snapshot?.dispose();
|
|
79
|
+
snapshot = void 0;
|
|
80
|
+
api.close();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createProject };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parse, stringify } from "../node_modules/.pnpm/@ungap_structured-clone@1.
|
|
1
|
+
import { parse, stringify } from "../node_modules/.pnpm/@ungap_structured-clone@1.4.0/node_modules/@ungap/structured-clone/esm/json.js";
|
|
2
2
|
//#region src/utils/serialization.ts
|
|
3
3
|
function serialize(value) {
|
|
4
4
|
return stringify(value);
|
package/dist/utils/transform.js
CHANGED
|
@@ -1,27 +1,60 @@
|
|
|
1
1
|
import { serialize } from "./serialization.js";
|
|
2
|
-
import { generateControls } from "./generate.js";
|
|
2
|
+
import { generateControls, getControlsAlias } from "./generate.js";
|
|
3
3
|
import { findDefineStoryCalls } from "./parse.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isObjectLiteralExpression, isPropertyAssignment } from "typescript/unstable/ast";
|
|
5
5
|
//#region src/utils/transform.ts
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
function getPropertyName(name) {
|
|
7
|
+
return /^['"`]/.test(name) ? name.slice(1, -1) : name;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create the edits to inject `_generated` into the options object literal
|
|
11
|
+
*/
|
|
12
|
+
function injectControls(sourceFile, object, exportName, controls) {
|
|
13
|
+
const initializer = `{ exportName: ${JSON.stringify(exportName)}, controls: ${JSON.stringify(serialize(controls))} }`;
|
|
14
|
+
const existing = object.properties.find((prop) => isPropertyAssignment(prop) && getPropertyName(prop.name.getText(sourceFile)) === "_generated");
|
|
15
|
+
if (existing) return {
|
|
16
|
+
start: existing.getStart(sourceFile),
|
|
17
|
+
end: existing.getEnd(),
|
|
18
|
+
text: `_generated: ${initializer}`
|
|
19
|
+
};
|
|
20
|
+
const last = object.properties.at(-1);
|
|
21
|
+
if (!last) {
|
|
22
|
+
const start = object.getStart(sourceFile) + 1;
|
|
23
|
+
return {
|
|
24
|
+
start,
|
|
25
|
+
end: start,
|
|
26
|
+
text: ` _generated: ${initializer} `
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const lastStart = last.getStart(sourceFile);
|
|
30
|
+
const lineStart = sourceFile.text.lastIndexOf("\n", lastStart) + 1;
|
|
31
|
+
const indent = /^\s*/.exec(sourceFile.text.slice(lineStart, lastStart))?.[0] ?? "";
|
|
32
|
+
return {
|
|
33
|
+
start: last.getEnd(),
|
|
34
|
+
end: last.getEnd(),
|
|
35
|
+
text: `,\n${indent}_generated: ${initializer}`
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function applyEdits(code, edits) {
|
|
39
|
+
let out = code;
|
|
40
|
+
for (const edit of edits.toSorted((a, b) => b.start - a.start)) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
41
|
+
return out;
|
|
15
42
|
}
|
|
16
43
|
function transformStoryFile(mode, code, id, project) {
|
|
17
|
-
const
|
|
18
|
-
|
|
44
|
+
const loaded = project.getSourceFile(id, code);
|
|
45
|
+
if (!loaded) throw new Error(`Failed to load "${id}" into TypeScript project`);
|
|
46
|
+
const calls = findDefineStoryCalls(loaded.project, loaded.sourceFile).filter((parsed) => parsed.call.arguments.length === 1);
|
|
19
47
|
if (calls.length === 0) return;
|
|
48
|
+
const aliases = calls.map((parsed) => getControlsAlias(mode, parsed.exportName)).filter((alias) => !code.includes(alias.code));
|
|
49
|
+
const content = [code, ...aliases.map((alias) => alias.code)].join("\n");
|
|
50
|
+
const edits = [];
|
|
20
51
|
for (const parsed of calls) {
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
const [optionsArg] = parsed.call.arguments;
|
|
53
|
+
if (!isObjectLiteralExpression(optionsArg)) throw new Error("defineStory() options must be an object literal to inject controls from @fumadocs/story.");
|
|
54
|
+
const controls = generateControls(mode, project, id, parsed.exportName, content);
|
|
55
|
+
edits.push(injectControls(loaded.sourceFile, optionsArg, parsed.exportName, controls));
|
|
23
56
|
}
|
|
24
|
-
return
|
|
57
|
+
return [applyEdits(code, edits), ...aliases.map((alias) => alias.code)].join("\n");
|
|
25
58
|
}
|
|
26
59
|
//#endregion
|
|
27
60
|
export { transformStoryFile };
|
package/dist/vite/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function story(pluginOptions = {}) {
|
|
|
16
16
|
filter: { id: filter },
|
|
17
17
|
async handler(code, id) {
|
|
18
18
|
projectPromise ??= createControlsProject(tsconfigPath);
|
|
19
|
-
return transformStoryFile("@
|
|
19
|
+
return transformStoryFile("@fumadocs/story/vite/client", code, id, await projectPromise);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
};
|
package/dist/webpack/story.js
CHANGED
|
@@ -13,7 +13,7 @@ const loader = function(source) {
|
|
|
13
13
|
projectPromise = createControlsProject(resolvedTsconfig);
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
|
-
const transformed = transformStoryFile("@
|
|
16
|
+
const transformed = transformStoryFile("@fumadocs/story/next/client", source, this.resourcePath, await projectPromise);
|
|
17
17
|
callback(void 0, transformed ?? source);
|
|
18
18
|
} catch (error) {
|
|
19
19
|
if (!(error instanceof Error)) throw error;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vx-oss/docs-story",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Story integration to Fumadocs.",
|
|
5
5
|
"keywords": [],
|
|
6
|
+
"homepage": "https://vezham.com",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"author": "Fuma Nama",
|
|
8
9
|
"repository": {
|
|
@@ -34,38 +35,38 @@
|
|
|
34
35
|
"@base-ui/react": "^1.7.0",
|
|
35
36
|
"@fuma-translate/react": "^1.0.2",
|
|
36
37
|
"class-variance-authority": "^0.7.1",
|
|
37
|
-
"
|
|
38
|
-
"lucide-react": "^1.
|
|
39
|
-
"
|
|
40
|
-
"@vx-oss/docs-stf
|
|
38
|
+
"cn": "^0.2.4",
|
|
39
|
+
"lucide-react": "^1.39.0",
|
|
40
|
+
"typescript": "~7.0.2",
|
|
41
|
+
"@fumari/stf": "npm:@vx-oss/docs-stf@1.0.8"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@fastify/deepmerge": "^3.2.1",
|
|
44
|
-
"@types/node": "26.
|
|
45
|
+
"@types/node": "26.4.1",
|
|
45
46
|
"@types/react": "^19.2.18",
|
|
46
47
|
"@types/ungap__structured-clone": "^1.2.0",
|
|
47
|
-
"@ungap/structured-clone": "^1.
|
|
48
|
-
"next": "^16.3.
|
|
48
|
+
"@ungap/structured-clone": "^1.4.0",
|
|
49
|
+
"next": "^16.3.4",
|
|
49
50
|
"react": "^19.2.8",
|
|
50
51
|
"react-dom": "^19.2.8",
|
|
51
|
-
"react-error-boundary": "^6.1.
|
|
52
|
+
"react-error-boundary": "^6.1.4",
|
|
52
53
|
"tailwindcss": "^4.3.3",
|
|
53
54
|
"tsdown": "0.22.14",
|
|
54
55
|
"vite": "^8.2.2",
|
|
55
|
-
"webpack": "^5.
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
56
|
+
"webpack": "^5.110.3",
|
|
57
|
+
"fumadocs-core": "npm:@vx-oss/docs-core@1.0.8",
|
|
58
|
+
"fumadocs-ui": "npm:@vx-oss/docs-base-ui@1.0.8",
|
|
59
|
+
"tsconfig": "0.0.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"@types/react": "*",
|
|
63
|
+
"fumadocs-core": "*",
|
|
64
|
+
"fumadocs-ui": "*",
|
|
62
65
|
"next": "^15.3.0 || ^16.0.0",
|
|
63
66
|
"react": "^19.2.0",
|
|
64
67
|
"react-dom": "^19.2.0",
|
|
65
68
|
"vite": "^8",
|
|
66
|
-
"webpack": "^5"
|
|
67
|
-
"@vx-oss/docs-core": "^1.0.4",
|
|
68
|
-
"@vx-oss/docs-react": "^1.0.4"
|
|
69
|
+
"webpack": "^5"
|
|
69
70
|
},
|
|
70
71
|
"peerDependenciesMeta": {
|
|
71
72
|
"next": {
|
|
@@ -83,8 +84,8 @@
|
|
|
83
84
|
},
|
|
84
85
|
"inlinedDependencies": {
|
|
85
86
|
"@fastify/deepmerge": "3.2.1",
|
|
86
|
-
"@ungap/structured-clone": "1.
|
|
87
|
-
"react-error-boundary": "6.1.
|
|
87
|
+
"@ungap/structured-clone": "1.4.0",
|
|
88
|
+
"react-error-boundary": "6.1.5"
|
|
88
89
|
},
|
|
89
90
|
"scripts": {
|
|
90
91
|
"build": "tsdown",
|