@vx-oss/docs-story 1.0.3
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/LICENSE +21 -0
- package/css/preset.css +1 -0
- package/dist/.translations/index.d.ts +18 -0
- package/dist/.translations/keys.js +18 -0
- package/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/cache/fs.d.ts +5 -0
- package/dist/cache/fs.js +22 -0
- package/dist/cache/index.d.ts +11 -0
- package/dist/cache/index.js +15 -0
- package/dist/client/arg-form.js +357 -0
- package/dist/client/compiled.d.ts +52 -0
- package/dist/client/compiled.js +47 -0
- package/dist/client/components/input.js +13 -0
- package/dist/client/components/select.js +78 -0
- package/dist/client/with-control.d.ts +8 -0
- package/dist/client/with-control.js +104 -0
- package/dist/i18n.d.ts +6 -0
- package/dist/i18n.js +7 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +74 -0
- package/dist/next/client.d.ts +2 -0
- package/dist/next/client.js +2 -0
- package/dist/next/index.d.ts +14 -0
- package/dist/next/index.js +37 -0
- package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js +110 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/deserialize.js +86 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/json.js +23 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/serialize.js +119 -0
- package/dist/node_modules/.pnpm/react-error-boundary@6.1.3_@types_react@19.2.18_react@19.2.8/node_modules/react-error-boundary/dist/react-error-boundary.js +61 -0
- package/dist/type-tree/builder.d.ts +41 -0
- package/dist/type-tree/builder.js +240 -0
- package/dist/type-tree/index.d.ts +6 -0
- package/dist/type-tree/index.js +5 -0
- package/dist/type-tree/sampler.d.ts +5 -0
- package/dist/type-tree/sampler.js +21 -0
- package/dist/type-tree/stringify.d.ts +9 -0
- package/dist/type-tree/stringify.js +20 -0
- package/dist/type-tree/types.d.ts +67 -0
- package/dist/type-tree/validator.d.ts +5 -0
- package/dist/type-tree/validator.js +21 -0
- package/dist/utils/cn.js +2 -0
- package/dist/utils/date.js +6 -0
- package/dist/utils/generate.js +24 -0
- package/dist/utils/parse.js +20 -0
- package/dist/utils/serialization.js +10 -0
- package/dist/utils/transform.js +27 -0
- package/dist/vite/client.d.ts +2 -0
- package/dist/vite/client.js +2 -0
- package/dist/vite/index.d.ts +19 -0
- package/dist/vite/index.js +25 -0
- package/dist/webpack/story.d.ts +13 -0
- package/dist/webpack/story.js +26 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fuma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/css/preset.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@source '../dist/client/**/*.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/.translations/index.d.ts
|
|
2
|
+
type Translations = {
|
|
3
|
+
"Encountered error when rendering the component.(story error boundary)": string;
|
|
4
|
+
"Enter bigint(story arguments form)": string;
|
|
5
|
+
"Enter date(story arguments form)": string;
|
|
6
|
+
"Enter number(story arguments form)": string;
|
|
7
|
+
"Enter text(story arguments form)": string;
|
|
8
|
+
"False(story arguments form)": string;
|
|
9
|
+
"New Item(story arguments form)": string;
|
|
10
|
+
"No Variant(story controls)": string;
|
|
11
|
+
"Props(story controls)": string;
|
|
12
|
+
"Remove Item(story arguments form)(aria-label)": string;
|
|
13
|
+
"Reset(story error boundary)": string;
|
|
14
|
+
"True(story arguments form)": string;
|
|
15
|
+
"Unset(story arguments form)": string;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Translations };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/.translations/keys.json
|
|
2
|
+
var keys_default = [
|
|
3
|
+
"Encountered error when rendering the component.(story error boundary)",
|
|
4
|
+
"Enter bigint(story arguments form)",
|
|
5
|
+
"Enter date(story arguments form)",
|
|
6
|
+
"Enter number(story arguments form)",
|
|
7
|
+
"Enter text(story arguments form)",
|
|
8
|
+
"False(story arguments form)",
|
|
9
|
+
"New Item(story arguments form)",
|
|
10
|
+
"No Variant(story controls)",
|
|
11
|
+
"Props(story controls)",
|
|
12
|
+
"Remove Item(story arguments form)(aria-label)",
|
|
13
|
+
"Reset(story error boundary)",
|
|
14
|
+
"True(story arguments form)",
|
|
15
|
+
"Unset(story arguments form)"
|
|
16
|
+
];
|
|
17
|
+
//#endregion
|
|
18
|
+
export { keys_default as default };
|
package/dist/cache/fs.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import * as path$1 from "node:path";
|
|
3
|
+
//#region src/cache/fs.ts
|
|
4
|
+
function createFileSystemCache(dir) {
|
|
5
|
+
dir = path$1.resolve(dir);
|
|
6
|
+
const initDirPromise = fs.mkdir(dir, { recursive: true }).catch(() => {});
|
|
7
|
+
return {
|
|
8
|
+
async write(key, data) {
|
|
9
|
+
await initDirPromise;
|
|
10
|
+
await fs.writeFile(path$1.join(dir, `${key}.json`), data);
|
|
11
|
+
},
|
|
12
|
+
async read(key) {
|
|
13
|
+
try {
|
|
14
|
+
return await fs.readFile(path$1.join(dir, `${key}.json`), "utf-8");
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { createFileSystemCache };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/cache/index.d.ts
|
|
2
|
+
type Awaitable<T> = T | Promise<T>;
|
|
3
|
+
/**
|
|
4
|
+
* cache utf-8 serialized value (e.g. JSON)
|
|
5
|
+
*/
|
|
6
|
+
interface Cache {
|
|
7
|
+
read: (key: string) => Awaitable<string | undefined>;
|
|
8
|
+
write: (key: string, value: string) => Awaitable<void>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Cache };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { deserialize, serialize } from "../utils/serialization.js";
|
|
2
|
+
//#region src/cache/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Note: the returned value is always re-constructed, direct modifications will not pollute the cached values.
|
|
5
|
+
*/
|
|
6
|
+
async function cached(cache, key, op) {
|
|
7
|
+
if (cache === false) return op();
|
|
8
|
+
const cached = await cache.read(key);
|
|
9
|
+
if (cached) return deserialize(cached);
|
|
10
|
+
const out = await op();
|
|
11
|
+
await cache.write(key, serialize(out));
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { cached };
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { validate } from "../type-tree/validator.js";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./components/select.js";
|
|
4
|
+
import { Input } from "./components/input.js";
|
|
5
|
+
import { getDefaultValue } from "../type-tree/sampler.js";
|
|
6
|
+
import { typeToString } from "../type-tree/stringify.js";
|
|
7
|
+
import { formatDateForInput } from "../utils/date.js";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { useArray, useDataEngine, useFieldValue, useNamespace, useObject } from "@vx-oss/docs-stf";
|
|
11
|
+
import { ChevronRight, Plus, Trash2, X } from "lucide-react";
|
|
12
|
+
import { cva } from "class-variance-authority";
|
|
13
|
+
import { buttonVariants } from "@vx-oss/docs-react/components/ui/button";
|
|
14
|
+
import { stringifyFieldKey } from "@vx-oss/docs-stf/lib/utils";
|
|
15
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
16
|
+
//#region src/client/arg-form.tsx
|
|
17
|
+
const labelVariants = cva("text-xs font-mono font-medium text-fd-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
|
|
18
|
+
function FieldLabel(props) {
|
|
19
|
+
return /* @__PURE__ */ jsx("label", {
|
|
20
|
+
...props,
|
|
21
|
+
className: cn("w-full inline-flex items-center gap-0.5", props.className),
|
|
22
|
+
children: props.children
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function FieldLabelRequired() {
|
|
26
|
+
return /* @__PURE__ */ jsx("span", {
|
|
27
|
+
className: "text-red-400/80 mx-1",
|
|
28
|
+
children: "*"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function FieldLabelType(props) {
|
|
32
|
+
return /* @__PURE__ */ jsx("code", {
|
|
33
|
+
...props,
|
|
34
|
+
className: cn("text-xs text-fd-muted-foreground", props.className),
|
|
35
|
+
children: props.children
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function ObjectInput({ field: node, fieldName, ...props }) {
|
|
39
|
+
const { properties } = useObject(fieldName, {
|
|
40
|
+
defaultValue: () => getDefaultValue(node),
|
|
41
|
+
properties: Object.fromEntries(node.properties.map((prop) => [prop.name, prop.type]))
|
|
42
|
+
});
|
|
43
|
+
return /* @__PURE__ */ jsx("div", {
|
|
44
|
+
...props,
|
|
45
|
+
className: cn("grid grid-cols-1 gap-4 @md:grid-cols-2", props.className),
|
|
46
|
+
children: properties.map((child) => {
|
|
47
|
+
const prop = node.properties.find((p) => p.name === child.key);
|
|
48
|
+
if (!prop) return null;
|
|
49
|
+
return /* @__PURE__ */ jsx(FieldSet, {
|
|
50
|
+
name: child.key,
|
|
51
|
+
field: prop.type,
|
|
52
|
+
fieldName: child.field,
|
|
53
|
+
isRequired: prop.required
|
|
54
|
+
}, child.key);
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function FieldInput({ field, fieldName, isRequired, ...props }) {
|
|
59
|
+
const engine = useDataEngine();
|
|
60
|
+
const t = useTranslations({ note: "story arguments form" });
|
|
61
|
+
const [value, setValue] = useFieldValue(fieldName);
|
|
62
|
+
const id = stringifyFieldKey(fieldName);
|
|
63
|
+
function renderUnset(children) {
|
|
64
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
65
|
+
...props,
|
|
66
|
+
className: cn("flex flex-row gap-2", props.className),
|
|
67
|
+
children: [children, value !== void 0 && !isRequired && /* @__PURE__ */ jsx("button", {
|
|
68
|
+
type: "button",
|
|
69
|
+
onClick: () => engine.delete(fieldName),
|
|
70
|
+
className: "text-fd-muted-foreground",
|
|
71
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (field.type === "null" || field.type === "undefined" || field.type === "never" || field.type === "unknown" || field.type === "literal") return null;
|
|
76
|
+
if (field.type === "enum") {
|
|
77
|
+
const idx = field.members.findIndex((m) => m.value === value);
|
|
78
|
+
const items = field.members.map((member, i) => ({
|
|
79
|
+
value: i,
|
|
80
|
+
label: member.label
|
|
81
|
+
}));
|
|
82
|
+
if (!isRequired) items.push({
|
|
83
|
+
value: -1,
|
|
84
|
+
label: /* @__PURE__ */ jsx("span", {
|
|
85
|
+
className: "text-fd-muted-foreground",
|
|
86
|
+
children: t("Unset")
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
90
|
+
items,
|
|
91
|
+
value: idx === -1 && isRequired ? null : idx,
|
|
92
|
+
onValueChange: (index) => {
|
|
93
|
+
if (index === null) return;
|
|
94
|
+
if (index >= 0 && index < field.members.length) setValue(field.members[index].value);
|
|
95
|
+
else setValue(void 0);
|
|
96
|
+
},
|
|
97
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
98
|
+
id,
|
|
99
|
+
...props,
|
|
100
|
+
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
101
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
102
|
+
value: item.value,
|
|
103
|
+
children: item.label
|
|
104
|
+
}, item.value)) })]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (field.type === "boolean") {
|
|
108
|
+
const items = [
|
|
109
|
+
{
|
|
110
|
+
value: true,
|
|
111
|
+
label: t("True")
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: false,
|
|
115
|
+
label: t("False")
|
|
116
|
+
},
|
|
117
|
+
...!isRequired ? [{
|
|
118
|
+
value: null,
|
|
119
|
+
label: /* @__PURE__ */ jsx("span", {
|
|
120
|
+
className: "text-fd-muted-foreground",
|
|
121
|
+
children: t("Unset")
|
|
122
|
+
})
|
|
123
|
+
}] : []
|
|
124
|
+
];
|
|
125
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
126
|
+
items,
|
|
127
|
+
value: typeof value === "boolean" ? value : null,
|
|
128
|
+
onValueChange: (val) => setValue(val === null ? void 0 : val),
|
|
129
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
130
|
+
id,
|
|
131
|
+
...props,
|
|
132
|
+
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
133
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map((item) => /* @__PURE__ */ jsx(SelectItem, {
|
|
134
|
+
value: item.value,
|
|
135
|
+
children: item.label
|
|
136
|
+
}, String(item.value))) })]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (field.type === "date") return renderUnset(/* @__PURE__ */ jsx(Input, {
|
|
140
|
+
id,
|
|
141
|
+
placeholder: t("Enter date"),
|
|
142
|
+
type: "date",
|
|
143
|
+
value: value instanceof Date ? formatDateForInput(value) : "",
|
|
144
|
+
onChange: (e) => {
|
|
145
|
+
setValue(e.target.valueAsDate ?? void 0);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
return renderUnset(/* @__PURE__ */ jsx(Input, {
|
|
149
|
+
id,
|
|
150
|
+
placeholder: field.type === "number" ? t("Enter number") : field.type === "bigint" ? t("Enter bigint") : t("Enter text"),
|
|
151
|
+
type: field.type === "number" || field.type === "bigint" ? "number" : "text",
|
|
152
|
+
value: String(value ?? ""),
|
|
153
|
+
onChange: (e) => {
|
|
154
|
+
if (field.type === "bigint") try {
|
|
155
|
+
setValue(BigInt(e.target.value));
|
|
156
|
+
} catch {
|
|
157
|
+
setValue(void 0);
|
|
158
|
+
}
|
|
159
|
+
else if (field.type === "number") setValue(Number.isNaN(e.target.valueAsNumber) ? void 0 : e.target.valueAsNumber);
|
|
160
|
+
else setValue(e.target.value);
|
|
161
|
+
}
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
function FieldSet({ depth = 0, field: _field, fieldName, toolbar, name, isRequired, slotType, collapsible = true, ...rest }) {
|
|
165
|
+
const field = _field.type === "intersection" ? _field.intersection : _field;
|
|
166
|
+
const [show, setShow] = useState(!collapsible);
|
|
167
|
+
const { info, updateInfo } = useFieldInfo(fieldName, field, depth);
|
|
168
|
+
const id = stringifyFieldKey(fieldName);
|
|
169
|
+
const dataEngine = useDataEngine();
|
|
170
|
+
const onShow = () => {
|
|
171
|
+
dataEngine.init(fieldName, getDefaultValue(field));
|
|
172
|
+
setShow((prev) => !prev);
|
|
173
|
+
};
|
|
174
|
+
if (field.type === "never") return;
|
|
175
|
+
if (field.type === "union") {
|
|
176
|
+
const showSelect = field.types.length > 1;
|
|
177
|
+
const selectedType = field.types[info.unionIndex] ?? field.types[0];
|
|
178
|
+
return /* @__PURE__ */ jsx(FieldSet, {
|
|
179
|
+
...rest,
|
|
180
|
+
name,
|
|
181
|
+
depth: depth + 1,
|
|
182
|
+
fieldName,
|
|
183
|
+
isRequired,
|
|
184
|
+
field: selectedType,
|
|
185
|
+
slotType: showSelect ? false : slotType,
|
|
186
|
+
toolbar: /* @__PURE__ */ jsxs(Fragment, { children: [showSelect && /* @__PURE__ */ jsx("select", {
|
|
187
|
+
className: "text-xs font-mono",
|
|
188
|
+
value: info.unionIndex,
|
|
189
|
+
onChange: (e) => {
|
|
190
|
+
updateInfo({ unionIndex: Number(e.target.value) });
|
|
191
|
+
},
|
|
192
|
+
children: field.types.map((item, i) => /* @__PURE__ */ jsx("option", {
|
|
193
|
+
value: i,
|
|
194
|
+
className: "bg-fd-popover text-fd-popover-foreground",
|
|
195
|
+
children: typeToString(item, 1)
|
|
196
|
+
}, i))
|
|
197
|
+
}), toolbar] })
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (field.type === "object") return /* @__PURE__ */ jsxs("fieldset", {
|
|
201
|
+
...rest,
|
|
202
|
+
className: cn("flex flex-col gap-1.5 col-span-full @container", rest.className),
|
|
203
|
+
children: [/* @__PURE__ */ jsxs(FieldLabel, {
|
|
204
|
+
htmlFor: id,
|
|
205
|
+
children: [
|
|
206
|
+
collapsible && /* @__PURE__ */ jsx("button", {
|
|
207
|
+
type: "button",
|
|
208
|
+
onClick: onShow,
|
|
209
|
+
className: cn(buttonVariants({
|
|
210
|
+
size: "icon-xs",
|
|
211
|
+
color: "ghost",
|
|
212
|
+
className: "text-fd-muted-foreground"
|
|
213
|
+
})),
|
|
214
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: cn(show && "rotate-90") })
|
|
215
|
+
}),
|
|
216
|
+
/* @__PURE__ */ jsxs("button", {
|
|
217
|
+
type: "button",
|
|
218
|
+
onClick: onShow,
|
|
219
|
+
className: cn(labelVariants(), "me-auto"),
|
|
220
|
+
children: [name, isRequired && /* @__PURE__ */ jsx(FieldLabelRequired, {})]
|
|
221
|
+
}),
|
|
222
|
+
slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: typeToString(field) }),
|
|
223
|
+
toolbar
|
|
224
|
+
]
|
|
225
|
+
}), show && /* @__PURE__ */ jsx(ObjectInput, {
|
|
226
|
+
field,
|
|
227
|
+
fieldName,
|
|
228
|
+
className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
|
|
229
|
+
})]
|
|
230
|
+
});
|
|
231
|
+
if (field.type === "array") return /* @__PURE__ */ jsxs("fieldset", {
|
|
232
|
+
...rest,
|
|
233
|
+
className: cn("flex flex-col gap-1.5 col-span-full", rest.className),
|
|
234
|
+
children: [/* @__PURE__ */ jsxs(FieldLabel, {
|
|
235
|
+
htmlFor: id,
|
|
236
|
+
children: [
|
|
237
|
+
collapsible && /* @__PURE__ */ jsx("button", {
|
|
238
|
+
type: "button",
|
|
239
|
+
onClick: onShow,
|
|
240
|
+
className: cn(buttonVariants({
|
|
241
|
+
size: "icon-xs",
|
|
242
|
+
color: "ghost",
|
|
243
|
+
className: "text-fd-muted-foreground -ms-1"
|
|
244
|
+
})),
|
|
245
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: cn(show && "rotate-90") })
|
|
246
|
+
}),
|
|
247
|
+
/* @__PURE__ */ jsxs("button", {
|
|
248
|
+
type: "button",
|
|
249
|
+
onClick: onShow,
|
|
250
|
+
className: cn(labelVariants(), "me-auto"),
|
|
251
|
+
children: [name, isRequired && /* @__PURE__ */ jsx(FieldLabelRequired, {})]
|
|
252
|
+
}),
|
|
253
|
+
slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: typeToString(field) }),
|
|
254
|
+
toolbar
|
|
255
|
+
]
|
|
256
|
+
}), show && /* @__PURE__ */ jsx(ArrayInput, {
|
|
257
|
+
fieldName,
|
|
258
|
+
items: field.elementType,
|
|
259
|
+
className: "rounded-lg border border-fd-primary/20 bg-fd-background/50 p-2 shadow-sm"
|
|
260
|
+
})]
|
|
261
|
+
});
|
|
262
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
263
|
+
...rest,
|
|
264
|
+
className: cn("flex flex-col gap-1.5", rest.className),
|
|
265
|
+
children: [/* @__PURE__ */ jsxs(FieldLabel, {
|
|
266
|
+
htmlFor: id,
|
|
267
|
+
children: [
|
|
268
|
+
/* @__PURE__ */ jsxs("span", {
|
|
269
|
+
className: cn(labelVariants(), "me-auto"),
|
|
270
|
+
children: [name, isRequired && /* @__PURE__ */ jsx(FieldLabelRequired, {})]
|
|
271
|
+
}),
|
|
272
|
+
slotType ?? /* @__PURE__ */ jsx(FieldLabelType, { children: typeToString(field) }),
|
|
273
|
+
toolbar
|
|
274
|
+
]
|
|
275
|
+
}), /* @__PURE__ */ jsx(FieldInput, {
|
|
276
|
+
field,
|
|
277
|
+
fieldName,
|
|
278
|
+
isRequired
|
|
279
|
+
})]
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function ArrayInput({ fieldName, items: itemType, ...props }) {
|
|
283
|
+
const t = useTranslations({ note: "story arguments form" });
|
|
284
|
+
const name = fieldName.at(-1) ?? "";
|
|
285
|
+
const { items, insertItem, removeItem } = useArray(fieldName, { defaultValue: [] });
|
|
286
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
287
|
+
...props,
|
|
288
|
+
className: cn("flex flex-col gap-2", props.className),
|
|
289
|
+
children: [items.map((item) => /* @__PURE__ */ jsx(FieldSet, {
|
|
290
|
+
name: /* @__PURE__ */ jsxs("span", {
|
|
291
|
+
className: "text-fd-muted-foreground",
|
|
292
|
+
children: [
|
|
293
|
+
name,
|
|
294
|
+
"[",
|
|
295
|
+
item.index,
|
|
296
|
+
"]"
|
|
297
|
+
]
|
|
298
|
+
}),
|
|
299
|
+
field: itemType,
|
|
300
|
+
isRequired: true,
|
|
301
|
+
fieldName: item.field,
|
|
302
|
+
toolbar: /* @__PURE__ */ jsx("button", {
|
|
303
|
+
type: "button",
|
|
304
|
+
"aria-label": t("Remove Item", { note: "aria-label" }),
|
|
305
|
+
className: cn(buttonVariants({
|
|
306
|
+
color: "outline",
|
|
307
|
+
size: "icon-xs"
|
|
308
|
+
})),
|
|
309
|
+
onClick: () => removeItem(item.index),
|
|
310
|
+
children: /* @__PURE__ */ jsx(Trash2, {})
|
|
311
|
+
})
|
|
312
|
+
}, item.index)), /* @__PURE__ */ jsxs("button", {
|
|
313
|
+
type: "button",
|
|
314
|
+
className: cn(buttonVariants({
|
|
315
|
+
color: "secondary",
|
|
316
|
+
className: "gap-1.5 py-2",
|
|
317
|
+
size: "sm"
|
|
318
|
+
})),
|
|
319
|
+
onClick: () => {
|
|
320
|
+
insertItem(getDefaultValue(itemType));
|
|
321
|
+
},
|
|
322
|
+
children: [/* @__PURE__ */ jsx(Plus, { className: "size-4" }), t("New Item")]
|
|
323
|
+
})]
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* A hook to store dynamic info of a field, such as selected type in union.
|
|
328
|
+
*/
|
|
329
|
+
function useFieldInfo(fieldName, node, depth = 0) {
|
|
330
|
+
const engine = useDataEngine();
|
|
331
|
+
const fieldData = useNamespace({
|
|
332
|
+
namespace: `field-info:${depth}:${stringifyFieldKey(fieldName)}`,
|
|
333
|
+
initial() {
|
|
334
|
+
const out = { unionIndex: 0 };
|
|
335
|
+
if (node.type === "union") {
|
|
336
|
+
const matchingIndex = node.types.findIndex(validate);
|
|
337
|
+
out.unionIndex = matchingIndex === -1 ? 0 : matchingIndex;
|
|
338
|
+
}
|
|
339
|
+
return out;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
const [info, setInfo] = useFieldValue([], { stf: fieldData });
|
|
343
|
+
return {
|
|
344
|
+
info,
|
|
345
|
+
updateInfo(value) {
|
|
346
|
+
const updated = {
|
|
347
|
+
...info,
|
|
348
|
+
...value
|
|
349
|
+
};
|
|
350
|
+
if (updated.unionIndex === info.unionIndex) return;
|
|
351
|
+
setInfo(updated);
|
|
352
|
+
if (node.type === "union" && node.types[updated.unionIndex]) engine.update(fieldName, getDefaultValue(node.types[updated.unionIndex]));
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
export { FieldInput, FieldSet, ObjectInput };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TypeNode } from "../type-tree/types.js";
|
|
2
|
+
import { VariantInfo } from "./with-control.js";
|
|
3
|
+
import { ComponentPropsWithoutRef, FC, ReactNode } from "react";
|
|
4
|
+
//#region src/client/compiled.d.ts
|
|
5
|
+
interface StoryOptions<C extends FC<any>> {
|
|
6
|
+
displayName?: string;
|
|
7
|
+
Component: C;
|
|
8
|
+
/**
|
|
9
|
+
* story arguments, you can pass an array of options for multiple presets.
|
|
10
|
+
*/
|
|
11
|
+
args?: ArgsOptions<C> | (ArgsOptions<C> & VariantInfo)[];
|
|
12
|
+
/**
|
|
13
|
+
* Controls & data generated at build time by `@vx-oss/docs-story/vite` or `@vx-oss/docs-story/next`.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
_generated?: {
|
|
18
|
+
exportName: string;
|
|
19
|
+
controls: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface ArgsOptions<C extends FC<any> = FC<any>> {
|
|
23
|
+
/**
|
|
24
|
+
* the default values of arguments.
|
|
25
|
+
*/
|
|
26
|
+
initial?: ComponentPropsWithoutRef<C> | (() => ComponentPropsWithoutRef<C>);
|
|
27
|
+
/**
|
|
28
|
+
* fixed values for arguments, will disable the relevant controls.
|
|
29
|
+
*/
|
|
30
|
+
fixed?: Partial<ComponentPropsWithoutRef<C>> | (() => Partial<ComponentPropsWithoutRef<C>>);
|
|
31
|
+
/**
|
|
32
|
+
* customize the generated controls, by default generated from component props using TypeScript compiler.
|
|
33
|
+
*/
|
|
34
|
+
controls?: {
|
|
35
|
+
node: TypeNode;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
interface Story<C extends FC<any> = FC<any>> {
|
|
39
|
+
/** render as a component. */
|
|
40
|
+
WithControl: FC;
|
|
41
|
+
_private_: {
|
|
42
|
+
component?: C;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
type GetProps<Result> = Result extends Story<infer C> ? ReplaceReactNode<Omit<ComponentPropsWithoutRef<C>, 'key'>> : never;
|
|
46
|
+
type ReplaceReactNode<V> = ReactNode extends V ? ReplaceReactNode<Exclude<V, ReactNode>> | string : V extends Record<string, unknown> ? { [K in keyof V]: ReplaceReactNode<V[K]>; } : V;
|
|
47
|
+
interface StoryFactory {
|
|
48
|
+
defineStory: <C extends FC<any>>(options: StoryOptions<C>) => Story<C>;
|
|
49
|
+
}
|
|
50
|
+
declare function defineStoryFactory(): StoryFactory;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { ArgsOptions, GetProps, Story, StoryFactory, StoryOptions, defineStoryFactory };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { deserialize } from "../utils/serialization.js";
|
|
2
|
+
import { require_deepmerge } from "../node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js";
|
|
3
|
+
import { WithControl } from "./with-control.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
//#region src/client/compiled.tsx
|
|
7
|
+
var import_deepmerge = require_deepmerge();
|
|
8
|
+
function defineStoryFactory() {
|
|
9
|
+
const propsDeepmerge = (0, import_deepmerge.deepmerge)({ mergeArray: () => (_target, source) => source });
|
|
10
|
+
return { defineStory({ Component, displayName, args = {}, _generated }) {
|
|
11
|
+
let generatedControls;
|
|
12
|
+
function getProps() {
|
|
13
|
+
return {
|
|
14
|
+
Component,
|
|
15
|
+
displayName,
|
|
16
|
+
presets: (Array.isArray(args) ? args : [{
|
|
17
|
+
...args,
|
|
18
|
+
variant: "default"
|
|
19
|
+
}]).map((preset) => {
|
|
20
|
+
const fixedValues = typeof preset.fixed === "function" ? preset.fixed() : preset.fixed;
|
|
21
|
+
const initial = typeof preset.initial === "function" ? preset.initial() : preset.initial;
|
|
22
|
+
let controls;
|
|
23
|
+
if (preset.controls && "node" in preset.controls) controls = preset.controls.node;
|
|
24
|
+
else if (_generated) {
|
|
25
|
+
generatedControls ??= deserialize(_generated.controls);
|
|
26
|
+
controls = generatedControls;
|
|
27
|
+
} else throw new Error(`[@vx-oss/docs-story] No generated data for story, make sure the Vite plugin or Turbopack loader is configured correctly`);
|
|
28
|
+
return {
|
|
29
|
+
variant: preset.variant,
|
|
30
|
+
description: preset.description,
|
|
31
|
+
controls,
|
|
32
|
+
defaultValues: fixedValues ? propsDeepmerge(initial, fixedValues) : initial
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
_private_: { component: Component },
|
|
39
|
+
WithControl() {
|
|
40
|
+
const props = useMemo(getProps, []);
|
|
41
|
+
return /* @__PURE__ */ jsx(WithControl, { ...props });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} };
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { defineStoryFactory };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import "react";
|
|
4
|
+
//#region src/client/components/input.tsx
|
|
5
|
+
function Input({ className, type, ...props }) {
|
|
6
|
+
return /* @__PURE__ */ jsx("input", {
|
|
7
|
+
type,
|
|
8
|
+
className: cn("flex h-9 w-full rounded-md border bg-fd-secondary px-2 py-1.5 text-[0.8125rem] text-fd-secondary-foreground transition-colors placeholder:text-fd-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50", className),
|
|
9
|
+
...props
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Input };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import "react";
|
|
4
|
+
import { Select } from "@base-ui/react/select";
|
|
5
|
+
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
|
6
|
+
import { cva } from "class-variance-authority";
|
|
7
|
+
//#region src/client/components/select.tsx
|
|
8
|
+
const Select$1 = Select.Root;
|
|
9
|
+
Select.Group;
|
|
10
|
+
const SelectValue = Select.Value;
|
|
11
|
+
const triggerVariants = cva("flex items-center w-full rounded-md gap-2 text-start text-sm focus:outline-none focus:ring focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50", {
|
|
12
|
+
variants: { variant: {
|
|
13
|
+
default: "border p-2 text-fd-secondary-foreground bg-fd-secondary hover:bg-fd-accent hover:text-fd-accent-foreground",
|
|
14
|
+
ghost: "px-1.5 py-1 hover:bg-fd-accent hover:text-fd-accent-foreground"
|
|
15
|
+
} },
|
|
16
|
+
defaultVariants: { variant: "default" }
|
|
17
|
+
});
|
|
18
|
+
function SelectTrigger({ className, variant, children, ref, ...props }) {
|
|
19
|
+
return /* @__PURE__ */ jsxs(Select.Trigger, {
|
|
20
|
+
ref,
|
|
21
|
+
className: cn(triggerVariants({ variant }), className),
|
|
22
|
+
...props,
|
|
23
|
+
children: [children, /* @__PURE__ */ jsx(Select.Icon, {
|
|
24
|
+
className: "ms-auto text-fd-muted-foreground shrink-0",
|
|
25
|
+
children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5" })
|
|
26
|
+
})]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function SelectScrollUpButton({ className, ref, ...props }) {
|
|
30
|
+
return /* @__PURE__ */ jsx(Select.ScrollUpArrow, {
|
|
31
|
+
ref,
|
|
32
|
+
className: cn("flex items-center justify-center py-1", className),
|
|
33
|
+
...props,
|
|
34
|
+
children: /* @__PURE__ */ jsx(ChevronUp, { className: "size-4" })
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function SelectScrollDownButton({ className, ref, ...props }) {
|
|
38
|
+
return /* @__PURE__ */ jsx(Select.ScrollDownArrow, {
|
|
39
|
+
ref,
|
|
40
|
+
className: cn("flex items-center justify-center py-1", className),
|
|
41
|
+
...props,
|
|
42
|
+
children: /* @__PURE__ */ jsx(ChevronDown, { className: "size-4" })
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function SelectContent({ className, children, align = "start", side = "bottom", sideOffset = 4, ref, ...props }) {
|
|
46
|
+
return /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, {
|
|
47
|
+
align,
|
|
48
|
+
side,
|
|
49
|
+
sideOffset,
|
|
50
|
+
className: "z-50",
|
|
51
|
+
children: /* @__PURE__ */ jsxs(Select.Popup, {
|
|
52
|
+
ref,
|
|
53
|
+
className: cn("z-50 min-w-(--anchor-width) overflow-hidden rounded-lg border bg-fd-popover text-fd-popover-foreground shadow-md", className),
|
|
54
|
+
...props,
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ jsx(SelectScrollUpButton, {}),
|
|
57
|
+
/* @__PURE__ */ jsx(Select.List, {
|
|
58
|
+
className: "p-1",
|
|
59
|
+
children
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ jsx(SelectScrollDownButton, {})
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
}) });
|
|
65
|
+
}
|
|
66
|
+
function SelectItem({ className, children, ref, ...props }) {
|
|
67
|
+
return /* @__PURE__ */ jsxs(Select.Item, {
|
|
68
|
+
ref,
|
|
69
|
+
className: cn("flex select-none flex-row items-center rounded-md gap-2 py-1.5 px-2 text-sm outline-none data-[highlighted]:bg-fd-accent data-[highlighted]:text-fd-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className),
|
|
70
|
+
...props,
|
|
71
|
+
children: [/* @__PURE__ */ jsx(Select.ItemText, { children }), /* @__PURE__ */ jsx(Select.ItemIndicator, {
|
|
72
|
+
className: "ms-auto",
|
|
73
|
+
children: /* @__PURE__ */ jsx(Check, { className: "size-3.5 text-fd-primary" })
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Select$1 as Select, SelectContent, SelectItem, SelectScrollDownButton, SelectScrollUpButton, SelectTrigger, SelectValue };
|