@vx-oss/docs-story 1.0.7 → 1.0.9
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 +2 -2
- package/dist/next/index.js +4 -2
- package/dist/node_modules/.pnpm/{react-error-boundary@6.1.4_@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 +1 -1
- package/dist/utils/generate.js +44 -8
- package/dist/utils/transform.js +7 -5
- package/dist/vite/index.js +3 -2
- package/dist/webpack/story.js +3 -2
- package/package.json +10 -10
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 docs-story's Vite plugin or Next loader.
|
|
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(`[docs-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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { collapse } from "./type-tree/builder.js";
|
|
2
2
|
import { cached } from "./cache/index.js";
|
|
3
3
|
import { require_deepmerge } from "./node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js";
|
|
4
|
-
import { createControlsProject, generateControls } from "./utils/generate.js";
|
|
4
|
+
import { createControlsProject, generateControls, getStoryClientModes } from "./utils/generate.js";
|
|
5
5
|
import { createFileSystemCache } from "./cache/fs.js";
|
|
6
6
|
import * as fs$1 from "node:fs/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -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(getStoryClientModes("next", fileURLToPath(new URL("./next/client.js", import.meta.url))), project, filePath, name, fileContent);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
return { defineStory(urlOrPath, { Component, name = "story", displayName, args = {} }) {
|
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
//#region src/next/index.ts
|
|
2
3
|
function createNextStory(createOptions = {}) {
|
|
3
4
|
const { filter = "*.story.{js,jsx,ts,tsx}", tsconfigPath } = createOptions;
|
|
5
|
+
const storyLoaderPath = fileURLToPath(new URL("../webpack/story.js", import.meta.url));
|
|
4
6
|
return (nextConfig = {}) => {
|
|
5
7
|
const loaderOptions = {};
|
|
6
8
|
if (tsconfigPath) loaderOptions.tsconfigPath = tsconfigPath;
|
|
@@ -9,7 +11,7 @@ function createNextStory(createOptions = {}) {
|
|
|
9
11
|
rules: {
|
|
10
12
|
...nextConfig.turbopack?.rules,
|
|
11
13
|
[filter]: { loaders: [{
|
|
12
|
-
loader:
|
|
14
|
+
loader: storyLoaderPath,
|
|
13
15
|
options: loaderOptions
|
|
14
16
|
}] }
|
|
15
17
|
}
|
|
@@ -24,7 +26,7 @@ function createNextStory(createOptions = {}) {
|
|
|
24
26
|
test: filter,
|
|
25
27
|
enforce: "pre",
|
|
26
28
|
use: [{
|
|
27
|
-
loader:
|
|
29
|
+
loader: storyLoaderPath,
|
|
28
30
|
options: loaderOptions
|
|
29
31
|
}]
|
|
30
32
|
});
|
|
@@ -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,
|
package/dist/utils/generate.js
CHANGED
|
@@ -4,6 +4,13 @@ import { createProject } from "./project.js";
|
|
|
4
4
|
async function createControlsProject(tsconfigPath) {
|
|
5
5
|
return createProject(tsconfigPath);
|
|
6
6
|
}
|
|
7
|
+
const publicStoryClientModes = {
|
|
8
|
+
next: ["@vezham/docs-story/next/client", "@vx-oss/docs-story/next/client"],
|
|
9
|
+
vite: ["@vezham/docs-story/vite/client", "@vx-oss/docs-story/vite/client"]
|
|
10
|
+
};
|
|
11
|
+
function getStoryClientModes(kind, clientPath) {
|
|
12
|
+
return clientPath ? [clientPath, ...publicStoryClientModes[kind]] : publicStoryClientModes[kind];
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* The type alias declaration to append to story files, for resolving the props of a story.
|
|
9
16
|
*/
|
|
@@ -14,12 +21,10 @@ function getControlsAlias(mode, exportName) {
|
|
|
14
21
|
code: `export type ${name} = import('${mode}').GetProps<typeof ${exportName}>;`
|
|
15
22
|
};
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*/
|
|
22
|
-
function generateControls(mode, project, filePath, exportName, content) {
|
|
24
|
+
function isResolvedControls(node) {
|
|
25
|
+
return node.type !== "never";
|
|
26
|
+
}
|
|
27
|
+
function generateControlsForMode(mode, project, filePath, exportName, content) {
|
|
23
28
|
const alias = getControlsAlias(mode, exportName);
|
|
24
29
|
if (!content.includes(alias.code)) content = `${content}\n${alias.code}`;
|
|
25
30
|
const loaded = project.getSourceFile(filePath, content);
|
|
@@ -31,7 +36,38 @@ function generateControls(mode, project, filePath, exportName, content) {
|
|
|
31
36
|
const declaration = exports.find((symbol) => symbol.name === alias.name)?.declarations[0]?.resolve(tsProject);
|
|
32
37
|
const type = declaration ? checker.getTypeAtLocation(declaration) : void 0;
|
|
33
38
|
if (!declaration || !type || !exports.some((symbol) => symbol.name === exportName)) throw new Error(`Export "${exportName}" not found in file "${filePath}"`);
|
|
34
|
-
return
|
|
39
|
+
return {
|
|
40
|
+
controls: createTypeTreeBuilder(tsProject, [literalEnumHandler]).typeToNode(type, declaration),
|
|
41
|
+
mode
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate controls for an exported story, also returning the mode that resolved its types.
|
|
46
|
+
*
|
|
47
|
+
* @param content - content of the story file, the alias declaration of `getControlsAlias()` is appended when missing.
|
|
48
|
+
*/
|
|
49
|
+
function generateControlsWithMode(mode, project, filePath, exportName, content) {
|
|
50
|
+
const modes = typeof mode === "string" ? [mode] : mode;
|
|
51
|
+
let fallback;
|
|
52
|
+
let firstError;
|
|
53
|
+
for (const item of modes) try {
|
|
54
|
+
const generated = generateControlsForMode(item, project, filePath, exportName, content);
|
|
55
|
+
if (isResolvedControls(generated.controls)) return generated;
|
|
56
|
+
fallback ??= generated;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
firstError ??= error;
|
|
59
|
+
}
|
|
60
|
+
if (fallback) return fallback;
|
|
61
|
+
if (firstError) throw firstError;
|
|
62
|
+
throw new Error(`Export "${exportName}" not found in file "${filePath}"`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generate controls for an exported story.
|
|
66
|
+
*
|
|
67
|
+
* @param content - content of the story file, the alias declaration of `getControlsAlias()` is appended when missing.
|
|
68
|
+
*/
|
|
69
|
+
function generateControls(mode, project, filePath, exportName, content) {
|
|
70
|
+
return generateControlsWithMode(mode, project, filePath, exportName, content).controls;
|
|
35
71
|
}
|
|
36
72
|
//#endregion
|
|
37
|
-
export { createControlsProject, generateControls, getControlsAlias };
|
|
73
|
+
export { createControlsProject, generateControls, generateControlsWithMode, getControlsAlias, getStoryClientModes, publicStoryClientModes };
|
package/dist/utils/transform.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serialize } from "./serialization.js";
|
|
2
|
-
import {
|
|
2
|
+
import { generateControlsWithMode, getControlsAlias } from "./generate.js";
|
|
3
3
|
import { findDefineStoryCalls } from "./parse.js";
|
|
4
4
|
import { isObjectLiteralExpression, isPropertyAssignment } from "typescript/unstable/ast";
|
|
5
5
|
//#region src/utils/transform.ts
|
|
@@ -45,13 +45,15 @@ function transformStoryFile(mode, code, id, project) {
|
|
|
45
45
|
if (!loaded) throw new Error(`Failed to load "${id}" into TypeScript project`);
|
|
46
46
|
const calls = findDefineStoryCalls(loaded.project, loaded.sourceFile).filter((parsed) => parsed.call.arguments.length === 1);
|
|
47
47
|
if (calls.length === 0) return;
|
|
48
|
-
const aliases =
|
|
49
|
-
const content = [code, ...aliases.map((alias) => alias.code)].join("\n");
|
|
48
|
+
const aliases = [];
|
|
50
49
|
const edits = [];
|
|
51
50
|
for (const parsed of calls) {
|
|
52
51
|
const [optionsArg] = parsed.call.arguments;
|
|
53
|
-
if (!isObjectLiteralExpression(optionsArg)) throw new Error("defineStory() options must be an object literal to inject controls from
|
|
54
|
-
const
|
|
52
|
+
if (!isObjectLiteralExpression(optionsArg)) throw new Error("defineStory() options must be an object literal to inject controls from docs-story.");
|
|
53
|
+
const generated = generateControlsWithMode(mode, project, id, parsed.exportName, code);
|
|
54
|
+
const alias = getControlsAlias(generated.mode, parsed.exportName);
|
|
55
|
+
if (!code.includes(alias.code)) aliases.push(alias);
|
|
56
|
+
const controls = generated.controls;
|
|
55
57
|
edits.push(injectControls(loaded.sourceFile, optionsArg, parsed.exportName, controls));
|
|
56
58
|
}
|
|
57
59
|
return [applyEdits(code, edits), ...aliases.map((alias) => alias.code)].join("\n");
|
package/dist/vite/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createControlsProject } from "../utils/generate.js";
|
|
1
|
+
import { createControlsProject, getStoryClientModes } from "../utils/generate.js";
|
|
2
2
|
import { transformStoryFile } from "../utils/transform.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
//#region src/vite/index.ts
|
|
5
6
|
function story(pluginOptions = {}) {
|
|
@@ -16,7 +17,7 @@ function story(pluginOptions = {}) {
|
|
|
16
17
|
filter: { id: filter },
|
|
17
18
|
async handler(code, id) {
|
|
18
19
|
projectPromise ??= createControlsProject(tsconfigPath);
|
|
19
|
-
return transformStoryFile("
|
|
20
|
+
return transformStoryFile(getStoryClientModes("vite", fileURLToPath(new URL("./client.js", import.meta.url))), code, id, await projectPromise);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
};
|
package/dist/webpack/story.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createControlsProject } from "../utils/generate.js";
|
|
1
|
+
import { createControlsProject, getStoryClientModes } from "../utils/generate.js";
|
|
2
2
|
import { transformStoryFile } from "../utils/transform.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
//#region src/webpack/story.ts
|
|
5
6
|
let projectPromise;
|
|
@@ -13,7 +14,7 @@ const loader = function(source) {
|
|
|
13
14
|
projectPromise = createControlsProject(resolvedTsconfig);
|
|
14
15
|
}
|
|
15
16
|
try {
|
|
16
|
-
const transformed = transformStoryFile("
|
|
17
|
+
const transformed = transformStoryFile(getStoryClientModes("next", fileURLToPath(new URL("../next/client.js", import.meta.url))), source, this.resourcePath, await projectPromise);
|
|
17
18
|
callback(void 0, transformed ?? source);
|
|
18
19
|
} catch (error) {
|
|
19
20
|
if (!(error instanceof Error)) throw error;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vx-oss/docs-story",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Story integration to Fumadocs.",
|
|
5
5
|
"keywords": [],
|
|
6
|
+
"homepage": "https://vezham.com",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"author": "
|
|
8
|
+
"author": "Vx OSS Devs <oss-developers@vezham.com>",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "https://github.com/vezham/fumadocs",
|
|
@@ -37,8 +38,7 @@
|
|
|
37
38
|
"cn": "^0.2.4",
|
|
38
39
|
"lucide-react": "^1.39.0",
|
|
39
40
|
"typescript": "~7.0.2",
|
|
40
|
-
"
|
|
41
|
-
"@vx-oss/docs-stf": "1.0.7"
|
|
41
|
+
"@fumari/stf": "npm:@vx-oss/docs-stf@1.0.9"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@fastify/deepmerge": "^3.2.1",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"tsdown": "0.22.14",
|
|
55
55
|
"vite": "^8.2.2",
|
|
56
56
|
"webpack": "^5.110.3",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
57
|
+
"fumadocs-core": "npm:@vx-oss/docs-core@1.0.9",
|
|
58
|
+
"tsconfig": "0.0.0",
|
|
59
|
+
"fumadocs-ui": "npm:@vx-oss/docs-base-ui@1.0.9"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@types/react": "*",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
63
|
+
"fumadocs-core": "*",
|
|
64
|
+
"fumadocs-ui": "*",
|
|
65
65
|
"next": "^15.3.0 || ^16.0.0",
|
|
66
66
|
"react": "^19.2.0",
|
|
67
67
|
"react-dom": "^19.2.0",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"inlinedDependencies": {
|
|
86
86
|
"@fastify/deepmerge": "3.2.1",
|
|
87
87
|
"@ungap/structured-clone": "1.4.0",
|
|
88
|
-
"react-error-boundary": "6.1.
|
|
88
|
+
"react-error-boundary": "6.1.5"
|
|
89
89
|
},
|
|
90
90
|
"scripts": {
|
|
91
91
|
"build": "tsdown",
|