@toriistudio/v0-playground 0.2.1 → 0.2.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/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import React, { ReactNode } from 'react';
3
3
 
4
4
  declare function Playground({ children }: {
5
5
  children: ReactNode;
6
- }): react_jsx_runtime.JSX.Element;
6
+ }): react_jsx_runtime.JSX.Element | null;
7
7
 
8
8
  type ControlType = {
9
9
  type: "boolean";
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import React, { ReactNode } from 'react';
3
3
 
4
4
  declare function Playground({ children }: {
5
5
  children: ReactNode;
6
- }): react_jsx_runtime.JSX.Element;
6
+ }): react_jsx_runtime.JSX.Element | null;
7
7
 
8
8
  type ControlType = {
9
9
  type: "boolean";
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 import_react5 = require("react");
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 import_react4 = require("react");
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,27 +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, import_react4.useState)(false);
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 previewUrl = (0, import_react4.useMemo)(() => {
543
- if (typeof window === "undefined") return "";
544
- const params = new URLSearchParams();
545
- params.set("nocontrols", "true");
546
- for (const [key, value] of Object.entries(values)) {
547
- if (value !== void 0 && value !== null) {
548
- params.set(key, value.toString());
549
- }
550
- }
551
- return `${window.location.pathname}?${params.toString()}`;
552
- }, [values]);
553
- const jsx12 = (0, import_react4.useMemo)(() => {
562
+ const jsx12 = (0, import_react5.useMemo)(() => {
554
563
  if (!componentName) return "";
555
564
  const props = Object.entries(values).map(([key, val]) => {
556
565
  if (typeof val === "string") return `${key}="${val}"`;
@@ -712,7 +721,7 @@ var ControlPanel = () => {
712
721
  ) })
713
722
  ] })
714
723
  ] }),
715
- /* @__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)(
716
725
  "a",
717
726
  {
718
727
  href: previewUrl,
@@ -735,10 +744,15 @@ var ControlPanel_default = ControlPanel;
735
744
  var import_jsx_runtime11 = require("react/jsx-runtime");
736
745
  var NO_CONTROLS_PARAM = "nocontrols";
737
746
  function Playground({ children }) {
738
- const hideControls = (0, import_react5.useMemo)(() => {
747
+ const [isHydrated, setIsHydrated] = (0, import_react6.useState)(false);
748
+ (0, import_react6.useEffect)(() => {
749
+ setIsHydrated(true);
750
+ }, []);
751
+ const hideControls = (0, import_react6.useMemo)(() => {
739
752
  if (typeof window === "undefined") return false;
740
753
  return new URLSearchParams(window.location.search).get(NO_CONTROLS_PARAM) === "true";
741
754
  }, []);
755
+ if (!isHydrated) return null;
742
756
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ResizableLayout, { hideControls, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(ControlsProvider, { children: [
743
757
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewContainer_default, { hideControls, children }),
744
758
  !hideControls && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ControlPanel_default, {})
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/components/Playground/Playground.tsx
2
- import { useMemo as useMemo3 } from "react";
2
+ import { useEffect as useEffect4, useMemo as useMemo3, useState as useState5 } from "react";
3
3
 
4
4
  // src/context/ResizableLayout.tsx
5
5
  import {
@@ -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 useState3, useMemo as useMemo2 } from "react";
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,26 +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] = useState3(false);
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
- if (typeof window === "undefined") return "";
518
- const params = new URLSearchParams();
519
- params.set("nocontrols", "true");
520
- for (const [key, value] of Object.entries(values)) {
521
- if (value !== void 0 && value !== null) {
522
- params.set(key, value.toString());
523
- }
524
- }
525
- return `${window.location.pathname}?${params.toString()}`;
526
- }, [values]);
527
536
  const jsx12 = useMemo2(() => {
528
537
  if (!componentName) return "";
529
538
  const props = Object.entries(values).map(([key, val]) => {
@@ -686,7 +695,7 @@ var ControlPanel = () => {
686
695
  ) })
687
696
  ] })
688
697
  ] }),
689
- /* @__PURE__ */ jsx10(Button, { asChild: true, children: /* @__PURE__ */ jsxs4(
698
+ previewUrl && /* @__PURE__ */ jsx10(Button, { asChild: true, children: /* @__PURE__ */ jsxs4(
690
699
  "a",
691
700
  {
692
701
  href: previewUrl,
@@ -709,10 +718,15 @@ var ControlPanel_default = ControlPanel;
709
718
  import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
710
719
  var NO_CONTROLS_PARAM = "nocontrols";
711
720
  function Playground({ children }) {
721
+ const [isHydrated, setIsHydrated] = useState5(false);
722
+ useEffect4(() => {
723
+ setIsHydrated(true);
724
+ }, []);
712
725
  const hideControls = useMemo3(() => {
713
726
  if (typeof window === "undefined") return false;
714
727
  return new URLSearchParams(window.location.search).get(NO_CONTROLS_PARAM) === "true";
715
728
  }, []);
729
+ if (!isHydrated) return null;
716
730
  return /* @__PURE__ */ jsx11(ResizableLayout, { hideControls, children: /* @__PURE__ */ jsxs5(ControlsProvider, { children: [
717
731
  /* @__PURE__ */ jsx11(PreviewContainer_default, { hideControls, children }),
718
732
  !hideControls && /* @__PURE__ */ jsx11(ControlPanel_default, {})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toriistudio/v0-playground",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "V0 Playground",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",