@codespark/react 1.0.4 → 1.0.5
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 +7 -7
- package/dist/index.js +23 -20
- package/package.json +3 -2
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
|
|
5
|
+
import * as react_jsx_runtime1 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";
|
|
@@ -261,7 +261,7 @@ declare function useWorkspace(init?: WorkspaceInit | Workspace): UseWorkspaceRet
|
|
|
261
261
|
/**
|
|
262
262
|
* Configuration options for createWorkspace function
|
|
263
263
|
*/
|
|
264
|
-
interface CreateWorkspaceConfig extends
|
|
264
|
+
interface CreateWorkspaceConfig extends Omit<WorkspaceInit, 'entry' | 'files'> {
|
|
265
265
|
/**
|
|
266
266
|
* Entry file name/path
|
|
267
267
|
*
|
|
@@ -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):
|
|
343
|
+
declare function ConfigProvider(props: ConfigProviderProps): react_jsx_runtime1.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):
|
|
354
|
+
declare function CodesparkProvider(props: CodesparkProviderProps): react_jsx_runtime1.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):
|
|
503
|
+
declare function CodesparkPreview(props: CodesparkPreviewProps): react_jsx_runtime1.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>):
|
|
509
|
+
}: React$1.ComponentProps<typeof Tabs.Root>): react_jsx_runtime1.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):
|
|
717
|
+
declare function Codespark(props: CodesparkProps): react_jsx_runtime1.JSX.Element;
|
|
718
718
|
declare const useMDXComponents: () => {
|
|
719
719
|
Codespark: typeof Codespark;
|
|
720
720
|
CodesparkEditor: typeof CodesparkEditor;
|
package/dist/index.js
CHANGED
|
@@ -397,25 +397,31 @@ function useWorkspace(init) {
|
|
|
397
397
|
const compiled = framework.compile();
|
|
398
398
|
workspace[INTERNAL_EMIT]("compiled", compiled);
|
|
399
399
|
const modules = framework.getOutput(LoaderType.ESModule);
|
|
400
|
+
const styles = framework.getOutput(LoaderType.Style);
|
|
401
|
+
const scripts = framework.getOutput(LoaderType.Script);
|
|
402
|
+
const externals = modules.flatMap(({ externals: externals$1 }) => externals$1).reduce((acc, { name, imported }) => {
|
|
403
|
+
if (!acc[name]) acc[name] = /* @__PURE__ */ new Set();
|
|
404
|
+
imported.forEach((i) => acc[name].add(i));
|
|
405
|
+
return acc;
|
|
406
|
+
}, {});
|
|
400
407
|
return {
|
|
401
408
|
fileTree,
|
|
402
409
|
compiled,
|
|
403
410
|
compileError: null,
|
|
404
411
|
vendor: {
|
|
405
412
|
modules,
|
|
406
|
-
styles
|
|
407
|
-
scripts
|
|
413
|
+
styles,
|
|
414
|
+
scripts,
|
|
408
415
|
imports: {
|
|
409
|
-
...
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
};
|
|
416
|
+
...Object.entries(externals).reduce((pre, [name, importedSet]) => {
|
|
417
|
+
const imported = Array.from(importedSet);
|
|
418
|
+
pre[name] = constructESMUrl({
|
|
419
|
+
pkg: name,
|
|
420
|
+
version: "",
|
|
421
|
+
external: Object.keys(framework.imports),
|
|
422
|
+
exports: imported.length ? imported : void 0
|
|
423
|
+
});
|
|
424
|
+
return pre;
|
|
419
425
|
}, {}),
|
|
420
426
|
...framework.imports
|
|
421
427
|
}
|
|
@@ -462,9 +468,8 @@ function useWorkspace(init) {
|
|
|
462
468
|
* ```
|
|
463
469
|
*/
|
|
464
470
|
function createWorkspace(source, config) {
|
|
465
|
-
const {
|
|
471
|
+
const { name = "./App.tsx", mode = "packed", ...workspaceInit } = config || {};
|
|
466
472
|
if (!this?.__scanned) return new Workspace({
|
|
467
|
-
id,
|
|
468
473
|
entry: name,
|
|
469
474
|
files: { [name]: source.toString() }
|
|
470
475
|
});
|
|
@@ -474,10 +479,9 @@ function createWorkspace(source, config) {
|
|
|
474
479
|
else if (mode === "source") {
|
|
475
480
|
packedCode = Object.values(files)[0] || "";
|
|
476
481
|
return new Workspace({
|
|
477
|
-
id,
|
|
478
|
-
framework,
|
|
479
482
|
entry: Object.keys(files)[0] || "",
|
|
480
|
-
files
|
|
483
|
+
files,
|
|
484
|
+
...workspaceInit
|
|
481
485
|
});
|
|
482
486
|
} else {
|
|
483
487
|
const { code, locals, imports } = entry;
|
|
@@ -488,13 +492,12 @@ function createWorkspace(source, config) {
|
|
|
488
492
|
].filter(Boolean).join("\n\n");
|
|
489
493
|
}
|
|
490
494
|
return new Workspace({
|
|
491
|
-
id,
|
|
492
|
-
framework,
|
|
493
495
|
entry: name,
|
|
494
496
|
files: {
|
|
495
497
|
[name]: packedCode,
|
|
496
498
|
...files
|
|
497
|
-
}
|
|
499
|
+
},
|
|
500
|
+
...workspaceInit
|
|
498
501
|
});
|
|
499
502
|
}
|
|
500
503
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codespark/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React components for codespark ecosystem",
|
|
6
6
|
"keywords": [
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "tsdown"
|
|
30
|
+
"build": "tsdown",
|
|
31
|
+
"release": "pnpm build && npm publish --access public"
|
|
31
32
|
},
|
|
32
33
|
"author": "TonyL1u",
|
|
33
34
|
"license": "MIT",
|