@seedgrid/fe-components 2026.3.2-6 → 2026.3.2-7
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.
|
@@ -16,11 +16,21 @@ export type SgPlaygroundProps = {
|
|
|
16
16
|
defaultImports?: string;
|
|
17
17
|
previewWrapperClassName?: string;
|
|
18
18
|
seedgridDependency?: string;
|
|
19
|
+
bundlerURL?: string;
|
|
20
|
+
bundlerTimeoutMs?: number;
|
|
21
|
+
npmRegistries?: SgPlaygroundNpmRegistry[];
|
|
19
22
|
withCard?: boolean;
|
|
20
23
|
collapsible?: boolean;
|
|
21
24
|
defaultOpen?: boolean;
|
|
22
25
|
cardId?: string;
|
|
23
26
|
};
|
|
24
27
|
export type SgPlaygroundPreset = "auto" | "basic" | "seedgrid" | "editor" | "full";
|
|
28
|
+
export type SgPlaygroundNpmRegistry = {
|
|
29
|
+
enabledScopes: string[];
|
|
30
|
+
limitToScopes: boolean;
|
|
31
|
+
registryUrl: string;
|
|
32
|
+
proxyEnabled: boolean;
|
|
33
|
+
registryAuthToken?: string;
|
|
34
|
+
};
|
|
25
35
|
export default function SgPlayground(props: Readonly<SgPlaygroundProps>): import("react/jsx-runtime").JSX.Element;
|
|
26
36
|
//# sourceMappingURL=SgPlayground.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SgPlayground.d.ts","sourceRoot":"","sources":["../../src/others/SgPlayground.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SgPlayground.d.ts","sourceRoot":"","sources":["../../src/others/SgPlayground.tsx"],"names":[],"mappings":"AAsBA,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;IACzB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,MAAM,CAAC;IAChD,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,uBAAuB,EAAE,CAAC;IAC1C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,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;AA6sBF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,2CAyXtE"}
|
|
@@ -4,10 +4,17 @@ import * as React from "react";
|
|
|
4
4
|
import { SandpackCodeEditor, SandpackPreview, SandpackProvider, useSandpack } from "@codesandbox/sandpack-react";
|
|
5
5
|
import { SgButton } from "../buttons/SgButton";
|
|
6
6
|
import { SgCard } from "../layout/SgCard";
|
|
7
|
+
import blockedEmailDomainsConfig from "../blocked-email-domains.json";
|
|
8
|
+
import componentsMessagesEnUsJson from "../i18n/en-US.json";
|
|
9
|
+
import componentsMessagesEsJson from "../i18n/es.json";
|
|
10
|
+
import componentsMessagesPtBrJson from "../i18n/pt-BR.json";
|
|
11
|
+
import componentsMessagesPtPtJson from "../i18n/pt-PT.json";
|
|
7
12
|
function cn(...parts) {
|
|
8
13
|
return parts.filter(Boolean).join(" ");
|
|
9
14
|
}
|
|
10
15
|
const DEFAULT_SEEDGRID_DEPENDENCY = "latest";
|
|
16
|
+
const DEFAULT_SANDPACK_BUNDLER_URL = "https://sandpack.seedgrid.com.br";
|
|
17
|
+
const DEFAULT_SANDPACK_BUNDLER_TIMEOUT_MS = 60000;
|
|
11
18
|
const DEFAULT_SANDBOX_BASE_DEPENDENCIES = {
|
|
12
19
|
react: "18.2.0",
|
|
13
20
|
"react-dom": "18.2.0"
|
|
@@ -59,16 +66,6 @@ const SANDPACK_EXTERNAL_RESOURCES = [
|
|
|
59
66
|
// Prebuilt utility CSS so classes from @seedgrid/fe-components can render inside Sandpack
|
|
60
67
|
"https://unpkg.com/tailwindcss@2.2.19/dist/tailwind.min.css"
|
|
61
68
|
];
|
|
62
|
-
const SANDPACK_QRCODE_SHIM_PACKAGE_JSON = `{
|
|
63
|
-
"name": "qrcode",
|
|
64
|
-
"version": "0.0.0-sandpack-shim",
|
|
65
|
-
"type": "module",
|
|
66
|
-
"main": "./index.js",
|
|
67
|
-
"module": "./index.js",
|
|
68
|
-
"exports": {
|
|
69
|
-
".": "./index.js"
|
|
70
|
-
}
|
|
71
|
-
}`;
|
|
72
69
|
const SANDPACK_QRCODE_SHIM_INDEX_JS = `const makeError = () =>
|
|
73
70
|
new Error(
|
|
74
71
|
"qrcode (node build) is not supported in Sandpack browser runtime. Update @seedgrid/fe-components to a browser-safe QR implementation."
|
|
@@ -90,18 +87,6 @@ const SANDPACK_MARKDOWN_IT_BIN_SHIM = `import markdownit from "../index.mjs";
|
|
|
90
87
|
export default markdownit;
|
|
91
88
|
export { markdownit };
|
|
92
89
|
`;
|
|
93
|
-
function createEsmShimPackageJson(name) {
|
|
94
|
-
return `{
|
|
95
|
-
"name": "${name}",
|
|
96
|
-
"version": "0.0.0-sandpack-shim",
|
|
97
|
-
"type": "module",
|
|
98
|
-
"main": "./index.js",
|
|
99
|
-
"module": "./index.js",
|
|
100
|
-
"exports": {
|
|
101
|
-
".": "./index.js"
|
|
102
|
-
}
|
|
103
|
-
}`;
|
|
104
|
-
}
|
|
105
90
|
const SANDPACK_SANDBOX_SANDPACK_REACT_SHIM_INDEX_JS = `export const SandpackProvider = ({ children }) => children ?? null;
|
|
106
91
|
export const SandpackCodeEditor = () => null;
|
|
107
92
|
export const SandpackPreview = () => null;
|
|
@@ -134,11 +119,6 @@ const SANDPACK_TIPTAP_EXTENSION_SHIM_INDEX_JS = `const extension = {
|
|
|
134
119
|
};
|
|
135
120
|
export default extension;
|
|
136
121
|
`;
|
|
137
|
-
const SANDPACK_ASSERT_SHIM_PACKAGE_JSON = `{
|
|
138
|
-
"name": "assert",
|
|
139
|
-
"version": "0.0.0-sandpack-shim",
|
|
140
|
-
"main": "./index.js"
|
|
141
|
-
}`;
|
|
142
122
|
const SANDPACK_ASSERT_SHIM_INDEX_JS = `function fail(message) {
|
|
143
123
|
throw new Error(message || "Assertion failed");
|
|
144
124
|
}
|
|
@@ -179,11 +159,6 @@ assert.fail = fail;
|
|
|
179
159
|
module.exports = assert;
|
|
180
160
|
module.exports.default = assert;
|
|
181
161
|
`;
|
|
182
|
-
const SANDPACK_UTIL_SHIM_PACKAGE_JSON = `{
|
|
183
|
-
"name": "util",
|
|
184
|
-
"version": "0.0.0-sandpack-shim",
|
|
185
|
-
"main": "./index.js"
|
|
186
|
-
}`;
|
|
187
162
|
const SANDPACK_UTIL_SHIM_INDEX_JS = `const inspect = function inspect(value) {
|
|
188
163
|
try {
|
|
189
164
|
return JSON.stringify(value);
|
|
@@ -217,11 +192,6 @@ const utilShim = { inspect, deprecate, format };
|
|
|
217
192
|
module.exports = utilShim;
|
|
218
193
|
module.exports.default = utilShim;
|
|
219
194
|
`;
|
|
220
|
-
const SANDPACK_PATH_SHIM_PACKAGE_JSON = `{
|
|
221
|
-
"name": "path",
|
|
222
|
-
"version": "0.0.0-sandpack-shim",
|
|
223
|
-
"main": "./index.js"
|
|
224
|
-
}`;
|
|
225
195
|
const SANDPACK_PATH_SHIM_INDEX_JS = `function normalize(input) {
|
|
226
196
|
return String(input || "").replace(/\\\\/g, "/");
|
|
227
197
|
}
|
|
@@ -264,11 +234,6 @@ const pathShim = {
|
|
|
264
234
|
module.exports = pathShim;
|
|
265
235
|
module.exports.default = pathShim;
|
|
266
236
|
`;
|
|
267
|
-
const SANDPACK_FS_SHIM_PACKAGE_JSON = `{
|
|
268
|
-
"name": "fs",
|
|
269
|
-
"version": "0.0.0-sandpack-shim",
|
|
270
|
-
"main": "./index.js"
|
|
271
|
-
}`;
|
|
272
237
|
const SANDPACK_FS_SHIM_INDEX_JS = `function notSupported(name) {
|
|
273
238
|
throw new Error("fs." + name + " is not supported in Sandpack browser runtime.");
|
|
274
239
|
}
|
|
@@ -283,11 +248,6 @@ const fsShim = {
|
|
|
283
248
|
module.exports = fsShim;
|
|
284
249
|
module.exports.default = fsShim;
|
|
285
250
|
`;
|
|
286
|
-
const SANDPACK_PROCESS_SHIM_PACKAGE_JSON = `{
|
|
287
|
-
"name": "process",
|
|
288
|
-
"version": "0.0.0-sandpack-shim",
|
|
289
|
-
"main": "./index.js"
|
|
290
|
-
}`;
|
|
291
251
|
const SANDPACK_PROCESS_SHIM_INDEX_JS = `const processShim = {
|
|
292
252
|
env: {},
|
|
293
253
|
argv: ["browser"],
|
|
@@ -389,6 +349,70 @@ const SANDPACK_HOST_STYLES_CSS = `
|
|
|
389
349
|
left: auto !important;
|
|
390
350
|
}
|
|
391
351
|
`;
|
|
352
|
+
function normalizeUrl(raw, fallback) {
|
|
353
|
+
const value = raw?.trim();
|
|
354
|
+
if (!value)
|
|
355
|
+
return fallback;
|
|
356
|
+
try {
|
|
357
|
+
const parsed = new URL(value);
|
|
358
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return fallback;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function normalizeTimeoutMs(value, fallback) {
|
|
365
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
366
|
+
return fallback;
|
|
367
|
+
}
|
|
368
|
+
return Math.round(value);
|
|
369
|
+
}
|
|
370
|
+
function parseBooleanFlag(value, fallback) {
|
|
371
|
+
const normalized = value?.trim().toLowerCase();
|
|
372
|
+
if (!normalized)
|
|
373
|
+
return fallback;
|
|
374
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return fallback;
|
|
381
|
+
}
|
|
382
|
+
function resolveDefaultNpmRegistriesFromEnv() {
|
|
383
|
+
const registryUrlRaw = process.env.NEXT_PUBLIC_SANDPACK_NPM_REGISTRY_URL?.trim();
|
|
384
|
+
if (!registryUrlRaw)
|
|
385
|
+
return undefined;
|
|
386
|
+
const scopesRaw = process.env.NEXT_PUBLIC_SANDPACK_NPM_REGISTRY_SCOPES;
|
|
387
|
+
const enabledScopes = (scopesRaw ?? "@seedgrid")
|
|
388
|
+
.split(",")
|
|
389
|
+
.map((scope) => scope.trim())
|
|
390
|
+
.filter(Boolean);
|
|
391
|
+
const limitToScopes = parseBooleanFlag(process.env.NEXT_PUBLIC_SANDPACK_NPM_REGISTRY_LIMIT_TO_SCOPES, true);
|
|
392
|
+
const proxyEnabled = parseBooleanFlag(process.env.NEXT_PUBLIC_SANDPACK_NPM_REGISTRY_PROXY_ENABLED, false);
|
|
393
|
+
const registryAuthToken = process.env.NEXT_PUBLIC_SANDPACK_NPM_REGISTRY_AUTH_TOKEN?.trim();
|
|
394
|
+
return [
|
|
395
|
+
{
|
|
396
|
+
enabledScopes,
|
|
397
|
+
limitToScopes,
|
|
398
|
+
registryUrl: registryUrlRaw.replace(/\/+$/, ""),
|
|
399
|
+
proxyEnabled,
|
|
400
|
+
...(registryAuthToken ? { registryAuthToken } : {})
|
|
401
|
+
}
|
|
402
|
+
];
|
|
403
|
+
}
|
|
404
|
+
function buildCjsJsonModule(value) {
|
|
405
|
+
const serialized = JSON.stringify(value);
|
|
406
|
+
return `const data = ${serialized};
|
|
407
|
+
module.exports = data;
|
|
408
|
+
module.exports.default = data;
|
|
409
|
+
`;
|
|
410
|
+
}
|
|
411
|
+
const SANDPACK_SEEDGRID_PT_BR_JSON_SHIM = buildCjsJsonModule(componentsMessagesPtBrJson);
|
|
412
|
+
const SANDPACK_SEEDGRID_PT_PT_JSON_SHIM = buildCjsJsonModule(componentsMessagesPtPtJson);
|
|
413
|
+
const SANDPACK_SEEDGRID_EN_US_JSON_SHIM = buildCjsJsonModule(componentsMessagesEnUsJson);
|
|
414
|
+
const SANDPACK_SEEDGRID_ES_JSON_SHIM = buildCjsJsonModule(componentsMessagesEsJson);
|
|
415
|
+
const SANDPACK_SEEDGRID_BLOCKED_EMAIL_DOMAINS_JSON_SHIM = buildCjsJsonModule(blockedEmailDomainsConfig);
|
|
392
416
|
function parseRgbParts(raw) {
|
|
393
417
|
const value = raw.trim();
|
|
394
418
|
if (!value)
|
|
@@ -627,7 +651,7 @@ function RunButton({ onRun }) {
|
|
|
627
651
|
return (_jsx(SgButton, { severity: "primary", size: "sm", loading: running, onClick: handleRun, children: running ? "Running" : "Run" }));
|
|
628
652
|
}
|
|
629
653
|
export default function SgPlayground(props) {
|
|
630
|
-
const { code, interactive = false, codeContract = "renderBody", preset = "auto", title, description, height = 360, expandedHeight = "70vh", expandable = true, resizable = true, resizeAxis = "vertical", previewPadding, className, dependencies, defaultImports, previewWrapperClassName = "h-[420px] rounded-xl border border-border bg-muted/30 p-3", seedgridDependency, withCard = true, collapsible = true, defaultOpen = true, cardId } = props;
|
|
654
|
+
const { code, interactive = false, codeContract = "renderBody", preset = "auto", title, description, height = 360, expandedHeight = "70vh", expandable = true, resizable = true, resizeAxis = "vertical", previewPadding, className, 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;
|
|
631
655
|
const effectivePreviewPadding = normalizeCssSize(previewPadding ?? (codeContract === "appFile" ? 12 : 0));
|
|
632
656
|
const [sandpackStylesCss, setSandpackStylesCss] = React.useState(() => buildSandpackStylesCss({}, effectivePreviewPadding));
|
|
633
657
|
const [isExpanded, setIsExpanded] = React.useState(false);
|
|
@@ -679,6 +703,26 @@ export default function SgPlayground(props) {
|
|
|
679
703
|
DEFAULT_SEEDGRID_DEPENDENCY;
|
|
680
704
|
const requestedDeps = dependencies ?? {};
|
|
681
705
|
const requestedDepKeys = Object.keys(requestedDeps);
|
|
706
|
+
const resolvedBundlerURL = normalizeUrl(bundlerURL ?? process.env.NEXT_PUBLIC_SANDPACK_BUNDLER_URL, DEFAULT_SANDPACK_BUNDLER_URL);
|
|
707
|
+
const resolvedBundlerTimeoutMs = normalizeTimeoutMs(bundlerTimeoutMs ??
|
|
708
|
+
Number(process.env.NEXT_PUBLIC_SANDPACK_BUNDLER_TIMEOUT_MS ?? Number.NaN), DEFAULT_SANDPACK_BUNDLER_TIMEOUT_MS);
|
|
709
|
+
const resolvedNpmRegistries = React.useMemo(() => npmRegistries ?? resolveDefaultNpmRegistriesFromEnv(), [npmRegistries]);
|
|
710
|
+
React.useEffect(() => {
|
|
711
|
+
if (!interactive)
|
|
712
|
+
return;
|
|
713
|
+
if (!parseBooleanFlag(process.env.NEXT_PUBLIC_SANDPACK_DEBUG, false))
|
|
714
|
+
return;
|
|
715
|
+
console.info("[SgPlayground] Sandpack runtime config", {
|
|
716
|
+
bundlerURL: resolvedBundlerURL,
|
|
717
|
+
bundlerTimeoutMs: resolvedBundlerTimeoutMs,
|
|
718
|
+
npmRegistries: (resolvedNpmRegistries ?? []).map((registry) => ({
|
|
719
|
+
enabledScopes: registry.enabledScopes,
|
|
720
|
+
limitToScopes: registry.limitToScopes,
|
|
721
|
+
registryUrl: registry.registryUrl,
|
|
722
|
+
proxyEnabled: registry.proxyEnabled
|
|
723
|
+
}))
|
|
724
|
+
});
|
|
725
|
+
}, [interactive, resolvedBundlerTimeoutMs, resolvedBundlerURL, resolvedNpmRegistries]);
|
|
682
726
|
const codeUsesSeedgrid = /from\s+["']@seedgrid\/fe-components["']/.test(appTsx);
|
|
683
727
|
const codeUsesTextEditor = /\bSgTextEditor\b/.test(appTsx);
|
|
684
728
|
const codeUsesPlaygroundComponent = /\bSgPlayground\b/.test(appTsx);
|
|
@@ -709,8 +753,29 @@ export default function SgPlayground(props) {
|
|
|
709
753
|
};
|
|
710
754
|
if (includeSeedgridDependency) {
|
|
711
755
|
// Compatibility shim for legacy @seedgrid/fe-components builds that still import "qrcode" (node-only path).
|
|
712
|
-
files["/node_modules/qrcode/package.json"] = { code: SANDPACK_QRCODE_SHIM_PACKAGE_JSON, hidden: true };
|
|
713
756
|
files["/node_modules/qrcode/index.js"] = { code: SANDPACK_QRCODE_SHIM_INDEX_JS, hidden: true };
|
|
757
|
+
// Sandpack runtime can evaluate JSON files as plain JS modules.
|
|
758
|
+
// Provide CJS-compatible shims to keep @seedgrid/fe-components i18n/validators working.
|
|
759
|
+
files["/node_modules/@seedgrid/fe-components/dist/i18n/pt-BR.json"] = {
|
|
760
|
+
code: SANDPACK_SEEDGRID_PT_BR_JSON_SHIM,
|
|
761
|
+
hidden: true
|
|
762
|
+
};
|
|
763
|
+
files["/node_modules/@seedgrid/fe-components/dist/i18n/pt-PT.json"] = {
|
|
764
|
+
code: SANDPACK_SEEDGRID_PT_PT_JSON_SHIM,
|
|
765
|
+
hidden: true
|
|
766
|
+
};
|
|
767
|
+
files["/node_modules/@seedgrid/fe-components/dist/i18n/en-US.json"] = {
|
|
768
|
+
code: SANDPACK_SEEDGRID_EN_US_JSON_SHIM,
|
|
769
|
+
hidden: true
|
|
770
|
+
};
|
|
771
|
+
files["/node_modules/@seedgrid/fe-components/dist/i18n/es.json"] = {
|
|
772
|
+
code: SANDPACK_SEEDGRID_ES_JSON_SHIM,
|
|
773
|
+
hidden: true
|
|
774
|
+
};
|
|
775
|
+
files["/node_modules/@seedgrid/fe-components/dist/blocked-email-domains.json"] = {
|
|
776
|
+
code: SANDPACK_SEEDGRID_BLOCKED_EMAIL_DOMAINS_JSON_SHIM,
|
|
777
|
+
hidden: true
|
|
778
|
+
};
|
|
714
779
|
}
|
|
715
780
|
if (shouldIncludeNodePolyfills) {
|
|
716
781
|
// markdown-it CLI entry uses node:fs and breaks in browser runtime.
|
|
@@ -719,41 +784,24 @@ export default function SgPlayground(props) {
|
|
|
719
784
|
hidden: true
|
|
720
785
|
};
|
|
721
786
|
// Node builtin compatibility shims used by transitive dependencies (e.g. argparse from markdown-it/tiptap).
|
|
722
|
-
files["/node_modules/assert/package.json"] = { code: SANDPACK_ASSERT_SHIM_PACKAGE_JSON, hidden: true };
|
|
723
787
|
files["/node_modules/assert/index.js"] = { code: SANDPACK_ASSERT_SHIM_INDEX_JS, hidden: true };
|
|
724
|
-
files["/node_modules/util/package.json"] = { code: SANDPACK_UTIL_SHIM_PACKAGE_JSON, hidden: true };
|
|
725
788
|
files["/node_modules/util/index.js"] = { code: SANDPACK_UTIL_SHIM_INDEX_JS, hidden: true };
|
|
726
|
-
files["/node_modules/path/package.json"] = { code: SANDPACK_PATH_SHIM_PACKAGE_JSON, hidden: true };
|
|
727
789
|
files["/node_modules/path/index.js"] = { code: SANDPACK_PATH_SHIM_INDEX_JS, hidden: true };
|
|
728
|
-
files["/node_modules/fs/package.json"] = { code: SANDPACK_FS_SHIM_PACKAGE_JSON, hidden: true };
|
|
729
790
|
files["/node_modules/fs/index.js"] = { code: SANDPACK_FS_SHIM_INDEX_JS, hidden: true };
|
|
730
|
-
files["/node_modules/process/package.json"] = { code: SANDPACK_PROCESS_SHIM_PACKAGE_JSON, hidden: true };
|
|
731
791
|
files["/node_modules/process/index.js"] = { code: SANDPACK_PROCESS_SHIM_INDEX_JS, hidden: true };
|
|
732
792
|
}
|
|
733
793
|
if (shouldShimSandpackReact) {
|
|
734
|
-
files["/node_modules/@codesandbox/sandpack-react/package.json"] = {
|
|
735
|
-
code: createEsmShimPackageJson("@codesandbox/sandpack-react"),
|
|
736
|
-
hidden: true
|
|
737
|
-
};
|
|
738
794
|
files["/node_modules/@codesandbox/sandpack-react/index.js"] = {
|
|
739
795
|
code: SANDPACK_SANDBOX_SANDPACK_REACT_SHIM_INDEX_JS,
|
|
740
796
|
hidden: true
|
|
741
797
|
};
|
|
742
798
|
}
|
|
743
799
|
if (shouldShimTiptap) {
|
|
744
|
-
files["/node_modules/@tiptap/react/package.json"] = {
|
|
745
|
-
code: createEsmShimPackageJson("@tiptap/react"),
|
|
746
|
-
hidden: true
|
|
747
|
-
};
|
|
748
800
|
files["/node_modules/@tiptap/react/index.js"] = {
|
|
749
801
|
code: SANDPACK_TIPTAP_REACT_SHIM_INDEX_JS,
|
|
750
802
|
hidden: true
|
|
751
803
|
};
|
|
752
804
|
for (const packageName of TIPTAP_SHIM_PACKAGES) {
|
|
753
|
-
files[`/node_modules/${packageName}/package.json`] = {
|
|
754
|
-
code: createEsmShimPackageJson(packageName),
|
|
755
|
-
hidden: true
|
|
756
|
-
};
|
|
757
805
|
files[`/node_modules/${packageName}/index.js`] = {
|
|
758
806
|
code: SANDPACK_TIPTAP_EXTENSION_SHIM_INDEX_JS,
|
|
759
807
|
hidden: true
|
|
@@ -777,17 +825,23 @@ export default function SgPlayground(props) {
|
|
|
777
825
|
: resizeAxis === "horizontal"
|
|
778
826
|
? "resize-x"
|
|
779
827
|
: "resize";
|
|
780
|
-
const
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
828
|
+
const sandpackCustomSetup = React.useMemo(() => ({
|
|
829
|
+
dependencies: deps,
|
|
830
|
+
entry: "/index.tsx",
|
|
831
|
+
...(resolvedNpmRegistries ? { npmRegistries: resolvedNpmRegistries } : {})
|
|
832
|
+
}), [deps, resolvedNpmRegistries]);
|
|
833
|
+
const sandpackOptions = React.useMemo(() => ({
|
|
834
|
+
autorun: false,
|
|
835
|
+
initMode: "lazy",
|
|
836
|
+
bundlerURL: resolvedBundlerURL,
|
|
837
|
+
// Keep both keys while sandpack typings/runtime differ across versions.
|
|
838
|
+
bundlerTimeOut: resolvedBundlerTimeoutMs,
|
|
839
|
+
bundlerTimeout: resolvedBundlerTimeoutMs,
|
|
840
|
+
activeFile: "/App.tsx",
|
|
841
|
+
visibleFiles: ["/App.tsx"],
|
|
842
|
+
externalResources: SANDPACK_EXTERNAL_RESOURCES
|
|
843
|
+
}), [resolvedBundlerTimeoutMs, resolvedBundlerURL]);
|
|
844
|
+
const content = interactive ? (_jsx("div", { className: cn(withCard ? "" : "rounded-lg border border-border", withCard ? undefined : className), children: _jsxs(SandpackProvider, { template: "react-ts", files: files, customSetup: sandpackCustomSetup, options: sandpackOptions, children: [_jsx("style", { children: SANDPACK_HOST_STYLES_CSS }), _jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [withCard ? null : _jsx("span", { className: "text-sm font-medium", children: title ?? "Example" }), _jsx("span", { className: "text-xs text-muted-foreground", children: codeContract === "renderBody" ? "editable snippet" : "editable App.tsx" })] }), _jsxs("div", { className: "flex items-center gap-2", children: [expandable ? (_jsx(SgButton, { appearance: "outline", size: "sm", onClick: () => setIsExpanded((prev) => !prev), children: isExpanded ? "Reduzir" : "Expandir" })) : null, _jsx(RunButton, { onRun: () => setActivePanel("preview") })] })] }), _jsxs("div", { className: "flex md:hidden border-b border-border", children: [_jsx("button", { type: "button", className: cn("flex-1 py-2 text-sm font-medium border-b-2 -mb-px transition-colors", activePanel === "code"
|
|
791
845
|
? "border-primary text-foreground"
|
|
792
846
|
: "border-transparent text-muted-foreground hover:text-foreground"), onClick: () => setActivePanel("code"), children: "C\u00F3digo" }), _jsx("button", { type: "button", className: cn("flex-1 py-2 text-sm font-medium border-b-2 -mb-px transition-colors", activePanel === "preview"
|
|
793
847
|
? "border-primary text-foreground"
|