@seedgrid/fe-playground 2026.3.26 → 2026.3.27-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.
@@ -1,6 +1,5 @@
1
1
  import * as React from "react";
2
- export type SgPlaygroundProps = {
3
- code: string;
2
+ type SgPlaygroundSharedProps = {
4
3
  interactive?: boolean;
5
4
  codeContract?: "renderBody" | "appFile";
6
5
  preset?: SgPlaygroundPreset;
@@ -26,6 +25,13 @@ export type SgPlaygroundProps = {
26
25
  defaultOpen?: boolean;
27
26
  cardId?: string;
28
27
  };
28
+ export type SgPlaygroundProps = ({
29
+ code: string;
30
+ playgroundFile?: never;
31
+ } & SgPlaygroundSharedProps) | ({
32
+ playgroundFile: string;
33
+ code?: never;
34
+ } & SgPlaygroundSharedProps);
29
35
  export type SgPlaygroundPreset = "auto" | "basic" | "seedgrid" | "editor" | "full";
30
36
  export type SgPlaygroundNpmRegistry = {
31
37
  enabledScopes: string[];
@@ -35,4 +41,5 @@ export type SgPlaygroundNpmRegistry = {
35
41
  registryAuthToken?: string;
36
42
  };
37
43
  export default function SgPlayground(props: Readonly<SgPlaygroundProps>): import("react/jsx-runtime").JSX.Element;
44
+ export {};
38
45
  //# sourceMappingURL=SgPlayground.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SgPlayground.d.ts","sourceRoot":"","sources":["../src/SgPlayground.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAc/B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACxC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC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uB,CAAC,GACpE,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG,uBAAuB,CAAC,CAAC;AAMzE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AACnF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AA6nCF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,2CAooBtE"}
@@ -6,6 +6,9 @@ import { SgButton, SgCard } from "@seedgrid/fe-components";
6
6
  function cn(...parts) {
7
7
  return parts.filter(Boolean).join(" ");
8
8
  }
9
+ function getInlinePlaygroundCode(props) {
10
+ return "code" in props ? (props.code ?? "") : "";
11
+ }
9
12
  const DEFAULT_SEEDGRID_DEPENDENCY = "latest";
10
13
  const DEFAULT_SANDPACK_BUNDLER_URL = "https://sandpack.seedgrid.com.br";
11
14
  const DEFAULT_SANDPACK_BUNDLER_TIMEOUT_MS = 60000;
@@ -1052,12 +1055,43 @@ function shouldSuppressCoreJsProviderWarning(args) {
1052
1055
  return typeof firstArg === "string" && firstArg.includes(COREJS_PROVIDER_WARNING_PREFIX);
1053
1056
  }
1054
1057
  export default function SgPlayground(props) {
1055
- const { code, interactive = false, codeContract = "renderBody", preset = "auto", title, description, height = 360, expandedHeight = "70vh", expandable = true, resizable = true, resizeAxis = "vertical", previewPadding, className, style, dependencies, defaultImports, previewWrapperClassName = "h-[420px] rounded-xl border border-border bg-muted/30 p-3", seedgridDependency, bundlerURL, bundlerTimeoutMs, npmRegistries, withCard = true, collapsible = true, defaultOpen = true, cardId } = props;
1058
+ const { interactive = false, codeContract = "renderBody", preset = "auto", title, description, height = 360, expandedHeight = "70vh", expandable = true, resizable = true, resizeAxis = "vertical", previewPadding, className, style, dependencies, defaultImports, previewWrapperClassName = "h-[420px] rounded-xl border border-border bg-muted/30 p-3", seedgridDependency, bundlerURL, bundlerTimeoutMs, npmRegistries, withCard = true, collapsible = true, defaultOpen = true, cardId } = props;
1059
+ const [resolvedCode, setResolvedCode] = React.useState(() => getInlinePlaygroundCode(props));
1056
1060
  const effectivePreviewPadding = normalizeCssSize(previewPadding ?? (codeContract === "appFile" ? 12 : 0));
1057
1061
  const [sandpackStylesCss, setSandpackStylesCss] = React.useState(() => buildSandpackStylesCss({}, effectivePreviewPadding));
1058
1062
  const [sandpackTheme, setSandpackTheme] = React.useState(() => resolveSandpackThemeFromHost());
1059
1063
  const [isExpanded, setIsExpanded] = React.useState(false);
1060
1064
  const [activePanel, setActivePanel] = React.useState("code");
1065
+ React.useEffect(() => {
1066
+ if ("code" in props) {
1067
+ setResolvedCode(props.code ?? "");
1068
+ return;
1069
+ }
1070
+ let active = true;
1071
+ const loadPlaygroundFile = async () => {
1072
+ try {
1073
+ const response = await fetch(`/api/showcase-code?path=${encodeURIComponent(props.playgroundFile)}`, {
1074
+ cache: "no-store"
1075
+ });
1076
+ if (!response.ok) {
1077
+ throw new Error(`Failed to load playground file: ${props.playgroundFile}`);
1078
+ }
1079
+ const payload = await response.json();
1080
+ if (active) {
1081
+ setResolvedCode(payload.code ?? "");
1082
+ }
1083
+ }
1084
+ catch {
1085
+ if (active) {
1086
+ setResolvedCode(`// Failed to load playground file: ${props.playgroundFile}`);
1087
+ }
1088
+ }
1089
+ };
1090
+ void loadPlaygroundFile();
1091
+ return () => {
1092
+ active = false;
1093
+ };
1094
+ }, [props.code, props.playgroundFile]);
1061
1095
  React.useEffect(() => {
1062
1096
  if (typeof window === "undefined")
1063
1097
  return;
@@ -1100,8 +1134,8 @@ export default function SgPlayground(props) {
1100
1134
  SgAutocomplete
1101
1135
  } from "@seedgrid/fe-components";`;
1102
1136
  const appTsx = React.useMemo(() => codeContract === "appFile"
1103
- ? code
1104
- : buildAppTsxFromRenderBody(code, seedgridDefaultImports, previewWrapperClassName), [code, codeContract, previewWrapperClassName, seedgridDefaultImports]);
1137
+ ? resolvedCode
1138
+ : buildAppTsxFromRenderBody(resolvedCode, seedgridDefaultImports, previewWrapperClassName), [codeContract, previewWrapperClassName, resolvedCode, seedgridDefaultImports]);
1105
1139
  const resolvedSeedgridDependency = seedgridDependency ??
1106
1140
  process.env.NEXT_PUBLIC_SANDPACK_SEEDGRID_DEPENDENCY ??
1107
1141
  DEFAULT_SEEDGRID_DEPENDENCY;
@@ -1453,7 +1487,7 @@ export default function SgPlayground(props) {
1453
1487
  ? "border-primary text-foreground"
1454
1488
  : "border-transparent text-muted-foreground hover:text-foreground"), onClick: () => setActivePanel("code"), children: "C\u00C3\u00B3digo" }), _jsx("button", { type: "button", className: cn("flex-1 py-2 text-sm font-medium border-b-2 -mb-px transition-colors", activePanel === "preview"
1455
1489
  ? "border-primary text-foreground"
1456
- : "border-transparent text-muted-foreground hover:text-foreground"), onClick: () => setActivePanel("preview"), children: "Preview" })] }), _jsxs("div", { className: cn("grid overflow-auto min-h-[260px]", "grid-cols-1 md:grid-cols-2", resizeClass), style: { height: currentHeight }, children: [_jsxs("div", { className: cn("min-w-0 md:border-r border-border", activePanel !== "code" ? "hidden md:block" : ""), children: [_jsx(SandpackCodeEditor, { showLineNumbers: true, wrapContent: true, showTabs: false, showRunButton: false, style: { height: "100%" } }), _jsx("div", { className: "flex justify-end border-t border-border px-3 py-2", children: _jsx(CopyButton, {}) })] }), _jsx("div", { className: cn("min-w-0", activePanel !== "preview" ? "hidden md:block" : ""), children: _jsx(SandpackPreview, { className: "sg-playground-preview", style: { height: "100%" }, showOpenInCodeSandbox: false, showRefreshButton: false, showRestartButton: false }) })] })] }) })) : (_jsxs("div", { className: cn(withCard ? undefined : "space-y-2", withCard ? undefined : className), style: withCard ? undefined : style, children: [withCard ? null : title ? _jsx("div", { className: "text-sm font-medium", children: title }) : null, _jsx(ReadonlyBlock, { code: code })] }));
1490
+ : "border-transparent text-muted-foreground hover:text-foreground"), onClick: () => setActivePanel("preview"), children: "Preview" })] }), _jsxs("div", { className: cn("grid overflow-auto min-h-[260px]", "grid-cols-1 md:grid-cols-2", resizeClass), style: { height: currentHeight }, children: [_jsxs("div", { className: cn("min-w-0 md:border-r border-border", activePanel !== "code" ? "hidden md:block" : ""), children: [_jsx(SandpackCodeEditor, { showLineNumbers: true, wrapContent: true, showTabs: false, showRunButton: false, style: { height: "100%" } }), _jsx("div", { className: "flex justify-end border-t border-border px-3 py-2", children: _jsx(CopyButton, {}) })] }), _jsx("div", { className: cn("min-w-0", activePanel !== "preview" ? "hidden md:block" : ""), children: _jsx(SandpackPreview, { className: "sg-playground-preview", style: { height: "100%" }, showOpenInCodeSandbox: false, showRefreshButton: false, showRestartButton: false }) })] })] }) })) : (_jsxs("div", { className: cn(withCard ? undefined : "space-y-2", withCard ? undefined : className), style: withCard ? undefined : style, children: [withCard ? null : title ? _jsx("div", { className: "text-sm font-medium", children: title }) : null, _jsx(ReadonlyBlock, { code: resolvedCode })] }));
1457
1491
  if (!withCard)
1458
1492
  return content;
1459
1493
  return (_jsx(SgCard, { id: cardId, title: title ?? "Codigo", description: description, collapsible: collapsible, defaultOpen: defaultOpen, className: cn("rounded-lg", className), style: style, bodyClassName: "p-0", children: content }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedgrid/fe-playground",
3
- "version": "2026.3.26",
3
+ "version": "2026.3.27-2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "react": "19.0.0",
39
39
  "react-dom": "19.0.0",
40
40
  "typescript": "^5.5.4",
41
- "@seedgrid/fe-components": "2026.3.26"
41
+ "@seedgrid/fe-components": "2026.3.27-2"
42
42
  },
43
43
  "scripts": {
44
44
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",