@codespark/react 1.0.2 → 1.0.4

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.ts CHANGED
@@ -2,7 +2,7 @@ import { Framework, Output } from "@codespark/framework";
2
2
  import * as React$1 from "react";
3
3
  import { ComponentProps, ComponentType, JSX, ReactElement, ReactNode, RefObject } from "react";
4
4
  import { LoaderType } from "@codespark/framework/loaders";
5
- import * as react_jsx_runtime1 from "react/jsx-runtime";
5
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
6
6
  import { Tabs } from "radix-ui";
7
7
  import { ReactCodeMirrorProps, ReactCodeMirrorRef } from "@uiw/react-codemirror";
8
8
  import { EditorProps } from "@monaco-editor/react";
@@ -340,7 +340,7 @@ interface CodesparkContextValue extends ConfigContextValue, WorkspaceDerivedStat
340
340
  interface ConfigProviderProps extends ConfigContextValue {
341
341
  children?: ReactNode;
342
342
  }
343
- declare function ConfigProvider(props: ConfigProviderProps): react_jsx_runtime1.JSX.Element;
343
+ declare function ConfigProvider(props: ConfigProviderProps): react_jsx_runtime0.JSX.Element;
344
344
  interface CodesparkProviderProps extends Omit<CodesparkContextValue, 'files' | 'currentFile' | keyof WorkspaceDerivedState> {
345
345
  children?: ReactNode;
346
346
  }
@@ -351,7 +351,7 @@ interface CodesparkProviderProps extends Omit<CodesparkContextValue, 'files' | '
351
351
  * Required when using CodesparkEditor, CodesparkPreview, or CodesparkFileExplorer independently.
352
352
  * Automatically manages workspace state synchronization across all child components.
353
353
  */
354
- declare function CodesparkProvider(props: CodesparkProviderProps): react_jsx_runtime1.JSX.Element;
354
+ declare function CodesparkProvider(props: CodesparkProviderProps): react_jsx_runtime0.JSX.Element;
355
355
  //#endregion
356
356
  //#region src/components/editor/index.d.ts
357
357
  type ToolboxItemId = 'reset' | 'format' | 'copy';
@@ -500,13 +500,13 @@ interface CodesparkPreviewProps extends ConfigContextValue, Pick<WorkspaceInit,
500
500
  * Supports Tailwind CSS, custom scripts/styles injection, and console output capture.
501
501
  * Displays a loading indicator during code compilation and execution.
502
502
  */
503
- declare function CodesparkPreview(props: CodesparkPreviewProps): react_jsx_runtime1.JSX.Element;
503
+ declare function CodesparkPreview(props: CodesparkPreviewProps): react_jsx_runtime0.JSX.Element;
504
504
  //#endregion
505
505
  //#region src/ui/tabs.d.ts
506
506
  declare function Tabs$1({
507
507
  className,
508
508
  ...props
509
- }: React$1.ComponentProps<typeof Tabs.Root>): react_jsx_runtime1.JSX.Element;
509
+ }: React$1.ComponentProps<typeof Tabs.Root>): react_jsx_runtime0.JSX.Element;
510
510
  //#endregion
511
511
  //#region src/components/file-explorer/index.d.ts
512
512
  interface FileExplorerItemRenderContext {
@@ -714,7 +714,7 @@ interface CodesparkProps extends Pick<ConfigContextValue, 'theme'>, Pick<Codespa
714
714
  * to provide a complete interactive code demonstration experience.
715
715
  * Supports both single-file mode (via `code` prop) and multi-file mode (via `files` prop).
716
716
  */
717
- declare function Codespark(props: CodesparkProps): react_jsx_runtime1.JSX.Element;
717
+ declare function Codespark(props: CodesparkProps): react_jsx_runtime0.JSX.Element;
718
718
  declare const useMDXComponents: () => {
719
719
  Codespark: typeof Codespark;
720
720
  CodesparkEditor: typeof CodesparkEditor;
package/dist/index.js CHANGED
@@ -57,16 +57,6 @@ function useLatest(value) {
57
57
  ref.current = value;
58
58
  return ref;
59
59
  }
60
- function useUpdateEffect(effect, deps) {
61
- const mounted = useRef(false);
62
- useEffect(() => {
63
- if (!mounted.current) {
64
- mounted.current = true;
65
- return;
66
- }
67
- return effect();
68
- }, deps);
69
- }
70
60
  function getLanguageFromFile(name) {
71
61
  const ext = name.split(".").pop()?.toLowerCase();
72
62
  return ext ? {
@@ -1317,8 +1307,6 @@ var PreviewProxy = class {
1317
1307
  script.type = "importmap";
1318
1308
  script.textContent = JSON.stringify({ imports: imports || {} });
1319
1309
  doc.head.insertBefore(script, doc.head.firstChild);
1320
- console.log(doc.querySelector("html").outerHTML);
1321
- this.iframe.src = URL.createObjectURL(new Blob([doc.querySelector("html").outerHTML], { type: "text/html" }));
1322
1310
  }
1323
1311
  };
1324
1312
  function usePreview(options) {
@@ -1327,7 +1315,6 @@ function usePreview(options) {
1327
1315
  const proxyRef = useRef(void 0);
1328
1316
  const iframeRef = useRef(null);
1329
1317
  const readyRef = useRef(Promise.withResolvers());
1330
- const isFirst = useRef(true);
1331
1318
  const preview = async (...code) => {
1332
1319
  try {
1333
1320
  setRunning(true);
@@ -1335,23 +1322,13 @@ function usePreview(options) {
1335
1322
  await proxyRef.current?.eval(code);
1336
1323
  } catch (error) {
1337
1324
  onError?.(error);
1338
- } finally {
1339
- isFirst.current = false;
1340
1325
  }
1341
1326
  };
1342
- useUpdateEffect(() => {
1343
- if (isFirst.current) return;
1344
- readyRef.current.promise.then(() => {
1345
- proxyRef.current?.setImportMap(imports);
1346
- });
1347
- }, [JSON.stringify(imports)]);
1348
1327
  useEffect(() => {
1349
1328
  if (iframeRef.current) {
1350
1329
  const proxy = new PreviewProxy({
1351
1330
  root: iframeRef.current,
1352
1331
  defaultTheme: theme,
1353
- defaultImports: imports,
1354
- defaultPresets: presets,
1355
1332
  handlers: {
1356
1333
  on_console: onConsole,
1357
1334
  on_fetch_progress: onFetchProgress,
@@ -1385,6 +1362,11 @@ function usePreview(options) {
1385
1362
  proxyRef.current?.injectTags(presets);
1386
1363
  });
1387
1364
  }, [presets?.join("\n")]);
1365
+ useEffect(() => {
1366
+ readyRef.current.promise.then(() => {
1367
+ proxyRef.current?.setImportMap(imports);
1368
+ });
1369
+ }, [JSON.stringify(imports)]);
1388
1370
  return {
1389
1371
  iframeRef,
1390
1372
  proxyRef,
@@ -1595,7 +1577,7 @@ function useTailwindCSS() {
1595
1577
  const PREFLIGHT_STYLE = `
1596
1578
  :root {
1597
1579
  font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
1598
- font-size: 14px;
1580
+ font-size: 16px;
1599
1581
  line-height: 1.5;
1600
1582
  font-synthesis: none;
1601
1583
  text-rendering: optimizeLegibility;
@@ -1618,6 +1600,7 @@ html {
1618
1600
  body {
1619
1601
  height: 100%;
1620
1602
  padding: 12px;
1603
+ font-size: 14px;
1621
1604
  overflow: auto;
1622
1605
  box-sizing: border-box;
1623
1606
  display: flex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codespark/react",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "React components for codespark ecosystem",
6
6
  "keywords": [