@modern-js/sandpack-react 0.0.0-next-1693385366305

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,7 @@
1
+ # @modern-js/sandpack-react
2
+
3
+ ## 0.0.0-next-1693385366305
4
+
5
+ ### Patch Changes
6
+
7
+ - 33a2b1a00: feat: add @modern-js/sandpack-react package
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,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ModernSandpack;
9
+ }
10
+ });
11
+ const _jsxruntime = require("react/jsx-runtime");
12
+ const _sandpackreact = require("@codesandbox/sandpack-react");
13
+ const _templates = require("./templates");
14
+ function fileterFiles(files, removeFiles) {
15
+ if (removeFiles.length === 0) {
16
+ return files;
17
+ }
18
+ const result = {};
19
+ Object.keys(files).forEach((filename) => {
20
+ if (!removeFiles.includes(filename)) {
21
+ result[filename] = files[filename];
22
+ }
23
+ });
24
+ return result;
25
+ }
26
+ function ModernSandpack(props) {
27
+ const { template, customSetup = {}, files: customFiles = {}, removeFiles = [], options = {}, initialCollapsedFolder = [], theme = "light" } = props;
28
+ const initFiles = _templates.ModernTemplates[template];
29
+ const files = {
30
+ ...fileterFiles(initFiles, removeFiles),
31
+ ...fileterFiles(customFiles, removeFiles)
32
+ };
33
+ return /* @__PURE__ */ (0, _jsxruntime.jsx)(_sandpackreact.SandpackProvider, {
34
+ theme,
35
+ customSetup: {
36
+ environment: "node",
37
+ ...customSetup
38
+ },
39
+ files,
40
+ options: {
41
+ activeFile: "src/routes/page.tsx",
42
+ visibleFiles: [
43
+ "src/routes/page.tsx",
44
+ "src/routes/layout.tsx",
45
+ "src/routes/index.css"
46
+ ],
47
+ ...options
48
+ },
49
+ children: /* @__PURE__ */ (0, _jsxruntime.jsxs)(_sandpackreact.SandpackLayout, {
50
+ children: [
51
+ /* @__PURE__ */ (0, _jsxruntime.jsx)(_sandpackreact.SandpackFileExplorer, {
52
+ initialCollapsedFolder: [
53
+ "/.husky/",
54
+ "/.vscode/",
55
+ "/.codesandbox/",
56
+ ...initialCollapsedFolder
57
+ ]
58
+ }),
59
+ /* @__PURE__ */ (0, _jsxruntime.jsx)(_sandpackreact.SandpackCodeEditor, {
60
+ showLineNumbers: true,
61
+ showInlineErrors: true,
62
+ showTabs: false
63
+ }),
64
+ /* @__PURE__ */ (0, _jsxruntime.jsx)("div", {
65
+ style: {
66
+ position: "absolute",
67
+ right: "5px",
68
+ bottom: "5px"
69
+ },
70
+ children: /* @__PURE__ */ (0, _jsxruntime.jsx)(_sandpackreact.OpenInCodeSandboxButton, {})
71
+ })
72
+ ]
73
+ })
74
+ });
75
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "commonFiles", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return commonFiles;
9
+ }
10
+ });
11
+ const commonFiles = {
12
+ ".codesandbox/environment.json": '{\n "nodeVersion": 18\n}\n',
13
+ ".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',
14
+ ".npmrc": "strict-peer-dependencies=false\n"
15
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ModernTemplates", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ModernTemplates;
9
+ }
10
+ });
11
+ const { ModuleFiles } = require("./module");
12
+ const { MWAFiles } = require("./mwa");
13
+ const ModernTemplates = {
14
+ "web-app": MWAFiles,
15
+ "npm-module": ModuleFiles
16
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ModuleFiles", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return ModuleFiles;
9
+ }
10
+ });
11
+ const _common = require("./common");
12
+ const ModuleFiles = {
13
+ ..._common.commonFiles,
14
+ ...{
15
+ ".npmignore": ".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*.tsbuildinfo\n.eslintcache\n\ncoverage/\nrelease/\noutput/\noutput_resource/\ntests/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/api/typings/auto-generated\n",
16
+ "README.md": "# Modern.js Package\n\n## Setup\n\nInstall the dependencies:\n\n```bash\n install\n```\n\n## Get Started\n\nRun and debug the module:\n\n```\n dev\n```\n\nRun test cases:\n\n```\n test\n```\n\nBuild the module for production:\n\n```\n build\n```\n\nEnable optional features:\n\n```\n new\n```\n\nOther commands:\n\n```\n lint # Lint and fix source files\n change # Add a new changeset\n bump # Update version and changelog via changeset\n release # Release the package\n\n```\n\nFor more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en).\n",
17
+ "package.json": '{\n "name": "modern-npm-module",\n "version": "0.1.0",\n "types": "./dist/types/index.d.ts",\n "main": "./dist/lib/index.js",\n "module": "./dist/es/index.js",\n "scripts": {\n "prepare": "modern build && husky install",\n "dev": "modern dev",\n "build": "modern build",\n "build:watch": "modern build -w",\n "reset": "rimraf ./**/node_modules",\n "lint": "modern lint",\n "change": "modern change",\n "bump": "modern bump",\n "pre": "modern pre",\n "change-status": "modern change-status",\n "gen-release-note": "modern gen-release-note",\n "release": "modern release",\n "new": "modern new",\n "upgrade": "modern upgrade"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {},\n "peerDependencies": {},\n "devDependencies": {\n "@modern-js/module-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "typescript": "~5.0.4",\n "@types/jest": "~29.2.4",\n "@types/node": "~16.11.7",\n "@types/react": "~18.0.26",\n "rimraf": "~3.0.2",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1"\n },\n "sideEffects": [],\n "publishConfig": {\n "access": "public",\n "registry": "https://registry.npmjs.org/"\n }\n}\n',
18
+ "src/index.ts": "export default function () {\n return 'hello world';\n}\n",
19
+ "modern.config.ts": "import { moduleTools, defineConfig } from '@modern-js/module-tools';\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n",
20
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "declaration": true,\n "compilerOptions": {\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"]\n },\n "isolatedModules": true\n },\n "include": ["src"],\n "exclude": ["**/node_modules"]\n}\n',
21
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/module-tools/types' />\n/// <reference types='@modern-js/plugin-testing/types' />\n"
22
+ }
23
+ };
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MWAFiles", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MWAFiles;
9
+ }
10
+ });
11
+ const _common = require("./common");
12
+ const MWAFiles = {
13
+ ..._common.commonFiles,
14
+ ...{
15
+ ".browserslistrc": "chrome >= 51\nedge >= 15\nfirefox >= 54\nsafari >= 10\nios_saf >= 10\n",
16
+ "README.md": "# Modern.js App\n\n## Setup\n\nInstall the dependencies:\n\n```bash\n install\n```\n\n## Get Started\n\nStart the dev server:\n\n```\n dev\n```\n\nEnable optional features or add a new entry:\n\n```\n new\n```\n\nBuild the app for production:\n\n```\n build\n```\n\nPreview the production build locally:\n\n```\n serve\n```\n\nFor more information, see the [Modern.js documentation](https://modernjs.dev/en).\n",
17
+ "package.json": '{\n "name": "modern-app",\n "version": "0.1.0",\n "scripts": {\n "reset": "npx rimraf ./**/node_modules",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "modern lint",\n "prepare": "husky install",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {\n "@modern-js/runtime": "2.32.1",\n "react": "~18.2.0",\n "react-dom": "~18.2.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1",\n "rimraf": "~3.0.2"\n }\n}\n',
18
+ "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: [appTools()],\n});\n",
19
+ "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',
20
+ "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",
21
+ "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: 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",
22
+ "src/routes/page.tsx": `import { Helmet } from '@modern-js/runtime/head';
23
+ import './index.css';
24
+
25
+ const Index = () => (
26
+ <div className="container-box">
27
+ <Helmet>
28
+ <link
29
+ rel="icon"
30
+ type="image/x-icon"
31
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
32
+ />
33
+ </Helmet>
34
+ <main>
35
+ <div className="title">
36
+ Welcome to
37
+ <img
38
+ className="logo"
39
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"
40
+ alt="Modern.js Logo"
41
+ />
42
+ <p className="name">Modern.js</p>
43
+ </div>
44
+ <p className="description">
45
+ Get started by editing <code className="code">src/routes/page.tsx</code>
46
+ </p>
47
+ <div className="grid">
48
+ <a
49
+ href="https://modernjs.dev/guides/get-started/introduction.html"
50
+ target="_blank"
51
+ rel="noopener noreferrer"
52
+ className="card"
53
+ >
54
+ <h2>
55
+ Guide
56
+ <img
57
+ className="arrow-right"
58
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
59
+ />
60
+ </h2>
61
+ <p>Follow the guides to use all features of Modern.js.</p>
62
+ </a>
63
+ <a
64
+ href="https://modernjs.dev/tutorials/foundations/introduction.html"
65
+ target="_blank"
66
+ className="card"
67
+ rel="noreferrer"
68
+ >
69
+ <h2>
70
+ Tutorials
71
+ <img
72
+ className="arrow-right"
73
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
74
+ />
75
+ </h2>
76
+ <p>Learn to use Modern.js to create your first application.</p>
77
+ </a>
78
+ <a
79
+ href="https://modernjs.dev/configure/app/usage.html"
80
+ target="_blank"
81
+ className="card"
82
+ rel="noreferrer"
83
+ >
84
+ <h2>
85
+ Config
86
+ <img
87
+ className="arrow-right"
88
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
89
+ />
90
+ </h2>
91
+ <p>Find all configuration options provided by Modern.js.</p>
92
+ </a>
93
+ <a
94
+ href="https://github.com/web-infra-dev/modern.js"
95
+ target="_blank"
96
+ rel="noopener noreferrer"
97
+ className="card"
98
+ >
99
+ <h2>
100
+ Github
101
+ <img
102
+ className="arrow-right"
103
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
104
+ />
105
+ </h2>
106
+ <p>View the source code of Github, feel free to contribute.</p>
107
+ </a>
108
+ </div>
109
+ </main>
110
+ </div>
111
+ );
112
+
113
+ export default Index;
114
+ `,
115
+ "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"
116
+ }
117
+ };
@@ -0,0 +1,61 @@
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 { SandpackProvider, SandpackLayout, SandpackFileExplorer, SandpackCodeEditor, OpenInCodeSandboxButton } 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
+ export default 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_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: theme,
24
+ customSetup: _object_spread({
25
+ environment: "node"
26
+ }, customSetup),
27
+ files: files,
28
+ options: _object_spread({
29
+ activeFile: "src/routes/page.tsx",
30
+ visibleFiles: [
31
+ "src/routes/page.tsx",
32
+ "src/routes/layout.tsx",
33
+ "src/routes/index.css"
34
+ ]
35
+ }, options),
36
+ children: /* @__PURE__ */ _jsxs(SandpackLayout, {
37
+ children: [
38
+ /* @__PURE__ */ _jsx(SandpackFileExplorer, {
39
+ initialCollapsedFolder: [
40
+ "/.husky/",
41
+ "/.vscode/",
42
+ "/.codesandbox/"
43
+ ].concat(_to_consumable_array(initialCollapsedFolder))
44
+ }),
45
+ /* @__PURE__ */ _jsx(SandpackCodeEditor, {
46
+ showLineNumbers: true,
47
+ showInlineErrors: 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
+ }
@@ -0,0 +1,5 @@
1
+ export 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
+ ".npmrc": "strict-peer-dependencies=false\n"
5
+ };
@@ -0,0 +1,6 @@
1
+ var ModuleFiles = require("./module").ModuleFiles;
2
+ var MWAFiles = require("./mwa").MWAFiles;
3
+ export var ModernTemplates = {
4
+ "web-app": MWAFiles,
5
+ "npm-module": ModuleFiles
6
+ };
@@ -0,0 +1,11 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { commonFiles } from "./common";
3
+ export var ModuleFiles = _object_spread({}, commonFiles, {
4
+ ".npmignore": ".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*.tsbuildinfo\n.eslintcache\n\ncoverage/\nrelease/\noutput/\noutput_resource/\ntests/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/api/typings/auto-generated\n",
5
+ "README.md": "# Modern.js Package\n\n## Setup\n\nInstall the dependencies:\n\n```bash\n install\n```\n\n## Get Started\n\nRun and debug the module:\n\n```\n dev\n```\n\nRun test cases:\n\n```\n test\n```\n\nBuild the module for production:\n\n```\n build\n```\n\nEnable optional features:\n\n```\n new\n```\n\nOther commands:\n\n```\n lint # Lint and fix source files\n change # Add a new changeset\n bump # Update version and changelog via changeset\n release # Release the package\n\n```\n\nFor more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en).\n",
6
+ "package.json": '{\n "name": "modern-npm-module",\n "version": "0.1.0",\n "types": "./dist/types/index.d.ts",\n "main": "./dist/lib/index.js",\n "module": "./dist/es/index.js",\n "scripts": {\n "prepare": "modern build && husky install",\n "dev": "modern dev",\n "build": "modern build",\n "build:watch": "modern build -w",\n "reset": "rimraf ./**/node_modules",\n "lint": "modern lint",\n "change": "modern change",\n "bump": "modern bump",\n "pre": "modern pre",\n "change-status": "modern change-status",\n "gen-release-note": "modern gen-release-note",\n "release": "modern release",\n "new": "modern new",\n "upgrade": "modern upgrade"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {},\n "peerDependencies": {},\n "devDependencies": {\n "@modern-js/module-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "typescript": "~5.0.4",\n "@types/jest": "~29.2.4",\n "@types/node": "~16.11.7",\n "@types/react": "~18.0.26",\n "rimraf": "~3.0.2",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1"\n },\n "sideEffects": [],\n "publishConfig": {\n "access": "public",\n "registry": "https://registry.npmjs.org/"\n }\n}\n',
7
+ "src/index.ts": "export default function () {\n return 'hello world';\n}\n",
8
+ "modern.config.ts": "import { moduleTools, defineConfig } from '@modern-js/module-tools';\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n",
9
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "declaration": true,\n "compilerOptions": {\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"]\n },\n "isolatedModules": true\n },\n "include": ["src"],\n "exclude": ["**/node_modules"]\n}\n',
10
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/module-tools/types' />\n/// <reference types='@modern-js/plugin-testing/types' />\n"
11
+ });
@@ -0,0 +1,13 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { commonFiles } from "./common";
3
+ export 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\n install\n```\n\n## Get Started\n\nStart the dev server:\n\n```\n dev\n```\n\nEnable optional features or add a new entry:\n\n```\n new\n```\n\nBuild the app for production:\n\n```\n build\n```\n\nPreview the production build locally:\n\n```\n 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",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "modern lint",\n "prepare": "husky install",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {\n "@modern-js/runtime": "2.32.1",\n "react": "~18.2.0",\n "react-dom": "~18.2.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1",\n "rimraf": "~3.0.2"\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: [appTools()],\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-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",
10
+ "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: 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",
11
+ "src/routes/page.tsx": 'import { Helmet } from \'@modern-js/runtime/head\';\nimport \'./index.css\';\n\nconst Index = () => (\n <div className="container-box">\n <Helmet>\n <link\n rel="icon"\n type="image/x-icon"\n href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"\n />\n </Helmet>\n <main>\n <div className="title">\n Welcome to\n <img\n className="logo"\n src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"\n alt="Modern.js Logo"\n />\n <p className="name">Modern.js</p>\n </div>\n <p className="description">\n Get started by editing <code className="code">src/routes/page.tsx</code>\n </p>\n <div className="grid">\n <a\n href="https://modernjs.dev/guides/get-started/introduction.html"\n target="_blank"\n rel="noopener noreferrer"\n className="card"\n >\n <h2>\n Guide\n <img\n className="arrow-right"\n src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"\n />\n </h2>\n <p>Follow the guides to use all features of Modern.js.</p>\n </a>\n <a\n href="https://modernjs.dev/tutorials/foundations/introduction.html"\n target="_blank"\n className="card"\n rel="noreferrer"\n >\n <h2>\n Tutorials\n <img\n className="arrow-right"\n src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"\n />\n </h2>\n <p>Learn to use Modern.js to create your first application.</p>\n </a>\n <a\n href="https://modernjs.dev/configure/app/usage.html"\n target="_blank"\n className="card"\n rel="noreferrer"\n >\n <h2>\n Config\n <img\n className="arrow-right"\n src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"\n />\n </h2>\n <p>Find all configuration options provided by Modern.js.</p>\n </a>\n <a\n href="https://github.com/web-infra-dev/modern.js"\n target="_blank"\n rel="noopener noreferrer"\n className="card"\n >\n <h2>\n Github\n <img\n className="arrow-right"\n src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"\n />\n </h2>\n <p>View the source code of Github, feel free to contribute.</p>\n </a>\n </div>\n </main>\n </div>\n);\n\nexport default Index;\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
+ });
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SandpackProvider, SandpackLayout, SandpackFileExplorer, SandpackCodeEditor, OpenInCodeSandboxButton } 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
+ export default function ModernSandpack(props) {
17
+ const { template, customSetup = {}, files: customFiles = {}, removeFiles = [], options = {}, initialCollapsedFolder = [], 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: "src/routes/page.tsx",
32
+ visibleFiles: [
33
+ "src/routes/page.tsx",
34
+ "src/routes/layout.tsx",
35
+ "src/routes/index.css"
36
+ ],
37
+ ...options
38
+ },
39
+ children: /* @__PURE__ */ _jsxs(SandpackLayout, {
40
+ children: [
41
+ /* @__PURE__ */ _jsx(SandpackFileExplorer, {
42
+ initialCollapsedFolder: [
43
+ "/.husky/",
44
+ "/.vscode/",
45
+ "/.codesandbox/",
46
+ ...initialCollapsedFolder
47
+ ]
48
+ }),
49
+ /* @__PURE__ */ _jsx(SandpackCodeEditor, {
50
+ showLineNumbers: true,
51
+ showInlineErrors: true,
52
+ showTabs: false
53
+ }),
54
+ /* @__PURE__ */ _jsx("div", {
55
+ style: {
56
+ position: "absolute",
57
+ right: "5px",
58
+ bottom: "5px"
59
+ },
60
+ children: /* @__PURE__ */ _jsx(OpenInCodeSandboxButton, {})
61
+ })
62
+ ]
63
+ })
64
+ });
65
+ }
@@ -0,0 +1,5 @@
1
+ export 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
+ ".npmrc": "strict-peer-dependencies=false\n"
5
+ };
@@ -0,0 +1,6 @@
1
+ const { ModuleFiles } = require("./module");
2
+ const { MWAFiles } = require("./mwa");
3
+ export const ModernTemplates = {
4
+ "web-app": MWAFiles,
5
+ "npm-module": ModuleFiles
6
+ };
@@ -0,0 +1,13 @@
1
+ import { commonFiles } from "./common";
2
+ export const ModuleFiles = {
3
+ ...commonFiles,
4
+ ...{
5
+ ".npmignore": ".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*.tsbuildinfo\n.eslintcache\n\ncoverage/\nrelease/\noutput/\noutput_resource/\ntests/\n\n.vscode/**/*\n!.vscode/settings.json\n!.vscode/extensions.json\n.idea/\n\n**/*/api/typings/auto-generated\n",
6
+ "README.md": "# Modern.js Package\n\n## Setup\n\nInstall the dependencies:\n\n```bash\n install\n```\n\n## Get Started\n\nRun and debug the module:\n\n```\n dev\n```\n\nRun test cases:\n\n```\n test\n```\n\nBuild the module for production:\n\n```\n build\n```\n\nEnable optional features:\n\n```\n new\n```\n\nOther commands:\n\n```\n lint # Lint and fix source files\n change # Add a new changeset\n bump # Update version and changelog via changeset\n release # Release the package\n\n```\n\nFor more information, see the [Modern.js Module documentation](https://modernjs.dev/module-tools/en).\n",
7
+ "package.json": '{\n "name": "modern-npm-module",\n "version": "0.1.0",\n "types": "./dist/types/index.d.ts",\n "main": "./dist/lib/index.js",\n "module": "./dist/es/index.js",\n "scripts": {\n "prepare": "modern build && husky install",\n "dev": "modern dev",\n "build": "modern build",\n "build:watch": "modern build -w",\n "reset": "rimraf ./**/node_modules",\n "lint": "modern lint",\n "change": "modern change",\n "bump": "modern bump",\n "pre": "modern pre",\n "change-status": "modern change-status",\n "gen-release-note": "modern gen-release-note",\n "release": "modern release",\n "new": "modern new",\n "upgrade": "modern upgrade"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {},\n "peerDependencies": {},\n "devDependencies": {\n "@modern-js/module-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "typescript": "~5.0.4",\n "@types/jest": "~29.2.4",\n "@types/node": "~16.11.7",\n "@types/react": "~18.0.26",\n "rimraf": "~3.0.2",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1"\n },\n "sideEffects": [],\n "publishConfig": {\n "access": "public",\n "registry": "https://registry.npmjs.org/"\n }\n}\n',
8
+ "src/index.ts": "export default function () {\n return 'hello world';\n}\n",
9
+ "modern.config.ts": "import { moduleTools, defineConfig } from '@modern-js/module-tools';\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n",
10
+ "tsconfig.json": '{\n "extends": "@modern-js/tsconfig/base",\n "declaration": true,\n "compilerOptions": {\n "baseUrl": "./",\n "paths": {\n "@/*": ["./src/*"]\n },\n "isolatedModules": true\n },\n "include": ["src"],\n "exclude": ["**/node_modules"]\n}\n',
11
+ "src/modern-app-env.d.ts": "/// <reference types='@modern-js/module-tools/types' />\n/// <reference types='@modern-js/plugin-testing/types' />\n"
12
+ }
13
+ };
@@ -0,0 +1,107 @@
1
+ import { commonFiles } from "./common";
2
+ export 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\n install\n```\n\n## Get Started\n\nStart the dev server:\n\n```\n dev\n```\n\nEnable optional features or add a new entry:\n\n```\n new\n```\n\nBuild the app for production:\n\n```\n build\n```\n\nPreview the production build locally:\n\n```\n 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",\n "dev": "modern dev",\n "build": "modern build",\n "start": "modern start",\n "serve": "modern serve",\n "new": "modern new",\n "lint": "modern lint",\n "prepare": "husky install",\n "upgrade": "modern upgrade"\n },\n "engines": {\n "node": ">=16.18.1"\n },\n "lint-staged": {\n "*.{ts,tsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ],\n "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [\n "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"\n ]\n },\n "eslintIgnore": [\n "node_modules/",\n "dist/"\n ],\n "dependencies": {\n "@modern-js/runtime": "2.32.1",\n "react": "~18.2.0",\n "react-dom": "~18.2.0"\n },\n "devDependencies": {\n "@modern-js/app-tools": "2.32.1",\n "@modern-js/eslint-config": "2.32.1",\n "@modern-js/tsconfig":"2.32.1",\n "@modern-js-app/eslint-config": "2.32.1",\n "lint-staged": "~13.1.0",\n "prettier": "~2.8.1",\n "husky": "~8.0.1",\n "rimraf": "~3.0.2"\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: [appTools()],\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-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: 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/page.tsx": `import { Helmet } from '@modern-js/runtime/head';
13
+ import './index.css';
14
+
15
+ const Index = () => (
16
+ <div className="container-box">
17
+ <Helmet>
18
+ <link
19
+ rel="icon"
20
+ type="image/x-icon"
21
+ href="https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico"
22
+ />
23
+ </Helmet>
24
+ <main>
25
+ <div className="title">
26
+ Welcome to
27
+ <img
28
+ className="logo"
29
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/modern-js-logo.svg"
30
+ alt="Modern.js Logo"
31
+ />
32
+ <p className="name">Modern.js</p>
33
+ </div>
34
+ <p className="description">
35
+ Get started by editing <code className="code">src/routes/page.tsx</code>
36
+ </p>
37
+ <div className="grid">
38
+ <a
39
+ href="https://modernjs.dev/guides/get-started/introduction.html"
40
+ target="_blank"
41
+ rel="noopener noreferrer"
42
+ className="card"
43
+ >
44
+ <h2>
45
+ Guide
46
+ <img
47
+ className="arrow-right"
48
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
49
+ />
50
+ </h2>
51
+ <p>Follow the guides to use all features of Modern.js.</p>
52
+ </a>
53
+ <a
54
+ href="https://modernjs.dev/tutorials/foundations/introduction.html"
55
+ target="_blank"
56
+ className="card"
57
+ rel="noreferrer"
58
+ >
59
+ <h2>
60
+ Tutorials
61
+ <img
62
+ className="arrow-right"
63
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
64
+ />
65
+ </h2>
66
+ <p>Learn to use Modern.js to create your first application.</p>
67
+ </a>
68
+ <a
69
+ href="https://modernjs.dev/configure/app/usage.html"
70
+ target="_blank"
71
+ className="card"
72
+ rel="noreferrer"
73
+ >
74
+ <h2>
75
+ Config
76
+ <img
77
+ className="arrow-right"
78
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
79
+ />
80
+ </h2>
81
+ <p>Find all configuration options provided by Modern.js.</p>
82
+ </a>
83
+ <a
84
+ href="https://github.com/web-infra-dev/modern.js"
85
+ target="_blank"
86
+ rel="noopener noreferrer"
87
+ className="card"
88
+ >
89
+ <h2>
90
+ Github
91
+ <img
92
+ className="arrow-right"
93
+ src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/arrow-right.svg"
94
+ />
95
+ </h2>
96
+ <p>View the source code of Github, feel free to contribute.</p>
97
+ </a>
98
+ </div>
99
+ </main>
100
+ </div>
101
+ );
102
+
103
+ export default Index;
104
+ `,
105
+ "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"
106
+ }
107
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { SandpackSetup, SandpackFiles, SandpackThemeProp } from '@codesandbox/sandpack-react';
3
+ export type ModernSandpackProps = {
4
+ template: 'web-app' | 'npm-module';
5
+ customSetup?: SandpackSetup;
6
+ files?: SandpackFiles;
7
+ removeFiles?: string[];
8
+ options?: Record<string, any>;
9
+ initialCollapsedFolder?: string[];
10
+ theme?: SandpackThemeProp;
11
+ };
12
+ export default function ModernSandpack(props: ModernSandpackProps): JSX.Element;
@@ -0,0 +1,5 @@
1
+ export declare const commonFiles: {
2
+ ".codesandbox/environment.json": string;
3
+ ".codesandbox/tasks.json": string;
4
+ ".npmrc": string;
5
+ };
@@ -0,0 +1,4 @@
1
+ export declare const ModernTemplates: {
2
+ 'web-app': any;
3
+ 'npm-module': any;
4
+ };
@@ -0,0 +1,12 @@
1
+ export declare const ModuleFiles: {
2
+ ".npmignore": string;
3
+ "README.md": string;
4
+ "package.json": string;
5
+ "src/index.ts": string;
6
+ "modern.config.ts": string;
7
+ "tsconfig.json": string;
8
+ "src/modern-app-env.d.ts": string;
9
+ ".codesandbox/environment.json": string;
10
+ ".codesandbox/tasks.json": string;
11
+ ".npmrc": string;
12
+ };
@@ -0,0 +1,14 @@
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-app-env.d.ts": string;
8
+ "src/routes/index.css": string;
9
+ "src/routes/page.tsx": string;
10
+ "src/routes/layout.tsx": string;
11
+ ".codesandbox/environment.json": string;
12
+ ".codesandbox/tasks.json": string;
13
+ ".npmrc": string;
14
+ };
package/package.json ADDED
@@ -0,0 +1,71 @@
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-template"
10
+ },
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "react",
14
+ "framework",
15
+ "modern",
16
+ "modern.js"
17
+ ],
18
+ "version": "0.0.0-next-1693385366305",
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": "./dist/esm/index.js"
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "react": "^18",
35
+ "react-dom": "^18",
36
+ "@swc/helpers": "0.5.1",
37
+ "@codesandbox/sandpack-react": "^2.6.9"
38
+ },
39
+ "devDependencies": {
40
+ "@modern-js/codesmith-api-handlebars": "2.2.5",
41
+ "@types/jest": "^29",
42
+ "@types/node": "^14",
43
+ "jest": "^29",
44
+ "typescript": "^5",
45
+ "ts-node": "^10.9.1",
46
+ "recursive-readdir": "^2.2.3",
47
+ "@types/recursive-readdir": "^2.2.1",
48
+ "@types/react": "^18",
49
+ "@types/react-dom": "^18",
50
+ "@modern-js/base-generator": "0.0.0-next-1693385366305",
51
+ "@modern-js/module-generator": "0.0.0-next-1693385366305",
52
+ "@modern-js/entry-generator": "0.0.0-next-1693385366305",
53
+ "@modern-js/mwa-generator": "0.0.0-next-1693385366305",
54
+ "@modern-js/generator-utils": "0.0.0-next-1693385366305",
55
+ "@modern-js/generator-common": "0.0.0-next-1693385366305",
56
+ "@scripts/build": "0.0.0-next-1693385366305",
57
+ "@modern-js/utils": "0.0.0-next-1693385366305",
58
+ "@scripts/jest-config": "0.0.0-next-1693385366305"
59
+ },
60
+ "sideEffects": false,
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/",
63
+ "access": "public",
64
+ "provenance": true
65
+ },
66
+ "scripts": {
67
+ "new": "modern-lib new",
68
+ "build": "ts-node scripts/template.ts && modern-lib build",
69
+ "test": "jest --passWithNoTests"
70
+ }
71
+ }
@@ -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,169 @@
1
+ import path from 'path';
2
+ import recursive from 'recursive-readdir';
3
+ import fs from '@modern-js/utils/fs-extra';
4
+ import { renderString } from '@modern-js/codesmith-api-handlebars';
5
+ import { getModernVersion } from '@modern-js/generator-utils';
6
+ import { Solution } from '@modern-js/generator-common';
7
+
8
+ const IgnoreFiles = [
9
+ '.nvmrc',
10
+ '.eslintrc.js.handlebars',
11
+ 'src/.eslintrc.js.handlebars',
12
+ '.prettierrc',
13
+ '.vscode/extensions.json',
14
+ '.vscode/settings.json',
15
+ '.husky/pre-commit',
16
+ 'README.md',
17
+ '.gitignore.handlebars',
18
+ ];
19
+
20
+ async function handleTemplate(
21
+ templatePath: string,
22
+ data: Record<string, any> = {},
23
+ { fileExtra, routerPrefix }: { fileExtra: string; routerPrefix: string } = {
24
+ fileExtra: '',
25
+ routerPrefix: '',
26
+ },
27
+ ) {
28
+ const files: Record<string, string> = {};
29
+ const templateFiles = await recursive(templatePath);
30
+ templateFiles.forEach(filePath => {
31
+ const file = filePath.replace(`${templatePath}/`, '');
32
+ if (IgnoreFiles.includes(file)) {
33
+ return;
34
+ }
35
+ if (fs.statSync(filePath).isFile()) {
36
+ if (file.endsWith('.handlebars')) {
37
+ files[
38
+ `${routerPrefix}${file
39
+ .replace('.handlebars', fileExtra)
40
+ .replace('npmrc', '.npmrc')}`.replace('language', 'ts')
41
+ ] = `${renderString(fs.readFileSync(filePath, 'utf-8'), data)}`;
42
+ } else {
43
+ files[`${routerPrefix}${file}`] = `${fs.readFileSync(
44
+ filePath,
45
+ 'utf-8',
46
+ )}`;
47
+ }
48
+ }
49
+ });
50
+ return files;
51
+ }
52
+
53
+ async function handleCodesandboxTemplate() {
54
+ const templateDir = path.join(__dirname, 'codesandbox');
55
+ const files: Record<string, string> = {
56
+ ...(await handleTemplate(templateDir)),
57
+ };
58
+
59
+ return files;
60
+ }
61
+ async function handleBaseTemplate() {
62
+ const templateDir = path.join(
63
+ require.resolve('@modern-js/base-generator'),
64
+ '../../',
65
+ 'templates',
66
+ );
67
+ const baseTemplate = path.join(templateDir, 'base-template');
68
+ const pnpmTemplate = path.join(templateDir, 'pnpm-template');
69
+ const files: Record<string, string> = {
70
+ ...(await handleTemplate(baseTemplate)),
71
+ ...(await handleTemplate(pnpmTemplate)),
72
+ };
73
+
74
+ return files;
75
+ }
76
+
77
+ async function handleMWATemplate() {
78
+ const templateDir = path.join(
79
+ require.resolve('@modern-js/mwa-generator'),
80
+ '../../',
81
+ 'templates',
82
+ );
83
+ const entryTemplateDir = path.join(
84
+ require.resolve('@modern-js/entry-generator'),
85
+ '../../',
86
+ 'templates',
87
+ );
88
+ const baseTemplate = path.join(templateDir, 'base-template');
89
+ const tsTemplate = path.join(templateDir, 'ts-template');
90
+ const modernVersion = await getModernVersion(Solution.MWA);
91
+ const files = {
92
+ ...(await handleTemplate(baseTemplate, {
93
+ name: 'modern-app',
94
+ isMonorepoSubProject: false,
95
+ modernVersion,
96
+ isTsProject: true,
97
+ })),
98
+ ...(await handleTemplate(tsTemplate)),
99
+ ...(await handleTemplate(
100
+ entryTemplateDir,
101
+ {},
102
+ { fileExtra: '.tsx', routerPrefix: 'src/' },
103
+ )),
104
+ };
105
+ return files;
106
+ }
107
+
108
+ async function handleModuleTemplate() {
109
+ const templateDir = path.join(
110
+ require.resolve('@modern-js/module-generator'),
111
+ '../../',
112
+ 'templates',
113
+ );
114
+ const baseTemplate = path.join(templateDir, 'base-template');
115
+ const tsTemplate = path.join(templateDir, 'ts-template');
116
+ const modernVersion = await getModernVersion(Solution.Module);
117
+ const files = {
118
+ ...(await handleTemplate(baseTemplate, {
119
+ name: 'modern-npm-module',
120
+ isMonorepoSubProject: false,
121
+ modernVersion,
122
+ isTs: true,
123
+ isPublic: true,
124
+ language: 'ts',
125
+ })),
126
+ ...(await handleTemplate(tsTemplate)),
127
+ };
128
+ return files;
129
+ }
130
+ async function main() {
131
+ const codesandboxFiles = await handleCodesandboxTemplate();
132
+ const baseFiles = await handleBaseTemplate();
133
+ const srcTemplatesDir = path.join(__dirname, '..', 'src/templates');
134
+ const commonFiles = { ...codesandboxFiles, ...baseFiles };
135
+ fs.writeFileSync(
136
+ path.join(srcTemplatesDir, 'common.ts'),
137
+ `export const commonFiles = ${JSON.stringify(commonFiles, null, 2)};`,
138
+ 'utf-8',
139
+ );
140
+ const mwaFiles = await handleMWATemplate();
141
+ fs.writeFileSync(
142
+ path.join(srcTemplatesDir, 'mwa.ts'),
143
+ `import { commonFiles } from './common';
144
+
145
+ export const MWAFiles = {
146
+ ...commonFiles,
147
+ ...${JSON.stringify(mwaFiles, null, 2)}
148
+ };`,
149
+ 'utf-8',
150
+ );
151
+
152
+ const moduleFiles = await handleModuleTemplate();
153
+ fs.writeFileSync(
154
+ path.join(srcTemplatesDir, 'module.ts'),
155
+ `import { commonFiles } from './common';
156
+
157
+ export const ModuleFiles = {
158
+ ...commonFiles,
159
+ ...${JSON.stringify(moduleFiles, null, 2)}
160
+ };`,
161
+ 'utf-8',
162
+ );
163
+ }
164
+
165
+ main().catch(e => {
166
+ console.error(e);
167
+ // eslint-disable-next-line no-process-exit
168
+ process.exit(1);
169
+ });