@modern-js/sandpack-react 0.0.0-canary-20250912092308

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/CHANGELOG.md ADDED
@@ -0,0 +1,59 @@
1
+ # @modern-js/sandpack-react
2
+
3
+ ## 0.0.0-canary-20250912092308
4
+
5
+ ## 2.68.1
6
+
7
+ ## 2.68.0
8
+
9
+ ## 2.67.11
10
+
11
+ ## 2.67.10
12
+
13
+ ## 2.67.9
14
+
15
+ ## 2.67.8
16
+
17
+ ## 2.67.7
18
+
19
+ ## 2.67.6
20
+
21
+ ## 2.67.5
22
+
23
+ ## 2.67.4
24
+
25
+ ## 2.67.3
26
+
27
+ ## 2.67.2
28
+
29
+ ## 2.67.1
30
+
31
+ ## 2.67.0
32
+
33
+ ## 2.66.0
34
+
35
+ ## 2.65.5
36
+
37
+ ## 2.65.4
38
+
39
+ ## 2.65.3
40
+
41
+ ## 2.65.2
42
+
43
+ ## 2.65.1
44
+
45
+ ## 2.65.0
46
+
47
+ ## 2.64.3
48
+
49
+ ## 2.64.2
50
+
51
+ ## 2.64.1
52
+
53
+ ## 2.64.0
54
+
55
+ ## 2.63.7
56
+
57
+ ## 2.63.6
58
+
59
+ ## 2.63.5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ <p align="center">
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
+ </p>
4
+
5
+ <h1 align="center">Modern.js</h1>
6
+
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
14
+
15
+ ## Documentation
16
+
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
19
+
20
+ ## Contributing
21
+
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
+
24
+ ## License
25
+
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ default: () => ModernSandpack
22
+ });
23
+ module.exports = __toCommonJS(src_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_sandpack_react = require("@codesandbox/sandpack-react");
26
+ var import_templates = require("./templates");
27
+ function fileterFiles(files, removeFiles) {
28
+ if (removeFiles.length === 0) {
29
+ return files;
30
+ }
31
+ const result = {};
32
+ Object.keys(files).forEach((filename) => {
33
+ if (!removeFiles.includes(filename)) {
34
+ result[filename] = files[filename];
35
+ }
36
+ });
37
+ return result;
38
+ }
39
+ function ModernSandpack(props) {
40
+ const { template, customSetup = {}, files: customFiles = {}, removeFiles = [], options = {}, initialCollapsedFolder = [], activeFile = "src/routes/page.tsx", theme = "light" } = props;
41
+ const initFiles = import_templates.ModernTemplates[template];
42
+ const files = {
43
+ ...fileterFiles(initFiles, removeFiles),
44
+ ...fileterFiles(customFiles, removeFiles)
45
+ };
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sandpack_react.SandpackProvider, {
47
+ theme,
48
+ customSetup: {
49
+ environment: "node",
50
+ ...customSetup
51
+ },
52
+ files,
53
+ options: {
54
+ activeFile,
55
+ visibleFiles: Object.keys(customFiles).filter((file) => !removeFiles.includes(file)),
56
+ ...options
57
+ },
58
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_sandpack_react.SandpackLayout, {
59
+ children: [
60
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sandpack_react.SandpackFileExplorer, {
61
+ autoHiddenFiles: true,
62
+ initialCollapsedFolder: [
63
+ "/.husky/",
64
+ "/.vscode/",
65
+ "/.codesandbox/",
66
+ ...initialCollapsedFolder
67
+ ]
68
+ }),
69
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sandpack_react.SandpackCodeEditor, {
70
+ showLineNumbers: true,
71
+ showInlineErrors: true,
72
+ readOnly: true,
73
+ showTabs: false
74
+ }),
75
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
76
+ style: {
77
+ position: "absolute",
78
+ right: "5px",
79
+ bottom: "5px"
80
+ },
81
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sandpack_react.OpenInCodeSandboxButton, {})
82
+ })
83
+ ]
84
+ })
85
+ });
86
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var common_exports = {};
20
+ __export(common_exports, {
21
+ commonFiles: () => commonFiles
22
+ });
23
+ module.exports = __toCommonJS(common_exports);
24
+ const commonFiles = {
25
+ ".codesandbox/environment.json": '{\n "nodeVersion": 18\n}\n',
26
+ ".codesandbox/tasks.json": '{\n "$schema": "https://codesandbox.io/schemas/tasks.json",\n "setupTasks": [\n {\n "name": "Installing Dependencies",\n "command": "pnpm install"\n }\n ],\n "tasks": {\n "start": {\n "name": "Application",\n "command": "pnpm run start",\n "runAtStart": true,\n "restartOn": {\n "files": ["pnpm-lock.yaml"]\n }\n }\n }\n}\n',
27
+ ".gitignore": ".DS_Store\n\n.pnp\n.pnp.js\n.env.local\n.env.*.local\n.history\n*.log*\n\nnode_modules/\n.yarn-integrity\n.pnpm-store/\n*.tsbuildinfo\n.changeset/pre.json\n\ndist/\ncoverage/\nrelease/\noutput/\noutput_resource/\nlog/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/typings/auto-generated\n\nmodern.config.local.*\n",
28
+ "biome.json": '{\n "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",\n "vcs": {\n "enabled": true,\n "defaultBranch": "main",\n "clientKind": "git",\n "useIgnoreFile": true\n },\n "formatter": {\n "enabled": true,\n "indentStyle": "space"\n },\n "javascript": {\n "formatter": {\n "quoteStyle": "single",\n "arrowParentheses": "asNeeded",\n "jsxQuoteStyle": "double",\n "lineWidth": 80\n }\n },\n "linter": {\n "enabled": true,\n "rules": {\n "recommended": true,\n "suspicious": {\n "noDuplicateFontNames": "off"\n }\n }\n },\n "organizeImports": {\n "enabled": true\n },\n "files": {\n "ignoreUnknown": true,\n "ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]\n }\n}\n',
29
+ ".npmrc": "strict-peer-dependencies=false\n"
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ commonFiles
34
+ });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var templates_exports = {};
20
+ __export(templates_exports, {
21
+ ModernTemplates: () => ModernTemplates
22
+ });
23
+ module.exports = __toCommonJS(templates_exports);
24
+ const { MWAFiles } = require("./mwa");
25
+ const ModernTemplates = {
26
+ "web-app": MWAFiles
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ ModernTemplates
31
+ });
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var mwa_exports = {};
20
+ __export(mwa_exports, {
21
+ MWAFiles: () => MWAFiles
22
+ });
23
+ module.exports = __toCommonJS(mwa_exports);
24
+ var import_common = require("./common");
25
+ const MWAFiles = {
26
+ ...import_common.commonFiles,
27
+ ...{
28
+ ".browserslistrc": "chrome >= 51\nedge >= 15\nfirefox >= 54\nsafari >= 10\nios_saf >= 10\n",
29
+ "README.md": "# Modern.js App\n\n## Setup\n\nInstall the dependencies:\n\n```bash\npnpm install\n```\n\n## Get Started\n\nStart the dev server:\n\n```bash\npnpm dev\n```\n\nEnable optional features or add a new entry:\n\n```bash\npnpm new\n```\n\nBuild the app for production:\n\n```bash\npnpm build\n```\n\nPreview the production build locally:\n\n```bash\npnpm serve\n```\n\nFor more information, see the [Modern.js documentation](https://modernjs.dev/en).\n",
30
+ "package.json": '{\n "name": "modern-app",\n "version": "0.1.0",\n "scripts": {\n "reset": "npx rimraf node_modules ./**/node_modules",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "biome check",\n "prepare": "simple-git-hooks",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [\n "biome check --files-ignore-unknown=true"\n ]\n },\n "simple-git-hooks": {\n "pre-commit": "npx lint-staged"\n },\n "dependencies": {\n "@modern-js/runtime": "2.68.12",\n "react": "^19.1.1",\n "react-dom": "^19.1.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.68.12",\n "@modern-js/tsconfig": "2.68.12",\n "@biomejs/biome": "1.9.4",\n "typescript": "~5.7.3",\n "@types/jest": "~29.2.4",\n "@types/node": "^20",\n "@types/react": "^19.1.8",\n "@types/react-dom": "^19.1.6",\n "lint-staged": "~15.4.0",\n "simple-git-hooks": "^2.11.1",\n "rimraf": "^6.0.1"\n }\n}\n',
31
+ "modern.config.ts": "import { appTools, defineConfig } from '@modern-js/app-tools';\n\n// https://modernjs.dev/en/configure/app/usage\nexport default defineConfig({\n runtime: {\n router: true,\n },\n plugins: [\n appTools({\n bundler: \n }),\n ],\n});\n",
32
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "compilerOptions": {\n "declaration": false,\n "jsx": "preserve",\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"],\n "@shared/*": ["./shared/*"]\n }\n },\n "include": ["src", "shared", "config", "modern.config.ts"],\n "exclude": ["**/node_modules"]\n}\n',
33
+ "src/modern.runtime.ts": "import { defineRuntimeConfig } from '@modern-js/runtime';\n\nexport default defineRuntimeConfig({});\n",
34
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/app-tools/types' />\n/// <reference types='@modern-js/runtime/types' />\n/// <reference types='@modern-js/runtime/types/router' />\n",
35
+ "src/routes/index.css": "html,\nbody {\n padding: 0;\n margin: 0;\n font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;\n background: linear-gradient(to bottom, transparent, #fff) #eceeef;\n}\n\np {\n margin: 0;\n}\n\n* {\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n box-sizing: border-box;\n}\n\n.container-box {\n min-height: 100vh;\n max-width: 100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n padding-top: 10px;\n}\n\nmain {\n flex: 1;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n}\n\n.title {\n display: flex;\n margin: 4rem 0 4rem;\n align-items: center;\n font-size: 4rem;\n font-weight: 600;\n}\n\n.logo {\n width: 6rem;\n margin: 7px 0 0 1rem;\n}\n\n.name {\n color: #4ecaff;\n}\n\n.description {\n text-align: center;\n line-height: 1.5;\n font-size: 1.3rem;\n color: #1b3a42;\n margin-bottom: 5rem;\n}\n\n.code {\n background: #fafafa;\n border-radius: 12px;\n padding: 0.6rem 0.9rem;\n font-size: 1.05rem;\n font-family:\n Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,\n Bitstream Vera Sans Mono, Courier New, monospace;\n}\n\n.container-box .grid {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 1100px;\n margin-top: 3rem;\n}\n\n.card {\n padding: 1.5rem;\n display: flex;\n flex-direction: column;\n justify-content: center;\n height: 100px;\n color: inherit;\n text-decoration: none;\n transition: 0.15s ease;\n width: 45%;\n}\n\n.card:hover,\n.card:focus {\n transform: scale(1.05);\n}\n\n.card h2 {\n display: flex;\n align-items: center;\n font-size: 1.5rem;\n margin: 0;\n padding: 0;\n}\n\n.card p {\n opacity: 0.6;\n font-size: 0.9rem;\n line-height: 1.5;\n margin-top: 1rem;\n}\n\n.arrow-right {\n width: 1.3rem;\n margin-left: 0.5rem;\n margin-top: 3px;\n}\n",
36
+ "src/routes/layout.tsx": "import { Outlet } from '@modern-js/runtime/router';\n\nexport default function Layout() {\n return (\n <div>\n <Outlet />\n </div>\n );\n}\n",
37
+ "src/routes/page.tsx": `import { Helmet } from '@modern-js/runtime/head';
38
+ import './index.css';
39
+
40
+ const Index = () => (
41
+ <div className="container-box">
42
+ <Helmet>
43
+ <link
44
+ rel="icon"
45
+ type="image/x-icon"
46
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
47
+ />
48
+ </Helmet>
49
+ <main>
50
+ <div className="title">
51
+ Welcome to
52
+ <img
53
+ className="logo"
54
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"
55
+ alt="Modern.js Logo"
56
+ />
57
+ <p className="name">Modern.js</p>
58
+ </div>
59
+ <p className="description">
60
+ Get started by editing <code className="code">src/routes/page.tsx</code>
61
+ </p>
62
+ <div className="grid">
63
+ <a
64
+ href="https://modernjs.dev/guides/get-started/introduction.html"
65
+ target="_blank"
66
+ rel="noopener noreferrer"
67
+ className="card"
68
+ >
69
+ <h2>
70
+ Guide
71
+ <img
72
+ className="arrow-right"
73
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
74
+ alt="Guide"
75
+ />
76
+ </h2>
77
+ <p>Follow the guides to use all features of Modern.js.</p>
78
+ </a>
79
+ <a
80
+ href="https://modernjs.dev/tutorials/foundations/introduction.html"
81
+ target="_blank"
82
+ className="card"
83
+ rel="noreferrer"
84
+ >
85
+ <h2>
86
+ Tutorials
87
+ <img
88
+ className="arrow-right"
89
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
90
+ alt="Tutorials"
91
+ />
92
+ </h2>
93
+ <p>Learn to use Modern.js to create your first application.</p>
94
+ </a>
95
+ <a
96
+ href="https://modernjs.dev/configure/app/usage.html"
97
+ target="_blank"
98
+ className="card"
99
+ rel="noreferrer"
100
+ >
101
+ <h2>
102
+ Config
103
+ <img
104
+ className="arrow-right"
105
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
106
+ alt="Config"
107
+ />
108
+ </h2>
109
+ <p>Find all configuration options provided by Modern.js.</p>
110
+ </a>
111
+ <a
112
+ href="https://github.com/web-infra-dev/modern.js"
113
+ target="_blank"
114
+ rel="noopener noreferrer"
115
+ className="card"
116
+ >
117
+ <h2>
118
+ GitHub
119
+ <img
120
+ className="arrow-right"
121
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
122
+ alt="Github"
123
+ />
124
+ </h2>
125
+ <p>View the source code on GitHub; feel free to contribute.</p>
126
+ </a>
127
+ </div>
128
+ </main>
129
+ </div>
130
+ );
131
+
132
+ export default Index;
133
+ `
134
+ }
135
+ };
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ MWAFiles
139
+ });
@@ -0,0 +1,64 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { OpenInCodeSandboxButton, SandpackCodeEditor, SandpackFileExplorer, SandpackLayout, SandpackProvider } from "@codesandbox/sandpack-react";
5
+ import { ModernTemplates } from "./templates";
6
+ function fileterFiles(files, removeFiles) {
7
+ if (removeFiles.length === 0) {
8
+ return files;
9
+ }
10
+ var result = {};
11
+ Object.keys(files).forEach(function(filename) {
12
+ if (!removeFiles.includes(filename)) {
13
+ result[filename] = files[filename];
14
+ }
15
+ });
16
+ return result;
17
+ }
18
+ function ModernSandpack(props) {
19
+ var template = props.template, _props_customSetup = props.customSetup, customSetup = _props_customSetup === void 0 ? {} : _props_customSetup, tmp = props.files, customFiles = tmp === void 0 ? {} : tmp, _props_removeFiles = props.removeFiles, removeFiles = _props_removeFiles === void 0 ? [] : _props_removeFiles, _props_options = props.options, options = _props_options === void 0 ? {} : _props_options, _props_initialCollapsedFolder = props.initialCollapsedFolder, initialCollapsedFolder = _props_initialCollapsedFolder === void 0 ? [] : _props_initialCollapsedFolder, _props_activeFile = props.activeFile, activeFile = _props_activeFile === void 0 ? "src/routes/page.tsx" : _props_activeFile, _props_theme = props.theme, theme = _props_theme === void 0 ? "light" : _props_theme;
20
+ var initFiles = ModernTemplates[template];
21
+ var files = _object_spread({}, fileterFiles(initFiles, removeFiles), fileterFiles(customFiles, removeFiles));
22
+ return /* @__PURE__ */ _jsx(SandpackProvider, {
23
+ theme,
24
+ customSetup: _object_spread({
25
+ environment: "node"
26
+ }, customSetup),
27
+ files,
28
+ options: _object_spread({
29
+ activeFile,
30
+ visibleFiles: Object.keys(customFiles).filter(function(file) {
31
+ return !removeFiles.includes(file);
32
+ })
33
+ }, options),
34
+ children: /* @__PURE__ */ _jsxs(SandpackLayout, {
35
+ children: [
36
+ /* @__PURE__ */ _jsx(SandpackFileExplorer, {
37
+ autoHiddenFiles: true,
38
+ initialCollapsedFolder: [
39
+ "/.husky/",
40
+ "/.vscode/",
41
+ "/.codesandbox/"
42
+ ].concat(_to_consumable_array(initialCollapsedFolder))
43
+ }),
44
+ /* @__PURE__ */ _jsx(SandpackCodeEditor, {
45
+ showLineNumbers: true,
46
+ showInlineErrors: true,
47
+ readOnly: true,
48
+ showTabs: false
49
+ }),
50
+ /* @__PURE__ */ _jsx("div", {
51
+ style: {
52
+ position: "absolute",
53
+ right: "5px",
54
+ bottom: "5px"
55
+ },
56
+ children: /* @__PURE__ */ _jsx(OpenInCodeSandboxButton, {})
57
+ })
58
+ ]
59
+ })
60
+ });
61
+ }
62
+ export {
63
+ ModernSandpack as default
64
+ };
@@ -0,0 +1,10 @@
1
+ var commonFiles = {
2
+ ".codesandbox/environment.json": '{\n "nodeVersion": 18\n}\n',
3
+ ".codesandbox/tasks.json": '{\n "$schema": "https://codesandbox.io/schemas/tasks.json",\n "setupTasks": [\n {\n "name": "Installing Dependencies",\n "command": "pnpm install"\n }\n ],\n "tasks": {\n "start": {\n "name": "Application",\n "command": "pnpm run start",\n "runAtStart": true,\n "restartOn": {\n "files": ["pnpm-lock.yaml"]\n }\n }\n }\n}\n',
4
+ ".gitignore": ".DS_Store\n\n.pnp\n.pnp.js\n.env.local\n.env.*.local\n.history\n*.log*\n\nnode_modules/\n.yarn-integrity\n.pnpm-store/\n*.tsbuildinfo\n.changeset/pre.json\n\ndist/\ncoverage/\nrelease/\noutput/\noutput_resource/\nlog/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/typings/auto-generated\n\nmodern.config.local.*\n",
5
+ "biome.json": '{\n "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",\n "vcs": {\n "enabled": true,\n "defaultBranch": "main",\n "clientKind": "git",\n "useIgnoreFile": true\n },\n "formatter": {\n "enabled": true,\n "indentStyle": "space"\n },\n "javascript": {\n "formatter": {\n "quoteStyle": "single",\n "arrowParentheses": "asNeeded",\n "jsxQuoteStyle": "double",\n "lineWidth": 80\n }\n },\n "linter": {\n "enabled": true,\n "rules": {\n "recommended": true,\n "suspicious": {\n "noDuplicateFontNames": "off"\n }\n }\n },\n "organizeImports": {\n "enabled": true\n },\n "files": {\n "ignoreUnknown": true,\n "ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]\n }\n}\n',
6
+ ".npmrc": "strict-peer-dependencies=false\n"
7
+ };
8
+ export {
9
+ commonFiles
10
+ };
@@ -0,0 +1,7 @@
1
+ var MWAFiles = require("./mwa").MWAFiles;
2
+ var ModernTemplates = {
3
+ "web-app": MWAFiles
4
+ };
5
+ export {
6
+ ModernTemplates
7
+ };
@@ -0,0 +1,113 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { commonFiles } from "./common";
3
+ var MWAFiles = _object_spread({}, commonFiles, {
4
+ ".browserslistrc": "chrome >= 51\nedge >= 15\nfirefox >= 54\nsafari >= 10\nios_saf >= 10\n",
5
+ "README.md": "# Modern.js App\n\n## Setup\n\nInstall the dependencies:\n\n```bash\npnpm install\n```\n\n## Get Started\n\nStart the dev server:\n\n```bash\npnpm dev\n```\n\nEnable optional features or add a new entry:\n\n```bash\npnpm new\n```\n\nBuild the app for production:\n\n```bash\npnpm build\n```\n\nPreview the production build locally:\n\n```bash\npnpm serve\n```\n\nFor more information, see the [Modern.js documentation](https://modernjs.dev/en).\n",
6
+ "package.json": '{\n "name": "modern-app",\n "version": "0.1.0",\n "scripts": {\n "reset": "npx rimraf node_modules ./**/node_modules",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "biome check",\n "prepare": "simple-git-hooks",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [\n "biome check --files-ignore-unknown=true"\n ]\n },\n "simple-git-hooks": {\n "pre-commit": "npx lint-staged"\n },\n "dependencies": {\n "@modern-js/runtime": "2.68.12",\n "react": "^19.1.1",\n "react-dom": "^19.1.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.68.12",\n "@modern-js/tsconfig": "2.68.12",\n "@biomejs/biome": "1.9.4",\n "typescript": "~5.7.3",\n "@types/jest": "~29.2.4",\n "@types/node": "^20",\n "@types/react": "^19.1.8",\n "@types/react-dom": "^19.1.6",\n "lint-staged": "~15.4.0",\n "simple-git-hooks": "^2.11.1",\n "rimraf": "^6.0.1"\n }\n}\n',
7
+ "modern.config.ts": "import { appTools, defineConfig } from '@modern-js/app-tools';\n\n// https://modernjs.dev/en/configure/app/usage\nexport default defineConfig({\n runtime: {\n router: true,\n },\n plugins: [\n appTools({\n bundler: \n }),\n ],\n});\n",
8
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "compilerOptions": {\n "declaration": false,\n "jsx": "preserve",\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"],\n "@shared/*": ["./shared/*"]\n }\n },\n "include": ["src", "shared", "config", "modern.config.ts"],\n "exclude": ["**/node_modules"]\n}\n',
9
+ "src/modern.runtime.ts": "import { defineRuntimeConfig } from '@modern-js/runtime';\n\nexport default defineRuntimeConfig({});\n",
10
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/app-tools/types' />\n/// <reference types='@modern-js/runtime/types' />\n/// <reference types='@modern-js/runtime/types/router' />\n",
11
+ "src/routes/index.css": "html,\nbody {\n padding: 0;\n margin: 0;\n font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;\n background: linear-gradient(to bottom, transparent, #fff) #eceeef;\n}\n\np {\n margin: 0;\n}\n\n* {\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n box-sizing: border-box;\n}\n\n.container-box {\n min-height: 100vh;\n max-width: 100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n padding-top: 10px;\n}\n\nmain {\n flex: 1;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n}\n\n.title {\n display: flex;\n margin: 4rem 0 4rem;\n align-items: center;\n font-size: 4rem;\n font-weight: 600;\n}\n\n.logo {\n width: 6rem;\n margin: 7px 0 0 1rem;\n}\n\n.name {\n color: #4ecaff;\n}\n\n.description {\n text-align: center;\n line-height: 1.5;\n font-size: 1.3rem;\n color: #1b3a42;\n margin-bottom: 5rem;\n}\n\n.code {\n background: #fafafa;\n border-radius: 12px;\n padding: 0.6rem 0.9rem;\n font-size: 1.05rem;\n font-family:\n Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,\n Bitstream Vera Sans Mono, Courier New, monospace;\n}\n\n.container-box .grid {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 1100px;\n margin-top: 3rem;\n}\n\n.card {\n padding: 1.5rem;\n display: flex;\n flex-direction: column;\n justify-content: center;\n height: 100px;\n color: inherit;\n text-decoration: none;\n transition: 0.15s ease;\n width: 45%;\n}\n\n.card:hover,\n.card:focus {\n transform: scale(1.05);\n}\n\n.card h2 {\n display: flex;\n align-items: center;\n font-size: 1.5rem;\n margin: 0;\n padding: 0;\n}\n\n.card p {\n opacity: 0.6;\n font-size: 0.9rem;\n line-height: 1.5;\n margin-top: 1rem;\n}\n\n.arrow-right {\n width: 1.3rem;\n margin-left: 0.5rem;\n margin-top: 3px;\n}\n",
12
+ "src/routes/layout.tsx": "import { Outlet } from '@modern-js/runtime/router';\n\nexport default function Layout() {\n return (\n <div>\n <Outlet />\n </div>\n );\n}\n",
13
+ "src/routes/page.tsx": `import { Helmet } from '@modern-js/runtime/head';
14
+ import './index.css';
15
+
16
+ const Index = () => (
17
+ <div className="container-box">
18
+ <Helmet>
19
+ <link
20
+ rel="icon"
21
+ type="image/x-icon"
22
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
23
+ />
24
+ </Helmet>
25
+ <main>
26
+ <div className="title">
27
+ Welcome to
28
+ <img
29
+ className="logo"
30
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"
31
+ alt="Modern.js Logo"
32
+ />
33
+ <p className="name">Modern.js</p>
34
+ </div>
35
+ <p className="description">
36
+ Get started by editing <code className="code">src/routes/page.tsx</code>
37
+ </p>
38
+ <div className="grid">
39
+ <a
40
+ href="https://modernjs.dev/guides/get-started/introduction.html"
41
+ target="_blank"
42
+ rel="noopener noreferrer"
43
+ className="card"
44
+ >
45
+ <h2>
46
+ Guide
47
+ <img
48
+ className="arrow-right"
49
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
50
+ alt="Guide"
51
+ />
52
+ </h2>
53
+ <p>Follow the guides to use all features of Modern.js.</p>
54
+ </a>
55
+ <a
56
+ href="https://modernjs.dev/tutorials/foundations/introduction.html"
57
+ target="_blank"
58
+ className="card"
59
+ rel="noreferrer"
60
+ >
61
+ <h2>
62
+ Tutorials
63
+ <img
64
+ className="arrow-right"
65
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
66
+ alt="Tutorials"
67
+ />
68
+ </h2>
69
+ <p>Learn to use Modern.js to create your first application.</p>
70
+ </a>
71
+ <a
72
+ href="https://modernjs.dev/configure/app/usage.html"
73
+ target="_blank"
74
+ className="card"
75
+ rel="noreferrer"
76
+ >
77
+ <h2>
78
+ Config
79
+ <img
80
+ className="arrow-right"
81
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
82
+ alt="Config"
83
+ />
84
+ </h2>
85
+ <p>Find all configuration options provided by Modern.js.</p>
86
+ </a>
87
+ <a
88
+ href="https://github.com/web-infra-dev/modern.js"
89
+ target="_blank"
90
+ rel="noopener noreferrer"
91
+ className="card"
92
+ >
93
+ <h2>
94
+ GitHub
95
+ <img
96
+ className="arrow-right"
97
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
98
+ alt="Github"
99
+ />
100
+ </h2>
101
+ <p>View the source code on GitHub; feel free to contribute.</p>
102
+ </a>
103
+ </div>
104
+ </main>
105
+ </div>
106
+ );
107
+
108
+ export default Index;
109
+ `
110
+ });
111
+ export {
112
+ MWAFiles
113
+ };
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { OpenInCodeSandboxButton, SandpackCodeEditor, SandpackFileExplorer, SandpackLayout, SandpackProvider } from "@codesandbox/sandpack-react";
3
+ import { ModernTemplates } from "./templates";
4
+ function fileterFiles(files, removeFiles) {
5
+ if (removeFiles.length === 0) {
6
+ return files;
7
+ }
8
+ const result = {};
9
+ Object.keys(files).forEach((filename) => {
10
+ if (!removeFiles.includes(filename)) {
11
+ result[filename] = files[filename];
12
+ }
13
+ });
14
+ return result;
15
+ }
16
+ function ModernSandpack(props) {
17
+ const { template, customSetup = {}, files: customFiles = {}, removeFiles = [], options = {}, initialCollapsedFolder = [], activeFile = "src/routes/page.tsx", theme = "light" } = props;
18
+ const initFiles = ModernTemplates[template];
19
+ const files = {
20
+ ...fileterFiles(initFiles, removeFiles),
21
+ ...fileterFiles(customFiles, removeFiles)
22
+ };
23
+ return /* @__PURE__ */ _jsx(SandpackProvider, {
24
+ theme,
25
+ customSetup: {
26
+ environment: "node",
27
+ ...customSetup
28
+ },
29
+ files,
30
+ options: {
31
+ activeFile,
32
+ visibleFiles: Object.keys(customFiles).filter((file) => !removeFiles.includes(file)),
33
+ ...options
34
+ },
35
+ children: /* @__PURE__ */ _jsxs(SandpackLayout, {
36
+ children: [
37
+ /* @__PURE__ */ _jsx(SandpackFileExplorer, {
38
+ autoHiddenFiles: true,
39
+ initialCollapsedFolder: [
40
+ "/.husky/",
41
+ "/.vscode/",
42
+ "/.codesandbox/",
43
+ ...initialCollapsedFolder
44
+ ]
45
+ }),
46
+ /* @__PURE__ */ _jsx(SandpackCodeEditor, {
47
+ showLineNumbers: true,
48
+ showInlineErrors: true,
49
+ readOnly: true,
50
+ showTabs: false
51
+ }),
52
+ /* @__PURE__ */ _jsx("div", {
53
+ style: {
54
+ position: "absolute",
55
+ right: "5px",
56
+ bottom: "5px"
57
+ },
58
+ children: /* @__PURE__ */ _jsx(OpenInCodeSandboxButton, {})
59
+ })
60
+ ]
61
+ })
62
+ });
63
+ }
64
+ export {
65
+ ModernSandpack as default
66
+ };
@@ -0,0 +1,10 @@
1
+ const commonFiles = {
2
+ ".codesandbox/environment.json": '{\n "nodeVersion": 18\n}\n',
3
+ ".codesandbox/tasks.json": '{\n "$schema": "https://codesandbox.io/schemas/tasks.json",\n "setupTasks": [\n {\n "name": "Installing Dependencies",\n "command": "pnpm install"\n }\n ],\n "tasks": {\n "start": {\n "name": "Application",\n "command": "pnpm run start",\n "runAtStart": true,\n "restartOn": {\n "files": ["pnpm-lock.yaml"]\n }\n }\n }\n}\n',
4
+ ".gitignore": ".DS_Store\n\n.pnp\n.pnp.js\n.env.local\n.env.*.local\n.history\n*.log*\n\nnode_modules/\n.yarn-integrity\n.pnpm-store/\n*.tsbuildinfo\n.changeset/pre.json\n\ndist/\ncoverage/\nrelease/\noutput/\noutput_resource/\nlog/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/typings/auto-generated\n\nmodern.config.local.*\n",
5
+ "biome.json": '{\n "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",\n "vcs": {\n "enabled": true,\n "defaultBranch": "main",\n "clientKind": "git",\n "useIgnoreFile": true\n },\n "formatter": {\n "enabled": true,\n "indentStyle": "space"\n },\n "javascript": {\n "formatter": {\n "quoteStyle": "single",\n "arrowParentheses": "asNeeded",\n "jsxQuoteStyle": "double",\n "lineWidth": 80\n }\n },\n "linter": {\n "enabled": true,\n "rules": {\n "recommended": true,\n "suspicious": {\n "noDuplicateFontNames": "off"\n }\n }\n },\n "organizeImports": {\n "enabled": true\n },\n "files": {\n "ignoreUnknown": true,\n "ignore": [".vscode/**/*", "node_modules/**/*", "dist/**/*"]\n }\n}\n',
6
+ ".npmrc": "strict-peer-dependencies=false\n"
7
+ };
8
+ export {
9
+ commonFiles
10
+ };
@@ -0,0 +1,7 @@
1
+ const { MWAFiles } = require("./mwa");
2
+ const ModernTemplates = {
3
+ "web-app": MWAFiles
4
+ };
5
+ export {
6
+ ModernTemplates
7
+ };
@@ -0,0 +1,115 @@
1
+ import { commonFiles } from "./common";
2
+ const MWAFiles = {
3
+ ...commonFiles,
4
+ ...{
5
+ ".browserslistrc": "chrome >= 51\nedge >= 15\nfirefox >= 54\nsafari >= 10\nios_saf >= 10\n",
6
+ "README.md": "# Modern.js App\n\n## Setup\n\nInstall the dependencies:\n\n```bash\npnpm install\n```\n\n## Get Started\n\nStart the dev server:\n\n```bash\npnpm dev\n```\n\nEnable optional features or add a new entry:\n\n```bash\npnpm new\n```\n\nBuild the app for production:\n\n```bash\npnpm build\n```\n\nPreview the production build locally:\n\n```bash\npnpm serve\n```\n\nFor more information, see the [Modern.js documentation](https://modernjs.dev/en).\n",
7
+ "package.json": '{\n "name": "modern-app",\n "version": "0.1.0",\n "scripts": {\n "reset": "npx rimraf node_modules ./**/node_modules",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "biome check",\n "prepare": "simple-git-hooks",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [\n "biome check --files-ignore-unknown=true"\n ]\n },\n "simple-git-hooks": {\n "pre-commit": "npx lint-staged"\n },\n "dependencies": {\n "@modern-js/runtime": "2.68.12",\n "react": "^19.1.1",\n "react-dom": "^19.1.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.68.12",\n "@modern-js/tsconfig": "2.68.12",\n "@biomejs/biome": "1.9.4",\n "typescript": "~5.7.3",\n "@types/jest": "~29.2.4",\n "@types/node": "^20",\n "@types/react": "^19.1.8",\n "@types/react-dom": "^19.1.6",\n "lint-staged": "~15.4.0",\n "simple-git-hooks": "^2.11.1",\n "rimraf": "^6.0.1"\n }\n}\n',
8
+ "modern.config.ts": "import { appTools, defineConfig } from '@modern-js/app-tools';\n\n// https://modernjs.dev/en/configure/app/usage\nexport default defineConfig({\n runtime: {\n router: true,\n },\n plugins: [\n appTools({\n bundler: \n }),\n ],\n});\n",
9
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "compilerOptions": {\n "declaration": false,\n "jsx": "preserve",\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"],\n "@shared/*": ["./shared/*"]\n }\n },\n "include": ["src", "shared", "config", "modern.config.ts"],\n "exclude": ["**/node_modules"]\n}\n',
10
+ "src/modern.runtime.ts": "import { defineRuntimeConfig } from '@modern-js/runtime';\n\nexport default defineRuntimeConfig({});\n",
11
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/app-tools/types' />\n/// <reference types='@modern-js/runtime/types' />\n/// <reference types='@modern-js/runtime/types/router' />\n",
12
+ "src/routes/index.css": "html,\nbody {\n padding: 0;\n margin: 0;\n font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;\n background: linear-gradient(to bottom, transparent, #fff) #eceeef;\n}\n\np {\n margin: 0;\n}\n\n* {\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n box-sizing: border-box;\n}\n\n.container-box {\n min-height: 100vh;\n max-width: 100%;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n padding-top: 10px;\n}\n\nmain {\n flex: 1;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n}\n\n.title {\n display: flex;\n margin: 4rem 0 4rem;\n align-items: center;\n font-size: 4rem;\n font-weight: 600;\n}\n\n.logo {\n width: 6rem;\n margin: 7px 0 0 1rem;\n}\n\n.name {\n color: #4ecaff;\n}\n\n.description {\n text-align: center;\n line-height: 1.5;\n font-size: 1.3rem;\n color: #1b3a42;\n margin-bottom: 5rem;\n}\n\n.code {\n background: #fafafa;\n border-radius: 12px;\n padding: 0.6rem 0.9rem;\n font-size: 1.05rem;\n font-family:\n Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,\n Bitstream Vera Sans Mono, Courier New, monospace;\n}\n\n.container-box .grid {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 1100px;\n margin-top: 3rem;\n}\n\n.card {\n padding: 1.5rem;\n display: flex;\n flex-direction: column;\n justify-content: center;\n height: 100px;\n color: inherit;\n text-decoration: none;\n transition: 0.15s ease;\n width: 45%;\n}\n\n.card:hover,\n.card:focus {\n transform: scale(1.05);\n}\n\n.card h2 {\n display: flex;\n align-items: center;\n font-size: 1.5rem;\n margin: 0;\n padding: 0;\n}\n\n.card p {\n opacity: 0.6;\n font-size: 0.9rem;\n line-height: 1.5;\n margin-top: 1rem;\n}\n\n.arrow-right {\n width: 1.3rem;\n margin-left: 0.5rem;\n margin-top: 3px;\n}\n",
13
+ "src/routes/layout.tsx": "import { Outlet } from '@modern-js/runtime/router';\n\nexport default function Layout() {\n return (\n <div>\n <Outlet />\n </div>\n );\n}\n",
14
+ "src/routes/page.tsx": `import { Helmet } from '@modern-js/runtime/head';
15
+ import './index.css';
16
+
17
+ const Index = () => (
18
+ <div className="container-box">
19
+ <Helmet>
20
+ <link
21
+ rel="icon"
22
+ type="image/x-icon"
23
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
24
+ />
25
+ </Helmet>
26
+ <main>
27
+ <div className="title">
28
+ Welcome to
29
+ <img
30
+ className="logo"
31
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"
32
+ alt="Modern.js Logo"
33
+ />
34
+ <p className="name">Modern.js</p>
35
+ </div>
36
+ <p className="description">
37
+ Get started by editing <code className="code">src/routes/page.tsx</code>
38
+ </p>
39
+ <div className="grid">
40
+ <a
41
+ href="https://modernjs.dev/guides/get-started/introduction.html"
42
+ target="_blank"
43
+ rel="noopener noreferrer"
44
+ className="card"
45
+ >
46
+ <h2>
47
+ Guide
48
+ <img
49
+ className="arrow-right"
50
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
51
+ alt="Guide"
52
+ />
53
+ </h2>
54
+ <p>Follow the guides to use all features of Modern.js.</p>
55
+ </a>
56
+ <a
57
+ href="https://modernjs.dev/tutorials/foundations/introduction.html"
58
+ target="_blank"
59
+ className="card"
60
+ rel="noreferrer"
61
+ >
62
+ <h2>
63
+ Tutorials
64
+ <img
65
+ className="arrow-right"
66
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
67
+ alt="Tutorials"
68
+ />
69
+ </h2>
70
+ <p>Learn to use Modern.js to create your first application.</p>
71
+ </a>
72
+ <a
73
+ href="https://modernjs.dev/configure/app/usage.html"
74
+ target="_blank"
75
+ className="card"
76
+ rel="noreferrer"
77
+ >
78
+ <h2>
79
+ Config
80
+ <img
81
+ className="arrow-right"
82
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
83
+ alt="Config"
84
+ />
85
+ </h2>
86
+ <p>Find all configuration options provided by Modern.js.</p>
87
+ </a>
88
+ <a
89
+ href="https://github.com/web-infra-dev/modern.js"
90
+ target="_blank"
91
+ rel="noopener noreferrer"
92
+ className="card"
93
+ >
94
+ <h2>
95
+ GitHub
96
+ <img
97
+ className="arrow-right"
98
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
99
+ alt="Github"
100
+ />
101
+ </h2>
102
+ <p>View the source code on GitHub; feel free to contribute.</p>
103
+ </a>
104
+ </div>
105
+ </main>
106
+ </div>
107
+ );
108
+
109
+ export default Index;
110
+ `
111
+ }
112
+ };
113
+ export {
114
+ MWAFiles
115
+ };
@@ -0,0 +1,12 @@
1
+ import { type SandpackFiles, type SandpackSetup, type SandpackThemeProp } from '@codesandbox/sandpack-react';
2
+ export type ModernSandpackProps = {
3
+ template: 'web-app';
4
+ customSetup?: SandpackSetup;
5
+ files?: SandpackFiles;
6
+ removeFiles?: string[];
7
+ options?: Record<string, any>;
8
+ initialCollapsedFolder?: string[];
9
+ theme?: SandpackThemeProp;
10
+ activeFile?: string;
11
+ };
12
+ export default function ModernSandpack(props: ModernSandpackProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ export declare const commonFiles: {
2
+ ".codesandbox/environment.json": string;
3
+ ".codesandbox/tasks.json": string;
4
+ ".gitignore": string;
5
+ "biome.json": string;
6
+ ".npmrc": string;
7
+ };
@@ -0,0 +1,3 @@
1
+ export declare const ModernTemplates: {
2
+ 'web-app': any;
3
+ };
@@ -0,0 +1,17 @@
1
+ export declare const MWAFiles: {
2
+ ".browserslistrc": string;
3
+ "README.md": string;
4
+ "package.json": string;
5
+ "modern.config.ts": string;
6
+ "tsconfig.json": string;
7
+ "src/modern.runtime.ts": string;
8
+ "src/modern-app-env.d.ts": string;
9
+ "src/routes/index.css": string;
10
+ "src/routes/layout.tsx": string;
11
+ "src/routes/page.tsx": string;
12
+ ".codesandbox/environment.json": string;
13
+ ".codesandbox/tasks.json": string;
14
+ ".gitignore": string;
15
+ "biome.json": string;
16
+ ".npmrc": string;
17
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@modern-js/sandpack-react",
3
+ "description": "A Progressive React Framework for modern web development.",
4
+ "homepage": "https://modernjs.dev",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/generator/sandpack-react"
10
+ },
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "react",
14
+ "framework",
15
+ "modern",
16
+ "modern.js"
17
+ ],
18
+ "version": "0.0.0-canary-20250912092308",
19
+ "jsnext:source": "./src/index.ts",
20
+ "types": "./dist/types/index.d.ts",
21
+ "main": "./dist/cjs/index.js",
22
+ "module": "./dist/esm/index.js",
23
+ "exports": {
24
+ ".": {
25
+ "node": {
26
+ "jsnext:source": "./src/index.ts",
27
+ "import": "./dist/esm-node/index.js",
28
+ "require": "./dist/cjs/index.js"
29
+ },
30
+ "default": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "import": "./dist/esm/index.js"
33
+ }
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "@codesandbox/sandpack-react": "^2.20.0",
38
+ "@swc/helpers": "^0.5.17",
39
+ "react": "^19.1.1",
40
+ "react-dom": "^19.1.1"
41
+ },
42
+ "devDependencies": {
43
+ "@modern-js/codesmith-api-handlebars": "2.6.8",
44
+ "@modern-js/codesmith-utils": "2.6.8",
45
+ "@types/jest": "^29.5.14",
46
+ "@types/node": "^20",
47
+ "@types/react": "^19.1.8",
48
+ "@types/react-dom": "^19.1.6",
49
+ "@types/recursive-readdir": "^2.2.4",
50
+ "jest": "^29.7.0",
51
+ "recursive-readdir": "^2.2.3",
52
+ "ts-node": "^10.9.2",
53
+ "typescript": "^5",
54
+ "@modern-js/base-generator": "0.0.0-canary-20250912092308",
55
+ "@modern-js/entry-generator": "0.0.0-canary-20250912092308",
56
+ "@modern-js/generator-common": "0.0.0-canary-20250912092308",
57
+ "@modern-js/generator-utils": "0.0.0-canary-20250912092308",
58
+ "@modern-js/mwa-generator": "0.0.0-canary-20250912092308",
59
+ "@scripts/jest-config": "0.0.0-canary-20250912092308",
60
+ "@scripts/build": "0.0.0-canary-20250912092308"
61
+ },
62
+ "sideEffects": false,
63
+ "publishConfig": {
64
+ "registry": "https://registry.npmjs.org/",
65
+ "access": "public"
66
+ },
67
+ "scripts": {
68
+ "new": "modern-lib new",
69
+ "build": "ts-node scripts/template.ts && modern-lib build",
70
+ "test": "jest --passWithNoTests"
71
+ }
72
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "nodeVersion": 18
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "https://codesandbox.io/schemas/tasks.json",
3
+ "setupTasks": [
4
+ {
5
+ "name": "Installing Dependencies",
6
+ "command": "pnpm install"
7
+ }
8
+ ],
9
+ "tasks": {
10
+ "start": {
11
+ "name": "Application",
12
+ "command": "pnpm run start",
13
+ "runAtStart": true,
14
+ "restartOn": {
15
+ "files": ["pnpm-lock.yaml"]
16
+ }
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,131 @@
1
+ import path from 'path';
2
+ import { renderString } from '@modern-js/codesmith-api-handlebars';
3
+ import { fs } from '@modern-js/codesmith-utils/fs-extra';
4
+ import { Solution } from '@modern-js/generator-common';
5
+ import { getModernVersion } from '@modern-js/generator-utils';
6
+ import recursive from 'recursive-readdir';
7
+
8
+ const IgnoreFiles = [
9
+ '.nvmrc',
10
+ '.vscode/extensions.json',
11
+ '.vscode/settings.json',
12
+ '.husky/pre-commit',
13
+ 'README.md',
14
+ ];
15
+
16
+ export async function handleTemplate(
17
+ templatePath: string,
18
+ data: Record<string, any> = {},
19
+ { fileExtra, routerPrefix }: { fileExtra: string; routerPrefix: string } = {
20
+ fileExtra: '',
21
+ routerPrefix: '',
22
+ },
23
+ ) {
24
+ const files: Record<string, string> = {};
25
+ const templateFiles = await recursive(templatePath);
26
+ templateFiles.forEach(filePath => {
27
+ const file = filePath.replace(`${templatePath}/`, '');
28
+ if (IgnoreFiles.includes(file)) {
29
+ return;
30
+ }
31
+ if (fs.statSync(filePath).isFile()) {
32
+ if (file.endsWith('.handlebars')) {
33
+ files[
34
+ `${routerPrefix}${file
35
+ .replace('.handlebars', fileExtra)
36
+ .replace('npmrc', '.npmrc')}`.replace('language', 'ts')
37
+ ] = `${renderString(fs.readFileSync(filePath, 'utf-8'), data)}`;
38
+ } else {
39
+ files[`${routerPrefix}${file}`] = `${fs.readFileSync(
40
+ filePath,
41
+ 'utf-8',
42
+ )}`;
43
+ }
44
+ }
45
+ });
46
+ return files;
47
+ }
48
+
49
+ async function handleCodesandboxTemplate() {
50
+ const templateDir = path.join(__dirname, 'codesandbox');
51
+ const files: Record<string, string> = {
52
+ ...(await handleTemplate(templateDir)),
53
+ };
54
+
55
+ return files;
56
+ }
57
+ async function handleBaseTemplate() {
58
+ const templateDir = path.join(
59
+ require.resolve('@modern-js/base-generator'),
60
+ '../../',
61
+ 'templates',
62
+ );
63
+ const baseTemplate = path.join(templateDir, 'base-template');
64
+ const pnpmTemplate = path.join(templateDir, 'pnpm-template');
65
+ const files: Record<string, string> = {
66
+ ...(await handleTemplate(baseTemplate)),
67
+ ...(await handleTemplate(pnpmTemplate)),
68
+ };
69
+
70
+ return files;
71
+ }
72
+
73
+ async function handleMWATemplate() {
74
+ const templateDir = path.join(
75
+ require.resolve('@modern-js/mwa-generator'),
76
+ '../../',
77
+ 'templates',
78
+ );
79
+ const entryTemplateDir = path.join(
80
+ require.resolve('@modern-js/entry-generator'),
81
+ '../../',
82
+ 'templates',
83
+ );
84
+ const baseTemplate = path.join(templateDir, 'base-template');
85
+ const tsTemplate = path.join(templateDir, 'ts-template');
86
+ const modernVersion = await getModernVersion(Solution.MWA);
87
+ const files = {
88
+ ...(await handleTemplate(baseTemplate, {
89
+ name: 'modern-app',
90
+ isMonorepoSubProject: false,
91
+ modernVersion,
92
+ isTs: true,
93
+ packageManager: 'pnpm',
94
+ })),
95
+ ...(await handleTemplate(tsTemplate)),
96
+ ...(await handleTemplate(
97
+ entryTemplateDir,
98
+ {},
99
+ { fileExtra: '.tsx', routerPrefix: 'src/' },
100
+ )),
101
+ };
102
+ return files;
103
+ }
104
+
105
+ async function main() {
106
+ const codesandboxFiles = await handleCodesandboxTemplate();
107
+ const baseFiles = await handleBaseTemplate();
108
+ const srcTemplatesDir = path.join(__dirname, '..', 'src/templates');
109
+ const commonFiles = { ...codesandboxFiles, ...baseFiles };
110
+ fs.writeFileSync(
111
+ path.join(srcTemplatesDir, 'common.ts'),
112
+ `export const commonFiles = ${JSON.stringify(commonFiles, null, 2)};`,
113
+ 'utf-8',
114
+ );
115
+ const mwaFiles = await handleMWATemplate();
116
+ fs.writeFileSync(
117
+ path.join(srcTemplatesDir, 'mwa.ts'),
118
+ `import { commonFiles } from './common';
119
+
120
+ export const MWAFiles = {
121
+ ...commonFiles,
122
+ ...${JSON.stringify(mwaFiles, null, 2)}
123
+ };`,
124
+ 'utf-8',
125
+ );
126
+ }
127
+
128
+ main().catch(e => {
129
+ console.error(e);
130
+ process.exit(1);
131
+ });