@toriistudio/v0-playground 0.2.0 → 0.2.2
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/index.js +26 -16
- package/dist/index.mjs +23 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(src_exports);
|
|
39
39
|
|
|
40
40
|
// src/components/Playground/Playground.tsx
|
|
41
|
-
var
|
|
41
|
+
var import_react6 = require("react");
|
|
42
42
|
|
|
43
43
|
// src/context/ResizableLayout.tsx
|
|
44
44
|
var import_react = require("react");
|
|
@@ -273,9 +273,28 @@ var PreviewContainer = ({ children, hideControls }) => {
|
|
|
273
273
|
var PreviewContainer_default = PreviewContainer;
|
|
274
274
|
|
|
275
275
|
// src/components/ControlPanel/ControlPanel.tsx
|
|
276
|
-
var
|
|
276
|
+
var import_react5 = require("react");
|
|
277
277
|
var import_lucide_react3 = require("lucide-react");
|
|
278
278
|
|
|
279
|
+
// src/hooks/usePreviewUrl.ts
|
|
280
|
+
var import_react4 = require("react");
|
|
281
|
+
var usePreviewUrl = (values, basePath = "") => {
|
|
282
|
+
const [url, setUrl] = (0, import_react4.useState)("");
|
|
283
|
+
(0, import_react4.useEffect)(() => {
|
|
284
|
+
if (typeof window === "undefined") return;
|
|
285
|
+
const params = new URLSearchParams();
|
|
286
|
+
params.set("nocontrols", "true");
|
|
287
|
+
for (const [key, value] of Object.entries(values)) {
|
|
288
|
+
if (value !== void 0 && value !== null) {
|
|
289
|
+
params.set(key, value.toString());
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const fullUrl = `${basePath || window.location.pathname}?${params.toString()}`;
|
|
293
|
+
setUrl(fullUrl);
|
|
294
|
+
}, [values, basePath]);
|
|
295
|
+
return url;
|
|
296
|
+
};
|
|
297
|
+
|
|
279
298
|
// src/components/ui/switch.tsx
|
|
280
299
|
var React4 = __toESM(require("react"));
|
|
281
300
|
var SwitchPrimitives = __toESM(require("@radix-ui/react-switch"));
|
|
@@ -530,26 +549,17 @@ Button.displayName = "Button";
|
|
|
530
549
|
// src/components/ControlPanel/ControlPanel.tsx
|
|
531
550
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
532
551
|
var ControlPanel = () => {
|
|
533
|
-
const [copied, setCopied] = (0,
|
|
552
|
+
const [copied, setCopied] = (0, import_react5.useState)(false);
|
|
534
553
|
const { leftPanelWidth, isDesktop, isHydrated, sidebarNarrow } = useResizableLayout();
|
|
535
554
|
const { schema, setValue, values, componentName } = useControlsContext();
|
|
555
|
+
const previewUrl = usePreviewUrl(values);
|
|
536
556
|
const normalControls = Object.entries(schema).filter(
|
|
537
557
|
([, control]) => control.type !== "button"
|
|
538
558
|
);
|
|
539
559
|
const buttonControls = Object.entries(schema).filter(
|
|
540
560
|
([, control]) => control.type === "button"
|
|
541
561
|
);
|
|
542
|
-
const
|
|
543
|
-
const params = new URLSearchParams();
|
|
544
|
-
params.set("nocontrols", "true");
|
|
545
|
-
for (const [key, value] of Object.entries(values)) {
|
|
546
|
-
if (value !== void 0 && value !== null) {
|
|
547
|
-
params.set(key, value.toString());
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return `${window.location.pathname}?${params.toString()}`;
|
|
551
|
-
}, [values]);
|
|
552
|
-
const jsx12 = (0, import_react4.useMemo)(() => {
|
|
562
|
+
const jsx12 = (0, import_react5.useMemo)(() => {
|
|
553
563
|
if (!componentName) return "";
|
|
554
564
|
const props = Object.entries(values).map(([key, val]) => {
|
|
555
565
|
if (typeof val === "string") return `${key}="${val}"`;
|
|
@@ -711,7 +721,7 @@ var ControlPanel = () => {
|
|
|
711
721
|
) })
|
|
712
722
|
] })
|
|
713
723
|
] }),
|
|
714
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Button, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
724
|
+
previewUrl && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Button, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
715
725
|
"a",
|
|
716
726
|
{
|
|
717
727
|
href: previewUrl,
|
|
@@ -734,7 +744,7 @@ var ControlPanel_default = ControlPanel;
|
|
|
734
744
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
735
745
|
var NO_CONTROLS_PARAM = "nocontrols";
|
|
736
746
|
function Playground({ children }) {
|
|
737
|
-
const hideControls = (0,
|
|
747
|
+
const hideControls = (0, import_react6.useMemo)(() => {
|
|
738
748
|
if (typeof window === "undefined") return false;
|
|
739
749
|
return new URLSearchParams(window.location.search).get(NO_CONTROLS_PARAM) === "true";
|
|
740
750
|
}, []);
|
package/dist/index.mjs
CHANGED
|
@@ -247,9 +247,28 @@ var PreviewContainer = ({ children, hideControls }) => {
|
|
|
247
247
|
var PreviewContainer_default = PreviewContainer;
|
|
248
248
|
|
|
249
249
|
// src/components/ControlPanel/ControlPanel.tsx
|
|
250
|
-
import { useState as
|
|
250
|
+
import { useState as useState4, useMemo as useMemo2 } from "react";
|
|
251
251
|
import { Check as Check2, Copy, SquareArrowOutUpRight } from "lucide-react";
|
|
252
252
|
|
|
253
|
+
// src/hooks/usePreviewUrl.ts
|
|
254
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
255
|
+
var usePreviewUrl = (values, basePath = "") => {
|
|
256
|
+
const [url, setUrl] = useState3("");
|
|
257
|
+
useEffect3(() => {
|
|
258
|
+
if (typeof window === "undefined") return;
|
|
259
|
+
const params = new URLSearchParams();
|
|
260
|
+
params.set("nocontrols", "true");
|
|
261
|
+
for (const [key, value] of Object.entries(values)) {
|
|
262
|
+
if (value !== void 0 && value !== null) {
|
|
263
|
+
params.set(key, value.toString());
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const fullUrl = `${basePath || window.location.pathname}?${params.toString()}`;
|
|
267
|
+
setUrl(fullUrl);
|
|
268
|
+
}, [values, basePath]);
|
|
269
|
+
return url;
|
|
270
|
+
};
|
|
271
|
+
|
|
253
272
|
// src/components/ui/switch.tsx
|
|
254
273
|
import * as React4 from "react";
|
|
255
274
|
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
|
@@ -504,25 +523,16 @@ Button.displayName = "Button";
|
|
|
504
523
|
// src/components/ControlPanel/ControlPanel.tsx
|
|
505
524
|
import { Fragment, jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
506
525
|
var ControlPanel = () => {
|
|
507
|
-
const [copied, setCopied] =
|
|
526
|
+
const [copied, setCopied] = useState4(false);
|
|
508
527
|
const { leftPanelWidth, isDesktop, isHydrated, sidebarNarrow } = useResizableLayout();
|
|
509
528
|
const { schema, setValue, values, componentName } = useControlsContext();
|
|
529
|
+
const previewUrl = usePreviewUrl(values);
|
|
510
530
|
const normalControls = Object.entries(schema).filter(
|
|
511
531
|
([, control]) => control.type !== "button"
|
|
512
532
|
);
|
|
513
533
|
const buttonControls = Object.entries(schema).filter(
|
|
514
534
|
([, control]) => control.type === "button"
|
|
515
535
|
);
|
|
516
|
-
const previewUrl = useMemo2(() => {
|
|
517
|
-
const params = new URLSearchParams();
|
|
518
|
-
params.set("nocontrols", "true");
|
|
519
|
-
for (const [key, value] of Object.entries(values)) {
|
|
520
|
-
if (value !== void 0 && value !== null) {
|
|
521
|
-
params.set(key, value.toString());
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return `${window.location.pathname}?${params.toString()}`;
|
|
525
|
-
}, [values]);
|
|
526
536
|
const jsx12 = useMemo2(() => {
|
|
527
537
|
if (!componentName) return "";
|
|
528
538
|
const props = Object.entries(values).map(([key, val]) => {
|
|
@@ -685,7 +695,7 @@ var ControlPanel = () => {
|
|
|
685
695
|
) })
|
|
686
696
|
] })
|
|
687
697
|
] }),
|
|
688
|
-
/* @__PURE__ */ jsx10(Button, { asChild: true, children: /* @__PURE__ */ jsxs4(
|
|
698
|
+
previewUrl && /* @__PURE__ */ jsx10(Button, { asChild: true, children: /* @__PURE__ */ jsxs4(
|
|
689
699
|
"a",
|
|
690
700
|
{
|
|
691
701
|
href: previewUrl,
|