@@ -6,6 +6,9 @@ declare const __TINY_VERSION__: string;
66const TINY_VERSION = `^${ __TINY_VERSION__ } ` ;
77const TINY_DESIGN_VERSION = TINY_VERSION ;
88const TINY_ICONS_VERSION = TINY_VERSION ;
9+ const TINY_CHARTS_VERSION = TINY_VERSION ;
10+ const RECHARTS_VERSION = '^3.8.1' ;
11+ const REACT_IS_VERSION = '^18.3.1' ;
912
1013const BOOTSTRAP_CODE = `import React from 'react';
1114import { createRoot } from 'react-dom/client';
@@ -17,6 +20,36 @@ createRoot(document.getElementById('root')!).render(
1720 </React.StrictMode>,
1821);` ;
1922
23+ function getSandboxDependencies ( sourceCode : string ) : Record < string , string > {
24+ const dependencies : Record < string , string > = {
25+ react : '^18.2.0' ,
26+ 'react-dom' : '^18.2.0' ,
27+ '@tiny-design/react' : TINY_DESIGN_VERSION ,
28+ '@tiny-design/icons' : TINY_ICONS_VERSION ,
29+ } ;
30+
31+ const importPattern = / (?: f r o m \s + | i m p o r t \s + ) [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / g;
32+ const importedPackages = new Set < string > ( ) ;
33+
34+ for ( const match of sourceCode . matchAll ( importPattern ) ) {
35+ importedPackages . add ( match [ 1 ] ) ;
36+ }
37+
38+ if (
39+ importedPackages . has ( '@tiny-design/charts' ) ||
40+ importedPackages . has ( '@tiny-design/charts/style' )
41+ ) {
42+ dependencies [ '@tiny-design/charts' ] = TINY_CHARTS_VERSION ;
43+ }
44+
45+ if ( importedPackages . has ( 'recharts' ) ) {
46+ dependencies . recharts = RECHARTS_VERSION ;
47+ dependencies [ 'react-is' ] = REACT_IS_VERSION ;
48+ }
49+
50+ return dependencies ;
51+ }
52+
2053/**
2154 * Generate the file set for StackBlitz (Vite-based).
2255 */
@@ -27,12 +60,7 @@ function buildStackBlitzFiles(sourceCode: string): Record<string, string> {
2760 name : 'tiny-design-demo' ,
2861 private : true ,
2962 scripts : { dev : 'vite' , build : 'vite build' } ,
30- dependencies : {
31- react : '^18.2.0' ,
32- 'react-dom' : '^18.2.0' ,
33- '@tiny-design/react' : TINY_DESIGN_VERSION ,
34- '@tiny-design/icons' : TINY_ICONS_VERSION ,
35- } ,
63+ dependencies : getSandboxDependencies ( sourceCode ) ,
3664 devDependencies : {
3765 '@vitejs/plugin-react' : '^4.0.0' ,
3866 vite : '^5.0.0' ,
@@ -77,12 +105,7 @@ function buildCodeSandboxFiles(sourceCode: string): Record<string, string> {
77105 {
78106 name : 'tiny-design-demo' ,
79107 private : true ,
80- dependencies : {
81- react : '^18.2.0' ,
82- 'react-dom' : '^18.2.0' ,
83- '@tiny-design/react' : TINY_DESIGN_VERSION ,
84- '@tiny-design/icons' : TINY_ICONS_VERSION ,
85- } ,
108+ dependencies : getSandboxDependencies ( sourceCode ) ,
86109 } ,
87110 null ,
88111 2 ,
0 commit comments